[Alsaplayer-devel] Is alsaplayer endian-safe?

Timur Tabi timur at freescale.com
Fri May 9 22:20:35 BST 2008


I don't think it is, at least not for WAV files.

When I try to play a WAV file on a PowerPC (big-endian) system, I get this:

alsaplayer -o alsa /usr/share/apps/korganizer/sounds/lightmag.wav
APLAY: Cannot identify WAV
APLAY: main_chunk = 52494646 -> 46464952
APLAY: chunk_type = 57415645 -> 45564157
APLAY: sub_chunk = 666d7420 -> 20746d66
APLAY: data_chunk = 64617461 -> 61746164
APLAY: Cannot identify WAV
APLAY: main_chunk = 52494646 -> 46464952
APLAY: chunk_type = 57415645 -> 45564157
APLAY: sub_chunk = 666d7420 -> 20746d66
APLAY: data_chunk = 64617461 -> 61746164

If you look at the chunk bytes, they're all reversed.

This is because of this code:

        if (wp->main_chunk == WAV_RIFF && wp->chunk_type == WAV_WAVE &&
            wp->sub_chunk == WAV_FMT &&

the 'chunk' fields are defined like this:

typedef struct wav_header {
        u_int main_chunk;       /* 'RIFF' */
        u_int length;           /* filelen */
        u_int chunk_type;       /* 'WAVE' */

        u_int sub_chunk;        /* 'fmt ' */
        u_int sc_len;           /* length of sub_chunk, =16 */

(let's ignore the fact that this code assumes that an integer is 4 bytes)

So when it tries to read wp->main_chunk from memory, it will treat the 4 bytes
as a big-endian integer, and WAV_RIFF is coded for little-endian only.

-- 
Timur Tabi
Linux kernel developer at Freescale



More information about the alsaplayer-devel mailing list