Bug 61150

Summary: Volumes in dB for artsshell and artsd
Product: [Unmaintained] arts Reporter: Benedikt Gollatz <benedikt>
Component: generalAssignee: Arnold Krille <arnold>
Status: RESOLVED FIXED    
Severity: wishlist    
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Benedikt Gollatz 2003-07-12 20:19:28 UTC
Version:           CVS 20030712 (using KDE Devel)
Installed from:    Compiled sources
Compiler:          gcc version 3.2.1 
OS:          Linux

I thought it were a nice feature if you could get and set the output volume in artsshell and with the command-line option of artsd in decibel and not with these unwieldy floating point values.

The first of the following two patches allows to give something like "-V -6dB" as command-line option to artsd; the second adds the command "volumedb" to artsshell, so "artsshell -- volumedb -6" is possible.

_____

--- arts/soundserver/artsd.cc	2003-07-02 20:36:47.000000000 +0200
+++ arts/soundserver/artsd.cc	2003-07-12 18:45:15.000000000 +0200
@@ -68,5 +68,5 @@
 	fprintf(stderr,"-b <bits>           set number of bits (8 or 16)\n");
 	fprintf(stderr,"-d                  enable full duplex operation\n");
-	fprintf(stderr,"-V <volume>         set output volume\n");
+	fprintf(stderr,"-V <volume>[dB]     set output volume\n");
 	fprintf(stderr,"-D <devicename>     audio device (usually /dev/dsp)\n");
 	fprintf(stderr,"-F <fragments>      number of fragments\n");
@@ -166,5 +166,16 @@
 			case 'f': cfgForceStart = true;
 				break;
-			case 'V': cfgVolume = atof(optarg);
+			case 'V':
+				if(strstr(optarg, "dB") &&
+					strlen(strstr(optarg, "dB")) == 2)
+				{
+					// last two chars of optarg are "dB"
+					char *val =
+						(char *)calloc(strlen(optarg) - 1, sizeof(char));
+					strncpy(val, optarg, strlen(optarg) - 2);
+						cfgVolume = pow(10, atof(val) / 10.0);
+						free(val);
+				} else
+					cfgVolume = atof(optarg);
 				break;
 			case 'h':

_____

--- arts/soundserver/artsshell.cc	2003-03-07 23:07:30.000000000 +0100
+++ arts/soundserver/artsshell.cc	2003-07-12 19:13:30.000000000 +0200
@@ -121,4 +121,5 @@
 #include "tradercheck.h"
 #include <stdio.h>
+#include <math.h>
 
 bool quiet = false;
@@ -146,4 +147,5 @@
   networkbuffers <n>  - increase network buffers by a factor of <n>\n\
   volume [<volume>]   - display/set the volume of the soundserver\n\
+  volumedb [<volume>] - display/set the volume in dB (decibel)\n\
   stereoeffect insert [top|bottom] <name>  - insert stereo effect\n\
   stereoeffect remove <id>  - remove stereo effect\n\
@@ -324,4 +326,16 @@
 }
 
+// set the output volume in dB
+void setDeciBelVolume(Arts::SoundServerV2 server, float volume)
+{
+	setVolume(server, pow(10, volume / 10));
+}
+
+// get the output volume in dB
+float getDeciBelVolume(Arts::SoundServerV2 server)
+{
+	return 10 * log10(getVolume(server));
+}
+
 // stereoeffect command
 void stereoEffect(Arts::SoundServerV2 server, int argc, char **argv)
@@ -473,4 +487,5 @@
   networkbuffers <n>       - increase network buffers by a factor of <n>\n\
   volume [<volume>]        - display/set the volume of the soundserver\n\
+  volumedb [<volume>]      - display/set the volume in dB (decibel)\n\
   stereoeffect insert [top|bottom] <name>  - insert stereo effect\n\
   stereoeffect remove <id> - remove stereo effect\n\
@@ -521,4 +536,13 @@
 	}
 
+	if(!strcmp(argv[0], "volumedb") && (argc == 2)) {
+		setDeciBelVolume(server,atof(argv[1]));
+		return 0;
+	}
+	if(!strcmp(argv[0], "volumedb") && (argc == 1)) {
+		cout << getDeciBelVolume(server) << endl;
+		return 0;
+	}
+
 	if(!strcmp(argv[0], "cpuusage") && (argc == 1)) {
 		printf("%.1f\n",server.cpuUsage());
Comment 1 Arnold Krille 2003-07-22 22:44:25 UTC
While I am currently working on artscontrol and its volumeslider/levelmeter and 
therefor messin around with volume: 
 
Are you aware that your formular is the one for intensity? The formular used in 
artscontrol untill now is the one for the acoustic pressure is 20*log( volume ). 
 
So I am wondering how this could be made configurable... 
 
Arnold 
Comment 2 Arnold Krille 2003-07-25 18:27:38 UTC
Apllied your patch, but it isn't working with negative dB-values since these get "eaten 
up" by the getopt-function... 
 
Arnold 
Comment 3 Arnold Krille 2003-07-25 18:28:12 UTC
:S/apllied/applied/g 
Comment 4 Benedikt Gollatz 2003-07-26 17:34:59 UTC
Using negative dB-volumes in artsd is no problem since getopt() doesn't "eat" 
multiple character command line options ("-XdB"). To use negative values with 
artsshell you have to call "artsshell -- volumedb -X" instead of "artsshell 
volumedb -X"; getopt() will ignore the (false) "-X" command line option now. 
Maybe there should be a warning in the "usage" display.

AFAIK the 20*log(volume) formula is for calculating the absolute dB(A) volume 
[volume_in_dBA = 20*log(acoustic_pressure / 0.00002 Pa)], not for calculating 
the relative dB volume. Since on every mixing console, compressor or amplifier 
increasing the volume 3 dB means approximately doubling the volume, I think my 
formula is right because:

2 = 10^(volume_dB / 10)		| log()
log 2 = volume_dB / 10		| * 10
10 * log 2 = volume_dB
3.0103 = volume_dB
Comment 5 Arnold Krille 2003-07-26 18:31:28 UTC
Subject: Re:  Volumes in dB for artsshell and artsd

On Saturday 26 July 2003 17:35, benedikt@gollatz.net wrote:
> ------- Using negative dB-volumes in artsd is no problem since getopt()
> doesn't "eat" multiple character command line options ("-XdB"). To use
> negative values with artsshell you have to call "artsshell -- volumedb -X"
> instead of "artsshell volumedb -X"; getopt() will ignore the (false) "-X"
> command line option now. Maybe there should be a warning in the "usage"
> display.

I will investigate on this...

> AFAIK the 20*log(volume) formula is for calculating the absolute dB(A)
> volume [volume_in_dBA = 20*log(acoustic_pressure / 0.00002 Pa)], not for
> calculating the relative dB volume. Since on every mixing console,
> compressor or amplifier increasing the volume 3 dB means approximately
> doubling the volume, I think my formula is right because:

But it would be a change for everyone used to the display in artscontrol and I 
think it should be consistent all over aRts. Thats why I finally used factor 
20.

But I will ask the experts on kde-multimedia on this...

Arnold