Results 1 to 12 of 12

Thread: Need help converting a c# to VB.NET

  1. #1

    Thread Starter
    New Member Roast247's Avatar
    Join Date
    Jan 2021
    Posts
    15

    Need help converting a c# to VB.NET

    Hi, I found kind of what I'm looking for which is a voice chat, but the problem is that it isn't in VB.NET. If someone could please help me convert either my own project to c# or convert the project that I found to VB.NET that would be much appreciated! Or if someone could guide me to creating a voice chat in VB.NET that would be even more cool and probably easier if someone knows how to do so.

    My project in VB.NET is at https://github.com/roast247/IRC-Chat...Code-Version-2

    The Voice Chat Project in c# I found TCP Streamer.zip

    I just want to combine the voice chat and my text chat. Please don't send me on a wild goose chase as I've been on one for hours. Just please help

    Converted Voice Chat Project from c# to VB.NET but this has 28 errors that I need help with streamer.zip
    Last edited by Roast247; Jan 19th, 2021 at 04:09 AM.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    106,288

    Re: Need help converting a c# to VB.NET

    In your previous thread you were recommended to use a code converter and even directed to one specifically and yet you have apparently made no effort to do that, instead asking someone else to do it for you. That is after having to be told multiple times in your previous thread to search for information on your problem first before expecting someone else to provide everything. Being new to programming and not understanding things is one thing, but not making any effort on your own behalf is quite another. We're happy to help you do it but doing it for you is something else. If you're not prepared to do what you can for yourself first then you'll find that people will tend to lose interest fairly quickly. If we see that you are making an effort, we'll tend to be more likely to make an effort for you too. If you don't try then you haven't failed and if you haven't failed then you don't even know whether you actually need our help. You apparently didn't need it to find some code but you wouldn't have done that if you hadn't been prompted to several times. Do what you can and then ask for help with what you can't.

  3. #3

    Thread Starter
    New Member Roast247's Avatar
    Join Date
    Jan 2021
    Posts
    15

    Re: Need help converting a c# to VB.NET

    Quote Originally Posted by jmcilhinney View Post
    In your previous thread you were recommended to use a code converter and even directed to one specifically and yet you have apparently made no effort to do that, instead asking someone else to do it for you. That is after having to be told multiple times in your previous thread to search for information on your problem first before expecting someone else to provide everything. Being new to programming and not understanding things is one thing, but not making any effort on your own behalf is quite another. We're happy to help you do it but doing it for you is something else. If you're not prepared to do what you can for yourself first then you'll find that people will tend to lose interest fairly quickly. If we see that you are making an effort, we'll tend to be more likely to make an effort for you too. If you don't try then you haven't failed and if you haven't failed then you don't even know whether you actually need our help. You apparently didn't need it to find some code but you wouldn't have done that if you hadn't been prompted to several times. Do what you can and then ask for help with what you can't.
    I just converted the whole entire project. I have 28 errors that I need help getting rid of though, can you at least help with that? I updated the file in this main thread right here streamer.zip
    Last edited by Roast247; Jan 19th, 2021 at 04:20 AM.

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    33,213

    Re: Need help converting a c# to VB.NET

    What are the errors? What's the code look like that's causing the errors? What did the original source code look like before it was converted (ie, what does the original C# code look like?)

    Here's the deal: We are all volunteers. None of us are getting paid for this. We are here on our own time for most part. We will help you, but you have to do your part to help us help you. Have you even researched the errors you're getting? Generally there's an error code or something you can look up. A code, a message, something. Lots of people have converted stuff between VB and C#... so odds are, if you simply search for it, you'll find it.

    Also, don't just throw us an entire project, and say "it broke, fix please" ... yeah that doesn't work around here. What does work is a piece of code between [code][/code] or [highlight][/highlight] tags with an explanation of what it is supposed to do, what it really does, error messages, and what the expected outcome is... and with the problem line noted. You don't walk into the doc's office and say "it hurts" do you? No, you say "I was skating, and fell while doing a trick and broke my arm" ... details, details, details.

    -tg
    Last edited by techgnome; Jan 19th, 2021 at 09:07 AM.
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    New Member Roast247's Avatar
    Join Date
    Jan 2021
    Posts
    15

    Re: Need help converting a c# to VB.NET

    Quote Originally Posted by techgnome View Post
    What are the errors? What's the code look like that's causing the errors? What did the original source code look like before it was converted (ie, what does the original C# code look like?)

    Here's the deal: We are all volunteers. None of us are getting paid for this. We are here on our own time for most part. We will help you, but you have to do your part to help us help you. Have you even researched the errors you're getting? Generally there's an error code or something you can look up. A code, a message, something. Lots of people have converted stuff between VB and C#... so odds are, if you simply search for it, you'll find it.

    Also, don't just throw us an entire project, and say "it broke, fix please" ... yeah that doesn't work around here. What does work is a piece of code between [code][/code] or [highlight][/highlight] tags with an explanation of what it is supposed to do, what it really does, error messages, and what the expected outcome is... and with the problem line noted. You don't walk into the doc's office and say "it hurts" do you? No, you say "I was skating, and fell while doing a trick and broke my arm" ... details, details, details.

    -tg
    Sorry that I dont post much detail. anyways, the errors i am getting are


    Error BC30002 Type 'WinSound.Recorder' is not defined. TCPStreamer
    Error BC30002 Type 'WinSound.Recorder' is not defined. TCPStreamer
    Error BC30002 Type 'WinSound.Player' is not defined. TCPStreamer
    Error BC30002 Type 'WinSound.Player' is not defined. TCPStreamer
    Error BC30057 Too many arguments to 'Public Shared Function MulawToLinear(ulaw As Integer) As Integer'. TCPStreamer
    Error BC30311 Value of type 'Byte()' cannot be converted to 'Integer'. TCPStreamer
    Error BC30057 Too many arguments to 'Public Shared Function MulawToLinear(ulaw As Integer) As Integer'. TCPStreamer
    Error BC30311 Value of type 'Byte()' cannot be converted to 'Integer'. TCPStreamer
    Error BC30002 Type 'WinSound.Player' is not defined. TCPStreamer
    Error BC30002 Type 'WinSound.Player' is not defined. TCPStreamer
    Error BC30057 Too many arguments to 'Public Shared Function MulawToLinear(ulaw As Integer) As Integer'. TCPStreamer
    Error BC30311 Value of type 'Byte()' cannot be converted to 'Integer'. TCPStreamer
    Error BC30002 Type 'WinSound.Recorder' is not defined. TCPStreamer
    Error BC30002 Type 'WinSound.Recorder' is not defined. TCPStreamer
    Error BC30456 'Properties' is not a member of 'TCPStreamer'. TCPStreamer
    Error BC30456 'Properties' is not a member of 'TCPStreamer'. TCPStreamer
    Error BC30456 'Properties' is not a member of 'TCPStreamer'. TCPStreamer
    Error BC30456 'Properties' is not a member of 'TCPStreamer'. TCPStreamer

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,736

    Re: Need help converting a c# to VB.NET

    If you doubleclick on the Error BC30311 Value of type 'Byte()' cannot be converted to 'Integer'. TCPStreamer error, what does the code look like on the line it takes you to?

  7. #7

    Thread Starter
    New Member Roast247's Avatar
    Join Date
    Jan 2021
    Posts
    15

    Re: Need help converting a c# to VB.NET

    Quote Originally Posted by .paul. View Post
    If you doubleclick on the Error BC30311 Value of type 'Byte()' cannot be converted to 'Integer'. TCPStreamer error, what does the code look like on the line it takes you to?
    it brings me to this line
    Code:
    Dim linearBytes() As Byte = WinSound.Utils.MuLawToLinear(rtp.Data, BitsPerSample, Channels)
    The whole entire code for the mainform.vb split up in different sections (top,middle, and bottom)

    Code:
    Imports System
    Imports System.Collections.Generic
    Imports System.ComponentModel
    Imports System.Data
    Imports System.Drawing
    Imports System.Linq
    Imports System.Text
    Imports System.Windows.Forms
    Imports System.Xml.Serialization
    Imports System.IO
    Imports System.Collections
    
    Namespace TCPStreamer
    	Partial Public Class FormMain
    		Inherits Form
    
    		''' <summary>
    		''' Konstruktor
    		''' </summary>
    		Public Sub New()
    			InitializeComponent()
    			Init()
    		End Sub
    
    		'Attribute
    		Private m_Client As NF.TCPClient
    		Private m_Server As NF.TCPServer
    		Private m_Config As New Configuration()
    		Private m_ConfigFileName As String = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "config.xml")
    		Private m_SoundBufferCount As Integer = 8
    		Private m_PrototolClient As New WinSound.Protocol(WinSound.ProtocolTypes.LH, Encoding.Default)
    		Private m_DictionaryServerDatas As New Dictionary(Of NF.ServerThread, ServerThreadData)()
    		Private m_Recorder_Client As WinSound.Recorder
    		Private m_Recorder_Server As WinSound.Recorder
    		Private m_PlayerClient As WinSound.Player
    		Private m_RecorderFactor As UInteger = 4
    		Private m_JitterBufferClientRecording As WinSound.JitterBuffer
    		Private m_JitterBufferClientPlaying As WinSound.JitterBuffer
    		Private m_JitterBufferServerRecording As WinSound.JitterBuffer
    		Private m_FileHeader As New WinSound.WaveFileHeader()
    		Private m_IsFormMain As Boolean = True
    		Private m_SequenceNumber As Long = 4596
    		Private m_TimeStamp As Long = 0
    		Private m_Version As Integer = 2
    		Private m_Padding As Boolean = False
    		Private m_Extension As Boolean = False
    		Private m_CSRCCount As Integer = 0
    		Private m_Marker As Boolean = False
    		Private m_PayloadType As Integer = 0
    		Private m_SourceId As UInteger = 0
    		Private m_TimerProgressBarFile As New System.Windows.Forms.Timer()
    		Private m_TimerProgressBarPlayingClient As New System.Windows.Forms.Timer()
    		Private m_TimerMixed As WinSound.EventTimer = Nothing
    		Private m_FilePayloadBuffer() As Byte
    		Private m_RTPPartsLength As Integer = 0
    		Private m_Milliseconds As UInteger = 20
    		Private m_TimerDrawProgressBar As System.Windows.Forms.Timer
    		Private LockerDictionary As New Object()
    		Public Shared DictionaryMixed As New Dictionary(Of Object, Queue(Of List(Of Byte)))()
    		Private m_Encoding As Encoding = Encoding.GetEncoding(1252)
    		Private Const RecordingJitterBufferCount As Integer = 8
    
    		''' <summary>
    		''' Init
    		''' </summary>
    		Private Sub Init()
    			Try
    				CreateHandle()
    				InitComboboxes()
    				LoadConfig()
    				InitJitterBufferClientRecording()
    				InitJitterBufferClientPlaying()
    				InitJitterBufferServerRecording()
    				InitTimerShowProgressBarPlayingClient()
    				InitProtocolClient()
    			Catch ex As Exception
    				ShowError(LabelClient, ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' InitProtocolClient
    		''' </summary>
    		Private Sub InitProtocolClient()
    			If m_PrototolClient IsNot Nothing Then
    				AddHandler m_PrototolClient.DataComplete, AddressOf OnProtocolClient_DataComplete
    			End If
    		End Sub
    		''' <summary>
    		''' FillRTPBufferWithPayloadData
    		''' </summary>
    		''' <param name="header"></param>
    		Private Sub FillRTPBufferWithPayloadData(ByVal header As WinSound.WaveFileHeader)
    			m_RTPPartsLength = WinSound.Utils.GetBytesPerInterval(header.SamplesPerSecond, header.BitsPerSample, header.Channels)
    			m_FilePayloadBuffer = header.Payload
    		End Sub
    		''' <summary>
    		''' InitTimerShowProgressBarPlayingClient
    		''' </summary>
    		Private Sub InitTimerShowProgressBarPlayingClient()
    			m_TimerProgressBarPlayingClient = New System.Windows.Forms.Timer()
    			m_TimerProgressBarPlayingClient.Interval = 60
    			AddHandler m_TimerProgressBarPlayingClient.Tick, AddressOf OnTimerProgressPlayingClient
    		End Sub
    		''' <summary>
    		''' OnTimerProgressPlayingClient
    		''' </summary>
    		''' <param name="obj"></param>
    		''' <param name="e"></param>
    		Private Sub OnTimerProgressPlayingClient(ByVal obj As Object, ByVal e As EventArgs)
    			Try
    				If m_PlayerClient IsNot Nothing Then
    					ProgressBarPlayingClient.Value = Math.Min(m_JitterBufferClientPlaying.Length, ProgressBarPlayingClient.Maximum)
    				End If
    			Catch ex As Exception
    				Console.WriteLine(String.Format("FormMain.cs | OnTimerProgressPlayingClient() | {0}", ex.Message))
    				m_TimerProgressBarPlayingClient.Stop()
    			End Try
    		End Sub
    		''' <summary>
    		''' OnTimerSendMixedDataToAllClients
    		''' </summary>
    		''' <param name="obj"></param>
    		''' <param name="e"></param>
    		Private Sub OnTimerSendMixedDataToAllClients()
    			Try
    				'Liste mit allen Sprachdaten (eigene + Clients)
    				Dim dic As New Dictionary(Of Object, List(Of Byte))()
    				Dim listlist As New List(Of List(Of Byte))()
    				Dim copy As New Dictionary(Of Object, Queue(Of List(Of Byte)))(FormMain.DictionaryMixed)
    				If True Then
    					Dim q As Queue(Of List(Of Byte)) = Nothing
    					For Each obj As Object In copy.Keys
    
    						q = copy(obj)
    
    						'Wenn Daten vorhanden
    						If q.Count > 0 Then
    							dic(obj) = q.Dequeue()
    							listlist.Add(dic(obj))
    						End If
    					Next obj
    				End If
    
    				If listlist.Count > 0 Then
    					'Gemischte Sprachdaten
    					Dim mixedBytes() As Byte = WinSound.Mixer.MixBytes(listlist, m_Config.BitsPerSampleServer).ToArray()
    					Dim listMixed As New List(Of Byte)(mixedBytes)
    
    					'Für alle Clients
    					For Each client As NF.ServerThread In m_Server.Clients
    						'Wenn nicht stumm
    						If client.IsMute = False Then
    							'Gemixte Sprache für Client
    							Dim mixedBytesClient() As Byte = mixedBytes
    
    							If dic.ContainsKey(client) Then
    								'Sprache des Clients ermitteln
    								Dim listClient As List(Of Byte) = dic(client)
    
    								'Sprache des Clients aus Mix subtrahieren
    								mixedBytesClient = WinSound.Mixer.SubsctractBytes_16Bit(listMixed, listClient).ToArray()
    							End If
    
    							'RTP Packet erstellen
    							Dim rtp As WinSound.RTPPacket = ToRTPPacket(mixedBytesClient, m_Config.BitsPerSampleServer, m_Config.ChannelsServer)
    							Dim rtpBytes() As Byte = rtp.ToBytes()
    
    							'Absenden
    							client.Send(m_PrototolClient.ToBytes(rtpBytes))
    						End If
    					Next client
    				End If
    
    			Catch ex As Exception
    				Console.WriteLine(String.Format("FormMain.cs | OnTimerSendMixedDataToAllClients() | {0}", ex.Message))
    				m_TimerProgressBarPlayingClient.Stop()
    			End Try
    		End Sub
    		''' <summary>
    		''' InitJitterBufferClientRecording
    		''' </summary>
    		Private Sub InitJitterBufferClientRecording()
    			'Wenn vorhanden
    			If m_JitterBufferClientRecording IsNot Nothing Then
    				RemoveHandler m_JitterBufferClientRecording.DataAvailable, AddressOf OnJitterBufferClientDataAvailableRecording
    			End If
    
    			'Neu erstellen
    			m_JitterBufferClientRecording = New WinSound.JitterBuffer(Nothing, RecordingJitterBufferCount, 20)
    			AddHandler m_JitterBufferClientRecording.DataAvailable, AddressOf OnJitterBufferClientDataAvailableRecording
    		End Sub
    		''' <summary>
    		''' InitJitterBufferClientPlaying
    		''' </summary>
    		Private Sub InitJitterBufferClientPlaying()
    			'Wenn vorhanden
    			If m_JitterBufferClientPlaying IsNot Nothing Then
    				RemoveHandler m_JitterBufferClientPlaying.DataAvailable, AddressOf OnJitterBufferClientDataAvailablePlaying
    			End If
    
    			'Neu erstellen
    			m_JitterBufferClientPlaying = New WinSound.JitterBuffer(Nothing, m_Config.JitterBufferCountClient, 20)
    			AddHandler m_JitterBufferClientPlaying.DataAvailable, AddressOf OnJitterBufferClientDataAvailablePlaying
    		End Sub
    		''' <summary>
    		''' InitJitterBuffer
    		''' </summary>
    		Private Sub InitJitterBufferServerRecording()
    			'Wenn vorhanden
    			If m_JitterBufferServerRecording IsNot Nothing Then
    				RemoveHandler m_JitterBufferServerRecording.DataAvailable, AddressOf OnJitterBufferServerDataAvailable
    			End If
    
    			'Neu erstellen
    			m_JitterBufferServerRecording = New WinSound.JitterBuffer(Nothing, RecordingJitterBufferCount, 20)
    			AddHandler m_JitterBufferServerRecording.DataAvailable, AddressOf OnJitterBufferServerDataAvailable
    		End Sub
    		''' <summary>
    		''' UseJitterBuffer
    		''' </summary>
    		Private ReadOnly Property UseJitterBufferServer() As Boolean
    			Get
    				Return m_Config.JitterBufferCountServer >= 2
    			End Get
    		End Property
    		''' <summary>
    		''' UseJitterBuffer
    		''' </summary>
    		Private ReadOnly Property UseJitterBufferClientRecording() As Boolean
    			Get
    				Return m_Config.UseJitterBufferClientRecording
    			End Get
    		End Property
    		''' <summary>
    		''' UseJitterBufferServerRecording
    		''' </summary>
    		Private ReadOnly Property UseJitterBufferServerRecording() As Boolean
    			Get
    				Return m_Config.UseJitterBufferServerRecording
    			End Get
    		End Property
    		''' <summary>
    		''' StartRecordingFromSounddevice_Client
    		''' </summary>
    		Private Sub StartRecordingFromSounddevice_Client()
    			Try
    				If IsRecorderFromSounddeviceStarted_Client = False Then
    					'Buffer Grösse berechnen
    					Dim bufferSize As Integer = 0
    					If UseJitterBufferClientRecording Then
    						bufferSize = WinSound.Utils.GetBytesPerInterval(CUInt(m_Config.SamplesPerSecondClient), m_Config.BitsPerSampleClient, m_Config.ChannelsClient) * CInt(m_RecorderFactor)
    					Else
    						bufferSize = WinSound.Utils.GetBytesPerInterval(CUInt(m_Config.SamplesPerSecondClient), m_Config.BitsPerSampleClient, m_Config.ChannelsClient)
    					End If
    
    					'Wenn Buffer korrekt
    					If bufferSize > 0 Then
    						'Recorder erstellen
    						m_Recorder_Client = New WinSound.Recorder()
    
    						'Events hinzufügen
    						AddHandler m_Recorder_Client.DataRecorded, AddressOf OnDataReceivedFromSoundcard_Client
    						AddHandler m_Recorder_Client.RecordingStopped, AddressOf OnRecordingStopped_Client
    
    						'Recorder starten
    						If m_Recorder_Client.Start(m_Config.SoundInputDeviceNameClient, m_Config.SamplesPerSecondClient, m_Config.BitsPerSampleClient, m_Config.ChannelsClient, m_SoundBufferCount, bufferSize) Then
    							'Anzeigen
    							ShowStreamingFromSounddeviceStarted_Client()
    
    							'Wenn JitterBuffer
    							If UseJitterBufferClientRecording Then
    								m_JitterBufferClientRecording.Start()
    							End If
    						End If
    					End If
    
    				End If
    			Catch ex As Exception
    				ShowError(LabelClient, ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' StartRecordingFromSounddevice_Server
    		''' </summary>
    		Private Sub StartRecordingFromSounddevice_Server()
    			Try
    				If IsRecorderFromSounddeviceStarted_Server = False Then
    					'Buffer Grösse berechnen
    					Dim bufferSize As Integer = 0
    					If UseJitterBufferServerRecording Then
    						bufferSize = WinSound.Utils.GetBytesPerInterval(CUInt(m_Config.SamplesPerSecondServer), m_Config.BitsPerSampleServer, m_Config.ChannelsServer) * CInt(m_RecorderFactor)
    					Else
    						bufferSize = WinSound.Utils.GetBytesPerInterval(CUInt(m_Config.SamplesPerSecondServer), m_Config.BitsPerSampleServer, m_Config.ChannelsServer)
    					End If
    
    					'Wenn Buffer korrekt
    					If bufferSize > 0 Then
    						'Recorder erstellen
    						m_Recorder_Server = New WinSound.Recorder()
    
    						'Events hinzufügen
    						AddHandler m_Recorder_Server.DataRecorded, AddressOf OnDataReceivedFromSoundcard_Server
    						AddHandler m_Recorder_Server.RecordingStopped, AddressOf OnRecordingStopped_Server
    
    						'Recorder starten
    						If m_Recorder_Server.Start(m_Config.SoundInputDeviceNameServer, m_Config.SamplesPerSecondServer, m_Config.BitsPerSampleServer, m_Config.ChannelsServer, m_SoundBufferCount, bufferSize) Then
    							'Anzeigen
    							ShowStreamingFromSounddeviceStarted_Server()
    
    							'Zu Mixer hinzufügen
    							FormMain.DictionaryMixed(Me) = New Queue(Of List(Of Byte))()
    
    							'JitterBuffer starten
    							m_JitterBufferServerRecording.Start()
    						End If
    					End If
    
    				End If
    			Catch ex As Exception
    				ShowError(LabelClient, ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' StopRecordingFromSounddevice_Client
    		''' </summary>
    		Private Sub StopRecordingFromSounddevice_Client()
    			Try
    				If IsRecorderFromSounddeviceStarted_Client Then
    					'Stoppen
    					m_Recorder_Client.Stop()
    
    					'Events entfernen
    					RemoveHandler m_Recorder_Client.DataRecorded, AddressOf OnDataReceivedFromSoundcard_Client
    					RemoveHandler m_Recorder_Client.RecordingStopped, AddressOf OnRecordingStopped_Client
    					m_Recorder_Client = Nothing
    
    					'Wenn JitterBuffer
    					If UseJitterBufferClientRecording Then
    						m_JitterBufferClientRecording.Stop()
    					End If
    
    					'Anzeigen
    					ShowStreamingFromSounddeviceStopped_Client()
    				End If
    			Catch ex As Exception
    				ShowError(LabelClient, ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' StopRecordingFromSounddevice_Server
    		''' </summary>
    		Private Sub StopRecordingFromSounddevice_Server()
    			Try
    				If IsRecorderFromSounddeviceStarted_Server Then
    					'Stoppen
    					m_Recorder_Server.Stop()
    
    					'Events entfernen
    					RemoveHandler m_Recorder_Server.DataRecorded, AddressOf OnDataReceivedFromSoundcard_Server
    					RemoveHandler m_Recorder_Server.RecordingStopped, AddressOf OnRecordingStopped_Server
    					m_Recorder_Server = Nothing
    
    					'JitterBuffer beenden
    					m_JitterBufferServerRecording.Stop()
    
    					'Anzeigen
    					ShowStreamingFromSounddeviceStopped_Server()
    				End If
    			Catch ex As Exception
    				ShowError(LabelClient, ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' OnRecordingStopped
    		''' </summary>
    		Private Sub OnRecordingStopped_Client()
    			Try
    				Me.Invoke(New MethodInvoker(Sub()
    					'Anzeigen
    					ShowStreamingFromSounddeviceStopped_Client()
    
    				End Sub))
    			Catch ex As Exception
    				ShowError(LabelClient, ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' OnRecordingStopped_Server
    		''' </summary>
    		Private Sub OnRecordingStopped_Server()
    			Try
    				Me.Invoke(New MethodInvoker(Sub()
    					'Anzeigen
    					ShowStreamingFromSounddeviceStopped_Server()
    
    				End Sub))
    			Catch ex As Exception
    				ShowError(LabelClient, ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' OnDataReceivedFromSoundcard_Client
    		''' </summary>
    		''' <param name="linearData"></param>
    		Private Sub OnDataReceivedFromSoundcard_Client(ByVal data() As Byte)
    			Try
    				SyncLock Me
    					If IsClientConnected Then
    						'Wenn gewünscht
    						If m_Config.ClientNoSpeakAll = False Then
    							'Sounddaten in kleinere Einzelteile zerlegen
    							Dim bytesPerInterval As Integer = WinSound.Utils.GetBytesPerInterval(CUInt(m_Config.SamplesPerSecondClient), m_Config.BitsPerSampleClient, m_Config.ChannelsClient)
    							Dim count As Integer = data.Length \ bytesPerInterval
    							Dim currentPos As Integer = 0
    							For i As Integer = 0 To count - 1
    								'Teilstück in RTP Packet umwandeln
    								Dim partBytes(bytesPerInterval - 1) As Byte
    								Array.Copy(data, currentPos, partBytes, 0, bytesPerInterval)
    								currentPos += bytesPerInterval
    								Dim rtp As WinSound.RTPPacket = ToRTPPacket(partBytes, m_Config.BitsPerSampleClient, m_Config.ChannelsClient)
    
    								'Wenn JitterBuffer
    								If UseJitterBufferClientRecording Then
    									'In Buffer legen
    									m_JitterBufferClientRecording.AddData(rtp)
    								Else
    									'Alles in RTP Packet umwandeln
    									Dim rtpBytes() As Byte = ToRTPData(data, m_Config.BitsPerSampleClient, m_Config.ChannelsClient)
    									'Absenden
    									m_Client.Send(m_PrototolClient.ToBytes(rtpBytes))
    								End If
    							Next i
    						End If
    					End If
    				End SyncLock
    			Catch ex As Exception
    				System.Diagnostics.Debug.WriteLine(ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' OnDataReceivedFromSoundcard_Server
    		''' </summary>
    		''' <param name="data"></param>
    		Private Sub OnDataReceivedFromSoundcard_Server(ByVal data() As Byte)
    			Try
    				SyncLock Me
    					If IsServerRunning Then
    						'Wenn Form noch aktiv
    						If m_IsFormMain Then
    							'Wenn gewünscht
    							If m_Config.ServerNoSpeakAll = False Then
    								'Sounddaten in kleinere Einzelteile zerlegen
    								Dim bytesPerInterval As Integer = WinSound.Utils.GetBytesPerInterval(CUInt(m_Config.SamplesPerSecondServer), m_Config.BitsPerSampleServer, m_Config.ChannelsServer)
    								Dim count As Integer = data.Length \ bytesPerInterval
    								Dim currentPos As Integer = 0
    								For i As Integer = 0 To count - 1
    									'Teilstück in RTP Packet umwandeln
    									Dim partBytes(bytesPerInterval - 1) As Byte
    									Array.Copy(data, currentPos, partBytes, 0, bytesPerInterval)
    									currentPos += bytesPerInterval
    
    									'Wenn Buffer nicht zu gross
    									Dim q As Queue(Of List(Of Byte)) = FormMain.DictionaryMixed(Me)
    									If q.Count < 10 Then
    										'Daten In Mixer legen
    										q.Enqueue(New List(Of Byte)(partBytes))
    									End If
    								Next i
    							End If
    						End If
    					End If
    				End SyncLock
    			Catch ex As Exception
    				System.Diagnostics.Debug.WriteLine(ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' OnJitterBufferClientDataAvailable
    		''' </summary>
    		''' <param name="rtp"></param>
    		Private Sub OnJitterBufferClientDataAvailableRecording(ByVal sender As Object, ByVal rtp As WinSound.RTPPacket)
    			Try
    				'Prüfen
    				If rtp IsNot Nothing AndAlso m_Client IsNot Nothing AndAlso rtp.Data IsNot Nothing AndAlso rtp.Data.Length > 0 Then
    					If IsClientConnected Then
    						If m_IsFormMain Then
    							'RTP Packet in Bytes umwandeln
    							Dim rtpBytes() As Byte = rtp.ToBytes()
    							'Absenden
    							m_Client.Send(m_PrototolClient.ToBytes(rtpBytes))
    						End If
    					End If
    				End If
    			Catch ex As Exception
    				Dim sf As New System.Diagnostics.StackFrame(True)
    				ShowError(LabelClient, String.Format("Exception: {0} StackTrace: {1}. FileName: {2} Method: {3} Line: {4}", ex.Message, ex.StackTrace, sf.GetFileName(), sf.GetMethod(), sf.GetFileLineNumber()))
    			End Try
    		End Sub
    		''' <summary>
    		''' OnJitterBufferClientDataAvailablePlaying
    		''' </summary>
    		''' <param name="sender"></param>
    		''' <param name="rtp"></param>
    		Private Sub OnJitterBufferClientDataAvailablePlaying(ByVal sender As Object, ByVal rtp As WinSound.RTPPacket)
    			Try
    				If m_PlayerClient IsNot Nothing Then
    					If m_PlayerClient.Opened Then
    						If m_IsFormMain Then
    							'Wenn nicht stumm
    							If m_Config.MuteClientPlaying = False Then
    								'Nach Linear umwandeln
    								Dim linearBytes() As Byte = WinSound.Utils.MuLawToLinear(rtp.Data, m_Config.BitsPerSampleClient, m_Config.ChannelsClient)
    								'Abspielen
    								m_PlayerClient.PlayData(linearBytes, False)
    							End If
    						End If
    					End If
    				End If
    			Catch ex As Exception
    				Dim sf As New System.Diagnostics.StackFrame(True)
    				ShowError(LabelClient, String.Format("Exception: {0} StackTrace: {1}. FileName: {2} Method: {3} Line: {4}", ex.Message, ex.StackTrace, sf.GetFileName(), sf.GetMethod(), sf.GetFileLineNumber()))
    			End Try
    		End Sub
    		''' <summary>
    		''' OnJitterBufferServerDataAvailable
    		''' </summary>
    		''' <param name="rtp"></param>
    		Private Sub OnJitterBufferServerDataAvailable(ByVal sender As Object, ByVal rtp As WinSound.RTPPacket)
    			Try
    				If IsServerRunning Then
    					If m_IsFormMain Then
    						'RTP Packet in Bytes umwandeln
    						Dim rtpBytes() As Byte = rtp.ToBytes()
    
    						'Für alle Clients
    						Dim list As New List(Of NF.ServerThread)(m_Server.Clients)
    						For Each client As NF.ServerThread In list
    							'Wenn nicht Mute
    							If client.IsMute = False Then
    								Try
    									'Absenden
    									client.Send(m_PrototolClient.ToBytes(rtpBytes))
    								Catch e1 As Exception
    									'Eintrag löschen
    									RemoveControlInAllFlowLayoutPanelsByServerThread(client)
    								End Try
    							End If
    						Next client
    					End If
    				End If
    			Catch ex As Exception
    				Dim sf As New System.Diagnostics.StackFrame(True)
    				ShowError(LabelServer, String.Format("Exception: {0} StackTrace: {1}. FileName: {2} Method: {3} Line: {4}", ex.Message, ex.StackTrace, sf.GetFileName(), sf.GetMethod(), sf.GetFileLineNumber()))
    			End Try
    		End Sub
    		''' <summary>
    		''' ToRTPData
    		''' </summary>
    		''' <param name="linearData"></param>
    		''' <param name="bitsPerSample"></param>
    		''' <param name="channels"></param>
    		''' <returns></returns>
    		Private Function ToRTPData(ByVal data() As Byte, ByVal bitsPerSample As Integer, ByVal channels As Integer) As Byte()
    			'Neues RTP Packet erstellen
    			Dim rtp As WinSound.RTPPacket = ToRTPPacket(data, bitsPerSample, channels)
    			'RTPHeader in Bytes erstellen
    			Dim rtpBytes() As Byte = rtp.ToBytes()
    			'Fertig
    			Return rtpBytes
    		End Function
    		''' <summary>
    		''' ToRTPPacket
    		''' </summary>
    		''' <param name="linearData"></param>
    		''' <param name="bitsPerSample"></param>
    		''' <param name="channels"></param>
    		''' <returns></returns>
    		Private Function ToRTPPacket(ByVal linearData() As Byte, ByVal bitsPerSample As Integer, ByVal channels As Integer) As WinSound.RTPPacket
    			'Daten Nach MuLaw umwandeln
    			Dim mulaws() As Byte = WinSound.Utils.LinearToMulaw(linearData, bitsPerSample, channels)
    
    			'Neues RTP Packet erstellen
    			Dim rtp As New WinSound.RTPPacket()
    
    			'Werte übernehmen
    			rtp.Data = mulaws
    			rtp.CSRCCount = m_CSRCCount
    			rtp.Extension = m_Extension
    			rtp.HeaderLength = WinSound.RTPPacket.MinHeaderLength
    			rtp.Marker = m_Marker
    			rtp.Padding = m_Padding
    			rtp.PayloadType = m_PayloadType
    			rtp.Version = m_Version
    			rtp.SourceId = m_SourceId
    
    			'RTP Header aktualisieren
    			Try
    				rtp.SequenceNumber = Convert.ToUInt16(m_SequenceNumber)
    				m_SequenceNumber += 1
    			Catch e1 As Exception
    				m_SequenceNumber = 0
    			End Try
    			Try
    				rtp.Timestamp = Convert.ToUInt32(m_TimeStamp)
    				m_TimeStamp += mulaws.Length
    			Catch e2 As Exception
    				m_TimeStamp = 0
    			End Try
    
    			'Fertig
    			Return rtp
    		End Function
    		''' <summary>
    		''' IsRecorderStarted
    		''' </summary>
    		Private ReadOnly Property IsRecorderFromSounddeviceStarted_Client() As Boolean
    			Get
    				If m_Recorder_Client IsNot Nothing Then
    					Return m_Recorder_Client.Started
    				End If
    				Return False
    			End Get
    		End Property
    		''' <summary>
    		''' IsRecorderFromSounddeviceStarted_Server
    		''' </summary>
    		Private ReadOnly Property IsRecorderFromSounddeviceStarted_Server() As Boolean
    			Get
    				If m_Recorder_Server IsNot Nothing Then
    					Return m_Recorder_Server.Started
    				End If
    				Return False
    			End Get
    		End Property
    		''' <summary>
    		''' InitComboboxes
    		''' </summary>
    		Private Sub InitComboboxes()
    			InitComboboxesClient()
    			InitComboboxesServer()
    		End Sub
    		''' <summary>
    		''' InitComboboxesClient
    		''' </summary>
    		Private Sub InitComboboxesClient()
    			ComboboxOutputSoundDeviceNameClient.Items.Clear()
    			ComboboxInputSoundDeviceNameClient.Items.Clear()
    			Dim playbackNames As List(Of String) = WinSound.WinSound.GetPlaybackNames()
    			Dim recordingNames As List(Of String) = WinSound.WinSound.GetRecordingNames()
    
    			'Output
    			ComboboxOutputSoundDeviceNameClient.Items.Add("None")
    'INSTANT VB NOTE: The variable name was renamed since Visual Basic does not handle local variables named the same as class members well:
    			For Each name_Conflict As String In playbackNames.Where(Function(x) x IsNot Nothing)
    				ComboboxOutputSoundDeviceNameClient.Items.Add(name_Conflict)
    			Next name_Conflict
    			'Input
    'INSTANT VB NOTE: The variable name was renamed since Visual Basic does not handle local variables named the same as class members well:
    			For Each name_Conflict As String In recordingNames.Where(Function(x) x IsNot Nothing)
    				ComboboxInputSoundDeviceNameClient.Items.Add(name_Conflict)
    			Next name_Conflict
    
    			'Output
    			If ComboboxOutputSoundDeviceNameClient.Items.Count > 0 Then
    				ComboboxOutputSoundDeviceNameClient.SelectedIndex = 0
    			End If
    			'Input
    			If ComboboxInputSoundDeviceNameClient.Items.Count > 0 Then
    				ComboboxInputSoundDeviceNameClient.SelectedIndex = 0
    			End If
    		End Sub

  8. #8

    Thread Starter
    New Member Roast247's Avatar
    Join Date
    Jan 2021
    Posts
    15

    Re: Need help converting a c# to VB.NET

    Quote Originally Posted by .paul. View Post
    If you doubleclick on the Error BC30311 Value of type 'Byte()' cannot be converted to 'Integer'. TCPStreamer error, what does the code look like on the line it takes you to?
    middle part of the code

    Code:
    		''' <summary>
    		''' InitComboboxesServer
    		''' </summary>
    		Private Sub InitComboboxesServer()
    			ComboboxOutputSoundDeviceNameServer.Items.Clear()
    			ComboboxInputSoundDeviceNameServer.Items.Clear()
    			Dim playbackNames As List(Of String) = WinSound.WinSound.GetPlaybackNames()
    			Dim recordingNames As List(Of String) = WinSound.WinSound.GetRecordingNames()
    
    			'Output
    'INSTANT VB NOTE: The variable name was renamed since Visual Basic does not handle local variables named the same as class members well:
    			For Each name_Conflict As String In playbackNames.Where(Function(x) x IsNot Nothing)
    				ComboboxOutputSoundDeviceNameServer.Items.Add(name_Conflict)
    			Next name_Conflict
    			'Input
    'INSTANT VB NOTE: The variable name was renamed since Visual Basic does not handle local variables named the same as class members well:
    			For Each name_Conflict As String In recordingNames.Where(Function(x) x IsNot Nothing)
    				ComboboxInputSoundDeviceNameServer.Items.Add(name_Conflict)
    			Next name_Conflict
    
    			'Output
    			If ComboboxOutputSoundDeviceNameServer.Items.Count > 0 Then
    				ComboboxOutputSoundDeviceNameServer.SelectedIndex = 0
    			End If
    			'Input
    			If ComboboxInputSoundDeviceNameServer.Items.Count > 0 Then
    				ComboboxInputSoundDeviceNameServer.SelectedIndex = 0
    			End If
    		End Sub
    
    		''' <summary>
    		''' ConnectClient
    		''' </summary>
    		Private Sub ConnectClient()
    			Try
    				If IsClientConnected = False Then
    					'Wenn Eingabe vorhanden
    					If m_Config.IpAddressClient.Length > 0 AndAlso m_Config.PortClient > 0 Then
    						m_Client = New NF.TCPClient(m_Config.IpAddressClient, m_Config.PortClient)
    						AddHandler m_Client.ClientConnected, AddressOf OnClientConnected
    						AddHandler m_Client.ClientDisconnected, AddressOf OnClientDisconnected
    						AddHandler m_Client.ExceptionAppeared, AddressOf OnClientExceptionAppeared
    						AddHandler m_Client.DataReceived, AddressOf OnClientDataReceived
    						m_Client.Connect()
    					End If
    				End If
    			Catch ex As Exception
    				m_Client = Nothing
    				ShowError(LabelClient, ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' DisconnectClient
    		''' </summary>
    		Private Sub DisconnectClient()
    			Try
    				'Aufnahme beenden
    				StopRecordingFromSounddevice_Client()
    
    				If m_Client IsNot Nothing Then
    					'Client beenden
    					m_Client.Disconnect()
    					RemoveHandler m_Client.ClientConnected, AddressOf OnClientConnected
    					RemoveHandler m_Client.ClientDisconnected, AddressOf OnClientDisconnected
    					RemoveHandler m_Client.ExceptionAppeared, AddressOf OnClientExceptionAppeared
    					RemoveHandler m_Client.DataReceived, AddressOf OnClientDataReceived
    					m_Client = Nothing
    				End If
    			Catch ex As Exception
    				ShowError(LabelClient, ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' StartServer
    		''' </summary>
    		Private Sub StartServer()
    			Try
    				If IsServerRunning = False Then
    					If m_Config.IPAddressServer.Length > 0 AndAlso m_Config.PortServer > 0 Then
    						m_Server = New NF.TCPServer()
    						AddHandler m_Server.ClientConnected, AddressOf OnServerClientConnected
    						AddHandler m_Server.ClientDisconnected, AddressOf OnServerClientDisconnected
    						AddHandler m_Server.DataReceived, AddressOf OnServerDataReceived
    						m_Server.Start(m_Config.IPAddressServer, m_Config.PortServer)
    
    						'Je nach Server Status
    						If m_Server.State = NF.TCPServer.ListenerState.Started Then
    							ShowServerStarted()
    						Else
    							ShowServerStopped()
    						End If
    					End If
    				End If
    			Catch ex As Exception
    				ShowError(LabelServer, ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' StopServer
    		''' </summary>
    		Private Sub StopServer()
    			Try
    				If IsServerRunning = True Then
    
    					'Player beenden
    					DeleteAllServerThreadDatas()
    
    					'Server beenden
    					m_Server.Stop()
    					RemoveHandler m_Server.ClientConnected, AddressOf OnServerClientConnected
    					RemoveHandler m_Server.ClientDisconnected, AddressOf OnServerClientDisconnected
    					RemoveHandler m_Server.DataReceived, AddressOf OnServerDataReceived
    				End If
    
    				'Je nach Server Status
    				If m_Server IsNot Nothing Then
    					If m_Server.State = NF.TCPServer.ListenerState.Started Then
    						ShowServerStarted()
    					Else
    						ShowServerStopped()
    					End If
    				End If
    
    				'Fertig
    				m_Server = Nothing
    			Catch ex As Exception
    				ShowError(LabelServer, ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' OnClientConnected
    		''' </summary>
    		''' <param name="client"></param>
    		''' <param name="info"></param>
    		Private Sub OnClientConnected(ByVal client As NF.TCPClient, ByVal info As String)
    			ShowMessage(LabelClient, String.Format("Client connected {0}", ""))
    			ShowClientConnected()
    		End Sub
    		''' <summary>
    		''' OnClientDisconnected
    		''' </summary>
    		''' <param name="client"></param>
    		''' <param name="info"></param>
    		Private Sub OnClientDisconnected(ByVal client As NF.TCPClient, ByVal info As String)
    			'Abspielen beenden
    			StopPlayingToSounddevice_Client()
    			'Streamen von Sounddevice beenden
    			StopRecordingFromSounddevice_Client()
    
    			If m_Client IsNot Nothing Then
    				RemoveHandler m_Client.ClientConnected, AddressOf OnClientConnected
    				RemoveHandler m_Client.ClientDisconnected, AddressOf OnClientDisconnected
    				RemoveHandler m_Client.ExceptionAppeared, AddressOf OnClientExceptionAppeared
    				RemoveHandler m_Client.DataReceived, AddressOf OnClientDataReceived
    				ShowMessage(LabelClient, String.Format("Client disconnected {0}", ""))
    			End If
    
    			ShowClientDisconnected()
    		End Sub
    		''' <summary>
    		''' OnClientExceptionAppeared
    		''' </summary>
    		''' <param name="client"></param>
    		''' <param name="ex"></param>
    		Private Sub OnClientExceptionAppeared(ByVal client As NF.TCPClient, ByVal ex As Exception)
    			DisconnectClient()
    			ShowError(LabelClient, ex.Message)
    		End Sub
    		''' <summary>
    		''' OnClientDataReceived
    		''' </summary>
    		''' <param name="client"></param>
    		''' <param name="bytes"></param>
    		Private Sub OnClientDataReceived(ByVal client As NF.TCPClient, ByVal bytes() As Byte)
    			Try
    				If m_PrototolClient IsNot Nothing Then
    					m_PrototolClient.Receive_LH(client, bytes)
    				End If
    			Catch ex As Exception
    				Console.WriteLine(ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' OnProtocolClient_DataComplete
    		''' </summary>
    		''' <param name="sender"></param>
    		''' <param name="data"></param>
    		Private Sub OnProtocolClient_DataComplete(ByVal sender As Object, ByVal data() As Byte)
    			Try
    				'Wenn der Player gestartet wurde
    				If m_PlayerClient IsNot Nothing Then
    					If m_PlayerClient.Opened Then
    						'RTP Header auslesen
    						Dim rtp As New WinSound.RTPPacket(data)
    
    						'Wenn Header korrekt
    						If rtp.Data IsNot Nothing Then
    							'In JitterBuffer hinzufügen
    							If m_JitterBufferClientPlaying IsNot Nothing Then
    								m_JitterBufferClientPlaying.AddData(rtp)
    							End If
    						End If
    					End If
    				Else
    					'Konfigurationsdaten erhalten
    					OnClientConfigReceived(sender, data)
    				End If
    			Catch ex As Exception
    				Console.WriteLine(ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' OnClientConfigReceived
    		''' </summary>
    		''' <param name="sender"></param>
    		''' <param name="data"></param>
    		Private Sub OnClientConfigReceived(ByVal sender As Object, ByVal data() As Byte)
    			Try
    				Dim msg As String = m_Encoding.GetString(data)
    				If msg.Length > 0 Then
    					'Parsen
    					Dim values() As String = msg.Split(":"c)
    					Dim cmd As String = values(0)
    
    					'Je nach Kommando
    					Select Case cmd.ToUpper()
    						Case "SAMPLESPERSECOND"
    							Dim samplePerSecond As Integer = Convert.ToInt32(values(1))
    							m_Config.SamplesPerSecondClient = samplePerSecond
    
    							Me.Invoke(New MethodInvoker(Sub()
    								'Aufnahme starten
    								StartPlayingToSounddevice_Client()
    								StartRecordingFromSounddevice_Client()
    							End Sub))
    					End Select
    				End If
    			Catch ex As Exception
    				Console.WriteLine(ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' OnServerClientConnected
    		''' </summary>
    		''' <param name="st"></param>
    		Private Sub OnServerClientConnected(ByVal st As NF.ServerThread)
    			Try
    				'ServerThread Daten erstellen
    				Dim data As New ServerThreadData()
    				'Initialisieren
    				data.Init(st, m_Config.SoundOutputDeviceNameServer, m_Config.SamplesPerSecondServer, m_Config.BitsPerSampleServer, m_Config.ChannelsServer, m_SoundBufferCount, m_Config.JitterBufferCountServer, m_Milliseconds)
    				'Hinzufügen
    				m_DictionaryServerDatas(st) = data
    				'Zu FlowLayoutPanels hinzufügen
    				AddServerClientToFlowLayoutPanel_ServerClient(st)
    				AddServerClientToFlowLayoutPanel_ServerProgressBars(data)
    				AddServerClientToFlowLayoutPanel_ServerListenButtons(data)
    				AddServerClientToFlowLayoutPanel_ServerSpeakButtons(data)
    
    				'Konfiguration senden
    				SendConfigurationToClient(data)
    			Catch ex As Exception
    				Console.WriteLine(ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' SendConfigurationToClient
    		''' </summary>
    		''' <param name="st"></param>
    		Private Sub SendConfigurationToClient(ByVal data As ServerThreadData)
    			Dim bytesConfig() As Byte = m_Encoding.GetBytes(String.Format("SamplesPerSecond:{0}", m_Config.SamplesPerSecondServer))
    			data.ServerThread.Send(m_PrototolClient.ToBytes(bytesConfig))
    		End Sub
    		''' <summary>
    		''' OnServerClientDisconnected
    		''' </summary>
    		''' <param name="st"></param>
    		''' <param name="info"></param>
    		Private Sub OnServerClientDisconnected(ByVal st As NF.ServerThread, ByVal info As String)
    			Try
    				'Wenn vorhanden
    				If m_DictionaryServerDatas.ContainsKey(st) Then
    					'Alle Daten freigeben
    					Dim data As ServerThreadData = m_DictionaryServerDatas(st)
    					data.Dispose()
    					SyncLock LockerDictionary
    						'Entfernen
    						m_DictionaryServerDatas.Remove(st)
    					End SyncLock
    					'Aus FlowLayoutPanels entfernen
    					RemoveServerClientToFlowLayoutPanel_ServerClient(st)
    					RemoveServerClientToFlowLayoutPanel_ServerProgressBar(data)
    					RemoveServerClientToFlowLayoutPanel_ButtonListen(data)
    					RemoveServerClientToFlowLayoutPanel_ButtonSpeak(data)
    				End If
    
    				'Aus Mixdaten entfernen
    				FormMain.DictionaryMixed.Remove(st)
    			Catch ex As Exception
    				Console.WriteLine(ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' StartTimerMixed
    		''' </summary>
    		Private Sub StartTimerMixed()
    			If m_TimerMixed Is Nothing Then
    				m_TimerMixed = New WinSound.EventTimer()
    				AddHandler m_TimerMixed.TimerTick, AddressOf OnTimerSendMixedDataToAllClients
    				m_TimerMixed.Start(20, 0)
    			End If
    		End Sub
    		''' <summary>
    		''' StopTimerMixed
    		''' </summary>
    		Private Sub StopTimerMixed()
    			If m_TimerMixed IsNot Nothing Then
    				m_TimerMixed.Stop()
    				RemoveHandler m_TimerMixed.TimerTick, AddressOf OnTimerSendMixedDataToAllClients
    				m_TimerMixed = Nothing
    			End If
    		End Sub
    		''' <summary>
    		''' StartTimerDrawProgressBar
    		''' </summary>
    		Private Sub StartTimerDrawProgressBar()
    			If m_TimerDrawProgressBar Is Nothing Then
    				m_TimerDrawProgressBar = New System.Windows.Forms.Timer()
    				AddHandler m_TimerDrawProgressBar.Tick, AddressOf OnTimerDrawServerClientsProgressBars
    				m_TimerDrawProgressBar.Interval = 100
    				m_TimerDrawProgressBar.Start()
    			End If
    		End Sub
    		''' <summary>
    		'''StopTimerDrawCurve 
    		''' </summary>
    		Private Sub StopTimerDrawProgressBar()
    			Try
    				If m_TimerDrawProgressBar IsNot Nothing Then
    					m_TimerDrawProgressBar.Stop()
    					m_TimerDrawProgressBar = Nothing
    
    					'Für jede ProgressBar
    					For Each prog As ProgressBar In FlowLayoutPanelServerProgressBars.Controls
    						If prog.Tag IsNot Nothing Then
    							'Daten ermitteln
    							Dim stData As ServerThreadData = DirectCast(prog.Tag, ServerThreadData)
    
    							'Wenn ein JitterBuffer vorhanden
    							If stData.JitterBuffer IsNot Nothing Then
    								prog.Value = 0
    							End If
    						End If
    					Next prog
    				End If
    			Catch ex As Exception
    				Console.WriteLine(ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' OnTimerDrawServerClientsProgressBars
    		''' </summary>
    		''' <param name="obj"></param>
    		''' <param name="e"></param>
    		Private Sub OnTimerDrawServerClientsProgressBars(ByVal obj As Object, ByVal e As EventArgs)
    			Try
    				'Für jede ProgressBar
    				For Each prog As ProgressBar In FlowLayoutPanelServerProgressBars.Controls
    					If prog.Tag IsNot Nothing Then
    						'Daten ermitteln
    						Dim stData As ServerThreadData = DirectCast(prog.Tag, ServerThreadData)
    
    						'Wenn ein JitterBuffer vorhanden
    						If stData.JitterBuffer IsNot Nothing Then
    							prog.Value = stData.JitterBuffer.Length
    						End If
    
    					End If
    				Next prog
    			Catch ex As Exception
    				Console.WriteLine(ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' RemoveControlByTag
    		''' </summary>
    		''' <param name="controls"></param>
    		''' <param name="tag"></param>
    		Private Sub RemoveControlByTag(ByVal controls As Control.ControlCollection, ByVal tag As Object)
    			Me.Invoke(New MethodInvoker(Sub()
    				'Control anhand Tag ermitteln
    				Dim existing As Control = Nothing
    				For Each ctrl As Control In controls
    					If ctrl.Tag Is tag Then
    						existing = ctrl
    						Exit For
    					End If
    				Next ctrl
    
    				'Wenn vorhanden
    				If existing IsNot Nothing Then
    					controls.Remove(existing)
    				End If
    			End Sub))
    		End Sub
    		''' <summary>
    		''' RemoveControlInAllFlowLayoutPanelsByServerThread
    		''' </summary>
    		''' <param name="st"></param>
    		Private Sub RemoveControlInAllFlowLayoutPanelsByServerThread(ByVal st As NF.ServerThread)
    			Me.Invoke(New MethodInvoker(Sub()
    				'Label
    				Dim ctrlLabel As Control = Nothing
    				For Each ctrl As Control In FlowLayoutPanelServerClients.Controls
    					Dim thread As NF.ServerThread = DirectCast(ctrl.Tag, NF.ServerThread)
    					If thread Is st Then
    						ctrlLabel = ctrl
    						Exit For
    					End If
    				Next ctrl
    				If ctrlLabel IsNot Nothing Then
    					FlowLayoutPanelServerClients.Controls.Remove(ctrlLabel)
    				End If
    
    				'ProgressBar
    				Dim ctrlProgress As Control = Nothing
    				For Each ctrl As Control In FlowLayoutPanelServerProgressBars.Controls
    					Dim data As ServerThreadData = DirectCast(ctrl.Tag, ServerThreadData)
    					If data.ServerThread Is st Then
    						ctrlProgress = ctrl
    						Exit For
    					End If
    				Next ctrl
    				If ctrlProgress IsNot Nothing Then
    					FlowLayoutPanelServerProgressBars.Controls.Remove(ctrlProgress)
    				End If
    
    				'ListenButton
    				Dim ctrlListen As Control = Nothing
    				For Each ctrl As Control In FlowLayoutPanelServerListen.Controls
    					Dim data As ServerThreadData = DirectCast(ctrl.Tag, ServerThreadData)
    					If data.ServerThread Is st Then
    						ctrlListen = ctrl
    						Exit For
    					End If
    				Next ctrl
    				If ctrlListen IsNot Nothing Then
    					FlowLayoutPanelServerListen.Controls.Remove(ctrlListen)
    				End If
    
    				'SpeakButton
    				Dim ctrlSpeak As Control = Nothing
    				For Each ctrl As Control In FlowLayoutPanelServerSpeak.Controls
    					Dim data As ServerThreadData = DirectCast(ctrl.Tag, ServerThreadData)
    					If data.ServerThread Is st Then
    						ctrlSpeak = ctrl
    						Exit For
    					End If
    				Next ctrl
    				If ctrlSpeak IsNot Nothing Then
    					FlowLayoutPanelServerSpeak.Controls.Remove(ctrlSpeak)
    				End If
    
    			End Sub))
    		End Sub
    		''' <summary>
    		''' RemoveServerClientToFlowLayoutPanel_ServerClient
    		''' </summary>
    		''' <param name="st"></param>
    		Private Sub RemoveServerClientToFlowLayoutPanel_ServerClient(ByVal st As NF.ServerThread)
    			Try
    				FlowLayoutPanelServerClients.Invoke(New MethodInvoker(Sub()
    					'Label löschen
    					RemoveControlByTag(FlowLayoutPanelServerClients.Controls, st)
    
    				End Sub))
    			Catch ex As Exception
    				Console.WriteLine(ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' RemoveServerClientToFlowLayoutPanel_ButtonListen
    		''' </summary>
    		''' <param name="st"></param>
    		Private Sub RemoveServerClientToFlowLayoutPanel_ButtonListen(ByVal data As ServerThreadData)
    			Try
    				FlowLayoutPanelServerListen.Invoke(New MethodInvoker(Sub()
    					'Button löschen
    					RemoveControlByTag(FlowLayoutPanelServerListen.Controls, data)
    				End Sub))
    			Catch ex As Exception
    				Console.WriteLine(ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' RemoveServerClientToFlowLayoutPanel_ButtonSpeak
    		''' </summary>
    		''' <param name="data"></param>
    		Private Sub RemoveServerClientToFlowLayoutPanel_ButtonSpeak(ByVal data As ServerThreadData)
    			Try
    				FlowLayoutPanelServerSpeak.Invoke(New MethodInvoker(Sub()
    					'Button löschen
    					RemoveControlByTag(FlowLayoutPanelServerSpeak.Controls, data)
    				End Sub))
    			Catch ex As Exception
    				Console.WriteLine(ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' AddServerClientToFlowLayoutPanel_ServerClient
    		''' </summary>
    		''' <param name="st"></param>
    		Private Sub AddServerClientToFlowLayoutPanel_ServerClient(ByVal st As NF.ServerThread)
    			Try
    				FlowLayoutPanelServerClients.Invoke(New MethodInvoker(Sub()
    					'Label erstellen
    					Dim lab As New Label()
    					lab.AutoSize = False
    					lab.BackColor = Color.DimGray
    					lab.ForeColor = Color.White
    					lab.Font = New Font(lab.Font, FontStyle.Bold)
    					lab.Margin = New Padding(5,If(FlowLayoutPanelServerClients.Controls.Count > 0, 5, 10), 0, 5)
    					lab.TextAlign = ContentAlignment.MiddleCenter
    					lab.Width = FlowLayoutPanelServerClients.Width - 10
    					lab.Text = st.Client.Client.RemoteEndPoint.ToString()
    					lab.Tag = st
    
    					'Hinzufügen
    					FlowLayoutPanelServerClients.Controls.Add(lab)
    				End Sub))
    			Catch ex As Exception
    				Console.WriteLine(ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' AddServerClientToFlowLayoutPanel_ServerProgressBars
    		''' </summary>
    		''' <param name="st"></param>
    		Private Sub AddServerClientToFlowLayoutPanel_ServerProgressBars(ByVal stData As ServerThreadData)
    			Try
    				FlowLayoutPanelServerProgressBars.Invoke(New MethodInvoker(Sub()
    					'ProgressBar erstellen
    					Dim prog As New ProgressBar()
    					prog.AutoSize = False
    					prog.Margin = New Padding(5,If(FlowLayoutPanelServerProgressBars.Controls.Count > 0, 5, 10), 0, 5)
    					prog.Width = FlowLayoutPanelServerProgressBars.Width - 20
    					prog.BackColor = Color.White
    					prog.Maximum = CInt(stData.JitterBuffer.Maximum)
    					prog.Tag = stData
    
    					'Hinzufügen
    					FlowLayoutPanelServerProgressBars.Controls.Add(prog)
    				End Sub))
    			Catch ex As Exception
    				Console.WriteLine(ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' AddServerClientToFlowLayoutPanel_ServerListenButtons
    		''' </summary>
    		''' <param name="stData"></param>
    		Private Sub AddServerClientToFlowLayoutPanel_ServerListenButtons(ByVal stData As ServerThreadData)
    			Try
    				Me.Invoke(New MethodInvoker(Sub()
    					'Button Listen erstellen
    					Dim btnListen As New Button()
    					btnListen.Width = 26
    					btnListen.Height = 27
    					btnListen.Margin = New Padding(0,If(FlowLayoutPanelServerListen.Controls.Count > 0, 3, 8), 0, 3)
    					btnListen.Tag = stData
    					btnListen.BackColor = Color.LightGray
    					btnListen.ImageAlign = ContentAlignment.MiddleCenter
    					btnListen.Image = My.Resources.Listen_On_Small
    					btnListen.Tag = stData
    					AddHandler btnListen.MouseClick, AddressOf OnButtonServerThreadListenClick
    
    					'Hinzufügen
    					FlowLayoutPanelServerListen.Controls.Add(btnListen)
    				End Sub))
    			Catch ex As Exception
    				Console.WriteLine(ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' AddServerClientToFlowLayoutPanel_ServerSpeakButtons
    		''' </summary>
    		''' <param name="stData"></param>
    		Private Sub AddServerClientToFlowLayoutPanel_ServerSpeakButtons(ByVal stData As ServerThreadData)
    			Try
    				FlowLayoutPanelServerSpeak.Invoke(New MethodInvoker(Sub()
    					'Button Listen erstellen
    					Dim btnSpeak As New Button()
    					btnSpeak.Width = 26
    					btnSpeak.Height = 27
    					btnSpeak.Margin = New Padding(0,If(FlowLayoutPanelServerSpeak.Controls.Count > 0, 3, 8), 0, 3)
    					btnSpeak.Tag = stData
    					btnSpeak.ImageAlign = ContentAlignment.MiddleCenter
    					btnSpeak.BackColor = Color.LightGray
    					btnSpeak.Image = My.Resources.Speak_On_Small
    					btnSpeak.Tag = stData
    					AddHandler btnSpeak.MouseClick, AddressOf OnButtonServerThreadSpeakClick
    
    					'Hinzufügen
    					FlowLayoutPanelServerSpeak.Controls.Add(btnSpeak)
    				End Sub))
    			Catch ex As Exception
    				Console.WriteLine(ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' OnButtonServerThreadListenClick
    		''' </summary>
    		''' <param name="sender"></param>
    		''' <param name="e"></param>
    		Private Sub OnButtonServerThreadListenClick(ByVal sender As Object, ByVal e As MouseEventArgs)
    			Try
    				Dim btn As Button = DirectCast(sender, Button)
    				If btn.Tag IsNot Nothing Then
    					Dim data As ServerThreadData = DirectCast(btn.Tag, ServerThreadData)
    					'Mute toggeln
    					data.IsMute = Not data.IsMute
    
    					'Anzeigen
    					If data.IsMute Then
    						btn.Image = My.Resources.Listen_Off_Small
    					Else
    						btn.Image = My.Resources.Listen_On_Small
    					End If
    				End If
    			Catch ex As Exception
    				ShowError(LabelServer, ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' OnButtonServerThreadSpeakClick
    		''' </summary>
    		''' <param name="sender"></param>
    		''' <param name="e"></param>
    		Private Sub OnButtonServerThreadSpeakClick(ByVal sender As Object, ByVal e As MouseEventArgs)
    			Try
    				Dim btn As Button = DirectCast(sender, Button)
    				If btn.Tag IsNot Nothing Then
    					Dim data As ServerThreadData = DirectCast(btn.Tag, ServerThreadData)
    					'Mute toggeln
    					data.ServerThread.IsMute = Not data.ServerThread.IsMute
    
    					'Anzeigen
    					If data.ServerThread.IsMute Then
    						btn.Image = My.Resources.Speak_Off_Small
    					Else
    						btn.Image = My.Resources.Speak_On_Small
    					End If
    				End If
    			Catch ex As Exception
    				ShowError(LabelServer, ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' RemoveServerClientToFlowLayoutPanel_ServerProgressBar
    		''' </summary>
    		''' <param name="st"></param>
    		Private Sub RemoveServerClientToFlowLayoutPanel_ServerProgressBar(ByVal data As ServerThreadData)
    			Try
    				FlowLayoutPanelServerProgressBars.Invoke(New MethodInvoker(Sub()
    					'ProgressBar löschen
    					RemoveControlByTag(FlowLayoutPanelServerProgressBars.Controls, data)
    				End Sub))
    			Catch ex As Exception
    				Console.WriteLine(ex.Message)
    			End Try
    		End Sub

  9. #9

    Thread Starter
    New Member Roast247's Avatar
    Join Date
    Jan 2021
    Posts
    15

    Re: Need help converting a c# to VB.NET

    Quote Originally Posted by .paul. View Post
    If you doubleclick on the Error BC30311 Value of type 'Byte()' cannot be converted to 'Integer'. TCPStreamer error, what does the code look like on the line it takes you to?
    middle part 2

    Code:
    		''' <summary>
    		''' OnServerDataReceived
    		''' </summary>
    		''' <param name="st"></param>
    		''' <param name="data"></param>
    		Private Sub OnServerDataReceived(ByVal st As NF.ServerThread, ByVal data() As Byte)
    			'Wenn vorhanden
    			If m_DictionaryServerDatas.ContainsKey(st) Then
    				'Wenn Protocol
    				Dim stData As ServerThreadData = m_DictionaryServerDatas(st)
    				If stData.Protocol IsNot Nothing Then
    					stData.Protocol.Receive_LH(st, data)
    				End If
    			End If
    		End Sub
    		''' <summary>
    		''' DeleteAllServerThreadDatas
    		''' </summary>
    		Private Sub DeleteAllServerThreadDatas()
    			SyncLock LockerDictionary
    				Try
    					For Each info As ServerThreadData In m_DictionaryServerDatas.Values
    						info.Dispose()
    					Next info
    					m_DictionaryServerDatas.Clear()
    				Catch ex As Exception
    					Console.WriteLine(ex.Message)
    				End Try
    			End SyncLock
    		End Sub
    		''' <summary>
    		'''IsServerRunning 
    		''' </summary>
    		Private ReadOnly Property IsServerRunning() As Boolean
    			Get
    				If m_Server IsNot Nothing Then
    					Return m_Server.State = NF.TCPServer.ListenerState.Started
    				End If
    				Return False
    			End Get
    		End Property
    		''' <summary>
    		''' IsClientConnected
    		''' </summary>
    		Private ReadOnly Property IsClientConnected() As Boolean
    			Get
    				If m_Client IsNot Nothing Then
    					Return m_Client.Connected
    				End If
    				Return False
    			End Get
    		End Property
    		''' <summary>
    		''' ShowClientConnected
    		''' </summary>
    		Private Sub ShowClientConnected()
    			Try
    				Me.Invoke(New MethodInvoker(Sub()
    					ButtonClient.BackColor = Color.DarkGreen
    					ButtonClient.ForeColor = Color.White
    					TextBoxClientAddress.Enabled = False
    					TextBoxClientPort.Enabled = False
    					NumericUpDownJitterBufferClient.Enabled = False
    					ComboboxOutputSoundDeviceNameClient.Enabled = False
    					ComboboxInputSoundDeviceNameClient.Enabled = False
    					ProgressBarPlayingClient.Visible = True
    				End Sub))
    			Catch ex As Exception
    				Console.WriteLine(ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' ShowClientDisconnected
    		''' </summary>
    		Private Sub ShowClientDisconnected()
    			Try
    				Me.Invoke(New MethodInvoker(Sub()
    					ButtonClient.BackColor = Color.Gray
    					ButtonClient.ForeColor = Color.Black
    					TextBoxClientAddress.Enabled = True
    					TextBoxClientPort.Enabled = True
    					NumericUpDownJitterBufferClient.Enabled = True
    					ComboboxOutputSoundDeviceNameClient.Enabled = True
    					ComboboxInputSoundDeviceNameClient.Enabled = True
    					ProgressBarPlayingClient.Visible = False
    				End Sub))
    			Catch ex As Exception
    				Console.WriteLine(ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' ShowServerStarted 
    		''' </summary>
    		Private Sub ShowServerStarted()
    			Try
    				Me.Invoke(New MethodInvoker(Sub()
    					ButtonServer.BackColor = Color.DarkGreen
    					ButtonServer.ForeColor = Color.White
    					NumericUpDownJitterBufferServer.Enabled = False
    					ComboboxOutputSoundDeviceNameServer.Enabled = False
    					ComboboxInputSoundDeviceNameServer.Enabled = False
    					TextBoxServerAddress.Enabled = False
    					TextBoxServerPort.Enabled = False
    					ComboboxSamplesPerSecondServer.Enabled = False
    					StartTimerDrawProgressBar()
    				End Sub))
    			Catch ex As Exception
    				Console.WriteLine(ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' ShowServerStopped
    		''' </summary>
    		Private Sub ShowServerStopped()
    			Try
    				Me.Invoke(New MethodInvoker(Sub()
    					ButtonServer.BackColor = Color.Gray
    					ButtonServer.ForeColor = Color.Black
    					StopTimerDrawProgressBar()
    					FlowLayoutPanelServerClients.Controls.Clear()
    					FlowLayoutPanelServerProgressBars.Controls.Clear()
    					FlowLayoutPanelServerListen.Controls.Clear()
    					FlowLayoutPanelServerSpeak.Controls.Clear()
    					NumericUpDownJitterBufferServer.Enabled = True
    					ComboboxOutputSoundDeviceNameServer.Enabled = True
    					ComboboxInputSoundDeviceNameServer.Enabled = True
    					TextBoxServerAddress.Enabled = True
    					TextBoxServerPort.Enabled = True
    					ComboboxSamplesPerSecondServer.Enabled = True
    				End Sub))
    			Catch ex As Exception
    				Console.WriteLine(ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' ShowStreamingFromSounddeviceStarted 
    		''' </summary>
    		Private Sub ShowStreamingFromSounddeviceStarted_Client()
    			Try
    				If Me.InvokeRequired Then
    					Me.Invoke(New MethodInvoker(Sub()
    						ShowStreamingFromSounddeviceStarted_Client()
    					End Sub))
    				Else
    
    				End If
    			Catch ex As Exception
    				ShowError(LabelClient, ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' ShowStreamingFromSounddeviceStopped_Client 
    		''' </summary>
    		Private Sub ShowStreamingFromSounddeviceStopped_Client()
    			Try
    				If Me.InvokeRequired Then
    					Me.Invoke(New MethodInvoker(Sub()
    						ShowStreamingFromSounddeviceStopped_Client()
    					End Sub))
    				Else
    
    				End If
    			Catch ex As Exception
    				ShowError(LabelClient, ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' ShowStreamingFromSounddeviceStarted_Server
    		''' </summary>
    		Private Sub ShowStreamingFromSounddeviceStarted_Server()
    			Try
    				If Me.InvokeRequired Then
    					Me.Invoke(New MethodInvoker(Sub()
    						ShowStreamingFromSounddeviceStarted_Server()
    					End Sub))
    				Else
    
    				End If
    			Catch ex As Exception
    				ShowError(LabelClient, ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' ShowStreamingFromSounddeviceStopped_Server
    		''' </summary>
    		Private Sub ShowStreamingFromSounddeviceStopped_Server()
    			Try
    				If Me.InvokeRequired Then
    					Me.Invoke(New MethodInvoker(Sub()
    						ShowStreamingFromSounddeviceStopped_Server()
    					End Sub))
    				Else
    
    				End If
    			Catch ex As Exception
    				ShowError(LabelClient, ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' ShowStreamingFromFileStarted 
    		''' </summary>
    		Private Sub ShowStreamingFromFileStarted()
    			Try
    				If Me.InvokeRequired Then
    					Me.Invoke(New MethodInvoker(Sub()
    						ShowStreamingFromFileStarted()
    					End Sub))
    				Else
    					ComboboxInputSoundDeviceNameClient.Enabled = False
    					ProgressBarPlayingClient.Visible = True
    				End If
    			Catch ex As Exception
    				ShowError(LabelClient, ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' ShowStreamingFromFileStopped 
    		''' </summary>
    		Private Sub ShowStreamingFromFileStopped()
    			Try
    				If Me.InvokeRequired Then
    					Me.Invoke(New MethodInvoker(Sub()
    						ShowStreamingFromFileStopped()
    					End Sub))
    				Else
    					ComboboxInputSoundDeviceNameClient.Enabled = True
    					ProgressBarPlayingClient.Visible = False
    				End If
    			Catch ex As Exception
    				ShowError(LabelClient, ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' ShowError
    		''' </summary>
    		''' <param name="lb"></param>
    		''' <param name="text"></param>
    		Private Sub ShowError(ByVal lb As Label, ByVal text As String)
    			Try
    				lb.Invoke(New MethodInvoker(Sub()
    					lb.Text = text
    					lb.ForeColor = Color.Red
    
    					'Je nach Quelle
    					If lb Is LabelClient Then
    						ButtonClient.BackColor = Color.Red
    					ElseIf lb Is LabelServer Then
    						ButtonServer.BackColor = Color.Red
    					End If
    				End Sub))
    			Catch ex As Exception
    				Console.WriteLine(ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' ShowInfo
    		''' </summary>
    		''' <param name="lb"></param>
    		''' <param name="text"></param>
    		Private Sub ShowMessage(ByVal lb As Label, ByVal text As String)
    			Try
    				lb.Invoke(New MethodInvoker(Sub()
    					lb.Text = text
    					lb.ForeColor = Color.Black
    				End Sub))
    			Catch ex As Exception
    				Console.WriteLine(ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' FormToConfig
    		''' </summary>
    		''' <returns></returns>
    		Private Function FormToConfig() As Boolean
    			Try
    				m_Config.IpAddressClient = TextBoxClientAddress.Text
    				m_Config.IPAddressServer = TextBoxServerAddress.Text
    				m_Config.PortClient = Convert.ToInt32(TextBoxClientPort.Text)
    				m_Config.PortServer = Convert.ToInt32(TextBoxServerPort.Text)
    				m_Config.SoundInputDeviceNameClient = If(ComboboxInputSoundDeviceNameClient.SelectedIndex >= 0, ComboboxInputSoundDeviceNameClient.SelectedItem.ToString(), "")
    				m_Config.SoundOutputDeviceNameClient = If(ComboboxOutputSoundDeviceNameClient.SelectedIndex >= 0, ComboboxOutputSoundDeviceNameClient.SelectedItem.ToString(), "")
    				m_Config.SoundInputDeviceNameServer = If(ComboboxInputSoundDeviceNameServer.SelectedIndex >= 0, ComboboxInputSoundDeviceNameServer.SelectedItem.ToString(), "")
    				m_Config.SoundOutputDeviceNameServer = If(ComboboxOutputSoundDeviceNameServer.SelectedIndex >= 0, ComboboxOutputSoundDeviceNameServer.SelectedItem.ToString(), "")
    				m_Config.JitterBufferCountServer = CUInt(Math.Truncate(NumericUpDownJitterBufferServer.Value))
    				m_Config.JitterBufferCountClient = CUInt(Math.Truncate(NumericUpDownJitterBufferClient.Value))
    				m_Config.SamplesPerSecondServer = If(ComboboxSamplesPerSecondServer.SelectedIndex >= 0, Convert.ToInt32(ComboboxSamplesPerSecondServer.SelectedItem.ToString()), 8000)
    				m_Config.BitsPerSampleServer = 16
    				m_Config.BitsPerSampleClient = 16
    				m_Config.ChannelsServer = 1
    				m_Config.ChannelsClient = 1
    				m_Config.UseJitterBufferClientRecording = True
    				m_Config.UseJitterBufferServerRecording = True
    				Return True
    			Catch ex As Exception
    				MessageBox.Show(ex.Message, "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    				Return False
    			End Try
    		End Function
    		''' <summary>
    		''' ConfigToForm
    		''' </summary>
    		''' <returns></returns>
    		Private Function ConfigToForm() As Boolean
    			Try
    				TextBoxClientAddress.Text = m_Config.IpAddressClient.ToString()
    				TextBoxServerAddress.Text = m_Config.IPAddressServer.ToString()
    				TextBoxClientPort.Text = m_Config.PortClient.ToString()
    				TextBoxServerPort.Text = m_Config.PortServer.ToString()
    				ComboboxInputSoundDeviceNameClient.SelectedIndex = ComboboxInputSoundDeviceNameClient.FindString(m_Config.SoundInputDeviceNameClient)
    				ComboboxOutputSoundDeviceNameClient.SelectedIndex = ComboboxOutputSoundDeviceNameClient.FindString(m_Config.SoundOutputDeviceNameClient)
    				ComboboxInputSoundDeviceNameServer.SelectedIndex = ComboboxInputSoundDeviceNameServer.FindString(m_Config.SoundInputDeviceNameServer)
    				ComboboxOutputSoundDeviceNameServer.SelectedIndex = ComboboxOutputSoundDeviceNameServer.FindString(m_Config.SoundOutputDeviceNameServer)
    				NumericUpDownJitterBufferServer.Value = m_Config.JitterBufferCountServer
    				NumericUpDownJitterBufferClient.Value = m_Config.JitterBufferCountClient
    				ComboboxSamplesPerSecondServer.SelectedIndex = ComboboxSamplesPerSecondServer.FindString(m_Config.SamplesPerSecondServer.ToString())
    
    				'Sonstiges
    				ShowButtonServerSpeak()
    				ShowButtonClientListen()
    				ShowButtonServerListen()
    				ShowButtonClientSpeak()
    
    				Return True
    			Catch ex As Exception
    				MessageBox.Show(ex.Message)
    				Return False
    			End Try
    		End Function
    		'----------------------------------------------------------------
    		'Daten schreiben
    		'----------------------------------------------------------------
    		Private Sub SaveConfig()
    			Try
    				FormToConfig()
    				Dim ser As New XmlSerializer(GetType(Configuration))
    				Dim stream As New FileStream(m_ConfigFileName, FileMode.Create)
    				ser.Serialize(stream, m_Config)
    				stream.Close()
    			Catch ex As Exception
    				MessageBox.Show(ex.Message)
    			End Try
    		End Sub

  10. #10

    Thread Starter
    New Member Roast247's Avatar
    Join Date
    Jan 2021
    Posts
    15

    Re: Need help converting a c# to VB.NET

    Quote Originally Posted by .paul. View Post
    If you doubleclick on the Error BC30311 Value of type 'Byte()' cannot be converted to 'Integer'. TCPStreamer error, what does the code look like on the line it takes you to?
    end of code

    Code:
    		'----------------------------------------------------------------
    		'Daten lesen
    		'---------------------------------------------------------------- 
    		Private Sub LoadConfig()
    			Try
    				'Wenn die Datei existiert
    				If File.Exists(m_ConfigFileName) Then
    					Dim ser As New XmlSerializer(GetType(Configuration))
    					Dim sr As New StreamReader(m_ConfigFileName)
    					m_Config = DirectCast(ser.Deserialize(sr), Configuration)
    					sr.Close()
    				End If
    
    				'Daten anzeigen
    				ConfigToForm()
    			Catch ex As Exception
    				MessageBox.Show(ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' FormMain_FormClosing
    		''' </summary>
    		''' <param name="sender"></param>
    		''' <param name="e"></param>
    		Private Sub FormMain_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs) Handles Me.FormClosing
    			Try
    				'Form ist geschlossen
    				m_IsFormMain = False
    
    				'Aufnahme beenden
    				StopRecordingFromSounddevice_Server()
    				'Streamen von Sounddevice beenden
    				StopRecordingFromSounddevice_Client()
    				'Client beenden
    				DisconnectClient()
    				'Server beenden
    				StopServer()
    
    				'Speichern
    				SaveConfig()
    			Catch ex As Exception
    				Console.WriteLine(ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' ButtonClient_Click
    		''' </summary>
    		''' <param name="sender"></param>
    		''' <param name="e"></param>
    		Private Sub ButtonClient_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ButtonClient.Click
    			If Not Me.ButtonClient.IsHandleCreated Then Return
    
    			Try
    				'Daten holen
    				FormToConfig()
    
    				If IsClientConnected Then
    					DisconnectClient()
    					StopRecordingFromSounddevice_Client()
    				Else
    					ConnectClient()
    				End If
    
    				'Kurz warten
    				System.Threading.Thread.Sleep(100)
    			Catch ex As Exception
    				ShowError(LabelClient, ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' ButtonServer_Click
    		''' </summary>
    		''' <param name="sender"></param>
    		''' <param name="e"></param>
    		Private Sub ButtonServer_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ButtonServer.Click
    			If Not Me.ButtonServer.IsHandleCreated Then Return
    
    			Try
    				'Daten holen
    				FormToConfig()
    
    				If IsServerRunning Then
    					StopServer()
    					StopRecordingFromSounddevice_Server()
    					StopTimerMixed()
    				Else
    					StartServer()
    
    					'Wenn aktiv
    					If m_Config.ServerNoSpeakAll = False Then
    						StartRecordingFromSounddevice_Server()
    					End If
    
    					StartTimerMixed()
    				End If
    			Catch ex As Exception
    				ShowError(LabelServer, ex.Message)
    			End Try
    		End Sub
    		''' <summary>
    		''' NumericUpDownJitterBufferServer_ValueChanged
    		''' </summary>
    		''' <param name="sender"></param>
    		''' <param name="e"></param>
    		Private Sub NumericUpDownJitterBufferServer_ValueChanged(ByVal sender As Object, ByVal e As EventArgs) Handles NumericUpDownJitterBufferServer.ValueChanged
    			If Not Me.NumericUpDownJitterBufferServer.IsHandleCreated Then Return
    
    			m_Config.JitterBufferCountServer = CUInt(Math.Truncate(NumericUpDownJitterBufferServer.Value))
    		End Sub
    		''' <summary>
    		''' NumericUpDownJitterBufferClient_ValueChanged
    		''' </summary>
    		''' <param name="sender"></param>
    		''' <param name="e"></param>
    		Private Sub NumericUpDownJitterBufferClient_ValueChanged(ByVal sender As Object, ByVal e As EventArgs) Handles NumericUpDownJitterBufferClient.ValueChanged
    			If Not Me.NumericUpDownJitterBufferClient.IsHandleCreated Then Return
    
    			m_Config.JitterBufferCountClient = CUInt(Math.Truncate(NumericUpDownJitterBufferClient.Value))
    		End Sub
    		''' <summary>
    		''' StopStreamSounddevice_Client
    		''' </summary>
    		Private Sub StopStreamSounddevice_Client()
    			StopRecordingFromSounddevice_Client()
    		End Sub
    		''' <summary>
    		''' IsPlayingToSoundDeviceWanted
    		''' </summary>
    		Private ReadOnly Property IsPlayingToSoundDeviceWanted() As Boolean
    			Get
    				If ComboboxOutputSoundDeviceNameClient.SelectedIndex >= 1 Then
    					Return True
    				End If
    				Return False
    			End Get
    		End Property
    		''' <summary>
    		''' StartPlayingToSounddevice_Client
    		''' </summary>
    		Private Sub StartPlayingToSounddevice_Client()
    			'Wenn gewünscht
    			If IsPlayingToSoundDeviceWanted Then
    				'JitterBuffer starten
    				If m_JitterBufferClientPlaying IsNot Nothing Then
    					InitJitterBufferClientPlaying()
    					m_JitterBufferClientPlaying.Start()
    				End If
    
    				If m_PlayerClient Is Nothing Then
    					m_PlayerClient = New WinSound.Player()
    					m_PlayerClient.Open(m_Config.SoundOutputDeviceNameClient, m_Config.SamplesPerSecondClient, m_Config.BitsPerSampleClient, m_Config.ChannelsClient, CInt(m_Config.JitterBufferCountClient))
    				End If
    
    				'Timer starten
    				m_TimerProgressBarPlayingClient.Start()
    
    			End If
    
    			'Anzeigen
    			ComboboxOutputSoundDeviceNameClient.Invoke(New MethodInvoker(Sub()
    				ComboboxOutputSoundDeviceNameClient.Enabled = False
    				NumericUpDownJitterBufferClient.Enabled = False
    				ProgressBarPlayingClient.Maximum = CInt(m_JitterBufferClientPlaying.Maximum)
    			End Sub))
    
    		End Sub
    		''' <summary>
    		''' StopPlayingToSounddevice_Client
    		''' </summary>
    		Private Sub StopPlayingToSounddevice_Client()
    			If m_PlayerClient IsNot Nothing Then
    				m_PlayerClient.Close()
    				m_PlayerClient = Nothing
    			End If
    
    			'JitterBuffer beenden
    			If m_JitterBufferClientPlaying IsNot Nothing Then
    				m_JitterBufferClientPlaying.Stop()
    			End If
    
    			'Timer beenden
    			m_TimerProgressBarPlayingClient.Stop()
    
    			'Anzeigen
    			Me.Invoke(New MethodInvoker(Sub()
    				ComboboxOutputSoundDeviceNameClient.Enabled = True
    				NumericUpDownJitterBufferClient.Enabled = True
    				ProgressBarPlayingClient.Value = 0
    			End Sub))
    		End Sub
    		''' <summary>
    		''' ButtonServerSpeak_Click
    		''' </summary>
    		''' <param name="sender"></param>
    		''' <param name="e"></param>
    		Private Sub ButtonServerSpeak_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ButtonServerSpeak.Click
    			If Not Me.ButtonServerSpeak.IsHandleCreated Then Return
    
    			'Toggeln
    			m_Config.ServerNoSpeakAll = Not m_Config.ServerNoSpeakAll
    
    			'Je nach Zustand
    			If m_Config.ServerNoSpeakAll Then
    				StopRecordingFromSounddevice_Server()
    			Else
    				StartRecordingFromSounddevice_Server()
    			End If
    
    			'Anzeigen
    			ShowButtonServerSpeak()
    		End Sub
    		''' <summary>
    		''' ShowButtonServerSpeak
    		''' </summary>
    		Private Sub ShowButtonServerSpeak()
    			If m_Config.ServerNoSpeakAll Then
    				ButtonServerSpeak.Image = My.Resources.Speak_Off
    			Else
    				ButtonServerSpeak.Image = My.Resources.Speak_On
    			End If
    		End Sub
    		''' <summary>
    		''' ShowButtonClientSpeak
    		''' </summary>
    		Private Sub ShowButtonClientSpeak()
    			If m_Config.ClientNoSpeakAll Then
    				ButtonClientSpeak.Image = My.Resources.Speak_Off
    			Else
    				ButtonClientSpeak.Image = My.Resources.Speak_On
    			End If
    		End Sub
    		''' <summary>
    		''' ButtonClientListen_Click
    		''' </summary>
    		''' <param name="sender"></param>
    		''' <param name="e"></param>
    		Private Sub ButtonClientListen_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ButtonClientListen.Click
    			If Not Me.ButtonClientListen.IsHandleCreated Then Return
    
    			'Toggeln
    			m_Config.MuteClientPlaying = Not m_Config.MuteClientPlaying
    			'Anzeigen
    			ShowButtonClientListen()
    		End Sub
    		''' <summary>
    		''' ShowButtonServerSpeak
    		''' </summary>
    		Private Sub ShowButtonClientListen()
    			If m_Config.MuteClientPlaying Then
    				ButtonClientListen.Image = My.Resources.Listen_Off
    			Else
    				ButtonClientListen.Image = My.Resources.Listen_On
    			End If
    		End Sub
    		''' <summary>
    		''' ButtonServerListen_Click
    		''' </summary>
    		''' <param name="sender"></param>
    		''' <param name="e"></param>
    		Private Sub ButtonServerListen_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ButtonServerListen.Click
    			If Not Me.ButtonServerListen.IsHandleCreated Then Return
    
    			'Toggeln
    			m_Config.MuteServerListen = Not m_Config.MuteServerListen
    
    			'Anzeigen
    			ShowButtonServerListen()
    		End Sub
    		''' <summary>
    		''' ShowButtonServerListen
    		''' </summary>
    		Private Sub ShowButtonServerListen()
    			If m_Config.MuteServerListen Then
    				ButtonServerListen.Image = My.Resources.Listen_Off
    			Else
    				ButtonServerListen.Image = My.Resources.Listen_On
    			End If
    
    			'Speichern
    			ServerThreadData.IsMuteAll = m_Config.MuteServerListen
    		End Sub
    		''' <summary>
    		''' ButtonClientSpeak_Click
    		''' </summary>
    		''' <param name="sender"></param>
    		''' <param name="e"></param>
    		Private Sub ButtonClientSpeak_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ButtonClientSpeak.Click
    			If Not Me.ButtonClientSpeak.IsHandleCreated Then Return
    
    			Try
    				'Toggeln
    				m_Config.ClientNoSpeakAll = Not m_Config.ClientNoSpeakAll
    				'Anzeigen
    				ShowButtonClientSpeak()
    			Catch ex As Exception
    				ShowError(LabelClient, ex.Message)
    			End Try
    		End Sub
    
    		Private Sub FormMain_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    
    		End Sub
    
    		Private Sub TextBoxServerAddress_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles TextBoxServerAddress.TextChanged
    			If Not Me.TextBoxServerAddress.IsHandleCreated Then Return
    
    
    		End Sub
    
    		Private Sub LabelServer_Click(ByVal sender As Object, ByVal e As EventArgs) Handles LabelServer.Click
    			If Not Me.LabelServer.IsHandleCreated Then Return
    
    
    		End Sub
    	End Class
    	''' <summary>
    	''' Config
    	''' </summary>
    	Public Class Configuration
    		''' <summary>
    		''' Config
    		''' </summary>
    		Public Sub New()
    
    		End Sub
    
    		'Attribute
    		Public IpAddressClient As String = ""
    		Public IPAddressServer As String = ""
    		Public PortClient As Integer = 0
    		Public PortServer As Integer = 0
    		Public SoundInputDeviceNameClient As String = ""
    		Public SoundOutputDeviceNameClient As String = ""
    		Public SoundInputDeviceNameServer As String = ""
    		Public SoundOutputDeviceNameServer As String = ""
    		Public SamplesPerSecondClient As Integer = 8000
    		Public BitsPerSampleClient As Integer = 16
    		Public ChannelsClient As Integer = 1
    		Public SamplesPerSecondServer As Integer = 8000
    		Public BitsPerSampleServer As Integer = 16
    		Public ChannelsServer As Integer = 1
    		Public UseJitterBufferClientRecording As Boolean = True
    		Public UseJitterBufferServerRecording As Boolean = True
    		Public JitterBufferCountServer As UInteger = 20
    		Public JitterBufferCountClient As UInteger = 20
    		Public FileName As String = ""
    		Public LoopFile As Boolean = False
    		Public MuteClientPlaying As Boolean = False
    		Public ServerNoSpeakAll As Boolean = False
    		Public ClientNoSpeakAll As Boolean = False
    		Public MuteServerListen As Boolean = False
    	End Class
    	''' <summary>
    	''' ServerThreadData
    	''' </summary>
    	Public Class ServerThreadData
    		''' <summary>
    		''' Konstruktor
    		''' </summary>
    		Public Sub New()
    
    		End Sub
    
    		'Attribute
    		Public ServerThread As NF.ServerThread
    		Public Player As WinSound.Player
    		Public JitterBuffer As WinSound.JitterBuffer
    		Public Protocol As WinSound.Protocol
    		Public SamplesPerSecond As Integer = 8000
    		Public BitsPerSample As Integer = 16
    		Public SoundBufferCount As Integer = 8
    		Public JitterBufferCount As UInteger = 20
    		Public JitterBufferMilliseconds As UInteger = 20
    		Public Channels As Integer = 1
    		Private IsInitialized As Boolean = False
    		Public IsMute As Boolean = False
    		Public Shared IsMuteAll As Boolean = False
    
    		''' <summary>
    		''' Init
    		''' </summary>
    		''' <param name="bitsPerSample"></param>
    		''' <param name="channels"></param>
    		Public Sub Init(ByVal st As NF.ServerThread, ByVal soundDeviceName As String, ByVal samplesPerSecond As Integer, ByVal bitsPerSample As Integer, ByVal channels As Integer, ByVal soundBufferCount As Integer, ByVal jitterBufferCount As UInteger, ByVal jitterBufferMilliseconds As UInteger)
    			'Werte übernehmen
    			Me.ServerThread = st
    			Me.SamplesPerSecond = samplesPerSecond
    			Me.BitsPerSample = bitsPerSample
    			Me.Channels = channels
    			Me.SoundBufferCount = soundBufferCount
    			Me.JitterBufferCount = jitterBufferCount
    			Me.JitterBufferMilliseconds = jitterBufferMilliseconds
    
    			'Player
    			Me.Player = New WinSound.Player()
    			Me.Player.Open(soundDeviceName, samplesPerSecond, bitsPerSample, channels, soundBufferCount)
    
    			'Wenn ein JitterBuffer verwendet werden soll
    			If jitterBufferCount >= 2 Then
    				'Neuen JitterBuffer erstellen
    				Me.JitterBuffer = New WinSound.JitterBuffer(st, jitterBufferCount, jitterBufferMilliseconds)
    				AddHandler JitterBuffer.DataAvailable, AddressOf OnJitterBufferDataAvailable
    				Me.JitterBuffer.Start()
    			End If
    
    			'Protocol
    			Me.Protocol = New WinSound.Protocol(WinSound.ProtocolTypes.LH, Encoding.Default)
    			AddHandler Protocol.DataComplete, AddressOf OnProtocolDataComplete
    
    			'Zu Mixer hinzufügen
    			FormMain.DictionaryMixed(st) = New Queue(Of List(Of Byte))()
    
    			'Initialisiert
    			IsInitialized = True
    		End Sub
    		''' <summary>
    		''' Dispose
    		''' </summary>
    		Public Sub Dispose()
    			'Protocol
    			If Protocol IsNot Nothing Then
    				RemoveHandler Protocol.DataComplete, AddressOf OnProtocolDataComplete
    				Me.Protocol = Nothing
    			End If
    
    			'JitterBuffer
    			If JitterBuffer IsNot Nothing Then
    				JitterBuffer.Stop()
    				RemoveHandler JitterBuffer.DataAvailable, AddressOf OnJitterBufferDataAvailable
    				Me.JitterBuffer = Nothing
    			End If
    
    			'Player
    			If Player IsNot Nothing Then
    				Player.Close()
    				Me.Player = Nothing
    			End If
    
    			'Nicht initialisiert
    			IsInitialized = False
    		End Sub
    		''' <summary>
    		''' OnProtocolDataComplete
    		''' </summary>
    		''' <param name="sender"></param>
    		''' <param name="data"></param>
    		Private Sub OnProtocolDataComplete(ByVal sender As Object, ByVal bytes() As Byte)
    			'Wenn initialisiert
    			If IsInitialized Then
    				If ServerThread IsNot Nothing AndAlso Player IsNot Nothing Then
    					Try
    						'Wenn der Player gestartet wurde
    						If Player.Opened Then
    
    							'RTP Header auslesen
    							Dim rtp As New WinSound.RTPPacket(bytes)
    
    							'Wenn Header korrekt
    							If rtp.Data IsNot Nothing Then
    								'Wenn JitterBuffer verwendet werden soll
    								If JitterBuffer IsNot Nothing AndAlso JitterBuffer.Maximum >= 2 Then
    									JitterBuffer.AddData(rtp)
    								Else
    									'Wenn kein Mute
    									If IsMuteAll = False AndAlso IsMute = False Then
    										'Nach Linear umwandeln
    										Dim linearBytes() As Byte = WinSound.Utils.MuLawToLinear(rtp.Data, Me.BitsPerSample, Me.Channels)
    										'Abspielen
    										Player.PlayData(linearBytes, False)
    									End If
    								End If
    							End If
    
    						End If
    					Catch ex As Exception
    						Console.WriteLine(ex.Message)
    						IsInitialized = False
    					End Try
    				End If
    			End If
    		End Sub
    		''' <summary>
    		''' OnJitterBufferDataAvailable
    		''' </summary>
    		''' <param name="packet"></param>
    		Private Sub OnJitterBufferDataAvailable(ByVal sender As Object, ByVal rtp As WinSound.RTPPacket)
    			Try
    				If Player IsNot Nothing Then
    					'Nach Linear umwandeln
    					Dim linearBytes() As Byte = WinSound.Utils.MuLawToLinear(rtp.Data, BitsPerSample, Channels)
    
    					'Wenn kein Mute
    					If IsMuteAll = False AndAlso IsMute = False Then
    						'Abspielen
    						Player.PlayData(linearBytes, False)
    					End If
    
    					'Wenn Buffer nicht zu gross
    					Dim q As Queue(Of List(Of Byte)) = FormMain.DictionaryMixed(sender)
    					If q.Count < 10 Then
    						'Daten Zu Mixer hinzufügen
    						FormMain.DictionaryMixed(sender).Enqueue(New List(Of Byte)(linearBytes))
    					End If
    				End If
    			Catch ex As Exception
    				Console.WriteLine(String.Format("FormMain.cs | OnJitterBufferDataAvailable() | {0}", ex.Message))
    			End Try
    		End Sub
    	End Class
    End Namespace

  11. #11
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    106,288

    Re: Need help converting a c# to VB.NET

    Why post an enormous wad of code and direct us to the middle or end without actually highlighting the line when you could just post a small snippet of relevant code. Also, please put some thought into the problem and what we might need to solve the problem. You started by posting one line of code, which is good.
    Code:
    Dim linearBytes() As Byte = WinSound.Utils.MuLawToLinear(rtp.Data, BitsPerSample, Channels)
    The bad part is that you didn't actually explain anything. The error message is telling you that a Byte array cannot be converted to an Integer so you must obviously be using a Byte array where an Integer is expected/required. So, what's what there? What is the signature of that method? What is the data type of each of the arguments you're passing? Presumably one of the parameters is type Integer and the corresponding argument is type Byte(). You have that information and we don't.

    As for the others, don't expect us to wade through a huge wad of code and try to work out where the issue is when you already know where it is. Post the smallest block of code you can to include all that's relevant to that specific issue and, if there's more than one line, highlight the actual line the error occurs on.

  12. #12
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,736

    Re: Need help converting a c# to VB.NET

    Quote Originally Posted by jmcilhinney View Post
    Code:
    Dim linearBytes() As Byte = WinSound.Utils.MuLawToLinear(rtp.Data, BitsPerSample, Channels)
    What is the signature of that method? What is the data type of each of the arguments you're passing? Presumably one of the parameters is type Integer and the corresponding argument is type Byte(). You have that information and we don't.
    It says: Too many arguments to 'Public Shared Function MulawToLinear(ulaw As Integer) As Integer

    My guess is that's an overloaded function, and the compiler is confused by inaccurate argument datatypes

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