STTypes.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. // License :
  12. //
  13. // SoundTouch audio processing library
  14. // Copyright (c) Olli Parviainen
  15. //
  16. // This library is free software; you can redistribute it and/or
  17. // modify it under the terms of the GNU Lesser General Public
  18. // License as published by the Free Software Foundation; either
  19. // version 2.1 of the License, or (at your option) any later version.
  20. //
  21. // This library is distributed in the hope that it will be useful,
  22. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  24. // Lesser General Public License for more details.
  25. //
  26. // You should have received a copy of the GNU Lesser General Public
  27. // License along with this library; if not, write to the Free Software
  28. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  29. //
  30. ////////////////////////////////////////////////////////////////////////////////
  31. #ifndef STTypes_H
  32. #define STTypes_H
  33. #if (defined(__GNUC__) && !defined(ANDROID))
  34. // In GCC, include soundtouch_config.h made by config scritps.
  35. // Skip this in Android compilation that uses GCC but without configure scripts.
  36. //#include "soundtouch_config.h"
  37. #endif
  38. namespace soundtouch
  39. {
  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. /// Max allowed number of channels
  51. #define SOUNDTOUCH_MAX_CHANNELS 16
  52. /// Activate these undef's to overrule the possible sampletype
  53. /// setting inherited from some other header file:
  54. #undef SOUNDTOUCH_INTEGER_SAMPLES
  55. #undef SOUNDTOUCH_FLOAT_SAMPLES
  56. /// If following flag is defined, always uses multichannel processing
  57. /// routines also for mono and stero sound. This is for routine testing
  58. /// purposes; output should be same with either routines, yet disabling
  59. /// the dedicated mono/stereo processing routines will result in slower
  60. /// runtime performance so recommendation is to keep this off.
  61. // #define USE_MULTICH_ALWAYS
  62. #if (defined(__SOFTFP__) && defined(ANDROID))
  63. // For Android compilation: Force use of Integer samples in case that
  64. // compilation uses soft-floating point emulation - soft-fp is way too slow
  65. #undef SOUNDTOUCH_FLOAT_SAMPLES
  66. #define SOUNDTOUCH_INTEGER_SAMPLES 1
  67. #endif
  68. #if !(SOUNDTOUCH_INTEGER_SAMPLES || SOUNDTOUCH_FLOAT_SAMPLES)
  69. /// Choose either 32bit floating point or 16bit integer sampletype
  70. /// by choosing one of the following defines, unless this selection
  71. /// has already been done in some other file.
  72. ////
  73. /// Notes:
  74. /// - In Windows environment, choose the sample format with the
  75. /// following defines.
  76. /// - In GNU environment, the floating point samples are used by
  77. /// default, but integer samples can be chosen by giving the
  78. /// following switch to the configure script:
  79. /// ./configure --enable-integer-samples
  80. /// However, if you still prefer to select the sample format here
  81. /// also in GNU environment, then please #undef the INTEGER_SAMPLE
  82. /// and FLOAT_SAMPLE defines first as in comments above.
  83. #define SOUNDTOUCH_INTEGER_SAMPLES 1 //< 16bit integer samples
  84. //#define SOUNDTOUCH_FLOAT_SAMPLES 1 //< 32bit float samples
  85. #endif
  86. #if (_M_IX86 || __i386__ || __x86_64__ || _M_X64)
  87. /// Define this to allow X86-specific assembler/intrinsic optimizations.
  88. /// Notice that library contains also usual C++ versions of each of these
  89. /// these routines, so if you're having difficulties getting the optimized
  90. /// routines compiled for whatever reason, you may disable these optimizations
  91. /// to make the library compile.
  92. //#define SOUNDTOUCH_ALLOW_X86_OPTIMIZATIONS 1
  93. /// In GNU environment, allow the user to override this setting by
  94. /// giving the following switch to the configure script:
  95. /// ./configure --disable-x86-optimizations
  96. /// ./configure --enable-x86-optimizations=no
  97. #ifdef SOUNDTOUCH_DISABLE_X86_OPTIMIZATIONS
  98. #undef SOUNDTOUCH_ALLOW_X86_OPTIMIZATIONS
  99. #endif
  100. #else
  101. /// Always disable optimizations when not using a x86 systems.
  102. #undef SOUNDTOUCH_ALLOW_X86_OPTIMIZATIONS
  103. #endif
  104. // If defined, allows the SIMD-optimized routines to skip unevenly aligned
  105. // memory offsets that can cause performance penalty in some SIMD implementations.
  106. // Causes slight compromise in sound quality.
  107. #define SOUNDTOUCH_ALLOW_NONEXACT_SIMD_OPTIMIZATION 1
  108. #ifdef SOUNDTOUCH_INTEGER_SAMPLES
  109. // 16bit integer sample type
  110. typedef short SAMPLETYPE;
  111. // data type for sample accumulation: Use 32bit integer to prevent overflows
  112. typedef long LONG_SAMPLETYPE;
  113. #ifdef SOUNDTOUCH_FLOAT_SAMPLES
  114. // check that only one sample type is defined
  115. #error "conflicting sample types defined"
  116. #endif // SOUNDTOUCH_FLOAT_SAMPLES
  117. #ifdef SOUNDTOUCH_ALLOW_X86_OPTIMIZATIONS
  118. // Allow MMX optimizations (not available in X64 mode)
  119. #if (!_M_X64)
  120. #define SOUNDTOUCH_ALLOW_MMX 1
  121. #endif
  122. #endif
  123. #else
  124. // floating point samples
  125. typedef float SAMPLETYPE;
  126. // data type for sample accumulation: Use float also here to enable
  127. // efficient autovectorization
  128. typedef float LONG_SAMPLETYPE;
  129. #ifdef SOUNDTOUCH_ALLOW_X86_OPTIMIZATIONS
  130. // Allow SSE optimizations
  131. #define SOUNDTOUCH_ALLOW_SSE 1
  132. #endif
  133. #endif // SOUNDTOUCH_INTEGER_SAMPLES
  134. #if ((SOUNDTOUCH_ALLOW_SSE) || (__SSE__) || (SOUNDTOUCH_USE_NEON))
  135. #if SOUNDTOUCH_ALLOW_NONEXACT_SIMD_OPTIMIZATION
  136. #define ST_SIMD_AVOID_UNALIGNED
  137. #endif
  138. #endif
  139. }
  140. // define ST_NO_EXCEPTION_HANDLING switch to disable throwing std exceptions:
  141. #define ST_NO_EXCEPTION_HANDLING 1
  142. #ifdef ST_NO_EXCEPTION_HANDLING
  143. // Exceptions disabled. Throw asserts instead if enabled.
  144. #include <assert.h>
  145. #define ST_THROW_RT_ERROR(x) {assert((const char *)x);}
  146. #else
  147. // use c++ standard exceptions
  148. #include <stdexcept>
  149. #include <string>
  150. #define ST_THROW_RT_ERROR(x) {throw std::runtime_error(x);}
  151. #endif
  152. // When this #define is active, eliminates a clicking sound when the "rate" or "pitch"
  153. // parameter setting crosses from value <1 to >=1 or vice versa during processing.
  154. // Default is off as such crossover is untypical case and involves a slight sound
  155. // quality compromise.
  156. //#define SOUNDTOUCH_PREVENT_CLICK_AT_RATE_CROSSOVER 1
  157. #endif