isp_isf.c revision e2e838afcf03e603a41a0455846eaf9614537c16
1e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard/* 2e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard ** Copyright 2003-2010, VisualOn, Inc. 3e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard ** 4e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard ** Licensed under the Apache License, Version 2.0 (the "License"); 5e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard ** you may not use this file except in compliance with the License. 6e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard ** You may obtain a copy of the License at 7e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard ** 8e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard ** http://www.apache.org/licenses/LICENSE-2.0 9e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard ** 10e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard ** Unless required by applicable law or agreed to in writing, software 11e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard ** distributed under the License is distributed on an "AS IS" BASIS, 12e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard ** See the License for the specific language governing permissions and 14e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard ** limitations under the License. 15e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard */ 16e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard 17e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard/*********************************************************************** 18e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard* File: isp_isf.c * 19e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard* * 20e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard* Description: * 21e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard* Isp_isf Transformation isp to isf * 22e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard* Isf_isp Transformation isf to isp * 23e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard* * 24e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard* The transformation from isp[i] to isf[i] and isf[i] to isp[i] * 25e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard* are approximated by a look-up table and interpolation * 26e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard* * 27e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard************************************************************************/ 28e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard 29e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard#include "typedef.h" 30e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard#include "basic_op.h" 31e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard#include "isp_isf.tab" /* Look-up table for transformations */ 32e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard 33e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgardvoid Isp_isf( 34e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard Word16 isp[], /* (i) Q15 : isp[m] (range: -1<=val<1) */ 35e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard Word16 isf[], /* (o) Q15 : isf[m] normalized (range: 0.0<=val<=0.5) */ 36e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard Word16 m /* (i) : LPC order */ 37e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard ) 38e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard{ 39e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard Word32 i, ind; 40e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard Word32 L_tmp; 41e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard ind = 127; /* beging at end of table -1 */ 42e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard for (i = (m - 1); i >= 0; i--) 43e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard { 44e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard if (i >= (m - 2)) 45e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard { /* m-2 is a constant */ 46e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard ind = 127; /* beging at end of table -1 */ 47e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard } 48e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard /* find value in table that is just greater than isp[i] */ 49e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard while (table[ind] < isp[i]) 50e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard ind--; 51e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard /* acos(isp[i])= ind*128 + ( ( isp[i]-table[ind] ) * slope[ind] )/2048 */ 52e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard L_tmp = vo_L_mult(vo_sub(isp[i], table[ind]), slope[ind]); 53e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard isf[i] = vo_round((L_tmp << 4)); /* (isp[i]-table[ind])*slope[ind])>>11 */ 54e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard isf[i] = add1(isf[i], (ind << 7)); 55e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard } 56e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard isf[m - 1] = (isf[m - 1] >> 1); 57e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard return; 58e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard} 59e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard 60e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard 61e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgardvoid Isf_isp( 62e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard Word16 isf[], /* (i) Q15 : isf[m] normalized (range: 0.0<=val<=0.5) */ 63e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard Word16 isp[], /* (o) Q15 : isp[m] (range: -1<=val<1) */ 64e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard Word16 m /* (i) : LPC order */ 65e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard ) 66e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard{ 67e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard Word16 offset; 68e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard Word32 i, ind, L_tmp; 69e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard 70e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard for (i = 0; i < m - 1; i++) 71e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard { 72e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard isp[i] = isf[i]; 73e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard } 74e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard isp[m - 1] = (isf[m - 1] << 1); 75e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard 76e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard for (i = 0; i < m; i++) 77e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard { 78e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard ind = (isp[i] >> 7); /* ind = b7-b15 of isf[i] */ 79e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard offset = (Word16) (isp[i] & 0x007f); /* offset = b0-b6 of isf[i] */ 80e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard 81e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard /* isp[i] = table[ind]+ ((table[ind+1]-table[ind])*offset) / 128 */ 82e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard L_tmp = vo_L_mult(vo_sub(table[ind + 1], table[ind]), offset); 83e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard isp[i] = add1(table[ind], (Word16)((L_tmp >> 8))); 84e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard } 85e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard 86e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard return; 87e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard} 88e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard 89e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard 90e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard 91e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard 92