0
0

Hi.

Im working on a gamelike environment where I can drop 3D sounds and reverb objects in a gameworld where ever I want. But the combination of those behaves awkward. This is the situation:

  • when I drop a reverb object somewhere, and then add a sound on about the same place, the sound is affected by the reverb. This is ok.
  • when I drop a sound object and after that drop a reverb object nearby, it works only the first time after I start the program. All later attempts do not affect the sound at all. The reverb is created though. Because if I add another new sound to the world, it IS affected by the reverb object.

I tried to recreate this, starting from a basic example program. It is very similar to my actual program. Only in the actual program the pointer to FMOD::Reverb is encapsulated in a class I use to make a game object. So while this example reuses the same pointer after releasing it, my actual gameobjects create a new pointer. The problem is the same though. Here is the code (based on the 3d example).

[code:25f09h20]/*===============================================================================================
3d Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2011.

This example shows how to basic 3d positioning
===============================================================================================*/

include <windows.h>

include <stdio.h>

include <conio.h>

include <math.h>

include "fmod.hpp"

include "fmod_errors.h"

const int INTERFACE_UPDATETIME = 50; // 50ms update for interface
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));
exit(-1);
}
}

int main(int argc, char *argv[])
{
FMOD::System *system;
FMOD::Sound *sound1, *sound2, *sound3;
FMOD::Reverb *reverb;
FMOD::Channel *channel1 = 0, *channel2 = 0, *channel3 = 0;
FMOD_RESULT result;
int key, numdrivers;
bool listenerflag = true;
FMOD_VECTOR listenerpos = { 0.0f, 0.0f, -1.0f * DISTANCEFACTOR };
unsigned int version;
FMOD_SPEAKERMODE speakermode;
FMOD_CAPS caps;
char name[256];

printf(&quot;===============================================================\n&quot;);
printf(&quot;3d Example.  Copyright (c) Firelight Technologies 2004-2011.\n&quot;);
printf(&quot;===============================================================\n&quot;);
printf(&quot;This example plays 2 3D sounds in hardware.  Optionally you can\n&quot;);
printf(&quot;play a 2D hardware sound as well.\n&quot;);
printf(&quot;===============================================================\n\n&quot;);

/*
    Create a System object and initialize.
*/
result = FMOD::System_Create(&amp;system);
ERRCHECK(result);

result = system-&gt;getVersion(&amp;version);
ERRCHECK(result);

if (version &lt; FMOD_VERSION)
{
    printf(&quot;Error!  You are using an old version of FMOD %08x.  This program requires %08x\n&quot;, version, FMOD_VERSION);
    return 0;
}

result = system-&gt;getNumDrivers(&amp;numdrivers);
ERRCHECK(result);

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

    result = system-&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 = system-&gt;setDSPBufferSize(1024, 10);
        ERRCHECK(result);
    }

    result = system-&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 = system-&gt;setSoftwareFormat(48000, FMOD_SOUND_FORMAT_PCMFLOAT, 0,0, FMOD_DSP_RESAMPLER_LINEAR);
        ERRCHECK(result);
    }
}

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

    result = system-&gt;init(100, FMOD_INIT_NORMAL, 0);/* ... and re-init. */
    ERRCHECK(result);
}


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

/*
    Load some sounds
*/
result = system-&gt;createSound(&quot;drumloop.wav&quot;, FMOD_3D|FMOD_SOFTWARE, 0, &amp;sound1);
ERRCHECK(result);
result = sound1-&gt;set3DMinMaxDistance(0.5f * DISTANCEFACTOR, 5000.0f * DISTANCEFACTOR);
ERRCHECK(result);
result = sound1-&gt;setMode(FMOD_LOOP_NORMAL);
ERRCHECK(result);

result = system-&gt;createSound(&quot;jaguar.wav&quot;, FMOD_3D|FMOD_SOFTWARE, 0, &amp;sound2);
ERRCHECK(result);
result = sound2-&gt;set3DMinMaxDistance(0.5f * DISTANCEFACTOR, 5000.0f * DISTANCEFACTOR);
ERRCHECK(result);
result = sound2-&gt;setMode(FMOD_LOOP_NORMAL);
ERRCHECK(result);

result = system-&gt;createSound(&quot;swish.wav&quot;, FMOD_SOFTWARE | FMOD_2D, 0, &amp;sound3);
ERRCHECK(result);

/*
    Play sounds at certain positions
*/
{
    FMOD_VECTOR pos = { -10.0f * DISTANCEFACTOR, 0.0f, 0.0f };
    FMOD_VECTOR vel = {  0.0f, 0.0f, 0.0f };

    result = system-&gt;playSound(FMOD_CHANNEL_FREE, sound1, true, &amp;channel1);
    ERRCHECK(result);
    result = channel1-&gt;set3DAttributes(&amp;pos, &amp;vel);
    ERRCHECK(result);
    result = channel1-&gt;setPaused(false);
    ERRCHECK(result);
}

{
    FMOD_VECTOR pos = { 15.0f * DISTANCEFACTOR, 0.0f, 0.0f };
    FMOD_VECTOR vel = { 0.0f, 0.0f, 0.0f };

    result = system-&gt;playSound(FMOD_CHANNEL_FREE, sound2, true, &amp;channel2);
    ERRCHECK(result);
    result = channel2-&gt;set3DAttributes(&amp;pos, &amp;vel);
    ERRCHECK(result);
    result = channel2-&gt;setPaused(false);
    ERRCHECK(result);
}

