Various updates and fixes before 4.0.5 release (GS).
[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 #include <cstdlib>
10 #include <cstring>
11
12 int record( void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames,
13          double streamTime, RtAudioStreamStatus status, void *userData )
14 {
15   if ( status )
16     std::cout << "Stream overflow detected!" << std::endl;
17
18   // Do something with the data in the "inputBuffer" buffer.
19
20   return 0;
21 }
22
23 int main()
24 {
25   RtAudio adc;
26   if ( adc.getDeviceCount() < 1 ) {
27     std::cout << "\nNo audio devices found!\n";
28     exit( 0 );
29   }
30
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
37
38   try {
39     adc.openStream( NULL, &parameters, RTAUDIO_SINT16,
40                     sampleRate, &bufferFrames, &record );
41     adc.startStream();
42   }
43   catch ( RtError& e ) {
44     e.printMessage();
45     exit( 0 );
46   }
47   
48   char input;
49   std::cout << "\nRecording ... press <enter> to quit.\n";
50   std::cin.get( input );
51
52   try {
53     // Stop the stream
54     adc.stopStream();
55   }
56   catch (RtError& e) {
57     e.printMessage();
58   }
59
60   if ( adc.isStreamOpen() ) adc.closeStream();
61
62   return 0;
63 }
64 \endcode
65
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.
67
68 */