annotate tremor/block.c @ 19902:2c43912bb46a

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