acelp_pitch_delay.c

Go to the documentation of this file.
00001 /*
00002  * gain code, gain pitch and pitch delay decoding
00003  *
00004  * Copyright (c) 2008 Vladimir Voroshilov
00005  *
00006  * This file is part of FFmpeg.
00007  *
00008  * FFmpeg is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  *
00013  * FFmpeg is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with FFmpeg; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00021  */
00022 
00023 #include "avcodec.h"
00024 #include "acelp_pitch_delay.h"
00025 #include "acelp_math.h"
00026 
00027 int ff_acelp_decode_8bit_to_1st_delay3(int ac_index)
00028 {
00029     ac_index += 58;
00030     if(ac_index > 254)
00031         ac_index = 3 * ac_index - 510;
00032     return ac_index;
00033 }
00034 
00035 int ff_acelp_decode_4bit_to_2nd_delay3(
00036         int ac_index,
00037         int pitch_delay_min)
00038 {
00039     if(ac_index < 4)
00040         return 3 * (ac_index + pitch_delay_min);
00041     else if(ac_index < 12)
00042         return 3 * pitch_delay_min + ac_index + 6;
00043     else
00044         return 3 * (ac_index + pitch_delay_min) - 18;
00045 }
00046 
00047 int ff_acelp_decode_5_6_bit_to_2nd_delay3(
00048         int ac_index,
00049         int pitch_delay_min)
00050 {
00051         return 3 * pitch_delay_min + ac_index - 2;
00052 }
00053 
00054 int ff_acelp_decode_9bit_to_1st_delay6(int ac_index)
00055 {
00056     if(ac_index < 463)
00057         return ac_index + 105;
00058     else
00059         return 6 * (ac_index - 368);
00060 }
00061 int ff_acelp_decode_6bit_to_2nd_delay6(
00062         int ac_index,
00063         int pitch_delay_min)
00064 {
00065     return 6 * pitch_delay_min + ac_index - 3;
00066 }
00067 
00068 void ff_acelp_update_past_gain(
00069     int16_t* quant_energy,
00070     int gain_corr_factor,
00071     int log2_ma_pred_order,
00072     int erasure)
00073 {
00074     int i;
00075     int avg_gain=quant_energy[(1 << log2_ma_pred_order) - 1]; // (5.10)
00076 
00077     for(i=(1 << log2_ma_pred_order) - 1; i>0; i--)
00078     {
00079         avg_gain       += quant_energy[i-1];
00080         quant_energy[i] = quant_energy[i-1];
00081     }
00082 
00083     if(erasure)
00084         quant_energy[0] = FFMAX(avg_gain >> log2_ma_pred_order, -10240) - 4096; // -10 and -4 in (5.10)
00085     else
00086         quant_energy[0] = (6165 * ((ff_log2(gain_corr_factor) >> 2) - (13 << 13))) >> 13;
00087 }
00088 
00089 int16_t ff_acelp_decode_gain_code(
00090     int gain_corr_factor,
00091     const int16_t* fc_v,
00092     int mr_energy,
00093     const int16_t* quant_energy,
00094     const int16_t* ma_prediction_coeff,
00095     int subframe_size,
00096     int ma_pred_order)
00097 {
00098     int i;
00099 
00100     mr_energy <<= 10;
00101 
00102     for(i=0; i<ma_pred_order; i++)
00103         mr_energy += quant_energy[i] * ma_prediction_coeff[i];
00104 
00105 #ifdef G729_BITEXACT
00106     mr_energy += (((-6165LL * ff_log2(dot_product(fc_v, fc_v, subframe_size, 0))) >> 3) & ~0x3ff);
00107 
00108     mr_energy = (5439 * (mr_energy >> 15)) >> 8;           // (0.15) = (0.15) * (7.23)
00109 
00110     return bidir_sal(
00111                ((ff_exp2(mr_energy & 0x7fff) + 16) >> 5) * (gain_corr_factor >> 1),
00112                (mr_energy >> 15) - 25
00113            );
00114 #else
00115     mr_energy = gain_corr_factor * exp(M_LN10 / (20 << 23) * mr_energy) /
00116                 sqrt(dot_product(fc_v, fc_v, subframe_size, 0));
00117     return mr_energy >> 12;
00118 #endif
00119 }

Generated on Thu Aug 28 04:44:15 2008 for libextractor by  doxygen 1.5.1