简体   繁体   English

如何通过UDP播放音频流?

[英]How to play audio stream over UDP?

I writing a Windows application, It receives audio data from an Android app, I use UDP to transfer data over LAN, and use RtAudio to play audio-stream. 我编写Windows应用程序,它从Android应用程序接收音频数据,我使用UDP通过LAN传输数据,并使用RtAudio播放音频流。

Every UDP package payload is a audio sample array, in 32k/16bit/pcm format. 每个UDP包有效载荷都是一个音频样本数组,格式为32k / 16bit / pcm。

When data size is 576 bytes, 288 samples in other words, every thing is OK, we can hear a clear voice. 当数据大小为576字节(换句话说为288个样本)时,一切正常,我们可以听到清晰的声音。

But when data size in 192 bytes, 96 samples in other words, the sound is not clear. 但是,当数据大小为192字节,换句话说为96个样本时,声音不清楚。

Does anyone have the problem? 有人有问题吗?

It is a balancing act to determine optimum size of each buffer packet ... too large and you progressively move away from real time response yet too small and the code spends proportionately too much time negotiating the boilerplate plumbing of simply transferring the data. 确定每个缓冲区数据包的最佳大小是一种平衡的行为……太大了,您逐渐偏离了实时响应,但是又变得太小,并且代码花费了过多的时间来协商简单传输数据的样板管道。 Looks like you have hit this lower boundary when as you say 192 bytes starts acting up. 好像您说到192个字节开始起作用时,您已达到此下限。

This is true independent of transport mechanism. 确实如此,与运输机制无关。 Also keep in mind the wall clock duration consumed when listening to a few hundred bytes is tiny (typically 42,100 samples per second for CD quality mono audio) so you will not loose much in the real time aspect to give yourself more than that lower bound you have hit. 还请记住,聆听几百个字节时消耗的挂钟时间很小(对于CD质量的单声道音频,通常为每秒42,100个样本),因此您不会在实时方面失去太多,可以给自己带来更多的收益。打了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM