Showing the changes to python (1 of 1 file). Show all
Unified · Split
| @@ -1,25 +1,34 @@ | |||
| 1 | #! /usr/bin/env python | 1 | #! /usr/bin/env python |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | def apply_filter(path, params = {}): | 4 | def apply_filter(path): |
| 5 | from aubio import source, sink, digital_filter | 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 | s = source(path) | 9 | s = source(path) |
| 10 | samplerate = s.samplerate | ||
| 11 | |||
| 12 | # create an A-weighting filter | ||
| 8 | f = digital_filter(7) | 13 | f = digital_filter(7) |
| 9 | f.set_a_weighting(s.samplerate) | 14 | f.set_a_weighting(samplerate) |
| 10 | #f = digital_filter(3) | 15 | # alternatively, apply another filter |
| 11 | #f.set_biquad(...) | ||
| 12 | o = sink("filtered_" + splitext(basename(path))[0] + ".wav") | ||
| 13 | # Total number of frames read | ||
| 14 | total_frames = 0 | ||
| 15 | 16 | ||
| 17 | # create output file | ||
| 18 | o = sink("filtered_" + splitext(basename(path))[0] + ".wav", samplerate) | ||
| 19 | |||
| 20 | total_frames = 0 | ||
| 16 | while True: | 21 | while True: |
| 17 | samples, read = s() | 22 | samples, read = s() |
| 18 | filtered_samples = f(samples) | 23 | filtered_samples = f(samples) |
| 19 | o(samples, read) | 24 | o(filtered_samples, read) |
| 20 | total_frames += read | 25 | total_frames += read |
| 21 | if read < s.hop_size: break | 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 | if __name__ == '__main__': | 33 | if __name__ == '__main__': |
| 25 | import sys | 34 | import sys |