From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-1.6 required=3.0 tests=AWL,BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 72A9E1F5AE for ; Sat, 1 Aug 2020 11:53:14 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1k1q4X-0006Kq-M7; Sat, 01 Aug 2020 11:53:05 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1q4W-0006Kd-OQ for sox-devel@lists.sourceforge.net; Sat, 01 Aug 2020 11:53:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:Content-Type:MIME-Version :Message-ID:In-Reply-To:Date:References:Subject:Cc:To:From:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=cSLtQoDSe8c+eN7qiHXIHMblaqqcMmxKJ93pYGIhf10=; b=fNnaooQqaaaqad1OLl2GCeQ+mD cyyA43iNPBwZRCSjU2279ampUb7Skbf5RCuCEYrexGhJKYoNlhWGWZY2B2aNYkcBaEeK6Jo2qJf00 nRoSrHtcRr6sZ5nuNHksTw2xu/EfniT1UYCME9TXMrxM34G5kydoVXCOhQ6zjVxauqTA=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-ID: In-Reply-To:Date:References:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=cSLtQoDSe8c+eN7qiHXIHMblaqqcMmxKJ93pYGIhf10=; b=S6is7r/l8DJLG0PvD5F4E7JKYq LtY07OFzffTCVRMXs/TeFcgoGoW9m/Kl+GAWLjkRklSxRUQs6muT5pGHziLfwXNGse7Mj0R3PkJ5s eljmq9OyNskJN8jXFOBiCaAJBPsdKyHJmM6ZcdjkcUvIqA5VjIzLgQOt+JSLmSMYIOLY=; Received: from unicorn.mansr.com ([81.2.72.234]) by sfi-mx-4.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1k1q4T-008zIx-6o for sox-devel@lists.sourceforge.net; Sat, 01 Aug 2020 11:53:04 +0000 Received: from raven.mansr.com (raven.mansr.com [IPv6:2001:8b0:ca0d:8d8e::3]) by unicorn.mansr.com (Postfix) with ESMTPS id 63B4815360; Sat, 1 Aug 2020 12:52:45 +0100 (BST) Received: by raven.mansr.com (Postfix, from userid 51770) id 5733F21A6F2; Sat, 1 Aug 2020 12:52:45 +0100 (BST) From: =?iso-8859-1?Q?M=E5ns_Rullg=E5rd?= To: Eric Wong References: <20200731093801.23548-1-normalperson@yhbt.net> <20200731093801.23548-10-normalperson@yhbt.net> Date: Sat, 01 Aug 2020 12:52:45 +0100 In-Reply-To: <20200731093801.23548-10-normalperson@yhbt.net> (Eric Wong's message of "Fri, 31 Jul 2020 09:38:01 +0000") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Headers-End: 1k1q4T-008zIx-6o Subject: Re: [PATCH RESEND 9/9] Added average power spectrum for stat -freq -a X-BeenThere: sox-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sox-devel@lists.sourceforge.net Cc: Pander , sox-devel@lists.sourceforge.net Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Errors-To: sox-devel-bounces@lists.sourceforge.net Eric Wong writes: > From: Pander Does "Pander" have a real name? > references: > https://sourceforge.net/p/sox/mailman/message/33186778/ > https://sourceforge.net/p/sox/mailman/message/33175940/ > https://sourceforge.net/p/sox/mailman/message/33625255/ > > Edited-by: Eric Wong > > [ew: removed extraneous whitespace changes, > squashed re_average initialization fix from Pander, > removed unnecessary check before free(3) call > (ref: <5498A2F9.2010500@free.fr>), > converted fft_average to bool] > --- > sox.1 | 6 ++++++ > src/stat.c | 27 ++++++++++++++++++++++++++- > 2 files changed, 32 insertions(+), 1 deletion(-) > > diff --git a/sox.1 b/sox.1 > index 04ab09b1..d64762af 100644 > --- a/sox.1 > +++ b/sox.1 > @@ -3596,6 +3596,12 @@ audio in SoX's internal buffer. > This is mainly used to help track down endian problems that > sometimes occur in cross-platform versions of SoX. > .SP > +The > +.B \-a > +option > +will output the average input's power spectrum instead of the default > +behavior in which the power spectrum is given for each 4096 point DFT. > +.SP > See also the > .B stats > effect. > diff --git a/src/stat.c b/src/stat.c > index cdea27cc..0ca6c232 100644 > --- a/src/stat.c > +++ b/src/stat.c > @@ -34,6 +34,7 @@ typedef struct { > float *re_out; > unsigned long fft_size; > unsigned long fft_offset; > + sox_bool fft_average; > } priv_t; > > @@ -69,6 +70,8 @@ static int sox_stat_getopts(sox_effect_t * effp, int ar= gc, char **argv) > stat->fft =3D 1; > else if (!(strcmp(*argv, "-d"))) > stat->volume =3D 2; > + else if (!(strcmp(*argv, "-a"))) > + stat->fft_average =3D sox_true; > else { > lsx_fail("Summary effect: unknown option"); > return SOX_EOF; > @@ -100,6 +103,7 @@ static int sox_stat_start(sox_effect_t * effp) > stat->bin[i] =3D 0; > > stat->fft_size =3D 4096; > + stat->fft_average =3D sox_false; > stat->re_in =3D stat->re_out =3D NULL; > > if (stat->fft) { > @@ -134,6 +138,16 @@ static int sox_stat_flow(sox_effect_t * effp, const = sox_sample_t *ibuf, sox_samp > priv_t * stat =3D (priv_t *) effp->priv; > int done, x, len =3D min(*isamp, *osamp); > short count =3D 0; > + float *re_average =3D NULL; > + unsigned samples =3D 0; > + float ffa =3D 0.0; > + unsigned i; > + > + if (stat->fft_average) { > + samples =3D (stat->fft_size / 2); > + ffa =3D effp->in_signal.rate / samples; > + re_average =3D lsx_malloc(sizeof(float) * (int)samples); > + } > > if (len) { > if (stat->read =3D=3D 0) /* 1st sample */ > @@ -146,10 +160,20 @@ static int sox_stat_flow(sox_effect_t * effp, const= sox_sample_t *ibuf, sox_samp > > if (stat->fft_offset >=3D stat->fft_size) { > stat->fft_offset =3D 0; > + if (stat->fft_average) { > + lsx_power_spectrum_f((int)samples, stat->re_in, stat->re_o= ut); > + for (i =3D 0; i < samples / 2; i++) /* FIXME: should be <= =3D samples / 2 */ What's this about? If it should be <=3D, why isn't it? > + re_average[i] +=3D stat->re_out[i]; re_average is never initialised. This will produce garbage. > + } else { > print_power_spectrum((unsigned) stat->fft_size, effp->in_signa= l.rate, stat->re_in, stat->re_out); > + } > } > > } > + if (stat->fft_average) { > + for (i =3D 0; i < samples / 2; i++) /* FIXME: should be <=3D s= amples / 2 */ > + fprintf(stderr, " %f %f\n", ffa * i, re_average[i] / len); > + } I don't understand the idea here. Unless I'm mistaken, this prints the power spectrum averaged over however many FFT blocks happen to fit in the input chunk, which could be none. > } > > for (done =3D 0; done < len; done++) { > @@ -192,6 +216,7 @@ static int sox_stat_flow(sox_effect_t * effp, const s= ox_sample_t *ibuf, sox_samp > stat->read +=3D len; > } > > + free(re_average); > *isamp =3D *osamp =3D len; > /* Process all samples */ > > @@ -320,7 +345,7 @@ static int sox_stat_stop(sox_effect_t * effp) > > static sox_effect_handler_t sox_stat_effect =3D { > "stat", > - "[ -s N ] [ -rms ] [-freq] [ -v ] [ -d ]", > + "[ -s N ] [ -rms ] [-freq] [ -v ] [ -d ] [ -a ]", > SOX_EFF_MCHAN | SOX_EFF_MODIFY, > sox_stat_getopts, > sox_stat_start, I'm skipping this patch unless someone can explain what the intent is. Then I might try to fix it. -- = M=E5ns Rullg=E5rd _______________________________________________ SoX-devel mailing list SoX-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sox-devel