1 /********************************************************************
3 * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
5 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
6 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
8 * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 *
9 * by the XIPHOPHORUS Company http://www.xiph.org/ *
11 ********************************************************************
13 function: single-block PCM synthesis
14 last mod: $Id: synthesis.c,v 1.22 2001/05/27 06:44:01 xiphmont Exp $
16 ********************************************************************/
20 #include "vorbis/codec.h"
25 int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){
26 vorbis_dsp_state *vd=vb->vd;
27 backend_lookup_state *b=vd->backend_state;
28 vorbis_info *vi=vd->vi;
29 codec_setup_info *ci=vi->codec_setup;
30 oggpack_buffer *opb=&vb->opb;
33 /* first things first. Make sure decode is ready */
34 _vorbis_block_ripcord(vb);
35 oggpack_readinit(opb,op->packet,op->bytes);
37 /* Check the packet type */
38 if(oggpack_read(opb,1)!=0){
39 /* Oops. This is not an audio data packet */
43 /* read our mode and pre/post windowsize */
44 mode=oggpack_read(opb,b->modebits);
45 if(mode==-1)return(OV_EBADPACKET);
48 vb->W=ci->mode_param[mode]->blockflag;
50 vb->lW=oggpack_read(opb,1);
51 vb->nW=oggpack_read(opb,1);
52 if(vb->nW==-1) return(OV_EBADPACKET);
59 vb->granulepos=op->granulepos;
60 vb->sequence=op->packetno-3; /* first block is third packet */
61 vb->eofflag=op->e_o_s;
63 /* alloc pcm passback storage */
64 vb->pcmend=ci->blocksizes[vb->W];
65 vb->pcm=_vorbis_block_alloc(vb,sizeof(float *)*vi->channels);
66 for(i=0;i<vi->channels;i++)
67 vb->pcm[i]=_vorbis_block_alloc(vb,vb->pcmend*sizeof(float));
69 /* unpack_header enforces range checking */
70 type=ci->map_type[ci->mode_param[mode]->mapping];
72 return(_mapping_P[type]->inverse(vb,b->mode[mode]));
75 long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){
76 codec_setup_info *ci=vi->codec_setup;
80 oggpack_readinit(&opb,op->packet,op->bytes);
82 /* Check the packet type */
83 if(oggpack_read(&opb,1)!=0){
84 /* Oops. This is not an audio data packet */
96 /* read our mode and pre/post windowsize */
97 mode=oggpack_read(&opb,modebits);
99 if(mode==-1)return(OV_EBADPACKET);
100 return(ci->blocksizes[ci->mode_param[mode]->blockflag]);