Exploratory work

This commit is contained in:
Chris Cannam
2024-03-15 16:44:38 +00:00
parent 68022c8dd9
commit cbb8329057
5 changed files with 45 additions and 26 deletions

View File

@@ -267,7 +267,7 @@ RubberBandLivePitchShifter::RubberBandLivePitchShifter(int sampleRate, size_t ch
m_shifter(new RubberBandLiveShifter m_shifter(new RubberBandLiveShifter
(sampleRate, channels, (sampleRate, channels,
RubberBandLiveShifter::OptionWindowLong | RubberBandLiveShifter::OptionWindowLong |
RubberBandLiveShifter::OptionPitchModeB | RubberBandLiveShifter::OptionPitchModeA |
RubberBandLiveShifter::OptionChannelsTogether)), RubberBandLiveShifter::OptionChannelsTogether)),
m_sampleRate(sampleRate), m_sampleRate(sampleRate),
m_channels(channels), m_channels(channels),

View File

@@ -201,6 +201,13 @@ BQResampler::resampleInterleaved(float *const out,
} }
} }
if (i < incount_samples) {
std::cerr << "only used " << i << " of " << incount_samples
<< " samples to generate output count " << o
<< " (outspace_samples was " << outspace_samples << ")"
<< std::endl;
}
int fbufsize = m_fade->buffer.size(); int fbufsize = m_fade->buffer.size();
int fi = 0, fo = 0; int fi = 0, fo = 0;
while (fo < o && m_fade_count > 0) { while (fo < o && m_fade_count > 0) {

View File

@@ -552,11 +552,12 @@ protected:
if (guidance.phaseReset.f0 < 100.0) { if (guidance.phaseReset.f0 < 100.0) {
guidance.phaseReset.f0 = 0.0; guidance.phaseReset.f0 = 0.0;
} }
/*
// if (guidance.phaseReset.f0 > 0.0) { if (guidance.phaseReset.f0 > 0.0) {
// std::cout << unityCount << ": f0 = " << guidance.phaseReset.f0 std::cout << "unity: f0 = " << guidance.phaseReset.f0
// << ", f1 = " << guidance.phaseReset.f1 << std::endl; << ", f1 = " << guidance.phaseReset.f1 << std::endl;
// } }
*/
} }
bool checkPotentialKick(const process_t *const magnitudes, bool checkPotentialKick(const process_t *const magnitudes,

View File

@@ -341,7 +341,7 @@ R3LiveShifter::shift(const float *const *input, float *const *output)
} }
} }
int requiredInOutbuf = int(ceil(incount / outRatio)); int requiredInOutbuf = 1 + int(ceil(incount / outRatio));
generate(requiredInOutbuf); generate(requiredInOutbuf);
int got = readOut(output, incount, 0); int got = readOut(output, incount, 0);
@@ -615,6 +615,8 @@ R3LiveShifter::readOut(float *const *output, int outcount, int origin)
int fromOutbuf = int(floor(outcount / outRatio)); int fromOutbuf = int(floor(outcount / outRatio));
m_log.log(2, "R3LiveShifter::readOut: origin and fromOutbuf", origin, fromOutbuf);
if (fromOutbuf == 0) { if (fromOutbuf == 0) {
fromOutbuf = 1; fromOutbuf = 1;
} }
@@ -630,9 +632,6 @@ R3LiveShifter::readOut(float *const *output, int outcount, int origin)
} }
got = std::min(got, std::max(gotHere, 0)); got = std::min(got, std::max(gotHere, 0));
} }
m_channelAssembly.resampled[c] = cd->resampled.data();
m_channelAssembly.mixdown[c] = output[c] + origin;
} }
m_log.log(2, "R3LiveShifter::readOut: requested and got from outbufs", fromOutbuf, got); m_log.log(2, "R3LiveShifter::readOut: requested and got from outbufs", fromOutbuf, got);
@@ -641,6 +640,13 @@ R3LiveShifter::readOut(float *const *output, int outcount, int origin)
int resampledCount = 0; int resampledCount = 0;
if (got > 0) { if (got > 0) {
for (int c = 0; c < m_parameters.channels; ++c) {
auto &cd = m_channelData.at(c);
m_channelAssembly.resampled[c] = cd->resampled.data();
m_channelAssembly.mixdown[c] = output[c] + origin;
}
resampledCount = m_outResampler->resample resampledCount = m_outResampler->resample
(m_channelAssembly.mixdown.data(), (m_channelAssembly.mixdown.data(),
outcount, outcount,
@@ -648,6 +654,17 @@ R3LiveShifter::readOut(float *const *output, int outcount, int origin)
got, got,
outRatio, outRatio,
false); false);
if (useMidSide()) {
for (int i = 0; i < resampledCount; ++i) {
float m = output[0][origin + i];
float s = output[1][origin + i];
float l = m + s;
float r = m - s;
output[0][origin + i] = l;
output[1][origin + i] = r;
}
}
} }
m_log.log(2, "R3LiveShifter::readOut: resampled to", resampledCount); m_log.log(2, "R3LiveShifter::readOut: resampled to", resampledCount);
@@ -665,26 +682,18 @@ R3LiveShifter::readOut(float *const *output, int outcount, int origin)
m_log.log(2, "R3LiveShifter::readOut: resampler left us short on first process, pre-padding output: expected and obtained", outcount, resampledCount); m_log.log(2, "R3LiveShifter::readOut: resampler left us short on first process, pre-padding output: expected and obtained", outcount, resampledCount);
int prepad = outcount - resampledCount; int prepad = outcount - resampledCount;
for (int c = 0; c < m_parameters.channels; ++c) { for (int c = 0; c < m_parameters.channels; ++c) {
v_move(m_channelAssembly.mixdown.data()[c] + prepad, v_move(output[c] + origin + prepad,
m_channelAssembly.mixdown.data()[c], resampledCount); output[c] + origin,
v_zero(m_channelAssembly.mixdown.data()[c], prepad); resampledCount);
v_zero(output[c] + origin, prepad);
} }
resampledCount = outcount; resampledCount = outcount;
} else { } else {
m_log.log(0, "R3LiveShifter::readOut: WARNING: Failed to obtain enough samples from resampler", resampledCount, outcount); m_log.log(0, "R3LiveShifter::readOut: WARNING: Failed to obtain enough samples from resampler", resampledCount, outcount);
} }
} }
if (useMidSide()) { m_log.log(2, "R3LiveShifter::readOut: returning", resampledCount);
for (int i = 0; i < resampledCount; ++i) {
float m = output[0][i];
float s = output[1][i];
float l = m + s;
float r = m - s;
output[0][i] = l;
output[1][i] = r;
}
}
return resampledCount; return resampledCount;
} }

