diff --git a/Tone/core/clock/TickSource.ts b/Tone/core/clock/TickSource.ts index dd353535..119ae4b6 100644 --- a/Tone/core/clock/TickSource.ts +++ b/Tone/core/clock/TickSource.ts @@ -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 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 {