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