Recent

Author Topic: Change master audio volume of my raspberry?  (Read 2127 times)

Ramses

  • New Member
  • *
  • Posts: 41
Change master audio volume of my raspberry?
« on: January 21, 2021, 02:06:03 am »
As the subject said, what is the easiest way to programmatically change the master volume of my raspberry pie with lazarus? (the same master volume as the one on my task bar)

Thanks!
« Last Edit: January 21, 2021, 02:07:50 am by Ramses »

Fred vS

  • Hero Member
  • *****
  • Posts: 3158
    • StrumPract is the musicians best friend
Re: Change master audio volume of my raspberry?
« Reply #1 on: January 21, 2021, 03:31:33 pm »
As the subject said, what is the easiest way to programmatically change the master volume of my raspberry pie with lazarus? (the same master volume as the one on my task bar)

Thanks!

Hello.

The easiest way is to use a TProcess that uses this command:

Code: Pascal  [Select][+][-]
  1. $ amixer sset 'Master' 50%
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Guva

  • Jr. Member
  • **
  • Posts: 82
Re: Change master audio volume of my raspberry?
« Reply #2 on: January 21, 2021, 03:43:12 pm »
As the subject said, what is the easiest way to programmatically change the master volume of my raspberry pie with lazarus? (the same master volume as the one on my task bar)

Thanks!
Code: [Select]
procedure ExecProgram(cmd:string; OutputStrings:Tstrings);
var
 P:TProcess;
begin
 P:=TProcess.Create(Nil);
 try
   P.CommandLine:=cmd;
   if OutputStrings=Nil then P.Execute  // just run, no output, not waiting
   else
   begin  // run, wait and pipe the output of the program to TStrings
     P.Options:=P.Options+[poWaitOnExit,poUsePipes];
     P.Execute;
     OutputStrings.LoadFromStream(P.Output);
   end;
 except
   // Error
 end;
 P.Free;
end;   

procedure TrackBarSoundChange(Sender: TObject);
//Change Sound Volume of the Master payback
var
 Vol:string;
begin
 if not amixer_Exists then exit;
 Vol:=IntToStr(TrackBarSound.Position)+'%';
 ExecProgram('amixer -c 0 -- sset Master playback '+Vol,Nil)
end;   

Ramses

  • New Member
  • *
  • Posts: 41
Re: Change master audio volume of my raspberry?
« Reply #3 on: January 21, 2021, 05:20:49 pm »
Alright!

Thanks a lot to both of you, it work perfectly!

Fred vS

  • Hero Member
  • *****
  • Posts: 3158
    • StrumPract is the musicians best friend
Re: Change master audio volume of my raspberry?
« Reply #4 on: March 15, 2021, 12:21:08 am »
Hello.

For all Linux OS included the Raspberry Pi OS, you may use alsa_mixer.
https://github.com/fredvs/alsa_mixer

To get and set mixer master volume of sound-card using only libasound.so.2.

A demo is included.

Fre;D
« Last Edit: March 15, 2021, 12:22:42 am by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

 

TinyPortal © 2005-2018