Mercurial > sdl-ios-xcode
annotate src/audio/nto/SDL_nto_audio.c @ 4311:1238da4a7112 SDL-1.2
Debian patch: f230_manpages.diff
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 10 Oct 2009 10:09:01 +0000 |
parents | a1b03ba2fcd0 |
children |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
4159 | 3 Copyright (C) 1997-2009 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
9 | |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
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 | 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 | 23 |
24 #include <errno.h> | |
25 #include <unistd.h> | |
26 #include <fcntl.h> | |
27 #include <signal.h> | |
28 #include <sys/types.h> | |
29 #include <sys/time.h> | |
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 | 33 #include <sys/asoundlib.h> |
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 | 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 | 39 #include "SDL_nto_audio.h" |
40 | |
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 | 43 |
44 /* default channel communication parameters */ | |
45 #define DEFAULT_CPARAMS_RATE 22050 | |
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 | 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 | 51 |
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 | 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 { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
60 char* cardname; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
61 unsigned long bugtype; |
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 |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
66 struct BuggyCards buggycards[QSA_WA_CARDS]= |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
67 { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
68 {"Sound Blaster Live!", QSA_MMAP_WORKAROUND}, |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
69 {"Vortex 8820", QSA_MMAP_WORKAROUND}, |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
70 {"Vortex 8830", QSA_MMAP_WORKAROUND}, |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
71 }; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
72 |
0 | 73 /* Audio driver functions */ |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
74 static void NTO_ThreadInit(_THIS); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
75 static int NTO_OpenAudio(_THIS, SDL_AudioSpec* spec); |
0 | 76 static void NTO_WaitAudio(_THIS); |
77 static void NTO_PlayAudio(_THIS); | |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
78 static Uint8* NTO_GetAudioBuf(_THIS); |
0 | 79 static void NTO_CloseAudio(_THIS); |
80 | |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
81 /* card names check to apply the workarounds */ |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
82 static int NTO_CheckBuggyCards(_THIS, unsigned long checkfor) |
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; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
86 |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
87 if (snd_card_get_name(cardno, scardname, 32)<0) |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
88 { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
89 return 0; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
90 } |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
91 |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
92 for (it=0; it<QSA_WA_CARDS; it++) |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
93 { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
94 if (SDL_strcmp(buggycards[it].cardname, scardname)==0) |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
95 { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
96 if (buggycards[it].bugtype==checkfor) |
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 return 1; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
99 } |
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 } |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
102 |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
103 return 0; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
104 } |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
105 |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
106 static void NTO_ThreadInit(_THIS) |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
107 { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
108 int status; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
109 struct sched_param param; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
110 |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
111 /* increasing default 10 priority to 25 to avoid jerky sound */ |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
112 status=SchedGet(0, 0, ¶m); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
113 param.sched_priority=param.sched_curpriority+15; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
114 status=SchedSet(0, 0, SCHED_NOCHANGE, ¶m); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
115 } |
0 | 116 |
117 /* PCM transfer channel parameters initialize function */ | |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
118 static void NTO_InitAudioParams(snd_pcm_channel_params_t* cpars) |
0 | 119 { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
120 SDL_memset(cpars, 0, sizeof(snd_pcm_channel_params_t)); |
0 | 121 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
122 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
|
123 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
|
124 cpars->start_mode = SND_PCM_START_DATA; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
125 cpars->stop_mode = SND_PCM_STOP_STOP; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
126 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
|
127 cpars->format.interleave = 1; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
128 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
|
129 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
|
130 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
|
131 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
|
132 cpars->buf.block.frags_max = DEFAULT_CPARAMS_FRAGS_MAX; |
0 | 133 } |
134 | |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
135 static int NTO_AudioAvailable(void) |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
136 { |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
137 /* See if we can open a nonblocking channel. |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
138 Return value '1' means we can. |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
139 Return value '0' means we cannot. */ |
0 | 140 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
141 int available; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
142 int rval; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
143 snd_pcm_t* handle; |
0 | 144 |
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 handle = NULL; |
0 | 147 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
148 rval = snd_pcm_open_preferred(&handle, NULL, NULL, OPEN_FLAGS); |
0 | 149 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
150 if (rval >= 0) |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
151 { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
152 available = 1; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
153 |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
154 if ((rval = snd_pcm_close(handle)) < 0) |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
155 { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
156 SDL_SetError("NTO_AudioAvailable(): snd_pcm_close failed: %s\n", snd_strerror(rval)); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
157 available = 0; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
158 } |
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 else |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
161 { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
162 SDL_SetError("NTO_AudioAvailable(): there are no available audio devices.\n"); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
163 } |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
164 |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
165 return (available); |
0 | 166 } |
167 | |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
168 static void NTO_DeleteAudioDevice(SDL_AudioDevice *device) |
0 | 169 { |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
170 if ((device)&&(device->hidden)) |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
171 { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
172 SDL_free(device->hidden); |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
173 } |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
174 if (device) |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
175 { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
176 SDL_free(device); |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
177 } |
0 | 178 } |
179 | |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
180 static SDL_AudioDevice* NTO_CreateAudioDevice(int devindex) |
0 | 181 { |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
182 SDL_AudioDevice *this; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
183 |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
184 /* Initialize all variables that we clean on shutdown */ |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
185 this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
186 if (this) |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
187 { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
188 SDL_memset(this, 0, sizeof(SDL_AudioDevice)); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
189 this->hidden = (struct SDL_PrivateAudioData *)SDL_malloc(sizeof(struct SDL_PrivateAudioData)); |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
190 } |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
191 if ((this == NULL) || (this->hidden == NULL)) |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
192 { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
193 SDL_OutOfMemory(); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
194 if (this) |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
195 { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
196 SDL_free(this); |
0 | 197 } |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
198 return (0); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
199 } |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
200 SDL_memset(this->hidden, 0, sizeof(struct SDL_PrivateAudioData)); |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
201 audio_handle = NULL; |
0 | 202 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
203 /* Set the function pointers */ |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
204 this->ThreadInit = NTO_ThreadInit; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
205 this->OpenAudio = NTO_OpenAudio; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
206 this->WaitAudio = NTO_WaitAudio; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
207 this->PlayAudio = NTO_PlayAudio; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
208 this->GetAudioBuf = NTO_GetAudioBuf; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
209 this->CloseAudio = NTO_CloseAudio; |
0 | 210 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
211 this->free = NTO_DeleteAudioDevice; |
0 | 212 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
213 return this; |
0 | 214 } |
215 | |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
216 AudioBootStrap QNXNTOAUDIO_bootstrap = |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
217 { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
218 DRIVER_NAME, "QNX6 QSA-NTO Audio", |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
219 NTO_AudioAvailable, |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
220 NTO_CreateAudioDevice |
0 | 221 }; |
222 | |
223 /* This function waits until it is possible to write a full sound buffer */ | |
224 static void NTO_WaitAudio(_THIS) | |
225 { | |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
226 fd_set wfds; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
227 int selectret; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
228 |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
229 FD_ZERO(&wfds); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
230 FD_SET(audio_fd, &wfds); |
0 | 231 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
232 do { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
233 selectret=select(audio_fd + 1, NULL, &wfds, NULL, NULL); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
234 switch (selectret) |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
235 { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
236 case -1: |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
237 case 0: SDL_SetError("NTO_WaitAudio(): select() failed: %s\n", strerror(errno)); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
238 return; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
239 default: if (FD_ISSET(audio_fd, &wfds)) |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
240 { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
241 return; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
242 } |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
243 break; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
244 } |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
245 } while(1); |
0 | 246 } |
247 | |
248 static void NTO_PlayAudio(_THIS) | |
249 { | |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
250 int written, rval; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
251 int towrite; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
252 void* pcmbuffer; |
0 | 253 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
254 if (!this->enabled) |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
255 { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
256 return; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
257 } |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
258 |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
259 towrite = this->spec.size; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
260 pcmbuffer = pcm_buf; |
0 | 261 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
262 /* 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
|
263 do { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
264 written = snd_pcm_plugin_write(audio_handle, pcm_buf, towrite); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
265 if (written != towrite) |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
266 { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
267 if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
268 { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
269 /* 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
|
270 SDL_Delay(1); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
271 /* if we wrote some data */ |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
272 towrite -= written; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
273 pcmbuffer += written * this->spec.channels; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
274 continue; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
275 } |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
276 else |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
277 { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
278 if ((errno == EINVAL) || (errno == EIO)) |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
279 { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
280 SDL_memset(&cstatus, 0, sizeof(cstatus)); |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
281 cstatus.channel = SND_PCM_CHANNEL_PLAYBACK; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
282 if ((rval = snd_pcm_plugin_status(audio_handle, &cstatus)) < 0) |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
283 { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
284 SDL_SetError("NTO_PlayAudio(): snd_pcm_plugin_status failed: %s\n", snd_strerror(rval)); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
285 return; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
286 } |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
287 if ((cstatus.status == SND_PCM_STATUS_UNDERRUN) || (cstatus.status == SND_PCM_STATUS_READY)) |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
288 { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
289 if ((rval = snd_pcm_plugin_prepare(audio_handle, SND_PCM_CHANNEL_PLAYBACK)) < 0) |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
290 { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
291 SDL_SetError("NTO_PlayAudio(): snd_pcm_plugin_prepare failed: %s\n", snd_strerror(rval)); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
292 return; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
293 } |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
294 } |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
295 continue; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
296 } |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
297 else |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
298 { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
299 return; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
300 } |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
301 } |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
302 } |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
303 else |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
304 { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
305 /* we wrote all remaining data */ |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
306 towrite -= written; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
307 pcmbuffer += written * this->spec.channels; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
308 } |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
309 } while ((towrite > 0) && (this->enabled)); |
0 | 310 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
311 /* If we couldn't write, assume fatal error for now */ |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
312 if (towrite != 0) |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
313 { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
314 this->enabled = 0; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
315 } |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
316 |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
317 return; |
0 | 318 } |
319 | |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
320 static Uint8* NTO_GetAudioBuf(_THIS) |
0 | 321 { |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
322 return pcm_buf; |
0 | 323 } |
324 | |
325 static void NTO_CloseAudio(_THIS) | |
326 { | |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
327 int rval; |
0 | 328 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
329 this->enabled = 0; |
0 | 330 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
331 if (audio_handle != NULL) |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
332 { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
333 if ((rval = snd_pcm_plugin_flush(audio_handle, SND_PCM_CHANNEL_PLAYBACK)) < 0) |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
334 { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
335 SDL_SetError("NTO_CloseAudio(): snd_pcm_plugin_flush failed: %s\n", snd_strerror(rval)); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
336 return; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
337 } |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
338 if ((rval = snd_pcm_close(audio_handle)) < 0) |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
339 { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
340 SDL_SetError("NTO_CloseAudio(): snd_pcm_close failed: %s\n",snd_strerror(rval)); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
341 return; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
342 } |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
343 audio_handle = NULL; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
344 } |
0 | 345 } |
346 | |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
347 static int NTO_OpenAudio(_THIS, SDL_AudioSpec* spec) |
0 | 348 { |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
349 int rval; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
350 int format; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
351 Uint16 test_format; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
352 int found; |
0 | 353 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
354 audio_handle = NULL; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
355 this->enabled = 0; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
356 |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
357 if (pcm_buf != NULL) |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
358 { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
359 SDL_FreeAudioMem(pcm_buf); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
360 pcm_buf = NULL; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
361 } |
0 | 362 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
363 /* 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
|
364 NTO_InitAudioParams(&cparams); |
0 | 365 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
366 /* Open the audio device */ |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
367 rval = snd_pcm_open_preferred(&audio_handle, &cardno, &deviceno, OPEN_FLAGS); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
368 if (rval < 0) |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
369 { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
370 SDL_SetError("NTO_OpenAudio(): snd_pcm_open failed: %s\n", snd_strerror(rval)); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
371 return (-1); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
372 } |
0 | 373 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
374 if (!NTO_CheckBuggyCards(this, QSA_MMAP_WORKAROUND)) |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
375 { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
376 /* enable count status parameter */ |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
377 if ((rval = snd_pcm_plugin_set_disable(audio_handle, PLUGIN_DISABLE_MMAP)) < 0) |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
378 { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
379 SDL_SetError("snd_pcm_plugin_set_disable failed: %s\n", snd_strerror(rval)); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
380 return (-1); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
381 } |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
382 } |
0 | 383 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
384 /* 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
|
385 format = 0; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
386 /* 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
|
387 found = 0; |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
388 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
389 for (test_format=SDL_FirstAudioFormat(spec->format); !found ;) |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
390 { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
391 /* if match found set format to equivalent ALSA format */ |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
392 switch (test_format) |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
393 { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
394 case AUDIO_U8: |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
395 format = SND_PCM_SFMT_U8; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
396 found = 1; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
397 break; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
398 case AUDIO_S8: |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
399 format = SND_PCM_SFMT_S8; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
400 found = 1; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
401 break; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
402 case AUDIO_S16LSB: |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
403 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
|
404 found = 1; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
405 break; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
406 case AUDIO_S16MSB: |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
407 format = SND_PCM_SFMT_S16_BE; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
408 found = 1; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
409 break; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
410 case AUDIO_U16LSB: |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
411 format = SND_PCM_SFMT_U16_LE; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
412 found = 1; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
413 break; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
414 case AUDIO_U16MSB: |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
415 format = SND_PCM_SFMT_U16_BE; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
416 found = 1; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
417 break; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
418 default: |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
419 break; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
420 } |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
421 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
422 if (!found) |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
423 { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
424 test_format = SDL_NextAudioFormat(); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
425 } |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
426 } |
0 | 427 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
428 /* assumes test_format not 0 on success */ |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
429 if (test_format == 0) |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
430 { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
431 SDL_SetError("NTO_OpenAudio(): Couldn't find any hardware audio formats"); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
432 return (-1); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
433 } |
0 | 434 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
435 spec->format = test_format; |
0 | 436 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
437 /* Set the audio format */ |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
438 cparams.format.format = format; |
0 | 439 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
440 /* Set mono or stereo audio (currently only two channels supported) */ |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
441 cparams.format.voices = spec->channels; |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
442 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
443 /* Set rate */ |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
444 cparams.format.rate = spec->freq; |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
445 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
446 /* Setup the transfer parameters according to cparams */ |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
447 rval = snd_pcm_plugin_params(audio_handle, &cparams); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
448 if (rval < 0) |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
449 { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
450 SDL_SetError("NTO_OpenAudio(): snd_pcm_channel_params failed: %s\n", snd_strerror(rval)); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
451 return (-1); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
452 } |
0 | 453 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
454 /* Make sure channel is setup right one last time */ |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
455 SDL_memset(&csetup, 0x00, sizeof(csetup)); |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
456 csetup.channel = SND_PCM_CHANNEL_PLAYBACK; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
457 if (snd_pcm_plugin_setup(audio_handle, &csetup) < 0) |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
458 { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
459 SDL_SetError("NTO_OpenAudio(): Unable to setup playback channel\n"); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
460 return -1; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
461 } |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
462 |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
463 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
464 /* Calculate the final parameters for this audio specification */ |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
465 SDL_CalculateAudioSpec(spec); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
466 |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
467 pcm_len = spec->size; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
468 |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
469 if (pcm_len==0) |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
470 { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
471 pcm_len = csetup.buf.block.frag_size * spec->channels * (snd_pcm_format_width(format)/8); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
472 } |
0 | 473 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
474 /* Allocate memory to the audio buffer and initialize with silence (Note that |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
475 buffer size must be a multiple of fragment size, so find closest multiple) |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
476 */ |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
477 pcm_buf = (Uint8*)SDL_AllocAudioMem(pcm_len); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
478 if (pcm_buf == NULL) |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
479 { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
480 SDL_SetError("NTO_OpenAudio(): pcm buffer allocation failed\n"); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
481 return (-1); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
482 } |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
483 SDL_memset(pcm_buf, spec->silence, pcm_len); |
0 | 484 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
485 /* get the file descriptor */ |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
486 if ((audio_fd = snd_pcm_file_descriptor(audio_handle, SND_PCM_CHANNEL_PLAYBACK)) < 0) |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
487 { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
488 SDL_SetError("NTO_OpenAudio(): snd_pcm_file_descriptor failed with error code: %s\n", snd_strerror(rval)); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
489 return (-1); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
490 } |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
491 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
492 /* Trigger audio playback */ |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
493 rval = snd_pcm_plugin_prepare(audio_handle, SND_PCM_CHANNEL_PLAYBACK); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
494 if (rval < 0) |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
495 { |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
496 SDL_SetError("snd_pcm_plugin_prepare failed: %s\n", snd_strerror(rval)); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
497 return (-1); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
498 } |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
499 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
500 this->enabled = 1; |
0 | 501 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
502 /* Get the parent process id (we're the parent of the audio thread) */ |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
503 parent = getpid(); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
504 |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
505 /* We're really ready to rock and roll. :-) */ |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
506 return (0); |
0 | 507 } |