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.

85 lines
2.4KB

  1. /******************************************/
  2. /*
  3. Example program to read N channels of audio data that are streamed
  4. over a network connection.
  5. by Gary P. Scavone, 2000
  6. NOTE: This program makes use of blocking audio input/output
  7. routines. On systems where the underlying audio API is based on a
  8. callback scheme (Macintosh OS-X, Windows ASIO, and Linux JACK),
  9. these routines are not fully robust (over/underruns can happen with
  10. some frequency). See the STK tutorial for example programs using
  11. callback schemes and/or visit the RtAudio tutorial page
  12. (http://music.mcgill.ca/~gary/rtaudio/) for more information.
  13. This program is currently written to play the input data in
  14. realtime. However, it is simple to replace the instance of RtWvOut
  15. with FileWvOut for writing to a soundfile.
  16. The streamed data format is assumed to be signed 16-bit integers.
  17. However, both InetWvIn and InetWvOut can be initialized to
  18. read/write any of the defined StkFormats.
  19. The class InetWvIn sets up a socket server and waits for a
  20. connection. Therefore, this program needs to be started before the
  21. streaming client. This program will terminate when the socket
  22. connection is closed.
  23. */
  24. /******************************************/
  25. #include "InetWvIn.h"
  26. #include "RtWvOut.h"
  27. #include <cstdlib>
  28. using namespace stk;
  29. void usage(void) {
  30. // Error function in case of incorrect command-line
  31. // argument specifications.
  32. std::cout << "\nuseage: inetIn N fs \n";
  33. std::cout << " where N = number of channels,\n";
  34. std::cout << " and fs = the data sample rate.\n\n";
  35. exit( 0 );
  36. }
  37. int main(int argc, char *argv[])
  38. {
  39. // Minimal command-line checking.
  40. if ( argc != 3 ) usage();
  41. Stk::showWarnings( true );
  42. Stk::setSampleRate( atof( argv[2] ) );
  43. int channels = (int) atoi( argv[1] );
  44. StkFrames frame( 1, channels );
  45. // Create instances and pointers.
  46. InetWvIn input;
  47. RtWvOut *output = 0;
  48. // Listen for a socket connection.
  49. try {
  50. //input.listen( 2006, channels, Stk::STK_SINT16, Socket::PROTO_UDP );
  51. input.listen( 2006, channels, Stk::STK_SINT16, Socket::PROTO_TCP );
  52. }
  53. catch ( StkError & ) {
  54. goto cleanup;
  55. }
  56. // Open the realtime output device.
  57. try {
  58. output = new RtWvOut( channels );
  59. }
  60. catch ( StkError & ) {
  61. goto cleanup;
  62. }
  63. // Here's the runtime loop.
  64. while ( input.isConnected() )
  65. output->tick( input.tick( frame ) );
  66. cleanup:
  67. delete output;
  68. return 0;
  69. }