Option Explicit
Private DX_Main As New DirectX7
Private DX_Writer As DirectSound
Private DX_WriterBuffer As DirectSoundBuffer
Private WAVBuffer() As Byte
Private SamplesPerSec As Long
Private Channels As Byte
Private BitsPerSample As Integer
Private DataLength As Long
Private DataLengthTemp As Long
Private Match As Boolean
Private Sub UserControl_Resize()
UserControl.Width = Img_Interface.Width
UserControl.Height = Img_Interface.Height
End Sub
Public Sub InitReceiver()
If DX_WriterBuffer Is Nothing Then Call CreateBuffer
DX_WriterBuffer.Play DSBPLAY_LOOPING
End Sub
Private Function CreateBuffer() As String
On Error GoTo ErrorHandel:
Dim BufferDescription As DSBUFFERDESC
Dim WAVFormat As WAVEFORMATEX
Set DX_Writer = DX_Main.DirectSoundCreate("")
DX_Writer.SetCooperativeLevel UserControl.hWnd, DSSCL_PRIORITY
WAVFormat = SetWavFormat(SamplesPerSec, Channels, BitsPerSample)
BufferDescription.lBufferBytes = WAVFormat.lAvgBytesPerSec
BufferDescription.lFlags = DSBCAPS_CTRLPOSITIONNOTIFY Or DSBCAPS_GLOBALFOCUS Or DSBCAPS_GETCURRENTPOSITION2
Set DX_WriterBuffer = DX_Writer.CreateSoundBuffer(BufferDescription, WAVFormat)
Exit Function
ErrorHandel:
CreateBuffer = "Error Source: " & Err.Source & vbCrLf & "Error Number: " & Err.Number & vbCrLf & "Error Description: " & Err.Description
End Function
Private Function SetWavFormat(ByVal WSamplesPerSec As Long, ByVal WChannels As Byte, ByVal WBitsPerSample As Integer) As WAVEFORMATEX
SetWavFormat.nFormatTag = WAVE_FORMAT_PCM
SetWavFormat.nChannels = WChannels
SetWavFormat.lSamplesPerSec = WSamplesPerSec
SetWavFormat.nBitsPerSample = WBitsPerSample
SetWavFormat.nBlockAlign = WChannels * WBitsPerSample / 8
SetWavFormat.lAvgBytesPerSec = SetWavFormat.lSamplesPerSec * SetWavFormat.nBlockAlign
SetWavFormat.nSize = 0
End Function
Public Sub SetWavQuality(ByVal WSamplesPerSec As Long, ByVal WChannels As Byte, ByVal WBitsPerSample As Integer)
SamplesPerSec = WSamplesPerSec
Channels = WChannels
BitsPerSample = WBitsPerSample
End Sub
Public Sub DestroyObjects()
Set DX_Main = Nothing
Set DX_Writer = Nothing
Set DX_WriterBuffer = Nothing
End Sub
Public Sub StopStreaming()
DX_WriterBuffer.Stop
End Sub
Private Sub Receiver_DataArrival(ByVal bytesTotal As Long)
On Error Resume Next
Receiver.GetData WAVBuffer, vbArray + vbByte, bytesTotal
DX_WriterBuffer.WriteBuffer 0, UBound(WAVBuffer), WAVBuffer(0), DSBLOCK_DEFAULT
'DataLength = bytesTotal
End Sub
'Private Sub Checker_Timer()
' If DataLengthTemp = DataLength Then
' StopStreaming
' Else
' DX_WriterBuffer.Play DSBPLAY_LOOPING
' DataLengthTemp = DataLength
' End If
'End Sub
Private Sub Receiver_Close()
StopStreaming
End Sub
Public Sub SetNetworkParameters(ByVal Protocol As Byte, ByVal LocalPort As Long)
Receiver.Close
Receiver.Protocol = Protocol
Receiver.LocalPort = LocalPort
Receiver.Bind LocalPort
End Sub
I added the directx to my project and added the usercontrole to the main form but still getting "Sub not definded" when im calling the SetNetworkParameters
here is my form code
Code:
Private Sub Form_Load()
Call Receiver.SetNetworkParameters(1, 19841)
Call Receiver.SetWavQuality(8000, 1, 8)
Call Receiver.InitReceiver
End Sub
Please help
Last edited by Milad87; Jun 1st, 2008 at 05:49 AM.
Is Receiver the name of the usercontrol that you've included to the form? I find it confusing you're using Receiver as the name of the usercontrol and as the name of a component within the usercontrol.
Re: [RESOLVED]Calling a function from usercontrole
When you add the usercontrol to the form, it'll get a unique new name (since there can be many of them). Just rename it like you'd do with any other control.