void StartEncoding() { _startTime = DateTime.Now; _bytesSent = 0; _segmentFrames = 960; _encoder = OpusEncoder.Create(48000, 1, FragLabs.Audio.Codecs.Opus.Application.Voip); _encoder.Bitrate = 8192; _decoder = OpusDecoder.Create(48000, 1); _bytesPerSegment = _encoder.FrameByteCount(_segmentFrames); _waveIn = new WaveIn(WaveCallbackInfo.FunctionCallback()); _waveIn.BufferMilliseconds = 50; _waveIn.DeviceNumber = comboBox1.SelectedIndex; _waveIn.DataAvailable += _waveIn_DataAvailable; _waveIn.WaveFormat = new WaveFormat(48000, 16, 1); _playBuffer = new BufferedWaveProvider(new WaveFormat(48000, 16, 1)); _waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback()); _waveOut.DeviceNumber = comboBox2.SelectedIndex; _waveOut.Init(_playBuffer); _waveOut.Play(); _waveIn.StartRecording(); if (_timer == null) { _timer = new Timer(); _timer.Interval = 1000; _timer.Tick += _timer_Tick; } _timer.Start(); }
public CSCoreRecorder(MMDevice captureDevice, bool triggerSingleBlockRead, int bitrate, Application application) { _captureDevice = captureDevice; _triggerSingleBlockRead = triggerSingleBlockRead; _opusEncoder = OpusEncoder.Create(48000, 1, application); _opusEncoder.Bitrate = bitrate; _bytesPerSegment = _opusEncoder.FrameByteCount(SegmentFrames); }
public Voice() { OnStatusChanged += EventOnStatusChanged; _decoder = OpusDecoder.Create((int)SampleRate, 1); _encoder = OpusEncoder.Create((int)SampleRate, 1, Application.Voip); _encoder.Bitrate = 8192 * 2; _bytesPerSegment = _encoder.FrameByteCount(StreamSize); }
public OpusEncoderManager(AudioOutputWriter aout, int sampleRate) { this.aout = aout; _bytesSent = 0; _segmentFrames = GlobalConfiguration.samplesPerPacket; //1024; //960; mEncoder = OpusEncoder.Create(sampleRate, 1, FragLabs.Audio.Codecs.Opus.Application.Voip); mEncoder.Bitrate = GlobalConfiguration.encoderBps; // 1KB/sec が最低値のようだ _bytesPerSegment = mEncoder.FrameByteCount(_segmentFrames); }
public void Record_OPUS(int device_num, string ip) { network.Initializecon(ip); startTime = DateTime.Now; bytesSent = 0; segmentFrames = 960; encoder = OpusEncoder.Create(48000, 1, FragLabs.Audio.Codecs.Opus.Application.Voip); encoder.Bitrate = 8192; bytesPerSegment = encoder.FrameByteCount(segmentFrames); waveIn = new WaveIn(WaveCallbackInfo.FunctionCallback()); waveIn.BufferMilliseconds = 50; waveIn.DeviceNumber = device_num; waveIn.DataAvailable += waveIn_DataAvailableEvent; waveIn.WaveFormat = new WaveFormat(48000, 16, 1); waveIn.StartRecording(); }
public AudioEncoder(Codec codec) { Util.Init(ref opusQueue); Codec = codec; switch (codec) { case Codec.SpeexNarrowband: throw new NotSupportedException(); case Codec.SpeexWideband: throw new NotSupportedException(); case Codec.SpeexUltraWideband: throw new NotSupportedException(); case Codec.CeltMono: throw new NotSupportedException(); case Codec.OpusVoice: SampleRate = 48000; Channels = 1; opusEncoder = OpusEncoder.Create(SampleRate, Channels, Application.Voip); Bitrate = 8192 * 2; break; case Codec.OpusMusic: SampleRate = 48000; Channels = 2; opusEncoder = OpusEncoder.Create(SampleRate, Channels, Application.Audio); Bitrate = 8192 * 4; break; default: throw new ArgumentOutOfRangeException(nameof(codec)); } BitsPerSample = 16; OptimalPacketSize = opusEncoder.FrameByteCount(SegmentFrames); segment = new byte[OptimalPacketSize]; }
private void CreateEncoder() { _Encoder = OpusEncoder.Create(outputSampleRate, channels, opusMode); _Encoder.Bitrate = bitRate * channels; _bytesPerSegment = _Encoder.FrameByteCount(_segmentFrames); }
private void button1_Click(object sender, EventArgs e) { playersForm.StopAll(); Remote remote = settings.Remotes[comboBox1.SelectedIndex]; try { farEnd = remote.GetIPEndPoint(); } catch { MessageBox.Show("This is not a valid IP Address"); return; } button2.Enabled = true; button1.Enabled = false; label5.Visible = true; segmentFrames = 960; encoder = OpusEncoder.Create(48000, 1, FragLabs.Audio.Codecs.Opus.Application.Audio); Decoder = new DGDecoder(remote.CodecType, 48000, 1); encoder.Bitrate = 64000; bytesPerSegment = encoder.FrameByteCount(segmentFrames); waveIn = new WaveIn(WaveCallbackInfo.FunctionCallback()); waveIn.DeviceNumber = inputList.SelectedIndex; waveIn.DataAvailable += waveIn_DataAvailable; waveIn.WaveFormat = new WaveFormat(48000, 16, 1); liveInput = new BufferedWaveProvider(waveIn.WaveFormat); List <ISampleProvider> sampleProviders = new List <ISampleProvider>(); sampleProviders.Add(liveInput.ToSampleProvider()); sampleProviders.Add(playersForm.Mixer); MixingSampleProvider = new MixingSampleProvider(sampleProviders); playBuffer = new BufferedWaveProvider(new WaveFormat(44100, 16, 2)); playBuffer.DiscardOnBufferOverflow = true; waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback()); waveOut.DeviceNumber = outputList.SelectedIndex; playersForm.PlaybackDeviceNum = outputList.SelectedIndex; session = new ComrexSession(); session.SetDestination(SDPMediaTypesEnum.audio, farEnd, farEnd); session.OnRtpPacketReceived += Session_OnRtpPacketReceived; session.Start(); killsession = false; waveOut.Init(playBuffer); waveIn.StartRecording(); if (timer == null) { timer = new Timer(); timer.Interval = 100; timer.Tick += timer_Tick; } timer.Start(); comboBox1.Enabled = false; outputList.Enabled = false; inputList.Enabled = false; }
public void Start(string serverIpAddress, string clientID, string inputDevice, string outputDevice) { _startTime = DateTime.Now; callsign = clientID; taskDataPub = new Task(() => TaskDataPub(cancelTokenSource.Token, dataPublishInputQueue, "tcp://" + serverIpAddress + ":60001"), TaskCreationOptions.LongRunning); taskDataPub.Start(); taskDataSub = new Task(() => TaskDataSub(cancelTokenSource.Token, "tcp://" + serverIpAddress + ":60000"), TaskCreationOptions.LongRunning); taskDataSub.Start(); taskAudioPub = new Task(() => TaskAudioPub(cancelTokenSource.Token, audioPublishInputQueue, "tcp://" + serverIpAddress + ":60003"), TaskCreationOptions.LongRunning); taskAudioPub.Start(); taskAudioSub = new Task(() => TaskAudioSub(cancelTokenSource.Token, audioPlaybackQueue, "tcp://" + serverIpAddress + ":60002"), TaskCreationOptions.LongRunning); taskAudioSub.Start(); _segmentFrames = 960; _encoder = OpusEncoder.Create(48000, 1, FragLabs.Audio.Codecs.Opus.Application.Voip); _encoder.Bitrate = 65536; _decoder = OpusDecoder.Create(48000, 1); _bytesPerSegment = _encoder.FrameByteCount(_segmentFrames); _waveIn = new WaveIn(WaveCallbackInfo.FunctionCallback()); _waveIn.BufferMilliseconds = 50; Console.WriteLine("Input device: " + WaveIn.GetCapabilities(0).ProductName); _waveIn.DeviceNumber = MapInputDevice(inputDevice); _waveIn.DataAvailable += _waveIn_DataAvailable; _waveIn.WaveFormat = new WaveFormat(48000, 16, 1); networkAudioBuffers = new List <ClientMixerInput> { new ClientMixerInput() { InUse = false, Provider = new BufferedWaveProvider(new WaveFormat(48000, 16, 1)) //Provider = new BufferedWaveProvider(WaveFormat.CreateIeeeFloatWaveFormat(48000, 1)) }, new ClientMixerInput() { InUse = false, Provider = new BufferedWaveProvider(new WaveFormat(48000, 16, 1)) //Provider = new BufferedWaveProvider(WaveFormat.CreateIeeeFloatWaveFormat(48000, 1)) }, new ClientMixerInput() { InUse = false, Provider = new BufferedWaveProvider(new WaveFormat(48000, 16, 1)) //Provider = new BufferedWaveProvider(WaveFormat.CreateIeeeFloatWaveFormat(48000, 1)) }, new ClientMixerInput() { InUse = false, Provider = new BufferedWaveProvider(new WaveFormat(48000, 16, 1)) //Provider = new BufferedWaveProvider(WaveFormat.CreateIeeeFloatWaveFormat(48000, 1)) } }; mixer = new MixingWaveProvider32(); //mixer.ReadFully = true; foreach (var buffer in networkAudioBuffers) { mixer.AddInputStream(new SampleToWaveProvider(new Equalizer(new WaveToSampleProvider(new Wave16ToFloatProvider(buffer.Provider)), bands))); } //_playBuffer = new BufferedWaveProvider(mixer.WaveFormat); //mixer.AddInputStream(_playBuffer); taskAudioPlayback = new Task(() => TaskAudioPlayback(cancelTokenSource.Token, audioPlaybackQueue), TaskCreationOptions.LongRunning); taskAudioPlayback.Start(); //_waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback()); _waveOut = new WaveOut(); Console.WriteLine("Output device: " + WaveOut.GetCapabilities(0).ProductName); _waveOut.DeviceNumber = MapOutputDevice(outputDevice); _waveOut.DesiredLatency = 200; //Default is 300 //_waveOut.Init(_playBuffer); _waveOut.Init(mixer); _waveOut.Play(); _waveIn.StartRecording(); if (_timer == null) { _timer = new System.Timers.Timer(); _timer.Interval = 1000; _timer.Elapsed += _timer_Elapsed; } _timer.Start(); started = true; }
public void StartEncoding(int mic, int speakers, string guid, InputDeviceManager inputManager, IPAddress ipAddress, int port) { _stop = false; try { InitMixer(); InitAudioBuffers(); //Audio manager should start / stop and cleanup based on connection successfull and disconnect //Should use listeners to synchronise all the state _waveOut = new WaveOut { DesiredLatency = 100, //100ms latency in output buffer DeviceNumber = speakers }; _volumeSampleProvider = new VolumeSampleProvider(_mixing); _volumeSampleProvider.Volume = SpeakerBoost; if (Resample) { var resampler = new WdlResamplingSampleProvider(_volumeSampleProvider, 44100); //resample and output at 44100 _waveOut.Init(resampler); } else { _waveOut.Init(_volumeSampleProvider); } _waveOut.Init(_volumeSampleProvider); _waveOut.Play(); _segmentFrames = SEGMENT_FRAMES; //160 frames is 20 ms of audio _encoder = OpusEncoder.Create(SAMPLE_RATE, 1, Application.Restricted_LowLatency); _decoder = OpusDecoder.Create(SAMPLE_RATE, 1); _bytesPerSegment = _encoder.FrameByteCount(_segmentFrames); _waveIn = new WaveIn(WaveCallbackInfo.FunctionCallback()) { BufferMilliseconds = 80, DeviceNumber = mic }; _waveIn.DataAvailable += _waveIn_DataAvailable; _waveIn.WaveFormat = new WaveFormat(SAMPLE_RATE, 16, 1); //take in at 8000 _udpVoiceHandler = new UdpVoiceHandler(_clientsList, guid, ipAddress, port, _decoder, this, inputManager); var voiceSenderThread = new Thread(_udpVoiceHandler.Listen); voiceSenderThread.Start(); _waveIn.StartRecording(); } catch (Exception ex) { Logger.Error(ex, "Error starting audio Quitting! Error:" + ex.Message); Environment.Exit(1); } }
private void button1_Click(object sender, EventArgs e) { try { farEnd = settings.Remotes[comboBox1.SelectedIndex].GetIPEndPoint(); } catch { MessageBox.Show("This is not a valid IP Address"); return; } button2.Enabled = true; button1.Enabled = false; label5.Visible = true; segmentFrames = 960; encoder = OpusEncoder.Create(48000, 1, FragLabs.Audio.Codecs.Opus.Application.Audio); decoder = OpusDecoder.Create(48000, 1); aacDecoder = new Decode(); encoder.Bitrate = 64000; bytesPerSegment = encoder.FrameByteCount(segmentFrames); waveIn = new WaveIn(WaveCallbackInfo.FunctionCallback()); //waveIn.BufferMilliseconds = 20; waveIn.DeviceNumber = inputList.SelectedIndex; waveIn.DataAvailable += waveIn_DataAvailable; waveIn.WaveFormat = new WaveFormat(48000, 16, 1); playBuffer = new BufferedWaveProvider(new WaveFormat(44100, 16, 2)); playBuffer.DiscardOnBufferOverflow = true; waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback()); waveOut.DeviceNumber = outputList.SelectedIndex; session = new ComrexSession(); session.SetDestination(SDPMediaTypesEnum.audio, farEnd, farEnd); session.OnRtpPacketReceived += Session_OnRtpPacketReceived; //session.addTrack(track); session.Start(); killsession = false; //participant = new RtpParticipant("dennis","DGoLive"); //session = new RtpSession(farEnd, participant, true, true); //rtpsender = session.CreateRtpSender("test", PayloadType.Opus, null); waveOut.Init(playBuffer); waveIn.StartRecording(); if (timer == null) { timer = new Timer(); timer.Interval = 100; timer.Tick += timer_Tick; } timer.Start(); comboBox1.Enabled = false; outputList.Enabled = false; inputList.Enabled = false; }