annotate src/audio/nto/SDL_nto_audio.c @ 3833:de857f0708f5 SDL-ryan-multiple-audio-device

Whoops, changed that symbol name...
author Ryan C. Gordon <icculus@icculus.org>
date Sat, 07 Oct 2006 20:23:02 +0000
parents 7df0d3efe682
children 66fb40445587
rev   line source
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
769
b8d311d90021 Updated copyright information for 2004 (Happy New Year!)
Sam Lantinga <slouken@libsdl.org>
parents: 718
diff changeset
3 Copyright (C) 1997-2004 Sam Lantinga
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
4
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
6 modify it under the terms of the GNU Library General Public
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
8 version 2 of the License, or (at your option) any later version.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
9
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
13 Library General Public License for more details.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
14
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
15 You should have received a copy of the GNU Library General Public
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
16 License along with this library; if not, write to the Free
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
18
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
19 Sam Lantinga
252
e8157fcb3114 Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents: 0
diff changeset
20 slouken@libsdl.org
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
21 */
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
22 #include "SDL_config.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
23
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
24 #include <errno.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
25 #include <unistd.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
26 #include <fcntl.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
27 #include <signal.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
28 #include <sys/types.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
29 #include <sys/time.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
30 #include <sched.h>
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
31 #include <sys/select.h>
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
32 #include <sys/neutrino.h>
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
33 #include <sys/asoundlib.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
34
1358
c71e05b4dc2e More header massaging... works great on Windows. ;-)
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
35 #include "SDL_timer.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
36 #include "SDL_audio.h"
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
37 #include "../SDL_audiomem.h"
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
38 #include "../SDL_audio_c.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
39 #include "SDL_nto_audio.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
40
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
41 /* The tag name used by NTO audio */
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
42 #define DRIVER_NAME "qsa-nto"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
43
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
44 /* default channel communication parameters */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
45 #define DEFAULT_CPARAMS_RATE 22050
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
46 #define DEFAULT_CPARAMS_VOICES 1
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
47 /* FIXME: need to add in the near future flexible logic with frag_size and frags count */
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
48 #define DEFAULT_CPARAMS_FRAG_SIZE 4096
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
49 #define DEFAULT_CPARAMS_FRAGS_MIN 1
283
3d8b6b9f1e18 Date: Mon, 18 Feb 2002 16:46:59 +1200
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
50 #define DEFAULT_CPARAMS_FRAGS_MAX 1
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
51
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
52 /* Open the audio device for playback, and don't block if busy */
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
53 #define OPEN_FLAGS SND_PCM_OPEN_PLAYBACK
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
54
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
55 #define QSA_NO_WORKAROUNDS 0x00000000
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
56 #define QSA_MMAP_WORKAROUND 0x00000001
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
57
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
58 struct BuggyCards
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
59 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
60 char *cardname;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
61 unsigned long bugtype;
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
62 };
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
63
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
64 #define QSA_WA_CARDS 3
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
65
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
66 struct BuggyCards buggycards[QSA_WA_CARDS] = {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
67 {"Sound Blaster Live!", QSA_MMAP_WORKAROUND},
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
68 {"Vortex 8820", QSA_MMAP_WORKAROUND},
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
69 {"Vortex 8830", QSA_MMAP_WORKAROUND},
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
70 };
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
71
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
72
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
73 static inline void
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
74 NTO_SetError(const char *fn, int rval)
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
75 {
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
76 SDL_SetError("NTO: %s failed: %s", fn, snd_strerror(rval));
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
77 }
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
78
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
79
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
80 /* card names check to apply the workarounds */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
81 static int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
82 NTO_CheckBuggyCards(_THIS, unsigned long checkfor)
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
83 {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
84 char scardname[33];
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
85 int it;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
86
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
87 if (snd_card_get_name(this->hidden->cardno, scardname, 32) < 0) {
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
88 return 0;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
89 }
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
90
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
91 for (it = 0; it < QSA_WA_CARDS; it++) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
92 if (SDL_strcmp(buggycards[it].cardname, scardname) == 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
93 if (buggycards[it].bugtype == checkfor) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
94 return 1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
95 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
96 }
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
97 }
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
98
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
99 return 0;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
100 }
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
101
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
102 static void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
103 NTO_ThreadInit(_THIS)
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
104 {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
105 struct sched_param param;
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
106 int status = SchedGet(0, 0, &param);
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
107
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
108 /* increasing default 10 priority to 25 to avoid jerky sound */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
109 param.sched_priority = param.sched_curpriority + 15;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
110 status = SchedSet(0, 0, SCHED_NOCHANGE, &param);
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
111 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
112
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
113 /* PCM transfer channel parameters initialize function */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
114 static void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
115 NTO_InitAudioParams(snd_pcm_channel_params_t * cpars)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
116 {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
117 SDL_memset(cpars, 0, sizeof(snd_pcm_channel_params_t));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
118
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
119 cpars->channel = SND_PCM_CHANNEL_PLAYBACK;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
120 cpars->mode = SND_PCM_MODE_BLOCK;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
121 cpars->start_mode = SND_PCM_START_DATA;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
122 cpars->stop_mode = SND_PCM_STOP_STOP;
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
123 cpars->format.format = SND_PCM_SFMT_S16_LE;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
124 cpars->format.interleave = 1;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
125 cpars->format.rate = DEFAULT_CPARAMS_RATE;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
126 cpars->format.voices = DEFAULT_CPARAMS_VOICES;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
127 cpars->buf.block.frag_size = DEFAULT_CPARAMS_FRAG_SIZE;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
128 cpars->buf.block.frags_min = DEFAULT_CPARAMS_FRAGS_MIN;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
129 cpars->buf.block.frags_max = DEFAULT_CPARAMS_FRAGS_MAX;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
130 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
131
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
132 static int
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
133 NTO_Available(void)
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
134 {
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
135 /* See if we can open a nonblocking channel.
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
136 Return value '1' means we can.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
137 Return value '0' means we cannot. */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
138
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
139 int available = 0;
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
140 snd_pcm_t *handle = NULL;
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
141 int rval = snd_pcm_open_preferred(&handle, NULL, NULL, OPEN_FLAGS);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
142 if (rval >= 0) {
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
143 available = 1;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
144 if ((rval = snd_pcm_close(handle)) < 0) {
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
145 available = 0;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
146 }
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
147 }
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
148
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
149 return (available);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
150 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
151
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
152
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
153 /* This function waits until it is possible to write a full sound buffer */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
154 static void
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
155 NTO_WaitDevice(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
156 {
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
157 fd_set wfds;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
158 int selectret;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
159
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
160 FD_ZERO(&wfds);
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
161 FD_SET(this->hidden->audio_fd, &wfds);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
162
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
163 do {
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
164 selectret = select(this->hidden->audio_fd+1, NULL, &wfds, NULL, NULL);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
165 switch (selectret) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
166 case -1:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
167 case 0:
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
168 SDL_SetError("NTO: select() failed: %s\n", strerror(errno));
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
169 return;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
170 default:
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
171 if (FD_ISSET(this->hidden->audio_fd, &wfds)) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
172 return;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
173 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
174 break;
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
175 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
176 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
177 while (1);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
178 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
179
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
180 static void
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
181 NTO_PlayDevice(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
182 {
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
183 snd_pcm_channel_status_t cstatus;
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
184 int written, rval;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
185 int towrite;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
186 void *pcmbuffer;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
187
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
188 if ((!this->enabled) || (!this->hidden)) {
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
189 return;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
190 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
191
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
192 towrite = this->spec.size;
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
193 pcmbuffer = this->hidden->pcm_buf;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
194
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
195 /* Write the audio data, checking for EAGAIN (buffer full) and underrun */
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
196 do {
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
197 written = snd_pcm_plugin_write(this->hidden->audio_handle,
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
198 pcmbuffer, towrite);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
199 if (written != towrite) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
200 if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) {
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
201 /* Let a little CPU time go by and try to write again */
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
202 SDL_Delay(1);
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
203 /* if we wrote some data */
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
204 towrite -= written;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
205 pcmbuffer += written * this->spec.channels;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
206 continue;
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
207 } else if ((errno == EINVAL) || (errno == EIO)) {
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
208 SDL_memset(&cstatus, 0, sizeof (cstatus));
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
209 cstatus.channel = SND_PCM_CHANNEL_PLAYBACK;
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
210 rval = snd_pcm_plugin_status(this->hidden->audio_handle,
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
211 &cstatus);
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
212 if (rval < 0) {
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
213 NTO_SetError("snd_pcm_plugin_status", rval);
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
214 return;
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
215 }
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
216
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
217 if ( (cstatus.status == SND_PCM_STATUS_UNDERRUN) ||
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
218 (cstatus.status == SND_PCM_STATUS_READY)) {
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
219 rval = snd_pcm_plugin_prepare(this->hidden->audio_handle,
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
220 SND_PCM_CHANNEL_PLAYBACK);
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
221 if (rval < 0) {
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
222 NTO_SetError("snd_pcm_plugin_prepare", rval);
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
223 return;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
224 }
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
225 }
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
226 continue;
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
227 } else {
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
228 return;
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
229 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
230 } else {
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
231 /* we wrote all remaining data */
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
232 towrite -= written;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
233 pcmbuffer += written * this->spec.channels;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
234 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
235 }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
236 while ((towrite > 0) && (this->enabled));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
237
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
238 /* If we couldn't write, assume fatal error for now */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
239 if (towrite != 0) {
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
240 this->enabled = 0;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
241 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
242 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
243
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
244 static Uint8 *
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
245 NTO_GetDeviceBuf(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
246 {
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
247 return this->hidden->pcm_buf;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
248 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
249
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
250 static void
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
251 NTO_CloseDevice(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
252 {
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
253 if (this->hidden != NULL) {
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
254 if (this->hidden->audio_handle != NULL) {
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
255 snd_pcm_plugin_flush(this->hidden->audio_handle,
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
256 SND_PCM_CHANNEL_PLAYBACK);
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
257 snd_pcm_close(this->hidden->audio_handle);
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
258 this->hidden->audio_handle = NULL;
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
259 }
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
260 if (this->hidden->pcm_buf != NULL) {
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
261 SDL_FreeAudioMem(this->hidden->pcm_buf);
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
262 this->hidden->pcm_buf = NULL;
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
263 }
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
264 SDL_free(this->hidden);
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
265 this->hidden = NULL;
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
266 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
267 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
268
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
269 static int
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
270 NTO_OpenDevice(_THIS, const char *devname, int iscapture)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
271 {
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
272 int rval = 0;
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
273 int format = 0;
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
274 SDL_AudioFormat test_format = 0;
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
275 int found = 0;
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
276 snd_pcm_channel_setup_t csetup;
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
277 snd_pcm_channel_params_t cparams;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
278
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
279 /* Initialize all variables that we clean on shutdown */
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
280 this->hidden = (struct SDL_PrivateAudioData *)
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
281 SDL_malloc((sizeof *this->hidden));
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
282 if (this->hidden == NULL) {
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
283 SDL_OutOfMemory();
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
284 return 0;
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
285 }
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
286 SDL_memset(this->hidden, 0, (sizeof *this->hidden));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
287
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
288 /* initialize channel transfer parameters to default */
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
289 NTO_InitAudioParams(&cparams);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
290
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
291 /* Open the audio device */
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
292 rval = snd_pcm_open_preferred(&this->hidden->audio_handle,
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
293 &this->hidden->cardno,
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
294 &this->hidden->deviceno, OPEN_FLAGS);
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
295
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
296 if (rval < 0) {
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
297 NTO_CloseDevice(this);
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
298 NTO_SetError("snd_pcm_open", rval);
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
299 return 0;
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
300 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
301
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
302 if (!NTO_CheckBuggyCards(this, QSA_MMAP_WORKAROUND)) {
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
303 /* enable count status parameter */
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
304 rval = snd_pcm_plugin_set_disable(this->hidden->audio_handle,
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
305 PLUGIN_DISABLE_MMAP);
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
306 if (rval < 0) {
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
307 NTO_CloseDevice(this);
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
308 NTO_SetError("snd_pcm_plugin_set_disable", rval);
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
309 return 0;
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
310 }
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
311 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
312
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
313 /* Try for a closest match on audio format */
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
314 format = 0;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
315 /* can't use format as SND_PCM_SFMT_U8 = 0 in nto */
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
316 found = 0;
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
317
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
318 for (test_format = SDL_FirstAudioFormat(this->spec.format); !found;) {
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
319 /* if match found set format to equivalent ALSA format */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
320 switch (test_format) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
321 case AUDIO_U8:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
322 format = SND_PCM_SFMT_U8;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
323 found = 1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
324 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
325 case AUDIO_S8:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
326 format = SND_PCM_SFMT_S8;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
327 found = 1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
328 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
329 case AUDIO_S16LSB:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
330 format = SND_PCM_SFMT_S16_LE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
331 found = 1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
332 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
333 case AUDIO_S16MSB:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
334 format = SND_PCM_SFMT_S16_BE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
335 found = 1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
336 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
337 case AUDIO_U16LSB:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
338 format = SND_PCM_SFMT_U16_LE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
339 found = 1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
340 break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
341 case AUDIO_U16MSB:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
342 format = SND_PCM_SFMT_U16_BE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
343 found = 1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
344 break;
2007
cff63f857ff3 QNX6 support for int32/float32 (isn't this just ALSA?!)
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
345 case AUDIO_S32LSB:
cff63f857ff3 QNX6 support for int32/float32 (isn't this just ALSA?!)
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
346 format = SND_PCM_SFMT_S32_LE;
cff63f857ff3 QNX6 support for int32/float32 (isn't this just ALSA?!)
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
347 found = 1;
cff63f857ff3 QNX6 support for int32/float32 (isn't this just ALSA?!)
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
348 break;
cff63f857ff3 QNX6 support for int32/float32 (isn't this just ALSA?!)
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
349 case AUDIO_S32MSB:
cff63f857ff3 QNX6 support for int32/float32 (isn't this just ALSA?!)
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
350 format = SND_PCM_SFMT_S32_BE;
cff63f857ff3 QNX6 support for int32/float32 (isn't this just ALSA?!)
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
351 found = 1;
cff63f857ff3 QNX6 support for int32/float32 (isn't this just ALSA?!)
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
352 break;
cff63f857ff3 QNX6 support for int32/float32 (isn't this just ALSA?!)
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
353 case AUDIO_F32LSB:
cff63f857ff3 QNX6 support for int32/float32 (isn't this just ALSA?!)
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
354 format = SND_PCM_SFMT_FLOAT_LE;
cff63f857ff3 QNX6 support for int32/float32 (isn't this just ALSA?!)
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
355 found = 1;
cff63f857ff3 QNX6 support for int32/float32 (isn't this just ALSA?!)
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
356 break;
cff63f857ff3 QNX6 support for int32/float32 (isn't this just ALSA?!)
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
357 case AUDIO_F32MSB:
cff63f857ff3 QNX6 support for int32/float32 (isn't this just ALSA?!)
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
358 format = SND_PCM_SFMT_FLOAT_BE;
cff63f857ff3 QNX6 support for int32/float32 (isn't this just ALSA?!)
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
359 found = 1;
cff63f857ff3 QNX6 support for int32/float32 (isn't this just ALSA?!)
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
360 break;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
361 default:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
362 break;
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
363 }
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
364
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
365 if (!found) {
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
366 test_format = SDL_NextAudioFormat();
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
367 }
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
368 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
369
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
370 /* assumes test_format not 0 on success */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
371 if (test_format == 0) {
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
372 NTO_CloseDevice(this);
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
373 SDL_SetError("NTO: Couldn't find any hardware audio formats");
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
374 return 0;
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
375 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
376
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
377 this->spec.format = test_format;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
378
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
379 /* Set the audio format */
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
380 cparams.format.format = format;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
381
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
382 /* Set mono or stereo audio (currently only two channels supported) */
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
383 cparams.format.voices = this->spec.channels;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
384
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
385 /* Set rate */
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
386 cparams.format.rate = this->spec.freq;
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
387
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
388 /* Setup the transfer parameters according to cparams */
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
389 rval = snd_pcm_plugin_params(this->hidden->audio_handle, &cparams);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
390 if (rval < 0) {
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
391 NTO_CloseDevice(this);
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
392 NTO_SetError("snd_pcm_channel_params", rval);
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
393 return 0;
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
394 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
395
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
396 /* Make sure channel is setup right one last time */
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
397 SDL_memset(&csetup, '\0', sizeof (csetup));
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
398 csetup.channel = SND_PCM_CHANNEL_PLAYBACK;
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
399 if (snd_pcm_plugin_setup(this->hidden->audio_handle, &csetup) < 0) {
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
400 NTO_CloseDevice(this);
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
401 SDL_SetError("NTO: Unable to setup playback channel\n");
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
402 return 0;
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
403 }
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
404
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
405 /* Calculate the final parameters for this audio specification */
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
406 SDL_CalculateAudioSpec(&this->spec);
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
407
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
408 this->hidden->pcm_len = this->spec.size;
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
409
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
410 if (this->hidden->pcm_len == 0) {
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
411 this->hidden->pcm_len =
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
412 csetup.buf.block.frag_size * this->spec.channels *
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
413 (snd_pcm_format_width(format) / 8);
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
414 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
415
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
416 /*
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
417 * Allocate memory to the audio buffer and initialize with silence
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
418 * (Note that buffer size must be a multiple of fragment size, so find
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
419 * closest multiple)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
420 */
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
421 this->hidden->pcm_buf = (Uint8 *) SDL_AllocAudioMem(this->hidden->pcm_len);
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
422 if (this->hidden->pcm_buf == NULL) {
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
423 NTO_CloseDevice(this);
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
424 SDL_OutOfMemory();
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
425 return 0;
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
426 }
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
427 SDL_memset(this->hidden->pcm_buf,this->spec.silence,this->hidden->pcm_len);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
428
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
429 /* get the file descriptor */
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
430 this->hidden->audio_fd = snd_pcm_file_descriptor(this->hidden->audio_handle,
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
431 SND_PCM_CHANNEL_PLAYBACK);
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
432 if (this->hidden->audio_fd < 0) {
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
433 NTO_CloseDevice(this);
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
434 NTO_SetError("snd_pcm_file_descriptor", rval);
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
435 return 0;
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
436 }
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
437
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
438 /* Trigger audio playback */
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
439 rval = snd_pcm_plugin_prepare(this->hidden->audio_handle,
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
440 SND_PCM_CHANNEL_PLAYBACK);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
441 if (rval < 0) {
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
442 NTO_CloseDevice(this);
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
443 NTO_SetError("snd_pcm_plugin_prepare", rval);
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
444 return 0;
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
445 }
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
446
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
447 /* We're really ready to rock and roll. :-) */
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
448 return 1;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
449 }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
450
3831
7df0d3efe682 Forgot to add NTO_Init()...
Ryan C. Gordon <icculus@icculus.org>
parents: 3829
diff changeset
451
7df0d3efe682 Forgot to add NTO_Init()...
Ryan C. Gordon <icculus@icculus.org>
parents: 3829
diff changeset
452 static int
7df0d3efe682 Forgot to add NTO_Init()...
Ryan C. Gordon <icculus@icculus.org>
parents: 3829
diff changeset
453 NTO_Init(SDL_AudioDriverImpl *impl)
7df0d3efe682 Forgot to add NTO_Init()...
Ryan C. Gordon <icculus@icculus.org>
parents: 3829
diff changeset
454 {
7df0d3efe682 Forgot to add NTO_Init()...
Ryan C. Gordon <icculus@icculus.org>
parents: 3829
diff changeset
455 /* Set the function pointers */
7df0d3efe682 Forgot to add NTO_Init()...
Ryan C. Gordon <icculus@icculus.org>
parents: 3829
diff changeset
456 impl->OpenDevice = NTO_OpenDevice;
7df0d3efe682 Forgot to add NTO_Init()...
Ryan C. Gordon <icculus@icculus.org>
parents: 3829
diff changeset
457 impl->ThreadInit = NTO_ThreadInit;
7df0d3efe682 Forgot to add NTO_Init()...
Ryan C. Gordon <icculus@icculus.org>
parents: 3829
diff changeset
458 impl->WaitDevice = NTO_WaitDevice;
7df0d3efe682 Forgot to add NTO_Init()...
Ryan C. Gordon <icculus@icculus.org>
parents: 3829
diff changeset
459 impl->PlayDevice = NTO_PlayDevice;
7df0d3efe682 Forgot to add NTO_Init()...
Ryan C. Gordon <icculus@icculus.org>
parents: 3829
diff changeset
460 impl->GetDeviceBuf = NTO_GetDeviceBuf;
7df0d3efe682 Forgot to add NTO_Init()...
Ryan C. Gordon <icculus@icculus.org>
parents: 3829
diff changeset
461 impl->CloseDevice = NTO_CloseDevice;
7df0d3efe682 Forgot to add NTO_Init()...
Ryan C. Gordon <icculus@icculus.org>
parents: 3829
diff changeset
462 impl->OnlyHasDefaultOutputDevice = 1; /* !!! FIXME: add device enum! */
7df0d3efe682 Forgot to add NTO_Init()...
Ryan C. Gordon <icculus@icculus.org>
parents: 3829
diff changeset
463
7df0d3efe682 Forgot to add NTO_Init()...
Ryan C. Gordon <icculus@icculus.org>
parents: 3829
diff changeset
464 return 1;
7df0d3efe682 Forgot to add NTO_Init()...
Ryan C. Gordon <icculus@icculus.org>
parents: 3829
diff changeset
465 }
7df0d3efe682 Forgot to add NTO_Init()...
Ryan C. Gordon <icculus@icculus.org>
parents: 3829
diff changeset
466
3829
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
467 AudioBootStrap QNXNTOAUDIO_bootstrap = {
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
468 DRIVER_NAME, "QNX6 QSA-NTO Audio",
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
469 NTO_AudioAvailable, NTO_Init, 0
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
470 };
d3171647e661 Moved NTO audio driver to 1.3 API.
Ryan C. Gordon <icculus@icculus.org>
parents: 3798
diff changeset
471
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
472 /* vi: set ts=4 sw=4 expandtab: */