[RESOLVED] music fade and timer equation
Hi All,
i'm creating a music player using windowsmediaplayer - i've got a text box, cmd button and timer that I want to be able to reduce the volume of the player over the number of seconds that are input in the text box, when the button is clicked.
So that if 3 is typed in for example the volume will reduce to zero (and then stop the player) over a 3 second period.
I can't seem to do the math equation to figure this out, and i'm feeling stupid about it.
Any help out there please?
thanks
Re: music fade and timer equation
If you were going to reduce the volume once per second for each of 3 seconds, you would reduce it by 1/3 of the original value each time.
If you do it every half a second, you would reduce it by 1/(3*2) = 1/6 of the original value.
Re: music fade and timer equation
Otto
Si gave you the formulae, but just to ram it home ...
Code:
Reduce to Amt to Amt to
zero in XX reduce reduce
seconds per sec per 1/2 second
========== ============ ================
3 1/3 = .333 1/(3*2) = .1667
6 1/6 = .1667 1/(6*2) = .0833
10 1/10 = .10 1/(10*2) = .05
Spoo
1 Attachment(s)
Re: music fade and timer equation
Something like this? (see attached project)
Note, timer object isn't really precise, so any interval below about 1.5 seconds wont work as fast as it should.
EDIT: Didn't refresh. Si and Spoo gave you correct math based on the approach you asked, but the end result of doing it like that will be a very choppy fade. If the interval is two, it will basically lower the volume to half after one second and after another it will completely mute the sound. My method calculates the intervals in which to reduce the volume by the lowest volume increment (assuming it goes from 0 to 100). That will give you a smooth transition over any interval.
Re: music fade and timer equation
ok so timer interval = 500
not there yet though, if I use the below the volume drops far to quickly, about a second or so.
Code:
Private Sub butfade1_Click()
Timer7.Enabled = True
End Sub
Private Sub Timer7_Timer()
Dim s As Integer 's is number of seconds
Dim fadetime As Long
s = txtfade1.Text
fadetime = 1 / (s * 2)
wmp1.settings.volume = fadetime
If wmp1.settings.volume = 0 Then
wmp1.Controls.stop
Timer7.Enabled = False
End If
End Sub
Re: music fade and timer equation
sorry didn't see the replies when trying it out and posting - will have another look.
thanks
Re: music fade and timer equation
I love this forum :):):):)
sorted - all working an absolute treat now
thank you guys