# How the ProfessionalAudioMixer Uses RMS-Based Ducking to Prevent System Audio from Drowning Out Microphone Input

> Learn how ProfessionalAudioMixer uses RMS-based ducking to prevent system audio from drowning out your mic. Discover its pre-scaling and soft-clipping techniques for clear audio.

- Repository: [Zackriya Solutions/meetily](https://github.com/Zackriya-Solutions/meetily)
- Tags: how-to-guide
- Published: 2026-07-10

---

**The ProfessionalAudioMixer in Meetily implements RMS-based ducking by pre-scaling system audio to approximately 70% amplitude before mixing with microphone input, then applies proportional soft-clipping to maintain headroom and prevent clipping.**

Meetily's audio processing pipeline, located in the Zackriya-Solutions/meetily repository, handles real-time mixing of microphone and system audio streams through a Rust-based backend. The **RMS-based ducking** strategy implemented in [`pipeline.rs`](https://github.com/Zackriya-Solutions/meetily/blob/main/pipeline.rs) ensures that speech remains intelligible during screen recording or system audio capture by dynamically reducing system audio levels relative to microphone input.

## Understanding the Audio Pipeline Architecture

### Window Extraction with AudioMixerRingBuffer

The mixing process begins with the `AudioMixerRingBuffer`, which accumulates raw samples from both microphone and system streams until sufficient data is available for a processing window. According to the source code in [`frontend/src-tauri/src/audio/pipeline.rs`](https://github.com/Zackriya-Solutions/meetily/blob/main/frontend/src-tauri/src/audio/pipeline.rs), the `extract_window` method (lines 101-138) returns two equally-sized float buffers representing approximately 50ms of audio data when both streams have enough samples available.

### The ProfessionalAudioMixer Implementation

The `ProfessionalAudioMixer` struct handles the actual mixing logic, processing these fixed-size windows to produce a balanced output. This component operates within the `AudioPipeline::run` method and serves dual purposes: feeding the VAD-driven transcription pipeline and writing to the recording output.

## How RMS-Based Ducking Works in pipeline.rs

### Pre-Scaling System Audio (70% Amplitude Reduction)

Before summing the audio buffers, the mixer applies the core ducking logic in `mix_window` (lines 65-71). The system audio buffer is deliberately **pre-scaled to approximately 70%** of its original amplitude to create headroom for the microphone signal. This scaling mimics an RMS-based ducking gain behavior where the system level remains suppressed relative to the microphone's RMS level, preventing loud system sounds from overwhelming speech.

### Proportional Soft-Clipping for Dynamic Range Control

After combining the pre-scaled system audio with the full-scale microphone buffer, the mixer checks for samples exceeding the ±1.0 digital audio clipping threshold. As implemented in lines 74-83 of [`pipeline.rs`](https://github.com/Zackriya-Solutions/meetily/blob/main/pipeline.rs), when clipping is detected, the entire sum is **scaled down proportionally** using the formula `sum / sum_abs`. This technique preserves the relative balance between microphone and system audio while keeping the overall RMS level within acceptable bounds, avoiding the harsh distortion associated with hard clipping.

## Implementation Details and Code Examples

The following Rust code demonstrates how to instantiate the mixer and process audio windows:

```rust
let mut mixer = ProfessionalAudioMixer::new(sample_rate);
let mixed = mixer.mix_window(&mic_window, &system_window);

```

Within the actual audio pipeline, this mixing occurs inside the main processing loop. The excerpt below from `AudioPipeline::run` shows how the ring buffer coordinates with the mixer to apply RMS-based ducking:

```rust
while self.ring_buffer.can_mix() {
    if let Some((mic_window, sys_window)) = self.ring_buffer.extract_window() {
        // Apply RMS-based ducking and soft-clipping
        let mixed_clean = self.mixer.mix_window(&mic_window, &sys_window);
        // …send `mixed_clean` to VAD / recording…
    }
}

```

## Summary

- The **ProfessionalAudioMixer** in [`frontend/src-tauri/src/audio/pipeline.rs`](https://github.com/Zackriya-Solutions/meetily/blob/main/frontend/src-tauri/src/audio/pipeline.rs) processes fixed 50ms windows extracted by the `AudioMixerRingBuffer`.
- **RMS-based ducking** is achieved by pre-scaling system audio to approximately 70% amplitude before mixing, creating headroom for microphone input.
- **Proportional soft-clipping** (lines 74-83) prevents digital distortion by scaling the entire mixed buffer when samples exceed ±1.0.
- The mixed output supports both VAD-driven transcription and simultaneous recording without requiring complex dynamic-range compression algorithms.

## Frequently Asked Questions

### What is RMS-based ducking in audio processing?

RMS-based ducking is a technique that reduces the amplitude of one audio signal based on the root mean square level of another signal. In Meetily's implementation, the system audio acts as the ducked signal while the microphone input serves as the priority signal, ensuring speech remains prominent during mixed recording sessions.

### Why does Meetily pre-scale system audio to 70% instead of using a dynamic compressor?

The 70% pre-scaling approach provides a lightweight, deterministic solution that doesn't require continuous RMS calculations or attack/release parameters. According to the source code in [`pipeline.rs`](https://github.com/Zackriya-Solutions/meetily/blob/main/pipeline.rs), this static reduction creates sufficient headroom for typical microphone levels while avoiding the computational overhead of a full dynamic-range compressor.

### How does the soft-clipping mechanism preserve audio quality?

The proportional soft-clipping implemented in lines 74-83 of [`pipeline.rs`](https://github.com/Zackriya-Solutions/meetily/blob/main/pipeline.rs) scales the entire mixed buffer uniformly when clipping is detected, rather than truncating individual samples. This preserves the relative phase and amplitude relationships between microphone and system audio, preventing the "radio break" distortion associated with hard limiting.

### Where can I find the ProfessionalAudioMixer implementation in the Meetily codebase?

The `ProfessionalAudioMixer` struct and its `mix_window` method 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) within the Zackriya-Solutions/meetily repository. The ducking logic appears in lines 65-71, while the soft-clipping implementation occupies lines 74-83.