For spectral features like roll-off, flux, centroid, etc, the process is as follows:
Before delving into the extraction process, a pre-processing phase is sometimes necessary, this includes:
* Converting stereo signals to mono by summing both channels.
* Resampling the signal to a target sample rate (if a collection of signal of heterogenous sample rates are used).
Now, we can assume that we are dealing with a mono signal of known sample rate.
At each time $t = 0, \Delta, 2\Delta...$ at which the feature has to be calculated (for example, $\Delta = 0.04s$ if 25 values of the feature are to be extracted per second of audio):
- Extract the block of signal in the range $[t, t+l]$. $l$ is the analysis window duration and must be greater or equal than $\Delta$. There is a compromise to be found between using short $\Delta$ and $l$ (good temporal resolution) and using a long $l$ (good frequency resolution).
- Multiply this signal chunk by a windowing function such as the Hann window. This prevents spectral leakage which might cause unwanted results (for example, report abnormally high values of spectral spread for a purely sinusoidal signal).
- Eventually, pad the resulting signal with zeros. The purpose is twofold: make sure the number of samples processed at the next step is a power of 2 (in case the FFT library you use is rustic and does not handle other sizes); and in some applications, artificially boost the frequency resolution through spectral interpolation.
- Compute the FFT of the windowed, padded, block of signal.
- Discard the upper half of the coefficients returned by the FFT function (they correspond to "negative frequencies" and are of no interest).
- Compute either the magnitude or square magnitude of the remaining coefficients. This gives the spectrum on which spectral features are computed.
- From there, use whatever formula describes the feature to be extracted. The formulas usually involve $A(k)$ (squared magnitude or magnitude in the $k^{th}$ FFT bin) and $f(k) = \frac{k . \text{sample rate}}{\text{FFT size}}$ (Center frequency of the $k^{th}$ FFT bin).
There is little consensus in the audio signal processing community as to whether the magnitude or power spectrum should be used for spectral features - I have routinely seen both used in research code.