Skip to content

Fix mono audio levels, early clipping, and noisy mono mic recordings - #1132

Merged
jonoomph merged 3 commits into
developfrom
audio-mixing-levels
Oct 21, 2026
Merged

jonoomph merged 3 commits into
developfrom
audio-mixing-levels

Conversation

@jonoomph

Copy link
Copy Markdown
Member

This PR fixes a few audio level problems that made mic recordings sound too quiet, and in some cases noisy.

  • Mono audio at full level: mono sources used to play 3 dB quieter in stereo projects, because FFmpeg's default mono to stereo mix lowers each side. Mono is now copied to both sides at full level (in FrameMapper and FFmpegWriter), matching normal media players. Mono mic recordings are the most common case.
  • No early clipping: FrameMapper and the first FFmpegWriter resample converted audio to 16-bit integers, which clipped loud sources (above 0 dBFS) before clip volume and mixing were applied. Audio now stays float until the encoder needs a different format.
  • Cleaner mono mic recordings: mono recordings asked the device for a single channel, which some Windows drivers seem to convert badly (a tester heard loud noise in mono, while stereo worked). AudioRecorder now opens stereo devices as stereo and keeps the first channel itself. Mono-only devices still open as mono, and recording them in stereo now fills both sides instead of leaving the right side silent.
  • Builds without OpenCV: the EffectMask tests used OpenCV-only classes, so test builds without OpenCV failed. Those parts are now guarded with USE_OPENCV.

Mono sources mapped to stereo were 3 dB quieter than in other players,
because FFmpeg's default mono to stereo mix lowers each side by 3 dB.
FrameMapper and FFmpegWriter now copy mono to both sides at full level.

FrameMapper and the first FFmpegWriter resample also converted audio to
16-bit integers, which clipped loud sources (above 0 dBFS) before clip
volume and mixing were applied. Audio now stays float until the encoder
needs a different sample format.
The EffectMask tests used Tracker and ObjectDetection classes, which are
only built with OpenCV, so builds without OpenCV failed to compile the
tests. Guard those includes, helpers and test cases with USE_OPENCV.
Mono recordings asked the audio device for a single channel. Some Windows
drivers convert badly when asked for fewer channels than the device has,
which a tester saw as loud noise in mono recordings while stereo worked.

The recorder now opens stereo devices as stereo and keeps the first
channel itself for mono recordings. Mono-only devices are still opened as
mono (the audio backends clamp the request), and recording such a device
in stereo now repeats its channel instead of leaving the right side silent.
If a driver refuses to open as stereo, the requested channel count is used.
@jonoomph

Copy link
Copy Markdown
Member Author

@codecov

codecov Bot commented Oct 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.05848% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.01%. Comparing base (7976991) to head (4b0ae8d).

Files with missing lines Patch % Lines
src/AudioRecorder.cpp 37.03% 17 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1132      +/-   ##
===========================================
+ Coverage    73.91%   74.01%   +0.10%     
===========================================
  Files          275      275              
  Lines        36995    37119     +124     
===========================================
+ Hits         27344    27475     +131     
+ Misses        9651     9644       -7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@jonoomph
jonoomph merged commit 6a54ea7 into develop Oct 21, 2026
20 checks passed
@jonoomph
jonoomph deleted the audio-mixing-levels branch October 21, 2026 04:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant