mirror of
https://github.com/claunia/flac.git
synced 2025-12-16 18:54:26 +00:00
replaygain_synthesis.c : Replace an int64_t/int32_t operation with a shift.
Patch-from: lvqcl <lvqcl.mail@gmail.com>
This commit is contained in:
@@ -294,41 +294,6 @@ static FLAC__int64 dither_output_(DitherContext *d, FLAC__bool do_dithering, int
|
|||||||
|
|
||||||
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[], unsigned wide_samples, unsigned channels, const unsigned source_bps, const unsigned target_bps, const double scale, const FLAC__bool hard_limit, FLAC__bool do_dithering, DitherContext *dither_context)
|
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[], unsigned wide_samples, unsigned channels, const unsigned source_bps, const unsigned target_bps, const double scale, const FLAC__bool hard_limit, FLAC__bool do_dithering, DitherContext *dither_context)
|
||||||
{
|
{
|
||||||
static const FLAC__int32 conv_factors_[33] = {
|
|
||||||
-1, /* 0 bits-per-sample (not supported) */
|
|
||||||
-1, /* 1 bits-per-sample (not supported) */
|
|
||||||
-1, /* 2 bits-per-sample (not supported) */
|
|
||||||
-1, /* 3 bits-per-sample (not supported) */
|
|
||||||
268435456, /* 4 bits-per-sample */
|
|
||||||
134217728, /* 5 bits-per-sample */
|
|
||||||
67108864, /* 6 bits-per-sample */
|
|
||||||
33554432, /* 7 bits-per-sample */
|
|
||||||
16777216, /* 8 bits-per-sample */
|
|
||||||
8388608, /* 9 bits-per-sample */
|
|
||||||
4194304, /* 10 bits-per-sample */
|
|
||||||
2097152, /* 11 bits-per-sample */
|
|
||||||
1048576, /* 12 bits-per-sample */
|
|
||||||
524288, /* 13 bits-per-sample */
|
|
||||||
262144, /* 14 bits-per-sample */
|
|
||||||
131072, /* 15 bits-per-sample */
|
|
||||||
65536, /* 16 bits-per-sample */
|
|
||||||
32768, /* 17 bits-per-sample */
|
|
||||||
16384, /* 18 bits-per-sample */
|
|
||||||
8192, /* 19 bits-per-sample */
|
|
||||||
4096, /* 20 bits-per-sample */
|
|
||||||
2048, /* 21 bits-per-sample */
|
|
||||||
1024, /* 22 bits-per-sample */
|
|
||||||
512, /* 23 bits-per-sample */
|
|
||||||
256, /* 24 bits-per-sample */
|
|
||||||
128, /* 25 bits-per-sample */
|
|
||||||
64, /* 26 bits-per-sample */
|
|
||||||
32, /* 27 bits-per-sample */
|
|
||||||
16, /* 28 bits-per-sample */
|
|
||||||
8, /* 29 bits-per-sample */
|
|
||||||
4, /* 30 bits-per-sample */
|
|
||||||
2, /* 31 bits-per-sample */
|
|
||||||
1 /* 32 bits-per-sample */
|
|
||||||
};
|
|
||||||
static const FLAC__int64 hard_clip_factors_[33] = {
|
static const FLAC__int64 hard_clip_factors_[33] = {
|
||||||
0, /* 0 bits-per-sample (not supported) */
|
0, /* 0 bits-per-sample (not supported) */
|
||||||
0, /* 1 bits-per-sample (not supported) */
|
0, /* 1 bits-per-sample (not supported) */
|
||||||
@@ -364,7 +329,7 @@ size_t FLAC__replaygain_synthesis__apply_gain(FLAC__byte *data_out, FLAC__bool l
|
|||||||
-1073741824, /* 31 bits-per-sample */
|
-1073741824, /* 31 bits-per-sample */
|
||||||
(FLAC__int64)(-1073741824) * 2 /* 32 bits-per-sample */
|
(FLAC__int64)(-1073741824) * 2 /* 32 bits-per-sample */
|
||||||
};
|
};
|
||||||
const FLAC__int32 conv_factor = conv_factors_[target_bps];
|
const FLAC__int32 conv_shift = 32 - target_bps;
|
||||||
const FLAC__int64 hard_clip_factor = hard_clip_factors_[target_bps];
|
const FLAC__int64 hard_clip_factor = hard_clip_factors_[target_bps];
|
||||||
/*
|
/*
|
||||||
* The integer input coming in has a varying range based on the
|
* The integer input coming in has a varying range based on the
|
||||||
@@ -409,7 +374,7 @@ size_t FLAC__replaygain_synthesis__apply_gain(FLAC__byte *data_out, FLAC__bool l
|
|||||||
}
|
}
|
||||||
sample *= 2147483647.;
|
sample *= 2147483647.;
|
||||||
|
|
||||||
val64 = dither_output_(dither_context, do_dithering, noise_shaping, (i + last_history_index) % 32, sample, channel) / conv_factor;
|
val64 = dither_output_(dither_context, do_dithering, noise_shaping, (i + last_history_index) % 32, sample, channel) >> conv_shift;
|
||||||
|
|
||||||
val32 = (FLAC__int32)val64;
|
val32 = (FLAC__int32)val64;
|
||||||
if(val64 >= -hard_clip_factor)
|
if(val64 >= -hard_clip_factor)
|
||||||
|
|||||||
Reference in New Issue
Block a user