LMMS
Loading...
Searching...
No Matches
juce_AudioBlock.h
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28namespace dsp
29{
30
31#ifndef DOXYGEN
32namespace SampleTypeHelpers // Internal classes needed for handling sample type classes
33{
34 template <typename T, bool = std::is_floating_point<T>::value>
36 {
37 using Type = T;
38 };
39
40 template <typename T>
42 {
43 using Type = const typename T::value_type;
44 };
45
46 template <typename T>
47 struct ElementType<T, false>
48 {
49 using Type = typename T::value_type;
50 };
51}
52#endif
53
54//==============================================================================
68template <typename SampleType>
70{
71private:
72 template <typename OtherSampleType>
74 std::enable_if_t<std::is_same<std::remove_const_t<SampleType>,
75 std::remove_const_t<OtherSampleType>>::value
76 && std::is_const<SampleType>::value
77 && ! std::is_const<OtherSampleType>::value,
78 int>;
79
80public:
81 //==============================================================================
83
84 //==============================================================================
86 AudioBlock() noexcept = default;
87
93 constexpr AudioBlock (SampleType* const* channelData,
94 size_t numberOfChannels, size_t numberOfSamples) noexcept
95 : channels (channelData),
96 numChannels (static_cast<ChannelCountType> (numberOfChannels)),
97 numSamples (numberOfSamples)
98 {
99 }
100
106 constexpr AudioBlock (SampleType* const* channelData, size_t numberOfChannels,
107 size_t startSampleIndex, size_t numberOfSamples) noexcept
108 : channels (channelData),
109 numChannels (static_cast<ChannelCountType> (numberOfChannels)),
110 startSample (startSampleIndex),
111 numSamples (numberOfSamples)
112 {
113 }
114
120 AudioBlock (HeapBlock<char>& heapBlockToUseForAllocation,
121 size_t numberOfChannels, size_t numberOfSamples,
122 size_t alignmentInBytes = defaultAlignment) noexcept
123 : numChannels (static_cast<ChannelCountType> (numberOfChannels)),
124 numSamples (numberOfSamples)
125 {
126 auto roundedUpNumSamples = (numberOfSamples + elementMask) & ~elementMask;
127 auto channelSize = sizeof (SampleType) * roundedUpNumSamples;
128 auto channelListBytes = sizeof (SampleType*) * numberOfChannels;
129 auto extraBytes = alignmentInBytes - 1;
130
131 heapBlockToUseForAllocation.malloc (channelListBytes + extraBytes + channelSize * numberOfChannels);
132
133 auto* chanArray = unalignedPointerCast<SampleType**> (heapBlockToUseForAllocation.getData());
134 channels = chanArray;
135
136 auto* data = unalignedPointerCast<SampleType*> (addBytesToPointer (chanArray, channelListBytes));
137 data = snapPointerToAlignment (data, alignmentInBytes);
138
139 for (ChannelCountType i = 0; i < numChannels; ++i)
140 {
141 chanArray[i] = data;
142 data += roundedUpNumSamples;
143 }
144 }
145
151 template <typename OtherSampleType>
153 : channels (buffer.getArrayOfWritePointers()),
154 numChannels (static_cast<ChannelCountType> (buffer.getNumChannels())),
155 numSamples (static_cast<size_t> (buffer.getNumSamples()))
156 {
157 }
158
164 template <typename OtherSampleType>
166 : channels (buffer.getArrayOfReadPointers()),
167 numChannels (static_cast<ChannelCountType> (buffer.getNumChannels())),
168 numSamples (static_cast<size_t> (buffer.getNumSamples()))
169 {
170 }
171
177 template <typename OtherSampleType>
178 AudioBlock (AudioBuffer<OtherSampleType>& buffer, size_t startSampleIndex) noexcept
179 : channels (buffer.getArrayOfWritePointers()),
180 numChannels (static_cast<ChannelCountType> (buffer.getNumChannels())),
181 startSample (startSampleIndex),
182 numSamples (static_cast<size_t> (buffer.getNumSamples()) - startSampleIndex)
183 {
184 jassert (startSample < static_cast<size_t> (buffer.getNumSamples()));
185 }
186
187 AudioBlock (const AudioBlock& other) noexcept = default;
188 AudioBlock& operator= (const AudioBlock& other) noexcept = default;
189
190 template <typename OtherSampleType, MayUseConvertingConstructor<OtherSampleType> = 0>
192 : channels { other.channels },
193 numChannels { other.numChannels },
194 startSample { other.startSample },
195 numSamples { other.numSamples }
196 {
197 }
198
199 template <typename OtherSampleType, MayUseConvertingConstructor<OtherSampleType> = 0>
200 AudioBlock& operator= (const AudioBlock<OtherSampleType>& other) noexcept
201 {
202 AudioBlock blockCopy { other };
203 swap (blockCopy);
204 return *this;
205 }
206
207 void swap (AudioBlock& other) noexcept
208 {
209 std::swap (other.channels, channels);
210 std::swap (other.numChannels, numChannels);
211 std::swap (other.startSample, startSample);
212 std::swap (other.numSamples, numSamples);
213 }
214
215 //==============================================================================
216 template <typename OtherSampleType>
217 constexpr bool operator== (const AudioBlock<OtherSampleType>& other) const noexcept
218 {
219 return std::equal (channels,
221 other.channels,
222 other.channels + other.numChannels)
223 && startSample == other.startSample
224 && numSamples == other.numSamples;
225 }
226
227 template <typename OtherSampleType>
228 constexpr bool operator!= (const AudioBlock<OtherSampleType>& other) const noexcept
229 {
230 return ! (*this == other);
231 }
232
233 //==============================================================================
235 constexpr size_t getNumChannels() const noexcept { return static_cast<size_t> (numChannels); }
236
238 constexpr size_t getNumSamples() const noexcept { return numSamples; }
239
241 SampleType* getChannelPointer (size_t channel) const noexcept
242 {
243 jassert (channel < numChannels);
244 jassert (numSamples > 0);
245 return channels[channel] + startSample;
246 }
247
249 AudioBlock getSingleChannelBlock (size_t channel) const noexcept
250 {
251 jassert (channel < numChannels);
252 return AudioBlock (channels + channel, 1, startSample, numSamples);
253 }
254
259 AudioBlock getSubsetChannelBlock (size_t channelStart, size_t numChannelsToUse) const noexcept
260 {
261 jassert (channelStart < numChannels);
262 jassert ((channelStart + numChannelsToUse) <= numChannels);
263
264 return AudioBlock (channels + channelStart, numChannelsToUse, startSample, numSamples);
265 }
266
272 SampleType getSample (int channel, int sampleIndex) const noexcept
273 {
275 jassert (isPositiveAndBelow (sampleIndex, numSamples));
276 return channels[channel][(size_t) startSample + (size_t) sampleIndex];
277 }
278
284 void setSample (int destChannel, int destSample, SampleType newValue) const noexcept
285 {
286 jassert (isPositiveAndBelow (destChannel, numChannels));
287 jassert (isPositiveAndBelow (destSample, numSamples));
288 channels[destChannel][(size_t) startSample + (size_t) destSample] = newValue;
289 }
290
296 void addSample (int destChannel, int destSample, SampleType valueToAdd) const noexcept
297 {
298 jassert (isPositiveAndBelow (destChannel, numChannels));
299 jassert (isPositiveAndBelow (destSample, numSamples));
300 channels[destChannel][(size_t) startSample + (size_t) destSample] += valueToAdd;
301 }
302
303 //==============================================================================
305 AudioBlock& clear() noexcept { clearInternal(); return *this; }
306 const AudioBlock& clear() const noexcept { clearInternal(); return *this; }
307
310 const AudioBlock& JUCE_VECTOR_CALLTYPE fill (NumericType value) const noexcept { fillInternal (value); return *this; }
311
313 template <typename OtherSampleType>
314 AudioBlock& copyFrom (const AudioBlock<OtherSampleType>& src) noexcept { copyFromInternal (src); return *this; }
315 template <typename OtherSampleType>
316 const AudioBlock& copyFrom (const AudioBlock<OtherSampleType>& src) const noexcept { copyFromInternal (src); return *this; }
317
324 template <typename OtherNumericType>
326 size_t srcPos = 0, size_t dstPos = 0,
327 size_t numElements = std::numeric_limits<size_t>::max()) { copyFromInternal (src, srcPos, dstPos, numElements); return *this; }
328 template <typename OtherNumericType>
330 size_t srcPos = 0, size_t dstPos = 0,
331 size_t numElements = std::numeric_limits<size_t>::max()) const { copyFromInternal (src, srcPos, dstPos, numElements); return *this; }
332
333
340 void copyTo (AudioBuffer<typename std::remove_const<NumericType>::type>& dst, size_t srcPos = 0, size_t dstPos = 0,
341 size_t numElements = std::numeric_limits<size_t>::max()) const
342 {
343 auto dstlen = static_cast<size_t> (dst.getNumSamples()) / sizeFactor;
344 auto n = jmin (numSamples - srcPos, dstlen - dstPos, numElements) * sizeFactor;
345 auto maxChannels = jmin (static_cast<size_t> (dst.getNumChannels()), static_cast<size_t> (numChannels));
346
347 for (size_t ch = 0; ch < maxChannels; ++ch)
348 FloatVectorOperations::copy (dst.getWritePointer ((int) ch, (int) (dstPos * sizeFactor)),
349 getDataPointer (ch) + (srcPos * sizeFactor),
350 n);
351 }
352
356 AudioBlock& move (size_t srcPos, size_t dstPos,
357 size_t numElements = std::numeric_limits<size_t>::max()) noexcept { moveInternal (srcPos, dstPos, numElements); return *this; }
358 const AudioBlock& move (size_t srcPos, size_t dstPos,
359 size_t numElements = std::numeric_limits<size_t>::max()) const noexcept { moveInternal (srcPos, dstPos, numElements); return *this; }
360
361 //==============================================================================
371 AudioBlock getSubBlock (size_t newOffset, size_t newLength) const noexcept
372 {
373 jassert (newOffset < numSamples);
374 jassert (newOffset + newLength <= numSamples);
375
376 return AudioBlock (channels, numChannels, startSample + newOffset, newLength);
377 }
378
389 AudioBlock getSubBlock (size_t newOffset) const noexcept
390 {
391 return getSubBlock (newOffset, getNumSamples() - newOffset);
392 }
393
394 //==============================================================================
397 const AudioBlock& JUCE_VECTOR_CALLTYPE add (NumericType value) const noexcept { addInternal (value); return *this; }
398
400 template <typename OtherSampleType>
401 AudioBlock& add (AudioBlock<OtherSampleType> src) noexcept { addInternal (src); return *this; }
402 template <typename OtherSampleType>
403 const AudioBlock& add (AudioBlock<OtherSampleType> src) const noexcept { addInternal (src); return *this; }
404
406 template <typename OtherSampleType>
408 template <typename OtherSampleType>
410
412 template <typename Src1SampleType, typename Src2SampleType>
414 template <typename Src1SampleType, typename Src2SampleType>
415 const AudioBlock& replaceWithSumOf (AudioBlock<Src1SampleType> src1, AudioBlock<Src2SampleType> src2) const noexcept { replaceWithSumOfInternal (src1, src2); return *this; }
416
417 //==============================================================================
421
423 template <typename OtherSampleType>
424 AudioBlock& subtract (AudioBlock<OtherSampleType> src) noexcept { subtractInternal (src); return *this; }
425 template <typename OtherSampleType>
426 const AudioBlock& subtract (AudioBlock<OtherSampleType> src) const noexcept { subtractInternal (src); return *this; }
427
429 template <typename OtherSampleType>
431 template <typename OtherSampleType>
433
435 template <typename Src1SampleType, typename Src2SampleType>
437 template <typename Src1SampleType, typename Src2SampleType>
439
440 //==============================================================================
444
446 template <typename OtherSampleType>
448 template <typename OtherSampleType>
449 const AudioBlock& multiplyBy (AudioBlock<OtherSampleType> src) const noexcept { multiplyByInternal (src); return *this; }
450
452 template <typename OtherSampleType>
454 template <typename OtherSampleType>
456
458 template <typename Src1SampleType, typename Src2SampleType>
460 template <typename Src1SampleType, typename Src2SampleType>
462
463 //==============================================================================
465 template <typename OtherSampleType, typename SmoothingType>
467 template <typename OtherSampleType, typename SmoothingType>
469
471 template <typename BlockSampleType, typename SmootherSampleType, typename SmoothingType>
473 template <typename BlockSampleType, typename SmootherSampleType, typename SmoothingType>
475
476 //==============================================================================
478 template <typename OtherSampleType>
480 template <typename OtherSampleType>
481 const AudioBlock& JUCE_VECTOR_CALLTYPE addProductOf (AudioBlock<OtherSampleType> src, NumericType factor) const noexcept { addProductOfInternal (src, factor); return *this; }
482
484 template <typename Src1SampleType, typename Src2SampleType>
486 template <typename Src1SampleType, typename Src2SampleType>
487 const AudioBlock& addProductOf (AudioBlock<Src1SampleType> src1, AudioBlock<Src2SampleType> src2) const noexcept { addProductOfInternal (src1, src2); return *this; }
488
489 //==============================================================================
491 AudioBlock& negate() noexcept { negateInternal(); return *this; }
492 const AudioBlock& negate() const noexcept { negateInternal(); return *this; }
493
495 template <typename OtherSampleType>
497 template <typename OtherSampleType>
499
501 template <typename OtherSampleType>
503 template <typename OtherSampleType>
505
506 //==============================================================================
508 template <typename Src1SampleType, typename Src2SampleType>
510 template <typename Src1SampleType, typename Src2SampleType>
511 const AudioBlock& replaceWithMinOf (AudioBlock<Src1SampleType> src1, AudioBlock<Src2SampleType> src2) const noexcept { replaceWithMinOfInternal (src1, src2); return *this; }
512
514 template <typename Src1SampleType, typename Src2SampleType>
516 template <typename Src1SampleType, typename Src2SampleType>
517 const AudioBlock& replaceWithMaxOf (AudioBlock<Src1SampleType> src1, AudioBlock<Src2SampleType> src2) const noexcept { replaceWithMaxOfInternal (src1, src2); return *this; }
518
519 //==============================================================================
522 {
523 if (numChannels == 0)
524 return {};
525
526 auto n = numSamples * sizeFactor;
527 auto minmax = FloatVectorOperations::findMinAndMax (getDataPointer (0), n);
528
529 for (size_t ch = 1; ch < numChannels; ++ch)
530 minmax = minmax.getUnionWith (FloatVectorOperations::findMinAndMax (getDataPointer (ch), n));
531
532 return minmax;
533 }
534
535 //==============================================================================
536 // Convenient operator wrappers.
537 AudioBlock& JUCE_VECTOR_CALLTYPE operator+= (NumericType value) noexcept { return add (value); }
538 const AudioBlock& JUCE_VECTOR_CALLTYPE operator+= (NumericType value) const noexcept { return add (value); }
539
540 AudioBlock& operator+= (AudioBlock src) noexcept { return add (src); }
541 const AudioBlock& operator+= (AudioBlock src) const noexcept { return add (src); }
542
543 AudioBlock& JUCE_VECTOR_CALLTYPE operator-= (NumericType value) noexcept { return subtract (value); }
544 const AudioBlock& JUCE_VECTOR_CALLTYPE operator-= (NumericType value) const noexcept { return subtract (value); }
545
546 AudioBlock& operator-= (AudioBlock src) noexcept { return subtract (src); }
547 const AudioBlock& operator-= (AudioBlock src) const noexcept { return subtract (src); }
548
550 const AudioBlock& JUCE_VECTOR_CALLTYPE operator*= (NumericType value) const noexcept { return multiplyBy (value); }
551
552 AudioBlock& operator*= (AudioBlock src) noexcept { return multiplyBy (src); }
553 const AudioBlock& operator*= (AudioBlock src) const noexcept { return multiplyBy (src); }
554
555 template <typename OtherSampleType, typename SmoothingType>
557 template <typename OtherSampleType, typename SmoothingType>
558 const AudioBlock& operator*= (SmoothedValue<OtherSampleType, SmoothingType>& value) const noexcept { return multiplyBy (value); }
559
560 //==============================================================================
561 // This class can only be used with floating point types
562 static_assert (std::is_same<std::remove_const_t<SampleType>, float>::value
563 || std::is_same<std::remove_const_t<SampleType>, double>::value
564 #if JUCE_USE_SIMD
565 || std::is_same<std::remove_const_t<SampleType>, SIMDRegister<float>>::value
566 || std::is_same<std::remove_const_t<SampleType>, SIMDRegister<double>>::value
567 #endif
568 , "AudioBlock only supports single or double precision floating point types");
569
570 //==============================================================================
575 template <typename Src1SampleType, typename Src2SampleType, typename FunctionType>
576 static void process (AudioBlock<Src1SampleType> inBlock, AudioBlock<Src2SampleType> outBlock, FunctionType&& function)
577 {
578 auto len = inBlock.getNumSamples();
579 auto numChans = inBlock.getNumChannels();
580
581 jassert (len == outBlock.getNumSamples());
582 jassert (numChans == outBlock.getNumChannels());
583
584 for (ChannelCountType c = 0; c < numChans; ++c)
585 {
586 auto* src = inBlock.getChannelPointer (c);
587 auto* dst = outBlock.getChannelPointer (c);
588
589 for (size_t i = 0; i < len; ++i)
590 dst[i] = function (src[i]);
591 }
592 }
593
594private:
595 NumericType* getDataPointer (size_t channel) const noexcept
596 {
597 return reinterpret_cast<NumericType*> (getChannelPointer (channel));
598 }
599
600 //==============================================================================
602 {
603 auto n = numSamples * sizeFactor;
604
605 for (size_t ch = 0; ch < numChannels; ++ch)
606 FloatVectorOperations::clear (getDataPointer (ch), n);
607 }
608
610 {
611 auto n = numSamples * sizeFactor;
612
613 for (size_t ch = 0; ch < numChannels; ++ch)
614 FloatVectorOperations::fill (getDataPointer (ch), value, n);
615 }
616
617 template <typename OtherSampleType>
618 void copyFromInternal (const AudioBlock<OtherSampleType>& src) const noexcept
619 {
620 auto maxChannels = jmin (src.numChannels, numChannels);
621 auto n = jmin (src.numSamples * src.sizeFactor, numSamples * sizeFactor);
622
623 for (size_t ch = 0; ch < maxChannels; ++ch)
624 FloatVectorOperations::copy (getDataPointer (ch), src.getDataPointer (ch), n);
625 }
626
627 template <typename OtherNumericType>
628 void copyFromInternal (const AudioBuffer<OtherNumericType>& src, size_t srcPos, size_t dstPos, size_t numElements) const
629 {
630 auto srclen = static_cast<size_t> (src.getNumSamples()) / sizeFactor;
631 auto n = jmin (srclen - srcPos, numSamples - dstPos, numElements) * sizeFactor;
632 auto maxChannels = jmin (static_cast<size_t> (src.getNumChannels()), static_cast<size_t> (numChannels));
633
634 for (size_t ch = 0; ch < maxChannels; ++ch)
635 FloatVectorOperations::copy (getDataPointer (ch) + (dstPos * sizeFactor),
636 src.getReadPointer ((int) ch, (int) (srcPos * sizeFactor)),
637 n);
638 }
639
640 void moveInternal (size_t srcPos, size_t dstPos,
641 size_t numElements = std::numeric_limits<size_t>::max()) const noexcept
642 {
643 jassert (srcPos <= numSamples && dstPos <= numSamples);
644 auto len = jmin (numSamples - srcPos, numSamples - dstPos, numElements) * sizeof (SampleType);
645
646 if (len != 0)
647 for (size_t ch = 0; ch < numChannels; ++ch)
648 ::memmove (getChannelPointer (ch) + dstPos,
649 getChannelPointer (ch) + srcPos, len);
650 }
651
652 //==============================================================================
654 {
655 auto n = numSamples * sizeFactor;
656
657 for (size_t ch = 0; ch < numChannels; ++ch)
658 FloatVectorOperations::add (getDataPointer (ch), value, n);
659 }
660
661 template <typename OtherSampleType>
662 void addInternal (AudioBlock<OtherSampleType> src) const noexcept
663 {
665 auto n = jmin (numSamples, src.numSamples) * sizeFactor;
666
667 for (size_t ch = 0; ch < numChannels; ++ch)
668 FloatVectorOperations::add (getDataPointer (ch), src.getDataPointer (ch), n);
669 }
670
671 template <typename OtherSampleType>
673 {
675 auto n = jmin (numSamples, src.numSamples) * sizeFactor;
676
677 for (size_t ch = 0; ch < numChannels; ++ch)
678 FloatVectorOperations::add (getDataPointer (ch), src.getDataPointer (ch), value, n);
679 }
680
681 template <typename Src1SampleType, typename Src2SampleType>
683 {
684 jassert (numChannels == src1.numChannels && src1.numChannels == src2.numChannels);
685 auto n = jmin (numSamples, src1.numSamples, src2.numSamples) * sizeFactor;
686
687 for (size_t ch = 0; ch < numChannels; ++ch)
688 FloatVectorOperations::add (getDataPointer (ch), src1.getDataPointer (ch), src2.getDataPointer (ch), n);
689 }
690
691 //==============================================================================
693 {
694 addInternal (value * static_cast<NumericType> (-1.0));
695 }
696
697 template <typename OtherSampleType>
699 {
701 auto n = jmin (numSamples, src.numSamples) * sizeFactor;
702
703 for (size_t ch = 0; ch < numChannels; ++ch)
704 FloatVectorOperations::subtract (getDataPointer (ch), src.getDataPointer (ch), n);
705 }
706
707 template <typename OtherSampleType>
712
713 template <typename Src1SampleType, typename Src2SampleType>
715 {
716 jassert (numChannels == src1.numChannels && src1.numChannels == src2.numChannels);
717 auto n = jmin (numSamples, src1.numSamples, src2.numSamples) * sizeFactor;
718
719 for (size_t ch = 0; ch < numChannels; ++ch)
720 FloatVectorOperations::subtract (getDataPointer (ch), src1.getDataPointer (ch), src2.getDataPointer (ch), n);
721 }
722
723 //==============================================================================
725 {
726 auto n = numSamples * sizeFactor;
727
728 for (size_t ch = 0; ch < numChannels; ++ch)
729 FloatVectorOperations::multiply (getDataPointer (ch), value, n);
730 }
731
732 template <typename OtherSampleType>
734 {
736 auto n = jmin (numSamples, src.numSamples) * sizeFactor;
737
738 for (size_t ch = 0; ch < numChannels; ++ch)
739 FloatVectorOperations::multiply (getDataPointer (ch), src.getDataPointer (ch), n);
740 }
741
742 template <typename OtherSampleType>
744 {
746 auto n = jmin (numSamples, src.numSamples) * sizeFactor;
747
748 for (size_t ch = 0; ch < numChannels; ++ch)
749 FloatVectorOperations::multiply (getDataPointer (ch), src.getDataPointer (ch), value, n);
750 }
751
752 template <typename Src1SampleType, typename Src2SampleType>
754 {
755 jassert (numChannels == src1.numChannels && src1.numChannels == src2.numChannels);
756 auto n = jmin (numSamples, src1.numSamples, src2.numSamples) * sizeFactor;
757
758 for (size_t ch = 0; ch < numChannels; ++ch)
759 FloatVectorOperations::multiply (getDataPointer (ch), src1.getDataPointer (ch), src2.getDataPointer (ch), n);
760 }
761
762 template <typename OtherSampleType, typename SmoothingType>
764 {
765 if (! value.isSmoothing())
766 {
767 multiplyByInternal ((NumericType) value.getTargetValue());
768 }
769 else
770 {
771 for (size_t i = 0; i < numSamples; ++i)
772 {
773 const auto scaler = (NumericType) value.getNextValue();
774
775 for (size_t ch = 0; ch < numChannels; ++ch)
776 getDataPointer (ch)[i] *= scaler;
777 }
778 }
779 }
780
781 template <typename BlockSampleType, typename SmootherSampleType, typename SmoothingType>
783 {
785
786 if (! value.isSmoothing())
787 {
788 replaceWithProductOfInternal (src, (NumericType) value.getTargetValue());
789 }
790 else
791 {
792 auto n = jmin (numSamples, src.numSamples) * sizeFactor;
793
794 for (size_t i = 0; i < n; ++i)
795 {
796 const auto scaler = (NumericType) value.getNextValue();
797
798 for (size_t ch = 0; ch < numChannels; ++ch)
799 getDataPointer (ch)[i] = scaler * src.getChannelPointer (ch)[i];
800 }
801 }
802 }
803
804 //==============================================================================
805 template <typename OtherSampleType>
807 {
809 auto n = jmin (numSamples, src.numSamples) * sizeFactor;
810
811 for (size_t ch = 0; ch < numChannels; ++ch)
812 FloatVectorOperations::addWithMultiply (getDataPointer (ch), src.getDataPointer (ch), factor, n);
813 }
814
815 template <typename Src1SampleType, typename Src2SampleType>
817 {
818 jassert (numChannels == src1.numChannels && src1.numChannels == src2.numChannels);
819 auto n = jmin (numSamples, src1.numSamples, src2.numSamples) * sizeFactor;
820
821 for (size_t ch = 0; ch < numChannels; ++ch)
822 FloatVectorOperations::addWithMultiply (getDataPointer (ch), src1.getDataPointer (ch), src2.getDataPointer (ch), n);
823 }
824
825 //==============================================================================
827 {
828 multiplyByInternal (static_cast<NumericType> (-1.0));
829 }
830
831 template <typename OtherSampleType>
833 {
835 auto n = jmin (numSamples, src.numSamples) * sizeFactor;
836
837 for (size_t ch = 0; ch < numChannels; ++ch)
838 FloatVectorOperations::negate (getDataPointer (ch), src.getDataPointer (ch), n);
839 }
840
841 template <typename OtherSampleType>
843 {
845 auto n = jmin (numSamples, src.numSamples) * sizeFactor;
846
847 for (size_t ch = 0; ch < numChannels; ++ch)
848 FloatVectorOperations::abs (getDataPointer (ch), src.getDataPointer (ch), n);
849 }
850
851 //==============================================================================
852 template <typename Src1SampleType, typename Src2SampleType>
854 {
855 jassert (numChannels == src1.numChannels && src1.numChannels == src2.numChannels);
856 auto n = jmin (src1.numSamples, src2.numSamples, numSamples) * sizeFactor;
857
858 for (size_t ch = 0; ch < numChannels; ++ch)
859 FloatVectorOperations::min (getDataPointer (ch), src1.getDataPointer (ch), src2.getDataPointer (ch), n);
860 }
861
862 template <typename Src1SampleType, typename Src2SampleType>
864 {
865 jassert (numChannels == src1.numChannels && src1.numChannels == src2.numChannels);
866 auto n = jmin (src1.numSamples, src2.numSamples, numSamples) * sizeFactor;
867
868 for (size_t ch = 0; ch < numChannels; ++ch)
869 FloatVectorOperations::max (getDataPointer (ch), src1.getDataPointer (ch), src2.getDataPointer (ch), n);
870 }
871
872 //==============================================================================
873 using ChannelCountType = unsigned int;
874
875 //==============================================================================
876 static constexpr size_t sizeFactor = sizeof (SampleType) / sizeof (NumericType);
877 static constexpr size_t elementMask = sizeFactor - 1;
878 static constexpr size_t byteMask = (sizeFactor * sizeof (NumericType)) - 1;
879
880 #if JUCE_USE_SIMD
881 static constexpr size_t defaultAlignment = sizeof (SIMDRegister<NumericType>);
882 #else
883 static constexpr size_t defaultAlignment = sizeof (NumericType);
884 #endif
885
886 SampleType* const* channels;
888 size_t startSample = 0, numSamples = 0;
889
890 template <typename OtherSampleType>
891 friend class AudioBlock;
892};
893
894} // namespace dsp
895} // namespace juce
#define constexpr
Definition CarlaDefines.h:94
Type jmin(const Type a, const Type b)
Definition MathsFunctions.h:60
#define noexcept
Definition DistrhoDefines.h:72
Definition juce_AudioSampleBuffer.h:34
int numChannels
Definition juce_AudioSampleBuffer.h:1256
int getNumChannels() const noexcept
Definition juce_AudioSampleBuffer.h:236
int getNumSamples() const noexcept
Definition juce_AudioSampleBuffer.h:242
const Type * getReadPointer(int channelNumber) const noexcept
Definition juce_AudioSampleBuffer.h:253
Definition juce_HeapBlock.h:87
Definition juce_Range.h:40
Definition juce_SmoothedValue.h:227
const AudioBlock & multiplyBy(SmoothedValue< OtherSampleType, SmoothingType > &value) const noexcept
Definition juce_AudioBlock.h:468
typename SampleTypeHelpers::ElementType< SampleType >::Type NumericType
Definition juce_AudioBlock.h:82
void addInternal(AudioBlock< OtherSampleType > src) const noexcept
Definition juce_AudioBlock.h:662
AudioBlock & addProductOf(AudioBlock< Src1SampleType > src1, AudioBlock< Src2SampleType > src2) noexcept
Definition juce_AudioBlock.h:485
const AudioBlock & replaceWithNegativeOf(AudioBlock< OtherSampleType > src) const noexcept
Definition juce_AudioBlock.h:498
void subtractInternal(AudioBlock< OtherSampleType > src) const noexcept
Definition juce_AudioBlock.h:698
std::enable_if_t< std::is_same< std::remove_const_t< SampleType >, std::remove_const_t< OtherSampleType > >::value &&std::is_const< SampleType >::value &&! std::is_const< OtherSampleType >::value, int > MayUseConvertingConstructor
Definition juce_AudioBlock.h:73
AudioBlock & copyFrom(const AudioBuffer< OtherNumericType > &src, size_t srcPos=0, size_t dstPos=0, size_t numElements=std::numeric_limits< size_t >::max())
Definition juce_AudioBlock.h:325
AudioBlock(const AudioBlock< OtherSampleType > &other) noexcept
Definition juce_AudioBlock.h:191
const AudioBlock & replaceWithSumOf(AudioBlock< Src1SampleType > src1, AudioBlock< Src2SampleType > src2) const noexcept
Definition juce_AudioBlock.h:415
void JUCE_VECTOR_CALLTYPE replaceWithSumOfInternal(AudioBlock< OtherSampleType > src, NumericType value) const noexcept
Definition juce_AudioBlock.h:672
void replaceWithMinOfInternal(AudioBlock< Src1SampleType > src1, AudioBlock< Src2SampleType > src2) const noexcept
Definition juce_AudioBlock.h:853
static void process(AudioBlock< Src1SampleType > inBlock, AudioBlock< Src2SampleType > outBlock, FunctionType &&function)
Definition juce_AudioBlock.h:576
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
Definition juce_AudioBlock.h:340
AudioBlock getSubBlock(size_t newOffset, size_t newLength) const noexcept
Definition juce_AudioBlock.h:371
const AudioBlock & replaceWithAbsoluteValueOf(AudioBlock< OtherSampleType > src) const noexcept
Definition juce_AudioBlock.h:504
AudioBlock &JUCE_VECTOR_CALLTYPE subtract(NumericType value) noexcept
Definition juce_AudioBlock.h:419
friend class AudioBlock
Definition juce_AudioBlock.h:891
const AudioBlock & subtract(AudioBlock< OtherSampleType > src) const noexcept
Definition juce_AudioBlock.h:426
void JUCE_VECTOR_CALLTYPE fillInternal(NumericType value) const noexcept
Definition juce_AudioBlock.h:609
AudioBlock &JUCE_VECTOR_CALLTYPE replaceWithProductOf(AudioBlock< OtherSampleType > src, NumericType value) noexcept
Definition juce_AudioBlock.h:453
AudioBlock getSubsetChannelBlock(size_t channelStart, size_t numChannelsToUse) const noexcept
Definition juce_AudioBlock.h:259
const AudioBlock &JUCE_VECTOR_CALLTYPE subtract(NumericType value) const noexcept
Definition juce_AudioBlock.h:420
const AudioBlock & replaceWithProductOf(AudioBlock< BlockSampleType > src, SmoothedValue< SmootherSampleType, SmoothingType > &value) const noexcept
Definition juce_AudioBlock.h:474
SampleType *const * channels
Definition juce_AudioBlock.h:886
const AudioBlock &JUCE_VECTOR_CALLTYPE replaceWithDifferenceOf(AudioBlock< OtherSampleType > src, NumericType value) const noexcept
Definition juce_AudioBlock.h:432
void moveInternal(size_t srcPos, size_t dstPos, size_t numElements=std::numeric_limits< size_t >::max()) const noexcept
Definition juce_AudioBlock.h:640
const AudioBlock & clear() const noexcept
Definition juce_AudioBlock.h:306
NumericType * getDataPointer(size_t channel) const noexcept
Definition juce_AudioBlock.h:595
void setSample(int destChannel, int destSample, SampleType newValue) const noexcept
Definition juce_AudioBlock.h:284
AudioBlock & replaceWithDifferenceOf(AudioBlock< Src1SampleType > src1, AudioBlock< Src2SampleType > src2) noexcept
Definition juce_AudioBlock.h:436
constexpr size_t getNumChannels() const noexcept
Definition juce_AudioBlock.h:235
const AudioBlock &JUCE_VECTOR_CALLTYPE add(NumericType value) const noexcept
Definition juce_AudioBlock.h:397
AudioBlock &JUCE_VECTOR_CALLTYPE replaceWithSumOf(AudioBlock< OtherSampleType > src, NumericType value) noexcept
Definition juce_AudioBlock.h:407
unsigned int ChannelCountType
Definition juce_AudioBlock.h:873
AudioBlock & replaceWithMaxOf(AudioBlock< Src1SampleType > src1, AudioBlock< Src2SampleType > src2) noexcept
Definition juce_AudioBlock.h:515
Range< typename std::remove_const< NumericType >::type > findMinAndMax() const noexcept
Definition juce_AudioBlock.h:521
const AudioBlock & replaceWithDifferenceOf(AudioBlock< Src1SampleType > src1, AudioBlock< Src2SampleType > src2) const noexcept
Definition juce_AudioBlock.h:438
SampleType * getChannelPointer(size_t channel) const noexcept
Definition juce_AudioBlock.h:241
AudioBlock & negate() noexcept
Definition juce_AudioBlock.h:491
AudioBlock & replaceWithNegativeOf(AudioBlock< OtherSampleType > src) noexcept
Definition juce_AudioBlock.h:496
AudioBlock &JUCE_VECTOR_CALLTYPE replaceWithDifferenceOf(AudioBlock< OtherSampleType > src, NumericType value) noexcept
Definition juce_AudioBlock.h:430
size_t numSamples
Definition juce_AudioBlock.h:888
AudioBlock & replaceWithSumOf(AudioBlock< Src1SampleType > src1, AudioBlock< Src2SampleType > src2) noexcept
Definition juce_AudioBlock.h:413
AudioBlock(AudioBuffer< OtherSampleType > &buffer, size_t startSampleIndex) noexcept
Definition juce_AudioBlock.h:178
const AudioBlock & add(AudioBlock< OtherSampleType > src) const noexcept
Definition juce_AudioBlock.h:403
void swap(AudioBlock &other) noexcept
Definition juce_AudioBlock.h:207
const AudioBlock &JUCE_VECTOR_CALLTYPE fill(NumericType value) const noexcept
Definition juce_AudioBlock.h:310
AudioBlock &JUCE_VECTOR_CALLTYPE multiplyBy(NumericType value) noexcept
Definition juce_AudioBlock.h:442
AudioBlock &JUCE_VECTOR_CALLTYPE add(NumericType value) noexcept
Definition juce_AudioBlock.h:396
constexpr AudioBlock(AudioBuffer< OtherSampleType > &buffer) noexcept
Definition juce_AudioBlock.h:152
void multiplyByInternal(SmoothedValue< OtherSampleType, SmoothingType > &value) const noexcept
Definition juce_AudioBlock.h:763
void JUCE_VECTOR_CALLTYPE addInternal(NumericType value) const noexcept
Definition juce_AudioBlock.h:653
const AudioBlock & replaceWithProductOf(AudioBlock< Src1SampleType > src1, AudioBlock< Src2SampleType > src2) const noexcept
Definition juce_AudioBlock.h:461
const AudioBlock & move(size_t srcPos, size_t dstPos, size_t numElements=std::numeric_limits< size_t >::max()) const noexcept
Definition juce_AudioBlock.h:358
AudioBlock & add(AudioBlock< OtherSampleType > src) noexcept
Definition juce_AudioBlock.h:401
AudioBlock & move(size_t srcPos, size_t dstPos, size_t numElements=std::numeric_limits< size_t >::max()) noexcept
Definition juce_AudioBlock.h:356
void replaceWithMaxOfInternal(AudioBlock< Src1SampleType > src1, AudioBlock< Src2SampleType > src2) const noexcept
Definition juce_AudioBlock.h:863
AudioBlock & replaceWithProductOf(AudioBlock< Src1SampleType > src1, AudioBlock< Src2SampleType > src2) noexcept
Definition juce_AudioBlock.h:459
AudioBlock & multiplyBy(SmoothedValue< OtherSampleType, SmoothingType > &value) noexcept
Definition juce_AudioBlock.h:466
void replaceWithNegativeOfInternal(AudioBlock< OtherSampleType > src) const noexcept
Definition juce_AudioBlock.h:832
const AudioBlock & replaceWithMinOf(AudioBlock< Src1SampleType > src1, AudioBlock< Src2SampleType > src2) const noexcept
Definition juce_AudioBlock.h:511
AudioBlock & replaceWithAbsoluteValueOf(AudioBlock< OtherSampleType > src) noexcept
Definition juce_AudioBlock.h:502
AudioBlock & copyFrom(const AudioBlock< OtherSampleType > &src) noexcept
Definition juce_AudioBlock.h:314
static constexpr size_t elementMask
Definition juce_AudioBlock.h:877
void replaceWithSumOfInternal(AudioBlock< Src1SampleType > src1, AudioBlock< Src2SampleType > src2) const noexcept
Definition juce_AudioBlock.h:682
constexpr void JUCE_VECTOR_CALLTYPE subtractInternal(NumericType value) const noexcept
Definition juce_AudioBlock.h:692
AudioBlock &JUCE_VECTOR_CALLTYPE addProductOf(AudioBlock< OtherSampleType > src, NumericType factor) noexcept
Definition juce_AudioBlock.h:479
AudioBlock getSingleChannelBlock(size_t channel) const noexcept
Definition juce_AudioBlock.h:249
constexpr AudioBlock(const AudioBuffer< OtherSampleType > &buffer) noexcept
Definition juce_AudioBlock.h:165
SampleType getSample(int channel, int sampleIndex) const noexcept
Definition juce_AudioBlock.h:272
AudioBlock & subtract(AudioBlock< OtherSampleType > src) noexcept
Definition juce_AudioBlock.h:424
void replaceWithAbsoluteValueOfInternal(AudioBlock< OtherSampleType > src) const noexcept
Definition juce_AudioBlock.h:842
void JUCE_VECTOR_CALLTYPE replaceWithDifferenceOfInternal(AudioBlock< OtherSampleType > src, NumericType value) const noexcept
Definition juce_AudioBlock.h:708
const AudioBlock &JUCE_VECTOR_CALLTYPE addProductOf(AudioBlock< OtherSampleType > src, NumericType factor) const noexcept
Definition juce_AudioBlock.h:481
AudioBlock getSubBlock(size_t newOffset) const noexcept
Definition juce_AudioBlock.h:389
static constexpr size_t byteMask
Definition juce_AudioBlock.h:878
const AudioBlock & replaceWithMaxOf(AudioBlock< Src1SampleType > src1, AudioBlock< Src2SampleType > src2) const noexcept
Definition juce_AudioBlock.h:517
void multiplyByInternal(AudioBlock< OtherSampleType > src) const noexcept
Definition juce_AudioBlock.h:733
const AudioBlock & negate() const noexcept
Definition juce_AudioBlock.h:492
AudioBlock & replaceWithMinOf(AudioBlock< Src1SampleType > src1, AudioBlock< Src2SampleType > src2) noexcept
Definition juce_AudioBlock.h:509
void JUCE_VECTOR_CALLTYPE clearInternal() const noexcept
Definition juce_AudioBlock.h:601
constexpr size_t getNumSamples() const noexcept
Definition juce_AudioBlock.h:238
const AudioBlock &JUCE_VECTOR_CALLTYPE replaceWithSumOf(AudioBlock< OtherSampleType > src, NumericType value) const noexcept
Definition juce_AudioBlock.h:409
const AudioBlock & addProductOf(AudioBlock< Src1SampleType > src1, AudioBlock< Src2SampleType > src2) const noexcept
Definition juce_AudioBlock.h:487
void replaceWithProductOfInternal(AudioBlock< Src1SampleType > src1, AudioBlock< Src2SampleType > src2) const noexcept
Definition juce_AudioBlock.h:753
void copyFromInternal(const AudioBuffer< OtherNumericType > &src, size_t srcPos, size_t dstPos, size_t numElements) const
Definition juce_AudioBlock.h:628
const AudioBlock & copyFrom(const AudioBlock< OtherSampleType > &src) const noexcept
Definition juce_AudioBlock.h:316
void addProductOfInternal(AudioBlock< Src1SampleType > src1, AudioBlock< Src2SampleType > src2) const noexcept
Definition juce_AudioBlock.h:816
void replaceWithProductOfInternal(AudioBlock< BlockSampleType > src, SmoothedValue< SmootherSampleType, SmoothingType > &value) const noexcept
Definition juce_AudioBlock.h:782
static constexpr size_t sizeFactor
Definition juce_AudioBlock.h:876
void replaceWithDifferenceOfInternal(AudioBlock< Src1SampleType > src1, AudioBlock< Src2SampleType > src2) const noexcept
Definition juce_AudioBlock.h:714
void addSample(int destChannel, int destSample, SampleType valueToAdd) const noexcept
Definition juce_AudioBlock.h:296
AudioBlock & clear() noexcept
Definition juce_AudioBlock.h:305
AudioBlock() noexcept=default
AudioBlock &JUCE_VECTOR_CALLTYPE fill(NumericType value) noexcept
Definition juce_AudioBlock.h:309
AudioBlock(const AudioBlock &other) noexcept=default
static constexpr size_t defaultAlignment
Definition juce_AudioBlock.h:883
constexpr AudioBlock(SampleType *const *channelData, size_t numberOfChannels, size_t startSampleIndex, size_t numberOfSamples) noexcept
Definition juce_AudioBlock.h:106
AudioBlock(HeapBlock< char > &heapBlockToUseForAllocation, size_t numberOfChannels, size_t numberOfSamples, size_t alignmentInBytes=defaultAlignment) noexcept
Definition juce_AudioBlock.h:120
void copyFromInternal(const AudioBlock< OtherSampleType > &src) const noexcept
Definition juce_AudioBlock.h:618
AudioBlock & replaceWithProductOf(AudioBlock< BlockSampleType > src, SmoothedValue< SmootherSampleType, SmoothingType > &value) noexcept
Definition juce_AudioBlock.h:472
ChannelCountType numChannels
Definition juce_AudioBlock.h:887
constexpr void negateInternal() const noexcept
Definition juce_AudioBlock.h:826
AudioBlock & multiplyBy(AudioBlock< OtherSampleType > src) noexcept
Definition juce_AudioBlock.h:447
void JUCE_VECTOR_CALLTYPE addProductOfInternal(AudioBlock< OtherSampleType > src, NumericType factor) const noexcept
Definition juce_AudioBlock.h:806
const AudioBlock & multiplyBy(AudioBlock< OtherSampleType > src) const noexcept
Definition juce_AudioBlock.h:449
void JUCE_VECTOR_CALLTYPE multiplyByInternal(NumericType value) const noexcept
Definition juce_AudioBlock.h:724
size_t startSample
Definition juce_AudioBlock.h:888
const AudioBlock &JUCE_VECTOR_CALLTYPE multiplyBy(NumericType value) const noexcept
Definition juce_AudioBlock.h:443
void JUCE_VECTOR_CALLTYPE replaceWithProductOfInternal(AudioBlock< OtherSampleType > src, NumericType value) const noexcept
Definition juce_AudioBlock.h:743
const AudioBlock & copyFrom(const AudioBuffer< OtherNumericType > &src, size_t srcPos=0, size_t dstPos=0, size_t numElements=std::numeric_limits< size_t >::max()) const
Definition juce_AudioBlock.h:329
const AudioBlock &JUCE_VECTOR_CALLTYPE replaceWithProductOf(AudioBlock< OtherSampleType > src, NumericType value) const noexcept
Definition juce_AudioBlock.h:455
register unsigned i
Definition inflate.c:1575
static PuglViewHint int value
Definition pugl.h:1708
JSAMPIMAGE data
Definition jpeglib.h:945
#define jassert(expression)
#define JUCE_VECTOR_CALLTYPE
Definition juce_dsp.h:100
Definition audio_fx.h:36
Definition juce_AudioBlock.h:33
Definition carla_juce.cpp:31
Type unalignedPointerCast(void *ptr) noexcept
Definition juce_Memory.h:88
jack_client_t client jack_client_t client jack_client_t client jack_client_t JackInfoShutdownCallback function
Definition juce_linux_JackAudio.cpp:63
Type * addBytesToPointer(Type *basePointer, IntegerType bytes) noexcept
Definition juce_Memory.h:111
bool isPositiveAndBelow(Type1 valueToTest, Type2 upperLimit) noexcept
Definition juce_MathsFunctions.h:279
Type * snapPointerToAlignment(Type *basePointer, IntegerType alignmentBytes) noexcept
Definition juce_Memory.h:45
#define false
Definition ordinals.h:83
Definition juce_SIMDRegister.h:63
typename T::value_type Type
Definition juce_AudioBlock.h:49
const typename T::value_type Type
Definition juce_AudioBlock.h:43
Definition juce_AudioBlock.h:36
T Type
Definition juce_AudioBlock.h:37
int n
Definition crypt.c:458
return c
Definition crypt.c:175
typedef int(UZ_EXP MsgFn)()
#define const
Definition zconf.h:137