50 #include <sys/types.h>
52 #include "EST_cutils.h"
54 #include "EST_Option.h"
56 #include "EST_io_aux.h"
60 #include <sys/filio.h>
61 #if defined(__svr4__) || defined(SYSV) || defined(SVR4)
63 #include <sys/audioio.h>
66 #include <sun/audioio.h>
69 static int sun16_check_device(
int audio);
70 static int sun16_set_info(
int audio,
int sample_rate);
72 int sun16_supported = TRUE;
75 static int dev_sr[] = {8000, 9600, 11025, 16000, 18900, 22050, 32000,
76 37800, 44100, 48000, -1};
78 #define AUDIOBUFFSIZE 256
91 int samp_rate_ok = FALSE;
92 for (i=0; dev_sr[i] != -1; i++)
93 if (sample_rate == dev_sr[i])
95 if (samp_rate_ok == FALSE)
97 if (sample_rate == 10000)
103 if (al.
present(
"-audiodevice"))
104 audiodevice = al.
val(
"-audiodevice");
105 else if ((audiodevice = getenv(
"AUDIODEV")) == NULL)
106 audiodevice =
"/dev/audio";
108 if ((fdaudio = fopen(audiodevice,
"wb")) == NULL)
110 cerr <<
"SUN16: can't open " << audiodevice << endl;
114 audio = fileno(fdaudio);
116 waveform = inwave.values().
memory();
120 if (sun16_check_device(audio) == FALSE)
122 cerr <<
"SUN16: device doesn't support 16bit linear." << endl;
127 if (sun16_set_info(audio,sample_rate) == FALSE)
129 cerr <<
"SUN16: unable to set sample rate " <<
135 for (i=0; i < num_samples; i += r/2)
137 if (num_samples > i+AUDIOBUFFSIZE)
141 r = write(audio,&waveform[i], n*2);
144 cerr <<
"SUN16: failed to write to buffer" <<
157 static int sun16_check_device(
int audio)
163 ioctl(audio, AUDIO_DRAIN, 0);
165 if ((ioctl(audio, AUDIO_GETDEV, &type) != -1) &&
166 ((streq(
"SUNW,CS4231",type.name)) ||
167 (streq(
"SUNW,dbri",type.name)) ||
168 (streq(
"SUNW,audiots",type.name)) ||
169 (streq(
"SUNW,sb16",type.name))))
177 ioctl(audio, AUDIO_DRAIN, 0);
179 if ((ioctl(audio, AUDIO_GETDEV, &type) != -1) &&
180 ((type == AUDIO_DEV_SPEAKERBOX) || (type == AUDIO_DEV_CODEC)))
188 static int sun16_set_info(
int audio,
int sample_rate)
192 ioctl(audio, AUDIO_GETINFO, &info);
194 info.play.sample_rate = sample_rate;
195 info.play.encoding = AUDIO_ENCODING_LINEAR;
196 info.play.precision = 16;
197 info.play.channels = 1;
199 if (ioctl(audio, AUDIO_SETINFO, &info) == -1)
205 static int sun16_setrecord_info(
int audio,
int sample_rate)
212 unsigned char buff[64];
214 ioctl(audio, AUDIO_GETINFO, &info);
216 info.record.pause = 1;
218 ioctl(audio, AUDIO_SETINFO, &info);
221 ioctl(audio, FIONREAD, &read_size);
222 for (r=i=0; (i < read_size); i += r)
223 r = read(audio,buff,64);
226 ioctl(audio, AUDIO_GETINFO, &info);
227 info.record.sample_rate = sample_rate;
228 info.record.encoding = AUDIO_ENCODING_LINEAR;
229 info.record.precision = 16;
230 info.record.channels = 1;
231 info.record.pause = 0;
232 info.record.samples = 0;
233 info.record.error = 0;
235 if (ioctl(audio, AUDIO_SETINFO, &info) == -1)
243 int desired_sample_rate = 16000;
244 int actual_sample_rate;
250 desired_sample_rate = al.
ival(
"-sample_rate");
251 actual_sample_rate = -1;
252 for (i=0; dev_sr[i] != -1; i++)
253 if (desired_sample_rate == dev_sr[i])
254 actual_sample_rate = desired_sample_rate;
255 if (actual_sample_rate == -1)
256 actual_sample_rate = 16000;
258 if ((audio = open(
"/dev/audio",O_RDONLY)) == -1)
260 cerr <<
"SUN16: can't open /dev/audio for reading" << endl;
264 if (sun16_check_device(audio) == FALSE)
266 cerr <<
"SUN16: device doesn't support 16bit linear." << endl;
271 if (sun16_setrecord_info(audio,actual_sample_rate) == FALSE)
273 cerr <<
"SUN16: unable to set sample rate " <<
274 actual_sample_rate << endl;
279 wave.
resize((
int)(actual_sample_rate*al.
fval(
"-time")));
282 waveform = wave.values().
memory();
286 for (r=i=0; i < num_samples; i+= r)
288 if (num_samples > i+AUDIOBUFFSIZE)
292 ioctl(audio, FIONREAD, &read_size);
300 r = read(audio,&waveform[i], n*2);
304 cerr <<
"SUN16: failed to read from audio device" << endl;
312 if (actual_sample_rate != desired_sample_rate)
318 int sun16_supported = FALSE;
324 cerr <<
"Sun 16bit linear not supported" << endl;
332 cerr <<
"Sun 16bit linear not supported" << endl;