summaryrefslogtreecommitdiffstats
path: root/libtoolame-dab/utils.c
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2016-02-15 02:44:20 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2016-02-15 02:44:20 +0100
commit22f1fce330059ef8a383cf327a023d6a9da5ad3e (patch)
tree6893f158dcaaaa1b9f1317923c32a841ba31f768 /libtoolame-dab/utils.c
parent891bb2592944aa2be2d81e1583e73e632e70537f (diff)
downloadfdk-aac-dabplus-22f1fce330059ef8a383cf327a023d6a9da5ad3e.tar.gz
fdk-aac-dabplus-22f1fce330059ef8a383cf327a023d6a9da5ad3e.tar.bz2
fdk-aac-dabplus-22f1fce330059ef8a383cf327a023d6a9da5ad3e.zip
Include toolame-dab as library
Diffstat (limited to 'libtoolame-dab/utils.c')
-rw-r--r--libtoolame-dab/utils.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/libtoolame-dab/utils.c b/libtoolame-dab/utils.c
new file mode 100644
index 0000000..a9aefbe
--- /dev/null
+++ b/libtoolame-dab/utils.c
@@ -0,0 +1,33 @@
+#include "utils.h"
+#include <unistd.h>
+#include <stdint.h>
+#include <math.h>
+
+/* Taken from sox */
+const char* level(int channel, int* peak)
+{
+ static char const * const text[][2] = {
+ /* White: 2dB steps */
+ {"", ""}, {"-", "-"}, {"=", "="}, {"-=", "=-"},
+ {"==", "=="}, {"-==", "==-"}, {"===", "==="}, {"-===", "===-"},
+ {"====", "===="}, {"-====", "====-"}, {"=====", "====="},
+ {"-=====", "=====-"}, {"======", "======"},
+ /* Red: 1dB steps */
+ {"!=====", "=====!"},
+ };
+ int const red = 1, white = NUMOF(text) - red;
+
+ double linear = (double)(*peak) / INT16_MAX;
+
+ int vu_dB = linear ? floor(2 * white + red + linear_to_dB(linear)) : 0;
+
+ int index = vu_dB < 2 * white ?
+ MAX(vu_dB / 2, 0) :
+ MIN(vu_dB - white, red + white - 1);
+
+ *peak = 0;
+
+ return text[index][channel];
+
+}
+