aboutsummaryrefslogtreecommitdiffstats
path: root/src/pcm/Traits.hxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-12-22 18:52:54 +0100
committerMax Kellermann <max@duempel.org>2013-12-22 21:32:25 +0100
commitb43ec3d6f08ab6b3044a2514f9bb8a8f1a0eb31f (patch)
tree790eef4806cb4839fef9cf18362ef0b08b1819ae /src/pcm/Traits.hxx
parent316a25dead0698be5e5befb236e08146740aca77 (diff)
downloadmpd-b43ec3d6f08ab6b3044a2514f9bb8a8f1a0eb31f.tar.gz
mpd-b43ec3d6f08ab6b3044a2514f9bb8a8f1a0eb31f.tar.xz
mpd-b43ec3d6f08ab6b3044a2514f9bb8a8f1a0eb31f.zip
pcm/Traits: add MIN and MAX
Move from PcmClamp().
Diffstat (limited to 'src/pcm/Traits.hxx')
-rw-r--r--src/pcm/Traits.hxx22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/pcm/Traits.hxx b/src/pcm/Traits.hxx
index 0ec4aaf0a..48e7d559e 100644
--- a/src/pcm/Traits.hxx
+++ b/src/pcm/Traits.hxx
@@ -74,6 +74,16 @@ struct SampleTraits<SampleFormat::S8> {
* not exist if this is not an integer sample format.
*/
static constexpr unsigned BITS = sizeof(value_type) * 8;
+
+ /**
+ * The minimum sample value.
+ */
+ static constexpr value_type MIN = -(sum_type(1) << (BITS - 1));
+
+ /**
+ * The maximum sample value.
+ */
+ static constexpr value_type MAX = (sum_type(1) << (BITS - 1)) - 1;
};
template<>
@@ -87,6 +97,9 @@ struct SampleTraits<SampleFormat::S16> {
static constexpr size_t SAMPLE_SIZE = sizeof(value_type);
static constexpr unsigned BITS = sizeof(value_type) * 8;
+
+ static constexpr value_type MIN = -(sum_type(1) << (BITS - 1));
+ static constexpr value_type MAX = (sum_type(1) << (BITS - 1)) - 1;
};
template<>
@@ -100,6 +113,9 @@ struct SampleTraits<SampleFormat::S32> {
static constexpr size_t SAMPLE_SIZE = sizeof(value_type);
static constexpr unsigned BITS = sizeof(value_type) * 8;
+
+ static constexpr value_type MIN = -(sum_type(1) << (BITS - 1));
+ static constexpr value_type MAX = (sum_type(1) << (BITS - 1)) - 1;
};
template<>
@@ -113,6 +129,9 @@ struct SampleTraits<SampleFormat::S24_P32> {
static constexpr size_t SAMPLE_SIZE = sizeof(value_type);
static constexpr unsigned BITS = 24;
+
+ static constexpr value_type MIN = -(sum_type(1) << (BITS - 1));
+ static constexpr value_type MAX = (sum_type(1) << (BITS - 1)) - 1;
};
template<>
@@ -125,6 +144,9 @@ struct SampleTraits<SampleFormat::FLOAT> {
typedef float long_type;
static constexpr size_t SAMPLE_SIZE = sizeof(value_type);
+
+ static constexpr value_type MIN = -1;
+ static constexpr value_type MAX = 1;
};
#endif