jass.render
Class RTPlay

java.lang.Object
  extended by java.lang.Thread
      extended by jass.render.RTPlay
All Implemented Interfaces:
java.lang.Runnable

public class RTPlay
extends java.lang.Thread

Utility class for real-time audio play.

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
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
RTPlay(float srate, int nchannels, int buffersizeJass)
          Constructor.
RTPlay(float srate, int bitsPerFrame, int nchannels, boolean signed)
          Constructor.
RTPlay(float srate, int nchannels, int buffersizeJass, int numRtAudioBuffers)
          Constructor.
RTPlay(int buffersize, float srate, int bitsPerFrame, int nchannels, boolean signed)
          Constructor.
RTPlay(int buffersize, float srate, int bitsPerFrame, int nchannels, boolean signed, java.lang.String preferredMixer)
          Constructor.
 
Method Summary
 void close()
          Close line or native sound
 void closeNativeSound(long nativeObjectPointer)
          Close native sound This is a native method and needs librtaudio.so (LINUX) or rtaudio.dll (Windows)
 long initNativeSound(int nchannels, int srate, int buffersizeJASS, int nRtaudioBuffers)
          Initialize native sound using RtAudio, setting buffersize and an internal RtAudio buffersize
 void write(float[] y)
          Write audio buffer to output queue and block if queue is full.
 void writeNativeSoundFloat(long nativeObjectPointer, float[] buf, int buflen)
          write a buffer of floats to native sound.
 
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, run, 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
 

Constructor Detail

RTPlay

public RTPlay(int buffersize,
              float srate,
              int bitsPerFrame,
              int nchannels,
              boolean signed)
Constructor.

Parameters:
bufferSize - Buffer size used by JavaSound.
srate - sampling rate in Hertz.
bitsPerFrame - number of bits per audio frame.
nchannels - number of audio channels.
signed - true if signed format, false otherwise.

RTPlay

public RTPlay(int buffersize,
              float srate,
              int bitsPerFrame,
              int nchannels,
              boolean signed,
              java.lang.String preferredMixer)
Constructor. Chose preferred mixer by name

Parameters:
bufferSize - Buffer size used by JavaSound.
srate - sampling rate in Hertz.
bitsPerFrame - number of bits per audio frame.
nchannels - number of audio channels.
signed - true if signed format, false otherwise.
preferredMixer - preferred mixer as a name string

RTPlay

public RTPlay(float srate,
              int bitsPerFrame,
              int nchannels,
              boolean signed)
Constructor. Uses default high latency JavaSound buffer size.

Parameters:
srate - sampling rate in Hertz.
bitsPerFrame - number of bits per audio frame.
nchannels - number of audio channels.
signed - true if signed format, false otherwise.

RTPlay

public RTPlay(float srate,
              int nchannels,
              int buffersizeJass)
Constructor. Uses native audio write. Needs librtaudio.so (LINUX) or rtaudio.dll (Windows)

Parameters:
srate - sampling rate in Hertz.
nchannels - number of audio channels.
buffersizeJass - this will be the buffersize of RtAudio

RTPlay

public RTPlay(float srate,
              int nchannels,
              int buffersizeJass,
              int numRtAudioBuffers)
Constructor. Uses native audio write. Also specify RtAudio tweak parameter numberofbuffers used Needs librtaudio.so (LINUX) or rtaudio.dll (Windows)

Parameters:
srate - sampling rate in Hertz.
nchannels - number of audio channels.
buffersizeJass - jass buffersize (TODO fix name)
numRtAudioBuffers - number of rtaudio buffers (0 is lowest)
Method Detail

initNativeSound

public long initNativeSound(int nchannels,
                            int srate,
                            int buffersizeJASS,
                            int nRtaudioBuffers)
Initialize native sound using RtAudio, setting buffersize and an internal RtAudio buffersize

Parameters:
nchannels - number of audio channels.
srate - sampling rate in Hertz.
buffersizeJASS - buffers will be rendered in these chunks
nRtaudioBuffers - internal buffers, 0 = lowest possiblse
Returns:
long representing C++ object pointer

writeNativeSoundFloat

public void writeNativeSoundFloat(long nativeObjectPointer,
                                  float[] buf,
                                  int buflen)
write a buffer of floats to native sound. This is a native method and needs librtaudio.so (LINUX) or rtaudio.dll (Windows)

Parameters:
nativeObjectPointer - representing C++ object pointer.
buf - array of floats with sound buffer.
buflen - length of buffer.

closeNativeSound

public void closeNativeSound(long nativeObjectPointer)
Close native sound This is a native method and needs librtaudio.so (LINUX) or rtaudio.dll (Windows)

Parameters:
nativeObjectPointer - representing C++ object pointer

write

public void write(float[] y)
Write audio buffer to output queue and block if queue is full.

Parameters:
y - output buffer.

close

public void close()
Close line or native sound