Onset detection is concerned with finding the start of a musical note immediately preceding the attack. Onset detection in conjunction with pitch detection are utilized in various processes such as pitch-shifting, synthesis, adaptive filtering and envelope generation, to name a few. Here, we focus on a very specific application of real-time (no latency) monophonic onset detection of percussive, picked, or plucked instruments, with sudden energy bursts at onsets that decay over time. For our use-case, we specialize on multichannel guitar audio signals (one channel per string).
Real-time onset detection is a tough nut to crack. I did not realize that onset detection is still an active research area before I tried to implement it myself. The usual way to detect onsets is to look for transients. Detecting attack transients by analyzing increases in amplitude or power may initially seem obvious when visualizing transients in audio waveforms of instruments such as the piano and the guitar, but it is not enough. When you look closer at the actual audio samples, you will realize that some details may not be so cleanly defined. Note transitions do not necessarily follow the ideal single note envelope.
Have a listen and look at this piano arpeggio, for example, and note that some softer notes do not have easily identifiable attack transients:
Download link: arpeggio-piano_01.wav
It becomes even more difficult when it comes to the guitar, taking into account playing techniques such as pull-offs and hammer-ons. Have a listen and look at this guitar sample (one of the samples I use in my tests):
Download link: hammer-pull.wav
Let us dig into the details to have a better view. The audio segment below indicates that the transition from a hammer-on to a pull-off may move from a higher level to a lower level and there’s no obvious transient spike to lock on.
Here’s another transition, now from a pull-off to a hammer-on:
Our eyes can clearly see the transition by looking at the waveform, but writing DSP code, or designing electronic circuits that detect these, can be deceptively difficult!
Let’s increase the difficulty even more! How about this transition, from another test file demonstrating two-handed hammer-ons and pull-offs:
Look at that. There’s no transient and no increase, nor decrease in energy level at all!
Having said all that and after having gone through this onset detection exploration, I think I may have something that works remarkably well. Here’s a snapshot of my onset detector in action, working on the pull-off, hammer-on example above:
The first waveform is the raw audio. The second waveform is a processed version of the audio, transforming each note into 75 millisecond staccatos, using the generated envelope (third waveform): a blackman taper window. The fourth and fifth waveforms are two (of three) parallel analysis algorithms for detecting onsets. Finally, the sixth waveform comprise the actual computed onsets.
Just to be clear, the taper is only for demonstration, shaping the envelope from the results obtained by the onset detector to give a staccato effect. The taper is not actually involved in onset detection.
Here’s the audio with the shaped envelope:
If there’s interest in how my onset detection algorithm works, tell me, and I’ll gladly present the code. It may be a good way to write about a specific application of the Q DSP library that I’ve been continually crafting in the recent years. The onset detector is built with components from that library.
Leave a comment here, or let’s discuss here: https://www.facebook.com/groups/cycfi, or here: https://discord.gg/yRtruR8Sn2.