Debian Codegraph @

src/audio/au_streaming.c

raw
1 /*************************************************************************/
2 /* */
3 /* Language Technologies Institute */
4 /* Carnegie Mellon University */
5 /* Copyright (c) 2008 */
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 ([email protected]) */
34 /* Date: November 2008 */
35 /*************************************************************************/
36 /* */
37 /* Support for audio streaming. */
38 /* */
39 /* When switched on you get called with cst_wave with a start and size */
40 /* at least as big as the requested buffer size (except for last chunk */
41 /* */
42 /*************************************************************************/
43
44 #include "cst_string.h"
45 #include "cst_wave.h"
46 #include "cst_audio.h"
47
48 CST_VAL_REGISTER_TYPE(audio_streaming_info,cst_audio_streaming_info)
49
50 cst_audio_streaming_info *new_audio_streaming_info(void)
51 {
52 cst_audio_streaming_info *asi =
53 cst_alloc(struct cst_audio_streaming_info_struct,1);
54
55 asi->min_buffsize = 256;
56 asi->asc = NULL;
57 asi->userdata = NULL;
58
59 return asi;
60 }
61
62 void delete_audio_streaming_info(cst_audio_streaming_info *asi)
63 {
64 if (asi)
65 cst_free(asi);
66 return;
67 }
68
69 int audio_stream_chunk(const cst_wave *w, int start, int size,
70 int last, cst_audio_streaming_info *asi)
71 {
72 /* Called with new samples from start for size samples */
73 /* last is true if this is the last segment. */
74 /* This is really just and example that you can copy for you streaming */
75 /* function */
76 /* This particular example is *not* thread safe */
77
78 static cst_audiodev *ad = 0;
79
80 if (start == 0)
81 ad = audio_open(w->sample_rate,w->num_channels,CST_AUDIO_LINEAR16);
82
83 audio_write(ad,&w->samples[start],size*sizeof(short));
84
85 if (last == 1)
86 {
87 audio_close(ad);
88 ad = NULL;
89 }
90
91 /* if you want to stop return CST_AUDIO_STREAM_STOP */
92 return CST_AUDIO_STREAM_CONT;
93 }
94