com.frinika.voiceserver
Class VoiceServer

java.lang.Object
  extended by com.frinika.voiceserver.VoiceServer
Direct Known Subclasses:
JavaSoundVoiceServer, PJVoiceServer

public abstract class VoiceServer
extends java.lang.Object

The VoiceServer terminates the audio output of all voices, by polling them sequentially for small buffers of data. The buffer size also determines the latency of the server, thus also for all the VoiceGenerators (softsynths) it is hosting. The VoiceServer is an abstract class which should be extended and integrated with a sound hardware interface. The voiceserver however provides all functionality needed for timing and synchronization of the voice generators. The VoiceServer has a realtime and a non-realtime mode. Realtime mode is used when playing live - and timing mechanisms has to be accurate. Non realtime mode is used when creating a rendered version of a sequence of sound. For example when exporting a song to a wav file. Routing mechanisms are available using Voice.nextVoice

Author:
Peter Johan Salomonsen PJL - changed call to FrinikaConfig.getOSLatency() to FrinikaAUdioSYstem.getOutputLatency()

Field Summary
protected  java.util.Vector<Voice> audioOutputGenerators
           
 
Constructor Summary
VoiceServer()
           
 
Method Summary
 void addTransmitter(Voice transmitter)
          Used by synths to add a new generator (midi note)
abstract  void configureAudioOutput(javax.swing.JFrame frame)
           
 int getBufferSize()
           
 long getLatency()
          Returns the latency in microseconds
 int getLatencyAsFrames()
          Returns the latency in frames
 int getSampleRate()
          Returns the current sample rate
 long getTotalLatency()
          Returns the voiceServer latency plus the operating system latency in microseconds
 int getTotalLatencyAsFrames()
          Returns the total latency in frames
 void interruptTransmitter(Voice transmitter, VoiceInterrupt interrupt)
          Used by synths to trigger a change in an existing generator.
 void processFinalOutput(float[] buffer)
          Override this method to add processing to the final output
 void read(byte[] outBuffer, float[] floatBuffer)
          Read a frame into the given buffers of bytes, and floats
 void read(float[] floatBuffer)
          Read a frame into the given buffer of floats
 void readNonRealtime(byte[] outBuffer, float[] floatBuffer)
          Read a frame into the given buffers of bytes, and floats.
 void realtimeOff()
           
 void realtimeOn()
           
 void removeTransmitter(Voice transmitter)
          Called by the generator itself when it knows that it has finished its processing.
 void setSampleRate(int sampleRate)
          Change current sample rate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

audioOutputGenerators

protected java.util.Vector<Voice> audioOutputGenerators
Constructor Detail

VoiceServer

public VoiceServer()
Method Detail

getSampleRate

public final int getSampleRate()
Returns the current sample rate

Returns:
samplerate

setSampleRate

public final void setSampleRate(int sampleRate)
Change current sample rate

Parameters:
sampleRate -

getBufferSize

public final int getBufferSize()
Returns:
Returns the bufferSize in number of frames

addTransmitter

public final void addTransmitter(Voice transmitter)
Used by synths to add a new generator (midi note)

Parameters:
transmitter - - the generator to add

interruptTransmitter

public final void interruptTransmitter(Voice transmitter,
                                       VoiceInterrupt interrupt)
Used by synths to trigger a change in an existing generator. Ie. a release of a midi note.

Parameters:
transmitter -
interrupt -

removeTransmitter

public final void removeTransmitter(Voice transmitter)
Called by the generator itself when it knows that it has finished its processing.

Parameters:
transmitter -

processFinalOutput

public void processFinalOutput(float[] buffer)
Override this method to add processing to the final output

Parameters:
buffer -

read

public final void read(float[] floatBuffer)
Read a frame into the given buffer of floats

Parameters:
floatBuffer -

read

public final void read(byte[] outBuffer,
                       float[] floatBuffer)
Read a frame into the given buffers of bytes, and floats

Parameters:
outBuffer -
floatBuffer -

readNonRealtime

public final void readNonRealtime(byte[] outBuffer,
                                  float[] floatBuffer)
Read a frame into the given buffers of bytes, and floats. Used in non realtime mode i.e. when exporting audio to a file.

Parameters:
outBuffer -
floatBuffer -

realtimeOn

public final void realtimeOn()

realtimeOff

public final void realtimeOff()

configureAudioOutput

public abstract void configureAudioOutput(javax.swing.JFrame frame)

getLatency

public final long getLatency()
Returns the latency in microseconds

Returns:

getLatencyAsFrames

public final int getLatencyAsFrames()
Returns the latency in frames

Returns:

getTotalLatency

public final long getTotalLatency()
Returns the voiceServer latency plus the operating system latency in microseconds

Returns:

getTotalLatencyAsFrames

public final int getTotalLatencyAsFrames()
Returns the total latency in frames

Returns: