misc/libtremor/tremor/synthesis.c
branchhedgeroid
changeset 6045 9a7cc0f29430
parent 6043 9bd2d6b1ba52
equal deleted inserted replaced
6043:9bd2d6b1ba52 6045:9a7cc0f29430
       
     1 /********************************************************************
       
     2  *                                                                  *
       
     3  * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE.   *
       
     4  *                                                                  *
       
     5  * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
       
     6  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
       
     7  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
       
     8  *                                                                  *
       
     9  * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2003    *
       
    10  * BY THE Xiph.Org FOUNDATION http://www.xiph.org/                  *
       
    11  *                                                                  *
       
    12  ********************************************************************
       
    13 
       
    14  function: single-block PCM synthesis
       
    15  last mod: $Id: synthesis.c,v 1.4 2003/03/29 03:07:21 xiphmont Exp $
       
    16 
       
    17  ********************************************************************/
       
    18 
       
    19 #include <stdio.h>
       
    20 #include "ogg.h"
       
    21 #include "ivorbiscodec.h"
       
    22 #include "codec_internal.h"
       
    23 #include "registry.h"
       
    24 #include "misc.h"
       
    25 #include "block.h"
       
    26 
       
    27 int vorbis_synthesis(vorbis_block *vb,ogg_packet *op,int decodep){
       
    28   vorbis_dsp_state     *vd=vb->vd;
       
    29   private_state        *b=(private_state *)vd->backend_state;
       
    30   vorbis_info          *vi=vd->vi;
       
    31   codec_setup_info     *ci=(codec_setup_info *)vi->codec_setup;
       
    32   oggpack_buffer       *opb=&vb->opb;
       
    33   int                   type,mode,i;
       
    34  
       
    35   /* first things first.  Make sure decode is ready */
       
    36   _vorbis_block_ripcord(vb);
       
    37   oggpack_readinit(opb,op->packet);
       
    38 
       
    39   /* Check the packet type */
       
    40   if(oggpack_read(opb,1)!=0){
       
    41     /* Oops.  This is not an audio data packet */
       
    42     return(OV_ENOTAUDIO);
       
    43   }
       
    44 
       
    45   /* read our mode and pre/post windowsize */
       
    46   mode=oggpack_read(opb,b->modebits);
       
    47   if(mode==-1)return(OV_EBADPACKET);
       
    48   
       
    49   vb->mode=mode;
       
    50   vb->W=ci->mode_param[mode]->blockflag;
       
    51   if(vb->W){
       
    52     vb->lW=oggpack_read(opb,1);
       
    53     vb->nW=oggpack_read(opb,1);
       
    54     if(vb->nW==-1)   return(OV_EBADPACKET);
       
    55   }else{
       
    56     vb->lW=0;
       
    57     vb->nW=0;
       
    58   }
       
    59   
       
    60   /* more setup */
       
    61   vb->granulepos=op->granulepos;
       
    62   vb->sequence=op->packetno-3; /* first block is third packet */
       
    63   vb->eofflag=op->e_o_s;
       
    64 
       
    65   if(decodep){
       
    66     /* alloc pcm passback storage */
       
    67     vb->pcmend=ci->blocksizes[vb->W];
       
    68     vb->pcm=(ogg_int32_t **)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
       
    69     for(i=0;i<vi->channels;i++)
       
    70       vb->pcm[i]=(ogg_int32_t *)_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i]));
       
    71     
       
    72     /* unpack_header enforces range checking */
       
    73     type=ci->map_type[ci->mode_param[mode]->mapping];
       
    74     
       
    75     return(_mapping_P[type]->inverse(vb,b->mode[mode]));
       
    76   }else{
       
    77     /* no pcm */
       
    78     vb->pcmend=0;
       
    79     vb->pcm=NULL;
       
    80     
       
    81     return(0);
       
    82   }
       
    83 }
       
    84 
       
    85 long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){
       
    86   codec_setup_info     *ci=(codec_setup_info *)vi->codec_setup;
       
    87   oggpack_buffer       opb;
       
    88   int                  mode;
       
    89  
       
    90   oggpack_readinit(&opb,op->packet);
       
    91 
       
    92   /* Check the packet type */
       
    93   if(oggpack_read(&opb,1)!=0){
       
    94     /* Oops.  This is not an audio data packet */
       
    95     return(OV_ENOTAUDIO);
       
    96   }
       
    97 
       
    98   {
       
    99     int modebits=0;
       
   100     int v=ci->modes;
       
   101     while(v>1){
       
   102       modebits++;
       
   103       v>>=1;
       
   104     }
       
   105 
       
   106     /* read our mode and pre/post windowsize */
       
   107     mode=oggpack_read(&opb,modebits);
       
   108   }
       
   109   if(mode==-1)return(OV_EBADPACKET);
       
   110   return(ci->blocksizes[ci->mode_param[mode]->blockflag]);
       
   111 }
       
   112 
       
   113