Question

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

Was it helpful?

Solution

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...

OTHER TIPS

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?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top