This sketch is an example of how to use the toArray method of an AudioBuffer to get a
copy of all the samples in 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 float array returned by toArray will always be the same length as the buffer's size. The values in
the array will always be between -1 and 1, unless you are using an AudioOutput
whose signals mix together to produce sample values outside of this range. If that is the case you will notice
it right away because the audio will sound distorted. You can use toArray to draw the waveform of the
audio in an AudioBuffer and it is the preferred method for doing so. The reason for this is due to
threading. The actual audio I/O happens in its own thread and calls back into the main thread (your sketch) when it
has a new buffer of samples. Because of this, when using get to draw the waveform, it is possible
(in fact highly likely) that the samples in the buffer will be changed while you are in the middle of drawing the
waveform, which will result in a waveform that seems to have discontinuities. When you use toArray you
are given a copy of the current contents of the buffer and it is guaranteed, thanks to synchronization, that
the entire array is created without the samples changing in the process.
Source code: toArray
Built with Processing