Wire up Log throughout

This commit is contained in:
Chris Cannam
2022-06-22 11:33:36 +01:00
parent e8b63bd10d
commit 5137b19407
7 changed files with 194 additions and 393 deletions

View File

@@ -40,8 +40,6 @@
#include <map>
#include <algorithm>
using std::cerr;
using std::endl;
using std::vector;
using std::map;
using std::set;
@@ -112,9 +110,7 @@ R2Stretcher::R2Stretcher(size_t sampleRate,
_initialised = true;
}
if (m_debugLevel > 0) {
cerr << "R2Stretcher::R2Stretcher: rate = " << m_sampleRate << ", options = " << options << endl;
}
m_log.log(1, "R2Stretcher::R2Stretcher: rate, options", m_sampleRate, options);
// Window size will vary according to the audio sample rate, but
// we don't let it drop below the 48k default
@@ -455,7 +451,7 @@ R2Stretcher::calculateSizes()
if (windowSize < minwin) windowSize = minwin;
if (rsb) {
// cerr << "adjusting window size from " << windowSize;
size_t oldWindowSize = windowSize;
size_t newWindowSize = roundUp(lrint(windowSize / m_pitchScale));
if (newWindowSize < 512) newWindowSize = 512;
size_t div = windowSize / newWindowSize;
@@ -464,7 +460,8 @@ R2Stretcher::calculateSizes()
outputIncrement /= div;
windowSize /= div;
}
// cerr << " to " << windowSize << " (inputIncrement = " << inputIncrement << ", outputIncrement = " << outputIncrement << ")" << endl;
m_log.log(2, "adjusting window size from/to", oldWindowSize, windowSize);
m_log.log(2, "input and output increments", inputIncrement, outputIncrement);
}
}
@@ -556,18 +553,19 @@ R2Stretcher::calculateSizes()
#endif
}
if (m_debugLevel > 0) {
cerr << "calculateSizes: outbuf size = " << m_outbufSize << endl;
}
m_log.log(1, "calculateSizes: outbuf size", m_outbufSize);
}
void
R2Stretcher::configure()
{
if (m_debugLevel > 0) {
std::cerr << "configure[" << this << "]: realtime = " << m_realtime << ", pitch scale = "
<< m_pitchScale << ", channels = " << m_channels << std::endl;
}
if (m_realtime) {
m_log.log(1, "configure, realtime: pitch scale and channels",
m_pitchScale, m_channels);
} else {
m_log.log(1, "configure, offline: pitch scale and channels",
m_pitchScale, m_channels);
}
size_t prevFftSize = m_fftSize;
size_t prevAWindowSize = m_aWindowSize;
@@ -621,9 +619,8 @@ R2Stretcher::configure()
m_afilter = m_sincs[m_aWindowSize];
m_swindow = m_windows[m_sWindowSize];
if (m_debugLevel > 0) {
cerr << "Window area: " << m_awindow->getArea() << "; synthesis window area: " << m_swindow->getArea() << endl;
}
m_log.log(1, "analysis and synthesis window areas",
m_awindow->getArea(), m_swindow->getArea());
}
if (windowSizeChanged || outbufSizeChanged) {
@@ -713,17 +710,16 @@ R2Stretcher::configure()
// want gaps when the ratio changes.
if (!m_realtime) {
if (m_debugLevel > 1) {
cerr << "Not real time mode: prefilling with " << m_aWindowSize/2 << " samples" << endl;
}
m_log.log(1, "offline mode: prefilling with", m_aWindowSize/2);
for (size_t c = 0; c < m_channels; ++c) {
m_channelData[c]->reset();
m_channelData[c]->inbuf->zero(m_aWindowSize/2);
}
} else {
m_log.log(1, "realtime mode: no prefill");
}
}
void
R2Stretcher::reconfigure()
{
@@ -759,7 +755,7 @@ R2Stretcher::reconfigure()
m_sWindowSize != prevSWindowSize) {
if (m_windows.find(m_aWindowSize) == m_windows.end()) {
std::cerr << "WARNING: reconfigure(): window allocation (size " << m_aWindowSize << ") required in RT mode" << std::endl;
m_log.log(0, "WARNING: reconfigure(): window allocation required in realtime mode, size", m_aWindowSize);
m_windows[m_aWindowSize] = new Window<float>
(HannWindow, m_aWindowSize);
m_sincs[m_aWindowSize] = new SincWindow<float>
@@ -767,7 +763,7 @@ R2Stretcher::reconfigure()
}
if (m_windows.find(m_sWindowSize) == m_windows.end()) {
std::cerr << "WARNING: reconfigure(): window allocation (size " << m_sWindowSize << ") required in RT mode" << std::endl;
m_log.log(0, "WARNING: reconfigure(): window allocation required in realtime mode, size", m_sWindowSize);
m_windows[m_sWindowSize] = new Window<float>
(HannWindow, m_sWindowSize);
m_sincs[m_sWindowSize] = new SincWindow<float>
@@ -798,7 +794,7 @@ R2Stretcher::reconfigure()
if (m_channelData[c]->resampler) continue;
std::cerr << "WARNING: reconfigure(): resampler construction required in RT mode" << std::endl;
m_log.log(0, "WARNING: reconfigure(): resampler construction required in RT mode");
Resampler::Parameters params;
params.quality = Resampler::FastestTolerable;
@@ -824,12 +820,10 @@ R2Stretcher::reconfigure()
somethingChanged = true;
}
if (m_debugLevel > 0) {
if (somethingChanged) {
std::cerr << "reconfigure: at least one parameter changed" << std::endl;
} else {
std::cerr << "reconfigure: nothing changed" << std::endl;
}
if (somethingChanged) {
m_log.log(1, "reconfigure: at least one parameter changed");
} else {
m_log.log(1, "reconfigure: nothing changed");
}
}
@@ -844,7 +838,7 @@ void
R2Stretcher::setTransientsOption(RubberBandStretcher::Options options)
{
if (!m_realtime) {
cerr << "R2Stretcher::setTransientsOption: Not permissible in non-realtime mode" << endl;
m_log.log(0, "R2Stretcher::setTransientsOption: Not permissible in non-realtime mode");
return;
}
int mask = (RubberBandStretcher::OptionTransientsMixed |
@@ -862,7 +856,7 @@ void
R2Stretcher::setDetectorOption(RubberBandStretcher::Options options)
{
if (!m_realtime) {
cerr << "R2Stretcher::setDetectorOption: Not permissible in non-realtime mode" << endl;
m_log.log(0, "R2Stretcher::setDetectorOption: Not permissible in non-realtime mode");
return;
}
int mask = (RubberBandStretcher::OptionDetectorPercussive |
@@ -911,7 +905,7 @@ void
R2Stretcher::setPitchOption(RubberBandStretcher::Options options)
{
if (!m_realtime) {
cerr << "R2Stretcher::setPitchOption: Pitch option is not used in non-RT mode" << endl;
m_log.log(0, "R2Stretcher::setPitchOption: Pitch option is not used in non-RT mode");
return;
}
@@ -933,14 +927,12 @@ R2Stretcher::study(const float *const *input, size_t samples, bool final)
Profiler profiler("R2Stretcher::study");
if (m_realtime) {
if (m_debugLevel > 1) {
cerr << "R2Stretcher::study: Not meaningful in realtime mode" << endl;
}
m_log.log(0, "R2Stretcher::study: Not meaningful in realtime mode");
return;
}
if (m_mode == Processing || m_mode == Finished) {
cerr << "R2Stretcher::study: Cannot study after processing" << endl;
m_log.log(0, "R2Stretcher::study: Cannot study after processing");
return;
}
m_mode = Studying;
@@ -983,7 +975,8 @@ R2Stretcher::study(const float *const *input, size_t samples, bool final)
if (writable == 0) {
// warn
cerr << "WARNING: writable == 0 (consumed = " << consumed << ", samples = " << samples << ")" << endl;
m_log.log(0, "WARNING: writable == 0: consumed, samples",
consumed, samples);
} else {
inbuf.write(mixdown + consumed, writable);
consumed += writable;
@@ -1044,8 +1037,8 @@ R2Stretcher::study(const float *const *input, size_t samples, bool final)
df = m_silentAudioCurve->processFloat(cd.fltbuf, m_increment);
bool silent = (df > 0.f);
if (silent && m_debugLevel > 1) {
cerr << "silence found at " << m_inputDuration << endl;
if (silent) {
m_log.log(2, "silence at", m_inputDuration);
}
m_silence.push_back(silent);
@@ -1059,7 +1052,6 @@ R2Stretcher::study(const float *const *input, size_t samples, bool final)
// extra afterwards.
m_inputDuration += m_increment;
// cerr << "incr input duration by increment: " << m_increment << " -> " << m_inputDuration << endl;
inbuf.skip(m_increment);
}
}
@@ -1067,8 +1059,6 @@ R2Stretcher::study(const float *const *input, size_t samples, bool final)
if (final) {
int rs = inbuf.getReadSpace();
m_inputDuration += rs;
// cerr << "incr input duration by read space: " << rs << " -> " << m_inputDuration << endl;
if (m_inputDuration > m_aWindowSize/2) { // deducting the extra
m_inputDuration -= m_aWindowSize/2;
}
@@ -1128,7 +1118,7 @@ R2Stretcher::calculateStretch()
if (!m_realtime && m_expectedInputDuration > 0) {
if (m_expectedInputDuration != inputDuration) {
std::cerr << "RubberBandStretcher: WARNING: Actual study() duration differs from duration set by setExpectedInputDuration (" << m_inputDuration << " vs " << m_expectedInputDuration << ", diff = " << (m_expectedInputDuration - m_inputDuration) << "), using the latter for calculation" << std::endl;
m_log.log(0, "WARNING: Actual study() duration differs from duration set by setExpectedInputDuration - using the latter for calculation", m_inputDuration, m_expectedInputDuration);
inputDuration = m_expectedInputDuration;
}
}
@@ -1145,10 +1135,7 @@ R2Stretcher::calculateStretch()
else history = 0;
if (history >= int(m_aWindowSize / m_increment) && increments[i] >= 0) {
increments[i] = -increments[i];
if (m_debugLevel > 1) {
std::cerr << "phase reset on silence (silent history == "
<< history << ")" << std::endl;
}
m_log.log(2, "phase reset on silence: silent history", history);
}
}
@@ -1187,9 +1174,7 @@ R2Stretcher::getSamplesRequired() const
size_t rs = inbuf.getReadSpace();
size_t ws = outbuf.getReadSpace();
if (m_debugLevel > 2) {
cerr << "getSamplesRequired: ws = " << ws << ", rs = " << rs << ", m_aWindowSize = " << m_aWindowSize << endl;
}
m_log.log(3, "getSamplesRequired: ws and rs ", ws, rs);
// We should never return zero in non-threaded modes if
// available() would also return zero, i.e. if ws == 0. If we
@@ -1226,7 +1211,7 @@ R2Stretcher::process(const float *const *input, size_t samples, bool final)
Profiler profiler("R2Stretcher::process");
if (m_mode == Finished) {
cerr << "R2Stretcher::process: Cannot process again after final chunk" << endl;
m_log.log(0, "R2Stretcher::process: Cannot process again after final chunk");
return;
}
@@ -1239,9 +1224,7 @@ R2Stretcher::process(const float *const *input, size_t samples, bool final)
if (!m_realtime) {
// See note in configure() above. Of course, we should
// never enter Studying unless we are non-RT anyway
if (m_debugLevel > 1) {
cerr << "Not real time mode: prefilling" << endl;
}
m_log.log(1, "offline mode: prefilling with", m_aWindowSize/2);
for (size_t c = 0; c < m_channels; ++c) {
m_channelData[c]->reset();
m_channelData[c]->inbuf->zero(m_aWindowSize/2);
@@ -1258,10 +1241,8 @@ R2Stretcher::process(const float *const *input, size_t samples, bool final)
m_threadSet.insert(thread);
thread->start();
}
if (m_debugLevel > 0) {
cerr << m_channels << " threads created" << endl;
}
m_log.log(1, "created threads", m_channels);
}
#endif
@@ -1293,12 +1274,10 @@ R2Stretcher::process(const float *const *input, size_t samples, bool final)
final);
if (consumed[c] < samples) {
allConsumed = false;
// cerr << "process: waiting on input consumption for channel " << c << endl;
} else {
if (final) {
m_channelData[c]->inputSize = m_channelData[c]->inCount;
}
// cerr << "process: happy with channel " << c << endl;
}
if (
#ifndef NO_THREADING
@@ -1331,14 +1310,10 @@ R2Stretcher::process(const float *const *input, size_t samples, bool final)
}
#endif
if (m_debugLevel > 1) {
if (!allConsumed) cerr << "process looping" << endl;
}
m_log.log(2, "process looping");
}
if (m_debugLevel > 1) {
cerr << "process returning" << endl;
}
m_log.log(2, "process returning");
if (final) m_mode = Finished;
}