[vorbis-dev] minor psy.c modifications

Attila Padar galileog at externet.hu
Thu Feb 1 18:10:11 PST 2001



Hello!
Some minor bugfixes...
source: psy.c
function: _vp_psy_init

1. '-' or '+' in this line?
maxoc=toOC((n*.5f  - .25f)*rate/n)*(1<<(p->shiftoc+1))+.5f;
maxoc=toOC((n*.5f  + .25f)*rate/n)*(1<<(p->shiftoc+1))+.5f;

2. I know: sizeof(float *) and sizeof(float) are 4 bytes long, but...
old lines:
p->noisemedian=_ogg_malloc(n*sizeof(float *));
p->noiseoffset=_ogg_malloc(n*sizeof(float *));
p->tonecurves[i]=_ogg_malloc(P_LEVELS*sizeof(float *));

new (corrected) lines:
p->noisemedian=_ogg_malloc(n*sizeof(float));
p->noiseoffset=_ogg_malloc(n*sizeof(float));
p->tonecurves[i]=_ogg_malloc(P_LEVELS*sizeof(float));

3. modified bark_noise_median():
3/a: floating point based (new) style:

#define BIN(x)   ((int)((x)*negFour))
#define BINdB(x) ((x)*negQuarter)
#define BINCOUNT (200*4)
#define LASTBIN  (BINCOUNT-1)

tatic void bark_noise_median(long n,float *b,
                                         float *f,float *noise,
                                         float lowidth,float hiwidth,
                                         int lomin,int himin,
                                         float *thresh,float *off){
 long i,lo=0,hi=0;
 long median=LASTBIN;
 float bi,threshi;
 float negFour    = -4.0f;
 float negQuarter = -0.25f;

 float radix[BINCOUNT];
 float countabove=0.f;
 float countbelow=0.f;

 memset(radix,0,sizeof(radix));

 for(i=0;i<n;i++){
  // find new lo/hi
  bi=b[i]+hiwidth;
  for(;hi<n && (hi<i+himin || b[hi]<=bi);hi++){
   int bin=BIN(f[hi]);
   if(bin>LASTBIN)
    bin=LASTBIN;
   if(bin<0)
    bin=0;
   radix[bin]++;
   if(bin<median)
    countabove++;
   else
    countbelow++;
  }
  bi=b[i]-lowidth;
  for(;lo<i && lo+lomin<i && b[lo]<=bi;lo++){
   int bin=BIN(f[lo]);
   if(bin>LASTBIN)
    bin=LASTBIN;
   if(bin<0)
    bin=0;
   radix[bin]--;
   if(bin<median)
    countabove--;
   else
    countbelow--;
  }
  // move the median if needed
  if(countabove+countbelow){
   threshi = (countabove+countbelow)*thresh[i];
   while(median>0 && threshi>countbelow){
    median--;
    countabove - =radix[median];
    countbelow + =radix[median];
   }
   while(median<LASTBIN && threshi<(countbelow-radix[median])){
    countbelow   =countbelow-radix[median];
    countabove + =radix[median];
    median++;
   }
  }
  noise[i]=BINdB(median)+off[i];
 }
}

3/b: integer based (old) style:

#define BNM_RES  4
#define BIN(x)   ((int)((x)*negMul))
#define BINdB(x) ((float)(x)*negDiv)
#define BINCOUNT (200*BNM_RES)
#define LASTBIN  (BINCOUNT-1)
static void bark_noise_median(long n,float *b,
                                               float *f,float *noise,
                                               float lowidth,float hiwidth,
                                               int lomin,int himin,
                                               float *thresh,float *off){
 long radix[BINCOUNT];
 long median=LASTBIN;
 long i,lo=0,hi=0,countabove=0,countbelow=0;
 const float negMul= -((float)BNM_RES);
 const float negDiv= 1.f/negMul;

 memset(radix,0,sizeof(radix));

 for(i=0;i<n;i++){
  {
   // find new lo/hi
   const float bih=b[i]+hiwidth;
   for(;hi<n && ((hi<i+himin) || (b[hi]<=bih));hi++){
    int bin=BIN(f[hi]);
    if(bin>LASTBIN)
     bin=LASTBIN;
    if(bin<0)
     bin=0;
    if(bin<median)
     countabove++;
    else
     countbelow++;
    radix[bin]++;
   }
  }
  {
   const float bil=b[i]-lowidth;
   for(;(lo<i) && (lo+lomin<i) && (b[lo]<=bil);lo++){
    int bin=BIN(f[lo]);
    if(bin>LASTBIN)
     bin=LASTBIN;
    if(bin<0)
     bin=0;
    if(bin<median)
     countabove--;
    else
     countbelow--;
    radix[bin]--;
   }
  }
   // move the median if needed
  if(countabove+countbelow){
   const float threshicc=(float)(countabove+countbelow)*thresh[i];
   long *radixp=&radix[median],cora;
   while((median>0) && (threshicc>(float)countbelow)){
    median--;
    radixp--;
    countabove - =*radixp;
    countbelow + =*radixp;
   }
   while((median<LASTBIN)
       && (threshicc<(float)(cora=countbelow-*radixp))){
    countbelow   =cora;
    countabove + =*radixp;
    median++;
    radixp++;
   }
  }
  noise[i]=BINdB(median)+off[i];
 }
}

that's all
regards
Attila Padar

--- >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 'vorbis-dev-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 Vorbis-dev mailing list