查找 .wav 文件和十六进制编辑器中的样本数量

发布于 2024-11-05 06:43:08 字数 1208 浏览 6 评论 0原文

需要有关十六进制编辑器和音频文件的帮助。我无法找出获取 .wav 文件中样本数量的公式。

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

您能下载这两个 .wav 文件,在十六进制编辑器中打开它们并告诉我获取样本数的公式吗?

如果您愿意为我做这件事,请告诉我每个 .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

/*******更新*********/ 我还用 2 个文件进行了计算 这个是正确的

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

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

2,473,696 bytes 

但正确的样本数是

 617,400

Need help with Hex Editor and audio files.I am having trouble figuring out the formula to get the number of samples in my .wav files.

I downloaded StripWav which tells me the number of samples in the .waves,but still cannot figure out the formula.

Can you please download these two .wavs,open them in a hex editor and tell me the formula to get the number of samples.

If you so kindly do this for me,pleas tell me the number of samples for each .wav so I can make sure the formula is correct.

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

Here is a problem I have two programs,

One reads the wav data and the other shows the numsamples
here is the data

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)

But the other program says NumSamples is

23,063 samples

/*******UPDATE*********/
One more thing I did the calculation with 2 files
This one is correct

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

But this other one is not coming out correctly it is over 2 megs i just subracted 44 bytes and I doing it wrong here? here is the filesize

2,473,696 bytes 

But the correct numsamples is

 617,400

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

樱花落人离去 2024-11-12 06:43:09

WAVE 格式

您必须阅读 fmt 标头才能确定每个样本的通道数和位数,然后读取数据块的大小以确定音频中有多少数据字节。然后:

NumSamples = NumBytes / (NumChannels * BitsPerSample / 8)

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)
美胚控场 2024-11-12 06:43:09

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

不幸的是,并非所有 WAV 文件都是这样“规范”的。 WAV 文件使用 RIFF 格式,因此解析 WAV 文件的正确方法是搜索文件并找到各个块。

这是一个示例(不确定您需要使用哪种语言来执行此操作):

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

There is no simple formula for determining the number of samples in a WAV file. A so-called "canonical" WAV file consists of a 44-byte header followed by the actual sample data. So, if you know that the file uses 2 bytes per sample, then the number of samples is equal to the size of the file in bytes, minus 44 (for the header), and then divided by 2 (since there are 2 bytes per sample).

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

高速公鹿 2024-11-12 06:43:09

WAVE格式块 (fmt) 将“每个样本帧的字节数”指定为 wBlockAlign。< br>
所以:framesTotal = data.ck_size / fmt.wBlockAlign;
samplesTotal=framesTotal*wChannels;
因此,samplesTotal===FramesTotal IIF wChannels === 1!!

请注意上面的答案如何优雅地避免解释规范的关键方程(以及基于它们的答案)是错误的:
考虑 flor 示例,一个 2 通道每秒 12 位的波..
规范解释说我们将每个 12bps 样本放在一个单词中:

  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
+------+------+------+------+------+------+------+------+-----

那么..根据规范,2ch 12bps 波形的样本帧 (BlockAlign) 有多少字节?
<讽刺> CEIL(wChannels * bps / 8) = 3 字节..
显然,正确的方程式是:wBlockAlign=wChannels*CEIL(bps/8)

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文