do little endian samples proper

git-svn-id: https://vgmstream.svn.sourceforge.net/svnroot/vgmstream@826 51a99a44-fe44-0410-b1ba-c3e57ba2b86b
This commit is contained in:
halleyscometsw 2010-08-31 04:44:04 +00:00
parent 8b7ed495f4
commit d993fbb44b
3 changed files with 15 additions and 10 deletions

View File

@ -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<count;i++) {
uint8_t b0 = buf[i]&0xff;
uint8_t b1 = buf[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) {

View File

@ -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);

View File

@ -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;k<toget*s->channels;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;