mirror of
https://github.com/Tonejs/Tone.js
synced 2024-12-27 12:03:12 +00:00
guarding against floating point issue where offset is very close to 1
fixes #645
This commit is contained in:
parent
0f47174272
commit
7f9cda9db0
1 changed files with 4 additions and 1 deletions
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue