Menu

Volume zero is not mute
πŸ“°

Volume zero is not mute

DEV Community: swiftΒ·BenCodeXΒ·2 days ago
#OcYLdsGr
#devtoswift#devto#dev#device#volume
Reading 0:00
15s threshold

With the volume at zero, my MacBook's speakers were still playing. Quietly enough that you only notice in a quiet room, but they were playing.

Zero is a position, not silence

On a Mac, volume and mute are two separate things. Volume is a number between 0 and 1. Mute is a switch. CoreAudio keeps them as two properties on the output device, and nothing forces them to agree.

The number is a position on the device's range, and the device reports that range in decibels. So I asked the built-in speakers for theirs:

var range = AudioValueRange ( ) var size = UInt32 ( MemoryLayout < AudioValueRange > . size ) var a = AudioObjectPropertyAddress ( mSelector : kAudioDevicePropertyVolumeRangeDecibels , mScope : kAudioDevicePropertyScopeOutput , mElement : kAudioObjectPropertyElementMain ) AudioObjectGetPropertyData ( device , & a , 0 , nil , & size , & range ) print ( range . mMinimum , range . mMaximum ) // -63.5 0.0

Enter fullscreen mode

Exit fullscreen mode

The bottom of the range is βˆ’63.5 dB.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.