0
0

I would like some suggestion and feedback on how to solve my problem…

I use the fmod callback function "FMOD_RESULT F_CALLBACK EndCallback" to indicate whether to play the next sound in my playlist which is a std::vector container. However, i understand that the Callback function must be either global or static and that’s where the problem comes in.

The function that i use to check if there is any more sound is part of my SoundEngine class called NextSound(). One way to solve it is to put all of these functions and variables as a global or static which i am trying to avoid.

Please give me suggestion on how to solve this problem. Code below…

NextSound function ( Part of the SoundEngine Class ) :
[code:1yyrpoow]

/*********These std::vectors are declared in a header file, SoundComponent.h
and they are private********
//Vector to contain the list of songs
std::vector<std::string> PlayList;

//Iterator to go thru the PlayList
std::vector<std::string>::iterator It_PlayList;
*************************************************/

bool SoundEngine::NextSound(){

    #ifdef DEBUG
        std::cout &lt;&lt; &quot;Next sound&quot; &lt;&lt; std::endl;
    #endif

    ++It_PlayList;

    if( It_PlayList == PlayList.end() ){

        std::cout &lt;&lt; &quot;End of PlayList&quot; &lt;&lt; std::endl;
        return false;

    }       

    PlaySound( *It_PlayList );

    return true;
}

[/code:1yyrpoow]

Callback function ( GLOBAL ) :
[code:1yyrpoow]
FMOD_RESULT F_CALLBACK EndCallback(FMOD_CHANNEL *channel,
FMOD_CHANNEL_CALLBACKTYPE type,
void *commanddata1,
void *commanddata2)
{
(void)commanddata1; // Unused (to avoid warnings)
(void)commanddata2; // Unused (to avoid warnings)
channel = 0;

    #ifdef DEBUG
        std::cout &lt;&lt; &quot;In Callback func...&quot; &lt;&lt; std::endl;
    #endif

   switch(type)
   {
       case FMOD_CHANNEL_CALLBACKTYPE_END:
           {
            //Do the checking of whether there is a next sound here
            /*bool IsThereNext = NextSound(); // This does not work as an object of NextSound is not created yet

            if( !IsThereNext )
                std::cout &lt;&lt; &quot;No more sound&quot; &lt;&lt; std::endl;*/

            break;
           }

       default:
        break;
   }

   return FMOD_OK;
}

[/code:1yyrpoow]

  • You must to post comments
0
0

You can set the Channel’s ‘user data’ field to point to your soundmanager.

Something like this:

[code:5q2zggp9]channel->setUserData(soundManager)[/code:5q2zggp9]

[code:5q2zggp9]FMOD_RESULT F_CALLBACK myCallback( FMOD_CHANNEL* channel, FMOD_CHANNEL_CALLBACKTYPE type, void* commanddata1, void* commanddata2 )
{
FMOD::Channel* chan = reinterpret_cast<FMOD::Channel>(channel);
FMOD::SoundEngine
soundEngine = 0;
chan->getUserData(reinterpret_cast<void**>(&soundEngine));
}[/code:5q2zggp9]

  • You must to post comments
0
0

So, a friend of mine suggested this.

In the global space of SoundComponent.h, declare :
[code:2jpmqpf7]extern SoundEngine *pExtSoundEng;[/code:2jpmqpf7]

Then, assume this is what is going on in the main.cpp :
[code:2jpmqpf7]

include "SoundComponent.h"

int main( void ){

PlainSoundPlayer::SoundEngine test;

test.Init();

PlainSoundPlayer::pExtSoundEng = &amp;test;

    ///And some other stuff below...

}
[/code:2jpmqpf7]

Then modify the Callback function ( GLOBAL ) :
[code:2jpmqpf7]
FMOD_RESULT F_CALLBACK EndCallback(FMOD_CHANNEL *channel,
FMOD_CHANNEL_CALLBACKTYPE type,
void *commanddata1,
void *commanddata2)
{
(void)commanddata1; // Unused (to avoid warnings)
(void)commanddata2; // Unused (to avoid warnings)
channel = 0;

    #ifdef DEBUG
        std::cout &lt;&lt; &quot;In Callback func...&quot; &lt;&lt; std::endl;
    #endif

   switch(type)
   {
       case FMOD_CHANNEL_CALLBACKTYPE_END:
           {
            //Do the checking of whether there is a next sound here
            bool IsThereNext = pExtSoundEng-&gt;NextSound();

            if( !IsThereNext )
                std::cout &lt;&lt; &quot;No more sound&quot; &lt;&lt; std::endl;

            break;
           }

       default:
        break;
   }

   return FMOD_OK;
}

[/code:2jpmqpf7]

The above will work but of course there would be other better class designs. Please feel free to comment.

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.