20 April 2007

EARdetector~

EARdetector~


An envelope, attack and rest detector. This blocks tells us the instantaneous RMS and peak values of a signal, both in dB and amplitude scale. It also gives a bang when an attack is detected or a rest of more than a specified time constant is registered. The attack and rest detection is based on the envelope of the signal.

version

v1.0: built 20/04/2007 with Pd v0.40-2 [pd][pdf]

interface

Input 1: the signal you want to follow. The attack and rest detectors will only work nicely when this signal is amplified to the loudest level without clipping. This is like adjusting the gain on a mixer.

Output 1: in this output three results are packed: a smoothed RMS signal, the instantaneous RMS signal (both in dB) and the smoothed amplitude signal (between 0 and 1)
Output 2: in this output two results are packed: a smoothed peak signal in dB and the amplitude signal of it.
Output 3: receives a bang if an attack is detected. This happens when a threshold of 55dB is reached and the signal was lower than 45dB before it.
Output 4: receives a bang if a rest is detected. This happens whenever a threshold of 45dB is not reached for longer then 100ms

When loaded the rest outlet gives a bang after the specified delay.

implementation

The basic block used here is the env~ block. It's output is in dB. To calculate the RMS amplitude value a dbtorms block has to be inserted.
TO DO: test if different arguments give better results (the argument stands for the interval in msec used to calculate the RMS on)
This signal is smoothed by running it through three lowpass filters with a cutoff frequency of 1Hz. Because the filters work on audio signals, a snapshot~ block had to be attached.
In the help patch about the env~ block that is found in a standard version of Pd, one sees that the peak value is 3.01dB higher than the RMS value.
The different results are packed to two outlets, the first outputs all RMS values, the second all peak values.
The attack detection works as a state machine with two states. When the state is 0 and the signal reaches 55dB or higher, the state becomes 1. When the state is 1 and the signal gets lower than 45dB, the state becomes 0. It might be necessary to adapt these thresholds later.
Also the rest detector works a two-state state machine. If a signal is more than 100msec under the threshold of 45dB the state changes to 1. It might be necessary to adapt these thresholds later.





No comments: