Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
554 lines (498 loc) · 17.9 KB

SDL_paudio.c

File metadata and controls

554 lines (498 loc) · 17.9 KB
 
Apr 26, 2001
Apr 26, 2001
1
/*
Feb 1, 2006
Feb 1, 2006
2
3
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 Sam Lantinga
Apr 26, 2001
Apr 26, 2001
4
5
This library is free software; you can redistribute it and/or
Feb 1, 2006
Feb 1, 2006
6
modify it under the terms of the GNU Lesser General Public
Apr 26, 2001
Apr 26, 2001
7
License as published by the Free Software Foundation; either
Feb 1, 2006
Feb 1, 2006
8
version 2.1 of the License, or (at your option) any later version.
Apr 26, 2001
Apr 26, 2001
9
10
11
12
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Feb 1, 2006
Feb 1, 2006
13
Lesser General Public License for more details.
Apr 26, 2001
Apr 26, 2001
14
Feb 1, 2006
Feb 1, 2006
15
16
17
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Apr 26, 2001
Apr 26, 2001
18
19
20
21
22
23
Carsten Griwodz
griff@kom.tu-darmstadt.de
based on linux/SDL_dspaudio.c by Sam Lantinga
*/
Feb 21, 2006
Feb 21, 2006
24
#include "SDL_config.h"
Apr 26, 2001
Apr 26, 2001
25
26
27
28
29
30
31
32
/* Allow access to a raw mixing buffer */
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/time.h>
#include <sys/ioctl.h>
Oct 17, 2006
Oct 17, 2006
33
#include <sys/types.h>
Apr 26, 2001
Apr 26, 2001
34
35
#include <sys/stat.h>
Feb 10, 2006
Feb 10, 2006
36
#include "SDL_timer.h"
Apr 26, 2001
Apr 26, 2001
37
#include "SDL_audio.h"
Oct 17, 2006
Oct 17, 2006
38
#include "SDL_stdinc.h"
Feb 16, 2006
Feb 16, 2006
39
40
#include "../SDL_audiomem.h"
#include "../SDL_audio_c.h"
Apr 26, 2001
Apr 26, 2001
41
42
#include "SDL_paudio.h"
Oct 17, 2006
Oct 17, 2006
43
#define DEBUG_AUDIO 0
Apr 26, 2001
Apr 26, 2001
44
45
46
47
48
49
50
51
/* A conflict within AIX 4.3.3 <sys/> headers and probably others as well.
* I guess nobody ever uses audio... Shame over AIX header files. */
#include <sys/machine.h>
#undef BIG_ENDIAN
#include <sys/audio.h>
/* The tag name used by paud audio */
Oct 17, 2006
Oct 17, 2006
52
#define PAUDIO_DRIVER_NAME "paud"
Apr 26, 2001
Apr 26, 2001
53
54
55
56
57
/* Open the audio device for playback, and don't block if busy */
/* #define OPEN_FLAGS (O_WRONLY|O_NONBLOCK) */
#define OPEN_FLAGS O_WRONLY
Oct 17, 2006
Oct 17, 2006
58
/* Get the name of the audio device we use for output */
Apr 26, 2001
Apr 26, 2001
59
Oct 17, 2006
Oct 17, 2006
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#ifndef _PATH_DEV_DSP
#define _PATH_DEV_DSP "/dev/%caud%c/%c"
#endif
static char devsettings[][3] = {
{'p', '0', '1'}, {'p', '0', '2'}, {'p', '0', '3'}, {'p', '0', '4'},
{'p', '1', '1'}, {'p', '1', '2'}, {'p', '1', '3'}, {'p', '1', '4'},
{'p', '2', '1'}, {'p', '2', '2'}, {'p', '2', '3'}, {'p', '2', '4'},
{'p', '3', '1'}, {'p', '3', '2'}, {'p', '3', '3'}, {'p', '3', '4'},
{'b', '0', '1'}, {'b', '0', '2'}, {'b', '0', '3'}, {'b', '0', '4'},
{'b', '1', '1'}, {'b', '1', '2'}, {'b', '1', '3'}, {'b', '1', '4'},
{'b', '2', '1'}, {'b', '2', '2'}, {'b', '2', '3'}, {'b', '2', '4'},
{'b', '3', '1'}, {'b', '3', '2'}, {'b', '3', '3'}, {'b', '3', '4'},
{'\0', '\0', '\0'}
};
Apr 26, 2001
Apr 26, 2001
75
Jul 10, 2006
Jul 10, 2006
76
static int
Oct 17, 2006
Oct 17, 2006
77
OpenUserDefinedDevice(char *path, int maxlen, int flags)
Apr 26, 2001
Apr 26, 2001
78
{
Oct 17, 2006
Oct 17, 2006
79
const char *audiodev;
Jul 10, 2006
Jul 10, 2006
80
81
int fd;
Oct 17, 2006
Oct 17, 2006
82
83
84
/* Figure out what our audio device is */
if ((audiodev = SDL_getenv("SDL_PATH_DSP")) == NULL) {
audiodev = SDL_getenv("AUDIODEV");
Jul 10, 2006
Jul 10, 2006
85
}
Oct 17, 2006
Oct 17, 2006
86
87
88
89
90
91
92
93
94
if (audiodev == NULL) {
return -1;
}
fd = open(audiodev, flags, 0);
if (path != NULL) {
SDL_strlcpy(path, audiodev, maxlen);
path[maxlen - 1] = '\0';
}
return fd;
Apr 26, 2001
Apr 26, 2001
95
96
}
Oct 17, 2006
Oct 17, 2006
97
98
static int
OpenAudioPath(char *path, int maxlen, int flags, int classic)
Apr 26, 2001
Apr 26, 2001
99
{
Oct 17, 2006
Oct 17, 2006
100
101
102
struct stat sb;
int cycle = 0;
int fd = OpenUserDefinedDevice(path, maxlen, flags);
Jul 10, 2006
Jul 10, 2006
103
Oct 17, 2006
Oct 17, 2006
104
105
if (fd != -1) {
return fd;
Jul 10, 2006
Jul 10, 2006
106
}
Oct 17, 2006
Oct 17, 2006
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* !!! FIXME: do we really need a table here? */
while (devsettings[cycle][0] != '\0') {
char audiopath[1024];
SDL_snprintf(audiopath, SDL_arraysize(audiopath),
_PATH_DEV_DSP,
devsettings[cycle][0],
devsettings[cycle][1], devsettings[cycle][2]);
if (stat(audiopath, &sb) == 0) {
fd = open(audiopath, flags, 0);
if (fd > 0) {
if (path != NULL) {
SDL_strlcpy(path, audiopath, maxlen);
}
return fd;
}
Jul 10, 2006
Jul 10, 2006
124
125
}
}
Oct 17, 2006
Oct 17, 2006
126
return -1;
Apr 26, 2001
Apr 26, 2001
127
128
129
}
/* This function waits until it is possible to write a full sound buffer */
Jul 10, 2006
Jul 10, 2006
130
static void
Oct 17, 2006
Oct 17, 2006
131
PAUDIO_WaitDevice(_THIS)
Apr 26, 2001
Apr 26, 2001
132
133
134
135
{
fd_set fdset;
/* See if we need to use timed audio synchronization */
Oct 17, 2006
Oct 17, 2006
136
if (this->hidden->frame_ticks) {
Apr 26, 2001
Apr 26, 2001
137
138
139
/* Use timer for general audio synchronization */
Sint32 ticks;
Oct 28, 2006
Oct 28, 2006
140
141
142
ticks =
((Sint32) (this->hidden->next_frame - SDL_GetTicks())) -
FUDGE_TICKS;
Jul 10, 2006
Jul 10, 2006
143
144
if (ticks > 0) {
SDL_Delay(ticks);
Apr 26, 2001
Apr 26, 2001
145
146
}
} else {
Jul 10, 2006
Jul 10, 2006
147
audio_buffer paud_bufinfo;
Apr 26, 2001
Apr 26, 2001
148
149
150
151
/* Use select() for audio synchronization */
struct timeval timeout;
FD_ZERO(&fdset);
Oct 17, 2006
Oct 17, 2006
152
FD_SET(this->hidden->audio_fd, &fdset);
Apr 26, 2001
Apr 26, 2001
153
Oct 17, 2006
Oct 17, 2006
154
if (ioctl(this->hidden->audio_fd, AUDIO_BUFFER, &paud_bufinfo) < 0) {
Apr 26, 2001
Apr 26, 2001
155
156
157
#ifdef DEBUG_AUDIO
fprintf(stderr, "Couldn't get audio buffer information\n");
#endif
Jul 10, 2006
Jul 10, 2006
158
timeout.tv_sec = 10;
Apr 26, 2001
Apr 26, 2001
159
160
timeout.tv_usec = 0;
} else {
Jul 10, 2006
Jul 10, 2006
161
162
163
164
long ms_in_buf = paud_bufinfo.write_buf_time;
timeout.tv_sec = ms_in_buf / 1000;
ms_in_buf = ms_in_buf - timeout.tv_sec * 1000;
timeout.tv_usec = ms_in_buf * 1000;
Apr 26, 2001
Apr 26, 2001
165
#ifdef DEBUG_AUDIO
Jul 10, 2006
Jul 10, 2006
166
167
168
fprintf(stderr,
"Waiting for write_buf_time=%ld,%ld\n",
timeout.tv_sec, timeout.tv_usec);
Apr 26, 2001
Apr 26, 2001
169
#endif
Jul 10, 2006
Jul 10, 2006
170
}
Apr 26, 2001
Apr 26, 2001
171
172
173
174
#ifdef DEBUG_AUDIO
fprintf(stderr, "Waiting for audio to get ready\n");
#endif
Oct 28, 2006
Oct 28, 2006
175
176
if (select(this->hidden->audio_fd + 1, NULL, &fdset, NULL, &timeout)
<= 0) {
Jul 10, 2006
Jul 10, 2006
177
178
const char *message =
"Audio timeout - buggy audio driver? (disabled)";
Apr 26, 2001
Apr 26, 2001
179
/*
Jul 10, 2006
Jul 10, 2006
180
* In general we should never print to the screen,
Apr 26, 2001
Apr 26, 2001
181
182
183
184
185
186
* but in this case we have no other way of letting
* the user know what happened.
*/
fprintf(stderr, "SDL: %s - %s\n", strerror(errno), message);
this->enabled = 0;
/* Don't try to close - may hang */
Oct 17, 2006
Oct 17, 2006
187
this->hidden->audio_fd = -1;
Apr 26, 2001
Apr 26, 2001
188
189
190
191
192
193
194
195
196
197
#ifdef DEBUG_AUDIO
fprintf(stderr, "Done disabling audio\n");
#endif
}
#ifdef DEBUG_AUDIO
fprintf(stderr, "Ready!\n");
#endif
}
}
Jul 10, 2006
Jul 10, 2006
198
static void
Oct 17, 2006
Oct 17, 2006
199
PAUDIO_PlayDevice(_THIS)
Apr 26, 2001
Apr 26, 2001
200
{
Oct 17, 2006
Oct 17, 2006
201
202
203
int written = 0;
const Uint8 *mixbuf = this->hidden->mixbuf;
const size_t mixlen = this->hidden->mixlen;
Jul 10, 2006
Jul 10, 2006
204
205
206
/* Write the audio data, checking for EAGAIN on broken audio drivers */
do {
Oct 17, 2006
Oct 17, 2006
207
written = write(this->hidden->audio_fd, mixbuf, mixlen);
Jul 10, 2006
Jul 10, 2006
208
209
210
211
212
213
214
215
if ((written < 0) && ((errno == 0) || (errno == EAGAIN))) {
SDL_Delay(1); /* Let a little CPU time go by */
}
}
while ((written < 0) &&
((errno == 0) || (errno == EAGAIN) || (errno == EINTR)));
/* If timer synchronization is enabled, set the next write frame */
Oct 17, 2006
Oct 17, 2006
216
217
if (this->hidden->frame_ticks) {
this->hidden->next_frame += this->hidden->frame_ticks;
Jul 10, 2006
Jul 10, 2006
218
219
220
221
222
223
}
/* If we couldn't write, assume fatal error for now */
if (written < 0) {
this->enabled = 0;
}
Apr 26, 2001
Apr 26, 2001
224
#ifdef DEBUG_AUDIO
Jul 10, 2006
Jul 10, 2006
225
fprintf(stderr, "Wrote %d bytes of audio data\n", written);
Apr 26, 2001
Apr 26, 2001
226
227
228
#endif
}
Jul 10, 2006
Jul 10, 2006
229
static Uint8 *
Oct 17, 2006
Oct 17, 2006
230
PAUDIO_GetDeviceBuf(_THIS)
Apr 26, 2001
Apr 26, 2001
231
{
Oct 17, 2006
Oct 17, 2006
232
return this->hidden->mixbuf;
Apr 26, 2001
Apr 26, 2001
233
234
}
Jul 10, 2006
Jul 10, 2006
235
static void
Oct 17, 2006
Oct 17, 2006
236
PAUDIO_CloseDevice(_THIS)
Apr 26, 2001
Apr 26, 2001
237
{
Oct 17, 2006
Oct 17, 2006
238
239
240
241
242
243
244
245
246
247
248
if (this->hidden != NULL) {
if (this->hidden->mixbuf != NULL) {
SDL_FreeAudioMem(this->hidden->mixbuf);
this->hidden->mixbuf = NULL;
}
if (this->hidden->audio_fd >= 0) {
close(this->hidden->audio_fd);
this->hidden->audio_fd = -1;
}
SDL_free(this->hidden);
this->hidden = NULL;
Jul 10, 2006
Jul 10, 2006
249
}
Apr 26, 2001
Apr 26, 2001
250
251
}
Jul 10, 2006
Jul 10, 2006
252
static int
Oct 17, 2006
Oct 17, 2006
253
PAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
Apr 26, 2001
Apr 26, 2001
254
{
Oct 17, 2006
Oct 17, 2006
255
const char *workaround = SDL_getenv("SDL_DSP_NOSELECT");
Jul 10, 2006
Jul 10, 2006
256
char audiodev[1024];
Oct 17, 2006
Oct 17, 2006
257
const char *err = NULL;
Jul 10, 2006
Jul 10, 2006
258
259
int format;
int bytes_per_sample;
Aug 24, 2006
Aug 24, 2006
260
SDL_AudioFormat test_format;
Jul 10, 2006
Jul 10, 2006
261
262
263
264
265
audio_init paud_init;
audio_buffer paud_bufinfo;
audio_status paud_status;
audio_control paud_control;
audio_change paud_change;
Oct 17, 2006
Oct 17, 2006
266
int fd = -1;
Jul 10, 2006
Jul 10, 2006
267
Oct 17, 2006
Oct 17, 2006
268
269
/* Initialize all variables that we clean on shutdown */
this->hidden = (struct SDL_PrivateAudioData *)
Oct 28, 2006
Oct 28, 2006
270
SDL_malloc((sizeof *this->hidden));
Oct 17, 2006
Oct 17, 2006
271
272
273
274
275
if (this->hidden == NULL) {
SDL_OutOfMemory();
return 0;
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
Jul 10, 2006
Jul 10, 2006
276
277
/* Open the audio device */
Oct 17, 2006
Oct 17, 2006
278
279
280
281
fd = OpenAudioPath(audiodev, sizeof(audiodev), OPEN_FLAGS, 0);
this->hidden->audio_fd = fd;
if (fd < 0) {
PAUDIO_CloseDevice(this);
Jul 10, 2006
Jul 10, 2006
282
SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno));
Oct 17, 2006
Oct 17, 2006
283
return 0;
Jul 10, 2006
Jul 10, 2006
284
285
286
287
288
289
}
/*
* We can't set the buffer size - just ask the device for the maximum
* that we can have.
*/
Oct 17, 2006
Oct 17, 2006
290
291
if (ioctl(fd, AUDIO_BUFFER, &paud_bufinfo) < 0) {
PAUDIO_CloseDevice(this);
Jul 10, 2006
Jul 10, 2006
292
SDL_SetError("Couldn't get audio buffer information");
Oct 17, 2006
Oct 17, 2006
293
return 0;
Jul 10, 2006
Jul 10, 2006
294
295
}
Oct 17, 2006
Oct 17, 2006
296
297
if (this->spec.channels > 1)
this->spec.channels = 2;
Jul 10, 2006
Jul 10, 2006
298
else
Oct 17, 2006
Oct 17, 2006
299
this->spec.channels = 1;
Jul 10, 2006
Jul 10, 2006
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
/*
* Fields in the audio_init structure:
*
* Ignored by us:
*
* paud.loadpath[LOAD_PATH]; * DSP code to load, MWave chip only?
* paud.slot_number; * slot number of the adapter
* paud.device_id; * adapter identification number
*
* Input:
*
* paud.srate; * the sampling rate in Hz
* paud.bits_per_sample; * 8, 16, 32, ...
* paud.bsize; * block size for this rate
* paud.mode; * ADPCM, PCM, MU_LAW, A_LAW, SOURCE_MIX
* paud.channels; * 1=mono, 2=stereo
* paud.flags; * FIXED - fixed length data
* * LEFT_ALIGNED, RIGHT_ALIGNED (var len only)
* * TWOS_COMPLEMENT - 2's complement data
* * SIGNED - signed? comment seems wrong in sys/audio.h
* * BIG_ENDIAN
* paud.operation; * PLAY, RECORD
*
* Output:
*
* paud.flags; * PITCH - pitch is supported
* * INPUT - input is supported
* * OUTPUT - output is supported
* * MONITOR - monitor is supported
* * VOLUME - volume is supported
* * VOLUME_DELAY - volume delay is supported
* * BALANCE - balance is supported
* * BALANCE_DELAY - balance delay is supported
* * TREBLE - treble control is supported
* * BASS - bass control is supported
* * BESTFIT_PROVIDED - best fit returned
* * LOAD_CODE - DSP load needed
* paud.rc; * NO_PLAY - DSP code can't do play requests
* * NO_RECORD - DSP code can't do record requests
* * INVALID_REQUEST - request was invalid
* * CONFLICT - conflict with open's flags
* * OVERLOADED - out of DSP MIPS or memory
* paud.position_resolution; * smallest increment for position
*/
Oct 17, 2006
Oct 17, 2006
346
paud_init.srate = this->spec.freq;
Jul 10, 2006
Jul 10, 2006
347
348
paud_init.mode = PCM;
paud_init.operation = PLAY;
Oct 17, 2006
Oct 17, 2006
349
paud_init.channels = this->spec.channels;
Jul 10, 2006
Jul 10, 2006
350
351
352
/* Try for a closest match on audio format */
format = 0;
Oct 17, 2006
Oct 17, 2006
353
for (test_format = SDL_FirstAudioFormat(this->spec.format);
Jul 10, 2006
Jul 10, 2006
354
!format && test_format;) {
Apr 26, 2001
Apr 26, 2001
355
#ifdef DEBUG_AUDIO
Jul 10, 2006
Jul 10, 2006
356
fprintf(stderr, "Trying format 0x%4.4x\n", test_format);
Apr 26, 2001
Apr 26, 2001
357
#endif
Jul 10, 2006
Jul 10, 2006
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
switch (test_format) {
case AUDIO_U8:
bytes_per_sample = 1;
paud_init.bits_per_sample = 8;
paud_init.flags = TWOS_COMPLEMENT | FIXED;
format = 1;
break;
case AUDIO_S8:
bytes_per_sample = 1;
paud_init.bits_per_sample = 8;
paud_init.flags = SIGNED | TWOS_COMPLEMENT | FIXED;
format = 1;
break;
case AUDIO_S16LSB:
bytes_per_sample = 2;
paud_init.bits_per_sample = 16;
paud_init.flags = SIGNED | TWOS_COMPLEMENT | FIXED;
format = 1;
break;
case AUDIO_S16MSB:
bytes_per_sample = 2;
paud_init.bits_per_sample = 16;
paud_init.flags = BIG_ENDIAN | SIGNED | TWOS_COMPLEMENT | FIXED;
format = 1;
break;
case AUDIO_U16LSB:
bytes_per_sample = 2;
paud_init.bits_per_sample = 16;
paud_init.flags = TWOS_COMPLEMENT | FIXED;
format = 1;
break;
case AUDIO_U16MSB:
bytes_per_sample = 2;
paud_init.bits_per_sample = 16;
paud_init.flags = BIG_ENDIAN | TWOS_COMPLEMENT | FIXED;
format = 1;
break;
default:
break;
}
if (!format) {
test_format = SDL_NextAudioFormat();
}
}
if (format == 0) {
Apr 26, 2001
Apr 26, 2001
403
#ifdef DEBUG_AUDIO
Jul 10, 2006
Jul 10, 2006
404
fprintf(stderr, "Couldn't find any hardware audio formats\n");
Apr 26, 2001
Apr 26, 2001
405
#endif
Oct 17, 2006
Oct 17, 2006
406
PAUDIO_CloseDevice(this);
Jul 10, 2006
Jul 10, 2006
407
SDL_SetError("Couldn't find any hardware audio formats");
Oct 17, 2006
Oct 17, 2006
408
return 0;
Jul 10, 2006
Jul 10, 2006
409
}
Oct 17, 2006
Oct 17, 2006
410
this->spec.format = test_format;
Jul 10, 2006
Jul 10, 2006
411
412
413
/*
* We know the buffer size and the max number of subsequent writes
Oct 17, 2006
Oct 17, 2006
414
415
416
* that can be pending. If more than one can pend, allow the application
* to do something like double buffering between our write buffer and
* the device's own buffer that we are filling with write() anyway.
Jul 10, 2006
Jul 10, 2006
417
*
Oct 17, 2006
Oct 17, 2006
418
419
420
* We calculate this->spec.samples like this because
* SDL_CalculateAudioSpec() will give put paud_bufinfo.write_buf_cap
* (or paud_bufinfo.write_buf_cap/2) into this->spec.size in return.
Jul 10, 2006
Jul 10, 2006
421
422
*/
if (paud_bufinfo.request_buf_cap == 1) {
Oct 17, 2006
Oct 17, 2006
423
424
this->spec.samples = paud_bufinfo.write_buf_cap
/ bytes_per_sample / this->spec.channels;
Jul 10, 2006
Jul 10, 2006
425
} else {
Oct 17, 2006
Oct 17, 2006
426
427
this->spec.samples = paud_bufinfo.write_buf_cap
/ bytes_per_sample / this->spec.channels / 2;
Jul 10, 2006
Jul 10, 2006
428
}
Oct 17, 2006
Oct 17, 2006
429
paud_init.bsize = bytes_per_sample * this->spec.channels;
Jul 10, 2006
Jul 10, 2006
430
Oct 17, 2006
Oct 17, 2006
431
SDL_CalculateAudioSpec(&this->spec);
Jul 10, 2006
Jul 10, 2006
432
433
434
435
436
437
438
439
440
/*
* The AIX paud device init can't modify the values of the audio_init
* structure that we pass to it. So we don't need any recalculation
* of this stuff and no reinit call as in linux dsp and dma code.
*
* /dev/paud supports all of the encoding formats, so we don't need
* to do anything like reopening the device, either.
*/
Oct 17, 2006
Oct 17, 2006
441
if (ioctl(fd, AUDIO_INIT, &paud_init) < 0) {
Jul 10, 2006
Jul 10, 2006
442
443
switch (paud_init.rc) {
case 1:
Oct 17, 2006
Oct 17, 2006
444
err = "Couldn't set audio format: DSP can't do play requests";
Jul 10, 2006
Jul 10, 2006
445
446
break;
case 2:
Oct 17, 2006
Oct 17, 2006
447
err = "Couldn't set audio format: DSP can't do record requests";
Jul 10, 2006
Jul 10, 2006
448
449
break;
case 4:
Oct 17, 2006
Oct 17, 2006
450
err = "Couldn't set audio format: request was invalid";
Jul 10, 2006
Jul 10, 2006
451
452
break;
case 5:
Oct 17, 2006
Oct 17, 2006
453
err = "Couldn't set audio format: conflict with open's flags";
Jul 10, 2006
Jul 10, 2006
454
455
break;
case 6:
Oct 17, 2006
Oct 17, 2006
456
err = "Couldn't set audio format: out of DSP MIPS or memory";
Jul 10, 2006
Jul 10, 2006
457
458
break;
default:
Oct 17, 2006
Oct 17, 2006
459
err = "Couldn't set audio format: not documented in sys/audio.h";
Jul 10, 2006
Jul 10, 2006
460
461
462
463
break;
}
}
Oct 17, 2006
Oct 17, 2006
464
465
466
467
468
469
if (err != NULL) {
PAUDIO_CloseDevice(this);
SDL_SetError("Paudio: %s", err);
return 0;
}
Jul 10, 2006
Jul 10, 2006
470
/* Allocate mixing buffer */
Oct 17, 2006
Oct 17, 2006
471
472
473
474
475
476
this->hidden->mixlen = this->spec.size;
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
if (this->hidden->mixbuf == NULL) {
PAUDIO_CloseDevice(this);
SDL_OutOfMemory();
return 0;
Jul 10, 2006
Jul 10, 2006
477
}
Oct 17, 2006
Oct 17, 2006
478
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
Jul 10, 2006
Jul 10, 2006
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
/*
* Set some paramters: full volume, first speaker that we can find.
* Ignore the other settings for now.
*/
paud_change.input = AUDIO_IGNORE; /* the new input source */
paud_change.output = OUTPUT_1; /* EXTERNAL_SPEAKER,INTERNAL_SPEAKER,OUTPUT_1 */
paud_change.monitor = AUDIO_IGNORE; /* the new monitor state */
paud_change.volume = 0x7fffffff; /* volume level [0-0x7fffffff] */
paud_change.volume_delay = AUDIO_IGNORE; /* the new volume delay */
paud_change.balance = 0x3fffffff; /* the new balance */
paud_change.balance_delay = AUDIO_IGNORE; /* the new balance delay */
paud_change.treble = AUDIO_IGNORE; /* the new treble state */
paud_change.bass = AUDIO_IGNORE; /* the new bass state */
paud_change.pitch = AUDIO_IGNORE; /* the new pitch state */
paud_control.ioctl_request = AUDIO_CHANGE;
paud_control.request_info = (char *) &paud_change;
Oct 17, 2006
Oct 17, 2006
497
if (ioctl(fd, AUDIO_CONTROL, &paud_control) < 0) {
Apr 26, 2001
Apr 26, 2001
498
#ifdef DEBUG_AUDIO
Jul 10, 2006
Jul 10, 2006
499
fprintf(stderr, "Can't change audio display settings\n");
Apr 26, 2001
Apr 26, 2001
500
#endif
Jul 10, 2006
Jul 10, 2006
501
502
503
504
505
506
507
508
}
/*
* Tell the device to expect data. Actual start will wait for
* the first write() call.
*/
paud_control.ioctl_request = AUDIO_START;
paud_control.position = 0;
Oct 17, 2006
Oct 17, 2006
509
510
if (ioctl(fd, AUDIO_CONTROL, &paud_control) < 0) {
PAUDIO_CloseDevice(this);
Apr 26, 2001
Apr 26, 2001
511
#ifdef DEBUG_AUDIO
Jul 10, 2006
Jul 10, 2006
512
fprintf(stderr, "Can't start audio play\n");
Apr 26, 2001
Apr 26, 2001
513
#endif
Jul 10, 2006
Jul 10, 2006
514
SDL_SetError("Can't start audio play");
Oct 17, 2006
Oct 17, 2006
515
return 0;
Jul 10, 2006
Jul 10, 2006
516
517
518
}
/* Check to see if we need to use select() workaround */
Oct 17, 2006
Oct 17, 2006
519
520
if (workaround != NULL) {
this->hidden->frame_ticks = (float) (this->spec.samples * 1000) /
Oct 28, 2006
Oct 28, 2006
521
this->spec.freq;
Oct 17, 2006
Oct 17, 2006
522
this->hidden->next_frame = SDL_GetTicks() + this->hidden->frame_ticks;
Jul 10, 2006
Jul 10, 2006
523
}
Apr 26, 2001
Apr 26, 2001
524
Jul 10, 2006
Jul 10, 2006
525
/* We're ready to rock and roll. :-) */
Oct 17, 2006
Oct 17, 2006
526
527
528
529
return 1;
}
static int
Oct 28, 2006
Oct 28, 2006
530
PAUDIO_Init(SDL_AudioDriverImpl * impl)
Oct 17, 2006
Oct 17, 2006
531
532
533
534
535
536
537
538
539
540
541
542
543
544
{
int fd = OpenAudioPath(NULL, 0, OPEN_FLAGS, 0);
if (fd < 0) {
SDL_SetError("PAUDIO: Couldn't open audio device");
return 0;
}
close(fd);
/* Set the function pointers */
impl->OpenDevice = DSP_OpenDevice;
impl->PlayDevice = DSP_PlayDevice;
impl->PlayDevice = DSP_WaitDevice;
impl->GetDeviceBuf = DSP_GetDeviceBuf;
impl->CloseDevice = DSP_CloseDevice;
Oct 28, 2006
Oct 28, 2006
545
impl->OnlyHasDefaultOutputDevice = 1; /* !!! FIXME: add device enum! */
Oct 17, 2006
Oct 17, 2006
546
547
return 1;
Apr 26, 2001
Apr 26, 2001
548
549
}
Oct 17, 2006
Oct 17, 2006
550
551
552
553
AudioBootStrap PAUDIO_bootstrap = {
PAUDIO_DRIVER_NAME, "AIX Paudio", PAUDIO_Init, 0
};
Jul 10, 2006
Jul 10, 2006
554
/* vi: set ts=4 sw=4 expandtab: */