Blame libmp3lame/gain_analysis.h

Packit 47f805
/*
Packit 47f805
 *  ReplayGainAnalysis - analyzes input samples and give the recommended dB change
Packit 47f805
 *  Copyright (C) 2001 David Robinson and Glen Sawyer
Packit 47f805
 *
Packit 47f805
 *  This library is free software; you can redistribute it and/or
Packit 47f805
 *  modify it under the terms of the GNU Lesser General Public
Packit 47f805
 *  License as published by the Free Software Foundation; either
Packit 47f805
 *  version 2.1 of the License, or (at your option) any later version.
Packit 47f805
 *
Packit 47f805
 *  This library is distributed in the hope that it will be useful,
Packit 47f805
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 47f805
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 47f805
 *  Lesser General Public License for more details.
Packit 47f805
 *
Packit 47f805
 *  You should have received a copy of the GNU Lesser General Public
Packit 47f805
 *  License along with this library; if not, write to the Free Software
Packit 47f805
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
Packit 47f805
 *
Packit 47f805
 *  concept and filter values by David Robinson (David@Robinson.org)
Packit 47f805
 *    -- blame him if you think the idea is flawed
Packit 47f805
 *  coding by Glen Sawyer (mp3gain@hotmail.com) 735 W 255 N, Orem, UT 84057-4505 USA
Packit 47f805
 *    -- blame him if you think this runs too slowly, or the coding is otherwise flawed
Packit 47f805
 *
Packit 47f805
 *  For an explanation of the concepts and the basic algorithms involved, go to:
Packit 47f805
 *    http://www.replaygain.org/
Packit 47f805
 */
Packit 47f805
Packit 47f805
#ifndef GAIN_ANALYSIS_H
Packit 47f805
#define GAIN_ANALYSIS_H
Packit 47f805
Packit 47f805
#ifdef HAVE_INTTYPES_H
Packit 47f805
# include <inttypes.h>
Packit 47f805
#else
Packit 47f805
# ifdef HAVE_STDINT_H
Packit 47f805
#  include <stdint.h>
Packit 47f805
# endif
Packit 47f805
#endif
Packit 47f805
Packit 47f805
#ifdef __cplusplus
Packit 47f805
extern  "C" {
Packit 47f805
#endif
Packit 47f805
Packit 47f805
Packit 47f805
    typedef sample_t Float_t; /* Type used for filtering */
Packit 47f805
Packit 47f805
Packit 47f805
#define PINK_REF                64.82       /* 298640883795 */ /* calibration value for 89dB */
Packit 47f805
Packit 47f805
Packit 47f805
#define YULE_ORDER         10
Packit 47f805
#define BUTTER_ORDER        2
Packit 47f805
#define YULE_FILTER     filterYule
Packit 47f805
#define BUTTER_FILTER   filterButter
Packit 47f805
#define RMS_PERCENTILE      0.95 /* percentile which is louder than the proposed level */
Packit 47f805
#define MAX_SAMP_FREQ   48000L /* maximum allowed sample frequency [Hz] */
Packit 47f805
#define RMS_WINDOW_TIME_NUMERATOR    1L
Packit 47f805
#define RMS_WINDOW_TIME_DENOMINATOR 20L /* numerator / denominator = time slice size [s] */
Packit 47f805
#define STEPS_per_dB      100 /* Table entries per dB */
Packit 47f805
#define MAX_dB            120 /* Table entries for 0...MAX_dB (normal max. values are 70...80 dB) */
Packit 47f805
Packit 47f805
    enum { GAIN_NOT_ENOUGH_SAMPLES = -24601, GAIN_ANALYSIS_ERROR = 0, GAIN_ANALYSIS_OK =
Packit 47f805
            1, INIT_GAIN_ANALYSIS_ERROR = 0, INIT_GAIN_ANALYSIS_OK = 1
Packit 47f805
    };
Packit 47f805
Packit 47f805
    enum { MAX_ORDER = (BUTTER_ORDER > YULE_ORDER ? BUTTER_ORDER : YULE_ORDER)
Packit 47f805
            , MAX_SAMPLES_PER_WINDOW = ((MAX_SAMP_FREQ * RMS_WINDOW_TIME_NUMERATOR) / RMS_WINDOW_TIME_DENOMINATOR + 1) /* max. Samples per Time slice */
Packit 47f805
    };
Packit 47f805
Packit 47f805
    struct replaygain_data {
Packit 47f805
        Float_t linprebuf[MAX_ORDER * 2];
Packit 47f805
        Float_t *linpre;     /* left input samples, with pre-buffer */
Packit 47f805
        Float_t lstepbuf[MAX_SAMPLES_PER_WINDOW + MAX_ORDER];
Packit 47f805
        Float_t *lstep;      /* left "first step" (i.e. post first filter) samples */
Packit 47f805
        Float_t loutbuf[MAX_SAMPLES_PER_WINDOW + MAX_ORDER];
Packit 47f805
        Float_t *lout;       /* left "out" (i.e. post second filter) samples */
Packit 47f805
        Float_t rinprebuf[MAX_ORDER * 2];
Packit 47f805
        Float_t *rinpre;     /* right input samples ... */
Packit 47f805
        Float_t rstepbuf[MAX_SAMPLES_PER_WINDOW + MAX_ORDER];
Packit 47f805
        Float_t *rstep;
Packit 47f805
        Float_t routbuf[MAX_SAMPLES_PER_WINDOW + MAX_ORDER];
Packit 47f805
        Float_t *rout;
Packit 47f805
        long    sampleWindow; /* number of samples required to reach number of milliseconds required for RMS window */
Packit 47f805
        long    totsamp;
Packit 47f805
        double  lsum;
Packit 47f805
        double  rsum;
Packit 47f805
        int     freqindex;
Packit 47f805
        int     first;
Packit 47f805
        uint32_t A[STEPS_per_dB * MAX_dB];
Packit 47f805
        uint32_t B[STEPS_per_dB * MAX_dB];
Packit 47f805
Packit 47f805
    };
Packit 47f805
#ifndef replaygain_data_defined
Packit 47f805
#define replaygain_data_defined
Packit 47f805
    typedef struct replaygain_data replaygain_t;
Packit 47f805
#endif
Packit 47f805
Packit 47f805
Packit 47f805
Packit 47f805
Packit 47f805
    int     InitGainAnalysis(replaygain_t * rgData, long samplefreq);
Packit 47f805
    int     AnalyzeSamples(replaygain_t * rgData, const Float_t * left_samples,
Packit 47f805
                           const Float_t * right_samples, size_t num_samples, int num_channels);
Packit 47f805
    Float_t GetTitleGain(replaygain_t * rgData);
Packit 47f805
Packit 47f805
Packit 47f805
#ifdef __cplusplus
Packit 47f805
}
Packit 47f805
#endif
Packit 47f805
#endif                       /* GAIN_ANALYSIS_H */