- added master clock PLL
git-svn-id: http://moon:8086/svn/software/trunk/projects/JaySynth@717 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
+29
-29
@@ -126,6 +126,8 @@ JaySynth::JaySynth (int num_voices, String pathToWaves)
|
||||
m_clock_cnt_bar = 0;
|
||||
m_lastTime_ms = 0;
|
||||
m_estimatedTime_ms = 0;
|
||||
m_numMidiClocksPerBeat = 1;
|
||||
m_numMidiClocksPerBar = 1;
|
||||
m_isMidiClockStarted = false;
|
||||
}
|
||||
|
||||
@@ -1014,7 +1016,9 @@ void JaySynth::renderNextBlock (AudioSampleBuffer& outputBuffer,
|
||||
}
|
||||
}
|
||||
if (useEvent)
|
||||
handleMidiEvent (m);
|
||||
{
|
||||
handleMidiEvent (m);
|
||||
}
|
||||
|
||||
startSample += numThisTime;
|
||||
numSamples -= numThisTime;
|
||||
@@ -1028,8 +1032,11 @@ void JaySynth::updateMidiTiming(const MidiMessage& m)
|
||||
int denom;
|
||||
m.getTimeSignatureInfo(nom, denom);
|
||||
|
||||
m_numMidiClocksPerBeat = m_numMidiclocksPerFourQuarterBeats/denom;
|
||||
m_numMidiClocksPerBar = nom*m_numMidiClocksPerBeat;
|
||||
if (denom > 0)
|
||||
{
|
||||
m_numMidiClocksPerBeat = m_numMidiclocksPerFourQuarterBeats/denom;
|
||||
m_numMidiClocksPerBar = nom*m_numMidiClocksPerBeat;
|
||||
}
|
||||
}
|
||||
|
||||
void JaySynth::handleMidiEvent (const MidiMessage& m)
|
||||
@@ -1129,55 +1136,48 @@ void JaySynth::handleMidiEvent (const MidiMessage& m)
|
||||
|
||||
// BPM Estimation
|
||||
double deltaTime_ms = currTime_ms - m_lastTime_ms;
|
||||
if (m_lastTime_ms)
|
||||
if (m_lastTime_ms > 0.0)
|
||||
{
|
||||
m_estimatedTime_ms = (1.0-alpha_1)*m_estimatedTime_ms + alpha_1*deltaTime_ms;
|
||||
voiceSetMidiBpm(m_lastTime_ms*m_numMidiclocksPerQuarterNote);
|
||||
}
|
||||
m_lastTime_ms = currTime_ms;
|
||||
|
||||
// Quarter clock generation
|
||||
m_clock_cnt_bar = m_clock_cnt_bar % m_numMidiClocksPerBar;
|
||||
if (m_clock_cnt_bar % m_numMidiClocksPerBeat == 0)
|
||||
if (m_isMidiClockStarted)
|
||||
{
|
||||
// Send quarter pulse with current BPM estimation
|
||||
midi_quarter_clock_info_t info;
|
||||
|
||||
info.bpm = (uint32_t)(m_numMidiclocksPerQuarterNote*m_estimatedTime_ms + 0.5);
|
||||
info.type = 1;
|
||||
if (m_clock_cnt_bar == 0)
|
||||
{
|
||||
info.type = 2;
|
||||
}
|
||||
if (m_isMidiClockStarted)
|
||||
voiceSetMidiBeat(m_clock_cnt_bar % m_numMidiclocksPerQuarterNote);
|
||||
if (m_clock_cnt_bar % m_numMidiClocksPerBeat == 0)
|
||||
{
|
||||
// Send quarter pulse with current BPM estimation
|
||||
midi_quarter_clock_info_t info;
|
||||
|
||||
info.bpm = (uint32_t)(m_numMidiclocksPerQuarterNote*m_estimatedTime_ms + 0.5);
|
||||
info.type = 1;
|
||||
if (m_clock_cnt_bar == 0)
|
||||
{
|
||||
info.type = 2;
|
||||
}
|
||||
listeners.call (&JaySynthListener::synthChanged, SYNTH_CHANGED_MIDICLOCK, &info);
|
||||
}
|
||||
voiceSetMidiBeat(m_clock_cnt_bar);
|
||||
}
|
||||
m_clock_cnt_bar++;
|
||||
}
|
||||
}
|
||||
|
||||
void JaySynth::voiceSetMidiBpm(synth_float_t bpm)
|
||||
void JaySynth::voiceSetMidiBeat(int quarterBeatCount)
|
||||
{
|
||||
lfo_t *pLfo = &m_pVoices[0].pCom->glfo[0];
|
||||
synth_float_t phase = (synth_float_t)quarterBeatCount/m_numMidiclocksPerQuarterNote;
|
||||
LFO_sync(pLfo, phase);
|
||||
|
||||
for (int i=0; i < max_num_voices; i++)
|
||||
{
|
||||
JaySynthVoice* const voice = voices.getUnchecked (i);
|
||||
voice->setMidiBpm(bpm);
|
||||
voice->setMidiBeat(quarterBeatCount);
|
||||
}
|
||||
}
|
||||
|
||||
void JaySynth::voiceSetMidiBeat(int beatcount)
|
||||
{
|
||||
for (int i=0; i < max_num_voices; i++)
|
||||
{
|
||||
JaySynthVoice* const voice = voices.getUnchecked (i);
|
||||
voice->setMidiBeat(beatcount);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
// Voice trigger stuff
|
||||
//==============================================================================
|
||||
|
||||
Reference in New Issue
Block a user