|
From: Jan S. <ha...@st...> - 2010-06-15 11:44:35
|
> > > > I am wondering if there's a way to implement into the "stats" feature the
> > > > inclusion of the position (in seconds or samples) of the Max and Min
> > > values
> > > > per channel.
> > > >
> > > > I work in a digital library where we use SoX to extract regions within
> > > our
> > > > archival files, but I would also like to collect stats without relying on
> > > a
> > > > non-open source application. The position of the max/min values would
> > > seem
> > > > to help future techs how to recreate the file in the event if the
> > > archival
> > > > file itself is lost somehow.
> > >
> > > If you lose your audio file, but you have the information
> > > that the peak was axactly at mm:ss - how is that gonna
> > > help recover the lost file?
> > >
>
> On Jun 14 21:05:43, nitin arora wrote:
> > Hi,
> > I should have used better wording.
> > I'm actually talking about if you had to (rather unfortunately) ever
> > re-digitize the object.
> > Having the location of the max/min position would seem to tell one a lot
> > more about how close/far they might be from the lost digital file than if
> > those stats weren't available at all.
>
> I still don't get it.
Anyway, this diff maybe does what you want,
adding the sample position of the peaks to the 'stat' effect.
'Tested' by running it over a Thelonious Monk album
where it gave sensible results. Comments from someone
who actually knows the code?
Oh, it should have been 'stats', not 'stat'
(you wanted to have it per channel).
Jan
Index: src/stat.c
===================================================================
RCS file: /cvsroot/sox/sox/src/stat.c,v
retrieving revision 1.68
diff -u -p -u -w -r1.68 stat.c
--- src/stat.c 18 Mar 2009 17:43:29 -0000 1.68
+++ src/stat.c 15 Jun 2010 11:40:11 -0000
@@ -19,6 +19,7 @@
/* Private data for stat effect */
typedef struct {
double min, max, mid;
+ size_t smin, smax;
double asum;
double sum1, sum2; /* amplitudes */
double dmin, dmax;
@@ -87,6 +88,7 @@ static int sox_stat_start(sox_effect_t *
int i;
stat->min = stat->max = stat->mid = 0;
+ stat->smin = stat->smax = 0;
stat->asum = 0;
stat->sum1 = stat->sum2 = 0;
@@ -168,10 +170,13 @@ static int sox_stat_flow(sox_effect_t *
}
/* update min/max */
- if (stat->min > samp)
+ if (stat->min > samp) {
stat->min = samp;
- else if (stat->max < samp)
+ stat->smin = stat->read + done;
+ } else if (stat->max < samp) {
stat->max = samp;
+ stat->smax = stat->read + done;
+ }
stat->mid = stat->min / 2 + stat->max / 2;
stat->sum1 += samp;
@@ -271,8 +276,10 @@ static int sox_stat_stop(sox_effect_t *
fprintf(stderr, "Scaled by rms: %12.6f\n", rms);
else
fprintf(stderr, "Scaled by: %12.1f\n", scale);
- fprintf(stderr, "Maximum amplitude: %12.6f\n", stat->max);
- fprintf(stderr, "Minimum amplitude: %12.6f\n", stat->min);
+ fprintf(stderr, "Maximum amplitude: %12.6f", stat->max);
+ fprintf(stderr, " (sample %lu)\n", stat->smax);
+ fprintf(stderr, "Minimum amplitude: %12.6f", stat->min);
+ fprintf(stderr, " (sample %lu)\n", stat->smin);
fprintf(stderr, "Midline amplitude: %12.6f\n", stat->mid);
fprintf(stderr, "Mean norm: %12.6f\n", stat->asum/ct);
fprintf(stderr, "Mean amplitude: %12.6f\n", stat->sum1/ct);
|