[aubio-user] Onset detection in Python

Paul Brossier piem at piem.org
Wed Mar 19 05:57:14 CET 2014


Hi Lukasz and all,

On 03/18/2014 04:46 AM, Lukasz Tracewski wrote:
> Thanks for the prompt answer!
>
>> why would you want to load the entire file in scipy, when you can
>> use aubio.source? :) it would avoid bloating your memory, and
>> should be much much faster. besides aubio.source knows how to read
>> much more than wav files, provided you compile aubio with libav or
>> ExtAudioFileRef.
>
> I need to do some filtering first (e.g. high-pass filter) before
> onsets can be detected. It seems more efficient and less prone to
> artifacts to process whole sample at once than a window at a time. My
> recordings are short (1 minute), so burden on memory is minimal.

Interesting, I just made some tests, and even with a 45 minutes long,
scipy is still 3 or 4 times slower. wow, memory is cheap nowadays, and
file access is slow. still, loading the entire file in memory is usually
*not* the best approach, at least not the one i prefer. :-)

of course, if speed is your main concern, i'm always happy to learn
about ways to make it faster!

> If I were to follow your advice then after loading a window I would
> have to first subject it to high-pass filter, then perform onset
> detection and stack output of the filter to get a complete
> high-passed sample at the end. To put into code (and following your
> example):
>
> out_sample = numpy.array([]) while True: samples, read = s()
> highpassed_samples = highpass_filter(samples) out_sample =
> numpy.hstack((samples, highpassed_samples)

why do you need this hstack line? you could use aubio.digital_filter and
use the highpassed_samples directly.

    https://github.com/piem/aubio/tree/master/src/temporal/filter.h

if you now the coefficients of your high pass filter, you can create it
with set_biquad:

   
https://github.com/piem/aubio/blob/develop/python/demos/demo_a_weighting.py

note that the filter object is called digital_filter, since filter is a
reserved keyword.

> if onset_detector(samples): onsets.append(onset_detector.get_last()
>
> ... which is not only twice slower, but also prone to border problems
> due to discontinuities in sample (I am reading only hop_size at a
> time).

as you will see in src/temporal/filter.c, the filter has a memory that
prevents discontinuities.

> On my GDrive you will find two spectrograms that should show I meant
> by this:
>
https://drive.google.com/folderview?id=0B46Cy3WOKgyJX1dsUng1T0FSUlk&usp=sharing
>
> sample_whole.pdf - highpass filter done over whole sample.
> sample_windowed.pdf - highpass filter done over windowed sample, read
> on the fly. simple.wav - example of what I am dealing with. It is
> actually quite clear sample, many are of much lower quality.
>
> Perhaps I am not doing something right? After all it seems quite
> common thing to do some pre-processing and filtering before onset
> detection.

very common indeed, and I will add some more examples to better document
the filtering features.

> Thanks for the hint about setting silence level!
>
> On a side note: the computing time is important since the program
> will have to process 10000 hours of recordings. It already does a
> nice job and helps in nature protection, and so is aubio :-).

that's great, i love thinking these lines of code can help a bit!

thanks for the feedback,

Paul


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 242 bytes
Desc: OpenPGP digital signature
URL: <http://lists.aubio.org/pipermail/aubio-user/attachments/20140319/6e508e85/attachment.sig>


More information about the aubio-user mailing list