LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-11-2018, 05:25 AM   #1
shogun1234
Member
 
Registered: May 2004
Posts: 226

Rep: Reputation: 15
Volume sound control


Came across to the lib pyalsaaudio (v0.8.4). When using following code, it prints values [27, 27], but using alsamixer the result shows Master volume level is at 20. What cause such different or how do I interpret the output of pyalsaaudio? Or is there any lib that's more popular if I want to control volume sound?

Thanks

Code:
import alsaaudio

mixer = alsaaudio.Mixer()
vol = mixer.getvolume()
print(vol)
 
Old 02-18-2018, 01:05 AM   #2
treemouse
Member
 
Registered: Jan 2017
Posts: 30

Rep: Reputation: Disabled
According to this, mixer.getvolume() is returning a percent. Presumably this is as a percent of the maximum possible volume, giving it a 0 to 100 scale.

Running alsamixer, it also gives me a percent on a 0 to 100 scale.

So it seems like the two must be using a different maximum volume to base their percents off of.

I suggest experimenting with setting the volume to different levels and seeing what each reports, so you can work out a conversion.

Assuming 0 in alsamixer is also 0 in mixer.getvolume() then your conversion formula would be that every 1% in alsamixer is equal to 1.35% in mixer.getvolume(). To put that in formulas, mixer.getvolume() = 1.35*alsamixer, or alsamixer = mixer.getvolume()/1.35. You can test this by checking to see if 50 in alsamixer is equal to 67 or 68 in mixer.getvolume().
 
Old 02-18-2018, 06:00 AM   #3
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Check volume with amixer instead, alsamixer has its own way to represent volume
Quote:
* The mapping is designed so that the position in the interval is proportional
* to the volume as a human ear would perceive it (i.e., the position is the
* cubic root of the linear sample multiplication factor). For controls with
* a small range (24 dB or less), the mapping is linear in the dB values so
* that each step has the same size visually. Only for controls without dB
* information, a linear mapping of the hardware volume register values is used
* (this is the same algorithm as used in the old alsamixer).
https://github.com/bear24rw/alsa-uti...lume_mapping.c

Code:
amixer sget Master
 
Old 02-20-2018, 10:24 AM   #4
shogun1234
Member
 
Registered: May 2004
Posts: 226

Original Poster
Rep: Reputation: 15
Thanks for the explanation.
 
Old 02-20-2018, 12:38 PM   #5
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Err, I was just quoting a part of source code comments
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
HDMI sound control (volume) software.. macey Linux - Software 0 07-14-2014 12:45 PM
Volume control on Toolbar has no influence over sound hilliard Linux - Newbie 4 03-29-2007 02:39 PM
sound volume control issues hbob49 Linux - Hardware 3 06-27-2006 05:34 PM
No sound until I mixer/volume control jimdaworm Linux - Software 5 09-04-2003 04:26 PM
No sound on rear channels, no volume control chiefjoe Linux - Hardware 7 08-23-2003 05:44 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration