Mercurial > sdl-ios-xcode
annotate src/audio/nto/SDL_nto_audio.c @ 424:b82518082828
*** empty log message ***
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 10 Jul 2002 17:10:46 +0000 |
parents | 337f3ec4c385 |
children | 8bedd6d61642 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
297
f6ffac90895c
Updated copyright information for 2002
Sam Lantinga <slouken@libsdl.org>
parents:
283
diff
changeset
|
3 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 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 */ |
22 | |
23 #include <stdlib.h> | |
24 #include <stdio.h> | |
25 #include <string.h> | |
26 #include <errno.h> | |
27 #include <unistd.h> | |
28 #include <fcntl.h> | |
29 #include <signal.h> | |
30 #include <sys/types.h> | |
31 #include <sys/time.h> | |
32 #include <sched.h> | |
33 #include <sys/asoundlib.h> | |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
34 #include <sys/select.h> |
0 | 35 |
36 #include "SDL_audio.h" | |
37 #include "SDL_error.h" | |
38 #include "SDL_audiomem.h" | |
39 #include "SDL_audio_c.h" | |
40 #include "SDL_timer.h" | |
41 #include "SDL_nto_audio.h" | |
42 | |
43 /* The tag name used by NTO audio */ | |
44 #define DRIVER_NAME "nto" | |
45 | |
46 /* default channel communication parameters */ | |
47 #define DEFAULT_CPARAMS_RATE 22050 | |
48 #define DEFAULT_CPARAMS_VOICES 1 | |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
49 #define DEFAULT_CPARAMS_FRAG_SIZE 4096 |
0 | 50 #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
|
51 #define DEFAULT_CPARAMS_FRAGS_MAX 1 |
0 | 52 |
53 /* 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
|
54 #define OPEN_FLAGS SND_PCM_OPEN_PLAYBACK |
0 | 55 |
56 /* Audio driver functions */ | |
57 static int NTO_OpenAudio(_THIS, SDL_AudioSpec *spec); | |
58 static void NTO_WaitAudio(_THIS); | |
59 static void NTO_PlayAudio(_THIS); | |
60 static Uint8 *NTO_GetAudioBuf(_THIS); | |
61 static void NTO_CloseAudio(_THIS); | |
62 | |
63 static snd_pcm_channel_status_t cstatus; | |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
64 static snd_pcm_channel_params_t cparams; |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
65 static snd_pcm_channel_setup_t csetup; |
0 | 66 |
67 /* PCM transfer channel parameters initialize function */ | |
68 static void init_pcm_cparams(snd_pcm_channel_params_t* cparams) | |
69 { | |
70 memset(cparams,0,sizeof(snd_pcm_channel_params_t)); | |
71 | |
72 cparams->channel = SND_PCM_CHANNEL_PLAYBACK; | |
73 cparams->mode = SND_PCM_MODE_BLOCK; | |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
74 cparams->start_mode = SND_PCM_START_DATA; |
0 | 75 cparams->stop_mode = SND_PCM_STOP_STOP; |
76 cparams->format.format = SND_PCM_SFMT_S16_LE; | |
77 cparams->format.interleave = 1; | |
78 cparams->format.rate = DEFAULT_CPARAMS_RATE; | |
79 cparams->format.voices = DEFAULT_CPARAMS_VOICES; | |
80 cparams->buf.block.frag_size = DEFAULT_CPARAMS_FRAG_SIZE; | |
81 cparams->buf.block.frags_min = DEFAULT_CPARAMS_FRAGS_MIN; | |
82 cparams->buf.block.frags_max = DEFAULT_CPARAMS_FRAGS_MAX; | |
83 } | |
84 | |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
85 static int Audio_Available(void) |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
86 { |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
87 /* |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
88 See if we can open a nonblocking channel. |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
89 Return value '1' means we can. |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
90 Return value '0' means we cannot. |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
91 */ |
0 | 92 |
93 int available; | |
94 int rval; | |
95 snd_pcm_t *handle; | |
96 | |
97 available = 0; | |
98 handle = NULL; | |
99 | |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
100 rval = snd_pcm_open_preferred(&handle, NULL, NULL, OPEN_FLAGS); |
0 | 101 |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
102 if (rval >= 0){ |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
103 available = 1; |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
104 |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
105 if ((rval = snd_pcm_close(handle)) < 0){ |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
106 SDL_SetError("snd_pcm_close failed: %s\n",snd_strerror(rval)); |
0 | 107 available = 0; |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
108 } |
0 | 109 } |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
110 else{ |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
111 SDL_SetError("snd_pcm_open failed: %s\n", snd_strerror(rval)); |
0 | 112 } |
113 | |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
114 #ifdef DEBUG_AUDIO |
0 | 115 fprintf(stderr,"AudioAvailable rtns %d\n", available); |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
116 #endif |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
117 |
0 | 118 return(available); |
119 } | |
120 | |
121 static void Audio_DeleteDevice(SDL_AudioDevice *device) | |
122 { | |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
123 #ifdef DEBUG_AUDIO |
0 | 124 fprintf(stderr,"Audio_DeleteDevice\n"); |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
125 #endif |
0 | 126 |
127 free(device->hidden); | |
128 free(device); | |
129 } | |
130 | |
131 static SDL_AudioDevice *Audio_CreateDevice(int devindex) | |
132 { | |
133 SDL_AudioDevice *this; | |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
134 #ifdef DEBUG_AUDIO |
0 | 135 fprintf(stderr,"Audio_CreateDevice\n"); |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
136 #endif |
0 | 137 /* Initialize all variables that we clean on shutdown */ |
138 this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice)); | |
139 if ( this ) { | |
140 memset(this, 0, (sizeof *this)); | |
141 this->hidden = (struct SDL_PrivateAudioData *) | |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
142 malloc((sizeof *this->hidden)); |
0 | 143 } |
144 if ( (this == NULL) || (this->hidden == NULL) ) { | |
145 SDL_OutOfMemory(); | |
146 if ( this ) { | |
147 free(this); | |
148 } | |
149 return(0); | |
150 } | |
151 memset(this->hidden, 0, (sizeof *this->hidden)); | |
152 audio_handle = NULL; | |
153 | |
154 /* Set the function pointers */ | |
155 this->OpenAudio = NTO_OpenAudio; | |
156 this->WaitAudio = NTO_WaitAudio; | |
157 this->PlayAudio = NTO_PlayAudio; | |
158 this->GetAudioBuf = NTO_GetAudioBuf; | |
159 this->CloseAudio = NTO_CloseAudio; | |
160 | |
161 this->free = Audio_DeleteDevice; | |
162 | |
163 return this; | |
164 } | |
165 | |
166 /* Don't change the name from "ALSA_bootstrap" - that's how it's called */ | |
167 AudioBootStrap ALSA_bootstrap = { | |
168 DRIVER_NAME, "Neutrino PCM audio", | |
169 Audio_Available, Audio_CreateDevice | |
170 }; | |
171 | |
172 /* This function waits until it is possible to write a full sound buffer */ | |
173 static void NTO_WaitAudio(_THIS) | |
174 { | |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
175 fd_set wfds; |
0 | 176 |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
177 FD_SET( audio_fd, &wfds ); |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
178 switch( select( audio_fd + 1, NULL, &wfds, NULL, NULL ) ) |
0 | 179 { |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
180 case -1: |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
181 case 0: |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
182 /* Error */ |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
183 SDL_SetError("select() in NTO_WaitAudio failed: %s\n", strerror(errno)); |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
184 break; |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
185 default: |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
186 if(FD_ISSET(audio_fd, &wfds)) |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
187 return; |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
188 } |
0 | 189 } |
190 | |
191 static void NTO_PlayAudio(_THIS) | |
192 { | |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
193 int written, rval; |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
194 int towrite; |
0 | 195 |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
196 #ifdef DEBUG_AUDIO |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
197 fprintf(stderr, "NTO_PlayAudio\n"); |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
198 #endif |
0 | 199 |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
200 if( !this->enabled){ |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
201 return; |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
202 } |
0 | 203 |
204 towrite = pcm_len; | |
205 | |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
206 /* Write the audio data, checking for EAGAIN (buffer full) and underrun */ |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
207 do { |
0 | 208 written = snd_pcm_plugin_write(audio_handle, pcm_buf, towrite); |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
209 #ifdef DEBUG_AUDIO |
0 | 210 fprintf(stderr, "NTO_PlayAudio: written = %d towrite = %d\n",written,towrite); |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
211 #endif |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
212 if (written != towrite){ |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
213 if ((errno == EAGAIN) || (errno == EWOULDBLOCK)){ |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
214 SDL_Delay(1); /* Let a little CPU time go by and try to write again */ |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
215 #ifdef DEBUG_AUDIO |
0 | 216 fprintf(stderr, "errno == EAGAIN written %d\n", written); |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
217 #endif |
0 | 218 towrite -= written; //we wrote some data |
219 continue; | |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
220 } |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
221 else if((errno == EINVAL) || (errno == EIO)){ |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
222 if(errno == EIO){ |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
223 #ifdef DEBUG_AUDIO |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
224 fprintf(stderr,"snd_pcm_plugin_write failed EIO: %s\n", snd_strerror(written)); |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
225 #endif |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
226 } |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
227 if(errno == EINVAL){ |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
228 #ifdef DEBUG_AUDIO |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
229 fprintf(stderr,"snd_pcm_plugin_write failed EINVAL: %s\n", snd_strerror(written)); |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
230 #endif |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
231 } |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
232 |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
233 memset(&cstatus, 0, sizeof(cstatus)); |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
234 if( (rval = snd_pcm_plugin_status(audio_handle, &cstatus)) < 0 ){ |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
235 #ifdef DEBUG_AUDIO |
0 | 236 fprintf(stderr, "snd_pcm_plugin_status failed %s\n",snd_strerror(rval)); |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
237 #endif |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
238 SDL_SetError("snd_pcm_plugin_status failed: %s\n", snd_strerror(rval)); |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
239 return; |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
240 } |
0 | 241 |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
242 if ( (cstatus.status == SND_PCM_STATUS_UNDERRUN) || (cstatus.status == SND_PCM_STATUS_READY) ){ |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
243 #ifdef DEBUG_AUDIO |
0 | 244 fprintf(stderr, "buffer underrun\n"); |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
245 #endif |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
246 if ( (rval = snd_pcm_plugin_prepare (audio_handle,SND_PCM_CHANNEL_PLAYBACK)) < 0 ){ |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
247 #ifdef DEBUG_AUDIO |
0 | 248 fprintf(stderr, "NTO_PlayAudio: prepare failed %s\n",snd_strerror(rval)); |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
249 #endif |
0 | 250 SDL_SetError("snd_pcm_plugin_prepare failed: %s\n",snd_strerror(rval) ); |
251 return; | |
252 } | |
253 } | |
254 continue; | |
255 } | |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
256 else{ |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
257 #ifdef DEBUG_AUDIO |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
258 fprintf(stderr, "NTO_PlayAudio: snd_pcm_plugin_write failed unknown errno %d %s\n",errno, snd_strerror(rval)); |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
259 #endif |
0 | 260 return; |
261 } | |
262 | |
263 } | |
264 else | |
265 { | |
266 towrite -= written; //we wrote all remaining data | |
267 } | |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
268 } while ( (towrite > 0) && (this->enabled) ); |
0 | 269 |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
270 /* If we couldn't write, assume fatal error for now */ |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
271 if ( towrite != 0 ) { |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
272 this->enabled = 0; |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
273 } |
0 | 274 return; |
275 } | |
276 | |
277 static Uint8 *NTO_GetAudioBuf(_THIS) | |
278 { | |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
279 #ifdef DEBUG_AUDIO |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
280 fprintf(stderr, "NTO_GetAudioBuf: pcm_buf %X\n",(Uint8 *)pcm_buf); |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
281 #endif |
0 | 282 return(pcm_buf); |
283 } | |
284 | |
285 static void NTO_CloseAudio(_THIS) | |
286 { | |
287 int rval; | |
288 | |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
289 #ifdef DEBUG_AUDIO |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
290 fprintf(stderr, "NTO_CloseAudio\n"); |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
291 #endif |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
292 |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
293 this->enabled = 0; |
0 | 294 |
295 if ( audio_handle != NULL ) { | |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
296 if ((rval = snd_pcm_plugin_flush(audio_handle,SND_PCM_CHANNEL_PLAYBACK)) < 0){ |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
297 SDL_SetError("snd_pcm_plugin_flush failed: %s\n",snd_strerror(rval)); |
0 | 298 return; |
299 } | |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
300 if ((rval = snd_pcm_close(audio_handle)) < 0){ |
0 | 301 SDL_SetError("snd_pcm_close failed: %s\n",snd_strerror(rval)); |
302 return; | |
303 } | |
304 audio_handle = NULL; | |
305 } | |
306 } | |
307 | |
308 static int NTO_OpenAudio(_THIS, SDL_AudioSpec *spec) | |
309 { | |
310 int rval; | |
311 int format; | |
312 Uint16 test_format; | |
313 int twidth; | |
314 int found; | |
315 | |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
316 #ifdef DEBUG_AUDIO |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
317 fprintf(stderr, "NTO_OpenAudio\n"); |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
318 #endif |
0 | 319 |
320 audio_handle = NULL; | |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
321 this->enabled = 0; |
0 | 322 |
323 if ( pcm_buf != NULL ) { | |
324 free((Uint8 *)pcm_buf); | |
325 pcm_buf = NULL; | |
326 } | |
327 | |
328 /* initialize channel transfer parameters to default */ | |
329 init_pcm_cparams(&cparams); | |
330 | |
331 /* Open the audio device */ | |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
332 rval = snd_pcm_open_preferred(&audio_handle, NULL, NULL, OPEN_FLAGS); |
0 | 333 if ( rval < 0 ) { |
334 SDL_SetError("snd_pcm_open failed: %s\n", snd_strerror(rval)); | |
335 return(-1); | |
336 } | |
337 | |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
338 /* enable count status parameter */ |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
339 if ((rval = snd_pcm_plugin_set_disable(audio_handle, PLUGIN_DISABLE_MMAP))<0){ |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
340 SDL_SetError("snd_pcm_plugin_set_disable failed: %s\n", snd_strerror(rval)); |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
341 return(-1); |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
342 } |
0 | 343 |
344 /* Try for a closest match on audio format */ | |
345 format = 0; | |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
346 found = 0; /* can't use format as SND_PCM_SFMT_U8 = 0 in nto */ |
0 | 347 for ( test_format = SDL_FirstAudioFormat(spec->format); !found ; ) |
348 { | |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
349 #ifdef DEBUG_AUDIO |
0 | 350 fprintf(stderr, "Trying format 0x%4.4x spec->samples %d\n", test_format,spec->samples); |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
351 #endif |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
352 |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
353 /* if match found set format to equivalent ALSA format */ |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
354 switch ( test_format ) { |
0 | 355 case AUDIO_U8: |
356 format = SND_PCM_SFMT_U8; | |
357 found = 1; | |
358 break; | |
359 case AUDIO_S8: | |
360 format = SND_PCM_SFMT_S8; | |
361 found = 1; | |
362 break; | |
363 case AUDIO_S16LSB: | |
364 format = SND_PCM_SFMT_S16_LE; | |
365 found = 1; | |
366 break; | |
367 case AUDIO_S16MSB: | |
368 format = SND_PCM_SFMT_S16_BE; | |
369 found = 1; | |
370 break; | |
371 case AUDIO_U16LSB: | |
372 format = SND_PCM_SFMT_U16_LE; | |
373 found = 1; | |
374 break; | |
375 case AUDIO_U16MSB: | |
376 format = SND_PCM_SFMT_U16_BE; | |
377 found = 1; | |
378 break; | |
379 default: | |
380 break; | |
381 } | |
382 if ( ! found ) { | |
383 test_format = SDL_NextAudioFormat(); | |
384 } | |
385 } | |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
386 |
0 | 387 /* assumes test_format not 0 on success */ |
388 if ( test_format == 0 ) { | |
389 SDL_SetError("Couldn't find any hardware audio formats"); | |
390 return(-1); | |
391 } | |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
392 |
0 | 393 spec->format = test_format; |
394 | |
395 /* Set the audio format */ | |
396 cparams.format.format = format; | |
397 | |
398 /* Set mono or stereo audio (currently only two channels supported) */ | |
399 cparams.format.voices = spec->channels; | |
400 | |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
401 #ifdef DEBUG_AUDIO |
0 | 402 fprintf(stderr,"intializing channels %d\n", cparams.format.voices); |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
403 #endif |
0 | 404 |
405 /* Set rate */ | |
406 cparams.format.rate = spec->freq ; | |
407 | |
408 /* Setup the transfer parameters according to cparams */ | |
409 rval = snd_pcm_plugin_params(audio_handle, &cparams); | |
410 if (rval < 0) { | |
411 SDL_SetError("snd_pcm_channel_params failed: %s\n", snd_strerror (rval)); | |
412 return(-1); | |
413 } | |
414 | |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
415 /* Make sure channel is setup right one last time */ |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
416 memset( &csetup, 0, sizeof( csetup ) ); |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
417 csetup.channel = SND_PCM_CHANNEL_PLAYBACK; |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
418 if ( snd_pcm_plugin_setup( audio_handle, &csetup ) < 0 ) |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
419 { |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
420 SDL_SetError("Unable to setup playback channel\n" ); |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
421 return(-1); |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
422 } |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
423 else |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
424 { |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
425 #ifdef DEBUG_AUDIO |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
426 fprintf(stderr,"requested format: %d\n",cparams.format.format); |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
427 fprintf(stderr,"requested frag size: %d\n",cparams.buf.block.frag_size); |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
428 fprintf(stderr,"requested max frags: %d\n\n",cparams.buf.block.frags_max); |
0 | 429 |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
430 fprintf(stderr,"real format: %d\n", csetup.format.format ); |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
431 fprintf(stderr,"real frag size : %d\n", csetup.buf.block.frag_size ); |
0 | 432 fprintf(stderr,"real max frags : %d\n", csetup.buf.block.frags_max ); |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
433 #endif |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
434 } |
0 | 435 |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
436 /* |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
437 Allocate memory to the audio buffer and initialize with silence (Note that |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
438 buffer size must be a multiple of fragment size, so find closest multiple) |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
439 */ |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
440 |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
441 twidth = snd_pcm_format_width(format); |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
442 if (twidth < 0) { |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
443 printf("snd_pcm_format_width failed\n"); |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
444 twidth = 0; |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
445 } |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
446 |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
447 #ifdef DEBUG_AUDIO |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
448 fprintf(stderr,"format is %d bits wide\n",twidth); |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
449 #endif |
0 | 450 |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
451 pcm_len = spec->size ; |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
452 |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
453 #ifdef DEBUG_AUDIO |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
454 fprintf(stderr,"pcm_len set to %d\n", pcm_len); |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
455 #endif |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
456 |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
457 if (pcm_len == 0){ |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
458 pcm_len = csetup.buf.block.frag_size; |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
459 } |
0 | 460 |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
461 pcm_buf = (Uint8*)malloc(pcm_len); |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
462 if (pcm_buf == NULL) { |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
463 SDL_SetError("pcm_buf malloc failed\n"); |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
464 return(-1); |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
465 } |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
466 memset(pcm_buf,spec->silence,pcm_len); |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
467 |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
468 #ifdef DEBUG_AUDIO |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
469 fprintf(stderr,"pcm_buf malloced and silenced.\n"); |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
470 #endif |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
471 |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
472 /* get the file descriptor */ |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
473 if( (audio_fd = snd_pcm_file_descriptor(audio_handle, SND_PCM_CHANNEL_PLAYBACK)) < 0){ |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
474 fprintf(stderr, "snd_pcm_file_descriptor failed with error code: %d\n", audio_fd); |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
475 } |
0 | 476 |
477 /* Trigger audio playback */ | |
478 rval = snd_pcm_plugin_prepare( audio_handle, SND_PCM_CHANNEL_PLAYBACK); | |
479 if (rval < 0) { | |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
480 SDL_SetError("snd_pcm_plugin_prepare failed: %s\n", snd_strerror (rval)); |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
481 return(-1); |
0 | 482 } |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
483 |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
484 this->enabled = 1; |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
485 |
0 | 486 /* Get the parent process id (we're the parent of the audio thread) */ |
487 parent = getpid(); | |
488 | |
489 /* We're ready to rock and roll. :-) */ | |
490 return(0); | |
491 } | |
492 |