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.17 2000/07/07 00:53:10 xiphmont Exp $
17 ********************************************************************/
20 #include "vorbis/codec.h"
26 int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){
27 vorbis_dsp_state *vd=vb->vd;
28 vorbis_info *vi=vd->vi;
29 oggpack_buffer *opb=&vb->opb;
32 /* first things first. Make sure decode is ready */
33 _vorbis_block_ripcord(vb);
34 _oggpack_readinit(opb,op->packet,op->bytes);
36 /* Check the packet type */
37 if(_oggpack_read(opb,1)!=0){
38 /* Oops. This is not an audio data packet */
42 /* read our mode and pre/post windowsize */
43 mode=_oggpack_read(opb,vd->modebits);
44 if(mode==-1)return(-1);
47 vb->W=vi->mode_param[mode]->blockflag;
49 vb->lW=_oggpack_read(opb,1);
50 vb->nW=_oggpack_read(opb,1);
51 if(vb->nW==-1) return(-1);
58 vb->frameno=op->frameno;
59 vb->sequence=op->packetno-3; /* first block is third packet */
60 vb->eofflag=op->e_o_s;
62 /* alloc pcm passback storage */
63 vb->pcmend=vi->blocksizes[vb->W];
64 vb->pcm=_vorbis_block_alloc(vb,sizeof(double *)*vi->channels);
65 for(i=0;i<vi->channels;i++)
66 vb->pcm[i]=_vorbis_block_alloc(vb,vb->pcmend*sizeof(double));
68 /* unpack_header enforces range checking */
69 type=vi->map_type[vi->mode_param[mode]->mapping];
71 return(_mapping_P[type]->inverse(vb,vd->mode[mode]));