简体   繁体   中英

How to read raw audio data in c++?

I'm trying to do a Fourier Transform on audio file. So far I've managed to read the header of the file with the help of this answer. This is the output.

The audio format is 1 which means PCM and I should really easily be able to work with the data. However, this is what I can't figure out.

Is the data binary and I should convert it to float or something else that I can't understand?

Yes, it's binary. Specifically, it's signed 16-bit integers. You may want to convert it to float or double depending on your FFT needs.

I suggest you use a mono channel input audio file ... the sample you showed has two channels ( stereo ) which complicates the data slightly ... for a mono PCM file the structure is

two-bytes-sample-A  immediately followed by two-bytes-sample-B ... etc.

in PCM each such sample directly corresponds to a point on the analog audio curve as the microphone diaphragm (or your eardrum) wobbles ... paying attention to correct use of endianness of your data each of these samples will result in an integer using all 16 bits so the unsigned integers go from values of 0 up to (2^16 - 1) which is 0 to 65535 .... confirm your samples stay inside this range IF they are unsigned

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM