• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavcodec/aacpsy.c

Go to the documentation of this file.
00001 /*
00002  * AAC encoder psychoacoustic model
00003  * Copyright (C) 2008 Konstantin Shishkov
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00027 #include "avcodec.h"
00028 #include "aacpsy.h"
00029 #include "aactab.h"
00030 
00031 /***********************************
00032  *              TODOs:
00033  * General:
00034  * better audio preprocessing (add DC highpass filter?)
00035  * more psy models
00036  * maybe improve coefficient quantization function in some way
00037  *
00038  * 3GPP-based psy model:
00039  * thresholds linearization after their modifications for attaining given bitrate
00040  * try other bitrate controlling mechanism (maybe use ratecontrol.c?)
00041  * control quality for quality-based output
00042  **********************************/
00043 
00049 static av_always_inline int quant(float coef, const float Q)
00050 {
00051     return av_clip((int)(pow(fabsf(coef) * Q, 0.75) + 0.4054), 0, 8191);
00052 }
00053 
00054 static inline float get_approximate_quant_error(float *c, int size, int scale_idx)
00055 {
00056     int i;
00057     int q;
00058     float coef, unquant, sum = 0.0f;
00059     const float Q  = ff_aac_pow2sf_tab[200 - scale_idx + SCALE_ONE_POS - SCALE_DIV_512];
00060     const float IQ = ff_aac_pow2sf_tab[200 + scale_idx - SCALE_ONE_POS + SCALE_DIV_512];
00061     for(i = 0; i < size; i++){
00062         coef = fabs(c[i]);
00063         q = quant(c[i], Q);
00064         unquant = (q * cbrt(q)) * IQ;
00065         sum += (coef - unquant) * (coef - unquant);
00066     }
00067     return sum;
00068 }
00069 
00074 #define PSY_3GPP_SPREAD_LOW  1.5f // spreading factor for ascending threshold spreading  (15 dB/Bark)
00075 #define PSY_3GPP_SPREAD_HI   3.0f // spreading factor for descending threshold spreading (30 dB/Bark)
00076 
00083 typedef struct Psy3gppBand{
00084     float energy;    
00085     float ffac;      
00086 }Psy3gppBand;
00087 
00091 typedef struct Psy3gppCoeffs{
00092     float ath       [64]; 
00093     float barks     [64]; 
00094     float spread_low[64]; 
00095     float spread_hi [64]; 
00096 }Psy3gppCoeffs;
00097 
00101 static inline float calc_bark(float f)
00102 {
00103     return 13.3f * atanf(0.00076f * f) + 3.5f * atanf((f / 7500.0f) * (f / 7500.0f));
00104 }

Generated on Sat Feb 16 2013 09:23:11 for ffmpeg by  doxygen 1.7.1