# AudioSampleBuffer is a second-class citizen

**URL:** https://forum.juce.com/t/audiosamplebuffer-is-a-second-class-citizen/6327
**Category:** General JUCE discussion
**Created:** [January 31, 2011, 8:40pm UTC](https://forum.juce.com/t/audiosamplebuffer-is-a-second-class-citizen/6327 "2011-01-31T20:40:12Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)
#### Post date: [January 31, 2011, 8:40pm UTC](https://forum.juce.com/t/audiosamplebuffer-is-a-second-class-citizen/6327/1 "2011-01-31T20:40:12Z")

</div>

Consider the declaration of AudioSourceChannelInfo:

```auto
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:

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

If we had this constructor we could do this:

```auto
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

```auto
    AudioSampleBuffer (const AudioSampleBuffer& other, int startSample);
```

Now to advance destBuffer we need only do

```auto
  destBuffer = AudioSampleBuffer (destBuffer, samplesToWrite);
```

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

---

<div class="post-metadata">

### Author: ![chkn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/chkn/32/3862_2.png) [@chkn](https://forum.juce.com/u/chkn)
#### Post date: [February 1, 2011, 7:26am UTC](https://forum.juce.com/t/audiosamplebuffer-is-a-second-class-citizen/6327/2 "2011-02-01T07:26:21Z")

</div>

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

---

<div class="post-metadata">

### Author: ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)
#### Post date: [February 1, 2011, 4:10pm UTC](https://forum.juce.com/t/audiosamplebuffer-is-a-second-class-citizen/6327/3 "2011-02-01T16:10:58Z")

</div>

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