[7175ed4] | 1 | #! /usr/bin/env python |
---|
[d3b1eb1] | 2 | |
---|
| 3 | import sys |
---|
| 4 | from aubio import source, sink, pvoc, tss |
---|
| 5 | |
---|
| 6 | if __name__ == '__main__': |
---|
[d0faeca] | 7 | if len(sys.argv) < 2: |
---|
[4120fbc] | 8 | print('usage: %s <inputfile> <outputfile_transient> <outputfile_steady>' % sys.argv[0]) |
---|
[d0faeca] | 9 | sys.exit(1) |
---|
| 10 | |
---|
| 11 | samplerate = 44100 |
---|
[4120fbc] | 12 | win_s = 1024 # fft size |
---|
[773a7f3] | 13 | hop_s = win_s // 8 # block size |
---|
[d0faeca] | 14 | |
---|
| 15 | f = source(sys.argv[1], samplerate, hop_s) |
---|
| 16 | g = sink(sys.argv[2], samplerate) |
---|
| 17 | h = sink(sys.argv[3], samplerate) |
---|
| 18 | |
---|
| 19 | pva = pvoc(win_s, hop_s) # a phase vocoder |
---|
| 20 | pvb = pvoc(win_s, hop_s) # another phase vocoder |
---|
| 21 | t = tss(win_s, hop_s) # transient steady state separation |
---|
| 22 | |
---|
[773a7f3] | 23 | t.set_threshold(0.01) |
---|
| 24 | t.set_alpha(3.) |
---|
| 25 | t.set_beta(4.) |
---|
[d0faeca] | 26 | |
---|
| 27 | read = hop_s |
---|
| 28 | |
---|
| 29 | while read: |
---|
| 30 | samples, read = f() # read file |
---|
| 31 | spec = pva(samples) # compute spectrum |
---|
| 32 | trans_spec, stead_spec = t(spec) # transient steady-state separation |
---|
| 33 | transients = pva.rdo(trans_spec) # overlap-add synthesis of transients |
---|
| 34 | steadstate = pvb.rdo(stead_spec) # overlap-add synthesis of steady states |
---|
| 35 | g(transients, read) # write transients to output |
---|
| 36 | h(steadstate, read) # write steady states to output |
---|
| 37 | |
---|
| 38 | del f, g, h # finish writing the files now |
---|
[773a7f3] | 39 | sys.exit(0) |
---|
[d0faeca] | 40 | |
---|
| 41 | from demo_spectrogram import get_spectrogram |
---|
| 42 | from pylab import subplot, show |
---|
| 43 | subplot(311) |
---|
| 44 | get_spectrogram(sys.argv[1]) |
---|
| 45 | subplot(312) |
---|
| 46 | get_spectrogram(sys.argv[2]) |
---|
| 47 | subplot(313) |
---|
| 48 | get_spectrogram(sys.argv[3]) |
---|
[8fb567c] | 49 | show() |
---|