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.

69 lines
1.7KB

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