0
0

SOrry for this Tourist question but How to use Fmod in VB or delpi? like call fmod.dll to play for ex. Win.mp3? do I have to use music with Delphi or VB commands much. becos im noob with delphi and VB but im starting to program with them.. thank you if somebody can help me 😳

  • You must to post comments
0
0

Read the f*** manual.

  • You must to post comments
0
0

look in the doc’s by the tutorials 😉

  • You must to post comments
0
0

This is an old modul I created for full automated playback with crossfade support, supporting tracker / stream-files

An application startup, you MUST call ctFMod_DMusicA_Initialize to initialize,
when quitting ctFMod_DMusicA_Close. Call each function ONCE only !!!
Be sure your app calls ctFMod_DMusicA_Close before stopping with the stop button once initialized, or visual basic will crash

Once initialized, use ctFMod_DMusicA_SetNewSong to specify the song to play (must be a supported file on your hard disk)

Check the function parameters to see all available options

Please note that I haven’t used this code for quite a while, so if it doesn’t work, contact me (info@ctuser.net)

Before you can use the modul, you’ll have to replace the UseResDLLFile(…) call wich is called when fmod.dll is missing or cannot load. If you don’t know how to use it, simply add a fake function:
Private Function UseResDLLFile(ByVal resFileName As String, Optional ByVal rVer As Single = -1&, Optional ByVal rVerMinor As Single = -1&, Optional ByVal CustomDirectory As String) As Boolean

Option Explicit
Option Base 0

Private Const DefaultVolume As Long = 200&

