0
0

Hi,

I am using FMOD 3.74 with the Delphi 6 IDE and am having problems passing userdata to the end callback of a stream. The software I am writing is a broadcast automation player, so it has three “carts” that can play simultaneously. I would like to use one callback function for all three carts and pass an index number through the userdata variable.

There seems to be some confusion as to what type of variable the userdata should be. In the FMOD help file, it is referred to as a void pointer, however in fmodtypes.pas it is referred to simply as an Integer. My program won’t compile if I pass a pointer to an Integer in my call to FSOUND_Stream_SetEndCallBack.

If I pass an Integer to FSOUND_Stream_SetEndCallBack:
ie) FSOUND_Stream_SetEndCallBack(plyrstrm,@DonePlaying,1);

and set up DonePlaying as:
procedure DonePlaying(stream: PFSoundStream; buff: Pointer; len,userdata: Integer);

then the userdata Integer which ends up in the DonePlaying procedure is not any reliable figure. It is usually some big number that appears to be a pointer to some memory location, but not a pointer to a memory location containing the Integer I passed using SetEndCallBack

Am I missing something?

Thanks,
Andrew

  • You must to post comments
0
0

you must cast the pointer to an integer and back again to make it work, eg:
[code:3rkvmsft]
type pint=^integer;
var int:pint;

begin
new(int);
int^:=1;
FSOUND_Stream_SetEndCallback(FModHandle,OnStreamEnd,integer(int));
end;

function OnStreamEnd (Stream: PFSoundStream; Buff: Pointer; Length, Param: Integer): ByteBool;stdcall;
begin
showmessage(inttostr(pint(param)^));
result:=false;
end;

[/code:3rkvmsft]

  • You must to post comments
0
0

Thanks for your quick response. My problem turned out to be that I wasn’t declaring my callback method as stdcall. After that adjustment, my code worked fine just passing an Integer (no pointers) as the third parameter to FSOUND_Stream_SetEndCallBack. I also changed my callback method to a function with a ByteBool return value, but it also seemed to work o.k. with a procedure as a callback method just as long as the procedure was declared as stdcall.

Andrew

  • You must to post comments
0
0

In case you want to make the callback a method of an object, for example it you have a TPlayer class and want the callback to call a method of that class.
You need to add [b:s6u7vxl4]of object;[/b:s6u7vxl4] after the callback method declaration, before the [b:s6u7vxl4]stdcall;[/b:s6u7vxl4] if I am not mistaken.

  • You must to post comments
0
0

that is not compatible with the function stereotype, to use callbacks on an object simply pass the object use the user data:
[code:2c2syug1]
type TPlayer=class(TObject);
var plr:TPlayer

begin
FSOUND_Stream_SetEndCallback(FModHandle,OnStreamEnd,integer(plr));
end;

function OnStreamEnd (Stream: PFSoundStream; Buff: Pointer; Length, Param: Integer): ByteBool;stdcall;
var plr:TPlayer;
begin
plr:=TPlayer(param);
plr.EndCallback(stream,buff,length);
result:=false;
end;
[/code:2c2syug1]

  • You must to post comments
0
0

You sure? Think I had that working ones, will try it sometime in the vacation. Could be tough that I am confused with something else.

  • You must to post comments
0
0

pretty sure, object methods are implemented slightly differently to standard functions and are, as far as i know, incompatible with fmod callbacks

  • You must to post comments
Showing 6 results
Your Answer

Please first to submit.