LMMS
Loading...
Searching...
No Matches
juce_AudioSampleBuffer.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 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
26//==============================================================================
32template <typename Type>
34{
35public:
36 //==============================================================================
39 : channels (static_cast<Type**> (preallocatedChannelSpace))
40 {
41 }
42
43 //==============================================================================
53 AudioBuffer (int numChannelsToAllocate,
54 int numSamplesToAllocate)
55 : numChannels (numChannelsToAllocate),
56 size (numSamplesToAllocate)
57 {
58 jassert (size >= 0 && numChannels >= 0);
60 }
61
77 AudioBuffer (Type* const* dataToReferTo,
78 int numChannelsToUse,
79 int numSamples)
80 : numChannels (numChannelsToUse),
81 size (numSamples)
82 {
83 jassert (dataToReferTo != nullptr);
84 jassert (numChannelsToUse >= 0 && numSamples >= 0);
85 allocateChannels (dataToReferTo, 0);
86 }
87
104 AudioBuffer (Type* const* dataToReferTo,
105 int numChannelsToUse,
106 int startSample,
107 int numSamples)
108 : numChannels (numChannelsToUse),
109 size (numSamples)
110 {
111 jassert (dataToReferTo != nullptr);
112 jassert (numChannelsToUse >= 0 && startSample >= 0 && numSamples >= 0);
113 allocateChannels (dataToReferTo, startSample);
114 }
115
123 : numChannels (other.numChannels),
124 size (other.size),
126 {
127 if (allocatedBytes == 0)
128 {
129 allocateChannels (other.channels, 0);
130 }
131 else
132 {
133 allocateData();
134
135 if (other.isClear)
136 {
137 clear();
138 }
139 else
140 {
141 for (int i = 0; i < numChannels; ++i)
142 FloatVectorOperations::copy (channels[i], other.channels[i], size);
143 }
144 }
145 }
146
151 AudioBuffer& operator= (const AudioBuffer& other)
152 {
153 if (this != &other)
154 {
155 setSize (other.getNumChannels(), other.getNumSamples(), false, false, false);
156
157 if (other.isClear)
158 {
159 clear();
160 }
161 else
162 {
163 isClear = false;
164
165 for (int i = 0; i < numChannels; ++i)
166 FloatVectorOperations::copy (channels[i], other.channels[i], size);
167 }
168 }
169
170 return *this;
171 }
172
177 ~AudioBuffer() = default;
178
181 : numChannels (other.numChannels),
182 size (other.size),
183 allocatedBytes (other.allocatedBytes),
184 allocatedData (std::move (other.allocatedData)),
185 isClear (other.isClear)
186 {
188 {
190
191 for (int i = 0; i < numChannels; ++i)
192 preallocatedChannelSpace[i] = other.channels[i];
193 }
194 else
195 {
196 channels = other.channels;
197 }
198
199 other.numChannels = 0;
200 other.size = 0;
201 other.allocatedBytes = 0;
202 }
203
205 AudioBuffer& operator= (AudioBuffer&& other) noexcept
206 {
207 numChannels = other.numChannels;
208 size = other.size;
209 allocatedBytes = other.allocatedBytes;
210 allocatedData = std::move (other.allocatedData);
211 isClear = other.isClear;
212
214 {
216
217 for (int i = 0; i < numChannels; ++i)
218 preallocatedChannelSpace[i] = other.channels[i];
219 }
220 else
221 {
222 channels = other.channels;
223 }
224
225 other.numChannels = 0;
226 other.size = 0;
227 other.allocatedBytes = 0;
228 return *this;
229 }
230
231 //==============================================================================
237
243
253 const Type* getReadPointer (int channelNumber) const noexcept
254 {
255 jassert (isPositiveAndBelow (channelNumber, numChannels));
256 return channels[channelNumber];
257 }
258
268 const Type* getReadPointer (int channelNumber, int sampleIndex) const noexcept
269 {
270 jassert (isPositiveAndBelow (channelNumber, numChannels));
271 jassert (isPositiveAndBelow (sampleIndex, size));
272 return channels[channelNumber] + sampleIndex;
273 }
274
291 Type* getWritePointer (int channelNumber) noexcept
292 {
293 jassert (isPositiveAndBelow (channelNumber, numChannels));
294 isClear = false;
295 return channels[channelNumber];
296 }
297
314 Type* getWritePointer (int channelNumber, int sampleIndex) noexcept
315 {
316 jassert (isPositiveAndBelow (channelNumber, numChannels));
317 jassert (isPositiveAndBelow (sampleIndex, size));
318 isClear = false;
319 return channels[channelNumber] + sampleIndex;
320 }
321
327 const Type** getArrayOfReadPointers() const noexcept { return const_cast<const Type**> (channels); }
328
342 Type** getArrayOfWritePointers() noexcept { isClear = false; return channels; }
343
344 //==============================================================================
367 void setSize (int newNumChannels,
368 int newNumSamples,
369 bool keepExistingContent = false,
370 bool clearExtraSpace = false,
371 bool avoidReallocating = false)
372 {
373 jassert (newNumChannels >= 0);
374 jassert (newNumSamples >= 0);
375
376 if (newNumSamples != size || newNumChannels != numChannels)
377 {
378 auto allocatedSamplesPerChannel = ((size_t) newNumSamples + 3) & ~3u;
379 auto channelListSize = ((static_cast<size_t> (1 + newNumChannels) * sizeof (Type*)) + 15) & ~15u;
380 auto newTotalBytes = ((size_t) newNumChannels * (size_t) allocatedSamplesPerChannel * sizeof (Type))
381 + channelListSize + 32;
382
383 if (keepExistingContent)
384 {
385 if (avoidReallocating && newNumChannels <= numChannels && newNumSamples <= size)
386 {
387 // no need to do any remapping in this case, as the channel pointers will remain correct!
388 }
389 else
390 {
391 HeapBlock<char, true> newData;
392 newData.allocate (newTotalBytes, clearExtraSpace || isClear);
393
394 auto numSamplesToCopy = (size_t) jmin (newNumSamples, size);
395
396 auto newChannels = unalignedPointerCast<Type**> (newData.get());
397 auto newChan = unalignedPointerCast<Type*> (newData + channelListSize);
398
399 for (int j = 0; j < newNumChannels; ++j)
400 {
401 newChannels[j] = newChan;
402 newChan += allocatedSamplesPerChannel;
403 }
404
405 if (! isClear)
406 {
407 auto numChansToCopy = jmin (numChannels, newNumChannels);
408
409 for (int i = 0; i < numChansToCopy; ++i)
410 FloatVectorOperations::copy (newChannels[i], channels[i], (int) numSamplesToCopy);
411 }
412
413 allocatedData.swapWith (newData);
414 allocatedBytes = newTotalBytes;
415 channels = newChannels;
416 }
417 }
418 else
419 {
420 if (avoidReallocating && allocatedBytes >= newTotalBytes)
421 {
422 if (clearExtraSpace || isClear)
423 allocatedData.clear (newTotalBytes);
424 }
425 else
426 {
427 allocatedBytes = newTotalBytes;
428 allocatedData.allocate (newTotalBytes, clearExtraSpace || isClear);
430 }
431
432 auto* chan = unalignedPointerCast<Type*> (allocatedData + channelListSize);
433
434 for (int i = 0; i < newNumChannels; ++i)
435 {
436 channels[i] = chan;
437 chan += allocatedSamplesPerChannel;
438 }
439 }
440
441 channels[newNumChannels] = nullptr;
442 size = newNumSamples;
443 numChannels = newNumChannels;
444 }
445 }
446
468 void setDataToReferTo (Type** dataToReferTo,
469 int newNumChannels,
470 int newStartSample,
471 int newNumSamples)
472 {
473 jassert (dataToReferTo != nullptr);
474 jassert (newNumChannels >= 0 && newNumSamples >= 0);
475
476 if (allocatedBytes != 0)
477 {
478 allocatedBytes = 0;
479 allocatedData.free();
480 }
481
482 numChannels = newNumChannels;
483 size = newNumSamples;
484
485 allocateChannels (dataToReferTo, newStartSample);
486 jassert (! isClear);
487 }
488
509 void setDataToReferTo (Type** dataToReferTo,
510 int newNumChannels,
511 int newNumSamples)
512 {
513 setDataToReferTo (dataToReferTo, newNumChannels, 0, newNumSamples);
514 }
515
524 template <typename OtherType>
525 void makeCopyOf (const AudioBuffer<OtherType>& other, bool avoidReallocating = false)
526 {
527 setSize (other.getNumChannels(), other.getNumSamples(), false, false, avoidReallocating);
528
529 if (other.hasBeenCleared())
530 {
531 clear();
532 }
533 else
534 {
535 isClear = false;
536
537 for (int chan = 0; chan < numChannels; ++chan)
538 {
539 auto* dest = channels[chan];
540 auto* src = other.getReadPointer (chan);
541
542 for (int i = 0; i < size; ++i)
543 dest[i] = static_cast<Type> (src[i]);
544 }
545 }
546 }
547
548 //==============================================================================
557 {
558 if (! isClear)
559 {
560 for (int i = 0; i < numChannels; ++i)
561 FloatVectorOperations::clear (channels[i], size);
562
563 isClear = true;
564 }
565 }
566
579 void clear (int startSample, int numSamples) noexcept
580 {
581 jassert (startSample >= 0 && numSamples >= 0 && startSample + numSamples <= size);
582
583 if (! isClear)
584 {
585 for (int i = 0; i < numChannels; ++i)
586 FloatVectorOperations::clear (channels[i] + startSample, numSamples);
587
588 isClear = (startSample == 0 && numSamples == size);
589 }
590 }
591
602 void clear (int channel, int startSample, int numSamples) noexcept
603 {
605 jassert (startSample >= 0 && numSamples >= 0 && startSample + numSamples <= size);
606
607 if (! isClear)
608 FloatVectorOperations::clear (channels[channel] + startSample, numSamples);
609 }
610
619
627 void setNotClear() noexcept { isClear = false; }
628
629 //==============================================================================
636 Type getSample (int channel, int sampleIndex) const noexcept
637 {
639 jassert (isPositiveAndBelow (sampleIndex, size));
640 return *(channels[channel] + sampleIndex);
641 }
642
651 void setSample (int destChannel, int destSample, Type newValue) noexcept
652 {
653 jassert (isPositiveAndBelow (destChannel, numChannels));
654 jassert (isPositiveAndBelow (destSample, size));
655 *(channels[destChannel] + destSample) = newValue;
656 isClear = false;
657 }
658
667 void addSample (int destChannel, int destSample, Type valueToAdd) noexcept
668 {
669 jassert (isPositiveAndBelow (destChannel, numChannels));
670 jassert (isPositiveAndBelow (destSample, size));
671 *(channels[destChannel] + destSample) += valueToAdd;
672 isClear = false;
673 }
674
680 void applyGain (int channel, int startSample, int numSamples, Type gain) noexcept
681 {
683 jassert (startSample >= 0 && numSamples >= 0 && startSample + numSamples <= size);
684
685 if (gain != Type (1) && ! isClear)
686 {
687 auto* d = channels[channel] + startSample;
688
689 if (gain == Type())
690 FloatVectorOperations::clear (d, numSamples);
691 else
692 FloatVectorOperations::multiply (d, gain, numSamples);
693 }
694 }
695
701 void applyGain (int startSample, int numSamples, Type gain) noexcept
702 {
703 for (int i = 0; i < numChannels; ++i)
704 applyGain (i, startSample, numSamples, gain);
705 }
706
708 void applyGain (Type gain) noexcept
709 {
710 applyGain (0, size, gain);
711 }
712
722 void applyGainRamp (int channel, int startSample, int numSamples,
723 Type startGain, Type endGain) noexcept
724 {
725 if (! isClear)
726 {
727 if (startGain == endGain)
728 {
729 applyGain (channel, startSample, numSamples, startGain);
730 }
731 else
732 {
734 jassert (startSample >= 0 && numSamples >= 0 && startSample + numSamples <= size);
735
736 const auto increment = (endGain - startGain) / (float) numSamples;
737 auto* d = channels[channel] + startSample;
738
739 while (--numSamples >= 0)
740 {
741 *d++ *= startGain;
742 startGain += increment;
743 }
744 }
745 }
746 }
747
757 void applyGainRamp (int startSample, int numSamples,
758 Type startGain, Type endGain) noexcept
759 {
760 for (int i = 0; i < numChannels; ++i)
761 applyGainRamp (i, startSample, numSamples, startGain, endGain);
762 }
763
780 void addFrom (int destChannel,
781 int destStartSample,
782 const AudioBuffer& source,
783 int sourceChannel,
784 int sourceStartSample,
785 int numSamples,
786 Type gainToApplyToSource = Type (1)) noexcept
787 {
788 jassert (&source != this
789 || sourceChannel != destChannel
790 || sourceStartSample + numSamples <= destStartSample
791 || destStartSample + numSamples <= sourceStartSample);
792 jassert (isPositiveAndBelow (destChannel, numChannels));
793 jassert (destStartSample >= 0 && numSamples >= 0 && destStartSample + numSamples <= size);
794 jassert (isPositiveAndBelow (sourceChannel, source.numChannels));
795 jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
796
797 if (gainToApplyToSource != 0 && numSamples > 0 && ! source.isClear)
798 {
799 auto* d = channels[destChannel] + destStartSample;
800 auto* s = source.channels[sourceChannel] + sourceStartSample;
801
802 if (isClear)
803 {
804 isClear = false;
805
806 if (gainToApplyToSource != Type (1))
807 FloatVectorOperations::copyWithMultiply (d, s, gainToApplyToSource, numSamples);
808 else
809 FloatVectorOperations::copy (d, s, numSamples);
810 }
811 else
812 {
813 if (gainToApplyToSource != Type (1))
814 FloatVectorOperations::addWithMultiply (d, s, gainToApplyToSource, numSamples);
815 else
816 FloatVectorOperations::add (d, s, numSamples);
817 }
818 }
819 }
820
835 void addFrom (int destChannel,
836 int destStartSample,
837 const Type* source,
838 int numSamples,
839 Type gainToApplyToSource = Type (1)) noexcept
840 {
841 jassert (isPositiveAndBelow (destChannel, numChannels));
842 jassert (destStartSample >= 0 && numSamples >= 0 && destStartSample + numSamples <= size);
843 jassert (source != nullptr);
844
845 if (gainToApplyToSource != 0 && numSamples > 0)
846 {
847 auto* d = channels[destChannel] + destStartSample;
848
849 if (isClear)
850 {
851 isClear = false;
852
853 if (gainToApplyToSource != Type (1))
854 FloatVectorOperations::copyWithMultiply (d, source, gainToApplyToSource, numSamples);
855 else
856 FloatVectorOperations::copy (d, source, numSamples);
857 }
858 else
859 {
860 if (gainToApplyToSource != Type (1))
861 FloatVectorOperations::addWithMultiply (d, source, gainToApplyToSource, numSamples);
862 else
863 FloatVectorOperations::add (d, source, numSamples);
864 }
865 }
866 }
867
868
883 void addFromWithRamp (int destChannel,
884 int destStartSample,
885 const Type* source,
886 int numSamples,
887 Type startGain,
888 Type endGain) noexcept
889 {
890 if (startGain == endGain)
891 {
892 addFrom (destChannel, destStartSample, source, numSamples, startGain);
893 }
894 else
895 {
896 jassert (isPositiveAndBelow (destChannel, numChannels));
897 jassert (destStartSample >= 0 && numSamples >= 0 && destStartSample + numSamples <= size);
898 jassert (source != nullptr);
899
900 if (numSamples > 0)
901 {
902 isClear = false;
903 const auto increment = (endGain - startGain) / numSamples;
904 auto* d = channels[destChannel] + destStartSample;
905
906 while (--numSamples >= 0)
907 {
908 *d++ += startGain * *source++;
909 startGain += increment;
910 }
911 }
912 }
913 }
914
926 void copyFrom (int destChannel,
927 int destStartSample,
928 const AudioBuffer& source,
929 int sourceChannel,
930 int sourceStartSample,
931 int numSamples) noexcept
932 {
933 jassert (&source != this
934 || sourceChannel != destChannel
935 || sourceStartSample + numSamples <= destStartSample
936 || destStartSample + numSamples <= sourceStartSample);
937 jassert (isPositiveAndBelow (destChannel, numChannels));
938 jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
939 jassert (isPositiveAndBelow (sourceChannel, source.numChannels));
940 jassert (sourceStartSample >= 0 && numSamples >= 0 && sourceStartSample + numSamples <= source.size);
941
942 if (numSamples > 0)
943 {
944 if (source.isClear)
945 {
946 if (! isClear)
947 FloatVectorOperations::clear (channels[destChannel] + destStartSample, numSamples);
948 }
949 else
950 {
951 isClear = false;
952 FloatVectorOperations::copy (channels[destChannel] + destStartSample,
953 source.channels[sourceChannel] + sourceStartSample,
954 numSamples);
955 }
956 }
957 }
958
971 void copyFrom (int destChannel,
972 int destStartSample,
973 const Type* source,
974 int numSamples) noexcept
975 {
976 jassert (isPositiveAndBelow (destChannel, numChannels));
977 jassert (destStartSample >= 0 && numSamples >= 0 && destStartSample + numSamples <= size);
978 jassert (source != nullptr);
979
980 if (numSamples > 0)
981 {
982 isClear = false;
983 FloatVectorOperations::copy (channels[destChannel] + destStartSample, source, numSamples);
984 }
985 }
986
1000 void copyFrom (int destChannel,
1001 int destStartSample,
1002 const Type* source,
1003 int numSamples,
1004 Type gain) noexcept
1005 {
1006 jassert (isPositiveAndBelow (destChannel, numChannels));
1007 jassert (destStartSample >= 0 && numSamples >= 0 && destStartSample + numSamples <= size);
1008 jassert (source != nullptr);
1009
1010 if (numSamples > 0)
1011 {
1012 auto* d = channels[destChannel] + destStartSample;
1013
1014 if (gain != Type (1))
1015 {
1016 if (gain == Type())
1017 {
1018 if (! isClear)
1019 FloatVectorOperations::clear (d, numSamples);
1020 }
1021 else
1022 {
1023 isClear = false;
1024 FloatVectorOperations::copyWithMultiply (d, source, gain, numSamples);
1025 }
1026 }
1027 else
1028 {
1029 isClear = false;
1030 FloatVectorOperations::copy (d, source, numSamples);
1031 }
1032 }
1033 }
1034
1051 void copyFromWithRamp (int destChannel,
1052 int destStartSample,
1053 const Type* source,
1054 int numSamples,
1055 Type startGain,
1056 Type endGain) noexcept
1057 {
1058 if (startGain == endGain)
1059 {
1060 copyFrom (destChannel, destStartSample, source, numSamples, startGain);
1061 }
1062 else
1063 {
1064 jassert (isPositiveAndBelow (destChannel, numChannels));
1065 jassert (destStartSample >= 0 && numSamples >= 0 && destStartSample + numSamples <= size);
1066 jassert (source != nullptr);
1067
1068 if (numSamples > 0)
1069 {
1070 isClear = false;
1071 const auto increment = (endGain - startGain) / numSamples;
1072 auto* d = channels[destChannel] + destStartSample;
1073
1074 while (--numSamples >= 0)
1075 {
1076 *d++ = startGain * *source++;
1077 startGain += increment;
1078 }
1079 }
1080 }
1081 }
1082
1089 Range<Type> findMinMax (int channel, int startSample, int numSamples) const noexcept
1090 {
1092 jassert (startSample >= 0 && numSamples >= 0 && startSample + numSamples <= size);
1093
1094 if (isClear)
1095 return { Type (0), Type (0) };
1096
1097 return FloatVectorOperations::findMinAndMax (channels[channel] + startSample, numSamples);
1098 }
1099
1101 Type getMagnitude (int channel, int startSample, int numSamples) const noexcept
1102 {
1104 jassert (startSample >= 0 && numSamples >= 0 && startSample + numSamples <= size);
1105
1106 if (isClear)
1107 return Type (0);
1108
1109 auto r = findMinMax (channel, startSample, numSamples);
1110
1111 return jmax (r.getStart(), -r.getStart(), r.getEnd(), -r.getEnd());
1112 }
1113
1115 Type getMagnitude (int startSample, int numSamples) const noexcept
1116 {
1117 Type mag (0);
1118
1119 if (! isClear)
1120 for (int i = 0; i < numChannels; ++i)
1121 mag = jmax (mag, getMagnitude (i, startSample, numSamples));
1122
1123 return mag;
1124 }
1125
1127 Type getRMSLevel (int channel, int startSample, int numSamples) const noexcept
1128 {
1130 jassert (startSample >= 0 && numSamples >= 0 && startSample + numSamples <= size);
1131
1132 if (numSamples <= 0 || channel < 0 || channel >= numChannels || isClear)
1133 return Type (0);
1134
1135 auto* data = channels[channel] + startSample;
1136 double sum = 0.0;
1137
1138 for (int i = 0; i < numSamples; ++i)
1139 {
1140 auto sample = data[i];
1141 sum += sample * sample;
1142 }
1143
1144 return static_cast<Type> (std::sqrt (sum / numSamples));
1145 }
1146
1148 void reverse (int channel, int startSample, int numSamples) const noexcept
1149 {
1151 jassert (startSample >= 0 && numSamples >= 0 && startSample + numSamples <= size);
1152
1153 if (! isClear)
1154 std::reverse (channels[channel] + startSample,
1155 channels[channel] + startSample + numSamples);
1156 }
1157
1159 void reverse (int startSample, int numSamples) const noexcept
1160 {
1161 for (int i = 0; i < numChannels; ++i)
1162 reverse (i, startSample, numSamples);
1163 }
1164
1165 //==============================================================================
1167 using SampleType = Type;
1168
1169private:
1170 //==============================================================================
1172 {
1173 #if (! JUCE_GCC || (__GNUC__ * 100 + __GNUC_MINOR__) >= 409)
1174 static_assert (alignof (Type) <= maxAlignment,
1175 "AudioBuffer cannot hold types with alignment requirements larger than that guaranteed by malloc");
1176 #endif
1177 jassert (size >= 0);
1178
1179 auto channelListSize = (size_t) (numChannels + 1) * sizeof (Type*);
1180 auto requiredSampleAlignment = std::alignment_of<Type>::value;
1181 size_t alignmentOverflow = channelListSize % requiredSampleAlignment;
1182
1183 if (alignmentOverflow != 0)
1184 channelListSize += requiredSampleAlignment - alignmentOverflow;
1185
1186 allocatedBytes = (size_t) numChannels * (size_t) size * sizeof (Type) + channelListSize + 32;
1189 auto chan = unalignedPointerCast<Type*> (allocatedData + channelListSize);
1190
1191 for (int i = 0; i < numChannels; ++i)
1192 {
1193 channels[i] = chan;
1194 chan += size;
1195 }
1196
1197 channels[numChannels] = nullptr;
1198 isClear = false;
1199 }
1200
1201 void allocateChannels (Type* const* dataToReferTo, int offset)
1202 {
1203 jassert (offset >= 0);
1204
1205 // (try to avoid doing a malloc here, as that'll blow up things like Pro-Tools)
1207 {
1208 channels = static_cast<Type**> (preallocatedChannelSpace);
1209 }
1210 else
1211 {
1212 allocatedData.malloc (numChannels + 1, sizeof (Type*));
1214 }
1215
1216 for (int i = 0; i < numChannels; ++i)
1217 {
1218 // you have to pass in the same number of valid pointers as numChannels
1219 jassert (dataToReferTo[i] != nullptr);
1220 channels[i] = dataToReferTo[i] + offset;
1221 }
1222
1223 channels[numChannels] = nullptr;
1224 isClear = false;
1225 }
1226
1227 /* On iOS/arm7 the alignment of `double` is greater than the alignment of
1228 `std::max_align_t`, so we can't trust max_align_t. Instead, we query
1229 lots of primitive types and use the maximum alignment of all of them.
1230 */
1231 static constexpr size_t getMaxAlignment() noexcept
1232 {
1233 constexpr size_t alignments[] { alignof (std::max_align_t),
1234 alignof (void*),
1235 alignof (float),
1236 alignof (double),
1237 alignof (long double),
1238 alignof (short int),
1239 alignof (int),
1240 alignof (long int),
1241 alignof (long long int),
1242 alignof (bool),
1243 alignof (char),
1244 alignof (char16_t),
1245 alignof (char32_t),
1246 alignof (wchar_t) };
1247
1248 size_t max = 0;
1249
1250 for (const auto elem : alignments)
1251 max = jmax (max, elem);
1252
1253 return max;
1254 }
1255
1256 int numChannels = 0, size = 0;
1257 size_t allocatedBytes = 0;
1258 Type** channels;
1261 bool isClear = false;
1262 static constexpr size_t maxAlignment = getMaxAlignment();
1263
1265};
1266
1267//==============================================================================
1278
1279} // namespace juce
Type jmin(const Type a, const Type b)
Definition MathsFunctions.h:60
Type jmax(const Type a, const Type b)
Definition MathsFunctions.h:48
#define noexcept
Definition DistrhoDefines.h:72
Definition juce_AudioSampleBuffer.h:34
int size
Definition juce_AudioSampleBuffer.h:1256
HeapBlock< char, true > allocatedData
Definition juce_AudioSampleBuffer.h:1259
void allocateData()
Definition juce_AudioSampleBuffer.h:1171
AudioBuffer(Type *const *dataToReferTo, int numChannelsToUse, int startSample, int numSamples)
Definition juce_AudioSampleBuffer.h:104
void setSize(int newNumChannels, int newNumSamples, bool keepExistingContent=false, bool clearExtraSpace=false, bool avoidReallocating=false)
Definition juce_AudioSampleBuffer.h:367
Type getMagnitude(int channel, int startSample, int numSamples) const noexcept
Definition juce_AudioSampleBuffer.h:1101
AudioBuffer(Type *const *dataToReferTo, int numChannelsToUse, int numSamples)
Definition juce_AudioSampleBuffer.h:77
Type getSample(int channel, int sampleIndex) const noexcept
Definition juce_AudioSampleBuffer.h:636
float * preallocatedChannelSpace[32]
Definition juce_AudioSampleBuffer.h:1260
void applyGain(Type gain) noexcept
Definition juce_AudioSampleBuffer.h:708
Range< Type > findMinMax(int channel, int startSample, int numSamples) const noexcept
Definition juce_AudioSampleBuffer.h:1089
AudioBuffer(const AudioBuffer &other)
Definition juce_AudioSampleBuffer.h:122
const Type * getReadPointer(int channelNumber, int sampleIndex) const noexcept
Definition juce_AudioSampleBuffer.h:268
int numChannels
Definition juce_AudioSampleBuffer.h:1256
void makeCopyOf(const AudioBuffer< OtherType > &other, bool avoidReallocating=false)
Definition juce_AudioSampleBuffer.h:525
void setNotClear() noexcept
Definition juce_AudioSampleBuffer.h:627
void applyGain(int startSample, int numSamples, Type gain) noexcept
Definition juce_AudioSampleBuffer.h:701
void setDataToReferTo(Type **dataToReferTo, int newNumChannels, int newNumSamples)
Definition juce_AudioSampleBuffer.h:509
void copyFromWithRamp(int destChannel, int destStartSample, const Type *source, int numSamples, Type startGain, Type endGain) noexcept
Definition juce_AudioSampleBuffer.h:1051
void addSample(int destChannel, int destSample, Type valueToAdd) noexcept
Definition juce_AudioSampleBuffer.h:667
Type getRMSLevel(int channel, int startSample, int numSamples) const noexcept
Definition juce_AudioSampleBuffer.h:1127
Type * getWritePointer(int channelNumber) noexcept
Definition juce_AudioSampleBuffer.h:291
void copyFrom(int destChannel, int destStartSample, const Type *source, int numSamples) noexcept
Definition juce_AudioSampleBuffer.h:971
float ** channels
Definition juce_AudioSampleBuffer.h:1258
int getNumChannels() const noexcept
Definition juce_AudioSampleBuffer.h:236
Type * getWritePointer(int channelNumber, int sampleIndex) noexcept
Definition juce_AudioSampleBuffer.h:314
int getNumSamples() const noexcept
Definition juce_AudioSampleBuffer.h:242
void clear() noexcept
Definition juce_AudioSampleBuffer.h:556
void clear(int channel, int startSample, int numSamples) noexcept
Definition juce_AudioSampleBuffer.h:602
void copyFrom(int destChannel, int destStartSample, const Type *source, int numSamples, Type gain) noexcept
Definition juce_AudioSampleBuffer.h:1000
~AudioBuffer()=default
void applyGainRamp(int channel, int startSample, int numSamples, Type startGain, Type endGain) noexcept
Definition juce_AudioSampleBuffer.h:722
void setDataToReferTo(Type **dataToReferTo, int newNumChannels, int newStartSample, int newNumSamples)
Definition juce_AudioSampleBuffer.h:468
void copyFrom(int destChannel, int destStartSample, const AudioBuffer &source, int sourceChannel, int sourceStartSample, int numSamples) noexcept
Definition juce_AudioSampleBuffer.h:926
void reverse(int startSample, int numSamples) const noexcept
Definition juce_AudioSampleBuffer.h:1159
void addFromWithRamp(int destChannel, int destStartSample, const Type *source, int numSamples, Type startGain, Type endGain) noexcept
Definition juce_AudioSampleBuffer.h:883
static constexpr size_t getMaxAlignment() noexcept
Definition juce_AudioSampleBuffer.h:1231
bool isClear
Definition juce_AudioSampleBuffer.h:1261
Type getMagnitude(int startSample, int numSamples) const noexcept
Definition juce_AudioSampleBuffer.h:1115
void reverse(int channel, int startSample, int numSamples) const noexcept
Definition juce_AudioSampleBuffer.h:1148
void setSample(int destChannel, int destSample, Type newValue) noexcept
Definition juce_AudioSampleBuffer.h:651
void addFrom(int destChannel, int destStartSample, const AudioBuffer &source, int sourceChannel, int sourceStartSample, int numSamples, Type gainToApplyToSource=Type(1)) noexcept
Definition juce_AudioSampleBuffer.h:780
size_t allocatedBytes
Definition juce_AudioSampleBuffer.h:1257
bool hasBeenCleared() const noexcept
Definition juce_AudioSampleBuffer.h:618
const Type * getReadPointer(int channelNumber) const noexcept
Definition juce_AudioSampleBuffer.h:253
AudioBuffer(AudioBuffer &&other) noexcept
Definition juce_AudioSampleBuffer.h:180
Type SampleType
Definition juce_AudioSampleBuffer.h:1167
AudioBuffer() noexcept
Definition juce_AudioSampleBuffer.h:38
void clear(int startSample, int numSamples) noexcept
Definition juce_AudioSampleBuffer.h:579
const Type ** getArrayOfReadPointers() const noexcept
Definition juce_AudioSampleBuffer.h:327
static constexpr size_t maxAlignment
Definition juce_AudioSampleBuffer.h:1262
AudioBuffer(int numChannelsToAllocate, int numSamplesToAllocate)
Definition juce_AudioSampleBuffer.h:53
void allocateChannels(float *const *dataToReferTo, int offset)
Definition juce_AudioSampleBuffer.h:1201
void addFrom(int destChannel, int destStartSample, const Type *source, int numSamples, Type gainToApplyToSource=Type(1)) noexcept
Definition juce_AudioSampleBuffer.h:835
void applyGainRamp(int startSample, int numSamples, Type startGain, Type endGain) noexcept
Definition juce_AudioSampleBuffer.h:757
Type ** getArrayOfWritePointers() noexcept
Definition juce_AudioSampleBuffer.h:342
void applyGain(int channel, int startSample, int numSamples, Type gain) noexcept
Definition juce_AudioSampleBuffer.h:680
Definition juce_HeapBlock.h:87
ElementType * get() const noexcept
Definition juce_HeapBlock.h:188
void allocate(SizeType newNumElements, bool initialiseToZero)
Definition juce_HeapBlock.h:275
Definition juce_Range.h:40
register unsigned j
Definition inflate.c:1576
unsigned d
Definition inflate.c:940
register unsigned i
Definition inflate.c:1575
unsigned s
Definition inflate.c:1555
JSAMPIMAGE data
Definition jpeglib.h:945
#define JUCE_LEAK_DETECTOR(OwnerClass)
Definition juce_LeakedObjectDetector.h:138
#define jassert(expression)
Definition carla_juce.cpp:31
constexpr Type jmin(Type a, Type b)
Definition juce_MathsFunctions.h:106
Type unalignedPointerCast(void *ptr) noexcept
Definition juce_Memory.h:88
constexpr Type jmax(Type a, Type b)
Definition juce_MathsFunctions.h:94
AudioBuffer< float > AudioSampleBuffer
Definition juce_AudioSampleBuffer.h:1277
bool isPositiveAndBelow(Type1 valueToTest, Type2 upperLimit) noexcept
Definition juce_MathsFunctions.h:279
constexpr int numElementsInArray(Type(&)[N]) noexcept
Definition juce_MathsFunctions.h:344
#define max(x, y)
Definition os.h:78
signed int sample
Definition tap_dynamics_m.c:41
int r
Definition crypt.c:458
ulg size
Definition extract.c:2350
typedef int(UZ_EXP MsgFn)()
#define const
Definition zconf.h:137