comparison src/audio/alsa/SDL_alsa_audio.c @ 1878:d7c9d7f42881

Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio. Untested, but potentially fixes Bugzilla #110.
author Ryan C. Gordon <icculus@icculus.org>
date Fri, 23 Jun 2006 08:35:48 +0000
parents 63fa37538842
children c121d94672cb a1b03ba2fcd0
comparison
equal deleted inserted replaced
1877:9b02a5b97f79 1878:d7c9d7f42881
262 } 262 }
263 } 263 }
264 } 264 }
265 } 265 }
266 266
267
268 /*
269 * http://bugzilla.libsdl.org/show_bug.cgi?id=110
270 * "For Linux ALSA, this is FL-FR-RL-RR-C-LFE
271 * and for Windows DirectX [and CoreAudio], this is FL-FR-C-LFE-RL-RR"
272 */
273 #define SWIZ6(T) \
274 T *ptr = (T *) mixbuf; \
275 const Uint32 count = (this->spec.samples / 6); \
276 Uint32 i; \
277 for (i = 0; i < count; i++, ptr += 6) { \
278 T tmp; \
279 tmp = ptr[2]; ptr[2] = ptr[4]; ptr[4] = tmp; \
280 tmp = ptr[3]; ptr[3] = ptr[5]; ptr[5] = tmp; \
281 }
282
283 static __inline__ void swizzle_alsa_channels_6_64bit(_THIS) { SWIZ6(Uint64); }
284 static __inline__ void swizzle_alsa_channels_6_32bit(_THIS) { SWIZ6(Uint32); }
285 static __inline__ void swizzle_alsa_channels_6_16bit(_THIS) { SWIZ6(Uint16); }
286 static __inline__ void swizzle_alsa_channels_6_8bit(_THIS) { SWIZ6(Uint8); }
287
288 #undef SWIZ6
289
290
291 /*
292 * Called right before feeding this->mixbuf to the hardware. Swizzle channels
293 * from Windows/Mac order to the format alsalib will want.
294 */
295 static __inline__ void swizzle_alsa_channels(_THIS)
296 {
297 if (this->spec.channels == 6) {
298 const Uint16 fmtsize = (this->spec.format & 0xFF); /* bits/channel. */
299 if (fmtsize == 16)
300 swizzle_alsa_channels_6_16bit(this);
301 else if (fmtsize == 8)
302 swizzle_alsa_channels_6_8bit(this);
303 else if (fmtsize == 32)
304 swizzle_alsa_channels_6_32bit(this);
305 else if (fmtsize == 64)
306 swizzle_alsa_channels_6_64bit(this);
307 }
308
309 /* !!! FIXME: update this for 7.1 if needed, later. */
310 }
311
312
267 static void ALSA_PlayAudio(_THIS) 313 static void ALSA_PlayAudio(_THIS)
268 { 314 {
269 int status; 315 int status;
270 int sample_len; 316 int sample_len;
271 signed short *sample_buf; 317 signed short *sample_buf;
272 318
319 swizzle_alsa_channels(this);
320
273 sample_len = this->spec.samples; 321 sample_len = this->spec.samples;
274 sample_buf = (signed short *)mixbuf; 322 sample_buf = (signed short *)mixbuf;
323
275 while ( sample_len > 0 ) { 324 while ( sample_len > 0 ) {
276 status = SDL_NAME(snd_pcm_writei)(pcm_handle, sample_buf, sample_len); 325 status = SDL_NAME(snd_pcm_writei)(pcm_handle, sample_buf, sample_len);
277 if ( status < 0 ) { 326 if ( status < 0 ) {
278 if ( status == -EAGAIN ) { 327 if ( status == -EAGAIN ) {
279 SDL_Delay(1); 328 SDL_Delay(1);