From 63dd01d5f2c2db804ede05fc1fe6600f4f7399c8 Mon Sep 17 00:00:00 2001 From: beveloper Date: Sun, 29 Feb 2004 17:33:36 +0000 Subject: [PATCH] added saturation to float conversion git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6801 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../plugins/raw_decoder/AudioConversion.cpp | 16 ++++++++-------- .../plugins/raw_decoder/RawDecoderPlugin.cpp | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/add-ons/media/plugins/raw_decoder/AudioConversion.cpp b/src/add-ons/media/plugins/raw_decoder/AudioConversion.cpp index 741d50ad1e..a9c793a8c6 100644 --- a/src/add-ons/media/plugins/raw_decoder/AudioConversion.cpp +++ b/src/add-ons/media/plugins/raw_decoder/AudioConversion.cpp @@ -79,10 +79,10 @@ private: class float32_sample { public: - inline operator uint8() { return (int32)(data * 127.0f) + 128; } - inline operator int8() { return (int8)(data * 127.0f); } - inline operator int16() { return (int16)(data * 32767.0f); } - inline operator int32() { return (int32)(data * 2147483647.0f); } + inline operator uint8() { int32 v = (int32)(data * 127.0f) + 128; if (v > 255) v = 255; else if (v < 0) v = 0; return v; } + inline operator int8() { int32 v = (int32)(data * 127.0f); if (v > 127) v = 127; else if (v < -127) v = -127; return v; } + inline operator int16() { int32 v = (int32)(data * 32767.0f); if (v > 32767) v = 32767; else if (v < -32767) v = -32767; return v; } + inline operator int32() { float32 v; if (data < -1.0f) v = -1.0f; else if (data > 1.0f) v = 1.0f; else v = data; return (int32)(v * 2147483647.0f); } inline operator float() { return data; } private: float32 data; @@ -91,10 +91,10 @@ private: class float64_sample { public: - inline operator uint8() { return (int32)(data * 127.0) + 128; } - inline operator int8() { return (int8)(data * 127.0); } - inline operator int16() { return (int16)(data * 32767.0); } - inline operator int32() { return (int32)(data * 2147483647.0); } + inline operator uint8() { int32 v = (int32)(data * 127.0f) + 128; if (v > 255) v = 255; else if (v < 0) v = 0; return v; } + inline operator int8() { int32 v = (int32)(data * 127.0f); if (v > 127) v = 127; else if (v < -127) v = -127; return v; } + inline operator int16() { int32 v = (int32)(data * 32767.0f); if (v > 32767) v = 32767; else if (v < -32767) v = -32767; return v; } + inline operator int32() { float64 v; if (data < -1.0) v = -1.0; else if (data > 1.0) v = 1.0; else v = data; return (int32)(v * 2147483647.0f); } inline operator float() { return data; } private: float64 data; diff --git a/src/add-ons/media/plugins/raw_decoder/RawDecoderPlugin.cpp b/src/add-ons/media/plugins/raw_decoder/RawDecoderPlugin.cpp index 949dc29c0f..f946e90fa0 100644 --- a/src/add-ons/media/plugins/raw_decoder/RawDecoderPlugin.cpp +++ b/src/add-ons/media/plugins/raw_decoder/RawDecoderPlugin.cpp @@ -7,7 +7,7 @@ #include "RawDecoderPlugin.h" #include "AudioConversion.h" -#define TRACE_THIS 1 +#define TRACE_THIS 0 #if TRACE_THIS #define TRACE printf #else