fixing MidiClock (Zwischenstand #3)
This commit is contained in:
@@ -33,6 +33,7 @@ JK_MidiClock::JK_MidiClock()
|
|||||||
m_songPositionMessage = new MidiMessage(MidiMessage::songPositionPointer(0));
|
m_songPositionMessage = new MidiMessage(MidiMessage::songPositionPointer(0));
|
||||||
m_last_sample_pos_sync = 0;
|
m_last_sample_pos_sync = 0;
|
||||||
m_syncSamplePos = 0;
|
m_syncSamplePos = 0;
|
||||||
|
m_syncNext_smp_f = 0;
|
||||||
}
|
}
|
||||||
//=================================================================================================
|
//=================================================================================================
|
||||||
void JK_MidiClock::generateMidiclock(const AudioPlayHead::CurrentPositionInfo &posInfo,
|
void JK_MidiClock::generateMidiclock(const AudioPlayHead::CurrentPositionInfo &posInfo,
|
||||||
@@ -54,7 +55,15 @@ void JK_MidiClock::generateMidiclock(const AudioPlayHead::CurrentPositionInfo &p
|
|||||||
const double ppqPerSample = (posInfo.bpm / 60.0) / sampleRate;
|
const double ppqPerSample = (posInfo.bpm / 60.0) / sampleRate;
|
||||||
|
|
||||||
//PPQ offset to compensate Midi interface latency
|
//PPQ offset to compensate Midi interface latency
|
||||||
double hostPpqPosition = posInfo.ppqPosition + m_ppqOffset * ppqPerSample;;
|
double hostPpqPosition = posInfo.ppqPosition + m_ppqOffset * ppqPerSample;
|
||||||
|
|
||||||
|
const double clockDistanceInSamples_f = (60.0 * sampleRate) / (posInfo.bpm * 24.0);
|
||||||
|
const int clockDistanceInSamples = roundToInt(clockDistanceInSamples_f);
|
||||||
|
|
||||||
|
const double quant = (60.0 / posInfo.bpm) * sampleRate;
|
||||||
|
const double hostSamplePos_f = hostPpqPosition * quant;
|
||||||
|
|
||||||
|
double syncSamplePos_f = hostSamplePos_f;
|
||||||
|
|
||||||
if (posInfo.isPlaying || posInfo.isRecording)
|
if (posInfo.isPlaying || posInfo.isRecording)
|
||||||
{
|
{
|
||||||
@@ -62,6 +71,7 @@ void JK_MidiClock::generateMidiclock(const AudioPlayHead::CurrentPositionInfo &p
|
|||||||
{
|
{
|
||||||
//set the point where to start the slave
|
//set the point where to start the slave
|
||||||
m_ppqToStartSyncAt = getNearestSixteenthInPPQ(hostPpqPosition);
|
m_ppqToStartSyncAt = getNearestSixteenthInPPQ(hostPpqPosition);
|
||||||
|
SynthDebug("m_ppqToStartSyncAt %f", m_ppqToStartSyncAt);
|
||||||
|
|
||||||
//Special case: Master is set to always start playback from the previous start position...
|
//Special case: Master is set to always start playback from the previous start position...
|
||||||
if (positionJumped(m_syncPpqPosition, hostPpqPosition, sampleRate, ppqPerSample))
|
if (positionJumped(m_syncPpqPosition, hostPpqPosition, sampleRate, ppqPerSample))
|
||||||
@@ -69,7 +79,10 @@ void JK_MidiClock::generateMidiclock(const AudioPlayHead::CurrentPositionInfo &p
|
|||||||
//Cue Midiclock slave to the nearest sixteenth note to new start position
|
//Cue Midiclock slave to the nearest sixteenth note to new start position
|
||||||
//because the one calculated in stop mode isn't valid anymore.
|
//because the one calculated in stop mode isn't valid anymore.
|
||||||
sendSongPositionPointerMessage(m_ppqToStartSyncAt, 0, midiBuffer);
|
sendSongPositionPointerMessage(m_ppqToStartSyncAt, 0, midiBuffer);
|
||||||
|
SynthDebug("m_ppqToStartSyncAt %f", m_ppqToStartSyncAt);
|
||||||
}
|
}
|
||||||
|
m_syncNext_smp_f = m_ppqToStartSyncAt * quant + clockDistanceInSamples_f;
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -103,14 +116,10 @@ void JK_MidiClock::generateMidiclock(const AudioPlayHead::CurrentPositionInfo &p
|
|||||||
m_syncFlag = 0;
|
m_syncFlag = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
m_syncNext_smp_f = m_ppqToStartSyncAt * quant + clockDistanceInSamples_f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const int clockDistanceInSamples = roundToInt((60.0 * sampleRate) / (posInfo.bpm * 24.0));
|
|
||||||
const double quant = (60.0 / posInfo.bpm) * sampleRate;
|
|
||||||
const double hostSamplePos_f = hostPpqPosition * quant;
|
|
||||||
|
|
||||||
double syncSamplePos_f = hostSamplePos_f;
|
|
||||||
int64 syncSamplePos = (int64)std::round(syncSamplePos_f);
|
int64 syncSamplePos = (int64)std::round(syncSamplePos_f);
|
||||||
double sample_offset = syncSamplePos_f - m_syncSamplePos;
|
double sample_offset = syncSamplePos_f - m_syncSamplePos;
|
||||||
|
|
||||||
@@ -151,6 +160,7 @@ void JK_MidiClock::generateMidiclock(const AudioPlayHead::CurrentPositionInfo &p
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
//For best timing we should never interupt Midiclock messages!
|
//For best timing we should never interupt Midiclock messages!
|
||||||
//Seems that some slaves constantly adjusting their internal clock
|
//Seems that some slaves constantly adjusting their internal clock
|
||||||
//to Midiclock even if they are in stop mode.
|
//to Midiclock even if they are in stop mode.
|
||||||
@@ -158,8 +168,10 @@ void JK_MidiClock::generateMidiclock(const AudioPlayHead::CurrentPositionInfo &p
|
|||||||
double distance = fabs(syncSamplePos_f-m_last_sample_pos_sync);
|
double distance = fabs(syncSamplePos_f-m_last_sample_pos_sync);
|
||||||
if ((syncSamplePos % clockDistanceInSamples) == 0 and sample_pos >= 0)
|
if ((syncSamplePos % clockDistanceInSamples) == 0 and sample_pos >= 0)
|
||||||
{
|
{
|
||||||
SynthDebug("Distance : %f", distance);
|
SynthDebug("Distance (soll) : %f", clockDistanceInSamples_f);
|
||||||
SynthDebug("syncSamplePos_f: %f", syncSamplePos_f);
|
SynthDebug("Distance (ist) : %f", distance);
|
||||||
|
SynthDebug("syncSamplePos_f : %f", syncSamplePos_f);
|
||||||
|
|
||||||
SynthDebug("sample_offset : %f", sample_offset);
|
SynthDebug("sample_offset : %f", sample_offset);
|
||||||
// SynthDebug("MidiClock at Sample Sync: %d | PPQ Host: %f | PPQ Sync: %f", syncSamplePos-m_last_sample_pos_sync, hostPpqPosition-m_last_ppq_pos_host, m_syncPpqPosition-m_last_syncPpqPosition);
|
// SynthDebug("MidiClock at Sample Sync: %d | PPQ Host: %f | PPQ Sync: %f", syncSamplePos-m_last_sample_pos_sync, hostPpqPosition-m_last_ppq_pos_host, m_syncPpqPosition-m_last_syncPpqPosition);
|
||||||
SynthDebug("MidiClock at Sample Sync: %f, diff %f", sample_pos, syncSamplePos_f-m_last_sample_pos_sync);
|
SynthDebug("MidiClock at Sample Sync: %f, diff %f", sample_pos, syncSamplePos_f-m_last_sample_pos_sync);
|
||||||
@@ -170,6 +182,24 @@ void JK_MidiClock::generateMidiclock(const AudioPlayHead::CurrentPositionInfo &p
|
|||||||
}
|
}
|
||||||
m_syncSamplePos = ++syncSamplePos;
|
m_syncSamplePos = ++syncSamplePos;
|
||||||
syncSamplePos_f += 1.0;
|
syncSamplePos_f += 1.0;
|
||||||
|
#else
|
||||||
|
double curr_sample_pos = hostSamplePos_f + (double)posInBuffer;
|
||||||
|
if (fabs(curr_sample_pos - m_syncNext_smp_f) <= 0.5)
|
||||||
|
{
|
||||||
|
SynthDebug("posInBuffer : %d", posInBuffer);
|
||||||
|
SynthDebug("hostSamplePos_f : %f", hostSamplePos_f);
|
||||||
|
SynthDebug("hostSamplePos_f + posInbuffer : %f", hostSamplePos_f + posInBuffer);
|
||||||
|
SynthDebug("clockDistanceInSamples_f (soll) : %f", clockDistanceInSamples_f);
|
||||||
|
SynthDebug("clockDistanceInSamples_f (ist) : %f", curr_sample_pos - m_last_sample_pos_sync);
|
||||||
|
|
||||||
|
m_syncNext_smp_f += clockDistanceInSamples_f;
|
||||||
|
m_last_sample_pos_sync = curr_sample_pos;
|
||||||
|
SynthDebug("m_syncNext_smp_f : %f", m_syncNext_smp_f);
|
||||||
|
midiBuffer->addEvent(*m_clockMessage, roundToInt(posInBuffer));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
m_wasPlaying = true;
|
m_wasPlaying = true;
|
||||||
@@ -185,6 +215,7 @@ void JK_MidiClock::generateMidiclock(const AudioPlayHead::CurrentPositionInfo &p
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_syncPpqPosition = hostPpqPosition;
|
m_syncPpqPosition = hostPpqPosition;
|
||||||
|
m_syncNext_smp_f = hostSamplePos_f + clockDistanceInSamples_f;
|
||||||
m_syncFlag = startSlave_;
|
m_syncFlag = startSlave_;
|
||||||
m_wasPlaying = false;
|
m_wasPlaying = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ private:
|
|||||||
double m_last_ppq_pos_host;
|
double m_last_ppq_pos_host;
|
||||||
double m_last_syncPpqPosition;
|
double m_last_syncPpqPosition;
|
||||||
double m_syncSamplePos;
|
double m_syncSamplePos;
|
||||||
|
double m_syncNext_smp_f;
|
||||||
static const int cycleEnd_ = 1;
|
static const int cycleEnd_ = 1;
|
||||||
static const int startSlave_ = 2;
|
static const int startSlave_ = 2;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user