uk.org.toot.audio.server
Class TimedAudioServer

java.lang.Object
  extended by uk.org.toot.audio.server.AbstractAudioServer
      extended by uk.org.toot.audio.server.TimedAudioServer
All Implemented Interfaces:
java.lang.Runnable, uk.org.toot.audio.server.AudioServer, ExtendedAudioServer
Direct Known Subclasses:
PriorityAudioServer

public abstract class TimedAudioServer
extends AbstractAudioServer
implements java.lang.Runnable, ExtendedAudioServer

TimedAudioServer extends AbstractAudioServer to control the timing of an AudioClient. The buffer size, latency and timing strategy may be varied while running. Note that changing latency may cause inputs to glitch.


Field Summary
protected  boolean hasStopped
           
protected  boolean isRunning
           
protected  float maximumLatencyMilliseconds
           
protected  int stableCount
           
protected  int stableThreshold
           
protected  boolean started
           
protected  AudioSyncLine syncLine
           
 
Fields inherited from class uk.org.toot.audio.server.AbstractAudioServer
bufferFrames, endTimeNanos, startTimeNanos
 
Fields inherited from interface uk.org.toot.audio.server.AudioServer
THREAD_NAME
 
Constructor Summary
TimedAudioServer()
           
 
Method Summary
protected  int calculateBufferFrames()
           
protected  boolean canStart()
           
protected  void controlGained()
          Called when the control loop gains control.
 float getActualLatencyMilliseconds()
          Return the actual instantaneous software output latency in milliseconds.
 float getBufferMilliseconds()
          Return the duration of the buffers in milliseconds.
 int getBufferUnderRuns()
          Return the number of buffer underruns which may have resulted in an audio glitch.
 float getLatencyMilliseconds()
          Return the requested software output latency in milliseconds.
 float getLowestLatencyMilliseconds()
          Because latency is measured just after writing a buffer and represents the maximum latency, the lowest latency has to be compensated by the duration of the buffer.
 float getMaximumLatencyMilliseconds()
          Return the maximum software output latency which may be requested.
 float getMinimumLatencyMilliseconds()
          Return the minimum software output latency which may be requested.
 int getTotalLatencyFrames()
          Return the total latency from analogue input to analogue output.
 boolean isRunning()
           
protected  void reset()
           
 void resetMetrics(boolean resetUnderruns)
           
 void run()
           
 void setBufferMilliseconds(float ms)
          Set the duration of the buffers in milliseconds.
 void setLatencyMilliseconds(float ms)
          Set the software output latency request in milliseconds.
protected  void startImpl()
           
protected  void stopImpl()
           
protected  void sync()
          Called synchronously with the server to simplify concurrency issues.
 
Methods inherited from class uk.org.toot.audio.server.AbstractAudioServer
_createAudioBuffer, checkStart, createAudioBuffer, getBufferFrames, getLoad, removeAudioBuffer, resizeBuffers, setClient, start, stop, work
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface uk.org.toot.audio.server.ExtendedAudioServer
getConfigKey, getInputs, getOutputs, getSampleSizeInBits
 
Methods inherited from interface uk.org.toot.audio.server.AudioServer
closeAudioInput, closeAudioOutput, createAudioBuffer, getAvailableInputNames, getAvailableOutputNames, getInputLatencyFrames, getLoad, getOutputLatencyFrames, getSampleRate, openAudioInput, openAudioOutput, setClient, start, stop
 

Field Detail

isRunning

protected boolean isRunning

hasStopped

protected boolean hasStopped

maximumLatencyMilliseconds

protected float maximumLatencyMilliseconds

syncLine

protected AudioSyncLine syncLine

started

protected boolean started

stableCount

protected int stableCount

stableThreshold

protected int stableThreshold
Constructor Detail

TimedAudioServer

public TimedAudioServer()
Method Detail

canStart

protected boolean canStart()
Overrides:
canStart in class AbstractAudioServer

startImpl

protected void startImpl()
Specified by:
startImpl in class AbstractAudioServer

stopImpl

protected void stopImpl()
Specified by:
stopImpl in class AbstractAudioServer

isRunning

public boolean isRunning()
Specified by:
isRunning in interface uk.org.toot.audio.server.AudioServer

getTotalLatencyFrames

public int getTotalLatencyFrames()
Return the total latency from analogue input to analogue output.

Specified by:
getTotalLatencyFrames in interface uk.org.toot.audio.server.AudioServer

run

public void run()
Specified by:
run in interface java.lang.Runnable

sync

protected void sync()
Called synchronously with the server to simplify concurrency issues.


controlGained

protected void controlGained()
Called when the control loop gains control.


resetMetrics

public void resetMetrics(boolean resetUnderruns)
Specified by:
resetMetrics in interface ExtendedAudioServer

reset

protected void reset()

setLatencyMilliseconds

public void setLatencyMilliseconds(float ms)
Set the software output latency request in milliseconds. This is the demand to the control loop.

Specified by:
setLatencyMilliseconds in interface ExtendedAudioServer

getLatencyMilliseconds

public float getLatencyMilliseconds()
Return the requested software output latency in milliseconds.

Specified by:
getLatencyMilliseconds in interface ExtendedAudioServer

getActualLatencyMilliseconds

public float getActualLatencyMilliseconds()
Return the actual instantaneous software output latency in milliseconds. This is the controlled amount which will diverge from the requested amount due to instantaneous control error caused by timing jitter.

Specified by:
getActualLatencyMilliseconds in interface ExtendedAudioServer

getLowestLatencyMilliseconds

public float getLowestLatencyMilliseconds()
Because latency is measured just after writing a buffer and represents the maximum latency, the lowest latency has to be compensated by the duration of the buffer. This might not be the best place to do the compensation but it is the cheapest. While bufferMilliseconds is effectively immutable it's ok.

Specified by:
getLowestLatencyMilliseconds in interface ExtendedAudioServer

getMinimumLatencyMilliseconds

public float getMinimumLatencyMilliseconds()
Return the minimum software output latency which may be requested.

Specified by:
getMinimumLatencyMilliseconds in interface ExtendedAudioServer

getMaximumLatencyMilliseconds

public float getMaximumLatencyMilliseconds()
Return the maximum software output latency which may be requested.

Specified by:
getMaximumLatencyMilliseconds in interface ExtendedAudioServer

getBufferUnderRuns

public int getBufferUnderRuns()
Return the number of buffer underruns which may have resulted in an audio glitch.

Specified by:
getBufferUnderRuns in interface ExtendedAudioServer

calculateBufferFrames

protected int calculateBufferFrames()

getBufferMilliseconds

public float getBufferMilliseconds()
Return the duration of the buffers in milliseconds.

Specified by:
getBufferMilliseconds in interface ExtendedAudioServer

setBufferMilliseconds

public void setBufferMilliseconds(float ms)
Set the duration of the buffers in milliseconds.

Specified by:
setBufferMilliseconds in interface ExtendedAudioServer