Skip to content

Commit

Permalink
Merge pull request #69 from spotify/psobot/external-plugin-latency-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
psobot authored Jan 28, 2022
2 parents 2ab83f9 + b8250a5 commit c1a2ae9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pedalboard/ExternalPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ template <typename ExternalPluginType> class ExternalPlugin : public Plugin {
// To compensate for any latency added by the plugin,
// only tell Pedalboard to use the last _n_ samples.
long usableSamplesProduced =
samplesProvided - pluginInstance->getLatencySamples();
std::max(0L, samplesProvided - pluginInstance->getLatencySamples());
return static_cast<int>(
std::min(usableSamplesProduced, (long)outputBlock.getNumSamples()));
}
Expand Down
5 changes: 5 additions & 0 deletions pedalboard/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,11 @@ process<float>(const py::array_t<float, py::array::c_style> inputArray,
juce::dsp::ProcessContextReplacing<float> context(ioBlock);

int outputSamples = plugin->process(context);
if (outputSamples < 0) {
throw std::runtime_error(
"A plugin returned a negative number of output samples! "
"This is an internal Pedalboard error and should be reported.");
}
pluginSamplesReceived += outputSamples;

int missingSamples = blockSize - outputSamples;
Expand Down
2 changes: 1 addition & 1 deletion tests/test_external_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ def test_parameter_name_normalization(_input: str, expected: str):


@pytest.mark.skipif(not plugin_named("CHOWTapeModel"), reason="Missing CHOWTapeModel plugin.")
@pytest.mark.parametrize("buffer_size", [128, 8192, 65536])
@pytest.mark.parametrize("buffer_size", [16, 128, 8192, 65536])
@pytest.mark.parametrize("oversampling", [1, 2, 4, 8, 16])
def test_external_plugin_latency_compensation(buffer_size: int, oversampling: int):
"""
Expand Down

0 comments on commit c1a2ae9

Please sign in to comment.