Results 1 to 7 of 7

Thread: [RESOLVED] music fade and timer equation

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2010
    Posts
    27

    Resolved [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

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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.

  3. #3
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    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
    Last edited by Spoo; Jun 15th, 2010 at 12:34 PM. Reason: added 1/2 sec column

  4. #4
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    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.
    Attached Files Attached Files
    Last edited by baja_yu; Jun 15th, 2010 at 12:34 PM.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    May 2010
    Posts
    27

    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

  6. #6

    Thread Starter
    Junior Member
    Join Date
    May 2010
    Posts
    27

    Re: music fade and timer equation

    sorry didn't see the replies when trying it out and posting - will have another look.

    thanks

  7. #7

    Thread Starter
    Junior Member
    Join Date
    May 2010
    Posts
    27

    Re: music fade and timer equation

    I love this forum

    sorted - all working an absolute treat now

    thank you guys

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width