Compare commits
3 Commits
968afb6920
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 89bb464e7e | |||
| 2a50293799 | |||
| 81e8d2727b |
@@ -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);
|
||||||
@@ -28,7 +30,6 @@ void TempoController::seekTo(double oldMarkerPosSec, double newMarkerPosSec) {
|
|||||||
std::lock_guard<std::mutex> lock(mMutex);
|
std::lock_guard<std::mutex> lock(mMutex);
|
||||||
double dt = newMarkerPosSec - oldMarkerPosSec;
|
double dt = newMarkerPosSec - oldMarkerPosSec;
|
||||||
lastBeatT += dt;
|
lastBeatT += dt;
|
||||||
lastStepT += dt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -37,7 +38,9 @@ void TempoController::seekTo(double oldMarkerPosSec, double newMarkerPosSec) {
|
|||||||
*/
|
*/
|
||||||
void TempoController::onBeat(double t) {
|
void TempoController::onBeat(double t) {
|
||||||
std::lock_guard<std::mutex> lock(mMutex);
|
std::lock_guard<std::mutex> lock(mMutex);
|
||||||
|
if(lastBeatT != 0.0) dtBeat = t - lastBeatT;
|
||||||
lastBeatT = t;
|
lastBeatT = t;
|
||||||
|
setStretchFactor();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -46,5 +49,16 @@ void TempoController::onBeat(double t) {
|
|||||||
*/
|
*/
|
||||||
void TempoController::onStep(double t) {
|
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;
|
||||||
lastStepT = t;
|
lastStepT = t;
|
||||||
|
//setStretchFactor(); // one call is enough. otherwise we set twice roughly around the same time.
|
||||||
|
}
|
||||||
|
|
||||||
|
void TempoController::setStretchFactor() {
|
||||||
|
if(dtBeat == 0.0 || dtStep == 0.0) return;
|
||||||
|
double ratio = dtStep / dtBeat;
|
||||||
|
ratio = std::min(3.3, ratio);
|
||||||
|
ratio = std::max(0.3, ratio);
|
||||||
|
this->have_stretch_factor->store(true);
|
||||||
|
this->stretch_factor->store(ratio);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ private:
|
|||||||
std::atomic<double> *stretch_factor;
|
std::atomic<double> *stretch_factor;
|
||||||
double lastBeatT;
|
double lastBeatT;
|
||||||
double lastStepT;
|
double lastStepT;
|
||||||
|
double dtBeat;
|
||||||
|
double dtStep;
|
||||||
public:
|
public:
|
||||||
TempoController(std::atomic<bool> *have_stretch_factor, std::atomic<double> *stretch_factor);
|
TempoController(std::atomic<bool> *have_stretch_factor, std::atomic<double> *stretch_factor);
|
||||||
void reset(std::vector<double> beatTimesSec);
|
void reset(std::vector<double> beatTimesSec);
|
||||||
@@ -33,6 +35,8 @@ public:
|
|||||||
* @param t marker position in sec of original music time
|
* @param t marker position in sec of original music time
|
||||||
*/
|
*/
|
||||||
void onStep(double t);
|
void onStep(double t);
|
||||||
|
private:
|
||||||
|
void setStretchFactor();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //LOCKSTEP_TEMPOCONTROLLER_H
|
#endif //LOCKSTEP_TEMPOCONTROLLER_H
|
||||||
|
|||||||
Reference in New Issue
Block a user