45 #include "EST_system.h" 46 #include "EST_socket.h" 47 #include "EST_Option.h" 49 #include "EST_io_aux.h" 51 #include "EST_audio.h" 52 #include "EST_wave_aux.h" 68 if ((sr = getenv(
"NA_PLAY_HOST")) != NULL)
72 if ((quality = getenv(
"NA_PLAY_QUALITY")) != NULL)
77 protocol = al.
val(
"-p");
78 else if ((sr=getenv(
"NA_PLAY_PROTOCOL")) != NULL)
80 else if (protocol ==
"")
83 protocol =
"netaudio";
84 else if (pulse_supported)
85 protocol =
"pulseaudio";
86 else if (esd_supported)
87 protocol =
"esdaudio";
88 else if (sun16_supported)
89 protocol =
"sun16audio";
90 else if (freebsd16_supported)
91 protocol =
"freebsd16audio";
92 else if (linux16_supported)
93 protocol =
"linux16audio";
94 else if (irix_supported)
95 protocol =
"irixaudio";
96 else if (macosx_supported)
97 protocol =
"macosxaudio";
98 else if (win32audio_supported)
99 protocol =
"win32audio";
100 else if (mplayer_supported)
101 protocol =
"mplayeraudio";
103 protocol =
"sunaudio";
107 if (inwave.
num_channels() > 1 && upcase(protocol) !=
"MACOSXAUDIO" )
109 wave_combine_channels(wtmp,inwave);
115 if (upcase(protocol) ==
"NETAUDIO")
116 return play_nas_wave(*toplay,al);
117 else if (upcase(protocol) ==
"PULSEAUDIO")
118 return play_pulse_wave(*toplay,al);
119 else if (upcase(protocol) ==
"ESDAUDIO")
120 return play_esd_wave(*toplay,al);
121 else if (upcase(protocol) ==
"SUNAUDIO")
122 return play_sunau_wave(*toplay,al);
123 else if (upcase(protocol) ==
"SUN16AUDIO")
124 return play_sun16_wave(*toplay,al);
125 else if ((upcase(protocol) ==
"FREEBSD16AUDIO") ||
126 (upcase(protocol) ==
"LINUX16AUDIO"))
127 return play_linux_wave(*toplay,al);
128 else if (upcase(protocol) ==
"IRIXAUDIO")
129 return play_irix_wave(*toplay,al);
130 else if (upcase(protocol) ==
"MACOSXAUDIO")
131 return play_macosx_wave(*toplay,al);
132 else if (upcase(protocol) ==
"MPLAYERAUDIO")
133 return play_mplayer_wave(*toplay,al);
134 else if (upcase(protocol) ==
"WIN32AUDIO")
135 return play_win32audio_wave(*toplay,al);
136 else if (upcase(protocol) ==
"AUDIO_COMMAND")
137 return play_aucomm_wave(*toplay,al);
138 else if (upcase(protocol) ==
"SOCKET")
139 return play_socket_wave(*toplay,al);
142 cerr <<
"Unknown audio server protocol " << protocol << endl;
155 fd = al.
ival(
"socket_fd");
158 cerr <<
"Socket audio mode: no socket_fd specified" << endl;
162 if (al.
present(
"socket_otype"))
163 otype = al.
val(
"socket_otype");
167 inwave.save(tmpfile,otype);
172 socket_send_file(fd,tmpfile);
186 usrcommand = al.
val(
"-command");
187 else if (getenv(
"NA_PLAY_COMMAND") != NULL)
188 usrcommand = getenv(
"NA_PLAY_COMMAND");
191 cerr <<
"Audio protocol set to COMMAND but no command specified\n";
195 sprintf(tmpfile,
"/tmp/audiofile_%05ld",(
long)getpid());
200 otype = al.
val(
"-otype");
204 if (inwave.save(tmpfile,otype) != write_ok)
206 cerr <<
"Audio writing file \"" << tmpfile <<
"\" in type \"" <<
207 otype <<
" failed " << endl;
211 sprintf(pref,
"FILE=%s;SR=%d;",tmpfile,inwave.
sample_rate());
225 const char *audiodevice;
229 if (al.
present(
"-audiodevice"))
230 audiodevice = al.
val(
"-audiodevice");
232 audiodevice =
"/dev/audio";
236 rcode = inwave.save(audiodevice,
"ulaw");
247 audios +=
"sunaudio";
249 audios +=
" audio_command";
251 audios +=
" netaudio";
252 else if (esd_supported)
253 audios +=
" esdaudio";
255 audios +=
" sun16audio";
257 audios +=
" pulseaudio";
258 if (freebsd16_supported)
259 audios +=
" freebsd16audio";
260 if (linux16_supported)
261 audios +=
" linux16audio";
263 audios +=
" irixaudio";
264 if (mplayer_supported)
265 audios +=
" mplayeraudio";
266 if (macosx_supported)
267 audios +=
"macosxaudio";
268 if (win32audio_supported)
269 audios +=
" win32audio";
270 if (os2audio_supported)
271 audios +=
" os2audio";
284 if ((sr = getenv(
"NA_PLAY_HOST")) != NULL)
289 protocol = al.
val(
"-p");
290 else if ((sr=getenv(
"NA_PLAY_PROTOCOL")) != NULL)
292 else if (protocol ==
"")
295 protocol =
"pulseaudio";
296 else if (nas_supported)
297 protocol =
"netaudio";
298 else if (esd_supported)
299 protocol =
"esdaudio";
300 else if (sun16_supported)
301 protocol =
"sun16audio";
302 else if (freebsd16_supported)
303 protocol =
"freebsd16audio";
304 else if (linux16_supported)
305 protocol =
"linux16audio";
306 else if (irix_supported)
307 protocol =
"irixaudio";
308 else if (win32audio_supported)
309 protocol =
"win32audio";
310 else if (mplayer_supported)
311 protocol =
"mplayeraudio";
313 protocol =
"sunaudio";
316 if (upcase(protocol) ==
"NETAUDIO")
317 return record_nas_wave(wave,al);
318 else if (upcase(protocol) ==
"PULSEAUDIO")
319 return record_pulse_wave(wave,al);
320 else if (upcase(protocol) ==
"ESDAUDIO")
321 return record_esd_wave(wave,al);
322 else if (upcase(protocol) ==
"SUN16AUDIO")
323 return record_sun16_wave(wave,al);
324 else if ((upcase(protocol) ==
"FREEBSD16AUDIO") ||
325 (upcase(protocol) ==
"LINUX16AUDIO"))
326 return record_linux_wave(wave,al);
327 else if (upcase(protocol) ==
"SUNAUDIO")
328 return record_sunau_wave(wave,al);
331 cerr <<
"NA_RECORD: \"" << protocol <<
332 "\" EST current has no record support" << endl;
339 int num_samples,i,r,n;
341 unsigned char *ulawwave;
343 const int AUDIOBUFFSIZE = 256;
344 const char *audiodevice;
346 if (al.
present(
"-audiodevice"))
347 audiodevice = al.
val(
"-audiodevice");
349 audiodevice =
"/dev/audio";
351 if ((audio = open(audiodevice, O_RDONLY)) == -1)
353 cerr <<
"SUN16: can't open " << audiodevice <<
" for reading" << endl;
357 num_samples = (int)(8000*al.
fval(
"-time"));
358 ulawwave = walloc(
unsigned char,num_samples);
360 for (r=i=0; i < num_samples; i+= r)
362 if (num_samples > i+AUDIOBUFFSIZE)
366 r = read(audio,&ulawwave[i], n);
369 cerr <<
"sunaudio: failed to read from audio device" << endl;
378 waveform = wave.values().
memory();
380 ulaw_to_short(ulawwave,waveform,num_samples);
void set_sample_rate(const int n)
Set sampling rate to n
EST_String unquote(const char quotec) const
Remove quotes and unprotect internal quotes.
int ival(const EST_String &rkey, int m=1) const
float fval(const EST_String &rkey, int m=1) const
int num_channels() const
return the number of channels in the waveform
const int present(const K &rkey) const
Returns true if key is present.
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 resample(int rate)
Resample waveform to rate