Skip to content

Commit

Permalink
Bugfix - SampleTrack -> Play: Fix sample track not being played in the
Browse files Browse the repository at this point in the history
right place when it not played from the begining.

That has created a difference between the ticks and the metronome and
the sample track.

The cause of the problem was that the calculation of the frame to play
was wrong: we had calculated `framesPerTick` according to the current
engine's sample rate instead of the SampleBuffer's sample rate.
  • Loading branch information
Reflexe committed Jun 2, 2019
1 parent 1611043 commit 78b0652
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 4 additions & 0 deletions include/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@


#include "export.h"
#include "lmms_basics.h"

class BBTrackContainer;
class DummyTrackContainer;
Expand Down Expand Up @@ -100,6 +101,9 @@ class EXPORT LmmsCore : public QObject
{
return s_framesPerTick;
}

static float framesPerTick(sample_rate_t sample_rate);

static void updateFramesPerTick();

static inline LmmsCore * inst()
Expand Down
6 changes: 6 additions & 0 deletions src/core/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ void LmmsCore::destroy()
delete ConfigManager::inst();
}

float LmmsCore::framesPerTick(sample_rate_t sample_rate)
{
return sample_rate * 60.0f * 4 /
DefaultTicksPerTact / s_song->getTempo();
}




Expand Down
9 changes: 6 additions & 3 deletions src/tracks/SampleTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,13 +604,16 @@ bool SampleTrack::play( const MidiTime & _start, const fpp_t _frames,
{
TrackContentObject * tco = getTCO( i );
SampleTCO * sTco = dynamic_cast<SampleTCO*>( tco );
float framesPerTick = Engine::framesPerTick();

if( _start >= sTco->startPosition() && _start < sTco->endPosition() )
{
if( sTco->isPlaying() == false )
{
f_cnt_t sampleStart = framesPerTick * ( _start - sTco->startPosition() );
f_cnt_t tcoFrameLength = framesPerTick * ( sTco->endPosition() - sTco->startPosition() );
auto bufferFramesPerTick = Engine::framesPerTick (sTco->sampleBuffer ()->sampleRate ());
f_cnt_t sampleStart = bufferFramesPerTick * ( _start - sTco->startPosition() );

f_cnt_t tcoFrameLength = bufferFramesPerTick * ( sTco->endPosition() - sTco->startPosition() );

f_cnt_t sampleBufferLength = sTco->sampleBuffer()->frames();
//if the Tco smaller than the sample length we play only until Tco end
//else we play the sample to the end but nothing more
Expand Down

0 comments on commit 78b0652

Please sign in to comment.