From b6ed0b606fe605fcb75b05578047dba747e9b9a3 Mon Sep 17 00:00:00 2001 From: Dominik Riebeling Date: Sun, 14 Mar 2010 18:20:18 +0000 Subject: Fix rbspeex on big endian hosts. Big endian hosts need to byteswap the wave data when reading or writing to disk. Should fix speex based voice- and talkfiles only containing garbage on PPC machines. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25177 a1c6a512-1295-4272-9138-f99709370657 --- tools/rbspeex/rbspeex.c | 11 ++++++++++- tools/rbspeex/rbspeexdec.c | 9 +++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/tools/rbspeex/rbspeex.c b/tools/rbspeex/rbspeex.c index 5d96ad8ab9..b72ff381d9 100644 --- a/tools/rbspeex/rbspeex.c +++ b/tools/rbspeex/rbspeex.c @@ -136,6 +136,7 @@ bool encode_file(FILE *fin, FILE *fout, float quality, int complexity, int i, tmp, target_sr, numchan, bps, sr, numsamples, frame_size, lookahead; int nbytes; bool ret = true; + int a; if (!get_wave_metadata(fin, &numchan, &bps, &sr, &numsamples)) { snprintf(errstr, errlen, "invalid WAV file"); @@ -179,7 +180,15 @@ bool encode_file(FILE *fin, FILE *fout, float quality, int complexity, snprintf(errstr, errlen, "could not read input file data"); ret = false; goto finish; - } + } +#if defined(__BIG_ENDIAN__) + /* byteswap read bytes to host endianess. */ + a = numsamples; + while(a--) { + *(in + a) = ((unsigned short)(*(in + a)) >> 8) & 0x00ff + | ((unsigned short)(*(in + a)) << 8) & 0xff00; + } +#endif if (volume != 1.0f) { for (i = 0; i < numsamples; ++i) diff --git a/tools/rbspeex/rbspeexdec.c b/tools/rbspeex/rbspeexdec.c index 7c5df3eb50..14ee971697 100644 --- a/tools/rbspeex/rbspeexdec.c +++ b/tools/rbspeex/rbspeexdec.c @@ -89,6 +89,15 @@ int main(int argc, char **argv) speex_bits_set_bit_buffer(&bits, indata, insize); while (speex_decode_int(st, &bits, out) == 0) { /* if no error, write decoded audio */ +#if defined(__BIG_ENDIAN__) + /* byteswap samples from host (big) endianess to file (little) before + * writing. */ + unsigned int a = frame_size - lookahead; + while(a--) { + out[lookahead + a] = ((unsigned short)out[lookahead+a]<<8)&0xff00 + | ((unsigned short)out[lookahead+a]>>8)&0x00ff; + } +#endif fwrite(out + lookahead, sizeof(short), frame_size - lookahead, fout); samples += frame_size - lookahead; lookahead = 0; /* only skip samples at the start */ -- cgit v1.2.3