0
0

Brett,

Thanks for the new version, but I’m still having trouble playing sounds from inside end callbacks. Using beta 28 I was able to get the callback to fire once but then it wouldn’t fire again (as mentioned in [url=http://www.fmod.org/forum/viewtopic.php?t=3901:h96bemv1]a previous thread[/url:h96bemv1]). With beta 29 I get VB5’s IDE crashing as soon as the new sound is played inside the callback.

I couldn’t find an example that plays a sound in an end callback, so I tried to produce a minimal code example. Call main() from a commandbutton or something on a form:
[code:h96bemv1]Option Explicit

Public system As Long
Public Sound As Long
Public channel As Long
Public timerid As Long

Public Declare Function SetTimer Lib "user32" _
(ByVal hwnd As Long, ByVal nIDEvent As Long, _
ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Public Declare Function KillTimer Lib "user32" _
(ByVal hwnd As Long, ByVal nIDEvent As Long) As Long

Sub main()
Debug.Print "Creating System..."
errCheck (FMOD_System_Create(system))
Debug.Print "Init-ing FMOD..."
errCheck (FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, 0))
Debug.Print "Setting timer..."
timerid = SetTimer(0, 0, 100, AddressOf timerproc)
Debug.Print "Loading winstart.wav..."
Dim exinfo As FMOD_CREATESOUNDEXINFO
errCheck (FMOD_System_CreateStream(system, "c:\winstart.wav", FMOD_DEFAULT, exinfo, Sound))
Debug.Print "Playing winstart.wav..."
errCheck (FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, Sound, False, channel))
Debug.Print "Channel: " & channel
errCheck (FMOD_Channel_SetCallback(channel, FMOD_CHANNEL_CALLBACKTYPE_END, AddressOf end_callback, 1))
End Sub

Public Sub errCheck(result As FMOD_RESULT)
If Not (result = FMOD_OK) Then
MsgBox "FMOD Error: " & FMOD_ErrorString(result)
shutdown
End
End If
End Sub

Public Sub shutdown()
KillTimer 0, timerid
errCheck (FMOD_System_Release(system))
End Sub

Public Sub timerproc()
errCheck (FMOD_System_Update(system))
End Sub

Public Sub setcallback()
errCheck (FMOD_Channel_SetCallback(channel, FMOD_CHANNEL_CALLBACKTYPE_END, AddressOf end_callback, 1))
End Sub

Public Function end_callback(cur_channel As Long, y As Long, z As Long, a As Long, b As Long) As Long
Debug.Print "callback"
errCheck (FMOD_System_PlaySound(system, FMOD_CHANNEL_REUSE, Sound, False, channel))
setcallback
Debug.Print "callback: channel: " & channel
end_callback = FMOD_OK
End Function[/code:h96bemv1]
I’d really appriciate any input into my problem!

Thanks! 8)

  • You must to post comments
0
0

Thanks Brett! That fixed it 😀

I’m still left with the problem where the end callback in the above code only occurs once though. The effect in the above code is that the sound should be played over and over, but is only played twice.

I think the end callback is not working at all when another sound is played on a channel using FMOD_CHANNEL_REUSE. If you change to FMOD_CHANNEL_FREE in the FMOD_System_PlaySound inside the callback – the callback fires over and over as expected.

  • You must to post comments
0
0

Must I call FMOD_System_Update over and over to make this work ?

Then it takes away some of the point of having this callback. Then it’s just as easy to check the status in the timer event who update the system.

David

  • You must to post comments
0
0

Yeah you do need to call FMOD_System_Update over and over in order to get callbacks. To quote the documentation:
[quote:fgzw8s2y]Currently callbacks are driven by System::update and will only occur when this function is called. This has the main advantage of far less complication due to thread issues, and allows all FMOD commands, including loading sounds and playing new sounds from the callback.
It also allows any type of sound to have an end callback, no matter what it is. The only disadvantage is that callbacks are not asynchronous and are bound by the latency caused by the rate the user calls the update command.[/quote:fgzw8s2y]
You could just check the status of streams yourself from your timer if you’d prefer, it depends on how your application works and what is most convenient for you.

  • You must to post comments
0
0

It is of course better to check for end since this callback is not what it appears to be.

But I seem to miss the point of this callback since it’s not automatic. And I thought this would get rid of the overhead of calling a timer event every few milliseconds (in our case)

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.