summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2004-09-01 12:48:47 +0000
committerLennart Poettering <lennart@poettering.net>2004-09-01 12:48:47 +0000
commit9c4fd2a2c75b958c22442d2b83e75021bd096be5 (patch)
treea5af70f1907ec09af7ba282b845df15cffb43796
parentfa19d6ab7e2df69902d94a38cc03a183f6d97670 (diff)
add support for dB volumes
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@166 fefdeb5f-60dc-0310-8127-8f9354f1896f
-rw-r--r--doc/todo1
-rw-r--r--polyp/Makefile.am6
-rw-r--r--polyp/cli-text.c6
-rw-r--r--polyp/sample.c15
-rw-r--r--polyp/sample.h6
5 files changed, 28 insertions, 6 deletions
diff --git a/doc/todo b/doc/todo
index cc9c333d..107fc443 100644
--- 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
diff --git a/polyp/Makefile.am b/polyp/Makefile.am
index bd71f550..6fb7a583 100644
--- a/polyp/Makefile.am
+++ b/polyp/Makefile.am
@@ -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
diff --git a/polyp/cli-text.c b/polyp/cli-text.c
index fa1ccdf9..18a99cfa 100644
--- a/polyp/cli-text.c
+++ b/polyp/cli-text.c
@@ -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);
diff --git a/polyp/sample.c b/polyp/sample.c
index edfe1959..3019f93b 100644
--- a/polyp/sample.c
+++ b/polyp/sample.c
@@ -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);
+}
diff --git a/polyp/sample.h b/polyp/sample.h
index 28ae51ea..ca462071 100644
--- a/polyp/sample.h
+++ b/polyp/sample.h
@@ -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