mirror of
https://github.com/Tonejs/Tone.js
synced 2024-12-28 20:43:08 +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 { Timeline } from "../util/Timeline";
|
||||||
import { isDefined } from "../util/TypeCheck";
|
import { isDefined } from "../util/TypeCheck";
|
||||||
import { TickSignal } from "./TickSignal";
|
import { TickSignal } from "./TickSignal";
|
||||||
|
import { EQ } from "../util/Math";
|
||||||
|
|
||||||
interface TickSourceOptions extends ToneWithContextOptions {
|
interface TickSourceOptions extends ToneWithContextOptions {
|
||||||
frequency: number;
|
frequency: number;
|
||||||
|
@ -302,7 +303,9 @@ export class TickSource<TypeName extends "bpm" | "hertz"> extends ToneWithContex
|
||||||
const startTicks = this.frequency.getTicksAtTime(maxStartTime);
|
const startTicks = this.frequency.getTicksAtTime(maxStartTime);
|
||||||
const ticksAtStart = this.frequency.getTicksAtTime(lastStateEvent.time);
|
const ticksAtStart = this.frequency.getTicksAtTime(lastStateEvent.time);
|
||||||
const diff = startTicks - ticksAtStart;
|
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);
|
let nextTickTime = this.frequency.getTimeOfTick(startTicks + offset);
|
||||||
while (nextTickTime < endTime) {
|
while (nextTickTime < endTime) {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue