From 45d27a52f17be05f5269d7dc37f380ed595196e7 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 22 Nov 2013 23:00:39 +0100 Subject: PcmUtils: add function PcmClampN() --- src/pcm/PcmUtils.hxx | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 +static inline void +PcmClampN(T *dest, const U *src, unsigned n) +{ + while (n-- > 0) + *dest++ = PcmClamp(*src++); +} + #endif -- cgit v1.2.3