2.1 KiB
Signal
The Signal class implements a piecewise automation curve for scalar parameters such as BPM. It stores automation points and evaluates the curve at any audio time, supporting step, linear, and exponential ramps.
(no submodules)
Purpose
Musical performances often require smooth tempo changes. Signal provides the mathematical foundation for these changes by scheduling automation points and interpolating between them. The TickSource reads the BPM curve through this Signal so that tempo ramps produce a continuously varying tick rate.
Features
setValueAtTimefor step changeslinearRampToValueAtTimefor linear interpolationexponentialRampToValueAtTimefor exponential curvesgetValueAtTimefor curve evaluation at arbitrary timescancelScheduledValuesfor clearing future points- Rejects non-positive and non-finite values with
AUDIO_TRANSPORT_INVALID_BPM
Usage: Basic
import { Signal } from "@suaveplan/audio-transport";
const bpm = new Signal({ initialValue: 120 });
bpm.linearRampToValueAtTime(240, 1);
console.log(bpm.getValueAtTime(0.5)); // 180
Usage: Advanced
const bpm = new Signal({ initialValue: 100 });
bpm.setValueAtTime(120, 0.5);
bpm.exponentialRampToValueAtTime(240, 1.5);
console.log(bpm.getValueAtTime(1)); // ~169.7
API Reference
Constructor
new Signal(options?)
Properties
initialValue— value before any pointsvalue— convenience getter returning value at time 0points— readonly array of automation points
Methods
setValueAtTime(value, time)— step changelinearRampToValueAtTime(value, time)— linear rampexponentialRampToValueAtTime(value, time)— exponential rampgetValueAtTime(time)— evaluate curvecancelScheduledValues(time)— remove points at or after time
Implementation Notes
Points are stored sorted by time. Exponential ramps require strictly positive start and target values; otherwise AUDIO_TRANSPORT_INVALID_BPM is thrown. The curve evaluation handles interpolation before the first point, between points, and after the last point.