Recent

Author Topic: Volume control in tray (Virtual Audio device)  (Read 2262 times)

Raskaton

  • New Member
  • *
  • Posts: 12
Volume control in tray (Virtual Audio device)
« on: April 15, 2023, 07:25:04 pm »
Hi!

Planned volume control of my device in local network (some REST API).
And for that need  in tray my sound device, where standart volume regulation appearce.

How can I create virtual audio device? libs? tips? Never try sound in Lazarus.

All I need now is receive position of volume slider in standard tray icon.
For example, user can set his HDMI-vol, default LineOut-Vol and my device volume.
And to another side when my program receive from net new volume value,
volume in tray must be changed accordingly.

Something like distance volume control for musicbox. But not with IR-remote.
But when IR-Remote is used, vol in tray must be synchronised.

metis

  • Sr. Member
  • ****
  • Posts: 300
Re: Volume control in tray (Virtual Audio device)
« Reply #1 on: April 15, 2023, 07:37:43 pm »
On older Windows via MMSystem:
https://forum.lazarus.freepascal.org/index.php/topic,35859.msg237925.html

There are many MixerCodes.
Which OS do You use ?
« Last Edit: April 16, 2023, 04:22:39 pm by metis »
Life could be so easy, if there weren't those f*** Details.
My FFmpeg4Lazarus = FFPlay4Laz + FFGrab4Laz + FFInfo4Laz

Fred vS

  • Hero Member
  • *****
  • Posts: 3168
    • StrumPract is the musicians best friend
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

Raskaton

  • New Member
  • *
  • Posts: 12
Re: Volume control in tray (Virtual Audio device)
« Reply #3 on: April 16, 2023, 09:39:51 pm »
Which OS do You use ?
I need cross-platform solution. Linux and Windows.

