1 /********************************************************************
3 * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
5 * THE GNU LESSER/LIBRARY PUBLIC LICENSE, WHICH IS INCLUDED WITH *
6 * THIS SOURCE. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
8 * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2000 *
9 * by Monty <monty@xiph.org> and the XIPHOPHORUS Company *
10 * http://www.xiph.org/ *
12 ********************************************************************
14 function: single-block PCM synthesis
15 last mod: $Id: synthesis.c,v 1.19 2000/11/06 00:07:02 xiphmont Exp $
17 ********************************************************************/
21 #include "vorbis/codec.h"
26 int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){
27 vorbis_dsp_state *vd=vb->vd;
28 backend_lookup_state *b=vd->backend_state;
29 vorbis_info *vi=vd->vi;
30 codec_setup_info *ci=vi->codec_setup;
31 oggpack_buffer *opb=&vb->opb;
34 /* first things first. Make sure decode is ready */
35 _vorbis_block_ripcord(vb);
36 oggpack_readinit(opb,op->packet,op->bytes);
38 /* Check the packet type */
39 if(oggpack_read(opb,1)!=0){
40 /* Oops. This is not an audio data packet */
44 /* read our mode and pre/post windowsize */
45 mode=oggpack_read(opb,b->modebits);
46 if(mode==-1)return(OV_EBADPACKET);
49 vb->W=ci->mode_param[mode]->blockflag;
51 vb->lW=oggpack_read(opb,1);
52 vb->nW=oggpack_read(opb,1);
53 if(vb->nW==-1) return(OV_EBADPACKET);
60 vb->granulepos=op->granulepos;
61 vb->sequence=op->packetno-3; /* first block is third packet */
62 vb->eofflag=op->e_o_s;
64 /* alloc pcm passback storage */
65 vb->pcmend=ci->blocksizes[vb->W];
66 vb->pcm=_vorbis_block_alloc(vb,sizeof(float *)*vi->channels);
67 for(i=0;i<vi->channels;i++)
68 vb->pcm[i]=_vorbis_block_alloc(vb,vb->pcmend*sizeof(float));
70 /* unpack_header enforces range checking */
71 type=ci->map_type[ci->mode_param[mode]->mapping];
73 return(_mapping_P[type]->inverse(vb,b->mode[mode]));