Resampling Audio Source is downsamplig custom audio source


#1

I´ve made a custom audio source that takes data from a wave file and stores it in a buffer, when I connect it to a Audio Source Player and it sounds "right" but if I connect it first to an Resampling Audio Source i get a downsampled sound 

 

This is the getNextAudioBlock method I am using:


void CustomAudioSource::getNextAudioBlock (const AudioSourceChannelInfo &bufferToFill)
{
    bufferToFill.buffer->clear();
    for (int i = 0; i < bufferToFill.numSamples; i++) {
    if(currentSample<buffer->getNumSamples())
        {
            bufferToFill.buffer->setSample(0,i,buffer->getSample(0,currentSample));
            bufferToFill.buffer->setSample(0,i,buffer->getSample(0,currentSample));
        }
        else
        currentSample=-1;//this is to loop the buffer
        
        currentSample++;//this is to loop the buffer
    }
}

 

How can I correct this?
 


#2

I was clearing the buffer and losing data...

void CustomAudioSource::getNextAudioBlock (const AudioSourceChannelInfo &bufferToFill)
{
    //bufferToFill.buffer->clear(); commenting this it is solved
    for (int i = 0; i < bufferToFill.numSamples; i++) {
    if(currentSample<buffer->getNumSamples())
        {
            bufferToFill.buffer->setSample(0,bufferToFill.startSample +i,buffer->getSample(0,currentSample));//And also this
            bufferToFill.buffer->setSample(0,bufferToFill.startSample +i,buffer->getSample(0,currentSample));
        }
        else
        currentSample=-1;//this is to loop the buffer
        
        currentSample++;//this is to loop the buffer
    }
}