Lazarus

Programming => General => Topic started by: pcurtis on October 28, 2020, 02:51:39 pm

Title: [SOLVED] System Audio Mute
Post by: pcurtis on October 28, 2020, 02:51:39 pm
Hi All,

I'm having problems muting audio on W10 using MMDev.

Can anyone see whats wrong? (see attachment)

Thanks in advance.
Title: Re: System Audio Mute
Post by: Jurassic Pork on October 28, 2020, 03:52:59 pm
hello,
it works on my computer (lazarus 2.0.10  fpc 3.2.0  Windows 10  Audio chip Realtek). Have you an error message ?


Friendly, J.P
Title: Re: System Auhttps://forum.lazarus.freepascal.org/Themes/default/images/dio Mute
Post by: pcurtis on October 28, 2020, 04:12:57 pm
No error message.
The call to  endpointVolume.SetMute(bState, nil) returns 0.
It just doesn't mute. SetVolume....... for example works.
Title: Re: System Audio Mute
Post by: jamie on October 28, 2020, 09:47:44 pm
what controls are you using to address the audio hardware on the pc ?
Title: Re: System Audio Mute
Post by: pcurtis on October 29, 2020, 07:05:34 am
What do you mean?
Title: Re: System Audio Mute
Post by: jamie on October 29, 2020, 01:41:16 pm
What do you mean?

Hmm I thought that was clear?

Working with sound on a pc isn't a pascal or laz thing so u must be using a lib, unit, functions u found somewhere ?
U need to show the code in more complete format so u can be helped.  Otherwise here we are rolling dice.
Title: Re: System Audio Mute
Post by: pcurtis on October 29, 2020, 02:19:00 pm
All the code is in the attachment with the opening post.
Title: Re: System Audio Mute
Post by: jamie on October 29, 2020, 11:42:21 pm
your problem deals with the fact that Windows which uses a C/C++ among others that SetMute function does not treat a non 0 value as true but is looking for a specific value of 1 for true.,.


 Infact, I wonder if the declaration of the function is even correct?

 The NOT operator isn't flipping the first the first bit but instead flipping the whole container holding the boolean..
 
 so you either have a a 0 for false or -1 for true..

 that function does not work with -1 for true and because that field is most likly not treated as a boolean it should be numerical instead

So to recap on this, if you still want to use a boolean, use a LONGBOOL for the definitions instead and do this just prior to using it in the function
Code: Pascal  [Select][+][-]
  1.   bState :=    not bstate;
  2.   LongInt(bState):=Longint(bState) and 1;
  3.   endpointVolume.SetMute(bstate, nil);          
  4.  

A function could be written or a helper for to force a return of 1 for true i guess.
Title: Re: System Audio Mute
Post by: pcurtis on October 30, 2020, 12:44:03 am
var
  bState : LongBool;

 bState := True;  // bState := False;
  LongInt(bState) := Longint(bState) and 1;
  endpointVolume.SetMute(bState, nil);

Still does nothing..........
Title: Re: System Audio Mute
Post by: jamie on October 30, 2020, 01:53:15 am
did you change the definition in the SetMute  interface too ?
Code: Pascal  [Select][+][-]
  1.   function SetMute(bMute:LongBool; pguidEventContext: PGUID): Integer; stdcall;
  2.  

you see where i also changed the define ? its LONGBOOL now, not boolean

You example did not work here at first, the changes I showed you corrects it

You can also hard code it  in the call
SetMute(LongBool(1).....

or
SeMute(LongBool(0) for false
Title: Re: System Audio Mute
Post by: pcurtis on October 30, 2020, 02:18:42 am
Perfect. Thanks.
TinyPortal © 2005-2018