AudioSampleBuffer is a second-class citizen


#1

Consider the declaration of AudioSourceChannelInfo:

struct JUCE_API  AudioSourceChannelInfo
{
    AudioSampleBuffer* buffer;
    int startSample;
    int numSamples;
};

There is no convenient way to construct an AudioSampleBuffer that points only to the data described by the AudioSourceChannelInfo. What is missing, is the following constructor for AudioSampleBuffer:

    AudioSampleBuffer (
                       float** dataToReferTo,
                       int numChannels,
                       int startSample,
                       int numSamples) throw();

If we had this constructor we could do this:

void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
{
  AudioSampleBuffer destBuffer (
    bufferToFill->buffer->getArrayOfChannels(),
    bufferToFill->buffer->getNumChannels(),
    bufferToFill->startSample,
    bufferToFill->numSamples);

  int samplesToWrite; // calculate this

  // advance destBuffer
  destBuffer = AudioSampleBuffer (destBuffer->getArrayofChannels(), destBuffer->getNumChannels(), samplesToWrite,
    destBuffer->getNumSamples() - samplesToWrite);

  // ...
}

Or, for clarity, we could have this constructor

    AudioSampleBuffer (const AudioSampleBuffer& other, int startSample);

Now to advance destBuffer we need only do

  destBuffer = AudioSampleBuffer (destBuffer, samplesToWrite);

If we want to overengineer it we could provide operator + (int deltaSamples) and so on and so forth.


#2

+1, and then we don’t need AudioSourceChannelInfo anymore!
the same request --> http://www.rawmaterialsoftware.com/viewtopic.php?f=2&t=6374


#3

[quote=“chkn”]+1, and then we don’t need AudioSourceChannelInfo anymore!
the same request --> http://www.rawmaterialsoftware.com/viewtopic.php?f=2&t=6374[/quote]

Oh yeah…I see what you mean, you pointed out the exact same problem.

It seems Jules has added the constructor which takes a sample offset, hooray!