Native Audio/C++ - UploadSample Loading Different Values for the Same Audio Data

I’m trying to use a copy of the demo convolution reverb plugin code to upload several head-related transfer functions (HRTFs, i.e. very short .wav files) to create a better sense of audio spatialization. I’m using the built-in (in the Native Audio SDK demo) ConvolutionReverb_UploadSample function (see below) to load audio buffers as impulse responses, but the audio content/waveform changes every time I upload the same audio buffer.

For example, when I try to upload an impulse response recorded at a certain location (5 degrees azimuth in this case), sometimes I get this:

2218425--147688--5aOne.png

…other times I get this:

2218425--147689--5aTwo.png

…and other times I get this:

2218425--147690--5aThree.png

It’s the exact same audio file, and this same thing happens even if I try loading sample buffers that I hardcode rather than uploading, so I’m fairly confident that my file upload process is not the culprit.

This is the function I’m using to upload files. It’s already included in the original file in the SDK - I did not modify anything within it. It looks fine, and I even tried manually setting some of the necessary data rather than using this function, but to no avail.

extern "C" UNITY_AUDIODSP_EXPORT_API bool ConvolutionReverbCopy_UploadSample(int index, float* data, int numsamples, int numchannels, int samplerate, const char* name)
{
    if (index < 0 || index >= ConvolutionReverbCopy::MAXSAMPLE)
        return false;
    MutexScopeLock mutexScope(ConvolutionReverbCopy::sampleMutex);
    ConvolutionReverbCopy::IRSample& s = ConvolutionReverbCopy::GetIRSample(index);
    if (s.allocated)
        delete[] s.data;
    int num = numsamples * numchannels;
    if (num > 0)
    {
        s.data = new float[num];
        s.allocated = 1;
        strcpy_s(s.name, name);
        memcpy(s.data, data, numsamples * numchannels * sizeof(float));
    }
    else
    {
        s.data = NULL;
        s.allocated = 1;
    }
    s.numsamples = numsamples;
    s.numchannels = numchannels;
    s.samplerate = samplerate;
    s.updatecount = ++ConvolutionReverbCopy::globalupdatecount;
    return true;
}

Summary: Can anyone help me identify why the audio content is manipulated differently every time I upload the same file?

FWIW, I found out that I was calling the UploadSample function incorrectly for audio files with more than one channel. In short, the numsamples parameter should probably be called numframes since that’s what it’s really looking for. E.g. when trying to upload a 2-channel audio file with 256 samples in the left channel and 256 in the right (i.e., 256 frames), I passed in 512 (numframes * numchannels) instead of 256. Once I changed how I called the function, everything uploaded just fine.

Hi, I was just wondering if you could share how you uploaded your own impulse response into the convolution reverb plugin. I have no experience with C++ and could really use this for a project I am working on. I understand that the necessary variables need to be passed onto ConvolutionReverb_UploadSample in the CreateCallback function, yet I don’t know how to simply read a wave file and get its number of samples, channels etc. Any help would be strongly appreciated.

Sorry… I just found out that there is a C# Script in Assets/Scripts called “ConvolutionReverbUploadIR” that basically does it for you.