]> code.delx.au - pulseaudio/commitdiff
add support for dB volumes
authorLennart Poettering <lennart@poettering.net>
Wed, 1 Sep 2004 12:48:47 +0000 (12:48 +0000)
committerLennart Poettering <lennart@poettering.net>
Wed, 1 Sep 2004 12:48:47 +0000 (12:48 +0000)
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@166 fefdeb5f-60dc-0310-8127-8f9354f1896f

doc/todo
polyp/Makefile.am
polyp/cli-text.c
polyp/sample.c
polyp/sample.h

index cc9c333d68e3876f56276e9bbb58739792d12ddd..107fc443c10fab7ebec0289f3fbfe4da417a3eaa 100644 (file)
--- a/doc/todo
+++ b/doc/todo
@@ -14,7 +14,6 @@
 - remove all gcc warnings
 - esd compatible startup script or personality
 - limit number of concurrent streams
-- decibel macros
 
 ** later ***
 - xmlrpc/http
index bd71f5509333c4cde24b3e5caee35c7ad045aa3a..6fb7a583e816e7ff6450d4761d92d443be6b1cf5 100644 (file)
@@ -19,8 +19,8 @@
 
 AM_CFLAGS=-D_GNU_SOURCE -I$(top_srcdir) $(PTHREAD_CFLAGS)
 #AM_CFLAGS+= -DDLSEARCHDIR=\"$(pkglibdir)\" 
-AM_LDADD=$(PTHREAD_LIBS)
-AM_LIBADD=$(PTHREAD_LIBS)
+AM_LDADD=$(PTHREAD_LIBS) -lm
+AM_LIBADD=$(PTHREAD_LIBS) -lm
 
 polypincludedir=$(includedir)/polyp
 
@@ -276,7 +276,7 @@ module_cli_la_LIBADD = $(AM_LIBADD) libcli.la libiochannel.la
 
 module_sine_la_SOURCES = module-sine.c
 module_sine_la_LDFLAGS = -module -avoid-version
-module_sine_la_LIBADD = $(AM_LIBADD) -lm
+module_sine_la_LIBADD = $(AM_LIBADD)
 
 if !X_DISPLAY_MISSING
 module_x11_bell_la_SOURCES = module-x11-bell.c
index fa1ccdf944c632ae5ae64cb1bb087dbcc77f5b3f..18a99cfabaad5cf1439a0a425359c650abc97b83 100644 (file)
@@ -93,10 +93,11 @@ char *pa_sink_list_to_string(struct pa_core *c) {
         assert(sink->monitor_source);
         pa_strbuf_printf(
             s,
-            "  %c index: %u\n\tname: <%s>\n\tvolume: <0x%04x>\n\tlatency: <%u usec>\n\tmonitor_source: <%u>\n\tsample_spec: <%s>\n",
+            "  %c index: %u\n\tname: <%s>\n\tvolume: <0x%04x> (%0.2fdB)\n\tlatency: <%u usec>\n\tmonitor_source: <%u>\n\tsample_spec: <%s>\n",
             c->default_sink_name && !strcmp(sink->name, c->default_sink_name) ? '*' : ' ',
             sink->index, sink->name,
             (unsigned) sink->volume,
+            pa_volume_to_dB(sink->volume),
             pa_sink_get_latency(sink),
             sink->monitor_source->index,
             ss);
@@ -188,11 +189,12 @@ char *pa_sink_input_list_to_string(struct pa_core *c) {
         pa_sample_spec_snprint(ss, sizeof(ss), &i->sample_spec);
         assert(i->sink);
         pa_strbuf_printf(
-            s, "    index: %u\n\tname: <%s>\n\tsink: <%u>\n\tvolume: <0x%04x>\n\tlatency: <%u usec>\n\tsample_spec: <%s>\n",
+            s, "    index: %u\n\tname: <%s>\n\tsink: <%u>\n\tvolume: <0x%04x> (%0.2fdB)\n\tlatency: <%u usec>\n\tsample_spec: <%s>\n",
             i->index,
             i->name,
             i->sink->index,
             (unsigned) i->volume,
+            pa_volume_to_dB(i->volume),
             pa_sink_input_get_latency(i),
             ss);
 
index edfe195941623fe1ee208a9be96898df23e3ef36..3019f93b872245402087eac210c594553b9b7629 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <stdio.h>
 #include <assert.h>
+#include <math.h>
 
 #include "sample.h"
 
@@ -104,3 +105,17 @@ pa_volume_t pa_volume_multiply(pa_volume_t a, pa_volume_t b) {
 
     return (pa_volume_t) p;
 }
+
+pa_volume_t pa_volume_from_dB(double f) {
+    if (f <= -200)
+        return PA_VOLUME_MUTED;
+
+    return (pa_volume_t) (pow(10, f/20)*PA_VOLUME_NORM);
+}
+
+double pa_volume_to_dB(pa_volume_t v) {
+    if (v == PA_VOLUME_MUTED)
+        return -200;
+
+    return 20*log10((double) v/PA_VOLUME_NORM);
+}
index 28ae51eabba38d98895405c875050b7b4f294f0a..ca462071716ab2b8c7d4daebfdc2cb482b8b9377 100644 (file)
@@ -102,6 +102,12 @@ typedef uint32_t pa_volume_t;
 /** Multiply two volumes specifications, return the result. This uses PA_VOLUME_NORM as neutral element of multiplication. */
 pa_volume_t pa_volume_multiply(pa_volume_t a, pa_volume_t b);
 
+/** Convert volume from decibel to linear level */
+pa_volume_t pa_volume_from_dB(double f);
+
+/** Convert volume from linear level to decibel */
+double pa_volume_to_dB(pa_volume_t v);
+
 PA_C_DECL_END
 
 #endif