# Populating AudioSampleBuffer

**URL:** <https://forum.juce.com/t/populating-audiosamplebuffer/12310>\
**Category:** General JUCE discussion\
**Created:** [February 4, 2014, 12:03am UTC](https://forum.juce.com/t/populating-audiosamplebuffer/12310 "2014-02-04T00:03:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ADNSS](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@ADNSS](https://forum.juce.com/u/ADNSS)\
**Post date:** [February 4, 2014, 12:03am UTC](https://forum.juce.com/t/populating-audiosamplebuffer/12310/1 "2014-02-04T00:03:42Z")

</div>

Hello,

I've just started playing with juce,&nbsp;I'm also a noob in field of c++ so forgive me if my question is stupid.

I wrote a function which resamples the audiobuffer to lower frequancy(for given numeber of samples)&nbsp;to "rBuffer".&nbsp;

Thi looks like this:

```
AudioSampleBuffer* AudioSampler::resample(int64 numSamples, int64 from, int64 into, int64 start)
{
    DBG("resampluje");
    //if(!bBuffer) return 0;
    rBuffer->setSize(2, numSamples  + start, true, true);
    rBuffer->clear(); //!temp
    int spsPerPixel = bBuffer->getNumSamples() / numSamples;
    if(spsPerPixel < 1) spsPerPixel = 1;
    int64 c = 0;
    DBG("resampluje2");
    float* l =  new float[bBuffer->getNumChannels()];
    float* s = new float[1];
    DBG("ustawione tablice:" + String(bBuffer->getNumSamples())+ ":" + String(rBuffer->getNumSamples())+ ":" + String(spsPerPixel));
    for (int i = 0; i < rBuffer->getNumSamples(); i++){
        
        for (int j = 0; j < rBuffer->getNumChannels(); j++){
            
            s[0] = *(bBuffer->getSampleData(j) + (i * spsPerPixel));
            if(c > 695){ DBG("sampel:" + String(s[0]) + ":" + String(c));}
            rBuffer->addFrom(j, start + c, s,1);
            l[j] = s[0];
        }
        
        c++;
        
    }
    return rBuffer;
}
```

The rBuffer&nbsp;is created first in constructor of my class and set to 2 channel, 100 samples.

Then in my function I set it's size for given numeber of samples .

My problem is that when I&nbsp;dont call rBuffer-\>Clear(), only the first 100 samples are set to correct values and the rest are undefined values.

I don't want to always clear old samples.&nbsp;Can someone please explain me how it works?&nbsp;
