From b43ec3d6f08ab6b3044a2514f9bb8a8f1a0eb31f Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 22 Dec 2013 18:52:54 +0100 Subject: pcm/Traits: add MIN and MAX Move from PcmClamp(). --- src/pcm/Traits.hxx | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/pcm/Traits.hxx') 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 { * 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 { 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 { 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 { 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 { 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 -- cgit v1.2.3