[aubio-user] Onset detection in Python

Lukasz Tracewski lukasz.tracewski at outlook.com
Tue Mar 18 08:46:35 CET 2014


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. 

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)
     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).

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.

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 :-).


Cheers,
Lucas

> 
> > Here is what I have:
> > 
> > 
> > onset_detector = onset("energy", window_size, hop_size,
> > sample_rate) onsets = []
> 
> you will want to use "default", "ernergy" is by far the worst method
> of all.
> 
> > windowed_sample = numpy.array_split(sample, numpy.arange(hop_size,
> > len(sample), hop_size)) for frame in windowed_sample: if
> > onset_detector(frame): onsets.append(onset_detector.get_last())
> 
> that looks correct.
> 
> > So in fact it simulates reading file from a disc, following what is
> >  in examples. One of problems I have with this approach is that I
> > am always detecting onset at zero. Is there a smarter solution?
> 
> if the file starts with a frame which level is higher than the silence
> threshold, that first frame will be marked as an onset.
> 
> so you could try using onset_detector.set_silence(-60) for instance, just
> after creating onset_detector. Default value is -70, in dB SPL.
> 
> > Thanks for the great work!
> 
> you're welcome! :)
> 
> Paul
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG/MacGPG2 v2.0.18 (Darwin)
> Comment: GPGTools - http://gpgtools.org
> Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
> 
> iEYEARECAAYFAlMndBcACgkQkuC958YALL1vBgCgrS4TL3QbsEIewOsavSxaxObB
> Ap4AoKhB5qqadVdbCXpMJnOkpF6u+q8w
> =9NVU
> -----END PGP SIGNATURE-----
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.aubio.org/pipermail/aubio-user/attachments/20140318/ab3e6f5f/attachment.html>


More information about the aubio-user mailing list