nuclear@0: /******************************************************************** nuclear@0: * * nuclear@0: * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * nuclear@0: * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * nuclear@0: * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * nuclear@0: * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * nuclear@0: * * nuclear@0: * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009 * nuclear@0: * by the Xiph.Org Foundation http://www.xiph.org/ * nuclear@0: * * nuclear@0: ******************************************************************** nuclear@0: nuclear@0: function: single-block PCM synthesis nuclear@0: last mod: $Id: synthesis.c 17474 2010-09-30 03:41:41Z gmaxwell $ nuclear@0: nuclear@0: ********************************************************************/ nuclear@0: nuclear@0: #include nuclear@0: #include nuclear@0: #include "vorbis/codec.h" nuclear@0: #include "codec_internal.h" nuclear@0: #include "registry.h" nuclear@0: #include "misc.h" nuclear@0: #include "os.h" nuclear@0: nuclear@0: int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){ nuclear@0: vorbis_dsp_state *vd= vb ? vb->vd : 0; nuclear@0: private_state *b= vd ? vd->backend_state : 0; nuclear@0: vorbis_info *vi= vd ? vd->vi : 0; nuclear@0: codec_setup_info *ci= vi ? vi->codec_setup : 0; nuclear@0: oggpack_buffer *opb=vb ? &vb->opb : 0; nuclear@0: int type,mode,i; nuclear@0: nuclear@0: if (!vd || !b || !vi || !ci || !opb) { nuclear@0: return OV_EBADPACKET; nuclear@0: } nuclear@0: nuclear@0: /* first things first. Make sure decode is ready */ nuclear@0: _vorbis_block_ripcord(vb); nuclear@0: oggpack_readinit(opb,op->packet,op->bytes); nuclear@0: nuclear@0: /* Check the packet type */ nuclear@0: if(oggpack_read(opb,1)!=0){ nuclear@0: /* Oops. This is not an audio data packet */ nuclear@0: return(OV_ENOTAUDIO); nuclear@0: } nuclear@0: nuclear@0: /* read our mode and pre/post windowsize */ nuclear@0: mode=oggpack_read(opb,b->modebits); nuclear@0: if(mode==-1){ nuclear@0: return(OV_EBADPACKET); nuclear@0: } nuclear@0: nuclear@0: vb->mode=mode; nuclear@0: if(!ci->mode_param[mode]){ nuclear@0: return(OV_EBADPACKET); nuclear@0: } nuclear@0: nuclear@0: vb->W=ci->mode_param[mode]->blockflag; nuclear@0: if(vb->W){ nuclear@0: nuclear@0: /* this doesn;t get mapped through mode selection as it's used nuclear@0: only for window selection */ nuclear@0: vb->lW=oggpack_read(opb,1); nuclear@0: vb->nW=oggpack_read(opb,1); nuclear@0: if(vb->nW==-1){ nuclear@0: return(OV_EBADPACKET); nuclear@0: } nuclear@0: }else{ nuclear@0: vb->lW=0; nuclear@0: vb->nW=0; nuclear@0: } nuclear@0: nuclear@0: /* more setup */ nuclear@0: vb->granulepos=op->granulepos; nuclear@0: vb->sequence=op->packetno; nuclear@0: vb->eofflag=op->e_o_s; nuclear@0: nuclear@0: /* alloc pcm passback storage */ nuclear@0: vb->pcmend=ci->blocksizes[vb->W]; nuclear@0: vb->pcm=_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels); nuclear@0: for(i=0;ichannels;i++) nuclear@0: vb->pcm[i]=_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i])); nuclear@0: nuclear@0: /* unpack_header enforces range checking */ nuclear@0: type=ci->map_type[ci->mode_param[mode]->mapping]; nuclear@0: nuclear@0: return(_mapping_P[type]->inverse(vb,ci->map_param[ci->mode_param[mode]-> nuclear@0: mapping])); nuclear@0: } nuclear@0: nuclear@0: /* used to track pcm position without actually performing decode. nuclear@0: Useful for sequential 'fast forward' */ nuclear@0: int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op){ nuclear@0: vorbis_dsp_state *vd=vb->vd; nuclear@0: private_state *b=vd->backend_state; nuclear@0: vorbis_info *vi=vd->vi; nuclear@0: codec_setup_info *ci=vi->codec_setup; nuclear@0: oggpack_buffer *opb=&vb->opb; nuclear@0: int mode; nuclear@0: nuclear@0: /* first things first. Make sure decode is ready */ nuclear@0: _vorbis_block_ripcord(vb); nuclear@0: oggpack_readinit(opb,op->packet,op->bytes); nuclear@0: nuclear@0: /* Check the packet type */ nuclear@0: if(oggpack_read(opb,1)!=0){ nuclear@0: /* Oops. This is not an audio data packet */ nuclear@0: return(OV_ENOTAUDIO); nuclear@0: } nuclear@0: nuclear@0: /* read our mode and pre/post windowsize */ nuclear@0: mode=oggpack_read(opb,b->modebits); nuclear@0: if(mode==-1)return(OV_EBADPACKET); nuclear@0: nuclear@0: vb->mode=mode; nuclear@0: if(!ci->mode_param[mode]){ nuclear@0: return(OV_EBADPACKET); nuclear@0: } nuclear@0: nuclear@0: vb->W=ci->mode_param[mode]->blockflag; nuclear@0: if(vb->W){ nuclear@0: vb->lW=oggpack_read(opb,1); nuclear@0: vb->nW=oggpack_read(opb,1); nuclear@0: if(vb->nW==-1) return(OV_EBADPACKET); nuclear@0: }else{ nuclear@0: vb->lW=0; nuclear@0: vb->nW=0; nuclear@0: } nuclear@0: nuclear@0: /* more setup */ nuclear@0: vb->granulepos=op->granulepos; nuclear@0: vb->sequence=op->packetno; nuclear@0: vb->eofflag=op->e_o_s; nuclear@0: nuclear@0: /* no pcm */ nuclear@0: vb->pcmend=0; nuclear@0: vb->pcm=NULL; nuclear@0: nuclear@0: return(0); nuclear@0: } nuclear@0: nuclear@0: long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){ nuclear@0: codec_setup_info *ci=vi->codec_setup; nuclear@0: oggpack_buffer opb; nuclear@0: int mode; nuclear@0: nuclear@0: oggpack_readinit(&opb,op->packet,op->bytes); nuclear@0: nuclear@0: /* Check the packet type */ nuclear@0: if(oggpack_read(&opb,1)!=0){ nuclear@0: /* Oops. This is not an audio data packet */ nuclear@0: return(OV_ENOTAUDIO); nuclear@0: } nuclear@0: nuclear@0: { nuclear@0: int modebits=0; nuclear@0: int v=ci->modes; nuclear@0: while(v>1){ nuclear@0: modebits++; nuclear@0: v>>=1; nuclear@0: } nuclear@0: nuclear@0: /* read our mode and pre/post windowsize */ nuclear@0: mode=oggpack_read(&opb,modebits); nuclear@0: } nuclear@0: if(mode==-1)return(OV_EBADPACKET); nuclear@0: return(ci->blocksizes[ci->mode_param[mode]->blockflag]); nuclear@0: } nuclear@0: nuclear@0: int vorbis_synthesis_halfrate(vorbis_info *vi,int flag){ nuclear@0: /* set / clear half-sample-rate mode */ nuclear@0: codec_setup_info *ci=vi->codec_setup; nuclear@0: nuclear@0: /* right now, our MDCT can't handle < 64 sample windows. */ nuclear@0: if(ci->blocksizes[0]<=64 && flag)return -1; nuclear@0: ci->halfrate_flag=(flag?1:0); nuclear@0: return 0; nuclear@0: } nuclear@0: nuclear@0: int vorbis_synthesis_halfrate_p(vorbis_info *vi){ nuclear@0: codec_setup_info *ci=vi->codec_setup; nuclear@0: return ci->halfrate_flag; nuclear@0: }