From 25560ed160f76a94fcba49652bd7cff8a051ae80 Mon Sep 17 00:00:00 2001 From: Gerald Date: Thu, 15 Sep 2016 14:39:13 +0200 Subject: [PATCH] Fixed the issue: Loosing sync after N Beats, found and fixed issue with metronome dial (integeger numbers where getting translated to fraktional floats in setBpm()), needs more testing --- src/gmastertrack.cxx | 6 +++++- src/looper.cxx | 2 +- src/looperclip.cxx | 7 ++++++- src/looperclip.hxx | 3 +++ src/metronome.cxx | 19 +++++++++++++++---- src/metronome.hxx | 6 +++--- 6 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/gmastertrack.cxx b/src/gmastertrack.cxx index 05ad1dd..fb55e9d 100644 --- a/src/gmastertrack.cxx +++ b/src/gmastertrack.cxx @@ -23,7 +23,11 @@ static void gmastertrack_tempoDial_callback(Fl_Widget *w, void *data) { Avtk::Dial* b = (Avtk::Dial*)w; - float bpm = b->value() * 160.f + 60; + float bpm = (int)(b->value() * 160.f + 60); + if(std::fabs(bpm-round(bpm))) + { + LUPPP_WARN("%f",bpm); + } EventTimeBPM e = EventTimeBPM( bpm ); writeToDspRingbuffer( &e ); } diff --git a/src/looper.cxx b/src/looper.cxx index efb6f77..117a08f 100644 --- a/src/looper.cxx +++ b/src/looper.cxx @@ -107,7 +107,7 @@ void Looper::process(unsigned int nframes, Buffers* buffers) { // copy data into tmpBuffer, then pitch-stretch into track buffer long targetFrames = clips[clip]->getBeats() * fpb; - long actualFrames = clips[clip]->getBufferLenght(); + long actualFrames = clips[clip]->getActualAudioLength();//getBufferLenght(); float playSpeed = 1.0; if ( targetFrames != 0 && actualFrames != 0 ) diff --git a/src/looperclip.cxx b/src/looperclip.cxx index 80ca535..809748e 100644 --- a/src/looperclip.cxx +++ b/src/looperclip.cxx @@ -259,7 +259,12 @@ int LooperClip::getBeats() long LooperClip::getBufferLenght() { - return _recordhead; + return _recordhead; +} + +long LooperClip::getActualAudioLength() +{ + return _buffer->getAudioFrames(); } void LooperClip::bar() diff --git a/src/looperclip.hxx b/src/looperclip.hxx index d064919..7824095 100644 --- a/src/looperclip.hxx +++ b/src/looperclip.hxx @@ -76,7 +76,10 @@ class LooperClip : public Stately /// get buffer details int getBeats(); float getProgress(); + //Return the length of the complete buffer long getBufferLenght(); + //Return the nr of samples holding actual audio. This is less then getBufferLength(); + long getActualAudioLength(); size_t audioBufferSize(); /// set clip state diff --git a/src/metronome.cxx b/src/metronome.cxx index e0b2e4a..2982a63 100644 --- a/src/metronome.cxx +++ b/src/metronome.cxx @@ -36,21 +36,32 @@ Metronome::Metronome() : playPoint (0), vol (1) { + //Create Beat/Bar samples + beatSample=new float[jack->getSamplerate()]; + barSample=new float[jack->getSamplerate()]; // create beat and bar samples - endPoint = ( jack->getSamplerate() / 441 ); + endPoint = ( jack->getSamplerate()/10 ); // samples per cycle of - float scale = 2 * 3.1415 / endPoint; + float scale = 2 * 3.1415 *880/jack->getSamplerate(); // And fill it up - for(int i=0;i < endPoint*40;i++){ + for(int i=0;i < jack->getSamplerate();i++){ beatSample[i]= sin(i*scale); - barSample [i]= sin(i*scale*1.5); + barSample [i]= sin(i*scale*2); } // don't play after creation playPoint = endPoint + 1; } +Metronome::~Metronome() +{ + if(beatSample) + delete [] beatSample; + if(barSample) + delete [] barSample; +} + void Metronome::setActive(bool a) { active = a; diff --git a/src/metronome.hxx b/src/metronome.hxx index baacb44..a33c842 100644 --- a/src/metronome.hxx +++ b/src/metronome.hxx @@ -32,7 +32,7 @@ class Metronome : public TimeObserver { public: Metronome(); - ~Metronome(){}; + ~Metronome(); void setActive(bool a); @@ -51,8 +51,8 @@ class Metronome : public TimeObserver float vol; int playPoint, endPoint; - float barSample[44100]; - float beatSample[44100]; + float* barSample; + float* beatSample; };