aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-11-22 23:00:39 +0100
committerMax Kellermann <max@duempel.org>2013-11-22 23:24:40 +0100
commit45d27a52f17be05f5269d7dc37f380ed595196e7 (patch)
tree18c1054ea447671578c8c7e6dc5b47460c1314fd
parentd22acc59c928bf4fd96eb569897bf6f64ae7df7a (diff)
downloadmpd-45d27a52f17be05f5269d7dc37f380ed595196e7.tar.gz
mpd-45d27a52f17be05f5269d7dc37f380ed595196e7.tar.xz
mpd-45d27a52f17be05f5269d7dc37f380ed595196e7.zip
PcmUtils: add function PcmClampN()
Diffstat (limited to '')
-rw-r--r--src/pcm/PcmUtils.hxx12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/pcm/PcmUtils.hxx b/src/pcm/PcmUtils.hxx
index 108ba85ae..febe12d7b 100644
--- a/src/pcm/PcmUtils.hxx
+++ b/src/pcm/PcmUtils.hxx
@@ -63,4 +63,16 @@ PcmClamp(U x)
return T(x);
}
+/**
+ * Check if the values in this buffer are within the range of the
+ * provided bit size, and clamps them whenever necessary.
+ */
+template<typename T, typename U, unsigned bits>
+static inline void
+PcmClampN(T *dest, const U *src, unsigned n)
+{
+ while (n-- > 0)
+ *dest++ = PcmClamp<T, U, bits>(*src++);
+}
+
#endif