简体   繁体   English

Web Audio Api实时流式传输PCM ADPCM

[英]Web Audio Api Realtime streaming PCM ADPCM

I have a server that passes the client PCM or ADPCM data. 我有一台服务器传递客户端PCM或ADPCM数据。

I initially decided to use PCM because I did not want to deal with encoding and decoding. 我最初决定使用PCM,因为我不想处理编码和解码。

I got PCM to work however between each chunk of audio I heard glitches.(Sort of like clipping) 我得到PCM工作但是在每一段音频之间我都听到了毛刺。(有点像剪辑)

So I thought maybe the reason is latency/high quality audio and all that stuff. 所以我想也许原因是延迟/高质量的音频和所有这些东西。

So I decided to use ADPCM to reduce the data amount. 所以我决定使用ADPCM来减少数据量。 I wrote a adpcm to pcm decoder in javascript. 我在javascript中写了一个adpcm到pcm解码器。 It was a hassle. 这很麻烦。 I was hoping that since the data count reduced maybe that would stop the glitches(data would catch up with what is being played) 我希望,因为数据计数减少可能会阻止故障(数据将赶上正在播放的内容)

But I was wrong. 但是我错了。 I still get the glitches. 我仍然有毛刺。

Can this even be done with TCP ? 这甚至可以用TCP完成吗? Or is it a lost cause. 或者这是一个失败的原因。 I dont have UDP over websockets. 我没有UDP over websockets。

Do I need to implement a buffering algorithm ? 我需要实现缓冲算法吗? I don't want to do this as it is real time audio and i just want to process it as fast as I can. 我不想这样做,因为它是实时音频,我只是想尽快处理它。

Do you guys know a good link to read about real time audio over the web. 你们知道一个很好的链接,通过网络阅读有关实时音频的信息。

I can give code example but this is a high level question. 我可以给出代码示例,但这是一个高级问题。

PS: I tried to use tabs but we get a buffering issue and we cant control it. PS:我试图使用制表符,但我们遇到缓冲问题,我们无法控制它。 I also dont get any flow control from the server. 我也没有从服务器获得任何流量控制。 It does not say that Audio starter or audio stopped our paused. 它没有说音频启动器或音频停止了我们的暂停。 It is a push protocol and All I get is ADPCM and PCM data 它是推送协议,我得到的只是ADPCM和PCM数据

Yes, of course you can use TCP. 是的,当然你可以使用TCP。 UDP is often used in telephony applications as the lower overhead makes everything faster, and for this application it doesn't matter if packets are dropped or arrive in the wrong order. UDP通常用于电话应用程序,因为较低的开销使一切更快,对于此应用程序,数据包是否被丢弃或以错误的顺序到达并不重要。 But since UDP isn't an option, you can use TCP. 但由于UDP不是一个选项,您可以使用TCP。

As you have suspected, it seems to me that your problem is buffer underruns. 正如您所怀疑的那样,在我看来,您的问题是缓冲区不足。 Either your connection to the server is not fast enough (or at least consistently fast enough), or you are not providing data from the encoder at a fast enough rate. 您与服务器的连接速度不够快(或者至少足够快),或者您没有以足够快的速度从编码器提供数据。 This can happen if you are recording data in real time, and trying to play it back in real time. 如果您实时记录数据并尝试实时播放,则可能会发生这种情况。

A solution is to buffer data server-side before sending it to the client. 解决方案是在将数据发送到客户端之前缓冲数据服务器端。 Have as large of buffer as your latency requirements allow. 拥有与延迟要求允许的一样大的缓冲区。 For internet radio purposes, I usually pick a 30-second buffer, as latency doesn't matter. 对于互联网广播目的,我通常会选择一个30秒的缓冲区,因为延迟并不重要。 For your purposes, you will probably want a buffer of at least 64KB. 出于您的目的,您可能需要至少64KB的缓冲区。 This is the maximum size allowed in a TCP packet. 这是TCP数据包中允许的最大大小。 This packet will get fragmented along the way, but that is okay. 这个包将在整个过程中碎片化,但这没关系。

You might also look into how your server is sending data. 您还可以查看服务器如何发送数据。 Experiment with disabling the Nagle algorithm so that your server isn't waiting for ACKs before sending more data. 尝试禁用Nagle算法,以便服务器在发送更多数据之前不等待ACK。

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

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