]>
Commit | Line | Data |
---|---|---|
964dd0bc JW |
1 | /* JOrbis |
2 | * Copyright (C) 2000 ymnk, JCraft,Inc. | |
3 | * | |
4 | * Written by: 2000 ymnk<ymnk@jcraft.com> | |
5 | * | |
6 | * Many thanks to | |
7 | * Monty <monty@xiph.org> and | |
8 | * The XIPHOPHORUS Company http://www.xiph.org/ . | |
9 | * JOrbis has been based on their awesome works, Vorbis codec. | |
10 | * | |
11 | * This program is free software; you can redistribute it and/or | |
12 | * modify it under the terms of the GNU Library General Public License | |
13 | * as published by the Free Software Foundation; either version 2 of | |
14 | * the License, or (at your option) any later version. | |
15 | ||
16 | * This program is distributed in the hope that it will be useful, | |
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | * GNU Library General Public License for more details. | |
20 | * | |
21 | * You should have received a copy of the GNU Library General Public | |
22 | * License along with this program; if not, write to the Free Software | |
23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
24 | */ | |
25 | ||
26 | package com.jcraft.jorbis; | |
27 | ||
28 | /* | |
29 | function: LSP (also called LSF) conversion routines | |
30 | ||
31 | The LSP generation code is taken (with minimal modification) from | |
32 | "On the Computation of the LSP Frequencies" by Joseph Rothweiler | |
33 | <rothwlr@altavista.net>, available at: | |
34 | ||
35 | http://www2.xtdl.com/~rothwlr/lsfpaper/lsfpage.html | |
36 | ********************************************************************/ | |
37 | ||
38 | class Lsp{ | |
39 | ||
40 | static final float M_PI=(float)(3.1415926539); | |
41 | ||
42 | static void lsp_to_curve(float[] curve, | |
43 | int[] map, int n, int ln, | |
44 | float[] lsp, int m, | |
45 | float amp, float ampoffset){ | |
46 | int i; | |
47 | float wdel=M_PI/ln; | |
48 | for(i=0;i<m;i++)lsp[i]=Lookup.coslook(lsp[i]); | |
49 | int m2=(m/2)*2; | |
50 | ||
51 | i=0; | |
52 | while(i<n){ | |
53 | int k=map[i]; | |
54 | float p=.7071067812f; | |
55 | float q=.7071067812f; | |
56 | float w=Lookup.coslook(wdel*k); | |
57 | int ftmp=0; | |
58 | int c=m>>>1; | |
59 | ||
60 | for(int j=0;j<m2;j+=2){ | |
61 | q*=lsp[j]-w; | |
62 | p*=lsp[j+1]-w; | |
63 | } | |
64 | ||
65 | if((m&1)!=0){ | |
66 | /* odd order filter; slightly assymetric */ | |
67 | /* the last coefficient */ | |
68 | q*=lsp[m-1]-w; | |
69 | q*=q; | |
70 | p*=p*(1.f-w*w); | |
71 | } | |
72 | else{ | |
73 | /* even order filter; still symmetric */ | |
74 | q*=q*(1.f+w); | |
75 | p*=p*(1.f-w); | |
76 | } | |
77 | ||
78 | // q=frexp(p+q,&qexp); | |
79 | q=p+q; | |
80 | int hx=Float.floatToIntBits(q); | |
81 | int ix=0x7fffffff&hx; | |
82 | int qexp=0; | |
83 | ||
84 | if(ix>=0x7f800000||(ix==0)){ | |
85 | // 0,inf,nan | |
86 | } | |
87 | else{ | |
88 | if(ix<0x00800000){ // subnormal | |
89 | q*=3.3554432000e+07; // 0x4c000000 | |
90 | hx=Float.floatToIntBits(q); | |
91 | ix=0x7fffffff&hx; | |
92 | qexp=-25; | |
93 | } | |
94 | qexp += ((ix>>>23)-126); | |
95 | hx=(hx&0x807fffff)|0x3f000000; | |
96 | q=Float.intBitsToFloat(hx); | |
97 | } | |
98 | ||
99 | q=Lookup.fromdBlook(amp* | |
100 | Lookup.invsqlook(q)* | |
101 | Lookup.invsq2explook(qexp+m)-ampoffset); | |
102 | ||
103 | do{curve[i++]*=q;} | |
104 | // do{curve[i++]=q;} | |
105 | while(i<n&&map[i]==k); | |
106 | ||
107 | } | |
108 | } | |
109 | } | |
110 | ||
111 |