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 | |
parent | 06ac740c56bfc0aaa8b67124a09dcbf91c74cdd3 (diff) | |
download | fdk-aac-ca5406108cb086f57222400a08fde34686ce1b3f.tar.gz fdk-aac-ca5406108cb086f57222400a08fde34686ce1b3f.tar.bz2 fdk-aac-ca5406108cb086f57222400a08fde34686ce1b3f.zip |
dabplus-enc-file: replace little dots by nice level indicator
Diffstat (limited to 'src')
-rw-r--r-- | src/dabplus-enc-file-zmq.c | 37 | ||||
-rw-r--r-- | src/utils.c | 32 | ||||
-rw-r--r-- | src/utils.h | 17 |
3 files changed, 73 insertions, 13 deletions
diff --git a/src/dabplus-enc-file-zmq.c b/src/dabplus-enc-file-zmq.c index 802f12e..35aaafe 100644 --- a/src/dabplus-enc-file-zmq.c +++ b/src/dabplus-enc-file-zmq.c @@ -32,6 +32,7 @@ #include "libAACenc/include/aacenc_lib.h" #include "wavreader.h" #include "encryption.h" +#include "utils.h" #include <fec.h> #include <sys/types.h> @@ -41,9 +42,6 @@ #include "contrib/lib_crc.h" -#define MIN(a,b) (((a)<(b))?(a):(b)) -#define MAX(a,b) (((a)>(b))?(a):(b)) - void usage(const char* name) { fprintf(stderr, "dabplus-enc-file-zmq %s is a HE-AACv2 encoder for DAB+\n" @@ -78,7 +76,7 @@ void usage(const char* name) { " -c, --channels={ 1, 2 } Nb of input channels for raw input (default: 2).\n" " -r, --rate={ 32000, 48000 } Sample rate for raw input (default: 48000).\n" " -k, --secret-key=FILE Set the secret key for encryption.\n" - " -s, --suppress-dots Do not show the little dots.\n" + " -l, --level Show level indication.\n" //" -v, --verbose=LEVEL Set verbosity level.\n" "\n" "Only the tcp:// zeromq transport has been tested until now.\n" @@ -103,6 +101,11 @@ int main(int argc, char *argv[]) { int wav_format, bits_per_sample, sample_rate=48000, channels=2; uint8_t* input_buf; int16_t* convert_buf; + + /* Keep track of peaks */ + int peak_left = 0; + int peak_right = 0; + void *rs_handler = NULL; int aot = AOT_DABPLUS_AAC_LC; int afterburner = 0, raw_input=0; @@ -118,7 +121,7 @@ int main(int argc, char *argv[]) { void *zmq_context = zmq_ctx_new(); void *zmq_sock = NULL; - int show_dots = 1; + int show_level = 0; /* Data for ZMQ CURVE authentication */ char* keyfile = NULL; @@ -136,7 +139,7 @@ int main(int argc, char *argv[]) { {"secret-key", required_argument, 0, 'k'}, {"afterburner", no_argument, 0, 'a'}, {"help", no_argument, 0, 'h'}, - {"suppress-dots", no_argument, 0, 's'}, + {"level", no_argument, 0, 'l'}, {0,0,0,0}, }; @@ -182,8 +185,8 @@ int main(int argc, char *argv[]) { case 'P': pad_fifo = optarg; break; - case 's': - show_dots = 0; + case 'l': + show_level = 1; break; case '?': case 'h': @@ -479,6 +482,11 @@ int main(int argc, char *argv[]) { convert_buf[i] = in[0] | (in[1] << 8); } + for (i = 0; i < pcmread/2; i+=2) { + peak_left = MAX(peak_left, convert_buf[i]); + peak_right = MAX(peak_right, convert_buf[i+1]); + } + if (pcmread <= 0) { in_args.numInSamples = -1; } else { @@ -563,14 +571,17 @@ int main(int argc, char *argv[]) { } //fwrite(outbuf, 1, /*out_args.numOutBytes*/ outbuf_size, out_fh); //fprintf(stderr, "Written %d/%d bytes!\n", out_args.numOutBytes + row*10, outbuf_size); - if (show_dots && - out_args.numOutBytes + row*10 == outbuf_size) - fprintf(stderr, "."); -// if(frame > 10) -// break; + if (show_level && out_args.numOutBytes + row*10 == outbuf_size) { + fprintf(stderr, "\rIn: [%6s|%-6s]", + level(0, &peak_left), + level(1, &peak_right)); + } + frame++; } + fprintf(stderr, "\n"); + free(input_buf); free(convert_buf); if(raw_input) { 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]; + +} + diff --git a/src/utils.h b/src/utils.h new file mode 100644 index 0000000..c7ddc1e --- /dev/null +++ b/src/utils.h @@ -0,0 +1,17 @@ +#ifndef UTILS_H_ +#define UTILS_H_ + +#include <math.h> + +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define MAX(a,b) (((a)>(b))?(a):(b)) + +#define NUMOF(l) (sizeof(l) / sizeof(*l)) + +#define linear_to_dB(x) (log10(x) * 20) + + +const char* level(int channel, int* peak); + +#endif + |