0
0

Hi!

I am trying to apply built-in DSP effects to events. I wish to be able to bypass the DSPs (setBypass(true) looks like the way I am supposed to do that).

Currently I can get the channelgroup and apply a dsp to that, and the audio plays as expected. However, if I subsequently change a parameter of the dsp, or setBypass(true), the audio stops playing entirely! If I setBypass(false) again, the audio plays. So far I am just working with one event and one DSP.

My example code looks like this:
[code:2zphnjlt]
/===============================================================================================
DSP applied to events example
===============================================================================================
/

include "fmod_event.hpp"

include "fmod_errors.h"

include "fmod_dsp.h"

include <windows.h>

include <stdio.h>

include <stdlib.h>

include <conio.h>

include <math.h>

const float DISTANCEFACTOR = 1.0f; // Units per meter. I.e feet would = 3.28. centimeters would = 100.

void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
system("pause");
exit(-1);
}
}

int main(int argc, char *argv[])
{
FMOD::EventSystem *eventsystem;
FMOD::System *fmodSystem;
FMOD::Event *eventEngine;
FMOD_SPEAKERMODE speakermode;
FMOD_CAPS caps;
char name[256];
FMOD::DSP *dspdistortion = 0;
FMOD::ChannelGroup *boatGroup;

//listener attributes
FMOD_VECTOR         listenerPos = { 0.0f, 0.0f, 0.0f };
FMOD_VECTOR         forward = {0.f, 0.f, -1.f};
FMOD_VECTOR         up = {0.f, 1.f, 0.f};
FMOD_VECTOR         listenerVel = { 0.0f, 0.0f, 0.0f };

//boat attributes
FMOD_VECTOR         boatPos, lastBoatPos;
FMOD_VECTOR         boatVel = { 0.0f, 0.0f, 0.0f };
float               angle = 0;
float               distance = 10;
bool                boatMoving = false;
bool                dspOn = true;

FMOD_RESULT         result;
int                 key = 0;
int                 numdrivers;
int                 milliseconds = 15;

printf(&quot;======================================================================\n&quot;);
printf(&quot;Simple 3D Event Example. \n&quot;);
printf(&quot;======================================================================\n&quot;);
printf(&quot;This example simply plays events created with the FMOD Designer tool.\n&quot;);
printf(&quot;======================================================================\n\n&quot;);

ERRCHECK(result = FMOD::EventSystem_Create(&amp;eventsystem));
//fetch the main FMOD::System form the eventsystem
ERRCHECK(result = eventsystem-&gt;getSystemObject(&amp;fmodSystem));
result = fmodSystem-&gt;getNumDrivers(&amp;numdrivers);
ERRCHECK(result);

if (numdrivers == 0)
{
    result = fmodSystem-&gt;setOutput(FMOD_OUTPUTTYPE_NOSOUND);
    ERRCHECK(result);
}
else
{
    result = fmodSystem-&gt;getDriverCaps(0, &amp;caps, 0, &amp;speakermode);
    ERRCHECK(result);

    result = fmodSystem-&gt;setSpeakerMode(speakermode);       /* Set the user selected speaker mode. */
    ERRCHECK(result);

    if (caps &amp; FMOD_CAPS_HARDWARE_EMULATED)             /* The user has the 'Acceleration' slider set to off!  This is really bad for latency!. */
    {                                                   /* You might want to warn the user about this. */
        result = fmodSystem-&gt;setDSPBufferSize(1024, 10);
        ERRCHECK(result);
    }

    result = fmodSystem-&gt;getDriverInfo(0, name, 256, 0);
    ERRCHECK(result);

    if (strstr(name, &quot;SigmaTel&quot;))   /* Sigmatel sound devices crackle for some reason if the format is PCM 16bit.  PCM floating point output seems to solve it. */
    {
        result = fmodSystem-&gt;setSoftwareFormat(48000, FMOD_SOUND_FORMAT_PCMFLOAT, 0,0, FMOD_DSP_RESAMPLER_LINEAR);
        ERRCHECK(result);
    }
}


/*
    Set the distance units. (meters/feet etc).
*/
result = fmodSystem-&gt;set3DSettings(1.0, DISTANCEFACTOR, 1.0f);
ERRCHECK(result);

//initailize the event system
result = eventsystem-&gt;init(64, FMOD_INIT_3D_RIGHTHANDED, 0, FMOD_EVENT_INIT_NORMAL);
if (result == FMOD_ERR_OUTPUT_CREATEBUFFER)         /* Ok, the speaker mode selected isn't supported by this soundcard.  Switch it back to stereo... */
{
    result = fmodSystem-&gt;setSpeakerMode(FMOD_SPEAKERMODE_STEREO);
    ERRCHECK(result);

    result = eventsystem-&gt;init(64, FMOD_INIT_3D_RIGHTHANDED, 0, FMOD_EVENT_INIT_NORMAL);/* ... and re-init. */
    ERRCHECK(result);
}
ERRCHECK(result = eventsystem-&gt;setMediaPath(&quot;media\\&quot;)); //set the relative file path to the audio files
//load the event project
ERRCHECK(result = eventsystem-&gt;load(&quot;3DExample.fev&quot;, 0, 0));
//fetch our event
ERRCHECK(result = eventsystem-&gt;getEvent(&quot;3DExample/Boat/Engine&quot;, FMOD_EVENT_USERDSP, &amp;eventEngine));

//initialize the listener
eventsystem-&gt;set3DListenerAttributes(0, &amp;listenerPos, &amp;listenerVel, &amp;forward, &amp;up);

printf(&quot;======================================================================\n&quot;);
printf(&quot;Press 1 to toggle the boat circling.\n&quot;);
printf(&quot;Press 2 to toggle the DSP effect.\n&quot;);
printf(&quot;Press ESC   to quit\n&quot;);
printf(&quot;======================================================================\n&quot;);

key = 0;    

//set the boat's starting position
boatPos.x = boatPos.y = 0.f;
boatPos.z = distance;
lastBoatPos = boatPos;

eventEngine-&gt;set3DAttributes(&amp;boatPos, &amp;boatVel);

//start the event playing
ERRCHECK(result = eventEngine-&gt;start());

//dsp
result = fmodSystem-&gt;createDSPByType(FMOD_DSP_TYPE_DISTORTION, &amp;dspdistortion);
ERRCHECK(result);

//get the channel group from the event: the channel group affects ALL of the
//event's sounds/layers
eventEngine-&gt;getChannelGroup(&amp;boatGroup);

//add the dsp to the event's channel group
result = boatGroup-&gt;addDSP(dspdistortion, NULL);
ERRCHECK(result);

result = dspdistortion-&gt;setParameter(FMOD_DSP_DISTORTION_LEVEL, 1.0f);
ERRCHECK(result);

do
{
    if (_kbhit())
    {
        key = _getch();

        switch(key)
        {
        case '1':
            {
                boatMoving = !boatMoving;
            }
            break;  

        case '2':
            {
                dspOn = !dspOn;

                if(dspOn)
                {
                    //boatGroup-&gt;addDSP(dspdistortion, NULL);
                    dspdistortion-&gt;setBypass(false);
                }
                else
                {
                    //dspdistortion-&gt;remove();
                    dspdistortion-&gt;setBypass(true);
                }
            }
            break;  

        default:
            break;
        }//end switch
    }

    //if the boat is moving, update it's position
    if(boatMoving)
    {
        //we just drive the boat around in a circle
        angle += 0.01f; //radians
        boatPos.x = sin(angle)*distance;
        boatPos.z = -cos(angle)*distance;

        boatVel.x = (boatPos.x - lastBoatPos.x) *  1000.0f / milliseconds;
        boatVel.y = (boatPos.y - lastBoatPos.y) *  1000.0f / milliseconds;
        boatVel.z = (boatPos.z - lastBoatPos.z) *  1000.0f / milliseconds;

        eventEngine-&gt;set3DAttributes(&amp;boatPos, &amp;boatVel);
        lastBoatPos = boatPos;
    }

    ERRCHECK(result = eventsystem-&gt;update());
    Sleep(milliseconds);

    printf(&quot;Boat movement: %s.\r&quot;, (boatMoving) ? &quot;circling&quot; : &quot;stopped&quot;);


} while (key != 27);

ERRCHECK(result = eventsystem-&gt;release());
return 0;

}[/code:2zphnjlt]

  • You must to post comments
Showing 0 results
Your Answer

Please first to submit.