com.frinika.audio.voicetemplate
Class SynchronizedVoice

java.lang.Object
  extended by com.frinika.audio.Voice
      extended by com.frinika.audio.voicetemplate.SynchronizedVoice

public abstract class SynchronizedVoice
extends Voice

A voice 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
protected  VoiceServer voiceServer
           
 
Fields inherited from class com.frinika.audio.Voice
interrupts, nextVoice, startFramePos
 
Constructor Summary
SynchronizedVoice(VoiceServer voiceServer, long initialFramePos)
          Construct a new Synchronized Voice.
 
Method Summary
 void fillBuffer(int startBufferPos, int endBufferPos, float[] buffer)
          This is where the raw audio data should be produced.
abstract  void fillBufferSynchronized(int startBufferPos, int endBufferPos, float[] buffer)
           
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
 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
 

Field Detail

voiceServer

protected VoiceServer voiceServer
Constructor Detail

SynchronizedVoice

public SynchronizedVoice(VoiceServer voiceServer,
                         long initialFramePos)
Construct a new Synchronized Voice. 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:

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:

fillBuffer

public final void fillBuffer(int startBufferPos,
                             int endBufferPos,
                             float[] buffer)
Description copied from class: Voice
This is where the raw audio data should be produced. The passed in buffer contains the audio data from the previous voice in the chain, thus new data should just be added to the buffer. It's important to just fill within the start and stop positions, because this is how the interrupt functions control that parameter modification occur at the right place.

Specified by:
fillBuffer in class Voice

fillBufferSynchronized

public abstract void fillBufferSynchronized(int startBufferPos,
                                            int endBufferPos,
                                            float[] buffer)