如何使用loadPCMFromByteArray?

发布于 2024-12-18 08:28:23 字数 601 浏览 1 评论 0原文

有人能够成功使用 Flash 11 中的新 Sound 方法 loadPCMFromByteArray 吗?每当我使用它时,我都会听到重复的滴答声。

还有一种方法可以在该方法中设置深度(位)?看来这个loadPCMFromByteArray只能理解32位PCM数据。

我已经查找了示例,但没有找到有效的示例

这是我的示例代码,请注意,我不断向 soundBA (ByteArray 对象)添加数据,并在将其传递给 loadPCMFromByteArray 方法后清除它,我也是如此我只是被迫进行检查(8192 * 4),因为看起来 loadPCMFromByeArray 方法只理解 32 位音频样本,我如何将其设置为读取 8 位和 16 位样品?:

if (soundBA.bytesAvailable >= (8192 * 4 * channels))
{ 
    soundPlayer.loadPCMFromByteArray(soundBA, soundBA.bytesAvailable / 4, "float", false, 22050);
    soundChannel = soundPlayer.play();
    soundBA.clear();
}

has anyone been able to use the new Sound method loadPCMFromByteArray in Flash 11 successfully? I just end up hearing repeating ticking sound whenever I use it.

And also is there a way to set the depth (bits) in that method? it seems that this loadPCMFromByteArray only understands 32bit PCM data.

I've looked for examples but I've found no working examples

Here is my sample code, please note that I'm continously adding data to the soundBA (ByteArray object) and clearing it after passing it to the loadPCMFromByteArray method, also I'm just forced to do a check (8192 * 4) since it really seems that the loadPCMFromByeArray method only understands 32bit audio samples, how can I set it to read 8-bit and 16-bit samples?:

if (soundBA.bytesAvailable >= (8192 * 4 * channels))
{ 
    soundPlayer.loadPCMFromByteArray(soundBA, soundBA.bytesAvailable / 4, "float", false, 22050);
    soundChannel = soundPlayer.play();
    soundBA.clear();
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

月隐月明月朦胧 2024-12-25 08:28:23

我正在寻找与你相同的东西,但我已经有了部分答案。
在尝试使用“loadPCMFromByteArray”函数之前,我使用 as3wavsound lib 它使用音频操作库称为“sazameki”。最后一个库为您提供了将 8 位或 16 位转码为数字向量的方法。您只需获取该向量并将其写入 ByteArray 中:

var someByteArray:ByteArray = new ByteArray();
for (....){
  someByteArray.writeFloat(number);
}

然后为其提供“loadPCMFromByteArray”函数。您应该会遇到错误,因为您在 ByteArray 上的位置不好。所以重置一下吧。
您的最终代码应如下所示:

var flexSound:Sound = new Sound();
var someByteArray:ByteArray = new ByteArray();
for (....){
    someByteArray.writeFloat(number);
}
someByteArray.position = 0;
flexSound.loadPCMFromByteArray(someByteArray, length);
flexSound.play();

我希望这可以帮助您。

I'm looking for the same thing as you but I already have a part of the answer.
Before trying to use "loadPCMFromByteArray" function, I was using as3wavsound lib which uses an audio manipulating library called "sazameki". This last library gives you ways to transcode 8 or 16 bits to a vector of Numbers. You just have to take that vector and write it into a ByteArray with:

var someByteArray:ByteArray = new ByteArray();
for (....){
  someByteArray.writeFloat(number);
}

then give it "loadPCMFromByteArray" function. You should have an error because your position on the ByteArray is not good. So reset it.
Your final code should look like that:

var flexSound:Sound = new Sound();
var someByteArray:ByteArray = new ByteArray();
for (....){
    someByteArray.writeFloat(number);
}
someByteArray.position = 0;
flexSound.loadPCMFromByteArray(someByteArray, length);
flexSound.play();

I hope this could help you.

遮了一弯 2024-12-25 08:28:23

我无法使用 loadPCMFromByteArray 它给了我这个错误:

通过静态类型 flash.media:Sound 的引用调用可能未定义的方法 loadPCMFromByteArray。

_output.position =0;
mySound.loadPCMFromByteArray(_output, _output.length);
channel = mySound.play();

I cannot use loadPCMFromByteArray it gives me this error :

Call to a possibly undefined method loadPCMFromByteArray through a reference with static type flash.media:Sound.

_output.position =0;
mySound.loadPCMFromByteArray(_output, _output.length);
channel = mySound.play();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文