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

Latest commit

 

History

History
526 lines (450 loc) · 14.4 KB

SDL_nto_audio.c

File metadata and controls

526 lines (450 loc) · 14.4 KB
 
Apr 26, 2001
Apr 26, 2001
1
2
/*
SDL - Simple DirectMedia Layer
Jan 4, 2004
Jan 4, 2004
3
Copyright (C) 1997-2004 Sam Lantinga
Apr 26, 2001
Apr 26, 2001
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
Dec 14, 2001
Dec 14, 2001
20
slouken@libsdl.org
Apr 26, 2001
Apr 26, 2001
21
*/
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
Apr 26, 2001
Apr 26, 2001
23
24
25
26
27
28
29
30
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sched.h>
Jun 16, 2002
Jun 16, 2002
31
#include <sys/select.h>
Sep 21, 2003
Sep 21, 2003
32
33
#include <sys/neutrino.h>
#include <sys/asoundlib.h>
Apr 26, 2001
Apr 26, 2001
34
Feb 10, 2006
Feb 10, 2006
35
#include "SDL_timer.h"
Apr 26, 2001
Apr 26, 2001
36
#include "SDL_audio.h"
Feb 16, 2006
Feb 16, 2006
37
38
#include "../SDL_audiomem.h"
#include "../SDL_audio_c.h"
Apr 26, 2001
Apr 26, 2001
39
40
41
#include "SDL_nto_audio.h"
/* The tag name used by NTO audio */
Sep 21, 2003
Sep 21, 2003
42
#define DRIVER_NAME "qsa-nto"
Apr 26, 2001
Apr 26, 2001
43
44
45
46
/* default channel communication parameters */
#define DEFAULT_CPARAMS_RATE 22050
#define DEFAULT_CPARAMS_VOICES 1
Sep 21, 2003
Sep 21, 2003
47
/* FIXME: need to add in the near future flexible logic with frag_size and frags count */
Jun 16, 2002
Jun 16, 2002
48
#define DEFAULT_CPARAMS_FRAG_SIZE 4096
Apr 26, 2001
Apr 26, 2001
49
#define DEFAULT_CPARAMS_FRAGS_MIN 1
Feb 20, 2002
Feb 20, 2002
50
#define DEFAULT_CPARAMS_FRAGS_MAX 1
Apr 26, 2001
Apr 26, 2001
51
52
/* Open the audio device for playback, and don't block if busy */
Jun 16, 2002
Jun 16, 2002
53
#define OPEN_FLAGS SND_PCM_OPEN_PLAYBACK
Apr 26, 2001
Apr 26, 2001
54
Sep 21, 2003
Sep 21, 2003
55
56
57
58
59
#define QSA_NO_WORKAROUNDS 0x00000000
#define QSA_MMAP_WORKAROUND 0x00000001
struct BuggyCards
{
Jul 10, 2006
Jul 10, 2006
60
61
char *cardname;
unsigned long bugtype;
Sep 21, 2003
Sep 21, 2003
62
63
64
65
};
#define QSA_WA_CARDS 3
Jul 10, 2006
Jul 10, 2006
66
67
68
69
struct BuggyCards buggycards[QSA_WA_CARDS] = {
{"Sound Blaster Live!", QSA_MMAP_WORKAROUND},
{"Vortex 8820", QSA_MMAP_WORKAROUND},
{"Vortex 8830", QSA_MMAP_WORKAROUND},
Sep 21, 2003
Sep 21, 2003
70
71
};
Apr 26, 2001
Apr 26, 2001
72
/* Audio driver functions */
Sep 21, 2003
Sep 21, 2003
73
static void NTO_ThreadInit(_THIS);
Jul 10, 2006
Jul 10, 2006
74
static int NTO_OpenAudio(_THIS, SDL_AudioSpec * spec);
Apr 26, 2001
Apr 26, 2001
75
76
static void NTO_WaitAudio(_THIS);
static void NTO_PlayAudio(_THIS);
Jul 10, 2006
Jul 10, 2006
77
static Uint8 *NTO_GetAudioBuf(_THIS);
Apr 26, 2001
Apr 26, 2001
78
79
static void NTO_CloseAudio(_THIS);
Sep 21, 2003
Sep 21, 2003
80
/* card names check to apply the workarounds */
Jul 10, 2006
Jul 10, 2006
81
82
static int
NTO_CheckBuggyCards(_THIS, unsigned long checkfor)
Sep 21, 2003
Sep 21, 2003
83
84
85
{
char scardname[33];
int it;
Jul 10, 2006
Jul 10, 2006
86
87
if (snd_card_get_name(cardno, scardname, 32) < 0) {
Sep 21, 2003
Sep 21, 2003
88
89
90
return 0;
}
Jul 10, 2006
Jul 10, 2006
91
92
93
94
95
96
for (it = 0; it < QSA_WA_CARDS; it++) {
if (SDL_strcmp(buggycards[it].cardname, scardname) == 0) {
if (buggycards[it].bugtype == checkfor) {
return 1;
}
}
Sep 21, 2003
Sep 21, 2003
97
98
99
100
}
return 0;
}
Apr 26, 2001
Apr 26, 2001
101
Jul 10, 2006
Jul 10, 2006
102
103
static void
NTO_ThreadInit(_THIS)
Apr 26, 2001
Apr 26, 2001
104
{
Jul 10, 2006
Jul 10, 2006
105
106
int status;
struct sched_param param;
Sep 21, 2003
Sep 21, 2003
107
Jul 10, 2006
Jul 10, 2006
108
109
110
111
/* increasing default 10 priority to 25 to avoid jerky sound */
status = SchedGet(0, 0, &param);
param.sched_priority = param.sched_curpriority + 15;
status = SchedSet(0, 0, SCHED_NOCHANGE, &param);
Apr 26, 2001
Apr 26, 2001
112
113
}
Sep 21, 2003
Sep 21, 2003
114
/* PCM transfer channel parameters initialize function */
Jul 10, 2006
Jul 10, 2006
115
116
static void
NTO_InitAudioParams(snd_pcm_channel_params_t * cpars)
Apr 26, 2001
Apr 26, 2001
117
{
Feb 7, 2006
Feb 7, 2006
118
SDL_memset(cpars, 0, sizeof(snd_pcm_channel_params_t));
Sep 21, 2003
Sep 21, 2003
119
120
121
122
cpars->channel = SND_PCM_CHANNEL_PLAYBACK;
cpars->mode = SND_PCM_MODE_BLOCK;
cpars->start_mode = SND_PCM_START_DATA;
Jul 10, 2006
Jul 10, 2006
123
cpars->stop_mode = SND_PCM_STOP_STOP;
Sep 21, 2003
Sep 21, 2003
124
125
126
127
128
129
130
cpars->format.format = SND_PCM_SFMT_S16_LE;
cpars->format.interleave = 1;
cpars->format.rate = DEFAULT_CPARAMS_RATE;
cpars->format.voices = DEFAULT_CPARAMS_VOICES;
cpars->buf.block.frag_size = DEFAULT_CPARAMS_FRAG_SIZE;
cpars->buf.block.frags_min = DEFAULT_CPARAMS_FRAGS_MIN;
cpars->buf.block.frags_max = DEFAULT_CPARAMS_FRAGS_MAX;
Apr 26, 2001
Apr 26, 2001
131
132
}
Jul 10, 2006
Jul 10, 2006
133
134
static int
NTO_AudioAvailable(void)
Apr 26, 2001
Apr 26, 2001
135
{
Sep 21, 2003
Sep 21, 2003
136
/* See if we can open a nonblocking channel.
Jul 10, 2006
Jul 10, 2006
137
138
Return value '1' means we can.
Return value '0' means we cannot. */
Sep 21, 2003
Sep 21, 2003
139
140
141
int available;
int rval;
Jul 10, 2006
Jul 10, 2006
142
snd_pcm_t *handle;
Sep 21, 2003
Sep 21, 2003
143
144
145
146
147
148
available = 0;
handle = NULL;
rval = snd_pcm_open_preferred(&handle, NULL, NULL, OPEN_FLAGS);
Jul 10, 2006
Jul 10, 2006
149
if (rval >= 0) {
Sep 21, 2003
Sep 21, 2003
150
151
available = 1;
Jul 10, 2006
Jul 10, 2006
152
153
154
155
if ((rval = snd_pcm_close(handle)) < 0) {
SDL_SetError
("NTO_AudioAvailable(): snd_pcm_close failed: %s\n",
snd_strerror(rval));
Sep 21, 2003
Sep 21, 2003
156
157
available = 0;
}
Jul 10, 2006
Jul 10, 2006
158
159
160
} else {
SDL_SetError
("NTO_AudioAvailable(): there are no available audio devices.\n");
Sep 21, 2003
Sep 21, 2003
161
162
163
164
}
return (available);
}
Apr 26, 2001
Apr 26, 2001
165
Jul 10, 2006
Jul 10, 2006
166
167
static void
NTO_DeleteAudioDevice(SDL_AudioDevice * device)
Sep 21, 2003
Sep 21, 2003
168
{
Jul 10, 2006
Jul 10, 2006
169
if ((device) && (device->hidden)) {
Feb 7, 2006
Feb 7, 2006
170
SDL_free(device->hidden);
Sep 21, 2003
Sep 21, 2003
171
}
Jul 10, 2006
Jul 10, 2006
172
if (device) {
Feb 7, 2006
Feb 7, 2006
173
SDL_free(device);
Sep 21, 2003
Sep 21, 2003
174
}
Apr 26, 2001
Apr 26, 2001
175
176
}
Jul 10, 2006
Jul 10, 2006
177
178
static SDL_AudioDevice *
NTO_CreateAudioDevice(int devindex)
Apr 26, 2001
Apr 26, 2001
179
{
Sep 21, 2003
Sep 21, 2003
180
181
182
SDL_AudioDevice *this;
/* Initialize all variables that we clean on shutdown */
Jul 10, 2006
Jul 10, 2006
183
184
this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
if (this) {
Feb 7, 2006
Feb 7, 2006
185
SDL_memset(this, 0, sizeof(SDL_AudioDevice));
Jul 10, 2006
Jul 10, 2006
186
187
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc(sizeof(struct SDL_PrivateAudioData));
Sep 21, 2003
Sep 21, 2003
188
}
Jul 10, 2006
Jul 10, 2006
189
if ((this == NULL) || (this->hidden == NULL)) {
Sep 21, 2003
Sep 21, 2003
190
SDL_OutOfMemory();
Jul 10, 2006
Jul 10, 2006
191
if (this) {
Feb 7, 2006
Feb 7, 2006
192
SDL_free(this);
Jul 10, 2006
Jul 10, 2006
193
}
Sep 21, 2003
Sep 21, 2003
194
195
return (0);
}
Feb 7, 2006
Feb 7, 2006
196
SDL_memset(this->hidden, 0, sizeof(struct SDL_PrivateAudioData));
Sep 21, 2003
Sep 21, 2003
197
198
199
200
201
202
203
204
205
206
207
208
209
audio_handle = NULL;
/* Set the function pointers */
this->ThreadInit = NTO_ThreadInit;
this->OpenAudio = NTO_OpenAudio;
this->WaitAudio = NTO_WaitAudio;
this->PlayAudio = NTO_PlayAudio;
this->GetAudioBuf = NTO_GetAudioBuf;
this->CloseAudio = NTO_CloseAudio;
this->free = NTO_DeleteAudioDevice;
return this;
Apr 26, 2001
Apr 26, 2001
210
211
}
Jul 10, 2006
Jul 10, 2006
212
AudioBootStrap QNXNTOAUDIO_bootstrap = {
Sep 21, 2003
Sep 21, 2003
213
214
215
DRIVER_NAME, "QNX6 QSA-NTO Audio",
NTO_AudioAvailable,
NTO_CreateAudioDevice
Apr 26, 2001
Apr 26, 2001
216
217
218
};
/* This function waits until it is possible to write a full sound buffer */
Jul 10, 2006
Jul 10, 2006
219
220
static void
NTO_WaitAudio(_THIS)
Apr 26, 2001
Apr 26, 2001
221
{
Sep 21, 2003
Sep 21, 2003
222
223
224
225
226
227
228
fd_set wfds;
int selectret;
FD_ZERO(&wfds);
FD_SET(audio_fd, &wfds);
do {
Jul 10, 2006
Jul 10, 2006
229
230
231
232
233
234
235
236
237
238
239
240
selectret = select(audio_fd + 1, NULL, &wfds, NULL, NULL);
switch (selectret) {
case -1:
case 0:
SDL_SetError("NTO_WaitAudio(): select() failed: %s\n",
strerror(errno));
return;
default:
if (FD_ISSET(audio_fd, &wfds)) {
return;
}
break;
Sep 21, 2003
Sep 21, 2003
241
}
Jul 10, 2006
Jul 10, 2006
242
243
}
while (1);
Apr 26, 2001
Apr 26, 2001
244
245
}
Jul 10, 2006
Jul 10, 2006
246
247
static void
NTO_PlayAudio(_THIS)
Apr 26, 2001
Apr 26, 2001
248
{
Sep 21, 2003
Sep 21, 2003
249
250
int written, rval;
int towrite;
Jul 10, 2006
Jul 10, 2006
251
void *pcmbuffer;
Sep 21, 2003
Sep 21, 2003
252
Jul 10, 2006
Jul 10, 2006
253
if (!this->enabled) {
Sep 21, 2003
Sep 21, 2003
254
255
return;
}
Jul 10, 2006
Jul 10, 2006
256
Sep 21, 2003
Sep 21, 2003
257
258
259
260
261
262
towrite = this->spec.size;
pcmbuffer = pcm_buf;
/* Write the audio data, checking for EAGAIN (buffer full) and underrun */
do {
written = snd_pcm_plugin_write(audio_handle, pcm_buf, towrite);
Jul 10, 2006
Jul 10, 2006
263
264
if (written != towrite) {
if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) {
Sep 21, 2003
Sep 21, 2003
265
266
267
268
269
270
/* Let a little CPU time go by and try to write again */
SDL_Delay(1);
/* if we wrote some data */
towrite -= written;
pcmbuffer += written * this->spec.channels;
continue;
Jul 10, 2006
Jul 10, 2006
271
272
} else {
if ((errno == EINVAL) || (errno == EIO)) {
Feb 7, 2006
Feb 7, 2006
273
SDL_memset(&cstatus, 0, sizeof(cstatus));
Sep 21, 2003
Sep 21, 2003
274
cstatus.channel = SND_PCM_CHANNEL_PLAYBACK;
Jul 10, 2006
Jul 10, 2006
275
276
277
278
279
if ((rval =
snd_pcm_plugin_status(audio_handle, &cstatus)) < 0) {
SDL_SetError
("NTO_PlayAudio(): snd_pcm_plugin_status failed: %s\n",
snd_strerror(rval));
Sep 21, 2003
Sep 21, 2003
280
return;
Jul 10, 2006
Jul 10, 2006
281
282
283
284
285
286
287
288
289
290
}
if ((cstatus.status == SND_PCM_STATUS_UNDERRUN)
|| (cstatus.status == SND_PCM_STATUS_READY)) {
if ((rval =
snd_pcm_plugin_prepare(audio_handle,
SND_PCM_CHANNEL_PLAYBACK))
< 0) {
SDL_SetError
("NTO_PlayAudio(): snd_pcm_plugin_prepare failed: %s\n",
snd_strerror(rval));
Sep 21, 2003
Sep 21, 2003
291
292
return;
}
Jul 10, 2006
Jul 10, 2006
293
}
Sep 21, 2003
Sep 21, 2003
294
continue;
Jul 10, 2006
Jul 10, 2006
295
} else {
Sep 21, 2003
Sep 21, 2003
296
297
298
return;
}
}
Jul 10, 2006
Jul 10, 2006
299
} else {
Sep 21, 2003
Sep 21, 2003
300
301
302
303
/* we wrote all remaining data */
towrite -= written;
pcmbuffer += written * this->spec.channels;
}
Jul 10, 2006
Jul 10, 2006
304
305
}
while ((towrite > 0) && (this->enabled));
Sep 21, 2003
Sep 21, 2003
306
307
/* If we couldn't write, assume fatal error for now */
Jul 10, 2006
Jul 10, 2006
308
if (towrite != 0) {
Sep 21, 2003
Sep 21, 2003
309
310
311
312
this->enabled = 0;
}
return;
Apr 26, 2001
Apr 26, 2001
313
314
}
Jul 10, 2006
Jul 10, 2006
315
316
static Uint8 *
NTO_GetAudioBuf(_THIS)
Apr 26, 2001
Apr 26, 2001
317
{
Sep 21, 2003
Sep 21, 2003
318
return pcm_buf;
Apr 26, 2001
Apr 26, 2001
319
320
}
Jul 10, 2006
Jul 10, 2006
321
322
static void
NTO_CloseAudio(_THIS)
Apr 26, 2001
Apr 26, 2001
323
{
Sep 21, 2003
Sep 21, 2003
324
325
326
327
int rval;
this->enabled = 0;
Jul 10, 2006
Jul 10, 2006
328
329
330
331
332
333
334
if (audio_handle != NULL) {
if ((rval =
snd_pcm_plugin_flush(audio_handle,
SND_PCM_CHANNEL_PLAYBACK)) < 0) {
SDL_SetError
("NTO_CloseAudio(): snd_pcm_plugin_flush failed: %s\n",
snd_strerror(rval));
Sep 21, 2003
Sep 21, 2003
335
336
return;
}
Jul 10, 2006
Jul 10, 2006
337
338
339
if ((rval = snd_pcm_close(audio_handle)) < 0) {
SDL_SetError("NTO_CloseAudio(): snd_pcm_close failed: %s\n",
snd_strerror(rval));
Sep 21, 2003
Sep 21, 2003
340
341
342
343
return;
}
audio_handle = NULL;
}
Apr 26, 2001
Apr 26, 2001
344
345
}
Jul 10, 2006
Jul 10, 2006
346
347
static int
NTO_OpenAudio(_THIS, SDL_AudioSpec * spec)
Apr 26, 2001
Apr 26, 2001
348
{
Sep 21, 2003
Sep 21, 2003
349
350
int rval;
int format;
Aug 24, 2006
Aug 24, 2006
351
SDL_AudioFormat test_format;
Sep 21, 2003
Sep 21, 2003
352
353
354
355
356
int found;
audio_handle = NULL;
this->enabled = 0;
Jul 10, 2006
Jul 10, 2006
357
358
if (pcm_buf != NULL) {
SDL_FreeAudioMem(pcm_buf);
Sep 21, 2003
Sep 21, 2003
359
360
361
362
363
364
365
pcm_buf = NULL;
}
/* initialize channel transfer parameters to default */
NTO_InitAudioParams(&cparams);
/* Open the audio device */
Jul 10, 2006
Jul 10, 2006
366
367
368
369
370
rval =
snd_pcm_open_preferred(&audio_handle, &cardno, &deviceno, OPEN_FLAGS);
if (rval < 0) {
SDL_SetError("NTO_OpenAudio(): snd_pcm_open failed: %s\n",
snd_strerror(rval));
Sep 21, 2003
Sep 21, 2003
371
372
373
return (-1);
}
Jul 10, 2006
Jul 10, 2006
374
if (!NTO_CheckBuggyCards(this, QSA_MMAP_WORKAROUND)) {
Sep 21, 2003
Sep 21, 2003
375
/* enable count status parameter */
Jul 10, 2006
Jul 10, 2006
376
377
378
379
380
if ((rval =
snd_pcm_plugin_set_disable(audio_handle,
PLUGIN_DISABLE_MMAP)) < 0) {
SDL_SetError("snd_pcm_plugin_set_disable failed: %s\n",
snd_strerror(rval));
Sep 21, 2003
Sep 21, 2003
381
382
383
384
385
386
387
388
389
return (-1);
}
}
/* Try for a closest match on audio format */
format = 0;
/* can't use format as SND_PCM_SFMT_U8 = 0 in nto */
found = 0;
Jul 10, 2006
Jul 10, 2006
390
for (test_format = SDL_FirstAudioFormat(spec->format); !found;) {
Sep 21, 2003
Sep 21, 2003
391
/* if match found set format to equivalent ALSA format */
Jul 10, 2006
Jul 10, 2006
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
switch (test_format) {
case AUDIO_U8:
format = SND_PCM_SFMT_U8;
found = 1;
break;
case AUDIO_S8:
format = SND_PCM_SFMT_S8;
found = 1;
break;
case AUDIO_S16LSB:
format = SND_PCM_SFMT_S16_LE;
found = 1;
break;
case AUDIO_S16MSB:
format = SND_PCM_SFMT_S16_BE;
found = 1;
break;
case AUDIO_U16LSB:
format = SND_PCM_SFMT_U16_LE;
found = 1;
break;
case AUDIO_U16MSB:
format = SND_PCM_SFMT_U16_BE;
found = 1;
break;
Sep 1, 2006
Sep 1, 2006
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
case AUDIO_S32LSB:
format = SND_PCM_SFMT_S32_LE;
found = 1;
break;
case AUDIO_S32MSB:
format = SND_PCM_SFMT_S32_BE;
found = 1;
break;
case AUDIO_F32LSB:
format = SND_PCM_SFMT_FLOAT_LE;
found = 1;
break;
case AUDIO_F32MSB:
format = SND_PCM_SFMT_FLOAT_BE;
found = 1;
break;
Jul 10, 2006
Jul 10, 2006
433
434
default:
break;
Sep 21, 2003
Sep 21, 2003
435
436
}
Jul 10, 2006
Jul 10, 2006
437
if (!found) {
Sep 21, 2003
Sep 21, 2003
438
439
440
441
442
test_format = SDL_NextAudioFormat();
}
}
/* assumes test_format not 0 on success */
Jul 10, 2006
Jul 10, 2006
443
444
445
if (test_format == 0) {
SDL_SetError
("NTO_OpenAudio(): Couldn't find any hardware audio formats");
Sep 21, 2003
Sep 21, 2003
446
447
448
449
450
451
452
453
454
455
return (-1);
}
spec->format = test_format;
/* Set the audio format */
cparams.format.format = format;
/* Set mono or stereo audio (currently only two channels supported) */
cparams.format.voices = spec->channels;
Jul 10, 2006
Jul 10, 2006
456
Sep 21, 2003
Sep 21, 2003
457
458
459
460
461
/* Set rate */
cparams.format.rate = spec->freq;
/* Setup the transfer parameters according to cparams */
rval = snd_pcm_plugin_params(audio_handle, &cparams);
Jul 10, 2006
Jul 10, 2006
462
463
464
465
if (rval < 0) {
SDL_SetError
("NTO_OpenAudio(): snd_pcm_channel_params failed: %s\n",
snd_strerror(rval));
Sep 21, 2003
Sep 21, 2003
466
467
468
469
return (-1);
}
/* Make sure channel is setup right one last time */
Feb 7, 2006
Feb 7, 2006
470
SDL_memset(&csetup, 0x00, sizeof(csetup));
Sep 21, 2003
Sep 21, 2003
471
csetup.channel = SND_PCM_CHANNEL_PLAYBACK;
Jul 10, 2006
Jul 10, 2006
472
if (snd_pcm_plugin_setup(audio_handle, &csetup) < 0) {
Sep 21, 2003
Sep 21, 2003
473
474
475
476
477
478
479
480
481
482
SDL_SetError("NTO_OpenAudio(): Unable to setup playback channel\n");
return -1;
}
/* Calculate the final parameters for this audio specification */
SDL_CalculateAudioSpec(spec);
pcm_len = spec->size;
Jul 10, 2006
Jul 10, 2006
483
484
485
486
if (pcm_len == 0) {
pcm_len =
csetup.buf.block.frag_size * spec->channels *
(snd_pcm_format_width(format) / 8);
Sep 21, 2003
Sep 21, 2003
487
488
489
490
}
/* Allocate memory to the audio buffer and initialize with silence (Note that
buffer size must be a multiple of fragment size, so find closest multiple)
Jul 10, 2006
Jul 10, 2006
491
492
493
*/
pcm_buf = (Uint8 *) SDL_AllocAudioMem(pcm_len);
if (pcm_buf == NULL) {
Sep 21, 2003
Sep 21, 2003
494
495
496
SDL_SetError("NTO_OpenAudio(): pcm buffer allocation failed\n");
return (-1);
}
Feb 7, 2006
Feb 7, 2006
497
SDL_memset(pcm_buf, spec->silence, pcm_len);
Sep 21, 2003
Sep 21, 2003
498
499
/* get the file descriptor */
Jul 10, 2006
Jul 10, 2006
500
501
502
503
504
505
if ((audio_fd =
snd_pcm_file_descriptor(audio_handle,
SND_PCM_CHANNEL_PLAYBACK)) < 0) {
SDL_SetError
("NTO_OpenAudio(): snd_pcm_file_descriptor failed with error code: %s\n",
snd_strerror(rval));
Sep 21, 2003
Sep 21, 2003
506
507
508
509
510
return (-1);
}
/* Trigger audio playback */
rval = snd_pcm_plugin_prepare(audio_handle, SND_PCM_CHANNEL_PLAYBACK);
Jul 10, 2006
Jul 10, 2006
511
512
513
if (rval < 0) {
SDL_SetError("snd_pcm_plugin_prepare failed: %s\n",
snd_strerror(rval));
Sep 21, 2003
Sep 21, 2003
514
515
516
517
518
519
520
521
522
523
return (-1);
}
this->enabled = 1;
/* Get the parent process id (we're the parent of the audio thread) */
parent = getpid();
/* We're really ready to rock and roll. :-) */
return (0);
Apr 26, 2001
Apr 26, 2001
524
}
Jul 10, 2006
Jul 10, 2006
525
526
/* vi: set ts=4 sw=4 expandtab: */