Ignore:
Timestamp:
May 10, 2016, 6:50:36 PM (9 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
a4575c4
Parents:
73d38d5
Message:

python/demos/demo_filter.py: clean-up

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/demos/demo_filter.py

    r73d38d5 r01f7598  
    22
    33
    4 def apply_filter(path, params = {}):
     4def apply_filter(path):
    55    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
    79    s = source(path)
     10    samplerate = s.samplerate
     11
     12    # create an A-weighting filter
    813    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    f.set_a_weighting(samplerate)
     15    # alternatively, apply another filter
     16
     17    # create output file
     18    o = sink("filtered_" + splitext(basename(path))[0] + ".wav", samplerate)
     19
    1420    total_frames = 0
    15 
    1621    while True:
    1722        samples, read = s()
    1823        filtered_samples = f(samples)
    19         o(samples, read)
     24        o(filtered_samples, read)
    2025        total_frames += read
    2126        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))
    2332
    2433if __name__ == '__main__':
Note: See TracChangeset for help on using the changeset viewer.