1 /*! \page recording Recording
4 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:
12 int record( void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames,
13 double streamTime, RtAudioStreamStatus status, void *userData )
16 std::cout << "Stream overflow detected!" << std::endl;
18 // Do something with the data in the "inputBuffer" buffer.
26 if ( adc.getDeviceCount() < 1 ) {
27 std::cout << "\nNo audio devices found!\n";
31 RtAudio::StreamParameters parameters;
32 parameters.deviceId = adc.getDefaultInputDevice();
33 parameters.nChannels = 2;
34 parameters.firstChannel = 0;
35 unsigned int sampleRate = 44100;
36 unsigned int bufferFrames = 256; // 256 sample frames
39 adc.openStream( NULL, ¶meters, RTAUDIO_SINT16,
40 sampleRate, &bufferFrames, &record );
43 catch ( RtError& e ) {
49 std::cout << "\nRecording ... press <enter> to quit.\n";
50 std::cin.get( input );
60 if ( adc.isStreamOpen() ) adc.closeStream();
66 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 \e record() callback function performs no specific operations.