1 /********************************************************************
3 * THIS FILE IS PART OF THE Ogg Vorbis SOFTWARE CODEC SOURCE CODE. *
4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
5 * THE GNU PUBLIC LICENSE 2, WHICH IS INCLUDED WITH THIS SOURCE. *
6 * PLEASE READ THESE TERMS DISTRIBUTING. *
8 * THE OggSQUISH 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.16 2000/06/15 09:18:34 xiphmont Exp $
17 ********************************************************************/
20 #include "vorbis/codec.h"
25 int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){
26 vorbis_dsp_state *vd=vb->vd;
27 vorbis_info *vi=vd->vi;
28 oggpack_buffer *opb=&vb->opb;
31 /* first things first. Make sure decode is ready */
32 _vorbis_block_ripcord(vb);
33 _oggpack_readinit(opb,op->packet,op->bytes);
35 /* Check the packet type */
36 if(_oggpack_read(opb,1)!=0){
37 /* Oops. This is not an audio data packet */
41 /* read our mode and pre/post windowsize */
42 mode=_oggpack_read(opb,vd->modebits);
43 if(mode==-1)return(-1);
46 vb->W=vi->mode_param[mode]->blockflag;
48 vb->lW=_oggpack_read(opb,1);
49 vb->nW=_oggpack_read(opb,1);
50 if(vb->nW==-1) return(-1);
57 vb->frameno=op->frameno;
58 vb->sequence=op->packetno-3; /* first block is third packet */
59 vb->eofflag=op->e_o_s;
61 /* alloc pcm passback storage */
62 vb->pcmend=vi->blocksizes[vb->W];
63 vb->pcm=_vorbis_block_alloc(vb,sizeof(double *)*vi->channels);
64 for(i=0;i<vi->channels;i++)
65 vb->pcm[i]=_vorbis_block_alloc(vb,vb->pcmend*sizeof(double));
67 /* unpack_header enforces range checking */
68 type=vi->map_type[vi->mode_param[mode]->mapping];
70 return(_mapping_P[type]->inverse(vb,vd->mode[mode]));