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