Access Violation when using SDL2_mixer effects?

70 views Asked by At

I've been working on my own lib for 3D audio using SDL2_Mixer and DSPFilters by Vinne Falco. Currently i'm at the stage where i need to create custom DSP to filter audio, while SDL_mixer takes care of the registering of the effects, the actual DSP is proving difficult.

SDL provides:

void Effect(int chan, void* stream, int len, void* udata){}

From here we have a stream of interleved audio, stream[0L], stream[0R], stream[1L], etc... I've tried breaking it down into seperate channels:

    float *p = (float*)stream;
    int length = len / 2;

    float* audioData[2];
    audioData[0] = new float[length];
    audioData[1] = new float[length];

    for (int i = 0; i < len; i++)
    {
        if (i %2 == 0) 
        {
            audioData[0][i / 2] = p[i];
        }
        else 
        {
            audioData[1][(i - 1) / 2] = p[i];
        }
    }

Once split into channels it is processed by the filter successfully. This is all fine but i now need to recombine this into a stream or how to directly process the stream data. Tried numerous methods but most end in access violations or heap corruptions.

EDIT1: Recombine stage:

    ///Combine output///
    for (int i = 0; i < length; i++)
    {
        p[i*2]=audioData[0][i];
        p[(i*2)+1]=audioData[1][i];
    }

Could anyone either point me in a better direction of processing the stream or a fix for this excerpt of code?

1

There are 1 answers

0
Sulkyoptimism On BEST ANSWER

I'm pretty sure len is in bytes, not in float elements. You could use len/sizeof(float). – keltar

This was the answer provided by keltar, which fixes the access violation. (It was provided on a seperate streamlined question)