author | Sam Lantinga <slouken@libsdl.org> |
Sun, 16 Jun 2002 04:17:57 +0000 | |
changeset 418 | 337f3ec4c385 |
parent 297 | f6ffac90895c |
child 424 | b82518082828 |
permissions | -rw-r--r-- |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
1 |
Date: Sun, 16 Jun 2002 00:59:13 -0300 |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
2 |
From: Travis <smallfri@bigfoot.com> |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
3 |
To: slouken@libsdl.org |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
4 |
Subject: NTO Audio Fixes |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
5 |
|
0 | 6 |
/* |
7 |
SDL - Simple DirectMedia Layer |
|
297
f6ffac90895c
Updated copyright information for 2002
Sam Lantinga <slouken@libsdl.org>
parents:
283
diff
changeset
|
8 |
Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga |
0 | 9 |
|
10 |
This library is free software; you can redistribute it and/or |
|
11 |
modify it under the terms of the GNU Library General Public |
|
12 |
License as published by the Free Software Foundation; either |
|
13 |
version 2 of the License, or (at your option) any later version. |
|
14 |
||
15 |
This library is distributed in the hope that it will be useful, |
|
16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
18 |
Library General Public License for more details. |
|
19 |
||
20 |
You should have received a copy of the GNU Library General Public |
|
21 |
License along with this library; if not, write to the Free |
|
22 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
23 |
||
24 |
Sam Lantinga |
|
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
25 |
slouken@libsdl.org |
0 | 26 |
*/ |
27 |
||
28 |
#include <stdlib.h> |
|
29 |
#include <stdio.h> |
|
30 |
#include <string.h> |
|
31 |
#include <errno.h> |
|
32 |
#include <unistd.h> |
|
33 |
#include <fcntl.h> |
|
34 |
#include <signal.h> |
|
35 |
#include <sys/types.h> |
|
36 |
#include <sys/time.h> |
|
37 |
#include <sched.h> |
|
38 |
#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
|
39 |
#include <sys/select.h> |
0 | 40 |
|
41 |
#include "SDL_audio.h" |
|
42 |
#include "SDL_error.h" |
|
43 |
#include "SDL_audiomem.h" |
|
44 |
#include "SDL_audio_c.h" |
|
45 |
#include "SDL_timer.h" |
|
46 |
#include "SDL_nto_audio.h" |
|
47 |
||
48 |
/* The tag name used by NTO audio */ |
|
49 |
#define DRIVER_NAME "nto" |
|
50 |
||
51 |
/* default channel communication parameters */ |
|
52 |
#define DEFAULT_CPARAMS_RATE 22050 |
|
53 |
#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
|
54 |
#define DEFAULT_CPARAMS_FRAG_SIZE 4096 |
0 | 55 |
#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
|
56 |
#define DEFAULT_CPARAMS_FRAGS_MAX 1 |
0 | 57 |
|
58 |
/* 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
|
59 |
#define OPEN_FLAGS SND_PCM_OPEN_PLAYBACK |
0 | 60 |
|
61 |
/* Audio driver functions */ |
|
62 |
static int NTO_OpenAudio(_THIS, SDL_AudioSpec *spec); |
|
63 |
static void NTO_WaitAudio(_THIS); |
|
64 |
static void NTO_PlayAudio(_THIS); |
|
65 |
static Uint8 *NTO_GetAudioBuf(_THIS); |
|
66 |
static void NTO_CloseAudio(_THIS); |
|
67 |
||
68 |
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
|
69 |
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
|
70 |
static snd_pcm_channel_setup_t csetup; |
0 | 71 |
|
72 |
/* PCM transfer channel parameters initialize function */ |
|
73 |
static void init_pcm_cparams(snd_pcm_channel_params_t* cparams) |
|
74 |
{ |
|
75 |
memset(cparams,0,sizeof(snd_pcm_channel_params_t)); |
|
76 |
||
77 |
cparams->channel = SND_PCM_CHANNEL_PLAYBACK; |
|
78 |
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
|
79 |
cparams->start_mode = SND_PCM_START_DATA; |
0 | 80 |
cparams->stop_mode = SND_PCM_STOP_STOP; |
81 |
cparams->format.format = SND_PCM_SFMT_S16_LE; |
|
82 |
cparams->format.interleave = 1; |
|
83 |
cparams->format.rate = DEFAULT_CPARAMS_RATE; |
|
84 |
cparams->format.voices = DEFAULT_CPARAMS_VOICES; |
|
85 |
cparams->buf.block.frag_size = DEFAULT_CPARAMS_FRAG_SIZE; |
|
86 |
cparams->buf.block.frags_min = DEFAULT_CPARAMS_FRAGS_MIN; |
|
87 |
cparams->buf.block.frags_max = DEFAULT_CPARAMS_FRAGS_MAX; |
|
88 |
} |
|
89 |
||
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
90 |
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
|
91 |
{ |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
92 |
/* |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
93 |
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
|
94 |
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
|
95 |
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
|
96 |
*/ |
0 | 97 |
|
98 |
int available; |
|
99 |
int rval; |
|
100 |
snd_pcm_t *handle; |
|
101 |
||
102 |
available = 0; |
|
103 |
handle = NULL; |
|
104 |
||
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
105 |
rval = snd_pcm_open_preferred(&handle, NULL, NULL, OPEN_FLAGS); |
0 | 106 |
|
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
107 |
if (rval >= 0){ |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
108 |
available = 1; |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
109 |
|
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
110 |
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
|
111 |
SDL_SetError("snd_pcm_close failed: %s\n",snd_strerror(rval)); |
0 | 112 |
available = 0; |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
113 |
} |
0 | 114 |
} |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
115 |
else{ |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
116 |
SDL_SetError("snd_pcm_open failed: %s\n", snd_strerror(rval)); |
0 | 117 |
} |
118 |
||
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
119 |
#ifdef DEBUG_AUDIO |
0 | 120 |
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
|
121 |
#endif |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
122 |
|
0 | 123 |
return(available); |
124 |
} |
|
125 |
||
126 |
static void Audio_DeleteDevice(SDL_AudioDevice *device) |
|
127 |
{ |
|
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
128 |
#ifdef DEBUG_AUDIO |
0 | 129 |
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
|
130 |
#endif |
0 | 131 |
|
132 |
free(device->hidden); |
|
133 |
free(device); |
|
134 |
} |
|
135 |
||
136 |
static SDL_AudioDevice *Audio_CreateDevice(int devindex) |
|
137 |
{ |
|
138 |
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
|
139 |
#ifdef DEBUG_AUDIO |
0 | 140 |
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
|
141 |
#endif |
0 | 142 |
/* Initialize all variables that we clean on shutdown */ |
143 |
this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice)); |
|
144 |
if ( this ) { |
|
145 |
memset(this, 0, (sizeof *this)); |
|
146 |
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
|
147 |
malloc((sizeof *this->hidden)); |
0 | 148 |
} |
149 |
if ( (this == NULL) || (this->hidden == NULL) ) { |
|
150 |
SDL_OutOfMemory(); |
|
151 |
if ( this ) { |
|
152 |
free(this); |
|
153 |
} |
|
154 |
return(0); |
|
155 |
} |
|
156 |
memset(this->hidden, 0, (sizeof *this->hidden)); |
|
157 |
audio_handle = NULL; |
|
158 |
||
159 |
/* Set the function pointers */ |
|
160 |
this->OpenAudio = NTO_OpenAudio; |
|
161 |
this->WaitAudio = NTO_WaitAudio; |
|
162 |
this->PlayAudio = NTO_PlayAudio; |
|
163 |
this->GetAudioBuf = NTO_GetAudioBuf; |
|
164 |
this->CloseAudio = NTO_CloseAudio; |
|
165 |
||
166 |
this->free = Audio_DeleteDevice; |
|
167 |
||
168 |
return this; |
|
169 |
} |
|
170 |
||
171 |
/* Don't change the name from "ALSA_bootstrap" - that's how it's called */ |
|
172 |
AudioBootStrap ALSA_bootstrap = { |
|
173 |
DRIVER_NAME, "Neutrino PCM audio", |
|
174 |
Audio_Available, Audio_CreateDevice |
|
175 |
}; |
|
176 |
||
177 |
/* This function waits until it is possible to write a full sound buffer */ |
|
178 |
static void NTO_WaitAudio(_THIS) |
|
179 |
{ |
|
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
180 |
fd_set wfds; |
0 | 181 |
|
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
182 |
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
|
183 |
switch( select( audio_fd + 1, NULL, &wfds, NULL, NULL ) ) |
0 | 184 |
{ |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
185 |
case -1: |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
186 |
case 0: |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
187 |
/* Error */ |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
188 |
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
|
189 |
break; |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
190 |
default: |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
191 |
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
|
192 |
return; |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
193 |
} |
0 | 194 |
} |
195 |
||
196 |
static void NTO_PlayAudio(_THIS) |
|
197 |
{ |
|
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
198 |
int written, rval; |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
199 |
int towrite; |
0 | 200 |
|
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
201 |
#ifdef DEBUG_AUDIO |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
202 |
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
|
203 |
#endif |
0 | 204 |
|
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
205 |
if( !this->enabled){ |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
206 |
return; |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
207 |
} |
0 | 208 |
|
209 |
towrite = pcm_len; |
|
210 |
||
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
211 |
/* 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
|
212 |
do { |
0 | 213 |
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
|
214 |
#ifdef DEBUG_AUDIO |
0 | 215 |
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
|
216 |
#endif |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
217 |
if (written != towrite){ |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
218 |
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
|
219 |
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
|
220 |
#ifdef DEBUG_AUDIO |
0 | 221 |
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
|
222 |
#endif |
0 | 223 |
towrite -= written; //we wrote some data |
224 |
continue; |
|
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
225 |
} |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
226 |
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
|
227 |
if(errno == EIO){ |
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 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
|
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 |
if(errno == EINVAL){ |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
233 |
#ifdef DEBUG_AUDIO |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
234 |
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
|
235 |
#endif |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
236 |
} |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
237 |
|
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
238 |
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
|
239 |
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
|
240 |
#ifdef DEBUG_AUDIO |
0 | 241 |
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
|
242 |
#endif |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
243 |
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
|
244 |
return; |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
245 |
} |
0 | 246 |
|
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
247 |
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
|
248 |
#ifdef DEBUG_AUDIO |
0 | 249 |
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
|
250 |
#endif |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
251 |
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
|
252 |
#ifdef DEBUG_AUDIO |
0 | 253 |
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
|
254 |
#endif |
0 | 255 |
SDL_SetError("snd_pcm_plugin_prepare failed: %s\n",snd_strerror(rval) ); |
256 |
return; |
|
257 |
} |
|
258 |
} |
|
259 |
continue; |
|
260 |
} |
|
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
261 |
else{ |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
262 |
#ifdef DEBUG_AUDIO |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
263 |
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
|
264 |
#endif |
0 | 265 |
return; |
266 |
} |
|
267 |
||
268 |
} |
|
269 |
else |
|
270 |
{ |
|
271 |
towrite -= written; //we wrote all remaining data |
|
272 |
} |
|
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
273 |
} while ( (towrite > 0) && (this->enabled) ); |
0 | 274 |
|
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
275 |
/* 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
|
276 |
if ( towrite != 0 ) { |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
277 |
this->enabled = 0; |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
278 |
} |
0 | 279 |
return; |
280 |
} |
|
281 |
||
282 |
static Uint8 *NTO_GetAudioBuf(_THIS) |
|
283 |
{ |
|
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
284 |
#ifdef DEBUG_AUDIO |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
285 |
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
|
286 |
#endif |
0 | 287 |
return(pcm_buf); |
288 |
} |
|
289 |
||
290 |
static void NTO_CloseAudio(_THIS) |
|
291 |
{ |
|
292 |
int rval; |
|
293 |
||
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
294 |
#ifdef DEBUG_AUDIO |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
295 |
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
|
296 |
#endif |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
297 |
|
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
298 |
this->enabled = 0; |
0 | 299 |
|
300 |
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
|
301 |
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
|
302 |
SDL_SetError("snd_pcm_plugin_flush failed: %s\n",snd_strerror(rval)); |
0 | 303 |
return; |
304 |
} |
|
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
305 |
if ((rval = snd_pcm_close(audio_handle)) < 0){ |
0 | 306 |
SDL_SetError("snd_pcm_close failed: %s\n",snd_strerror(rval)); |
307 |
return; |
|
308 |
} |
|
309 |
audio_handle = NULL; |
|
310 |
} |
|
311 |
} |
|
312 |
||
313 |
static int NTO_OpenAudio(_THIS, SDL_AudioSpec *spec) |
|
314 |
{ |
|
315 |
int rval; |
|
316 |
int format; |
|
317 |
Uint16 test_format; |
|
318 |
int twidth; |
|
319 |
int found; |
|
320 |
||
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
321 |
#ifdef DEBUG_AUDIO |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
322 |
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
|
323 |
#endif |
0 | 324 |
|
325 |
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
|
326 |
this->enabled = 0; |
0 | 327 |
|
328 |
if ( pcm_buf != NULL ) { |
|
329 |
free((Uint8 *)pcm_buf); |
|
330 |
pcm_buf = NULL; |
|
331 |
} |
|
332 |
||
333 |
/* initialize channel transfer parameters to default */ |
|
334 |
init_pcm_cparams(&cparams); |
|
335 |
||
336 |
/* 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
|
337 |
rval = snd_pcm_open_preferred(&audio_handle, NULL, NULL, OPEN_FLAGS); |
0 | 338 |
if ( rval < 0 ) { |
339 |
SDL_SetError("snd_pcm_open failed: %s\n", snd_strerror(rval)); |
|
340 |
return(-1); |
|
341 |
} |
|
342 |
||
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
343 |
/* 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
|
344 |
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
|
345 |
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
|
346 |
return(-1); |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
347 |
} |
0 | 348 |
|
349 |
/* Try for a closest match on audio format */ |
|
350 |
format = 0; |
|
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
351 |
found = 0; /* can't use format as SND_PCM_SFMT_U8 = 0 in nto */ |
0 | 352 |
for ( test_format = SDL_FirstAudioFormat(spec->format); !found ; ) |
353 |
{ |
|
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
354 |
#ifdef DEBUG_AUDIO |
0 | 355 |
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
|
356 |
#endif |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
357 |
|
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
358 |
/* 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
|
359 |
switch ( test_format ) { |
0 | 360 |
case AUDIO_U8: |
361 |
format = SND_PCM_SFMT_U8; |
|
362 |
found = 1; |
|
363 |
break; |
|
364 |
case AUDIO_S8: |
|
365 |
format = SND_PCM_SFMT_S8; |
|
366 |
found = 1; |
|
367 |
break; |
|
368 |
case AUDIO_S16LSB: |
|
369 |
format = SND_PCM_SFMT_S16_LE; |
|
370 |
found = 1; |
|
371 |
break; |
|
372 |
case AUDIO_S16MSB: |
|
373 |
format = SND_PCM_SFMT_S16_BE; |
|
374 |
found = 1; |
|
375 |
break; |
|
376 |
case AUDIO_U16LSB: |
|
377 |
format = SND_PCM_SFMT_U16_LE; |
|
378 |
found = 1; |
|
379 |
break; |
|
380 |
case AUDIO_U16MSB: |
|
381 |
format = SND_PCM_SFMT_U16_BE; |
|
382 |
found = 1; |
|
383 |
break; |
|
384 |
default: |
|
385 |
break; |
|
386 |
} |
|
387 |
if ( ! found ) { |
|
388 |
test_format = SDL_NextAudioFormat(); |
|
389 |
} |
|
390 |
} |
|
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
391 |
|
0 | 392 |
/* assumes test_format not 0 on success */ |
393 |
if ( test_format == 0 ) { |
|
394 |
SDL_SetError("Couldn't find any hardware audio formats"); |
|
395 |
return(-1); |
|
396 |
} |
|
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
397 |
|
0 | 398 |
spec->format = test_format; |
399 |
||
400 |
/* Set the audio format */ |
|
401 |
cparams.format.format = format; |
|
402 |
||
403 |
/* Set mono or stereo audio (currently only two channels supported) */ |
|
404 |
cparams.format.voices = spec->channels; |
|
405 |
||
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
406 |
#ifdef DEBUG_AUDIO |
0 | 407 |
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
|
408 |
#endif |
0 | 409 |
|
410 |
/* Set rate */ |
|
411 |
cparams.format.rate = spec->freq ; |
|
412 |
||
413 |
/* Setup the transfer parameters according to cparams */ |
|
414 |
rval = snd_pcm_plugin_params(audio_handle, &cparams); |
|
415 |
if (rval < 0) { |
|
416 |
SDL_SetError("snd_pcm_channel_params failed: %s\n", snd_strerror (rval)); |
|
417 |
return(-1); |
|
418 |
} |
|
419 |
||
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
420 |
/* 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
|
421 |
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
|
422 |
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
|
423 |
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
|
424 |
{ |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
425 |
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
|
426 |
return(-1); |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
427 |
} |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
428 |
else |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
429 |
{ |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
430 |
#ifdef DEBUG_AUDIO |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
431 |
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
|
432 |
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
|
433 |
fprintf(stderr,"requested max frags: %d\n\n",cparams.buf.block.frags_max); |
0 | 434 |
|
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
435 |
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
|
436 |
fprintf(stderr,"real frag size : %d\n", csetup.buf.block.frag_size ); |
0 | 437 |
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
|
438 |
#endif |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
439 |
} |
0 | 440 |
|
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
441 |
/* |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
442 |
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
|
443 |
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
|
444 |
*/ |
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 |
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
|
447 |
if (twidth < 0) { |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
448 |
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
|
449 |
twidth = 0; |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
450 |
} |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
451 |
|
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
452 |
#ifdef DEBUG_AUDIO |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
453 |
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
|
454 |
#endif |
0 | 455 |
|
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
456 |
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
|
457 |
|
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
458 |
#ifdef DEBUG_AUDIO |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
459 |
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
|
460 |
#endif |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
461 |
|
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
462 |
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
|
463 |
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
|
464 |
} |
0 | 465 |
|
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
466 |
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
|
467 |
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
|
468 |
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
|
469 |
return(-1); |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
470 |
} |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
471 |
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
|
472 |
|
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
473 |
#ifdef DEBUG_AUDIO |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
474 |
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
|
475 |
#endif |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
476 |
|
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
477 |
/* 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
|
478 |
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
|
479 |
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
|
480 |
} |
0 | 481 |
|
482 |
/* Trigger audio playback */ |
|
483 |
rval = snd_pcm_plugin_prepare( audio_handle, SND_PCM_CHANNEL_PLAYBACK); |
|
484 |
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
|
485 |
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
|
486 |
return(-1); |
0 | 487 |
} |
418
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
488 |
|
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
489 |
this->enabled = 1; |
337f3ec4c385
Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
490 |
|
0 | 491 |
/* Get the parent process id (we're the parent of the audio thread) */ |
492 |
parent = getpid(); |
|
493 |
||
494 |
/* We're ready to rock and roll. :-) */ |
|
495 |
return(0); |
|
496 |
} |
|
497 |