SetSoundVolumeMBS does not work?

I have this code, which does nothing:

Var Value As Integer //Between 0 and 100

if Value<1 then //Mute
  SetSoundVolumeMBS 0
  SetSoundMuteMBS True
Else //Unmute
  SetSoundMuteMBS False
  SetSoundVolumeMBS Value/100
end if

For example, even when value=0, I can still listen to the running music.
It’s on MacOS 12. Does it works for someone else or it’s just broken?

1 Like

@Christian_Schmitz

1 Like

I can’t make it working on Windows, either.

let me look. This is quite old code.

SetSoundVolumeMBS 0.5

on macOS works just fine.
You don’t need to do mute, I think.

On Mac this sets kAudioDevicePropertyVolumeScalar for the system sound device and you can do that yourself with CoreAudioMBS class.

On which MacOS version have you tried?
I just tried your exact code and it still does nothing. MacOS 12 here.

I’ll try later with the CoreAudioMBS class.
Ultimately, I need a solution for Windows.

Thank you.

Monterey 12.1.
On windows, it changes the mixer, which you can also change with WindowsAudioMixerMBS class.

But if macOS or Windows changed APIs or permissions to do this, that may not work.

That’s useful. I always wonder about that and never found a definitive answer (never searched enough, either).

Same as me…

So if we have the same OS version, it shouldn’t be a permission issue :thinking:
Could it be related to our configuration? Like you’re trying on the built-in speaker and I’m attempting on the Line-out, giving different results?

I’ll check this.

Thank you.

So, I tested on a real Windows 10 computer (no longer using Boot Camp) and the WindowsAudioMixerMBS class gives me these results:

(the last number is the ticks, so I can monitor that the app didn’t hang. The other numbers are the properties of the WindowsAudioMixer object (code below)).
Whatever volume I set, the numbers don’t change (except the ticks).

Here’s the code, in a timer (“wam” is the WindowsAudioMixer property of the window):

if wam=nil then wam=new WindowsAudioMixerMBS

Label1.Text="DD: "+wam.DestinationDigitalVolume.ToString+EndOfLine+"DHP: "+wam.DestinationHeadPhonesVolume.ToString+EndOfLine+"DL: "+wam.DestinationLineVolume.ToString+EndOfLine+"DM: "+wam.DestinationMonitorVolume.ToString+EndOfLine+"DS: "+wam.DestinationSpeakersVolume.ToString+EndOfLine+"DT: "+wam.DestinationTelephoneVolume.ToString+EndOfLine+"DVI: "+wam.DestinationVoiceInVolume.ToString+EndOfLine+"DWI: "+wam.DestinationWaveInVolume.ToString+EndOfLine+"SA: "+wam.SourceAnalogVolume.ToString+EndOfLine+"SAU: "+wam.SourceAuxiliaryVolume.ToString+EndOfLine+"SCD: "+wam.SourceCompactDiscVolume.ToString+EndOfLine+"SD: "+wam.SourceDigitalVolume.ToString+EndOfLine+"SM: "+wam.SourceMicrophoneVolume.ToString+EndOfLine+"SPCS: "+wam.SourcePCSpeakerVolume.ToString+EndOfLine+"SS: "+wam.SourceSynthesizerVolume.ToString+EndOfLine+"ST: "+wam.SourceTelephoneVolume.ToString+EndOfLine+"SWO: "+wam.SourceWaveOutVolume.ToString+EndOfLine+System.Ticks.ToString

if wam.DestinationDigitalMute or wam.DestinationHeadPhonesMute or wam.DestinationLineMute or wam.DestinationMonitorMute or wam.DestinationSpeakersMute or wam.DestinationTelephoneMute or wam.DestinationVoiceInMute or wam.DestinationWaveInMute or wam.SourceWaveOutMute or wam.SourceTelephoneMute or wam.SourceSynthesizerMute or wam.SourcePCSpeakerMute or wam.SourceMicrophoneMute or wam.SourceLineMute or wam.SourceDigitalMute or wam.SourceCompactDiscMute or wam.SourceAuxiliaryMute or wam.SourceAnalogMute then break

Therefore, I also get wrong results here.

For the Windows 10 tests, I tried on Boot Camp, a real PC and Parallels Desktop (32 bits there).

Does this exact code give you better results?
Plugin version=21.5, if it matters.

Here’s a Xojo project showing the issue, on my server:
https://www.lebarbu.ch/partages/AudioMixer.xojo_binary_project

