aboutsummaryrefslogtreecommitdiffstats
path: root/src/pcm_utils.h
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-01-07 18:03:53 +0100
committerMax Kellermann <max@duempel.org>2009-01-07 18:03:53 +0100
commite8c323ed7e6cda5b96871d922e66f573059f8b62 (patch)
treedde798f243804b2ce48c9f3ecc0705fe433edd25 /src/pcm_utils.h
parent9cb76856c06109ea210ad6dbd5ddc209e1a2311e (diff)
downloadmpd-e8c323ed7e6cda5b96871d922e66f573059f8b62.tar.gz
mpd-e8c323ed7e6cda5b96871d922e66f573059f8b62.tar.xz
mpd-e8c323ed7e6cda5b96871d922e66f573059f8b62.zip
pcm_utils: export pcm_range()
We are going to split the pcm_utils.c library, and pcm_range() will be useful for several sub libraries.
Diffstat (limited to '')
-rw-r--r--src/pcm_utils.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/pcm_utils.h b/src/pcm_utils.h
index 71398c015..44ea5aa16 100644
--- a/src/pcm_utils.h
+++ b/src/pcm_utils.h
@@ -22,6 +22,8 @@
#include "pcm_resample.h"
#include "pcm_dither.h"
+#include <glib.h>
+
#include <stdint.h>
#include <stddef.h>
@@ -42,6 +44,20 @@ struct pcm_convert_state {
};
/**
+ * Check if the value is within the range of the provided bit size,
+ * and caps it if necessary.
+ */
+static inline int32_t
+pcm_range(int32_t sample, unsigned bits)
+{
+ if (G_UNLIKELY(sample < (-1 << (bits - 1))))
+ return -1 << (bits - 1);
+ if (G_UNLIKELY(sample >= (1 << (bits - 1))))
+ return (1 << (bits - 1)) - 1;
+ return sample;
+}
+
+/**
* Converts a float value (0.0 = silence, 1.0 = 100% volume) to an
* integer volume value (1000 = 100%).
*/