From ba2ea5f262853ee38e955a29d95028d14a6e18ea Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ond=C5=99ej=20Ho=C5=A1ek?= Date: Tue, 11 Apr 2006 19:11:51 +0000 Subject: [PATCH] Byteswapping code for sound engine on big-endian systems SVN-Revision: 3303 --- src/audio/sound_file.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/audio/sound_file.cpp b/src/audio/sound_file.cpp index 42548ace2..bcd6e3eb4 100644 --- a/src/audio/sound_file.cpp +++ b/src/audio/sound_file.cpp @@ -151,6 +151,23 @@ WavSoundFile::read(void* buffer, size_t buffer_size) if(PHYSFS_read(file, buffer, readsize, 1) != 1) throw std::runtime_error("read error while reading samples"); +#ifdef WORDS_BIGENDIAN + if (bits_per_sample != 16) + return readsize; + char *tmp = (char*)buffer; + + size_t i; + char c; + for (i = 0; i < readsize / 2; i++) + { + c = tmp[2*i]; + tmp[2*i] = tmp[2*i+1]; + tmp[2*i+1] = c; + } + + buffer = tmp; +#endif + return readsize; } @@ -203,8 +220,13 @@ OggSoundFile::read(void* _buffer, size_t buffer_size) while(buffer_size>0){ long bytesRead - = ov_read(&vorbis_file, buffer, static_cast (buffer_size), 0, 2, 1, - §ion); + = ov_read(&vorbis_file, buffer, static_cast (buffer_size), +#ifdef WORDS_BIGENDIAN +1, +#else +0, +#endif + 2, 1, §ion); if(bytesRead==0){ break; } -- 2.11.0