diff options
author | Lennart Poettering <lennart@poettering.net> | 2009-08-14 20:03:30 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2009-08-14 20:03:30 +0200 |
commit | 0f2a4ed422530b56b3744efe8055540644c0e774 (patch) | |
tree | 4236f23bd76f445b8d7119de0c9e30471673daa5 /src/tests | |
parent | 72d2540e8dc47e101ac9d5ae24eee1b95e8dbcfa (diff) |
volume: guarantee dB/linear conversion is reversible
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/voltest.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/tests/voltest.c b/src/tests/voltest.c index 2dcfa53c..64aec5c6 100644 --- a/src/tests/voltest.c +++ b/src/tests/voltest.c @@ -1,8 +1,33 @@ +/*** + This file is part of PulseAudio. + + PulseAudio is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published + by the Free Software Foundation; either version 2.1 of the License, + or (at your option) any later version. + + PulseAudio is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with PulseAudio; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + #include <stdio.h> #include <pulse/volume.h> #include <pulse/gccmacro.h> +#include <pulsecore/macro.h> + int main(int argc, char *argv[]) { pa_volume_t v; pa_cvolume cv; @@ -60,5 +85,16 @@ int main(int argc, char *argv[]) { printf("After: volume: [%s]; balance: %2.1f (intended: %2.1f) %s\n", pa_cvolume_snprint(s, sizeof(s), &r), k, b, k < b-.05 || k > b+.5 ? "MISMATCH" : ""); } + for (v = PA_VOLUME_MUTED; v <= PA_VOLUME_NORM*2; v += 1) { + + double l = pa_sw_volume_to_linear(v); + pa_volume_t k = pa_sw_volume_from_linear(l); + double db = pa_sw_volume_to_dB(v); + pa_volume_t r = pa_sw_volume_from_dB(db); + + pa_assert(k == v); + pa_assert(r == v); + } + return 0; } |