FahlGrahn Audio v1.0.0
Loading...
Searching...
No Matches
RingBuffer.h
1#include <JuceHeader.h>
2
4{
5 public:
6 RingBuffer(int size) : mAbstractFifo(size)
7 {
8 mAudioBuffer.setSize(1, size);
9 }
10
11 void setSize(int size)
12 {
13 mAbstractFifo.setTotalSize(size);
14 mAudioBuffer.setSize(1, size);
15 }
16
17 template <typename T> void addToFifo(const T *data, int numSamples)
18 {
19 const auto scope = mAbstractFifo.write(numSamples);
20
21 if (scope.blockSize1 > 0)
22 mAudioBuffer.copyFrom(0, scope.startIndex1, data, scope.blockSize1);
23 if (scope.blockSize2 > 0)
24 mAudioBuffer.copyFrom(0, scope.startIndex2, data + scope.blockSize1, scope.blockSize2);
25 }
26
27 template <typename T> void readFromFifo(T *destination, int numSamples)
28 {
29 const auto scope = mAbstractFifo.read(numSamples);
30
31 const float *buffer = mAudioBuffer.getReadPointer(0);
32
33 if (scope.blockSize1 > 0)
34 std::copy(buffer + scope.startIndex1, buffer + scope.startIndex1 + scope.blockSize1, destination);
35
36 if (scope.blockSize2 > 0)
37 std::copy(buffer + scope.startIndex2, buffer + scope.startIndex2 + scope.blockSize2,
38 destination + scope.blockSize1);
39 }
40
41 int getNumReady()
42 {
43 return mAbstractFifo.getNumReady();
44 }
45
46 juce::AbstractFifo mAbstractFifo;
47
48 private:
49 juce::AudioBuffer<float> mAudioBuffer;
50};
Definition RingBuffer.h:4