From 659900bfc9ad85e8f68e60d390aa40300d05aae8 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Sat, 17 Sep 2016 01:47:46 +0200 Subject: [PATCH] python/demos/demo_pitchshift.py: add simple pitch demo with a ramp --- python/demos/demo_pitchshift.py | 49 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 python/demos/demo_pitchshift.py diff --git a/python/demos/demo_pitchshift.py b/python/demos/demo_pitchshift.py new file mode 100755 index 00000000..a7cd06b0 --- /dev/null +++ b/python/demos/demo_pitchshift.py @@ -0,0 +1,49 @@ +#! /usr/bin/env python + +import sys +import aubio + +if __name__ == '__main__': + if len(sys.argv) < 3: + print('usage: %s [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) -- 2.11.0