Skip to content

Commit

Permalink
Use immediate scheduling.
Browse files Browse the repository at this point in the history
  • Loading branch information
anarkiwi committed Feb 19, 2020
1 parent 1eef457 commit ba83ce2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 18 deletions.
21 changes: 4 additions & 17 deletions Oscillator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,10 @@ bool Oscillator::Triggered(cr_tick_t masterClock) {
return _nextClock == masterClock;
}

void Oscillator::ScheduleNext(cr_tick_t masterClock) {
cr_tick_t newNextClock = ((masterClock / _clockPeriod) + 1) * _clockPeriod;
// Avoid destructive interface.
if (_clockPeriod & 1) {
newNextClock += pulseGuardTicks;
} else {
newNextClock -= pulseGuardTicks;
}
_updateNextClock(newNextClock);
}

void Oscillator::ScheduleNow(cr_tick_t masterClock) {
_updateNextClock(masterClock + 1);
// Schedule on next odd numbered clock tick to minimize destructive interference.
cr_tick_t newNextClock = (masterClock + 1) | 1;
_updateNextClock(newNextClock);
}

cr_tick_t Oscillator::SetNextTick(cr_tick_t masterClock) {
Expand Down Expand Up @@ -104,10 +95,6 @@ bool Oscillator::SetFreqLazy(cr_fp_t newHz, cr_fp_t maxHz, cr_fp_t newVelocitySc

bool Oscillator::SetFreq(cr_fp_t newHz, cr_fp_t maxHz, cr_fp_t newVelocityScale, cr_tick_t masterClock, int newPeriodOffset) {
if (SetFreqLazy(newHz, maxHz, newVelocityScale, newPeriodOffset)) {
if (hz > 1.0) {
ScheduleNext(masterClock);
} else {
ScheduleNow(masterClock);
}
ScheduleNow(masterClock);
}
}
1 change: 0 additions & 1 deletion Oscillator.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class Oscillator {
bool SetFreq(cr_fp_t newHz, cr_fp_t maxHz, cr_fp_t newVelocityScale, cr_tick_t masterClock, int periodOffset);
bool SetFreqLazy(cr_fp_t newHz, cr_fp_t maxHz, cr_fp_t newVelocityScale, int periodOffset);
cr_tick_t SetNextTick(cr_tick_t masterClock);
void ScheduleNext(cr_tick_t masterClock);
void ScheduleNow(cr_tick_t masterClock);
void Reset();
cr_fp_t hz;
Expand Down

0 comments on commit ba83ce2

Please sign in to comment.