jass.render
Class RTAudioFullDuplexRtAudio

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

public class RTAudioFullDuplexRtAudio
extends java.lang.Thread

Utility class to read/write audio in real-time using native libs from RtAudio C++ classes

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
RTAudioFullDuplexRtAudio(float srate, int nchannels, int buffersizeJASS, int numRtAudioBuffers)
          Constructor.
 
Method Summary
 void close()
           
 void closeNativeSound(long nativeObjectPointer)
          Close native sound This is a native method and needs librtaudio.so (LINUX) or rtaudio.dll (Windows) or whatever its called on MAC OSX
 long initNativeSound(int nchannels, int srate, int buffersizeJASS, int nRtaudioBuffers)
          Initialize native sound using RtAudio, setting buffersize and an internal RtAudio buffersize
 void read(float[] y, int nsamples)
          Read audio buffer from input queue and block if queue is empty.
 void write(float[] y)
          Write audio buffer to output queue and block if queue is full.
 void writeReadNativeSoundFloat(long nativeObjectPointer, float[] outbuf, int outbuflen, float[] readbuf, int readbuflen)
          write/read 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

RTAudioFullDuplexRtAudio

public RTAudioFullDuplexRtAudio(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
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

closeNativeSound

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

Parameters:
nativeObjectPointer - representing C++ object pointer

writeReadNativeSoundFloat

public void writeReadNativeSoundFloat(long nativeObjectPointer,
                                      float[] outbuf,
                                      int outbuflen,
                                      float[] readbuf,
                                      int readbuflen)
write/read 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.
outbuf - array of floats with sound buffer to be output to audio card
outbuflen - length of buffer.
readbuf - array of floats with sound buffer to be read from audio input
readbuflen - length of read buffer.

read

public void read(float[] y,
                 int nsamples)
Read audio buffer from input queue and block if queue is empty.

Parameters:
y - buffer to write to.
nsamples - number of samples required.

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()