Showing the changes to python (1 of 1 file). Show all
Unified · Split
| @@ -1,25 +1,34 @@ | ||
| 1 | 1 | #! /usr/bin/env python |
| 2 | 2 | |
| 3 | 3 | |
| 4 | −def apply_filter(path, params = {}): | |
| 4 | +def apply_filter(path): | |
| 5 | 5 | from aubio import source, sink, digital_filter |
| 6 | − from os.path import basename, splitex, splitextt | |
| 6 | + from os.path import basename, splitext | |
| 7 | + | |
| 8 | + # open input file, get its samplerate | |
| 7 | 9 | s = source(path) |
| 10 | + samplerate = s.samplerate | |
| 11 | + | |
| 12 | + # create an A-weighting filter | |
| 8 | 13 | f = digital_filter(7) |
| 9 | − f.set_a_weighting(s.samplerate) | |
| 10 | − #f = digital_filter(3) | |
| 11 | − #f.set_biquad(...) | |
| 12 | − o = sink("filtered_" + splitext(basename(path))[0] + ".wav") | |
| 13 | − # Total number of frames read | |
| 14 | − total_frames = 0 | |
| 14 | + f.set_a_weighting(samplerate) | |
| 15 | + # alternatively, apply another filter | |
| 15 | 16 | |
| 17 | + # create output file | |
| 18 | + o = sink("filtered_" + splitext(basename(path))[0] + ".wav", samplerate) | |
| 19 | + | |
| 20 | + total_frames = 0 | |
| 16 | 21 | while True: |
| 17 | 22 | samples, read = s() |
| 18 | 23 | filtered_samples = f(samples) |
| 19 | − o(samples, read) | |
| 24 | + o(filtered_samples, read) | |
| 20 | 25 | total_frames += read |
| 21 | 26 | if read < s.hop_size: break |
| 22 | − print "filtered", s.uri, "to", o.uri, "using an A-weighting filter" | |
| 27 | + | |
| 28 | + duration = total_frames / float(samplerate) | |
| 29 | + print ("read {:s}".format(s.uri)) | |
| 30 | + print ("applied A-weighting filtered ({:d} Hz)".format(samplerate)) | |
| 31 | + print ("wrote {:s} ({:.2f} s)".format(o.uri, duration)) | |
| 23 | 32 | |
| 24 | 33 | if __name__ == '__main__': |
| 25 | 34 | import sys |