Private Declare Function SetTimer Lib “user32” (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib “user32” (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Private xHWnd As Long
Private xTimerID As Long

Private Declare Function FSOUND_SetBufferSize Lib “fmod.dll” Alias “_FSOUND_SetBufferSize@4” (ByVal lenms As Long) As Byte
Private Declare Function FSOUND_Init Lib “fmod.dll” Alias “_FSOUND_Init@12” (ByVal mixrate As Long, ByVal MaxChannels As Long, ByVal flags As Long) As Byte
Private Declare Function FSOUND_Close Lib “fmod.dll” Alias “_FSOUND_Close@0” () As Long
Private Declare Function FSOUND_SetHWND Lib “fmod.dll” Alias “_FSOUND_SetHWND@4” (ByVal hwnd As Long) As Byte
Private Declare Function FSOUND_Stream_Open Lib “fmod.dll” Alias “_FSOUND_Stream_Open@16” (ByVal FileName As String, ByVal mode As Long, ByVal Offset As Long, ByVal Length As Long) As Long
Private Declare Function FSOUND_Stream_PlayEx Lib “fmod.dll” Alias “_FSOUND_Stream_PlayEx@16” (ByVal channel As Long, ByVal stream As Long, ByVal dsp As Long, ByVal startpaused As Byte) As Long
Private Declare Function FSOUND_SetPaused Lib “fmod.dll” Alias “_FSOUND_SetPaused@8” (ByVal channel As Long, ByVal Paused As Byte) As Byte
Private Declare Function FSOUND_Stream_Stop Lib “fmod.dll” Alias “_FSOUND_Stream_Stop@4” (ByVal stream As Long) As Byte
Private Declare Function FSOUND_Stream_GetLengthMs Lib “fmod.dll” Alias “_FSOUND_Stream_GetLengthMs@4” (ByVal stream As Long) As Long
Private Declare Function FSOUND_Stream_GetTime Lib “fmod.dll” Alias “_FSOUND_Stream_GetTime@4” (ByVal stream As Long) As Long
Private Declare Function FSOUND_Stream_Close Lib “fmod.dll” Alias “_FSOUND_Stream_Close@4” (ByVal stream As Long) As Byte
Private Declare Function FSOUND_StopSound Lib “fmod.dll” Alias “_FSOUND_StopSound@4” (ByVal channel As Long) As Byte
Private Declare Function FSOUND_SetVolume Lib “fmod.dll” Alias “_FSOUND_SetVolume@8” (ByVal channel As Long, ByVal Vol As Long) As Byte
Private Declare Function FMUSIC_LoadSong Lib “fmod.dll” Alias “_FMUSIC_LoadSong@4” (ByVal name As String) As Long
Private Declare Function FMUSIC_PlaySong Lib “fmod.dll” Alias “_FMUSIC_PlaySong@4” (ByVal module As Long) As Byte
Private Declare Function FMUSIC_StopSong Lib “fmod.dll” Alias “_FMUSIC_StopSong@4” (ByVal module As Long) As Byte
Private Declare Function FMUSIC_SetPaused Lib “fmod.dll” Alias “_FMUSIC_SetPaused@8” (ByVal module As Long, ByVal Pause As Byte) As Byte
Private Declare Function FMUSIC_SetLooping Lib “fmod.dll” Alias “_FMUSIC_SetLooping@8” (ByVal module As Long, ByVal looping As Boolean) As Byte
Private Declare Function FMUSIC_GetOrder Lib “fmod.dll” Alias “_FMUSIC_GetOrder@4” (ByVal module As Long) As Long
Private Declare Function FMUSIC_GetNumOrders Lib “fmod.dll” Alias “_FMUSIC_GetNumOrders@4” (ByVal module As Long) As Long
Private Declare Function FMUSIC_IsFinished Lib “fmod.dll” Alias “_FMUSIC_IsFinished@4” (ByVal module As Long) As Byte
Private Declare Function FMUSIC_FreeSong Lib “fmod.dll” Alias “_FMUSIC_FreeSong@4” (ByVal module As Long) As Byte
Private Declare Function FMUSIC_SetMasterVolume Lib “fmod.dll” Alias “_FMUSIC_SetMasterVolume@8” (ByVal module As Long, ByVal Volume As Long) As Byte

Private Const FadeOutStep As Long = 12&
Private Const FadeOutTimer As Long = 10&
Private Const CrossFadeWaitTime As Long = 200&
Private Const CrossFadeWaitEndTime As Long = 50&
Private Const CrossFadeOverlap As Long = 6&
Private Const CrossFadeStepsCount As Long = 32&
Private Const CrossFadeTimer As Long = 14&
Private Const CrossFadeMinTime As Long = 60000
Private Const CrossFadeMinPos As Long = 18&
Private Const CrossFadeMaxPos As Long = 12&
Private Const CrossFadeMinPatterns As Long = 10&
Private Const CrossFadeMinPattern As Long = 2&
Private Const CrossFadeMaxPattern As Long = 2&

Dim xSongPointer2 As Long
Dim xSongChannel2 As Long

Dim xSongFile As String
Dim xSongFormat As Boolean
Dim xSongPointer As Long
Dim xSongChannel As Long
Dim xSongMaxPos As Long
Dim xSongOldPos As Long
Dim xSongOffset As Long
Dim xSongLength As Long

Dim xVolume As Long
Dim xVol1 As Long
Dim xVol2 As Long
Dim xSkipNow As Boolean
Private xEStop As Boolean

Private xFading As Boolean
Dim xLoaded As Boolean
Dim xLocked As Boolean
Dim xPlaying As Boolean

Public Function ctFMod_DMusicA_Initialize(ByVal AppHWnd As Long, Optional ByVal Volume As Long = DefaultVolume, Optional ByVal Fading As Boolean = True, Optional ByVal TimerID As Long = 0&) As Boolean
Dim xLong1 As Long
Static xBool1 As Boolean

xFading = Fading
xVol1 = -1&
xVol2 = -1&

xVolume = Volume
On Error GoTo Er1
xHWnd = AppHWnd
xTimerID = TimerID
RsX1:
Call FSOUND_SetBufferSize(400&)
On Error GoTo Er2
Call FSOUND_SetHWND(xHWnd)
Call FSOUND_Init(44001, 16&, 2&)
xLong1 = Timer * 100&: Do While Abs(Timer * 100& – xLong1) < 100&: DoEvents: Loop
Rs2:
xLoaded = True
ctFMod_DMusicA_Initialize = True
Call SetTimer(xHWnd, xTimerID, 1000&, AddressOf ctFMod_DMusicA_Timer)
Rs1:
On Error GoTo 0
Exit Function

Er1:
If Not xBool1 Then Resume ErX1
Resume Rs1

ErX1:
xBool1 = True
If UseResDLLFile(“FMOD.DLL”, 3.71, 0) Then
On Error GoTo Er1
GoTo RsX1
Else
GoTo Rs1
End If

Er2:
Resume Rs2
End Function

Public Sub ctFMod_DMusicA_SetNewSong(ByVal FileName As String, Optional ByVal PlayImmediatelly As Boolean = True, Optional ByVal Offset As Long, Optional ByVal Length As Long)
If Not FileName = “” Then
xSkipNow = (PlayImmediatelly Or xSongFile = “”)
xSongFile = FileName
xSongOffset = Offset
xSongLength = Length
End If
End Sub

Private Sub ctFMod_DMusicA_Timer()
Dim xLong1 As Long

If Not xLocked Then
If xSkipNow Then
xSkipNow = False
If Not xSongFile = “” Then
PlayX
End If
Else
If xPlaying Then
If xSongFormat Then
If FMUSIC_IsFinished(xSongPointer) Then
StopPlaybackX True
If Not xSongFile = “” Then
PlayX
End If
Else
xLong1 = FMUSIC_GetOrder(xSongPointer)
If xSongMaxPos > CrossFadeMinPatterns And Not xSongFile = “” And _
xSongMaxPos – xLong1 <= CrossFadeMinPattern And _
xSongMaxPos – xLong1 >= CrossFadeMaxPattern Then
PlayX
End If
End If
Else
xLong1 = FSOUND_Stream_GetTime(xSongPointer)
If xSongMaxPos > CrossFadeMinTime And Not xSongFile = “” And _
((xSongMaxPos – xLong1) / 1000) <= CrossFadeMinPos And _
((xSongMaxPos – xLong1) / 1000) > CrossFadeMaxPos Then
PlayX
ElseIf xLong1 = xSongMaxPos Or xLong1 = xSongOldPos Then
StopPlaybackX True
If Not xSongFile = “” Then
PlayX
End If
Else
xSongOldPos = xLong1
End If
End If
End If
End If
End If
End Sub

Public Function ctFMod_DMusicA_Close(Optional ByVal Fading As Boolean = False) As Boolean
Dim xLong1 As Long

If xLoaded Then
If xLocked Then
StopX Fading
End If
Call KillTimer(xHWnd, xTimerID)
If xPlaying Then
StopPlaybackX Fading
xLong1 = Timer * 100: Do While Abs(xLong1 – Timer * 100) < 100: DoEvents: Loop
End If
FSOUND_Close
xLoaded = False

End If
ctFMod_DMusicA_Close = True
End Function

Private Sub PlayX()
Dim xLong1 As Long
Dim xBool1 As Boolean
Dim xBool2 As Boolean

Select Case UCase(Right(xSongFile, 4))
Case “.MP3”, “.WAV”, “.OGG”
xBool2 = True
Case “.MOD”, “.S3M”
xBool1 = True
xBool2 = True
Case Else
xBool2 = Not (xSongLength = 0&)
End Select
Select Case UCase(Right(xSongFile, 3))
Case “.IT”, “.XM”
xBool1 = True
xBool2 = True
End Select
If xBool2 And xLoaded Then
ctFMOD_DMusicA_NoNextSongCallback
If xPlaying Then
If xFading Then
SkipToNextSong xBool1
Else
StopPlaybackX False
PlayX
End If
Else
xLocked = True ”’
xSongFormat = xBool1
If xSongFormat Then
xSongPointer = FMUSIC_LoadSong(xSongFile)
If Not xSongPointer = 0& Then
xSongMaxPos = FMUSIC_GetNumOrders(xSongPointer)
FMUSIC_SetLooping xSongPointer, False
FMUSIC_SetMasterVolume xSongPointer, xVolume
FMUSIC_PlaySong xSongPointer
FMUSIC_SetMasterVolume xSongPointer, xVolume
FMUSIC_SetLooping xSongPointer, False
xVol1 = xVolume
xPlaying = True
End If
Else
xSongPointer = FSOUND_Stream_Open(xSongFile, &H22000, xSongOffset, xSongLength)
If Not xSongPointer = 0& Then
xSongMaxPos = FSOUND_Stream_GetLengthMs(xSongPointer)
xSongOldPos = -1
xSongChannel = FSOUND_Stream_PlayEx(-1, xSongPointer, 0, 1)
FSOUND_SetVolume xSongChannel, xVolume
Call FSOUND_SetPaused(xSongChannel, 0)
xVol1 = xVolume
xPlaying = True
End If
End If
xEStop = 0&
xLocked = False
End If
End If
End Sub

Private Sub StopPlaybackX(ByVal Fading As Boolean)
Dim xLong1 As Long

If xLoaded And xPlaying Then
If xLocked Then
StopX Fading
Else
xLocked = True
If Fading And xFading Then
If xSongFormat Then
For xVol1 = xVolume To 0 Step -FadeOutStep
xLong1 = Timer * 100: Do While Abs(xLong1 – Timer * 100) < FadeOutTimer: DoEvents: Loop
If xEStop Then xEStop = 0&: Exit Sub
FMUSIC_SetMasterVolume xSongPointer, xVol1
Next
xLong1 = Timer * 100: Do While Abs(xLong1 – Timer * 100) < FadeOutTimer: DoEvents: Loop
If xEStop Then xEStop = 0&: Exit Sub
FMUSIC_SetMasterVolume xSongPointer, 0
Else
For xVol1 = xVolume To 0 Step -FadeOutStep
xLong1 = Timer * 100: Do While Abs(xLong1 – Timer * 100) < FadeOutTimer: DoEvents: Loop
If xEStop Then xEStop = 0&: Exit Sub
FSOUND_SetVolume xSongChannel, xVol1
Next
xLong1 = Timer * 100: Do While Abs(xLong1 – Timer * 100) < FadeOutTimer: DoEvents: Loop
If xEStop Then xEStop = 0&: Exit Sub
FSOUND_SetVolume xSongChannel, 0
End If
xLong1 = Timer * 100: Do While Abs(xLong1 – Timer * 100) < FadeOutTimer: DoEvents: Loop
If xEStop Then xEStop = 0&: Exit Sub
End If
If xSongFormat Then
FMUSIC_FreeSong xSongPointer
Else
Call FSOUND_Stream_Stop(xSongPointer)
Call FSOUND_Stream_Close(xSongPointer)
Call FSOUND_StopSound(xSongChannel)
End If
xLocked = False
End If
End If
xVol1 = -1&
xPlaying = False
End Sub

Private Sub SkipToNextSong(ByVal xSongNextF As Boolean)
If Not xPlaying Then
Stop
Exit Sub
End If
Dim xLong1 As Long
Dim xLong2 As Long
Dim xLong3 As Long
Dim CrossFadeStep As Long

xLocked = True
If xSongNextF Then
xSongPointer2 = FMUSIC_LoadSong(xSongFile)
If xSongPointer = 0& Then
xLocked = False
Exit Sub
End If
FMUSIC_SetLooping xSongPointer2, False
FMUSIC_SetMasterVolume xSongPointer2, 0&
FMUSIC_PlaySong xSongPointer2
FMUSIC_SetMasterVolume xSongPointer2, 0&
FMUSIC_SetLooping xSongPointer2, False
Else
xSongPointer2 = FSOUND_Stream_Open(xSongFile, &H22000, xSongOffset, xSongLength)
If xSongPointer = 0& Then
xLocked = False
Exit Sub
End If
xSongChannel2 = FSOUND_Stream_PlayEx(-1, xSongPointer2, 0&, 1&)
Call FSOUND_SetVolume(xSongChannel2, 0&)
Call FSOUND_SetPaused(xSongChannel2, 0&)
End If

xLong1 = Timer * 100
xVol2 = xVolume
Do While Abs(xLong1 – Timer * 100) < CrossFadeWaitTime: DoEvents: Loop
If xEStop Then xEStop = 0&: Exit Sub
CrossFadeStep = xVolume \ CrossFadeStepsCount

xLong3 = ((xVolume * (1 – (CrossFadeOverlap / 10))) \ CrossFadeStep) * CrossFadeStep
For xVol2 = 0& To xLong3 Step CrossFadeStep
xLong1 = Timer * 100
Do While Abs(xLong1 – Timer * 100) < CrossFadeTimer: DoEvents: Loop
If xEStop Then xEStop = 0&: Exit Sub
If xSongNextF Then
Call FMUSIC_SetMasterVolume(xSongPointer2, xVol2)
Else
Call FSOUND_SetVolume(xSongChannel2, xVol2)
End If
Next

‘Stop
For xLong2 = 0 To (xVolume – xLong3 – CrossFadeStep) Step CrossFadeStep
xLong1 = Timer * 100
Do While Abs(xLong1 – Timer * 100) < CrossFadeTimer: DoEvents: Loop
If xEStop Then xEStop = 0&: Exit Sub
xVol1 = xVolume – xLong2
If xSongFormat Then
Call FMUSIC_SetMasterVolume(xSongPointer, xVol1)
Else
Call FSOUND_SetVolume(xSongChannel, xVol1)
End If
xVol2 = xLong3 + xLong2
If xSongNextF Then
Call FMUSIC_SetMasterVolume(xSongPointer2, xVol2)
Else
Call FSOUND_SetVolume(xSongChannel2, xVol2)
End If
Next

‘Stop
For xVol1 = xLong2 To xVolume Step CrossFadeStep
xLong1 = Timer * 100
Do While Abs(xLong1 – Timer * 100) < CrossFadeTimer: DoEvents: Loop
If xEStop Then xEStop = 0&: Exit Sub
If xSongFormat Then
Call FMUSIC_SetMasterVolume(xSongPointer, xVolume – xVol1)
Else
Call FSOUND_SetVolume(xSongChannel, xVolume – xVol1)
End If
Next

xLong1 = Timer * 100
Do While Abs(xLong1 – Timer * 100) < CrossFadeWaitEndTime: DoEvents: Loop
If xEStop Then xEStop = 0&: Exit Sub

xLocked = False
StopPlaybackX True
xVol1 = xVolume
xVol2 = -1&
””””””xLong2 = -1&
xPlaying = True
xLocked = True
xSongPointer = xSongPointer2
xSongChannel = xSongChannel2
xSongFormat = xSongNextF
If xSongFormat Then
xSongMaxPos = FMUSIC_GetNumOrders(xSongPointer)
Else
xSongMaxPos = FSOUND_Stream_GetLengthMs(xSongPointer)
xSongOldPos = -1
End If
xPlaying = True
xLocked = False
End Sub

Private Sub StopX(ByVal Fading As Boolean)
Dim xLong1 As Long
xEStop = True

If Fading And xFading Then
Do
If Not xVol1 = -1& Then
xVol1 = xVol1 – FadeOutStep
If xVol1 < 0& Then
xVol1 = -1&
If xSongFormat Then
FMUSIC_FreeSong xSongPointer
Else
Call FSOUND_Stream_Stop(xSongPointer)
Call FSOUND_Stream_Close(xSongPointer)
Call FSOUND_StopSound(xSongChannel)
End If
If xVol2 = -1& Then Exit Do
Else
If xSongFormat Then
FMUSIC_SetMasterVolume xSongPointer, xVol1
Else
FSOUND_SetVolume xSongChannel, xVol1
End If
End If
End If

If Not xVol2 = -1&amp; Then
  xVol2 = xVol2 - FadeOutStep
  If xVol2 &lt; 0&amp; Then
    xVol2 = -1&amp;
    If xSongFormat Then
      FMUSIC_FreeSong xSongPointer2
      Else
      Call FSOUND_Stream_Stop(xSongPointer2)
      Call FSOUND_Stream_Close(xSongPointer2)
      Call FSOUND_StopSound(xSongChannel2)
      End If
    If xVol1 = -1&amp; Then Exit Do
    Else
    If xSongFormat Then
      FMUSIC_SetMasterVolume xSongPointer2, xVol2
      Else
      FSOUND_SetVolume xSongChannel2, xVol2
      End If
    End If
  End If
xLong1 = Timer * 100: Do While Abs(xLong1 - Timer * 100) &lt; FadeOutTimer: DoEvents: Loop
Loop

xLong1 = Timer * 100: Do While Abs(xLong1 – Timer * 100) < 100&: DoEvents: Loop

Else
If Not xVol1 = -1& Then
xVol1 = -1&
If xSongFormat Then
FMUSIC_FreeSong xSongPointer
Else
Call FSOUND_Stream_Stop(xSongPointer)
Call FSOUND_Stream_Close(xSongPointer)
Call FSOUND_StopSound(xSongChannel)
End If
End If
If Not xVol2 = -1& Then
xVol2 = -1&
If xSongFormat Then
FMUSIC_FreeSong xSongPointer2
Else
Call FSOUND_Stream_Stop(xSongPointer2)
Call FSOUND_Stream_Close(xSongPointer2)
Call FSOUND_StopSound(xSongChannel2)
End If
End If
End If

xPlaying = False
End Sub

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.