def fradosify(path, outfp, delta): print >>sys.stderr, 'reading: %r' % path ratio = pow(2, delta/12.0) src = WaveReader(path) if src.nchannels != 1: raise ValueError('invalid number of channels') if src.sampwidth != 2: raise ValueError('invalid sampling width') dst = WaveWriter(outfp, framerate=src.framerate) contour = PitchContour(src.framerate) contour.load(src) def f(t): x = contour.getavg(t) if x is not None: x = int(x*ratio) return x src.seek(0) dst.write(psola(src.read(), src.framerate, contour.getsrc, f, contour.wmin)) src.close() dst.close() return
def main(argv): import getopt def usage(): print 'usage: %s [-f] [-o out.wav] [-m maxlength] [expr]' % argv[0] return 100 try: (opts, args) = getopt.getopt(argv[1:], 'fo:m:') except getopt.GetoptError: return usage() force = False maxlength = 10 path = 'out.wav' for (k, v) in opts: if k == '-f': force = True elif k == '-o': path = v elif k == '-m': maxlength = float(v) if not args: return usage() if not force and os.path.exists(path): raise IOError(path) fp = open(path, 'wb') stream = WaveWriter(fp) expr = args.pop(0) gen = WaveGenerator(stream.framerate) vars = { 'add': gen.add, 'mult': gen.mult, 'amp': gen.amp, 'concat': gen.concat, 'mix': gen.mix, 'clip': gen.clip, 'env': gen.env, 'sine': gen.sine, 'rect': gen.rect, 'saw': gen.saw, 'noise': gen.noise, } wav = eval(expr, vars, {}) stream.write(gen.clip(wav, maxlength)) stream.close() fp.close() return 0
def main(argv): import getopt import fileinput def usage(): print 'usage: %s [-v] [-o out.wav] [script ...]' % argv[0] return 100 def getv(v): try: if '.' in v: return float(v) else: return int(v) except ValueError: return 0 try: (opts, args) = getopt.getopt(argv[1:], 'vo:') except getopt.GetoptError: return usage() verbose = 0 outfp = None for (k, v) in opts: if k == '-v': verbose += 1 elif k == '-o': outfp = open(v, 'wb') # if not args: return usage() path = args.pop(0) src = WaveReader(path) # waves = [] for line in fileinput.input(args): (line,_,_) = line.partition('#') line = line.strip() if not line: continue (t,dur,path) = line.split('\t') t = getv(t) dur = getv(dur) wav = WaveReader(path) assert wav.nchannels == src.nchannels assert wav.sampwidth == src.sampwidth #assert wav.framerate == src.framerate if isinstance(t, float): t = int(t*src.framerate) if isinstance(dur, float): dur = int(dur*src.framerate) buf = wav.read(dur) wav.close() waves.append((t, buf)) waves.append((src.nframes, [])) # if outfp is not None: dst = WaveWriter(outfp, nchannels=src.nchannels, sampwidth=src.sampwidth, framerate=src.framerate) else: dst = WavePlayer(nchannels=src.nchannels, sampwidth=src.sampwidth, framerate=src.framerate) # t0 = 0 bufs = [] for (t1,buf1) in sorted(waves, key=lambda (t,_): t): dt = (t1-t0)*dst.nchannels tmp = [src.read(t1-t0)] assert len(tmp[0]) == dt for (i,b) in enumerate(bufs): if dt <= len(b): tmp.append(b[:dt]) else: tmp.append(b+[0]*(dt-len(b))) bufs[i] = b[dt:] bufs.append(buf1) bufs = [ b for b in bufs if b ] dst.write(mix(tmp)) t0 = t1 # dst.close() if outfp is not None: outfp.close() return
def main(argv): import getopt import fileinput def usage(): print 'usage: %s [-v] [-o out.wav] [script ...]' % argv[0] return 100 def getv(v): try: if '.' in v: return float(v) else: return int(v) except ValueError: return 0 try: (opts, args) = getopt.getopt(argv[1:], 'vo:') except getopt.GetoptError: return usage() verbose = 0 outfp = None for (k, v) in opts: if k == '-v': verbose += 1 elif k == '-o': outfp = open(v, 'wb') # if not args: return usage() path = args.pop(0) src = WaveReader(path) # waves = [] for line in fileinput.input(args): (line, _, _) = line.partition('#') line = line.strip() if not line: continue (t, dur, path) = line.split('\t') t = getv(t) dur = getv(dur) wav = WaveReader(path) assert wav.nchannels == src.nchannels assert wav.sampwidth == src.sampwidth #assert wav.framerate == src.framerate if isinstance(t, float): t = int(t * src.framerate) if isinstance(dur, float): dur = int(dur * src.framerate) buf = wav.read(dur) wav.close() waves.append((t, buf)) waves.append((src.nframes, [])) # if outfp is not None: dst = WaveWriter(outfp, nchannels=src.nchannels, sampwidth=src.sampwidth, framerate=src.framerate) else: dst = WavePlayer(nchannels=src.nchannels, sampwidth=src.sampwidth, framerate=src.framerate) # t0 = 0 bufs = [] for (t1, buf1) in sorted(waves, key=lambda (t, _): t): dt = (t1 - t0) * dst.nchannels tmp = [src.read(t1 - t0)] assert len(tmp[0]) == dt for (i, b) in enumerate(bufs): if dt <= len(b): tmp.append(b[:dt]) else: tmp.append(b + [0] * (dt - len(b))) bufs[i] = b[dt:] bufs.append(buf1) bufs = [b for b in bufs if b] dst.write(mix(tmp)) t0 = t1 # dst.close() if outfp is not None: outfp.close() return