diff options
author | Chris Robinson <[email protected]> | 2013-06-19 22:47:17 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2013-06-19 22:47:17 -0700 |
commit | 160e901381614ee398b3316c3d0491a9da534355 (patch) | |
tree | 71acabe3fd430a890a02fcb746049a2218e24684 /examples | |
parent | a9fac129696731bb307a72e8ae6c95e474587221 (diff) |
Handle non-native endian formats with SDL_sound
Diffstat (limited to 'examples')
-rw-r--r-- | examples/common/sdl_sound.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/examples/common/sdl_sound.c b/examples/common/sdl_sound.c index 9e9f1d62..79a5bf32 100644 --- a/examples/common/sdl_sound.c +++ b/examples/common/sdl_sound.c @@ -105,9 +105,9 @@ int getAudioInfo(FilePtr file, ALuint *rate, ALenum *channels, ALenum *type) *type = AL_UNSIGNED_BYTE_SOFT; else if(file->actual.format == AUDIO_S8) *type = AL_BYTE_SOFT; - else if(file->actual.format == AUDIO_U16SYS) + else if(file->actual.format == AUDIO_U16LSB || file->actual.format == AUDIO_U16MSB) *type = AL_UNSIGNED_SHORT_SOFT; - else if(file->actual.format == AUDIO_S16SYS) + else if(file->actual.format == AUDIO_S16LSB || file->actual.format == AUDIO_S16MSB) *type = AL_SHORT_SOFT; else { @@ -126,6 +126,21 @@ uint8_t *getAudioData(FilePtr file, size_t *length) *length = Sound_Decode(file); if(*length == 0) return NULL; + if((file->actual.format == AUDIO_U16LSB && AUDIO_U16LSB != AUDIO_U16SYS) || + (file->actual.format == AUDIO_U16MSB && AUDIO_U16MSB != AUDIO_U16SYS) || + (file->actual.format == AUDIO_S16LSB && AUDIO_S16LSB != AUDIO_S16SYS) || + (file->actual.format == AUDIO_S16MSB && AUDIO_S16MSB != AUDIO_S16SYS)) + { + /* Swap bytes if the decoded endianness doesn't match the system. */ + char *buffer = file->buffer; + size_t i; + for(i = 0;i < *length;i+=2) + { + char b = buffer[i]; + buffer[i] = buffer[i+1]; + buffer[i+1] = b; + } + } return file->buffer; } |