micromod
Class InstrumentPlayer

java.lang.Object
  extended bymicromod.InstrumentPlayer

public class InstrumentPlayer
extends java.lang.Object

InstrumentPlayer 0.5 This class is designed to play a ProTracker style instrument at the specified pitch The output of an object of this class has any instrument-related effects applied. This class supports resamplers with "cushion" sizes up to 16 points.


Field Summary
protected static int CUSHION_BUFFER_SAMPLES
           
protected  short[] cushionBuffer
           
protected static int FIXED_POINT_BITMASK
           
static int FIXED_POINT_SHIFT
           
protected  LoopDecoder loopDecoder
           
protected static int RESAMPLE_BUFFER_SAMPLES
           
protected  short[] resampleBuffer
           
protected  int resampleFactor
           
protected  int subSamplePos
           
 
Constructor Summary
InstrumentPlayer()
           
 
Method Summary
 void assignInstrument(Instrument i)
          Assign an Instrument to be played.
protected  void blankCushionBuffer()
          Zero the contents of the cushion buffer.
 void getAudio(short[] buffer, int length, Resampler resampler, boolean snapBack)
          Get the required amount of audio for resampling, and resample it into the specified buffer.
 Instrument getInstrument()
          Get the current instrument
 int getSamplePosition()
           
protected  int getSamplesRequired(int length)
           
 boolean hasFinished()
           
 void setAssigned()
           
 void setResampleFactor(int resampleFactor)
          Set the number of input samples per output sample produced in the getAudio() method.
 void setSamplePosition(int samplePosition)
          Explicitly set the sample position of playback.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FIXED_POINT_SHIFT

public static final int FIXED_POINT_SHIFT
See Also:
Constant Field Values

FIXED_POINT_BITMASK

protected static final int FIXED_POINT_BITMASK
See Also:
Constant Field Values

CUSHION_BUFFER_SAMPLES

protected static final int CUSHION_BUFFER_SAMPLES
See Also:
Constant Field Values

RESAMPLE_BUFFER_SAMPLES

protected static final int RESAMPLE_BUFFER_SAMPLES
See Also:
Constant Field Values

resampleFactor

protected int resampleFactor

subSamplePos

protected int subSamplePos

resampleBuffer

protected short[] resampleBuffer

cushionBuffer

protected short[] cushionBuffer

loopDecoder

protected LoopDecoder loopDecoder
Constructor Detail

InstrumentPlayer

public InstrumentPlayer()
Method Detail

assignInstrument

public void assignInstrument(Instrument i)
Assign an Instrument to be played. Under some circumstances the assigned Instrument will begin to play.


setAssigned

public void setAssigned()

getInstrument

public Instrument getInstrument()
Get the current instrument


setSamplePosition

public void setSamplePosition(int samplePosition)
Explicitly set the sample position of playback. Protracker has an effect command to do this.


getSamplePosition

public int getSamplePosition()
Returns:
the current sample position.

hasFinished

public boolean hasFinished()
Returns:
whether or not the Instrument has finished playing.

setResampleFactor

public void setResampleFactor(int resampleFactor)
Set the number of input samples per output sample produced in the getAudio() method. A higher value results in a higher pitch. The value is in 16 bit fixed point format, with 65536 representing 1 input sample per output sample.


getAudio

public void getAudio(short[] buffer,
                     int length,
                     Resampler resampler,
                     boolean snapBack)
Get the required amount of audio for resampling, and resample it into the specified buffer.


getSamplesRequired

protected int getSamplesRequired(int length)
Returns:
the integer number of input samples required to provied length samples of output, using the most basic "nearest" algorithm. Unless the resampler requires precisely an integer number of input samples, an extra sample will be required at the end. This sample will be needed by the resampler again when resampling the next segment, so you should always tack on an extra sample that is duplicated at the start of the next invocation. This is what snapBack is for.

blankCushionBuffer

protected void blankCushionBuffer()
Zero the contents of the cushion buffer. Use when the contents of the buffer are no longer valid.