1 /**
2 * @file test/aulevel.c Baresip selftest -- audio levels
3 *
4 * Copyright (C) 2010 - 2017 Creytiv.com
5 */
6
7 #include <re.h>
8 #include <baresip.h>
9 #include "test.h"
10
11
12 #define DEBUG_MODULE "aulevel"
13 #define DEBUG_LEVEL 5
14 #include <re_dbg.h>
15
16
17 #define PREC .6
18
19
test_aulevel(void)20 int test_aulevel(void)
21 {
22 static const struct {
23 int16_t sampv[2];
24 double level;
25 } testv[] = {
26
27 { { 0, -0}, -96.0 },
28 { { 0, 1}, -93.0 },
29 { { 1, -1}, -90.0 },
30 { { 2, -2}, -84.0 },
31 { { 4, -4}, -78.0 },
32 { { 8, -8}, -72.0 },
33 { { 16, -16}, -66.0 },
34 { { 32, -32}, -60.0 },
35 { { 64, -64}, -54.0 },
36 { { 128, -128}, -48.0 },
37 { { 256, -256}, -42.0 },
38 { { 512, -512}, -36.0 },
39 { { 1024, -1024}, -30.0 },
40 { { 2048, -2048}, -24.0 },
41 { { 4096, -4096}, -18.0 },
42 { { 8192, -8192}, -12.0 },
43 { {16384, -16384}, -6.0 },
44 { {32767, -32768}, 0.0 },
45 };
46 size_t i;
47 int err = 0;
48
49 for (i=0; i<ARRAY_SIZE(testv); i++) {
50
51 double level;
52
53 level = aulevel_calc_dbov(testv[i].sampv,
54 ARRAY_SIZE(testv[i].sampv));
55
56 ASSERT_DOUBLE_EQ(testv[i].level, level, PREC);
57 }
58
59 out:
60 return err;
61 }
62