OpenShot Library | libopenshot-audio 0.2.0
juce_FloatVectorOperations.h
1
2/** @weakgroup juce_audio_basics-buffers
3 * @{
4 */
5/*
6 ==============================================================================
7
8 This file is part of the JUCE library.
9 Copyright (c) 2017 - ROLI Ltd.
10
11 JUCE is an open source library subject to commercial or open-source
12 licensing.
13
14 The code included in this file is provided under the terms of the ISC license
15 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
16 To use, copy, modify, and/or distribute this software for any purpose with or
17 without fee is hereby granted provided that the above copyright notice and
18 this permission notice appear in all copies.
19
20 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22 DISCLAIMED.
23
24 ==============================================================================
25*/
26
27namespace juce
28{
29
30#ifndef JUCE_SNAP_TO_ZERO
31 #if JUCE_INTEL
32 #define JUCE_SNAP_TO_ZERO(n) if (! (n < -1.0e-8f || n > 1.0e-8f)) n = 0;
33 #else
34 #define JUCE_SNAP_TO_ZERO(n) ignoreUnused (n)
35 #endif
36#endif
37class ScopedNoDenormals;
38
39//==============================================================================
40/**
41 A collection of simple vector operations on arrays of floats, accelerated with
42 SIMD instructions where possible.
43
44 @tags{Audio}
45*/
47{
48public:
49 //==============================================================================
50 /** Clears a vector of floats. */
51 static void JUCE_CALLTYPE clear (float* dest, int numValues) noexcept;
52
53 /** Clears a vector of doubles. */
54 static void JUCE_CALLTYPE clear (double* dest, int numValues) noexcept;
55
56 /** Copies a repeated value into a vector of floats. */
57 static void JUCE_CALLTYPE fill (float* dest, float valueToFill, int numValues) noexcept;
58
59 /** Copies a repeated value into a vector of doubles. */
60 static void JUCE_CALLTYPE fill (double* dest, double valueToFill, int numValues) noexcept;
61
62 /** Copies a vector of floats. */
63 static void JUCE_CALLTYPE copy (float* dest, const float* src, int numValues) noexcept;
64
65 /** Copies a vector of doubles. */
66 static void JUCE_CALLTYPE copy (double* dest, const double* src, int numValues) noexcept;
67
68 /** Copies a vector of floats, multiplying each value by a given multiplier */
69 static void JUCE_CALLTYPE copyWithMultiply (float* dest, const float* src, float multiplier, int numValues) noexcept;
70
71 /** Copies a vector of doubles, multiplying each value by a given multiplier */
72 static void JUCE_CALLTYPE copyWithMultiply (double* dest, const double* src, double multiplier, int numValues) noexcept;
73
74 /** Adds a fixed value to the destination values. */
75 static void JUCE_CALLTYPE add (float* dest, float amountToAdd, int numValues) noexcept;
76
77 /** Adds a fixed value to the destination values. */
78 static void JUCE_CALLTYPE add (double* dest, double amountToAdd, int numValues) noexcept;
79
80 /** Adds a fixed value to each source value and stores it in the destination array. */
81 static void JUCE_CALLTYPE add (float* dest, const float* src, float amount, int numValues) noexcept;
82
83 /** Adds a fixed value to each source value and stores it in the destination array. */
84 static void JUCE_CALLTYPE add (double* dest, const double* src, double amount, int numValues) noexcept;
85
86 /** Adds the source values to the destination values. */
87 static void JUCE_CALLTYPE add (float* dest, const float* src, int numValues) noexcept;
88
89 /** Adds the source values to the destination values. */
90 static void JUCE_CALLTYPE add (double* dest, const double* src, int numValues) noexcept;
91
92 /** Adds each source1 value to the corresponding source2 value and stores the result in the destination array. */
93 static void JUCE_CALLTYPE add (float* dest, const float* src1, const float* src2, int num) noexcept;
94
95 /** Adds each source1 value to the corresponding source2 value and stores the result in the destination array. */
96 static void JUCE_CALLTYPE add (double* dest, const double* src1, const double* src2, int num) noexcept;
97
98 /** Subtracts the source values from the destination values. */
99 static void JUCE_CALLTYPE subtract (float* dest, const float* src, int numValues) noexcept;
100
101 /** Subtracts the source values from the destination values. */
102 static void JUCE_CALLTYPE subtract (double* dest, const double* src, int numValues) noexcept;
103
104 /** Subtracts each source2 value from the corresponding source1 value and stores the result in the destination array. */
105 static void JUCE_CALLTYPE subtract (float* dest, const float* src1, const float* src2, int num) noexcept;
106
107 /** Subtracts each source2 value from the corresponding source1 value and stores the result in the destination array. */
108 static void JUCE_CALLTYPE subtract (double* dest, const double* src1, const double* src2, int num) noexcept;
109
110 /** Multiplies each source value by the given multiplier, then adds it to the destination value. */
111 static void JUCE_CALLTYPE addWithMultiply (float* dest, const float* src, float multiplier, int numValues) noexcept;
112
113 /** Multiplies each source value by the given multiplier, then adds it to the destination value. */
114 static void JUCE_CALLTYPE addWithMultiply (double* dest, const double* src, double multiplier, int numValues) noexcept;
115
116 /** Multiplies each source1 value by the corresponding source2 value, then adds it to the destination value. */
117 static void JUCE_CALLTYPE addWithMultiply (float* dest, const float* src1, const float* src2, int num) noexcept;
118
119 /** Multiplies each source1 value by the corresponding source2 value, then adds it to the destination value. */
120 static void JUCE_CALLTYPE addWithMultiply (double* dest, const double* src1, const double* src2, int num) noexcept;
121
122 /** Multiplies each source value by the given multiplier, then subtracts it to the destination value. */
123 static void JUCE_CALLTYPE subtractWithMultiply (float* dest, const float* src, float multiplier, int numValues) noexcept;
124
125 /** Multiplies each source value by the given multiplier, then subtracts it to the destination value. */
126 static void JUCE_CALLTYPE subtractWithMultiply (double* dest, const double* src, double multiplier, int numValues) noexcept;
127
128 /** Multiplies each source1 value by the corresponding source2 value, then subtracts it to the destination value. */
129 static void JUCE_CALLTYPE subtractWithMultiply (float* dest, const float* src1, const float* src2, int num) noexcept;
130
131 /** Multiplies each source1 value by the corresponding source2 value, then subtracts it to the destination value. */
132 static void JUCE_CALLTYPE subtractWithMultiply (double* dest, const double* src1, const double* src2, int num) noexcept;
133
134 /** Multiplies the destination values by the source values. */
135 static void JUCE_CALLTYPE multiply (float* dest, const float* src, int numValues) noexcept;
136
137 /** Multiplies the destination values by the source values. */
138 static void JUCE_CALLTYPE multiply (double* dest, const double* src, int numValues) noexcept;
139
140 /** Multiplies each source1 value by the correspinding source2 value, then stores it in the destination array. */
141 static void JUCE_CALLTYPE multiply (float* dest, const float* src1, const float* src2, int numValues) noexcept;
142
143 /** Multiplies each source1 value by the correspinding source2 value, then stores it in the destination array. */
144 static void JUCE_CALLTYPE multiply (double* dest, const double* src1, const double* src2, int numValues) noexcept;
145
146 /** Multiplies each of the destination values by a fixed multiplier. */
147 static void JUCE_CALLTYPE multiply (float* dest, float multiplier, int numValues) noexcept;
148
149 /** Multiplies each of the destination values by a fixed multiplier. */
150 static void JUCE_CALLTYPE multiply (double* dest, double multiplier, int numValues) noexcept;
151
152 /** Multiplies each of the source values by a fixed multiplier and stores the result in the destination array. */
153 static void JUCE_CALLTYPE multiply (float* dest, const float* src, float multiplier, int num) noexcept;
154
155 /** Multiplies each of the source values by a fixed multiplier and stores the result in the destination array. */
156 static void JUCE_CALLTYPE multiply (double* dest, const double* src, double multiplier, int num) noexcept;
157
158 /** Copies a source vector to a destination, negating each value. */
159 static void JUCE_CALLTYPE negate (float* dest, const float* src, int numValues) noexcept;
160
161 /** Copies a source vector to a destination, negating each value. */
162 static void JUCE_CALLTYPE negate (double* dest, const double* src, int numValues) noexcept;
163
164 /** Copies a source vector to a destination, taking the absolute of each value. */
165 static void JUCE_CALLTYPE abs (float* dest, const float* src, int numValues) noexcept;
166
167 /** Copies a source vector to a destination, taking the absolute of each value. */
168 static void JUCE_CALLTYPE abs (double* dest, const double* src, int numValues) noexcept;
169
170 /** Converts a stream of integers to floats, multiplying each one by the given multiplier. */
171 static void JUCE_CALLTYPE convertFixedToFloat (float* dest, const int* src, float multiplier, int numValues) noexcept;
172
173 /** Each element of dest will be the minimum of the corresponding element of the source array and the given comp value. */
174 static void JUCE_CALLTYPE min (float* dest, const float* src, float comp, int num) noexcept;
175
176 /** Each element of dest will be the minimum of the corresponding element of the source array and the given comp value. */
177 static void JUCE_CALLTYPE min (double* dest, const double* src, double comp, int num) noexcept;
178
179 /** Each element of dest will be the minimum of the corresponding source1 and source2 values. */
180 static void JUCE_CALLTYPE min (float* dest, const float* src1, const float* src2, int num) noexcept;
181
182 /** Each element of dest will be the minimum of the corresponding source1 and source2 values. */
183 static void JUCE_CALLTYPE min (double* dest, const double* src1, const double* src2, int num) noexcept;
184
185 /** Each element of dest will be the maximum of the corresponding element of the source array and the given comp value. */
186 static void JUCE_CALLTYPE max (float* dest, const float* src, float comp, int num) noexcept;
187
188 /** Each element of dest will be the maximum of the corresponding element of the source array and the given comp value. */
189 static void JUCE_CALLTYPE max (double* dest, const double* src, double comp, int num) noexcept;
190
191 /** Each element of dest will be the maximum of the corresponding source1 and source2 values. */
192 static void JUCE_CALLTYPE max (float* dest, const float* src1, const float* src2, int num) noexcept;
193
194 /** Each element of dest will be the maximum of the corresponding source1 and source2 values. */
195 static void JUCE_CALLTYPE max (double* dest, const double* src1, const double* src2, int num) noexcept;
196
197 /** 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. */
198 static void JUCE_CALLTYPE clip (float* dest, const float* src, float low, float high, int num) noexcept;
199
200 /** 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. */
201 static void JUCE_CALLTYPE clip (double* dest, const double* src, double low, double high, int num) noexcept;
202
203 /** Finds the minimum and maximum values in the given array. */
204 static Range<float> JUCE_CALLTYPE findMinAndMax (const float* src, int numValues) noexcept;
205
206 /** Finds the minimum and maximum values in the given array. */
207 static Range<double> JUCE_CALLTYPE findMinAndMax (const double* src, int numValues) noexcept;
208
209 /** Finds the minimum value in the given array. */
210 static float JUCE_CALLTYPE findMinimum (const float* src, int numValues) noexcept;
211
212 /** Finds the minimum value in the given array. */
213 static double JUCE_CALLTYPE findMinimum (const double* src, int numValues) noexcept;
214
215 /** Finds the maximum value in the given array. */
216 static float JUCE_CALLTYPE findMaximum (const float* src, int numValues) noexcept;
217
218 /** Finds the maximum value in the given array. */
219 static double JUCE_CALLTYPE findMaximum (const double* src, int numValues) noexcept;
220
221 /** This method enables or disables the SSE/NEON flush-to-zero mode. */
222 static void JUCE_CALLTYPE enableFlushToZeroMode (bool shouldEnable) noexcept;
223
224 /** On Intel CPUs, this method enables the SSE flush-to-zero and denormalised-are-zero modes.
225 This effectively sets the DAZ and FZ bits of the MXCSR register. On arm CPUs this will
226 enable flush to zero mode.
227 It's a convenient thing to call before audio processing code where you really want to
228 avoid denormalisation performance hits.
229 */
230 static void JUCE_CALLTYPE disableDenormalisedNumberSupport (bool shouldDisable = true) noexcept;
231
232 /** This method returns true if denormals are currently disabled. */
233 static bool JUCE_CALLTYPE areDenormalsDisabled() noexcept;
234
235private:
236 friend ScopedNoDenormals;
237
238 static intptr_t JUCE_CALLTYPE getFpStatusRegister() noexcept;
239 static void JUCE_CALLTYPE setFpStatusRegister (intptr_t) noexcept;
240};
241
242//==============================================================================
243/**
244 Helper class providing an RAII-based mechanism for temporarily disabling
245 denormals on your CPU.
246
247 @tags{Audio}
248*/
250{
251public:
252 ScopedNoDenormals() noexcept;
253 ~ScopedNoDenormals() noexcept;
254
255private:
256 #if JUCE_USE_SSE_INTRINSICS || (JUCE_USE_ARM_NEON || defined (__arm64__) || defined (__aarch64__))
258 #endif
259};
260
261} // namespace juce
262
263/** @}*/
Holds a resizable array of primitive or copy-by-value objects.
Definition juce_Array.h:60
A collection of simple vector operations on arrays of floats, accelerated with SIMD instructions wher...
Helper class providing an RAII-based mechanism for temporarily disabling denormals on your CPU.
#define JUCE_API
This macro is added to all JUCE public class declarations.