Mercurial > sdl-ios-xcode
annotate src/audio/nto/SDL_nto_audio.c @ 2049:5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Tue, 17 Oct 2006 09:15:21 +0000 |
parents | cff63f857ff3 |
children | 866052b01ee5 |
rev | line source |
---|---|
0 | 1 /* |
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 | 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 { |
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 |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
72 |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
73 static inline void |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
74 NTO_SetError(const char *fn, int rval) |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
75 { |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
76 SDL_SetError("NTO: %s failed: %s", fn, snd_strerror(rval)); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
77 } |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
78 |
0 | 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 |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
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; |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
106 int status = SchedGet(0, 0, ¶m); |
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, ¶m); |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
111 } |
0 | 112 |
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 | 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 | 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 | 130 } |
131 | |
132 | |
133 /* 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
|
134 static void |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
135 NTO_WaitDevice(_THIS) |
0 | 136 { |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
137 fd_set wfds; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
138 int selectret; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
139 |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
140 FD_ZERO(&wfds); |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
141 FD_SET(this->hidden->audio_fd, &wfds); |
0 | 142 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
143 do { |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
144 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
|
145 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
|
146 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
|
147 case 0: |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
148 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
|
149 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
|
150 default: |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
151 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
|
152 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
|
153 } |
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 break; |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
155 } |
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
|
156 } |
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
|
157 while (1); |
0 | 158 } |
159 | |
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
|
160 static void |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
161 NTO_PlayDevice(_THIS) |
0 | 162 { |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
163 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
|
164 int written, rval; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
165 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
|
166 void *pcmbuffer; |
0 | 167 |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
168 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
|
169 return; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
170 } |
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
|
171 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
172 towrite = this->spec.size; |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
173 pcmbuffer = this->hidden->pcm_buf; |
0 | 174 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
175 /* 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
|
176 do { |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
177 written = snd_pcm_plugin_write(this->hidden->audio_handle, |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
178 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
|
179 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
|
180 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
|
181 /* 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
|
182 SDL_Delay(1); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
183 /* if we wrote some data */ |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
184 towrite -= written; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
185 pcmbuffer += written * this->spec.channels; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
186 continue; |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
187 } else if ((errno == EINVAL) || (errno == EIO)) { |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
188 SDL_memset(&cstatus, 0, sizeof (cstatus)); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
189 cstatus.channel = SND_PCM_CHANNEL_PLAYBACK; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
190 rval = snd_pcm_plugin_status(this->hidden->audio_handle, |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
191 &cstatus); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
192 if (rval < 0) { |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
193 NTO_SetError("snd_pcm_plugin_status", rval); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
194 return; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
195 } |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
196 |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
197 if ( (cstatus.status == SND_PCM_STATUS_UNDERRUN) || |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
198 (cstatus.status == SND_PCM_STATUS_READY)) { |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
199 rval = snd_pcm_plugin_prepare(this->hidden->audio_handle, |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
200 SND_PCM_CHANNEL_PLAYBACK); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
201 if (rval < 0) { |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
202 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
|
203 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
|
204 } |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
205 } |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
206 continue; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
207 } else { |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
208 return; |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
209 } |
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
|
210 } else { |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
211 /* we wrote all remaining data */ |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
212 towrite -= written; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
213 pcmbuffer += written * this->spec.channels; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
214 } |
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
|
215 } |
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
|
216 while ((towrite > 0) && (this->enabled)); |
0 | 217 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
218 /* 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
|
219 if (towrite != 0) { |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
220 this->enabled = 0; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
221 } |
0 | 222 } |
223 | |
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 static Uint8 * |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
225 NTO_GetDeviceBuf(_THIS) |
0 | 226 { |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
227 return this->hidden->pcm_buf; |
0 | 228 } |
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 static void |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
231 NTO_CloseDevice(_THIS) |
0 | 232 { |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
233 if (this->hidden != NULL) { |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
234 if (this->hidden->audio_handle != NULL) { |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
235 snd_pcm_plugin_flush(this->hidden->audio_handle, |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
236 SND_PCM_CHANNEL_PLAYBACK); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
237 snd_pcm_close(this->hidden->audio_handle); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
238 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
|
239 } |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
240 if (this->hidden->pcm_buf != NULL) { |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
241 SDL_FreeAudioMem(this->hidden->pcm_buf); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
242 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
|
243 } |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
244 SDL_free(this->hidden); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
245 this->hidden = NULL; |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
246 } |
0 | 247 } |
248 | |
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
|
249 static int |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
250 NTO_OpenDevice(_THIS, const char *devname, int iscapture) |
0 | 251 { |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
252 int rval = 0; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
253 int format = 0; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
254 SDL_AudioFormat test_format = 0; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
255 int found = 0; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
256 snd_pcm_channel_setup_t csetup; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
257 snd_pcm_channel_params_t cparams; |
0 | 258 |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
259 /* Initialize all variables that we clean on shutdown */ |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
260 this->hidden = (struct SDL_PrivateAudioData *) |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
261 SDL_malloc((sizeof *this->hidden)); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
262 if (this->hidden == NULL) { |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
263 SDL_OutOfMemory(); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
264 return 0; |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
265 } |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
266 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); |
0 | 267 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
268 /* 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
|
269 NTO_InitAudioParams(&cparams); |
0 | 270 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
271 /* Open the audio device */ |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
272 rval = snd_pcm_open_preferred(&this->hidden->audio_handle, |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
273 &this->hidden->cardno, |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
274 &this->hidden->deviceno, OPEN_FLAGS); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
275 |
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
|
276 if (rval < 0) { |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
277 NTO_CloseDevice(this); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
278 NTO_SetError("snd_pcm_open", rval); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
279 return 0; |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
280 } |
0 | 281 |
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
|
282 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
|
283 /* enable count status parameter */ |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
284 rval = snd_pcm_plugin_set_disable(this->hidden->audio_handle, |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
285 PLUGIN_DISABLE_MMAP); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
286 if (rval < 0) { |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
287 NTO_CloseDevice(this); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
288 NTO_SetError("snd_pcm_plugin_set_disable", rval); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
289 return 0; |
718
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 } |
0 | 292 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
293 /* 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
|
294 format = 0; |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
295 /* 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
|
296 found = 0; |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
297 |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
298 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
|
299 /* 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
|
300 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
|
301 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
|
302 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
|
303 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
|
304 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
|
305 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
|
306 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
|
307 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
|
308 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
|
309 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
|
310 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
|
311 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
|
312 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
|
313 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
|
314 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
|
315 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
|
316 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
|
317 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
|
318 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
|
319 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
|
320 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
|
321 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
|
322 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
|
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; |
2007
cff63f857ff3
QNX6 support for int32/float32 (isn't this just ALSA?!)
Ryan C. Gordon <icculus@icculus.org>
parents:
1982
diff
changeset
|
325 case AUDIO_S32LSB: |
cff63f857ff3
QNX6 support for int32/float32 (isn't this just ALSA?!)
Ryan C. Gordon <icculus@icculus.org>
parents:
1982
diff
changeset
|
326 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
|
327 found = 1; |
cff63f857ff3
QNX6 support for int32/float32 (isn't this just ALSA?!)
Ryan C. Gordon <icculus@icculus.org>
parents:
1982
diff
changeset
|
328 break; |
cff63f857ff3
QNX6 support for int32/float32 (isn't this just ALSA?!)
Ryan C. Gordon <icculus@icculus.org>
parents:
1982
diff
changeset
|
329 case AUDIO_S32MSB: |
cff63f857ff3
QNX6 support for int32/float32 (isn't this just ALSA?!)
Ryan C. Gordon <icculus@icculus.org>
parents:
1982
diff
changeset
|
330 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
|
331 found = 1; |
cff63f857ff3
QNX6 support for int32/float32 (isn't this just ALSA?!)
Ryan C. Gordon <icculus@icculus.org>
parents:
1982
diff
changeset
|
332 break; |
cff63f857ff3
QNX6 support for int32/float32 (isn't this just ALSA?!)
Ryan C. Gordon <icculus@icculus.org>
parents:
1982
diff
changeset
|
333 case AUDIO_F32LSB: |
cff63f857ff3
QNX6 support for int32/float32 (isn't this just ALSA?!)
Ryan C. Gordon <icculus@icculus.org>
parents:
1982
diff
changeset
|
334 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
|
335 found = 1; |
cff63f857ff3
QNX6 support for int32/float32 (isn't this just ALSA?!)
Ryan C. Gordon <icculus@icculus.org>
parents:
1982
diff
changeset
|
336 break; |
cff63f857ff3
QNX6 support for int32/float32 (isn't this just ALSA?!)
Ryan C. Gordon <icculus@icculus.org>
parents:
1982
diff
changeset
|
337 case AUDIO_F32MSB: |
cff63f857ff3
QNX6 support for int32/float32 (isn't this just ALSA?!)
Ryan C. Gordon <icculus@icculus.org>
parents:
1982
diff
changeset
|
338 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
|
339 found = 1; |
cff63f857ff3
QNX6 support for int32/float32 (isn't this just ALSA?!)
Ryan C. Gordon <icculus@icculus.org>
parents:
1982
diff
changeset
|
340 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
|
341 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
|
342 break; |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
343 } |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
344 |
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
|
345 if (!found) { |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
346 test_format = SDL_NextAudioFormat(); |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
347 } |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
348 } |
0 | 349 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
350 /* 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
|
351 if (test_format == 0) { |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
352 NTO_CloseDevice(this); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
353 SDL_SetError("NTO: Couldn't find any hardware audio formats"); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
354 return 0; |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
355 } |
0 | 356 |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
357 this->spec.format = test_format; |
0 | 358 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
359 /* Set the audio format */ |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
360 cparams.format.format = format; |
0 | 361 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
362 /* Set mono or stereo audio (currently only two channels supported) */ |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
363 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
|
364 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
365 /* Set rate */ |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
366 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
|
367 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
368 /* Setup the transfer parameters according to cparams */ |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
369 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
|
370 if (rval < 0) { |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
371 NTO_CloseDevice(this); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
372 NTO_SetError("snd_pcm_channel_params", rval); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
373 return 0; |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
374 } |
0 | 375 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
376 /* Make sure channel is setup right one last time */ |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
377 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
|
378 csetup.channel = SND_PCM_CHANNEL_PLAYBACK; |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
379 if (snd_pcm_plugin_setup(this->hidden->audio_handle, &csetup) < 0) { |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
380 NTO_CloseDevice(this); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
381 SDL_SetError("NTO: Unable to setup playback channel\n"); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
382 return 0; |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
383 } |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
384 |
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
385 /* Calculate the final parameters for this audio specification */ |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
386 SDL_CalculateAudioSpec(&this->spec); |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
387 |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
388 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
|
389 |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
390 if (this->hidden->pcm_len == 0) { |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
391 this->hidden->pcm_len = |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
392 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
|
393 (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
|
394 } |
0 | 395 |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
396 /* |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
397 * Allocate memory to the audio buffer and initialize with silence |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
398 * (Note that buffer size must be a multiple of fragment size, so find |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
399 * 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
|
400 */ |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
401 this->hidden->pcm_buf = (Uint8 *) SDL_AllocAudioMem(this->hidden->pcm_len); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
402 if (this->hidden->pcm_buf == NULL) { |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
403 NTO_CloseDevice(this); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
404 SDL_OutOfMemory(); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
405 return 0; |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
406 } |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
407 SDL_memset(this->hidden->pcm_buf,this->spec.silence,this->hidden->pcm_len); |
0 | 408 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
409 /* get the file descriptor */ |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
410 this->hidden->audio_fd = snd_pcm_file_descriptor(this->hidden->audio_handle, |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
411 SND_PCM_CHANNEL_PLAYBACK); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
412 if (this->hidden->audio_fd < 0) { |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
413 NTO_CloseDevice(this); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
414 NTO_SetError("snd_pcm_file_descriptor", rval); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
415 return 0; |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
416 } |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
417 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
418 /* Trigger audio playback */ |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
419 rval = snd_pcm_plugin_prepare(this->hidden->audio_handle, |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
420 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
|
421 if (rval < 0) { |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
422 NTO_CloseDevice(this); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
423 NTO_SetError("snd_pcm_plugin_prepare", rval); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
424 return 0; |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
425 } |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
426 |
718
cbc0f7fabd1c
Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
427 /* We're really ready to rock and roll. :-) */ |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
428 return 1; |
0 | 429 } |
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
|
430 |
2049
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
431 |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
432 static int |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
433 NTO_Init(SDL_AudioDriverImpl *impl) |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
434 { |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
435 /* See if we can open a nonblocking channel. */ |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
436 snd_pcm_t *handle = NULL; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
437 int rval = snd_pcm_open_preferred(&handle, NULL, NULL, OPEN_FLAGS); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
438 if (rval < 0) { |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
439 SDL_SetError("NTO: couldn't open preferred audio device"); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
440 return 0; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
441 } |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
442 if ((rval = snd_pcm_close(handle)) < 0) { |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
443 SDL_SetError("NTO: couldn't close test audio device"); |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
444 return 0; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
445 } |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
446 |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
447 /* Set the function pointers */ |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
448 impl->OpenDevice = NTO_OpenDevice; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
449 impl->ThreadInit = NTO_ThreadInit; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
450 impl->WaitDevice = NTO_WaitDevice; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
451 impl->PlayDevice = NTO_PlayDevice; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
452 impl->GetDeviceBuf = NTO_GetDeviceBuf; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
453 impl->CloseDevice = NTO_CloseDevice; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
454 impl->OnlyHasDefaultOutputDevice = 1; /* !!! FIXME: add device enum! */ |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
455 |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
456 return 1; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
457 } |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
458 |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
459 AudioBootStrap QNXNTOAUDIO_bootstrap = { |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
460 DRIVER_NAME, "QNX6 QSA-NTO Audio", NTO_Init, 0 |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
461 }; |
5f6550e5184f
Merged SDL-ryan-multiple-audio-device branch r2803:2871 into the trunk.
Ryan C. Gordon <icculus@icculus.org>
parents:
2007
diff
changeset
|
462 |
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
|
463 /* vi: set ts=4 sw=4 expandtab: */ |