gain_analysis.h

Go to the documentation of this file.
00001 /*
00002  *  ReplayGainAnalysis - analyzes input samples and give the recommended dB change
00003  *  Copyright (C) 2001 David Robinson and Glen Sawyer
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Lesser General Public
00007  *  License as published by the Free Software Foundation; either
00008  *  version 2.1 of the License, or (at your option) any later version.
00009  *
00010  *  This library is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *  Lesser General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU Lesser General Public
00016  *  License along with this library; if not, write to the Free Software
00017  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  *
00019  *  concept and filter values by David Robinson (David@Robinson.org)
00020  *    -- blame him if you think the idea is flawed
00021  *  coding by Glen Sawyer (mp3gain@hotmail.com) 735 W 255 N, Orem, UT 84057-4505 USA
00022  *    -- blame him if you think this runs too slowly, or the coding is otherwise flawed
00023  *
00024  *  For an explanation of the concepts and the basic algorithms involved, go to:
00025  *    http://www.replaygain.org/
00026  */
00027 
00028 #ifndef GAIN_ANALYSIS_H
00029 #define GAIN_ANALYSIS_H
00030 
00031 #ifdef HAVE_INTTYPES_H
00032 # include <inttypes.h>
00033 #else
00034 # ifdef HAVE_STDINT_H
00035 #  include <stdint.h>
00036 # endif
00037 #endif
00038 
00039 #ifdef __cplusplus
00040 extern  "C" {
00041 #endif
00042 
00043 
00044     typedef sample_t Float_t; /* Type used for filtering */
00045 
00046 
00047 #define PINK_REF                64.82       /* 298640883795 */ /* calibration value for 89dB */
00048 
00049 
00050 #define YULE_ORDER         10
00051 #define BUTTER_ORDER        2
00052 #define YULE_FILTER     filterYule
00053 #define BUTTER_FILTER   filterButter
00054 #define RMS_PERCENTILE      0.95 /* percentile which is louder than the proposed level */
00055 #define MAX_SAMP_FREQ   48000L /* maximum allowed sample frequency [Hz] */
00056 #define RMS_WINDOW_TIME_NUMERATOR    1L
00057 #define RMS_WINDOW_TIME_DENOMINATOR 20L /* numerator / denominator = time slice size [s] */
00058 #define STEPS_per_dB      100. /* Table entries per dB */
00059 #define MAX_dB            120. /* Table entries for 0...MAX_dB (normal max. values are 70...80 dB) */
00060 
00061     enum { GAIN_NOT_ENOUGH_SAMPLES = -24601, GAIN_ANALYSIS_ERROR = 0, GAIN_ANALYSIS_OK =
00062             1, INIT_GAIN_ANALYSIS_ERROR = 0, INIT_GAIN_ANALYSIS_OK = 1
00063     };
00064 
00065     enum { MAX_ORDER = (BUTTER_ORDER > YULE_ORDER ? BUTTER_ORDER : YULE_ORDER)
00066             , MAX_SAMPLES_PER_WINDOW = ((MAX_SAMP_FREQ * RMS_WINDOW_TIME_NUMERATOR) / RMS_WINDOW_TIME_DENOMINATOR + 1) /* max. Samples per Time slice */
00067     };
00068 
00069     struct replaygain_data {
00070         Float_t linprebuf[MAX_ORDER * 2];
00071         Float_t *linpre;     /* left input samples, with pre-buffer */
00072         Float_t lstepbuf[MAX_SAMPLES_PER_WINDOW + MAX_ORDER];
00073         Float_t *lstep;      /* left "first step" (i.e. post first filter) samples */
00074         Float_t loutbuf[MAX_SAMPLES_PER_WINDOW + MAX_ORDER];
00075         Float_t *lout;       /* left "out" (i.e. post second filter) samples */
00076         Float_t rinprebuf[MAX_ORDER * 2];
00077         Float_t *rinpre;     /* right input samples ... */
00078         Float_t rstepbuf[MAX_SAMPLES_PER_WINDOW + MAX_ORDER];
00079         Float_t *rstep;
00080         Float_t routbuf[MAX_SAMPLES_PER_WINDOW + MAX_ORDER];
00081         Float_t *rout;
00082         long    sampleWindow; /* number of samples required to reach number of milliseconds required for RMS window */
00083         long    totsamp;
00084         double  lsum;
00085         double  rsum;
00086         int     freqindex;
00087         int     first;
00088         uint32_t A[(size_t) (STEPS_per_dB * MAX_dB)];
00089         uint32_t B[(size_t) (STEPS_per_dB * MAX_dB)];
00090 
00091     };
00092 #ifndef replaygain_data_defined
00093 #define replaygain_data_defined
00094     typedef struct replaygain_data replaygain_t;
00095 #endif
00096 
00097 
00098 
00099 
00100     int     InitGainAnalysis(replaygain_t * rgData, long samplefreq);
00101     int     AnalyzeSamples(replaygain_t * rgData, const Float_t * left_samples,
00102                            const Float_t * right_samples, size_t num_samples, int num_channels);
00103     int     ResetSampleFrequency(replaygain_t * rgData, long samplefreq);
00104     Float_t GetTitleGain(replaygain_t * rgData);
00105     Float_t GetAlbumGain(replaygain_t * rgData);
00106 
00107 
00108 #ifdef __cplusplus
00109 }
00110 #endif
00111 #endif                       /* GAIN_ANALYSIS_H */

Generated on Sun Dec 2 11:34:19 2007 for LAME by  doxygen 1.5.2