blob: 07e09bb887ae047dec1c742dad287ab6a73bd33b [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
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 "defines.h"
20#include "constants.h"
21
22/*----------------------------------------------------------------*
23 * decoder for quantized gains in the gain-shape coding of
24 * residual
25 *---------------------------------------------------------------*/
26
pbos@webrtc.org0946a562013-04-09 00:28:06 +000027int16_t WebRtcIlbcfix_GainDequant(
niklase@google.com470e71d2011-07-07 08:21:25 +000028 /* (o) quantized gain value (Q14) */
pbos@webrtc.org0946a562013-04-09 00:28:06 +000029 int16_t index, /* (i) quantization index */
30 int16_t maxIn, /* (i) maximum of unquantized gain (Q14) */
31 int16_t stage /* (i) The stage of the search */
niklase@google.com470e71d2011-07-07 08:21:25 +000032 ){
pbos@webrtc.org0946a562013-04-09 00:28:06 +000033 int16_t scale;
34 const int16_t *gain;
niklase@google.com470e71d2011-07-07 08:21:25 +000035
36 /* obtain correct scale factor */
37
38 scale=WEBRTC_SPL_ABS_W16(maxIn);
39 scale = WEBRTC_SPL_MAX(1638, scale); /* if lower than 0.1, set it to 0.1 */
40
41 /* select the quantization table and return the decoded value */
42 gain = WebRtcIlbcfix_kGain[stage];
43
bjornv@webrtc.orgba97ea62015-02-13 09:51:40 +000044 return (int16_t)((scale * gain[index] + 8192) >> 14);
niklase@google.com470e71d2011-07-07 08:21:25 +000045}