AS3 加法音调合成。播放多个生成的声音

发布于 2024-09-18 02:13:49 字数 219 浏览 2 评论 0原文

受到 Andre michelle 的启发,我正在 AS3 中构建一个色调矩阵。 我设法创建了矩阵并生成了不同的声音。听起来不太好,但我已经到了 我遇到的一个大问题是,当设置多个点播放时,听起来很糟糕。我在 google 上搜索了很多,找到了加法合成方法,但不知道如何将其应用到 as3。 有人知道如何一起播放多种声音吗?有什么提示吗?

我的演示位于 www.inklink.co.at/tonematrix

Inspired by Andre michelle, I`m building a tone matrix in AS3.
I managed to create the matrix and generate the different sounds. They don´t sound that good, but I´m getting there
One big problem I have is when more than one dot is set to play, it sounds just horrible. I googled a lot and found the additive synthesis method but don´t have a clue how to apply it to as3.
anybody out there knows how to play multiple sounds together? any hint?

my demo is at www.inklink.co.at/tonematrix

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

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

发布评论

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

评论(2

入怼 2024-09-25 02:13:50

哦,常见的是,声音太可怕了……

检查过维基吗?这并不难理解...即使您不太了解数学...您应该知道 - 音乐编程并不容易。

所以:

让我们首先定义一些东西:

var harmonics:Array = new Array();

harmonics 是我们将在其中存储各个谐波的数组。每个子项将是另一个数组,包含[“振幅”](技术上是音量)、[“频率”]和[“波长”](周期)。我们还需要一个函数,可以在给定振幅波长偏移(从波的开始处)的情况下给出波的相位。对于方波,例如:

function getSquarePhase(amp:Number, wl:Number, off:Number):Number {
    while (off > wl){off -= wl;}
    return (off > wl / 2 ? -amp : amp); // Return amp in first half, -amp in 2.
}

如果需要,您可以添加其他类型,甚至自定义矢量波。

现在是更困难的部分。

var samplingFrequency; // set this to your SF

function getAddSyn(harmonics:Array, time:Number):Number {
    if (harmonics.length == 1){ // We do not need to perform AS here
        return getSquarePhase(harmonics[0]["amplitude"], harmonics[0]["wavelength"], time);
    } else {
        var hs:Number = 0;
        hs += 0.5 * (harmonics[0]["amplitude"] * Math.cos(getSquarePhase(harmonics[0]["amplitude"], harmonics[0]["wavelength"], time)));
        // ^ You can try to remove the line above if it does not sound right.
        for (var i:int = 1; i < harmonics.length; i++){
            hs += (harmonics[0]["amplitude"] * Math.cos(getSquarePhase(harmonics[0]["amplitude"], harmonics[0]["wavelength"], time)) * Math.cos((Math.PI * 2 * harmonics[0]["frequency"] / samplingFrequency) * time);
            hs -= Math.sin(getSquarePhase(harmonics[0]["amplitude"], harmonics[0]["wavelength"], time)) * Math.sin((Math.PI * 2 * harmonics[0]["frequency"] / samplingFrequency) * time);
        }

        return hs;
    }
}

这一切都只是从维基百科转换而来(弱:D),我可能在其中某处犯了一个错误......但我认为你应该明白......如果没有,请尝试自己从维基百科转换AS,正如我所说,这并不难。

我还以某种方式忽略了奈奎斯特频率......

Oh common the sound was horrible...

Checked wiki? It is not that hard to understand... Even if you don't know that much of mathematics... Which you should - PROGRAMMING music is not easy.

So:

Let's first define something:

var harmonics:Array = new Array();

harmonics is the array in which we will store individual harmonics. Each child will be another array, containing ["amplitude"] (technically the volume), ["frequency"] and ["wavelength"] (period). We also need a function that can give us the phase of the wave given the amplitude, wavelength and offset (from the beginning of the wave). For square wave something like:

function getSquarePhase(amp:Number, wl:Number, off:Number):Number {
    while (off > wl){off -= wl;}
    return (off > wl / 2 ? -amp : amp); // Return amp in first half, -amp in 2.
}

You might add other types, or even custom vector waves if you want.

Now for the harder part.

var samplingFrequency; // set this to your SF

function getAddSyn(harmonics:Array, time:Number):Number {
    if (harmonics.length == 1){ // We do not need to perform AS here
        return getSquarePhase(harmonics[0]["amplitude"], harmonics[0]["wavelength"], time);
    } else {
        var hs:Number = 0;
        hs += 0.5 * (harmonics[0]["amplitude"] * Math.cos(getSquarePhase(harmonics[0]["amplitude"], harmonics[0]["wavelength"], time)));
        // ^ You can try to remove the line above if it does not sound right.
        for (var i:int = 1; i < harmonics.length; i++){
            hs += (harmonics[0]["amplitude"] * Math.cos(getSquarePhase(harmonics[0]["amplitude"], harmonics[0]["wavelength"], time)) * Math.cos((Math.PI * 2 * harmonics[0]["frequency"] / samplingFrequency) * time);
            hs -= Math.sin(getSquarePhase(harmonics[0]["amplitude"], harmonics[0]["wavelength"], time)) * Math.sin((Math.PI * 2 * harmonics[0]["frequency"] / samplingFrequency) * time);
        }

        return hs;
    }
}

This is all just converted (weakly :D) from the Wikipedia, I may have done a mistake somewhere in there... But I think you should get the idea... And if not, try to convert the AS from Wikipedia yourself, as I said, it is not so hard.

I also somehow ignored the Nyquist frequency...

未蓝澄海的烟 2024-09-25 02:13:50

我已经尝试过你的演示,并认为它实际上听起来不错。你说这听起来不太好是什么意思?缺少什么?我的主要兴趣领域是音乐,我没有发现任何问题,只是有点令人沮丧,因为在创建序列后,我觉得需要添加新的声音!如果我能够录制我正在玩的东西,我会把它发送给你。

不过,进入加法合成看起来并不是一件容易的事。你想把它推到什么程度,你想创建某种形式的合成器吗?

I have tried your demo and thought it sounded pretty good actually. What do you mean it doesn't sound that good? What's missing? My main area of interest is music and I haven't found anything wrong , only it's a little frustrating , because after creating a sequence, I feel the need to add new sounds! Had I been able to record what I was playing with, I would have sent it to you.

Going into additive synthesis doesn't look like a light undertaking though. How far do you want to push it, would you want to create some form of synthesizer?

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