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 13 iLBC Speech Coder ANSI-C Source Code 14 15 WebRtcIlbcfix_GainDequant.c 16 17 ******************************************************************/ 18 19 #include "modules/audio_coding/codecs/ilbc/gain_dequant.h" 20 21 #include "modules/audio_coding/codecs/ilbc/constants.h" 22 #include "modules/audio_coding/codecs/ilbc/defines.h" 23 24 /*----------------------------------------------------------------* 25 * decoder for quantized gains in the gain-shape coding of 26 * residual 27 *---------------------------------------------------------------*/ 28 WebRtcIlbcfix_GainDequant(int16_t index,int16_t maxIn,int16_t stage)29int16_t WebRtcIlbcfix_GainDequant( 30 /* (o) quantized gain value (Q14) */ 31 int16_t index, /* (i) quantization index */ 32 int16_t maxIn, /* (i) maximum of unquantized gain (Q14) */ 33 int16_t stage /* (i) The stage of the search */ 34 ){ 35 int16_t scale; 36 const int16_t *gain; 37 38 /* obtain correct scale factor */ 39 40 scale=WEBRTC_SPL_ABS_W16(maxIn); 41 scale = WEBRTC_SPL_MAX(1638, scale); /* if lower than 0.1, set it to 0.1 */ 42 43 /* select the quantization table and return the decoded value */ 44 gain = WebRtcIlbcfix_kGain[stage]; 45 46 return (int16_t)((scale * gain[index] + 8192) >> 14); 47 } 48