aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--options.h1
-rw-r--r--toolame.c49
-rw-r--r--utils.c33
-rw-r--r--utils.h20
-rw-r--r--zmqoutput.c8
-rw-r--r--zmqoutput.h2
7 files changed, 107 insertions, 8 deletions
diff --git a/Makefile b/Makefile
index 14c72e8..a3fad82 100644
--- a/Makefile
+++ b/Makefile
@@ -32,6 +32,7 @@ HEADERS = \
subband.h \
tables.h \
toolame.h \
+ utils.h \
xpad.h \
zmqoutput.h
@@ -58,6 +59,7 @@ c_sources = \
ath.c \
encode_new.c \
zmqoutput.c \
+ utils.c \
xpad.c
OBJ = $(c_sources:.c=.o)
diff --git a/options.h b/options.h
index 2219643..a03db04 100644
--- a/options.h
+++ b/options.h
@@ -17,6 +17,7 @@ typedef struct
used for VBR in LAME */
int verbosity; /* 2 by default. 0 is no output at all */
int enable_jack; /* 1=use JACK input, 2=use wav input */
+ int show_level; /* 1=show the sox-like audio level measurement */
}
options;
diff --git a/toolame.c b/toolame.c
index 19a6323..42cc558 100644
--- a/toolame.c
+++ b/toolame.c
@@ -24,6 +24,7 @@
#include "encode_new.h"
#include "toolame.h"
#include "xpad.h"
+#include "utils.h"
#include <assert.h>
@@ -128,6 +129,10 @@ int main (int argc, char **argv)
int lg_frame;
int i;
+ /* Keep track of peaks */
+ int peak_left = 0;
+ int peak_right = 0;
+
char* mot_file = NULL;
/* Used to keep the SNR values for the fast/quick psy models */
@@ -198,22 +203,44 @@ int main (int argc, char **argv)
nch = frame.nch;
error_protection = header.error_protection;
- while (get_audio (&musicin, buffer, num_samples, nch, &header) > 0) {
+ unsigned long samps_read;
+ while ((samps_read = get_audio(&musicin, buffer, num_samples, nch, &header)) > 0) {
+ unsigned long j;
+ for (j = 0; j < samps_read; j++) {
+ peak_left = MAX(peak_left, buffer[0][j]);
+ }
+ for (j = 0; j < samps_read; j++) {
+ peak_right = MAX(peak_right, buffer[1][j]);
+ }
+
+ // We can always set the zmq peaks, even if the output is not
+ // used, it just writes some variables
+ zmqoutput_set_peaks(peak_left, peak_right);
+
if (glopts.verbosity > 1)
if (++frameNum % 10 == 0) {
+
+ fprintf(stderr, "[%4u", frameNum);
+
if (mot_file) {
- fprintf (stderr, "[%4u %s ]\r",
- frameNum,
- xpad_len > 0 ? "p" : " "
- );
+ fprintf(stderr, " %s",
+ xpad_len > 0 ? "p" : " ");
+ }
+
+ if (glopts.show_level) {
+ fprintf(stderr, " (%6d|%-6d) ",
+ peak_left, peak_right);
+
+ fprintf(stderr, "] [%6s|%-6s]\r",
+ level(0, &peak_left),
+ level(1, &peak_right) );
}
else {
- fprintf (stderr, "[%4u]\r",
- frameNum);
+ fprintf(stderr, "]\r");
}
}
- fflush (stderr);
+ fflush(stderr);
win_buf[0] = &buffer[0][0];
win_buf[1] = &buffer[1][0];
@@ -633,6 +660,7 @@ void usage (void)
fprintf (stdout, "\t-x force byte-swapping of input\n");
fprintf (stdout, "\t-g swap channels of input file\n");
fprintf (stdout, "\t-j enable jack input\n");
+ fprintf (stdout, "\t-L enable audio level display\n");
fprintf (stdout, "Output\n");
fprintf (stdout, "\t-m mode channel mode : s/d/j/m (dflt %4c)\n",
DFLT_MOD);
@@ -700,6 +728,7 @@ void short_usage (void)
* syntax:
*
* -j turns on JACK input
+ * -L turns on audio level display
* -m is followed by the mode
* -y is followed by the psychoacoustic model number
* -s is followed by the sampling rate
@@ -836,6 +865,10 @@ void parse_args (int argc, char **argv, frame_info * frame, int *psy,
argUsed = 1;
break;
+ case 'L':
+ glopts.show_level = 1;
+ break;
+
case 's':
argUsed = 1;
srate = atof (arg);
diff --git a/utils.c b/utils.c
new file mode 100644
index 0000000..a9aefbe
--- /dev/null
+++ b/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];
+
+}
+
diff --git a/utils.h b/utils.h
new file mode 100644
index 0000000..7d98ab6
--- /dev/null
+++ b/utils.h
@@ -0,0 +1,20 @@
+#ifndef _UTILS_H_
+#define _UTILS_H_
+
+#include <math.h>
+#include <stdint.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)
+
+/* Calculate the little string containing a bargraph
+ * 'VU-meter' from the peak value measured
+ */
+const char* level(int channel, int* peak);
+
+#endif
+
diff --git a/zmqoutput.c b/zmqoutput.c
index 6d9db68..75a3543 100644
--- a/zmqoutput.c
+++ b/zmqoutput.c
@@ -13,6 +13,14 @@ unsigned char* zmqbuf;
// buffer size)
size_t zmqbuf_len;
+static int zmq_peak_left = 0;
+static int zmq_peak_right = 0;
+
+void zmqoutput_set_peaks(int left, int right)
+{
+ zmq_peak_left = left;
+ zmq_peak_right = right;
+}
int zmqoutput_open(Bit_stream_struc *bs, char* uri)
{
diff --git a/zmqoutput.h b/zmqoutput.h
index a4eb556..36b8e9b 100644
--- a/zmqoutput.h
+++ b/zmqoutput.h
@@ -28,5 +28,7 @@ int zmqoutput_write_byte(Bit_stream_struc *bs, unsigned char data);
void zmqoutput_close(Bit_stream_struc *bs);
+void zmqoutput_set_peaks(int left, int right);
+
#endif