Timer Question

Tekman
09-06-2003, 09:12 PM
Hello everybody, I am writing a program to help my kids with spelling. In the program I record a wav file for each letter of the alphabet. The program records, saves, and plays the wave files fine except for one minor inconvinence.....The wave files range in length from about .9 seconds to 1.6 seconds. I would like to make them more consistant if possible. Here is the relevent code (I hope)
Thanks for any help


Private Sub RecordLetter_Click()
Call recordsound
Call waitaround
Call playsound
Call waitaround

cmdAccept.Caption = "Accept " & wavname(Counter)
cmdReject.Caption = "Reject " & wavname(Counter)
cmdAccept.Enabled = True
cmdReject.Enabled = True
cmdRecordLetter.Enabled = False
End Sub

Sub recordsound()


i = mciSendString("open new type waveaudio alias capture", 0&, 0, 0) 'get ready
i = mciSendString("seek capture to start", 0&, 0, 0) 'Start at the beginning
i = mciSendString("set capture samplespersec 32000", 0&, 0, 0) 'quality
i = mciSendString("set capture bitspersample 8", 0&, 0, 0) '8 bit sound
i = mciSendString("set capture channels 1", 0&, 0, 0) 'mono
i = mciSendString("record capture", 0&, 0, 0) 'Start recording

End Sub


Sub waitaround()

Dim starttime As Long
starttime = Timer
progressbar1.Value = 0

Do While Timer < starttime + 1.5
If progressbar1.Value < 2000 Then
progressbar1.Value = progressbar1.Value + 1
End If
Loop

End Sub

Sub playsound()

i = mciSendString("play capture from 0", 0&, 0, 0)

End Sub

If any more code is needed, let me know

Lee

Tekman
09-07-2003, 02:15 PM
After reading through the archives, it seems that the timer is inherantly inaccurate.... Is there another method to ensure equal length wav files??


Lee

GavinO
09-07-2003, 02:51 PM
For time measured in milliseconds, the GetTickCount API call is useful.

DeX
09-07-2003, 03:49 PM
For time measured in milliseconds, the GetTickCount API call is useful.

Although timeGetTime will actually give you 1ms whereas GetTickCount won't.

Tekman
09-07-2003, 06:28 PM
Thanks for the input, I will give it a try

Lee

passel
09-07-2003, 06:34 PM
Since you are just recording letters of the alphabet for periods of 1 and
1/2 seconds each, the timer is probably sufficient. At worst, you are
talking an 1/18th of a second difference between recording lengths, and
on an NT system, it may only be 1/100th of a second off.
I'm sure you won't be able to tell, since I assume the letter itself will
have been fully enunciated before you reach the 1.5 seconds, and an
extra 1/18th of a second on some, will not be distinguishable from the
others.

Tekman
09-07-2003, 07:08 PM
You are right, the difference was probably not noticable to others, but it was bugging me. I used the timegettime API and the wav files range from .92 to .98 now. I guess I am writing this program as much for my benefit as for the kids.........I am practicing and learning all the time.

Here is the code I finally used


Option Explicit

Dim Counter As Integer
Private Declare Function timeGetTime Lib "winmm.dll" () As Long

Sub waitaround()

Dim StartTime As Long

progressbar1.Value = 0 ' reset progressbar
StartTime = timeGetTime ' get starting time

Do While timeGetTime < StartTime + 1000 ' loop for 1000ms

If progressbar1.Value < 2000 Then
progressbar1.Value = progressbar1.Value + 1 ' index progressbar
End If

Loop

End Sub


Thanks again for the input

Lee

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum