Mercurial > sdl-ios-xcode
comparison src/audio/alsa/SDL_alsa_audio.c @ 1702:a7ad7081b977 SDL-1.3
Merged Ryan's 5.1 audio fix from SDL 1.2
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 23 Jun 2006 09:01:08 +0000 |
parents | 4da1ee79c9af |
children |
comparison
equal
deleted
inserted
replaced
1701:442248d4e738 | 1702:a7ad7081b977 |
---|---|
349 } | 349 } |
350 } | 350 } |
351 } | 351 } |
352 } | 352 } |
353 | 353 |
354 | |
355 /* | |
356 * http://bugzilla.libsdl.org/show_bug.cgi?id=110 | |
357 * "For Linux ALSA, this is FL-FR-RL-RR-C-LFE | |
358 * and for Windows DirectX [and CoreAudio], this is FL-FR-C-LFE-RL-RR" | |
359 */ | |
360 #define SWIZ6(T) \ | |
361 T *ptr = (T *) mixbuf; \ | |
362 const Uint32 count = (this->spec.samples / 6); \ | |
363 Uint32 i; \ | |
364 for (i = 0; i < count; i++, ptr += 6) { \ | |
365 T tmp; \ | |
366 tmp = ptr[2]; ptr[2] = ptr[4]; ptr[4] = tmp; \ | |
367 tmp = ptr[3]; ptr[3] = ptr[5]; ptr[5] = tmp; \ | |
368 } | |
369 | |
370 static __inline__ void | |
371 swizzle_alsa_channels_6_64bit(_THIS) | |
372 { | |
373 SWIZ6(Uint64); | |
374 } | |
375 static __inline__ void | |
376 swizzle_alsa_channels_6_32bit(_THIS) | |
377 { | |
378 SWIZ6(Uint32); | |
379 } | |
380 static __inline__ void | |
381 swizzle_alsa_channels_6_16bit(_THIS) | |
382 { | |
383 SWIZ6(Uint16); | |
384 } | |
385 static __inline__ void | |
386 swizzle_alsa_channels_6_8bit(_THIS) | |
387 { | |
388 SWIZ6(Uint8); | |
389 } | |
390 | |
391 #undef SWIZ6 | |
392 | |
393 | |
394 /* | |
395 * Called right before feeding this->mixbuf to the hardware. Swizzle channels | |
396 * from Windows/Mac order to the format alsalib will want. | |
397 */ | |
398 static __inline__ void | |
399 swizzle_alsa_channels(_THIS) | |
400 { | |
401 if (this->spec.channels == 6) { | |
402 const Uint16 fmtsize = (this->spec.format & 0xFF); /* bits/channel. */ | |
403 if (fmtsize == 16) | |
404 swizzle_alsa_channels_6_16bit(this); | |
405 else if (fmtsize == 8) | |
406 swizzle_alsa_channels_6_8bit(this); | |
407 else if (fmtsize == 32) | |
408 swizzle_alsa_channels_6_32bit(this); | |
409 else if (fmtsize == 64) | |
410 swizzle_alsa_channels_6_64bit(this); | |
411 } | |
412 | |
413 /* !!! FIXME: update this for 7.1 if needed, later. */ | |
414 } | |
415 | |
416 | |
354 static void | 417 static void |
355 ALSA_PlayAudio(_THIS) | 418 ALSA_PlayAudio(_THIS) |
356 { | 419 { |
357 int status; | 420 int status; |
358 int sample_len; | 421 int sample_len; |
359 signed short *sample_buf; | 422 signed short *sample_buf; |
360 | 423 |
424 swizzle_alsa_channels(this); | |
425 | |
361 sample_len = this->spec.samples; | 426 sample_len = this->spec.samples; |
362 sample_buf = (signed short *) mixbuf; | 427 sample_buf = (signed short *) mixbuf; |
428 | |
363 while (sample_len > 0) { | 429 while (sample_len > 0) { |
364 status = | 430 status = |
365 SDL_NAME(snd_pcm_writei) (pcm_handle, sample_buf, sample_len); | 431 SDL_NAME(snd_pcm_writei) (pcm_handle, sample_buf, sample_len); |
366 if (status < 0) { | 432 if (status < 0) { |
367 if (status == -EAGAIN) { | 433 if (status == -EAGAIN) { |
370 } | 436 } |
371 if (status == -ESTRPIPE) { | 437 if (status == -ESTRPIPE) { |
372 do { | 438 do { |
373 SDL_Delay(1); | 439 SDL_Delay(1); |
374 status = SDL_NAME(snd_pcm_resume) (pcm_handle); | 440 status = SDL_NAME(snd_pcm_resume) (pcm_handle); |
375 } | 441 } while (status == -EAGAIN); |
376 while (status == -EAGAIN); | |
377 } | 442 } |
378 if (status < 0) { | 443 if (status < 0) { |
379 status = SDL_NAME(snd_pcm_prepare) (pcm_handle); | 444 status = SDL_NAME(snd_pcm_prepare) (pcm_handle); |
380 } | 445 } |
381 if (status < 0) { | 446 if (status < 0) { |