Skip to content

Add constant volume output setting#125

Open
Gleek wants to merge 1 commit into
kamillobinski:mainfrom
Gleek:main
Open

Add constant volume output setting#125
Gleek wants to merge 1 commit into
kamillobinski:mainfrom
Gleek:main

Conversation

@Gleek
Copy link
Copy Markdown

@Gleek Gleek commented May 29, 2026

  • Adds a new Output setting for Constant volume, off by default
  • Compensates Thock playback gain against the current system output volume
  • Reads output volume from CoreAudio, preferring dB volume and falling back to virtual/scalar volume properties
  • Keeps compensation internal to Thock without changing macOS system volume

Fixes #74

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 29, 2026

Greptile Summary

This PR adds a "Constant volume" setting that compensates Thock's playback gain against the current macOS system output volume, keeping keyboard sounds at a consistent perceived level when the user adjusts system volume. It reads output volume via CoreAudio (preferring dB, falling back to VirtualMainVolume and scalar), stores the preference in UserDefaults, and exposes a toggle in SoundSettingsView.

  • AudioDeviceManager grows three new private helpers to read system output volume via kAudioDevicePropertyVolumeDecibels, kAudioHardwareServiceDeviceProperty_VirtualMainVolume, and kAudioDevicePropertyVolumeScalar, called before each sound is scheduled.
  • SoundManager caches systemOutputVolume and applies a compensation formula (appVolume / pow(outputVolume, 1.08)) in the real-time render callback, with a maximumGain cap and a small minimumSystemVolume floor to prevent division near zero.
  • Settings plumbing follows the existing SettingsEngine / SettingsManager / UserDefaults pattern; the UI toggle is integrated into SoundSettingsView with correct onChange and onReceive sync.

Confidence Score: 3/5

The core settings plumbing and UI are solid, but the volume-reading logic in AudioDeviceManager has a fallback path that can silently return a per-channel (not master) volume value, making the compensation wrong on affected devices. The maximumGain ceiling is also set high enough to cause PCM clipping at moderate-low system volumes.

The per-channel dB fallback in getOutputDecibelVolume returns channel 1's reading instead of the master volume when the main channel lacks dB support — on a device where the user has adjusted audio balance, this feeds a wrong divisor into currentRenderVolume(), producing incorrect gain compensation. Separately, the 100× maximumGain cap allows the compensated scalar to climb well into the clipping zone for typical normalized PCM data at moderate-low system volumes (~20–30%), defeating the feature's goal of clean constant-level output. Both issues are in the two most central new files.

AudioDeviceManager.swift (volume-reading priority and per-channel fallback) and SoundManager.swift (maximumGain ceiling and lockless-read scope).

Important Files Changed

Filename Overview
Thock/Managers/AudioDeviceManager.swift Adds CoreAudio volume-reading helpers; per-channel dB fallback (channels 1 & 2) can return non-master volume when audio balance is adjusted, leading to incorrect compensation.
Thock/Managers/SoundManager.swift Adds system-volume snapshot and compensation formula; maximumGain cap of 100× is well above the clipping threshold for normalized PCM data at moderate-low system volumes.
Thock/Engines/SettingsEngine.swift Adds getter/setter pair for constantVolumeEnabled with correct notification posting; no issues.
Thock/Managers/SettingsManager.swift Adds UserDefaults persistence for constantVolumeEnabled with correct default-fallback pattern; no issues.
Thock/Helpers/Localization.swift Adds constantVolume and constantVolumeSubtitle strings for all supported languages; no issues.
Thock/Views/Settings/SoundSettingsView.swift Adds toggle row for constant volume with correct onChange and onReceive sync; no issues.

Reviews (1): Last reviewed commit: "Add constant volume output setting" | Re-trigger Greptile

Comment thread Thock/Managers/AudioDeviceManager.swift Outdated
Comment thread Thock/Managers/SoundManager.swift
Comment thread Thock/Managers/SoundManager.swift
@kamillobinski
Copy link
Copy Markdown
Owner

thanks! ill do the cr tomorrow
we back

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.

Constant Volume

2 participants