cst_audio.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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: August 2000 */
  35. /*************************************************************************/
  36. /* */
  37. /* Audio */
  38. /* */
  39. /*************************************************************************/
  40. #ifndef _CST_AUDIO_H__
  41. #define _CST_AUDIO_H__
  42. #include "cst_wave.h"
  43. #include "cst_hrg.h"
  44. #ifdef CST_AUDIO_WIN32
  45. #define CST_AUDIOBUFFSIZE 8092
  46. #else
  47. #define CST_AUDIOBUFFSIZE 128
  48. #endif
  49. #define CST_AUDIO_DEFAULT_PORT 1746
  50. #define CST_AUDIO_DEFAULT_SERVER "localhost"
  51. #define CST_AUDIO_DEFAULT_ENCODING "short"
  52. typedef enum {
  53. CST_AUDIO_LINEAR16 = 0,
  54. CST_AUDIO_LINEAR8,
  55. CST_AUDIO_MULAW
  56. } cst_audiofmt;
  57. /* Returns the number of bytes per sample for a given audio format */
  58. int audio_bps(cst_audiofmt fmt);
  59. typedef struct cst_audiodev_struct {
  60. int sps, real_sps;
  61. int channels, real_channels;
  62. cst_audiofmt fmt, real_fmt;
  63. int byteswap;
  64. cst_rateconv *rateconv;
  65. void *platform_data;
  66. } cst_audiodev;
  67. /* Generic audio functions */
  68. cst_audiodev *audio_open(int sps, int channels, cst_audiofmt fmt);
  69. int audio_close(cst_audiodev *ad);
  70. int audio_write(cst_audiodev *ad, void *buff, int num_bytes);
  71. int audio_flush(cst_audiodev *ad); /* wait for buffers to empty */
  72. int audio_drain(cst_audiodev *ad); /* empty buffers now */
  73. /* Generic high level audio functions */
  74. int play_wave(cst_wave *w);
  75. int play_wave_sync(cst_wave *w, cst_relation *rel,
  76. int (*call_back)(cst_item *));
  77. int play_wave_client(cst_wave *w, const char *servername, int port,
  78. const char *encoding);
  79. int auserver(int port);
  80. /* Play wave to specified device */
  81. int play_wave_device(cst_wave *w, cst_audiodev *ad);
  82. /* Output to a file as if its an audio device */
  83. cst_audiodev *audio_open_file(int sps, int channels, cst_audiofmt fmt,
  84. const char *filename);
  85. int audio_close_file(cst_audiodev *ad);
  86. int audio_write_file(cst_audiodev *ad, void *buff, int num_bytes);
  87. int audio_drain_file(cst_audiodev *ad);
  88. int audio_flush_file(cst_audiodev *ad);
  89. /* For audio streaming */
  90. #define CST_AUDIO_STREAM_STOP -1
  91. #define CST_AUDIO_STREAM_CONT 0
  92. typedef struct cst_audio_streaming_info_struct
  93. {
  94. int min_buffsize;
  95. int (*asc)(const cst_wave *w,int start,int size,
  96. int last, struct cst_audio_streaming_info_struct *asi);
  97. const cst_utterance *utt; /* in case you need more information */
  98. const cst_item *item; /* because you'll probably want this */
  99. /* But this is *not* updated automatically */
  100. void *userdata;
  101. } cst_audio_streaming_info;
  102. cst_audio_streaming_info *new_audio_streaming_info();
  103. void delete_audio_streaming_info(cst_audio_streaming_info *asi);
  104. CST_VAL_USER_TYPE_DCLS(audio_streaming_info,cst_audio_streaming_info)
  105. typedef int (*cst_audio_stream_callback)(const cst_wave *w,int start,int size,
  106. int last, cst_audio_streaming_info *asi);
  107. /* An example audio streaming callback function src/audio/au_streaming.c */
  108. int audio_stream_chunk(const cst_wave *w, int start, int size,
  109. int last, cst_audio_streaming_info *asi);
  110. #endif