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.24 2001/10/02 00:14:32 segher Exp $
16 ********************************************************************/
20 #include "vorbis/codec.h"
21 #include "codec_internal.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(*vb->pcm)*vi->channels);
67 for(i=0;i<vi->channels;i++)
68 vb->pcm[i]=_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i]));
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]));
76 long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){
77 codec_setup_info *ci=vi->codec_setup;
81 oggpack_readinit(&opb,op->packet,op->bytes);
83 /* Check the packet type */
84 if(oggpack_read(&opb,1)!=0){
85 /* Oops. This is not an audio data packet */
97 /* read our mode and pre/post windowsize */
98 mode=oggpack_read(&opb,modebits);
100 if(mode==-1)return(OV_EBADPACKET);
101 return(ci->blocksizes[ci->mode_param[mode]->blockflag]);