0
0

Hi,
I would write a channel callback as part of a class ( a member of a class ).

How must I write it?

Best,
Franco

  • You must to post comments
0
0

The callbacks in FMOD are C style, so you can’t pass a pointer to a function in an instance of a class (AFAIK). If you need to do that, you might try a trampoline type pattern, where you have a regular callback function which class the class instance method.

  • You must to post comments
0
0

[quote="audiodev":1bmfpndg]The callbacks in FMOD are C style, so you can’t pass a pointer to a function in an instance of a class (AFAIK). If you need to do that, you might try a trampoline type pattern, where you have a regular callback function which class the class instance method.[/quote:1bmfpndg]

Can you do a little example? Is not so easy to understand.
I would emit a qt signal from the callback so my callback should part of a class.

Best

  • You must to post comments
0
0

[code:17bc69d1]
class Foo
{
void instanceCallack();
};

Foo myFoo;

static void trampolineCallback()
{
myFoo.instanceCallack();
}
[/code:17bc69d1]

  • You must to post comments
0
0

[quote="audiodev":3rnzyte5][code:3rnzyte5]
class Foo
{
void instanceCallack();
};

Foo myFoo;

static void trampolineCallback()
{
myFoo.instanceCallack();
}
[/code:3rnzyte5][/quote:3rnzyte5]

This is my callback:
[code:3rnzyte5]
FMOD_RESULT F_CALLBACK endCallback(FMOD_CHANNEL *channel, FMOD_CHANNEL_CALLBACKTYPE type,
unsigned int commanddata1, unsigned int commanddata2);
{
(void)commanddata1; // Unused (to avoid warnings)
(void)commanddata2; // Unused (to avoid warnings)

    SoundData* currentSound; 

    switch(type)
    {
    case FMOD_CHANNEL_CALLBACKTYPE_END:
        {
            FMOD_RESULT result;
            FMOD::Channel *currentChannel = (FMOD::Channel *)channel;

            void *ud = NULL;
            result = currentChannel->getUserData( &ud );


            currentSound = (SoundData*)ud;


            /* inform that sound stopped */
            emit( soundStopped() );
            break;
        }
    default:
        break;
    }

    return FMOD_OK;

}[/code:3rnzyte5]

In your example your trampolinecallback is a method of the class?

And where is the body of the callback?

  • You must to post comments
0
0

[quote="audiodev":2hi2awxt][code:2hi2awxt]
class Foo
{
void instanceCallack();
};

Foo myFoo;

static void trampolineCallback()
{
myFoo.instanceCallack();
}
[/code:2hi2awxt][/quote:2hi2awxt]

Audiodev in your example where is the body of the callback?

  • You must to post comments
0
0

This is pseudo code. What happens inside of Foo.instanceCallback() is irrelevant to the pattern. I suggest you google trampoline pattern or trampoline callback for more info.

  • You must to post comments
0
0

[quote="audiodev":2c85f9gr]This is pseudo code. What happens inside of Foo.instanceCallback() is irrelevant to the pattern. I suggest you google trampoline pattern or trampoline callback for more info.[/quote:2c85f9gr]

Yes I understood that is not relevant. I only asked where in your pseudo-code is the body of the callback.

Thanx in advance.

Franco

  • You must to post comments
0
0

In my code, trampolineCallback is what you would register with FMOD. Then you would have that make the call to the instance method call.

  • You must to post comments
0
0

[quote="audiodev":16t6vmin]In my code, trampolineCallback is what you would register with FMOD. Then you would have that make the call to the instance method call.[/quote:16t6vmin]

What does mean? Is really difficult to understand.
If my callback has that body

callback
{
body of the callback
}

and that prototype
callbackPrototype();

how can I implement your method?

  • You must to post comments
0
0

You can add a pointer to your class in the user data of your channel.
So, you have :

[code:135inn38]// out of your class
callback(....)
{
your_class *c;
channel->getUserData((void**)&c);
c->your_callback();
}

// in your class
your_class::your_callback()
{
....
}
[/code:135inn38]
I think it should work 😉

ps : sorry for my poor english 😳

  • You must to post comments
Showing 10 results
Your Answer

Please first to submit.