com.frinika.audio.toot
Class SynchronizedAudioProcess

java.lang.Object
  extended by com.frinika.audio.toot.SynchronizedAudioProcess
All Implemented Interfaces:
uk.org.toot.audio.core.AudioProcess
Direct Known Subclasses:
AudioStreamVoice

public abstract class SynchronizedAudioProcess
extends java.lang.Object
implements uk.org.toot.audio.core.AudioProcess

An audioprocess that can be synchronized from an outside timing source. Useful for e.g. audio playback to be synchronized with a sequencer.

Author:
Peter Johan Salomonsen

Field Summary
 
Fields inherited from interface uk.org.toot.audio.core.AudioProcess
AUDIO_DISCONNECT, AUDIO_OK
 
Constructor Summary
SynchronizedAudioProcess(uk.org.toot.audio.server.AudioServer audioServer, long initialFramePos)
          Construct a new Synchronized audioProcess.
 
Method Summary
protected  long getFramePos()
          Call this method from fillBufferSynchronized to get the framePos according to the external timing source
protected  int getMissedFrames()
          Call this method from fillBufferSynchronized to get the number of missing frames (glitch) after an external sync notification NOTE: Your tolerance on missed frames should not be too low - since timing functions like System.currentTimeMillis might slide up to 50 ms on some systems.
 int getMissedFramesToleranceMillis()
          Number of milliseconds of glitch before synchronization if enforced
 int processAudio(uk.org.toot.audio.core.AudioBuffer buffer)
           
abstract  void processAudioSynchronized(uk.org.toot.audio.core.AudioBuffer buffer)
           
 void setFramePos(long framePos)
          The external timing source should regularly notify with the current frame position here
 void setMissedFramesToleranceMillis(int missedFramesToleranceMillis)
          Set number of milliseconds of glitch before synchronization if enforced
 
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.core.AudioProcess
close, open
 

Constructor Detail

SynchronizedAudioProcess

public SynchronizedAudioProcess(uk.org.toot.audio.server.AudioServer audioServer,
                                long initialFramePos)
Construct a new Synchronized audioProcess. Note that in order for the initialFramePos to be valid, this voice should be added to the voiceServer not too long after it's constructed Since glitches may "come and go" due to the missing accuracy in Java timing functions, synchronization is not applied until a tolerance threshold is exceeded.

Parameters:
voiceServer -
initialFramePos - - the initial position of playback start - relative to audio clip start
Method Detail

getMissedFramesToleranceMillis

public int getMissedFramesToleranceMillis()
Number of milliseconds of glitch before synchronization if enforced


setMissedFramesToleranceMillis

public void setMissedFramesToleranceMillis(int missedFramesToleranceMillis)
Set number of milliseconds of glitch before synchronization if enforced

Parameters:
missedFramesToleranceMillis -

setFramePos

public void setFramePos(long framePos)
The external timing source should regularly notify with the current frame position here

Parameters:
framePos -

getFramePos

protected final long getFramePos()
Call this method from fillBufferSynchronized to get the framePos according to the external timing source

Returns:
the current frame postion.

getMissedFrames

protected final int getMissedFrames()
Call this method from fillBufferSynchronized to get the number of missing frames (glitch) after an external sync notification NOTE: Your tolerance on missed frames should not be too low - since timing functions like System.currentTimeMillis might slide up to 50 ms on some systems. Your number of missed frames tolerance should be thereafter before correcting your framepos.

Returns:

processAudio

public int processAudio(uk.org.toot.audio.core.AudioBuffer buffer)
Specified by:
processAudio in interface uk.org.toot.audio.core.AudioProcess

processAudioSynchronized

public abstract void processAudioSynchronized(uk.org.toot.audio.core.AudioBuffer buffer)