Klasse SincResampler
- Alle implementierten Schnittstellen:
Resampler
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:
- An equiripple filter design could yield a lower filter order, see http://www.mwrf.com/Articles/ArticleID/7229/7229.html
- 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
- 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
FelderModifizierer und TypFeldBeschreibungprivate static final intprivate final intprivate int[][]Cache for caching the expensive FIR table computation results in the Java process.private intprivate intprivate static final doubleMaximum error acceptable in I0 is 1e-6, or ~96 dB.private intprivate static final intprivate final int[]private intprivate int -
Konstruktorübersicht
KonstruktorenKonstruktorBeschreibungSincResampler(double clockFrequency, double samplingFrequency, double highestAccurateFrequency) Use a clock frequency of 985248Hz for PAL C64, 1022730Hz for NTSC C64. -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungprivate static intconvolve(int[] a, int aPos, int[] b) Calculate convolution with sample and sinc.private intfir(int subcycle) private static doubleI0(double x) I0() computes the 0th order modified Bessel function of the first kind.booleaninput(int input) Inputs a given sample into this SincResampler.static voidSimple sin waveform in, power output measurement function.intoutput()Gets the current output sample.voidreset()Resets this SincResampler.
-
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
Cache for caching the expensive FIR table computation results in the Java process. -
I0E
private static final double I0EMaximum 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 HzsamplingFrequency- Desired output sampling ratehighestAccurateFrequency-
-
-
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 inputaPos- offset in sample bufferb- sinc- Gibt zurück:
- convolved result
-
input
public boolean input(int input) Inputs a given sample into this SincResampler. -
output
public int output()Gets the current output sample. -
reset
public void reset()Resets this SincResampler. -
fir
private int fir(int subcycle) -
main
Simple sin waveform in, power output measurement function. It would be far better to use FFT.- Parameter:
args- Arguments
-