views:

366

answers:

1

A few days ago, this was my question, and I found the answer. Maybe this will help someone else.

A. The first part of the problem: can you amplify sound using Flash? The AS3 documentation for SoundTransform says this about the volume attribute:

"The volume, ranging from 0 (silent) to 1 (full volume).

At face value, this means you can only make sounds quieter. In fact, if you supply a value greater than one (1.0), sounds will be amplified. You risk saturating the sound and getting poor quality, but you can do it, and for voice, you can get away with a lot. (Music is less forgiving, so experiment. This method does not do dynamic compression, which is better suited to music.)

B. The second part of the problem: the order in which you do things.

RIGHT:

soundTransform = new SoundTransform();
soundTransform.volume = volume * volumeAdjustment;
audioChannel.soundTransform = soundTransform;

WRONG:

soundTransform = new SoundTransform();
audioChannel.soundTransform = soundTransform;
soundTransform.volume = volume * volumeAdjustment;

I did some testing in CS3 and CS4, and got different results. In CS3, I could set the volume on the transform AFTER "audioChannel.soundTransform = soundTransform;" and everything was fine. But in CS4 it had no effect. I suspect that CS3 used pass by reference to set the soundTransform, while CS4 uses pass by value semantics and copies the object passed into it. The CS4 approach is better designed, but did break my code that worked fine in CS3.

C. The last question, is how to convert a decibel value to a factor that can be multiplied by the volume to amplify (or quiet) the sound by the desired amount.

var multiplier:Number = Math.pow(10, decibels / 20); // Power vs. amplitude

Note that "decibels" may be a positive number (to amplify) or a negative number (to make quieter). If decibels is zero, no change occurs.

A value for decibels of 3 will (to a close approximation) double the amplitude. A value of 10 decibels will increase the volume tenfold (exactly).

+2  A: 

Your decibel calculation should actually use 20, not 10:

var multiplier:Number = Math.pow(10, decibels / 20);

Digital audio is amplitude, not power (it's a representation of sound pressure, not sound power).

endolith
You are correct. Thanks for pointing this out. I will edit my post.
Paul Chernoch