From 0f2a4ed422530b56b3744efe8055540644c0e774 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 14 Aug 2009 20:03:30 +0200 Subject: volume: guarantee dB/linear conversion is reversible --- src/tests/voltest.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/tests') 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 +#endif + #include #include #include +#include + 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; } -- cgit