add user volume API

git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@255 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
Lennart Poettering 2004-10-24 00:48:02 +00:00
parent a6471e2602
commit da45617efc
6 changed files with 45 additions and 2 deletions

View file

@ -1,6 +1,7 @@
*** $Id$ ***
*** 0.6 ****
- latency interpolation
- per-channel volume
- unix socket directories include user name
- add sample directory
@ -22,7 +23,7 @@
backends for:
- portaudio (semi-done)
- gstreamer (semi-done)
- alsa-lib
- sdl
- gstreamer (semi-done)
- OSS (esddsp style)

View file

@ -33,7 +33,7 @@ AM_LDADD=$(PTHREAD_LIBS) -lm
AM_LIBADD=$(PTHREAD_LIBS) -lm
EXTRA_DIST = default.pa.in daemon.conf.in client.conf.in depmod.py esdcompat.sh.in
bin_PROGRAMS = polypaudio pacat pactl paplay
bin_PROGRAMS = polypaudio pacat pactl paplay voltest
bin_SCRIPTS = esdcompat.sh
noinst_PROGRAMS = \
mainloop-test \
@ -408,6 +408,10 @@ mainloop_test_SOURCES = mainloop-test.c
mainloop_test_CFLAGS = $(AM_CFLAGS)
mainloop_test_LDADD = $(AM_LDADD) libpolyp-mainloop-@PA_MAJORMINOR@.la libpolyp-@PA_MAJORMINOR@.la
voltest_SOURCES = voltest.c sample.c
voltest_CFLAGS = $(AM_CFLAGS)
voltest_LDADD = $(AM_LDADD)
cpulimit_test_SOURCES = cpulimit-test.c cpulimit.c util.c log.c
cpulimit_test_CFLAGS = $(AM_CFLAGS)
cpulimit_test_LDADD = $(AM_LDADD) libpolyp-mainloop-@PA_MAJORMINOR@.la

View file

@ -27,6 +27,8 @@
/** \file
* Define header version */
PA_C_DECL_BEGIN
/** Return the version of the header files. Keep in mind that this is
a macro and not a function, so it is impossible to get the pointer of
it. */
@ -40,4 +42,6 @@ const char* pa_get_library_version(void);
* PA_API_VERSION undefined. */
#define PA_API_VERSION @PA_API_VERSION@
PA_C_DECL_END
#endif

View file

@ -125,6 +125,22 @@ double pa_volume_to_dB(pa_volume_t v) {
return 20*log10((double) v/PA_VOLUME_NORM);
}
#define USER_DECIBEL_RANGE 30
double pa_volume_to_user(pa_volume_t v) {
double dB = pa_volume_to_dB(v);
return dB < -USER_DECIBEL_RANGE ? 0 : dB/USER_DECIBEL_RANGE+1;
}
pa_volume_t pa_volume_from_user(double v) {
if (v <= 0)
return PA_VOLUME_MUTED;
return pa_volume_from_dB((v-1)*USER_DECIBEL_RANGE);
}
void pa_bytes_snprint(char *s, size_t l, unsigned v) {
if (v >= ((unsigned) 1024)*1024*1024)
snprintf(s, l, "%0.1f GB", ((double) v)/1024/1024/1024);

View file

@ -110,6 +110,12 @@ pa_volume_t pa_volume_from_dB(double f);
/** Convert volume from linear level to decibel. \since 0.4 */
double pa_volume_to_dB(pa_volume_t v);
/** Convert volume to scaled value understandable by the user (between 0 and 1). \since 0.6 */
double pa_volume_to_user(pa_volume_t v);
/** Convert user volume to polypaudio volume. \since 0.6 */
pa_volume_t pa_volume_from_user(double v);
#ifdef INFINITY
#define PA_DECIBEL_MININFTY (-INFINITY)
#else

12
polyp/voltest.c Normal file
View file

@ -0,0 +1,12 @@
#include <stdio.h>
#include <polyp/sample.h>
int main() {
int p;
for (p = 0; p <= 200; p++) {
pa_volume_t v = pa_volume_from_user((double) p/100);
double dB = pa_volume_to_dB(v);
printf("%3i%% = %u = %0.2f dB = %u = %3i%%\n", p, v, dB, pa_volume_from_dB(dB), (int) (pa_volume_to_user(v)*100));
}
}