Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
authorRyan C. Gordon <icculus@icculus.org>
Fri, 23 Jun 2006 08:35:48 +0000
changeset 1878d7c9d7f42881
parent 1877 9b02a5b97f79
child 1879 cb232e63552c
Swizzle ALSA channels for 5.1 output to match DirectSound and CoreAudio.
Untested, but potentially fixes Bugzilla #110.
src/audio/alsa/SDL_alsa_audio.c
     1.1 --- a/src/audio/alsa/SDL_alsa_audio.c	Fri Jun 23 08:15:47 2006 +0000
     1.2 +++ b/src/audio/alsa/SDL_alsa_audio.c	Fri Jun 23 08:35:48 2006 +0000
     1.3 @@ -264,14 +264,63 @@
     1.4  	}
     1.5  }
     1.6  
     1.7 +
     1.8 +/*
     1.9 + * http://bugzilla.libsdl.org/show_bug.cgi?id=110
    1.10 + * "For Linux ALSA, this is FL-FR-RL-RR-C-LFE
    1.11 + *  and for Windows DirectX [and CoreAudio], this is FL-FR-C-LFE-RL-RR"
    1.12 + */
    1.13 +#define SWIZ6(T) \
    1.14 +    T *ptr = (T *) mixbuf; \
    1.15 +    const Uint32 count = (this->spec.samples / 6); \
    1.16 +    Uint32 i; \
    1.17 +    for (i = 0; i < count; i++, ptr += 6) { \
    1.18 +        T tmp; \
    1.19 +        tmp = ptr[2]; ptr[2] = ptr[4]; ptr[4] = tmp; \
    1.20 +        tmp = ptr[3]; ptr[3] = ptr[5]; ptr[5] = tmp; \
    1.21 +    }
    1.22 +
    1.23 +static __inline__ void swizzle_alsa_channels_6_64bit(_THIS) { SWIZ6(Uint64); }
    1.24 +static __inline__ void swizzle_alsa_channels_6_32bit(_THIS) { SWIZ6(Uint32); }
    1.25 +static __inline__ void swizzle_alsa_channels_6_16bit(_THIS) { SWIZ6(Uint16); }
    1.26 +static __inline__ void swizzle_alsa_channels_6_8bit(_THIS) { SWIZ6(Uint8); }
    1.27 +
    1.28 +#undef SWIZ6
    1.29 +
    1.30 +
    1.31 +/*
    1.32 + * Called right before feeding this->mixbuf to the hardware. Swizzle channels
    1.33 + *  from Windows/Mac order to the format alsalib will want.
    1.34 + */
    1.35 +static __inline__ void swizzle_alsa_channels(_THIS)
    1.36 +{
    1.37 +    if (this->spec.channels == 6) {
    1.38 +        const Uint16 fmtsize = (this->spec.format & 0xFF); /* bits/channel. */
    1.39 +        if (fmtsize == 16)
    1.40 +            swizzle_alsa_channels_6_16bit(this);
    1.41 +        else if (fmtsize == 8)
    1.42 +            swizzle_alsa_channels_6_8bit(this);
    1.43 +        else if (fmtsize == 32)
    1.44 +            swizzle_alsa_channels_6_32bit(this);
    1.45 +        else if (fmtsize == 64)
    1.46 +            swizzle_alsa_channels_6_64bit(this);
    1.47 +    }
    1.48 +
    1.49 +    /* !!! FIXME: update this for 7.1 if needed, later. */
    1.50 +}
    1.51 +
    1.52 +
    1.53  static void ALSA_PlayAudio(_THIS)
    1.54  {
    1.55  	int           status;
    1.56  	int           sample_len;
    1.57  	signed short *sample_buf;
    1.58  
    1.59 +	swizzle_alsa_channels(this);
    1.60 +
    1.61  	sample_len = this->spec.samples;
    1.62  	sample_buf = (signed short *)mixbuf;
    1.63 +
    1.64  	while ( sample_len > 0 ) {
    1.65  		status = SDL_NAME(snd_pcm_writei)(pcm_handle, sample_buf, sample_len);
    1.66  		if ( status < 0 ) {