diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2014-04-25 09:21:35 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2014-04-25 09:21:35 +0200 |
commit | ca5406108cb086f57222400a08fde34686ce1b3f (patch) | |
tree | 6edbfc168ea3e2a210a1d8350ba6fcf063abaa59 /src/utils.c | |
parent | 06ac740c56bfc0aaa8b67124a09dcbf91c74cdd3 (diff) | |
download | ODR-AudioEnc-ca5406108cb086f57222400a08fde34686ce1b3f.tar.gz ODR-AudioEnc-ca5406108cb086f57222400a08fde34686ce1b3f.tar.bz2 ODR-AudioEnc-ca5406108cb086f57222400a08fde34686ce1b3f.zip |
dabplus-enc-file: replace little dots by nice level indicator
Diffstat (limited to 'src/utils.c')
-rw-r--r-- | src/utils.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c new file mode 100644 index 0000000..3b0bee4 --- /dev/null +++ b/src/utils.c @@ -0,0 +1,32 @@ +#include "utils.h" +#include <unistd.h> +#include <stdint.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]; + +} + |