Skip to content

Commit

Permalink
More cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
psobot committed Sep 12, 2024
1 parent 04da799 commit 79d1604
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 62 deletions.
1 change: 0 additions & 1 deletion pedalboard/io/ResampledReadableAudioFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ static inline int inputBufferSizeFor(ResamplingQuality quality) {
"); this is an internal "
"Pedalboard error and should be reported.");
}
assert(false);
return 0;
}

Expand Down
3 changes: 1 addition & 2 deletions pedalboard/io/StreamResampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ template <typename SampleType = float> class StreamResampler {
overflowSamples.resize(numChannels);
resamplers.resize(numChannels);

resamplerRatio = sourceSampleRate / targetSampleRate;

for (int i = 0; i < numChannels; i++) {
resamplers[i].setQuality(quality);
resamplers[i].reset();
}

resamplerRatio = sourceSampleRate / targetSampleRate;
inputLatency = resamplers[0].getBaseLatency();
outputLatency = inputLatency / resamplerRatio;

Expand Down
53 changes: 0 additions & 53 deletions pedalboard/juce_overrides/juce_FastWindowedSincInterpolators.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,6 @@ struct FastWindowedSincTraits {
double speedRatio,
const std::array<float, BufferSize> &sincValues) noexcept {
double effectiveSpeedRatio = std::max(speedRatio, 1.0);
// int inputIndices[BufferSize];
// #pragma clang loop vectorize(enable) interleave(enable)
// for (int i = 0; i < BufferSize; i++) {
// // inputIndices[i] = (indexBuffer + i) % BufferSize;
// // Very neat trick: regular modular math is not vectorizable,
// // but floating-point multiplication and subtraction is!
// // So doing this in float32 space and then converting to int
// // is about 4x faster, as the compiler can emit SIMD instructions.
// // The result is identical as long as the range of the input
// // is within the range of the mantissa of a float32.
// const int d = indexBuffer + i;
// const int index =
// d - ((int)((float)(d) / (float)BufferSize) * BufferSize);
// inputIndices[i] = index;
// }

// Copy from inputs in two contiguous chunks
// ([indexBuffer, BufferSize), then [0, indexBuffer))
Expand Down Expand Up @@ -158,50 +143,12 @@ template <class InterpolatorTraits> class FastWindowedSincInterpolator {
std::fill(std::begin(lastInputSamples), std::end(lastInputSamples), 0.0f);
}

/** Resamples a stream of samples.
@param speedRatio the number of input samples to use for
each output sample
@param inputSamples the source data to read from. This
must contain at least (speedRatio * numOutputSamplesToProduce) samples.
@param outputSamples the buffer to write the results into
@param numOutputSamplesToProduce the number of output samples that
should be created
@returns the actual number of input samples that were used
*/
int process(double speedRatio, const float *inputSamples,
float *outputSamples, int numOutputSamplesToProduce) noexcept {
return interpolate(speedRatio, inputSamples, outputSamples,
numOutputSamplesToProduce);
}

/** Resamples a stream of samples.
@param speedRatio the number of input samples to use for
each output sample
@param inputSamples the source data to read from. This
must contain at least (speedRatio * numOutputSamplesToProduce) samples.
@param outputSamples the buffer to write the results into
@param numOutputSamplesToProduce the number of output samples that
should be created
@param numInputSamplesAvailable the number of available input samples.
If it needs more samples than available, it either wraps back for
wrapAround samples, or it feeds zeroes
@param wrapAround if the stream exceeds available
samples, it wraps back for wrapAround samples. If wrapAround is set to 0,
it will feed zeroes.
@returns the actual number of input samples that were used
*/
int process(double speedRatio, const float *inputSamples,
float *outputSamples, int numOutputSamplesToProduce,
int numInputSamplesAvailable, int wrapAround) noexcept {
return interpolate(speedRatio, inputSamples, outputSamples,
numOutputSamplesToProduce, numInputSamplesAvailable,
wrapAround);
}

private:
//==============================================================================
forcedinline void pushInterpolationSample(float newValue) noexcept {
Expand Down
7 changes: 3 additions & 4 deletions pedalboard/plugin_templates/Resample.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ enum class ResamplingQuality {
// counterpart, and all properly handle downsampling without
// aliasing. They also include significant speedups for the cases
// in which the speed ratio is a nice fraction like 2/3 or 3/2.
// The higher the number used as the suffix
WindowedSinc256 = 5,
WindowedSinc128 = 6,
WindowedSinc64 = 7,
Expand Down Expand Up @@ -288,16 +287,16 @@ class Resample : public Plugin {
nativeToTargetResamplers.resize(spec.numChannels);
targetToNativeResamplers.resize(spec.numChannels);

resamplerRatio = spec.sampleRate / targetSampleRate;
inverseResamplerRatio = targetSampleRate / spec.sampleRate;

for (int i = 0; i < spec.numChannels; i++) {
nativeToTargetResamplers[i].setQuality(quality);
nativeToTargetResamplers[i].reset();
targetToNativeResamplers[i].setQuality(quality);
targetToNativeResamplers[i].reset();
}

resamplerRatio = spec.sampleRate / targetSampleRate;
inverseResamplerRatio = targetSampleRate / spec.sampleRate;

maximumBlockSizeInTargetSampleRate =
std::ceil(spec.maximumBlockSize / resamplerRatio);

Expand Down
2 changes: 0 additions & 2 deletions tests/test_stream_resampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
# limitations under the License.


import time

import numpy as np
import pytest

Expand Down

0 comments on commit 79d1604

Please sign in to comment.