You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.6KB

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