Mercurial > sdl-ios-xcode
comparison src/audio/dmedia/SDL_irixaudio.c @ 3851:405a192b68e7 SDL-1.2
Backport from 1.3: most of the audio drivers can now handle data
conversion at a higher level when they can't open the hardware in the
exact format requested.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Fri, 01 Sep 2006 22:50:24 +0000 |
parents | d910939febfa |
children | 5b5e549382b3 |
comparison
equal
deleted
inserted
replaced
3850:28db418c7573 | 3851:405a192b68e7 |
---|---|
137 alClosePort(audio_port); | 137 alClosePort(audio_port); |
138 audio_port = NULL; | 138 audio_port = NULL; |
139 } | 139 } |
140 } | 140 } |
141 | 141 |
142 static int AL_OpenAudio(_THIS, SDL_AudioSpec *spec) | 142 static int AL_OpenAudio(_THIS, SDL_AudioSpec * spec) |
143 { | 143 { |
144 ALconfig audio_config; | 144 SDL_AudioFormat test_format = SDL_FirstAudioFormat(spec->format); |
145 long width = 0; | |
146 long fmt = 0; | |
147 int valid = 0; | |
148 | |
145 #ifdef OLD_IRIX_AUDIO | 149 #ifdef OLD_IRIX_AUDIO |
146 long audio_param[2]; | 150 { |
151 long audio_param[2]; | |
152 audio_param[0] = AL_OUTPUT_RATE; | |
153 audio_param[1] = spec->freq; | |
154 valid = (ALsetparams(AL_DEFAULT_DEVICE, audio_param, 2) < 0); | |
155 } | |
147 #else | 156 #else |
148 ALpv audio_param; | 157 { |
158 ALpv audio_param; | |
159 audio_param.param = AL_RATE; | |
160 audio_param.value.i = spec->freq; | |
161 valid = (alSetParams(AL_DEFAULT_OUTPUT, &audio_param, 1) < 0); | |
162 } | |
149 #endif | 163 #endif |
150 int width; | 164 |
151 | 165 while ((!valid) && (test_format)) { |
152 /* Determine the audio parameters from the AudioSpec */ | 166 valid = 1; |
153 switch ( spec->format & 0xFF ) { | 167 spec->format = test_format; |
154 | 168 |
155 case 8: { /* Signed 8 bit audio data */ | 169 switch (test_format) { |
156 spec->format = AUDIO_S8; | 170 case AUDIO_S8: |
157 width = AL_SAMPLE_8; | 171 width = AL_SAMPLE_8; |
172 fmt = AL_SAMPFMT_TWOSCOMP; | |
173 break; | |
174 | |
175 case AUDIO_S16SYS: | |
176 width = AL_SAMPLE_16; | |
177 fmt = AL_SAMPFMT_TWOSCOMP; | |
178 break; | |
179 | |
180 default: | |
181 valid = 0; | |
182 test_format = SDL_NextAudioFormat(); | |
183 break; | |
158 } | 184 } |
159 break; | 185 |
160 | 186 if (valid) { |
161 case 16: { /* Signed 16 bit audio data */ | 187 ALconfig audio_config = alNewConfig(); |
162 spec->format = AUDIO_S16MSB; | 188 valid = 0; |
163 width = AL_SAMPLE_16; | 189 if (audio_config) { |
190 if (alSetChannels(audio_config, spec->channels) < 0) { | |
191 if (spec->channels > 2) { /* can't handle > stereo? */ | |
192 spec->channels = 2; /* try again below. */ | |
193 } | |
194 } | |
195 | |
196 if ((alSetSampFmt(audio_config, fmt) >= 0) && | |
197 ((!width) || (alSetWidth(audio_config, width) >= 0)) && | |
198 (alSetQueueSize(audio_config, spec->samples * 2) >= 0) && | |
199 (alSetChannels(audio_config, spec->channels) >= 0)) { | |
200 | |
201 audio_port = alOpenPort("SDL audio", "w", audio_config); | |
202 if (audio_port == NULL) { | |
203 /* docs say AL_BAD_CHANNELS happens here, too. */ | |
204 int err = oserror(); | |
205 if (err == AL_BAD_CHANNELS) { | |
206 spec->channels = 2; | |
207 alSetChannels(audio_config, spec->channels); | |
208 audio_port = alOpenPort("SDL audio", "w", | |
209 audio_config); | |
210 } | |
211 } | |
212 | |
213 if (audio_port != NULL) { | |
214 valid = 1; | |
215 } | |
216 } | |
217 | |
218 alFreeConfig(audio_config); | |
219 } | |
164 } | 220 } |
165 break; | 221 } |
166 | 222 |
167 default: { | 223 if (!valid) { |
168 SDL_SetError("Unsupported audio format"); | 224 SDL_SetError("Unsupported audio format"); |
169 return(-1); | 225 return (-1); |
170 } | |
171 } | 226 } |
172 | 227 |
173 /* Update the fragment size as size in bytes */ | 228 /* Update the fragment size as size in bytes */ |
174 SDL_CalculateAudioSpec(spec); | 229 SDL_CalculateAudioSpec(spec); |
175 | 230 |
176 /* Set output frequency */ | |
177 #ifdef OLD_IRIX_AUDIO | |
178 audio_param[0] = AL_OUTPUT_RATE; | |
179 audio_param[1] = spec->freq; | |
180 if( ALsetparams(AL_DEFAULT_DEVICE, audio_param, 2) < 0 ) { | |
181 #else | |
182 audio_param.param = AL_RATE; | |
183 audio_param.value.i = spec->freq; | |
184 if( alSetParams(AL_DEFAULT_OUTPUT, &audio_param, 1) < 0 ) { | |
185 #endif | |
186 SDL_SetError("alSetParams failed"); | |
187 return(-1); | |
188 } | |
189 | |
190 /* Open the audio port with the requested frequency */ | |
191 audio_port = NULL; | |
192 audio_config = alNewConfig(); | |
193 if ( audio_config && | |
194 (alSetSampFmt(audio_config, AL_SAMPFMT_TWOSCOMP) >= 0) && | |
195 (alSetWidth(audio_config, width) >= 0) && | |
196 (alSetQueueSize(audio_config, spec->samples*2) >= 0) && | |
197 (alSetChannels(audio_config, spec->channels) >= 0) ) { | |
198 audio_port = alOpenPort("SDL audio", "w", audio_config); | |
199 } | |
200 alFreeConfig(audio_config); | |
201 if( audio_port == NULL ) { | |
202 SDL_SetError("Unable to open audio port"); | |
203 return(-1); | |
204 } | |
205 | |
206 /* Allocate mixing buffer */ | 231 /* Allocate mixing buffer */ |
207 mixbuf = (Uint8 *)SDL_AllocAudioMem(spec->size); | 232 mixbuf = (Uint8 *) SDL_AllocAudioMem(spec->size); |
208 if ( mixbuf == NULL ) { | 233 if (mixbuf == NULL) { |
209 SDL_OutOfMemory(); | 234 SDL_OutOfMemory(); |
210 return(-1); | 235 return (-1); |
211 } | 236 } |
212 SDL_memset(mixbuf, spec->silence, spec->size); | 237 SDL_memset(mixbuf, spec->silence, spec->size); |
213 | 238 |
214 /* We're ready to rock and roll. :-) */ | 239 /* We're ready to rock and roll. :-) */ |
215 return(0); | 240 return (0); |
216 } | 241 } |
242 |