Audio samples per second?

时光怂恿深爱的人放手 提交于 2019-12-04 08:38:01

问题


I am wondering on the relationship between a block of samples and its time equivalent. Given my rough idea so far:

Number of samples played per second = total filesize / duration.

So say, I have a 1.02MB file and a duration of 12 sec (avg), I will have about 89,300 samples played per second. Is this right?

Is there other ways on how to compute this? For example, how can I know how much a byte[1024] array is equivalent to in time?


回答1:


Generally speaking for PCM samples you can divide the total length (in bytes) by the duration (in seconds) to get the number of bytes per second (for WAV files there will be some inaccuracy to account for the header). How these translate into samples depends on

  1. the sample rate
  2. bits used per sample, i.e. commonly used is 16 bits = 2 bytes
  3. number of channels, i.e. for stereo this is 2

If you know 2) and 3) you can determine 1)

In your example 89300 bytes/second, assuming stereo and 16 bits per sample would be 89300 / 4 ~= 22Khz sample rate




回答2:


In addition to @BrokenGlass's very good answer, I'll just add that for uncompressed audio with a fixed sample rate, number of channels and bits per sample, the arithmetic is fairly straightforward. E.g. for "CD quality" audio we have a 44.1 kHz sample rate, 16 bits per sample, 2 channels (stereo), therefore the data rate is:

  44100 * 16 * 2
= 1,411,200 bits / sec
= 176,400 bytes / sec
= 10 MB / minute (approx)


来源:https://stackoverflow.com/questions/5017367/audio-samples-per-second

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!