Initial branch merge toward rc3
[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.38 2001/12/12 09:45:25 xiphmont 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   if(seq%10==0)fprintf(stderr,"%d",seq);
319   if(!vb->W){
320     if(blocktype==BLOCKTYPE_IMPULSE)
321       fprintf(stderr,"|");
322     else
323       fprintf(stderr,".");
324   }else{
325     if(blocktype==BLOCKTYPE_TRANSITION)
326       fprintf(stderr,"-");
327     else
328       fprintf(stderr,"_");
329   }
330
331   for(i=0;i<vi->channels;i++){
332     float scale=4.f/n;
333
334     /* the following makes things clearer to *me* anyway */
335     float *pcm     =vb->pcm[i]; 
336     float *fft     =work;
337     float *logfft  =pcm+n/2;
338
339     /*float *res     =pcm;
340     float *mdct    =pcm;
341     float *codedflr=pcm+n/2;
342     float *logmax  =work;
343     float *logmask =work+n/2;*/
344
345     _analysis_output("pcm",seq+i,pcm,n,0,0);
346
347     /* window the PCM data */
348     for(j=0;j<n;j++)
349       fft[j]=pcm[j]*=window[j];
350     
351     //_analysis_output("windowed",seq+i,pcm,n,0,0);
352
353     /* transform the PCM data */
354     /* only MDCT right now.... */
355     mdct_forward(b->transform[vb->W][0],pcm,pcm);
356     
357     /* FFT yields more accurate tonal estimation (not phase sensitive) */
358     drft_forward(&look->fft_look,fft);
359     fft[0]*=scale;
360     logfft[0]=todB(fft);
361     local_ampmax[i]=logfft[0];
362     for(j=1;j<n-1;j+=2){
363       float temp=scale*FAST_HYPOT(fft[j],fft[j+1]);
364       temp=logfft[(j+1)>>1]=todB(&temp);
365       if(temp>local_ampmax[i])local_ampmax[i]=temp;
366     }
367
368     if(local_ampmax[i]>0.f)local_ampmax[i]=0.f;
369     if(local_ampmax[i]>global_ampmax)global_ampmax=local_ampmax[i];
370
371     _analysis_output("fft",seq+i,logfft,n/2,1,0);
372   }
373
374   for(i=0;i<vi->channels;i++){
375     int submap=info->chmuxlist[i];
376
377     /* the following makes things clearer to *me* anyway */
378     float *mdct    =vb->pcm[i]; 
379     float *res     =mdct;
380     float *codedflr=mdct+n/2;
381     float *logfft  =mdct+n/2;
382
383     float *logmdct =work;
384     float *logmax  =mdct+n/2;
385     float *logmask =work+n/2;
386
387     for(j=0;j<n/2;j++)
388       logmdct[j]=todB(mdct+j);
389     _analysis_output("mdct",seq+i,logmdct,n/2,1,0);
390
391
392     /* perform psychoacoustics; do masking */
393     _vp_compute_mask(look->psy_look[blocktype],
394                      b->psy_g_look,
395                      i,
396                      logfft, /* -> logmax */
397                      logmdct,
398                      logmask,
399                      global_ampmax,
400                      local_ampmax[i],
401                      ci->blocksizes[vb->lW]/2,
402                      bm->avgnoise);
403
404     _analysis_output("mask",seq+i,logmask,n/2,1,0);
405     /* perform floor encoding */
406     nonzero[i]=look->floor_func[submap]->
407       forward(vb,look->floor_look[submap],
408               mdct,
409               logmdct,
410               logmask,
411               logmax,
412
413               codedflr);
414
415
416     _vp_remove_floor(look->psy_look[blocktype],
417                      b->psy_g_look,
418                      logmdct,
419                      mdct,
420                      codedflr,
421                      res,
422                      local_ampmax[i]);
423
424     /*for(j=0;j<n/2;j++)
425       if(fabs(res[j])>1200){
426         analysis_noisy=1;
427         fprintf(stderr,"%ld ",seq+i);
428         }*/
429
430     //_analysis_output("res",seq+i,res,n/2,1,0);
431     _analysis_output("codedflr",seq+i,codedflr,n/2,1,1);
432       
433   }
434
435   vbi->ampmax=global_ampmax;
436
437   /* partition based prequantization and channel coupling */
438   /* Steps in prequant and coupling:
439
440      classify by |mag| across all pcm vectors 
441
442      down-couple/down-quantize from perfect residue ->  quantized vector 
443      
444      do{ 
445         encode quantized vector; add encoded values to 'so-far' vector
446         more? [not yet at bitrate/not yet at target]
447           yes{
448               down-couple/down-quantize from perfect-'so-far' -> 
449                 quantized vector; when subtracting coupling, 
450                 account for +/- out-of-phase component
451           }no{  
452               break
453           }
454      }
455      done.
456
457      quantization in each iteration is done (after circular normalization 
458      in coupling) using a by-iteration quantization granule value.
459   */
460    
461   {
462     float  **pcm=vb->pcm;
463     float  **quantized=alloca(sizeof(*quantized)*vi->channels);
464     float  **sofar=alloca(sizeof(*sofar)*vi->channels);
465
466     long  ***classifications=alloca(sizeof(*classifications)*info->submaps);
467     float ***qbundle=alloca(sizeof(*qbundle)*info->submaps);
468     float ***pcmbundle=alloca(sizeof(*pcmbundle)*info->submaps);
469     float ***sobundle=alloca(sizeof(*sobundle)*info->submaps);
470     int    **zerobundle=alloca(sizeof(*zerobundle)*info->submaps);
471     int     *chbundle=alloca(sizeof(*chbundle)*info->submaps);
472     int      chcounter=0;
473
474     /* play a little loose with this abstraction */
475     int   quant_passes=ci->coupling_passes;
476
477     for(i=0;i<vi->channels;i++){
478       quantized[i]=_vorbis_block_alloc(vb,n*sizeof(*sofar[i]));
479       sofar[i]=quantized[i]+n/2;
480       memset(sofar[i],0,sizeof(*sofar[i])*n/2);
481     }
482
483     qbundle[0]=alloca(sizeof(*qbundle[0])*vi->channels);
484     pcmbundle[0]=alloca(sizeof(*pcmbundle[0])*vi->channels);
485     sobundle[0]=alloca(sizeof(*sobundle[0])*vi->channels);
486     zerobundle[0]=alloca(sizeof(*zerobundle[0])*vi->channels);
487
488     /* initial down-quantized coupling */
489     
490     if(info->coupling_steps==0){
491       /* this assumes all or nothing coupling right now.  it should pass
492          through any channels left uncoupled, but it doesn't do that now */
493       for(i=0;i<vi->channels;i++){
494         float *lpcm=pcm[i];
495         float *lqua=quantized[i];
496         for(j=0;j<n/2;j++)
497           lqua[j]=lpcm[j];
498       }
499     }else{
500       _vp_quantize_couple(look->psy_look[blocktype],
501                           info,
502                           pcm,
503                           sofar,
504                           quantized,
505                           nonzero,
506                           0);
507     }
508
509     //for(i=0;i<vi->channels;i++)
510     //_analysis_output("quant",seq+i,quantized[i],n/2,1,0);
511
512   
513     /* classify, by submap */
514
515     for(i=0;i<info->submaps;i++){
516       int ch_in_bundle=0;
517       qbundle[i]=qbundle[0]+chcounter;
518       sobundle[i]=sobundle[0]+chcounter;
519       zerobundle[i]=zerobundle[0]+chcounter;
520
521       for(j=0;j<vi->channels;j++){
522         if(info->chmuxlist[j]==i){
523           if(nonzero[j])
524             zerobundle[i][ch_in_bundle]=1;
525           else
526             zerobundle[i][ch_in_bundle]=0;
527           qbundle[i][ch_in_bundle]=quantized[j];
528           pcmbundle[i][ch_in_bundle]=pcm[j];
529           sobundle[i][ch_in_bundle++]=sofar[j];
530         }
531       }
532       chbundle[i]=ch_in_bundle;
533       chcounter+=ch_in_bundle;
534
535       classifications[i]=look->residue_func[i]->
536         class(vb,look->residue_look[i],pcmbundle[i],zerobundle[i],chbundle[i]);
537     }
538
539     /* actual encoding loop; we pack all the iterations to collect
540        management data */
541
542     for(i=0;i<quant_passes;){
543
544       /* perform residue encoding of this pass's quantized residue
545          vector, according residue mapping */
546     
547       for(j=0;j<info->submaps;j++){
548         look->residue_func[j]->
549           forward(vb,look->residue_look[j],
550                   qbundle[j],sobundle[j],zerobundle[j],chbundle[j],
551                   i,classifications[j],vbi->packet_markers);
552         
553       }
554       i++;
555         
556       if(i<quant_passes){
557         /* down-couple/down-quantize from perfect-'so-far' -> 
558          new quantized vector */
559         if(info->coupling_steps==0){
560           /* this assumes all or nothing coupling right now.  it should pass
561              through any channels left uncoupled, but it doesn't do that now */
562           int k;
563           for(k=0;k<vi->channels;k++){
564             float *lpcm=pcm[k];
565             float *lsof=sofar[k];
566             float *lqua=quantized[k];
567             for(j=0;j<n/2;j++)
568               lqua[j]=lpcm[j]-lsof[j];
569           }
570         }else{
571           char buf[80];
572           
573           _vp_quantize_couple(look->psy_look[blocktype],
574                               info,
575                               pcm,
576                               sofar,
577                               quantized,
578                               nonzero,
579                               i);
580           
581           //sprintf(buf,"quant%d",i);
582           //for(j=0;j<vi->channels;j++)
583           //_analysis_output(buf,seq+j,quantized[j],n/2,1,0);
584           
585         }
586       }
587     }
588     seq+=vi->channels;
589   } 
590
591   look->lastframe=vb->sequence;
592   return(0);
593 }
594
595 static int mapping0_inverse(vorbis_block *vb,vorbis_look_mapping *l){
596   vorbis_dsp_state     *vd=vb->vd;
597   vorbis_info          *vi=vd->vi;
598   codec_setup_info     *ci=vi->codec_setup;
599   backend_lookup_state *b=vd->backend_state;
600   vorbis_look_mapping0 *look=(vorbis_look_mapping0 *)l;
601   vorbis_info_mapping0 *info=look->map;
602   vorbis_info_mode     *mode=look->mode;
603   int                   i,j;
604   long                  n=vb->pcmend=ci->blocksizes[vb->W];
605
606   float *window=b->window[vb->W][vb->lW][vb->nW][mode->windowtype];
607   float **pcmbundle=alloca(sizeof(*pcmbundle)*vi->channels);
608   int    *zerobundle=alloca(sizeof(*zerobundle)*vi->channels);
609
610   int   *nonzero  =alloca(sizeof(*nonzero)*vi->channels);
611   void **floormemo=alloca(sizeof(*floormemo)*vi->channels);
612   
613   /* time domain information decode (note that applying the
614      information would have to happen later; we'll probably add a
615      function entry to the harness for that later */
616   /* NOT IMPLEMENTED */
617
618   /* recover the spectral envelope; store it in the PCM vector for now */
619   for(i=0;i<vi->channels;i++){
620     int submap=info->chmuxlist[i];
621     floormemo[i]=look->floor_func[submap]->
622       inverse1(vb,look->floor_look[submap]);
623     if(floormemo[i])
624       nonzero[i]=1;
625     else
626       nonzero[i]=0;      
627     memset(vb->pcm[i],0,sizeof(*vb->pcm[i])*n/2);
628   }
629
630   /* channel coupling can 'dirty' the nonzero listing */
631   for(i=0;i<info->coupling_steps;i++){
632     if(nonzero[info->coupling_mag[i]] ||
633        nonzero[info->coupling_ang[i]]){
634       nonzero[info->coupling_mag[i]]=1; 
635       nonzero[info->coupling_ang[i]]=1; 
636     }
637   }
638
639   /* recover the residue into our working vectors */
640   for(i=0;i<info->submaps;i++){
641     int ch_in_bundle=0;
642     for(j=0;j<vi->channels;j++){
643       if(info->chmuxlist[j]==i){
644         if(nonzero[j])
645           zerobundle[ch_in_bundle]=1;
646         else
647           zerobundle[ch_in_bundle]=0;
648         pcmbundle[ch_in_bundle++]=vb->pcm[j];
649       }
650     }
651     
652     look->residue_func[i]->inverse(vb,look->residue_look[i],
653                                    pcmbundle,zerobundle,ch_in_bundle);
654   }
655
656   /* channel coupling */
657   for(i=info->coupling_steps-1;i>=0;i--){
658     float *pcmM=vb->pcm[info->coupling_mag[i]];
659     float *pcmA=vb->pcm[info->coupling_ang[i]];
660
661     for(j=0;j<n/2;j++){
662       float mag=pcmM[j];
663       float ang=pcmA[j];
664
665       if(mag>0)
666         if(ang>0){
667           pcmM[j]=mag;
668           pcmA[j]=mag-ang;
669         }else{
670           pcmA[j]=mag;
671           pcmM[j]=mag+ang;
672         }
673       else
674         if(ang>0){
675           pcmM[j]=mag;
676           pcmA[j]=mag+ang;
677         }else{
678           pcmA[j]=mag;
679           pcmM[j]=mag-ang;
680         }
681     }
682   }
683
684   /* compute and apply spectral envelope */
685   for(i=0;i<vi->channels;i++){
686     float *pcm=vb->pcm[i];
687     int submap=info->chmuxlist[i];
688     look->floor_func[submap]->
689       inverse2(vb,look->floor_look[submap],floormemo[i],pcm);
690   }
691
692   /* transform the PCM data; takes PCM vector, vb; modifies PCM vector */
693   /* only MDCT right now.... */
694   for(i=0;i<vi->channels;i++){
695     float *pcm=vb->pcm[i];
696     //_analysis_output("out",seq+i,pcm,n/2,1,1);
697     //_analysis_output("lout",seq+i,pcm,n/2,0,0);
698     mdct_backward(b->transform[vb->W][0],pcm,pcm);
699   }
700
701   /* window the data */
702   for(i=0;i<vi->channels;i++){
703     float *pcm=vb->pcm[i];
704     if(nonzero[i])
705       for(j=0;j<n;j++)
706         pcm[j]*=window[j];
707     else
708       for(j=0;j<n;j++)
709         pcm[j]=0.f;
710
711     //_analysis_output("final",seq,pcm,n,0,0);
712   }
713             
714   /* now apply the decoded post-window time information */
715   /* NOT IMPLEMENTED */
716
717   fprintf(stderr,"seq %d\r",seq);
718     
719   /* all done! */
720   return(0);
721 }
722
723 /* export hooks */
724 vorbis_func_mapping mapping0_exportbundle={
725   &mapping0_pack,
726   &mapping0_unpack,
727   &mapping0_look,
728   &mapping0_copy_info,
729   &mapping0_free_info,
730   &mapping0_free_look,
731   &mapping0_forward,
732   &mapping0_inverse
733 };