From 96dd502d675026dc8c7631c9d1e4eec6e0f01e57 Mon Sep 17 00:00:00 2001 From: Harry van Haaren Date: Sun, 29 Dec 2013 00:37:49 +0000 Subject: [PATCH] -Fixed #63 nasty timing bug, now dynamically changing BPM is with audio as it should. --- src/timemanager.cxx | 28 +++++++++++++++++----------- src/timemanager.hxx | 4 ++-- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/timemanager.cxx b/src/timemanager.cxx index a907464..c30af66 100644 --- a/src/timemanager.cxx +++ b/src/timemanager.cxx @@ -42,7 +42,7 @@ TimeManager::TimeManager(): barCounter = 0; beatCounter = 0; - beatFrameCountdown = fpb; + previousBeat = 0; totalFrameCounter = 0; @@ -138,7 +138,8 @@ void TimeManager::tap() int TimeManager::getNframesToBeat() { - return beatFrameCountdown; + // FIXME + return -1; //beatFrameCountdown; } void TimeManager::process(Buffers* buffers) @@ -147,19 +148,21 @@ void TimeManager::process(Buffers* buffers) //buffers->transportPosition->beats_per_bar = 4; //buffers->transportPosition->beat_type = 4; - totalFrameCounter += buffers->nframes; // calculate beat / bar position in nframes - int beat = totalFrameCounter / fpb; - beatFrameCountdown = totalFrameCounter - (beat*fpb); + //beatFrameCountdown = totalFrameCounter - (beat*fpb); - if ( beatFrameCountdown < buffers->nframes ) + if ( previousBeat + fpb < totalFrameCounter + buffers->nframes ) { beatCounter++; + long remaining = (totalFrameCounter + buffers->nframes) - (previousBeat + fpb); + + //printf("remaining %li",remaining); + // process *upto* beat frame: - jack->processFrames( beatFrameCountdown ); + jack->processFrames( buffers->nframes - remaining ); // inform observers of new beat FIRST for(uint i = 0; i < observers.size(); i++) @@ -180,21 +183,21 @@ void TimeManager::process(Buffers* buffers) } // process frames after beat() - int remaining = long(buffers->nframes) - beatFrameCountdown; + //int remaining = long(buffers->nframes) - beatFrameCountdown; /* char buffer [50]; sprintf (buffer, "r: %i, nfr: %i, bFC %li\ttFC %lli", remaining, buffers->nframes, beatFrameCountdown, totalFrameCounter ); EventGuiPrint e2( buffer ); writeToGuiRingbuffer( &e2 ); */ - if ( remaining > 0 ) + if ( remaining > 0 && remaining < buffers->nframes ) { jack->processFrames( remaining ); } else { char buffer [50]; - sprintf (buffer, "Timing Error: negative samples %i", remaining ); + sprintf (buffer, "Timing Error: negative samples %li", remaining ); EventGuiPrint e2( buffer ); writeToGuiRingbuffer( &e2 ); } @@ -203,7 +206,8 @@ void TimeManager::process(Buffers* buffers) EventTimeBarBeat e( barCounter, beatCounter ); writeToGuiRingbuffer( &e ); - beatFrameCountdown = fpb; + //beatFrameCountdown = fpb; + previousBeat += fpb; } else { @@ -211,6 +215,8 @@ void TimeManager::process(Buffers* buffers) } + totalFrameCounter += buffers->nframes; + /* int tick = int( (beatFloat - beat) * 1920 ); diff --git a/src/timemanager.hxx b/src/timemanager.hxx index 3b1f5cb..6aae624 100644 --- a/src/timemanager.hxx +++ b/src/timemanager.hxx @@ -63,8 +63,8 @@ class TimeManager /// holds the number of frames processed long long totalFrameCounter; - /// counts down frames until the next beat - long beatFrameCountdown; + /// frame number of the last beat + long previousBeat; /// counts bars / beats processed int barCounter;