如何在 AS3 中将声音对象提取到单字节数组

发布于 2024-12-27 19:03:33 字数 520 浏览 5 评论 0原文

我试图将声音对象的字节数组添加到捕获的麦克风声音字节数组中。

它可以工作,但是提取的声音对象会被缩小并长度加倍。我猜这是因为声音对象的字节数组是立体声的,而麦克风字节数组是单声道的。

我有这个:

sound.extract(myByteArray, extract);

myByteArray 现在包含立体声数据。我怎样才能把它变成单声道(我是 ByteArrays 的新手)。

更新:

这是一个可行的解决方案:

existingByte.position = 0;
var mono : ByteArray = new ByteArray();
while(existingByte.bytesAvailable) {
    var left : Number = existingByte.readFloat();
    mono.writeFloat(left);
    existingByte.position +=4;
}

I'm trying to prepend the byte array of a sound object to a captured microphone sound byte array.

It works, but the extracted sound object get pichted down and doubled in length. I guess this is because the byte array of the sound object is in stereo, while the mic byte array is in mono.

I have this:

sound.extract(myByteArray, extract);

myByteArray now contains the stereo data. How can I turn this to mono (I'm new to ByteArrays).

UPDATE:

Here's a working solution:

existingByte.position = 0;
var mono : ByteArray = new ByteArray();
while(existingByte.bytesAvailable) {
    var left : Number = existingByte.readFloat();
    mono.writeFloat(left);
    existingByte.position +=4;
}

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

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

发布评论

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

评论(1

网名女生简单气质 2025-01-03 19:03:33

只需选择一个通道即可提取。我认为 ByteArray 是交错的,因此如果您选择所有奇数字节,则它是左通道,如果您选择所有偶数字节,则它是右通道。

var mono : ByteArray = new ByteArray();
for( var i : int = 0; i < raw.length; i+=2 ) {
    var left : int = raw[i];
    var right : int = raw[i+1];

    var mixed : int = left * 0.5 + right * 0.5;
    if( pickLeft ) {
      mono.writeByte( left );
    } else if( pickRight ) {
      mono.writeByte( right );
    } else {
      mono.writeByte( mixed );
    }
}

Just pick a channel to extract. I think ByteArray is interleaved so if you pick all odd bytes its the left channel, if you pick all even bytes it's the right channel.

var mono : ByteArray = new ByteArray();
for( var i : int = 0; i < raw.length; i+=2 ) {
    var left : int = raw[i];
    var right : int = raw[i+1];

    var mixed : int = left * 0.5 + right * 0.5;
    if( pickLeft ) {
      mono.writeByte( left );
    } else if( pickRight ) {
      mono.writeByte( right );
    } else {
      mono.writeByte( mixed );
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文