DOH << ENDL;
Order of destructors. Blah. I was close()'ing the system before I stopped playing music and released the sound. If a mod sees it fit, they can split this thread, but I have a related question, about opening it in non-blocking mode instead.
Code:
struct fmod_system
{
FMOD::System * fsystem;
FMOD::Sound * fsound;
FMOD::Channel * fchannel;
fmod_system()
{
FMOD_RESULT result;
result = FMOD::System_Create( &fsystem );
if (result != FMOD_OK)
{
cout << TEXT("FMOD: ") << FMOD_ErrorString(result) << endl;
}
result = fsystem->init(10, FMOD_INIT_NORMAL, 0);
if (result != FMOD_OK)
{
cout << TEXT("FMOD: ") << FMOD_ErrorString(result) << endl;
}
FMOD_CREATESOUNDEXINFO exInfo = { 0 };
exInfo.cbsize = sizeof( FMOD_CREATESOUNDEXINFO );
exInfo.nonblockcallback = asyncOpen;
result = fsystem->createSound( "C:\\Documents and Settings\\Tonto\\My Documents\\Visual Studio 2005\\Projects\\Base\\Base\\Black Fire.mp3",
FMOD_DEFAULT | FMOD_NONBLOCKING, &exInfo, &fsound );
if( result != FMOD_OK )
{
cout << TEXT("FMOD: ") << FMOD_ErrorString(result) << endl;
}
FMOD_OPENSTATE open_state;
unsigned int percent, i = 0;
do
{
fsystem->update();
result = fsound->getOpenState( &open_state, &percent, 0 );
if( result == FMOD_OK )
{
cout << TEXT("FMOD: ") << open_state << TEXT(" ") << percent << TEXT("\n");
}
else
{
cout << TEXT("FMOD: ") << FMOD_ErrorString(result) << TEXT("\n");
break;
}
::Sleep( 100 );
}
while( !g_thang );
result = fsystem->playSound( FMOD_CHANNEL_FREE, fsound, false, &fchannel );
if( result != FMOD_OK )
{
cout << TEXT("FMOD: ") << FMOD_ErrorString(result) << endl;
}
cout << "HERE!\n";
}
~fmod_system()
{
fchannel->stop();
fsound->release();
fsystem->release();
}
} system;
And then this
Code:
static bool g_thang = false;
FMOD_RESULT F_CALLBACK asyncOpen( FMOD_SOUND * sound, FMOD_RESULT result )
{
FMOD::Sound * cppsound = reinterpret_cast< FMOD::Sound * >( sound );
g_thang = true;
return result;
}
When FMOD finishes loading the sound asynchronously, then it calls my callback routine, where I set a global variable. This is a wierd design I know, but the callback doesn't have access to the FMOD::System pointer so I can't do anything more useful. Anyways, two things are wierd about that code:
1) When I do not have the Sleep(x) in there, then that loop will never stop, and apparently FMOD will never load the sound. If I force myself out of that loop with a break, right after I exit it FMOD loads the sound just fine. So, if the Sleep(x) isn't there, the sound doesn't load.
2) The getOpenState doesn't do squat. It tells me that the FMOD_OPENSTATE is always FMOD_LOADING, and the percent buffered is always 0. And then, somehow the callback is called and it says it's done, without ever telling me anything. Mind you, it's not the sleep that skipped over the loading process or anything, it sits for a good couple seconds before it's loaded. Here's what the docs say:
Code:
Sound::getOpenState
Retrieves the state a sound is in after FMOD_NONBLOCKING has been used to open it, or the state of the streaming buffer.
Syntax
FMOD_RESULT Sound::getOpenState(
FMOD_OPENSTATE * openstate,
unsigned int * percentbuffered,
bool * starving
);
Parameters
openstate
Address of a variable that receives the open state of a sound. Optional. Specify 0 or NULL to ignore.
percentbuffered
Address of a variable that receives the percentage of the file buffer filled progress of a stream. Optional. Specify 0 or NULL to ignore.
starving
Address of a variable that receives the starving state of a sound. If a stream has decoded more than the stream file buffer has ready for it, it will return TRUE. Optional. Specify 0 or NULL to ignore.
Return Values
If the function succeeds then the return value is FMOD_OK.
If the function fails then the return value will be one of the values defined in the FMOD_RESULT enumeration.
Note: The return value will be the result of the asynchronous sound create. Use this to determine what happened if a sound failed to open.
Remarks
When a sound is opened with FMOD_NONBLOCKING, it is opened and prepared in the background, or asynchronously.
This allows the main application to execute without stalling on audio loads.
This function will describe the state of the asynchronous load routine. I.e. whether it has succeeded or failed.
Sorry the docs aren't online. So, it doesn't -- seem -- like I'm doing anything wrong. But it's definitely wierd. Any thoughts about this?