aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/Input/mad
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/Input/mad')
-rw-r--r--src/plugins/Input/mad/decoder_mad.cpp35
-rw-r--r--src/plugins/Input/mad/decoder_mad.h7
2 files changed, 24 insertions, 18 deletions
diff --git a/src/plugins/Input/mad/decoder_mad.cpp b/src/plugins/Input/mad/decoder_mad.cpp
index 08b2486fb..820e37ea1 100644
--- a/src/plugins/Input/mad/decoder_mad.cpp
+++ b/src/plugins/Input/mad/decoder_mad.cpp
@@ -418,21 +418,6 @@ unsigned long DecoderMAD::prng(unsigned long state) // 32-bit pseudo-random numb
return (state * 0x0019660dL + 0x3c6ef35fL) & 0xffffffffL;
}
-// gather signal statistics while clipping
-void DecoderMAD::clip(mad_fixed_t *sample)
-{
- enum
- {
- MIN = -MAD_F_ONE,
- MAX = MAD_F_ONE - 1
- };
-
- if (*sample > MAX)
- *sample = MAX;
- else if (*sample < MIN)
- *sample = MIN;
-}
-
long DecoderMAD::audio_linear_dither(unsigned int bits, mad_fixed_t sample,
struct audio_dither *dither)
{
@@ -458,7 +443,20 @@ long DecoderMAD::audio_linear_dither(unsigned int bits, mad_fixed_t sample,
dither->random = random;
/* clip */
- clip(&output);
+ if (output > CLIP_MAX)
+ {
+ output = CLIP_MAX;
+
+ if (sample > CLIP_MAX)
+ sample = CLIP_MAX;
+ }
+ else if (output < CLIP_MIN)
+ {
+ output = CLIP_MIN;
+
+ if (sample < CLIP_MIN)
+ sample = CLIP_MIN;
+ }
/* quantize */
output &= ~mask;
@@ -477,7 +475,10 @@ long DecoderMAD::audio_linear_round(unsigned int bits, mad_fixed_t sample)
sample += (1L << (MAD_F_FRACBITS - bits));
/* clip */
- clip(&sample);
+ if (sample > CLIP_MAX)
+ sample = CLIP_MAX;
+ else if (sample < CLIP_MIN)
+ sample = CLIP_MIN;
/* quantize and scale */
return sample >> (MAD_F_FRACBITS + 1 - bits);
diff --git a/src/plugins/Input/mad/decoder_mad.h b/src/plugins/Input/mad/decoder_mad.h
index d15508848..2e91ed334 100644
--- a/src/plugins/Input/mad/decoder_mad.h
+++ b/src/plugins/Input/mad/decoder_mad.h
@@ -99,9 +99,14 @@ private:
struct mad_synth m_synth;
struct audio_dither m_left_dither, m_right_dither;
+ enum
+ {
+ CLIP_MIN = -MAD_F_ONE,
+ CLIP_MAX = MAD_F_ONE - 1
+ };
+
//converter functions
unsigned long prng(unsigned long state);
- void clip(mad_fixed_t *sample);
long audio_linear_dither(unsigned int bits, mad_fixed_t sample, struct audio_dither *dither);
long audio_linear_round(unsigned int bits, mad_fixed_t sample);
};