On older Windows via MMSystem:
Oh yes, I use it about 15 years ago in Delphi7 to play *.wav files :)
Let`s say Windows7 is my minimum now.

For Linux: https://github.com/fredvs/alsa_mixer
For Windows: https://github.com/fredvs/win_mixer
This is for "master volume", but I need my own device with his own volume.

Someting like:
Code: Pascal  [Select][+][-]
  1.   id := AddSoundDevice('My virtual sound card', 'Output type');  // how can I do this?
  2.   vol_left  := ALSAmixerGetVolume(id, 0);
  3.   vol_right := ALSAmixerGetVolume(id, 1);
  4.  

Screenshot from my Linux (KDE) and Win example:

Fred vS

  • Hero Member
  • *****
  • Posts: 3168
    • StrumPract is the musicians best friend
Re: Volume control in tray (Virtual Audio device)
« Reply #4 on: April 16, 2023, 10:02:34 pm »
For Linux: https://github.com/fredvs/alsa_mixer
For Windows: https://github.com/fredvs/win_mixer
This is for "master volume", but I need my own device with his own volume.

Indeed it is to deal with master volume.
But take a look at the source, it is easy to find the way how to do for each device.   ;)
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

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2050
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Volume control in tray (Virtual Audio device)
« Reply #5 on: April 16, 2023, 10:16:27 pm »
I only can talk for Windows and there it really is a pain the a** to do it in a way you would like to have it done so I would ask:
"What are you doing, why not change the audio output volume of your software instead of dealing with the mixer?"
Dealing with mixer means that you need to enumerate each and every moment since it never is a permanent thing on Windows.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

Raskaton

  • New Member
  • *
  • Posts: 12
Re: Volume control in tray (Virtual Audio device)
« Reply #6 on: April 17, 2023, 11:23:12 pm »
But take a look at the source, it is easy to find the way how to do for each device.   ;)
Yes! I see it now. Just need chage 'default' to 'my_device_name':
Code: Pascal  [Select][+][-]
  1. snd_mixer_attach(hmixcallback, 'default');
Thanks! But this way is only half of my question  ;)
I found this: ALSA Softvol plugin
This is exactly what I need!
Is this plugin in 'libasound.so.2' ? Is it posible create this 'Abstract PCM device' via lib?

What are you doing, why not change the audio output volume of your software instead of dealing with the mixer?
I am planning a program for devices like "Google Nest Audio", "Prestigio Smart Voice" or "LG WK-7Y" etc.
These devices are an audio speaker connected via Wi-Fi to a local network. But you cannot adjust the sound or output sound from the computer.
They also have bluetooth. When enabled, "bluetooth audio device" appears on the computer. Exactly like in my screenshots.
I want to develop a program that will allow you to get the same functionality without turning on bluetooth. Moreover, there are various problems in bluetooth mode.
Also, there can be two or three such devices on the network, and you can only connect bluetooth to one.
Now I only want to adjust the volume of each device, but in the future it would be great to also output sound from a computer via Wi-Fi to several speakers at once or with a left/right channel split into two/four speakers.

On Windows do I have to develop my own audio device driver? This will be a real problem...

Fred vS

  • Hero Member
  • *****
  • Posts: 3168
    • StrumPract is the musicians best friend
Re: Volume control in tray (Virtual Audio device)
« Reply #7 on: April 17, 2023, 11:52:09 pm »
I found this: ALSA Softvol plugin
This is exactly what I need!

I suppose you refer to this: https://alsa.opensrc.org/Softvol
Ha, ok, you want also something that will add your device in the ALSA native mixer.
Sorry but I dont know how to do this.
« Last Edit: April 18, 2023, 12:14:20 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

metis

  • Sr. Member
  • ****
  • Posts: 300
Re: Volume control in tray (Virtual Audio device)
« Reply #8 on: April 18, 2023, 03:23:19 pm »
@Raskaton

Quote
On Windows ...
On WinXP, I use a Mixer that is based on the TAudioMixer by Vit Kovalcik:
-> GoTo "TAudioMixer v.1.70".
Another good MixerCode was made by 'Lake of Soft' at that Time (see attached ZIP-File).
Both are not the newest, but they work, and maybe You can at least get some MixerConstants out of them.

For newer WindowsVersions, a GoogleSearch resulted in EarTrumpet (= Win10+11):
https://sourceforge.net/projects/eartrumpet.mirror/
https://github.com/File-New-Project/EarTrumpet

EDIT:
Here some more Codes, that I've found not only for Win10:
https://webrtc.googlesource.com/src/+/6592f2cfd28c54ef95aa049b44372103fa2ccdbd/modules/audio_device/win/audio_device_core_win.h
https://stackoverflow.com/questions/60309999/finding-the-current-volume-level-of-the-speaker-output-in-windows
https://stackoverflow.com/questions/14306048/controlling-volume-mixer
https://www.c-sharpcorner.com/article/understanding-and-controlling-the-windows-mixer-api/

And an alternative Way, using "the old exe...in system32":
https://github.com/popeen/Classic-Volume-Mixer

Maybe, that's what You're Looking for for Windows.  :)
« Last Edit: April 19, 2023, 02:54:30 pm by metis »
Life could be so easy, if there weren't those f*** Details.
My FFmpeg4Lazarus = FFPlay4Laz + FFGrab4Laz + FFInfo4Laz

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2050
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Volume control in tray (Virtual Audio device)
« Reply #9 on: April 18, 2023, 03:45:39 pm »
Your zip contains the old way of doing. (Microsoft link)
Nowadays (Vista+) it is the Core Audio that should be used.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

metis

  • Sr. Member
  • ****
  • Posts: 300
Re: Volume control in tray (Virtual Audio device)
« Reply #10 on: April 18, 2023, 03:55:26 pm »
I know - Therefore I wrote "On WinXP ... at that Time" + "Both are not the newest, but ...";) 
« Last Edit: April 18, 2023, 04:24:06 pm by metis »
Life could be so easy, if there weren't those f*** Details.
My FFmpeg4Lazarus = FFPlay4Laz + FFGrab4Laz + FFInfo4Laz

 

TinyPortal © 2005-2018