Bugfix - SampleTrack -> Play: Fix sample track not being played in the

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.
This commit is contained in:
Shmuel H
2017-12-16 11:47:08 +02:00
parent 6d27f90271
commit 665e50395c
3 changed files with 16 additions and 3 deletions

View File

@@ -31,6 +31,7 @@
#include "export.h"
#include "lmms_basics.h"
class BBTrackContainer;
class DummyTrackContainer;
@@ -100,6 +101,9 @@ public:
{
return s_framesPerTick;
}
static float framesPerTick(sample_rate_t sample_rate);
static void updateFramesPerTick();
static inline LmmsCore * inst()

View File

@@ -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();
}

View File

@@ -626,13 +626,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