Remove the alternate pitch method. It isn't as reliable in avoiding artifacts and it's quite a bit of overhead to test.

This commit is contained in:
Chris Cannam
2024-05-10 13:38:15 +01:00
parent 8ea77bb96d
commit bbbba44774
5 changed files with 20 additions and 85 deletions

View File

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

View File

@@ -102,9 +102,6 @@ public:
OptionFormantShifted = 0x00000000,
OptionFormantPreserved = 0x01000000,
OptionPitchMethodStandard = 0x00000000,
OptionPitchMethodAlternate = 0x02000000,
OptionChannelsApart = 0x00000000,
OptionChannelsTogether = 0x10000000,

View File

@@ -45,7 +45,6 @@ R3LiveShifter::R3LiveShifter(Parameters parameters, Log log) :
m_useReadahead(false),
m_prevInhop(m_limits.maxInhopWithReadahead / 2),
m_prevOuthop(m_prevInhop),
m_expandThenContract(false),
m_firstProcess(true),
m_unityCount(0)
{
@@ -71,11 +70,6 @@ R3LiveShifter::initialise()
m_useReadahead = true;
}
if ((m_parameters.options & RubberBandLiveShifter::OptionPitchMethodAlternate)) {
m_log.log(1, "R3LiveShifter::R3LiveShifter: expand-then-contract enabled");
m_expandThenContract = true;
}
double maxClassifierFrequency = 16000.0;
if (maxClassifierFrequency > m_parameters.sampleRate/2) {
maxClassifierFrequency = m_parameters.sampleRate/2;
@@ -247,15 +241,9 @@ R3LiveShifter::measureResamplerDelay()
auto outbuf = inbuf;
double inRatio = 1.0;
if (m_expandThenContract) {
if (m_pitchScale < 1.0) {
inRatio = 1.0 / m_pitchScale;
}
} else {
if (m_pitchScale > 1.0) {
inRatio = 1.0 / m_pitchScale;
}
}
int outcount = m_inResampler->resampleInterleaved
(outbuf.data(), bs, inbuf.data(), bs, inRatio, false);
@@ -290,19 +278,11 @@ R3LiveShifter::getStartDelay() const
{
int fixed = getWindowSourceSize() / 2 + m_resamplerDelay * 2;
int variable = getWindowSourceSize() / 2;
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 {
if (m_pitchScale < 1.0) {
return size_t(fixed + ceil(variable / m_pitchScale));
} else {
return size_t(fixed + ceil(variable * m_pitchScale));
}
}
}
size_t
@@ -353,14 +333,10 @@ R3LiveShifter::shift(const float *const *input, float *const *output)
int pad = 0;
if (m_firstProcess) {
if (m_expandThenContract) {
pad = getWindowSourceSize() / 2;
} else {
pad = getWindowSourceSize();
if (m_pitchScale > 1.0) {
pad = int(ceil(pad * m_pitchScale));
}
}
m_log.log(2, "R3LiveShifter::shift: extending input with pre-pad", incount, pad);
for (int c = 0; c < m_parameters.channels; ++c) {
m_channelData[c]->inbuf->zero(pad);
@@ -371,15 +347,9 @@ R3LiveShifter::shift(const float *const *input, float *const *output)
double outRatio = 1.0;
if (m_expandThenContract) {
if (m_pitchScale > 1.0) {
outRatio = 1.0 / m_pitchScale;
}
} else {
if (m_pitchScale < 1.0) {
outRatio = 1.0 / m_pitchScale;
}
}
int requiredInOutbuf = int(ceil(incount / outRatio));
generate(requiredInOutbuf);
@@ -440,16 +410,9 @@ R3LiveShifter::readIn(const float *const *input)
}
double inRatio = 1.0;
if (m_expandThenContract) {
if (m_pitchScale < 1.0) {
inRatio = 1.0 / m_pitchScale;
}
} else {
if (m_pitchScale > 1.0) {
inRatio = 1.0 / m_pitchScale;
}
}
m_log.log(2, "R3LiveShifter::readIn: ratio", inRatio);
@@ -639,16 +602,9 @@ int
R3LiveShifter::readOut(float *const *output, int outcount)
{
double outRatio = 1.0;
if (m_expandThenContract) {
if (m_pitchScale > 1.0) {
outRatio = 1.0 / m_pitchScale;
}
} else {
if (m_pitchScale < 1.0) {
outRatio = 1.0 / m_pitchScale;
}
}
m_log.log(2, "R3LiveShifter::readOut: outcount and ratio", outcount, outRatio);

View File

@@ -315,7 +315,6 @@ protected:
bool m_useReadahead;
int m_prevInhop;
int m_prevOuthop;
bool m_expandThenContract; // otherwise contract then expand
bool m_firstProcess;
uint32_t m_unityCount;

View File

@@ -230,34 +230,18 @@ static void check_sinusoid_shifted(int n, int rate, float freq, float shift,
}
}
BOOST_AUTO_TEST_CASE(sinusoid_unchanged_mode_a)
BOOST_AUTO_TEST_CASE(sinusoid_unchanged)
{
RubberBandLiveShifter::Options options =
RubberBandLiveShifter::OptionPitchMethodStandard;
int n = 20000;
check_sinusoid_unchanged(n, 44100, 440.f, options, false);
check_sinusoid_unchanged(n, 48000, 260.f, options, false);
check_sinusoid_unchanged(n, 44100, 440.f, 0, false);
check_sinusoid_unchanged(n, 48000, 260.f, 0, false);
}
BOOST_AUTO_TEST_CASE(sinusoid_unchanged_mode_b)
BOOST_AUTO_TEST_CASE(sinusoid_down_octave)
{
RubberBandLiveShifter::Options options =
RubberBandLiveShifter::OptionPitchMethodAlternate;
int n = 20000;
check_sinusoid_unchanged(n, 44100, 440.f, options, false);
check_sinusoid_unchanged(n, 48000, 260.f, options, false);
}
BOOST_AUTO_TEST_CASE(sinusoid_down_octave_mode_a)
{
RubberBandLiveShifter::Options options =
RubberBandLiveShifter::OptionPitchMethodStandard;
int n = 20000;
check_sinusoid_shifted(n, 44100, 440.f, 0.5f, options, true);
// check_sinusoid_shifted(n, 48000, 260.f, 0.5f, options, false);
check_sinusoid_shifted(n, 44100, 440.f, 0.5f, 0, true);
// check_sinusoid_shifted(n, 48000, 260.f, 0.5f, 0, false);
}
BOOST_AUTO_TEST_SUITE_END()