FreeCalypso > hg > gsm-codec-lib
comparison libtwamr/ex_ctrl.c @ 364:3f27ca24c620
libtwamr: integrate ex_ctrl.c
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Mon, 06 May 2024 02:54:36 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 363:0349de7c45b7 | 364:3f27ca24c620 |
|---|---|
| 1 /************************************************************************* | |
| 2 * | |
| 3 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001 | |
| 4 * R99 Version 3.3.0 | |
| 5 * REL-4 Version 4.1.0 | |
| 6 * | |
| 7 ******************************************************************************** | |
| 8 * | |
| 9 * File : ex_ctrl.c | |
| 10 * Purpose : Excitation Control module in background noise | |
| 11 * | |
| 12 ******************************************************************************** | |
| 13 */ | |
| 14 | |
| 15 /* | |
| 16 ******************************************************************************** | |
| 17 * MODULE INCLUDE FILE AND VERSION ID | |
| 18 ******************************************************************************** | |
| 19 */ | |
| 20 #include "namespace.h" | |
| 21 #include "ex_ctrl.h" | |
| 22 | |
| 23 #include "typedef.h" | |
| 24 #include "basic_op.h" | |
| 25 #include "no_count.h" | |
| 26 #include "cnst.h" | |
| 27 #include "memops.h" | |
| 28 #include "gmed_n.h" | |
| 29 #include "sqrt_l.h" | |
| 30 | |
| 31 /* | |
| 32 ******************************************************************************** | |
| 33 * LOCAL VARIABLES AND TABLES | |
| 34 ******************************************************************************** | |
| 35 */ | |
| 36 /*-----------------------------------------------------------------* | |
| 37 * Decoder constant parameters (defined in "cnst.h") * | |
| 38 *-----------------------------------------------------------------* | |
| 39 * L_FRAME : Frame size. * | |
| 40 * L_SUBFR : Sub-frame size. * | |
| 41 *-----------------------------------------------------------------*/ | |
| 42 | |
| 43 /* | |
| 44 ******************************************************************************** | |
| 45 * PUBLIC PROGRAM CODE | |
| 46 ******************************************************************************** | |
| 47 */ | |
| 48 | |
| 49 /* | |
| 50 ************************************************************************** | |
| 51 * | |
| 52 * Function : Ex_ctrl | |
| 53 * Purpose : Charaterice synthesis speech and detect background noise | |
| 54 * Returns : background noise decision; 0 = no bgn, 1 = bgn | |
| 55 * | |
| 56 ************************************************************************** | |
| 57 */ | |
| 58 Word16 Ex_ctrl (Word16 excitation[], /*i/o: Current subframe excitation */ | |
| 59 Word16 excEnergy, /* i : Exc. Energy, sqrt(totEx*totEx)*/ | |
| 60 Word16 exEnergyHist[], /* i : History of subframe energies */ | |
| 61 Word16 voicedHangover, /* i : # of fr. after last voiced fr.*/ | |
| 62 Word16 prevBFI, /* i : Set i previous BFI */ | |
| 63 Word16 carefulFlag /* i : Restrict dymamic in scaling */ | |
| 64 ) | |
| 65 { | |
| 66 Word16 i, exp; | |
| 67 Word16 testEnergy, scaleFactor, avgEnergy, prevEnergy; | |
| 68 Word32 t0; | |
| 69 | |
| 70 /* get target level */ | |
| 71 avgEnergy = gmed_n(exEnergyHist, 9); move16(); | |
| 72 | |
| 73 prevEnergy = shr( add (exEnergyHist[7], exEnergyHist[8]) ,1); | |
| 74 | |
| 75 test (); | |
| 76 if ( sub (exEnergyHist[8], prevEnergy) < 0) | |
| 77 { | |
| 78 prevEnergy = exEnergyHist[8]; move16 (); | |
| 79 } | |
| 80 | |
| 81 /* upscaling to avoid too rapid energy rises for some cases */ | |
| 82 test (); test (); | |
| 83 if ( sub (excEnergy, avgEnergy) < 0 && sub (excEnergy, 5) > 0) | |
| 84 { | |
| 85 testEnergy = shl(prevEnergy, 2); /* testEnergy = 4*prevEnergy; */ | |
| 86 | |
| 87 test (); test (); | |
| 88 if ( sub (voicedHangover, 7) < 0 || prevBFI != 0 ) | |
| 89 { | |
| 90 /* testEnergy = 3*prevEnergy */ | |
| 91 testEnergy = sub (testEnergy, prevEnergy); | |
| 92 } | |
| 93 | |
| 94 test (); | |
| 95 if ( sub (avgEnergy, testEnergy) > 0) | |
| 96 { | |
| 97 avgEnergy = testEnergy; move16 (); | |
| 98 } | |
| 99 | |
| 100 /* scaleFactor=avgEnergy/excEnergy in Q0 (const 29 below)*/ | |
| 101 exp = norm_s (excEnergy); | |
| 102 excEnergy = shl (excEnergy, exp); | |
| 103 excEnergy = div_s ((Word16) 16383, excEnergy); | |
| 104 t0 = L_mult (avgEnergy, excEnergy); | |
| 105 t0 = L_shr (t0, sub (20, exp)); /* const=30 for t0 in Q0, 20 for Q10 */ | |
| 106 if ( L_sub(t0, 32767) > 0 ) | |
| 107 { | |
| 108 t0 = 32767; move32 (); /* saturate */ | |
| 109 } | |
| 110 scaleFactor = extract_l (t0); | |
| 111 | |
| 112 /* test if scaleFactor > 3.0 */ | |
| 113 test (); test (); | |
| 114 if ( carefulFlag != 0 && sub(scaleFactor, 3072) > 0 ) | |
| 115 { | |
| 116 scaleFactor = 3072; move16 (); | |
| 117 } | |
| 118 | |
| 119 /* scale the excitation by scaleFactor */ | |
| 120 for (i = 0; i < L_SUBFR; i++) | |
| 121 { | |
| 122 t0 = L_mult (scaleFactor, excitation[i]); | |
| 123 t0 = L_shr (t0, 11); | |
| 124 excitation[i] = extract_l (t0); | |
| 125 } | |
| 126 } | |
| 127 | |
| 128 return 0; | |
| 129 } |
