some additions:
the object maintains a summing buffer where it writes the current sum of the different analysis windows (the number of windows depends on the hop size), starting with the most recent one.
what happens in the loop is that it takes n input samples, squares them, multiplies it with a section of the hanning windows depending on the current phase and adds the sum to the first element of the summing buffer. this is repeated for the number of overlaps, but the pointer into the hanning window gets incremented based on the phase difference (= hop size) and the result is now added to the *next* element in the summing buffer etc.
once the sum of a complete analysis window has been calculated (this takes 16 DSP ticks when your block size is 64 and the [env~] window size is 1024), the elements of the summing buffer are shifted one element to the front, the front (= sum of the most recent window) itself gets popped and passed to the outlet (where it is converted from power to decibels).
the powtodb function takes care of taking the square root of the sum but it's done in the logarithmic domain where it's just a division by two.
with smaller hop sizes you basically just get more frequent updates while maintaining a larger window size but with more CPU cost.
this is at least how I understood the code.
Gesendet: Donnerstag, 23. März 2017 um 10:54 Uhr Von: "Orm Finnendahl" orm.finnendahl@selma.hfmdk-frankfurt.de An: pd-list@lists.iem.at Betreff: Re: [PD] how does env~ work?
Am Donnerstag, den 23. März 2017 um 01:34:58 Uhr (-0300) schrieb Alexandre Torres Porres:
howdy, help file says "The analysis is "Hanning" (raised cosine) windowed."
how does that work? I tried looking at the code and got no clue...
In the object's new method, the object allocates a buffer ("buf") and writes the Hanning function with RMS compensation (the two nested divisions by npoints) into it.
I assume it's not just passing the input through a hanning window, and one way or another,
That's exactly what it does. The Hanning window emphasizes the middle of the analysis window and by adjusting the hop size in the second argument of env~ you can fine tune the results.
-- Orm
Pd-list@lists.iem.at mailing list UNSUBSCRIBE and account-management -> https://lists.puredata.info/listinfo/pd-list