在使用 Web Audio Api 播放的 Stream 中单击声音 [英] Clicking sounds in Stream played with Web Audio Api

查看:22
本文介绍了在使用 Web Audio Api 播放的 Stream 中单击声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题.我正在使用网络音频播放来自服务器的流.我这样做的方式如下:

I have a strange Problem. I'm using Web Audio to play a stream from the server. I do that the following way:

 var d2 = new DataView(evt.data);

var data = new Float32Array(d2.byteLength / Float32Array.BYTES_PER_ELEMENT);
for (var jj = 0; jj < data.length; ++jj) {
    data[jj] = d2.getFloat32(jj * Float32Array.BYTES_PER_ELEMENT, true);
}

var buffer = context.createBuffer(1, data.length, 44100);
buffer.getChannelData(0).set(data);

source = context.createBufferSource();
source.buffer = buffer;
source.start(startTime);
source.connect(context.destination);

startTime += buffer.duration;

这很好用.如果我在我的电脑上播放流,我没有任何问题.

This works fine. If i play the stream on my Computer i don't have any problems.

如果我在我的 Windows 8 平板电脑(相同的 Chrome 版本)上播放相同的流,我的音频中有很多点击声.一秒钟内有多个.在每个缓冲区的末尾我听到咔哒声有点接缝.

If i play the same stream on my Windows 8 tablet (same Chrome version) i have a lot of clicking sounds in the audio. There are multiple of them within one second. It kinda seams that on the end of each buffer i hear a click.

我不明白其中的区别...我能找到的唯一区别是我的计算机声卡的采样率为 44100,而平板电脑上的采样率为 48000.

I don't understand the difference... The only difference i could find was that the samplingrate of the soundcard on my computer is 44100 and on the tablet it's 48000.

传输的流在 44100 中,我没有任何采样率问题.只是咔哒声.

The transmitted stream is in 44100 and i don't have any samplerate problems. just the clicking sounds.

有人知道为什么会这样吗?

Does anybody have an idea why this is happening?

谢谢,代谢

推荐答案

AudioBufferSourceNode 将其缓冲区重新采样为 AudioContext 采样率.可以想象,该 API 不允许您在一个 AudioBufferSourceNode 和另一个之间保持重采样器状态,因此两个缓冲区之间存在不连续性.

AudioBufferSourceNode resample their buffers to the AudioContext samplerate. As you can imagine, the API does not allow you to keep the resampler state between one AudioBufferSourceNode and the other, so there is a discontinuity between the two buffers.

我认为最简单的方法是以设备的采样率提供流,通过重新采样服务器端.当 AudioWorkerNode 准备好并实施后,您将能够自己解决此问题以及客户端,但事实并非如此.

I think the easiest way is to provide a stream at the sample-rate of the device, by resampling server-side. When the AudioWorkerNode will be ready and implemented, you'll be able to fix this yourself as well client side, but it's not.

或者,您也可以使用元素进行流式传输,然后使用 AudioContext.createMediaElementSource() 将其通过管道传输到 Web Audio API.

Alternatively also you can just stream using an element, and pipe that to Web Audio API using AudioContext.createMediaElementSource().

这篇关于在使用 Web Audio Api 播放的 Stream 中单击声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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