Klasse SincResampler

java.lang.Object
builder.resid.resample.SincResampler
Alle implementierten Schnittstellen:
Resampler

public final class SincResampler extends Object implements Resampler
This is the theoretically correct (and computationally intensive) audio sample generation. The samples are generated by resampling to the specified sampling frequency. The work rate is inversely proportional to the percentage of the bandwidth allocated to the filter transition band.

This implementation is based on the paper "A Flexible Sampling-Rate Conversion Method", by J. O. Smith and P. Gosset, or rather on the expanded tutorial on the "Digital Audio Resampling Home Page": http:*www-ccrma.stanford.edu/~jos/resample/

By building shifted FIR tables with samples according to the sampling frequency, this implementation dramatically reduces the computational effort in the filter convolutions, without any loss of accuracy. The filter convolutions are also vectorizable on current hardware.

Further possible optimizations are:

  1. An equiripple filter design could yield a lower filter order, see http://www.mwrf.com/Articles/ArticleID/7229/7229.html
  2. The Convolution Theorem could be used to bring the complexity of convolution down from O(n*n) to O(n*log(n)) using the Fast Fourier Transform, see http://en.wikipedia.org/wiki/Convolution_theorem
  3. Simply resampling in two steps can also yield computational savings, since the transition band will be wider in the first step and the required filter order is thus lower in this step. Laurent Ganier has found the optimal intermediate sampling frequency to be (via derivation of sum of two steps):
    2 * pass_freq + sqrt [ 2 * pass_freq * orig_sample_freq * (dest_sample_freq - 2 * pass_freq) / dest_sample_freq ]
Autor:
Dag Lem, Antti Lankila
  • Feldübersicht

    Felder
    Modifizierer und Typ
    Feld
    Beschreibung
    private static final int
     
    private final int
     
    private int[][]
     
    private static Map<String,int[][]>
    Cache for caching the expensive FIR table computation results in the Java process.
    private int
     
    private int
     
    private static final double
    Maximum error acceptable in I0 is 1e-6, or ~96 dB.
    private int
     
    private static final int
     
    private final int[]
     
    private int
     
    private int
     
  • Konstruktorübersicht

    Konstruktoren
    Konstruktor
    Beschreibung
    SincResampler(double clockFrequency, double samplingFrequency, double highestAccurateFrequency)
    Use a clock frequency of 985248Hz for PAL C64, 1022730Hz for NTSC C64.
  • Methodenübersicht

    Modifizierer und Typ
    Methode
    Beschreibung
    private static int
    convolve(int[] a, int aPos, int[] b)
    Calculate convolution with sample and sinc.
    private int
    fir(int subcycle)
     
    private static double
    I0(double x)
    I0() computes the 0th order modified Bessel function of the first kind.
    boolean
    input(int input)
    Inputs a given sample into this SincResampler.
    static void
    main(String[] args)
    Simple sin waveform in, power output measurement function.
    int
    Gets the current output sample.
    void
    Resets this SincResampler.

    Von Klasse geerbte Methoden java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Felddetails

    • RINGSIZE

      private static final int RINGSIZE
      Siehe auch:
    • BITS

      private static final int BITS
      Siehe auch:
    • sample

      private final int[] sample
    • fir

      private int[][] fir
    • sampleIndex

      private int sampleIndex
    • firRES

      private int firRES
    • firN

      private int firN
    • cyclesPerSample

      private final int cyclesPerSample
    • sampleOffset

      private int sampleOffset
    • output

      private int output
    • FIR_CACHE

      private static Map<String,int[][]> FIR_CACHE
      Cache for caching the expensive FIR table computation results in the Java process.
    • I0E

      private static final double I0E
      Maximum error acceptable in I0 is 1e-6, or ~96 dB.
      Siehe auch:
  • Konstruktordetails

    • SincResampler

      public SincResampler(double clockFrequency, double samplingFrequency, double highestAccurateFrequency)
      Use a clock frequency of 985248Hz for PAL C64, 1022730Hz for NTSC C64. The default end of passband frequency is pass_freq = 0.9*sample_freq/2 for sample frequencies up to ~ 44.1kHz, and 20kHz for higher sample frequencies.

      For resampling, the ratio between the clock frequency and the sample frequency is limited as follows: 125*clock_freq/sample_freq < 16384 E.g. provided a clock frequency of ~ 1MHz, the sample frequency can not be set lower than ~ 8kHz. A lower sample frequency would make the resampling code overfill its 16k sample ring buffer.

      The end of passband frequency is also limited: pass_freq <= 0.9*sample_freq/2

      E.g. for a 44.1kHz sampling rate the end of passband frequency is limited to slightly below 20kHz. This constraint ensures that the FIR table is not overfilled.

      Parameter:
      clockFrequency - System clock frequency at Hz
      samplingFrequency - Desired output sampling rate
      highestAccurateFrequency -
  • Methodendetails

    • I0

      private static double I0(double x)
      I0() computes the 0th order modified Bessel function of the first kind. This function is originally from resample-1.5/filterkit.c by J. O. Smith. It is used to build the Kaiser window for resampling.
      Parameter:
      x - evaluate I0 at x
      Gibt zurück:
      value of I0 at x.
    • convolve

      private static int convolve(int[] a, int aPos, int[] b)
      Calculate convolution with sample and sinc.
      Parameter:
      a - sample buffer input
      aPos - offset in sample buffer
      b - sinc
      Gibt zurück:
      convolved result
    • input

      public boolean input(int input)
      Inputs a given sample into this SincResampler.
      Angegeben von:
      input in Schnittstelle Resampler
      Parameter:
      input - The sample to input into this resampler.
      Gibt zurück:
      True if the sample is ready to output.
    • output

      public int output()
      Gets the current output sample.
      Angegeben von:
      output in Schnittstelle Resampler
      Gibt zurück:
      The current output sample.
    • reset

      public void reset()
      Resets this SincResampler.
      Angegeben von:
      reset in Schnittstelle Resampler
    • fir

      private int fir(int subcycle)
    • main

      public static void main(String[] args)
      Simple sin waveform in, power output measurement function. It would be far better to use FFT.
      Parameter:
      args - Arguments