One major issue with dealing with sound is having a rock solid timer available. Coming from an Actionscript background, it appears that Corona is in the same situation that Flash was prior to AS3, where it was difficult to synchronize audio events due to timers based on frame rates and/or polling the system clock.
One solution (in the flash world) is to read bytes from a silent audio resource (file). Then fire events based on the “position”.
Example:
[code]
var _bpm = 120;
var _bpmTrigger = (60 / _bpm ) * 1000;
var _sound = new Sound(“10_seconds_of_silence.wav”);
var silenceBA:ByteArray = new ByteArray();
var silenceBA_len:Number = Math.floor ((_sound.length/1000)*44100);
_sound.extract (silenceBA, silenceBA_len);
silenceBA.position = 0;
function fSampleData(event:SampleDataEvent): void {
for(i = 0; i<num_samples i> silenceBA.readFloat();
silenceBA.readFloat();
// 10,000 because our WAV is a known 10 second value
ms = 10000 * (silenceBA.position/silenceBA_len);
if(ms >= _bpmTrigger){
silenceBA.position = 0;
fireEvent();
}
}
}
function fireEvent();
// do something
}
_sound.addEventListener( SampleDataEvent.SAMPLE_DATA, fSampleData );
[/code]
Just thought Id throw this out there, as I’d love to see the audio capabilities of Corona expand.
Direct manipulation of (or exposure to) an audio byte array would be awsome
-mike
[import]uid: 616 topic_id: 8267 reply_id: 308267[/import] </num_samples>