********************************************************************
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 $
********************************************************************/
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;i<bm->queue_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 */
slew=(new-bm->avgfloat)/samples*vi->rate;
- if(slew<bi->avgfloat_downhyst || slew>bi->avgfloat_uphyst){
- if(slew<bi->avgfloat_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(slew<bi->avgfloat_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<<BITTRACK_BPT);
bm->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)
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;i<bm->queue_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
/* 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.
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;
sizeof(*bm->minmax_limitstack)*bm->minmax_stackptr);
bm->minmax_stackptr--;
}
-
+
bm->minmax_tail++;
if(bm->minmax_tail>=bm->queue_size)bm->minmax_tail=0;
}
bytes=(BINBITS(bm,bm->next_to_flush,bin)+7)/8;
memcpy(op,bm->queue_packets+bm->next_to_flush,sizeof(*op));
+
if(bytes<op->bytes)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);
********************************************************************
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 $
********************************************************************/
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;
********************************************************************
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.
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;
}
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;i<vi->channels;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;i<vi->channels;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
v->W=v->nW;
v->centerW=new_centerNext;
- v->sequence++;
-
if(v->eofflag){
v->eofflag-=movementW;
/* do not add padding to end of stream! */
********************************************************************
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 $
********************************************************************/
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.
};
********************************************************************
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 $
********************************************************************/
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];
}