fixup: use stretcher properly, play silence on glitches

This commit is contained in:
2026-06-14 19:07:58 +02:00
parent 2a50293799
commit 89bb464e7e
2 changed files with 16 additions and 3 deletions

View File

@@ -273,9 +273,15 @@ void PlaybackEngine::musicFeedThread() {
}
if(haveTimeRatio.load() || haveStretchFactor.load()) {
LOGI("ratio: %.3lf stretch: %.3lf", timeRatio.load(), stretchFactor.load());
#if 1
double ratio = timeRatio.load() * stretchFactor.load();
#else
double ratio = timeRatio.load();
#endif
stretcher.setTimeRatio(ratio);
stretcher.setPitchScale(1.0 / ratio);
//stretcher.setPitchScale(1.0 / ratio);
stretcher.setPitchScale(1.0 / timeRatio.load());
haveTimeRatio.store(false);
haveStretchFactor.store(false);
}
@@ -622,6 +628,11 @@ void MusicProvider::onAudioReady(float *data, int32_t frames) {
// this is an audio glitch
// TODO: bubble info upwards, in a counter (so we can collect device-specific glitch stats)
LOGI("stretcher lag: %d requested, %d available", num_frames_requested, num_frames_available);
if(num_frames_available == 0) {
// at least play silence, avoiding to play garbled stuff
memset(data, 0, sizeof(float)*frames*num_ch_out);
return;
}
}
size_t num_frames = std::min(num_frames_available, num_frames_requested);
stretcher->retrieve(buf_ptr, num_frames);

View File

@@ -8,7 +8,9 @@ TempoController::TempoController(std::atomic<bool> *have_stretch_factor, std::at
have_stretch_factor(have_stretch_factor),
stretch_factor(stretch_factor),
lastBeatT(0.0),
lastStepT(0.0)
lastStepT(0.0),
dtBeat(0.0),
dtStep(0.0)
{
this->have_stretch_factor->store(false);
this->stretch_factor->store(1.0);
@@ -49,7 +51,7 @@ void TempoController::onStep(double t) {
std::lock_guard<std::mutex> lock(mMutex);
if(lastStepT != 0.0) dtStep = t - lastStepT;
lastStepT = t;
setStretchFactor();
//setStretchFactor(); // one call is enough. otherwise we set twice roughly around the same time.
}
void TempoController::setStretchFactor() {