This sketch is an example of how to use the level method of an AudioBuffer to get the
level of one of an AudioSource's sample buffers. The classes in Minim that extend AudioSource
and therefore inherit the left, right, and mix buffers of that class, are
AudioInput, AudioOutput, AudioSample, and AudioPlayer.
Not coincidentally, these are also all of the classes in Minim that are Recordable.
The value returned by level will always be between zero and one, but you may find that the value
returned is often smaller than you expect. The level is found by calculating the root-mean-squared amplitude of the
samples in the buffer. First the samples are all squared, then the average (mean) of all the samples is taken (sum
and then divide by the number of samples), then the square root of the average is returned. This is why the range can be
determined as [0, 1] because the largest value a squared sample can have is 1. However, in order for the RMS amplitude
to equal 1, every sample must have either -1 or 1 as its value (amplitude). This is only going to be the case
if your sound is a square wave at full amplitude. If your sound is a song or other complex sound source,
the level is generally going to be much lower.
Source code: level
Built with Processing