shithub: sox

Download patch

ref: d0114fd159961b078a003e006aa198a0588c5bd1
parent: 8f7906573f3f9a82c638de7036362048e5300844
author: robs <robs>
date: Tue Feb 24 12:40:59 EST 2009

add peak level in dBFS

--- a/src/stat.c
+++ b/src/stat.c
@@ -228,7 +228,7 @@
  */
 static int sox_stat_stop(sox_effect_t * effp)
 {
-  priv_t * stat = (priv_t *) effp->priv;
+  priv_t * stat = (priv_t *) effp->priv, stat0 = *stat;
   double amp, scale, rms = 0, freq;
   double x, ct;
 
@@ -284,6 +284,7 @@
   fprintf(stderr, "RMS     delta:     %12.6f\n", sqrt(stat->dsum2/(ct-1)));
   freq = sqrt(stat->dsum2/stat->sum2)*effp->in_signal.rate/(M_PI*2);
   fprintf(stderr, "Rough   frequency: %12d\n", (int)freq);
+  fprintf(stderr, "Peak level (dBFS): %12.6f\n", 20 * log(stat0.scale * (1. / SOX_SAMPLE_MAX) * max(fabs(stat0.max), fabs(stat0.min))));
 
   if (amp>0)
     fprintf(stderr, "Volume adjustment: %12.3f\n", SOX_SAMPLE_MAX/(amp*scale));