sdl.audio
Class SDLAudio

java.lang.Object
  |
  +--sdl.audio.SDLAudio

public class SDLAudio
extends java.lang.Object

SDLAudio is the primary binding for the SDL Audio subsystem. This class manages all the audio played by SDL. It is responsible for

Using SDLAudio

In a typical application, the user instantiates a SDLAudio object and registers a callback with it. An SDLAudioCallback is an interruptable piece of code does the actual management of the individual audio samples. In JSDL, callbacks are implemented as AudioCallBack objects which contain this code in the method feedMe(). Users always need to have a callback method written which mixes their audio data and puts it in the audio stream

Step 1. Instantiation and CallBack registration

      SDLAudio audio = new SDLAudio();
      audio.registerAudioCallBack(aCallback);
 

Step 2. Opening the audio device
Next the user will define the type of audio to be played on the audio device, and open the device.

      SDLAudioSpec spec = new SDLAudioSpec(
      		44100,(short)SDLAudio.AUDIO_S16,
      		(byte)2,(byte)0,(short)4096,0);
      audio.setDesiredAudioSpec(spec);
      audio.openDevice();
 

Step 3. Optional initialization stuff
Now we will do some initialization stuff if we want. Here, the callback is loading and audio file.

 	// code in AudioCallBack object's (aCallBack) initialization part 
      AudioPlay playable1 = audio.loadAndConvertSDLAudio("song1.wav");
 

Step 4. Start ("unpause") the audio playblack
Once the extra initialization stuff is finished, we allow the callback to play the audio stream by "un-pausing" the audio (ie. starting the audio). The audio won't actually start playing until the user calls pauseAudio(false), allowing him to perform other audio initialization as needed before his callback function is run. After the user is done using the sound output, he should close it with the closeAudio() method.

      audio.pauseAudio(false); //start Sound
 

At this point the user may choose to sleep and allow the AudioCallBack thread to play the streams

See Also:
AudioCallBack, AudioPlay

Field Summary
static int AUDIO_S16
           
static int AUDIO_S16LSB
           
static int AUDIO_S16MSB
           
static int AUDIO_S8
           
static int AUDIO_U16
           
static int AUDIO_U16LSB
           
static int AUDIO_U16MSB
           
static int AUDIO_U8
           
 
Constructor Summary
SDLAudio()
           
 
Method Summary
 void audioCallBack(int handle, int length)
           
 void closeDevice()
           
 SDLAudioSpec getObtainedAudioSpec()
           
 AudioPlay loadAndConvertSDLAudio(java.lang.String fileName)
          Encapsulates the functionality of the native methods SDL_LoadWAV and SDL_ConvertAudio.
 void openDevice()
           
 void pauseAudio(boolean b)
          Starts and stops the audio playback done by the AudioCallbacks.
 boolean registerAudioCallBack(AudioCallBack e)
           
static void SDLMixAudio(int handleAudio, int handleBuffer, int offset, int length, int volume)
           
 void setDesiredAudioSpec(SDLAudioSpec spec)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AUDIO_U8

public static final int AUDIO_U8
See Also:
Constant Field Values

AUDIO_S8

public static final int AUDIO_S8
See Also:
Constant Field Values

AUDIO_U16LSB

public static final int AUDIO_U16LSB
See Also:
Constant Field Values

AUDIO_S16LSB

public static final int AUDIO_S16LSB
See Also:
Constant Field Values

AUDIO_U16MSB

public static final int AUDIO_U16MSB
See Also:
Constant Field Values

AUDIO_S16MSB

public static final int AUDIO_S16MSB
See Also:
Constant Field Values

AUDIO_U16

public static final int AUDIO_U16
See Also:
Constant Field Values

AUDIO_S16

public static final int AUDIO_S16
See Also:
Constant Field Values
Constructor Detail

SDLAudio

public SDLAudio()
Method Detail

openDevice

public void openDevice()

setDesiredAudioSpec

public void setDesiredAudioSpec(SDLAudioSpec spec)

getObtainedAudioSpec

public SDLAudioSpec getObtainedAudioSpec()

pauseAudio

public void pauseAudio(boolean b)
Starts and stops the audio playback done by the AudioCallbacks. When SDLAudio is instantiated, the pauseAudio state is true. pauseAudio(false) starts playback.


closeDevice

public void closeDevice()

loadAndConvertSDLAudio

public AudioPlay loadAndConvertSDLAudio(java.lang.String fileName)
Encapsulates the functionality of the native methods SDL_LoadWAV and SDL_ConvertAudio. SDL provides a single sound loading routine for your convenience, SDL_LoadWAV(). After you load your sounds, you should convert them to the audio format of the sound output using SDL_ConvertAudio(), and make them available to your mixing function.


registerAudioCallBack

public boolean registerAudioCallBack(AudioCallBack e)

audioCallBack

public void audioCallBack(int handle,
                          int length)

SDLMixAudio

public static void SDLMixAudio(int handleAudio,
                               int handleBuffer,
                               int offset,
                               int length,
                               int volume)