annotate tremor/block.c @ 28717:7bbe6626f0e0

Support fractional arguments for some override tags. Done by parsing all integers as doubles first and then converting them to the nearest integer. Patch by Grigori G (greg chown ath cx).
author eugeni
date Fri, 27 Feb 2009 23:06:47 +0000
parents 8dfda4d651ec
children e83eef58b30a
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"
24796
8dfda4d651ec _vorbis_block_alloc() is used w/o prototype, this will crash on ia64.
diego
parents: 19251
diff changeset
28 #include "block.h"
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
29
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
30 static int ilog(unsigned int v){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
31 int ret=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
32 if(v)--v;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
33 while(v){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
34 ret++;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
35 v>>=1;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
36 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
37 return(ret);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
38 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
39
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
40 /* pcm accumulator examples (not exhaustive):
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
41
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
42 <-------------- lW ---------------->
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
43 <--------------- W ---------------->
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 :.................|__________________|_______|__|______|
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
48 |<------ Sl ------>| > Sr < |endW
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
49 |beginSl |endSl | |endSr
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
50 |beginW |endlW |beginSr
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 |< lW >|
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
54 <--------------- W ---------------->
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 |_______|__|_______|_________________|
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
59 | >|Sl|< |<------ Sr ----->|endW
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
60 | | |endSl |beginSr |endSr
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
61 |beginW | |endlW
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
62 mult[0] |beginSl mult[n]
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
63
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
64 <-------------- lW ----------------->
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
65 |<--W-->|
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 :.........................|___|___|___|
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
70 |Sl |Sr |endW
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
71 | | |endSr
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
72 | |beginSr
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
73 | |endSl
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
74 |beginSl
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
75 |beginW
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
76 */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
77
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
78 /* block abstraction setup *********************************************/
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
79
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
80 #ifndef WORD_ALIGN
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
81 #define WORD_ALIGN 8
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
82 #endif
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
83
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
84 int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
85 memset(vb,0,sizeof(*vb));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
86 vb->vd=v;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
87 vb->localalloc=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
88 vb->localstore=NULL;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
89
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
90 return(0);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
91 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
92
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
93 void *_vorbis_block_alloc(vorbis_block *vb,long bytes){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
94 bytes=(bytes+(WORD_ALIGN-1)) & ~(WORD_ALIGN-1);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
95 if(bytes+vb->localtop>vb->localalloc){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
96 /* can't just _ogg_realloc... there are outstanding pointers */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
97 if(vb->localstore){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
98 struct alloc_chain *link=(struct alloc_chain *)_ogg_malloc(sizeof(*link));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
99 vb->totaluse+=vb->localtop;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
100 link->next=vb->reap;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
101 link->ptr=vb->localstore;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
102 vb->reap=link;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
103 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
104 /* highly conservative */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
105 vb->localalloc=bytes;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
106 vb->localstore=_ogg_malloc(vb->localalloc);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
107 vb->localtop=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
108 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
109 {
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
110 void *ret=(void *)(((char *)vb->localstore)+vb->localtop);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
111 vb->localtop+=bytes;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
112 return ret;
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
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
116 /* reap the chain, pull the ripcord */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
117 void _vorbis_block_ripcord(vorbis_block *vb){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
118 /* reap the chain */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
119 struct alloc_chain *reap=vb->reap;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
120 while(reap){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
121 struct alloc_chain *next=reap->next;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
122 _ogg_free(reap->ptr);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
123 memset(reap,0,sizeof(*reap));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
124 _ogg_free(reap);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
125 reap=next;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
126 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
127 /* consolidate storage */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
128 if(vb->totaluse){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
129 vb->localstore=_ogg_realloc(vb->localstore,vb->totaluse+vb->localalloc);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
130 vb->localalloc+=vb->totaluse;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
131 vb->totaluse=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
132 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
133
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
134 /* pull the ripcord */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
135 vb->localtop=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
136 vb->reap=NULL;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
137 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
138
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
139 int vorbis_block_clear(vorbis_block *vb){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
140 _vorbis_block_ripcord(vb);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
141 if(vb->localstore)_ogg_free(vb->localstore);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
142
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
143 memset(vb,0,sizeof(*vb));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
144 return(0);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
145 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
146
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
147 int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
148 int i;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
149 codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
150 backend_lookup_state *b=NULL;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
151
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
152 memset(v,0,sizeof(*v));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
153 b=(backend_lookup_state *)(v->backend_state=_ogg_calloc(1,sizeof(*b)));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
154
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
155 v->vi=vi;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
156 b->modebits=ilog(ci->modes);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
157
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
158 /* Vorbis I uses only window type 0 */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
159 b->window[0]=_vorbis_window(0,ci->blocksizes[0]/2);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
160 b->window[1]=_vorbis_window(0,ci->blocksizes[1]/2);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
161
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
162 /* finish the codebooks */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
163 if(!ci->fullbooks){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
164 ci->fullbooks=(codebook *)_ogg_calloc(ci->books,sizeof(*ci->fullbooks));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
165 for(i=0;i<ci->books;i++){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
166 vorbis_book_init_decode(ci->fullbooks+i,ci->book_param[i]);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
167 /* decode codebooks are now standalone after init */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
168 vorbis_staticbook_destroy(ci->book_param[i]);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
169 ci->book_param[i]=NULL;
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
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
173 v->pcm_storage=ci->blocksizes[1];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
174 v->pcm=(ogg_int32_t **)_ogg_malloc(vi->channels*sizeof(*v->pcm));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
175 v->pcmret=(ogg_int32_t **)_ogg_malloc(vi->channels*sizeof(*v->pcmret));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
176 for(i=0;i<vi->channels;i++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
177 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
178
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
179 /* all 1 (large block) or 0 (small block) */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
180 /* explicitly set for the sake of clarity */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
181 v->lW=0; /* previous window size */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
182 v->W=0; /* current window size */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
183
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
184 /* all vector indexes */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
185 v->centerW=ci->blocksizes[1]/2;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
186
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
187 v->pcm_current=v->centerW;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
188
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
189 /* initialize all the mapping/backend lookups */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
190 b->mode=(vorbis_look_mapping **)_ogg_calloc(ci->modes,sizeof(*b->mode));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
191 for(i=0;i<ci->modes;i++){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
192 int mapnum=ci->mode_param[i]->mapping;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
193 int maptype=ci->map_type[mapnum];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
194 b->mode[i]=_mapping_P[maptype]->look(v,ci->mode_param[i],
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
195 ci->map_param[mapnum]);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
196 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
197
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
198 v->pcm_returned=-1;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
199 v->granulepos=-1;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
200 v->sequence=-1;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
201
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
202 return(0);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
203 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
204
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
205 void vorbis_dsp_clear(vorbis_dsp_state *v){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
206 int i;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
207 if(v){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
208 vorbis_info *vi=v->vi;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
209 codec_setup_info *ci=(codec_setup_info *)(vi?vi->codec_setup:NULL);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
210 backend_lookup_state *b=(backend_lookup_state *)v->backend_state;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
211
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
212 if(v->pcm){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
213 for(i=0;i<vi->channels;i++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
214 if(v->pcm[i])_ogg_free(v->pcm[i]);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
215 _ogg_free(v->pcm);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
216 if(v->pcmret)_ogg_free(v->pcmret);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
217 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
218
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
219 /* free mode lookups; these are actually vorbis_look_mapping structs */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
220 if(ci){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
221 for(i=0;i<ci->modes;i++){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
222 int mapnum=ci->mode_param[i]->mapping;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
223 int maptype=ci->map_type[mapnum];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
224 if(b && b->mode)_mapping_P[maptype]->free_look(b->mode[i]);
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
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
228 if(b){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
229 if(b->mode)_ogg_free(b->mode);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
230 _ogg_free(b);
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 memset(v,0,sizeof(*v));
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
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
237 /* Unlike in analysis, the window is only partially applied for each
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
238 block. The time domain envelope is not yet handled at the point of
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
239 calling (as it relies on the previous block). */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
240
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
241 int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
242 vorbis_info *vi=v->vi;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
243 codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
244 int i,j;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
245
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
246 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
247
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
248 v->lW=v->W;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
249 v->W=vb->W;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
250 v->nW=-1;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
251
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
252 if(v->sequence+1 != vb->sequence)v->granulepos=-1; /* out of sequence;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
253 lose count */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
254
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
255 v->sequence=vb->sequence;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
256
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 n=ci->blocksizes[v->W]/2;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
259 int n0=ci->blocksizes[0]/2;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
260 int n1=ci->blocksizes[1]/2;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
261
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
262 int thisCenter;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
263 int prevCenter;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
264
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
265 if(v->centerW){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
266 thisCenter=n1;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
267 prevCenter=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
268 }else{
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
269 thisCenter=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
270 prevCenter=n1;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
271 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
272
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
273 /* 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
274 to have to constantly shift *or* adjust memory usage. Don't
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
275 accept a new block until the old is shifted out */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
276
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
277 /* overlap/add PCM */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
278
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
279 for(j=0;j<vi->channels;j++){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
280 /* the overlap/add section */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
281 if(v->lW){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
282 if(v->W){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
283 /* large/large */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
284 ogg_int32_t *pcm=v->pcm[j]+prevCenter;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
285 ogg_int32_t *p=vb->pcm[j];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
286 for(i=0;i<n1;i++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
287 pcm[i]+=p[i];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
288 }else{
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
289 /* large/small */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
290 ogg_int32_t *pcm=v->pcm[j]+prevCenter+n1/2-n0/2;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
291 ogg_int32_t *p=vb->pcm[j];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
292 for(i=0;i<n0;i++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
293 pcm[i]+=p[i];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
294 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
295 }else{
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
296 if(v->W){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
297 /* small/large */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
298 ogg_int32_t *pcm=v->pcm[j]+prevCenter;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
299 ogg_int32_t *p=vb->pcm[j]+n1/2-n0/2;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
300 for(i=0;i<n0;i++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
301 pcm[i]+=p[i];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
302 for(;i<n1/2+n0/2;i++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
303 pcm[i]=p[i];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
304 }else{
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
305 /* small/small */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
306 ogg_int32_t *pcm=v->pcm[j]+prevCenter;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
307 ogg_int32_t *p=vb->pcm[j];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
308 for(i=0;i<n0;i++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
309 pcm[i]+=p[i];
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
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
313 /* the copy section */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
314 {
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
315 ogg_int32_t *pcm=v->pcm[j]+thisCenter;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
316 ogg_int32_t *p=vb->pcm[j]+n;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
317 for(i=0;i<n;i++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
318 pcm[i]=p[i];
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
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
322 if(v->centerW)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
323 v->centerW=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
324 else
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
325 v->centerW=n1;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
326
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
327 /* deal with initial packet state; we do this using the explicit
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
328 pcm_returned==-1 flag otherwise we're sensitive to first block
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
329 being short or long */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
330
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
331 if(v->pcm_returned==-1){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
332 v->pcm_returned=thisCenter;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
333 v->pcm_current=thisCenter;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
334 }else{
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
335 v->pcm_returned=prevCenter;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
336 v->pcm_current=prevCenter+
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
337 ci->blocksizes[v->lW]/4+
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
338 ci->blocksizes[v->W]/4;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
339 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
340
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
341 /* track the frame number... This is for convenience, but also
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
342 making sure our last packet doesn't end with added padding. If
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
343 the last packet is partial, the number of samples we'll have to
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
344 return will be past the vb->granulepos.
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
345
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
346 This is not foolproof! It will be confused if we begin
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
347 decoding at the last page after a seek or hole. In that case,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
348 we don't have a starting point to judge where the last frame
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
349 is. For this reason, vorbisfile will always try to make sure
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
350 it reads the last two marked pages in proper sequence */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
351
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
352 if(v->granulepos==-1)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
353 if(vb->granulepos==-1){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
354 v->granulepos=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
355 }else{
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
356 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 else{
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
359 v->granulepos+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
360 if(vb->granulepos!=-1 && v->granulepos!=vb->granulepos){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
361
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
362 if(v->granulepos>vb->granulepos){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
363 long extra=v->granulepos-vb->granulepos;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
364
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
365 if(vb->eofflag){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
366 /* partial last frame. Strip the extra samples off */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
367 v->pcm_current-=extra;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
368 }else if(vb->sequence == 1){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
369 /* ^^^ argh, this can be 1 from seeking! */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
370
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
371
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
372 /* partial first frame. Discard extra leading samples */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
373 v->pcm_returned+=extra;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
374 if(v->pcm_returned>v->pcm_current)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
375 v->pcm_returned=v->pcm_current;
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
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
379 }/* else{ Shouldn't happen *unless* the bitstream is out of
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
380 spec. Either way, believe the bitstream } */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
381 v->granulepos=vb->granulepos;
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
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
385 /* Update, cleanup */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
386
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
387 if(vb->eofflag)v->eofflag=1;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
388 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
389
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
390 return(0);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
391 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
392
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
393 /* pcm==NULL indicates we just want the pending samples, no more */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
394 int vorbis_synthesis_pcmout(vorbis_dsp_state *v,ogg_int32_t ***pcm){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
395 vorbis_info *vi=v->vi;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
396 if(v->pcm_returned>-1 && v->pcm_returned<v->pcm_current){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
397 if(pcm){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
398 int i;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
399 for(i=0;i<vi->channels;i++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
400 v->pcmret[i]=v->pcm[i]+v->pcm_returned;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
401 *pcm=v->pcmret;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
402 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
403 return(v->pcm_current-v->pcm_returned);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
404 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
405 return(0);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
406 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
407
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
408 int vorbis_synthesis_read(vorbis_dsp_state *v,int bytes){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
409 if(bytes && v->pcm_returned+bytes>v->pcm_current)return(OV_EINVAL);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
410 v->pcm_returned+=bytes;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
411 return(0);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
412 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
413