diff options
author | Max Kellermann <max@duempel.org> | 2011-10-08 10:25:06 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2011-10-20 02:32:39 +0200 |
commit | 545685bc3209d9cfdf6c4b9aeee4715edd453dc1 (patch) | |
tree | a8c1eea32702dcb319bae836581f1938c8bc6152 /src/pcm_utils.h | |
parent | 13ad2b4dc2a11ab7bad3703cdca050dd55243b6b (diff) | |
download | mpd-545685bc3209d9cfdf6c4b9aeee4715edd453dc1.tar.gz mpd-545685bc3209d9cfdf6c4b9aeee4715edd453dc1.tar.xz mpd-545685bc3209d9cfdf6c4b9aeee4715edd453dc1.zip |
audio_format: basic support for floating point samples
Support for conversion from float to 16, 24 and 32 bit integer
samples.
Diffstat (limited to 'src/pcm_utils.h')
-rw-r--r-- | src/pcm_utils.h | 28 |
1 files changed, 28 insertions, 0 deletions
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 |