# How meetily Implements RMS-Based Ducking to Prevent System Audio from Drowning Out Microphone

> Discover how meetily’s ProfessionalAudioMixer uses RMS-based ducking to effectively prevent system audio from overpowering your microphone, maintaining clear speech.

- Repository: [Zackriya Solutions/meetily](https://github.com/Zackriya-Solutions/meetily)
- Tags: internals
- Published: 2026-07-26

---

**The ProfessionalAudioMixer in meetily prevents system audio from drowning out the microphone by pre-scaling system audio to approximately 70% amplitude, creating RMS-based headroom for speech signals while applying proportional soft-clipping to prevent digital distortion.**

The open-source meeting assistant meetily processes simultaneous audio streams from both microphone and system sources to enable comprehensive transcription. To ensure speech remains intelligible during loud system events, the application implements an intelligent **RMS-based ducking** strategy in [`frontend/src-tauri/src/audio/pipeline.rs`](https://github.com/Zackriya-Solutions/meetily/blob/main/frontend/src-tauri/src/audio/pipeline.rs) that balances audio levels before they reach the transcription engine.

## Understanding the ProfessionalAudioMixer Architecture

The audio pipeline collects raw samples in fixed-size windows of approximately 50ms using the **AudioMixerRingBuffer**. Before any mixing occurs, the system ensures both streams have sufficient data by calling `extract_window`, which returns two equally-sized float buffers containing normalized samples for the microphone and system audio respectively. This synchronization happens in lines 101-138 of [`pipeline.rs`](https://github.com/Zackriya-Solutions/meetily/blob/main/pipeline.rs).

### Window Extraction and Buffer Management

The `AudioMixerRingBuffer::extract_window` method blocks until both streams contain enough samples for a complete mixing window. When ready, it extracts the data into separate buffers that maintain the temporal alignment necessary for coherent mixing. Without this synchronized extraction, phase misalignment could cause comb filtering or other artifacts that degrade speech clarity.

## RMS-Based Ducking Through Pre-Scaling

The core ducking mechanism operates on a simple but effective principle: reduce system audio amplitude before mixing to create dynamic headroom for the microphone signal.

In `ProfessionalAudioMixer::mix_window` (lines 65-71), the system audio undergoes deliberate amplitude reduction. While the code applies a scaling factor that effectively targets approximately 70% of original amplitude, this pre-scaling mimics RMS-based ducking behavior by ensuring that microphone signals—which typically contain speech with higher RMS values—remain clearly audible above the reduced system audio level.

## Proportional Soft-Clipping for Distortion Prevention

After scaling and summing the two audio sources, the mixer checks for digital clipping. When any sample in the mixed buffer exceeds the ±1.0 range, the entire window undergoes proportional soft-clipping rather than hard limiting.

As implemented in lines 74-83 of [`pipeline.rs`](https://github.com/Zackriya-Solutions/meetily/blob/main/pipeline.rs), the logic calculates the maximum absolute value of the summed signal and scales the entire buffer down proportionally (`sum / sum_abs`) if clipping is detected. This preserves the relative balance between microphone and system audio while preventing the "radio break" distortion characteristic of hard clipping.

## Implementation Example

The following code demonstrates how the mixer integrates into the audio pipeline according to the meetily source code:

```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 to VAD-driven transcription and recording
        self.process_mixed_audio(mixed_clean);
    }
}

```

To instantiate the mixer for custom processing:

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

```

## Summary

- **Window Synchronization**: The `AudioMixerRingBuffer` ensures microphone and system audio align in 50ms windows before mixing.
- **RMS-Based Ducking**: Pre-scaling system audio to approximately 70% creates headroom for microphone signals without requiring complex compressor algorithms.
- **Soft-Clipping Protection**: Proportional scaling prevents digital distortion while maintaining the relative balance between audio sources.
- **Pipeline Integration**: Mixed output serves both real-time VAD transcription and file recording paths in the meetily application.

## Frequently Asked Questions

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

RMS-based ducking automatically reduces the amplitude of background audio (system audio) when foreground audio (microphone speech) is present. In meetily's implementation, this occurs through pre-scaling the system buffer before mixing, effectively lowering the RMS level of system audio so microphone signals remain prominent in the combined output.

### Why does the ProfessionalAudioMixer scale system audio to 70%?

The 70% scaling factor provides sufficient headroom for typical speech signals while preserving system audio audibility. This static reduction mimics dynamic ducking behavior found in professional broadcast mixers, ensuring that even loud system notifications or music do not overpower the primary microphone content being transcribed.

### How does the mixer prevent clipping when combining audio sources?

Instead of hard-limiting individual samples that exceed ±1.0, the mixer implements proportional soft-clipping by detecting the maximum absolute sample value in the window and scaling the entire buffer down uniformly. This occurs in `ProfessionalAudioMixer::mix_window` at lines 74-83 of [`pipeline.rs`](https://github.com/Zackriya-Solutions/meetily/blob/main/pipeline.rs), preventing distortion while maintaining the intended mix ratio.

### Where is the mixing logic implemented in the meetily codebase?

The complete mixing implementation resides in [`frontend/src-tauri/src/audio/pipeline.rs`](https://github.com/Zackriya-Solutions/meetily/blob/main/frontend/src-tauri/src/audio/pipeline.rs), specifically within the `ProfessionalAudioMixer` struct and its `mix_window` method (lines 65-83), alongside the `AudioMixerRingBuffer::extract_window` method (lines 101-138) that handles synchronized window extraction.