Home | History | Annotate | Download | only in src
      1 /* ------------------------------------------------------------------
      2  * Copyright (C) 1998-2009 PacketVideo
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
     13  * express or implied.
     14  * See the License for the specific language governing permissions
     15  * and limitations under the License.
     16  * -------------------------------------------------------------------
     17  */
     18 /****************************************************************************************
     19 Portions of this file are derived from the following 3GPP standard:
     20 
     21     3GPP TS 26.173
     22     ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
     23     Available from http://www.3gpp.org
     24 
     25 (C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
     26 Permission to distribute, modify and use this file under the standard license
     27 terms listed above has been obtained from the copyright holder.
     28 ****************************************************************************************/
     29 /*
     30 ------------------------------------------------------------------------------
     31 
     32 
     33 
     34  Pathname: ./cpp/include/pvamrwbdecoder_acelp.h
     35 
     36      Date: 01/04/2007
     37 
     38 ------------------------------------------------------------------------------
     39  REVISION HISTORY
     40 
     41  Description:
     42 ------------------------------------------------------------------------------
     43  INCLUDE DESCRIPTION
     44 
     45 ------------------------------------------------------------------------------
     46 */
     47 
     48 #ifndef PVAMRWBDECODER_ACELP_H
     49 #define PVAMRWBDECODER_ACELP_H
     50 
     51 
     52 /*----------------------------------------------------------------------------
     53 ; INCLUDES
     54 ----------------------------------------------------------------------------*/
     55 
     56 #include "pv_amr_wb_type_defs.h"
     57 #include "pvamrwbdecoder_mem_funcs.h"
     58 
     59 #ifdef __cplusplus
     60 extern "C"
     61 {
     62 #endif
     63 
     64     /*-----------------------------------------------------------------*
     65      *                        LPC prototypes                           *
     66      *-----------------------------------------------------------------*/
     67 
     68     void isf_extrapolation(int16 HfIsf[]);
     69 
     70     void Init_Lagconc(int16 lag_hist[]);
     71     void lagconceal(
     72         int16 gain_hist[],                   /* (i) : Gain history     */
     73         int16 lag_hist[],                    /* (i) : Subframe size         */
     74         int16 * T0,
     75         int16 * old_T0,
     76         int16 * seed,
     77         int16 unusable_frame
     78     );
     79 
     80     void agc2_amr_wb(
     81         int16 * sig_in,                      /* input : postfilter input signal  */
     82         int16 * sig_out,                     /* in/out: postfilter output signal */
     83         int16 l_trm                          /* input : subframe size            */
     84     );
     85 
     86     void low_pass_filt_7k_init(int16 mem[]);
     87     void low_pass_filt_7k(
     88         int16 signal[],                      /* input:  signal                  */
     89         int16 lg,                            /* input:  length of input         */
     90         int16 mem[],                         /* in/out: memory (size=30)        */
     91         int16 x[]
     92     );
     93 
     94     int16 median5(int16 x[]);
     95 
     96     void Isp_Az(
     97         int16 isp[],                         /* (i) Q15 : Immittance spectral pairs            */
     98         int16 a[],                           /* (o) Q12 : predictor coefficients (order = M)   */
     99         int16 m,
    100         int16 adaptive_scaling               /* (i) 0   : adaptive scaling disabled */
    101         /*     1   : adaptive scaling enabled  */
    102     );
    103     void Isf_isp(
    104         int16 isf[],                         /* (i) Q15 : isf[m] normalized (range: 0.0<=val<=0.5) */
    105         int16 isp[],                         /* (o) Q15 : isp[m] (range: -1<=val<1)                */
    106         int16 m                              /* (i)     : LPC order                                */
    107     );
    108     void interpolate_isp(
    109         int16 isp_old[],                     /* input : isps from past frame              */
    110         int16 isp_new[],                     /* input : isps from present frame           */
    111         const int16 frac[],                  /* input : fraction for 3 first subfr (Q15)  */
    112         int16 Az[]                           /* output: LP coefficients in 4 subframes    */
    113     );
    114     void weight_amrwb_lpc(
    115         int16 a[],                           /* (i) Q12 : a[m+1]  LPC coefficients             */
    116         int16 ap[],                          /* (o) Q12 : Spectral expanded LPC coefficients   */
    117         int16 gamma,                         /* (i) Q15 : Spectral expansion factor.           */
    118         int16 m                              /* (i)     : LPC order.                           */
    119     );
    120 
    121 
    122     /*-----------------------------------------------------------------*
    123      *                        isf quantizers                           *
    124      *-----------------------------------------------------------------*/
    125 
    126     void Disf_ns(
    127         int16 * indice,                      /* input:  quantization indices                  */
    128         int16 * isf_q                        /* input : ISF in the frequency domain (0..0.5)  */
    129     );
    130 
    131     void Dpisf_2s_46b(
    132         int16 * indice,                      /* input:  quantization indices                       */
    133         int16 * isf_q,                       /* output: quantized ISF in frequency domain (0..0.5) */
    134         int16 * past_isfq,                   /* i/0   : past ISF quantizer                    */
    135         int16 * isfold,                      /* input : past quantized ISF                    */
    136         int16 * isf_buf,                     /* input : isf buffer                                                        */
    137         int16 bfi,                           /* input : Bad frame indicator                   */
    138         int16 enc_dec
    139     );
    140     void Dpisf_2s_36b(
    141         int16 * indice,                      /* input:  quantization indices                       */
    142         int16 * isf_q,                       /* output: quantized ISF in frequency domain (0..0.5) */
    143         int16 * past_isfq,                   /* i/0   : past ISF quantizer                    */
    144         int16 * isfold,                      /* input : past quantized ISF                    */
    145         int16 * isf_buf,                     /* input : isf buffer                                                        */
    146         int16 bfi,                           /* input : Bad frame indicator                   */
    147         int16 enc_dec
    148     );
    149 
    150 
    151     void Reorder_isf(
    152         int16 * isf,                         /* (i/o) Q15: ISF in the frequency domain (0..0.5) */
    153         int16 min_dist,                      /* (i) Q15  : minimum distance to keep             */
    154         int16 n                              /* (i)      : number of ISF                        */
    155     );
    156 
    157     /*-----------------------------------------------------------------*
    158      *                       filter prototypes                         *
    159      *-----------------------------------------------------------------*/
    160 
    161     void oversamp_12k8_to_16k_init(
    162         int16 mem[]                          /* output: memory (2*NB_COEF_UP) set to zeros  */
    163     );
    164     void oversamp_12k8_to_16k(
    165         int16 sig12k8[],                     /* input:  signal to oversampling  */
    166         int16 lg,                            /* input:  length of input         */
    167         int16 sig16k[],                      /* output: oversampled signal      */
    168         int16 mem[],                         /* in/out: memory (2*NB_COEF_UP)   */
    169         int16 signal[]
    170     );
    171 
    172     void highpass_50Hz_at_12k8_init(int16 mem[]);
    173     void highpass_50Hz_at_12k8(
    174         int16 signal[],                      /* input/output signal */
    175         int16 lg,                            /* lenght of signal    */
    176         int16 mem[]                          /* filter memory [6]   */
    177     );
    178     void highpass_400Hz_at_12k8_init(int16 mem[]);
    179     void highpass_400Hz_at_12k8(
    180         int16 signal[],                      /* input/output signal */
    181         int16 lg,                            /* lenght of signal    */
    182         int16 mem[]                          /* filter memory [6]   */
    183     );
    184 
    185     void band_pass_6k_7k_init(int16 mem[]);
    186     void band_pass_6k_7k(
    187         int16 signal[],                      /* input:  signal                  */
    188         int16 lg,                            /* input:  length of input         */
    189         int16 mem[],                         /* in/out: memory (size=30)        */
    190         int16 x[]
    191     );
    192 
    193 
    194     void preemph_amrwb_dec(
    195         int16 x[],                           /* (i/o)   : input signal overwritten by the output */
    196         int16 mu,                            /* (i) Q15 : preemphasis coefficient                */
    197         int16 lg                             /* (i)     : lenght of filtering                    */
    198     );
    199 
    200     void deemphasis_32(
    201         int16 x_hi[],                        /* (i)     : input signal (bit31..16) */
    202         int16 x_lo[],                        /* (i)     : input signal (bit15..4)  */
    203         int16 y[],                           /* (o)     : output signal (x16)      */
    204         int16 mu,                            /* (i) Q15 : deemphasis factor        */
    205         int16 L,                             /* (i)     : vector size              */
    206         int16 * mem                          /* (i/o)   : memory (y[-1])           */
    207     );
    208 
    209 
    210     void wb_syn_filt(
    211         int16 a[],                           /* (i) Q12 : a[m+1] prediction coefficients           */
    212         int16 m,                             /* (i)     : order of LP filter                       */
    213         int16 x[],                           /* (i)     : input signal                             */
    214         int16 y[],                           /* (o)     : output signal                            */
    215         int16 lg,                            /* (i)     : size of filtering                        */
    216         int16 mem[],                         /* (i/o)   : memory associated with this filtering.   */
    217         int16 update,                        /* (i)     : 0=no update, 1=update of memory.         */
    218         int16 y_buf[]
    219     );
    220     void Syn_filt_32(
    221         int16 a[],                           /* (i) Q12 : a[m+1] prediction coefficients */
    222         int16 m,                             /* (i)     : order of LP filter             */
    223         int16 exc[],                         /* (i) Qnew: excitation (exc[i] >> Qnew)    */
    224         int16 Qnew,                          /* (i)     : exc scaling = 0(min) to 8(max) */
    225         int16 sig_hi[],                      /* (o) /16 : synthesis high                 */
    226         int16 sig_lo[],                      /* (o) /16 : synthesis low                  */
    227         int16 lg                             /* (i)     : size of filtering              */
    228     );
    229 
    230     /*-----------------------------------------------------------------*
    231      *                       pitch prototypes                          *
    232      *-----------------------------------------------------------------*/
    233 
    234 
    235     void Pred_lt4(
    236         int16 exc[],                         /* in/out: excitation buffer */
    237         int16 T0,                            /* input : integer pitch lag */
    238         int16 frac,                          /* input : fraction of lag   */
    239         int16 L_subfr                        /* input : subframe size     */
    240     );
    241 
    242     /*-----------------------------------------------------------------*
    243      *                       gain prototypes                           *
    244      *-----------------------------------------------------------------*/
    245 
    246 
    247     void dec_gain2_amr_wb_init(
    248         int16 * mem                          /* output  : memory (4 words)      */
    249     );
    250     void dec_gain2_amr_wb(
    251         int16 index,                         /* (i)     :index of quantization.       */
    252         int16 nbits,                         /* (i)     : number of bits (6 or 7)     */
    253         int16 code[],                        /* (i) Q9  :Innovative vector.           */
    254         int16 L_subfr,                       /* (i)     :Subframe lenght.             */
    255         int16 * gain_pit,                    /* (o) Q14 :Pitch gain.                  */
    256         int32 * gain_cod,                    /* (o) Q16 :Code gain.                   */
    257         int16 bfi,                           /* (i)     :bad frame indicator          */
    258         int16 prev_bfi,                      /* (i) : Previous BF indicator      */
    259         int16 state,                         /* (i) : State of BFH               */
    260         int16 unusable_frame,                /* (i) : UF indicator            */
    261         int16 vad_hist,                      /* (i)         :number of non-speech frames  */
    262         int16 * mem                          /* (i/o)   : memory (4 words)      */
    263     );
    264 
    265     /*-----------------------------------------------------------------*
    266      *                       acelp prototypes                          *
    267      *-----------------------------------------------------------------*/
    268 
    269     void dec_acelp_2p_in_64(
    270         int16 index,                         /* (i) :    12 bits index                                  */
    271         int16 code[]                         /* (o) :Q9  algebraic (fixed) codebook excitation          */
    272     );
    273 
    274     void dec_acelp_4p_in_64(
    275         int16 index[],                       /* (i) : index (20): 5+5+5+5 = 20 bits.                 */
    276         /* (i) : index (36): 9+9+9+9 = 36 bits.                 */
    277         /* (i) : index (44): 13+9+13+9 = 44 bits.               */
    278         /* (i) : index (52): 13+13+13+13 = 52 bits.             */
    279         /* (i) : index (64): 2+2+2+2+14+14+14+14 = 64 bits.     */
    280         /* (i) : index (72): 10+2+10+2+10+14+10+14 = 72 bits.   */
    281         /* (i) : index (88): 11+11+11+11+11+11+11+11 = 88 bits. */
    282         int16 nbbits,                        /* (i) : 20, 36, 44, 52, 64, 72 or 88 bits              */
    283         int16 code[]                         /* (o) Q9: algebraic (fixed) codebook excitation        */
    284     );
    285     void Pit_shrp(
    286         int16 * x,                           /* in/out: impulse response (or algebraic code) */
    287         int16 pit_lag,                       /* input : pitch lag                            */
    288         int16 sharp,                         /* input : pitch sharpening factor (Q15)        */
    289         int16 L_subfr                        /* input : subframe size                        */
    290     );
    291 
    292 
    293     /*-----------------------------------------------------------------*
    294      *                        others prototypes                        *
    295      *-----------------------------------------------------------------*/
    296 
    297     int16 voice_factor(                       /* (o) Q15 : factor (-1=unvoiced to 1=voiced) */
    298         int16 exc[],                         /* (i) Q_exc: pitch excitation                */
    299         int16 Q_exc,                         /* (i)     : exc format                       */
    300         int16 gain_pit,                      /* (i) Q14 : gain of pitch                    */
    301         int16 code[],                        /* (i) Q9  : Fixed codebook excitation        */
    302         int16 gain_code,                     /* (i) Q0  : gain of code                     */
    303         int16 L_subfr                        /* (i)     : subframe length                  */
    304     );
    305 
    306     void scale_signal(
    307         int16 x[],                           /* (i/o) : signal to scale               */
    308         int16 lg,                            /* (i)   : size of x[]                   */
    309         int16 exp                            /* (i)   : exponent: x = round(x << exp) */
    310     );
    311 
    312     int16 noise_gen_amrwb(int16 * seed);
    313 
    314 
    315     void phase_dispersion(
    316         int16 gain_code,                     /* (i) Q0  : gain of code             */
    317         int16 gain_pit,                      /* (i) Q14 : gain of pitch            */
    318         int16 code[],                        /* (i/o)   : code vector              */
    319         int16 mode,                          /* (i)     : level, 0=hi, 1=lo, 2=off */
    320         int16 disp_mem[],                    /* (i/o)   :  memory (size = 8) */
    321         int16 ScratchMem[]
    322     );
    323 
    324 #ifdef __cplusplus
    325 }
    326 #endif
    327 
    328 #endif  /* ACELP_H */
    329 
    330