0
0

[b:be1ixx90]UPDATE:[/b:be1ixx90] Skip to the second post before replying.

Slowly learning a little more about FMOD everyday, although I’m still a novice in whatever is used to make sounds play…

Before I begin, I want to say that this is my first project that involves referencing DLLs and calling up an outside API. Most of my VB work has been limited to simple database management so far, and this is my first go at playing a sound.

Anyway, here’s the goal: I play one file, and wish to continuously loop it. To this end, I’ve prepared a small OGM sound – a short piece of music. I also compiled the FMOD Wrapper for VB.NET as per the Wiki article’s instructions.

Next…

In my main form, I declare a timer:

[code:be1ixx90]
GameFrames = New Timer
GameFrames.Interval = 1
GameFrames.Start()
[/code:be1ixx90]

This is linked to a function on another code sheet:

[code:be1ixx90]
Public Sub Game_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GameFrames.Tick
Fsystem.update()
End Sub
[/code:be1ixx90]

That’s tested, and it works: the update function is called.

Next, I make a new FMOD object, give it the sound and play it:

[code:be1ixx90]
MusicPlayer = New FMODPlayer
MusicPlayer.PlaySound("music.ogm")
[/code:be1ixx90]

In the code sheet I’ve dedicated to FMOD, this results in the following:

[code:be1ixx90]
Public Sub New()
Fresult = FMOD.Factory.System_Create(Fsystem)
ERRCHECK(Fresult)
Fresult = Fsystem.setSpeakerMode(FMOD.SPEAKERMODE.STEREO)
ERRCHECK(Fresult)
Fresult = Fsystem.setOutput(FMOD.OUTPUTTYPE.AUTODETECT)
ERRCHECK(Fresult)
Fresult = Fsystem.init(100, FMOD.INITFLAG.NORMAL, Nothing)
ERRCHECK(Fresult)
End Sub

Private Sub ERRCHECK(ByVal Fresult As FMOD.RESULT)
If Fresult <> FMOD.RESULT.OK Then
MsgBox("FMOD error: " & Fresult & "-" & FMOD.Error.String(Fresult), MsgBoxStyle.Critical)
Application.Exit()
End If
End Sub

Public Sub PlaySound(ByVal SelectedSound As String)
Dim sound As New FMOD.Sound

    Fresult = Fsystem.createStream(SelectedSound, FMOD.MODE.NONBLOCKING, sound)
    ERRCHECK(Fresult)

    Dim channel As New FMOD.Channel

    channel.setCallback(FMOD.CHANNEL_CALLBACKTYPE.END, AddressOf SongEnded, 0)

    While Fsystem.playSound(FMOD.CHANNELINDEX.FREE, sound, False, channel) = FMOD.RESULT.ERR_NOTREADY
        Fresult = Fsystem.playSound(FMOD.CHANNELINDEX.FREE, sound, False, channel)
    End While
    'ERRCHECK(Fresult)
End Sub

[/code:be1ixx90]

I commented out the last ERRCHECK since it decides to fire even after I’ve successfully played the sound (I’m going at it by the "try playing ’till it works" method.)

And finally, the callback:

[code:be1ixx90]
Public Function SongEnded(ByVal channelraw As System.IntPtr, ByVal type As FMOD.CHANNEL_CALLBACKTYPE, ByVal command As Integer, ByVal commanddata1 As UInt32, ByVal commanddata2 As UInt32) As FMOD.RESULT
MsgBox("Test")
End Function
[/code:be1ixx90]

Now here’s the problem: SongEnded never fires.

At this point, I’m almost certain I forgot just one simple thing, a VB technicality of some sort. In my understanding, I’ve declared a sound object, told it what its end callback was, and then played the aforementioned sound. So in my head, things should go smoothly from there.

Hypothesis:
-Callback declared/set in the wrong manner?
-Bad Fsystem.Update() strategy?
-Missing some sort of command (Private Declare or Private Delegate?) to make VB.NET understand it has to work with a DLL or whatever outside library?

  • You must to post comments
0
0

[b:3j724exp]Update[/b:3j724exp]

Using http://52.88.2.202/forum/viewtopic.php?t=10340 as the start of an idea, I tried to go at it by making a Timer intervaled to the length of the sound itself. I don’t find it to be a solution that’s as elegant as the original, but after testing, I found it did the job: my sound is now looping seamlessly!

I’ll prolly post a new version of the code once I’m all done cleaning it up. There can never be too much support for us VB zealots. 8)

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.