From 01f75985bafd2b9366e897b356abb9ab11656e51 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Tue, 10 May 2016 18:50:36 +0200 Subject: [PATCH] python/demos/demo_filter.py: clean-up --- python/demos/demo_filter.py | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/python/demos/demo_filter.py b/python/demos/demo_filter.py index 345e6510..10226cea 100755 --- a/python/demos/demo_filter.py +++ b/python/demos/demo_filter.py @@ -1,25 +1,34 @@ #! /usr/bin/env python -def apply_filter(path, params = {}): +def apply_filter(path): from aubio import source, sink, digital_filter - from os.path import basename, splitex, splitextt + from os.path import basename, splitext + + # open input file, get its samplerate s = source(path) + samplerate = s.samplerate + + # create an A-weighting filter f = digital_filter(7) - f.set_a_weighting(s.samplerate) - #f = digital_filter(3) - #f.set_biquad(...) - o = sink("filtered_" + splitext(basename(path))[0] + ".wav") - # Total number of frames read - total_frames = 0 + f.set_a_weighting(samplerate) + # alternatively, apply another filter + # create output file + o = sink("filtered_" + splitext(basename(path))[0] + ".wav", samplerate) + + total_frames = 0 while True: samples, read = s() filtered_samples = f(samples) - o(samples, read) + o(filtered_samples, read) total_frames += read if read < s.hop_size: break - print "filtered", s.uri, "to", o.uri, "using an A-weighting filter" + + duration = total_frames / float(samplerate) + print ("read {:s}".format(s.uri)) + print ("applied A-weighting filtered ({:d} Hz)".format(samplerate)) + print ("wrote {:s} ({:.2f} s)".format(o.uri, duration)) if __name__ == '__main__': import sys -- 2.11.0