examples/sfexamples/oggvorbiscodec/src/tremor/synthesis.c

00001 /********************************************************************
00002  *                                                                  *
00003  * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE.   *
00004  *                                                                  *
00005  * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
00006  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
00007  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
00008  *                                                                  *
00009  * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2003    *
00010  * BY THE Xiph.Org FOUNDATION http://www.xiph.org/                  *
00011  *                                                                  *
00012  ********************************************************************
00013 
00014  function: single-block PCM synthesis
00015  last mod: $Id: synthesis.c,v 1.4 2003/03/29 03:07:21 xiphmont Exp $
00016 
00017  ********************************************************************/
00018 
00019 #include <stdio.h>
00020 #include "ogg.h"
00021 #include "ivorbiscodec.h"
00022 #include "codec_internal.h"
00023 #include "registry.h"
00024 #include "misc.h"
00025 #include "os.h"
00026 int _vorbis_block_ripcord(vorbis_block *vb);
00027 void *_vorbis_block_alloc(vorbis_block *vb,long bytes);
00028 int vorbis_synthesis(vorbis_block *vb,ogg_packet *op,int decodep){
00029   vorbis_dsp_state     *vd=vb->vd;
00030   private_state        *b=(private_state *)vd->backend_state;
00031   vorbis_info          *vi=vd->vi;
00032   codec_setup_info     *ci=(codec_setup_info *)vi->codec_setup;
00033   oggpack_buffer       *opb=&vb->opb;
00034   int                   type,mode,i;
00035  
00036   /* first things first.  Make sure decode is ready */
00037   _vorbis_block_ripcord(vb);
00038   oggpack_readinit(opb,op->packet);
00039 
00040   /* Check the packet type */
00041   if(oggpack_read(opb,1)!=0){
00042     /* Oops.  This is not an audio data packet */
00043     return(OV_ENOTAUDIO);
00044   }
00045 
00046   /* read our mode and pre/post windowsize */
00047   mode=oggpack_read(opb,b->modebits);
00048   if(mode==-1)return(OV_EBADPACKET);
00049   
00050   vb->mode=mode;
00051   vb->W=ci->mode_param[mode]->blockflag;
00052   if(vb->W){
00053     vb->lW=oggpack_read(opb,1);
00054     vb->nW=oggpack_read(opb,1);
00055     if(vb->nW==-1)   return(OV_EBADPACKET);
00056   }else{
00057     vb->lW=0;
00058     vb->nW=0;
00059   }
00060   
00061   /* more setup */
00062   vb->granulepos=op->granulepos;
00063   vb->sequence=op->packetno-3; /* first block is third packet */
00064   vb->eofflag=op->e_o_s;
00065 
00066   if(decodep){
00067     /* alloc pcm passback storage */
00068     vb->pcmend=ci->blocksizes[vb->W];
00069     vb->pcm=(ogg_int32_t **)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
00070     for(i=0;i<vi->channels;i++)
00071       vb->pcm[i]=(ogg_int32_t *)_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i]));
00072     
00073     /* unpack_header enforces range checking */
00074     type=ci->map_type[ci->mode_param[mode]->mapping];
00075     
00076     return(_mapping_P[type]->inverse(vb,b->mode[mode]));
00077   }else{
00078     /* no pcm */
00079     vb->pcmend=0;
00080     vb->pcm=NULL;
00081     
00082     return(0);
00083   }
00084 }
00085 
00086 long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){
00087   codec_setup_info     *ci=(codec_setup_info *)vi->codec_setup;
00088   oggpack_buffer       opb;
00089   int                  mode;
00090  
00091   oggpack_readinit(&opb,op->packet);
00092 
00093   /* Check the packet type */
00094   if(oggpack_read(&opb,1)!=0){
00095     /* Oops.  This is not an audio data packet */
00096     return(OV_ENOTAUDIO);
00097   }
00098 
00099   {
00100     int modebits=0;
00101     int v=ci->modes;
00102     while(v>1){
00103       modebits++;
00104       v>>=1;
00105     }
00106 
00107     /* read our mode and pre/post windowsize */
00108     mode=oggpack_read(&opb,modebits);
00109   }
00110   if(mode==-1)return(OV_EBADPACKET);
00111   return(ci->blocksizes[ci->mode_param[mode]->blockflag]);
00112 }
00113 
00114 

Generated by  doxygen 1.6.2