Could someone please try it on Windows 10 and tell me whether I’m alone with this trouble on all my computers?
I’m rather annoyed to not be trusted because it appears to work for you, Christian, but it doesn’t work on all my Windows 10 devices.

Yes, it may be a configuration thing. Maybe it only works for stereo output.

The function and classes are >10 years old and Microsoft may have changed something.

I can look again in the next days.

1 Like

Thank you.

Hello Christian, any news on this?

Well, the mixer class seems to work here:

I can move the control for the app on the right side and the percent fraction changes in the app.
So the plugin can report the settings correctly.

Also I added a muted flag to show:

Sub Action() Handles Action
  If wam=Nil Then wam=New WindowsAudioMixerMBS
  
  Label1.Text="DD: "+wam.DestinationDigitalVolume.ToString+EndOfLine+"DHP: "+wam.DestinationHeadPhonesVolume.ToString+EndOfLine+"DL: "+wam.DestinationLineVolume.ToString+EndOfLine+"DM: "+wam.DestinationMonitorVolume.ToString+EndOfLine+"DS: "+wam.DestinationSpeakersVolume.ToString+EndOfLine+"DT: "+wam.DestinationTelephoneVolume.ToString+EndOfLine+"DVI: "+wam.DestinationVoiceInVolume.ToString+EndOfLine+"DWI: "+wam.DestinationWaveInVolume.ToString+EndOfLine+"SA: "+wam.SourceAnalogVolume.ToString+EndOfLine+"SAU: "+wam.SourceAuxiliaryVolume.ToString+EndOfLine+"SCD: "+wam.SourceCompactDiscVolume.ToString+EndOfLine+"SD: "+wam.SourceDigitalVolume.ToString+EndOfLine+"SM: "+wam.SourceMicrophoneVolume.ToString+EndOfLine+"SPCS: "+wam.SourcePCSpeakerVolume.ToString+EndOfLine+"SS: "+wam.SourceSynthesizerVolume.ToString+EndOfLine+"ST: "+wam.SourceTelephoneVolume.ToString+EndOfLine+"SWO: "+wam.SourceWaveOutVolume.ToString+EndOfLine+System.Ticks.ToString
  
  If wam.DestinationDigitalMute Or wam.DestinationHeadPhonesMute Or wam.DestinationLineMute Or wam.DestinationMonitorMute Or wam.DestinationSpeakersMute Or wam.DestinationTelephoneMute Or wam.DestinationVoiceInMute Or wam.DestinationWaveInMute Or wam.SourceWaveOutMute Or wam.SourceTelephoneMute Or wam.SourceSynthesizerMute Or wam.SourcePCSpeakerMute Or wam.SourceMicrophoneMute Or wam.SourceLineMute Or wam.SourceDigitalMute Or wam.SourceCompactDiscMute Or wam.SourceAuxiliaryMute Or wam.SourceAnalogMute Then 
    label1.Text = label1.Text + EndOfLine+"muted!"
    
    Break
  End If
  
End Sub

and it shows the flag here.

Please be aware that the class may not do what you need. But from what it should report, it seems to work fine here.

Thanks for your answer.
That’s really weird; it clearly doesn’t work on my side.
First, I’m noticing you don’t use my example project the way I do. I don’t open the volume mixer at all, but rather change the overall volume using standard volume keys on the keyboard. Does this make any difference?
I’ll try using the volume mixer, just to see, but it won’t suit my needs.

The strange thing is, I’ve tried on several computers (1 physical Windows 10 laptop, 1 MacBook Air with Boot Camp (Windows 10) and 1 virtual machine (Parallels Desktop, Windows 10 32 bits)) and they all show only zeroes for all fields and won’t detect muting (again, using the keyboard’s volume keys).
These systems are all up to date; yours are too? (I’m thinking perhaps you tried on an not updated system; that would perhaps explain the difference?).

It’s disappointing when all tests one makes show (prove) a thing but someone else gets different proofs; it makes me looking like a liar or such, but I’d hate to lie. That’s why I have to find what’s going on.
Thanks again.

You are certainly right, that it doesn’t work well for you.
I think this class using the old mixer interface from Windows may have worked years ago, but now in Windows 10 it seems to only control sound within the application.

Please look for another way to control sound.

Thanks for your replies and explanations.
Dead end, then. I’ve already searched several times and only found similar, unanswered, questions or answers I can’t coerce in Xojo code.

I use a shell command to nircmd.

If it helps. Works great for switching audio sources etc.

Will give it a try, thank you!

After checking its documentation, it seems NirCmd, albeit having a lot of features, can only set the sound volume, not get and report it. And that’s what I’m looking for.
Thanks anyway.