openshot-audio  0.1.2
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) 2015 - ROLI Ltd.
6 
7  Permission is granted to use this software under the terms of either:
8  a) the GPL v2 (or any later version)
9  b) the Affero GPL v3
10 
11  Details of these licenses can be found at: www.gnu.org/licenses
12 
13  JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
14  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15  A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 
17  ------------------------------------------------------------------------------
18 
19  To release a closed-source product which uses JUCE, commercial licenses are
20  available: visit www.juce.com for more information.
21 
22  ==============================================================================
23 */
24 
25 #ifndef JUCE_AUDIOSAMPLEBUFFER_H_INCLUDED
26 #define JUCE_AUDIOSAMPLEBUFFER_H_INCLUDED
27 
28 
29 //==============================================================================
35 {
36 public:
37  //==============================================================================
40 
41  //==============================================================================
51  AudioSampleBuffer (int numChannels,
52  int numSamples) noexcept;
53 
69  AudioSampleBuffer (float* const* dataToReferTo,
70  int numChannels,
71  int numSamples) noexcept;
72 
89  AudioSampleBuffer (float* const* dataToReferTo,
90  int numChannels,
91  int startSample,
92  int numSamples) noexcept;
93 
101 
105  AudioSampleBuffer& operator= (const AudioSampleBuffer&) noexcept;
106 
111 
112  //==============================================================================
116  int getNumChannels() const noexcept { return numChannels; }
117 
121  int getNumSamples() const noexcept { return size; }
122 
130  const float* getReadPointer (int channelNumber) const noexcept
131  {
132  jassert (isPositiveAndBelow (channelNumber, numChannels));
133  return channels [channelNumber];
134  }
135 
143  const float* getReadPointer (int channelNumber, int sampleIndex) const noexcept
144  {
145  jassert (isPositiveAndBelow (channelNumber, numChannels));
146  jassert (isPositiveAndBelow (sampleIndex, size));
147  return channels [channelNumber] + sampleIndex;
148  }
149 
156  float* getWritePointer (int channelNumber) noexcept
157  {
158  jassert (isPositiveAndBelow (channelNumber, numChannels));
159  isClear = false;
160  return channels [channelNumber];
161  }
162 
169  float* getWritePointer (int channelNumber, int sampleIndex) noexcept
170  {
171  jassert (isPositiveAndBelow (channelNumber, numChannels));
172  jassert (isPositiveAndBelow (sampleIndex, size));
173  isClear = false;
174  return channels [channelNumber] + sampleIndex;
175  }
176 
182  const float** getArrayOfReadPointers() const noexcept { return const_cast<const float**> (channels); }
183 
189  float** getArrayOfWritePointers() noexcept { isClear = false; return channels; }
190 
191  //==============================================================================
211  void setSize (int newNumChannels,
212  int newNumSamples,
213  bool keepExistingContent = false,
214  bool clearExtraSpace = false,
215  bool avoidReallocating = false) noexcept;
216 
217 
236  void setDataToReferTo (float** dataToReferTo,
237  int numChannels,
238  int numSamples) noexcept;
239 
240  //==============================================================================
242  void clear() noexcept;
243 
249  void clear (int startSample,
250  int numSamples) noexcept;
251 
257  void clear (int channel,
258  int startSample,
259  int numSamples) noexcept;
260 
267  bool hasBeenCleared() const noexcept { return isClear; }
268 
269  //==============================================================================
275  float getSample (int channel, int sampleIndex) const noexcept;
276 
282  void setSample (int destChannel, int destSample, float newValue) noexcept;
283 
289  void addSample (int destChannel, int destSample, float valueToAdd) noexcept;
290 
296  void applyGain (int channel,
297  int startSample,
298  int numSamples,
299  float gain) noexcept;
300 
306  void applyGain (int startSample,
307  int numSamples,
308  float gain) noexcept;
309 
311  void applyGain (float gain) noexcept;
312 
322  void applyGainRamp (int channel,
323  int startSample,
324  int numSamples,
325  float startGain,
326  float endGain) noexcept;
327 
337  void applyGainRamp (int startSample,
338  int numSamples,
339  float startGain,
340  float endGain) noexcept;
341 
355  void addFrom (int destChannel,
356  int destStartSample,
357  const AudioSampleBuffer& source,
358  int sourceChannel,
359  int sourceStartSample,
360  int numSamples,
361  float gainToApplyToSource = 1.0f) noexcept;
362 
374  void addFrom (int destChannel,
375  int destStartSample,
376  const float* source,
377  int numSamples,
378  float gainToApplyToSource = 1.0f) noexcept;
379 
391  void addFromWithRamp (int destChannel,
392  int destStartSample,
393  const float* source,
394  int numSamples,
395  float startGain,
396  float endGain) noexcept;
397 
409  void copyFrom (int destChannel,
410  int destStartSample,
411  const AudioSampleBuffer& source,
412  int sourceChannel,
413  int sourceStartSample,
414  int numSamples) noexcept;
415 
425  void copyFrom (int destChannel,
426  int destStartSample,
427  const float* source,
428  int numSamples) noexcept;
429 
440  void copyFrom (int destChannel,
441  int destStartSample,
442  const float* source,
443  int numSamples,
444  float gain) noexcept;
445 
459  void copyFromWithRamp (int destChannel,
460  int destStartSample,
461  const float* source,
462  int numSamples,
463  float startGain,
464  float endGain) noexcept;
465 
466 
473  Range<float> findMinMax (int channel,
474  int startSample,
475  int numSamples) const noexcept;
476 
478  float getMagnitude (int channel,
479  int startSample,
480  int numSamples) const noexcept;
481 
483  float getMagnitude (int startSample,
484  int numSamples) const noexcept;
485 
487  float getRMSLevel (int channel,
488  int startSample,
489  int numSamples) const noexcept;
490 
492  void reverse (int channel, int startSample, int numSamples) const noexcept;
493 
495  void reverse (int startSample, int numSamples) const noexcept;
496 
497  //==============================================================================
498  #ifndef DOXYGEN
499  // Note that these methods have now been replaced by getReadPointer() and getWritePointer()
500  JUCE_DEPRECATED_WITH_BODY (const float* getSampleData (int channel) const, { return getReadPointer (channel); })
501  JUCE_DEPRECATED_WITH_BODY (const float* getSampleData (int channel, int index) const, { return getReadPointer (channel, index); })
502  JUCE_DEPRECATED_WITH_BODY (float* getSampleData (int channel), { return getWritePointer (channel); })
503  JUCE_DEPRECATED_WITH_BODY (float* getSampleData (int channel, int index), { return getWritePointer (channel, index); })
504 
505  // These have been replaced by getArrayOfReadPointers() and getArrayOfWritePointers()
506  JUCE_DEPRECATED_WITH_BODY (const float** getArrayOfChannels() const, { return getArrayOfReadPointers(); })
507  JUCE_DEPRECATED_WITH_BODY (float** getArrayOfChannels(), { return getArrayOfWritePointers(); })
508  #endif
509 
510 private:
511  //==============================================================================
512  int numChannels, size;
513  size_t allocatedBytes;
514  float** channels;
515  HeapBlock<char, true> allocatedData;
516  float* preallocatedChannelSpace [32];
517  bool isClear;
518 
519  void allocateData();
520  void allocateChannels (float* const*, int offset);
521 
523 };
524 
525 
526 #endif // JUCE_AUDIOSAMPLEBUFFER_H_INCLUDED
Definition: juce_AudioSampleBuffer.h:34
float * getWritePointer(int channelNumber, int sampleIndex) noexcept
Definition: juce_AudioSampleBuffer.h:169
const float * getReadPointer(int channelNumber) const noexcept
Definition: juce_AudioSampleBuffer.h:130
#define noexcept
Definition: juce_CompilerSupport.h:141
const float ** getArrayOfReadPointers() const noexcept
Definition: juce_AudioSampleBuffer.h:182
bool isPositiveAndBelow(Type valueToTest, Type upperLimit) noexcept
Definition: juce_core.h:238
Definition: juce_Range.h:44
int getNumChannels() const noexcept
Definition: juce_AudioSampleBuffer.h:116
#define JUCE_API
Definition: juce_StandardHeader.h:139
#define const
const float * getReadPointer(int channelNumber, int sampleIndex) const noexcept
Definition: juce_AudioSampleBuffer.h:143
float * getWritePointer(int channelNumber) noexcept
Definition: juce_AudioSampleBuffer.h:156
bool hasBeenCleared() const noexcept
Definition: juce_AudioSampleBuffer.h:267
#define jassert(a)
Definition: juce_PlatformDefs.h:146
#define JUCE_LEAK_DETECTOR(OwnerClass)
Definition: juce_LeakedObjectDetector.h:141
float ** getArrayOfWritePointers() noexcept
Definition: juce_AudioSampleBuffer.h:189
#define JUCE_DEPRECATED_WITH_BODY(functionDef, body)
Definition: juce_PlatformDefs.h:320
int getNumSamples() const noexcept
Definition: juce_AudioSampleBuffer.h:121