Fixes a problem where the sim would try to start the WPS on HAVE_RTC_ALARM sims ...
[Rockbox.git] / apps / codecs / Tremor / synthesis.c
blobcef240e796dffa0eba21c732b13c47b37b137c76
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 /* IRAM buffer keep the block pcm data; only for windows size upto 2048
29 for space restrictions.
30 libVorbis 1.1 Oggenc doesn't use larger windows anyway. */
31 /* max 2 channels on the ihp-1xx (stereo), 2048 samples (2*2048*4=16Kb) */
32 #define IRAM_PCM_END 2048
33 #define CHANNELS 2
35 static ogg_int32_t *ipcm_vect[CHANNELS] IBSS_ATTR;
36 static ogg_int32_t ipcm_buff[CHANNELS*IRAM_PCM_END] IBSS_ATTR LINE_ATTR;
38 int vorbis_synthesis(vorbis_block *vb,ogg_packet *op,int decodep)
39 ICODE_ATTR_TREMOR_NOT_MDCT;
40 int vorbis_synthesis(vorbis_block *vb,ogg_packet *op,int decodep){
41 vorbis_dsp_state *vd=vb->vd;
42 private_state *b=(private_state *)vd->backend_state;
43 vorbis_info *vi=vd->vi;
44 codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
45 oggpack_buffer *opb=&vb->opb;
46 int type,mode,i;
48 /* first things first. Make sure decode is ready */
49 _vorbis_block_ripcord(vb);
50 oggpack_readinit(opb,op->packet);
52 /* Check the packet type */
53 if(oggpack_read(opb,1)!=0){
54 /* Oops. This is not an audio data packet */
55 return(OV_ENOTAUDIO);
58 /* read our mode and pre/post windowsize */
59 mode=oggpack_read(opb,b->modebits);
60 if(mode==-1)return(OV_EBADPACKET);
62 vb->mode=mode;
63 vb->W=ci->mode_param[mode]->blockflag;
64 if(vb->W){
65 vb->lW=oggpack_read(opb,1);
66 vb->nW=oggpack_read(opb,1);
67 if(vb->nW==-1) return(OV_EBADPACKET);
68 }else{
69 vb->lW=0;
70 vb->nW=0;
73 /* more setup */
74 vb->granulepos=op->granulepos;
75 vb->sequence=op->packetno-3; /* first block is third packet */
76 vb->eofflag=op->e_o_s;
78 if(decodep && vi->channels<=CHANNELS){
79 /* alloc pcm passback storage */
80 vb->pcmend=ci->blocksizes[vb->W];
81 if (vb->pcmend<=IRAM_PCM_END) {
82 /* use statically allocated iram buffer */
83 vb->pcm = ipcm_vect;
84 for(i=0; i<CHANNELS; i++)
85 vb->pcm[i] = &ipcm_buff[i*IRAM_PCM_END];
86 } else {
87 /* dynamic allocation (slower) */
88 vb->pcm=(ogg_int32_t **)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
89 for(i=0;i<vi->channels;i++)
90 vb->pcm[i]=(ogg_int32_t *)_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i]));
93 /* unpack_header enforces range checking */
94 type=ci->map_type[ci->mode_param[mode]->mapping];
96 return(_mapping_P[type]->inverse(vb,b->mode[mode]));
97 }else{
98 /* no pcm */
99 vb->pcmend=0;
100 vb->pcm=NULL;
102 return(0);
106 long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){
107 codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
108 oggpack_buffer opb;
109 int mode;
111 oggpack_readinit(&opb,op->packet);
113 /* Check the packet type */
114 if(oggpack_read(&opb,1)!=0){
115 /* Oops. This is not an audio data packet */
116 return(OV_ENOTAUDIO);
120 int modebits=0;
121 int v=ci->modes;
122 while(v>1){
123 modebits++;
124 v>>=1;
127 /* read our mode and pre/post windowsize */
128 mode=oggpack_read(&opb,modebits);
130 if(mode==-1)return(OV_EBADPACKET);
131 return(ci->blocksizes[ci->mode_param[mode]->blockflag]);