From 3b23cf0258e4225d094e10d16fcdc95b10d49d84 Mon Sep 17 00:00:00 2001 From: Marcin Jurkowski Date: Sun, 29 Oct 2017 00:59:27 +0200 Subject: [PATCH] decoder/vorbis: scale and clip tremor-decoded samples to 15 bits Tremor decoder is unusable since commit 2ee43c4. Sound is distorted to the point where it's nothing but noise. The data from vorbis_synthesis_pcmout() needs to be scaled and clipped for 16 bit sample size. For reference see http://lists.xiph.org/pipermail/tremor/2010-April/001642.html and http://lists.xiph.org/pipermail/vorbis/2006-October/026513.html. Signed-off-by: Marcin Jurkowski --- NEWS | 2 ++ src/decoder/plugins/VorbisDecoderPlugin.cxx | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index f21b4224c..cb932c430 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,8 @@ ver 0.20.12 (not yet released) * input - curl: fix seeking +* decoder + - vorbis: fix Tremor support * player - log message when decoder is too slow diff --git a/src/decoder/plugins/VorbisDecoderPlugin.cxx b/src/decoder/plugins/VorbisDecoderPlugin.cxx index a01a92d31..4c86b3cab 100644 --- a/src/decoder/plugins/VorbisDecoderPlugin.cxx +++ b/src/decoder/plugins/VorbisDecoderPlugin.cxx @@ -178,6 +178,20 @@ VorbisDecoder::SubmitInit() client.Ready(audio_format, eos_granulepos > 0, duration); } +#ifdef HAVE_TREMOR +static inline int16_t tremor_clip_sample(int32_t x) +{ + x >>= 9; + + if (x < INT16_MIN) + return INT16_MIN; + if (x > INT16_MAX) + return INT16_MAX; + + return x; +} +#endif + bool VorbisDecoder::SubmitSomePcm() { @@ -197,7 +211,7 @@ VorbisDecoder::SubmitSomePcm() auto *dest = &buffer[c]; for (size_t i = 0; i < n_frames; ++i) { - *dest = *src++; + *dest = tremor_clip_sample(*src++); dest += channels; } }