mirror of
https://github.com/vgmstream/vgmstream.git
synced 2025-01-29 19:37:30 +01:00
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:
parent
8b7ed495f4
commit
d993fbb44b
11
src/util.c
11
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<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) {
|
||||
|
@ -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);
|
||||
|
13
test/test.c
13
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;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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user