~ubuntu-branches/ubuntu/hardy/avidemux/hardy

« back to all changes in this revision

Viewing changes to avidemux/libtoolame/ath.c

  • Committer: Bazaar Package Importer
  • Author(s): Matvey Kozhev
  • Date: 2007-12-18 13:53:04 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20071218135304-cdqec2lg2bglyz15
Tags: 1:2.4~preview3-0.0ubuntu1
* Upload to Ubuntu. (LP: #163287, LP: #126572)
* debian/changelog: re-added Ubuntu releases.
* debian/control:
  - Require debhelper >= 5.0.51 (for dh_icons) and imagemagick.
  - Build-depend on libsdl1.2-dev instead of libsdl-dev.
  - Build against newer libx264-dev. (LP: #138854)
  - Removed libamrnb-dev, not in Ubuntu yet.
* debian/rules:
  - Install all icon sizes, using convert (upstream installs none).
  - Added missing calls to dh_installmenu, dh_installman, dh_icons and
    dh_desktop.
* debian/menu, debian/avidemux-qt.menu:
  - Corrected package and executable names.
* debian/avidemux-common.install: Install icons.
* debian/avidemux.common.manpages: Install man/avidemux.1.
* debian/links, debian/avidemux-cli.links, debian/avidemux-gtk.links:
  - Link manpages to avidemux.1.gz.
* debian/install, debian/avidemux-qt.install, debian/avidemux-gtk.desktop,
  debian/avidemux-qt.desktop: Install desktop files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  TwoLAME: an optimized MPEG Audio Layer Two encoder
3
 
 *
4
 
 *  Copyright (C) 2001-2004 Michael Cheng
5
 
 *  Copyright (C) 2004-2005 The TwoLAME Project
6
 
 *
7
 
 *  This library is free software; you can redistribute it and/or
8
 
 *  modify it under the terms of the GNU Lesser General Public
9
 
 *  License as published by the Free Software Foundation; either
10
 
 *  version 2.1 of the License, or (at your option) any later version.
11
 
 *
12
 
 *  This library is distributed in the hope that it will be useful,
13
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 
 *  Lesser General Public License for more details.
16
 
 *
17
 
 *  You should have received a copy of the GNU Lesser General Public
18
 
 *  License along with this library; if not, write to the Free Software
19
 
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
 
 *  
21
 
 */
22
 
 
23
 
 
24
 
#include <stdio.h>
25
 
#include <math.h>
26
 
 
27
 
#include "twolame.h"
28
 
#include "common.h"
29
 
#include "ath.h"
30
 
 
31
 
 
32
 
/* freq in hz */
33
 
FLOAT ath_db(FLOAT f, FLOAT value)
34
 
{
35
 
  /* from Painter & Spanias
36
 
    modified by Gabriel Bouvigne to better fit the reality
37
 
  ath =    3.640 * pow(f,-0.8)
38
 
         - 6.800 * exp(-0.6*pow(f-3.4,2.0))
39
 
         + 6.000 * exp(-0.15*pow(f-8.7,2.0))
40
 
         + 0.6* 0.001 * pow(f,4.0);
41
 
 
42
 
 
43
 
  In the past LAME was using the Painter &Spanias formula.
44
 
  But we had some recurrent problems with HF content.
45
 
  We measured real ATH values, and found the older formula
46
 
  to be inacurate in the higher part. So we made this new
47
 
  formula and this solved most of HF problematic testcases.
48
 
  The tradeoff is that in VBR mode it increases a lot the
49
 
  bitrate.*/
50
 
 
51
 
 
52
 
/*this curve can be udjusted according to the VBR scale:
53
 
it adjusts from something close to Painter & Spanias
54
 
on V9 up to Bouvigne's formula for V0. This way the VBR
55
 
bitrate is more balanced according to the -V value.*/
56
 
 
57
 
  FLOAT ath;
58
 
  FLOAT valueold = 0.0;
59
 
 
60
 
  if (f < -.3)
61
 
      f=3410;
62
 
 
63
 
  f /= 1000;  // convert to khz
64
 
  f  = MAX(0.01, f);
65
 
  f  = MIN(18.0, f);
66
 
 
67
 
  ath =    3.640 * pow(f,-0.8)
68
 
         - 6.800 * exp(-0.6*pow(f-3.4,2.0))
69
 
         + 6.000 * exp(-0.15*pow(f-8.7,2.0))
70
 
         + (0.6+0.04*valueold)* 0.001 * pow(f,4.0);
71
 
 
72
 
  /* MFC Feb 2003
73
 
     I've changed the fudge technique on the code.
74
 
     The "-l [float]" value raises/lowers the ATH by this many dB */
75
 
  return (ath + value);
76
 
}
77
 
 
78
 
 
79
 
/* Convert ATH values from dB into energy values as required by the psycho model */
80
 
FLOAT ath_energy(FLOAT freq, FLOAT value) {
81
 
  FLOAT db;
82
 
  db = ath_db(freq, 0) + value; // Originally: ath_db(freq,value)
83
 
  /* The values in the standard, and from the ATH formula are in dB.
84
 
     In the psycho model we are working in the energy domain. Hence the values that 
85
 
     are in the absthr_X tables are not in dB. This function converts from dB into the energy domain.
86
 
     As noted on the LAME mailing list from years ago (MFC FIX find the reference), the 
87
 
     absolute threhsold of hearing values in the tables in the standard are dodgy - the
88
 
     ATH in the tables do not correspond to any previously known values of the ATH. 
89
 
     From ISO 11172 Tables D.4.x
90
 
       "A value of 0dB represents a level in the absolute threshold calculation of
91
 
        96dB below the energy of a sine wave of amplitude 32760."
92
 
     But I still don't know why the factor of 41.837375 is the value that it is. MFC Feb 2003 */
93
 
  return(pow(10.0, (db+41.837375)*0.1));
94
 
}
95
 
 
96
 
 
97
 
/* Convert a frequency (in Hz) to a bark value
98
 
   Taken from LAME. MFC Feb 2003 
99
 
   see for example "Zwicker: Psychoakustik, 1982; ISBN 3-540-11401-7 */
100
 
FLOAT ath_freq2bark(FLOAT freq)
101
 
{
102
 
    if (freq<0) freq=0;
103
 
    freq = freq * 0.001;
104
 
    return 13.0*atan(.76*freq) + 3.5*atan(freq*freq/(7.5*7.5));
105
 
}