3 * Copyright (C) 2010-2013 Team XBMC
6 * This Program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * This Program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with XBMC; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
22 #include "../AEAudioFormat.h"
23 #include "utils/StdString.h"
24 #include "PlatformDefs.h"
28 #if _M_IX86_FP>0 && !defined(__SSE__)
34 #include <xmmintrin.h>
40 #define MEMALIGN(b, x) x __attribute__((aligned(b)))
42 #define MEMALIGN(b, x) __declspec(align(b)) x
48 static unsigned int m_seed;
50 static __m128i m_sseSeed;
53 static float SoftClamp(const float x);
56 static CAEChannelInfo GuessChLayout (const unsigned int channels);
57 static const char* GetStdChLayoutName(const enum AEStdChLayout layout);
58 static const unsigned int DataFormatToBits (const enum AEDataFormat dataFormat);
59 static const char* DataFormatToStr (const enum AEDataFormat dataFormat);
61 /*! \brief convert a volume percentage (as a proportion) to a dB gain
62 We assume a dB range of 60dB, i.e. assume that 0% volume corresponds
63 to a reduction of 60dB.
64 \param value the volume from 0..1
65 \return the corresponding gain in dB from -60dB .. 0dB.
68 static inline const float PercentToGain(const float value)
70 static const float db_range = 60.0f;
71 return (value - 1)*db_range;
74 /*! \brief convert a dB gain to volume percentage (as a proportion)
75 We assume a dB range of 60dB, i.e. assume that 0% volume corresponds
76 to a reduction of 60dB.
77 \param the corresponding gain in dB from -60dB .. 0dB.
78 \return value the volume from 0..1
81 static inline const float GainToPercent(const float gain)
83 static const float db_range = 60.0f;
84 return 1+(gain/db_range);
87 /*! \brief convert a dB gain to a scale factor for audio manipulation
88 Inverts gain = 20 log_10(scale)
89 \param dB the gain in decibels.
90 \return the scale factor (equivalent to a voltage multiplier).
93 static inline const float GainToScale(const float dB)
95 return pow(10.0f, dB/20);
98 /*! \brief convert a scale factor to dB gain for audio manipulation
99 Inverts GainToScale result
100 \param the scale factor (equivalent to a voltage multiplier).
101 \return dB the gain in decibels.
104 static inline const float ScaleToGain(const float scale)
106 return 20*log10(scale);
110 static void SSEMulArray (float *data, const float mul, uint32_t count);
111 static void SSEMulAddArray (float *data, float *add, const float mul, uint32_t count);
113 static void ClampArray(float *data, uint32_t count);
116 Rand implementations based on:
117 http://software.intel.com/en-us/articles/fast-random-number-generator-on-the-intel-pentiumr-4-processor/
118 This is NOT safe for crypto work, but perfectly fine for audio usage (dithering)
120 static float FloatRand1(const float min, const float max);
121 static void FloatRand4(const float min, const float max, float result[4], __m128 *sseresult = NULL);
123 static bool S16NeedsByteSwap(AEDataFormat in, AEDataFormat out);