From 545685bc3209d9cfdf6c4b9aeee4715edd453dc1 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 8 Oct 2011 10:25:06 +0200 Subject: audio_format: basic support for floating point samples Support for conversion from float to 16, 24 and 32 bit integer samples. --- src/pcm_utils.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/pcm_utils.h') diff --git a/src/pcm_utils.h b/src/pcm_utils.h index 001423b37..4ad896570 100644 --- a/src/pcm_utils.h +++ b/src/pcm_utils.h @@ -63,4 +63,32 @@ pcm_range_64(int64_t sample, unsigned bits) return sample; } +G_GNUC_CONST +static inline int16_t +pcm_clamp_16(int x) +{ + static const int32_t MIN_VALUE = G_MININT16; + static const int32_t MAX_VALUE = G_MAXINT16; + + if (G_UNLIKELY(x < MIN_VALUE)) + return MIN_VALUE; + if (G_UNLIKELY(x > MAX_VALUE)) + return MAX_VALUE; + return x; +} + +G_GNUC_CONST +static inline int32_t +pcm_clamp_24(int x) +{ + static const int32_t MIN_VALUE = -(1 << 23); + static const int32_t MAX_VALUE = (1 << 23) - 1; + + if (G_UNLIKELY(x < MIN_VALUE)) + return MIN_VALUE; + if (G_UNLIKELY(x > MAX_VALUE)) + return MAX_VALUE; + return x; +} + #endif -- cgit v1.2.3