OpenShot Library | OpenShotAudio 0.2.2
juce_AudioBlock.h
1
2/** @weakgroup juce_dsp-containers
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 By using JUCE, you agree to the terms of both the JUCE 5 End-User License
15 Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
16 27th April 2017).
17
18 End User License Agreement: www.juce.com/juce-5-licence
19 Privacy Policy: www.juce.com/juce-5-privacy-policy
20
21 Or: You may also use this code under the terms of the GPL v3 (see
22 www.gnu.org/licenses).
23
24 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
25 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
26 DISCLAIMED.
27
28 ==============================================================================
29*/
30
31namespace juce
32{
33namespace dsp
34{
35
36#ifndef DOXYGEN
37namespace SampleTypeHelpers // Internal classes needed for handling sample type classes
38{
39 template <typename T, bool = std::is_floating_point<T>::value>
40 struct ElementType
41 {
42 using Type = T;
43 };
44
45 template <typename T>
46 struct ElementType<T, false>
47 {
48 using Type = typename T::value_type;
49 };
50}
51#endif
52
53//==============================================================================
54/**
55 Minimal and lightweight data-structure which contains a list of pointers to
56 channels containing some kind of sample data.
57
58 This class doesn't own any of the data which it points to, it's simply a view
59 into data that is owned elsewhere. You can construct one from some raw data
60 that you've allocated yourself, or give it a HeapBlock to use, or give it
61 an AudioBuffer which it can refer to, but in all cases the user is
62 responsible for making sure that the data doesn't get deleted while there's
63 still an AudioBlock using it.
64
65 @tags{DSP}
66*/
67template <typename SampleType>
69{
70private:
71 template <typename OtherSampleType>
72 using MayUseConvertingConstructor =
73 std::enable_if_t<std::is_same<std::remove_const_t<SampleType>,
74 std::remove_const_t<OtherSampleType>>::value
75 && std::is_const<SampleType>::value
76 && ! std::is_const<OtherSampleType>::value,
77 int>;
78
79public:
80 //==============================================================================
81 using NumericType = typename SampleTypeHelpers::ElementType<SampleType>::Type;
82
83 //==============================================================================
84 /** Create a zero-sized AudioBlock. */
85 AudioBlock() noexcept = default;
86
87 /** Creates an AudioBlock from a pointer to an array of channels.
88 AudioBlock does not copy nor own the memory pointed to by dataToUse.
89 Therefore it is the user's responsibility to ensure that the memory is retained
90 throughout the life-time of the AudioBlock and released when no longer needed.
91 */
92 constexpr AudioBlock (SampleType* const* channelData,
93 size_t numberOfChannels, size_t numberOfSamples) noexcept
94 : channels (channelData),
95 numChannels (static_cast<ChannelCountType> (numberOfChannels)),
96 numSamples (numberOfSamples)
97 {
98 }
99
100 /** Creates an AudioBlock from a pointer to an array of channels.
101 AudioBlock does not copy nor own the memory pointed to by dataToUse.
102 Therefore it is the user's responsibility to ensure that the memory is retained
103 throughout the life-time of the AudioBlock and released when no longer needed.
104 */
105 constexpr AudioBlock (SampleType* const* channelData, size_t numberOfChannels,
106 size_t startSampleIndex, size_t numberOfSamples) noexcept
107 : channels (channelData),
108 numChannels (static_cast<ChannelCountType> (numberOfChannels)),
109 startSample (startSampleIndex),
110 numSamples (numberOfSamples)
111 {
112 }
113
114 /** Allocates a suitable amount of space in a HeapBlock, and initialises this object
115 to point into it.
116 The HeapBlock must of course not be freed or re-allocated while this object is still in
117 use, because it will be referencing its data.
118 */
119 AudioBlock (HeapBlock<char>& heapBlockToUseForAllocation,
120 size_t numberOfChannels, size_t numberOfSamples,
121 size_t alignmentInBytes = defaultAlignment) noexcept
122 : numChannels (static_cast<ChannelCountType> (numberOfChannels)),
123 numSamples (numberOfSamples)
124 {
125 auto roundedUpNumSamples = (numberOfSamples + elementMask) & ~elementMask;
126 auto channelSize = sizeof (SampleType) * roundedUpNumSamples;
127 auto channelListBytes = sizeof (SampleType*) * numberOfChannels;
128 auto extraBytes = alignmentInBytes - 1;
129
130 heapBlockToUseForAllocation.malloc (channelListBytes + extraBytes + channelSize * numberOfChannels);
131
132 auto* chanArray = reinterpret_cast<SampleType**> (heapBlockToUseForAllocation.getData());
133 channels = chanArray;
134
135 auto* data = reinterpret_cast<SampleType*> (addBytesToPointer (chanArray, channelListBytes));
136 data = snapPointerToAlignment (data, alignmentInBytes);
137
138 for (ChannelCountType i = 0; i < numChannels; ++i)
139 {
140 chanArray[i] = data;
141 data += roundedUpNumSamples;
142 }
143 }
144
145 /** Creates an AudioBlock that points to the data in an AudioBuffer.
146 AudioBlock does not copy nor own the memory pointed to by dataToUse.
147 Therefore it is the user's responsibility to ensure that the buffer is retained
148 throughout the life-time of the AudioBlock without being modified.
149 */
150 template <typename OtherSampleType>
151 constexpr AudioBlock (AudioBuffer<OtherSampleType>& buffer) noexcept
152 : channels (buffer.getArrayOfWritePointers()),
153 numChannels (static_cast<ChannelCountType> (buffer.getNumChannels())),
154 numSamples (static_cast<size_t> (buffer.getNumSamples()))
155 {
156 }
157
158 /** Creates an AudioBlock that points to the data in an AudioBuffer.
159 AudioBlock does not copy nor own the memory pointed to by dataToUse.
160 Therefore it is the user's responsibility to ensure that the buffer is retained
161 throughout the life-time of the AudioBlock without being modified.
162 */
163 template <typename OtherSampleType>
164 AudioBlock (AudioBuffer<OtherSampleType>& buffer, size_t startSampleIndex) noexcept
165 : channels (buffer.getArrayOfWritePointers()),
166 numChannels (static_cast<ChannelCountType> (buffer.getNumChannels())),
167 startSample (startSampleIndex),
168 numSamples (static_cast<size_t> (buffer.getNumSamples()) - startSampleIndex)
169 {
170 jassert (startSample < static_cast<size_t> (buffer.getNumSamples()));
171 }
172
173 AudioBlock (const AudioBlock& other) noexcept = default;
174 AudioBlock& operator= (const AudioBlock& other) noexcept = default;
175
176 template <typename OtherSampleType, MayUseConvertingConstructor<OtherSampleType> = 0>
177 AudioBlock (const AudioBlock<OtherSampleType>& other) noexcept
178 : channels { other.channels },
179 numChannels { other.numChannels },
180 startSample { other.startSample },
181 numSamples { other.numSamples }
182 {
183 }
184
185 template <typename OtherSampleType, MayUseConvertingConstructor<OtherSampleType> = 0>
186 AudioBlock& operator= (const AudioBlock<OtherSampleType>& other) noexcept
187 {
188 AudioBlock blockCopy { other };
189 swap (blockCopy);
190 return *this;
191 }
192
193 void swap (AudioBlock& other) noexcept
194 {
195 std::swap (other.channels, channels);
196 std::swap (other.numChannels, numChannels);
197 std::swap (other.startSample, startSample);
198 std::swap (other.numSamples, numSamples);
199 }
200
201 //==============================================================================
202 template <typename OtherSampleType>
203 constexpr bool operator== (const AudioBlock<OtherSampleType>& other) const noexcept
204 {
205 return std::equal (channels,
206 channels + numChannels,
207 other.channels,
208 other.channels + other.numChannels)
209 && startSample == other.startSample
210 && numSamples == other.numSamples;
211 }
212
213 template <typename OtherSampleType>
214 constexpr bool operator!= (const AudioBlock<OtherSampleType>& other) const noexcept
215 {
216 return ! (*this == other);
217 }
218
219 //==============================================================================
220 /** Returns the number of channels referenced by this block. */
221 constexpr size_t getNumChannels() const noexcept { return static_cast<size_t> (numChannels); }
222
223 /** Returns the number of samples referenced by this block. */
224 constexpr size_t getNumSamples() const noexcept { return numSamples; }
225
226 /** Returns a raw pointer into one of the channels in this block. */
227 SampleType* getChannelPointer (size_t channel) const noexcept
228 {
229 jassert (channel < numChannels);
230 jassert (numSamples > 0);
231 return channels[channel] + startSample;
232 }
233
234 /** Returns an AudioBlock that represents one of the channels in this block. */
235 AudioBlock getSingleChannelBlock (size_t channel) const noexcept
236 {
237 jassert (channel < numChannels);
238 return AudioBlock (channels + channel, 1, startSample, numSamples);
239 }
240
241 /** Returns a subset of contiguous channels
242 @param channelStart First channel of the subset
243 @param numChannelsToUse Count of channels in the subset
244 */
245 AudioBlock getSubsetChannelBlock (size_t channelStart, size_t numChannelsToUse) const noexcept
246 {
247 jassert (channelStart < numChannels);
248 jassert ((channelStart + numChannelsToUse) <= numChannels);
249
250 return AudioBlock (channels + channelStart, numChannelsToUse, startSample, numSamples);
251 }
252
253 /** Returns a sample from the buffer.
254 The channel and index are not checked - they are expected to be in-range. If not,
255 an assertion will be thrown, but in a release build, you're into 'undefined behaviour'
256 territory.
257 */
258 SampleType getSample (int channel, int sampleIndex) const noexcept
259 {
260 jassert (isPositiveAndBelow (channel, numChannels));
261 jassert (isPositiveAndBelow (sampleIndex, numSamples));
262 return channels[channel][(size_t) startSample + (size_t) sampleIndex];
263 }
264
265 /** Modifies a sample in the buffer.
266 The channel and index are not checked - they are expected to be in-range. If not,
267 an assertion will be thrown, but in a release build, you're into 'undefined behaviour'
268 territory.
269 */
270 void setSample (int destChannel, int destSample, SampleType newValue) const noexcept
271 {
272 jassert (isPositiveAndBelow (destChannel, numChannels));
273 jassert (isPositiveAndBelow (destSample, numSamples));
274 channels[destChannel][(size_t) startSample + (size_t) destSample] = newValue;
275 }
276
277 /** Adds a value to a sample in the buffer.
278 The channel and index are not checked - they are expected to be in-range. If not,
279 an assertion will be thrown, but in a release build, you're into 'undefined behaviour'
280 territory.
281 */
282 void addSample (int destChannel, int destSample, SampleType valueToAdd) const noexcept
283 {
284 jassert (isPositiveAndBelow (destChannel, numChannels));
285 jassert (isPositiveAndBelow (destSample, numSamples));
286 channels[destChannel][(size_t) startSample + (size_t) destSample] += valueToAdd;
287 }
288
289 //==============================================================================
290 /** Clears the memory referenced by this AudioBlock. */
291 AudioBlock& clear() noexcept { clearInternal(); return *this; }
292 const AudioBlock& clear() const noexcept { clearInternal(); return *this; }
293
294 /** Fills the memory referenced by this AudioBlock with value. */
295 AudioBlock& JUCE_VECTOR_CALLTYPE fill (NumericType value) noexcept { fillInternal (value); return *this; }
296 const AudioBlock& JUCE_VECTOR_CALLTYPE fill (NumericType value) const noexcept { fillInternal (value); return *this; }
297
298 /** Copies the values in src to this block. */
299 template <typename OtherSampleType>
300 AudioBlock& copyFrom (const AudioBlock<OtherSampleType>& src) noexcept { copyFromInternal (src); return *this; }
301 template <typename OtherSampleType>
302 const AudioBlock& copyFrom (const AudioBlock<OtherSampleType>& src) const noexcept { copyFromInternal (src); return *this; }
303
304 /** Copy the values from an AudioBuffer to this block.
305
306 All indices and sizes are in this AudioBlock's units, i.e. if SampleType is a
307 SIMDRegister then incrementing srcPos by one will increase the sample position
308 in the AudioBuffer's units by a factor of SIMDRegister<SampleType>::SIMDNumElements.
309 */
310 template <typename OtherNumericType>
312 size_t srcPos = 0, size_t dstPos = 0,
313 size_t numElements = std::numeric_limits<size_t>::max()) { copyFromInternal (src, srcPos, dstPos, numElements); return *this; }
314 template <typename OtherNumericType>
316 size_t srcPos = 0, size_t dstPos = 0,
317 size_t numElements = std::numeric_limits<size_t>::max()) const { copyFromInternal (src, srcPos, dstPos, numElements); return *this; }
318
319
320 /** Copies the values from this block to an AudioBuffer.
321
322 All indices and sizes are in this AudioBlock's units, i.e. if SampleType is a
323 SIMDRegister then incrementing dstPos by one will increase the sample position
324 in the AudioBuffer's units by a factor of SIMDRegister<SampleType>::SIMDNumElements.
325 */
326 void copyTo (AudioBuffer<typename std::remove_const<NumericType>::type>& dst, size_t srcPos = 0, size_t dstPos = 0,
327 size_t numElements = std::numeric_limits<size_t>::max()) const
328 {
329 auto dstlen = static_cast<size_t> (dst.getNumSamples()) / sizeFactor;
330 auto n = static_cast<int> (jmin (numSamples - srcPos, dstlen - dstPos, numElements) * sizeFactor);
331 auto maxChannels = jmin (static_cast<size_t> (dst.getNumChannels()), static_cast<size_t> (numChannels));
332
333 for (size_t ch = 0; ch < maxChannels; ++ch)
334 FloatVectorOperations::copy (dst.getWritePointer (static_cast<int> (ch),
335 static_cast<int> (dstPos * sizeFactor)),
336 getDataPointer (ch) + (srcPos * sizeFactor),
337 n);
338 }
339
340 /** Move memory within this block from the position srcPos to the position dstPos.
341 If numElements is not specified then move will move the maximum amount of memory.
342 */
343 AudioBlock& move (size_t srcPos, size_t dstPos,
344 size_t numElements = std::numeric_limits<size_t>::max()) noexcept { moveInternal (srcPos, dstPos, numElements); return *this; }
345 const AudioBlock& move (size_t srcPos, size_t dstPos,
346 size_t numElements = std::numeric_limits<size_t>::max()) const noexcept { moveInternal (srcPos, dstPos, numElements); return *this; }
347
348 //==============================================================================
349 /** Return a new AudioBlock pointing to a sub-block inside this block. This
350 function does not copy the memory and you must ensure that the original memory
351 pointed to by the receiver remains valid through-out the life-time of the
352 returned sub-block.
353
354 @param newOffset The index of an element inside the receiver which will
355 will become the first element of the return value.
356 @param newLength The number of elements of the newly created sub-block.
357 */
358 AudioBlock getSubBlock (size_t newOffset, size_t newLength) const noexcept
359 {
360 jassert (newOffset < numSamples);
361 jassert (newOffset + newLength <= numSamples);
362
363 return AudioBlock (channels, numChannels, startSample + newOffset, newLength);
364 }
365
366 /** Return a new AudioBlock pointing to a sub-block inside this block. This
367 function does not copy the memory and you must ensure that the original memory
368 pointed to by the receiver remains valid through-out the life-time of the
369 returned sub-block.
370
371 @param newOffset The index of an element inside the block which will
372 will become the first element of the return value.
373 The return value will include all subsequent elements
374 of the receiver.
375 */
376 AudioBlock getSubBlock (size_t newOffset) const noexcept
377 {
378 return getSubBlock (newOffset, getNumSamples() - newOffset);
379 }
380
381 //==============================================================================
382 /** Adds a fixed value to the elements in this block. */
383 AudioBlock& JUCE_VECTOR_CALLTYPE add (NumericType value) noexcept { addInternal (value); return *this; }
384 const AudioBlock& JUCE_VECTOR_CALLTYPE add (NumericType value) const noexcept { addInternal (value); return *this; }
385
386 /** Adds the elements in the src block to the elements in this block. */
387 template <typename OtherSampleType>
388 AudioBlock& add (AudioBlock<OtherSampleType> src) noexcept { addInternal (src); return *this; }
389 template <typename OtherSampleType>
390 const AudioBlock& add (AudioBlock<OtherSampleType> src) const noexcept { addInternal (src); return *this; }
391
392 /** Adds a fixed value to each source value and replaces the contents of this block. */
393 template <typename OtherSampleType>
394 AudioBlock& JUCE_VECTOR_CALLTYPE replaceWithSumOf (AudioBlock<OtherSampleType> src, NumericType value) noexcept { replaceWithSumOfInternal (src, value); return *this; }
395 template <typename OtherSampleType>
396 const AudioBlock& JUCE_VECTOR_CALLTYPE replaceWithSumOf (AudioBlock<OtherSampleType> src, NumericType value) const noexcept { replaceWithSumOfInternal (src, value); return *this; }
397
398 /** Adds each source1 value to the corresponding source2 value and replaces the contents of this block. */
399 template <typename Src1SampleType, typename Src2SampleType>
400 AudioBlock& replaceWithSumOf (AudioBlock<Src1SampleType> src1, AudioBlock<Src2SampleType> src2) noexcept { replaceWithSumOfInternal (src1, src2); return *this; }
401 template <typename Src1SampleType, typename Src2SampleType>
402 const AudioBlock& replaceWithSumOf (AudioBlock<Src1SampleType> src1, AudioBlock<Src2SampleType> src2) const noexcept { replaceWithSumOfInternal (src1, src2); return *this; }
403
404 //==============================================================================
405 /** Subtracts a fixed value from the elements in this block. */
406 AudioBlock& JUCE_VECTOR_CALLTYPE subtract (NumericType value) noexcept { subtractInternal (value); return *this; }
407 const AudioBlock& JUCE_VECTOR_CALLTYPE subtract (NumericType value) const noexcept { subtractInternal (value); return *this; }
408
409 /** Subtracts the source values from the elements in this block. */
410 template <typename OtherSampleType>
411 AudioBlock& subtract (AudioBlock<OtherSampleType> src) noexcept { subtractInternal (src); return *this; }
412 template <typename OtherSampleType>
413 const AudioBlock& subtract (AudioBlock<OtherSampleType> src) const noexcept { subtractInternal (src); return *this; }
414
415 /** Subtracts a fixed value from each source value and replaces the contents of this block. */
416 template <typename OtherSampleType>
417 AudioBlock& JUCE_VECTOR_CALLTYPE replaceWithDifferenceOf (AudioBlock<OtherSampleType> src, NumericType value) noexcept { replaceWithDifferenceOfInternal (src, value); return *this; }
418 template <typename OtherSampleType>
419 const AudioBlock& JUCE_VECTOR_CALLTYPE replaceWithDifferenceOf (AudioBlock<OtherSampleType> src, NumericType value) const noexcept { replaceWithDifferenceOfInternal (src, value); return *this; }
420
421 /** Subtracts each source2 value from the corresponding source1 value and replaces the contents of this block. */
422 template <typename Src1SampleType, typename Src2SampleType>
423 AudioBlock& replaceWithDifferenceOf (AudioBlock<Src1SampleType> src1, AudioBlock<Src2SampleType> src2) noexcept { replaceWithDifferenceOfInternal (src1, src2); return *this; }
424 template <typename Src1SampleType, typename Src2SampleType>
425 const AudioBlock& replaceWithDifferenceOf (AudioBlock<Src1SampleType> src1, AudioBlock<Src2SampleType> src2) const noexcept { replaceWithDifferenceOfInternal (src1, src2); return *this; }
426
427 //==============================================================================
428 /** Multiplies the elements in this block by a fixed value. */
429 AudioBlock& JUCE_VECTOR_CALLTYPE multiplyBy (NumericType value) noexcept { multiplyByInternal (value); return *this; }
430 const AudioBlock& JUCE_VECTOR_CALLTYPE multiplyBy (NumericType value) const noexcept { multiplyByInternal (value); return *this; }
431
432 /** Multiplies the elements in this block by the elements in the src block */
433 template <typename OtherSampleType>
434 AudioBlock& multiplyBy (AudioBlock<OtherSampleType> src) noexcept { multiplyByInternal (src); return *this; }
435 template <typename OtherSampleType>
436 const AudioBlock& multiplyBy (AudioBlock<OtherSampleType> src) const noexcept { multiplyByInternal (src); return *this; }
437
438 /** Replaces the elements in this block with the product of the elements in the source src block and a fixed value. */
439 template <typename OtherSampleType>
440 AudioBlock& JUCE_VECTOR_CALLTYPE replaceWithProductOf (AudioBlock<OtherSampleType> src, NumericType value) noexcept { replaceWithProductOfInternal (src, value); return *this; }
441 template <typename OtherSampleType>
442 const AudioBlock& JUCE_VECTOR_CALLTYPE replaceWithProductOf (AudioBlock<OtherSampleType> src, NumericType value) const noexcept { replaceWithProductOfInternal (src, value); return *this; }
443
444 /** Replaces the elements in this block with the product of the elements in the src1 and scr2 blocks. */
445 template <typename Src1SampleType, typename Src2SampleType>
446 AudioBlock& replaceWithProductOf (AudioBlock<Src1SampleType> src1, AudioBlock<Src2SampleType> src2) noexcept { replaceWithProductOfInternal (src1, src2); return *this; }
447 template <typename Src1SampleType, typename Src2SampleType>
448 const AudioBlock& replaceWithProductOf (AudioBlock<Src1SampleType> src1, AudioBlock<Src2SampleType> src2) const noexcept { replaceWithProductOfInternal (src1, src2); return *this; }
449
450 //==============================================================================
451 /** Multiplies each channels of this block by a smoothly changing value. */
452 template <typename SmoothingType>
453 AudioBlock& multiplyBy (SmoothedValue<SampleType, SmoothingType>& value) noexcept { multiplyByInternal (value); return *this; }
454 template <typename SmoothingType>
455 const AudioBlock& multiplyBy (SmoothedValue<SampleType, SmoothingType>& value) const noexcept { multiplyByInternal (value); return *this; }
456
457 /** Replaces each channel of this block with the product of the src block and a smoothed value. */
458 template <typename OtherSampleType, typename SmoothingType>
459 AudioBlock& replaceWithProductOf (AudioBlock<OtherSampleType> src, SmoothedValue<SampleType, SmoothingType>& value) noexcept { replaceWithProductOfInternal (src, value); return *this; }
460 template <typename OtherSampleType, typename SmoothingType>
461 const AudioBlock& replaceWithProductOf (AudioBlock<OtherSampleType> src, SmoothedValue<SampleType, SmoothingType>& value) const noexcept { replaceWithProductOfInternal (src, value); return *this; }
462
463 //==============================================================================
464 /** Multiplies each value in src by a fixed value and adds the result to this block. */
465 template <typename OtherSampleType>
466 AudioBlock& JUCE_VECTOR_CALLTYPE addProductOf (AudioBlock<OtherSampleType> src, NumericType factor) noexcept { addProductOfInternal (src, factor); return *this; }
467 template <typename OtherSampleType>
468 const AudioBlock& JUCE_VECTOR_CALLTYPE addProductOf (AudioBlock<OtherSampleType> src, NumericType factor) const noexcept { addProductOfInternal (src, factor); return *this; }
469
470 /** Multiplies each value in srcA with the corresponding value in srcB and adds the result to this block. */
471 template <typename Src1SampleType, typename Src2SampleType>
472 AudioBlock& addProductOf (AudioBlock<Src1SampleType> src1, AudioBlock<Src2SampleType> src2) noexcept { addProductOfInternal (src1, src2); return *this; }
473 template <typename Src1SampleType, typename Src2SampleType>
474 const AudioBlock& addProductOf (AudioBlock<Src1SampleType> src1, AudioBlock<Src2SampleType> src2) const noexcept { addProductOfInternal (src1, src2); return *this; }
475
476 //==============================================================================
477 /** Negates each value of this block. */
478 AudioBlock& negate() noexcept { negateInternal(); return *this; }
479 const AudioBlock& negate() const noexcept { negateInternal(); return *this; }
480
481 /** Replaces the contents of this block with the negative of the values in the src block. */
482 template <typename OtherSampleType>
483 AudioBlock& replaceWithNegativeOf (AudioBlock<OtherSampleType> src) noexcept { replaceWithNegativeOfInternal (src); return *this; }
484 template <typename OtherSampleType>
485 const AudioBlock& replaceWithNegativeOf (AudioBlock<OtherSampleType> src) const noexcept { replaceWithNegativeOfInternal (src); return *this; }
486
487 /** Replaces the contents of this block with the absolute values of the src block. */
488 template <typename OtherSampleType>
489 AudioBlock& replaceWithAbsoluteValueOf (AudioBlock<OtherSampleType> src) noexcept { replaceWithAbsoluteValueOfInternal (src); return *this; }
490 template <typename OtherSampleType>
491 const AudioBlock& replaceWithAbsoluteValueOf (AudioBlock<OtherSampleType> src) const noexcept { replaceWithAbsoluteValueOfInternal (src); return *this; }
492
493 //==============================================================================
494 /** Replaces each element of this block with the minimum of the corresponding element of the source arrays. */
495 template <typename Src1SampleType, typename Src2SampleType>
496 AudioBlock& replaceWithMinOf (AudioBlock<Src1SampleType> src1, AudioBlock<Src2SampleType> src2) noexcept { replaceWithMinOfInternal (src1, src2); return *this; }
497 template <typename Src1SampleType, typename Src2SampleType>
498 const AudioBlock& replaceWithMinOf (AudioBlock<Src1SampleType> src1, AudioBlock<Src2SampleType> src2) const noexcept { replaceWithMinOfInternal (src1, src2); return *this; }
499
500 /** Replaces each element of this block with the maximum of the corresponding element of the source arrays. */
501 template <typename Src1SampleType, typename Src2SampleType>
502 AudioBlock& replaceWithMaxOf (AudioBlock<Src1SampleType> src1, AudioBlock<Src2SampleType> src2) noexcept { replaceWithMaxOfInternal (src1, src2); return *this; }
503 template <typename Src1SampleType, typename Src2SampleType>
504 const AudioBlock& replaceWithMaxOf (AudioBlock<Src1SampleType> src1, AudioBlock<Src2SampleType> src2) const noexcept { replaceWithMaxOfInternal (src1, src2); return *this; }
505
506 //==============================================================================
507 /** Finds the minimum and maximum value of the buffer. */
509 {
510 if (numChannels == 0)
511 return {};
512
513 auto n = static_cast<int> (numSamples * sizeFactor);
514 auto minmax = FloatVectorOperations::findMinAndMax (getDataPointer (0), n);
515
516 for (size_t ch = 1; ch < numChannels; ++ch)
517 minmax = minmax.getUnionWith (FloatVectorOperations::findMinAndMax (getDataPointer (ch), n));
518
519 return minmax;
520 }
521
522 //==============================================================================
523 // Convenient operator wrappers.
524 AudioBlock& JUCE_VECTOR_CALLTYPE operator+= (NumericType value) noexcept { return add (value); }
525 const AudioBlock& JUCE_VECTOR_CALLTYPE operator+= (NumericType value) const noexcept { return add (value); }
526
527 AudioBlock& operator+= (AudioBlock src) noexcept { return add (src); }
528 const AudioBlock& operator+= (AudioBlock src) const noexcept { return add (src); }
529
530 AudioBlock& JUCE_VECTOR_CALLTYPE operator-= (NumericType value) noexcept { return subtract (value); }
531 const AudioBlock& JUCE_VECTOR_CALLTYPE operator-= (NumericType value) const noexcept { return subtract (value); }
532
533 AudioBlock& operator-= (AudioBlock src) noexcept { return subtract (src); }
534 const AudioBlock& operator-= (AudioBlock src) const noexcept { return subtract (src); }
535
536 AudioBlock& JUCE_VECTOR_CALLTYPE operator*= (NumericType value) noexcept { return multiplyBy (value); }
537 const AudioBlock& JUCE_VECTOR_CALLTYPE operator*= (NumericType value) const noexcept { return multiplyBy (value); }
538
539 AudioBlock& operator*= (AudioBlock src) noexcept { return multiplyBy (src); }
540 const AudioBlock& operator*= (AudioBlock src) const noexcept { return multiplyBy (src); }
541
542 template <typename SmoothingType>
543 AudioBlock& operator*= (SmoothedValue<SampleType, SmoothingType>& value) noexcept { return multiplyBy (value); }
544 template <typename SmoothingType>
545 const AudioBlock& operator*= (SmoothedValue<SampleType, SmoothingType>& value) const noexcept { return multiplyBy (value); }
546
547 //==============================================================================
548 // This class can only be used with floating point types
549 static_assert (std::is_same<std::remove_const_t<SampleType>, float>::value
550 || std::is_same<std::remove_const_t<SampleType>, double>::value
551 #if JUCE_USE_SIMD
552 || std::is_same<std::remove_const_t<SampleType>, SIMDRegister<float>>::value
553 || std::is_same<std::remove_const_t<SampleType>, SIMDRegister<double>>::value
554 #endif
555 , "AudioBlock only supports single or double precision floating point types");
556
557 //==============================================================================
558 /** Applies a function to each value in an input block, putting the result into an output block.
559 The function supplied must take a SampleType as its parameter, and return a SampleType.
560 The two blocks must have the same number of channels and samples.
561 */
562 template <typename Src1SampleType, typename Src2SampleType, typename FunctionType>
563 static void process (AudioBlock<Src1SampleType> inBlock, AudioBlock<Src2SampleType> outBlock, FunctionType&& function)
564 {
565 auto len = inBlock.getNumSamples();
566 auto numChans = inBlock.getNumChannels();
567
568 jassert (len == outBlock.getNumSamples());
569 jassert (numChans == outBlock.getNumChannels());
570
571 for (ChannelCountType c = 0; c < numChans; ++c)
572 {
573 auto* src = inBlock.getChannelPointer (c);
574 auto* dst = outBlock.getChannelPointer (c);
575
576 for (size_t i = 0; i < len; ++i)
577 dst[i] = function (src[i]);
578 }
579 }
580
581private:
582 NumericType* getDataPointer (size_t channel) const noexcept
583 {
584 return reinterpret_cast<NumericType*> (getChannelPointer (channel));
585 }
586
587 //==============================================================================
588 void JUCE_VECTOR_CALLTYPE clearInternal() const noexcept
589 {
590 auto n = static_cast<int> (numSamples * sizeFactor);
591
592 for (size_t ch = 0; ch < numChannels; ++ch)
593 FloatVectorOperations::clear (getDataPointer (ch), n);
594 }
595
596 void JUCE_VECTOR_CALLTYPE fillInternal (NumericType value) const noexcept
597 {
598 auto n = static_cast<int> (numSamples * sizeFactor);
599
600 for (size_t ch = 0; ch < numChannels; ++ch)
601 FloatVectorOperations::fill (getDataPointer (ch), value, n);
602 }
603
604 template <typename OtherSampleType>
605 void copyFromInternal (const AudioBlock<OtherSampleType>& src) const noexcept
606 {
607 auto maxChannels = jmin (src.numChannels, numChannels);
608 auto n = static_cast<int> (jmin (src.numSamples * src.sizeFactor,
609 numSamples * sizeFactor));
610
611 for (size_t ch = 0; ch < maxChannels; ++ch)
612 FloatVectorOperations::copy (getDataPointer (ch), src.getDataPointer (ch), n);
613 }
614
615 template <typename OtherNumericType>
616 void copyFromInternal (const AudioBuffer<OtherNumericType>& src, size_t srcPos, size_t dstPos, size_t numElements) const
617 {
618 auto srclen = static_cast<size_t> (src.getNumSamples()) / sizeFactor;
619 auto n = static_cast<int> (jmin (srclen - srcPos, numSamples - dstPos, numElements) * sizeFactor);
620 auto maxChannels = jmin (static_cast<size_t> (src.getNumChannels()), static_cast<size_t> (numChannels));
621
622 for (size_t ch = 0; ch < maxChannels; ++ch)
623 FloatVectorOperations::copy (getDataPointer (ch) + (dstPos * sizeFactor),
624 src.getReadPointer (static_cast<int> (ch),
625 static_cast<int> (srcPos * sizeFactor)),
626 n);
627 }
628
629 void moveInternal (size_t srcPos, size_t dstPos,
630 size_t numElements = std::numeric_limits<size_t>::max()) const noexcept
631 {
632 jassert (srcPos <= numSamples && dstPos <= numSamples);
633 auto len = jmin (numSamples - srcPos, numSamples - dstPos, numElements) * sizeof (SampleType);
634
635 if (len != 0)
636 for (size_t ch = 0; ch < numChannels; ++ch)
637 ::memmove (getChannelPointer (ch) + dstPos,
638 getChannelPointer (ch) + srcPos, len);
639 }
640
641 //==============================================================================
642 void JUCE_VECTOR_CALLTYPE addInternal (NumericType value) const noexcept
643 {
644 auto n = static_cast<int> (numSamples * sizeFactor);
645
646 for (size_t ch = 0; ch < numChannels; ++ch)
647 FloatVectorOperations::add (getDataPointer (ch), value, n);
648 }
649
650 template <typename OtherSampleType>
651 void addInternal (AudioBlock<OtherSampleType> src) const noexcept
652 {
653 jassert (numChannels == src.numChannels);
654 auto n = static_cast<int> (jmin (numSamples, src.numSamples) * sizeFactor);
655
656 for (size_t ch = 0; ch < numChannels; ++ch)
657 FloatVectorOperations::add (getDataPointer (ch), src.getDataPointer (ch), n);
658 }
659
660 template <typename OtherSampleType>
661 void JUCE_VECTOR_CALLTYPE replaceWithSumOfInternal (AudioBlock<OtherSampleType> src, NumericType value) const noexcept
662 {
663 jassert (numChannels == src.numChannels);
664 auto n = static_cast<int> (jmin (numSamples, src.numSamples) * sizeFactor);
665
666 for (size_t ch = 0; ch < numChannels; ++ch)
667 FloatVectorOperations::add (getDataPointer (ch), src.getDataPointer (ch), value, n);
668 }
669
670 template <typename Src1SampleType, typename Src2SampleType>
671 void replaceWithSumOfInternal (AudioBlock<Src1SampleType> src1, AudioBlock<Src2SampleType> src2) const noexcept
672 {
673 jassert (numChannels == src1.numChannels && src1.numChannels == src2.numChannels);
674 auto n = static_cast<int> (jmin (numSamples, src1.numSamples, src2.numSamples) * sizeFactor);
675
676 for (size_t ch = 0; ch < numChannels; ++ch)
677 FloatVectorOperations::add (getDataPointer (ch), src1.getDataPointer (ch), src2.getDataPointer (ch), n);
678 }
679
680 //==============================================================================
681 constexpr void JUCE_VECTOR_CALLTYPE subtractInternal (NumericType value) const noexcept
682 {
683 addInternal (value * static_cast<NumericType> (-1.0));
684 }
685
686 template <typename OtherSampleType>
687 void subtractInternal (AudioBlock<OtherSampleType> src) const noexcept
688 {
689 jassert (numChannels == src.numChannels);
690 auto n = static_cast<int> (jmin (numSamples, src.numSamples) * sizeFactor);
691
692 for (size_t ch = 0; ch < numChannels; ++ch)
693 FloatVectorOperations::subtract (getDataPointer (ch), src.getDataPointer (ch), n);
694 }
695
696 template <typename OtherSampleType>
697 void JUCE_VECTOR_CALLTYPE replaceWithDifferenceOfInternal (AudioBlock<OtherSampleType> src, NumericType value) const noexcept
698 {
699 replaceWithSumOfInternal (src, static_cast<NumericType> (-1.0) * value);
700 }
701
702 template <typename Src1SampleType, typename Src2SampleType>
703 void replaceWithDifferenceOfInternal (AudioBlock<Src1SampleType> src1, AudioBlock<Src2SampleType> src2) const noexcept
704 {
705 jassert (numChannels == src1.numChannels && src1.numChannels == src2.numChannels);
706 auto n = static_cast<int> (jmin (numSamples, src1.numSamples, src2.numSamples) * sizeFactor);
707
708 for (size_t ch = 0; ch < numChannels; ++ch)
709 FloatVectorOperations::subtract (getDataPointer (ch), src1.getDataPointer (ch), src2.getDataPointer (ch), n);
710 }
711
712 //==============================================================================
713 void JUCE_VECTOR_CALLTYPE multiplyByInternal (NumericType value) const noexcept
714 {
715 auto n = static_cast<int> (numSamples * sizeFactor);
716
717 for (size_t ch = 0; ch < numChannels; ++ch)
718 FloatVectorOperations::multiply (getDataPointer (ch), value, n);
719 }
720
721 template <typename OtherSampleType>
722 void multiplyByInternal (AudioBlock<OtherSampleType> src) const noexcept
723 {
724 jassert (numChannels == src.numChannels);
725 auto n = static_cast<int> (jmin (numSamples, src.numSamples) * sizeFactor);
726
727 for (size_t ch = 0; ch < numChannels; ++ch)
728 FloatVectorOperations::multiply (getDataPointer (ch), src.getDataPointer (ch), n);
729 }
730
731 template <typename OtherSampleType>
732 void JUCE_VECTOR_CALLTYPE replaceWithProductOfInternal (AudioBlock<OtherSampleType> src, NumericType value) const noexcept
733 {
734 jassert (numChannels == src.numChannels);
735 auto n = static_cast<int> (jmin (numSamples, src.numSamples) * sizeFactor);
736
737 for (size_t ch = 0; ch < numChannels; ++ch)
738 FloatVectorOperations::multiply (getDataPointer (ch), src.getDataPointer (ch), value, n);
739 }
740
741 template <typename Src1SampleType, typename Src2SampleType>
742 void replaceWithProductOfInternal (AudioBlock<Src1SampleType> src1, AudioBlock<Src2SampleType> src2) const noexcept
743 {
744 jassert (numChannels == src1.numChannels && src1.numChannels == src2.numChannels);
745 auto n = static_cast<int> (jmin (numSamples, src1.numSamples, src2.numSamples) * sizeFactor);
746
747 for (size_t ch = 0; ch < numChannels; ++ch)
748 FloatVectorOperations::multiply (getDataPointer (ch), src1.getDataPointer (ch), src2.getDataPointer (ch), n);
749 }
750
751 template <typename SmoothingType>
752 void multiplyByInternal (SmoothedValue<SampleType, SmoothingType>& value) const noexcept
753 {
754 if (! value.isSmoothing())
755 {
756 multiplyByInternal (value.getTargetValue());
757 }
758 else
759 {
760 for (size_t i = 0; i < numSamples; ++i)
761 {
762 const auto scaler = value.getNextValue();
763
764 for (size_t ch = 0; ch < numChannels; ++ch)
765 getDataPointer (ch)[i] *= scaler;
766 }
767 }
768 }
769
770 template <typename OtherSampleType, typename SmoothingType>
771 void replaceWithProductOfInternal (AudioBlock<OtherSampleType> src, SmoothedValue<SampleType, SmoothingType>& value) const noexcept
772 {
773 jassert (numChannels == src.numChannels);
774
775 if (! value.isSmoothing())
776 {
777 replaceWithProductOfInternal (src, value.getTargetValue());
778 }
779 else
780 {
781 auto n = jmin (numSamples, src.numSamples) * sizeFactor;
782
783 for (size_t i = 0; i < n; ++i)
784 {
785 const auto scaler = value.getNextValue();
786
787 for (size_t ch = 0; ch < numChannels; ++ch)
788 getDataPointer (ch)[i] = scaler * src.getChannelPointer (ch)[i];
789 }
790 }
791 }
792
793 //==============================================================================
794 template <typename OtherSampleType>
795 void JUCE_VECTOR_CALLTYPE addProductOfInternal (AudioBlock<OtherSampleType> src, NumericType factor) const noexcept
796 {
797 jassert (numChannels == src.numChannels);
798 auto n = static_cast<int> (jmin (numSamples, src.numSamples) * sizeFactor);
799
800 for (size_t ch = 0; ch < numChannels; ++ch)
801 FloatVectorOperations::addWithMultiply (getDataPointer (ch), src.getDataPointer (ch), factor, n);
802 }
803
804 template <typename Src1SampleType, typename Src2SampleType>
805 void addProductOfInternal (AudioBlock<Src1SampleType> src1, AudioBlock<Src2SampleType> src2) const noexcept
806 {
807 jassert (numChannels == src1.numChannels && src1.numChannels == src2.numChannels);
808 auto n = static_cast<int> (jmin (numSamples, src1.numSamples, src2.numSamples) * sizeFactor);
809
810 for (size_t ch = 0; ch < numChannels; ++ch)
811 FloatVectorOperations::addWithMultiply (getDataPointer (ch), src1.getDataPointer (ch), src2.getDataPointer (ch), n);
812 }
813
814 //==============================================================================
815 constexpr void negateInternal() const noexcept
816 {
817 multiplyByInternal (static_cast<NumericType> (-1.0));
818 }
819
820 template <typename OtherSampleType>
821 void replaceWithNegativeOfInternal (AudioBlock<OtherSampleType> src) const noexcept
822 {
823 jassert (numChannels == src.numChannels);
824 auto n = static_cast<int> (jmin (numSamples, src.numSamples) * sizeFactor);
825
826 for (size_t ch = 0; ch < numChannels; ++ch)
827 FloatVectorOperations::negate (getDataPointer (ch), src.getDataPointer (ch), n);
828 }
829
830 template <typename OtherSampleType>
831 void replaceWithAbsoluteValueOfInternal (AudioBlock<OtherSampleType> src) const noexcept
832 {
833 jassert (numChannels == src.numChannels);
834 auto n = static_cast<int> (jmin (numSamples, src.numSamples) * sizeFactor);
835
836 for (size_t ch = 0; ch < numChannels; ++ch)
837 FloatVectorOperations::abs (getDataPointer (ch), src.getDataPointer (ch), n);
838 }
839
840 //==============================================================================
841 template <typename Src1SampleType, typename Src2SampleType>
842 void replaceWithMinOfInternal (AudioBlock<Src1SampleType> src1, AudioBlock<Src2SampleType> src2) const noexcept
843 {
844 jassert (numChannels == src1.numChannels && src1.numChannels == src2.numChannels);
845 auto n = static_cast<int> (jmin (src1.numSamples, src2.numSamples, numSamples) * sizeFactor);
846
847 for (size_t ch = 0; ch < numChannels; ++ch)
848 FloatVectorOperations::min (getDataPointer (ch), src1.getDataPointer (ch), src2.getDataPointer (ch), n);
849 }
850
851 template <typename Src1SampleType, typename Src2SampleType>
852 void replaceWithMaxOfInternal (AudioBlock<Src1SampleType> src1, AudioBlock<Src2SampleType> src2) const noexcept
853 {
854 jassert (numChannels == src1.numChannels && src1.numChannels == src2.numChannels);
855 auto n = static_cast<int> (jmin (src1.numSamples, src2.numSamples, numSamples) * sizeFactor);
856
857 for (size_t ch = 0; ch < numChannels; ++ch)
858 FloatVectorOperations::max (getDataPointer (ch), src1.getDataPointer (ch), src2.getDataPointer (ch), n);
859 }
860
861 //==============================================================================
862 using ChannelCountType = unsigned int;
863
864 //==============================================================================
865 static constexpr size_t sizeFactor = sizeof (SampleType) / sizeof (NumericType);
866 static constexpr size_t elementMask = sizeFactor - 1;
867 static constexpr size_t byteMask = (sizeFactor * sizeof (NumericType)) - 1;
868
869 #if JUCE_USE_SIMD
870 static constexpr size_t defaultAlignment = sizeof (SIMDRegister<NumericType>);
871 #else
872 static constexpr size_t defaultAlignment = sizeof (NumericType);
873 #endif
874
875 SampleType* const* channels;
876 ChannelCountType numChannels = 0;
877 size_t startSample = 0, numSamples = 0;
878
879 template <typename OtherSampleType>
880 friend class AudioBlock;
881};
882
883} // namespace dsp
884} // namespace juce
885
886/** @}*/
A multi-channel buffer containing floating point audio samples.
static void JUCE_CALLTYPE max(float *dest, const float *src, float comp, int num) noexcept
Each element of dest will be the maximum of the corresponding element of the source array and the giv...
static void JUCE_CALLTYPE negate(float *dest, const float *src, int numValues) noexcept
Copies a source vector to a destination, negating each value.
static void JUCE_CALLTYPE fill(float *dest, float valueToFill, int numValues) noexcept
Copies a repeated value into a vector of floats.
static void JUCE_CALLTYPE multiply(float *dest, const float *src, int numValues) noexcept
Multiplies the destination values by the source values.
static void JUCE_CALLTYPE clear(float *dest, int numValues) noexcept
Clears a vector of floats.
static void JUCE_CALLTYPE subtract(float *dest, const float *src, int numValues) noexcept
Subtracts the source values from the destination values.
static void JUCE_CALLTYPE copy(float *dest, const float *src, int numValues) noexcept
Copies a vector of floats.
static void JUCE_CALLTYPE addWithMultiply(float *dest, const float *src, float multiplier, int numValues) noexcept
Multiplies each source value by the given multiplier, then adds it to the destination value.
static void JUCE_CALLTYPE min(float *dest, const float *src, float comp, int num) noexcept
Each element of dest will be the minimum of the corresponding element of the source array and the giv...
static Range< float > JUCE_CALLTYPE findMinAndMax(const float *src, int numValues) noexcept
Finds the minimum and maximum values in the given array.
static void JUCE_CALLTYPE abs(float *dest, const float *src, int numValues) noexcept
Copies a source vector to a destination, taking the absolute of each value.
static void JUCE_CALLTYPE add(float *dest, float amountToAdd, int numValues) noexcept
Adds a fixed value to the destination values.
A general-purpose range object, that simply represents any linear range with a start and end point.
Definition: juce_Range.h:44
A utility class for values that need smoothing to avoid audio glitches.
Minimal and lightweight data-structure which contains a list of pointers to channels containing some ...
AudioBlock & multiplyBy(SmoothedValue< SampleType, SmoothingType > &value) noexcept
Multiplies each channels of this block by a smoothly changing value.
AudioBlock & addProductOf(AudioBlock< Src1SampleType > src1, AudioBlock< Src2SampleType > src2) noexcept
Multiplies each value in srcA with the corresponding value in srcB and adds the result to this block.
AudioBlock & copyFrom(const AudioBuffer< OtherNumericType > &src, size_t srcPos=0, size_t dstPos=0, size_t numElements=std::numeric_limits< size_t >::max())
Copy the values from an AudioBuffer to this block.
static void process(AudioBlock< Src1SampleType > inBlock, AudioBlock< Src2SampleType > outBlock, FunctionType &&function)
Applies a function to each value in an input block, putting the result into an output block.
void copyTo(AudioBuffer< typename std::remove_const< NumericType >::type > &dst, size_t srcPos=0, size_t dstPos=0, size_t numElements=std::numeric_limits< size_t >::max()) const
Copies the values from this block to an AudioBuffer.
AudioBlock getSubBlock(size_t newOffset, size_t newLength) const noexcept
Return a new AudioBlock pointing to a sub-block inside this block.
AudioBlock &JUCE_VECTOR_CALLTYPE subtract(NumericType value) noexcept
Subtracts a fixed value from the elements in this block.
AudioBlock &JUCE_VECTOR_CALLTYPE replaceWithProductOf(AudioBlock< OtherSampleType > src, NumericType value) noexcept
Replaces the elements in this block with the product of the elements in the source src block and a fi...
AudioBlock getSubsetChannelBlock(size_t channelStart, size_t numChannelsToUse) const noexcept
Returns a subset of contiguous channels.
void setSample(int destChannel, int destSample, SampleType newValue) const noexcept
Modifies a sample in the buffer.
AudioBlock & replaceWithDifferenceOf(AudioBlock< Src1SampleType > src1, AudioBlock< Src2SampleType > src2) noexcept
Subtracts each source2 value from the corresponding source1 value and replaces the contents of this b...
constexpr size_t getNumChannels() const noexcept
Returns the number of channels referenced by this block.
AudioBlock &JUCE_VECTOR_CALLTYPE replaceWithSumOf(AudioBlock< OtherSampleType > src, NumericType value) noexcept
Adds a fixed value to each source value and replaces the contents of this block.
AudioBlock & replaceWithMaxOf(AudioBlock< Src1SampleType > src1, AudioBlock< Src2SampleType > src2) noexcept
Replaces each element of this block with the maximum of the corresponding element of the source array...
Range< typename std::remove_const< NumericType >::type > findMinAndMax() const noexcept
Finds the minimum and maximum value of the buffer.
SampleType * getChannelPointer(size_t channel) const noexcept
Returns a raw pointer into one of the channels in this block.
AudioBlock & negate() noexcept
Negates each value of this block.
AudioBlock & replaceWithNegativeOf(AudioBlock< OtherSampleType > src) noexcept
Replaces the contents of this block with the negative of the values in the src block.
AudioBlock &JUCE_VECTOR_CALLTYPE replaceWithDifferenceOf(AudioBlock< OtherSampleType > src, NumericType value) noexcept
Subtracts a fixed value from each source value and replaces the contents of this block.
AudioBlock & replaceWithSumOf(AudioBlock< Src1SampleType > src1, AudioBlock< Src2SampleType > src2) noexcept
Adds each source1 value to the corresponding source2 value and replaces the contents of this block.
AudioBlock(AudioBuffer< OtherSampleType > &buffer, size_t startSampleIndex) noexcept
Creates an AudioBlock that points to the data in an AudioBuffer.
AudioBlock &JUCE_VECTOR_CALLTYPE multiplyBy(NumericType value) noexcept
Multiplies the elements in this block by a fixed value.
AudioBlock &JUCE_VECTOR_CALLTYPE add(NumericType value) noexcept
Adds a fixed value to the elements in this block.
constexpr AudioBlock(AudioBuffer< OtherSampleType > &buffer) noexcept
Creates an AudioBlock that points to the data in an AudioBuffer.
AudioBlock & add(AudioBlock< OtherSampleType > src) noexcept
Adds the elements in the src block to the elements in this block.
AudioBlock & move(size_t srcPos, size_t dstPos, size_t numElements=std::numeric_limits< size_t >::max()) noexcept
Move memory within this block from the position srcPos to the position dstPos.
AudioBlock & replaceWithProductOf(AudioBlock< Src1SampleType > src1, AudioBlock< Src2SampleType > src2) noexcept
Replaces the elements in this block with the product of the elements in the src1 and scr2 blocks.
AudioBlock & replaceWithAbsoluteValueOf(AudioBlock< OtherSampleType > src) noexcept
Replaces the contents of this block with the absolute values of the src block.
AudioBlock & copyFrom(const AudioBlock< OtherSampleType > &src) noexcept
Copies the values in src to this block.
AudioBlock &JUCE_VECTOR_CALLTYPE addProductOf(AudioBlock< OtherSampleType > src, NumericType factor) noexcept
Multiplies each value in src by a fixed value and adds the result to this block.
AudioBlock getSingleChannelBlock(size_t channel) const noexcept
Returns an AudioBlock that represents one of the channels in this block.
SampleType getSample(int channel, int sampleIndex) const noexcept
Returns a sample from the buffer.
AudioBlock & subtract(AudioBlock< OtherSampleType > src) noexcept
Subtracts the source values from the elements in this block.
AudioBlock getSubBlock(size_t newOffset) const noexcept
Return a new AudioBlock pointing to a sub-block inside this block.
AudioBlock & replaceWithProductOf(AudioBlock< OtherSampleType > src, SmoothedValue< SampleType, SmoothingType > &value) noexcept
Replaces each channel of this block with the product of the src block and a smoothed value.
AudioBlock & replaceWithMinOf(AudioBlock< Src1SampleType > src1, AudioBlock< Src2SampleType > src2) noexcept
Replaces each element of this block with the minimum of the corresponding element of the source array...
constexpr size_t getNumSamples() const noexcept
Returns the number of samples referenced by this block.
void addSample(int destChannel, int destSample, SampleType valueToAdd) const noexcept
Adds a value to a sample in the buffer.
AudioBlock & clear() noexcept
Clears the memory referenced by this AudioBlock.
AudioBlock() noexcept=default
Create a zero-sized AudioBlock.
AudioBlock &JUCE_VECTOR_CALLTYPE fill(NumericType value) noexcept
Fills the memory referenced by this AudioBlock with value.
constexpr AudioBlock(SampleType *const *channelData, size_t numberOfChannels, size_t startSampleIndex, size_t numberOfSamples) noexcept
Creates an AudioBlock from a pointer to an array of channels.
AudioBlock(HeapBlock< char > &heapBlockToUseForAllocation, size_t numberOfChannels, size_t numberOfSamples, size_t alignmentInBytes=defaultAlignment) noexcept
Allocates a suitable amount of space in a HeapBlock, and initialises this object to point into it.
AudioBlock & multiplyBy(AudioBlock< OtherSampleType > src) noexcept
Multiplies the elements in this block by the elements in the src block.