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.

81 lines
2.3KB

  1. /******************************************/
  2. /*
  3. Example program to output N channels of audio
  4. data over a network socket connection.
  5. by Gary P. Scavone, 2000
  6. This program will load a specified WAV, SND, AIFF, STK RAW, or
  7. MAT-file formatted file. The output data format is set for signed
  8. 16-bit integers. However, it is easy to change the InetWvOut
  9. setting to any of the other defined StkFormats. If using tcpIn, it
  10. will be necessary to change the expected data format there as well.
  11. The class InetWvOut first attempts to establish a socket connection
  12. to a socket server running on port 2006. Therefore, this program
  13. needs to be started AFTER the streaming server.
  14. */
  15. /******************************************/
  16. #include "FileWvIn.h"
  17. #include "InetWvOut.h"
  18. #include <cstdlib>
  19. using namespace stk;
  20. void usage(void) {
  21. // Error function in case of incorrect command-line
  22. // argument specifications.
  23. std::cout << "\nuseage: inetOut file host <rate>\n";
  24. std::cout << " where file = the file to load,\n";
  25. std::cout << " host = the hostname where the receiving\n";
  26. std::cout << " application is running.\n";
  27. std::cout << " and rate = an optional playback rate for the file.\n";
  28. std::cout << " (default = 1.0, can be negative)\n\n";
  29. exit( 0 );
  30. }
  31. int main( int argc, char *argv[] )
  32. {
  33. // Minimal command-line checking.
  34. if ( argc < 3 || argc > 4 ) usage();
  35. FileWvIn input;
  36. InetWvOut output;
  37. // Load the file.
  38. try {
  39. input.openFile( (char *)argv[1] );
  40. }
  41. catch ( StkError & ) {
  42. exit( 1 );
  43. }
  44. // Set the global STK sample rate to the file rate.
  45. Stk::setSampleRate( input.getFileRate() );
  46. // Set input read rate.
  47. double rate = 1.0;
  48. if ( argc == 4 ) rate = atof( argv[3] );
  49. input.setRate( rate );
  50. // Find out how many channels we have.
  51. int channels = input.channelsOut();
  52. StkFrames frames( 4096, channels );
  53. // Attempt to connect to the socket server.
  54. try {
  55. //output.connect( 2006, Socket::PROTO_UDP, (char *)argv[2], channels, Stk::STK_SINT16 );
  56. output.connect( 2006, Socket::PROTO_TCP, (char *)argv[2], channels, Stk::STK_SINT16 );
  57. }
  58. catch ( StkError & ) {
  59. exit( 1 );
  60. }
  61. // Here's the runtime loop
  62. while ( !input.isFinished() )
  63. output.tick( input.tick( frames ) );
  64. return 0;
  65. }