How Ecasound Synchronizes Parallel Audio Tracks
Ecasound synchronizes audio playheads across parallel recorded tracks by processing all audio streams through a unified, sample-based engine loop driven by a single master clock. Rather than allowing individual tracks to manage their own playback timers, Ecasound binds every active chain into a centralized chainsetup that advances input and output playheads simultaneously by an identical number of samples per processing cycle. This design prevents phase drift, guarantees sample-accurate alignment, and allows seamless integration with both internal audio drivers and external transport protocols like JACK.
The Chainsetup Architecture
At the core of Ecasound's synchronization model is the chainsetup. A chainsetup acts as the master container that holds all audio inputs, processing chains, and outputs for a multitrack session. When multiple tracks are routed through Ecasound in parallel:
- Every track is assigned to an individual processing chain.
- All chains are executed simultaneously under a single instance of the Ecasound audio processing engine.
- The engine guarantees that all active chains share identical global
audio parameters, specifically the sampling rate
(
-f:bits,channels,rate).
Because all streams must match the global sampling frequency, the engine can measure the passage of time strictly in audio frames (samples per channel) rather than relying on inconsistent system clocks.
The Sample-Buffer Processing Loop
Ecasound advances audio playheads using a fixed-size buffer
processing loop determined by the engine buffer size parameter
(-b:buffersize).
- Cycle Initialization: During each iteration of the engine loop, Ecasound requests a fixed block of audio frames (e.g., 512 or 1024 samples) from every input source simultaneously.
- Parallel Processing: The samples pass through any assigned chain operators (effects, filters, volume envelopes) allocated to each track.
- Synchronized Output: The resulting frames are routed simultaneously to the assigned output devices or recorded files.
Because the engine processes exactly \(N\) samples across all parallel tracks in each loop cycle, the relative position of each playhead remains locked. If an input or output stream encounters latency or buffer starvation, the entire engine loop pauses, preventing one track from moving ahead of another.
Master Clocking and Hardware Timing
Playhead synchronization requires a reliable timing reference to govern when each buffer cycle executes. Ecasound establishes this timing using one of two methods:
- Hardware Clock (ALSA / OSS): When interacting directly with sound card drivers, the hardware digital-to-analog (DAC) or analog-to-digital (ADC) clock serves as the master timer. The engine's read and write calls block until the physical audio buffer requests the next block of samples. All parallel tracks running in the chainsetup are tied to this single hardware clock tick.
- JACK Audio Connection Kit: When integrated with JACK, Ecasound delegates master synchronization to the JACK server. Ecasound acts as a client process called once per JACK process cycle. Playhead alignment is maintained through the JACK Transport API, which broadcasts sample-accurate playhead position, frame offsets, and transport state (play, stop, locate) across all connected audio clients.
Alignment Offsets and Positional Tracking
Ecasound tracks the timeline using absolute sample positions
calculated from the start of the session. When tracks require offset
alignment (such as bringing a delayed recording into sync with existing
material), Ecasound utilizes offset controls (-y:seconds or
sample-based equivalents).
When an offset is defined for a specific chain, the engine holds that chain's playhead inactive until the global sample counter reaches the designated position. Once reached, the playhead begins advancing in strict sample lockstep with the other running chains, maintaining parallel phase alignment for the remainder of the session.