diff --git a/app/src/main/cpp/PlaybackEngine.cpp b/app/src/main/cpp/PlaybackEngine.cpp index 2e6e865..dc6ae93 100644 --- a/app/src/main/cpp/PlaybackEngine.cpp +++ b/app/src/main/cpp/PlaybackEngine.cpp @@ -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); diff --git a/app/src/main/cpp/TempoController.cpp b/app/src/main/cpp/TempoController.cpp index 7f52c97..9d07525 100644 --- a/app/src/main/cpp/TempoController.cpp +++ b/app/src/main/cpp/TempoController.cpp @@ -8,7 +8,9 @@ TempoController::TempoController(std::atomic *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 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() {