-Fixed timing bug

This commit is contained in:
Harry van Haaren 2013-12-05 19:57:17 +00:00
parent f48174f7f3
commit d7c0f4b73f
3 changed files with 29 additions and 23 deletions

View file

@ -158,7 +158,7 @@ void LooperClip::recieveSaveBuffer( AudioBuffer* saveBuffer )
else else
{ {
char buffer [50]; char buffer [50];
sprintf (buffer, "LC:: %i, s: can't save, buf too small",track, scene ); sprintf (buffer, "LC:: %i, %i: can't save, buf too small",track, scene );
EventGuiPrint e( buffer ); EventGuiPrint e( buffer );
writeToGuiRingbuffer( &e ); writeToGuiRingbuffer( &e );
Stately::error(""); Stately::error("");

View file

@ -26,6 +26,8 @@ TimeManager::TimeManager():
beatFrameCountdown = fpb; beatFrameCountdown = fpb;
totalFrameCounter = 0;
tapTempoPos = 0; tapTempoPos = 0;
tapTempo[0] = 0; tapTempo[0] = 0;
tapTempo[1] = 0; tapTempo[1] = 0;
@ -121,12 +123,6 @@ int TimeManager::getNframesToBeat()
return beatFrameCountdown; return beatFrameCountdown;
} }
bool TimeManager::beatInThisProcess()
{
return beatInProcess;
}
void TimeManager::process(Buffers* buffers) void TimeManager::process(Buffers* buffers)
{ {
// tap tempo measurements // tap tempo measurements
@ -138,17 +134,25 @@ void TimeManager::process(Buffers* buffers)
//buffers->transportPosition->beats_per_bar = 4; //buffers->transportPosition->beats_per_bar = 4;
//buffers->transportPosition->beat_type = 4; //buffers->transportPosition->beat_type = 4;
totalFrameCounter += buffers->nframes;
beatFrameCountdown = beatFrameCountdown - buffers->nframes; //beatFrameCountdown = beatFrameCountdown - buffers->nframes;
//printf("beatFCd %i, %i\n", beatFrameCountdown, buffers->nframes ); //printf("beatFCd %i, %i\n", beatFrameCountdown, buffers->nframes );
if ( beatFrameCountdown < long(buffers->nframes) )
// calculate beat / bar position in nframes
int beat = totalFrameCounter / fpb;
beatFrameCountdown = totalFrameCounter - (beat*fpb);
if ( beatFrameCountdown < buffers->nframes )
{ {
beatCounter++; beatCounter++;
beatInProcess = true;
// process *upto* beat frame: // process *upto* beat frame:
jack->processFrames( beatFrameCountdown ); jack->processFrames( beatFrameCountdown );
@ -170,15 +174,18 @@ void TimeManager::process(Buffers* buffers)
} }
// process frames after beat() // process frames after beat()
int remaining = buffers->nframes - beatFrameCountdown;
// beatFrameCountdown < nframes in this case, so this remaining is a + int
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 )
{ {
char buffer [50];
sprintf (buffer, "remaining %i", remaining );
EventGuiPrint e2( buffer );
writeToGuiRingbuffer( &e2 );
jack->processFrames( remaining ); jack->processFrames( remaining );
} }
else else
@ -193,12 +200,11 @@ void TimeManager::process(Buffers* buffers)
EventTimeBarBeat e( 0, beatCounter ); EventTimeBarBeat e( 0, beatCounter );
writeToGuiRingbuffer( &e ); writeToGuiRingbuffer( &e );
beatFrameCountdown = fpb; beatFrameCountdown = fpb;
} }
else else
{ {
//printf("nframes %i\n", buffers->nframes ); //printf("nframes %i\n", buffers->nframes );
beatInProcess = false;
jack->processFrames( buffers->nframes ); jack->processFrames( buffers->nframes );
} }

View file

@ -31,17 +31,17 @@ class TimeManager
/// returns the number of samples till beat if a beat exists in this process /// returns the number of samples till beat if a beat exists in this process
/// Otherwise returns nframes /// Otherwise returns nframes
int getNframesToBeat(); int getNframesToBeat();
bool beatInThisProcess();
private: private:
int samplerate; int samplerate;
/// holds the number of frames before a beat /// holds the number of frames before a beat
//int nframesToBeat; //int nframesToBeat;
bool beatInProcess;
long long totalFrameCounter;
/// counts down frames until the next beat /// counts down frames until the next beat
int beatFrameCountdown; long beatFrameCountdown;
float fpb; float fpb;
int beatCounter; int beatCounter;