i am trying make software which plays different frequency sound.My problem is that out of three sound first two plays very fast and third plays for longer time.The code for the program is below
can anybody help?
HTML Code:
Option Explicit
'
' DirectSound access
Dim DX As DirectX8
Dim DS As DirectSound8
Dim dsToneBuffer As DirectSoundSecondaryBuffer8
Dim desc As DSBUFFERDESC
'
' Global variables
Const PI = 3.14159265358979
Const SRATE = 44100             ' Sampling Rate
Const DUR = 5                ' Tone duration
Const FREQUENCY = 240              ' Tone frequency
Dim sbuf(0 To DUR * SRATE) As Integer

Public Sub Command1_Click()
Dim sc(3) As Double
Static J As Integer
Dim FREQ As Integer


sc(1) = 1
sc(2) = 2
sc(3) = 2.5
For J = 1 To 3
FREQ = FREQUENCY * sc(J)
Call createtone(FREQ, DUR)
' play the tone
dsToneBuffer.Play DSBPLAY_DEFAULT
Next J

End Sub

Private Sub Form_Load()
'
' initialise DirectSound
Set DX = New DirectX8
Set DS = DX.DirectSoundCreate("")
DS.SetCooperativeLevel Me.hWnd, DSSCL_NORMAL
'
' create a buffer
desc.fxFormat.nFormatTag = WAVE_FORMAT_PCM
desc.fxFormat.nSize = 0
desc.fxFormat.lExtra = 0
desc.fxFormat.nChannels = 1
desc.fxFormat.lSamplesPerSec = SRATE
desc.fxFormat.nBitsPerSample = 16
desc.fxFormat.nBlockAlign = 2
desc.fxFormat.lAvgBytesPerSec = 2 * SRATE
desc.lFlags = 0
desc.lBufferBytes = 2 * DUR * SRATE
Set dsToneBuffer = DS.CreateSoundBuffer(desc)
End Sub
Public Sub createtone(FREQ As Integer, DUR As Integer)

' create a tone
Dim I
For I = 0 To DUR * SRATE
    sbuf(I) = 10000 * Sin(2 * PI * FREQ * I / SRATE)
Next I
'
' copy tone to buffer
dsToneBuffer.WriteBuffer 0, 2 * DUR * SRATE, sbuf(0), DSBLOCK_DEFAULT


'
End Sub