7

I'm developing an application in c to read simple PCM WAV files. My question is, how should I interpret the samples from the data chunk, so that I can extract the sample's frequency?

Given a WAV example, how can the original data represent frequencies. E.g. this data chunk, 24 17 1e f3, for stereo, 16 bits, the left channel sample is, 0x1724 = 5924d, means 5924Hz ? How can that be, for samples that are signed or frequencies that humans can´t hear?

AShelly
  • 34,686
  • 15
  • 91
  • 152
ikyr9999
  • 115
  • 1
  • 1
  • 6
  • I'd bet there at least 10 duplicates of this question. – AShelly Nov 16 '11 at 15:36
  • possible duplicate of [Detect a specific frequency/tone from raw wave-data](http://stackoverflow.com/questions/4808893/detect-a-specific-frequency-tone-from-raw-wave-data) – AShelly Nov 16 '11 at 15:40
  • @AShelly link me to one of those topics plz – ikyr9999 Nov 16 '11 at 15:41
  • http://stackoverflow.com/questions/65268/music-how-do-you-analyse-the-fundamental-frequency-of-a-pcm-or-wac-sample – AShelly Nov 16 '11 at 15:56
  • OK now I'm seriously confused. I asked this question because I'm working on something that will read a wav and, because I cannot use the soundBoard, I want to convert the wav to a list of frequencies (mean among several data samples) and then play it through the Timer2, connected to the speakers. Are you saying that I need to compute FFT to obtain those? – ikyr9999 Nov 16 '11 at 16:40
  • Yes, if you want to find the primary frequencies of a WAV segment, you should perform a FFT. To play through the speakers, you do not need the FFT, just the original WAV data. – AShelly Nov 16 '11 at 18:55
  • OK, but, there again I can't make a clear vision out of it. I mean, given a WAV example, how can the original data represent frequencies. E.g. this data chunk, 24 17 1e f3, for stereo, 16 bits, the left channel sample is, 0x1724 = 5924d, means 5924Hz ? How can that be, for samples that are signed or frequencies that humans can´t hear? Sorry for all these questions, and thank you for answering =) – ikyr9999 Nov 16 '11 at 21:21
  • PCM data does not directly represent frequencies. It represents amplitude of the signal at the time each sample was taken. – Adam Zalcman Nov 17 '11 at 00:46

2 Answers2

12

Your assumption is incorrect. The sample data is simply a digital representation of the actual sound wave. The numbers represent wave amplitude, the array offset represents time.

I would suggest reading about How Audio is Represented, specifically PCM.

To convert this data (amplitude-vs-time) to frequency data, you need to understand the basic concepts of The Fourier Transform

I really suggest taking the time to read these before trying to do any audio processing.

Community
  • 1
  • 1
AShelly
  • 34,686
  • 15
  • 91
  • 152
1

You can extract the sample rate in the WAV header, but if you need the actual frequency data of the audio that was recorded, i.e. how much energy at 200Hz, how much at 2kHz, how much at 8kHz, etc. you need to do an FFT, or run it through a spectrogram.

IO_Madness
  • 11
  • 1