5

在 Hex Editor 和音频文件方面需要帮助。我无法找出公式来获取 .wav 文件中的样本数量。

我下载了 StripWav,它告诉我 .waves 中的样本数量,但仍然无法计算出公式。

你能下载这两个.wavs,在十六进制编辑器中打开它们,然后告诉我获取样本数量的公式吗?

如果您为我这样做,请告诉我每个 .wav 的样本数量,以便我确保公式正确。

http://sinewavemultimedia.com/1wav.wav http://sinewavemultimedia.com/2wav.wav

这是一个问题,我有两个程序,

一个读取 wav 数据,另一个显示这里的 numsamples 是数据

RIFF 'WAVE' (wave file)
        <fmt > (format description)
                PCM format
                2 channel
                44100 frames per sec
                176400 bytes per sec
                4 bytes per frame
                16 bits per sample
        <data> (waveform data - 92252 bytes)

但是另一个程序说 NumSamples 是

23,063 samples

/ * ** * ** * UPDATE * ** * ** * ** / 我用 2 个文件计算的另一件事 这个是正确的

92,296 bytes and num samples is 23,063` 

但是另一个没有正确显示它超过 2 兆,我只是减去了 44 个字节,我在这里做错了吗?这是文件大小

2,473,696 bytes 

但正确的 numsamples 是

 617,400
4

3 回答 3

3

WAVE format

You must read the fmt header to determine the number of channels and bits per sample, then read the size of the data chunk to determine how many bytes of data are in the audio. Then:

NumSamples = NumBytes / (NumChannels * BitsPerSample / 8)
于 2011-05-02T20:07:09.833 回答
1

没有简单的公式来确定 WAV 文件中的样本数量。一个所谓的“规范”WAV 文件由一个 44 字节的标题和后面的实际样本数据组成。因此,如果您知道文件每个样本使用 2 个字节,那么样本数等于文件大小(以字节为单位)减去 44(对于标头),然后除以 2(因为每个样本有 2 个字节)样本)。

Unfortunately, not all WAV files are "canonical" like this. A WAV file uses the RIFF format, so the proper way to parse a WAV file is to search through the file and locate the various chunks.

Here is a sample (not sure what language you need to do this in):

http://msdn.microsoft.com/en-us/library/ms712835

于 2011-05-02T20:06:42.137 回答
0

A WAVE's format chunk (fmt) has the 'bytes per sample frame' specified as wBlockAlign.
So: framesTotal = data.ck_size / fmt.wBlockAlign;
and samplesTotal = framesTotal * wChannels;
Thus, samplesTotal===FramesTotal IIF wChannels === 1!!

Note how the above answer elegantly avoided to explain that key-equations the spec (and answers based on them) are WRONG: consider flor example a 2 channel 12 bits per second wave..
The spec explains we put each 12bps sample in a word:

  note: t=point in time, chan = channel
+---------------------------+---------------------------+-----
|         frame 1           |         frame 2           |  etc
+-------------+-------------+-------------+-------------+-----
| chan 1 @ t1 | chan 2 @ t1 | chan 1 @ t2 | chan 2 @ t2 |  etc
+------+------+------+------+------+------+------+------+-----
| byte | byte | byte | byte | byte | byte | byte | byte |  etc
+------+------+------+------+------+------+------+------+-----

So.. how many bytes does the sample-frame (BlockAlign) for a 2ch 12bps wave have according to spec?
<sarcasm> CEIL(wChannels * bps / 8) = 3 bytes.. </sarcasm>
Obviously the correct equation is: wBlockAlign=wChannels*CEIL(bps/8)

于 2014-09-24T16:38:41.133 回答