From d993fbb44bc9adeefc612bd32d4a9d5b7fcac9d5 Mon Sep 17 00:00:00 2001 From: halleyscometsw Date: Tue, 31 Aug 2010 04:44:04 +0000 Subject: [PATCH] do little endian samples proper git-svn-id: https://vgmstream.svn.sourceforge.net/svnroot/vgmstream@826 51a99a44-fe44-0410-b1ba-c3e57ba2b86b --- src/util.c | 11 +++++++++++ src/util.h | 1 + test/test.c | 13 +++---------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/util.c b/src/util.c index 7c7b012d..412d03e8 100644 --- a/src/util.c +++ b/src/util.c @@ -127,6 +127,17 @@ void make_wav_header(uint8_t * buf, int32_t sample_count, int32_t sample_rate, i put_32bitLE(buf+0x28, (int32_t)bytecount); } +void swap_samples_le(sample *buf, int count) { + int i; + for (i=0;i>8; + uint8_t *p = (uint8_t*)&(buf[i]); + p[0] = b0; + p[1] = b1; + } +} + /* length is maximum length of dst. dst will always be null-terminated if * length > 0 */ void concatn(int length, char * dst, const char * src) { diff --git a/src/util.h b/src/util.h index 6f7799fe..ff702e25 100644 --- a/src/util.h +++ b/src/util.h @@ -63,6 +63,7 @@ static inline int clamp16(int32_t val) { /* make a header for PCM .wav */ /* buffer must be 0x2c bytes */ void make_wav_header(uint8_t * buf, int32_t sample_count, int32_t sample_rate, int channels); +void swap_samples_le(sample *buf, int count); void concatn(int length, char * dst, const char * src); void concatn_doublenull(int length, char * dst, const char * src); diff --git a/test/test.c b/test/test.c index ffabfeef..36f96364 100644 --- a/test/test.c +++ b/test/test.c @@ -242,6 +242,7 @@ int main(int argc, char ** argv) { /* decode forever */ while (forever) { render_vgmstream(buf,BUFSIZE,s); + swap_samples_le(buf,s->channels*BUFSIZE); fwrite(buf,sizeof(sample)*s->channels,BUFSIZE,outfile); } @@ -265,6 +266,7 @@ int main(int argc, char ** argv) { } } } + swap_samples_le(buf,s->channels*toget); fwrite(buf,sizeof(sample)*s->channels,toget,outfile); } @@ -353,16 +355,7 @@ int main(int argc, char ** argv) { } /* do proper little endian samples */ - { - int k; - for (k=0;kchannels;k++) { - uint8_t b0 = buf[k]&0xff; - uint8_t b1 = buf[k]>>8; - uint8_t *p = (uint8_t*)&buf[k]; - p[0] = b0; - p[1] = b1; - } - } + swap_samples_le(buf,s->channels*toget); fwrite(buf,sizeof(sample)*s->channels,toget,outfile); } fclose(outfile); outfile = NULL;