aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2015-09-07 18:44:07 +0000
committertrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2015-09-07 18:44:07 +0000
commitef146b6de5258408ced5418e4e9967a431b0c33b (patch)
treecaf60ac92c129b85a24b3fb73a60ec309099f65d
parentb04ba619ee3d3138d8d26d0e9516dd7352f16bad (diff)
downloadqmmp-ef146b6de5258408ced5418e4e9967a431b0c33b.tar.gz
qmmp-ef146b6de5258408ced5418e4e9967a431b0c33b.tar.bz2
qmmp-ef146b6de5258408ced5418e4e9967a431b0c33b.zip
fixed audio clicks while playing some mp3 files (#806)
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@5550 90c681e8-e032-0410-971d-27865f9a5e38
-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);
};