6316a5c9adc3db7b0de0dc27d04933e76cd7a5a0
[rtaudio.git] / doc / doxygen / recording.txt
1 /*! \page recording Recording
2
3
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:
5
6 \code
7 #include "RtAudio.h"
8 #include <iostream>
9
10 int record( void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames,
11          double streamTime, RtAudioStreamStatus status, void *userData )
12 {
13   if ( status )
14     std::cout << "Stream overflow detected!" << std::endl;
15
16   // Do something with the data in the "inputBuffer" buffer.
17
18   return 0;
19 }
20
21 int main()
22 {
23   RtAudio adc;
24   if ( adc.getDeviceCount() < 1 ) {
25     std::cout << "\nNo audio devices found!\n";
26     exit( 0 );
27   }
28
29   RtAudio::StreamParameters parameters;
30   parameters.deviceId = adc.getDefaultInputDevice();
31   parameters.nChannels = 2;
32   parameters.firstChannel = 0;
33   unsigned int sampleRate = 44100;
34   unsigned int bufferFrames = 256; // 256 sample frames
35
36   try {
37     adc.openStream( NULL, &parameters, RTAUDIO_SINT16,
38                     sampleRate, &bufferFrames, &record );
39     adc.startStream();
40   }
41   catch ( RtError& e ) {
42     e.printMessage();
43     exit( 0 );
44   }
45   
46   char input;
47   std::cout << "\nRecording ... press <enter> to quit.\n";
48   std::cin.get( input );
49
50   try {
51     // Stop the stream
52     adc.stopStream();
53   }
54   catch (RtError& e) {
55     e.printMessage();
56   }
57
58   if ( adc.isStreamOpen() ) adc.closeStream();
59
60   return 0;
61 }
62 \endcode
63
64 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.
65
66 */