annotate tremor/block.c @ 15609:0d66e391796b

better quotes
author wight
date Wed, 01 Jun 2005 21:55:28 +0000
parents 8631a3803289
children cd6b211be811
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
1 /********************************************************************
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
2 * *
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
3 * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
4 * *
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
5 * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
6 * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
7 * ALL REDISTRIBUTION RIGHTS RESERVED. *
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
8 * *
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
9 ********************************************************************
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
10
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
11 function: PCM data vector blocking, windowing and dis/reassembly
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
12
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
13 ********************************************************************/
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
14
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
15 #include <stdio.h>
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
16 #include <stdlib.h>
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
17 #include <string.h>
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
18 #include "ogg.h"
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
19 #include "ivorbiscodec.h"
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
20 #include "codec_internal.h"
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
21
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
22 #include "window.h"
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
23 #include "registry.h"
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
24 #include "misc.h"
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
25
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
26 static int ilog(unsigned int v){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
27 int ret=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
28 if(v)--v;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
29 while(v){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
30 ret++;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
31 v>>=1;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
32 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
33 return(ret);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
34 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
35
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
36 /* pcm accumulator examples (not exhaustive):
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
37
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
38 <-------------- lW ---------------->
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
39 <--------------- W ---------------->
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
40 : .....|..... _______________ |
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
41 : .''' | '''_--- | |\ |
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
42 :.....''' |_____--- '''......| | \_______|
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
43 :.................|__________________|_______|__|______|
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
44 |<------ Sl ------>| > Sr < |endW
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
45 |beginSl |endSl | |endSr
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
46 |beginW |endlW |beginSr
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
47
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
48
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
49 |< lW >|
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
50 <--------------- W ---------------->
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
51 | | .. ______________ |
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
52 | | ' `/ | ---_ |
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
53 |___.'___/`. | ---_____|
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
54 |_______|__|_______|_________________|
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
55 | >|Sl|< |<------ Sr ----->|endW
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
56 | | |endSl |beginSr |endSr
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
57 |beginW | |endlW
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
58 mult[0] |beginSl mult[n]
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
59
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
60 <-------------- lW ----------------->
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
61 |<--W-->|
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
62 : .............. ___ | |
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
63 : .''' |`/ \ | |
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
64 :.....''' |/`....\|...|
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
65 :.........................|___|___|___|
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
66 |Sl |Sr |endW
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
67 | | |endSr
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
68 | |beginSr
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
69 | |endSl
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
70 |beginSl
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
71 |beginW
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
72 */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
73
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
74 /* block abstraction setup *********************************************/
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
75
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
76 #ifndef WORD_ALIGN
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
77 #define WORD_ALIGN 8
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
78 #endif
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
79
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
80 int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
81 memset(vb,0,sizeof(*vb));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
82 vb->vd=v;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
83 vb->localalloc=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
84 vb->localstore=NULL;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
85
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
86 return(0);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
87 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
88
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
89 void *_vorbis_block_alloc(vorbis_block *vb,long bytes){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
90 bytes=(bytes+(WORD_ALIGN-1)) & ~(WORD_ALIGN-1);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
91 if(bytes+vb->localtop>vb->localalloc){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
92 /* can't just _ogg_realloc... there are outstanding pointers */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
93 if(vb->localstore){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
94 struct alloc_chain *link=(struct alloc_chain *)_ogg_malloc(sizeof(*link));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
95 vb->totaluse+=vb->localtop;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
96 link->next=vb->reap;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
97 link->ptr=vb->localstore;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
98 vb->reap=link;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
99 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
100 /* highly conservative */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
101 vb->localalloc=bytes;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
102 vb->localstore=_ogg_malloc(vb->localalloc);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
103 vb->localtop=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
104 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
105 {
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
106 void *ret=(void *)(((char *)vb->localstore)+vb->localtop);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
107 vb->localtop+=bytes;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
108 return ret;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
109 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
110 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
111
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
112 /* reap the chain, pull the ripcord */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
113 void _vorbis_block_ripcord(vorbis_block *vb){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
114 /* reap the chain */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
115 struct alloc_chain *reap=vb->reap;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
116 while(reap){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
117 struct alloc_chain *next=reap->next;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
118 _ogg_free(reap->ptr);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
119 memset(reap,0,sizeof(*reap));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
120 _ogg_free(reap);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
121 reap=next;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
122 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
123 /* consolidate storage */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
124 if(vb->totaluse){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
125 vb->localstore=_ogg_realloc(vb->localstore,vb->totaluse+vb->localalloc);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
126 vb->localalloc+=vb->totaluse;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
127 vb->totaluse=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
128 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
129
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
130 /* pull the ripcord */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
131 vb->localtop=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
132 vb->reap=NULL;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
133 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
134
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
135 int vorbis_block_clear(vorbis_block *vb){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
136 _vorbis_block_ripcord(vb);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
137 if(vb->localstore)_ogg_free(vb->localstore);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
138
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
139 memset(vb,0,sizeof(*vb));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
140 return(0);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
141 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
142
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
143 int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
144 int i;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
145 codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
146 backend_lookup_state *b=NULL;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
147
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
148 memset(v,0,sizeof(*v));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
149 b=(backend_lookup_state *)(v->backend_state=_ogg_calloc(1,sizeof(*b)));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
150
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
151 v->vi=vi;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
152 b->modebits=ilog(ci->modes);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
153
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
154 /* Vorbis I uses only window type 0 */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
155 b->window[0]=_vorbis_window(0,ci->blocksizes[0]/2);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
156 b->window[1]=_vorbis_window(0,ci->blocksizes[1]/2);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
157
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
158 /* finish the codebooks */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
159 if(!ci->fullbooks){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
160 ci->fullbooks=(codebook *)_ogg_calloc(ci->books,sizeof(*ci->fullbooks));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
161 for(i=0;i<ci->books;i++){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
162 vorbis_book_init_decode(ci->fullbooks+i,ci->book_param[i]);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
163 /* decode codebooks are now standalone after init */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
164 vorbis_staticbook_destroy(ci->book_param[i]);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
165 ci->book_param[i]=NULL;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
166 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
167 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
168
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
169 v->pcm_storage=ci->blocksizes[1];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
170 v->pcm=(ogg_int32_t **)_ogg_malloc(vi->channels*sizeof(*v->pcm));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
171 v->pcmret=(ogg_int32_t **)_ogg_malloc(vi->channels*sizeof(*v->pcmret));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
172 for(i=0;i<vi->channels;i++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
173 v->pcm[i]=(ogg_int32_t *)_ogg_calloc(v->pcm_storage,sizeof(*v->pcm[i]));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
174
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
175 /* all 1 (large block) or 0 (small block) */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
176 /* explicitly set for the sake of clarity */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
177 v->lW=0; /* previous window size */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
178 v->W=0; /* current window size */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
179
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
180 /* all vector indexes */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
181 v->centerW=ci->blocksizes[1]/2;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
182
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
183 v->pcm_current=v->centerW;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
184
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
185 /* initialize all the mapping/backend lookups */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
186 b->mode=(vorbis_look_mapping **)_ogg_calloc(ci->modes,sizeof(*b->mode));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
187 for(i=0;i<ci->modes;i++){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
188 int mapnum=ci->mode_param[i]->mapping;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
189 int maptype=ci->map_type[mapnum];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
190 b->mode[i]=_mapping_P[maptype]->look(v,ci->mode_param[i],
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
191 ci->map_param[mapnum]);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
192 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
193
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
194 v->pcm_returned=-1;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
195 v->granulepos=-1;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
196 v->sequence=-1;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
197
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
198 return(0);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
199 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
200
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
201 void vorbis_dsp_clear(vorbis_dsp_state *v){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
202 int i;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
203 if(v){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
204 vorbis_info *vi=v->vi;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
205 codec_setup_info *ci=(codec_setup_info *)(vi?vi->codec_setup:NULL);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
206 backend_lookup_state *b=(backend_lookup_state *)v->backend_state;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
207
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
208 if(v->pcm){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
209 for(i=0;i<vi->channels;i++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
210 if(v->pcm[i])_ogg_free(v->pcm[i]);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
211 _ogg_free(v->pcm);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
212 if(v->pcmret)_ogg_free(v->pcmret);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
213 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
214
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
215 /* free mode lookups; these are actually vorbis_look_mapping structs */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
216 if(ci){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
217 for(i=0;i<ci->modes;i++){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
218 int mapnum=ci->mode_param[i]->mapping;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
219 int maptype=ci->map_type[mapnum];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
220 if(b && b->mode)_mapping_P[maptype]->free_look(b->mode[i]);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
221 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
222 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
223
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
224 if(b){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
225 if(b->mode)_ogg_free(b->mode);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
226 _ogg_free(b);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
227 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
228
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
229 memset(v,0,sizeof(*v));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
230 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
231 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
232
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
233 /* Unlike in analysis, the window is only partially applied for each
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
234 block. The time domain envelope is not yet handled at the point of
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
235 calling (as it relies on the previous block). */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
236
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
237 int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
238 vorbis_info *vi=v->vi;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
239 codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
240 int i,j;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
241
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
242 if(v->pcm_current>v->pcm_returned && v->pcm_returned!=-1)return(OV_EINVAL);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
243
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
244 v->lW=v->W;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
245 v->W=vb->W;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
246 v->nW=-1;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
247
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
248 if(v->sequence+1 != vb->sequence)v->granulepos=-1; /* out of sequence;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
249 lose count */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
250
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
251 v->sequence=vb->sequence;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
252
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
253 {
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
254 int n=ci->blocksizes[v->W]/2;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
255 int n0=ci->blocksizes[0]/2;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
256 int n1=ci->blocksizes[1]/2;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
257
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
258 int thisCenter;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
259 int prevCenter;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
260
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
261 if(v->centerW){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
262 thisCenter=n1;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
263 prevCenter=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
264 }else{
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
265 thisCenter=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
266 prevCenter=n1;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
267 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
268
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
269 /* v->pcm is now used like a two-stage double buffer. We don't want
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
270 to have to constantly shift *or* adjust memory usage. Don't
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
271 accept a new block until the old is shifted out */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
272
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
273 /* overlap/add PCM */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
274
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
275 for(j=0;j<vi->channels;j++){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
276 /* the overlap/add section */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
277 if(v->lW){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
278 if(v->W){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
279 /* large/large */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
280 ogg_int32_t *pcm=v->pcm[j]+prevCenter;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
281 ogg_int32_t *p=vb->pcm[j];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
282 for(i=0;i<n1;i++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
283 pcm[i]+=p[i];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
284 }else{
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
285 /* large/small */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
286 ogg_int32_t *pcm=v->pcm[j]+prevCenter+n1/2-n0/2;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
287 ogg_int32_t *p=vb->pcm[j];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
288 for(i=0;i<n0;i++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
289 pcm[i]+=p[i];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
290 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
291 }else{
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
292 if(v->W){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
293 /* small/large */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
294 ogg_int32_t *pcm=v->pcm[j]+prevCenter;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
295 ogg_int32_t *p=vb->pcm[j]+n1/2-n0/2;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
296 for(i=0;i<n0;i++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
297 pcm[i]+=p[i];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
298 for(;i<n1/2+n0/2;i++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
299 pcm[i]=p[i];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
300 }else{
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
301 /* small/small */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
302 ogg_int32_t *pcm=v->pcm[j]+prevCenter;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
303 ogg_int32_t *p=vb->pcm[j];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
304 for(i=0;i<n0;i++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
305 pcm[i]+=p[i];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
306 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
307 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
308
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
309 /* the copy section */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
310 {
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
311 ogg_int32_t *pcm=v->pcm[j]+thisCenter;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
312 ogg_int32_t *p=vb->pcm[j]+n;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
313 for(i=0;i<n;i++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
314 pcm[i]=p[i];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
315 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
316 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
317
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
318 if(v->centerW)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
319 v->centerW=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
320 else
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
321 v->centerW=n1;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
322
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
323 /* deal with initial packet state; we do this using the explicit
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
324 pcm_returned==-1 flag otherwise we're sensitive to first block
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
325 being short or long */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
326
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
327 if(v->pcm_returned==-1){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
328 v->pcm_returned=thisCenter;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
329 v->pcm_current=thisCenter;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
330 }else{
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
331 v->pcm_returned=prevCenter;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
332 v->pcm_current=prevCenter+
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
333 ci->blocksizes[v->lW]/4+
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
334 ci->blocksizes[v->W]/4;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
335 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
336
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
337 /* track the frame number... This is for convenience, but also
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
338 making sure our last packet doesn't end with added padding. If
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
339 the last packet is partial, the number of samples we'll have to
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
340 return will be past the vb->granulepos.
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
341
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
342 This is not foolproof! It will be confused if we begin
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
343 decoding at the last page after a seek or hole. In that case,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
344 we don't have a starting point to judge where the last frame
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
345 is. For this reason, vorbisfile will always try to make sure
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
346 it reads the last two marked pages in proper sequence */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
347
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
348 if(v->granulepos==-1)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
349 if(vb->granulepos==-1){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
350 v->granulepos=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
351 }else{
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
352 v->granulepos=vb->granulepos;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
353 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
354 else{
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
355 v->granulepos+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
356 if(vb->granulepos!=-1 && v->granulepos!=vb->granulepos){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
357
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
358 if(v->granulepos>vb->granulepos){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
359 long extra=v->granulepos-vb->granulepos;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
360
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
361 if(vb->eofflag){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
362 /* partial last frame. Strip the extra samples off */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
363 v->pcm_current-=extra;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
364 }else if(vb->sequence == 1){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
365 /* ^^^ argh, this can be 1 from seeking! */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
366
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
367
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
368 /* partial first frame. Discard extra leading samples */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
369 v->pcm_returned+=extra;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
370 if(v->pcm_returned>v->pcm_current)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
371 v->pcm_returned=v->pcm_current;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
372
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
373 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
374
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
375 }/* else{ Shouldn't happen *unless* the bitstream is out of
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
376 spec. Either way, believe the bitstream } */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
377 v->granulepos=vb->granulepos;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
378 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
379 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
380
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
381 /* Update, cleanup */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
382
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
383 if(vb->eofflag)v->eofflag=1;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
384 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
385
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
386 return(0);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
387 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
388
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
389 /* pcm==NULL indicates we just want the pending samples, no more */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
390 int vorbis_synthesis_pcmout(vorbis_dsp_state *v,ogg_int32_t ***pcm){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
391 vorbis_info *vi=v->vi;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
392 if(v->pcm_returned>-1 && v->pcm_returned<v->pcm_current){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
393 if(pcm){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
394 int i;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
395 for(i=0;i<vi->channels;i++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
396 v->pcmret[i]=v->pcm[i]+v->pcm_returned;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
397 *pcm=v->pcmret;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
398 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
399 return(v->pcm_current-v->pcm_returned);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
400 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
401 return(0);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
402 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
403
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
404 int vorbis_synthesis_read(vorbis_dsp_state *v,int bytes){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
405 if(bytes && v->pcm_returned+bytes>v->pcm_current)return(OV_EINVAL);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
406 v->pcm_returned+=bytes;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
407 return(0);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
408 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
409