brglng / libwave

A simple C library for reading/writing PCM wave (.wav) files
Mozilla Public License 2.0
79 stars 20 forks source link

wav_set_format doesn't properly set block_align? #6

Closed oskarvonephesos closed 3 years ago

oskarvonephesos commented 3 years ago

Hi there! I'm using your library to write a single channel of floats to a wav file. To open the file I run: WavFile* fp; fp = wav_open(file_path, restrict_mode); wav_set_format(fp, WAV_FORMAT_IEEE_FLOAT); wav_set_sample_size(fp, sizeof(float)); wav_set_num_channels(fp, 1); wav_set_sample_rate(fp, SR);

Calling wav_set_sample_size is necessary, because otherwise I get incorrect files (which I think my have to do with block_align -- I have posted a picture: the upper audio is produced by the code shown above, the lower picture is the audio produced without wav_set_sample_size. On import, Audacity et al warn about a corrupted header). It does seem quite redundant, though, that I specify the format as floats and set the sample_size to be sizeof(float) as well.

Screen Shot 2021-03-10 at 3 22 20 PM
brglng commented 3 years ago

@oskarvonephesos Please checkout the latest commit, thanks.