annotate src/audio/nto/SDL_nto_audio.c @ 769:b8d311d90021

Updated copyright information for 2004 (Happy New Year!)
author Sam Lantinga <slouken@libsdl.org>
date Sun, 04 Jan 2004 16:49:27 +0000
parents cbc0f7fabd1c
children 3692456e7b0f
rev   line source
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
769
b8d311d90021 Updated copyright information for 2004 (Happy New Year!)
Sam Lantinga <slouken@libsdl.org>
parents: 718
diff changeset
3 Copyright (C) 1997-2004 Sam Lantinga
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
4
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
6 modify it under the terms of the GNU Library General Public
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
8 version 2 of the License, or (at your option) any later version.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
9
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
13 Library General Public License for more details.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
14
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
15 You should have received a copy of the GNU Library General Public
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
16 License along with this library; if not, write to the Free
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
18
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
19 Sam Lantinga
252
e8157fcb3114 Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents: 0
diff changeset
20 slouken@libsdl.org
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
21 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
22
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
23 #include <stdlib.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
24 #include <stdio.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
25 #include <string.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
26 #include <errno.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
27 #include <unistd.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
28 #include <fcntl.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
29 #include <signal.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
30 #include <sys/types.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
31 #include <sys/time.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
32 #include <sched.h>
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
33 #include <sys/select.h>
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
34 #include <sys/neutrino.h>
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
35 #include <sys/asoundlib.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
36
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
37 #include "SDL_audio.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
38 #include "SDL_error.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
39 #include "SDL_audiomem.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
40 #include "SDL_audio_c.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
41 #include "SDL_timer.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
42 #include "SDL_nto_audio.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
43
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
44 /* 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
45 #define DRIVER_NAME "qsa-nto"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
46
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
47 /* default channel communication parameters */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
48 #define DEFAULT_CPARAMS_RATE 22050
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
49 #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
50 /* 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
51 #define DEFAULT_CPARAMS_FRAG_SIZE 4096
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
52 #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
53 #define DEFAULT_CPARAMS_FRAGS_MAX 1
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
54
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
55 /* 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
56 #define OPEN_FLAGS SND_PCM_OPEN_PLAYBACK
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
57
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
58 #define QSA_NO_WORKAROUNDS 0x00000000
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
59 #define QSA_MMAP_WORKAROUND 0x00000001
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
60
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
61 struct BuggyCards
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 char* cardname;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
64 unsigned long bugtype;
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
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
67 #define QSA_WA_CARDS 3
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
68
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
69 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
70 {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
71 {"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
72 {"Vortex 8820", QSA_MMAP_WORKAROUND},
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
73 {"Vortex 8830", QSA_MMAP_WORKAROUND},
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
74 };
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
75
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
76 /* Audio driver functions */
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
77 static void NTO_ThreadInit(_THIS);
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
78 static int NTO_OpenAudio(_THIS, SDL_AudioSpec* spec);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
79 static void NTO_WaitAudio(_THIS);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
80 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
81 static Uint8* NTO_GetAudioBuf(_THIS);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
82 static void NTO_CloseAudio(_THIS);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
83
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
84 /* 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
85 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
86 {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
87 char scardname[33];
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
88 int it;
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 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
91 {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
92 return 0;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
93 }
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
94
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
95 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
96 {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
97 if (strcmp(buggycards[it].cardname, scardname)==0)
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 if (buggycards[it].bugtype==checkfor)
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 return 1;
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 }
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 return 0;
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
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
109 static void NTO_ThreadInit(_THIS)
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 int status;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
112 struct sched_param param;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
113
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
114 /* 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
115 status=SchedGet(0, 0, &param);
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
116 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
117 status=SchedSet(0, 0, SCHED_NOCHANGE, &param);
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
118 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
119
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
120 /* 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
121 static void NTO_InitAudioParams(snd_pcm_channel_params_t* cpars)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
122 {
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
123 memset(cpars, 0, sizeof(snd_pcm_channel_params_t));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
124
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
125 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
126 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
127 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
128 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
129 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
130 cpars->format.interleave = 1;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
131 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
132 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
133 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
134 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
135 cpars->buf.block.frags_max = DEFAULT_CPARAMS_FRAGS_MAX;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
136 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
137
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
138 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
139 {
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
140 /* 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
141 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
142 Return value '0' means we cannot. */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
143
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
144 int available;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
145 int rval;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
146 snd_pcm_t* handle;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
147
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
148 available = 0;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
149 handle = NULL;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
150
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
151 rval = snd_pcm_open_preferred(&handle, NULL, NULL, OPEN_FLAGS);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
152
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
153 if (rval >= 0)
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
154 {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
155 available = 1;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
156
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
157 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
158 {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
159 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
160 available = 0;
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 }
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
163 else
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 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
166 }
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
167
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
168 return (available);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
169 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
170
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
171 static void NTO_DeleteAudioDevice(SDL_AudioDevice *device)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
172 {
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
173 if ((device)&&(device->hidden))
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
174 {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
175 free(device->hidden);
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
176 }
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
177 if (device)
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
178 {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
179 free(device);
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
180 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
181 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
182
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
183 static SDL_AudioDevice* NTO_CreateAudioDevice(int devindex)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
184 {
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
185 SDL_AudioDevice *this;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
186
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
187 /* Initialize all variables that we clean on shutdown */
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
188 this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
189 if (this)
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 memset(this, 0, sizeof(SDL_AudioDevice));
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
192 this->hidden = (struct SDL_PrivateAudioData *)malloc(sizeof(struct SDL_PrivateAudioData));
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
193 }
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
194 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
195 {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
196 SDL_OutOfMemory();
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
197 if (this)
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
198 {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
199 free(this);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
200 }
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
201 return (0);
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
202 }
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
203 memset(this->hidden, 0, sizeof(struct SDL_PrivateAudioData));
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
204 audio_handle = NULL;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
205
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
206 /* Set the function pointers */
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
207 this->ThreadInit = NTO_ThreadInit;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
208 this->OpenAudio = NTO_OpenAudio;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
209 this->WaitAudio = NTO_WaitAudio;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
210 this->PlayAudio = NTO_PlayAudio;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
211 this->GetAudioBuf = NTO_GetAudioBuf;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
212 this->CloseAudio = NTO_CloseAudio;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
213
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
214 this->free = NTO_DeleteAudioDevice;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
215
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
216 return this;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
217 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
218
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
219 AudioBootStrap QNXNTOAUDIO_bootstrap =
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
220 {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
221 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
222 NTO_AudioAvailable,
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
223 NTO_CreateAudioDevice
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
224 };
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
225
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
226 /* This function waits until it is possible to write a full sound buffer */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
227 static void NTO_WaitAudio(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
228 {
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
229 fd_set wfds;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
230 int selectret;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
231
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
232 FD_ZERO(&wfds);
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
233 FD_SET(audio_fd, &wfds);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
234
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
235 do {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
236 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
237 switch (selectret)
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
238 {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
239 case -1:
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
240 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
241 return;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
242 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
243 {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
244 return;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
245 }
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
246 break;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
247 }
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
248 } while(1);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
249 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
250
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
251 static void NTO_PlayAudio(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
252 {
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
253 int written, rval;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
254 int towrite;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
255 void* pcmbuffer;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
256
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
257 if (!this->enabled)
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 return;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
260 }
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
261
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
262 towrite = this->spec.size;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
263 pcmbuffer = pcm_buf;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
264
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
265 /* 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
266 do {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
267 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
268 if (written != towrite)
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
269 {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
270 if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
271 {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
272 /* 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
273 SDL_Delay(1);
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
274 /* if we wrote some data */
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
275 towrite -= written;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
276 pcmbuffer += written * this->spec.channels;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
277 continue;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
278 }
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
279 else
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
280 {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
281 if ((errno == EINVAL) || (errno == EIO))
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
282 {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
283 memset(&cstatus, 0, sizeof(cstatus));
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
284 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
285 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
286 {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
287 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
288 return;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
289 }
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
290 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
291 {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
292 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
293 {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
294 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
295 return;
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 }
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
298 continue;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
299 }
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
300 else
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 return;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
303 }
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 }
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
306 else
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
307 {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
308 /* we wrote all remaining data */
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
309 towrite -= written;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
310 pcmbuffer += written * this->spec.channels;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
311 }
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
312 } while ((towrite > 0) && (this->enabled));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
313
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
314 /* 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
315 if (towrite != 0)
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 this->enabled = 0;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
318 }
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
319
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
320 return;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
321 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
322
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
323 static Uint8* NTO_GetAudioBuf(_THIS)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
324 {
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
325 return pcm_buf;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
326 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
327
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
328 static void NTO_CloseAudio(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
329 {
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
330 int rval;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
331
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
332 this->enabled = 0;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
333
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
334 if (audio_handle != NULL)
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
335 {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
336 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
337 {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
338 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
339 return;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
340 }
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
341 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
342 {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
343 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
344 return;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
345 }
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
346 audio_handle = NULL;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
347 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
348 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
349
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
350 static int NTO_OpenAudio(_THIS, SDL_AudioSpec* spec)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
351 {
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
352 int rval;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
353 int format;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
354 Uint16 test_format;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
355 int found;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
356
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
357 audio_handle = NULL;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
358 this->enabled = 0;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
359
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
360 if (pcm_buf != NULL)
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
361 {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
362 SDL_FreeAudioMem(pcm_buf);
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
363 pcm_buf = NULL;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
364 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
365
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
366 /* 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
367 NTO_InitAudioParams(&cparams);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
368
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
369 /* Open the audio device */
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
370 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
371 if (rval < 0)
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
372 {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
373 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
374 return (-1);
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
375 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
376
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
377 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
378 {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
379 /* enable count status parameter */
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
380 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
381 {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
382 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
383 return (-1);
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 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
386
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
387 /* 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
388 format = 0;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
389 /* 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
390 found = 0;
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
391
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
392 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
393 {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
394 /* 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
395 switch (test_format)
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
396 {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
397 case AUDIO_U8:
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
398 format = SND_PCM_SFMT_U8;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
399 found = 1;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
400 break;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
401 case AUDIO_S8:
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
402 format = SND_PCM_SFMT_S8;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
403 found = 1;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
404 break;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
405 case AUDIO_S16LSB:
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
406 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
407 found = 1;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
408 break;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
409 case AUDIO_S16MSB:
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
410 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
411 found = 1;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
412 break;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
413 case AUDIO_U16LSB:
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
414 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
415 found = 1;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
416 break;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
417 case AUDIO_U16MSB:
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
418 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
419 found = 1;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
420 break;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
421 default:
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
422 break;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
423 }
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
424
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
425 if (!found)
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
426 {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
427 test_format = SDL_NextAudioFormat();
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
428 }
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
429 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
430
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
431 /* 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
432 if (test_format == 0)
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
433 {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
434 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
435 return (-1);
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
436 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
437
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
438 spec->format = test_format;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
439
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
440 /* Set the audio format */
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
441 cparams.format.format = format;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
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 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
444 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
445
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
446 /* Set rate */
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
447 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
448
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
449 /* 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
450 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
451 if (rval < 0)
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
452 {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
453 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
454 return (-1);
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
455 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
456
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
457 /* Make sure channel is setup right one last time */
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
458 memset(&csetup, 0x00, sizeof(csetup));
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
459 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
460 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
461 {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
462 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
463 return -1;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
464 }
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
465
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
466
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
467 /* 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
468 SDL_CalculateAudioSpec(spec);
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
469
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
470 pcm_len = spec->size;
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
471
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
472 if (pcm_len==0)
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
473 {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
474 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
475 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
476
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
477 /* 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
478 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
479 */
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
480 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
481 if (pcm_buf == NULL)
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
482 {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
483 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
484 return (-1);
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
485 }
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
486 memset(pcm_buf, spec->silence, pcm_len);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
487
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
488 /* get the file descriptor */
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
489 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
490 {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
491 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
492 return (-1);
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
493 }
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
494
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
495 /* Trigger audio playback */
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
496 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
497 if (rval < 0)
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
498 {
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
499 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
500 return (-1);
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
501 }
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
502
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
503 this->enabled = 1;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
504
718
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
505 /* 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
506 parent = getpid();
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
507
cbc0f7fabd1c Date: Sat, 13 Sep 2003 15:50:43 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 663
diff changeset
508 /* 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
509 return (0);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
510 }