observe padding byte requirement when writing test WAVEs

This commit is contained in:
Josh Coalson 2004-07-20 01:25:36 +00:00
parent a9414544f0
commit ab8633212a

View File

@ -612,7 +612,8 @@ foo:
static FLAC__bool generate_wav(const char *filename, unsigned sample_rate, unsigned channels, unsigned bytes_per_sample, unsigned samples)
{
const unsigned size = channels * bytes_per_sample * samples;
const unsigned true_size = channels * bytes_per_sample * samples;
const unsigned padded_size = (true_size + 1) & (~1u);
FILE *f;
unsigned i;
@ -620,7 +621,7 @@ static FLAC__bool generate_wav(const char *filename, unsigned sample_rate, unsig
return false;
if(fwrite("RIFF", 1, 4, f) < 4)
goto foo;
if(!write_little_endian_uint32(f, size + 36))
if(!write_little_endian_uint32(f, padded_size + 36))
goto foo;
if(fwrite("WAVEfmt \020\000\000\000\001\000", 1, 14, f) < 14)
goto foo;
@ -636,12 +637,15 @@ static FLAC__bool generate_wav(const char *filename, unsigned sample_rate, unsig
goto foo;
if(fwrite("data", 1, 4, f) < 4)
goto foo;
if(!write_little_endian_uint32(f, size))
if(!write_little_endian_uint32(f, true_size))
goto foo;
for(i = 0; i < size; i++)
for(i = 0; i < true_size; i++)
if(fputc(i, f) == EOF)
goto foo;
for( ; i < padded_size; i++)
if(fputc(0, f) == EOF)
goto foo;
fclose(f);
return true;