Files
skills/docs/media/audio/audio-transport/src/signal/signal.md
2026-05-29 08:20:56 +01:00

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

  • setValueAtTime for step changes
  • linearRampToValueAtTime for linear interpolation
  • exponentialRampToValueAtTime for exponential curves
  • getValueAtTime for curve evaluation at arbitrary times
  • cancelScheduledValues for 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 points
  • value — convenience getter returning value at time 0
  • points — readonly array of automation points

Methods

  • setValueAtTime(value, time) — step change
  • linearRampToValueAtTime(value, time) — linear ramp
  • exponentialRampToValueAtTime(value, time) — exponential ramp
  • getValueAtTime(time) — evaluate curve
  • cancelScheduledValues(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.