/** * Audio tracks play as AudioBufferSourceNodes in the synthesizer's own * AudioContext, so the recording and the MIDI share one sample clock. The only * way they can part is a transport change (play, pause, seek, tempo-free * rebuild), which shows up as a position error and is fixed by restarting the * source at the right offset. */ /** A playing source further than this from the MIDI position is restarted. */ export declare const AUDIO_RESTART_SECONDS = 0.03; /** A recording that starts this soon after the playhead is scheduled sample-accurately. */ export declare const AUDIO_SCHEDULE_AHEAD_SECONDS = 0.5; /** The MIDI clock counts as settled once it tracks the context clock this closely. */ export declare const MASTER_SETTLED_SECONDS = 0.01; export type ClockSample = { contextTime: number; masterTime: number; }; /** * The sequencer reports a lagging position for a few frames after it resumes. * Audio is started only once the MIDI clock advances in step with the context clock. */ export declare function isMasterClockSettled(previous: ClockSample | undefined, current: ClockSample): boolean; export type AudioSyncInput = { /** MIDI transport time in seconds. */ masterTime: number; /** True while the MIDI engine is actually advancing. */ masterRunning: boolean; /** See isMasterClockSettled; starting waits for it, keeping and stopping do not. */ masterSettled: boolean; /** Seconds into the MIDI where the recording starts (negative trims its start). */ offset: number; /** Recording duration in seconds. */ duration: number; /** * Where the current source is (or will be) in the recording now, or undefined * when no source is scheduled. May be negative for a source scheduled to start later. */ sourcePosition: number | undefined; }; export type AudioSyncPlan = { action: "stop"; } | { action: "keep"; } /** Start a new source after `delay` seconds, `bufferOffset` seconds into the recording. */ | { action: "start"; delay: number; bufferOffset: number; }; export declare function planAudioSync(input: AudioSyncInput): AudioSyncPlan; /** Peak amplitude per bin across all channels, for drawing a waveform. */ export declare function computeWaveformPeaks(channels: readonly Float32Array[], binCount: number): Float32Array;