Ejemplo n.º 1
0
/* the floor has already been filtered to only include relevant sections */
static int accumulate_fit(const float *flr,const float *mdct,
			  int x0, int x1,lsfit_acc *a,
			  int n,vorbis_info_floor1 *info){
  long i;
  int quantized=vorbis_dBquant(flr+x0);

  long xa=0,ya=0,x2a=0,y2a=0,xya=0,na=0, xb=0,yb=0,x2b=0,y2b=0,xyb=0,nb=0;

  memset(a,0,sizeof(*a));
  a->x0=x0;
  a->x1=x1;
  if(x1>=n)x1=n-1;

  for(i=x0;i<=x1;i++){
    int quantized=vorbis_dBquant(flr+i);
    if(quantized){
      if(mdct[i]+info->twofitatten>=flr[i]){
	xa  += i;
	ya  += quantized;
	x2a += i*i;
	y2a += quantized*quantized;
	xya += i*quantized;
	na++;
      }else{
	xb  += i;
	yb  += quantized;
	x2b += i*i;
	y2b += quantized*quantized;
	xyb += i*quantized;
	nb++;
      }
    }
  }

  xb+=xa;
  yb+=ya;
  x2b+=x2a;
  y2b+=y2a;
  xyb+=xya;
  nb+=na;

  /* weight toward the actually used frequencies if we meet the threshhold */
  {
    int weight=nb*info->twofitweight/(na+1);

    a->xa=xa*weight+xb;
    a->ya=ya*weight+yb;
    a->x2a=x2a*weight+x2b;
    a->y2a=y2a*weight+y2b;
    a->xya=xya*weight+xyb;
    a->an=na*weight+nb;
    a->n=nb;
  }

  return(na);
}
Ejemplo n.º 2
0
static int inspect_error(int x0,int x1,int y0,int y1,const float *mask,
			 const float *mdct,
			 vorbis_info_floor1 *info){
  int dy=y1-y0;
  int adx=x1-x0;
  int ady=abs(dy);
  int base=dy/adx;
  int sy=(dy<0?base-1:base+1);
  int x=x0;
  int y=y0;
  int err=0;
  int val=vorbis_dBquant(mask+x);
  int mse=0;
  int n=0;

  ady-=abs(base*adx);
  
  if(mdct[x]+info->twofitatten>=mask[x]){
    if(y+info->maxover<val)return(1);
    if(y-info->maxunder>val)return(1);
    mse=(y-val);
    mse*=mse;
    n++;
  }

  while(++x<x1){
    err=err+ady;
    if(err>=adx){
      err-=adx;
      y+=sy;
    }else{
      y+=base;
    }

    if(mdct[x]+info->twofitatten>=mask[x]){
      val=vorbis_dBquant(mask+x);
      if(val){
	if(y+info->maxover<val)return(1);
	if(y-info->maxunder>val)return(1);
	mse+=((y-val)*(y-val));
	n++;
      }
    }
  }
  
  if(n){
    if(info->maxover*info->maxover/n>info->maxerr)return(0);
    if(info->maxunder*info->maxunder/n>info->maxerr)return(0);
    if(mse/n>info->maxerr)return(1);
  }
  return(0);
}
Ejemplo n.º 3
0
/* the floor has already been filtered to only include relevant sections */
static int accumulate_fit(const float *flr,const float *mdct,
                          int x0, int x1,lsfit_acc *a,
                          int n,vorbis_info_floor1 *info) {
    long i;

    int xa=0,ya=0,x2a=0,y2a=0,xya=0,na=0, xb=0,yb=0,x2b=0,y2b=0,xyb=0,nb=0;

    memset(a,0,sizeof(*a));
    a->x0=x0;
    a->x1=x1;
    if(x1>=n)x1=n-1;

    for(i=x0; i<=x1; i++) {
        int quantized=vorbis_dBquant(flr+i);
        if(quantized) {
            if(mdct[i]+info->twofitatten>=flr[i]) {
                xa  += i;
                ya  += quantized;
                x2a += i*i;
                y2a += quantized*quantized;
                xya += i*quantized;
                na++;
            } else {
                xb  += i;
                yb  += quantized;
                x2b += i*i;
                y2b += quantized*quantized;
                xyb += i*quantized;
                nb++;
            }
        }
    }

    a->xa=xa;
    a->ya=ya;
    a->x2a=x2a;
    a->y2a=y2a;
    a->xya=xya;
    a->an=na;

    a->xb=xb;
    a->yb=yb;
    a->x2b=x2b;
    a->y2b=y2b;
    a->xyb=xyb;
    a->bn=nb;

    return(na);
}
Ejemplo n.º 4
0
/* the floor has already been filtered to only include relevant sections */
static int accumulate_fit(const float *flr,const float *mdct,
			  int x0, int x1,lsfit_acc *a,
			  int n,vorbis_info_floor1 *info){
  long i;
  int quantized=vorbis_dBquant(flr);

  long xa=0,ya=0,x2a=0,y2a=0,xya=0,na=0, xb=0,yb=0,x2b=0,y2b=0,xyb=0,nb=0;

  memset(a,0,sizeof(lsfit_acc));
  a->x0=x0;
  a->x1=x1;
  a->edgey0=quantized;
  if(x1>n)x1=n;

  for(i=x0;i<x1;i++){
    int quantized=vorbis_dBquant(flr+i);
    if(quantized){
      if(mdct[i]+info->twofitatten>=flr[i]){
	xa  += i;
	ya  += quantized;
	x2a += i*i;
	y2a += quantized*quantized;
	xya += i*quantized;
	na++;
      }else{
	xb  += i;
	yb  += quantized;
	x2b += i*i;
	y2b += quantized*quantized;
	xyb += i*quantized;
	nb++;
      }
    }
  }

  xb+=xa;
  yb+=ya;
  x2b+=x2a;
  y2b+=y2a;
  xyb+=xya;
  nb+=na;

  /* weight toward the actually used frequencies if we meet the threshhold */
  {
    int weight;
    if(nb<info->twofitminsize || na<info->twofitminused){
      weight=0;
    }else{
      weight=nb*info->twofitweight/na;
    }
    a->xa=xa*weight+xb;
    a->ya=ya*weight+yb;
    a->x2a=x2a*weight+x2b;
    a->y2a=y2a*weight+y2b;
    a->xya=xya*weight+xyb;
    a->an=na*weight+nb;
    a->n=nb;
    a->un=na;
    if(nb>=info->unusedminsize)a->un++;
  }

  a->edgey1=-200;
  if(x1<n){
    int quantized=vorbis_dBquant(flr+i);
    a->edgey1=quantized;
  }
  return(a->n);
}