Debugging Clicks and Distortion in Ecasound

Intermittent distortion and clicking sounds during Ecasound processing are typically caused by buffer underruns or overruns (xruns), sample rate mismatches, internal signal clipping, or insufficient real-time system priorities. This guide covers how to isolate the root cause using Ecasound's logging tools, optimize buffer and format parameters, eliminate audio clipping, and configure your operating system for reliable, artifact-free stream processing.

1. Enable Verbose Debugging to Detect Xruns

Clicks and pops are most frequently "xruns" (buffer overruns or underruns), which occur when the CPU fails to process an audio buffer before the audio interface needs the next block of samples.

To confirm whether xruns are occurring, run Ecasound with explicit debugging flags enabled:

ecasound -d:1 -i input.wav -o alsa

The -d option controls debug output:

  • -d:1 prints standard diagnostic messages and warnings.
  • -d:2 or -d:4 provides low-level debugging details on buffer management and subsystem calls.
  • -d:16 specifically traces real-time audio device operations.

Watch the terminal output while the clicks happen. If you see ALSA or JACK reporting xrun or buffer underrun/overrun, the pipeline is dropping audio frames due to timing constraints.

2. Adjust Buffer Size and Processing Multipliers

If xruns are detected, your current buffer configuration is too small for your CPU load, or it is misaligned with the underlying audio driver.

Adjust the buffer size using the -b flag:

ecasound -b:512 -i input.wav -o alsa,default
  • Increase Buffer Size: If latency is not critical, increase the buffer size (e.g., from 128 or 256 up to 512, 1024, or 2048). Larger buffers give the processor more time to absorb execution spikes.
  • Internal Buffering (-z:intbuf): When routing across multiple chains or slow storage, use the -z:intbuf option to enable internal buffering between the processing engine and real-time outputs.
  • Period Count (-B option): When targeting raw ALSA devices, adjust the number of periods per buffer using -B:auto or specify the period count directly to match your sound card's native hardware layout.

3. Identify and Fix Sample Rate Mismatches

Intermittent clicks often sound like a periodic ticking when two devices or files operate at slightly different sample rates without a synchronous resampler.

Ensure that all inputs, chain processing setups, and output devices explicitly use the same audio format:

ecasound -f:s16_le,2,44100 -i input.wav -f:s16_le,2,44100 -o alsa,hw:0,0
  • Explicitly specify the sample format using -f:sample_format,channels,sample_rate.
  • Avoid hardware devices that lack hardware resampling when feeding them mismatched rates. In ALSA, targeting hw:X,Y bypasses all software conversion. If your input is 44.1 kHz and the hardware requires 48 kHz, using hw: will cause pitch drift, clicks, or failure. Switch to plughw:X,Y to allow ALSA’s automatic resampling layer, or resample the source before feeding it to Ecasound.

4. Check for Internal Digital Clipping

Distortion that only occurs during louder musical passages is usually digital clipping, not a buffer issue. Ecasound processes internal audio using 32-bit floating-point or 16-bit integer formats depending on configuration, but writing to fixed-point outputs (like 16-bit or 24-bit PCM) hard-clips values exceeding 0 dBFS.

Diagnose signal levels by adding the volume analysis operator to your chain:

ecasound -i input.wav -ea:100 -ev -o output.wav

The -ev operator analyzes peak and average amplitude:

  • If the peak amplitude reaches or exceeds 1.0 (or 0 dB), digital clipping is occurring.
  • Reduce the gain using the amplitude operator (-ea:80 for 80% volume) or apply a limiter/compressor operator earlier in the chain.

5. Configure System Priorities and CPU Scaling

If buffer settings are adequate but clicks still occur intermittently, background system processes are likely preempting Ecasound.

  • Set Real-Time Scheduling: Run Ecasound with real-time audio priority using chrt:

    chrt -f 70 ecasound -i input.wav -o alsa

    Ensure your user account has real-time permissions defined in /etc/security/limits.d/audio.conf (rtprio set to 95 or higher, memlock set to unlimited).

  • Lock CPU Frequency: Dynamic CPU frequency scaling can cause brief latency spikes when ramping clock speeds up and down. Set your CPU governor to performance mode:

    echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
  • Use JACK for Complex Routing: If Ecasound must interact with multiple audio streams simultaneously, route Ecasound through a dedicated JACK audio server (-i:jack -o:jack). JACK provides centralized clocking, synchronous processing, and reliable xrun reporting across all client applications.