private void audioWaveIn_BufferFull(byte[] buffer) { // Compress data. byte[] encodedData = null; if (m_Codec == 0) { encodedData = G711.Encode_aLaw(buffer, 0, buffer.Length); } else if (m_Codec == 1) { encodedData = G711.Encode_uLaw(buffer, 0, buffer.Length); } //Send to all other clients foreach (User usr in Main.Surgery.ConnectedClients) { if (!usr.MyName.Equals(Main.User.MyName)) { audioServer.SendPacket(encodedData, 0, encodedData.Length, new IPEndPoint(IPAddress.Parse(usr.MyIPAddress), audioPort)); } } //If client, send to master if (!Main.User.IsMaster) { audioServer.SendPacket(encodedData, 0, encodedData.Length, new IPEndPoint(IPAddress.Parse(Main.Surgery.Master.MyIPAddress), audioPort)); } }
void m_pWaveIn_BufferFull(byte[] buffer) { ResponseStartCaptureAudio resp = new ResponseStartCaptureAudio(); resp.AudioData = G711.Encode_aLaw(buffer, 0, buffer.Length); _session.Send(ePacketType.PACKET_START_CAPTURE_AUDIO_RESPONSE, resp); }
private void gpcst_BufferFull(byte[] buffer) { // Compress data. if (gpcst.Count > 0) { byte[] encodedData = null; if (m_Codec == 0) { encodedData = G711.Encode_aLaw(buffer, 0, buffer.Length); } else if (m_Codec == 1) { encodedData = G711.Encode_uLaw(buffer, 0, buffer.Length); } // We just sent buffer to target end point. foreach (IPEndPoint k in gpcst) { VUdpServer.SendPacket(encodedData, 0, encodedData.Length, k); } } else { VWaveIn.Stop(); VWaveIn = null; checkedListBox1.Items.Clear(); gpcst.Clear(); button10.Enabled = false; } }
public void waveIn_Buffer_Full(byte[] buffer) { byte[] encodedData = null; encodedData = G711.Encode_aLaw(buffer, 0, buffer.Length); udpServer.SendPacket(encodedData, 0, encodedData.Length, remoteEndPoint); }
private void WaveInBufferFull(byte[] buffer) { byte[] encodedData = G711.Encode_aLaw(buffer, 0, buffer.Length); if (encodedData != null) { SoundUdpServer.Instance.udpServer.SendPacket(encodedData, 0, encodedData.Length, _targetEndPoint); } }
private void m_pWaveIn_BufferFull(byte[] buffer) { // Compress data. byte[] encodedData = null; encodedData = G711.Encode_aLaw(buffer, 0, buffer.Length); // We just sent buffer to target end point. wc.audioUdpServer.SendPacket(encodedData, 0, encodedData.Length, audioTargetEP); }
private void m_pUdpServer_PacketReceived(UdpPacket_eArgs e) { // Decompress data. byte[] decodedData = null; // Elegir el codec decodedData = G711.Decode_aLaw(e.Data, 0, e.Data.Length); // We just play received packet. m_pWaveOut.Play(decodedData, 0, decodedData.Length); }
public void G711ComparisonTest() { for (int i = short.MinValue; i <= short.MaxValue; i++) { Assert.AreEqual(G711.LinearToULaw((byte)i), G711.LinearToULawFast((byte)i)); } for (int i = byte.MinValue; i <= byte.MaxValue; i++) { Assert.AreEqual(G711.ULawToLinear((byte)i), G711.ULawToLinearFast((byte)i)); } }
public void udpServer_packet_received_method(UdpPacket_eArgs e) { // byte[] decodedData = null; byte[] receiveData = null; //decodedData = G711.Decode_aLaw(e.Data, 0, e.Data.Length); receiveData = G711.Decode_aLaw(e.Data, 0, e.Data.Length); ASCIIEncoding aEncoding = new ASCIIEncoding(); string receivedMessage = aEncoding.GetString(receiveData); listMessage.Items.Add("Friend: " + receivedMessage); //waveOut.Play(decodedData, 0, decodedData.Length); }
/// <summary> /// This method is called when recording buffer is full and we need to process it. /// </summary> /// <param name="buffer">Recorded data.</param> private void m_pWaveIn_BufferFull(byte[] buffer) { // Compress data. byte[] encodedData = null; if (m_Codec == 0) { encodedData = G711.Encode_aLaw(buffer, 0, buffer.Length); } else if (m_Codec == 1) { encodedData = G711.Encode_uLaw(buffer, 0, buffer.Length); } // We just sent buffer to target end point. m_pUdpServer.SendPacket(encodedData, 0, encodedData.Length, m_pTargetEP); }
private void AudioServer_PacketReceived(UdpPacket_eArgs e) { // Decompress data. byte[] decodedData = null; if (m_Codec == 0) { decodedData = G711.Decode_aLaw(e.Data, 0, e.Data.Length); } else if (m_Codec == 1) { decodedData = G711.Decode_uLaw(e.Data, 0, e.Data.Length); } // just play received packet audioWaveOut.Play(decodedData, 0, decodedData.Length); }
/// <summary> /// Sends test sound to target end point. /// </summary> private void SendTest() { try { using (FileStream fs = File.OpenRead(m_PlayFile)) { byte[] buffer = new byte[400]; int readedCount = fs.Read(buffer, 0, buffer.Length); long lastSendTime = DateTime.Now.Ticks; while (m_IsSendingTest && readedCount > 0) { // Compress data. byte[] encodedData = null; if (m_Codec == 0) { encodedData = G711.Encode_aLaw(buffer, 0, buffer.Length); } else if (m_Codec == 1) { encodedData = G711.Encode_uLaw(buffer, 0, buffer.Length); } // Send and read next. m_pUdpServer.SendPacket(encodedData, 0, encodedData.Length, m_pTargetEP); readedCount = fs.Read(buffer, 0, buffer.Length); Thread.Sleep(25); lastSendTime = DateTime.Now.Ticks; } } if (m_IsRunning) { this.Invoke(new MethodInvoker(this.OnAudioStopped)); } } catch (Exception x) { MessageBox.Show(null, "Error: " + x.ToString(), "Error:", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void audio_BufferFull(byte[] buffer) { // Compress data. byte[] encodedData = null; if (m_Codec == 0) { encodedData = G711.Encode_aLaw(buffer, 0, buffer.Length); } else if (m_Codec == 1) { encodedData = G711.Encode_uLaw(buffer, 0, buffer.Length); } // We just sent buffer to target end point. if (m_IsSendingTest) { byte[] decodedData = null; if (m_Codec == 0) { decodedData = G711.Decode_aLaw(encodedData, 0, encodedData.Length); } else if (m_Codec == 1) { decodedData = G711.Decode_uLaw(encodedData, 0, encodedData.Length); } // We just play received packet. VWaveOut.Play(decodedData, 0, decodedData.Length); /* * VWaveOut.Play(buffer, 0, buffer.Length); */ } else //sending to server { // We just sent buffer to target end point. VUdpServer.SendPacket(encodedData, 0, encodedData.Length, VTargetEP); } }
/// <summary> /// This method is called when we got UDP packet. /// </summary> /// <param name="e">Event data.</param> private void m_pUdpServer_PacketReceived(UdpPacket_eArgs e) { // Decompress data. byte[] decodedData = null; if (m_Codec == 0) { decodedData = G711.Decode_aLaw(e.Data, 0, e.Data.Length); } else if (m_Codec == 1) { decodedData = G711.Decode_uLaw(e.Data, 0, e.Data.Length); } // We just play received packet. m_pWaveOut.Play(decodedData, 0, decodedData.Length); // Record if recoring enabled. if (m_pRecordStream != null) { m_pRecordStream.Write(decodedData, 0, decodedData.Length); } }
public void G711LinearToULawPerformanceComparison() { const int innerIterations = 10000; var input = new short[_audioFormat.SamplesPerFrame]; var rnd = new Random(); for (int i = 0; i < input.Length; i++) { input[i] = (short)rnd.Next(short.MinValue, short.MaxValue); } var calculationElapsed = new TimeSpan(); var lookupElapsed = new TimeSpan(); for (int i = 0; i < 10; i++) { var start = DateTime.Now; for (int j = 0; j < innerIterations; j++) { foreach (short k in input) { var encoded = G711.LinearToULaw(k); } } calculationElapsed += DateTime.Now - start; start = DateTime.Now; for (int j = 0; j < innerIterations; j++) { foreach (short k in input) { var encoded = G711.LinearToULawFast(k); } } lookupElapsed += DateTime.Now - start; } ClientLogger.Debug("CalculationElapsed: {0}; LookupElapsed: {1}", calculationElapsed.TotalMilliseconds, lookupElapsed.TotalMilliseconds); }
static void Main(string[] args) { InitializeLog4net(); TestExpressionBuilder testExpressionBuilder = new TestExpressionBuilder(); //testExpressionBuilder.TestBuild(); testExpressionBuilder.TestProperty(); Console.ReadLine(); //byte[] data = CRC.CRC16(new byte[] { 0x01, 0x02, 0x00, 0x00, 0x00, 0x04 }); //Console.WriteLine(Convert.ToString(data[0], 16)); //Console.WriteLine(Convert.ToString(data[1], 16)); //Console.ReadLine(); //Console.WriteLine(20 * Math.Log10((double)1 / (double)32767)); //Console.ReadLine(); //double maxDb = 20 * Math.Log10(32767); //Console.WriteLine(maxDb); //Console.ReadLine(); //string data = string.Empty; //for (int i = 1; i < 65535; i++) //{ // double maxDb = 20 * Math.Log10(i); // data += maxDb.ToString() + Environment.NewLine; //} //File.WriteAllText("1.txt", data); Dictionary <string, object> parameters = new Dictionary <string, object>(); //DirectSoundPlay Player = new DirectSoundPlay(); //int code = Player.Initialize(parameters); //if (code != DotNEToolkit.DotNETCode.SUCCESS) //{ // Console.WriteLine("初始化DirectSoundPlay失败"); //} //while (true) //{ // Player.PlayFile("out.pcm"); // System.Threading.Thread.Sleep(1000); //} //Dictionary<string, object> parameters1 = new Dictionary<string, object>(); ////parameters1["Channel"] = 1; ////parameters1["SamplesPerSec"] = 16000; //DirectSoundRecord Record = new DirectSoundRecord(); //Record.Initialize(parameters1); //Record.SetRecordFile("out.pcm"); //Record.Start(); byte[] alaw = File.ReadAllBytes("audio"); byte[] pcm = G711.Alaw2PCM(alaw); File.WriteAllBytes("pcm", pcm); Console.WriteLine("转换成功"); Console.ReadLine(); }
private void PacketRecieved(UdpPacket_eArgs e) { byte[] decodedData = G711.Decode_aLaw(e.Data, 0, e.Data.Length); _waveOut.Play(decodedData, 0, decodedData.Length); }