π π A Python library for audio.
C audioaudio-processingaudio-productionaudio-researchaudio-unitaugmentationjucemachine-learningpybind11pythonvst3vst3-host
Fix tests.
Peter Sobotb722a5cef250
diff --git a/pedalboard/plugins/MP3Compressor.h b/pedalboard/plugins/MP3Compressor.hindex caa9aed..3200a76 100644--- a/pedalboard/plugins/MP3Compressor.h+++ b/pedalboard/plugins/MP3Compressor.h@@ -200,6 +200,8 @@ public:// Constants copied from the LAME documentation:mp3Buffer.ensureSize((int) (1.25 * MAX_LAME_MP3_BUFFER_SIZE_SAMPLES) + 7200);++ // TODO: Find a tighter bound for this output buffer.outputBuffer.setSize(32768 + spec.maximumBlockSize * 2);// Feed in some silence at the start so that LAME buffers up enough samples@@ -222,6 +224,10 @@ public:delete[] silence;+ if (numBytesEncoded != 0) {+ throw std::runtime_error("Failed to prime MP3 encoder!");+ }+encoderInStreamLatency += samplesToAdd;lastSpec = spec;}diff --git a/pedalboard/process.h b/pedalboard/process.hindex 329aab9..4eefab2 100644--- a/pedalboard/process.h+++ b/pedalboard/process.h@@ -75,7 +75,7 @@ detectChannelLayout(const py::array_t<T, py::array::c_style> inputArray) {"Unable to determine channel layout from shape!");}} else {- throw std::runtime_error("Number of input dimensions must be 1 or 2.");+ throw std::runtime_error("Number of input dimensions must be 1 or 2 (got " + std::to_string(inputInfo.ndim) + ").");}}@@ -104,7 +104,7 @@ copyPyArrayIntoJuceBuffer(const py::array_t<T, py::array::c_style> inputArray) {throw std::runtime_error("Unable to determine shape of audio input!");}} else {- throw std::runtime_error("Number of input dimensions must be 1 or 2.");+ throw std::runtime_error("Number of input dimensions must be 1 or 2 (got " + std::to_string(inputInfo.ndim) + ").");}if (numChannels == 0) {diff --git a/setup.py b/setup.pyindex cf99187..4c35389 100644--- a/setup.py+++ b/setup.py@@ -93,9 +93,7 @@ LAME_FLAGS = ["-DHAVE_MPGLIB"]LAME_CONFIG_FILE = str(Path("vendors/lame_config.h").resolve())if platform.system() == "Windows":LAME_FLAGS.append(f"/FI{LAME_CONFIG_FILE}")- # Enable native assembly instructions via NASM for x86- # If we enable Windows-on-ARM builds, this should be disabled.- LAME_FLAGS.append(f"-DHAVE_NASM")+ LAME_FLAGS.append(f"-DHAVE_XMMINTRIN_H")else:LAME_FLAGS.append(f"-include{LAME_CONFIG_FILE}")ALL_CFLAGS.extend(LAME_FLAGS)diff --git a/tests/test_mp3_compressor.py b/tests/test_mp3_compressor.pyindex aca2e23..06bb5bf 100644--- a/tests/test_mp3_compressor.py+++ b/tests/test_mp3_compressor.py@@ -19,34 +19,43 @@ import pytestimport numpy as npfrom pedalboard import MP3Compressor+# For the range of VBR quality levels supported by LAME,+# all output samples will match all input samples within+# this range. Not bad for a 25-year-old codec!+MP3_ABSOLUTE_TOLERANCE = 0.25+@pytest.mark.parametrize("vbr_quality", [0.0, 0.5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9.5])@pytest.mark.parametrize("sample_rate", [44100, 48000])-def test_mp3_compressor(vbr_quality: float, sample_rate: int):[email protected]("num_channels", [1, 2])+def test_mp3_compressor(vbr_quality: float, sample_rate: int, num_channels: int):num_seconds = 10.0fundamental_hz = 440samples = np.arange(num_seconds * sample_rate)sine_wave = np.sin(2 * np.pi * fundamental_hz * samples / sample_rate)- stereo_sine_wave = np.stack([sine_wave, sine_wave])+ if num_channels == 2:+ sine_wave = np.stack([sine_wave, sine_wave])- compressed = MP3Compressor(vbr_quality)(stereo_sine_wave, sample_rate)- np.testing.assert_allclose(stereo_sine_wave, compressed, atol=0.25)+ compressed = MP3Compressor(vbr_quality)(sine_wave, sample_rate)+ np.testing.assert_allclose(sine_wave, compressed, atol=MP3_ABSOLUTE_TOLERANCE)@pytest.mark.parametrize("vbr_quality", [0.0, 0.5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9.5])@pytest.mark.parametrize("sample_rate", [44100, 48000])-def test_mp3_compressor_invariant_to_buffer_size(vbr_quality: float, sample_rate: int):[email protected]("num_channels", [1, 2])+def test_mp3_compressor_invariant_to_buffer_size(vbr_quality: float, sample_rate: int, num_channels: int):num_seconds = 10.0fundamental_hz = 440samples = np.arange(num_seconds * sample_rate)sine_wave = np.sin(2 * np.pi * fundamental_hz * samples / sample_rate)- stereo_sine_wave = np.stack([sine_wave, sine_wave])+ if num_channels == 2:+ sine_wave = np.stack([sine_wave, sine_wave])compressed_different_buffer_sizes = [- MP3Compressor(vbr_quality)(stereo_sine_wave, sample_rate, buffer_size=buffer_size)+ MP3Compressor(vbr_quality)(sine_wave, sample_rate, buffer_size=buffer_size)for buffer_size in (32, 128, 1024, 1152, 8192, 65536)]# These should all be the same, so any two should be the same:for a, b in zip(compressed_different_buffer_sizes, compressed_different_buffer_sizes[:1]):- np.testing.assert_allclose(a, b, atol=0.25)+ np.testing.assert_allclose(a, b, atol=MP3_ABSOLUTE_TOLERANCE)