Skip to contentSkip to conversation

alternative peak meter for aplay

PATCH In review Dirk Jagdmann 2 participants 4 messages Dec 3, 2005 – Dec 6, 2005

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 alternative peak meter for aplay

This patch adds an alternative peak meter for aplay/arecord which is enabled via three "-v" command line arguments. This new mode differs from the old in a larger meter, no linefeeds for every meter update and a static maximum peak (for 1s).

Signature · 3 lines
---> Dirk Jagdmann ^ doj / cubic
----> http://cubic.org/~doj
-----> http://llg.cubic.org
aplay/aplay.c +37 -7
Index: alsa-utils-1.0.10/aplay/aplay.c
===================================================================
@@ -1183,17 +1183,47 @@
 	max = 1 << (bits_per_sample-1);
 	if (max <= 0)
 		max = 0x7fffffff;
-	printf(_("Max peak (%li samples): 0x%08x "), (long)ocount, max_peak);
+
 	if (bits_per_sample > 16)
 		perc = max_peak / (max / 100);
 	else
 		perc = max_peak * 100 / max;
-	for (val = 0; val < 20; val++)
-		if (val <= perc / 5)
-			putc('#', stdout);
-		else
-			putc(' ', stdout);
-	printf(" %i%%\n", perc);
+
+	if(verbose<=2) {
+		printf(_("Max peak (%li samples): 0x%08x "), (long)ocount, max_peak);
+		for (val = 0; val < 20; val++)
+			if (val <= perc / 5)
+				putchar('#');
+			else
+				putchar(' ');
+		printf(" %i%%\n", perc);
+	}
+	else if(verbose==3) {
+		static int maxperc=0;
+		static time_t t=0;
+		const time_t tt=time(NULL);
+		if(tt>t) {
+			t=tt;
+			maxperc=0;
+		}
+		if(perc>maxperc)
+			maxperc=perc;
+
+		putchar('\r');
+		for (val = 0; val <= perc / 2 && val < 50; val++)
+			putchar('#');
+		for (; val < maxperc / 2 && val < 50; val++)
+			putchar(' ');
+		putchar('+');
+		for (++val; val < 50; val++)
+			putchar(' ');
+
+		printf("| %02i%%", maxperc);
+		if (perc>99)
+			printf(_(" !clip  "));
+
+		fflush(stdout);
+	}
 }
 
 /*
aplay/aplay.1 +1 -1
Index: alsa-utils-1.0.10/aplay/aplay.1
===================================================================
@@ -111,7 +111,7 @@
 \fI\-v, \-\-verbose\fP           
 Show PCM structure and setup.
 This option is accumulative.  The VU meter is displayed when this
-is given twice.
+is given twice or three times.
 .TP
 \fI\-I, \-\-separate\-channels\fP 
 One file for each channel
aplay/arecord.1 +1 -1
Index: alsa-utils-1.0.10/aplay/arecord.1
===================================================================
@@ -111,7 +111,7 @@
 \fI\-v, \-\-verbose\fP           
 Show PCM structure and setup.
 This option is accumulative.  The VU meter is displayed when this
-is given twice.
+is given twice or three times.
 .TP
 \fI\-I, \-\-separate\-channels\fP 
 One file for each channel
#1 lore raw

At Sat, 03 Dec 2005 11:58:44 +0100,

Quoted 5 lines · Dirk Jagdmann

This patch adds an alternative peak meter for aplay/arecord which is enabled via three "-v" command line arguments. This new mode differs from the old in a larger meter, no linefeeds for every meter update and a static maximum peak (for 1s).

I like this one. I'd vote to make this one as -vv and the older one to -vvv. -vvv would be useful to log to a file while -vv is prettier for a terminal output.

The only problem with this patch is that a linefeed is missing even after the playback is finished. Could you fix it?

thanks,

Takashi

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click

#2 lore raw
Quoted 3 lines

I like this one. I'd vote to make this one as -vv and the older one to -vvv. -vvv would be useful to log to a file while -vv is prettier for a terminal output.

Ok, I exchanged the appropriate blocks.

Quoted 2 lines

The only problem with this patch is that a linefeed is missing even after the playback is finished. Could you fix it?

Yes I can fix it, although it's a very difficult request ;-)

Signature · 3 lines
---> Dirk Jagdmann ^ doj / cubic
----> http://cubic.org/~doj
-----> http://llg.cubic.org
aplay/aplay.c +41 -7
Index: alsa-utils-1.0.10/aplay/aplay.c
===================================================================
@@ -303,6 +303,8 @@
 
 static void signal_handler(int sig)
 {
+	if (verbose==2)
+		putchar('\n');
 	if (!quiet_mode)
 		fprintf(stderr, _("Aborted by signal %s...\n"), strsignal(sig));
 	if (stream == SND_PCM_STREAM_CAPTURE) {
@@ -603,6 +605,8 @@
 		else
 			capturev(&argv[optind], argc - optind);
 	}
+	if (verbose==2)
+		putchar('\n');
 	snd_pcm_close(handle);
 	free(audiobuf);
 	snd_output_close(log);
@@ -1183,17 +1187,47 @@
 	max = 1 << (bits_per_sample-1);
 	if (max <= 0)
 		max = 0x7fffffff;
-	printf(_("Max peak (%li samples): 0x%08x "), (long)ocount, max_peak);
+
 	if (bits_per_sample > 16)
 		perc = max_peak / (max / 100);
 	else
 		perc = max_peak * 100 / max;
-	for (val = 0; val < 20; val++)
-		if (val <= perc / 5)
-			putc('#', stdout);
-		else
-			putc(' ', stdout);
-	printf(" %i%%\n", perc);
+
+	if(verbose<=2) {
+		static int maxperc=0;
+		static time_t t=0;
+		const time_t tt=time(NULL);
+		if(tt>t) {
+			t=tt;
+			maxperc=0;
+		}
+		if(perc>maxperc)
+			maxperc=perc;
+
+		putchar('\r');
+		for (val = 0; val <= perc / 2 && val < 50; val++)
+			putchar('#');
+		for (; val < maxperc / 2 && val < 50; val++)
+			putchar(' ');
+		putchar('+');
+		for (++val; val < 50; val++)
+			putchar(' ');
+
+		printf("| %02i%%", maxperc);
+		if (perc>99)
+			printf(_(" !clip  "));
+
+		fflush(stdout);
+	}
+	else if(verbose==3) {
+		printf(_("Max peak (%li samples): 0x%08x "), (long)ocount, max_peak);
+		for (val = 0; val < 20; val++)
+			if (val <= perc / 5)
+				putchar('#');
+			else
+				putchar(' ');
+		printf(" %i%%\n", perc);
+	}
 }
 
 /*
aplay/aplay.1 +1 -1
Index: alsa-utils-1.0.10/aplay/aplay.1
===================================================================
@@ -111,7 +111,7 @@
 \fI\-v, \-\-verbose\fP           
 Show PCM structure and setup.
 This option is accumulative.  The VU meter is displayed when this
-is given twice.
+is given twice or three times.
 .TP
 \fI\-I, \-\-separate\-channels\fP 
 One file for each channel
aplay/arecord.1 +1 -1
Index: alsa-utils-1.0.10/aplay/arecord.1
===================================================================
@@ -111,7 +111,7 @@
 \fI\-v, \-\-verbose\fP           
 Show PCM structure and setup.
 This option is accumulative.  The VU meter is displayed when this
-is given twice.
+is given twice or three times.
 .TP
 \fI\-I, \-\-separate\-channels\fP 
 One file for each channel
#3 lore raw

At Tue, 06 Dec 2005 00:26:06 +0100,

Quoted 11 lines · Dirk Jagdmann
Quoted 4 lines

I like this one. I'd vote to make this one as -vv and the older one to -vvv. -vvv would be useful to log to a file while -vv is prettier for a terminal output.

Ok, I exchanged the appropriate blocks.

Quoted 2 lines

The only problem with this patch is that a linefeed is missing even after the playback is finished. Could you fix it?

Yes I can fix it, although it's a very difficult request ;-)

Great, now it's on CVS. Thanks.

Takashi

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click