0
0

Hello!

I got very intrested in FMOD and started playing with it, it is a fantastic sound engine and it got me interested in how you can manipulate audio. I based my try on the Custom DSP example that was in the FMOD API folder.

So i started out with trying to code a very simple feedback delay, it felt clear how to do it in my mind but it turned out to be harder.

[code:423i43ny]FMOD_RESULT F_CALLBACK myDSPCallback(FMOD_DSP_STATE *dsp_state, float *inbuffer, float *outbuffer, unsigned int length, int inchannels, int outchannels)
{
unsigned int count, userdata;
int count2;
char name[256];
FMOD::DSP *thisdsp = (FMOD::DSP *)dsp_state->instance;
float fDlyTime = 0.5;

float MaxDlyTime = 1.0;

float feedback = 1.0;

float DlyBuffer[length];
int i, j;

thisdsp->getInfo(name, 0, 0, 0, 0);

thisdsp->getUserData((void **)&userdata);

for (count = 0; count < length; count++) 
{ 

    for (count2 = 0; count2 < outchannels; count2++)
    {
        if( i >= length )
            i = 0;

        j = i - (fDlyTime * MaxDlyTime);

        if( j < 0 )
            j += length;

        outbuffer[(count * outchannels) + count2] = DlyBuffer[ i++ ] = inbuffer[(count * inchannels) + count2] + (DlyBuffer[ j ] * feedback);

        i++;
    }
} 

return FMOD_OK; 

} [/code:423i43ny]

However, i only get a solid tone when i activate my custom DSP. I don’t really know where to go from here. Can someone with more experience of how a delay works explain what i am doing wrong?

  • You must to post comments
0
0

[code:1ve8wzcj] float DlyBuffer[length];[/code:1ve8wzcj]
You cant declare your buffer on the stack, it will disappear when it goes out of scope. For testing purposes you can make that declaration static and at least the data will still be there next iteration. A proper solution would be to declare a buffer using new or malloc and put a pointer to it in the userdata property.

[code:1ve8wzcj] int i, j; [/code:1ve8wzcj]
[code:1ve8wzcj] if( i >= length ) [/code:1ve8wzcj]

You’re not setting ‘i’ or ‘j’ to any value before doing this comparison, this should be producing a warning in the compiler. The loop values are called ‘count’ and ‘count2’ for those loops, you should be able to just use those.

You have the right idea of how to create a delay filter. You need to copy the data into that buffer. The output of the filter should be (input + feedback_factor * buffer)

-Pete

  • You must to post comments
0
0

Okay… Hmm i tried to implement what you suggested but no:

[code:3ihnm6fb]FMOD_RESULT F_CALLBACK myDSPCallback(FMOD_DSP_STATE *dsp_state, float *inbuffer, float *outbuffer, unsigned int length, int inchannels, int outchannels)
{
unsigned int count, userdata;
int count2;
char name[256];
FMOD::DSP *thisdsp = (FMOD::DSP *)dsp_state->instance;
float fDlyTime = 2000;

float MaxDlyTime = 44100;

float feedback;
if(echo <= 1) {
    feedback = echo;
} else {
    feedback = 1;
}

static float DlyBuffer[44100];
int i = 0, j = 0 ;

thisdsp->getInfo(name, 0, 0, 0, 0);

thisdsp->getUserData((void **)&userdata);

for (count = 0; count < length; count++) 
{ 

    for (count2 = 0; count2 < outchannels; count2++)
    {
        if( i >= length )
            i = 0;

        j = i - (fDlyTime * MaxDlyTime);

        if( j < 0 )
            j += length;

        outbuffer[(count * outchannels) + count2] = DlyBuffer[ i++ ] = inbuffer[(count * inchannels) + count2] + (DlyBuffer[ j ] * feedback);

        i++;
    }
} 

return FMOD_OK; 

}
[/code:3ihnm6fb]

(this is a Very rough test, very bad code, don’t mind it)

  • You must to post comments
0
0

[quote:2p4es4ok] float fDlyTime = 2000;

float MaxDlyTime = 44100; [/quote:2p4es4ok]
Assuming the delay time is in milliseconds that buffer is too small. You’re going to need a buffer big enough to hold (numchannels x frequency x maxdelay[in seconds] )

Since the DSP output will be of the size (numchannels x length), you should be able to make do with the count and count2 variables. I think those ‘i’ and ‘j’ variables are adding additional complexity.

In your code I cant see any code which is writing to the DlyBuffer. You need to put data into that buffer before trying to read from it.

-Pete

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.