micromod.resamplers
Class FIRResampler

java.lang.Object
  extended bymicromod.resamplers.FIRResampler
All Implemented Interfaces:
Resampler

public class FIRResampler
extends java.lang.Object
implements Resampler

Table based multipoint FIR resampler. This took many, many hours to debug! Note to self: No more 12-hour sleep ins.


Field Summary
protected static int FIXED_POINT_BITMASK
           
protected static int FIXED_POINT_CONV
           
protected static int FIXED_POINT_ONE
           
protected static int FIXED_POINT_SHIFT
           
protected  int points
           
protected  short[] sinc
           
 
Constructor Summary
FIRResampler(int numPoints)
          Constructor.
 
Method Summary
protected  void genSinc()
          Generate one wing of a Blackman windowed sinc equation.
 int getCushionSize()
          Return minimum number of samples required by the resampler before and after the audio to be processed.
 void resample(short[] inputBuf, int samplePos, int subSamplePos, int step, int subStep, short[] outputBuf, int position, int length)
          Do resampling.
protected static void zero(short[] buffer, int start, int end)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FIXED_POINT_SHIFT

protected static final int FIXED_POINT_SHIFT
See Also:
Constant Field Values

FIXED_POINT_ONE

protected static final int FIXED_POINT_ONE
See Also:
Constant Field Values

FIXED_POINT_BITMASK

protected static final int FIXED_POINT_BITMASK
See Also:
Constant Field Values

FIXED_POINT_CONV

protected static final int FIXED_POINT_CONV
See Also:
Constant Field Values

points

protected int points

sinc

protected short[] sinc
Constructor Detail

FIRResampler

public FIRResampler(int numPoints)
Constructor.

Parameters:
numPoints - The higher the better but more cpu and memory intensive. Even number, minimum 2.
Method Detail

resample

public void resample(short[] inputBuf,
                     int samplePos,
                     int subSamplePos,
                     int step,
                     int subStep,
                     short[] outputBuf,
                     int position,
                     int length)
Do resampling.

Specified by:
resample in interface Resampler
Parameters:
samplePos - The index of the sample in inputBuf
subSamplePos - The fractional part of the index, in 16 bit fixed point.
step - The integer part of the number of input samples per output sample.
subStep - The fractional part of the number of input samples per output sample. The value is in 16 bit fixed point.
position - The index of the output buffer to start writing to.
length - The number of samples of output to produce.

getCushionSize

public int getCushionSize()
Description copied from interface: Resampler
Return minimum number of samples required by the resampler before and after the audio to be processed. A cubic resampler might return 3, for example.

Specified by:
getCushionSize in interface Resampler
Returns:
the number of extra input samples required before and after the audio.

genSinc

protected void genSinc()
Generate one wing of a Blackman windowed sinc equation. According to Shannon's sampling theory, a sample should be rendered according to the equation A Sin(PI*t)/(PI*t) where the sampling frequency is 1/t. This equation goes to +-infinity so it is multiplied by a window function to make it tail off at the ends. The more points you use to render each sample, the more accurate the result. Linear interpolation is actually a very, very course approximation of the above "sinc" equation, which sorta explains why it works.


zero

protected static void zero(short[] buffer,
                           int start,
                           int end)