jass.render
Class SourcePlayer

java.lang.Object
  extended by java.lang.Thread
      extended by jass.engine.In
          extended by jass.render.SourcePlayer
All Implemented Interfaces:
Sink, java.lang.Runnable

public class SourcePlayer
extends In

Renders Sources to audio card using JavaSound or native methods, or out to file. To write to file manually call advanceTime(), see renderToFile example. Can't add rendered objects after starting it.

Author:
Kees van den Doel (kvdoel@cs.ubc.ca)

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
protected  boolean pushIsInitialized
          Push a buffer out if you want to manually "render" sound
 
Fields inherited from class jass.engine.In
sourceContainer
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
SourcePlayer(int bufferSize, float srate)
          Create Source Player intended to real-time audio output.
SourcePlayer(int bufferSize, float srate, java.lang.String fn)
          Create Source Player intended for audio-file output.
SourcePlayer(int bufferSize, int bufferSizeJavaSound, float srate)
          Create Source Player intended to real-time audio output.
SourcePlayer(int bufferSize, int bufferSizeJavaSound, float srate, Source src)
          Create Source Player intended to real-time audio output.
SourcePlayer(int bufferSize, int bufferSizeJavaSound, float srate, java.lang.String preferredMixer)
          Create Source Player intended to real-time audio output.
 
Method Summary
 void advanceTime(double realTime)
          Advance time and process audio till then.
 void advanceTime(double realTime, boolean ascii)
          Advance time and process audio till then.
 void AGCOff()
          Disable AGC
 void AGCOn()
          Enable AGC
 void cleanupASIO()
          Shut down the ASIO libraries.
 void closeASIO()
          Stop the ASIO streaming process and clean up.
 float getAGC()
          Get value used by AGC.
 java.lang.String getAudioAPI()
          Get method for audioAPI string
 int getInputChannelNum()
          Get method for returning the selected output channel for ASIO
 boolean getMute()
          Get Mute/unmute state
 void getNextBuffer(short[] myData)
          Retrieve the next available audio buffer.
 int getNumRtAudioBuffersNative()
          Get RtAudio latency parameter if using native sound.
 int getOutputChannelNum()
          Get method for output channel number.
 RTAudioFullDuplexRtAudio getRTAudioFullDuplexRtAudio()
          Get render object when using full duplex with RtAudio native libs Needs rtaudio.dll or librtaudio.so and works on Windows/LINUX/MAXOSX only.
 boolean getUseNativeSound()
          Get method for useNativeSound flag
 boolean getUseNativeSoundFullDuplex()
          Get method for useNativeSoundFullDuplex flag
 float getVolume()
          Get volume (used if ACG is off)
 void initASIO()
          Initialize the ASIO system and start it up.
 int initAsioJass(int srate, int bufferSize, int outputchannelNum, int inputchannelNum, AudioIn myInput)
          Initialize the ASIO libraries this is done in JassASIO.dll The system will begin running once the initialization has occurred The buffers will be retrieved from the getNextBuffer(short[]) method
