Discussion:
[SoX-devel] Review patch for average power spectrum
Pander
2014-12-22 21:50:11 UTC
Permalink
Hi all,

Please review the attached patch for outputting the average power spectrum.

For many applications I need to calculate this with additional tools.
This patch will make SoX do it directly.

Regards,

Pander
Eric Wong
2014-12-22 22:14:50 UTC
Permalink
Post by Pander
Please review the attached patch for outputting the average power spectrum.
I am not knowledgable in the math behind this, but I noticed one
Post by Pander
@@ -134,6 +138,15 @@ static int sox_stat_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_samp
priv_t * stat = (priv_t *) effp->priv;
int done, x, len = min(*isamp, *osamp);
short count = 0;
+ float *re_average;
re_average needs to be initialized for the "stat->fft_average != 1" case

float *re_average = NULL;
Post by Pander
+ if (stat->fft_average == 1) {
+ samples = (stat->fft_size / 2);
+ ffa = effp->in_signal.rate / samples;
+ re_average = lsx_malloc(sizeof(float) * (int)samples);
+ }
+ if (re_average) {
+ free(re_average);
+ }
*isamp = *osamp = len;
/* Process all samples */
There's also a bunch of unrelated whitespace eliminations
in the manpage which should probably be a separate commit
(but I'm not a sox maintainer, just another user + occasional patcher).
Pander
2014-12-22 22:59:28 UTC
Permalink
Post by Eric Wong
Post by Pander
Please review the attached patch for outputting the average power spectrum.
I am not knowledgable in the math behind this, but I noticed one
Post by Pander
@@ -134,6 +138,15 @@ static int sox_stat_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_samp
priv_t * stat = (priv_t *) effp->priv;
int done, x, len = min(*isamp, *osamp);
short count = 0;
+ float *re_average;
re_average needs to be initialized for the "stat->fft_average != 1" case
float *re_average = NULL;
Thanks, that will also remove a warning.

Please see the attachement for the incremental patch.

The first patch also included some of the changes coming in with the
promoted git pull in http://sox.sourceforge.net/ but git can split them
in the patch for the maintainer.
Post by Eric Wong
Post by Pander
+ if (stat->fft_average == 1) {
+ samples = (stat->fft_size / 2);
+ ffa = effp->in_signal.rate / samples;
+ re_average = lsx_malloc(sizeof(float) * (int)samples);
+ }
+ if (re_average) {
+ free(re_average);
+ }
*isamp = *osamp = len;
/* Process all samples */
There's also a bunch of unrelated whitespace eliminations
in the manpage which should probably be a separate commit
(but I'm not a sox maintainer, just another user + occasional patcher).
------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net
_______________________________________________
SoX-devel mailing list
https://lists.sourceforge.net/lists/listinfo/sox-devel
Cedric Roux
2014-12-22 23:02:17 UTC
Permalink
Post by Pander
+ if (re_average) {
+ free(re_average);
+ }
Just for you information,
if a pointer is null free(p) is fine and does nothing.
The "if" is not required.
Pander
2014-12-23 19:05:51 UTC
Permalink
Post by Cedric Roux
Post by Pander
+ if (re_average) {
+ free(re_average);
+ }
Just for you information,
if a pointer is null free(p) is fine and does nothing.
The "if" is not required.
Thanks. Could the person implementing or applying the patch take this
into account?

Question for another unrelated patch, is non-linear interpolation
available in SoX via the C libraries which are already included?
Post by Cedric Roux
------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net
_______________________________________________
SoX-devel mailing list
https://lists.sourceforge.net/lists/listinfo/sox-devel
Loading...