Hi,
I’m new member and fmodex user, I try to use Fmosex in my VB6 Software.
How can simulate the fade in/out when I press play/stop command or step to a song? (like a winamp)
Thank
Luca
- luca.decarlo asked 10 years ago
- You must login to post comments
Seems you code does steps each timer event? Which has lot’s of pro’s (especially for events), but it’s still step-based and not really accurate, because the timer intervals aren’t quite accurate. Doing a volume calculation based upon elapsed time would make it real accurate, however if the system is real busy, the next timer event may have to adjust volume from 0% to 100%.
BTW, analzsing elapsed timer intervals is a quite good ‘performance monitor’, really showing how much ‘resources’ an app gets, … shows pretty much opposit values compared to Windows CPU monitor, but 95% fits operating system usage state (yep, WinXP often hangs with <10% CPU usage on my system). And if the elapsed interval is quite high, you can assume how long your system was busy (while XP ‘misses’ this)
You should set a value for m_dblFadeStepSize, or make a constant… won’t really fade otherwise…?
- Controller answered 10 years ago
- You must login to post comments
Controller – you are correct that the built in VB timer is a load of <insert adjective here>. This was simply a proof of concept for the question. In my actual code I’m using the HiRes VB timer from VBAccelerator – [url:sltgol7v]http://www.vbaccelerator.com/codelib/ssubtmr/hirestmr.htm[/url:sltgol7v]. This timer seems to have low over head while allowing for very accurate timing. As well – the user could always write their own timer class as I’ve done once before using direct API calls. But the HiRes timer has been extensively tested and is well trusted to perform consistently with applications. During a Fade my system usage for the main EXE does not change at all.
As far as the m_dblFadeStepSize is concerned:
[code:sltgol7v]Public Property Get FadeStepSize() As Double
FadeStepSize = m_dblFadeStepSize
End Property
Public Propertty Let FadeStepSize(ByVal dblFadeStepSize As Double)
m_dblFadeStepSize = dblFadeStepSize
End Property[/code:sltgol7v]
I accidentally left this out of the code I posted. Thanks for the catch!
Again I do note that there is an issue with my code as well. If the code is executing a FadeOut and the user grabs the volume control and pulls it upward the FadeOut can never complete. Of course if the class had a property of IsFading that was Boolean then the UI could look at that and not allow the user to change the fader value. The main reason why this method would be better is the ability to dynamically change the length of time the Fade requires while also allowing to Fade to a value and not just 0 all of the time.
- cxvjeff answered 10 years ago
- You must login to post comments
You have to adjust volume, e.g. with a For … Next
- Controller answered 10 years ago
- You must login to post comments
Hopefully this does not confuse more than it helps… this is a snippet of my FadeOut from a wrapper I’ve made for my VB6 project. It does get a bit more complicated than it truely needs to be but it will give you a much smoother fade than with a For…Next loop. Plus you will be able to give a time duration to make the FadeOut last and you don’t have to always Fade to 0.
[code:bmiart5u]Private m_dblFadeStepSize As Double
Private m_blnFading As Boolean
Private m_lngFadeOutToLevel As Long
Private Sub m_objFadeOutTimer_Timer(ByVal Milliseconds As Long)
‘Decrease fader value by another step
Me.Fader = Me.Fader – m_dblFadeStepSize
m_blnFading = True
m_lngFadeDirection = FadingOut
If (Me.Fader <= Me.FadeOutToLevel) Then
Call StopPlayerObject
End If
End Sub
Public Property Get Fader() As Double
Dim sngVolumeLevel As Single ‘Values from 0.0 to 1.0 values
FMOD_Channel_GetVolume m_objFMODChannel, sngVolumeLevel
Fader = sngVolumeLevel * 100
End Property
Public Property Let Fader(ByVal dblFaderLevel As Double)
Dim lngErrorResult As Long
Dim sngVolumeLevel As Single
If (dblFaderLevel <= 0) Then
dblFaderLevel = 0
End If
If (dblFaderLevel > 0) Then
sngVolumeLevel = CSng(dblFaderLevel / 100)
Else
sngVolumeLevel = 0#
End If
'Set the volume in FMOD
FMOD_Channel_SetVolume m_objFMODChannel, sngVolumeLevel
m_dblFaderPosition = dblFaderLevel
End Property
Public Property Get FadeOutToLevel() As Long
FadeOutToLevel = m_lngFadeOutToLevel
End Property
Public Property Let FadeOutToLevel(ByVal lngFadeOutToLevel As Long)
m_lngFadeOutToLevel = lngFadeOutToLevel
End Property
Private Sub StopPlayerObject()
m_objFadeOutTimer.Enabled = False
m_blnFading = False
FMOD_Channel_Stop m_objChannel
End Sub[/code:bmiart5u]
- cxvjeff answered 10 years ago
- You must login to post comments
Please login first to submit.