sound.position

it's an available feature in OpenAL 1.1. maybe it would be possible to implement into corona?


alxGetSoundOffset( sound_id )
Gets the current playback position of the sound buffer.

This function requires a OpenAL 1.1 or an extension of OpenAL 1.0

we could use this to check the position of the playhead in the audio file in order to sync animation etc

(also alxSetSoundOffet would be good too to move the playhead)

regards
j

I've used the sound position parameter a lot for projects in Flash; in particular this allowed me to do music playing widgets that show the playback progress on a timeline.

However the main reason I used this parameter in Flash was to pause music (ie. keep track of where the playback left off in order to start again from the same place) and Corona already has a pause sound method.

OpenAL has an offset API (the one you list is not from OpenAL though). However, what it actually returns may not be useful for most cases. With streaming samples, the offset is only relative to the current buffer fragment that is playing, not the entire audio sample. Typically, offsets are not heavily used except for long sounds which is when you usually use streaming.

We already do have audio.seek() which will let you move the offset which is relative to the entire file, not just the current playing buffer. And as mentioned, we already have audio.pause().

thanks for that eric

really though my request for sound.position is for getting, not for setting, in order to sync animation as mentioned.

looking forward to your contributions to the product

regards
j

What you ask for might be possible if you are willing to accept a degree of error. The problem is that particularly for streaming samples, you somehow need to compute the current OpenAL buffer offset relative to the entire file. To complicate the matter, the APIs to determine the length of a file are not always accurate so the position may be additionally inaccurate.

As of right now, this feature is a lower priority for us than a lot of other features, but I do see some of the utility of having such a function. So for the moment, the only thing I can offer is this: if you know of some C programmers who don't mind working with some really scary code, my audio backend is open source and I would be willing to discuss how others could contribute the feature.

One other note, we will never use the word 'position' for this feature because it is confusing with the 3D features of OpenAL which include things like position, orientation, and velocity.

actually my guess is that OpenAL system at a low level is more akin to the the newer Flash 10 audio features. I don't know how OpenAL works but with Flash 10, audio bytes go to the soundcard via a single Sound object instance in buffers of, say, 8192 bytes at a time. In these circumstances it is not possible to get a totally accurate playback position anyway because Flash only responds to events between each buffer ("onSampleData" aka Event.SAMPLE_DATA). Whilst there is some latency here, re-syncing the graphics/animation on the event has proven to be suitable enough.

the sound.position in Flash that I mentioned previously is from the old simple audio API where you just set event sounds to play. This is not governed by the audio buffering as explained above, so the value would be more accurately readable.

the two are completely different systems, and when and where to use one or the other depends on the type of application needed

As for determining the length of the file, would this matter for "position"? I don't need to know the overall percentage played I just need to know the time position to relate my animation to

not sure if this helps?

thanks
j

+1 for this request. How could we build a mp3 player without beeing able to tell the sec elapsed in a textfield or a bar moving?

Hi guys. Any news for the future of this feature? Right now I'm still stuck with my project due to this absent feature. Not saying that corona is bad or anything, its a great framework. But for my current project condition its just not workable. Perhaps for my next project corona will be used for sure.

Currently finishing all of my asset: animation, art, sounds. And already build a prototype in flash (duhh, dejavu). Tested on iOS, Android and playbook. The fps not so great, only 20fps (no manual blitting, just hard doc properties) with adobe air 2.6

Sorry, no news to report on this.
If anybody is really impatient and wants to get it done, ALmixer is open source and I would be happy to take patches.

Just want to bump this and see if we can get an estimate on where this sits on the food chain. I am writing a search and rescue tool for the FAA and having the audio synchronized with the playback of the aircraft flight is critical. If the API could publish the length it is playing to a callback this would allow us adjust the graphical recreation to match the audio. I wish I could dive in and edit the code, but C is not a tool in my quiver.

Sorry, this is currently low on the priority list. But for your purposes, you could implement this yourself in Corona by keeping track of the elapsed time using the enterframe callback.

Thanks for the quick response. Any solution is great, but not following how keeping track of the enterframe callback is going to tell me how much of the audio has played? How do I link the enterframe callback to the audio player? How often is the callback going to occur and what will the behavior be if we are buffering do to CPU load?

Again, a huge thank your for the followup!

When you start playing audio, call system.getTimer() to get the current time and save this value as your startTime.
In every enterframe callback, call system.getTimer() again and subtract the startTime. The difference is the elapsed time of the audio playback.

Basically we are talking about starting the audio and counting on it playing continuesly. Could I possibly get a copy of your C code so I can try and add the functionality?

Thanks for all your hardwork, Corona is a real game changer.

views:2558 update:2011/9/18 10:09:28
corona forums © 2003-2011