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.26 2002/02/28 04:12:48 xiphmont 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 /* used to track pcm position without actually performing decode.
77 Useful for sequential 'fast forward' */
78 int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op){
79 vorbis_dsp_state *vd=vb->vd;
80 backend_lookup_state *b=vd->backend_state;
81 vorbis_info *vi=vd->vi;
82 codec_setup_info *ci=vi->codec_setup;
83 oggpack_buffer *opb=&vb->opb;
86 /* first things first. Make sure decode is ready */
87 _vorbis_block_ripcord(vb);
88 oggpack_readinit(opb,op->packet,op->bytes);
90 /* Check the packet type */
91 if(oggpack_read(opb,1)!=0){
92 /* Oops. This is not an audio data packet */
96 /* read our mode and pre/post windowsize */
97 mode=oggpack_read(opb,b->modebits);
98 if(mode==-1)return(OV_EBADPACKET);
101 vb->W=ci->mode_param[mode]->blockflag;
103 vb->lW=oggpack_read(opb,1);
104 vb->nW=oggpack_read(opb,1);
105 if(vb->nW==-1) return(OV_EBADPACKET);
112 vb->granulepos=op->granulepos;
113 vb->sequence=op->packetno-3; /* first block is third packet */
114 vb->eofflag=op->e_o_s;
123 long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){
124 codec_setup_info *ci=vi->codec_setup;
128 oggpack_readinit(&opb,op->packet,op->bytes);
130 /* Check the packet type */
131 if(oggpack_read(&opb,1)!=0){
132 /* Oops. This is not an audio data packet */
133 return(OV_ENOTAUDIO);
144 /* read our mode and pre/post windowsize */
145 mode=oggpack_read(&opb,modebits);
147 if(mode==-1)return(OV_EBADPACKET);
148 return(ci->blocksizes[ci->mode_param[mode]->blockflag]);