ref: 659900bfc9ad85e8f68e60d390aa40300d05aae8
parent: 0015a549fa241de8dc566f038ec793930239b7e2
author: Paul Brossier <piem@piem.org>
date: Fri Sep 16 21:47:46 EDT 2016
python/demos/demo_pitchshift.py: add simple pitch demo with a ramp
--- /dev/null
+++ b/python/demos/demo_pitchshift.py
@@ -1,0 +1,49 @@
+#! /usr/bin/env python
+
+import sys
+import aubio
+
+if __name__ == '__main__':
+ if len(sys.argv) < 3:
+ print('usage: %s <inputfile> <outputfile> [transpose] [samplerate] [hop_size]' % sys.argv[0])+ sys.exit(1)
+ if len(sys.argv) > 3: transpose = float(sys.argv[3])
+ else: transpose = 12.
+ if len(sys.argv) > 4: samplerate = int(sys.argv[4])
+ else: samplerate = 0
+ if len(sys.argv) > 5: hop_size = int(sys.argv[5])
+ else: hop_size = 256
+
+ source_read = aubio.source(sys.argv[1], samplerate, hop_size)
+ if samplerate == 0: samplerate = source_read.samplerate
+ sink_out = aubio.sink(sys.argv[2], samplerate)
+
+ pitchshifter = aubio.pitchshift("default", 1., hop_size, samplerate)+ if transpose: pitchshifter.set_transpose(transpose)
+
+ total_frames, read = 0, hop_size
+ transpose_range = 23.9
+ while read:
+ vec, read = source_read()
+ # transpose the samples
+ out = pitchshifter(vec)
+ # position in the file (between 0. and 1.)
+ percent_read = total_frames / float(source_read.duration)
+ # variable transpose rate (in semitones)
+ transpose = 2 * transpose_range * percent_read - transpose_range
+ # set transpose rate
+ pitchshifter.set_transpose(transpose)
+ # print the transposition
+ #print pitchshifter.get_transpose()
+ # write the output
+ sink_out(out, read)
+ total_frames += read
+
+ # end of file, print some results
+ outstr = "wrote %.2fs" % (total_frames / float(samplerate))
+ outstr += " (%d frames in" % total_frames
+ outstr += " %d blocks" % (total_frames // source_read.hop_size)
+ outstr += " at %dHz)" % source_read.samplerate
+ outstr += " from " + source_read.uri
+ outstr += " to " + sink_out.uri
+ print(outstr)
--
⑨