source: python/demos/demo_filter.py @ ad65346

feature/cnnfeature/crepefeature/pitchshiftfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretch
Last change on this file since ad65346 was 01f7598, checked in by Paul Brossier <piem@piem.org>, 8 years ago

python/demos/demo_filter.py: clean-up

  • Property mode set to 100755
File size: 994 bytes
RevLine 
[0b3c17b]1#! /usr/bin/env python
2
3
[01f7598]4def apply_filter(path):
[0b3c17b]5    from aubio import source, sink, digital_filter
[01f7598]6    from os.path import basename, splitext
7
8    # open input file, get its samplerate
[0b3c17b]9    s = source(path)
[01f7598]10    samplerate = s.samplerate
11
12    # create an A-weighting filter
[0b3c17b]13    f = digital_filter(7)
[01f7598]14    f.set_a_weighting(samplerate)
15    # alternatively, apply another filter
[0b3c17b]16
[01f7598]17    # create output file
18    o = sink("filtered_" + splitext(basename(path))[0] + ".wav", samplerate)
19
20    total_frames = 0
[0b3c17b]21    while True:
22        samples, read = s()
23        filtered_samples = f(samples)
[01f7598]24        o(filtered_samples, read)
[0b3c17b]25        total_frames += read
26        if read < s.hop_size: break
[01f7598]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))
[0b3c17b]32
33if __name__ == '__main__':
34    import sys
35    for f in sys.argv[1:]:
36        apply_filter(f)
Note: See TracBrowser for help on using the repository browser.