From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eric Wong Newsgroups: gmane.comp.audio.sox.devel Subject: Re: Follow up on Average power spectrum path Date: Sat, 19 Dec 2015 11:12:35 +0000 Message-ID: <20151219111235.GA24760@dcvr.yhbt.net> References: <5672C4E3.9090605@users.sourceforge.net> Reply-To: sox-devel@lists.sourceforge.net NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1450523588 18585 80.91.229.3 (19 Dec 2015 11:13:08 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 19 Dec 2015 11:13:08 +0000 (UTC) To: sox-devel@lists.sourceforge.net Original-X-From: sox-devel-bounces@lists.sourceforge.net Sat Dec 19 12:13:02 2015 Return-path: Envelope-to: gcasd-sox-devel@m.gmane.org X-ACL-Warn: Content-Disposition: inline In-Reply-To: <5672C4E3.9090605@users.sourceforge.net> X-Spam-Score: -0.0 (/) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain X-Headers-End: 1aAFRJ-0007kB-BI X-BeenThere: sox-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: sox-devel-bounces@lists.sourceforge.net Xref: news.gmane.org gmane.comp.audio.sox.devel:441 Archived-At: Received: from lists.sourceforge.net ([216.34.181.88]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aAFRc-0000bg-L6 for gcasd-sox-devel@m.gmane.org; Sat, 19 Dec 2015 12:13:00 +0100 Received: from localhost ([127.0.0.1] helo=sfs-ml-2.v29.ch3.sourceforge.com) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1aAFRL-0002Ag-MK; Sat, 19 Dec 2015 11:12:43 +0000 Received: from sog-mx-2.v43.ch3.sourceforge.com ([172.29.43.192] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1aAFRK-0002Ab-S7 for sox-devel@lists.sourceforge.net; Sat, 19 Dec 2015 11:12:42 +0000 Received: from dcvr.yhbt.net ([64.71.152.64]) by sog-mx-2.v43.ch3.sourceforge.com with esmtp (Exim 4.76) id 1aAFRJ-0007kB-BI for sox-devel@lists.sourceforge.net; Sat, 19 Dec 2015 11:12:42 +0000 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 52A2721062; Sat, 19 Dec 2015 11:12:35 +0000 (UTC) Pander wrote: > Because of a question on the users list, I would like to ask how to move > forward the following patch and documentation? I guess the real sox developers are still busy... I suppose I'll start publishing things I've reviewed/tested and push things I've reviewed to branches my server (see below)[1] so it'll hopefully be easier for them when they return. I'm not really qualified to review the maths parts of this; as I am only a simple Unix/C plumber and I already commented some last year on this patch... I wonder if "-a" should imply "-freq", since it's "-a" is a no-op without "-freq". And is this option is intended to be the average of each hunk in the flow and not for the entire file? In other words, it outputs a LOT of lines with 2 floating point numbers in them when I run: "sox foo.flac -n stat -freq -a" on an arbitrary file. Most of the normal "stat" output is printed in the sox_stat_stop function instead of sox_stat_flow; the lone exception being '-d' which seems mainly for troubleshooting. Also, did you intend fft_average to be extended for non-boolean purposes? I don't mind using "int" as a bool for other pre-C99 projects, but the "== 1" checks in conditionals looked a bit odd to me and sox already defines a sox_bool type, so I figure squashing in the following would improve readability: diff --git a/src/stat.c b/src/stat.c index 63d1741..89bed55 100644 --- a/src/stat.c +++ b/src/stat.c @@ -34,7 +34,7 @@ typedef struct { float *re_out; unsigned long fft_size; unsigned long fft_offset; - int fft_average; + sox_bool fft_average; } priv_t; @@ -71,7 +71,7 @@ static int sox_stat_getopts(sox_effect_t * effp, int argc, char **argv) else if (!(strcmp(*argv, "-d"))) stat->volume = 2; else if (!(strcmp(*argv, "-a"))) - stat->fft_average = 1; + stat->fft_average = sox_true; else { lsx_fail("Summary effect: unknown option"); return SOX_EOF; @@ -103,7 +103,7 @@ static int sox_stat_start(sox_effect_t * effp) stat->bin[i] = 0; stat->fft_size = 4096; - stat->fft_average = 0; + stat->fft_average = sox_false; stat->re_in = stat->re_out = NULL; if (stat->fft) { @@ -142,7 +142,8 @@ static int sox_stat_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_samp unsigned samples = 0; float ffa = 0.0; unsigned i; - if (stat->fft_average == 1) { + + if (stat->fft_average) { samples = (stat->fft_size / 2); ffa = effp->in_signal.rate / samples; re_average = lsx_malloc(sizeof(float) * (int)samples); @@ -159,7 +160,7 @@ static int sox_stat_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_samp if (stat->fft_offset >= stat->fft_size) { stat->fft_offset = 0; - if (stat->fft_average == 1) { + if (stat->fft_average) { lsx_power_spectrum_f((int)samples, stat->re_in, stat->re_out); for (i = 0; i < samples / 2; i++) /* FIXME: should be <= samples / 2 */ re_average[i] += stat->re_out[i]; @@ -169,7 +170,7 @@ static int sox_stat_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_samp } } - if (stat->fft_average == 1) { + if (stat->fft_average) { for (i = 0; i < samples / 2; i++) /* FIXME: should be <= samples / 2 */ fprintf(stderr, " %f %f\n", ffa * i, re_average[i] / len); } --- [1] you can add my repo to your existing sox repository: git remote add 80x24 git://80x24.org/sox.git git fetch 80x24 (or a web viewer if you prefer: http://bogomips.org/sox.git ) These are work-in-progress dev branches, so I will squash and rebase branches as needed with forced pushes. ------------------------------------------------------------------------------