gainquant.c

Go to the documentation of this file.
00001 
00002    /******************************************************************
00003 
00004        iLBC Speech Coder ANSI-C Source Code
00005 
00006 
00007 
00008 
00009 
00010 
00011        gainquant.c
00012 
00013        Copyright (C) The Internet Society (2004).
00014        All Rights Reserved.
00015 
00016    ******************************************************************/
00017 
00018    #include <string.h>
00019    #include <math.h>
00020    #include "constants.h"
00021    #include "filter.h"
00022 
00023    /*----------------------------------------------------------------*
00024     *  quantizer for the gain in the gain-shape coding of residual
00025     *---------------------------------------------------------------*/
00026 
00027    float gainquant(/* (o) quantized gain value */
00028        float in,       /* (i) gain value */
00029        float maxIn,/* (i) maximum of gain value */
00030        int cblen,      /* (i) number of quantization indices */
00031        int *index      /* (o) quantization index */
00032    ){
00033        int i, tindex;
00034        float minmeasure,measure, *cb, scale;
00035 
00036        /* ensure a lower bound on the scaling factor */
00037 
00038        scale=maxIn;
00039 
00040        if (scale<0.1) {
00041            scale=(float)0.1;
00042        }
00043 
00044        /* select the quantization table */
00045 
00046        if (cblen == 8) {
00047            cb = gain_sq3Tbl;
00048        } else if (cblen == 16) {
00049            cb = gain_sq4Tbl;
00050        } else  {
00051            cb = gain_sq5Tbl;
00052        }
00053 
00054        /* select the best index in the quantization table */
00055 
00056        minmeasure=10000000.0;
00057        tindex=0;
00058        for (i=0; i<cblen; i++) {
00059 
00060 
00061 
00062 
00063 
00064            measure=(in-scale*cb[i])*(in-scale*cb[i]);
00065 
00066            if (measure<minmeasure) {
00067                tindex=i;
00068                minmeasure=measure;
00069            }
00070        }
00071        *index=tindex;
00072 
00073        /* return the quantized value */
00074 
00075        return scale*cb[tindex];
00076    }
00077 
00078    /*----------------------------------------------------------------*
00079     *  decoder for quantized gains in the gain-shape coding of
00080     *  residual
00081     *---------------------------------------------------------------*/
00082 
00083    float gaindequant(  /* (o) quantized gain value */
00084        int index,      /* (i) quantization index */
00085        float maxIn,/* (i) maximum of unquantized gain */
00086        int cblen       /* (i) number of quantization indices */
00087    ){
00088        float scale;
00089 
00090        /* obtain correct scale factor */
00091 
00092        scale=(float)fabs(maxIn);
00093 
00094        if (scale<0.1) {
00095            scale=(float)0.1;
00096        }
00097 
00098        /* select the quantization table and return the decoded value */
00099 
00100        if (cblen==8) {
00101            return scale*gain_sq3Tbl[index];
00102        } else if (cblen==16) {
00103            return scale*gain_sq4Tbl[index];
00104        }
00105        else if (cblen==32) {
00106            return scale*gain_sq5Tbl[index];
00107        }
00108 
00109        return 0.0;
00110    }
00111 
00112 
00113 
00114 
00115 
00116 

Generated on Thu Apr 16 06:27:36 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6