0
0

Hello!

Im experiencing some problems with FMOD. The problems occures when im trying to implement FMOD into my Win32 Application (window). The sound doesnt sound good.
But the strange part is that when i create a Win32 Application (console), everything sounds perfect.

Howcome? Is there anything i’ve missed?

Im using the same FMOD code in the two projects (ie The two projects uses the same FMOD related code that i’ve written). You know, init system and create sound, bla bla.

This is the code i use in my window applications

[code:rgxx2gvl]int WINAPI WinMain(HINSTANCE instance, HINSTANCE p, LPSTR cmd, int show)
{
FMOD_RESULT r;
FMOD::System* system;
FMOD::Sound* sound;

FMOD_RESULT      result;
unsigned int     version;
FMOD_SPEAKERMODE speakermode;
FMOD_CAPS        caps;

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

result = system->getVersion(&version);
ERRCHECK(result);

if (version < FMOD_VERSION)
{
    ::MessageBox(0, "Error!  You are using an old version of FMOD.  This program requires\n", 0, 0);
    return 0;
}

result = system->getDriverCaps(0, &caps, 0, 0, &speakermode);
ERRCHECK(result);

result = system->setSpeakerMode(speakermode);       /* Set the user selected speaker mode. */
ERRCHECK(result);

if (caps & 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->setDSPBufferSize(1024, 10);    /* At 48khz, the latency between issuing an fmod command and hearing it will now be about 213ms. */
    ERRCHECK(result);
}

result = system->init(100, FMOD_INIT_NORMAL, 0);    /* Replace with whatever channel count and flags you use! */
if (result == FMOD_ERR_OUTPUT_CREATEBUFFER)         /* Ok, the speaker mode selected isn't supported by this soundcard.  Switch it back to stereo... */
{
    result = system->setSpeakerMode(FMOD_SPEAKERMODE_STEREO);
    ERRCHECK(result);

    result = system->init(100, FMOD_INIT_NORMAL, 0); /* Replace with whatever channel count and flags you use! */
    ERRCHECK(result);
}


r = system->createSound("./double.mp3", FMOD_HARDWARE, 0, &sound);
ERRCHECK(r);

::MessageBox(0, "go", 0, 0);

while(true)
{
    if(::GetAsyncKeyState('A'))
    {
        r = system->playSound(FMOD_CHANNEL_FREE, sound, false, 0);
        ERRCHECK(r);
    }

    r = system->update();
    ERRCHECK(r);
}

return 0;

}[/code:rgxx2gvl]

The strange part is, when i set a breakpoint on system->playSound() and then step over it, it outputs the sound as it should (ie everything works fine). But when i dont use a breakpoint at the system->playSound() it receives and FMOD_ERR_MEMORY. This is strange, I only create one sound. Please help me. This messes my brain up (works with breakpoint in code, but without it doesnt – gaah).

You got to help me :)

Thanks in advance.
[/code]

  • You must to post comments
0
0

You are running your code in such a tight loop that you are stalling the whole operating system. Put a sleep somewhere in your loop.

Besides this wouldn’t getasynckeystate just mean it spams multiple playsound commands while you’re holding the key down?

  • You must to post comments
0
0

Ok, thanks for your reply.

What exactly are stalling the os? is it the system->update() function that is called every loop?

The thing is, Im implementing fmod in my game engine, so a sleep call every frame would have devasting effect. In the helpfile in fmod, it says that update() should be called every frame, but should i rather call it like every second?

Here is my engine loop: (simplified)

[code:3nzwlq5z]

//System = FMOD::System*
//lets say that ‘Sound’ is created in the constructor of the engine

void Engine::Run()
{
if(!mLoaded)
{
return;
}

DWORD currentTime = 0;
DWORD lastTime = 0;
float elapsedTime = 0.0f;

MSG msg;
::ZeroMemory(&msg, sizeof(MSG));

::ShowWindow(mWindow, SW_NORMAL);
::UpdateWindow(mWindow);

while(msg.message != WM_QUIT)
{
    if(PeekMessage(&msg, null, 0, 0, PM_REMOVE))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
            else
    {
        currentTime = timeGetTime();
        elapsedTime = (currentTime - lastTime) / 1000.0f;
        lastTime = currentTime;

        mInput->Update();

                   if(mInput->KeyDown('A'))
                        System->PlaySound(FMOD_CHANNEL_FREE, Sound, false, 0); //the error

                   ProcessGraphics();

                   System->Update(); //FMOD::System
    }
}

}[/code:3nzwlq5z]

Btw, should I update the fmod system in the beginning of the frame or in the end of the frame?

Thanks

  • You must to post comments
0
0

You said "This is the code i use in my window applications".
Obviously you don’t sleep in your game code, but you didnt even mention that in your first post. You just posted a flawed test application.

Blurry doesnt describe any sound artifact that i’ve heard of, please clarify what you mean, and make sure it is not your application that is causing the problem. You said yourself that the fmod examples work ok so compare the difference.

You update every frame. There is no problem doing that. Your test app was probably doing it 1,000,000 times a second though, that is not normal.

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.