Exemple #1
0
        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();
        }
Exemple #2
0
        void StartEncoding()
        {
            _startTime     = DateTime.Now;
            _bytesSent     = 0;
            _segmentFrames = 960;
            var channels = 1;

            _encoder         = Codec.OpusEncoder.Create(48000, channels, Codec.Opus.Application.Voip);
            _encoder.Bitrate = 8192;
            _decoder         = Codec.OpusDecoder.Create(48000, channels);
            _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, channels);

            _playBuffer = new BufferedWaveProvider(new WaveFormat(48000, 16, channels));

            _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();
        }
Exemple #3
0
 void StopEncoding()
 {
     _timer.Stop();
     _waveIn.StopRecording();
     _waveIn.Dispose();
     _waveIn = null;
     _waveOut.Stop();
     _waveOut.Dispose();
     _waveOut    = null;
     _playBuffer = null;
     _encoder.Dispose();
     _encoder = null;
     _decoder.Dispose();
     _decoder = null;
 }
Exemple #4
0
 private void CreateEncoder()
 {
     _Encoder = OpusEncoder.Create(outputSampleRate, channels, opusMode);
     _Encoder.Bitrate = bitRate * channels;
     _bytesPerSegment = _Encoder.FrameByteCount(_segmentFrames);
 }
Exemple #5
0
        public void Dispose()
        {
            var e = Encoder;
            var d = _Decoder;

            _Encoder = null;
            _Decoder = null;

            if (e != null)
                e.Dispose();
            if (d != null)
                d.Dispose();
        }
Exemple #6
0
 void StopEncoding()
 {
     _timer.Stop();
     _waveIn.StopRecording();
     _waveIn.Dispose();
     _waveIn = null;
     _waveOut.Stop();
     _waveOut.Dispose();
     _waveOut = null;
     _playBuffer = null;
     _encoder.Dispose();
     _encoder = null;
     _decoder.Dispose();
     _decoder = null;
 }
Exemple #7
0
        public byte[] Encode(byte[] data)
        {
            if (data == null)
                throw new ArgumentNullException("data");

            if (this.encoder == null) {
                lock (this.codecLock) {
                    if (this.encoder == null) {
                        this.encoder = OpusEncoder.Create (this.settings.SampleRate, this.settings.Channels, Application.Voip);
                        this.encoder.Bitrate = this.settings.Bitrate;
                    }
                }
            }

            int encodedLength;
            byte[] encoded = this.encoder.Encode (data, data.Length, out encodedLength);
            if (encoded.Length != encodedLength) {
                byte[] final = new byte[encodedLength];
                Buffer.BlockCopy (encoded, 0, final, 0, encodedLength);
                encoded = final;
            }

            return encoded;
        }