计算一个字节数组的定时流的帧速率和大小 [英] Calculating the Frame Rate and Size for a Timed Stream of a Byte Array

查看:202
本文介绍了计算一个字节数组的定时流的帧速率和大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题可能是有点棘手。

This question might be a little tricky.

我试图发送一个字节]通过Windows套接字与System.Timer。

I am trying to send a Byte[] over a Windows Socket with a System.Timer.

中的数据是一个WAV文件,常见的编码是每个样本16位为8KHz

The Data is a wav file, the common encoding is 8Khz 16bits per sample.

本文介绍的一些细节我想做的事:创建具有蓝牙音频应用

This article explains in some detail what I am trying to do: Creating audio applications with Bluetooth

在一个MP3应用中,假设该装置是从一个文件的连接$ C $光盘在128千比特/秒和48千赫的采样频率发送一个MP3流。这意味着,一个MP3音频帧长每隔24.0毫秒发送384字节。因此,如果当定时器到期时的恒定比特率将被维护的设备简单地设置一个周期定时器为24.0毫秒,并发送一个数据包。

In an MP3 application, suppose the device is sending an MP3 stream from a file encoded at 128 kbit/sec and 48 kHz sample frequency. This means an MP3 audio frame 384 bytes long is sent every 24.0 msec. So, if the device simply sets a periodic timer for 24.0 msec and sends a packet when the timer expires the constant bit rate will be maintained.

我的问题是,如何在这些数字计算?它是如何音频帧的 384 字节长,我们怎么知道这个周期定时器为 24.0毫秒

My question is, how are these figures derived? How is it that audio frame is 384 bytes long and how do we know the periodic timer is 24.0 msec

如何在这些数字从编码格式计算:12​​8千比特/秒和48 kHz采样频率

How are these figures calculated from the Encoding format: 128 kbit/sec and 48 kHz sample frequency?

数学我曾尝试:

double BitsPerSample = 128000;
double SamplesPerSecond = 48000;

// 1 for Mono, 2 for Stereo:
double Channels = 2;

double SingleFramePeriod = 1 / SamplesPerSecond;
double BitsPerSecond = SamplesPerSecond * BitsPerSample * Channels;
double BytesPerSecond = ( BitsPerSecond / 8 );
double BytesPerFrame = (1 / (BitsPerSecond / 8));

这没有给我上面的数字。

None of which give me the above figures.

推荐答案

128千比特/秒不BitsPerSample,但BitsPerSeconds。

128 kbit/sec is not BitsPerSample, but BitsPerSeconds.

说不同的,这是(一个字节8位)16KB /秒。因此,如果你决定,样品是384字节长,那么你就需要每秒发送384分之16000= 41.6666样本

Said differently, it's 16kB/s (8 bits in a byte). Therefore, if you decide that the "sample" is 384 bytes long, then you need to send 16000 / 384 = 41.6666 "samples" per second

只要你想送它尽可能顺利(在样品时期是恒定的),这意味着你必须把这些384字节每秒41.6666倍,即每: 1秒/ 41.66666 = 24ms

Provided you want to sent it as smooth as possible (the period between "sample" is constant), this means you have to send these 384 bytes 41.6666 times per second, that is, every: 1s / 41.66666 = 24ms.

显然,384个字节是不是MP3任意选择,对于帧长度计算如下:

Obviously, 384 bytes is not an arbitrary choice for MP3, the computation for the frame length follows:

FrameLengthInBytes = 144 * BitRate / SampleRate + Padding

=> For 128 kbit/s, 48Khz, 0 padding, it gives 384 bytes

这篇关于计算一个字节数组的定时流的帧速率和大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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