public void Dispose()
 {
     if (_decoder != null)
         _decoder.Dispose();
     if (_encoder != null)
         _encoder.Dispose();
     _decoder = null;
     _encoder = null;
 }
        public VoipCodecOpus(int sampleRate, int bitrate, string description, VoipCodecMode mode = VoipCodecMode.Both)
        {
            _bitrate = bitrate;
            _segmentLength = sampleRate / 25;// 2 bytes per sample, 20ms per segment
            _recordingFormat = new WaveFormat(sampleRate, 16, 1);
            _description = description;

            if (mode.HasFlag(VoipCodecMode.Decode))
                _decoder = OpusDecoder.Create(sampleRate, 1);

            if (mode.HasFlag(VoipCodecMode.Encode))
            {
                _encoder = OpusEncoder.Create(sampleRate, 1, OpusAPI.Application.Voip);
                // 16kHz sample rate is 32kB/s raw.
                // Compressed bitrates:
                // 32768 is 4kB/s
                // 24800 is 3kB/s (3100B/s, same as Speex 16kHz)
                // 8192 is 1kB/s
                _encoder.Bitrate = bitrate;
                _encoderInputBuffer = new byte[_recordingFormat.AverageBytesPerSecond]; // more than enough
            }
        }