From 9998c26ea3b34e27926252503a218e78436f05a6 Mon Sep 17 00:00:00 2001 From: Chris Cannam Date: Fri, 3 May 2024 17:52:14 +0100 Subject: [PATCH] Rename and reorder mode options; drop support for long window --- ladspa-lv2/RubberBandLivePitchShifter.cpp | 3 +- ladspa-lv2/RubberBandPitchShifter.cpp | 2 - ladspa-lv2/RubberBandR3PitchShifter.cpp | 2 - rubberband/RubberBandLiveShifter.h | 6 +-- src/finer/R3LiveShifter.cpp | 49 +++++++++++------------ src/finer/R3LiveShifter.h | 23 ++++------- src/test/TestLiveShifter.cpp | 4 +- 7 files changed, 36 insertions(+), 53 deletions(-) diff --git a/ladspa-lv2/RubberBandLivePitchShifter.cpp b/ladspa-lv2/RubberBandLivePitchShifter.cpp index b3ac3ea..16bcaa5 100644 --- a/ladspa-lv2/RubberBandLivePitchShifter.cpp +++ b/ladspa-lv2/RubberBandLivePitchShifter.cpp @@ -266,8 +266,7 @@ RubberBandLivePitchShifter::RubberBandLivePitchShifter(int sampleRate, size_t ch m_currentFormant(false), m_shifter(new RubberBandLiveShifter (sampleRate, channels, - RubberBandLiveShifter::OptionWindowLong | - RubberBandLiveShifter::OptionPitchModeA | + RubberBandLiveShifter::OptionPitchMethodStandard | RubberBandLiveShifter::OptionChannelsTogether)), m_sampleRate(sampleRate), m_channels(channels), diff --git a/ladspa-lv2/RubberBandPitchShifter.cpp b/ladspa-lv2/RubberBandPitchShifter.cpp index a2b6cca..c98487f 100644 --- a/ladspa-lv2/RubberBandPitchShifter.cpp +++ b/ladspa-lv2/RubberBandPitchShifter.cpp @@ -642,7 +642,6 @@ RubberBandPitchShifter::runImpl(uint32_t insamples, uint32_t offset) const int samples = insamples; int processed = 0; - size_t outTotal = 0; while (processed < samples) { @@ -671,7 +670,6 @@ RubberBandPitchShifter::runImpl(uint32_t insamples, uint32_t offset) } size_t actual = m_stretcher->retrieve(m_scratch, outchunk); - outTotal += actual; for (size_t c = 0; c < m_channels; ++c) { m_outputBuffer[c]->write(m_scratch[c], actual); diff --git a/ladspa-lv2/RubberBandR3PitchShifter.cpp b/ladspa-lv2/RubberBandR3PitchShifter.cpp index 91c804f..746900a 100644 --- a/ladspa-lv2/RubberBandR3PitchShifter.cpp +++ b/ladspa-lv2/RubberBandR3PitchShifter.cpp @@ -593,7 +593,6 @@ RubberBandR3PitchShifter::runImpl(uint32_t insamples, uint32_t offset) const int samples = insamples; int processed = 0; - size_t outTotal = 0; while (processed < samples) { @@ -622,7 +621,6 @@ RubberBandR3PitchShifter::runImpl(uint32_t insamples, uint32_t offset) } size_t actual = m_stretcher->retrieve(m_scratch, outchunk); - outTotal += actual; for (size_t c = 0; c < m_channels; ++c) { m_outputBuffer[c]->write(m_scratch[c], actual); diff --git a/rubberband/RubberBandLiveShifter.h b/rubberband/RubberBandLiveShifter.h index 0ecaed2..a9b37ff 100644 --- a/rubberband/RubberBandLiveShifter.h +++ b/rubberband/RubberBandLiveShifter.h @@ -98,14 +98,12 @@ public: enum Option { OptionWindowShort = 0x00000000, OptionWindowMedium = 0x00100000, - OptionWindowLong = 0x00200000, OptionFormantShifted = 0x00000000, OptionFormantPreserved = 0x01000000, - //!!! Rename and document - OptionPitchModeA = 0x00000000, - OptionPitchModeB = 0x02000000, + OptionPitchMethodStandard = 0x00000000, + OptionPitchMethodAlternate = 0x02000000, OptionChannelsApart = 0x00000000, OptionChannelsTogether = 0x10000000, diff --git a/src/finer/R3LiveShifter.cpp b/src/finer/R3LiveShifter.cpp index faca038..d80f643 100644 --- a/src/finer/R3LiveShifter.cpp +++ b/src/finer/R3LiveShifter.cpp @@ -37,8 +37,7 @@ R3LiveShifter::R3LiveShifter(Parameters parameters, Log log) : m_pitchScale(1.0), m_formantScale(0.0), m_guide(Guide::Parameters - (m_parameters.sampleRate, - !(m_parameters.options & RubberBandLiveShifter::OptionWindowLong)), + (m_parameters.sampleRate, true), m_log), m_guideConfiguration(m_guide.getConfiguration()), m_channelAssembly(m_parameters.channels), @@ -46,7 +45,7 @@ R3LiveShifter::R3LiveShifter(Parameters parameters, Log log) : m_useReadahead(false), m_prevInhop(m_limits.maxInhopWithReadahead / 2), m_prevOuthop(m_prevInhop), - m_contractThenExpand(false), + m_expandThenContract(false), m_firstProcess(true), m_unityCount(0) { @@ -67,15 +66,14 @@ R3LiveShifter::initialise() m_log.log(1, "R3LiveShifter::R3LiveShifter: multi window enabled"); } - if ((m_parameters.options & RubberBandLiveShifter::OptionWindowMedium) || - (m_parameters.options & RubberBandLiveShifter::OptionWindowLong)) { + if (m_parameters.options & RubberBandLiveShifter::OptionWindowMedium) { m_log.log(1, "R3LiveShifter::R3LiveShifter: readahead enabled"); m_useReadahead = true; } - if ((m_parameters.options & RubberBandLiveShifter::OptionPitchModeB)) { - m_log.log(1, "R3LiveShifter::R3LiveShifter: contract-then-expand enabled"); - m_contractThenExpand = true; + if ((m_parameters.options & RubberBandLiveShifter::OptionPitchMethodAlternate)) { + m_log.log(1, "R3LiveShifter::R3LiveShifter: expand-then-contract enabled"); + m_expandThenContract = true; } double maxClassifierFrequency = 16000.0; @@ -276,17 +274,17 @@ R3LiveShifter::getStartDelay() const { int fixed = getWindowSourceSize() / 2 + m_resamplerDelay * 2; int variable = getWindowSourceSize() / 2; - if (m_contractThenExpand) { + if (m_expandThenContract) { if (m_pitchScale < 1.0) { - return size_t(fixed + ceil(variable / m_pitchScale)); - } else { return size_t(fixed + ceil(variable * m_pitchScale)); + } else { + return size_t(fixed + ceil(variable / m_pitchScale)); } } else { if (m_pitchScale < 1.0) { - return size_t(fixed + ceil(variable * m_pitchScale)); - } else { return size_t(fixed + ceil(variable / m_pitchScale)); + } else { + return size_t(fixed + ceil(variable * m_pitchScale)); } } } @@ -339,13 +337,13 @@ R3LiveShifter::shift(const float *const *input, float *const *output) int pad = 0; if (m_firstProcess) { - if (m_contractThenExpand) { + if (m_expandThenContract) { + pad = getWindowSourceSize() / 2; + } else { pad = getWindowSourceSize(); if (m_pitchScale > 1.0) { pad = int(ceil(pad * m_pitchScale)); } - } else { - pad = getWindowSourceSize() / 2; } m_log.log(2, "R3LiveShifter::shift: extending input with pre-pad", incount, pad); for (int c = 0; c < m_parameters.channels; ++c) { @@ -357,12 +355,12 @@ R3LiveShifter::shift(const float *const *input, float *const *output) double outRatio = 1.0; - if (m_contractThenExpand) { - if (m_pitchScale < 1.0) { + if (m_expandThenContract) { + if (m_pitchScale > 1.0) { outRatio = 1.0 / m_pitchScale; } } else { - if (m_pitchScale > 1.0) { + if (m_pitchScale < 1.0) { outRatio = 1.0 / m_pitchScale; } } @@ -427,12 +425,12 @@ R3LiveShifter::readIn(const float *const *input) double inRatio = 1.0; - if (m_contractThenExpand) { - if (m_pitchScale > 1.0) { + if (m_expandThenContract) { + if (m_pitchScale < 1.0) { inRatio = 1.0 / m_pitchScale; } } else { - if (m_pitchScale < 1.0) { + if (m_pitchScale > 1.0) { inRatio = 1.0 / m_pitchScale; } } @@ -484,7 +482,6 @@ R3LiveShifter::generate(int requiredInOutbuf) int toGenerate = requiredInOutbuf - alreadyGenerated; -// int longest = m_guideConfiguration.longestFftSize; int channels = m_parameters.channels; int ws = getWindowSourceSize(); @@ -627,12 +624,12 @@ R3LiveShifter::readOut(float *const *output, int outcount) { double outRatio = 1.0; - if (m_contractThenExpand) { - if (m_pitchScale < 1.0) { + if (m_expandThenContract) { + if (m_pitchScale > 1.0) { outRatio = 1.0 / m_pitchScale; } } else { - if (m_pitchScale > 1.0) { + if (m_pitchScale < 1.0) { outRatio = 1.0 / m_pitchScale; } } diff --git a/src/finer/R3LiveShifter.h b/src/finer/R3LiveShifter.h index d2fed52..814ea52 100644 --- a/src/finer/R3LiveShifter.h +++ b/src/finer/R3LiveShifter.h @@ -94,20 +94,14 @@ protected: int minInhop; int maxInhopWithReadahead; int maxInhop; - Limits(RubberBandLiveShifter::Options options, double rate) : + Limits(RubberBandLiveShifter::Options, double rate) : // commented values are results when rate = 44100 or 48000 - minPreferredOuthop(roundUpDiv(rate, 512)), // 128 - maxPreferredOuthop(roundUpDiv(rate, 128)), // 512 - minInhop(1), - maxInhopWithReadahead(roundUpDiv(rate, 64)), // 1024 - maxInhop(roundUpDiv(rate, 32)) // 2048 + minInhop(1) { - if (!(options & RubberBandLiveShifter::OptionWindowLong)) { - minPreferredOuthop = roundUpDiv(rate, 256); // 256 - maxPreferredOuthop = (roundUpDiv(rate, 128) * 5) / 4; // 640 - maxInhopWithReadahead = roundUpDiv(rate, 128); // 512 - maxInhop = (roundUpDiv(rate, 64) * 3) / 2; // 1536 - } + minPreferredOuthop = roundUpDiv(rate, 256); // 256 + maxPreferredOuthop = (roundUpDiv(rate, 128) * 5) / 4; // 640 + maxInhopWithReadahead = roundUpDiv(rate, 128); // 512 + maxInhop = (roundUpDiv(rate, 64) * 3) / 2; // 1536 } }; @@ -321,7 +315,7 @@ protected: bool m_useReadahead; int m_prevInhop; int m_prevOuthop; - bool m_contractThenExpand; // otherwise expand then contract + bool m_expandThenContract; // otherwise contract then expand bool m_firstProcess; uint32_t m_unityCount; @@ -391,8 +385,7 @@ protected: } bool isSingleWindowed() const { - return !(m_parameters.options & - RubberBandLiveShifter::OptionWindowLong); + return true; } int getWindowSourceSize() const { diff --git a/src/test/TestLiveShifter.cpp b/src/test/TestLiveShifter.cpp index 3fbd168..884d180 100644 --- a/src/test/TestLiveShifter.cpp +++ b/src/test/TestLiveShifter.cpp @@ -117,7 +117,7 @@ static void check_sinusoid_unchanged(int n, int rate, float freq, BOOST_AUTO_TEST_CASE(sinusoid_unchanged_mode_a) { RubberBandLiveShifter::Options options = - RubberBandLiveShifter::OptionPitchModeA; + RubberBandLiveShifter::OptionPitchMethodStandard; int n = 100000; check_sinusoid_unchanged(n, 44100, 440.f, options, false); @@ -127,7 +127,7 @@ BOOST_AUTO_TEST_CASE(sinusoid_unchanged_mode_a) BOOST_AUTO_TEST_CASE(sinusoid_unchanged_mode_b) { RubberBandLiveShifter::Options options = - RubberBandLiveShifter::OptionPitchModeB; + RubberBandLiveShifter::OptionPitchMethodAlternate; int n = 100000; check_sinusoid_unchanged(n, 44100, 440.f, options, false);