Rename and reorder mode options; drop support for long window

This commit is contained in:
Chris Cannam
2024-05-03 17:52:14 +01:00
parent 3a95b94087
commit 9998c26ea3
7 changed files with 36 additions and 53 deletions

View File

@@ -266,8 +266,7 @@ RubberBandLivePitchShifter::RubberBandLivePitchShifter(int sampleRate, size_t ch
m_currentFormant(false), m_currentFormant(false),
m_shifter(new RubberBandLiveShifter m_shifter(new RubberBandLiveShifter
(sampleRate, channels, (sampleRate, channels,
RubberBandLiveShifter::OptionWindowLong | RubberBandLiveShifter::OptionPitchMethodStandard |
RubberBandLiveShifter::OptionPitchModeA |
RubberBandLiveShifter::OptionChannelsTogether)), RubberBandLiveShifter::OptionChannelsTogether)),
m_sampleRate(sampleRate), m_sampleRate(sampleRate),
m_channels(channels), m_channels(channels),

View File

@@ -642,7 +642,6 @@ RubberBandPitchShifter::runImpl(uint32_t insamples, uint32_t offset)
const int samples = insamples; const int samples = insamples;
int processed = 0; int processed = 0;
size_t outTotal = 0;
while (processed < samples) { while (processed < samples) {
@@ -671,7 +670,6 @@ RubberBandPitchShifter::runImpl(uint32_t insamples, uint32_t offset)
} }
size_t actual = m_stretcher->retrieve(m_scratch, outchunk); size_t actual = m_stretcher->retrieve(m_scratch, outchunk);
outTotal += actual;
for (size_t c = 0; c < m_channels; ++c) { for (size_t c = 0; c < m_channels; ++c) {
m_outputBuffer[c]->write(m_scratch[c], actual); m_outputBuffer[c]->write(m_scratch[c], actual);

View File

@@ -593,7 +593,6 @@ RubberBandR3PitchShifter::runImpl(uint32_t insamples, uint32_t offset)
const int samples = insamples; const int samples = insamples;
int processed = 0; int processed = 0;
size_t outTotal = 0;
while (processed < samples) { while (processed < samples) {
@@ -622,7 +621,6 @@ RubberBandR3PitchShifter::runImpl(uint32_t insamples, uint32_t offset)
} }
size_t actual = m_stretcher->retrieve(m_scratch, outchunk); size_t actual = m_stretcher->retrieve(m_scratch, outchunk);
outTotal += actual;
for (size_t c = 0; c < m_channels; ++c) { for (size_t c = 0; c < m_channels; ++c) {
m_outputBuffer[c]->write(m_scratch[c], actual); m_outputBuffer[c]->write(m_scratch[c], actual);

View File

@@ -98,14 +98,12 @@ public:
enum Option { enum Option {
OptionWindowShort = 0x00000000, OptionWindowShort = 0x00000000,
OptionWindowMedium = 0x00100000, OptionWindowMedium = 0x00100000,
OptionWindowLong = 0x00200000,
OptionFormantShifted = 0x00000000, OptionFormantShifted = 0x00000000,
OptionFormantPreserved = 0x01000000, OptionFormantPreserved = 0x01000000,
//!!! Rename and document OptionPitchMethodStandard = 0x00000000,
OptionPitchModeA = 0x00000000, OptionPitchMethodAlternate = 0x02000000,
OptionPitchModeB = 0x02000000,
OptionChannelsApart = 0x00000000, OptionChannelsApart = 0x00000000,
OptionChannelsTogether = 0x10000000, OptionChannelsTogether = 0x10000000,

View File

@@ -37,8 +37,7 @@ R3LiveShifter::R3LiveShifter(Parameters parameters, Log log) :
m_pitchScale(1.0), m_pitchScale(1.0),
m_formantScale(0.0), m_formantScale(0.0),
m_guide(Guide::Parameters m_guide(Guide::Parameters
(m_parameters.sampleRate, (m_parameters.sampleRate, true),
!(m_parameters.options & RubberBandLiveShifter::OptionWindowLong)),
m_log), m_log),
m_guideConfiguration(m_guide.getConfiguration()), m_guideConfiguration(m_guide.getConfiguration()),
m_channelAssembly(m_parameters.channels), m_channelAssembly(m_parameters.channels),
@@ -46,7 +45,7 @@ R3LiveShifter::R3LiveShifter(Parameters parameters, Log log) :
m_useReadahead(false), m_useReadahead(false),
m_prevInhop(m_limits.maxInhopWithReadahead / 2), m_prevInhop(m_limits.maxInhopWithReadahead / 2),
m_prevOuthop(m_prevInhop), m_prevOuthop(m_prevInhop),
m_contractThenExpand(false), m_expandThenContract(false),
m_firstProcess(true), m_firstProcess(true),
m_unityCount(0) m_unityCount(0)
{ {
@@ -67,15 +66,14 @@ R3LiveShifter::initialise()
m_log.log(1, "R3LiveShifter::R3LiveShifter: multi window enabled"); m_log.log(1, "R3LiveShifter::R3LiveShifter: multi window enabled");
} }
if ((m_parameters.options & RubberBandLiveShifter::OptionWindowMedium) || if (m_parameters.options & RubberBandLiveShifter::OptionWindowMedium) {
(m_parameters.options & RubberBandLiveShifter::OptionWindowLong)) {
m_log.log(1, "R3LiveShifter::R3LiveShifter: readahead enabled"); m_log.log(1, "R3LiveShifter::R3LiveShifter: readahead enabled");
m_useReadahead = true; m_useReadahead = true;
} }
if ((m_parameters.options & RubberBandLiveShifter::OptionPitchModeB)) { if ((m_parameters.options & RubberBandLiveShifter::OptionPitchMethodAlternate)) {
m_log.log(1, "R3LiveShifter::R3LiveShifter: contract-then-expand enabled"); m_log.log(1, "R3LiveShifter::R3LiveShifter: expand-then-contract enabled");
m_contractThenExpand = true; m_expandThenContract = true;
} }
double maxClassifierFrequency = 16000.0; double maxClassifierFrequency = 16000.0;
@@ -276,17 +274,17 @@ R3LiveShifter::getStartDelay() const
{ {
int fixed = getWindowSourceSize() / 2 + m_resamplerDelay * 2; int fixed = getWindowSourceSize() / 2 + m_resamplerDelay * 2;
int variable = getWindowSourceSize() / 2; int variable = getWindowSourceSize() / 2;
if (m_contractThenExpand) { if (m_expandThenContract) {
if (m_pitchScale < 1.0) { if (m_pitchScale < 1.0) {
return size_t(fixed + ceil(variable / m_pitchScale));
} else {
return size_t(fixed + ceil(variable * m_pitchScale)); return size_t(fixed + ceil(variable * m_pitchScale));
} else {
return size_t(fixed + ceil(variable / m_pitchScale));
} }
} else { } else {
if (m_pitchScale < 1.0) { if (m_pitchScale < 1.0) {
return size_t(fixed + ceil(variable * m_pitchScale));
} else {
return size_t(fixed + ceil(variable / m_pitchScale)); 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; int pad = 0;
if (m_firstProcess) { if (m_firstProcess) {
if (m_contractThenExpand) { if (m_expandThenContract) {
pad = getWindowSourceSize() / 2;
} else {
pad = getWindowSourceSize(); pad = getWindowSourceSize();
if (m_pitchScale > 1.0) { if (m_pitchScale > 1.0) {
pad = int(ceil(pad * m_pitchScale)); pad = int(ceil(pad * m_pitchScale));
} }
} else {
pad = getWindowSourceSize() / 2;
} }
m_log.log(2, "R3LiveShifter::shift: extending input with pre-pad", incount, pad); m_log.log(2, "R3LiveShifter::shift: extending input with pre-pad", incount, pad);
for (int c = 0; c < m_parameters.channels; ++c) { 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; double outRatio = 1.0;
if (m_contractThenExpand) { if (m_expandThenContract) {
if (m_pitchScale < 1.0) { if (m_pitchScale > 1.0) {
outRatio = 1.0 / m_pitchScale; outRatio = 1.0 / m_pitchScale;
} }
} else { } else {
if (m_pitchScale > 1.0) { if (m_pitchScale < 1.0) {
outRatio = 1.0 / m_pitchScale; outRatio = 1.0 / m_pitchScale;
} }
} }
@@ -427,12 +425,12 @@ R3LiveShifter::readIn(const float *const *input)
double inRatio = 1.0; double inRatio = 1.0;
if (m_contractThenExpand) { if (m_expandThenContract) {
if (m_pitchScale > 1.0) { if (m_pitchScale < 1.0) {
inRatio = 1.0 / m_pitchScale; inRatio = 1.0 / m_pitchScale;
} }
} else { } else {
if (m_pitchScale < 1.0) { if (m_pitchScale > 1.0) {
inRatio = 1.0 / m_pitchScale; inRatio = 1.0 / m_pitchScale;
} }
} }
@@ -484,7 +482,6 @@ R3LiveShifter::generate(int requiredInOutbuf)
int toGenerate = requiredInOutbuf - alreadyGenerated; int toGenerate = requiredInOutbuf - alreadyGenerated;
// int longest = m_guideConfiguration.longestFftSize;
int channels = m_parameters.channels; int channels = m_parameters.channels;
int ws = getWindowSourceSize(); int ws = getWindowSourceSize();
@@ -627,12 +624,12 @@ R3LiveShifter::readOut(float *const *output, int outcount)
{ {
double outRatio = 1.0; double outRatio = 1.0;
if (m_contractThenExpand) { if (m_expandThenContract) {
if (m_pitchScale < 1.0) { if (m_pitchScale > 1.0) {
outRatio = 1.0 / m_pitchScale; outRatio = 1.0 / m_pitchScale;
} }
} else { } else {
if (m_pitchScale > 1.0) { if (m_pitchScale < 1.0) {
outRatio = 1.0 / m_pitchScale; outRatio = 1.0 / m_pitchScale;
} }
} }

View File

@@ -94,21 +94,15 @@ protected:
int minInhop; int minInhop;
int maxInhopWithReadahead; int maxInhopWithReadahead;
int maxInhop; int maxInhop;
Limits(RubberBandLiveShifter::Options options, double rate) : Limits(RubberBandLiveShifter::Options, double rate) :
// commented values are results when rate = 44100 or 48000 // commented values are results when rate = 44100 or 48000
minPreferredOuthop(roundUpDiv(rate, 512)), // 128 minInhop(1)
maxPreferredOuthop(roundUpDiv(rate, 128)), // 512
minInhop(1),
maxInhopWithReadahead(roundUpDiv(rate, 64)), // 1024
maxInhop(roundUpDiv(rate, 32)) // 2048
{ {
if (!(options & RubberBandLiveShifter::OptionWindowLong)) {
minPreferredOuthop = roundUpDiv(rate, 256); // 256 minPreferredOuthop = roundUpDiv(rate, 256); // 256
maxPreferredOuthop = (roundUpDiv(rate, 128) * 5) / 4; // 640 maxPreferredOuthop = (roundUpDiv(rate, 128) * 5) / 4; // 640
maxInhopWithReadahead = roundUpDiv(rate, 128); // 512 maxInhopWithReadahead = roundUpDiv(rate, 128); // 512
maxInhop = (roundUpDiv(rate, 64) * 3) / 2; // 1536 maxInhop = (roundUpDiv(rate, 64) * 3) / 2; // 1536
} }
}
}; };
struct ClassificationReadaheadData { struct ClassificationReadaheadData {
@@ -321,7 +315,7 @@ protected:
bool m_useReadahead; bool m_useReadahead;
int m_prevInhop; int m_prevInhop;
int m_prevOuthop; int m_prevOuthop;
bool m_contractThenExpand; // otherwise expand then contract bool m_expandThenContract; // otherwise contract then expand
bool m_firstProcess; bool m_firstProcess;
uint32_t m_unityCount; uint32_t m_unityCount;
@@ -391,8 +385,7 @@ protected:
} }
bool isSingleWindowed() const { bool isSingleWindowed() const {
return !(m_parameters.options & return true;
RubberBandLiveShifter::OptionWindowLong);
} }
int getWindowSourceSize() const { int getWindowSourceSize() const {

View File

@@ -117,7 +117,7 @@ static void check_sinusoid_unchanged(int n, int rate, float freq,
BOOST_AUTO_TEST_CASE(sinusoid_unchanged_mode_a) BOOST_AUTO_TEST_CASE(sinusoid_unchanged_mode_a)
{ {
RubberBandLiveShifter::Options options = RubberBandLiveShifter::Options options =
RubberBandLiveShifter::OptionPitchModeA; RubberBandLiveShifter::OptionPitchMethodStandard;
int n = 100000; int n = 100000;
check_sinusoid_unchanged(n, 44100, 440.f, options, false); 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) BOOST_AUTO_TEST_CASE(sinusoid_unchanged_mode_b)
{ {
RubberBandLiveShifter::Options options = RubberBandLiveShifter::Options options =
RubberBandLiveShifter::OptionPitchModeB; RubberBandLiveShifter::OptionPitchMethodAlternate;
int n = 100000; int n = 100000;
check_sinusoid_unchanged(n, 44100, 440.f, options, false); check_sinusoid_unchanged(n, 44100, 440.f, options, false);