maxl0rd / standingwave3

Flash ActionScript3 dynamic audio library
http://www.noteflight.com
160 stars 25 forks source link

Problem with mixing simultaneous sources #5

Closed dannycorts closed 13 years ago

dannycorts commented 13 years ago

Hello, thanks by SW3, I am studing the new version of SW, and i am very happy with SW3.

I have found a problem with mixing simultaneous sources, for example:

            var sequence:ListPerformance = new ListPerformance();
            sequence.addSourceAt(0, new SineSource(new AudioDescriptor(), 0.8, 440));
            sequence.addSourceAt(0, new SineSource(new AudioDescriptor(), 0.8, 660));
            sequence.addSourceAt(0, new SineSource(new AudioDescriptor(), 0.8, 880));
            var source:IAudioSource = new AudioPerformer(sequence, new AudioDescriptor() );
            player.play(source);

The result have some noise, and do not work well, i whish to know how to solve this problem, do i have something wrong in my code?

Thanks by help, :)

maxl0rd commented 13 years ago

Hi

You're clipping.

Just turn the gain down in the AudioPerformer with the mixGain property, which sets mixing loss in decibels.

ie audioPerformer.mixGain = -12 ... would let you mix any 4 sources without clipping.

That's a new SW3 feature.

dannycorts commented 13 years ago

Hey, i found that changing audioPermorfer.mixGain help to solve the problem, but i will like to know if there is a function that calculate the correct value of the mixGain, because it is not the same if the number of mixed notes change.

maxl0rd commented 13 years ago

That's not an easy problem to solve generally in real-time. Best to set your mix conservatively or provide a user control.

If you have a final, rendered sample that you want to be amplified to full scale, you can use sample.normalize(), but you can't use that in a real-time signal chain.

dannycorts commented 13 years ago

Thank you :)