summaryrefslogtreecommitdiff
path: root/block.c
diff options
context:
space:
mode:
authorMonty <xiphmont@xiph.org>2003-03-29 03:07:21 +0000
committerMonty <xiphmont@xiph.org>2003-03-29 03:07:21 +0000
commit3c764af8013b5b153d3e97311d56a8741536f4cf (patch)
treeb8201ccdd984c9b5b682641996a19cca15b6593c /block.c
parenta80cb134d84683d6c4961e2c33fddf3a24b378fa (diff)
downloadtremor-3c764af8013b5b153d3e97311d56a8741536f4cf.tar.gz
Roll all recent optimizations and fixes to mainline vorbisfile into Tremor
First mainline deployment of libogg 2 (embedded into Tremor) git-svn-id: https://svn.xiph.org/trunk/Tremor@4565 0101bb08-14d6-0310-b084-bc0e0c8e3800
Diffstat (limited to 'block.c')
-rw-r--r--block.c149
1 files changed, 83 insertions, 66 deletions
diff --git a/block.c b/block.c
index e35ff6b..8949253 100644
--- a/block.c
+++ b/block.c
@@ -143,7 +143,7 @@ int vorbis_block_clear(vorbis_block *vb){
return(0);
}
-int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){
+static int _vds_init(vorbis_dsp_state *v,vorbis_info *vi){
int i;
codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
private_state *b=NULL;
@@ -180,11 +180,6 @@ int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){
v->lW=0; /* previous window size */
v->W=0; /* current window size */
- /* all vector indexes */
- v->centerW=ci->blocksizes[1]/2;
-
- v->pcm_current=v->centerW;
-
/* initialize all the mapping/backend lookups */
b->mode=(vorbis_look_mapping **)_ogg_calloc(ci->modes,sizeof(*b->mode));
for(i=0;i<ci->modes;i++){
@@ -193,7 +188,21 @@ int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){
b->mode[i]=_mapping_P[maptype]->look(v,ci->mode_param[i],
ci->map_param[mapnum]);
}
+ return(0);
+}
+
+int vorbis_synthesis_restart(vorbis_dsp_state *v){
+ vorbis_info *vi=v->vi;
+ codec_setup_info *ci;
+ if(!v->backend_state)return -1;
+ if(!vi)return -1;
+ ci=vi->codec_setup;
+ if(!ci)return -1;
+
+ v->centerW=ci->blocksizes[1]/2;
+ v->pcm_current=v->centerW;
+
v->pcm_returned=-1;
v->granulepos=-1;
v->sequence=-1;
@@ -202,6 +211,13 @@ int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){
return(0);
}
+int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){
+ _vds_init(v,vi);
+ vorbis_synthesis_restart(v);
+
+ return(0);
+}
+
void vorbis_dsp_clear(vorbis_dsp_state *v){
int i;
if(v){
@@ -258,7 +274,8 @@ int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
v->sequence=vb->sequence;
- {
+ if(vb->pcm){ /* no pcm to process if vorbis_synthesis_trackonly
+ was called on block */
int n=ci->blocksizes[v->W]/2;
int n0=ci->blocksizes[0]/2;
int n1=ci->blocksizes[1]/2;
@@ -341,75 +358,75 @@ int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
ci->blocksizes[v->lW]/4+
ci->blocksizes[v->W]/4;
}
+
+ }
- /* track the frame number... This is for convenience, but also
- making sure our last packet doesn't end with added padding. If
- the last packet is partial, the number of samples we'll have to
- return will be past the vb->granulepos.
-
- This is not foolproof! It will be confused if we begin
- decoding at the last page after a seek or hole. In that case,
- we don't have a starting point to judge where the last frame
- is. For this reason, vorbisfile will always try to make sure
- it reads the last two marked pages in proper sequence */
-
- if(b->sample_count==-1){
- b->sample_count=0;
- }else{
- b->sample_count+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
- }
+ /* track the frame number... This is for convenience, but also
+ making sure our last packet doesn't end with added padding. If
+ the last packet is partial, the number of samples we'll have to
+ return will be past the vb->granulepos.
+
+ This is not foolproof! It will be confused if we begin
+ decoding at the last page after a seek or hole. In that case,
+ we don't have a starting point to judge where the last frame
+ is. For this reason, vorbisfile will always try to make sure
+ it reads the last two marked pages in proper sequence */
+
+ if(b->sample_count==-1){
+ b->sample_count=0;
+ }else{
+ b->sample_count+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
+ }
- if(v->granulepos==-1){
- if(vb->granulepos!=-1){ /* only set if we have a position to set to */
-
- v->granulepos=vb->granulepos;
-
- /* is this a short page? */
- if(b->sample_count>v->granulepos){
- /* corner case; if this is both the first and last audio page,
- then spec says the end is cut, not beginning */
- if(vb->eofflag){
- /* trim the end */
- /* no preceeding granulepos; assume we started at zero (we'd
- have to in a short single-page stream) */
- /* granulepos could be -1 due to a seek, but that would result
- in a long coun`t, not short count */
-
- v->pcm_current-=(b->sample_count-v->granulepos);
- }else{
- /* trim the beginning */
- v->pcm_returned+=(b->sample_count-v->granulepos);
- if(v->pcm_returned>v->pcm_current)
- v->pcm_returned=v->pcm_current;
- }
+ if(v->granulepos==-1){
+ if(vb->granulepos!=-1){ /* only set if we have a position to set to */
+
+ v->granulepos=vb->granulepos;
+
+ /* is this a short page? */
+ if(b->sample_count>v->granulepos){
+ /* corner case; if this is both the first and last audio page,
+ then spec says the end is cut, not beginning */
+ if(vb->eofflag){
+ /* trim the end */
+ /* no preceeding granulepos; assume we started at zero (we'd
+ have to in a short single-page stream) */
+ /* granulepos could be -1 due to a seek, but that would result
+ in a long coun`t, not short count */
+ v->pcm_current-=(b->sample_count-v->granulepos);
+ }else{
+ /* trim the beginning */
+ v->pcm_returned+=(b->sample_count-v->granulepos);
+ if(v->pcm_returned>v->pcm_current)
+ v->pcm_returned=v->pcm_current;
}
}
- }else{
- v->granulepos+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
- if(vb->granulepos!=-1 && v->granulepos!=vb->granulepos){
+
+ }
+ }else{
+ v->granulepos+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
+ if(vb->granulepos!=-1 && v->granulepos!=vb->granulepos){
+
+ if(v->granulepos>vb->granulepos){
+ long extra=v->granulepos-vb->granulepos;
- if(v->granulepos>vb->granulepos){
- long extra=v->granulepos-vb->granulepos;
-
- if(extra)
- if(vb->eofflag){
- /* partial last frame. Strip the extra samples off */
- v->pcm_current-=extra;
- } /* else {Shouldn't happen *unless* the bitstream is out of
- spec. Either way, believe the bitstream } */
- } /* else {Shouldn't happen *unless* the bitstream is out of
- spec. Either way, believe the bitstream } */
- v->granulepos=vb->granulepos;
- }
+ if(extra)
+ if(vb->eofflag){
+ /* partial last frame. Strip the extra samples off */
+ v->pcm_current-=extra;
+ } /* else {Shouldn't happen *unless* the bitstream is out of
+ spec. Either way, believe the bitstream } */
+ } /* else {Shouldn't happen *unless* the bitstream is out of
+ spec. Either way, believe the bitstream } */
+ v->granulepos=vb->granulepos;
}
-
- /* Update, cleanup */
-
- if(vb->eofflag)v->eofflag=1;
}
+ /* Update, cleanup */
+
+ if(vb->eofflag)v->eofflag=1;
return(0);
}