/*
    Display help
*/
{
    int num3d = 0, num2d = 0;

    result = system-&gt;getHardwareChannels(&amp;num2d, &amp;num3d, 0);
    ERRCHECK(result);

    printf(&quot;Hardware 2D channels : %d\n&quot;, num2d);
    printf(&quot;Hardware 3D channels : %d\n&quot;, num3d);
}

printf(&quot;=========================================================================\n&quot;);
printf(&quot;Press 1        Pause/Unpause 16bit 3D sound at any time\n&quot;);
printf(&quot;      2        Pause/Unpause 8bit 3D sound at any time\n&quot;);
printf(&quot;      3        Play 16bit STEREO 2D sound at any time\n&quot;);
    printf(&quot;           4                Create a reverb object\n&quot;);
    printf(&quot;           5                Release a reverb object\n&quot;);
printf(&quot;      &lt;        Move listener left (in still mode)\n&quot;);
printf(&quot;      &gt;        Move listener right (in still mode)\n&quot;);
printf(&quot;      SPACE    Stop/Start listener automatic movement\n&quot;);
printf(&quot;      ESC      Quit\n&quot;);
printf(&quot;=========================================================================\n&quot;);

/*
    Main loop
*/
do
{
    if (_kbhit())
    {
        key = _getch();

        if (key == '1') 
        {
            bool paused;
            channel1-&gt;getPaused(&amp;paused);
            channel1-&gt;setPaused(!paused);
        }

        if (key == '2') 
        {
            bool paused;
            channel2-&gt;getPaused(&amp;paused);
            channel2-&gt;setPaused(!paused);
        }

        if (key == '3') 
        {
            result = system-&gt;playSound(FMOD_CHANNEL_FREE, sound3, false, &amp;channel3);
            ERRCHECK(result);
        }

                    if (key == '4')
                    {
                    result = system-&gt;createReverb(&amp;reverb);
                    ERRCHECK(result);
                    FMOD_REVERB_PROPERTIES p    = FMOD_PRESET_STONECORRIDOR;
                    result = reverb-&gt;setProperties(&amp;p);
                    ERRCHECK(result);
                    FMOD_VECTOR pos = { 0.0f, 0.0f, 0.0f };
                    result = reverb-&gt;set3DAttributes(&amp;pos, 30.0f, 50.0f);
                    ERRCHECK(result);
                    result = reverb-&gt;setActive(true);
                    ERRCHECK(result);
                    }

                    if (key == '5') 
                    {
                        result = reverb-&gt;release();
                        ERRCHECK(result);
                        reverb = NULL;
                    }

        if (key == ' ')
        {
            listenerflag = !listenerflag;
        }

        if (!listenerflag)
        {
            if (key == '&lt;') 
            {
                listenerpos.x -= 1.0f * DISTANCEFACTOR;
                if (listenerpos.x &lt; -35 * DISTANCEFACTOR)
                {
                    listenerpos.x = -35 * DISTANCEFACTOR;
                }
            }
            if (key == '&gt;') 
            {
                listenerpos.x += 1.0f * DISTANCEFACTOR;
                if (listenerpos.x &gt; 36 * DISTANCEFACTOR)
                {
                    listenerpos.x = 36 * DISTANCEFACTOR;
                }
            }
        }
    }

    // ==========================================================================================
    // UPDATE THE LISTENER
    // ==========================================================================================
    {
        static float t = 0;
        static FMOD_VECTOR lastpos = { 0.0f, 0.0f, 0.0f };
        FMOD_VECTOR forward        = { 0.0f, 0.0f, 1.0f };
        FMOD_VECTOR up             = { 0.0f, 1.0f, 0.0f };
        FMOD_VECTOR vel;

        if (listenerflag)
        {
            listenerpos.x = (float)sin(t * 0.05f) * 33.0f * DISTANCEFACTOR; // left right pingpong
        }

        // ********* NOTE ******* READ NEXT COMMENT!!!!!
        // vel = how far we moved last FRAME (m/f), then time compensate it to SECONDS (m/s).
        vel.x = (listenerpos.x - lastpos.x) * (1000 / INTERFACE_UPDATETIME);
        vel.y = (listenerpos.y - lastpos.y) * (1000 / INTERFACE_UPDATETIME);
        vel.z = (listenerpos.z - lastpos.z) * (1000 / INTERFACE_UPDATETIME);

        // store pos for next time
        lastpos = listenerpos;

        result = system-&gt;set3DListenerAttributes(0, &amp;listenerpos, &amp;vel, &amp;forward, &amp;up);
        ERRCHECK(result);

        t += (30 * (1.0f / (float)INTERFACE_UPDATETIME));    // t is just a time value .. it increments in 30m/s steps in this example

        // print out a small visual display
        {
            char s[80];

            sprintf(s, &quot;|.......................&lt;1&gt;......................&lt;2&gt;....................|&quot;);

            s[(int)(listenerpos.x / DISTANCEFACTOR) + 35] = 'L';
            printf(&quot;%s\r&quot;, s);
        }
    }

    system-&gt;update();

    Sleep(INTERFACE_UPDATETIME - 1);

} while (key != 27);

printf(&quot;\n&quot;);

/*
    Shut down
*/
result = sound1-&gt;release();
ERRCHECK(result);
result = sound2-&gt;release();
ERRCHECK(result);
result = sound3-&gt;release();
ERRCHECK(result);

result = system-&gt;close();
ERRCHECK(result);
result = system-&gt;release();
ERRCHECK(result);

return 0;

}
[/code:25f09h20]

Any suggestions?

Thanks, yvan

  • You must to post comments
Showing 0 results
Your Answer

Please first to submit.