add support for dB volumes

git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@166 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
Lennart Poettering 2004-09-01 12:48:47 +00:00
parent fa19d6ab7e
commit 9c4fd2a2c7
5 changed files with 28 additions and 6 deletions

View file

@ -14,7 +14,6 @@
- remove all gcc warnings
- esd compatible startup script or personality
- limit number of concurrent streams
- decibel macros
** later ***
- xmlrpc/http

View 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

View 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);

View 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);
}

View 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