getting rid of some hypot() calls
[platform/upstream/libvorbis.git] / lib / mapping0.c
1 /********************************************************************
2  *                                                                  *
3  * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
4  * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
5  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
6  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
7  *                                                                  *
8  * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001             *
9  * by the XIPHOPHORUS Company http://www.xiph.org/                  *
10  *                                                                  *
11  ********************************************************************
12
13  function: channel mapping 0 implementation
14  last mod: $Id: mapping0.c,v 1.40 2001/12/18 00:55:53 segher Exp $
15
16  ********************************************************************/
17
18 #include <stdlib.h>
19 #include <stdio.h>
20 #include <string.h>
21 #include <math.h>
22 #include <ogg/ogg.h>
23 #include "vorbis/codec.h"
24 #include "codec_internal.h"
25 #include "codebook.h"
26 #include "registry.h"
27 #include "psy.h"
28 #include "misc.h"
29
30 /* simplistic, wasteful way of doing this (unique lookup for each
31    mode/submapping); there should be a central repository for
32    identical lookups.  That will require minor work, so I'm putting it
33    off as low priority.
34
35    Why a lookup for each backend in a given mode?  Because the
36    blocksize is set by the mode, and low backend lookups may require
37    parameters from other areas of the mode/mapping */
38
39 extern int analysis_noisy;
40
41 typedef struct {
42   drft_lookup fft_look;
43   vorbis_info_mode *mode;
44   vorbis_info_mapping0 *map;
45
46   vorbis_look_time **time_look;
47   vorbis_look_floor **floor_look;
48
49   vorbis_look_residue **residue_look;
50   vorbis_look_psy *psy_look[2];
51
52   vorbis_func_time **time_func;
53   vorbis_func_floor **floor_func;
54   vorbis_func_residue **residue_func;
55
56   int ch;
57   long lastframe; /* if a different mode is called, we need to 
58                      invalidate decay */
59 } vorbis_look_mapping0;
60
61 static vorbis_info_mapping *mapping0_copy_info(vorbis_info_mapping *vm){
62   vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)vm;
63   vorbis_info_mapping0 *ret=_ogg_malloc(sizeof(*ret));
64   memcpy(ret,info,sizeof(*ret));
65   return(ret);
66 }
67
68 static void mapping0_free_info(vorbis_info_mapping *i){
69   vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)i;
70   if(info){
71     memset(info,0,sizeof(*info));
72     _ogg_free(info);
73   }
74 }
75
76 static void mapping0_free_look(vorbis_look_mapping *look){
77   int i;
78   vorbis_look_mapping0 *l=(vorbis_look_mapping0 *)look;
79   if(l){
80     drft_clear(&l->fft_look);
81
82     for(i=0;i<l->map->submaps;i++){
83       l->time_func[i]->free_look(l->time_look[i]);
84       l->floor_func[i]->free_look(l->floor_look[i]);
85       l->residue_func[i]->free_look(l->residue_look[i]);
86     }
87     if(l->psy_look[1] && l->psy_look[1]!=l->psy_look[0]){
88       _vp_psy_clear(l->psy_look[1]);
89       _ogg_free(l->psy_look[1]);
90     }
91     if(l->psy_look[0]){
92       _vp_psy_clear(l->psy_look[0]);
93       _ogg_free(l->psy_look[0]);
94     }
95     _ogg_free(l->time_func);
96     _ogg_free(l->floor_func);
97     _ogg_free(l->residue_func);
98     _ogg_free(l->time_look);
99     _ogg_free(l->floor_look);
100     _ogg_free(l->residue_look);
101     memset(l,0,sizeof(*l));
102     _ogg_free(l);
103   }
104 }
105
106 static vorbis_look_mapping *mapping0_look(vorbis_dsp_state *vd,vorbis_info_mode *vm,
107                           vorbis_info_mapping *m){
108   int i;
109   vorbis_info          *vi=vd->vi;
110   codec_setup_info     *ci=vi->codec_setup;
111   vorbis_look_mapping0 *look=_ogg_calloc(1,sizeof(*look));
112   vorbis_info_mapping0 *info=look->map=(vorbis_info_mapping0 *)m;
113   look->mode=vm;
114   
115   look->time_look=_ogg_calloc(info->submaps,sizeof(*look->time_look));
116   look->floor_look=_ogg_calloc(info->submaps,sizeof(*look->floor_look));
117
118   look->residue_look=_ogg_calloc(info->submaps,sizeof(*look->residue_look));
119
120   look->time_func=_ogg_calloc(info->submaps,sizeof(*look->time_func));
121   look->floor_func=_ogg_calloc(info->submaps,sizeof(*look->floor_func));
122   look->residue_func=_ogg_calloc(info->submaps,sizeof(*look->residue_func));
123   
124   for(i=0;i<info->submaps;i++){
125     int timenum=info->timesubmap[i];
126     int floornum=info->floorsubmap[i];
127     int resnum=info->residuesubmap[i];
128
129     look->time_func[i]=_time_P[ci->time_type[timenum]];
130     look->time_look[i]=look->time_func[i]->
131       look(vd,vm,ci->time_param[timenum]);
132     look->floor_func[i]=_floor_P[ci->floor_type[floornum]];
133     look->floor_look[i]=look->floor_func[i]->
134       look(vd,vm,ci->floor_param[floornum]);
135     look->residue_func[i]=_residue_P[ci->residue_type[resnum]];
136     look->residue_look[i]=look->residue_func[i]->
137       look(vd,vm,ci->residue_param[resnum]);
138     
139   }
140   if(ci->psys && vd->analysisp){
141     if(info->psy[0] != info->psy[1]){
142
143       int psynum=info->psy[0];
144       look->psy_look[0]=_ogg_calloc(1,sizeof(*look->psy_look[0]));      
145       _vp_psy_init(look->psy_look[0],ci->psy_param[psynum],
146                    &ci->psy_g_param,
147                    ci->blocksizes[vm->blockflag]/2,vi->rate);
148
149       psynum=info->psy[1];
150       look->psy_look[1]=_ogg_calloc(1,sizeof(*look->psy_look[1]));      
151       _vp_psy_init(look->psy_look[1],ci->psy_param[psynum],
152                    &ci->psy_g_param,
153                    ci->blocksizes[vm->blockflag]/2,vi->rate);
154     }else{
155
156       int psynum=info->psy[0];
157       look->psy_look[0]=_ogg_calloc(1,sizeof(*look->psy_look[0]));      
158       look->psy_look[1]=look->psy_look[0];
159       _vp_psy_init(look->psy_look[0],ci->psy_param[psynum],
160                    &ci->psy_g_param,
161                    ci->blocksizes[vm->blockflag]/2,vi->rate);
162
163     }
164   }
165
166   look->ch=vi->channels;
167
168   if(vd->analysisp)drft_init(&look->fft_look,ci->blocksizes[vm->blockflag]);
169   return(look);
170 }
171
172 static int ilog2(unsigned int v){
173   int ret=0;
174   while(v>1){
175     ret++;
176     v>>=1;
177   }
178   return(ret);
179 }
180
181 static void mapping0_pack(vorbis_info *vi,vorbis_info_mapping *vm,
182                           oggpack_buffer *opb){
183   int i;
184   vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)vm;
185
186   /* another 'we meant to do it this way' hack...  up to beta 4, we
187      packed 4 binary zeros here to signify one submapping in use.  We
188      now redefine that to mean four bitflags that indicate use of
189      deeper features; bit0:submappings, bit1:coupling,
190      bit2,3:reserved. This is backward compatable with all actual uses
191      of the beta code. */
192
193   if(info->submaps>1){
194     oggpack_write(opb,1,1);
195     oggpack_write(opb,info->submaps-1,4);
196   }else
197     oggpack_write(opb,0,1);
198
199   if(info->coupling_steps>0){
200     oggpack_write(opb,1,1);
201     oggpack_write(opb,info->coupling_steps-1,8);
202     
203     for(i=0;i<info->coupling_steps;i++){
204       oggpack_write(opb,info->coupling_mag[i],ilog2(vi->channels));
205       oggpack_write(opb,info->coupling_ang[i],ilog2(vi->channels));
206     }
207   }else
208     oggpack_write(opb,0,1);
209   
210   oggpack_write(opb,0,2); /* 2,3:reserved */
211
212   /* we don't write the channel submappings if we only have one... */
213   if(info->submaps>1){
214     for(i=0;i<vi->channels;i++)
215       oggpack_write(opb,info->chmuxlist[i],4);
216   }
217   for(i=0;i<info->submaps;i++){
218     oggpack_write(opb,info->timesubmap[i],8);
219     oggpack_write(opb,info->floorsubmap[i],8);
220     oggpack_write(opb,info->residuesubmap[i],8);
221   }
222 }
223
224 /* also responsible for range checking */
225 static vorbis_info_mapping *mapping0_unpack(vorbis_info *vi,oggpack_buffer *opb){
226   int i;
227   vorbis_info_mapping0 *info=_ogg_calloc(1,sizeof(*info));
228   codec_setup_info     *ci=vi->codec_setup;
229   memset(info,0,sizeof(*info));
230
231   if(oggpack_read(opb,1))
232     info->submaps=oggpack_read(opb,4)+1;
233   else
234     info->submaps=1;
235
236   if(oggpack_read(opb,1)){
237     info->coupling_steps=oggpack_read(opb,8)+1;
238
239     for(i=0;i<info->coupling_steps;i++){
240       int testM=info->coupling_mag[i]=oggpack_read(opb,ilog2(vi->channels));
241       int testA=info->coupling_ang[i]=oggpack_read(opb,ilog2(vi->channels));
242
243       if(testM<0 || 
244          testA<0 || 
245          testM==testA || 
246          testM>=vi->channels ||
247          testA>=vi->channels) goto err_out;
248     }
249
250   }
251
252   if(oggpack_read(opb,2)>0)goto err_out; /* 2,3:reserved */
253     
254   if(info->submaps>1){
255     for(i=0;i<vi->channels;i++){
256       info->chmuxlist[i]=oggpack_read(opb,4);
257       if(info->chmuxlist[i]>=info->submaps)goto err_out;
258     }
259   }
260   for(i=0;i<info->submaps;i++){
261     info->timesubmap[i]=oggpack_read(opb,8);
262     if(info->timesubmap[i]>=ci->times)goto err_out;
263     info->floorsubmap[i]=oggpack_read(opb,8);
264     if(info->floorsubmap[i]>=ci->floors)goto err_out;
265     info->residuesubmap[i]=oggpack_read(opb,8);
266     if(info->residuesubmap[i]>=ci->residues)goto err_out;
267   }
268
269   return info;
270
271  err_out:
272   mapping0_free_info(info);
273   return(NULL);
274 }
275
276 #include "os.h"
277 #include "lpc.h"
278 #include "lsp.h"
279 #include "envelope.h"
280 #include "mdct.h"
281 #include "psy.h"
282 #include "scales.h"
283
284 /* no time mapping implementation for now */
285 static long seq=0;
286 static int mapping0_forward(vorbis_block *vb,vorbis_look_mapping *l){
287   vorbis_dsp_state      *vd=vb->vd;
288   vorbis_info           *vi=vd->vi;
289   codec_setup_info      *ci=vi->codec_setup;
290   backend_lookup_state  *b=vb->vd->backend_state;
291   bitrate_manager_state *bm=&b->bms;
292   vorbis_look_mapping0  *look=(vorbis_look_mapping0 *)l;
293   vorbis_info_mapping0  *info=look->map;
294   vorbis_info_mode      *mode=look->mode;
295   vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
296   int                    n=vb->pcmend;
297   int i,j;
298   float *window=b->window[vb->W][vb->lW][vb->nW][mode->windowtype];
299   int   *nonzero=alloca(sizeof(*nonzero)*vi->channels);
300
301   float *work=_vorbis_block_alloc(vb,n*sizeof(*work));
302
303   float global_ampmax=vbi->ampmax;
304   float *local_ampmax=alloca(sizeof(*local_ampmax)*vi->channels);
305   int blocktype=vbi->blocktype;
306
307   /* we differentiate between short and long block types to help the
308      masking engine; the window shapes also matter.
309      impulse block (a short block in which an impulse occurs)
310      padding block (a short block that pads between a transitional 
311           long block and an impulse block, or vice versa)
312      transition block (the wqeird one; a long block with the transition 
313           window; affects bass/midrange response and that must be 
314           accounted for in masking) 
315      long block (run of the mill long block)
316   */
317
318   for(i=0;i<vi->channels;i++){
319     float scale=4.f/n;
320     float scale_dB;
321
322     /* the following makes things clearer to *me* anyway */
323     float *pcm     =vb->pcm[i]; 
324     float *fft     =work;
325     float *logfft  =pcm+n/2;
326
327     /*float *res     =pcm;
328     float *mdct    =pcm;
329     float *codedflr=pcm+n/2;
330     float *logmax  =work;
331     float *logmask =work+n/2;*/
332
333     scale_dB=todB(&scale);
334     _analysis_output("pcm",seq+i,pcm,n,0,0);
335
336     /* window the PCM data */
337     for(j=0;j<n;j++)
338       fft[j]=pcm[j]*=window[j];
339     
340     //_analysis_output("windowed",seq+i,pcm,n,0,0);
341
342     /* transform the PCM data */
343     /* only MDCT right now.... */
344     mdct_forward(b->transform[vb->W][0],pcm,pcm);
345     
346     /* FFT yields more accurate tonal estimation (not phase sensitive) */
347     drft_forward(&look->fft_look,fft);
348     fft[0]*=scale;
349     logfft[0]=todB(fft);
350     local_ampmax[i]=logfft[0];
351     for(j=1;j<n-1;j+=2){
352       float temp=fft[j]*fft[j]+fft[j+1]*fft[j+1];
353       temp=logfft[(j+1)>>1]=scale_dB+.5f*todB(&temp);
354       if(temp>local_ampmax[i])local_ampmax[i]=temp;
355     }
356
357     if(local_ampmax[i]>0.f)local_ampmax[i]=0.f;
358     if(local_ampmax[i]>global_ampmax)global_ampmax=local_ampmax[i];
359
360     _analysis_output("fft",seq+i,logfft,n/2,1,0);
361   }
362
363   for(i=0;i<vi->channels;i++){
364     int submap=info->chmuxlist[i];
365
366     /* the following makes things clearer to *me* anyway */
367     float *mdct    =vb->pcm[i]; 
368     float *res     =mdct;
369     float *codedflr=mdct+n/2;
370     float *logfft  =mdct+n/2;
371
372     float *logmdct =work;
373     float *logmax  =mdct+n/2;
374     float *logmask =work+n/2;
375
376     for(j=0;j<n/2;j++)
377       logmdct[j]=todB(mdct+j);
378     _analysis_output("mdct",seq+i,logmdct,n/2,1,0);
379
380
381     /* perform psychoacoustics; do masking */
382     _vp_compute_mask(look->psy_look[blocktype],
383                      b->psy_g_look,
384                      i,
385                      logfft, /* -> logmax */
386                      logmdct,
387                      logmask,
388                      global_ampmax,
389                      local_ampmax[i],
390                      ci->blocksizes[vb->lW]/2,
391                      bm->avgnoise);
392
393     _analysis_output("mask",seq+i,logmask,n/2,1,0);
394     /* perform floor encoding */
395     nonzero[i]=look->floor_func[submap]->
396       forward(vb,look->floor_look[submap],
397               mdct,
398               logmdct,
399               logmask,
400               logmax,
401
402               codedflr);
403
404
405     _vp_remove_floor(look->psy_look[blocktype],
406                      b->psy_g_look,
407                      logmdct,
408                      mdct,
409                      codedflr,
410                      res,
411                      local_ampmax[i]);
412
413     /*for(j=0;j<n/2;j++)
414       if(fabs(res[j])>1200){
415         analysis_noisy=1;
416         fprintf(stderr,"%ld ",seq+i);
417         }*/
418
419     //_analysis_output("res",seq+i,res,n/2,1,0);
420     _analysis_output("codedflr",seq+i,codedflr,n/2,1,1);
421       
422   }
423
424   vbi->ampmax=global_ampmax;
425
426   /* partition based prequantization and channel coupling */
427   /* Steps in prequant and coupling:
428
429      classify by |mag| across all pcm vectors 
430
431      down-couple/down-quantize from perfect residue ->  quantized vector 
432      
433      do{ 
434         encode quantized vector; add encoded values to 'so-far' vector
435         more? [not yet at bitrate/not yet at target]
436           yes{
437               down-couple/down-quantize from perfect-'so-far' -> 
438                 quantized vector; when subtracting coupling, 
439                 account for +/- out-of-phase component
440           }no{  
441               break
442           }
443      }
444      done.
445
446      quantization in each iteration is done (after circular normalization 
447      in coupling) using a by-iteration quantization granule value.
448   */
449    
450   {
451     float  **pcm=vb->pcm;
452     float  **quantized=alloca(sizeof(*quantized)*vi->channels);
453     float  **sofar=alloca(sizeof(*sofar)*vi->channels);
454
455     long  ***classifications=alloca(sizeof(*classifications)*info->submaps);
456     float ***qbundle=alloca(sizeof(*qbundle)*info->submaps);
457     float ***pcmbundle=alloca(sizeof(*pcmbundle)*info->submaps);
458     float ***sobundle=alloca(sizeof(*sobundle)*info->submaps);
459     int    **zerobundle=alloca(sizeof(*zerobundle)*info->submaps);
460     int     *chbundle=alloca(sizeof(*chbundle)*info->submaps);
461     int      chcounter=0;
462
463     /* play a little loose with this abstraction */
464     int   quant_passes=ci->coupling_passes;
465
466     for(i=0;i<vi->channels;i++){
467       quantized[i]=_vorbis_block_alloc(vb,n*sizeof(*sofar[i]));
468       sofar[i]=quantized[i]+n/2;
469       memset(sofar[i],0,sizeof(*sofar[i])*n/2);
470     }
471
472     qbundle[0]=alloca(sizeof(*qbundle[0])*vi->channels);
473     pcmbundle[0]=alloca(sizeof(*pcmbundle[0])*vi->channels);
474     sobundle[0]=alloca(sizeof(*sobundle[0])*vi->channels);
475     zerobundle[0]=alloca(sizeof(*zerobundle[0])*vi->channels);
476
477     /* initial down-quantized coupling */
478     
479     if(info->coupling_steps==0){
480       /* this assumes all or nothing coupling right now.  it should pass
481          through any channels left uncoupled, but it doesn't do that now */
482       for(i=0;i<vi->channels;i++){
483         float *lpcm=pcm[i];
484         float *lqua=quantized[i];
485         for(j=0;j<n/2;j++)
486           lqua[j]=lpcm[j];
487       }
488     }else{
489       _vp_quantize_couple(look->psy_look[blocktype],
490                           info,
491                           pcm,
492                           sofar,
493                           quantized,
494                           nonzero,
495                           0);
496     }
497
498     //for(i=0;i<vi->channels;i++)
499     //_analysis_output("quant",seq+i,quantized[i],n/2,1,0);
500
501   
502     /* classify, by submap */
503
504     for(i=0;i<info->submaps;i++){
505       int ch_in_bundle=0;
506       qbundle[i]=qbundle[0]+chcounter;
507       sobundle[i]=sobundle[0]+chcounter;
508       zerobundle[i]=zerobundle[0]+chcounter;
509
510       for(j=0;j<vi->channels;j++){
511         if(info->chmuxlist[j]==i){
512           if(nonzero[j])
513             zerobundle[i][ch_in_bundle]=1;
514           else
515             zerobundle[i][ch_in_bundle]=0;
516           qbundle[i][ch_in_bundle]=quantized[j];
517           pcmbundle[i][ch_in_bundle]=pcm[j];
518           sobundle[i][ch_in_bundle++]=sofar[j];
519         }
520       }
521       chbundle[i]=ch_in_bundle;
522       chcounter+=ch_in_bundle;
523
524       classifications[i]=look->residue_func[i]->
525         class(vb,look->residue_look[i],pcmbundle[i],zerobundle[i],chbundle[i]);
526     }
527
528     /* actual encoding loop; we pack all the iterations to collect
529        management data */
530
531     for(i=0;i<quant_passes;){
532
533       /* perform residue encoding of this pass's quantized residue
534          vector, according residue mapping */
535     
536       for(j=0;j<info->submaps;j++){
537         look->residue_func[j]->
538           forward(vb,look->residue_look[j],
539                   qbundle[j],sobundle[j],zerobundle[j],chbundle[j],
540                   i,classifications[j],vbi->packet_markers);
541         
542       }
543       i++;
544         
545       if(i<quant_passes){
546         /* down-couple/down-quantize from perfect-'so-far' -> 
547          new quantized vector */
548         if(info->coupling_steps==0){
549           /* this assumes all or nothing coupling right now.  it should pass
550              through any channels left uncoupled, but it doesn't do that now */
551           int k;
552           for(k=0;k<vi->channels;k++){
553             float *lpcm=pcm[k];
554             float *lsof=sofar[k];
555             float *lqua=quantized[k];
556             for(j=0;j<n/2;j++)
557               lqua[j]=lpcm[j]-lsof[j];
558           }
559         }else{
560           char buf[80];
561           
562           _vp_quantize_couple(look->psy_look[blocktype],
563                               info,
564                               pcm,
565                               sofar,
566                               quantized,
567                               nonzero,
568                               i);
569           
570           //sprintf(buf,"quant%d",i);
571           //for(j=0;j<vi->channels;j++)
572           //_analysis_output(buf,seq+j,quantized[j],n/2,1,0);
573           
574         }
575       }
576     }
577     seq+=vi->channels;
578   } 
579
580   look->lastframe=vb->sequence;
581   return(0);
582 }
583
584 static int mapping0_inverse(vorbis_block *vb,vorbis_look_mapping *l){
585   vorbis_dsp_state     *vd=vb->vd;
586   vorbis_info          *vi=vd->vi;
587   codec_setup_info     *ci=vi->codec_setup;
588   backend_lookup_state *b=vd->backend_state;
589   vorbis_look_mapping0 *look=(vorbis_look_mapping0 *)l;
590   vorbis_info_mapping0 *info=look->map;
591   vorbis_info_mode     *mode=look->mode;
592   int                   i,j;
593   long                  n=vb->pcmend=ci->blocksizes[vb->W];
594
595   float *window=b->window[vb->W][vb->lW][vb->nW][mode->windowtype];
596   float **pcmbundle=alloca(sizeof(*pcmbundle)*vi->channels);
597   int    *zerobundle=alloca(sizeof(*zerobundle)*vi->channels);
598
599   int   *nonzero  =alloca(sizeof(*nonzero)*vi->channels);
600   void **floormemo=alloca(sizeof(*floormemo)*vi->channels);
601   
602   /* time domain information decode (note that applying the
603      information would have to happen later; we'll probably add a
604      function entry to the harness for that later */
605   /* NOT IMPLEMENTED */
606
607   /* recover the spectral envelope; store it in the PCM vector for now */
608   for(i=0;i<vi->channels;i++){
609     int submap=info->chmuxlist[i];
610     floormemo[i]=look->floor_func[submap]->
611       inverse1(vb,look->floor_look[submap]);
612     if(floormemo[i])
613       nonzero[i]=1;
614     else
615       nonzero[i]=0;      
616     memset(vb->pcm[i],0,sizeof(*vb->pcm[i])*n/2);
617   }
618
619   /* channel coupling can 'dirty' the nonzero listing */
620   for(i=0;i<info->coupling_steps;i++){
621     if(nonzero[info->coupling_mag[i]] ||
622        nonzero[info->coupling_ang[i]]){
623       nonzero[info->coupling_mag[i]]=1; 
624       nonzero[info->coupling_ang[i]]=1; 
625     }
626   }
627
628   /* recover the residue into our working vectors */
629   for(i=0;i<info->submaps;i++){
630     int ch_in_bundle=0;
631     for(j=0;j<vi->channels;j++){
632       if(info->chmuxlist[j]==i){
633         if(nonzero[j])
634           zerobundle[ch_in_bundle]=1;
635         else
636           zerobundle[ch_in_bundle]=0;
637         pcmbundle[ch_in_bundle++]=vb->pcm[j];
638       }
639     }
640     
641     look->residue_func[i]->inverse(vb,look->residue_look[i],
642                                    pcmbundle,zerobundle,ch_in_bundle);
643   }
644
645   /* channel coupling */
646   for(i=info->coupling_steps-1;i>=0;i--){
647     float *pcmM=vb->pcm[info->coupling_mag[i]];
648     float *pcmA=vb->pcm[info->coupling_ang[i]];
649
650     for(j=0;j<n/2;j++){
651       float mag=pcmM[j];
652       float ang=pcmA[j];
653
654       if(mag>0)
655         if(ang>0){
656           pcmM[j]=mag;
657           pcmA[j]=mag-ang;
658         }else{
659           pcmA[j]=mag;
660           pcmM[j]=mag+ang;
661         }
662       else
663         if(ang>0){
664           pcmM[j]=mag;
665           pcmA[j]=mag+ang;
666         }else{
667           pcmA[j]=mag;
668           pcmM[j]=mag-ang;
669         }
670     }
671   }
672
673   /* compute and apply spectral envelope */
674   for(i=0;i<vi->channels;i++){
675     float *pcm=vb->pcm[i];
676     int submap=info->chmuxlist[i];
677     look->floor_func[submap]->
678       inverse2(vb,look->floor_look[submap],floormemo[i],pcm);
679   }
680
681   /* transform the PCM data; takes PCM vector, vb; modifies PCM vector */
682   /* only MDCT right now.... */
683   for(i=0;i<vi->channels;i++){
684     float *pcm=vb->pcm[i];
685     //_analysis_output("out",seq+i,pcm,n/2,1,1);
686     //_analysis_output("lout",seq+i,pcm,n/2,0,0);
687     mdct_backward(b->transform[vb->W][0],pcm,pcm);
688   }
689
690   /* window the data */
691   for(i=0;i<vi->channels;i++){
692     float *pcm=vb->pcm[i];
693     if(nonzero[i])
694       for(j=0;j<n;j++)
695         pcm[j]*=window[j];
696     else
697       for(j=0;j<n;j++)
698         pcm[j]=0.f;
699
700     //_analysis_output("final",seq,pcm,n,0,0);
701   }
702             
703   /* now apply the decoded post-window time information */
704   /* NOT IMPLEMENTED */
705
706   fprintf(stderr,"seq %d\r",seq);
707     
708   /* all done! */
709   return(0);
710 }
711
712 /* export hooks */
713 vorbis_func_mapping mapping0_exportbundle={
714   &mapping0_pack,
715   &mapping0_unpack,
716   &mapping0_look,
717   &mapping0_copy_info,
718   &mapping0_free_info,
719   &mapping0_free_look,
720   &mapping0_forward,
721   &mapping0_inverse
722 };