Sign in to follow this  

FMOD stream call back functions

This topic is 3007 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! I can't figure out what am I doing wrong. Here is how I specify end callback function :
signed char StreamEndCallback(SOUND_STREAM *stream, void *buff, int len, int param)
{
   return 1;
}
When I call ...
FSOUND_Stream_SetEndCallback(tag.m_pStream, StreamEndCallback,  0);
... I am getting a following error (MSVC++ 6.0) :
error C2664: 'FSOUND_Stream_SetEndCallback' : cannot convert parameter 2 from 'signed char (struct FSOUND_STREAM *,void *,int,int)' to 'signed char (__stdcall *)(struct FSOUND_S
TREAM *,void *,int,int)'
What is wrong? I was looking at some sample code and everything seems to be identical. Thanks in advance! -------------

Share this post


Link to post
Share on other sites
Try adding a & before the functio name like FSOUND_Stream_SetEndCallback(tag.m_pStream, &StreamEndCallback, 0)

You can also try specifically declaring it as __stdcall, I think MSVC used __cdecl by default.

Share this post


Link to post
Share on other sites
Hello! Thanks for your reply. :)

Quote:
Original post by Gyrbo
Try adding a & before the functio name like FSOUND_Stream_SetEndCallback(tag.m_pStream, &StreamEndCallback, 0)


Unfortunately, this way I get an error.

Quote:

You can also try specifically declaring it as __stdcall, I think MSVC used __cdecl by default.


I've tried to declaring the function as __stdcall but it doesn't work anyway. :/ Is it possible that this declaration can be skipped by the compiler (some settings etc...) ?

Thanks!

------------

Share this post


Link to post
Share on other sites
If you have the function prototype in a header file, make sure you add the __stdcall there (too).

It's always helpful if you post the actual error messages ;).

Share this post


Link to post
Share on other sites
Hey, Gyrbo.

This morning I woke up and went to a hairdresser. Then, I took some time to practice a guitar and when I finished I discovered that none of my (two) brothers is occupying the computer. I thought : 'No way, I can stay at this point for too long'. I launched the compiler and started to think. Suddenly, I realized a following thing : 'How can FMOD call the callback function when it's included in my own class?'. I figured out that if I make a callback function static the code compiles without errors (don't know if it really works, anyway). Unfortunately, that's not the end of my question. Even though the code 'theoriticaly' works, I am getting this error :

error C2352: 'FMODSoundSystem::PlaylistNextSong' : illegal call of non-static member function


How can I call a member functions within a static member-function (in some elegant way, of course) ?

Thanks! :)

PS. Because of your effort, you deserved some positive rating, Gyrbo. :)

-------------

Share this post


Link to post
Share on other sites
Static member functions aren't really meant to call other functions of that class. You could work around that by making your class a singleton (or just storing an instance of it in a global/static variable). I haven't used them before, but functors could probably also work for this.
You probably have a flaw in your design somewhere if you have to call a non-static function from a static one.

I'm not really familiar with fmod, so I can't really help you on that side.

Share this post


Link to post
Share on other sites
Quote:
Original post by Gyrbo
I'm not really familiar with fmod, so I can't really help you on that side.


It's not an FMOD question now really. Thanks, anyway.

Share this post


Link to post
Share on other sites
Hello,

Here what to do :

1) Put the callback prototype on top of your file .cpp just after #include "myClass.h" and before class constructor myClass:myClass()...

ex: FMOD_RESULT F_CALLBACK pcmreadcallback(FMOD_SOUND *sound, ...);

2) Put the callback function at the end of your .cpp after all the methods

ex:
FMOD_RESULT F_CALLBACK pcmreadcallback(FMOD_SOUND *sound, ...)
{
...
}

3) Declare the variables you need to control that are inside your callback function as global on top of your .cpp (after the #include"myClass")

4) Modify the variables of 3) as needed with methods of your class.

And voilà!

Hope it will work for you!

Firsbruno


Share this post


Link to post
Share on other sites

This topic is 3007 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this