45 #include "EST_system.h"
46 #include "EST_socket.h"
47 #include "EST_Option.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 +=
" sun16audio";
253 audios +=
" pulseaudio";
254 if (freebsd16_supported)
255 audios +=
" freebsd16audio";
256 if (linux16_supported)
257 audios +=
" linux16audio";
259 audios +=
" irixaudio";
260 if (mplayer_supported)
261 audios +=
" mplayeraudio";
262 if (macosx_supported)
263 audios +=
"macosxaudio";
264 if (win32audio_supported)
265 audios +=
" win32audio";
266 if (os2audio_supported)
267 audios +=
" os2audio";
280 if ((sr = getenv(
"NA_PLAY_HOST")) != NULL)
285 protocol = al.
val(
"-p");
286 else if ((sr=getenv(
"NA_PLAY_PROTOCOL")) != NULL)
288 else if (protocol ==
"")
291 protocol =
"pulseaudio";
292 else if (sun16_supported)
293 protocol =
"sun16audio";
294 else if (freebsd16_supported)
295 protocol =
"freebsd16audio";
296 else if (linux16_supported)
297 protocol =
"linux16audio";
298 else if (irix_supported)
299 protocol =
"irixaudio";
300 else if (win32audio_supported)
301 protocol =
"win32audio";
302 else if (esd_supported)
303 protocol =
"esdaudio";
304 else if (nas_supported)
305 protocol =
"netaudio";
306 else if (mplayer_supported)
307 protocol =
"mplayeraudio";
309 protocol =
"sunaudio";
312 if (upcase(protocol) ==
"NETAUDIO")
313 return record_nas_wave(wave,al);
314 else if (upcase(protocol) ==
"PULSEAUDIO")
315 return record_pulse_wave(wave,al);
316 else if (upcase(protocol) ==
"ESDAUDIO")
317 return record_esd_wave(wave,al);
318 else if (upcase(protocol) ==
"SUN16AUDIO")
319 return record_sun16_wave(wave,al);
320 else if ((upcase(protocol) ==
"FREEBSD16AUDIO") ||
321 (upcase(protocol) ==
"LINUX16AUDIO"))
322 return record_linux_wave(wave,al);
323 else if (upcase(protocol) ==
"SUNAUDIO")
324 return record_sunau_wave(wave,al);
327 cerr <<
"NA_RECORD: \"" << protocol <<
328 "\" EST current has no record support" << endl;
335 int num_samples,i,r,n;
337 unsigned char *ulawwave;
339 const int AUDIOBUFFSIZE = 256;
340 const char *audiodevice;
342 if (al.
present(
"-audiodevice"))
343 audiodevice = al.
val(
"-audiodevice");
345 audiodevice =
"/dev/audio";
347 if ((audio = open(audiodevice, O_RDONLY)) == -1)
349 cerr <<
"SUN16: can't open " << audiodevice <<
" for reading" << endl;
353 num_samples = (int)(8000*al.
fval(
"-time"));
354 ulawwave = walloc(
unsigned char,num_samples);
356 for (r=i=0; i < num_samples; i+= r)
358 if (num_samples > i+AUDIOBUFFSIZE)
362 r = read(audio,&ulawwave[i], n);
365 cerr <<
"sunaudio: failed to read from audio device" << endl;
374 waveform = wave.values().
memory();
376 ulaw_to_short(ulawwave,waveform,num_samples);
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
EST_String unquote(const char quotec) const
Remove quotes and unprotect internal quotes.
Utility IO Function header file.
int ival(const EST_String &rkey, int m=1) const
float fval(const EST_String &rkey, int m=1) const
EST_String make_tmp_filename()
Make a unique temporary filename.
EST_write_status save(const EST_String filename, const EST_String EST_filetype="")
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