Alejandro Acuña
2024-12-18 44b33e24b644459038edd956cfce7345ce3236c1
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//  c_utils.cpp
 
//  utility functions for vad program
 
#include "c_utils.h"
#include <math.h>
 
 
S2byte 
sature16(S4byte data)
{
  if ( data > (S2byte)0x7fff )
    {
        return (S2byte)MAX_16;
    }
  if ( data < (S2byte)0xffff8000 )
    {
        return (S2byte)MIN_16;
    }
  return (S2byte)data; 
}
 
void
bqInit (t_biquad *bq, S2byte a0, S2byte a1, S2byte a2, S2byte b1, S2byte b2)
{
   bq->a0 = a0;
   bq->a11 = a1;
   bq->a12 = a2; 
   bq->negb11 = -b1;
   bq->negb12 = -b2;
   bq->dn_1 = 0;
   bq->dn_2 = 0;
}
 
void
bqProcess(t_biquad *bq, S2byte *datain, S2byte *dataout, int n) 
{
    int i;
    static S2byte prev = 1700;
 
    for (i = 0; i < n; i++)
    {
        /* do biquad processing */
        
        dataout[i] = datain[i] - prev;
        prev = datain[i];
    }
    
}
 
 
void 
calcPower ( int length, U4byte *login, float *logout)   // formerly called log10_32()
{
    int i;
 
    for (i = 0; i < length; i++)
    {
        logout[i] = (float) (10 * log10(login[i]) - 10 * 9.332); 
    }
    
}