I run the following with confusing results:
>> audiowrite('test.wav', -2^32:2^23:2^32, 10000, 'BitsPerSample', 32)>> dataRead = audioread('test.wav');>> max(dataRead)ans = 4.2950e+09 %%%%%As expected
>> min(dataRead)ans = -4.2950e+09 %%%%%As expected>> audiowrite('test.wav', int32(-2^32:2^23:2^32), 10000, 'BitsPerSample', 32)>> dataRead = audioread('test.wav');>> max(dataRead)ans = 1.0000 %%%%%Huh?
>> min(dataRead)ans = -1 %%%%%Huh?
Why does the "int32" data get scaled when it should fit in the range specified by audiowrite help:
Data Type of Y Valid Range for Y ----------------------------------- uint8 0 <= Y <= 255 int16 -32768 <= Y <= +32767 int32 -2^32 <= Y <= 2^32-1 single -1.0 <= Y <= +1.0 double -1.0 <= Y <= +1.0 Data beyond the valid range is clipped. If Y is single or double, then audio data in Y should be normalized to values in the range -1.0 and 1.0, inclusive. Output Data Type The native data type written to the audio file is determined by the file format, the data type of Y, and the specified output BitsPerSample. File Formats Data Type of Y Output BitsPerSample Output Data Type ----------------------------------------------------------------------- WAVE (.wav) uint8,int16,int32 8 uint8 single,double 16 int16 24 int32 --------------------------------------------------------- uint8,int16,int32 32 int32 --------------------------------------------------------- single,double 32 single --------------------------------------------------------- single,double 64 double
Best Answer