fixup: use stretcher properly, play silence on glitches
This commit is contained in:
@@ -273,9 +273,15 @@ void PlaybackEngine::musicFeedThread() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(haveTimeRatio.load() || haveStretchFactor.load()) {
|
if(haveTimeRatio.load() || haveStretchFactor.load()) {
|
||||||
|
LOGI("ratio: %.3lf stretch: %.3lf", timeRatio.load(), stretchFactor.load());
|
||||||
|
#if 1
|
||||||
double ratio = timeRatio.load() * stretchFactor.load();
|
double ratio = timeRatio.load() * stretchFactor.load();
|
||||||
|
#else
|
||||||
|
double ratio = timeRatio.load();
|
||||||
|
#endif
|
||||||
stretcher.setTimeRatio(ratio);
|
stretcher.setTimeRatio(ratio);
|
||||||
stretcher.setPitchScale(1.0 / ratio);
|
//stretcher.setPitchScale(1.0 / ratio);
|
||||||
|
stretcher.setPitchScale(1.0 / timeRatio.load());
|
||||||
haveTimeRatio.store(false);
|
haveTimeRatio.store(false);
|
||||||
haveStretchFactor.store(false);
|
haveStretchFactor.store(false);
|
||||||
}
|
}
|
||||||
@@ -622,6 +628,11 @@ void MusicProvider::onAudioReady(float *data, int32_t frames) {
|
|||||||
// this is an audio glitch
|
// this is an audio glitch
|
||||||
// TODO: bubble info upwards, in a counter (so we can collect device-specific glitch stats)
|
// 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);
|
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);
|
size_t num_frames = std::min(num_frames_available, num_frames_requested);
|
||||||
stretcher->retrieve(buf_ptr, num_frames);
|
stretcher->retrieve(buf_ptr, num_frames);
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ TempoController::TempoController(std::atomic<bool> *have_stretch_factor, std::at
|
|||||||
have_stretch_factor(have_stretch_factor),
|
have_stretch_factor(have_stretch_factor),
|
||||||
stretch_factor(stretch_factor),
|
stretch_factor(stretch_factor),
|
||||||
lastBeatT(0.0),
|
lastBeatT(0.0),
|
||||||
lastStepT(0.0)
|
lastStepT(0.0),
|
||||||
|
dtBeat(0.0),
|
||||||
|
dtStep(0.0)
|
||||||
{
|
{
|
||||||
this->have_stretch_factor->store(false);
|
this->have_stretch_factor->store(false);
|
||||||
this->stretch_factor->store(1.0);
|
this->stretch_factor->store(1.0);
|
||||||
@@ -49,7 +51,7 @@ void TempoController::onStep(double t) {
|
|||||||
std::lock_guard<std::mutex> lock(mMutex);
|
std::lock_guard<std::mutex> lock(mMutex);
|
||||||
if(lastStepT != 0.0) dtStep = t - lastStepT;
|
if(lastStepT != 0.0) dtStep = t - lastStepT;
|
||||||
lastStepT = t;
|
lastStepT = t;
|
||||||
setStretchFactor();
|
//setStretchFactor(); // one call is enough. otherwise we set twice roughly around the same time.
|
||||||
}
|
}
|
||||||
|
|
||||||
void TempoController::setStretchFactor() {
|
void TempoController::setStretchFactor() {
|
||||||
|
|||||||
Reference in New Issue
Block a user