Answered
0
0

Problem is that with a custom DSP just like the 1 given as example in the FMOD low level, when adjust just some parts or even half the length of the input buffer instead of making the sound in those frequencies lower it create cracking or popping in playback. Anyone knows the cause if this? please help!

void audioClass::addCustomDSP(void)
{
    myNewDSP = new(std::nothrow) struct FMOD_DSP_DESCRIPTION;
    memset(this->myNewDSP, 0, sizeof(struct FMOD_DSP_DESCRIPTION));
    strcpy_s(myNewDSP->name, sizeof(myNewDSP->name),"lower volume DSP");
    this->myNewDSP->version = (unsigned int)1.0;
    this->myNewDSP->numinputbuffers = 1;
    this->myNewDSP->numoutputbuffers = 1;
    this->myNewDSP->read = myDSPCallback;
    this->result = this->system->createDSP(this->myNewDSP, &this->myDsp2);
    if (this->result != FMOD_OK)
        myErrorFunc2(FMOD_ErrorString(result), "Failed to create custom DSP.");
    this->myDsp2->setBypass(true);
    this->result = this->masterGroup->addDSP(0, this->myDsp2);
    if (this->result != FMOD_OK)
        myErrorFunc2(FMOD_ErrorString(result), "Failed to add custom DSP to master channel");
}

    FMOD_RESULT F_CALLBACK myDSPCallback(FMOD_DSP_STATE * cState, float * inBuffer, float * outBuffer, unsigned int lenght, int inChannel, int * outChannel)
{
    for (unsigned int sample = 0; sample < lenght; sample++)
    {
        for (int chan = 0; chan < inChannel; chan++)
        {
            //outBuffer[(sample * *outChannel) + chan] = inBuffer[(sample * inChannel) + chan] * 0.2f;  // lowers all freq volume
            if(sample < 512)
                outBuffer[(sample * *outChannel) + chan] = inBuffer[(sample * inChannel) + chan] * 0.5f;
        }
    }

    return FMOD_OK;
}
  • You must to post comments
Best Answer
0
0

I assume the input length is 1024, and you’ve changed it from copying only 512 from in out out, and not copying the rest? That is why your sound is bad.

You need to copy the whole buffer, not just half of it. Even if you just want to process 512 out of the 1024, you still need to copy the remaining 512 to make it process the full amount.

  • Deniro

    thanks for your reply, just got done with trying the fix you suggested but its still there

  • You must to post comments
0
0

Edited code with suggestion above, but still has noise:

/*      with tested audio file(sexual seduction snoop dogg from youtube)
        length = 1024
        inchannel = 2
        outchannel = 2
        max loop value = 2048
        max hertz range = 22030.2
        180hz to 250hz index = 17 - 249
        without adjusting all input buffers output audio gets distorted with static(AKA audio noise)
*/
FMOD_RESULT F_CALLBACK myDSPCallback(FMOD_DSP_STATE * cState, float * inBuffer, float * outBuffer, unsigned int lenght, int inChannel, int * outChannel)
{
    for (unsigned int sample = 0; sample < lenght; sample++)
    {
        for (int chan = 0; chan < inChannel; chan++)
        {
            outBuffer[(sample * *outChannel) + chan] = inBuffer[(sample * inChannel) + chan] * 1.0f;    // leaves volume un-adjusted
            if (((sample * *outChannel) + chan) <= 1)
            {
                outBuffer[(sample * *outChannel) + chan] = inBuffer[(sample * inChannel) + chan] * 0.5f;    // lowers volume
            }
            if((((sample * inChannel) + chan)*HZrange) > 180 && ((sample * inChannel)+chan) < 250)
                std::cout << "here: " << ((sample * inChannel) + chan) << std::endl;
        }
    }

    return FMOD_OK;
}
  • Brett Paterson

    I’m not sure why you think that wouldnt generate noise, from what I can see you are now muting 2 samples out of 1024, which distorts the signal?

    The only thing I suggest is if you take out your if statement, and leave the outbuffer[…] = inbuffer[…] bit does it sound normal, then as soon as you introduce your scaling code it distorts? This means the function you wrote is the thing distorting the signal.

  • Brett Paterson

    refer to http://www.fmod.org/documentation/#content/generated/overview/terminology.html for the layout of the signal in a buffer.

  • Deniro

    read that entire document lol, I’m not a professional at this API thing I’m just on holiday from school tryna build my skillset.

    And yes you are correct without the if statement it process just fine and replace 1.0f with 0.5f for all buffers there is no noise. What I’m exactly trying to do is recreate the low pass DSP but I guess ill have to use the low pass DSP and hope it works how I want it to

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.