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); }
public void Dispose() { LibOpus.DestroyEncoder(_encoderPtr); }
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)); }
public int SetControl(OpusCtl ctl, int value) { return(LibOpus.EncoderCtl(_encoderPtr, ctl, value)); }