FreeCalypso > hg > gsm-codec-lib
comparison libgsmefr/agc.c @ 54:7b11cbe99a0e
libgsmefr: agc.c compiles
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Fri, 25 Nov 2022 16:35:07 +0000 |
| parents | 49dd1ac8e75b |
| children |
comparison
equal
deleted
inserted
replaced
| 53:49dd1ac8e75b | 54:7b11cbe99a0e |
|---|---|
| 12 * g_in/g_out is the square root of the ratio of energy at the input | 12 * g_in/g_out is the square root of the ratio of energy at the input |
| 13 * and output of the postfilter. | 13 * and output of the postfilter. |
| 14 * | 14 * |
| 15 *************************************************************************/ | 15 *************************************************************************/ |
| 16 | 16 |
| 17 #include "gsm_efr.h" | |
| 17 #include "typedef.h" | 18 #include "typedef.h" |
| 19 #include "namespace.h" | |
| 18 #include "basic_op.h" | 20 #include "basic_op.h" |
| 19 #include "count.h" | 21 #include "no_count.h" |
| 22 #include "cnst.h" | |
| 23 #include "dec_state.h" | |
| 20 #include "sig_proc.h" | 24 #include "sig_proc.h" |
| 21 #include "cnst.h" | |
| 22 | |
| 23 Word16 past_gain; /* initial value of past_gain = 1.0 */ | |
| 24 | 25 |
| 25 void agc ( | 26 void agc ( |
| 27 struct EFR_decoder_state *st, | |
| 26 Word16 *sig_in, /* (i) : postfilter input signal */ | 28 Word16 *sig_in, /* (i) : postfilter input signal */ |
| 27 Word16 *sig_out, /* (i/o) : postfilter output signal */ | 29 Word16 *sig_out, /* (i/o) : postfilter output signal */ |
| 28 Word16 agc_fac, /* (i) : AGC factor */ | 30 Word16 agc_fac, /* (i) : AGC factor */ |
| 29 Word16 l_trm /* (i) : subframe size */ | 31 Word16 l_trm /* (i) : subframe size */ |
| 30 ) | 32 ) |
| 44 { | 46 { |
| 45 temp = shr (sig_out[i], 2); | 47 temp = shr (sig_out[i], 2); |
| 46 s = L_mac (s, temp, temp); | 48 s = L_mac (s, temp, temp); |
| 47 } | 49 } |
| 48 | 50 |
| 49 test (); | |
| 50 if (s == 0) | 51 if (s == 0) |
| 51 { | 52 { |
| 52 past_gain = 0; move16 (); | 53 st->past_gain = 0; |
| 53 return; | 54 return; |
| 54 } | 55 } |
| 55 exp = sub (norm_l (s), 1); | 56 exp = sub (norm_l (s), 1); |
| 56 gain_out = round (L_shl (s, exp)); | 57 gain_out = round (L_shl (s, exp)); |
| 57 | 58 |
| 64 { | 65 { |
| 65 temp = shr (sig_in[i], 2); | 66 temp = shr (sig_in[i], 2); |
| 66 s = L_mac (s, temp, temp); | 67 s = L_mac (s, temp, temp); |
| 67 } | 68 } |
| 68 | 69 |
| 69 test (); | |
| 70 if (s == 0) | 70 if (s == 0) |
| 71 { | 71 { |
| 72 g0 = 0; move16 (); | 72 g0 = 0; |
| 73 } | 73 } |
| 74 else | 74 else |
| 75 { | 75 { |
| 76 i = norm_l (s); | 76 i = norm_l (s); |
| 77 gain_in = round (L_shl (s, i)); | 77 gain_in = round (L_shl (s, i)); |
| 94 | 94 |
| 95 /* compute gain[n] = agc_fac * gain[n-1] | 95 /* compute gain[n] = agc_fac * gain[n-1] |
| 96 + (1-agc_fac) * sqrt(gain_in/gain_out) */ | 96 + (1-agc_fac) * sqrt(gain_in/gain_out) */ |
| 97 /* sig_out[n] = gain[n] * sig_out[n] */ | 97 /* sig_out[n] = gain[n] * sig_out[n] */ |
| 98 | 98 |
| 99 gain = past_gain; move16 (); | 99 gain = st->past_gain; |
| 100 | 100 |
| 101 for (i = 0; i < l_trm; i++) | 101 for (i = 0; i < l_trm; i++) |
| 102 { | 102 { |
| 103 gain = mult (gain, agc_fac); | 103 gain = mult (gain, agc_fac); |
| 104 gain = add (gain, g0); | 104 gain = add (gain, g0); |
| 105 sig_out[i] = extract_h (L_shl (L_mult (sig_out[i], gain), 3)); | 105 sig_out[i] = extract_h (L_shl (L_mult (sig_out[i], gain), 3)); |
| 106 move16 (); | |
| 107 } | 106 } |
| 108 | 107 |
| 109 past_gain = gain; move16 (); | 108 st->past_gain = gain; |
| 110 | 109 |
| 111 return; | 110 return; |
| 112 } | 111 } |
| 113 | 112 |
| 114 void agc2 ( | 113 void agc2 ( |
