aboutsummaryrefslogtreecommitdiffstats
path: root/src/pcm_utils.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/pcm_utils.h')
-rw-r--r--src/pcm_utils.h41
1 files changed, 40 insertions, 1 deletions
diff --git a/src/pcm_utils.h b/src/pcm_utils.h
index 15f9e1b10..4ad896570 100644
--- a/src/pcm_utils.h
+++ b/src/pcm_utils.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2010 The Music Player Daemon Project
+ * Copyright (C) 2003-2011 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -25,6 +25,17 @@
#include <stdint.h>
/**
+ * Add a byte count to the specified pointer. This is a utility
+ * function to convert a source pointer and a byte count to an "end"
+ * pointer for use in loops.
+ */
+static inline const void *
+pcm_end_pointer(const void *p, size_t size)
+{
+ return (const char *)p + size;
+}
+
+/**
* Check if the value is within the range of the provided bit size,
* and caps it if necessary.
*/
@@ -52,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