@@ -44,7 +44,7 @@ const char* ffDetectSound(FF_MAYBE_UNUSED const FFinstance* instance, FFlist* de
4444 FFSoundDevice * device = (FFSoundDevice * ) ffListAdd (devices );
4545 device -> main = deviceId == mainDeviceId ;
4646 device -> active = false;
47- device -> volume = 0 ;
47+ device -> volume = FF_SOUND_VOLUME_UNKNOWN ;
4848 ffStrbufInitF (& device -> identifier , "%u" , (unsigned ) deviceId );
4949 ffStrbufInit (& device -> name );
5050
@@ -67,6 +67,34 @@ const char* ffDetectSound(FF_MAYBE_UNUSED const FFinstance* instance, FFlist* de
6767 kAudioObjectPropertyElementMain
6868 }, 0 , NULL , & dataSize , & volume ) == kAudioHardwareNoError )
6969 device -> volume = (uint8_t ) (volume * 100 + 0.5 );
70+ else
71+ {
72+ // Try detecting volume from channels
73+ uint32_t channels [2 ];
74+ dataSize = sizeof (channels );
75+ if (AudioObjectGetPropertyData (deviceId , & (AudioObjectPropertyAddress ){
76+ kAudioDevicePropertyPreferredChannelsForStereo ,
77+ kAudioObjectPropertyScopeOutput ,
78+ kAudioObjectPropertyElementMain
79+ }, 0 , NULL , & dataSize , channels ) == kAudioHardwareNoError )
80+ {
81+ dataSize = sizeof (volume );
82+ if (AudioObjectGetPropertyData (deviceId , & (AudioObjectPropertyAddress ){
83+ kAudioDevicePropertyVolumeScalar ,
84+ kAudioObjectPropertyScopeOutput ,
85+ channels [0 ]
86+ }, 0 , NULL , & dataSize , & volume ) == kAudioHardwareNoError )
87+ {
88+ float temp ;
89+ if (AudioObjectGetPropertyData (deviceId , & (AudioObjectPropertyAddress ){
90+ kAudioDevicePropertyVolumeScalar ,
91+ kAudioObjectPropertyScopeOutput ,
92+ channels [1 ]
93+ }, 0 , NULL , & dataSize , & temp ) == kAudioHardwareNoError )
94+ device -> volume = (uint8_t ) ((volume + temp ) / 2 * 100 + 0.5 );
95+ }
96+ }
97+ }
7098 }
7199
72100 CFStringRef name ;
0 commit comments