0
$\begingroup$

I am trying to generate a 32bit PCM wav file with octave, the file shall contain a single full-scale sample (0db impulse). I am getting the expected result when using 24 bits per sample:

>> wavwrite(1, 96000, 24, 'foo.wav');
>> wavread('foo.wav')
ans =  1.00000                          # as expected

However, when using 32 bits per sample, the value seems to overflow.

>> wavwrite(1, 96000, 32, 'foo.wav');
>> wavread('foo.wav')
ans = -1                                # WHAT ?!

I am expecting the second wavread('foo.wav') to return 1 not -1. I have checked the wav file with a hex editor, the sample raw value is 0x80000000, I am expecting it to be 0x7fffffff. Is it an octave bug or am I missing something?

Using 0.99999 instead of 1 generates the expected result.

$\endgroup$
  • $\begingroup$ Check the documentation -- different bit formats have different max and min values. It's possible that for 32 bits the max is 1.0-eps. $\endgroup$ – MBaz Aug 2 '17 at 22:43
  • 1
    $\begingroup$ using matlab, audiowrite('foo.wav', 1, 96000, 'BitsPerSample', 32); works fine... Could be a problem of representation: Q31 can't represent 1. $\endgroup$ – Florent Aug 2 '17 at 22:47
  • 1
    $\begingroup$ It sounds like an octave bug. Matlab (R2014b) produces the expected result. $\endgroup$ – jaket Aug 2 '17 at 22:49
  • 2
    $\begingroup$ this could be the bug : Octave writes in 32bit int (type 1) whereas Matlab writes 32bit normalized floats (type 3) $\endgroup$ – Florent Aug 2 '17 at 23:00
1
$\begingroup$

It seems like it is a bug. Octave's wavwrite() function writes 32-bit wav in 32 bits int (type 1 format) instead of normalized 32-bit floats (type 3 format). Unfortunately, 1 can't be represented in 32-bit type 1 format which is why you get this result.

The solution could be to use the audiowrite() function, or to write 0x7fffffff instead of 1.

More about wav formats.

EDIT: seems from the bug report that the audiowrite function has the same problem...

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.