From a4ba7350a7a9b294d4efc347e339fad25ce297e5 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Fri, 11 Aug 2023 08:39:52 +1000 Subject: Fix docs nits, avoid recalculating frame length --- src/codecs/include/sample.hpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/codecs/include/sample.hpp') diff --git a/src/codecs/include/sample.hpp b/src/codecs/include/sample.hpp index ea3a7ffc..f77284bb 100644 --- a/src/codecs/include/sample.hpp +++ b/src/codecs/include/sample.hpp @@ -1,3 +1,9 @@ +/* + * Copyright 2023 jacqueline + * + * SPDX-License-Identifier: GPL-3.0-only + */ + #pragma once #include @@ -8,7 +14,14 @@ namespace sample { -// A signed, 32-bit PCM sample. +// A signed, 16-bit PCM sample. All decoder output should be normalised to this +// format, in order to simplify resampling and/or re-encoding for bluetooth. +// Why 'only' 16 bits? +// 1. It's the lowest common bits per sample amongst our codecs. A higher bits +// per sample would require us to uselessly scale up those outputs. +// 2. With appropriate dithering, you're not going to hear a difference +// between 16 bit samples and higher bits anyway. +// 3. Monty from Xiph.org reckons it's all you need. typedef int16_t Sample; constexpr auto Clip(int64_t v) -> Sample { @@ -21,7 +34,6 @@ constexpr auto Clip(int64_t v) -> Sample { constexpr auto FromSigned(int32_t src, uint_fast8_t bits) -> Sample { if (bits > 16) { - // Left-align samples, effectively scaling them up to 32 bits. return src << (sizeof(Sample) * 8 - bits); } else if (bits < 16) { return src << (bits - (sizeof(Sample) * 8)); -- cgit v1.2.3