Mercurial > sdl-ios-xcode
comparison src/audio/dmedia/SDL_irixaudio.c @ 2002:7590aaf89a60
Cleaned up IRIX audio driver, added float32 support and fallbacks when
a specific audiospec isn't supported or the hardware fails.
Usual disclaimer: No IRIX box, so this may not even compile.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Fri, 01 Sep 2006 00:04:07 +0000 |
parents | c121d94672cb |
children | adf732f1f016 |
comparison
equal
deleted
inserted
replaced
2001:02108bfd6550 | 2002:7590aaf89a60 |
---|---|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | 17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
18 | 18 |
19 Sam Lantinga | 19 Sam Lantinga |
20 slouken@libsdl.org | 20 slouken@libsdl.org |
21 */ | 21 */ |
22 #include <errno.h> | |
22 #include "SDL_config.h" | 23 #include "SDL_config.h" |
23 | 24 |
24 /* Allow access to a raw mixing buffer (For IRIX 6.5 and higher) */ | 25 /* Allow access to a raw mixing buffer (For IRIX 6.5 and higher) */ |
25 /* patch for IRIX 5 by Georg Schwarz 18/07/2004 */ | 26 /* patch for IRIX 5 by Georg Schwarz 18/07/2004 */ |
26 | 27 |
147 } | 148 } |
148 | 149 |
149 static int | 150 static int |
150 AL_OpenAudio(_THIS, SDL_AudioSpec * spec) | 151 AL_OpenAudio(_THIS, SDL_AudioSpec * spec) |
151 { | 152 { |
152 ALconfig audio_config; | 153 SDL_AudioFormat test_format = SDL_FirstAudioFormat(spec->format); |
154 long width = 0; | |
155 long fmt = 0; | |
156 int valid = 0; | |
157 | |
153 #ifdef OLD_IRIX_AUDIO | 158 #ifdef OLD_IRIX_AUDIO |
154 long audio_param[2]; | 159 { |
160 long audio_param[2]; | |
161 audio_param[0] = AL_OUTPUT_RATE; | |
162 audio_param[1] = spec->freq; | |
163 valid = (ALsetparams(AL_DEFAULT_DEVICE, audio_param, 2) < 0); | |
164 } | |
155 #else | 165 #else |
156 ALpv audio_param; | 166 { |
167 ALpv audio_param; | |
168 audio_param.param = AL_RATE; | |
169 audio_param.value.i = spec->freq; | |
170 valid = (alSetParams(AL_DEFAULT_OUTPUT, &audio_param, 1) < 0); | |
171 } | |
157 #endif | 172 #endif |
158 int width; | 173 |
159 | 174 while ((!valid) && (test_format)) { |
160 /* Determine the audio parameters from the AudioSpec */ | 175 valid = 1; |
161 switch (spec->format & 0xFF) { | 176 spec->format = test_format; |
162 | 177 |
163 case 8: | 178 switch (test_format) { |
164 { /* Signed 8 bit audio data */ | 179 case AUDIO_S8: |
165 spec->format = AUDIO_S8; | 180 width = AL_SAMPLE_8; |
166 width = AL_SAMPLE_8; | 181 fmt = AL_SAMPFMT_TWOSCOMP; |
182 break; | |
183 | |
184 case AUDIO_S16SYS: | |
185 width = AL_SAMPLE_16; | |
186 fmt = AL_SAMPFMT_TWOSCOMP; | |
187 break; | |
188 | |
189 case AUDIO_F32SYS: | |
190 width = 0; /* not used here... */ | |
191 fmt = AL_SAMPFMT_FLOAT; | |
192 break; | |
193 | |
194 /* Docs say there is int24, but not int32.... */ | |
195 | |
196 default: | |
197 valid = 0; | |
198 test_format = SDL_NextAudioFormat(); | |
199 break; | |
167 } | 200 } |
168 break; | 201 |
169 | 202 if (valid) { |
170 case 16: | 203 ALconfig audio_config = alNewConfig(); |
171 { /* Signed 16 bit audio data */ | 204 valid = 0; |
172 spec->format = AUDIO_S16MSB; | 205 if (audio_config) { |
173 width = AL_SAMPLE_16; | 206 if (alSetChannels(audio_config, spec->channels) < 0) { |
207 if (spec->channels > 2) { /* can't handle > stereo? */ | |
208 spec->channels = 2; /* try again below. */ | |
209 } | |
210 } | |
211 | |
212 if ((alSetSampFmt(audio_config, fmt) >= 0) && | |
213 ((!width) || (alSetWidth(audio_config, width) >= 0)) && | |
214 (alSetQueueSize(audio_config, spec->samples * 2) >= 0) && | |
215 (alSetChannels(audio_config, spec->channels) >= 0)) { | |
216 | |
217 audio_port = alOpenPort("SDL audio", "w", audio_config); | |
218 if (audio_port == NULL) { | |
219 /* docs say AL_BAD_CHANNELS happens here, too. */ | |
220 int err = oserror(); | |
221 if (err == AL_BAD_CHANNELS) { | |
222 spec->channels = 2; | |
223 alSetChannels(audio_config, spec->channels); | |
224 audio_port = alOpenPort("SDL audio", "w", | |
225 audio_config); | |
226 } | |
227 } | |
228 | |
229 if (audio_port != NULL) { | |
230 valid = 1; | |
231 } | |
232 } | |
233 | |
234 alFreeConfig(audio_config); | |
235 } | |
174 } | 236 } |
175 break; | 237 } |
176 | 238 |
177 default: | 239 if (!valid) { |
178 { | 240 SDL_SetError("Unsupported audio format"); |
179 SDL_SetError("Unsupported audio format"); | 241 return (-1); |
180 return (-1); | |
181 } | |
182 } | 242 } |
183 | 243 |
184 /* Update the fragment size as size in bytes */ | 244 /* Update the fragment size as size in bytes */ |
185 SDL_CalculateAudioSpec(spec); | 245 SDL_CalculateAudioSpec(spec); |
186 | |
187 /* Set output frequency */ | |
188 #ifdef OLD_IRIX_AUDIO | |
189 audio_param[0] = AL_OUTPUT_RATE; | |
190 audio_param[1] = spec->freq; | |
191 if (ALsetparams(AL_DEFAULT_DEVICE, audio_param, 2) < 0) { | |
192 #else | |
193 audio_param.param = AL_RATE; | |
194 audio_param.value.i = spec->freq; | |
195 if (alSetParams(AL_DEFAULT_OUTPUT, &audio_param, 1) < 0) { | |
196 #endif | |
197 SDL_SetError("alSetParams failed"); | |
198 return (-1); | |
199 } | |
200 | |
201 /* Open the audio port with the requested frequency */ | |
202 audio_port = NULL; | |
203 audio_config = alNewConfig(); | |
204 if (audio_config && | |
205 (alSetSampFmt(audio_config, AL_SAMPFMT_TWOSCOMP) >= 0) && | |
206 (alSetWidth(audio_config, width) >= 0) && | |
207 (alSetQueueSize(audio_config, spec->samples * 2) >= 0) && | |
208 (alSetChannels(audio_config, spec->channels) >= 0)) { | |
209 audio_port = alOpenPort("SDL audio", "w", audio_config); | |
210 } | |
211 alFreeConfig(audio_config); | |
212 if (audio_port == NULL) { | |
213 SDL_SetError("Unable to open audio port"); | |
214 return (-1); | |
215 } | |
216 | 246 |
217 /* Allocate mixing buffer */ | 247 /* Allocate mixing buffer */ |
218 mixbuf = (Uint8 *) SDL_AllocAudioMem(spec->size); | 248 mixbuf = (Uint8 *) SDL_AllocAudioMem(spec->size); |
219 if (mixbuf == NULL) { | 249 if (mixbuf == NULL) { |
220 SDL_OutOfMemory(); | 250 SDL_OutOfMemory(); |