[Bf-committers] Animation system problem: Sound
neXyon
nexyon at gmail.com
Sat Jul 25 14:42:27 CEST 2009
Greetings!
I've been trying to integrate my audio library into the sequencer and it
already works with some flaws if you checked out my branch.
The problem is that the animation system is not really useful for audio
playback and I need your help to find a good solution to integrate sound!
I sum up the background you have to know:
Animation system: Works pretty easy, if the frame changes (by user
action or if animation runs by a timer), everything is updated to
display the CFRA (current frame).
Audio system: The two important things are sources and the playback
device. A source is for example an ogg sound file, the device is SDL or
OpenAL or whatever.
The next step is to play back the source. As a source can be played back
multiple times at the same time, the device returns a handle to that
specific playing source when you start playback.
The device then starts reading the source and plays it, you have no
influence on that and you don't know when exactly that happens.
What you can do with the handle is: pause, resume, stop, seek, change
volume etc.
So what do I currently do?
When the user hits (forward) play, I start all the sound strips with a
delay layed over them (playing silence as for the delay time), so if the
strip starts at frame 20 instead of 1, I add a delay of 19 frames / FPS.
And then I seek all sounds to the current frame / FPS.
When the user stops playback I stop all those playing sources again. If
the animation system tells that the frame changed and the change is not
+1, I seek all playing sounds to the current frame.
What's the problem with that?
* Once playback has started the playing sources are not editable, moving
strips or changing the sound source has no effect.
* If you seek to a frame before the SFRA (starting frame) the sounds are
seeked to 0 as there's no possibility to seek to a negative value: no
sound data there, not even silence.
What about frame by frame playback like the rest?
The idea is to play a source on frame change for this frame. The problem
is: even when the playback is real time you get cracks, as the playback
cannot be kept that accurate that as soon as the playback of the
previous frame stopped, the next frame starts.
What then?
I think of a solution in between. On frame change all sources are
notified. If the source is not playing but should, it's started. If the
current playback position differs a specific value (lambda) from the
CFRA time, the source is seeked.
The question now is what happens if the playback is slower than
realtime? It first of all depends on frame skipping on or off. If it's
off the sources will be seeked quite often and the playback doesn't
sound to nice...
I'd really like to get some suggestions on this!
Regards,
Jörg
More information about the Bf-committers
mailing list