Sources and Buffers

[email protected] Mon, 19 Nov 2012 14:57:45 -0500
Newsgroups gmane.comp.lib.openal
Message-ID <[email protected]>
OK,

Thanks again for all the responses so far.  I'd like to dig into a
specific area that I'm doing something rather simplistic and maybe you can
help me "see the light" on.

(Keep in mind I'm actually writing this in Java using the JOAL bindings,
so please excuse the OOP-ish pseudocode...)

So, at the concept level, I have this locomotive sitting there, and I'm
looping a WAV file representing its idle sound.  When the user increases
the throttle, I interrupt that loop, play a single WAV file (or a series
of WAV files) that represents the engine accelerating, and then loop a new
WAV that represents the faster-running engine.  Likewise, when the
throttle is reduced, I reverse the process, playing a deceleration sound
before going back to the idle.

There are actually 8 different "notches" at which the engine can run, and
transitions up/down between each adjacent "notch" (for practical sake, I'm
daisy-chaining the transitions if the user makes a large throttle change).

OK, so under the covers, here's what I'm doing, and it's very simplistic.

I create a Source for each "notch" looping sound, and a Source for each
transition.  The WAV files are loaded into a single buffer associated with
each Source.  When the throttle change occurs, something like the
following pseudocode happens:

Notch1_Source.loop()
< throttle change envent>
Notch1_Source.stop()
N1-N2_Source.play()
<wait for play to end (set a Timer event for the duration of the N1-N2 WAV
file)>
N1-N2_Source.stop()
Notch2_Source.loop()

And so on.

Now, it occurs to me I could do something similar by having a single
Source for the Engine, and queuing up buffers in the right sequence for
that single Source to play...

Engine_Source.queueBuffer(N1_loop_buffer)
Engine_Source.setLooping(true)
Engine_Source.play()
<throttle change event>
Engine_Source.setLooping(false)
Engine_Source.queueBuffer(N1-N2_buffer)
Engine_Source.queueBuffer(N2_loop_buffer)
<Wait long enough to be sure we're in the N2_loop buffer>
Engine_Source.setLooping(true)

BUT ... this seems to create two issues... one is that it's not entirely
clear to me how to tell the Source to loop ONLY the last buffer, nor is it
clear to me how to tell which buffer is currently being played (I think
for the latter I can poll the AL_BUFFER property or do some math on
AL_BUFFERS_QUEUED and AL_BUFFERS_PROCESSED).

More importantly, what happens if the user shifts up 3 notches, and then
back down rapidly...

<throttle change to N4 event>
Engine_Source.setLooping(false)
Engine_Source.queueBuffer(N1-N2_buffer)
Engine_Source.queueBuffer(N2-N3_buffer)
Engine_Source.queueBuffer(N3-N4_buffer)
Engine_Source.queueBuffer(N4_loop_buffer)
<throttle change to N1 event while EngineSource is still playing
N2-N3_buffer>
?????

... hmm... I need to kill the N4_loop_buffer and replace the N3-N4_buffer
with the N3-N2_buffer and N2-N1_buffer, and then tag the N1_loop_buffer on
the end of the queue.  I'm not at all sure how to go about doing this.

Does this make any sense at all?  I get the impression that using the
buffer queueing will provide cleaner transitions from one sound to the
next, BUT it appears to greatly complicate when I need to "orchestrate"
the different sounds as in a rapid or "interrupting" throttle change. 
Note that all of these sounds are being played in sequence, not
overlapping at all.  But it appears much easier to just STOP one Source
and PLAY a different Source, rather than mess with the Buffer Queue...

HELP????

Thanks,

Mark (TD)


_______________________________________________
Openal mailing list
[email protected]
http://opensource.creative.com/mailman/listinfo/openal