0
0

I have a small compilable example that is not working for reasons that are way beyond me. I say percent != 100 && g_thang != true, which are two conditions that would be set if the sound was loaded, yet, my loop breaks when only g_thang get’s set to true (which is when the completion callback is called), you can see in the sample output at the bottom that this the results don’t make sense!

[code:1cai30av]#include "fmod.hpp"

include "fmod_errors.h"

using namespace std;

static bool g_thang = false;

FMOD_RESULT F_CALLBACK asyncOpen( FMOD_SOUND * sound, FMOD_RESULT result )

{
cout << "OMG!\n";

FMOD::Sound * cppsound = reinterpret_cast&lt; FMOD::Sound * &gt;( sound );
g_thang = true;

return result;

}

struct fmod_system
{
FMOD::System * fsystem;
FMOD::Sound * fsound;
FMOD::Channel * fchannel;

fmod_system()
{
    FMOD_RESULT result;

    result = FMOD::System_Create( &amp;fsystem );
    if (result != FMOD_OK)
    {
        cout &lt;&lt; TEXT(&quot;FMOD: &quot;) &lt;&lt; FMOD_ErrorString(result) &lt;&lt; endl;
    }

    result = fsystem-&gt;init(10, FMOD_INIT_NORMAL, 0);
    if (result != FMOD_OK)
    {
        cout &lt;&lt; TEXT(&quot;FMOD: &quot;) &lt;&lt; FMOD_ErrorString(result) &lt;&lt; endl;
    }

    FMOD_CREATESOUNDEXINFO exInfo = { 0 };

    exInfo.cbsize           = sizeof( FMOD_CREATESOUNDEXINFO );
    exInfo.nonblockcallback = asyncOpen;

    result = fsystem-&gt;createSound( &quot;C:\\Black Fire.mp3&quot;, 
        FMOD_DEFAULT | FMOD_NONBLOCKING, &amp;exInfo, &amp;fsound );

    if( result != FMOD_OK )
    {
        cout &lt;&lt; TEXT(&quot;FMOD 1: &quot;) &lt;&lt; FMOD_ErrorString(result) &lt;&lt; endl;
    }

    FMOD_OPENSTATE open_state;
    unsigned int percent = 0, i = 0;

    do
    {
        result = fsound-&gt;getOpenState( &amp;open_state, &amp;percent, 0 );
        if( result == FMOD_OK )
        {
            cout &lt;&lt; TEXT(&quot;FMOD 2: &quot;) &lt;&lt; open_state &lt;&lt; TEXT(&quot; &quot;) &lt;&lt; percent &lt;&lt; TEXT(&quot;\n&quot;);
        }
        else
        {
            cout &lt;&lt; TEXT(&quot;FMOD 3: &quot;) &lt;&lt; FMOD_ErrorString(result) &lt;&lt; TEXT(&quot;\n&quot;);
            break;
        }

        fsystem-&gt;update();
    }
    while( percent != 100 &amp;&amp; g_thang != true );

    result = fsystem-&gt;playSound( FMOD_CHANNEL_FREE, fsound, false, &amp;fchannel );
    if( result != FMOD_OK )
    {
        cout &lt;&lt; TEXT(&quot;Percent loaded: &quot;) &lt;&lt; percent &lt;&lt; endl &lt;&lt; TEXT(&quot;FMOD 4: &quot;) &lt;&lt; FMOD_ErrorString(result) &lt;&lt; endl;
    }
}
~fmod_system()
{
    fchannel-&gt;stop();
    fsound-&gt;release();
    fsystem-&gt;release();
}

};

int main()
{
fmod_system system;
}[/code:1cai30av]

The output of the program is something like this:

[code:1cai30av]FMOD 2: OMG!
1 0
Percent loaded: 0
FMOD 4: Operation could not be performed because specified sound is not ready.[/code:1cai30av]

It immediately calls the completion callback, somehow thinks that the percent is 100, and then says that the sound is not ready. Why would it do this?

  • You must to post comments
0
0

You should not do direct comparisons of floats in C, 100.0 does not always equal 100.0 (see IEEE standard). You should be using a small epsilon with greater than/equals check with something like 99.9 for example.

  • You must to post comments
0
0

I don’t think there’s any floating point things here.

[code:r51j2a3d]FMOD_RESULT Sound::getOpenState(
FMOD_OPENSTATE * openstate,
unsigned int * percentbuffered,
bool * starving
);[/code:r51j2a3d]

In addition, somehow the loop breaks without percent being 100 (in fact, the program says that it’s value if 0!). I will try to do some debugging to see what could have caused this madness. In the mean time, replies are appreciated because this function is pretty wierd.

It should be noted that FMOD_OPENSTATE that I get seems valid (FMOD_LOADING and then FMOD_READY) but the percent always seems to be 0

  • You must to post comments
0
0

Does a sound have to be streaming to recieve the percent loading thing?

  • You must to post comments
0
0

I believe that yes.
I am requesting something like that:

http://52.88.2.202/forum/viewtopic.php?t=7284

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.