问题
This question might be a little tricky.
I am trying to send a Byte[] over a Windows Socket with a System.Timer.
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
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.
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
How are these figures calculated from the Encoding format: 128 kbit/sec and 48 kHz sample frequency?
Math I have tried:
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.
回答1:
128 kbit/sec is not BitsPerSample, but BitsPerSeconds.
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
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.
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
来源:https://stackoverflow.com/questions/37449498/calculating-the-frame-rate-and-size-for-a-timed-stream-of-a-byte-array