0
0

Hi!
I’m new to FMODEX and I would evaluate it for a commercial application I’m developing. It seems to me I’m using an “unsupported language” (Delphi) and after some success with some small tests, I am already having the first troubles with Callbacks, in particular FMOD_CHANNEL_CALLBACKTYPE_END.

Now, I understand that I could develop my own callback system using the FMOD_Channel_IsPlaying function, but maybe I’m just overlooking something and FMOD callbacks in Delphi are already ok.

What I basically do is:

….somewhere in code after application start ….

[code:1nbw2jjs]constructor TFMODSoundSystem.Create;
var
fmr: FMOD_RESULT;
begin
// FMOD System Creation
fmr := FMOD_System_Create(FHandle);
FMODCheck(fmr);

// FMOD Version Check
FMODCheckVersion(FHandle, FMOD_VERSION);

// FMOD System Initialization
fmr := FMOD_System_Init(FHandle, 32, FMOD_INIT_NORMAL, nil);
FMODCheck(fmr);

// Setup a timer for calling FMOD_System_Update. It is needed for callbacks
EventsTimer := TTimer.Create(nil);
EventsTimer.Interval := 50;
EventsTimer.OnTimer := EventsTimerTimer;
end;[/code:1nbw2jjs]

… here is the timer event handler …
.. I’m monitoring the result of FMOD_System_Update and the time that goes on display it on the mainform title bar, …

[code:1nbw2jjs]procedure TFMODSoundSystem.EventsTimerTimer(Sender: TObject);
var
fmr: FMOD_RESULT;
begin
fmr := FMOD_System_Update(FHandle);
Application.MainForm.Caption := TimeToStr(Now) + ‘ ‘+IntToStr(ord(fmr));
end;[/code:1nbw2jjs]

… this is the method I’m calling to play a sound. The Sound parameter passed is only a business class. It has a property FileName to indicate which file need to be played … here I’m setting a callback too …

[code:1nbw2jjs]procedure TFMODSoundSystem.PlaySound(Sound: TSound; ChannelId: Integer);
var
fmr: FMOD_RESULT;
FMODSound: FMOD_SOUND;
FMODChannel: FMOD_CHANNEL;
begin
fmr := FMOD_System_CreateStream(Handle, PAnsiChar(Sound.FileName),
FMOD_SOFTWARE, nil, FMODSound);
FMODCheck(fmr);

fmr := FMOD_Sound_SetMode(FMODSound, FMOD_LOOP_OFF);
FMODCheck(fmr);

fmr := FMOD_System_PlaySound(Handle, ChannelId, FMODSound, True, FMODChannel);
FMODCheck(fmr);

//Callbacks
fmr := FMOD_Channel_SetCallback( FMODChannel, FMOD_CHANNEL_CALLBACKTYPE_END,
ChannelCallback, 0 );
FMODCheck(fmr);

fmr := FMOD_Channel_SetPaused(FMODChannel, False);
FMODCheck(fmr);
end;[/code:1nbw2jjs]

… and here is the callback function … nothing special here … just a small beep to test if it was called…

[code:1nbw2jjs]function ChannelCallback( channel: FMOD_CHANNEL; evdata: Cardinal;
callbacktype: Cardinal; command: Integer;
commanddata1, commanddata2: Cardinal): FMOD_Result; stdcall;
begin
Beep;
Result := FMOD_OK;
end;[/code:1nbw2jjs]

Now if I call

[code:1nbw2jjs]FMODSoundSystem.PlaySound(SoundToPlay, 0);[/code:1nbw2jjs]

The sound start playing as expected, the callback function is called, I hear the beep and then the program is not responding anymore and the clock on the title bar is stopped.
I don’t know if it is a thread syncronization problem or something else, but I’m obviously missing something here.

I would be glad if someone could help me. I’m using the version 4.02.03.

Best Regards. Thank you.

Jonni

  • You must to post comments
0
0

i have the same problem did you get rid of it?

julian

  • You must to post comments
0
0

found the error

[code:2375qtan]
function ChannelCallback( channel: FMOD_CHANNEL; evdata: Cardinal;
callbacktype: Cardinal; command: Integer;
commanddata1, commanddata2: Cardinal): FMOD_Result; stdcall; [/code:2375qtan]

this is wrong it has to be:

[code:2375qtan]
function ChannelCallback(channel: FMOD_CHANNEL; callbacktype: FMOD_CHANNEL_CALLBACK; command: Integer;commanddata1:word; commanddata2:word ): FMOD_RESULT;stdcall;
[/code:2375qtan]

we had a cardinal value to much!

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.