Search code examples
c++classaudiobufferjuce

Copying data from one AudioSampleBuffer to another in a different class


I have two separate AudioSampleBuffer objects in two separate classes. Here is the private section of the first class which is called TransportBar.h:

private:
Atomic<int> playState;
Atomic<int> soloState;
Atomic<int> muteState;

unsigned int bufferPosition;
AudioSampleBuffer masterBuffer;
static const int bufferSize = 352800; //constant

and here is the private section of the section class which is called Looper.h:

private:  
//Shared data
Atomic<int> recordState;
Atomic<int> playState;

//Audio data
static const int bufferSize = 352800; //constant
unsigned int bufferPosition;
AudioSampleBuffer audioSampleBuffer;

The application I am creating has 4 tracks which record to audioSampleBuffer. I then want a "master" play button, which plays all this data. Therefor what I need to do is copy the data from audioSampleBuffer to masterBuffer. Is there a way to do this?


Solution

  • AudioSampleBuffer is simply a typedef for AudioBuffer<float>, the documentation for which can be found here. Inside there you will see the copyFrom member function. There are several overloads for this function, one of which takes an AudioBuffer<T> as its source buffer.

    To get access to the AudioSampleBuffer so you can copy it, you must do one of the following:

    • Make it public (or protected if you're in a derived type)
    • Create an getter function
    • Make the other class a friend
    • Use another instance of the same class to access the member

    It's worth asking yourself whether or not this is an architectural problem too; could this problem have been avoided entirely with a better design?