Using RtAudio for audio input is almost identical to the way it is used for playback. Here's the blocking playback example rewritten for recording:
#include <iostream>
#include <cstdlib>
#include <cstring>
int record( void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames,
{
if ( status )
std::cout << "Stream overflow detected!" << std::endl;
return 0;
}
int main()
{
if ( deviceIds.size() < 1 ) {
std::cout << "\nNo audio devices found!\n";
exit( 0 );
}
unsigned int sampleRate = 44100;
unsigned int bufferFrames = 256;
if ( adc.
openStream( NULL, ¶meters, RTAUDIO_SINT16,
sampleRate, &bufferFrames, &record ) ) {
std::cout <<
'\n' << adc.
getErrorText() <<
'\n' << std::endl;
exit( 0 );
}
goto cleanup;
}
char input;
std::cout << "\nRecording ... press <enter> to quit.\n";
std::cin.get( input );
cleanup:
return 0;
}
In this example, we pass the address of the stream parameter structure as the second argument of the RtAudio::openStream() function and pass a NULL value for the output stream parameters. In this example, the record() callback function performs no specific operations.