Recent

Author Topic: [SOLVED] System Audio Mute  (Read 1275 times)

pcurtis

  • Hero Member
  • *****
  • Posts: 951
[SOLVED] System Audio Mute
« 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.
« Last Edit: October 30, 2020, 02:19:50 am by pcurtis »
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: System Audio Mute
« Reply #1 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
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

pcurtis

  • Hero Member
  • *****
  • Posts: 951
No error message.
The call to  endpointVolume.SetMute(bState, nil) returns 0.
It just doesn't mute. SetVolume....... for example works.
« Last Edit: October 28, 2020, 06:22:38 pm by pcurtis »
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: System Audio Mute
« Reply #3 on: October 28, 2020, 09:47:44 pm »
what controls are you using to address the audio hardware on the pc ?
The only true wisdom is knowing you know nothing

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: System Audio Mute
« Reply #4 on: October 29, 2020, 07:05:34 am »
What do you mean?
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: System Audio Mute
« Reply #5 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.
The only true wisdom is knowing you know nothing

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: System Audio Mute
« Reply #6 on: October 29, 2020, 02:19:00 pm »
All the code is in the attachment with the opening post.
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: System Audio Mute
« Reply #7 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.
The only true wisdom is knowing you know nothing

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: System Audio Mute
« Reply #8 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..........
« Last Edit: October 30, 2020, 12:56:47 am by pcurtis »
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: System Audio Mute
« Reply #9 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
The only true wisdom is knowing you know nothing

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: System Audio Mute
« Reply #10 on: October 30, 2020, 02:18:42 am »
Perfect. Thanks.
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

 

TinyPortal © 2005-2018