Remove leftover unused buffer from the mdctexp branch
[kugel-rb.git] / apps / codecs / libtremor / synthesis.c
blob35d080180b74d582a80143b99baceb38f07f453a
1 /********************************************************************
2 * *
3 * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
4 * *
5 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
6 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
7 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
8 * *
9 * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2003 *
10 * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
11 * *
12 ********************************************************************
14 function: single-block PCM synthesis
15 last mod: $Id$
17 ********************************************************************/
19 #include <stdio.h>
20 #include "ogg.h"
21 #include "ivorbiscodec.h"
22 #include "codec_internal.h"
23 #include "registry.h"
24 #include "misc.h"
25 #include "os.h"
28 static ogg_int32_t *ipcm_vect[CHANNELS] IBSS_ATTR;
30 int vorbis_synthesis(vorbis_block *vb,ogg_packet *op,int decodep)
31 ICODE_ATTR_TREMOR_NOT_MDCT;
32 int vorbis_synthesis(vorbis_block *vb,ogg_packet *op,int decodep){
33 vorbis_dsp_state *vd=vb->vd;
34 private_state *b=(private_state *)vd->backend_state;
35 vorbis_info *vi=vd->vi;
36 codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
37 oggpack_buffer *opb=&vb->opb;
38 int type,mode,i;
40 /* first things first. Make sure decode is ready */
41 _vorbis_block_ripcord(vb);
42 oggpack_readinit(opb,op->packet);
44 /* Check the packet type */
45 if(oggpack_read(opb,1)!=0){
46 /* Oops. This is not an audio data packet */
47 return(OV_ENOTAUDIO);
50 /* read our mode and pre/post windowsize */
51 mode=oggpack_read(opb,b->modebits);
52 if(mode==-1)return(OV_EBADPACKET);
54 vb->mode=mode;
55 vb->W=ci->mode_param[mode]->blockflag;
56 if(vb->W){
57 vb->lW=oggpack_read(opb,1);
58 vb->nW=oggpack_read(opb,1);
59 if(vb->nW==-1) return(OV_EBADPACKET);
60 }else{
61 vb->lW=0;
62 vb->nW=0;
65 /* more setup */
66 vb->granulepos=op->granulepos;
67 vb->sequence=op->packetno-3; /* first block is third packet */
68 vb->eofflag=op->e_o_s;
70 if(decodep && vi->channels<=CHANNELS)
72 vb->pcm = ipcm_vect;
74 /* set pcm end point */
75 vb->pcmend=ci->blocksizes[vb->W];
76 /* use statically allocated buffer */
77 if(vd->reset_pcmb || vb->pcm[0]==NULL)
79 /* one-time initialisation at codec start
80 NOT for every block synthesis start
81 allows us to flip between buffers once initialised
82 by simply flipping pointers */
83 for(i=0; i<vi->channels; i++)
84 vb->pcm[i] = &vd->first_pcm[i*ci->blocksizes[1]];
87 vd->reset_pcmb = false;
89 /* unpack_header enforces range checking */
90 type=ci->map_type[ci->mode_param[mode]->mapping];
91 return(_mapping_P[type]->inverse(vb,b->mode[mode]));
92 }else{
93 /* no pcm */
94 vb->pcmend=0;
95 vb->pcm=NULL;
97 return(0);
101 long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){
102 codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
103 oggpack_buffer opb;
104 int mode;
106 oggpack_readinit(&opb,op->packet);
108 /* Check the packet type */
109 if(oggpack_read(&opb,1)!=0){
110 /* Oops. This is not an audio data packet */
111 return(OV_ENOTAUDIO);
115 int modebits=0;
116 int v=ci->modes;
117 while(v>1){
118 modebits++;
119 v>>=1;
122 /* read our mode and pre/post windowsize */
123 mode=oggpack_read(&opb,modebits);
125 if(mode==-1)return(OV_EBADPACKET);
126 return(ci->blocksizes[ci->mode_param[mode]->blockflag]);