Improved bitrev with approach suggested by Jens Arnold, gives 0.5%-1% speedup for...
[kugel-rb.git] / apps / codecs / libtremor / synthesis.c
bloba882a6d07a0ac291374305f43731ab0874da4608
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){
71 vb->pcm = ipcm_vect;
73 /* set pcm end point */
74 vb->pcmend=ci->blocksizes[vb->W];
75 /* use statically allocated buffer */
76 if(vd->reset_pcmb || vb->pcm[0]==NULL)
78 /* one-time initialisation at codec start
79 NOT for every block synthesis start
80 allows us to flip between buffers once initialised
81 by simply flipping pointers */
82 for(i=0; i<vi->channels; i++)
83 vb->pcm[i] = &vd->first_pcm[i*ci->blocksizes[1]];
85 vd->reset_pcmb = false;
87 /* unpack_header enforces range checking */
88 type=ci->map_type[ci->mode_param[mode]->mapping];
89 return(_mapping_P[type]->inverse(vb,b->mode[mode]));
90 }else{
91 /* no pcm */
92 vb->pcmend=0;
93 vb->pcm=NULL;
95 return(0);
99 long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){
100 codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
101 oggpack_buffer opb;
102 int mode;
104 oggpack_readinit(&opb,op->packet);
106 /* Check the packet type */
107 if(oggpack_read(&opb,1)!=0){
108 /* Oops. This is not an audio data packet */
109 return(OV_ENOTAUDIO);
113 int modebits=0;
114 int v=ci->modes;
115 while(v>1){
116 modebits++;
117 v>>=1;
120 /* read our mode and pre/post windowsize */
121 mode=oggpack_read(&opb,modebits);
123 if(mode==-1)return(OV_EBADPACKET);
124 return(ci->blocksizes[ci->mode_param[mode]->blockflag]);