1470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com/* 2470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 3470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com * 4470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com * Use of this source code is governed by a BSD-style license 5470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com * that can be found in the LICENSE file in the root of the source 6470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com * tree. An additional intellectual property rights grant can be found 7470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com * in the file PATENTS. All contributing project authors may 8470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com * be found in the AUTHORS file in the root of the source tree. 9470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com */ 10470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com 11470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com/****************************************************************** 12470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com 13470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com iLBC Speech Coder ANSI-C Source Code 14470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com 15470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com WebRtcIlbcfix_Lsf2Lsp.c 16470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com 17470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com******************************************************************/ 18470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com 19470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com#include "defines.h" 20470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com#include "constants.h" 21470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com 22470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com/*----------------------------------------------------------------* 23470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com * conversion from lsf to lsp coefficients 24470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com *---------------------------------------------------------------*/ 25470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com 26470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.comvoid WebRtcIlbcfix_Lsf2Lsp( 270946a56023d821e0deca04029bb016ae1f23aa82pbos@webrtc.org int16_t *lsf, /* (i) lsf in Q13 values between 0 and pi */ 280946a56023d821e0deca04029bb016ae1f23aa82pbos@webrtc.org int16_t *lsp, /* (o) lsp in Q15 values between -1 and 1 */ 290946a56023d821e0deca04029bb016ae1f23aa82pbos@webrtc.org int16_t m /* (i) number of coefficients */ 30470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com ) { 310946a56023d821e0deca04029bb016ae1f23aa82pbos@webrtc.org int16_t i, k; 320946a56023d821e0deca04029bb016ae1f23aa82pbos@webrtc.org int16_t diff; /* difference, which is used for the 33470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com linear approximation (Q8) */ 340946a56023d821e0deca04029bb016ae1f23aa82pbos@webrtc.org int16_t freq; /* normalized frequency in Q15 (0..1) */ 350946a56023d821e0deca04029bb016ae1f23aa82pbos@webrtc.org int32_t tmpW32; 36470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com 37470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com for(i=0; i<m; i++) 38470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com { 392f6ae0de5b0ca98cdcf3fd3c5a9848a5814aadddbjornv@webrtc.org freq = (int16_t)((lsf[i] * 20861) >> 15); 40470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com /* 20861: 1.0/(2.0*PI) in Q17 */ 41470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com /* 42470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com Upper 8 bits give the index k and 43470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com Lower 8 bits give the difference, which needs 44470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com to be approximated linearly 45470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com */ 46f71785cd3b282ad7d584d746ba5b19833a11692bbjornv@webrtc.org k = freq >> 8; 47470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com diff = (freq&0x00ff); 48470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com 49470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com /* Guard against getting outside table */ 50470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com 51470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com if (k>63) { 52470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com k = 63; 53470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com } 54470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com 55470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com /* Calculate linear approximation */ 56ba97ea69f0b8bb73a837869211627b705eac8f98bjornv@webrtc.org tmpW32 = WebRtcIlbcfix_kCosDerivative[k] * diff; 5778ea06dd34a584acad4a2cf2142de218cb06eef4bjornv@webrtc.org lsp[i] = WebRtcIlbcfix_kCos[k] + (int16_t)(tmpW32 >> 12); 58470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com } 59470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com 60470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com return; 61470e71d3649f6cac4688e83819640b012b5d38bbniklase@google.com} 62