Below is a snippet from the Adobe Live Docs SampleDataEvent
class. It demonstrates how to create an audible sine wave by pushing samples into a ByteArray
. The part that I am hung up on is why you need to push the same value into the writeFloat()
method twice?
var mySound:Sound = new Sound();
function sineWaveGenerator(event:SampleDataEvent):void
{
for ( var c:int=0; c<8192; c++ ) {
event.data.writeFloat( Math.sin((Number(c+event.position)/Math.PI/2))*0.25 );
event.data.writeFloat( Math.sin((Number(c+event.position)/Math.PI/2))*0.25 );
}
}
mySound.addEventListener(SampleDataEvent.SAMPLE_DATA,sineWaveGenerator);
mySound.play();
As a test, I removed one of the calls to writeFloat() and increased the buffer to 16384 samples ( twice the current ). This created an audible gap and click in the the audio, but didn't enlighten me much as to why. Perhaps you can...
Thanks again :)