feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5sampler
Last change
on this file since 1eb8c0e was
01f7598,
checked in by Paul Brossier <piem@piem.org>, 9 years ago
|
python/demos/demo_filter.py: clean-up
|
-
Property mode set to
100755
|
File size:
994 bytes
|
Line | |
---|
1 | #! /usr/bin/env python |
---|
2 | |
---|
3 | |
---|
4 | def apply_filter(path): |
---|
5 | from aubio import source, sink, digital_filter |
---|
6 | from os.path import basename, splitext |
---|
7 | |
---|
8 | # open input file, get its samplerate |
---|
9 | s = source(path) |
---|
10 | samplerate = s.samplerate |
---|
11 | |
---|
12 | # create an A-weighting filter |
---|
13 | f = digital_filter(7) |
---|
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 | |
---|
20 | total_frames = 0 |
---|
21 | while True: |
---|
22 | samples, read = s() |
---|
23 | filtered_samples = f(samples) |
---|
24 | o(filtered_samples, read) |
---|
25 | total_frames += read |
---|
26 | if read < s.hop_size: break |
---|
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)) |
---|
32 | |
---|
33 | if __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.