guarding against floating point issue where offset is very close to 1

fixes #645
This commit is contained in:
Yotam Mann 2020-04-14 23:46:08 -04:00
parent 0f47174272
commit 7f9cda9db0

View file

@ -6,6 +6,7 @@ import { PlaybackState, StateTimeline, StateTimelineEvent } from "../util/StateT
import { Timeline } from "../util/Timeline";
import { isDefined } from "../util/TypeCheck";
import { TickSignal } from "./TickSignal";
import { EQ } from "../util/Math";
interface TickSourceOptions extends ToneWithContextOptions {
frequency: number;
@ -302,7 +303,9 @@ export class TickSource<TypeName extends "bpm" | "hertz"> extends ToneWithContex
const startTicks = this.frequency.getTicksAtTime(maxStartTime);
const ticksAtStart = this.frequency.getTicksAtTime(lastStateEvent.time);
const diff = startTicks - ticksAtStart;
const offset = Math.ceil(diff) - diff;
let offset = Math.ceil(diff) - diff;
// guard against floating point issues
offset = EQ(offset, 1) ? 0 : offset;
let nextTickTime = this.frequency.getTimeOfTick(startTicks + offset);
while (nextTickTime < endTime) {
try {