From 7391c55f9efe117546521c8510675d763ee0957f Mon Sep 17 00:00:00 2001 From: Christian Speckner Date: Sat, 12 May 2018 13:32:31 +0200 Subject: [PATCH] Documentation, minor optimization. --- src/common/audio/ConvolutionBuffer.cxx | 2 +- src/common/audio/LanczosResampler.cxx | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/common/audio/ConvolutionBuffer.cxx b/src/common/audio/ConvolutionBuffer.cxx index c0513ad45..983b06209 100644 --- a/src/common/audio/ConvolutionBuffer.cxx +++ b/src/common/audio/ConvolutionBuffer.cxx @@ -29,8 +29,8 @@ ConvolutionBuffer::ConvolutionBuffer(uInt32 size) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void ConvolutionBuffer::shift(float nextValue) { + myData[myFirstIndex] = nextValue; myFirstIndex = (myFirstIndex + 1) % mySize; - myData[(myFirstIndex + mySize - 1) % mySize] = nextValue; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/common/audio/LanczosResampler.cxx b/src/common/audio/LanczosResampler.cxx index 56fa9aac1..25ecd82ec 100644 --- a/src/common/audio/LanczosResampler.cxx +++ b/src/common/audio/LanczosResampler.cxx @@ -114,11 +114,14 @@ void LanczosResampler::precomputeKernels() // Next step: time += 1 / formatTo.sampleRate // // By construction, we limit the argument during kernel evaluation to 0 .. 1, which - // corresponds to 0 .. 1 / formatFrom.sampleRate for the time + // corresponds to 0 .. 1 / formatFrom.sampleRate for time. To implement this, we decompose + // time as follows: // // time = N / formatFrom.sampleRate + delta + // timeIndex = N * formatTo.sampleRate + delta * formatTo.sampleRate * formatFrom.sampleRate // - // with max integral N and delta, then time = delta -> modulus + // with N integral and delta < 0. From this, it follows that we replace + // time with delta, i.e. take the modulus of timeIndex. timeIndex = (timeIndex + myFormatFrom.sampleRate) % myFormatTo.sampleRate; } }