Using a microphone
The way to input sound data from a microphone or other audio input device is similar to the sound output considered earlier, with small changes:
Add a sound stream object and function for the audio input to the
testApp
class declaration as follows:ofSoundStream soundStream; void audioReceived( float *input, int bufferSize, int nChannels );
At the end of the
testApp::setup()
function definition, add the following:soundStream.setup( this, 0, 1, 44100, 512, 4 );
Here,
this
is a pointer to ourtestApp
object which will receive the microphone's sound data by calling ourtestApp::audioReceived
function.Subsequently,
0
is the number of output channels (hence, no output),1
is the number of input channels (hence, mono input),44100
is a sample rate, that is, the received number of audio samples per second.The last two parameters
512
and4
are the size of the buffer for audio samples and the number of buffers.Add function definition as follows:
void testApp::audioReceived( ...