Results 1 to 4 of 4

Thread: Keep the rhythm with a timer

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Location
    Belgium
    Posts
    87

    Unhappy Please help a poor guy with your knowledge

    I want a short sound to be repeated continuously but I want this rhythmical, in time. I tried this with a timer control but that doesn't work like I want it (sometimes it goes fast than slow...). Does somebody know how I can play the sound with exactly the same time between every beat?
    (PS: I'm using DirectSound to play the wav file)

    Thanx

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    Use the Timer control to reduce the variance on the elapsed time by using a variable within the Timer to measure the actual time elapsed more accurately, i.e.
    Code:
    Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
    Private Const SND_ASYNC = &H1
    Private Const SND_NOWAIT = &H2000
    
    Private Sub Form_Load()
        Timer1.Interval = 1
    End Sub
    
    Private Sub Timer1_Timer()
        Static tTimer As Single
        
        If tTimer = 0 Then tTimer = Timer
        If Timer - tTimer >= 1 Then
            Call sndPlaySound("C:\Windows\Media\Start.wav", SND_ASYNC Or SND_NOWAIT)
            tTimer = Timer
        End If
    End Sub

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Location
    Belgium
    Posts
    87
    I tried Aaron Young's code but it seems to go fast and slow too. When I play a sound the program waits until the sound is completly finished, when I try to play the sound with DirectSound it isn't in time too.

    And something else, when I play sounds with DirectSound I alway get a click between the sounds. Does anybody know how to fix that problem?

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Location
    Belgium
    Posts
    87

    Unhappy

    Help me please I realy need the code to do this!

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