View File

@@ -52,6 +52,8 @@ static void check_sinusoid_unchanged(int n, int rate, float freq,
RubberBandLiveShifter shifter(rate, 1, options); RubberBandLiveShifter shifter(rate, 1, options);
shifter.setPitchScale(2.66968);
int blocksize = shifter.getBlockSize(); int blocksize = shifter.getBlockSize();
BOOST_TEST(blocksize == 512); BOOST_TEST(blocksize == 512);
@@ -118,7 +120,7 @@ BOOST_AUTO_TEST_CASE(sinusoid_unchanged_mode_a)
RubberBandLiveShifter::OptionPitchModeA; RubberBandLiveShifter::OptionPitchModeA;
int n = 100000; int n = 100000;
check_sinusoid_unchanged(n, 44100, 440.f, options, false); check_sinusoid_unchanged(n, 44100, 440.f, options, true);
check_sinusoid_unchanged(n, 48000, 260.f, options, false); check_sinusoid_unchanged(n, 48000, 260.f, options, false);
} }
@@ -128,7 +130,7 @@ BOOST_AUTO_TEST_CASE(sinusoid_unchanged_mode_b)
RubberBandLiveShifter::OptionPitchModeB; RubberBandLiveShifter::OptionPitchModeB;
int n = 100000; int n = 100000;
check_sinusoid_unchanged(n, 44100, 440.f, options, true); check_sinusoid_unchanged(n, 44100, 440.f, options, false);
check_sinusoid_unchanged(n, 48000, 260.f, options, false); check_sinusoid_unchanged(n, 48000, 260.f, options, false);
} }