From e825a4e82b7a4c94725e1769bdc688fb815c9f04 Mon Sep 17 00:00:00 2001 From: Monty Date: Sun, 23 Dec 2001 11:53:54 +0000 Subject: [PATCH] beginning-of-stream tuning oops in bitrate management svn path=/trunk/vorbis/; revision=2898 --- lib/bitrate.c | 57 +++++++++++++++++++++++++------------------------- lib/bitrate.h | 4 +--- lib/block.c | 49 +++++++++++++++++++------------------------ lib/modes/residue_44.h | 6 +++--- lib/vorbisenc.c | 6 +----- 5 files changed, 55 insertions(+), 67 deletions(-) diff --git a/lib/bitrate.c b/lib/bitrate.c index 1424348..cb0472a 100644 --- a/lib/bitrate.c +++ b/lib/bitrate.c @@ -11,7 +11,7 @@ ******************************************************************** function: bitrate tracking and management - last mod: $Id: bitrate.c,v 1.7 2001/12/23 10:12:03 xiphmont Exp $ + last mod: $Id: bitrate.c,v 1.8 2001/12/23 11:53:52 xiphmont Exp $ ********************************************************************/ @@ -294,17 +294,6 @@ int vorbis_bitrate_addblock(vorbis_block *vb){ if(bm->avg_sampleacc>bm->avg_sampledesired || eofflag){ - /* update the avg tail if needed */ - while(bm->avg_sampleacc>bm->avg_sampledesired){ - int samples= - ci->blocksizes[bm->queue_actual[bm->avg_tail]&0x80000000UL?1:0]>>1; - for(i=0;iqueue_bins;i++) - bm->avg_binacc[i]-=LACING_ADJUST(bm->queue_binned[bins*bm->avg_tail+i]); - bm->avg_sampleacc-=samples; - bm->avg_tail++; - if(bm->avg_tail>=bm->queue_size)bm->avg_tail=0; - } - /* update the avg center */ if(bm->avg_centeracc>desired_center){ /* choose the new average floater */ @@ -321,14 +310,14 @@ int vorbis_bitrate_addblock(vorbis_block *vb){ slew=(new-bm->avgfloat)/samples*vi->rate; - if(slewavgfloat_downhyst || slew>bi->avgfloat_uphyst){ - if(slewavgfloat_downslew_max) - new=bm->avgfloat+bi->avgfloat_downslew_max/vi->rate*samples; - if(slew>bi->avgfloat_upslew_max) - new=bm->avgfloat+bi->avgfloat_upslew_max/vi->rate*samples; - - bm->avgfloat=new; - } + if(slewavgfloat_downslew_max) + new=bm->avgfloat+bi->avgfloat_downslew_max/vi->rate*samples; + if(slew>bi->avgfloat_upslew_max) + new=bm->avgfloat+bi->avgfloat_upslew_max/vi->rate*samples; + + bm->avgfloat=new; + + fprintf(stderr,"%d float: %f\n",bm->avg_center,new); /* apply the average floater to new blocks */ bin=bm->avgfloat*(BITTRACK_DIVISOR<avgnoise+=1.f; bm->noisetrigger_postpone=bm->avg_sampleacc/2; } - + /* we generally want the noise bias to drift back to zero */ bm->noisetrigger_request=0.f; if(bm->avgnoise>0) @@ -386,6 +375,19 @@ int vorbis_bitrate_addblock(vorbis_block *vb){ bm->avgnoise=bi->avgfloat_noise_maxval; } } + + /* update the avg tail if needed */ + while(bm->avg_sampleacc>bm->avg_sampledesired){ + int samples= + ci->blocksizes[bm->queue_actual[bm->avg_tail]&0x80000000UL?1:0]>>1; + for(i=0;iqueue_bins;i++) + bm->avg_binacc[i]-=LACING_ADJUST(bm->queue_binned[bins*bm->avg_tail+i]); + bm->avg_sampleacc-=samples; + bm->avg_tail++; + if(bm->avg_tail>=bm->queue_size)bm->avg_tail=0; + } + + } }else{ /* if we're not using an average tracker, the 'float' is nailed to @@ -399,13 +401,13 @@ int vorbis_bitrate_addblock(vorbis_block *vb){ /* update the min/max queues and enforce limits */ if(bm->minmax_binstack){ unsigned long sampledesired=eofflag?0:bm->minmax_sampledesired; - + /* add to stack recent */ while(minmax_head!=new_minmax_head){ unsigned int i; int samples=ci->blocksizes[bm->queue_actual[minmax_head]& 0x80000000UL?1:0]>>1; - + /* the construction here is not parallel to the floater's stack. @@ -451,13 +453,12 @@ int vorbis_bitrate_addblock(vorbis_block *vb){ bm->minmax_limitstack[bm->minmax_stackptr]=0; bm->minmax_sampleacc+=samples; bm->minmax_acctotal+= - LACING_ADJUST( - BINBITS(bm,minmax_head,bm->queue_actual[minmax_head])); + LACING_ADJUST(BINBITS(bm,minmax_head,bm->queue_actual[minmax_head])); minmax_head++; if(minmax_head>=bm->queue_size)minmax_head=0; } - + /* check limits, enforce changes */ if(bm->minmax_sampleacc>sampledesired){ double bitrate=(double)bm->minmax_acctotal/bm->minmax_sampleacc*vi->rate; @@ -575,7 +576,7 @@ int vorbis_bitrate_addblock(vorbis_block *vb){ sizeof(*bm->minmax_limitstack)*bm->minmax_stackptr); bm->minmax_stackptr--; } - + bm->minmax_tail++; if(bm->minmax_tail>=bm->queue_size)bm->minmax_tail=0; } @@ -610,12 +611,12 @@ int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,ogg_packet *op){ bytes=(BINBITS(bm,bm->next_to_flush,bin)+7)/8; memcpy(op,bm->queue_packets+bm->next_to_flush,sizeof(*op)); + if(bytesbytes)op->bytes=bytes; bm->next_to_flush++; if(bm->next_to_flush>=bm->queue_size)bm->next_to_flush=0; - if(bytes==0)exit(1); } return(1); diff --git a/lib/bitrate.h b/lib/bitrate.h index 5bf6d3b..b084b05 100644 --- a/lib/bitrate.h +++ b/lib/bitrate.h @@ -11,7 +11,7 @@ ******************************************************************** function: bitrate tracking and management - last mod: $Id: bitrate.h,v 1.4 2001/12/23 10:12:03 xiphmont Exp $ + last mod: $Id: bitrate.h,v 1.5 2001/12/23 11:53:52 xiphmont Exp $ ********************************************************************/ @@ -79,8 +79,6 @@ typedef struct bitrate_manager_info{ double avgfloat_minimum; /* set by mode */ double avgfloat_downslew_max; double avgfloat_upslew_max; - double avgfloat_downhyst; - double avgfloat_uphyst; double avgfloat_noise_lowtrigger; double avgfloat_noise_hightrigger; double avgfloat_noise_minval; diff --git a/lib/block.c b/lib/block.c index 5517672..5e7c887 100644 --- a/lib/block.c +++ b/lib/block.c @@ -11,7 +11,7 @@ ******************************************************************** function: PCM data vector blocking, windowing and dis/reassembly - last mod: $Id: block.c,v 1.54 2001/12/21 14:52:35 segher Exp $ + last mod: $Id: block.c,v 1.55 2001/12/23 11:53:52 xiphmont Exp $ Handle windowing, overlap-add, etc of the PCM vectors. This is made more amusing by Vorbis' current two allowed block sizes. @@ -502,7 +502,6 @@ int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb){ if(bp==-1)return(0); /* not enough data currently to search for a full long block */ v->nW=bp; - /*v->nW=0;*/ }else v->nW=0; @@ -551,35 +550,31 @@ int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb){ } vb->vd=v; - vb->sequence=v->sequence; + vb->sequence=v->sequence++; vb->granulepos=v->granulepos; vb->pcmend=ci->blocksizes[v->W]; - /* copy the vectors; this uses the local storage in vb */ - { - vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal; - - /* this tracks 'strongest peak' for later psychoacoustics */ - /* moved to the global psy state; clean this mess up */ - if(vbi->ampmax>g->ampmax)g->ampmax=vbi->ampmax; - g->ampmax=_vp_ampmax_decay(g->ampmax,v); - vbi->ampmax=g->ampmax; - - vb->pcm=_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels); - vbi->pcmdelay=_vorbis_block_alloc(vb,sizeof(*vbi->pcmdelay)*vi->channels); - for(i=0;ichannels;i++){ - vbi->pcmdelay[i]= - _vorbis_block_alloc(vb,(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i])); - memcpy(vbi->pcmdelay[i],v->pcm[i],(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i])); - vb->pcm[i]=vbi->pcmdelay[i]+beginW; - - /* before we added the delay - vb->pcm[i]=_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i])); - memcpy(vb->pcm[i],v->pcm[i]+beginW,ci->blocksizes[v->W]*sizeof(*vb->pcm[i])); - */ - } + /* this tracks 'strongest peak' for later psychoacoustics */ + /* moved to the global psy state; clean this mess up */ + if(vbi->ampmax>g->ampmax)g->ampmax=vbi->ampmax; + g->ampmax=_vp_ampmax_decay(g->ampmax,v); + vbi->ampmax=g->ampmax; + + vb->pcm=_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels); + vbi->pcmdelay=_vorbis_block_alloc(vb,sizeof(*vbi->pcmdelay)*vi->channels); + for(i=0;ichannels;i++){ + vbi->pcmdelay[i]= + _vorbis_block_alloc(vb,(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i])); + memcpy(vbi->pcmdelay[i],v->pcm[i],(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i])); + vb->pcm[i]=vbi->pcmdelay[i]+beginW; + + /* before we added the delay + vb->pcm[i]=_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i])); + memcpy(vb->pcm[i],v->pcm[i]+beginW,ci->blocksizes[v->W]*sizeof(*vb->pcm[i])); + */ + } /* handle eof detection: eof==0 means that we've not yet received EOF @@ -613,8 +608,6 @@ int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb){ v->W=v->nW; v->centerW=new_centerNext; - v->sequence++; - if(v->eofflag){ v->eofflag-=movementW; /* do not add padding to end of stream! */ diff --git a/lib/modes/residue_44.h b/lib/modes/residue_44.h index e500f60..b99c91b 100644 --- a/lib/modes/residue_44.h +++ b/lib/modes/residue_44.h @@ -11,7 +11,7 @@ ******************************************************************** function: toplevel residue templates for 32/44.1/48kHz - last mod: $Id: residue_44.h,v 1.10 2001/12/23 10:12:04 xiphmont Exp $ + last mod: $Id: residue_44.h,v 1.11 2001/12/23 11:53:54 xiphmont Exp $ ********************************************************************/ @@ -24,8 +24,8 @@ static bitrate_manager_info _bm_44_default={ 2., 0, 0, 0, 0, - 4.0,2.3, -350, .02, - -.00, .00, + 4.0,2.3, -9999, .02, + 3.2,5.0, 0.,0. }; diff --git a/lib/vorbisenc.c b/lib/vorbisenc.c index 204574b..2134177 100644 --- a/lib/vorbisenc.c +++ b/lib/vorbisenc.c @@ -11,7 +11,7 @@ ******************************************************************** function: simple programmatic interface for encoder mode setup - last mod: $Id: vorbisenc.c,v 1.32 2001/12/23 10:12:03 xiphmont Exp $ + last mod: $Id: vorbisenc.c,v 1.33 2001/12/23 11:53:53 xiphmont Exp $ ********************************************************************/ @@ -978,10 +978,6 @@ int vorbis_encode_setup_managed(vorbis_info *vi, ci->bi.queue_avgmax=tnominal; /* adjust management */ - if(max_bitrate<=0. && min_bitrate<=0.){ - /* just an average tracker; no reason for the window to be as small as 2s. */ - //ci->bi.queue_avg_time=4.; - } ci->bi.avgfloat_noise_maxval=_bm_max_noise_offset[(int)approx_vbr]; } -- 2.7.4