play_client_main.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*************************************************************************/
  2. /* */
  3. /* Language Technologies Institute */
  4. /* Carnegie Mellon University */
  5. /* Copyright (c) 2000 */
  6. /* All Rights Reserved. */
  7. /* */
  8. /* Permission is hereby granted, free of charge, to use and distribute */
  9. /* this software and its documentation without restriction, including */
  10. /* without limitation the rights to use, copy, modify, merge, publish, */
  11. /* distribute, sublicense, and/or sell copies of this work, and to */
  12. /* permit persons to whom this work is furnished to do so, subject to */
  13. /* the following conditions: */
  14. /* 1. The code must retain the above copyright notice, this list of */
  15. /* conditions and the following disclaimer. */
  16. /* 2. Any modifications must be clearly marked as such. */
  17. /* 3. Original authors' names are not deleted. */
  18. /* 4. The authors' names are not used to endorse or promote products */
  19. /* derived from this software without specific prior written */
  20. /* permission. */
  21. /* */
  22. /* CARNEGIE MELLON UNIVERSITY AND THE CONTRIBUTORS TO THIS WORK */
  23. /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
  24. /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
  25. /* SHALL CARNEGIE MELLON UNIVERSITY NOR THE CONTRIBUTORS BE LIABLE */
  26. /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
  27. /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
  28. /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
  29. /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
  30. /* THIS SOFTWARE. */
  31. /* */
  32. /*************************************************************************/
  33. /* Author: Alan W Black (awb@cs.cmu.edu) */
  34. /* Date: October 2000 */
  35. /*************************************************************************/
  36. /* */
  37. /* Read and play a waveform by sending it to a server */
  38. /* */
  39. /*************************************************************************/
  40. #include <stdio.h>
  41. #include <stdlib.h>
  42. #include "cst_wave.h"
  43. #include "cst_audio.h"
  44. int play_client_main_usage()
  45. {
  46. printf("simple audio server: client program\n");
  47. printf("usage: play_client [-s SERVERNAME] [-p PORTNUMBER] [-e ENCODING ] WAVEFORM0 ...\n");
  48. printf("Send waveforms to a named audio sever\n");
  49. printf("Default server is \"localhost\" default port is %d\n",
  50. CST_AUDIO_DEFAULT_PORT);
  51. printf("Default encoding is short, but you can choose ulaw too\n");
  52. printf("If encoding is ulaw, transfer is as 8 bit mulaw (i.e. quicker)\n");
  53. return 0;
  54. }
  55. int main(int argc, char **argv)
  56. {
  57. cst_wave *w;
  58. int port;
  59. char *server;
  60. char *encoding;
  61. int i,iw;
  62. port = CST_AUDIO_DEFAULT_PORT;
  63. server = CST_AUDIO_DEFAULT_SERVER;
  64. encoding = CST_AUDIO_DEFAULT_ENCODING;
  65. if (argc == 1)
  66. {
  67. play_client_main_usage();
  68. return 1;
  69. }
  70. if ((cst_streq("-h",argv[1])) ||
  71. (cst_streq("-help",argv[1])) ||
  72. (cst_streq("--help",argv[1])))
  73. {
  74. play_client_main_usage();
  75. return 1;
  76. }
  77. iw = 1;
  78. if (cst_streq("-s",argv[iw]))
  79. {
  80. if (argc < iw+1)
  81. {
  82. fprintf(stderr,"ERROR: no servername given\n");
  83. play_client_main_usage();
  84. return 1;
  85. }
  86. server = argv[iw+1];
  87. iw+=2;
  88. }
  89. if (cst_streq("-p",argv[iw]))
  90. {
  91. if (argc < iw+1)
  92. {
  93. fprintf(stderr,"ERROR: no port given\n");
  94. play_client_main_usage();
  95. return 1;
  96. }
  97. port = atoi(argv[iw+1]);
  98. iw+=2;
  99. }
  100. if (cst_streq("-e",argv[iw]))
  101. {
  102. if (argc < iw+1)
  103. {
  104. fprintf(stderr,"ERROR: no encoding given\n");
  105. play_client_main_usage();
  106. return 1;
  107. }
  108. encoding = argv[iw+1];
  109. iw+=2;
  110. }
  111. for (i=iw; i<argc; i++)
  112. {
  113. w = new_wave();
  114. if (cst_wave_load_riff(w,argv[i]) != CST_OK_FORMAT)
  115. {
  116. fprintf(stderr,
  117. "play_wave: can't read file or wrong format \"%s\"\n",
  118. argv[i]);
  119. continue;
  120. }
  121. play_wave_client(w,server,port,encoding);
  122. delete_wave(w);
  123. }
  124. return 0;
  125. }