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