Source code available here
Note: This example uses Minimal Comps by Keith Peters
Tremolo is a nice effect and actually quite simple to produce. It consists of modulating the amplitude ( audible volume ) of a carrier signal ( in this case an mp3 ) over time. In this demo we use a simple sine wave oscillation to produce a number between 1 and -1 and multiply the left and right samples of an input sound by it.
The pseudo-code below demonstrates the basics of the algorithm used. Note: this is not the complete code, this is just an example of the calculation used to create the effect
protected function onSampleData( event:SampleDataEvent ):void
{
var trem:Number; // -- modulation value
var rate:Number = 2.5; // -- cycles per second, pretty slow oscillation
var depth:Number = 1; // -- peaks and crests of the tremolo
for( var i:int = 0; i < length; i++ )
{
var l:Number = synthbytes.readFloat();
var r:Number = synthbytes.readFloat();
// -- creating an ocsillating value between 1 & -1
trem = Math.sin( ( Math.PI * 2 ) * rate * trempos / SAMPLE_RATE );
// -- using additive process here because we actually want to add the modulated audio to the existing
// -- audio, this way if the depth is zero the original audio is still audible
// -- scale the amplitude of the sample by trem oscillation creates modulation
l += l * trem * depth;
r += r * trem * depth;
event.data.writeFloat( l );
event.data.writeFloat( r );
// -- increment the phase of the calculation on each iteration
trempos++;
}
}
Durr. I’m losing my adenoids!