[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.
In my main form, I declare a timer:
GameFrames = New Timer
GameFrames.Interval = 1
This is linked to a function on another code sheet:
Public Sub Game_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GameFrames.Tick
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:
MusicPlayer = New FMODPlayer
In the code sheet I’ve dedicated to FMOD, this results in the following:
Public Sub New()
Fresult = FMOD.Factory.System_Create(Fsystem)
Fresult = Fsystem.setSpeakerMode(FMOD.SPEAKERMODE.STEREO)
Fresult = Fsystem.setOutput(FMOD.OUTPUTTYPE.AUTODETECT)
Fresult = Fsystem.init(100, FMOD.INITFLAG.NORMAL, Nothing)
Private Sub ERRCHECK(ByVal Fresult As FMOD.RESULT)
If Fresult <> FMOD.RESULT.OK Then
MsgBox("FMOD error: " & Fresult & "-" & FMOD.Error.String(Fresult), MsgBoxStyle.Critical)
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
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:
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
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.
-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?
- Shurikane asked 10 years ago
- You must login to post comments
Using http://18.104.22.168/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)
- Shurikane answered 10 years ago
- You must login to post comments
Please login first to submit.