Mason - I don't think that the problem is with audiowrite for your int32 example. According to audioread, If you do not specify dataType, or dataType is 'double', then y is of type double, and matrix elements are normalized values between −1.0 and 1.0.. So >> audiowrite('test.wav', int32(-2^32:2^23:2^32), 10000, 'BitsPerSample', 32)
>> dataRead = audioread('test.wav');
will be such that dataRead is an array of doubles normalized between -1.0 and 1.0. If I do the following instead
>> dataRead = audioread('test.wav', 'native');
>> whos dataRead
Name Size Bytes Class Attributes
dataRead 1025x1 4100 int32
then dataRead is of the correct data type with the minimum and maximum the expected integer values.
The problem seems more to be with
audiowrite('test.wav', -2^32:2^23:2^32, 10000, 'BitsPerSample', 32)
where the input -2^32:2^23:2^32 is of a single (or double) data type. According to the documentation for audiowrite, I would have expected the data to be clipped to [-1.0, 1.0] but that doesn't seem to be the case. With
>> audiowrite('test.wav', -2^32:2^23:2^32, 10000, 'BitsPerSample', 32)
>> dataRead = audioread('test.wav');
>> whos dataRead
Name Size Bytes Class Attributes
dataRead 1025x1 8200 double
with the minimum and maximum of -4.2950e+09 and 4.2950e+09 respectively. This seems unexpected - why wasn't this clipped as the documentation suggests it would be?
Best Answer