What does the 'audioread' function actually do?
5 ビュー (過去 30 日間)
古いコメントを表示
Pedro Andre Viegas Ochoa de Carvalho
2016 年 7 月 7 日
コメント済み: Walter Roberson
2016 年 7 月 8 日
I have a .wav file exported by a vibration analyser Svan 958A. It contains data from 4 channels. The samples are written in hexadecimal representation.
I read the file by executing the following line: [data,fs] = audioread('svan0004.wav','native'). MATLAB correctly organises the data in an 4-column array. Since the file was obtained at 24 bits per sample, the output array elements are of the type int32.
However, there is something wrong with the reading/extraction of the sample values from the .wav file. The first 4 values of each column are known to me, because they include the data definitions for each channel. By looking at those values I realised that somehow MATLAB did not convert the sample hexadecimal numbers as I was expecting. Here is what I get. The following values are the first 4 extracted values for the 4 channels:
Channel 1: [256, 512, 4199168, 0];
Channel 2: [512, 512, 4199168, 0];
Channel 3: [768, 512, 4199168, 0];
Channel 4: [1024, 512, 4452608, 0];
The following values are what should have been read:
Channel 1: [1, 2, 16403, 0];
Channel 2: [2, 2, 16403, 0];
Channel 3: [3, 2, 16403, 0];
Channel 4: [4, 2, 17393, 0];
Could you explain me what does the 'audioread' function actually do? What is the way around this? How can I extract the sample values correctly from my .wav file?
Thank you for the support. Best regards, Pedro Ochôa
1 件のコメント
採用された回答
Walter Roberson
2016 年 7 月 7 日
When a value is 24 bits placed in a 32 bit integer, the value can either be packed at the "left" or at the "right" of the 32 bit integer. Whatever is creating the values is packing at the "left". MATLAB does not know that; it just thinks it is working with 32 bit values.
To get your expected values back, divide the values by 256. But watch out for sign extension: if you do use int32() instead of uint32() and you divide (say) 0x85401300 by 256 then you would get 0xFF854013 as the result as the sign bit propagates on the signed division. If you would want 0x85401300 to become 0x00854013 then you should be using uint32 instead of int32
4 件のコメント
Walter Roberson
2016 年 7 月 8 日
The data that has been stored in the file was effectively already multiplied by 256 to produce a 32 bit number.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Audio I/O and Waveform Generation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!