xref: /aosp_15_r20/external/flac/include/share/replaygain_synthesis.h (revision 600f14f40d737144c998e2ec7a483122d3776fbc)
1*600f14f4SXin Li /* replaygain_synthesis - Routines for applying ReplayGain to a signal
2*600f14f4SXin Li  * Copyright (C) 2002-2009  Josh Coalson
3*600f14f4SXin Li  * Copyright (C) 2011-2023  Xiph.Org Foundation
4*600f14f4SXin Li  *
5*600f14f4SXin Li  * This library is free software; you can redistribute it and/or
6*600f14f4SXin Li  * modify it under the terms of the GNU Lesser General Public
7*600f14f4SXin Li  * License as published by the Free Software Foundation; either
8*600f14f4SXin Li  * version 2.1 of the License, or (at your option) any later version.
9*600f14f4SXin Li  *
10*600f14f4SXin Li  * This library is distributed in the hope that it will be useful,
11*600f14f4SXin Li  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12*600f14f4SXin Li  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13*600f14f4SXin Li  * Lesser General Public License for more details.
14*600f14f4SXin Li  *
15*600f14f4SXin Li  * You should have received a copy of the GNU Lesser General Public
16*600f14f4SXin Li  * License along with this library; if not, write to the Free Software
17*600f14f4SXin Li  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18*600f14f4SXin Li  */
19*600f14f4SXin Li 
20*600f14f4SXin Li #ifndef FLAC__SHARE__REPLAYGAIN_SYNTHESIS_H
21*600f14f4SXin Li #define FLAC__SHARE__REPLAYGAIN_SYNTHESIS_H
22*600f14f4SXin Li 
23*600f14f4SXin Li #include <stdlib.h> /* for size_t */
24*600f14f4SXin Li #include "FLAC/format.h"
25*600f14f4SXin Li 
26*600f14f4SXin Li #define FLAC_SHARE__MAX_SUPPORTED_CHANNELS FLAC__MAX_CHANNELS
27*600f14f4SXin Li 
28*600f14f4SXin Li typedef enum {
29*600f14f4SXin Li 	NOISE_SHAPING_NONE = 0,
30*600f14f4SXin Li 	NOISE_SHAPING_LOW = 1,
31*600f14f4SXin Li 	NOISE_SHAPING_MEDIUM = 2,
32*600f14f4SXin Li 	NOISE_SHAPING_HIGH = 3
33*600f14f4SXin Li } NoiseShaping;
34*600f14f4SXin Li 
35*600f14f4SXin Li typedef struct {
36*600f14f4SXin Li 	const float*  FilterCoeff;
37*600f14f4SXin Li 	FLAC__uint64  Mask;
38*600f14f4SXin Li 	double        Add;
39*600f14f4SXin Li 	float         Dither;
40*600f14f4SXin Li 	float         ErrorHistory     [FLAC_SHARE__MAX_SUPPORTED_CHANNELS] [16];  /* 16th order Noise shaping */
41*600f14f4SXin Li 	float         DitherHistory    [FLAC_SHARE__MAX_SUPPORTED_CHANNELS] [16];
42*600f14f4SXin Li 	int           LastRandomNumber [FLAC_SHARE__MAX_SUPPORTED_CHANNELS];
43*600f14f4SXin Li 	unsigned      LastHistoryIndex;
44*600f14f4SXin Li 	NoiseShaping  ShapingType;
45*600f14f4SXin Li } DitherContext;
46*600f14f4SXin Li 
47*600f14f4SXin Li void FLAC__replaygain_synthesis__init_dither_context(DitherContext *dither, int bits, int shapingtype);
48*600f14f4SXin Li 
49*600f14f4SXin Li /* scale = (float) pow(10., (double)replaygain * 0.05); */
50*600f14f4SXin Li size_t FLAC__replaygain_synthesis__apply_gain(FLAC__byte *data_out, FLAC__bool little_endian_data_out, FLAC__bool unsigned_data_out, const FLAC__int32 * const input[], uint32_t wide_samples, uint32_t channels, const uint32_t source_bps, const uint32_t target_bps, const double scale, const FLAC__bool hard_limit, FLAC__bool do_dithering, DitherContext *dither_context);
51*600f14f4SXin Li 
52*600f14f4SXin Li #endif
53