summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2010-03-14 18:20:18 +0000
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2010-03-14 18:20:18 +0000
commitb6ed0b606fe605fcb75b05578047dba747e9b9a3 (patch)
treeee6e6de886f10aefa758e065014c4ef676756f61
parent3e9222de387df622e014d4792199e50183c7cc73 (diff)
downloadrockbox-b6ed0b606fe605fcb75b05578047dba747e9b9a3.tar.gz
rockbox-b6ed0b606fe605fcb75b05578047dba747e9b9a3.zip
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
-rw-r--r--tools/rbspeex/rbspeex.c11
-rw-r--r--tools/rbspeex/rbspeexdec.c9
2 files changed, 19 insertions, 1 deletions
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,
136 int i, tmp, target_sr, numchan, bps, sr, numsamples, frame_size, lookahead; 136 int i, tmp, target_sr, numchan, bps, sr, numsamples, frame_size, lookahead;
137 int nbytes; 137 int nbytes;
138 bool ret = true; 138 bool ret = true;
139 int a;
139 140
140 if (!get_wave_metadata(fin, &numchan, &bps, &sr, &numsamples)) { 141 if (!get_wave_metadata(fin, &numchan, &bps, &sr, &numsamples)) {
141 snprintf(errstr, errlen, "invalid WAV file"); 142 snprintf(errstr, errlen, "invalid WAV file");
@@ -179,7 +180,15 @@ bool encode_file(FILE *fin, FILE *fout, float quality, int complexity,
179 snprintf(errstr, errlen, "could not read input file data"); 180 snprintf(errstr, errlen, "could not read input file data");
180 ret = false; 181 ret = false;
181 goto finish; 182 goto finish;
182 } 183 }
184#if defined(__BIG_ENDIAN__)
185 /* byteswap read bytes to host endianess. */
186 a = numsamples;
187 while(a--) {
188 *(in + a) = ((unsigned short)(*(in + a)) >> 8) & 0x00ff
189 | ((unsigned short)(*(in + a)) << 8) & 0xff00;
190 }
191#endif
183 192
184 if (volume != 1.0f) { 193 if (volume != 1.0f) {
185 for (i = 0; i < numsamples; ++i) 194 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)
89 speex_bits_set_bit_buffer(&bits, indata, insize); 89 speex_bits_set_bit_buffer(&bits, indata, insize);
90 while (speex_decode_int(st, &bits, out) == 0) { 90 while (speex_decode_int(st, &bits, out) == 0) {
91 /* if no error, write decoded audio */ 91 /* if no error, write decoded audio */
92#if defined(__BIG_ENDIAN__)
93 /* byteswap samples from host (big) endianess to file (little) before
94 * writing. */
95 unsigned int a = frame_size - lookahead;
96 while(a--) {
97 out[lookahead + a] = ((unsigned short)out[lookahead+a]<<8)&0xff00
98 | ((unsigned short)out[lookahead+a]>>8)&0x00ff;
99 }
100#endif
92 fwrite(out + lookahead, sizeof(short), frame_size - lookahead, fout); 101 fwrite(out + lookahead, sizeof(short), frame_size - lookahead, fout);
93 samples += frame_size - lookahead; 102 samples += frame_size - lookahead;
94 lookahead = 0; /* only skip samples at the start */ 103 lookahead = 0; /* only skip samples at the start */