- evaluate MidiClock

git-svn-id: http://moon:8086/svn/software/trunk/projects/JaySynth@269 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
2015-03-20 16:35:58 +00:00
parent 13adfc4ddd
commit 210833df74
18 changed files with 1826 additions and 1640 deletions
+37 -4
View File
@@ -113,6 +113,11 @@ JaySynth::JaySynth (int num_voices, String pathToWaves)
for (i=0; i < m_num_audiothreads; i++)
m_ppAudioThread[i] = new JaySynthThread(&m_pEventAudioThreadRdy[i], m_pVoices, num_voices, i, m_num_audiothreads);
m_clockdiv = 0;
m_lastTime_ms = 0;
m_lastTimeError_ms = 0;
m_estimatedTime_ms = 0;
}
JaySynth::~JaySynth()
@@ -1047,19 +1052,47 @@ void JaySynth::handleMidiEvent (const MidiMessage& m)
}
else if (m.isMidiClock())
{
const double alpha_1 = 1.0;
const double alpha_2 = 1.0/48;
const double currTime_ms = juce::Time::getMillisecondCounterHiRes();
double deltaTime_ms = currTime_ms - m_lastTime_ms;
if (m_lastTime_ms)
{
double timeError_ms = deltaTime_ms - m_estimatedTime_ms;
m_lastTimeError_ms = (1-alpha_1)*m_lastTimeError_ms + alpha_1*timeError_ms;
if (std::abs(timeError_ms) > 5.0)
{
m_estimatedTime_ms = deltaTime_ms;
}
else
{
m_estimatedTime_ms = m_estimatedTime_ms + alpha_2*(m_lastTimeError_ms);
}
}
m_lastTime_ms = currTime_ms;
if (!m_clockdiv)
{
uint32_t dT = (uint32_t)(24*m_estimatedTime_ms + 0.5);
listeners.call (&JaySynthListener::synthChanged, SYNTH_CHANGED_MIDICLOCK, &dT);
m_clockdiv = 24;
}
m_clockdiv--;
}
else if (m.isSongPositionPointer())
{
SynthDebug("SongPositionPointer\n");
m_clockdiv = (6 * m.getSongPositionPointerMidiBeat()) % 24;
}
else if (m.isQuarterFrame())
{
SynthDebug("QuarterFrame\n");
}
else if (m.isFullFrame())
{
SynthDebug("FullFrame\n");
}
else
{