|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Consumes handles to audio files and controls how they are mixed and played. An SDLAudioCallback is an interruptable piece of code does the actual management of the individual audio samples. You always need to have a callback method written which mixes your audio data and puts it in the audio stream .
There are two notions of "play" in SDL.
For review, here is the relationship between the JSDL Audio classes.
This "unpausing" is performed manually by invoking a method in
the SDLAudio object the callback was orginally registered with.
Refer to SDLAudio.pauseAudio(false)
(Analogy: The SDLAudio object controls whether the dam is open).
Once started, the AudioCallBack will begin to "play" audio files. This
is done by processing instances of AudioPlay objects in the feedMe method.
In the analogy, the AudioCallBack is a third party. As a "river
traffic controller", the AudioCallBack delivers the
boats to the river and controls whether they ride the river or dock
on the shore for a bit (by controlling the AudioPlay state, and
supervising when Mixing happens).
public class ACallBack implements AudioCallBack, sdl.event.EventListener
Let's assume a new AudioPlay object has been created within the callback
AudioPlay song = null; public ACallBack() { song=audio.loadAndConvertSDLAudio("magnum.wav"); } ... public void feedMe(int handle, int length, SDLAudio obj) { if ( song.getActive() ) { int position = song.getPosition(); int audioLen = song.getAudioData().getBufferSize(); if ( length < (audioLen - position) ) { length = audioLen - position; song.setActive(false); } SDLAudio.SDLMixAudio(handle, song.getAudioData().getBufferHandle(), position,length,64); song.setPosition(position+length); if ( song.getActive()==false ) { song.setPosition(0); } } }
To affect the AudioCallBack from outside its thread, we implemented ACallBack as an event listener. When it receives a keyboard event, it will "play" the song.
public boolean incomingEvents(SDLCustomEvent event) throws SDLEventException { if ( event instanceof SDLKeyboardEvent ) { SDLKeyboardEvent keyboard = (SDLKeyboardEvent)event if ( keyboard.getKey()==SDLKeyboardEvent.SDLK_p ) song.setActive(true); else song.setActive(false); } }
AudioPlay
,
SDLAudio
,
sdl.test.TestAudio
Method Summary | |
void |
feedMe(int handle,
int length,
SDLAudio obj)
|
Method Detail |
public void feedMe(int handle, int length, SDLAudio obj)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |