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
56typedef 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 */
62int audio_bps(cst_audiofmt fmt);
63
64typedef 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 */
74cst_audiodev *audio_open(int sps, int channels, cst_audiofmt fmt);
75int audio_close(cst_audiodev *ad);
76int audio_write(cst_audiodev *ad, void *buff, int num_bytes);
77int audio_flush(cst_audiodev *ad); /* wait for buffers to empty */
78int audio_drain(cst_audiodev *ad); /* empty buffers now */
79
80/* Generic high level audio functions */
81int play_wave(cst_wave *w);
82int play_wave_sync(cst_wave *w, cst_relation *rel,
83 int (*call_back)(cst_item *));
84int play_wave_client(cst_wave *w, const char *servername, int port,
85 const char *encoding);
86int auserver(int port);
87
88/* Play wave to specified device */
89int play_wave_device(cst_wave *w, cst_audiodev *ad);
90
91/* Output to a file as if its an audio device */
92cst_audiodev *audio_open_file(int sps, int channels, cst_audiofmt fmt,
93 const char *filename);
94int audio_close_file(cst_audiodev *ad);
95int audio_write_file(cst_audiodev *ad, void *buff, int num_bytes);
96int audio_drain_file(cst_audiodev *ad);
97int 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
102typedef 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;
113cst_audio_streaming_info *new_audio_streaming_info();
114void delete_audio_streaming_info(cst_audio_streaming_info *asi);
115CST_VAL_USER_TYPE_DCLS(audio_streaming_info,cst_audio_streaming_info)
116typedef 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 */
120int audio_stream_chunk(const cst_wave *w, int start, int size,
121 int last, cst_audio_streaming_info *asi);
122
123#endif
124

source code of include/flite/cst_audio.h