aboutsummaryrefslogtreecommitdiff
path: root/src/pcm_utils.h
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2011-10-08 10:25:06 +0200
committerMax Kellermann <max@duempel.org>2011-10-20 02:32:39 +0200
commit545685bc3209d9cfdf6c4b9aeee4715edd453dc1 (patch)
treea8c1eea32702dcb319bae836581f1938c8bc6152 /src/pcm_utils.h
parent13ad2b4dc2a11ab7bad3703cdca050dd55243b6b (diff)
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.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/pcm_utils.h b/src/pcm_utils.h
index 001423b3..4ad89657 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