Home | History | Annotate | Download | only in source
      1 /*
      2  *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
      3  *
      4  *  Use of this source code is governed by a BSD-style license
      5  *  that can be found in the LICENSE file in the root of the source
      6  *  tree. An additional intellectual property rights grant can be found
      7  *  in the file PATENTS.  All contributing project authors may
      8  *  be found in the AUTHORS file in the root of the source tree.
      9  */
     10 
     11 /*
     12  * initialize.c
     13  *
     14  * Internal initfunctions
     15  *
     16  */
     17 
     18 #include "codec.h"
     19 #include "structs.h"
     20 #include "pitch_estimator.h"
     21 
     22 
     23 void WebRtcIsacfix_InitMaskingEnc(MaskFiltstr_enc *maskdata) {
     24 
     25   int k;
     26 
     27   for (k = 0; k < WINLEN; k++) {
     28     maskdata->DataBufferLoQ0[k] = (WebRtc_Word16) 0;
     29     maskdata->DataBufferHiQ0[k] = (WebRtc_Word16) 0;
     30   }
     31   for (k = 0; k < ORDERLO+1; k++) {
     32     maskdata->CorrBufLoQQ[k] = (WebRtc_Word32) 0;
     33     maskdata->CorrBufLoQdom[k] = 0;
     34 
     35     maskdata->PreStateLoGQ15[k] = 0;
     36 
     37   }
     38   for (k = 0; k < ORDERHI+1; k++) {
     39     maskdata->CorrBufHiQQ[k] = (WebRtc_Word32) 0;
     40     maskdata->CorrBufHiQdom[k] = 0;
     41     maskdata->PreStateHiGQ15[k] = 0;
     42   }
     43 
     44   maskdata->OldEnergy = 10;
     45 
     46   return;
     47 }
     48 
     49 void WebRtcIsacfix_InitMaskingDec(MaskFiltstr_dec *maskdata) {
     50 
     51   int k;
     52 
     53   for (k = 0; k < ORDERLO+1; k++)
     54   {
     55     maskdata->PostStateLoGQ0[k] = 0;
     56   }
     57   for (k = 0; k < ORDERHI+1; k++)
     58   {
     59     maskdata->PostStateHiGQ0[k] = 0;
     60   }
     61 
     62   maskdata->OldEnergy = 10;
     63 
     64   return;
     65 }
     66 
     67 
     68 
     69 
     70 
     71 
     72 
     73 void WebRtcIsacfix_InitPreFilterbank(PreFiltBankstr *prefiltdata)
     74 {
     75   int k;
     76 
     77   for (k = 0; k < QLOOKAHEAD; k++) {
     78     prefiltdata->INLABUF1_fix[k] = 0;
     79     prefiltdata->INLABUF2_fix[k] = 0;
     80   }
     81   for (k = 0; k < WEBRTC_SPL_MUL_16_16(2,(QORDER-1)); k++) {
     82 
     83     prefiltdata->INSTAT1_fix[k] = 0;
     84     prefiltdata->INSTAT2_fix[k] = 0;
     85   }
     86 
     87   /* High pass filter states */
     88   prefiltdata->HPstates_fix[0] = 0;
     89   prefiltdata->HPstates_fix[1] = 0;
     90 
     91   return;
     92 }
     93 
     94 void WebRtcIsacfix_InitPostFilterbank(PostFiltBankstr *postfiltdata)
     95 {
     96   int k;
     97 
     98   for (k = 0; k < WEBRTC_SPL_MUL_16_16(2, POSTQORDER); k++) {
     99 
    100     postfiltdata->STATE_0_LOWER_fix[k] = 0;
    101     postfiltdata->STATE_0_UPPER_fix[k] = 0;
    102   }
    103 
    104   /* High pass filter states */
    105 
    106   postfiltdata->HPstates1_fix[0] = 0;
    107   postfiltdata->HPstates1_fix[1] = 0;
    108 
    109   postfiltdata->HPstates2_fix[0] = 0;
    110   postfiltdata->HPstates2_fix[1] = 0;
    111 
    112   return;
    113 }
    114 
    115 
    116 void WebRtcIsacfix_InitPitchFilter(PitchFiltstr *pitchfiltdata)
    117 {
    118   int k;
    119 
    120   for (k = 0; k < PITCH_BUFFSIZE; k++)
    121     pitchfiltdata->ubufQQ[k] = 0;
    122   for (k = 0; k < (PITCH_DAMPORDER); k++)
    123     pitchfiltdata->ystateQQ[k] = 0;
    124 
    125   pitchfiltdata->oldlagQ7 = 6400; /* 50.0 in Q7 */
    126   pitchfiltdata->oldgainQ12 = 0;
    127 }
    128 
    129 void WebRtcIsacfix_InitPitchAnalysis(PitchAnalysisStruct *State)
    130 {
    131   int k;
    132 
    133   for (k = 0; k < PITCH_CORR_LEN2+PITCH_CORR_STEP2+PITCH_MAX_LAG/2-PITCH_FRAME_LEN/2+2; k++) {
    134     State->dec_buffer16[k] = 0;
    135   }
    136   for (k = 0; k < WEBRTC_SPL_MUL_16_16(2, ALLPASSSECTIONS)+1; k++) {
    137     State->decimator_state32[k] = 0;
    138   }
    139 
    140   for (k = 0; k < QLOOKAHEAD; k++)
    141     State->inbuf[k] = 0;
    142 
    143   WebRtcIsacfix_InitPitchFilter(&(State->PFstr_wght));
    144 
    145   WebRtcIsacfix_InitPitchFilter(&(State->PFstr));
    146 }
    147 
    148 
    149 void WebRtcIsacfix_InitPlc( PLCstr *State )
    150 {
    151   State->decayCoeffPriodic = WEBRTC_SPL_WORD16_MAX;
    152   State->decayCoeffNoise = WEBRTC_SPL_WORD16_MAX;
    153 
    154   State->used = PLC_WAS_USED;
    155 
    156   WebRtcSpl_ZerosArrayW16(State->overlapLP, RECOVERY_OVERLAP);
    157   WebRtcSpl_ZerosArrayW16(State->lofilt_coefQ15, ORDERLO);
    158   WebRtcSpl_ZerosArrayW16(State->hifilt_coefQ15, ORDERHI );
    159 
    160   State->AvgPitchGain_Q12 = 0;
    161   State->lastPitchGain_Q12 = 0;
    162   State->lastPitchLag_Q7 = 0;
    163   State->gain_lo_hiQ17[0]=State->gain_lo_hiQ17[1] = 0;
    164   WebRtcSpl_ZerosArrayW16(State->prevPitchInvIn, FRAMESAMPLES/2);
    165   WebRtcSpl_ZerosArrayW16(State->prevPitchInvOut, PITCH_MAX_LAG + 10 );
    166   WebRtcSpl_ZerosArrayW32(State->prevHP, PITCH_MAX_LAG + 10 );
    167   State->pitchCycles = 0;
    168   State->A = 0;
    169   State->B = 0;
    170   State->pitchIndex = 0;
    171   State->stretchLag = 240;
    172   State->seed = 4447;
    173 
    174 
    175 }
    176