如何与音频数据的时间 [英] How to relate audio data to time

查看:118
本文介绍了如何与音频数据的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以说,我想从一个MP3文件和present它读1毫秒的声音数据。事情是这样的:

Lets say I would like to read 1 millisecond of sound data from an Mp3 file and present it. Something like this:

var stream = NAudio.WaveStream.Mp3FileReader(filename);
int intervalInMilliseconds = someInterval;
int bytesPerInterval = ???;
for(int i = 0; i < bytesPerInterval;i++)
{
     Console.WriteLine(stream.GetByte());
}

我需要做什么做解决bytesPerInterval?这甚至可能做到准确? (注:n音讯是不是在这里的要求,正是我目前使用)

What do I need to do to solve for bytesPerInterval? Is this even possible to do accurately? (Note:NAudio is not a requirement here, just what I am currently using.)

或者,如果我有一个字节的索引,它是可以确定该字节将发挥什么样的时间点(相对于时间00:00:0000)?

Or if I have a byte index, is it possible to determine what point in time that byte would be played (relative to time 00:00:0000)?

推荐答案

您无法读取MP3音频数据的1毫秒直接。的MP3可与固定大小的时间片频域。一个典型的片是大约13毫秒。

You can't read 1 millisecond of audio data from MP3 directly. MP3 works in the frequency domain with fixed size time slices. A typical slice is around 13 milliseconds.

要得到准确的时间,您需要将音频转换回样品中的时域。 CD质量的音频采样每秒44,100次的16位PCM样本。在计算该数据字节的原始大小很简单:

To get accurate timing, you need to convert your audio back to samples in the time domain. CD-quality audio is sampled 44,100 times per second with 16-bit PCM samples. Calculating the raw size in bytes for this data is simple:

sampleCount * bytesPerSample * channels

另外,音响一毫秒不平均分为44.1,所以你需要选择时机,做。

Also, one millisecond of audio doesn't evenly divide into 44.1kHz, so you will need to pick timing that does.

这篇关于如何与音频数据的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