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.

103 lines
2.1KB

  1. /******************************************/
  2. /*
  3. call_inout.cpp
  4. by Gary P. Scavone, 2001
  5. Records from default input and passes it
  6. through to the output. Takes number of
  7. channels and sample rate as input arguments.
  8. Uses callback functionality.
  9. */
  10. /******************************************/
  11. #include "RtAudio.h"
  12. #include <iostream>
  13. /*
  14. typedef signed long MY_TYPE;
  15. #define FORMAT RTAUDIO_SINT24
  16. typedef char MY_TYPE;
  17. #define FORMAT RTAUDIO_SINT8
  18. typedef signed short MY_TYPE;
  19. #define FORMAT RTAUDIO_SINT16
  20. typedef signed long MY_TYPE;
  21. #define FORMAT RTAUDIO_SINT32
  22. typedef float MY_TYPE;
  23. #define FORMAT RTAUDIO_FLOAT32
  24. */
  25. typedef double MY_TYPE;
  26. #define FORMAT RTAUDIO_FLOAT64
  27. void usage(void) {
  28. /* Error function in case of incorrect command-line
  29. argument specifications
  30. */
  31. std::cout << "\nuseage: call_inout N fs device\n";
  32. std::cout << " where N = number of channels,\n";
  33. std::cout << " fs = the sample rate,\n";
  34. std::cout << " and device = the device to use (default = 0).\n\n";
  35. exit(0);
  36. }
  37. int inout(char *buffer, int buffer_size, void *)
  38. {
  39. // Surprise!! We do nothing to pass the data through.
  40. return 0;
  41. }
  42. int main(int argc, char *argv[])
  43. {
  44. int chans, fs, device = 0;
  45. RtAudio *audio = 0;
  46. char input;
  47. // minimal command-line checking
  48. if (argc != 3 && argc != 4 ) usage();
  49. chans = (int) atoi(argv[1]);
  50. fs = (int) atoi(argv[2]);
  51. if ( argc == 4 )
  52. device = (int) atoi(argv[3]);
  53. // Open the realtime output device
  54. int buffer_size = 512;
  55. try {
  56. audio = new RtAudio( device, chans, device, chans,
  57. FORMAT, fs, &buffer_size, 8 );
  58. }
  59. catch (RtError &error) {
  60. error.printMessage();
  61. exit(EXIT_FAILURE);
  62. }
  63. try {
  64. audio->setStreamCallback(&inout, NULL);
  65. audio->startStream();
  66. }
  67. catch (RtError &error) {
  68. error.printMessage();
  69. goto cleanup;
  70. }
  71. std::cout << "\nRunning ... press <enter> to quit (buffer size = " << buffer_size << ").\n";
  72. std::cin.get(input);
  73. try {
  74. audio->stopStream();
  75. }
  76. catch (RtError &error) {
  77. error.printMessage();
  78. }
  79. cleanup:
  80. audio->closeStream();
  81. delete audio;
  82. return 0;
  83. }