[xiph-cvs] cvs commit: vorbis/lib/modes mode_44c_A.h
Monty
xiphmont at xiph.org
Wed Nov 21 22:21:12 PST 2001
xiphmont 01/11/21 22:21:12
Modified: examples Tag: branch_monty_20011009 chaining_example.c
include/vorbis Tag: branch_monty_20011009 codec.h
lib Tag: branch_monty_20011009 Makefile.am analysis.c
backends.h bitrate.c bitrate.h block.c codebook.c
codec_internal.h floor0.c floor1.c mapping0.c
res0.c
lib/modes Tag: branch_monty_20011009 mode_44c_A.h
Log:
bitrate management mark II running in 'full blown' mode. Likely still
issues with partially enabled modes. testing continues...
Revision Changes Path
No revision
No revision
1.13.2.2 +1 -3 vorbis/examples/chaining_example.c
Index: chaining_example.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/examples/chaining_example.c,v
retrieving revision 1.13.2.1
retrieving revision 1.13.2.2
diff -u -r1.13.2.1 -r1.13.2.2
--- chaining_example.c 2001/11/22 06:19:52 1.13.2.1
+++ chaining_example.c 2001/11/22 06:21:05 1.13.2.2
@@ -11,7 +11,7 @@
********************************************************************
function: illustrate simple use of chained bitstream and vorbisfile.a
- last mod: $Id: chaining_example.c,v 1.13.2.1 2001/11/22 06:19:52 xiphmont Exp $
+ last mod: $Id: chaining_example.c,v 1.13.2.2 2001/11/22 06:21:05 xiphmont Exp $
********************************************************************/
@@ -61,8 +61,6 @@
printf("\t\theader length: %ld bytes\n",(long)
(ov.dataoffsets[i]-ov.offsets[i]));
printf("\t\tcompressed length: %ld bytes\n",(long)(ov_raw_total(&ov,i)));
- printf("\t\tuncompressed length: %ld bytes\n",
- (long)(ov_pcm_total(&ov,i))*vi->channels*2+44);
printf("\t\tplay time: %lds\n",(long)ov_time_total(&ov,i));
}
No revision
No revision
1.38.6.1 +5 -1 vorbis/include/vorbis/codec.h
Index: codec.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis/include/vorbis/codec.h,v
retrieving revision 1.38
retrieving revision 1.38.6.1
diff -u -r1.38 -r1.38.6.1
--- codec.h 2001/05/27 06:43:59 1.38
+++ codec.h 2001/11/22 06:21:06 1.38.6.1
@@ -11,7 +11,7 @@
********************************************************************
function: libvorbis codec headers
- last mod: $Id: codec.h,v 1.38 2001/05/27 06:43:59 xiphmont Exp $
+ last mod: $Id: codec.h,v 1.38.6.1 2001/11/22 06:21:06 xiphmont Exp $
********************************************************************/
@@ -189,6 +189,10 @@
extern int vorbis_analysis_wrote(vorbis_dsp_state *v,int vals);
extern int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb);
extern int vorbis_analysis(vorbis_block *vb,ogg_packet *op);
+
+extern int vorbis_bitrate_addblock(vorbis_block *vb);
+extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,
+ ogg_packet *op);
/* Vorbis PRIMITIVES: synthesis layer *******************************/
extern int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,
No revision
No revision
1.12.6.1 +2 -2 vorbis/lib/Makefile.am
Index: Makefile.am
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/Makefile.am,v
retrieving revision 1.12
retrieving revision 1.12.6.1
diff -u -r1.12 -r1.12.6.1
--- Makefile.am 2001/05/27 06:43:59 1.12
+++ Makefile.am 2001/11/22 06:21:07 1.12.6.1
@@ -12,11 +12,11 @@
lpc.c analysis.c synthesis.c psy.c info.c time0.c \
floor1.c floor0.c\
res0.c mapping0.c registry.c codebook.c sharedbook.c\
- lookup.c bitbuffer.c\
+ lookup.c bitrate.c\
envelope.h lpc.h lsp.h codebook.h misc.h psy.h\
masking.h iir.h os.h mdct.h smallft.h\
registry.h scales.h window.h lookup.h lookup_data.h\
- codec_internal.h backends.h bitbuffer.h
+ codec_internal.h backends.h bitrate.h
libvorbis_la_LDFLAGS = -version-info @V_LIB_CURRENT@:@V_LIB_REVISION@:@V_LIB_AGE@
libvorbisfile_la_SOURCES = vorbisfile.c
1.46.4.2 +13 -9 vorbis/lib/analysis.c
Index: analysis.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/analysis.c,v
retrieving revision 1.46.4.1
retrieving revision 1.46.4.2
diff -u -r1.46.4.1 -r1.46.4.2
--- analysis.c 2001/11/16 08:17:04 1.46.4.1
+++ analysis.c 2001/11/22 06:21:07 1.46.4.2
@@ -11,7 +11,7 @@
********************************************************************
function: single-block PCM analysis mode dispatch
- last mod: $Id: analysis.c,v 1.46.4.1 2001/11/16 08:17:04 xiphmont Exp $
+ last mod: $Id: analysis.c,v 1.46.4.2 2001/11/22 06:21:07 xiphmont Exp $
********************************************************************/
@@ -27,12 +27,8 @@
int analysis_noisy=1;
-int vorbis_analysis_packetout(vorbis_block *vb,ogg_packet *op){
- return(vorbis_bitrate_flushpacket(&(vb->bms),op));
-}
-
/* decides between modes, dispatches to the appropriate mapping. */
-int vorbis_analysis(vorbis_block *vb){
+int vorbis_analysis(vorbis_block *vb, ogg_packet *op){
vorbis_dsp_state *vd=vb->vd;
backend_lookup_state *b=vd->backend_state;
vorbis_info *vi=vd->vi;
@@ -49,9 +45,9 @@
oggpack_reset(&vb->opb);
/* Encode the packet type */
oggpack_write(&vb->opb,0,1);
-
+
/* currently lazy. Short block dispatches to 0, long to 1. */
-
+
if(vb->W &&ci->modes>1)mode=1;
type=ci->map_type[ci->mode_param[mode]->mapping];
vb->mode=mode;
@@ -69,7 +65,15 @@
if((ret=_mapping_P[type]->forward(vb,b->mode[mode])))
return(ret);
- return(vorbis_bitrate_addblock(vb));
+ if(op){
+ op->packet=oggpack_get_buffer(&vb->opb);
+ op->bytes=oggpack_bytes(&vb->opb);
+ op->b_o_s=0;
+ op->e_o_s=vb->eofflag;
+ op->granulepos=vb->granulepos;
+ op->packetno=vb->sequence; /* for sake of completeness */
+ }
+ return(0);
}
/* there was no great place to put this.... */
1.10.4.2 +2 -2 vorbis/lib/backends.h
Index: backends.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/backends.h,v
retrieving revision 1.10.4.1
retrieving revision 1.10.4.2
diff -u -r1.10.4.1 -r1.10.4.2
--- backends.h 2001/10/09 04:34:45 1.10.4.1
+++ backends.h 2001/11/22 06:21:07 1.10.4.2
@@ -12,7 +12,7 @@
function: libvorbis backend and mapping structures; needed for
static mode headers
- last mod: $Id: backends.h,v 1.10.4.1 2001/10/09 04:34:45 xiphmont Exp $
+ last mod: $Id: backends.h,v 1.10.4.2 2001/11/22 06:21:07 xiphmont Exp $
********************************************************************/
@@ -130,7 +130,7 @@
long **(*class) (struct vorbis_block *,vorbis_look_residue *,
float **,int *,int);
int (*forward) (struct vorbis_block *,vorbis_look_residue *,
- float **,float **,int *,int,int,long **,double,ogg_uint32_t *);
+ float **,float **,int *,int,int,long **,ogg_uint32_t *);
int (*inverse) (struct vorbis_block *,vorbis_look_residue *,
float **,int *,int);
} vorbis_func_residue;
1.1.2.2 +253 -150 vorbis/lib/Attic/bitrate.c
Index: bitrate.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/Attic/bitrate.c,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- bitrate.c 2001/11/16 08:17:04 1.1.2.1
+++ bitrate.c 2001/11/22 06:21:07 1.1.2.2
@@ -11,11 +11,13 @@
********************************************************************
function: bitrate tracking and management
- last mod: $Id: bitrate.c,v 1.1.2.1 2001/11/16 08:17:04 xiphmont Exp $
+ last mod: $Id: bitrate.c,v 1.1.2.2 2001/11/22 06:21:07 xiphmont Exp $
********************************************************************/
#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
#include <string.h>
#include <math.h>
#include <ogg/ogg.h>
@@ -61,7 +63,8 @@
static long limit_sum(bitrate_manager_state *bm,int limit){
int i=bm->minmax_stackptr;
long acc=bm->minmax_acctotal;
-
+ long bins=bm->queue_bins;
+
acc-=LIMITBITS(i,0);
acc+=LIMITBITS(i,limit);
@@ -73,60 +76,71 @@
return(acc);
}
+/* compute bitrate tracking setup, allocate circular packet size queue */
void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bm){
- /* compute bitrate tracking setup, allocate circular packet size queue */
- {
- codec_setup_info *ci=vi->codec_setup;
- bitrate_manager_info *bi=ci->bi;
- long maxlatency;
-
- memset(bm,0,sizeof(*bm));
+ int i;
+ codec_setup_info *ci=vi->codec_setup;
+ bitrate_manager_info *bi=ci->bi;
+ long maxlatency;
+
+ memset(bm,0,sizeof(*bm));
+
+ bm->avg_sampledesired=bi->queue_avg_time*vi->rate;
+ bm->avg_centerdesired=bi->queue_avg_time*vi->rate*bi->queue_avg_center;
+ bm->minmax_sampledesired=bi->queue_minmax_time*vi->rate;
+
+ if(bm->avg_sampledesired<0)bm->avg_sampledesired=0;
+ if(bm->avg_centerdesired<0)bm->avg_centerdesired=0;
+ if(bm->minmax_sampledesired<0)bm->minmax_sampledesired=0;
+
+ /* first find the max possible needed queue size */
+ maxlatency=max(bm->avg_sampledesired-bm->avg_centerdesired,
+ bi->queue_minmax_time)+bm->avg_centerdesired;
+
+ if(maxlatency>0){
+ long maxpackets=maxlatency/ci->blocksizes[0]+3;
+ long bins=BITTRACK_DIVISOR*ci->passlimit[ci->coupling_passes-1];
- bm->avg_sampledesired=bi->queue_avg_time*vi->rate;
- bm->avg_centerdesired=bi->queue_avg_time*vi->rate*bi->queue_avg_center;
- bm->minmax_sampledesired=bi->queue_minmax_time*vi->rate;
-
- if(bm->avg_sampledesired<0)bm->avg_sampledesired=0;
- if(bm->avg_centerdesired<0)bm->avg_centerdesired=0;
- if(bm->minmax_sampledesired<0)bm->minmax_sampledesired=0;
-
- /* first find the max possible needed queue size */
- maxlatency=max(bm->avg_sampledesired-bm->avg_centerdesired,
- bi->queue_minmax_time)+bm->avg_centerdesired;
+ bm->queue_size=maxpackets;
+ bm->queue_bins=bins;
+ bm->queue_binned=_ogg_malloc(maxpackets*bins*sizeof(*bm->queue_binned));
+ bm->queue_actual=_ogg_malloc(maxpackets*sizeof(*bm->queue_actual));
- if(maxlatency>0){
- long maxpackets=maxlatency/ci->blocksizes[0]+3;
- long bins=BITTRACK_DIVISOR*ci->passlimit[ci->coupling_passes-1];
-
- bm->queue_size=maxpackets;
- bm->queue_bins=bins;
- b->queue_binned=_ogg_malloc(maxpackets*bins*sizeof(*b->queue_binned));
- b->queue_actual=_ogg_malloc(maxpackets*sizeof(*b->queue_actual));
+ if((bi->queue_avgmin>0 || bi->queue_avgmax>0) &&
+ bi->queue_avg_time>0){
- if((bi->queue_avgmin>0 || bi->queue_avgmax>0) &&
- bi->queue_avg_time>0){
-
- bm->avg_binacc=_ogg_malloc(bins*sizeof(*bm->binacc));
- bm->avgfloat=bi->avgfloat_initial;
-
-
- }
-
- if((bi->queue_hardmin>0 || bi->queue_hardmax>0) &&
+ bm->avg_binacc=_ogg_malloc(bins*sizeof(*bm->avg_binacc));
+ bm->avgfloat=bi->avgfloat_initial;
+
+
+ }
+
+ if((bi->queue_hardmin>0 || bi->queue_hardmax>0) &&
bi->queue_minmax_time>0){
-
- bm->minmax_binstack=_ogg_malloc((bins+1)*bins*2*
- sizeof(bm->minmax_binstack));
- bm->minmax_posstack=_ogg_malloc((bins+1)*
- sizeof(bm->minmax_posstack));
- bm->minmax_limitstack=_ogg_malloc((bins+1)*
- sizeof(bm->minmax_limitstack));
- }
+
+ bm->minmax_binstack=_ogg_malloc((bins+1)*bins*2*
+ sizeof(bm->minmax_binstack));
+ bm->minmax_posstack=_ogg_malloc((bins+1)*
+ sizeof(bm->minmax_posstack));
+ bm->minmax_limitstack=_ogg_malloc((bins+1)*
+ sizeof(bm->minmax_limitstack));
}
- }
+
+ /* space for the packet queueing */
+ bm->queue_packet_buffers=calloc(maxpackets,sizeof(*bm->queue_packet_buffers));
+ bm->queue_packets=calloc(maxpackets,sizeof(*bm->queue_packets));
+ for(i=0;i<maxpackets;i++)
+ oggpack_writeinit(bm->queue_packet_buffers+i);
+
+ }else{
+ bm->queue_packet_buffers=calloc(1,sizeof(*bm->queue_packet_buffers));
+ bm->queue_packets=calloc(1,sizeof(*bm->queue_packets));
+ oggpack_writeinit(bm->queue_packet_buffers);
+ }
}
void vorbis_bitrate_clear(bitrate_manager_state *bm){
+ int i;
if(bm){
if(bm->queue_binned)_ogg_free(bm->queue_binned);
if(bm->queue_actual)_ogg_free(bm->queue_actual);
@@ -134,56 +148,118 @@
if(bm->minmax_binstack)_ogg_free(bm->minmax_binstack);
if(bm->minmax_posstack)_ogg_free(bm->minmax_posstack);
if(bm->minmax_limitstack)_ogg_free(bm->minmax_limitstack);
+ if(bm->queue_packet_buffers){
+ if(bm->queue_size==0){
+ oggpack_writeclear(bm->queue_packet_buffers);
+ _ogg_free(bm->queue_packet_buffers);
+ }else{
+ for(i=0;i<bm->queue_size;i++)
+ oggpack_writeclear(bm->queue_packet_buffers+i);
+ _ogg_free(bm->queue_packet_buffers);
+ }
+ }
+ if(bm->queue_packets)_ogg_free(bm->queue_packets);
memset(bm,0,sizeof(*bm));
}
}
-/* makes the accumulation buffer available to the encode process */
-ogg_uint32_t vorbis_bitrate_bufferblock(vorbis_block *vb){
- bitrate_manager_state *bm=&vb->bms;
- int next_head=bm->queue_head+1;
- if(!bm->queue_binned)return(NULL);
- if(next_head>bm->queue_size)next_head==0;
+int vorbis_bitrate_managed(vorbis_block *vb){
+ vorbis_dsp_state *vd=vb->vd;
+ backend_lookup_state *b=vd->backend_state;
+ bitrate_manager_state *bm=&b->bms;
- /* is there room to add a block? In proper use of the API, this will
- never come up... but guard it anyway. */
- if(next_head==bm->avg_tail || next_head==bm->minmax_tail)return(NULL);
- return(bm->queue_binned+bm->queue_head*bm->queue_bins);
+ if(bm->queue_binned)return(1);
+ return(0);
}
+int vorbis_bitrate_maxmarkers(void){
+ return 8*BITTRACK_DIVISOR;
+}
+
/* finish taking in the block we just processed */
int vorbis_bitrate_addblock(vorbis_block *vb){
- int i,j;
- bitrate_manager_state *bm=&vb->bms;
+ int i;
+ vorbis_block_internal *vbi=vb->internal;
vorbis_dsp_state *vd=vb->vd;
- backend_lookup_state *b=vd->backend_state;
+ backend_lookup_state *b=vd->backend_state;
+ bitrate_manager_state *bm=&b->bms;
vorbis_info *vi=vd->vi;
codec_setup_info *ci=vi->codec_setup;
- int eofflag=vd->eofflag;
+ bitrate_manager_info *bi=ci->bi;
+ int eofflag=vb->eofflag;
int head=bm->queue_head;
int next_head=head+1;
int bins=bm->queue_bins;
- int avg_head=head;
int minmax_head,new_minmax_head;
+ long maxbits;
ogg_uint32_t *head_ptr;
-
- if(!bm->queue_binned)return(0);
- if(next_head>bm->queue_size)next_head==0;
+ oggpack_buffer temp;
+
+ /* enforce maxbits; min is enforced in the mapping */
+ /*if(bi->queue_hardmax){
+ maxbits=bi->queue_hardmax/vi->rate*ci->blocksizes[vb->W?1:0]/2;
+ if(maxbits<oggpack_bits(&vb->opb)){
+ vb->opb.endbyte=maxbits/8;
+ vb->opb.endbit=maxbits%8;
+ }
+ }*/
+
+ if(!bm->queue_binned){
+ oggpack_buffer temp;
+ /* not a bitrate managed stream, but for API simplicity, we'll
+ buffer one packet to keep the code path clean */
+
+ if(bm->queue_head)return(-1); /* one has been submitted without
+ being claimed */
+ bm->queue_head++;
+
+ bm->queue_packets[0].packet=oggpack_get_buffer(&vb->opb);
+ bm->queue_packets[0].bytes=oggpack_bytes(&vb->opb);
+ bm->queue_packets[0].b_o_s=0;
+ bm->queue_packets[0].e_o_s=vb->eofflag;
+ bm->queue_packets[0].granulepos=vb->granulepos;
+ bm->queue_packets[0].packetno=vb->sequence; /* for sake of completeness */
+
+ memcpy(&temp,bm->queue_packet_buffers,sizeof(vb->opb));
+ memcpy(bm->queue_packet_buffers,&vb->opb,sizeof(vb->opb));
+ memcpy(&vb->opb,&temp,sizeof(vb->opb));
+
+ return(0);
+ }
+
+ /* add encoded packet to head */
+ if(next_head>=bm->queue_size)next_head=0;
head_ptr=bm->queue_binned+bins*head;
/* is there room to add a block? In proper use of the API, this will
never come up... but guard it anyway */
if(next_head==bm->avg_tail || next_head==bm->minmax_tail)return(-1);
- /* add the block to the toplevel queue; the buffer is already set */
- bm->head=next_head;
+ /* add the block to the toplevel queue */
+ bm->queue_head=next_head;
bm->queue_actual[head]=(vb->W?0x80000000UL:0);
+ /* buffer packet fields */
+ bm->queue_packets[head].packet=oggpack_get_buffer(&vb->opb);
+ bm->queue_packets[head].bytes=oggpack_bytes(&vb->opb);
+ bm->queue_packets[head].b_o_s=0;
+ bm->queue_packets[head].e_o_s=vb->eofflag;
+ bm->queue_packets[head].granulepos=vb->granulepos;
+ bm->queue_packets[head].packetno=vb->sequence; /* for sake of completeness */
+
+ /* swap packet buffers */
+ memcpy(&temp,bm->queue_packet_buffers+head,sizeof(vb->opb));
+ memcpy(bm->queue_packet_buffers+head,&vb->opb,sizeof(vb->opb));
+ memcpy(&vb->opb,&temp,sizeof(vb->opb));
+
+ /* save markers */
+ memcpy(head_ptr,vbi->packet_markers,sizeof(*head_ptr)*bins);
+
if(bm->avg_binacc)
- minmax_head=bm->avg_center;
+ new_minmax_head=minmax_head=bm->avg_center;
else
- minmax_head=head;
+ new_minmax_head=minmax_head=head;
/* the average tracking queue is updated first; its results (if it's
in use) are taken into account by the min/max limiter (if min/max
@@ -200,18 +276,17 @@
/* update the avg tail if needed */
while(bm->avg_sampleacc>bm->avg_sampledesired){
- int samples=(bm->queue_actual[b->avg_tail]&0x80000000UL?
- samples=ci->blocksizes[1]>>1:
- samples=ci->blocksizes[0]>>1);
+ 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]-=bm->queue_binned[bins*bm->queue_tail+i];
+ bm->avg_binacc[i]-=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 */
double upper=floater_interpolate(bm,vi,bi->queue_avgmax);
double lower=floater_interpolate(bm,vi,bi->queue_avgmin);
@@ -220,7 +295,7 @@
if(upper>0. && upper<new)new=upper;
if(lower<bi->avgfloat_minimum)
- lower=bi->bitrate_avgfloat_minimum;
+ lower=bi->avgfloat_minimum;
if(lower>new)new=lower;
slew=new-bm->avgfloat;
@@ -236,10 +311,11 @@
/* apply the average floater to new blocks */
bin=bm->avgfloat*BITTRACK_DIVISOR; /* truncate on purpose */
+ //fprintf(stderr,"float:%d ",bin);
while(bm->avg_centeracc>desired_center){
- int samples=(bm->queue_actual[b->avg_tail]&0x80000000UL?
- samples=ci->blocksizes[1]>>1:
- samples=ci->blocksizes[0]>>1);
+ int samples=
+ samples=ci->blocksizes[bm->queue_actual[bm->avg_center]&
+ 0x80000000UL?1:0]>>1;
bm->queue_actual[bm->avg_center]|=bin;
@@ -278,29 +354,29 @@
if(bm->avgnoise<0)
bm->noisetrigger_request= +1.;
- if(bm->avgnoise<bi->avgfloat_noisetrigger_minoff)
- bm->avgnoise=bi->avgfloat_noisetrigger_minoff;
- if(bm->avgnoise>bi->avgfloat_noisetrigger_maxoff)
- bm->avgnoise=bi->avgfloat_noisetrigger_maxoff;
+ if(bm->avgnoise<bi->avgfloat_noise_minval)
+ bm->avgnoise=bi->avgfloat_noise_minval;
+ if(bm->avgnoise>bi->avgfloat_noise_maxval)
+ bm->avgnoise=bi->avgfloat_noise_maxval;
}
}
}else{
/* if we're not using an average tracker, the 'float' is nailed to
the avgfloat_initial value. It needs to be set for the min/max
to deal properly */
- bin=bi->avgfloat_initial*BITTRACK_DIVISOR; /* truncate on purpose */
+ long bin=bi->avgfloat_initial*BITTRACK_DIVISOR; /* truncate on purpose */
bm->queue_actual[head]|=bin;
- new_minmax_head=new_head;
+ new_minmax_head=next_head;
}
/* update the min/max queues and enforce limits */
if(bm->minmax_binstack){
-
+ long sampledesired=eofflag?0:bm->minmax_sampledesired;
+
/* add to stack recent */
while(minmax_head!=new_minmax_head){
- int samples=(vb->W?
- samples=ci->blocksizes[1]>>1:
- samples=ci->blocksizes[0]>>1);
+ int samples=ci->blocksizes[bm->queue_actual[minmax_head]&
+ 0x80000000UL?1:0]>>1;
/* the construction here is not parallel to the floater's
stack.
@@ -328,15 +404,17 @@
(bm->queue_actual[minmax_head]&0x7fffffffUL)>i+1?
(bm->queue_actual[minmax_head]&0x7fffffffUL):i+1);
- bm->minmax_binstack[bm->max_stackptr*bins*2+i]+=
+ bm->minmax_binstack[bm->minmax_stackptr*bins*2+i]+=
BINBITS(minmax_head,
(bm->queue_actual[minmax_head]&0x7fffffffUL)<i+1?
(bm->queue_actual[minmax_head]&0x7fffffffUL):i+1);
}
- bm->minmax_posstack[bm->max_stackptr]=minmax_head; /* not one past like
- typical */
- bm->minmax_limitstack[bm->max_stackptr]=0;
+ bm->minmax_posstack[bm->minmax_stackptr]=minmax_head; /* not one
+ past
+ like
+ typical */
+ bm->minmax_limitstack[bm->minmax_stackptr]=0;
bm->minmax_sampleacc+=samples;
bm->minmax_acctotal+=
BINBITS(minmax_head,(bm->queue_actual[minmax_head]&0x7fffffffUL));
@@ -345,70 +423,32 @@
if(minmax_head>=bm->queue_size)minmax_head=0;
}
- /* remove from tail */
- while(bm->minmax_sampleacc>bm->minmax_sampledesired){
- int samples=(bm->queue_actual[bm->minmax_tail]&0x80000000UL?
- samples=ci->blocksizes[1]>>1:
- samples=ci->blocksizes[0]>>1);
- int actual=bm->queue_actual[bm->minmax_tail]&0x7fffffffUL;
-
- for(i=0;i<bins;i++){
- bm->min_binstack[bins+i]-= /* always comes off the stack bottom */
- BINBITS(bm->minmax_tail,
- (bm->queue_actual[bm->minmax_tail]&0x7fffffffUL)>i+1?
- (bm->queue_actual[bm->minmax_tail]&0x7fffffffUL):i+1);
- bm->max_binstack[i]-=
- BINBITS(bm->minmax_tail,
- (bm->queue_actual[bm->minmax_tail]&0x7fffffffUL)<i+1?
- (bm->queue_actual[bm->minmax_tail]&0x7fffffffUL):i+1);
- }
-
- if(bm->minmax_tail==bm->minmax_posstack[0]){
- /* the stack becomes a FILO; we've fallen off the end of the
- first data */
- memmove(bm->minmax_binstack,bm->minmax_binstack+bins*2,
- sizeof(*bm->minmax_binstack)*bins*2*bm->minmax_stackptr);
- memmove(bm->minmax_posstack,bm->minmax_posstack+1,
- sizeof(*bm->minmax_posstack)*bm->minmax_stackptr);
- memmove(bm->minmax_limitstack,bm->minmax_limitstack+1,
- sizeof(*bm->minmax_limitstack)*bm->minmax_stackptr);
- bm->minmax_stackptr--;
- }
-
- /* always perform in this order; max overrules min */
- if(bm->minmax_limitstack[0]>actual)
- actual=bm->minmax_limitstack[0];
- if(bins+bm->minmax_limitstack[0]<actual)
- actual=bins+bm->minmax_limitstack[0];
-
- bm->minmax_acctotal-=BINBITS(bm->minmax_tail,actual);
- bm->minmax_sampleacc-=samples;
- bm->minmax_tail++;
- if(bm->minmax_tail>bm->queue_size)bm->minmax_tail=bm->queue_size;
- }
-
/* check limits, enforce changes */
- if(bm->minmax_binstack){
+ if(bm->minmax_sampleacc>sampledesired){
double bitrate=(double)bm->minmax_acctotal/bm->minmax_sampleacc*vi->rate;
int limit=0;
- if(bitrate>bi->queue_hardmax || bitrate<bi->queue_hardmax){
- int limit=0;
+
+ //fprintf(stderr,"prelimit:%dkbps ",(int)bitrate);
+ if(bitrate>bi->queue_hardmax || bitrate<bi->queue_hardmin){
int newstack;
- int stcakctr;
+ int stackctr;
+ long bitsum=limit_sum(bm,0);
+ bitrate=(double)bitsum/bm->minmax_sampleacc*vi->rate;
+
/* we're off rate. Iteratively try out new hard floater
limits until we find one that brings us inside. Here's
where we see the whole point of the limit stacks. */
if(bitrate>bi->queue_hardmax){
- for(limit=-1;limit>=-bins;limit--){
+ for(limit=-1;limit>-bins;limit--){
long bitsum=limit_sum(bm,limit);
bitrate=(double)bitsum/bm->minmax_sampleacc*vi->rate;
if(bitrate<=bi->queue_hardmax)break;
}
}else if(bitrate<bi->queue_hardmin){
- for(limit=1;limit<bins*2;limit++){
+ for(limit=1;limit<bins;limit++){
long bitsum=limit_sum(bm,limit);
bitrate=(double)bitsum/bm->minmax_sampleacc*vi->rate;
- if(bitrate>=bi->queue_hardmax)break;
+ if(bitrate>=bi->queue_hardmin)break;
}
}
@@ -418,7 +458,7 @@
if(bm->minmax_limitstack[newstack]<limit)break;
newstack--;
}
-
+
/* update bit counter with new limit and replace any stack
limits that have been replaced by our new lower limit */
stackctr=bm->minmax_stackptr;
@@ -437,6 +477,7 @@
stackctr++;
bm->minmax_posstack[stackctr]=bm->minmax_posstack[bm->minmax_stackptr];
bm->minmax_limitstack[stackctr]=limit;
+ //fprintf(stderr,"limit:%d\n",limit);
/* set up new blank stack entry */
stackctr++;
@@ -446,27 +487,89 @@
sizeof(*bm->minmax_binstack)*bins*2);
bm->minmax_limitstack[stackctr]=0;
bm->minmax_posstack[stackctr]=-1;
-
+
}
}
+
+ /* remove from tail */
+ while(bm->minmax_sampleacc>sampledesired){
+ int samples=
+ ci->blocksizes[bm->queue_actual[bm->minmax_tail]&0x80000000UL?1:0]>>1;
+ int actual=bm->queue_actual[bm->minmax_tail]&0x7fffffffUL;
+ for(i=0;i<bins;i++){
+ bm->minmax_binstack[bins+i]-= /* always comes off the stack bottom */
+ BINBITS(bm->minmax_tail,actual>i+1?actual:i+1);
+ bm->minmax_binstack[i]-=
+ BINBITS(bm->minmax_tail,actual<i+1?actual:i+1);
+ }
+
+ /* always perform in this order; max overrules min */
+ if(bm->minmax_limitstack[0]>actual)
+ actual=bm->minmax_limitstack[0];
+ if(bins+bm->minmax_limitstack[0]<actual)
+ actual=bins+bm->minmax_limitstack[0];
+
+ bm->minmax_acctotal-=BINBITS(bm->minmax_tail,actual);
+ bm->minmax_sampleacc-=samples;
+
+ /* revise queue_actual to reflect the limit */
+ bm->queue_actual[bm->minmax_tail]=actual;
+
+ if(bm->minmax_tail==bm->minmax_posstack[0]){
+ /* the stack becomes a FIFO; the first data has fallen off */
+ memmove(bm->minmax_binstack,bm->minmax_binstack+bins*2,
+ sizeof(*bm->minmax_binstack)*bins*2*bm->minmax_stackptr);
+ memmove(bm->minmax_posstack,bm->minmax_posstack+1,
+ sizeof(*bm->minmax_posstack)*bm->minmax_stackptr);
+ memmove(bm->minmax_limitstack,bm->minmax_limitstack+1,
+ sizeof(*bm->minmax_limitstack)*bm->minmax_stackptr);
+ bm->minmax_stackptr--;
+ }
+
+ bm->minmax_tail++;
+ if(bm->minmax_tail>=bm->queue_size)bm->minmax_tail=0;
+ }
+
+
bm->last_to_flush=bm->minmax_tail;
}else{
bm->last_to_flush=bm->avg_center;
}
if(eofflag)
- bm->last_to_flush=bm->head;
+ bm->last_to_flush=bm->queue_head;
return(0);
}
+
+int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,ogg_packet *op){
+ backend_lookup_state *b=vd->backend_state;
+ bitrate_manager_state *bm=&b->bms;
+
+ if(bm->queue_size==0){
+ if(bm->queue_head==0)return(0);
-int vorbis_bitrate_flushpacket(bitrate_manager_state *bm, vorbis_packet *op){
- vorbis_dsp_state *vd=vb->vd;
- backend_lookup_state *b=vd->backend_state;
- vorbis_info *vi=vd->vi;
- codec_setup_info *ci=vi->codec_setup;
- int eofflag=vd->eofflag;
+ memcpy(op,bm->queue_packets,sizeof(*op));
+ bm->queue_head=0;
- if(bm
+ }else{
+ long bin;
+ long bytes;
+
+ fprintf(stderr,"in ");
+ if(bm->next_to_flush==bm->last_to_flush)return(0);
+
+ bin=bm->queue_actual[bm->next_to_flush];
+ bytes=(bm->queue_binned[bm->queue_bins*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;
+
+ fprintf(stderr,"eof %d %ld\n",op->e_o_s,(long)op->granulepos);
+
+ }
+ return(1);
}
1.1.2.2 +7 -6 vorbis/lib/Attic/bitrate.h
Index: bitrate.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/Attic/bitrate.h,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- bitrate.h 2001/11/16 08:17:06 1.1.2.1
+++ bitrate.h 2001/11/22 06:21:07 1.1.2.2
@@ -11,7 +11,7 @@
********************************************************************
function: bitrate tracking and management
- last mod: $Id: bitrate.h,v 1.1.2.1 2001/11/16 08:17:06 xiphmont Exp $
+ last mod: $Id: bitrate.h,v 1.1.2.2 2001/11/22 06:21:07 xiphmont Exp $
********************************************************************/
@@ -59,10 +59,8 @@
long noisetrigger_request;
/* unfortunately, we need to hold queued packet data somewhere */
- unsigned char *packetdoublebuffer[2];
- unsigned char doublebufferhead[2];
- unsigned char doublebuffertail[2];
- oggpack_buffer *queue_packets;
+ oggpack_buffer *queue_packet_buffers;
+ ogg_packet *queue_packets;
} bitrate_manager_state;
@@ -74,6 +72,7 @@
double absolute_max_long;
double queue_avg_time;
+ double queue_avg_center;
double queue_minmax_time;
double queue_hardmin;
double queue_hardmax;
@@ -94,7 +93,9 @@
extern void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bs);
extern void vorbis_bitrate_clear(bitrate_manager_state *bs);
+extern int vorbis_bitrate_managed(vorbis_block *vb);
+extern int vorbis_bitrate_maxmarkers(void);
extern int vorbis_bitrate_addblock(vorbis_block *vb);
-extern int vorbis_bitrate_flushpacket(vorbis_block *vb, vorbis_packet *op);
+extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd, ogg_packet *op);
#endif
1.50.2.6 +13 -4 vorbis/lib/block.c
Index: block.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/block.c,v
retrieving revision 1.50.2.5
retrieving revision 1.50.2.6
diff -u -r1.50.2.5 -r1.50.2.6
--- block.c 2001/11/16 08:17:05 1.50.2.5
+++ block.c 2001/11/22 06:21:07 1.50.2.6
@@ -11,7 +11,7 @@
********************************************************************
function: PCM data vector blocking, windowing and dis/reassembly
- last mod: $Id: block.c,v 1.50.2.5 2001/11/16 08:17:05 xiphmont Exp $
+ last mod: $Id: block.c,v 1.50.2.6 2001/11/22 06:21:07 xiphmont Exp $
Handle windowing, overlap-add, etc of the PCM vectors. This is made
more amusing by Vorbis' current two allowed block sizes.
@@ -90,9 +90,12 @@
vb->localalloc=0;
vb->localstore=NULL;
if(v->analysisp){
+ vorbis_block_internal *vbi=
+ vb->internal=_ogg_calloc(1,sizeof(vorbis_block_internal));
oggpack_writeinit(&vb->opb);
- vb->internal=_ogg_calloc(1,sizeof(vorbis_block_internal));
- ((vorbis_block_internal *)vb->internal)->ampmax=-9999;
+ vbi->ampmax=-9999;
+ vbi->packet_markers=_ogg_malloc(vorbis_bitrate_maxmarkers()*
+ sizeof(*vbi->packet_markers));
}
return(0);
@@ -150,7 +153,13 @@
oggpack_writeclear(&vb->opb);
_vorbis_block_ripcord(vb);
if(vb->localstore)_ogg_free(vb->localstore);
- if(vb->internal)_ogg_free(vb->internal);
+
+ if(vb->internal){
+ vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
+ if(vbi->packet_markers)_ogg_free(vbi->packet_markers);
+
+ _ogg_free(vb->internal);
+ }
memset(vb,0,sizeof(*vb));
return(0);
1.30.2.1 +2 -2 vorbis/lib/codebook.c
Index: codebook.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/codebook.c,v
retrieving revision 1.30
retrieving revision 1.30.2.1
diff -u -r1.30 -r1.30.2.1
--- codebook.c 2001/10/02 00:14:30 1.30
+++ codebook.c 2001/11/22 06:21:07 1.30.2.1
@@ -11,7 +11,7 @@
********************************************************************
function: basic codebook pack/unpack/code/decode operations
- last mod: $Id: codebook.c,v 1.30 2001/10/02 00:14:30 segher Exp $
+ last mod: $Id: codebook.c,v 1.30.2.1 2001/11/22 06:21:07 xiphmont Exp $
********************************************************************/
@@ -418,7 +418,7 @@
long vorbis_book_decodevv_add(codebook *book,float **a,long offset,int ch,
oggpack_buffer *b,int n){
- long i,j,k,entry;
+ long i,j,entry;
int chptr=0;
for(i=offset/ch;i<(offset+n)/ch;){
1.9.4.6 +4 -2 vorbis/lib/codec_internal.h
Index: codec_internal.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/codec_internal.h,v
retrieving revision 1.9.4.5
retrieving revision 1.9.4.6
diff -u -r1.9.4.5 -r1.9.4.6
--- codec_internal.h 2001/11/16 08:17:06 1.9.4.5
+++ codec_internal.h 2001/11/22 06:21:07 1.9.4.6
@@ -10,7 +10,7 @@
********************************************************************
function: libvorbis codec headers
- last mod: $Id: codec_internal.h,v 1.9.4.5 2001/11/16 08:17:06 xiphmont Exp $
+ last mod: $Id: codec_internal.h,v 1.9.4.6 2001/11/22 06:21:07 xiphmont Exp $
********************************************************************/
@@ -23,6 +23,8 @@
typedef struct vorbis_block_internal{
float **pcmdelay; /* this is a pointer into local storage */
float ampmax;
+
+ ogg_uint32_t *packet_markers;
} vorbis_block_internal;
typedef void vorbis_look_time;
@@ -45,7 +47,7 @@
typedef void vorbis_info_mapping;
#include "psy.h"
-#inclide "bitrate.h"
+#include "bitrate.h"
typedef struct backend_lookup_state {
/* local lookup storage */
1.46.2.1 +1 -2 vorbis/lib/floor0.c
Index: floor0.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/floor0.c,v
retrieving revision 1.46
retrieving revision 1.46.2.1
diff -u -r1.46 -r1.46.2.1
--- floor0.c 2001/10/02 00:14:30 1.46
+++ floor0.c 2001/11/22 06:21:07 1.46.2.1
@@ -11,7 +11,7 @@
********************************************************************
function: floor backend 0 implementation
- last mod: $Id: floor0.c,v 1.46 2001/10/02 00:14:30 segher Exp $
+ last mod: $Id: floor0.c,v 1.46.2.1 2001/11/22 06:21:07 xiphmont Exp $
********************************************************************/
@@ -266,7 +266,6 @@
vorbis_look_floor0 *look=(vorbis_look_floor0 *)in;
vorbis_info_floor0 *info=look->vi;
float amp;
- long bits=0;
long val=0;
static int seq=0;
1.16.2.1 +1 -2 vorbis/lib/floor1.c
Index: floor1.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/floor1.c,v
retrieving revision 1.16
retrieving revision 1.16.2.1
diff -u -r1.16 -r1.16.2.1
--- floor1.c 2001/10/02 00:14:31 1.16
+++ floor1.c 2001/11/22 06:21:08 1.16.2.1
@@ -11,7 +11,7 @@
********************************************************************
function: floor backend 1 implementation
- last mod: $Id: floor1.c,v 1.16 2001/10/02 00:14:31 segher Exp $
+ last mod: $Id: floor1.c,v 1.16.2.1 2001/11/22 06:21:08 xiphmont Exp $
********************************************************************/
@@ -1025,7 +1025,6 @@
vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
vorbis_info_floor1 *info=look->vi;
- codec_setup_info *ci=vb->vd->vi->codec_setup;
int i,j,k;
codebook *books=((backend_lookup_state *)(vb->vd->backend_state))->
fullbooks;
1.37.2.8 +18 -291 vorbis/lib/mapping0.c
Index: mapping0.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/mapping0.c,v
retrieving revision 1.37.2.7
retrieving revision 1.37.2.8
diff -u -r1.37.2.7 -r1.37.2.8
--- mapping0.c 2001/11/16 08:17:05 1.37.2.7
+++ mapping0.c 2001/11/22 06:21:08 1.37.2.8
@@ -11,7 +11,7 @@
********************************************************************
function: channel mapping 0 implementation
- last mod: $Id: mapping0.c,v 1.37.2.7 2001/11/16 08:17:05 xiphmont Exp $
+ last mod: $Id: mapping0.c,v 1.37.2.8 2001/11/22 06:21:08 xiphmont Exp $
********************************************************************/
@@ -287,7 +287,9 @@
vorbis_dsp_state *vd=vb->vd;
vorbis_info *vi=vd->vi;
codec_setup_info *ci=vi->codec_setup;
+ bitrate_manager_info *bi=ci->bi;
backend_lookup_state *b=vb->vd->backend_state;
+ bitrate_manager_state *bm=&b->bms;
vorbis_look_mapping0 *look=(vorbis_look_mapping0 *)l;
vorbis_info_mapping0 *info=look->map;
vorbis_info_mode *mode=look->mode;
@@ -392,7 +394,7 @@
global_ampmax,
local_ampmax[i],
ci->blocksizes[vb->lW]/2,
- b->bitrate_avgnoise);
+ bm->avgnoise);
_analysis_output("mask",seq+i,logmask,n/2,1,0);
/* perform floor encoding */
@@ -464,11 +466,10 @@
int *chbundle=alloca(sizeof(*chbundle)*info->submaps);
int chcounter=0;
- long maxbits,minbits;
+ long minbits;
/* play a little loose with this abstraction */
int quant_passes=ci->coupling_passes;
- int stopflag=0,stoppos=0;
for(i=0;i<vi->channels;i++){
quantized[i]=_vorbis_block_alloc(vb,n*sizeof(*sofar[i]));
@@ -532,129 +533,29 @@
class(vb,look->residue_look[i],pcmbundle[i],zerobundle[i],chbundle[i]);
}
- /* basic bitrate fitting algorithm:
- determine a current-packet maximum size from the bound queue and
- point maximums
- determine a current-packet minimum size from the bound queue and
- point minimums
- determine a desired packet size:
- if there's a requested average, get that from the floater
- else, use the bits sunk by a single iteration (bounded by min/max)
- */
- {
- long maxbits_absolute=
- (vb->W?
- (ci->bitrate_absolute_max_long>0?
- ci->bitrate_absolute_max_long/vi->rate*ci->blocksizes[1]/2:-1):
- (ci->bitrate_absolute_max_short>0?
- ci->bitrate_absolute_max_short/vi->rate*ci->blocksizes[0]/2:-1));
- long minbits_absolute=
- (vb->W?
- (ci->bitrate_absolute_min_long>0?
- ci->bitrate_absolute_min_long/vi->rate*ci->blocksizes[1]/2:-1):
- (ci->bitrate_absolute_min_short>0?
- ci->bitrate_absolute_min_short/vi->rate*ci->blocksizes[0]/2:-1));
-
- long minbits_period=ci->bitrate_queue_hardmin/vi->rate*
- (b->bitrate_queue_sampleacc[0]+ci->blocksizes[vb->W]/2)-
- b->bitrate_queue_bitacc[0];
-
- long period_samples=max(ci->bitrate_queue_time*vi->rate,
- b->bitrate_queue_sampleacc[0]);
- long maxbits_period=-1;
-
- maxbits=-1;
- minbits=-1;
-
- /* pessimistic checkahead */
- for(i=0;i<8;i++){
- long ahead_samples=period_samples-b->bitrate_queue_sampleacc[i];
- if(ahead_samples>=0){
- long maxbits_local=ci->bitrate_queue_hardmax/vi->rate*
- (period_samples+ci->blocksizes[vb->W]/2)-
- b->bitrate_queue_bitacc[i]-
- ci->bitrate_queue_hardmax/vi->rate*ahead_samples;
-
- if(maxbits_period==-1 || maxbits_local<maxbits_period)
- maxbits_period=maxbits_local;
-
- }
- }
-
+ /* this is the only good place to enforce minimum by-packet bitrate */
+ if(vb->W)
+ minbits=bi->absolute_min_long/vi->rate*ci->blocksizes[1]/2;
+ else
+ minbits=bi->absolute_min_short/vi->rate*ci->blocksizes[0]/2;
- fprintf(stderr,"maxbits_a %ld maxbit_period %ld\n",maxbits_absolute,maxbits_period);
+ /* actual encoding loop; we pack all the iterations to collect
+ management data */
- if(maxbits_absolute>=0.){
- if(maxbits_period>=0.){
- maxbits=min(maxbits_period,maxbits_absolute);
- }else{
- maxbits=maxbits_absolute;
- }
- }else
- if(maxbits_period>=0)maxbits=maxbits_period;
- minbits=max(minbits_period,minbits_absolute);
-
- if(maxbits>=0)minbits=min(minbits,maxbits);
- }
-
- /* actual encoding loop; if we have a desired stopping point, pack
- slightly past it so that the end of the packet is not
- uninitialized data that could pollute the decoded audio on the
- decode side. We want to truncate at a clean byte boundary.
-
- If we're doing an average bitrate, we need to encode to the
- bitter end then truncate (so that we can collect bit usage
- statistics for floater adjustment) */
- for(i=0;!stopflag;){
+ for(i=0;i<quant_passes;){
/* perform residue encoding of this pass's quantized residue
vector, according residue mapping */
for(j=0;j<info->submaps;j++){
- ogg_uint32_t *queueptr=b->bitrate_queue_binned;
- if(queueptr)queueptr+=b->bitrate_queue_head*b->bitrate_bins;
-
- if(stoppos){
- look->residue_func[j]->
- forward(vb,look->residue_look[j],
- qbundle[j],sobundle[j],zerobundle[j],chbundle[j],
- i,classifications[j],b->bitrate_avgfloat,queueptr);
-
- }else{
- stoppos=look->residue_func[j]->
- forward(vb,look->residue_look[j],
- qbundle[j],sobundle[j],zerobundle[j],chbundle[j],
- i,classifications[j],b->bitrate_avgfloat,queueptr);
- }
+ look->residue_func[j]->
+ forward(vb,look->residue_look[j],
+ qbundle[j],sobundle[j],zerobundle[j],chbundle[j],
+ i,classifications[j],vbi->packet_markers);
+
}
i++;
-
- /* bitrate management.... deciding when it's time to stop. */
- if(i<quant_passes){
- if(b->bitrate_bins==0){ /* average bitrate always runs
- encode to the bitter end in
- order to collect statistics */
-
- long current_bytes=oggpack_bits(&vb->opb)/8;
-
- if(maxbits>=0 && current_bytes>maxbits/8){
- /* maxbits trumps all... */
- stoppos=maxbits/8;
- stopflag=1;
- }else{
- if(current_bytes>(minbits+7)/8){
- if(ci->passlimit[i-1]>=b->bitrate_avgfloat){
- if(!stoppos)stoppos=current_bytes;
- if(stoppos<current_bytes)
- stopflag=1;
- }
- }
- }
- }
- }else
- stopflag=1;
-
/* down-couple/down-quantize from perfect-'so-far' ->
new quantized vector */
if(info->coupling_steps==0){
@@ -684,182 +585,8 @@
_analysis_output(buf,seq+j,quantized[j],n/2,1,0);
}
-
- /* steady as she goes */
}
-
- /* truncate the packet according to stoppos */
- if(!stoppos)stoppos=oggpack_bytes(&vb->opb);
- if(minbits>=0 && stoppos*8<minbits)stoppos=(minbits+7)/8;
- if(maxbits>=0 && stoppos*8>maxbits)stoppos=maxbits/8;
- if(stoppos>oggpack_bytes(&vb->opb))stoppos=oggpack_bytes(&vb->opb);
- vb->opb.endbyte=stoppos;
- vb->opb.endbit=0;
-
seq+=vi->channels;
-
- fprintf(stderr,"Bitrate: cav %d, cmin %ld, cmax %ld, float %.1f,"
- " this %ld\n",
- (int)((double)b->bitrate_queue_bitacc[0]*vi->rate/b->bitrate_queue_sampleacc[0]),
- minbits,maxbits,b->bitrate_avgfloat,
- oggpack_bytes(&vb->opb)*8);
-
- /* track bitrate*/
- /* update boundary accumulators */
- for(i=0;i<8;i++){
- long desired=ci->bitrate_queue_time*vi->rate;
- switch(i){
- case 0:
- break;
- case 1:
- desired-=ci->blocksizes[0]/2;
- break;
- case 2:
- desired-=ci->blocksizes[0]*2;
- break;
- case 3:
- desired-=ci->blocksizes[0]*8;
- break;
- case 4:
- desired-=ci->bitrate_queue_time*vi->rate*(1./16.);
- break;
- case 5:
- desired-=ci->bitrate_queue_time*vi->rate*(1./8.);
- break;
- case 6:
- desired-=ci->bitrate_queue_time*vi->rate*(1./4.);
- break;
- case 7:
- desired-=ci->bitrate_queue_time*vi->rate*(1./2.);
- break;
- }
-
- while(b->bitrate_queue_sampleacc[i]>desired){
- int samples=ci->blocksizes[0]>>1;
- if(b->bitrate_queue_actual[b->bitrate_queue_tail[i]]&0x80000000UL)
- samples=ci->blocksizes[1]>>1;
- b->bitrate_queue_sampleacc[i]-=samples;
- b->bitrate_queue_bitacc[i]-=
- b->bitrate_queue_actual[b->bitrate_queue_tail[i]]&0x7fffffffUL;
-
- /* update moving average accumulators */
- if(i==0){
- for(j=0;j<b->bitrate_bins;j++)
- b->bitrate_queue_binacc[j]-=
- b->bitrate_queue_binned[b->bitrate_queue_tail[0]*b->bitrate_bins+j];
-
- /* watch the running noise offset trigger */
- if(b->bitrate_noisetrigger_postpone)--b->bitrate_noisetrigger_postpone;
- }
-
- b->bitrate_queue_tail[i]++;
- if(b->bitrate_queue_tail[i]>=b->bitrate_queue_size)
- b->bitrate_queue_tail[i]=0;
-
- }
- }
-
- /* update queue head */
- if(oggpack_bytes(&vb->opb)>2){
-
- int bits=oggpack_bytes(&vb->opb)*8;
-
- /* boundaries */
- b->bitrate_queue_actual[b->bitrate_queue_head]=bits;
- if(vb->W)b->bitrate_queue_actual[b->bitrate_queue_head]|=0x80000000UL;
- for(i=0;i<8;i++){
- b->bitrate_queue_bitacc[i]+=bits;
- b->bitrate_queue_sampleacc[i]+=ci->blocksizes[vb->W]>>1;
- }
-
- /* bins */
- if(b->bitrate_bins){
- for(i=0;i<b->bitrate_bins;i++)
- b->bitrate_queue_binacc[i]+=
- b->bitrate_queue_binned[b->bitrate_queue_head*b->bitrate_bins+i];
- }
-
- b->bitrate_queue_head++;
- if(b->bitrate_queue_head>=b->bitrate_queue_size)b->bitrate_queue_head=0;
-
- }
-
- /* adjust the floater to offset bitrate above/below desired average */
- /* look for the bin settings in recent history that bracket
- the desired bitrate, and interpolate twixt them for the
- flaoter setting we want */
-
- if(b->bitrate_bins>0 &&
- (b->bitrate_queue_sampleacc[0]>ci->bitrate_queue_time*vi->rate/8 ||
- b->bitrate_queue_sampleacc[0]>8192 || b->bitrate_queue_head>16)){
-
- double upper=floater_interpolate(b,vi,ci->bitrate_queue_avgmax);
- double lower=floater_interpolate(b,vi,ci->bitrate_queue_avgmin);
- double new=ci->bitrate_avgfloat_initial;
- double slew;
-
- if(upper>0. && upper<new)new=upper;
- if(lower<ci->bitrate_avgfloat_minimum)
- lower=ci->bitrate_avgfloat_minimum;
- if(lower>new)new=lower;
-
- slew=new-b->bitrate_avgfloat;
-
- if(slew<ci->bitrate_avgfloat_downhyst || slew>ci->bitrate_avgfloat_uphyst){
- if(slew<ci->bitrate_avgfloat_downslew_max)
- new=b->bitrate_avgfloat+ci->bitrate_avgfloat_downslew_max;
- if(slew>ci->bitrate_avgfloat_upslew_max)
- new=b->bitrate_avgfloat+ci->bitrate_avgfloat_upslew_max;
-
- b->bitrate_avgfloat=new;
- }
-
- {
- long queueusage=b->bitrate_queue_head;
- if(b->bitrate_queue_tail[0]>b->bitrate_queue_head)
- queueusage+=b->bitrate_queue_size;
- queueusage-=b->bitrate_queue_tail[0];
-
- if(b->bitrate_avgfloat<ci->bitrate_avgfloat_noisetrigger_low)
- b->bitrate_noisetrigger_request+=1.f;
-
- if(b->bitrate_avgfloat>ci->bitrate_avgfloat_noisetrigger_high)
- b->bitrate_noisetrigger_request-=1.f;
-
- if(b->bitrate_noisetrigger_postpone==0){
- if(b->bitrate_noisetrigger_request<0.){
- b->bitrate_avgnoise-=1.f;
- if(b->bitrate_noisetrigger_request<10.)
- b->bitrate_avgnoise-=1.f;
- b->bitrate_noisetrigger_postpone=queueusage;
- }
- if(b->bitrate_noisetrigger_request>0.){
- b->bitrate_avgnoise+=1.f;
- if(b->bitrate_noisetrigger_request>10.)
- b->bitrate_avgnoise+=1.f;
- b->bitrate_noisetrigger_postpone=queueusage;
- }
-
- b->bitrate_noisetrigger_request=0.f;
- if(b->bitrate_avgnoise>0)
- b->bitrate_noisetrigger_request= -1.;
- if(b->bitrate_avgnoise<0)
- b->bitrate_noisetrigger_request= +1.;
-
- if(b->bitrate_avgnoise<ci->bitrate_avgfloat_noisetrigger_minoff)
- b->bitrate_avgnoise=ci->bitrate_avgfloat_noisetrigger_minoff;
- if(b->bitrate_avgnoise>ci->bitrate_avgfloat_noisetrigger_maxoff)
- b->bitrate_avgnoise=ci->bitrate_avgfloat_noisetrigger_maxoff;
- }
- }
-
- fprintf(stderr,"\tupper:%g :: lower:%g (noise offset=%g, pending=%d, trigger=%d)\n",
- upper,lower,b->bitrate_avgnoise,b->bitrate_noisetrigger_request,
- b->bitrate_noisetrigger_postpone);
-
-
-
- }
}
1.37.2.7 +34 -40 vorbis/lib/res0.c
Index: res0.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/res0.c,v
retrieving revision 1.37.2.6
retrieving revision 1.37.2.7
diff -u -r1.37.2.6 -r1.37.2.7
--- res0.c 2001/10/22 09:09:29 1.37.2.6
+++ res0.c 2001/11/22 06:21:08 1.37.2.7
@@ -11,7 +11,7 @@
********************************************************************
function: residue backend 0, 1 and 2 implementation
- last mod: $Id: res0.c,v 1.37.2.6 2001/10/22 09:09:29 xiphmont Exp $
+ last mod: $Id: res0.c,v 1.37.2.7 2001/11/22 06:21:08 xiphmont Exp $
********************************************************************/
@@ -49,7 +49,7 @@
long phrasebits;
long frames;
- int qoffsets[BITTRACK_DIVISOR];
+ int qoffsets[BITTRACK_DIVISOR+1];
} vorbis_look_residue0;
@@ -245,6 +245,8 @@
for(i=0;i<BITTRACK_DIVISOR;i++)
look->qoffsets[i]=partvals*(i+1)/BITTRACK_DIVISOR;
+
+ look->qoffsets[i]=9999999;
}
return(look);
@@ -467,7 +469,7 @@
int pass,long **partword,
int (*encode)(oggpack_buffer *,float *,int,
codebook *,vorbis_look_residue0 *),
- double passlimit,ogg_uint32_t *stats){
+ ogg_uint32_t *stats){
long i,j,k,s;
vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
vorbis_info_residue0 *info=look->info;
@@ -487,10 +489,6 @@
long resbits[128];
long resvals[128];
- long wholepasses;
- long partialpass;
- int stoppos=0;
-
#ifdef TRAIN_RES
FILE *of;
char buffer[80];
@@ -511,9 +509,6 @@
}
#endif
- wholepasses=passlimit;
- partialpass=(passlimit-wholepasses)*partvals;
-
memset(resbits,0,sizeof(resbits));
memset(resvals,0,sizeof(resvals));
@@ -529,11 +524,6 @@
for(i=0;i<partvals;){
- if(!stoppos &&
- s>=wholepasses &&
- i>=partialpass)
- stoppos=oggpack_bytes(&vb->opb);
-
/* first we encode a partition codeword for each channel */
if(s==0){
for(j=0;j<ch;j++){
@@ -559,12 +549,10 @@
/* now we encode interleaved residual values for the partitions */
for(k=0;k<partitions_per_word && i<partvals;k++,i++){
long offset=i*samples_per_partition+info->begin;
-
- if(!stoppos &&
- s>=wholepasses &&
- i>=partialpass)
- stoppos=oggpack_bytes(&vb->opb);
+ if(qptr)while(i>=look->qoffsets[bin])
+ qptr[bin++]=oggpack_bits(&vb->opb);
+
for(j=0;j<ch;j++){
if(s==0)resvals[partword[j][i]]+=samples_per_partition;
if(info->secondstages[partword[j][i]]&(1<<s)){
@@ -572,20 +560,14 @@
if(statebook){
int ret=encode(&vb->opb,in[j]+offset,samples_per_partition,
statebook,look);
- if(!stoppos){
- look->postbits+=ret;
- resbits[partword[j][i]]+=ret;
- }
+ look->postbits+=ret;
+ resbits[partword[j][i]]+=ret;
}
}
}
-
- if(qptr)while(i>=look->qoffsets[bin])
- qptr[bin++]=oggpack_bits(&vb->opb);
-
-
-
}
+ if(qptr)while(i>=look->qoffsets[bin])
+ qptr[bin++]=oggpack_bits(&vb->opb);
}
}
@@ -601,7 +583,7 @@
fprintf(stderr,":: %ld:%1.2g\n",total,(double)totalbits/total);
}*/
- return(stoppos);
+ return(0);
}
/* a truncated packet here just means 'stop working'; it's not an error */
@@ -679,7 +661,7 @@
int res0_forward(vorbis_block *vb,vorbis_look_residue *vl,
float **in,float **out,int *nonzero,int ch,
- int pass, long **partword,double passlimit,ogg_uint32_t *stats){
+ int pass, long **partword,ogg_uint32_t *stats){
/* we encode only the nonzero parts of a bundle */
int i,j,used=0,n=vb->pcmend/2;
for(i=0;i<ch;i++)
@@ -690,7 +672,7 @@
}
if(used){
int ret=_01forward(vb,vl,in,used,pass,partword,
- _interleaved_encodepart,passlimit,stats);
+ _interleaved_encodepart,stats);
used=0;
for(i=0;i<ch;i++)
if(nonzero[i]){
@@ -699,8 +681,12 @@
used++;
}
return(ret);
- }else
+ }else{
+ for(i=0;i<vorbis_bitrate_maxmarkers();i++)
+ stats[i]=oggpack_bits(&vb->opb);
+
return(0);
+ }
}
int res0_inverse(vorbis_block *vb,vorbis_look_residue *vl,
@@ -717,7 +703,7 @@
int res1_forward(vorbis_block *vb,vorbis_look_residue *vl,
float **in,float **out,int *nonzero,int ch,
- int pass, long **partword, double passlimit,ogg_uint32_t *stats){
+ int pass, long **partword, ogg_uint32_t *stats){
int i,j,used=0,n=vb->pcmend/2;
for(i=0;i<ch;i++)
if(nonzero[i]){
@@ -727,7 +713,7 @@
}
if(used){
- int ret=_01forward(vb,vl,in,used,pass,partword,_encodepart,passlimit,stats);
+ int ret=_01forward(vb,vl,in,used,pass,partword,_encodepart,stats);
used=0;
for(i=0;i<ch;i++)
if(nonzero[i]){
@@ -736,8 +722,12 @@
used++;
}
return(ret);
- }else
+ }else{
+ for(i=0;i<vorbis_bitrate_maxmarkers();i++)
+ stats[i]=oggpack_bits(&vb->opb);
+
return(0);
+ }
}
long **res1_class(vorbis_block *vb,vorbis_look_residue *vl,
@@ -781,7 +771,7 @@
int res2_forward(vorbis_block *vb,vorbis_look_residue *vl,
float **in,float **out,int *nonzero,int ch,
- int pass,long **partword,double passlimit, ogg_uint32_t *stats){
+ int pass,long **partword,ogg_uint32_t *stats){
long i,j,k,n=vb->pcmend/2,used=0;
/* don't duplicate the code; use a working vector hack for now and
@@ -796,7 +786,7 @@
}
if(used){
- int ret=_01forward(vb,vl,&work,1,pass,partword,_encodepart,passlimit,stats);
+ int ret=_01forward(vb,vl,&work,1,pass,partword,_encodepart,stats);
/* update the sofar vector */
for(i=0;i<ch;i++){
float *pcm=in[i];
@@ -810,8 +800,12 @@
#endif
}
return(ret);
- }else
+ }else{
+ for(i=0;i<vorbis_bitrate_maxmarkers();i++)
+ stats[i]=oggpack_bits(&vb->opb);
+
return(0);
+ }
}
/* duplicate code here as speed is somewhat more important */
No revision
No revision
1.4.2.9 +15 -9 vorbis/lib/modes/mode_44c_A.h
Index: mode_44c_A.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/modes/mode_44c_A.h,v
retrieving revision 1.4.2.8
retrieving revision 1.4.2.9
diff -u -r1.4.2.8 -r1.4.2.9
--- mode_44c_A.h 2001/10/22 07:34:22 1.4.2.8
+++ mode_44c_A.h 2001/11/22 06:21:11 1.4.2.9
@@ -11,7 +11,7 @@
********************************************************************
function: predefined encoding modes; 44kHz stereo ~64kbps true VBR
- last mod: $Id: mode_44c_A.h,v 1.4.2.8 2001/10/22 07:34:22 xiphmont Exp $
+ last mod: $Id: mode_44c_A.h,v 1.4.2.9 2001/11/22 06:21:11 xiphmont Exp $
********************************************************************/
@@ -80,6 +80,19 @@
#include "maskadj_A.h"
+static bitrate_manager_info _bm_set_44c_A={
+ /* progressive coding and bitrate controls */
+ 110000,90000, -1,-1,
+ 2.,.5,
+ 1., 112000, 140000,
+ 124000, 128000,
+
+ 4.0, 0., -1., .05,
+ -.05, .05,
+ 3.0,5.0,
+ -10.f,+4.f
+};
+
static vorbis_info_psy_global _psy_set_44c_AG={
0, /* decaydBpms */
8, /* lines per eighth octave */
@@ -377,14 +390,7 @@
/* psy */
{&_psy_set_44c_A0,&_psy_set_44c_AT,&_psy_set_44c_A},
&_psy_set_44c_AG,
-
- /* progressive coding and bitrate controls */
- 110000,90000, 0,0,
- 3., 112000, 140000,
- 124000, 128000,
-
- 4.0, 0., -1., .05,
- -.05, .05,
+ &_bm_set_44c_A,
{3,4,6,8},
4,
--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the commits
mailing list