74 if ((quality =
getenv(
"NA_PLAY_QUALITY")) !=
NULL)
79 protocol = al.
val(
"-p");
80 else if ((sr=
getenv(
"NA_PLAY_PROTOCOL")) !=
NULL)
82 else if (protocol ==
"")
85 protocol =
"netaudio";
87 protocol =
"pulseaudio";
89 protocol =
"sun16audio";
91 protocol =
"freebsd16audio";
93 protocol =
"linux16audio";
95 protocol =
"irixaudio";
97 protocol =
"macosxaudio";
99 protocol =
"win32audio";
101 protocol =
"mplayeraudio";
103 protocol =
"sunaudio";
115 if (
upcase(protocol) ==
"NETAUDIO")
117 else if (
upcase(protocol) ==
"PULSEAUDIO")
119 else if (
upcase(protocol) ==
"SUNAUDIO")
120 return play_sunau_wave(*toplay,al);
121 else if (
upcase(protocol) ==
"SUN16AUDIO")
123 else if ((
upcase(protocol) ==
"FREEBSD16AUDIO") ||
124 (
upcase(protocol) ==
"LINUX16AUDIO"))
126 else if (
upcase(protocol) ==
"IRIXAUDIO")
128 else if (
upcase(protocol) ==
"MACOSXAUDIO")
130 else if (
upcase(protocol) ==
"MPLAYERAUDIO")
132 else if (
upcase(protocol) ==
"WIN32AUDIO")
134 else if (
upcase(protocol) ==
"AUDIO_COMMAND")
135 return play_aucomm_wave(*toplay,al);
136 else if (
upcase(protocol) ==
"SOCKET")
137 return play_socket_wave(*toplay,al);
140 cerr <<
"Unknown audio server protocol " << protocol << endl;
153 fd = al.
ival(
"socket_fd");
156 cerr <<
"Socket audio mode: no socket_fd specified" << endl;
160 if (al.
present(
"socket_otype"))
161 otype = al.
val(
"socket_otype");
165 inwave.
save(tmpfile,otype);
169 if (send(fd,
"WV\n",3,0) != 3) {
170 cerr <<
"Socket: Error sending 'WV\\n' to the client" << endl;
188 usrcommand = al.
val(
"-command");
190 usrcommand =
getenv(
"NA_PLAY_COMMAND");
193 cerr <<
"Audio protocol set to COMMAND but no command specified\n";
197 sprintf(tmpfile,
"/tmp/audiofile_%05ld",(
long)getpid());
202 otype = al.
val(
"-otype");
208 cerr <<
"Audio writing file \"" << tmpfile <<
"\" in type \"" <<
209 otype <<
" failed " << endl;
213 sprintf(pref,
"FILE=%s;SR=%d;",tmpfile,inwave.
sample_rate());
216 system_result = system(finalcommand);
217 if (system_result != 0)
219 cerr <<
"Command \"" << finalcommand <<
"\" returned error " <<
220 system_result << endl;
224 return system_result;
232 const char *audiodevice;
236 if (al.
present(
"-audiodevice"))
237 audiodevice = al.
val(
"-audiodevice");
239 audiodevice =
"/dev/audio";
243 rcode = inwave.
save(audiodevice,
"ulaw");
254 audios +=
"sunaudio";
256 audios +=
" audio_command";
258 audios +=
" netaudio";
260 audios +=
" sun16audio";
262 audios +=
" pulseaudio";
264 audios +=
" freebsd16audio";
266 audios +=
" linux16audio";
268 audios +=
" irixaudio";
270 audios +=
" mplayeraudio";
272 audios +=
"macosxaudio";
274 audios +=
" win32audio";
276 audios +=
" os2audio";
294 protocol = al.
val(
"-p");
295 else if ((sr=
getenv(
"NA_PLAY_PROTOCOL")) !=
NULL)
297 else if (protocol ==
"")
300 protocol =
"pulseaudio";
302 protocol =
"sun16audio";
304 protocol =
"freebsd16audio";
306 protocol =
"linux16audio";
308 protocol =
"irixaudio";
310 protocol =
"win32audio";
312 protocol =
"mplayeraudio";
314 protocol =
"sunaudio";
317 if (
upcase(protocol) ==
"NETAUDIO")
319 else if (
upcase(protocol) ==
"PULSEAUDIO")
321 else if (
upcase(protocol) ==
"SUN16AUDIO")
323 else if ((
upcase(protocol) ==
"FREEBSD16AUDIO") ||
324 (
upcase(protocol) ==
"LINUX16AUDIO"))
326 else if (
upcase(protocol) ==
"SUNAUDIO")
327 return record_sunau_wave(wave,al);
330 cerr <<
"NA_RECORD: \"" << protocol <<
331 "\" EST current has no record support" << endl;
338 int num_samples,i,r,n;
340 unsigned char *ulawwave;
342 const int AUDIOBUFFSIZE = 256;
343 const char *audiodevice;
345 if (al.
present(
"-audiodevice"))
346 audiodevice = al.
val(
"-audiodevice");
348 audiodevice =
"/dev/audio";
350 if ((audio =
open(audiodevice, O_RDONLY)) == -1)
352 cerr <<
"SUN16: can't open " << audiodevice <<
" for reading" << endl;
356 num_samples = (
int)(8000*al.
fval(
"-time"));
357 ulawwave =
walloc(
unsigned char,num_samples);
359 for (r=i=0; i < num_samples; i+= r)
361 if (num_samples > i+AUDIOBUFFSIZE)
365 r = read(audio,&ulawwave[i], n);
368 cerr <<
"sunaudio: failed to read from audio device" << endl;
A class for storing digital waveforms. The waveform is stored as an array of 16 bit shorts...
void set_sample_rate(const int n)
Set sampling rate to n
#define walloc(TYPE, SIZE)
int play_sun16_wave(EST_Wave &inwave, EST_Option &al)
EST_String unquote(const char quotec) const
Remove quotes and unprotect internal quotes.
Utility IO Function header file.
int record_pulse_wave(EST_Wave &inwave, EST_Option &al)
int ival(const EST_String &rkey, int m=1) const
int record_wave(EST_Wave &wave, EST_Option &al)
float fval(const EST_String &rkey, int m=1) const
int play_win32audio_wave(EST_Wave &inwave, EST_Option &al)
EST_String make_tmp_filename()
Make a unique temporary filename.
int play_nas_wave(EST_Wave &inwave, EST_Option &al)
EST_write_status save(const EST_String filename, const EST_String EST_filetype="")
int record_linux_wave(EST_Wave &inwave, EST_Option &al)
EST_String upcase(const EST_String &s)
int socket_send_file(SOCKET_FD fd, const EST_String &filename)
int play_linux_wave(EST_Wave &inwave, EST_Option &al)
int play_macosx_wave(EST_Wave &inwave, EST_Option &al)
void ulaw_to_short(const unsigned char *ulaw, short *data, int length)
int play_pulse_wave(EST_Wave &inwave, EST_Option &al)
const EST_SMatrix & values() const
The file was written successfully.
int play_irix_wave(EST_Wave &inwave, EST_Option &al)
int play_mplayer_wave(EST_Wave &inwave, EST_Option &al)
const V & val(const K &rkey, bool m=0) const
return value according to key (const)
int add_item(const K &rkey, const V &rval, int no_search=0)
add key-val pair to list
void resize(int num_samples, int num_channels=EST_ALL, int set=1)
resize the waveform
int sample_rate() const
return the sampling rate (frequency)
void wave_combine_channels(EST_Wave &combined, const EST_Wave &multi)
int record_nas_wave(EST_Wave &inwave, EST_Option &al)
int present(const K &rkey) const
Returns true if key is present.
ssize_t num_channels() const
return the number of channels in the waveform
FILE16 *(* open)(const char *, const char *, int, const char *, const char *)
EST_String options_supported_audio(void)
void resample(int rate)
Resample waveform to rate
int record_sun16_wave(EST_Wave &inwave, EST_Option &al)
int play_wave(EST_Wave &inwave, EST_Option &al)