STTypes.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. ////////////////////////////////////////////////////////////////////////////////
  2. ///
  3. /// Common type definitions for SoundTouch audio processing library.
  4. ///
  5. /// Author : Copyright (c) Olli Parviainen
  6. /// Author e-mail : oparviai 'at' iki.fi
  7. /// SoundTouch WWW: http://www.surina.net/soundtouch
  8. ///
  9. ////////////////////////////////////////////////////////////////////////////////
  10. //
  11. // Last changed : $Date: 2013-06-12 15:24:44 +0000 (Wed, 12 Jun 2013) $
  12. // File revision : $Revision: 3 $
  13. //
  14. // $Id: STTypes.h 171 2013-06-12 15:24:44Z oparviai $
  15. //
  16. ////////////////////////////////////////////////////////////////////////////////
  17. //
  18. // License :
  19. //
  20. // SoundTouch audio processing library
  21. // Copyright (c) Olli Parviainen
  22. //
  23. // This library is free software; you can redistribute it and/or
  24. // modify it under the terms of the GNU Lesser General Public
  25. // License as published by the Free Software Foundation; either
  26. // version 2.1 of the License, or (at your option) any later version.
  27. //
  28. // This library is distributed in the hope that it will be useful,
  29. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  30. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  31. // Lesser General Public License for more details.
  32. //
  33. // You should have received a copy of the GNU Lesser General Public
  34. // License along with this library; if not, write to the Free Software
  35. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  36. //
  37. ////////////////////////////////////////////////////////////////////////////////
  38. #ifndef STTypes_H
  39. #define STTypes_H
  40. typedef unsigned int uint;
  41. typedef unsigned long ulong;
  42. // Patch for MinGW: on Win64 long is 32-bit
  43. #ifdef _WIN64
  44. typedef unsigned long long ulongptr;
  45. #else
  46. typedef ulong ulongptr;
  47. #endif
  48. // Helper macro for aligning pointer up to next 16-byte boundary
  49. #define SOUNDTOUCH_ALIGN_POINTER_16(x) ( ( (ulongptr)(x) + 15 ) & ~(ulongptr)15 )
  50. #if (defined(__GNUC__) && !defined(ANDROID))
  51. // In GCC, include soundtouch_config.h made by config scritps.
  52. // Skip this in Android compilation that uses GCC but without configure scripts.
  53. //#include "soundtouch_config.h"
  54. #endif
  55. #ifndef _WINDEF_
  56. // if these aren't defined already by Windows headers, define now
  57. typedef int BOOL;
  58. #define FALSE 0
  59. #define TRUE 1
  60. #endif // _WINDEF_
  61. namespace soundtouch
  62. {
  63. /// Activate these undef's to overrule the possible sampletype
  64. /// setting inherited from some other header file:
  65. #undef SOUNDTOUCH_INTEGER_SAMPLES
  66. #undef SOUNDTOUCH_FLOAT_SAMPLES
  67. /// If following flag is defined, always uses multichannel processing
  68. /// routines also for mono and stero sound. This is for routine testing
  69. /// purposes; output should be same with either routines, yet disabling
  70. /// the dedicated mono/stereo processing routines will result in slower
  71. /// runtime performance so recommendation is to keep this off.
  72. // #define USE_MULTICH_ALWAYS
  73. #if (defined(__SOFTFP__))
  74. // For Android compilation: Force use of Integer samples in case that
  75. // compilation uses soft-floating point emulation - soft-fp is way too slow
  76. #undef SOUNDTOUCH_FLOAT_SAMPLES
  77. #define SOUNDTOUCH_INTEGER_SAMPLES 1
  78. #endif
  79. #if !(SOUNDTOUCH_INTEGER_SAMPLES || SOUNDTOUCH_FLOAT_SAMPLES)
  80. /// Choose either 32bit floating point or 16bit integer sampletype
  81. /// by choosing one of the following defines, unless this selection
  82. /// has already been done in some other file.
  83. ////
  84. /// Notes:
  85. /// - In Windows environment, choose the sample format with the
  86. /// following defines.
  87. /// - In GNU environment, the floating point samples are used by
  88. /// default, but integer samples can be chosen by giving the
  89. /// following switch to the configure script:
  90. /// ./configure --enable-integer-samples
  91. /// However, if you still prefer to select the sample format here
  92. /// also in GNU environment, then please #undef the INTEGER_SAMPLE
  93. /// and FLOAT_SAMPLE defines first as in comments above.
  94. //#define SOUNDTOUCH_INTEGER_SAMPLES 1 //< 16bit integer samples
  95. #define SOUNDTOUCH_FLOAT_SAMPLES 1 //< 32bit float samples
  96. #endif
  97. #if (_M_IX86 || __i386__ || __x86_64__ || _M_X64)
  98. /// Define this to allow X86-specific assembler/intrinsic optimizations.
  99. /// Notice that library contains also usual C++ versions of each of these
  100. /// these routines, so if you're having difficulties getting the optimized
  101. /// routines compiled for whatever reason, you may disable these optimizations
  102. /// to make the library compile.
  103. #define SOUNDTOUCH_ALLOW_X86_OPTIMIZATIONS 1
  104. /// In GNU environment, allow the user to override this setting by
  105. /// giving the following switch to the configure script:
  106. /// ./configure --disable-x86-optimizations
  107. /// ./configure --enable-x86-optimizations=no
  108. #ifdef SOUNDTOUCH_DISABLE_X86_OPTIMIZATIONS
  109. #undef SOUNDTOUCH_ALLOW_X86_OPTIMIZATIONS
  110. #endif
  111. #else
  112. /// Always disable optimizations when not using a x86 systems.
  113. #undef SOUNDTOUCH_ALLOW_X86_OPTIMIZATIONS
  114. #endif
  115. // If defined, allows the SIMD-optimized routines to take minor shortcuts
  116. // for improved performance. Undefine to require faithfully similar SIMD
  117. // calculations as in normal C implementation.
  118. #define SOUNDTOUCH_ALLOW_NONEXACT_SIMD_OPTIMIZATION 1
  119. #ifdef SOUNDTOUCH_INTEGER_SAMPLES
  120. // 16bit integer sample type
  121. typedef short SAMPLETYPE;
  122. // data type for sample accumulation: Use 32bit integer to prevent overflows
  123. typedef long LONG_SAMPLETYPE;
  124. #ifdef SOUNDTOUCH_FLOAT_SAMPLES
  125. // check that only one sample type is defined
  126. #error "conflicting sample types defined"
  127. #endif // SOUNDTOUCH_FLOAT_SAMPLES
  128. #ifdef SOUNDTOUCH_ALLOW_X86_OPTIMIZATIONS
  129. // Allow MMX optimizations
  130. #define SOUNDTOUCH_ALLOW_MMX 1
  131. #endif
  132. #else
  133. // floating point samples
  134. typedef float SAMPLETYPE;
  135. // data type for sample accumulation: Use double to utilize full precision.
  136. typedef double LONG_SAMPLETYPE;
  137. #ifdef SOUNDTOUCH_ALLOW_X86_OPTIMIZATIONS
  138. // Allow SSE optimizations
  139. #define SOUNDTOUCH_ALLOW_SSE 1
  140. #endif
  141. #endif // SOUNDTOUCH_INTEGER_SAMPLES
  142. };
  143. // define ST_NO_EXCEPTION_HANDLING switch to disable throwing std exceptions:
  144. #define ST_NO_EXCEPTION_HANDLING 1
  145. #ifdef ST_NO_EXCEPTION_HANDLING
  146. // Exceptions disabled. Throw asserts instead if enabled.
  147. #include <assert.h>
  148. #define ST_THROW_RT_ERROR(x) {assert((const char *)x);}
  149. #else
  150. // use c++ standard exceptions
  151. #include <stdexcept>
  152. #define ST_THROW_RT_ERROR(x) {throw std::runtime_error(x);}
  153. #endif
  154. // When this #define is active, eliminates a clicking sound when the "rate" or "pitch"
  155. // parameter setting crosses from value <1 to >=1 or vice versa during processing.
  156. // Default is off as such crossover is untypical case and involves a slight sound
  157. // quality compromise.
  158. //#define SOUNDTOUCH_PREVENT_CLICK_AT_RATE_CROSSOVER 1
  159. #endif