From: Ondřej Hošek Date: Tue, 11 Apr 2006 19:11:51 +0000 (+0000) Subject: Byteswapping code for sound engine on big-endian systems X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=ba2ea5f262853ee38e955a29d95028d14a6e18ea;p=supertux.git Byteswapping code for sound engine on big-endian systems SVN-Revision: 3303 --- 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; }