Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

juce_FloatVectorOperations.h 12KB

9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
8 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef JUCE_FLOATVECTOROPERATIONS_H_INCLUDED
  18. #define JUCE_FLOATVECTOROPERATIONS_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. A collection of simple vector operations on arrays of floats, accelerated with
  22. SIMD instructions where possible.
  23. */
  24. class JUCE_API FloatVectorOperations
  25. {
  26. public:
  27. //==============================================================================
  28. /** Clears a vector of floats. */
  29. static void JUCE_CALLTYPE clear (float* dest, int numValues) noexcept;
  30. /** Clears a vector of doubles. */
  31. static void JUCE_CALLTYPE clear (double* dest, int numValues) noexcept;
  32. /** Copies a repeated value into a vector of floats. */
  33. static void JUCE_CALLTYPE fill (float* dest, float valueToFill, int numValues) noexcept;
  34. /** Copies a repeated value into a vector of doubles. */
  35. static void JUCE_CALLTYPE fill (double* dest, double valueToFill, int numValues) noexcept;
  36. /** Copies a vector of floats. */
  37. static void JUCE_CALLTYPE copy (float* dest, const float* src, int numValues) noexcept;
  38. /** Copies a vector of doubles. */
  39. static void JUCE_CALLTYPE copy (double* dest, const double* src, int numValues) noexcept;
  40. /** Copies a vector of floats, multiplying each value by a given multiplier */
  41. static void JUCE_CALLTYPE copyWithMultiply (float* dest, const float* src, float multiplier, int numValues) noexcept;
  42. /** Copies a vector of doubles, multiplying each value by a given multiplier */
  43. static void JUCE_CALLTYPE copyWithMultiply (double* dest, const double* src, double multiplier, int numValues) noexcept;
  44. /** Adds a fixed value to the destination values. */
  45. static void JUCE_CALLTYPE add (float* dest, float amountToAdd, int numValues) noexcept;
  46. /** Adds a fixed value to the destination values. */
  47. static void JUCE_CALLTYPE add (double* dest, double amountToAdd, int numValues) noexcept;
  48. /** Adds a fixed value to each source value and stores it in the destination array. */
  49. static void JUCE_CALLTYPE add (float* dest, float* src, float amount, int numValues) noexcept;
  50. /** Adds a fixed value to each source value and stores it in the destination array. */
  51. static void JUCE_CALLTYPE add (double* dest, double* src, double amount, int numValues) noexcept;
  52. /** Adds the source values to the destination values. */
  53. static void JUCE_CALLTYPE add (float* dest, const float* src, int numValues) noexcept;
  54. /** Adds the source values to the destination values. */
  55. static void JUCE_CALLTYPE add (double* dest, const double* src, int numValues) noexcept;
  56. /** Adds each source1 value to the corresponding source2 value and stores the result in the destination array. */
  57. static void JUCE_CALLTYPE add (float* dest, const float* src1, const float* src2, int num) noexcept;
  58. /** Adds each source1 value to the corresponding source2 value and stores the result in the destination array. */
  59. static void JUCE_CALLTYPE add (double* dest, const double* src1, const double* src2, int num) noexcept;
  60. /** Subtracts the source values from the destination values. */
  61. static void JUCE_CALLTYPE subtract (float* dest, const float* src, int numValues) noexcept;
  62. /** Subtracts the source values from the destination values. */
  63. static void JUCE_CALLTYPE subtract (double* dest, const double* src, int numValues) noexcept;
  64. /** Subtracts each source2 value from the corresponding source1 value and stores the result in the destination array. */
  65. static void JUCE_CALLTYPE subtract (float* dest, const float* src1, const float* src2, int num) noexcept;
  66. /** Subtracts each source2 value from the corresponding source1 value and stores the result in the destination array. */
  67. static void JUCE_CALLTYPE subtract (double* dest, const double* src1, const double* src2, int num) noexcept;
  68. /** Multiplies each source value by the given multiplier, then adds it to the destination value. */
  69. static void JUCE_CALLTYPE addWithMultiply (float* dest, const float* src, float multiplier, int numValues) noexcept;
  70. /** Multiplies each source value by the given multiplier, then adds it to the destination value. */
  71. static void JUCE_CALLTYPE addWithMultiply (double* dest, const double* src, double multiplier, int numValues) noexcept;
  72. /** Multiplies each source1 value by the corresponding source2 value, then adds it to the destination value. */
  73. static void JUCE_CALLTYPE addWithMultiply (float* dest, const float* src1, const float* src2, int num) noexcept;
  74. /** Multiplies each source1 value by the corresponding source2 value, then adds it to the destination value. */
  75. static void JUCE_CALLTYPE addWithMultiply (double* dest, const double* src1, const double* src2, int num) noexcept;
  76. /** Multiplies the destination values by the source values. */
  77. static void JUCE_CALLTYPE multiply (float* dest, const float* src, int numValues) noexcept;
  78. /** Multiplies the destination values by the source values. */
  79. static void JUCE_CALLTYPE multiply (double* dest, const double* src, int numValues) noexcept;
  80. /** Multiplies each source1 value by the correspinding source2 value, then stores it in the destination array. */
  81. static void JUCE_CALLTYPE multiply (float* dest, const float* src1, const float* src2, int numValues) noexcept;
  82. /** Multiplies each source1 value by the correspinding source2 value, then stores it in the destination array. */
  83. static void JUCE_CALLTYPE multiply (double* dest, const double* src1, const double* src2, int numValues) noexcept;
  84. /** Multiplies each of the destination values by a fixed multiplier. */
  85. static void JUCE_CALLTYPE multiply (float* dest, float multiplier, int numValues) noexcept;
  86. /** Multiplies each of the destination values by a fixed multiplier. */
  87. static void JUCE_CALLTYPE multiply (double* dest, double multiplier, int numValues) noexcept;
  88. /** Multiplies each of the source values by a fixed multiplier and stores the result in the destination array. */
  89. static void JUCE_CALLTYPE multiply (float* dest, const float* src, float multiplier, int num) noexcept;
  90. /** Multiplies each of the source values by a fixed multiplier and stores the result in the destination array. */
  91. static void JUCE_CALLTYPE multiply (double* dest, const double* src, double multiplier, int num) noexcept;
  92. /** Copies a source vector to a destination, negating each value. */
  93. static void JUCE_CALLTYPE negate (float* dest, const float* src, int numValues) noexcept;
  94. /** Copies a source vector to a destination, negating each value. */
  95. static void JUCE_CALLTYPE negate (double* dest, const double* src, int numValues) noexcept;
  96. /** Copies a source vector to a destination, taking the absolute of each value. */
  97. static void JUCE_CALLTYPE abs (float* dest, const float* src, int numValues) noexcept;
  98. /** Copies a source vector to a destination, taking the absolute of each value. */
  99. static void JUCE_CALLTYPE abs (double* dest, const double* src, int numValues) noexcept;
  100. /** Converts a stream of integers to floats, multiplying each one by the given multiplier. */
  101. static void JUCE_CALLTYPE convertFixedToFloat (float* dest, const int* src, float multiplier, int numValues) noexcept;
  102. /** Each element of dest will be the minimum of the corresponding element of the source array and the given comp value. */
  103. static void JUCE_CALLTYPE min (float* dest, const float* src, float comp, int num) noexcept;
  104. /** Each element of dest will be the minimum of the corresponding element of the source array and the given comp value. */
  105. static void JUCE_CALLTYPE min (double* dest, const double* src, double comp, int num) noexcept;
  106. /** Each element of dest will be the minimum of the corresponding source1 and source2 values. */
  107. static void JUCE_CALLTYPE min (float* dest, const float* src1, const float* src2, int num) noexcept;
  108. /** Each element of dest will be the minimum of the corresponding source1 and source2 values. */
  109. static void JUCE_CALLTYPE min (double* dest, const double* src1, const double* src2, int num) noexcept;
  110. /** Each element of dest will be the maximum of the corresponding element of the source array and the given comp value. */
  111. static void JUCE_CALLTYPE max (float* dest, const float* src, float comp, int num) noexcept;
  112. /** Each element of dest will be the maximum of the corresponding element of the source array and the given comp value. */
  113. static void JUCE_CALLTYPE max (double* dest, const double* src, double comp, int num) noexcept;
  114. /** Each element of dest will be the maximum of the corresponding source1 and source2 values. */
  115. static void JUCE_CALLTYPE max (float* dest, const float* src1, const float* src2, int num) noexcept;
  116. /** Each element of dest will be the maximum of the corresponding source1 and source2 values. */
  117. static void JUCE_CALLTYPE max (double* dest, const double* src1, const double* src2, int num) noexcept;
  118. /** Each element of dest is calculated by hard clipping the corresponding src element so that it is in the range specified by the arguments low and high. */
  119. static void JUCE_CALLTYPE clip (float* dest, const float* src, float low, float high, int num) noexcept;
  120. /** Each element of dest is calculated by hard clipping the corresponding src element so that it is in the range specified by the arguments low and high. */
  121. static void JUCE_CALLTYPE clip (double* dest, const double* src, double low, double high, int num) noexcept;
  122. /** Finds the miniumum and maximum values in the given array. */
  123. static Range<float> JUCE_CALLTYPE findMinAndMax (const float* src, int numValues) noexcept;
  124. /** Finds the miniumum and maximum values in the given array. */
  125. static Range<double> JUCE_CALLTYPE findMinAndMax (const double* src, int numValues) noexcept;
  126. /** Finds the miniumum value in the given array. */
  127. static float JUCE_CALLTYPE findMinimum (const float* src, int numValues) noexcept;
  128. /** Finds the miniumum value in the given array. */
  129. static double JUCE_CALLTYPE findMinimum (const double* src, int numValues) noexcept;
  130. /** Finds the maximum value in the given array. */
  131. static float JUCE_CALLTYPE findMaximum (const float* src, int numValues) noexcept;
  132. /** Finds the maximum value in the given array. */
  133. static double JUCE_CALLTYPE findMaximum (const double* src, int numValues) noexcept;
  134. /** On Intel CPUs, this method enables or disables the SSE flush-to-zero mode.
  135. Effectively, this is a wrapper around a call to _MM_SET_FLUSH_ZERO_MODE
  136. */
  137. static void JUCE_CALLTYPE enableFlushToZeroMode (bool shouldEnable) noexcept;
  138. /** On Intel CPUs, this method enables the SSE flush-to-zero and denormalised-are-zero modes.
  139. This effectively sets the DAZ and FZ bits of the MXCSR register. It's a convenient thing to
  140. call before audio processing code where you really want to avoid denormalisation performance hits.
  141. */
  142. static void JUCE_CALLTYPE disableDenormalisedNumberSupport() noexcept;
  143. };
  144. #endif // JUCE_FLOATVECTOROPERATIONS_H_INCLUDED