Mercurial > mplayer.hg
annotate tremor/mapping0.c @ 34129:a7d1a3c3bc74
Prevent adding a base path wrongly.
For ports with DOS style paths, X:/ at the beginning is allowed
and not unusal. It must be treated as an absolute path.
author | ib |
---|---|
date | Thu, 20 Oct 2011 11:15:30 +0000 |
parents | e83eef58b30a |
children |
rev | line source |
---|---|
14280 | 1 /******************************************************************** |
2 * * | |
3 * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * | |
4 * * | |
19251
cd6b211be811
Replace tremor files that had old headers saying "ALL REDISTRIBUTION
uau
parents:
14280
diff
changeset
|
5 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * |
cd6b211be811
Replace tremor files that had old headers saying "ALL REDISTRIBUTION
uau
parents:
14280
diff
changeset
|
6 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * |
cd6b211be811
Replace tremor files that had old headers saying "ALL REDISTRIBUTION
uau
parents:
14280
diff
changeset
|
7 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * |
cd6b211be811
Replace tremor files that had old headers saying "ALL REDISTRIBUTION
uau
parents:
14280
diff
changeset
|
8 * * |
14280 | 9 * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * |
10 * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * | |
11 * * | |
12 ******************************************************************** | |
13 | |
14 function: channel mapping 0 implementation | |
15 | |
16 ********************************************************************/ | |
17 | |
18 #include <stdlib.h> | |
19 #include <stdio.h> | |
20 #include <string.h> | |
21 #include <math.h> | |
22 #include "ogg.h" | |
28240
4940b8a98c78
Fix r28222, including alloca.h directly might break compilation.
reimar
parents:
28187
diff
changeset
|
23 #include "os.h" |
14280 | 24 #include "ivorbiscodec.h" |
25 #include "mdct.h" | |
26 #include "codec_internal.h" | |
27 #include "codebook.h" | |
28 #include "window.h" | |
29 #include "registry.h" | |
30 #include "misc.h" | |
31 | |
32 /* simplistic, wasteful way of doing this (unique lookup for each | |
33 mode/submapping); there should be a central repository for | |
34 identical lookups. That will require minor work, so I'm putting it | |
35 off as low priority. | |
36 | |
37 Why a lookup for each backend in a given mode? Because the | |
38 blocksize is set by the mode, and low backend lookups may require | |
39 parameters from other areas of the mode/mapping */ | |
40 | |
41 typedef struct { | |
42 vorbis_info_mode *mode; | |
43 vorbis_info_mapping0 *map; | |
44 | |
45 vorbis_look_floor **floor_look; | |
46 | |
47 vorbis_look_residue **residue_look; | |
48 | |
49 vorbis_func_floor **floor_func; | |
50 vorbis_func_residue **residue_func; | |
51 | |
52 int ch; | |
29264
e83eef58b30a
Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents:
28240
diff
changeset
|
53 long lastframe; /* if a different mode is called, we need to |
14280 | 54 invalidate decay */ |
55 } vorbis_look_mapping0; | |
56 | |
57 static void mapping0_free_info(vorbis_info_mapping *i){ | |
58 vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)i; | |
59 if(info){ | |
60 memset(info,0,sizeof(*info)); | |
61 _ogg_free(info); | |
62 } | |
63 } | |
64 | |
65 static void mapping0_free_look(vorbis_look_mapping *look){ | |
66 int i; | |
67 vorbis_look_mapping0 *l=(vorbis_look_mapping0 *)look; | |
68 if(l){ | |
69 | |
70 for(i=0;i<l->map->submaps;i++){ | |
71 l->floor_func[i]->free_look(l->floor_look[i]); | |
72 l->residue_func[i]->free_look(l->residue_look[i]); | |
73 } | |
74 | |
75 _ogg_free(l->floor_func); | |
76 _ogg_free(l->residue_func); | |
77 _ogg_free(l->floor_look); | |
78 _ogg_free(l->residue_look); | |
79 memset(l,0,sizeof(*l)); | |
80 _ogg_free(l); | |
81 } | |
82 } | |
83 | |
84 static vorbis_look_mapping *mapping0_look(vorbis_dsp_state *vd,vorbis_info_mode *vm, | |
85 vorbis_info_mapping *m){ | |
86 int i; | |
87 vorbis_info *vi=vd->vi; | |
88 codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; | |
89 vorbis_look_mapping0 *look=(vorbis_look_mapping0 *)_ogg_calloc(1,sizeof(*look)); | |
90 vorbis_info_mapping0 *info=look->map=(vorbis_info_mapping0 *)m; | |
91 look->mode=vm; | |
29264
e83eef58b30a
Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents:
28240
diff
changeset
|
92 |
14280 | 93 look->floor_look=(vorbis_look_floor **)_ogg_calloc(info->submaps,sizeof(*look->floor_look)); |
94 | |
95 look->residue_look=(vorbis_look_residue **)_ogg_calloc(info->submaps,sizeof(*look->residue_look)); | |
96 | |
97 look->floor_func=(vorbis_func_floor **)_ogg_calloc(info->submaps,sizeof(*look->floor_func)); | |
98 look->residue_func=(vorbis_func_residue **)_ogg_calloc(info->submaps,sizeof(*look->residue_func)); | |
29264
e83eef58b30a
Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents:
28240
diff
changeset
|
99 |
14280 | 100 for(i=0;i<info->submaps;i++){ |
101 int floornum=info->floorsubmap[i]; | |
102 int resnum=info->residuesubmap[i]; | |
103 | |
104 look->floor_func[i]=_floor_P[ci->floor_type[floornum]]; | |
105 look->floor_look[i]=look->floor_func[i]-> | |
106 look(vd,vm,ci->floor_param[floornum]); | |
107 look->residue_func[i]=_residue_P[ci->residue_type[resnum]]; | |
108 look->residue_look[i]=look->residue_func[i]-> | |
109 look(vd,vm,ci->residue_param[resnum]); | |
29264
e83eef58b30a
Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents:
28240
diff
changeset
|
110 |
14280 | 111 } |
112 | |
113 look->ch=vi->channels; | |
114 | |
115 return(look); | |
116 } | |
117 | |
118 static int ilog(unsigned int v){ | |
119 int ret=0; | |
120 if(v)--v; | |
121 while(v){ | |
122 ret++; | |
123 v>>=1; | |
124 } | |
125 return(ret); | |
126 } | |
127 | |
128 /* also responsible for range checking */ | |
129 static vorbis_info_mapping *mapping0_unpack(vorbis_info *vi,oggpack_buffer *opb){ | |
130 int i; | |
131 vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)_ogg_calloc(1,sizeof(*info)); | |
132 codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; | |
133 memset(info,0,sizeof(*info)); | |
134 | |
135 if(oggpack_read(opb,1)) | |
136 info->submaps=oggpack_read(opb,4)+1; | |
137 else | |
138 info->submaps=1; | |
139 | |
140 if(oggpack_read(opb,1)){ | |
141 info->coupling_steps=oggpack_read(opb,8)+1; | |
142 | |
143 for(i=0;i<info->coupling_steps;i++){ | |
144 int testM=info->coupling_mag[i]=oggpack_read(opb,ilog(vi->channels)); | |
145 int testA=info->coupling_ang[i]=oggpack_read(opb,ilog(vi->channels)); | |
146 | |
29264
e83eef58b30a
Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents:
28240
diff
changeset
|
147 if(testM<0 || |
e83eef58b30a
Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents:
28240
diff
changeset
|
148 testA<0 || |
e83eef58b30a
Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents:
28240
diff
changeset
|
149 testM==testA || |
14280 | 150 testM>=vi->channels || |
151 testA>=vi->channels) goto err_out; | |
152 } | |
153 | |
154 } | |
155 | |
156 if(oggpack_read(opb,2)>0)goto err_out; /* 2,3:reserved */ | |
29264
e83eef58b30a
Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents:
28240
diff
changeset
|
157 |
14280 | 158 if(info->submaps>1){ |
159 for(i=0;i<vi->channels;i++){ | |
160 info->chmuxlist[i]=oggpack_read(opb,4); | |
161 if(info->chmuxlist[i]>=info->submaps)goto err_out; | |
162 } | |
163 } | |
164 for(i=0;i<info->submaps;i++){ | |
165 int temp=oggpack_read(opb,8); | |
166 if(temp>=ci->times)goto err_out; | |
167 info->floorsubmap[i]=oggpack_read(opb,8); | |
168 if(info->floorsubmap[i]>=ci->floors)goto err_out; | |
169 info->residuesubmap[i]=oggpack_read(opb,8); | |
170 if(info->residuesubmap[i]>=ci->residues)goto err_out; | |
171 } | |
172 | |
173 return info; | |
174 | |
175 err_out: | |
176 mapping0_free_info(info); | |
177 return(NULL); | |
178 } | |
179 | |
180 static int seq=0; | |
181 static int mapping0_inverse(vorbis_block *vb,vorbis_look_mapping *l){ | |
182 vorbis_dsp_state *vd=vb->vd; | |
183 vorbis_info *vi=vd->vi; | |
184 codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; | |
185 backend_lookup_state *b=(backend_lookup_state *)vd->backend_state; | |
186 vorbis_look_mapping0 *look=(vorbis_look_mapping0 *)l; | |
187 vorbis_info_mapping0 *info=look->map; | |
188 | |
189 int i,j; | |
190 long n=vb->pcmend=ci->blocksizes[vb->W]; | |
191 | |
192 ogg_int32_t **pcmbundle=(ogg_int32_t **)alloca(sizeof(*pcmbundle)*vi->channels); | |
193 int *zerobundle=(int *)alloca(sizeof(*zerobundle)*vi->channels); | |
29264
e83eef58b30a
Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents:
28240
diff
changeset
|
194 |
14280 | 195 int *nonzero =(int *)alloca(sizeof(*nonzero)*vi->channels); |
196 void **floormemo=(void **)alloca(sizeof(*floormemo)*vi->channels); | |
29264
e83eef58b30a
Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents:
28240
diff
changeset
|
197 |
14280 | 198 /* time domain information decode (note that applying the |
199 information would have to happen later; we'll probably add a | |
200 function entry to the harness for that later */ | |
201 /* NOT IMPLEMENTED */ | |
202 | |
203 /* recover the spectral envelope; store it in the PCM vector for now */ | |
204 for(i=0;i<vi->channels;i++){ | |
205 int submap=info->chmuxlist[i]; | |
206 floormemo[i]=look->floor_func[submap]-> | |
207 inverse1(vb,look->floor_look[submap]); | |
208 if(floormemo[i]) | |
209 nonzero[i]=1; | |
210 else | |
29264
e83eef58b30a
Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents:
28240
diff
changeset
|
211 nonzero[i]=0; |
14280 | 212 memset(vb->pcm[i],0,sizeof(*vb->pcm[i])*n/2); |
213 } | |
214 | |
215 /* channel coupling can 'dirty' the nonzero listing */ | |
216 for(i=0;i<info->coupling_steps;i++){ | |
217 if(nonzero[info->coupling_mag[i]] || | |
218 nonzero[info->coupling_ang[i]]){ | |
29264
e83eef58b30a
Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents:
28240
diff
changeset
|
219 nonzero[info->coupling_mag[i]]=1; |
e83eef58b30a
Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents:
28240
diff
changeset
|
220 nonzero[info->coupling_ang[i]]=1; |
14280 | 221 } |
222 } | |
223 | |
224 /* recover the residue into our working vectors */ | |
225 for(i=0;i<info->submaps;i++){ | |
226 int ch_in_bundle=0; | |
227 for(j=0;j<vi->channels;j++){ | |
228 if(info->chmuxlist[j]==i){ | |
229 if(nonzero[j]) | |
230 zerobundle[ch_in_bundle]=1; | |
231 else | |
232 zerobundle[ch_in_bundle]=0; | |
233 pcmbundle[ch_in_bundle++]=vb->pcm[j]; | |
234 } | |
235 } | |
29264
e83eef58b30a
Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents:
28240
diff
changeset
|
236 |
14280 | 237 look->residue_func[i]->inverse(vb,look->residue_look[i], |
238 pcmbundle,zerobundle,ch_in_bundle); | |
239 } | |
240 | |
241 //for(j=0;j<vi->channels;j++) | |
242 //_analysis_output("coupled",seq+j,vb->pcm[j],-8,n/2,0,0); | |
243 | |
244 | |
245 /* channel coupling */ | |
246 for(i=info->coupling_steps-1;i>=0;i--){ | |
247 ogg_int32_t *pcmM=vb->pcm[info->coupling_mag[i]]; | |
248 ogg_int32_t *pcmA=vb->pcm[info->coupling_ang[i]]; | |
29264
e83eef58b30a
Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents:
28240
diff
changeset
|
249 |
14280 | 250 for(j=0;j<n/2;j++){ |
251 ogg_int32_t mag=pcmM[j]; | |
252 ogg_int32_t ang=pcmA[j]; | |
29264
e83eef58b30a
Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents:
28240
diff
changeset
|
253 |
14280 | 254 if(mag>0) |
255 if(ang>0){ | |
256 pcmM[j]=mag; | |
257 pcmA[j]=mag-ang; | |
258 }else{ | |
259 pcmA[j]=mag; | |
260 pcmM[j]=mag+ang; | |
261 } | |
262 else | |
263 if(ang>0){ | |
264 pcmM[j]=mag; | |
265 pcmA[j]=mag+ang; | |
266 }else{ | |
267 pcmA[j]=mag; | |
268 pcmM[j]=mag-ang; | |
269 } | |
270 } | |
271 } | |
272 | |
273 //for(j=0;j<vi->channels;j++) | |
274 //_analysis_output("residue",seq+j,vb->pcm[j],-8,n/2,0,0); | |
275 | |
276 /* compute and apply spectral envelope */ | |
277 for(i=0;i<vi->channels;i++){ | |
278 ogg_int32_t *pcm=vb->pcm[i]; | |
279 int submap=info->chmuxlist[i]; | |
280 look->floor_func[submap]-> | |
281 inverse2(vb,look->floor_look[submap],floormemo[i],pcm); | |
282 } | |
283 | |
284 //for(j=0;j<vi->channels;j++) | |
285 //_analysis_output("mdct",seq+j,vb->pcm[j],-24,n/2,0,1); | |
286 | |
287 /* transform the PCM data; takes PCM vector, vb; modifies PCM vector */ | |
288 /* only MDCT right now.... */ | |
289 for(i=0;i<vi->channels;i++){ | |
290 ogg_int32_t *pcm=vb->pcm[i]; | |
291 mdct_backward(n,pcm,pcm); | |
292 } | |
293 | |
294 //for(j=0;j<vi->channels;j++) | |
295 //_analysis_output("imdct",seq+j,vb->pcm[j],-24,n,0,0); | |
296 | |
297 /* window the data */ | |
298 for(i=0;i<vi->channels;i++){ | |
299 ogg_int32_t *pcm=vb->pcm[i]; | |
300 if(nonzero[i]) | |
301 _vorbis_apply_window(pcm,b->window,ci->blocksizes,vb->lW,vb->W,vb->nW); | |
302 else | |
303 for(j=0;j<n;j++) | |
304 pcm[j]=0; | |
29264
e83eef58b30a
Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents:
28240
diff
changeset
|
305 |
14280 | 306 } |
307 | |
308 //for(j=0;j<vi->channels;j++) | |
309 //_analysis_output("window",seq+j,vb->pcm[j],-24,n,0,0); | |
310 | |
311 seq+=vi->channels; | |
312 /* all done! */ | |
313 return(0); | |
314 } | |
315 | |
316 /* export hooks */ | |
317 vorbis_func_mapping mapping0_exportbundle={ | |
318 &mapping0_unpack, | |
319 &mapping0_look, | |
320 &mapping0_free_info, | |
321 &mapping0_free_look, | |
322 &mapping0_inverse | |
323 }; |