1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
|
$NetBSD: patch-ai,v 1.2 2011/11/22 20:57:35 wiz Exp $
--- obuffer.cc.orig 1994-06-27 11:14:03.000000000 +0000
+++ obuffer.cc
@@ -47,7 +47,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
-#include <iostream.h>
+#include <iostream>
#include "obuffer.h"
#include "header.h"
#ifdef ULAW
@@ -65,14 +65,14 @@ FileObuffer::FileObuffer (uint32 number_
#ifdef DEBUG
if (!number_of_channels || number_of_channels > MAXCHANNELS)
{
- cerr << "FileObuffer: number of channels has to be in [1, " << MAXCHANNELS << "] !\n";
+ std::cerr << "FileObuffer: number of channels has to be in [1, " << MAXCHANNELS << "] !\n";
exit (1);
}
#endif
#ifdef ULAW
if (number_of_channels > 1)
- cerr << "Are you sure you need stereo u-law output?\n";
+ std::cerr << "Are you sure you need stereo u-law output?\n";
#endif
channels = number_of_channels;
for (int i = 0; i < number_of_channels; ++i)
@@ -85,12 +85,12 @@ void FileObuffer::append (uint32 channel
#ifdef DEBUG
if (channel >= channels)
{
- cerr << "illegal channelnumber in FileObuffer::append()!\n";
+ std::cerr << "illegal channelnumber in FileObuffer::append()!\n";
exit (1);
}
if (bufferp[channel] - buffer >= OBUFFERSIZE)
{
- cerr << "FileObuffer: buffer overflow!\n";
+ std::cerr << "FileObuffer: buffer overflow!\n";
exit (1);
}
#endif
@@ -143,7 +143,7 @@ IndigoObuffer::IndigoObuffer (uint32 num
#ifdef DEBUG
if (!number_of_channels || number_of_channels > MAXCHANNELS)
{
- cerr << "IndigoObuffer: number of channels has to be in [1, " << MAXCHANNELS << "] !\n";
+ std::cerr << "IndigoObuffer: number of channels has to be in [1, " << MAXCHANNELS << "] !\n";
exit (1);
}
#endif
@@ -155,7 +155,7 @@ IndigoObuffer::IndigoObuffer (uint32 num
ALconfig config;
if (!(config = ALnewconfig ()))
{
- cerr << "ALnewconfig failed!\n";
+ std::cerr << "ALnewconfig failed!\n";
exit (1);
}
ALsetwidth (config, AL_SAMPLE_16);
@@ -165,7 +165,7 @@ IndigoObuffer::IndigoObuffer (uint32 num
ALsetchannels (config, AL_STEREO);
if (!(port = ALopenport ("MPEG audio player", "w", config)))
{
- cerr << "can't allocate an audio port!\n";
+ std::cerr << "can't allocate an audio port!\n";
exit (1);
}
@@ -190,12 +190,12 @@ void IndigoObuffer::append (uint32 chann
#ifdef DEBUG
if (channel >= channels)
{
- cerr << "illegal channelnumber in IndigoObuffer::append()!\n";
+ std::cerr << "illegal channelnumber in IndigoObuffer::append()!\n";
exit (1);
}
if (bufferp[channel] - buffer >= OBUFFERSIZE)
{
- cerr << "IndigoObuffer: buffer overflow!\n";
+ std::cerr << "IndigoObuffer: buffer overflow!\n";
exit (1);
}
#endif
@@ -217,17 +217,17 @@ void IndigoObuffer::write_buffer (int)
int SparcObuffer::audio_fd = -1;
#ifdef ULAW
-SparcObuffer::SparcObuffer (Header *header, bool use_speaker, bool use_headphone, bool use_line_out)
+SparcObuffer::SparcObuffer (Header *header, boolean use_speaker, boolean use_headphone, boolean use_line_out)
#else
SparcObuffer::SparcObuffer (uint32 number_of_channels, Header *header,
- bool use_speaker, bool use_headphone, bool use_line_out)
+ boolean use_speaker, boolean use_headphone, boolean use_line_out)
#endif
{
#ifndef ULAW
#ifdef DEBUG
if (!number_of_channels || number_of_channels > MAXCHANNELS)
{
- cerr << "SparcObuffer: 0 < number of channels < " << MAXCHANNELS << "!\n";
+ std::cerr << "SparcObuffer: 0 < number of channels < " << MAXCHANNELS << "!\n";
exit (1);
}
#endif
@@ -235,7 +235,7 @@ SparcObuffer::SparcObuffer (uint32 numbe
if (audio_fd < 0)
{
- cerr << "Internal error: SparcObuffer::audio_fd has to be initialized\n"
+ std::cerr << "Internal error: SparcObuffer::audio_fd has to be initialized\n"
"by SparcObuffer::class_suitable()!\n";
exit (1);
}
@@ -296,7 +296,7 @@ void SparcObuffer::append (uint32 channe
#ifdef DEBUG
if (bufferp - buffer >= OBUFFERSIZE >> 1)
{
- cerr << "SparcObuffer: buffer overflow!\n";
+ std::cerr << "SparcObuffer: buffer overflow!\n";
exit (1);
}
#endif
@@ -307,12 +307,12 @@ void SparcObuffer::append (uint32 channe
#ifdef DEBUG
if (channel >= channels)
{
- cerr << "illegal channelnumber in SparcObuffer::append()!\n";
+ std::cerr << "illegal channelnumber in SparcObuffer::append()!\n";
exit (1);
}
if (bufferp[channel] - buffer >= OBUFFERSIZE)
{
- cerr << "SparcObuffer: buffer overflow!\n";
+ std::cerr << "SparcObuffer: buffer overflow!\n";
exit (1);
}
#endif
@@ -351,7 +351,7 @@ int SparcObuffer::open_audio_device (voi
if ((fd = open ("/dev/audio", O_WRONLY | O_NDELAY, 0)) < 0)
if (errno == EBUSY)
{
- cerr << "Sorry, the audio device is busy!\n";
+ std::cerr << "Sorry, the audio device is busy!\n";
exit (1);
}
else
@@ -398,7 +398,7 @@ int SparcObuffer::get_device_type (int f
}
return devtype;
#else
- cerr << "SparcObuffer::get_device_type(): AUDIO_GETDEV ioctl not available!\n";
+ std::cerr << "SparcObuffer::get_device_type(): AUDIO_GETDEV ioctl not available!\n";
return -1;
#endif
}
@@ -406,15 +406,15 @@ int SparcObuffer::get_device_type (int f
#ifdef ULAW
-bool SparcObuffer::class_suitable (uint32 number_of_channels, bool force_amd)
+boolean SparcObuffer::class_suitable (uint32 number_of_channels, boolean force_amd)
#else
-bool SparcObuffer::class_suitable (void)
+boolean SparcObuffer::class_suitable (void)
#endif
{
#ifdef ULAW
if (number_of_channels > 1)
{
- cerr << "Your audio hardware cannot handle more than one audio channel.\n"
+ std::cerr << "Your audio hardware cannot handle more than one audio channel.\n"
"Please use the option -l or -r for stereo streams.\n";
return False;
}
@@ -436,7 +436,7 @@ bool SparcObuffer::class_suitable (void)
return True;
else if (!strcmp (devtype.name, "SUNW,dbri"))
{
- cerr << "Your machine can produce CD-quality audio output,\n"
+ std::cerr << "Your machine can produce CD-quality audio output,\n"
"but this binary was compiled for 8 kHz u-law ouput. (telephone quality)\n"
"Please recompile it without the ULAW define in COMPILERFLAGS.\n"
"(or use the -amd option to use this binary with low-quality output)\n";
@@ -448,7 +448,7 @@ bool SparcObuffer::class_suitable (void)
return True;
else if (!strcmp (devtype.name, "SUNW,am79c30"))
{
- cerr << "Your machine can produce 8 kHz u-law audio output only,\n"
+ std::cerr << "Your machine can produce 8 kHz u-law audio output only,\n"
"but this binary was compiled for CD-quality output.\n"
"Please recompile it with ULAW defined in COMPILERFLAGS\n"
"or use it in stdout mode as an decoder only.\n";
@@ -464,7 +464,7 @@ bool SparcObuffer::class_suitable (void)
# ifdef ULAW
return True;
# else
- cerr << "Your machine can produce 8 kHz u-law audio output only,\n"
+ std::cerr << "Your machine can produce 8 kHz u-law audio output only,\n"
"but this binary was compiled for CD-quality output.\n"
"Please recompile it with ULAW defined in COMPILERFLAGS\n"
"or use it in stdout mode as an decoder only.\n";
@@ -479,7 +479,7 @@ bool SparcObuffer::class_suitable (void)
return True;
else if (device_type == AUDIO_DEV_SPEAKERBOX)
{
- cerr << "Your machine can produce CD-quality audio output,\n"
+ std::cerr << "Your machine can produce CD-quality audio output,\n"
"but this binary was compiled for 8 kHz u-law ouput. (telephone quality)\n"
"Please recompile it without the ULAW define in COMPILERFLAGS.\n"
"(or use the -amd option to use this binary with low-quality output)\n";
@@ -491,7 +491,7 @@ bool SparcObuffer::class_suitable (void)
return True;
else if (device_type == AUDIO_DEV_AMD)
{
- cerr << "Your machine can produce 8 kHz u-law audio output only,\n"
+ std::cerr << "Your machine can produce 8 kHz u-law audio output only,\n"
"but this binary was compiled for CD-quality output.\n"
"Please recompile it with ULAW defined in COMPILERFLAGS\n"
"or use it in stdout mode as an decoder only.\n";
@@ -504,7 +504,7 @@ bool SparcObuffer::class_suitable (void)
#ifndef SunOS4_1_1
close (audio_fd);
- cerr << "Sorry, I don't recognize your audio device.\n"
+ std::cerr << "Sorry, I don't recognize your audio device.\n"
# ifdef ULAW
"Please try the -amd option or use the stdout mode.\n";
# else
@@ -527,7 +527,7 @@ int LinuxObuffer::open_audio_device (voi
if ((fd = open ("/dev/dsp", O_WRONLY | O_NDELAY, 0)) < 0)
if (errno == EBUSY)
{
- cerr << "Sorry, the audio device is busy!\n";
+ std::cerr << "Sorry, the audio device is busy!\n";
exit (1);
}
else
@@ -537,6 +537,7 @@ int LinuxObuffer::open_audio_device (voi
}
// turn NDELAY mode off:
+#ifndef __FreeBSD__ /* Our /dev/audio doesn't like non-blocking I/O */
int flags;
if ((flags = fcntl (fd, F_GETFL, 0)) < 0)
{
@@ -549,6 +550,7 @@ int LinuxObuffer::open_audio_device (voi
perror ("fcntl F_SETFL on /dev/audio failed");
exit (1);
}
+#endif
return fd;
}
@@ -558,7 +560,7 @@ LinuxObuffer::LinuxObuffer (uint32 numbe
#ifdef DEBUG
if (!number_of_channels || number_of_channels > MAXCHANNELS)
{
- cerr << "LinuxObuffer: 0 < number of channels < " << MAXCHANNELS << "!\n";
+ std::cerr << "LinuxObuffer: 0 < number of channels < " << MAXCHANNELS << "!\n";
exit (1);
}
#endif
@@ -568,7 +570,7 @@ LinuxObuffer::LinuxObuffer (uint32 numbe
if (audio_fd < 0)
{
- cerr << "Internal error, LinuxObuffer::audio_fd has to be initialized\n"
+ std::cerr << "Internal error, LinuxObuffer::audio_fd has to be initialized\n"
"by LinuxObuffer::class_suitable()!\n";
exit (1);
}
@@ -602,12 +604,12 @@ void LinuxObuffer::append (uint32 channe
#ifdef DEBUG
if (channel >= channels)
{
- cerr << "illegal channelnumber in LinuxObuffer::append()!\n";
+ std::cerr << "illegal channelnumber in LinuxObuffer::append()!\n";
exit (1);
}
if (bufferp[channel] - buffer >= OBUFFERSIZE)
{
- cerr << "buffer overflow!\n";
+ std::cerr << "buffer overflow!\n";
exit (1);
}
#endif
@@ -629,7 +631,7 @@ void LinuxObuffer::write_buffer (int)
}
-bool LinuxObuffer::class_suitable (uint32 number_of_channels)
+boolean LinuxObuffer::class_suitable (uint32 number_of_channels)
{
// open the dsp audio device:
audio_fd = open_audio_device ();
@@ -637,3 +639,122 @@ bool LinuxObuffer::class_suitable (uint3
}
#endif /* LINUX */
+
+#ifdef NETBSD
+int NetBSDObuffer::audio_fd = -1;
+
+int NetBSDObuffer::open_audio_device (void)
+{
+ int fd;
+
+ if ((fd = open ("/dev/audio", O_WRONLY | O_NDELAY, 0)) < 0)
+ if (errno == EBUSY)
+ {
+ std::cerr << "Sorry, the audio device is busy!\n";
+ exit (1);
+ }
+ else
+ {
+ perror ("can't open /dev/audio for writing");
+ exit (1);
+ }
+
+ int flags;
+ if ((flags = fcntl (fd, F_GETFL, 0)) < 0)
+ {
+ perror ("fcntl F_GETFL on /dev/audio failed");
+ exit (1);
+ }
+ flags &= ~O_NDELAY;
+ if (fcntl (fd, F_SETFL, flags) < 0)
+ {
+ perror ("fcntl F_SETFL on /dev/audio failed");
+ exit (1);
+ }
+ return fd;
+}
+
+
+NetBSDObuffer::NetBSDObuffer (uint32 number_of_channels, Header *header)
+{
+#ifdef DEBUG
+ if (!number_of_channels || number_of_channels > MAXCHANNELS)
+ {
+ std::cerr << "NetBSDObuffer: 0 < number of channels < " << MAXCHANNELS << "!\n";
+ exit (1);
+ }
+#endif
+ channels = number_of_channels;
+ for (int i = 0; i < number_of_channels; ++i)
+ bufferp[i] = buffer + i;
+
+ if (audio_fd < 0)
+ {
+ std::cerr << "Internal error, NetBSDObuffer::audio_fd has to be initialized\n"
+ "by NetBSDObuffer::class_suitable()!\n";
+ exit (1);
+ }
+
+ audio_info info;
+ AUDIO_INITINFO(&info);
+
+ // configure the device:
+ info.play.encoding = AUDIO_ENCODING_SLINEAR;
+ info.play.precision = 16;
+ info.play.channels = channels;
+ info.play.sample_rate = header->frequency ();
+
+ if (ioctl (audio_fd, AUDIO_SETINFO, &info))
+ {
+ perror ("configuration of /dev/audio failed");
+ exit (1);
+ }
+}
+
+
+NetBSDObuffer::~NetBSDObuffer (void)
+{
+ close (audio_fd);
+}
+
+
+void NetBSDObuffer::append (uint32 channel, int16 value)
+{
+#ifdef DEBUG
+ if (channel >= channels)
+ {
+ std::cerr << "illegal channelnumber in NetBSDObuffer::append()!\n";
+ exit (1);
+ }
+ if (bufferp[channel] - buffer >= OBUFFERSIZE)
+ {
+ std::cerr << "buffer overflow!\n";
+ exit (1);
+ }
+#endif
+ *bufferp[channel] = value;
+ bufferp[channel] += channels;
+}
+
+
+void NetBSDObuffer::write_buffer (int)
+{
+ int length = (int)((char *)bufferp[0] - (char *)buffer);
+ if (write (audio_fd, buffer, length) != length)
+ {
+ perror ("write to /dev/audio failed");
+ exit (1);
+ }
+ for (int i = 0; i < channels; ++i)
+ bufferp[i] = buffer + i;
+}
+
+
+boolean NetBSDObuffer::class_suitable (uint32 number_of_channels)
+{
+ // open the dsp audio device:
+ audio_fd = open_audio_device ();
+ return True;
+}
+
+#endif /* NETBSD */
|