예제 #1
0
파일: ath.c 프로젝트: penghui2103/P36
/* Convert ATH values from dB into energy values as required by the psycho model */
float ATH_energy(float freq, float value) {
  float db;
  db = ATH_dB(freq, 0) + value; // Originally: ATH_dB(freq,value)
  /* The values in the standard, and from the ATH formula are in dB.
     In the psycho model we are working in the energy domain. Hence the values that 
     are in the absthr_X tables are not in dB. This function converts from dB into the energy domain.
     As noted on the LAME mailing list from years ago (MFC FIX find the reference), the 
     absolute threhsold of hearing values in the tables in the standard are dodgy - the
     ATH in the tables do not correspond to any previously known values of the ATH. 
     From ISO 11172 Tables D.4.x
       "A value of 0dB represents a level in the absolute threshold calculation of
        96dB below the energy of a sine wave of amplitude 32760."
     But I still don't know why the factor of 41.837375 is the value that it is. MFC Feb 2003 */
  return(pow(10.0, (db+41.837375)*0.1));
}
예제 #2
0
void psycho_3_init(options *glopts) {
  int i;
  int cbase = 0; /* current base index for the bark range calculation */

  fft_buf = (D1408 *) mem_alloc ((long) sizeof (D1408) * 2, "fft_buf");
  
  /* Initialise the tables for the adding dB */
  psycho_3_init_add_db();
  
  /* For each spectral line calculate the bark and the ATH (in dB) */
  FLOAT sfreq = (FLOAT) s_freq[header->version][header->sampling_frequency] * 1000;
  for (i=1;i<HBLKSIZE; i++) {
    FLOAT freq = i * sfreq/BLKSIZE;
    bark[i] = toolame_freq2bark(freq);
    ath[i] = ATH_dB(freq,glopts->athlevel);
  }
  
  { /* Work out the critical bands
       Starting from line 0, all lines within 1 bark of the starting
       bark are added to the same critical band. When a line is greater
       by 1.0 of a bark, start a new critical band.  */
    
    numlines = (int *)calloc(HBLKSIZE, sizeof(int));
    cbval = (float *)calloc(HBLKSIZE, sizeof(float));
    cbandindex[0] = 1;
    for (i=1;i<HBLKSIZE;i++) {
      if ((bark[i] - bark[cbase]) > 1.0) { /* 1 critical band? 1 bark? */
	/* this frequency line is too different from the starting line,
	   (in terms of the bark distance)
	   so make this spectral line the first member of the next critical band */
	cbase = i; /* Start the new critical band from this frequency line */
	cbands++;
	cbandindex[cbands] = cbase;
      } 
      /* partition[i] tells us which critical band the i'th frequency line is in */
      partition[i] = cbands;
      /* keep a count of how many frequency lines are in each partition */
      numlines[cbands]++;
    }
    
    cbands++;
    cbandindex[cbands] = 513; /* Set the top of the last critical band */

    /* For each crtical band calculate the average bark value 
       cbval [central bark value] */
    for (i=1;i<HBLKSIZE;i++) 
      cbval[partition[i]] += bark[i]; /* sum up all the bark values */
    for (i=1;i<CBANDS;i++) {
      if (numlines[i] != 0)
	cbval[i] /= numlines[i]; /* divide by the number of values */
      else {
	cbval[i]=0; /* this isn't a partition */
      }
    }     
  }
  
  {
    /* For Step6 - For the calculation of individual masking thresholds
       the spectral lines are subsampled 
       i.e. no need to work out the masking for every single spectral line.
       Depending upon which subband the calculation is for, you
       can skip a number of lines 
       There are 16 lines per subband -> 32 * 16 = 512 
       Subband 0-2 : Every line        (3 * 16 = 48 lines)
       Subband 3-5 : Every Second line (3 * 16/2 = 24 lines)
       Subband 6-11 : Every 4th line   (6 * 16/4 = 24 lines)
       Subband 12-31 : Every 12th line (20 * 16/8 = 40 lines) 
       
       create this subset of frequencies (freq_subset) */
    int freq_index=0;
    for (i=1;i<(3*16)+1;i++) 
      freq_subset[freq_index++] = i;
    for (;i<(6*16)+1;i+=2)
      freq_subset[freq_index++] = i;
    for (;i<(12*16)+1;i+=4)
      freq_subset[freq_index++] = i;
    for (;i<(32*16)+1;i+=8)
      freq_subset[freq_index++] = i;
  }

  if (glopts->verbosity > 4) {
    fprintf(stdout,"%i critical bands\n",cbands);
    for (i=0;i<cbands;i++)
      fprintf(stdout,"cband %i spectral line index %i\n",i,cbandindex[i]);
    fprintf(stdout,"%i Subsampled spectral lines\n",SUBSIZE);
    for (i=0;i<SUBSIZE;i++) 
      fprintf(stdout,"%i Spectral line %i Bark %.2f\n",i,freq_subset[i], bark[freq_subset[i]]);
  }
}