I have been thinking about the ATH bug and finally found the reason and
a workaround. Let me explain it... But if you can't understand my poor
english, please find out what I want to explain from the source code
patch... :-)

calc_noise calculates the avarage noise of each frequency band.
And the ATH is the threshold of one actual frequency, not the band.
I think this difference is the reason that sometimes the ATH makes
problem.

example)

noise
 |   
 |   |   ^  |
9|***|***^**|******* <-ATH
 |   |   ^  |
 |   |   ^  |
-+------------------
0|  f0  fn  f1
     band A

If the amplitude of noise for f = fn exceeds ATH, we can hear the
distortion. But LAME will divide the noise with band width |f0-f1|,
to obtain the average and LAME will compare it to the ATH to see if
it is distorted or not.

If the input wave has peaky spectrum like a sine wave, 
it could be happen that the noise for f=fn exceeds the ATH but
the average noise of band A(which contains f=fn) does not exceed it.
when such a situation, LAME will fail to determine if it is distorted
or not.



Workaround:

Supposing the worst case, we should divide ATH with the band width,
like the patch below (this is patch for lame3.54).

*** lame3.54/quantize.c Tue Nov  9 09:23:50 1999
--- lame3.54+ath/quantize.c     Mon Nov 15 21:56:53 1999
***************
*** 235,241 ****
      end   = scalefac_band_long[ sfb+1 ];
      ATH_l[sfb]=1e99;
      for (i=start ; i < end; i++) {
!       ATH_f = ATHformula(samp_freq*i/(2*576)); /* freq in kHz */
        ATH_l[sfb]=Min(ATH_l[sfb],ATH_f);
      }
      /*
--- 235,241 ----
      end   = scalefac_band_long[ sfb+1 ];
      ATH_l[sfb]=1e99;
      for (i=start ; i < end; i++) {
!       ATH_f = ATHformula(samp_freq*i/(2*576))/(end-start); /* freq in kHz */
        ATH_l[sfb]=Min(ATH_l[sfb],ATH_f);
      }
      /*
***************
*** 251,257 ****
      end   = scalefac_band_short[ sfb+1 ];
      ATH_s[sfb]=1e99;
      for (i=start ; i < end; i++) {
!       ATH_f = ATHformula(samp_freq*i/(2*192));     /* freq in kHz */
        ATH_s[sfb]=Min(ATH_s[sfb],ATH_f);
      }
    }
--- 251,257 ----
      end   = scalefac_band_short[ sfb+1 ];
      ATH_s[sfb]=1e99;
      for (i=start ; i < end; i++) {
!       ATH_f = ATHformula(samp_freq*i/(2*192))/(end-start);  /* freq in kHz */
        ATH_s[sfb]=Min(ATH_s[sfb],ATH_f);
      }
    }


---
Takehiro TOMINAGA // may the source be with you !
--
MP3 ENCODER mailing list ( http://geek.rcc.se/mp3encoder/ )

Reply via email to