Skip to content

Commit

Permalink
Merge pull request #109 from geraldmwangi/master
Browse files Browse the repository at this point in the history
Fixed the issue: Loosing sync after N Beats, and some more stuff. Huge thanks @geraldmwangi, appreciate the contribution, its a good fix :)
  • Loading branch information
harryhaaren committed Sep 19, 2016
2 parents 2531177 + 25560ed commit daa852b
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 10 deletions.
6 changes: 5 additions & 1 deletion src/gmastertrack.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down
2 changes: 1 addition & 1 deletion src/looper.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
7 changes: 6 additions & 1 deletion src/looperclip.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,12 @@ int LooperClip::getBeats()

long LooperClip::getBufferLenght()
{
return _recordhead;
return _recordhead;
}

long LooperClip::getActualAudioLength()
{
return _buffer->getAudioFrames();
}

void LooperClip::bar()
Expand Down
3 changes: 3 additions & 0 deletions src/looperclip.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 15 additions & 4 deletions src/metronome.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/metronome.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Metronome : public TimeObserver
{
public:
Metronome();
~Metronome(){};
~Metronome();

void setActive(bool a);

Expand All @@ -51,8 +51,8 @@ class Metronome : public TimeObserver
float vol;

int playPoint, endPoint;
float barSample[44100];
float beatSample[44100];
float* barSample;
float* beatSample;

};

Expand Down

0 comments on commit daa852b

Please sign in to comment.