blob: 96b1d644a38a65e78da6e64d1a0d08f979c34167 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
/* process one (interleaved) channel of incoming samples
* calculate square sum of samples
* normalize and return normalized Cumulative Square
* caller must assure num is a multiple of channels
* this filter only accepts signed audio data, so mid level is always 0
*/
{
register int j;
double squaresum = 0.0; /* square sum of the integer samples */
register double square = 0.0; /* Square */
register double PSS = 0.0; /* Peak Square Sample */
gdouble normalizer;
*CS = 0.0; /* Cumulative Square for this block */
normalizer = (double) (1 << resolution);
/*
* process data here
* input sample data enters in *in_data as 8 or 16 bit data
* samples for left and right channel are interleaved
* returns the Mean Square of the samples as a double between 0 and 1
*/
for (j = 0; j < num; j += channels)
{
square = (double) (in[j] * in[j]);
if (square > PSS) PSS = square;
squaresum += square;
}
*peak = PSS / ((double) normalizer * (double) normalizer);
/* return normalized cumulative square */
*CS = squaresum / ((double) normalizer * (double) normalizer);
}
|