Is it possible to read the current playback position of a piece of audio?

Hi,

I’m trying to read the current playing position of a sound, in order to trigger an event when the sound reaches a certain point. You might say, “Just trigger the event using a timer”, but because the sounds I’m playing back will be subject to pitch alterations thanks to these features:

http://www.coronalabs.com/blog/2011/07/27/the-secretundocumented-audio-apis-in-corona-sdk/

… chronology alone is not going to be sufficient to find out how far through the audio file we are in terms of frames, rather than time. What I want to do is start a sound playing, set up something like this:

local soundtrack1 = audio.loadSound(“1.m4a”, {bufferSize=16384, maxQueueBuffers=24, startupBuffers=8, buffersQueuedPerUpdate=4});

audio.play(soundtrack1, {channel = 1, loops=-1});

The above will load a file called “1.m4a”, name it “soundtrack1”, play it on channel 1 and loop it indefinitely. In my project this sound is likely to be a two-bar drum loop. While it plays, the user can adjust its playback pitch (and hence its speed) in realtime via some other code I have. Then I want to constantly read its playback position, and when that returned value falls between a certain bracket, trigger an event to coincide with a particular part of “soundtrack1”. Maybe this is too much or too little info but I’m just trying to illustrate what I’m really trying to do.

I think this would be quite simple if there was an API such as:
audio.getPlaybackposition which returned a value in sample frames. But there isn’t, as far as I can tell.

Maybe there’s something in the OpenAL features I linked to above that could do it. I’ll dig into that but any help would be much appreciated.
Tony [import]uid: 111970 topic_id: 36395 reply_id: 336395[/import]