public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sbc: added saturated clipping of decoder output to 16-bit
@ 2009-04-17 16:26 Siarhei Siamashka
  2009-04-17 17:01 ` Marcel Holtmann
  0 siblings, 1 reply; 2+ messages in thread
From: Siarhei Siamashka @ 2009-04-17 16:26 UTC (permalink / raw)
  To: linux-bluetooth@vger.kernel.org

[-- Attachment #1: Type: text/plain, Size: 79 bytes --]

Hello,

This is a bugfix for SBC decoder.

-- 
Best regards,
Siarhei Siamashka

[-- Attachment #2: 0001-sbc-added-saturated-clipping-of-decoder-output-to-1.patch --]
[-- Type: text/x-diff, Size: 2958 bytes --]

From 3f9180b9b32c17b6f6594ac7e7b03fa0d665c7f8 Mon Sep 17 00:00:00 2001
From: Siarhei Siamashka <siarhei.siamashka@nokia.com>
Date: Fri, 17 Apr 2009 18:27:38 +0300
Subject: [PATCH] sbc: added saturated clipping of decoder output to 16-bit

This prevents overflows and audible artefacts for the audio files which
originally had loudness maximized. Music from audio CD disks is an
example of such files, see http://en.wikipedia.org/wiki/Loudness_war
---
 sbc/sbc.c |   20 +++++++++++++++-----
 1 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/sbc/sbc.c b/sbc/sbc.c
index a6b6563..14e5869 100644
--- a/sbc/sbc.c
+++ b/sbc/sbc.c
@@ -534,6 +534,16 @@ static void sbc_decoder_init(struct sbc_decoder_state *state,
 			state->offset[ch][i] = (10 * i + 10);
 }
 
+static SBC_ALWAYS_INLINE int16_t sbc_clip16(int32_t s)
+{
+	if (s > 0x7FFF)
+		return 0x7FFF;
+	else if (s < -0x8000)
+		return -0x8000;
+	else
+		return s;
+}
+
 static inline void sbc_synthesize_four(struct sbc_decoder_state *state,
 				struct sbc_frame *frame, int ch, int blk)
 {
@@ -562,7 +572,7 @@ static inline void sbc_synthesize_four(struct sbc_decoder_state *state,
 		k = (i + 4) & 0xf;
 
 		/* Store in output, Q0 */
-		frame->pcm_sample[ch][blk * 4 + i] = SCALE4_STAGED1(
+		frame->pcm_sample[ch][blk * 4 + i] = sbc_clip16(SCALE4_STAGED1(
 			MULA(v[offset[i] + 0], sbc_proto_4_40m0[idx + 0],
 			MULA(v[offset[k] + 1], sbc_proto_4_40m1[idx + 0],
 			MULA(v[offset[i] + 2], sbc_proto_4_40m0[idx + 1],
@@ -572,7 +582,7 @@ static inline void sbc_synthesize_four(struct sbc_decoder_state *state,
 			MULA(v[offset[i] + 6], sbc_proto_4_40m0[idx + 3],
 			MULA(v[offset[k] + 7], sbc_proto_4_40m1[idx + 3],
 			MULA(v[offset[i] + 8], sbc_proto_4_40m0[idx + 4],
-			MUL( v[offset[k] + 9], sbc_proto_4_40m1[idx + 4])))))))))));
+			MUL( v[offset[k] + 9], sbc_proto_4_40m1[idx + 4]))))))))))));
 	}
 }
 
@@ -607,8 +617,8 @@ static inline void sbc_synthesize_eight(struct sbc_decoder_state *state,
 	for (idx = 0, i = 0; i < 8; i++, idx += 5) {
 		k = (i + 8) & 0xf;
 
-		/* Store in output */
-		frame->pcm_sample[ch][blk * 8 + i] = SCALE8_STAGED1( // Q0
+		/* Store in output, Q0 */
+		frame->pcm_sample[ch][blk * 8 + i] = sbc_clip16(SCALE8_STAGED1(
 			MULA(state->V[ch][offset[i] + 0], sbc_proto_8_80m0[idx + 0],
 			MULA(state->V[ch][offset[k] + 1], sbc_proto_8_80m1[idx + 0],
 			MULA(state->V[ch][offset[i] + 2], sbc_proto_8_80m0[idx + 1],
@@ -618,7 +628,7 @@ static inline void sbc_synthesize_eight(struct sbc_decoder_state *state,
 			MULA(state->V[ch][offset[i] + 6], sbc_proto_8_80m0[idx + 3],
 			MULA(state->V[ch][offset[k] + 7], sbc_proto_8_80m1[idx + 3],
 			MULA(state->V[ch][offset[i] + 8], sbc_proto_8_80m0[idx + 4],
-			MUL( state->V[ch][offset[k] + 9], sbc_proto_8_80m1[idx + 4])))))))))));
+			MUL( state->V[ch][offset[k] + 9], sbc_proto_8_80m1[idx + 4]))))))))))));
 	}
 }
 
-- 
1.5.6.5


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] sbc: added saturated clipping of decoder output to 16-bit
  2009-04-17 16:26 [PATCH] sbc: added saturated clipping of decoder output to 16-bit Siarhei Siamashka
@ 2009-04-17 17:01 ` Marcel Holtmann
  0 siblings, 0 replies; 2+ messages in thread
From: Marcel Holtmann @ 2009-04-17 17:01 UTC (permalink / raw)
  To: Siarhei Siamashka; +Cc: linux-bluetooth@vger.kernel.org

Hi Siarhei,

> This is a bugfix for SBC decoder.

patch has been applied. Thanks.

Regards

Marcel



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-04-17 17:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-17 16:26 [PATCH] sbc: added saturated clipping of decoder output to 16-bit Siarhei Siamashka
2009-04-17 17:01 ` Marcel Holtmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox