Why is audiowrite scaling my int32 data?

11 vues (au cours des 30 derniers jours)
Mr. Mas
Mr. Mas le 23 Juin 2016
Commenté : Mr. Mas le 19 Juil 2016
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
  1 commentaire
Mr. Mas
Mr. Mas le 19 Juil 2016
Thanks, Geoff. That's the information I needed.

Connectez-vous pour commenter.

Réponse acceptée

Geoff Hayes
Geoff Hayes le 5 Juil 2016
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?
  1 commentaire
Mr. Mas
Mr. Mas le 19 Juil 2016
Funny how I misunderstood what to expect exactly the opposite of what happened. No idea about the clipping -- but I can see now, plain as day, that it should have been clipped, not the values I said were expected.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Introduction to Installation and Licensing dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by