diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2014-09-22 21:38:37 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2014-09-22 21:38:37 +0200 |
commit | 01bcfc5d692236bffeec5b8de2c27138e71d2bd6 (patch) | |
tree | caeef2a186acb074388484f78c4445353afe5ac1 /utils.c | |
parent | a0bbc1d61bff38e5db76d3e11813551977411543 (diff) | |
download | toolame-dab-01bcfc5d692236bffeec5b8de2c27138e71d2bd6.tar.gz toolame-dab-01bcfc5d692236bffeec5b8de2c27138e71d2bd6.tar.bz2 toolame-dab-01bcfc5d692236bffeec5b8de2c27138e71d2bd6.zip |
Add -L option to print level
Diffstat (limited to 'utils.c')
-rw-r--r-- | utils.c | 33 |
1 files changed, 33 insertions, 0 deletions
@@ -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]; + +} + |