protected  void initPush()
           
 void push(float[] buf)
           
 void resetAGC()
          Reset AGC state
 void run()
          Start thread which obtains buffers form sources and writes to audio out.
 void setAGC(float maxSignal)
          Set AGC maximum signal seen.
 void setASIOInput(AudioIn commingIn)
          Set this AudioIn object so that we can use ASIO input.
 void setInputChannelNum(int channel)
          Set method for Input channel Number
 void setMute(boolean muted)
          Set mute/unmute
 void setNChannels(int n)
          set nchannels 1 for mone 2 for stereo
 void setNumRtAudioBuffersNative(int numRtAudioBuffers)
          Set RtAudio latency parameter if using native sound.
 void setOutputChannelNum(int channel)
          Set method for output channel Number
 void setUseNativeSound(boolean value)
          Set method to make it use/not use RtAudio based native sound.
 void setUseNativeSound(boolean value, java.lang.String audioAPI)
          Determine the use of Native Methods, either ASIO (needs JassASIO.dll) or something else (will be chosen later at run time depending on which shared library is found: rtaudio.dll (ASIO or DX version) or librtaudio.so (OSS or ALSA version).
 void setUseNativeSoundFullDuplex(boolean value)
          Set method to make it use RtAudio based native sound with full duplex Needs rtaudio.dll or librtaudio.so and works on Windows/LINUX/MAX OSX only.
 void setVolume(float v)
          Set volume (if ACG is off)
 void stopPlaying()
          Call to stop player
 void stopPushing()
           
 
Methods inherited from class jass.engine.In
addSource, getSources, removeSource
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

pushIsInitialized

protected boolean pushIsInitialized
Push a buffer out if you want to manually "render" sound

Constructor Detail

SourcePlayer

public SourcePlayer(int bufferSize,
                    int bufferSizeJavaSound,
                    float srate)
Create Source Player intended to real-time audio output.

Parameters:
bufferSize - Buffersize used for blocks in filter graph
bufferSizeJavaSound - buffer size used by Java Sound. Use 0 for default.
srate - sampling rate in Hz

SourcePlayer

public SourcePlayer(int bufferSize,
                    float srate)
Create Source Player intended to real-time audio output. Will use default for JavaSound buffersize.

Parameters:
bufferSize - Buffersize used for blocks in filter graph
srate - sampling rate in Hz

SourcePlayer

public SourcePlayer(int bufferSize,
                    int bufferSizeJavaSound,
                    float srate,
                    java.lang.String preferredMixer)
Create Source Player intended to real-time audio output. Chose a preferred Mixer. If not found will get line from AudioSystem.

Parameters:
bufferSize - Buffersize used for blocks in filter graph
bufferSizeJavaSound - buffer size used by Java Sound. Use 0 for default.
srate - sampling rate in Hz
preferredMixer - preferred Mixer (e.g., "Esd Mixer").

SourcePlayer

public SourcePlayer(int bufferSize,
                    int bufferSizeJavaSound,
                    float srate,
                    Source src)
             throws SinkIsFullException
Create Source Player intended to real-time audio output.

Parameters:
bufferSize - Buffersize used for blocks in filter graph
bufferSizeJavaSound - buffer size used by Java Sound. Use 0 for default.
srate - sampling rate in Hz
src - Source to play.
Throws:
SinkIsFullException

SourcePlayer

public SourcePlayer(int bufferSize,
                    float srate,
                    java.lang.String fn)
Create Source Player intended for audio-file output. Will create raw audio file, or ascii data depending on which advanceTime() call is made.

Parameters:
bufferSize - Buffersize used for blocks in filter graph
srate - sampling rate in Hz
fn - file name for raw audio data
Method Detail

initAsioJass

public int initAsioJass(int srate,
                        int bufferSize,
                        int outputchannelNum,
                        int inputchannelNum,
                        AudioIn myInput)
Initialize the ASIO libraries this is done in JassASIO.dll The system will begin running once the initialization has occurred The buffers will be retrieved from the getNextBuffer(short[]) method

Parameters:
srate - is the smapling rate
bufferSize - is the size of the output buffer to be used in ASIO
outputchannelNum - selects the output channels
inputchannelNum - select the input channel (if desired)
myInput - is used to give access to an input device if ASIO input-output is desired

cleanupASIO

public void cleanupASIO()
Shut down the ASIO libraries. This call will disconnect the ASIO and stop its execution.


setASIOInput

public void setASIOInput(AudioIn commingIn)
Set this AudioIn object so that we can use ASIO input. Input must be handled here if using ASIO as it provides only one ASIO conncection.

Parameters:
commingIn - audio input through ASIO

setUseNativeSound

public void setUseNativeSound(boolean value,
                              java.lang.String audioAPI)
Determine the use of Native Methods, either ASIO (needs JassASIO.dll) or something else (will be chosen later at run time depending on which shared library is found: rtaudio.dll (ASIO or DX version) or librtaudio.so (OSS or ALSA version).

Parameters:
value - - true to use native methods, false otherwise
audioAPI - - either "something", or "ASIO".

getRTAudioFullDuplexRtAudio

public RTAudioFullDuplexRtAudio getRTAudioFullDuplexRtAudio()
Get render object when using full duplex with RtAudio native libs Needs rtaudio.dll or librtaudio.so and works on Windows/LINUX/MAXOSX only.

Returns:
i/o object

setUseNativeSound

public void setUseNativeSound(boolean value)
Set method to make it use/not use RtAudio based native sound. Needs rtaudio.dll or librtaudio.so and works on Windows/LINUX only.

Parameters:
value - value

setUseNativeSoundFullDuplex

public void setUseNativeSoundFullDuplex(boolean value)
Set method to make it use RtAudio based native sound with full duplex Needs rtaudio.dll or librtaudio.so and works on Windows/LINUX/MAX OSX only.

Parameters:
value - value

getOutputChannelNum

public int getOutputChannelNum()
Get method for output channel number. This selects the output channel number. Refer to sound card driver documentation to decide which channel to output through. Once ASIO has started the selected channel and the next greatest one will be used for output. On the SoundBlaster Audigy the left speaker chennel is number 6 therefore the output will be on channel 6 and 7 (7 is the right channel). This convention assumes that the two sides of a stereo convention will be consecutive channels in the driver.

Returns:
channel number

setOutputChannelNum

public void setOutputChannelNum(int channel)
Set method for output channel Number

Parameters:
channel - - the selected channel. Output will be done through the selected channel and the chennel at the next largest location. This will create matched stereo sound.
channel - the channel to use

getInputChannelNum

public int getInputChannelNum()
Get method for returning the selected output channel for ASIO

Returns:
int input channel number

setInputChannelNum

public void setInputChannelNum(int channel)
Set method for Input channel Number

Parameters:
channel - - the desired Input channel. This must be set before the InitASIO method is called

getUseNativeSound

public boolean getUseNativeSound()
Get method for useNativeSound flag

Returns:
true is using native sound

getUseNativeSoundFullDuplex

public boolean getUseNativeSoundFullDuplex()
Get method for useNativeSoundFullDuplex flag

Returns:
true is using native sound full duplex

getAudioAPI

public java.lang.String getAudioAPI()
Get method for audioAPI string

Returns:
string indicating which native audio API used

setNumRtAudioBuffersNative

public void setNumRtAudioBuffersNative(int numRtAudioBuffers)
Set RtAudio latency parameter if using native sound.

Parameters:
numRtAudioBuffer - rtaudio parameter influences latency. 0 will choose minimum

getNumRtAudioBuffersNative

public int getNumRtAudioBuffersNative()
Get RtAudio latency parameter if using native sound.

Returns:
rtaudio parameter influences latency. 0 will choose minimum

setNChannels

public void setNChannels(int n)
set nchannels 1 for mone 2 for stereo

Parameters:
n - # channels

setMute

public void setMute(boolean muted)
Set mute/unmute

Parameters:
muted - false if unmute, true if mute

getMute

public boolean getMute()
Get Mute/unmute state

Returns:
muted false if unmuted, true if muted

getAGC

public float getAGC()
Get value used by AGC.

Returns:
maximum signal value used by AGC

setAGC

public void setAGC(float maxSignal)
Set AGC maximum signal seen.

Parameters:
maxSignal - maximum value of signal seen.

resetAGC

public void resetAGC()
Reset AGC state


setVolume

public void setVolume(float v)
Set volume (if ACG is off)


getVolume

public float getVolume()
Get volume (used if ACG is off)

Parameters:
v - volume (scales the output)

AGCOn

public void AGCOn()
Enable AGC


AGCOff

public void AGCOff()
Disable AGC


advanceTime

public void advanceTime(double realTime)
                 throws BufferNotAvailableException,
                        java.io.IOException
Advance time and process audio till then. This writes raw data suitable for playback as raw audio (16-bit mono ).

Parameters:
realTime - real-time in seconds.
Throws:
BufferNotAvailableException
java.io.IOException

advanceTime

public void advanceTime(double realTime,
                        boolean ascii)
                 throws BufferNotAvailableException,
                        java.io.IOException
Advance time and process audio till then. This writes ascii data, one sample per line.

Parameters:
realTime - real-time in seconds.
Throws:
BufferNotAvailableException
java.io.IOException

getNextBuffer

public void getNextBuffer(short[] myData)
                   throws BufferNotAvailableException
Retrieve the next available audio buffer.

Parameters:
myData - an array to be filled with the data elements
Throws:
BufferNotAvailableException

stopPlaying

public void stopPlaying()
Call to stop player


run

public void run()
Start thread which obtains buffers form sources and writes to audio out.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

initASIO

public void initASIO()
Initialize the ASIO system and start it up. This must be done through JassAsio.dll. Once this method is called the ASIO streaming proccess will begin and the getNextBuffer(short[]) method will be called when new buffers are required for output.


closeASIO

public void closeASIO()
Stop the ASIO streaming process and clean up. This must be done through JassAsio.dll. Call this method asynchronously to stop the ASIO streaming process. Once the streaming has stopped the ASIO connection will be destructed. To reconnect call initASIO().


stopPushing

public void stopPushing()

initPush

protected void initPush()

push

public void push(float[] buf)