Skip to content

πŸŽ› πŸ”Š A Python library for audio.

Simplify write codepath.

Peter Sobotbb62cc08f37c
diff --git a/.github/workflows/all.yml b/.github/workflows/all.yml
index ce8a343..43e28b7 100644
--- a/.github/workflows/all.yml
+++ b/.github/workflows/all.yml
@@ -105,7 +105,7 @@ jobs:
run: python ./tests/download_test_plugins.py
- name: Run tests
if: matrix.os != 'ubuntu-latest' || matrix.python-version != '3.6'
- run: pytest -v --cov-report term --cov-fail-under=${{ env.MINIMUM_COVERAGE_PERCENTAGE }} --cov=pedalboard -s
+ run: pytest -v --cov-report term --cov-fail-under=${{ env.MINIMUM_COVERAGE_PERCENTAGE }} --cov=pedalboard
- name: Run tests with coverage reporting
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.6'
run: |
diff --git a/pedalboard/io/AudioFile.h b/pedalboard/io/AudioFile.h
index b9f472e..99be0b0 100644
--- a/pedalboard/io/AudioFile.h
+++ b/pedalboard/io/AudioFile.h
@@ -419,7 +419,6 @@ public:
unsigned int bufferSize = DEFAULT_AUDIO_BUFFER_SIZE_FRAMES>
bool writeConvertingTo(const InputType **channels, int numChannels,
unsigned int numSamples) {
- printf("in writeConvertingTo with %d %s %d-channel frames, converting to %s\n", numSamples, typeid(InputType).name(), numChannels, typeid(TargetType).name());
std::vector<std::vector<TargetType>> targetTypeBuffers;
targetTypeBuffers.resize(numChannels);
@@ -436,6 +435,7 @@ public:
for (unsigned int i = 0; i < samplesToWrite; i++) {
if constexpr (std::is_integral<InputType>::value) {
if constexpr (std::is_integral<TargetType>::value) {
+ // Left-align the samples to use all 32 bits, as JUCE requires:
targetTypeBuffers[c][i] =
((int)channels[c][startSample + i])
<< (std::numeric_limits<int>::digits -
@@ -488,21 +488,20 @@ public:
} else {
return writeConvertingTo<int>(channels, numChannels, numSamples);
}
- } else {
- if (writer->isFloatingPoint()) {
+ } else if constexpr (std::is_same<SampleType, float>::value) {
+ if (writer->isFloatingPoint()) {
// Just pass the floating point data into the writer as if it were
// integer data. If the writer requires floating-point input data, this
// works (and is documented!)
return writer->write((const int **)channels, numSamples);
} else {
- if constexpr (std::is_same<SampleType, float>::value) {
- // Convert floating-point to fixed point, but let JUCE do that for us:
- return writer->writeFromFloatArrays(channels, numChannels,
- numSamples);
- } else {
- return writeConvertingTo<float>(channels, numChannels, numSamples);
- }
+ // Convert floating-point to fixed point, but let JUCE do that for us:
+ return writer->writeFromFloatArrays(channels, numChannels,
+ numSamples);
}
+ } else {
+ // We must have double-format data:
+ return writeConvertingTo<float>(channels, numChannels, numSamples);
}
}
diff --git a/tests/test_io.py b/tests/test_io.py
index 6cbd4cc..b46c5b7 100644
--- a/tests/test_io.py
+++ b/tests/test_io.py
@@ -243,8 +243,7 @@ def test_fails_on_unsupported_format(audio_filename: str):
@pytest.mark.parametrize("extension", pedalboard.io.get_supported_write_formats())
@pytest.mark.parametrize(
- "samplerate",
- [8000, 11025, 12000, 16000, 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000],
+ "samplerate", [8000, 11025, 12000, 16000, 22050, 32000, 44100, 48000, 88200, 96000]
)
@pytest.mark.parametrize("num_channels", [1, 2, 8])
@pytest.mark.parametrize("transposed", [False, True])