public OpusEncoder(SamplingRate inputSamplingRateHz, Channels numChannels, OpusApplicationType applicationType, Delay encoderDelay) { if ((inputSamplingRateHz != SamplingRate.Sampling08000) && (inputSamplingRateHz != SamplingRate.Sampling12000) && (inputSamplingRateHz != SamplingRate.Sampling16000) && (inputSamplingRateHz != SamplingRate.Sampling24000) && (inputSamplingRateHz != SamplingRate.Sampling48000)) { throw new ArgumentOutOfRangeException("inputSamplingRateHz", "Must use one of the pre-defined sampling rates"); } if ((numChannels != Channels.Mono) && (numChannels != Channels.Stereo)) { throw new ArgumentOutOfRangeException("numChannels", "Must be Mono or Stereo"); } if ((applicationType != OpusApplicationType.Audio) && (applicationType != OpusApplicationType.RestrictedLowDelay) && (applicationType != OpusApplicationType.Voip)) { throw new ArgumentOutOfRangeException("applicationType", "Must use one of the pre-defined application types"); } if ((encoderDelay != Delay.Delay10ms) && (encoderDelay != Delay.Delay20ms) && (encoderDelay != Delay.Delay2dot5ms) && (encoderDelay != Delay.Delay40ms) && (encoderDelay != Delay.Delay5ms) && (encoderDelay != Delay.Delay60ms)) { throw new ArgumentOutOfRangeException("encoderDelay", "Must use one of the pre-defined delay values"); } _inputSamplingRate = inputSamplingRateHz; _inputChannels = numChannels; _handle = Wrapper.opus_encoder_create(inputSamplingRateHz, numChannels, applicationType); _version = Wrapper.opus_get_version(); if (_handle == IntPtr.Zero) { throw new OpusException(OpusStatusCode.AllocFail, "Memory was not allocated for the encoder"); } EncoderDelay = encoderDelay; }
public static IntPtr opus_encoder_create(SamplingRate Fs, Channels channels, OpusApplicationType application) { int size = Wrapper.opus_encoder_get_size(channels); IntPtr ptr = Marshal.AllocHGlobal(size); OpusStatusCode statusCode = Wrapper.opus_encoder_init(ptr, Fs, channels, application); try { HandleStatusCode(statusCode); } catch (Exception ex) { if (ptr != IntPtr.Zero) { Wrapper.opus_encoder_destroy(ptr); ptr = IntPtr.Zero; } throw ex; } return(ptr); }
public OpusEncoder(SamplingRate inputSamplingRateHz, Channels numChannels, int bitrate, OpusApplicationType applicationType) : this(inputSamplingRateHz, numChannels, bitrate, applicationType, Delay.Delay20ms) { }
private static extern OpusStatusCode opus_encoder_init(IntPtr st, SamplingRate Fs, Channels channels, OpusApplicationType application);
internal static extern OpusStatusCode opus_encoder_init( [In] this Encoder st, [In] SamplingRate Fs, [In] Channels channels, [In] OpusApplicationType application );
opus_encoder_create( [In] SamplingRate Fs, [In] Channels channels, [In] OpusApplicationType application, [Out] out OpusStatusCode error );