# How the ProfessionalAudioMixer Prevents Audio Distortion with Soft Scaling in Meetily

> Learn how the ProfessionalAudioMixer stops audio distortion with soft scaling. Our multi-stage techniques ensure clear, safe audio levels for your mix.

- Repository: [Zackriya Solutions/meetily](https://github.com/Zackriya-Solutions/meetily)
- Tags: deep-dive
- Published: 2026-07-18

---

**The ProfessionalAudioMixer prevents audio distortion by applying multi-stage soft-scaling techniques—including RMS-based ducking, exponential gain smoothing, strict headroom margins, and non-destructive clipping guards—to keep mixed microphone and system audio within safe amplitude limits.**

Meetily is an open-source meeting recorder that simultaneously captures microphone input and system audio. To combine these streams without the harsh digital clipping that occurs when raw waveforms are simply summed, the application relies on the **ProfessionalAudioMixer** struct implemented in the Rust-based Tauri backend. Understanding how this component prevents audio distortion with soft scaling is essential for developers working on professional-grade audio pipelines.

## The ProfessionalAudioMixer Architecture

Located in [[`frontend/src-tauri/src/audio/pipeline.rs`](https://github.com/Zackriya-Solutions/meetily/blob/main/frontend/src-tauri/src/audio/pipeline.rs)](https://github.com/Zackriya-Solutions/meetily/blob/main/frontend/src-tauri/src/audio/pipeline.rs#L147), the **ProfessionalAudioMixer** serves as the central processing node between raw capture buffers and the final recording file. Unlike simple additive mixing that pushes combined signals into digital full-scale distortion, this mixer analyzes incoming chunks in real-time and applies proportional attenuation.

The mixer operates on floating-point audio buffers (`Vec<f32>`) at the system sample rate—typically 48 kHz—ensuring enough dynamic range for precise gain calculations before conversion to 16-bit or 24-bit integer output formats.

## Four-Stage Soft-Scaling Pipeline

The distortion prevention strategy operates through four distinct soft-scaling mechanisms that work sequentially on each audio chunk:

### RMS-Based Ducking

Before mixing, the engine calculates the **root-mean-square (RMS)** level of both the microphone and system audio chunks. When the combined amplitude approaches the clipping threshold (0 dBFS), the mixer proportionally reduces—or "ducks"—the louder stream while preserving the dynamic range of the softer stream. This proportional reduction prevents the harsh volume cuts associated with hard limiting, maintaining natural conversation dynamics while keeping peak amplitude within safe boundaries.

### Gradual Gain Adjustment

Rather than applying abrupt gain changes that cause audible pops or clicks, the mixer implements an **exponential moving average** smoothing factor. When gain reduction is required, the adjustment ramps gradually over multiple samples, creating a gentle fade-in/fade-out effect. This temporal smoothing ensures that sudden amplitude spikes from either input source do not translate into transient distortion artifacts in the final mix.

### Headroom Preservation

The mixer enforces a fixed **-3 dB headroom margin** during the combining process. All soft-scaled gain values are mathematically constrained so that the mixed signal never exceeds this ceiling, regardless of how loud the individual input sources become. This safety buffer ensures that even during unexpected volume spikes, the final waveform remains within the representable range of the target bit depth, preventing inter-sample clipping during format conversion.

### Clipping Guard Attenuation

As a final safety mechanism, the **clipping guard** performs a post-mix validation pass. Any samples that still exceed the allowable digital range are attenuated by a factor of **0.999** rather than being hard-clipped to the maximum value. This micro-attenuation preserves the waveform's curvature and prevents the flat-topped distortion characteristic that defines digital clipping, while negligibly affecting overall loudness.

## Implementation in the Audio Pipeline

The mixer integrates into Meetily's recording workflow through tight coupling with the capture and persistence layers. The `RecordingManager` in [[`frontend/src-tauri/src/audio/recording_manager.rs`](https://github.com/Zackriya-Solutions/meetily/blob/main/frontend/src-tauri/src/audio/recording_manager.rs)](https://github.com/Zackriya-Solutions/meetily/blob/main/frontend/src-tauri/src/audio/recording_manager.rs) orchestrates the capture of both audio streams and forwards raw chunks to the mixer instance.

```rust
// Initialize the mixer with the target sample rate
let mixer = ProfessionalAudioMixer::new(48000.0);

// Process concurrent mic and system audio chunks
let mixed_chunk = mixer.mix(&microphone_buffer, &system_buffer);

// Write the soft-scaled result to disk via the saver
recording_saver.write_chunk(&mixed_chunk);

```

The `mix()` method encapsulates the entire soft-scaling pipeline: RMS analysis, gain smoothing, headroom enforcement, and clipping guard validation occur internally before returning the processed buffer. The `RecordingSaver` in [[`frontend/src-tauri/src/audio/recording_saver.rs`](https://github.com/Zackriya-Solutions/meetily/blob/main/frontend/src-tauri/src/audio/recording_saver.rs)](https://github.com/Zackriya-Solutions/meetily/blob/main/frontend/src-tauri/src/audio/recording_saver.rs) then persists this distortion-free audio to the final output file.

## Why Soft Scaling Outperforms Hard Limiting

**Hard limiting** simply truncates samples exceeding the threshold, introducing harmonic distortion and harsh artifacts. In contrast, **soft scaling** as implemented in the ProfessionalAudioMixer employs anticipatory gain reduction and proportional attenuation that preserves the psychoacoustic integrity of both voice and system audio. This approach maintains clarity during screen-share narration, video playback, and cross-talk scenarios where microphone and system levels might simultaneously peak.

## Summary

- **RMS-based ducking** proportionally attenuates the louder of two mixed streams to prevent combined amplitude overflow.
- **Exponential smoothing** applies gradual gain changes to eliminate transient pops and zipper noise.
- **-3 dB headroom preservation** guarantees the mixed signal never approaches digital full-scale, protecting against inter-sample peaks.
- **Post-mix clipping guard** applies micro-attenuation (0.999 factor) to out-of-range samples rather than hard-clipping, preserving waveform fidelity.
- The **ProfessionalAudioMixer** in [`pipeline.rs`](https://github.com/Zackriya-Solutions/meetily/blob/main/pipeline.rs) processes floating-point buffers at the system sample rate before [`recording_saver.rs`](https://github.com/Zackriya-Solutions/meetily/blob/main/recording_saver.rs) writes the final 16-bit or 24-bit output.

## Frequently Asked Questions

### What is soft scaling in audio processing?

Soft scaling refers to techniques that gradually adjust audio amplitude using proportional gain reduction and smoothing algorithms, rather than abruptly clipping or hard-limiting signals that exceed threshold levels. This approach prevents the harsh distortion artifacts characteristic of digital clipping while maintaining natural-sounding dynamics.

### How does RMS-based ducking prevent distortion?

RMS-based ducking calculates the root-mean-square energy of incoming audio streams to determine their relative loudness. When combining two sources would exceed safe levels, the mixer reduces the gain of the louder stream proportionally, keeping the total amplitude below the clipping point without silencing either source completely.

### Why is headroom preservation necessary when mixing digital audio?

Headroom preservation maintains a safety buffer—typically -3 dB—below the maximum digital level (0 dBFS). This margin accommodates inter-sample peaks that occur during digital-to-analog conversion and prevents distortion when multiple audio sources sum together, ensuring the final recording remains clean even during unexpected volume spikes.

### Where is the ProfessionalAudioMixer implemented in the Meetily codebase?

The ProfessionalAudioMixer struct and its soft-scaling implementation are located in [[`frontend/src-tauri/src/audio/pipeline.rs`](https://github.com/Zackriya-Solutions/meetily/blob/main/frontend/src-tauri/src/audio/pipeline.rs)](https://github.com/Zackriya-Solutions/meetily/blob/main/frontend/src-tauri/src/audio/pipeline.rs), specifically around line 147. The mixer is instantiated by the recording manager and consumed by the recording saver to process audio buffers between capture and persistence.