Exemple #1
0
        public LibOpusEncoder(int sampleRate, int channels, int bitRate, int frameDelay)
        {
            _sampleRate = sampleRate;
            // _channels = channels;
            // _bitRate = bitRate;
            _frameDelay          = frameDelay;
            _frameSizePerChannel = _sampleRate * _frameDelay / 1000;

            _encoderPtr = LibOpus.CreateEncoder(sampleRate, channels, (int)OpusApplication.Audio, out var error);
            if (error != OpusError.OK)
            {
                throw new ExternalException(error.ToString());
            }

            LibOpus.EncoderCtl(_encoderPtr, OpusCtl.SetSignal, (int)OpusSignal.Music);
            LibOpus.EncoderCtl(_encoderPtr, OpusCtl.SetInbandFEC, 1);
            LibOpus.EncoderCtl(_encoderPtr, OpusCtl.SetBitrate, bitRate);
            LibOpus.EncoderCtl(_encoderPtr, OpusCtl.SetPacketLossPerc, 2);
        }
Exemple #2
0
 public void Dispose()
 {
     LibOpus.DestroyEncoder(_encoderPtr);
 }
Exemple #3
0
 public int EncodeFloat(Span <byte> input, byte[] output)
 {
     fixed(byte *inPtr = input)
     fixed(byte *outPtr = output)
     return(LibOpus.EncodeFloat(_encoderPtr, inPtr, FrameSizePerChannel, outPtr, output.Length));
 }
Exemple #4
0
 public int SetControl(OpusCtl ctl, int value)
 {
     return(LibOpus.EncoderCtl(_encoderPtr, ctl, value));
 }