/// <summary> /// Initializes a new <see cref="OpusEncoder"/> instance, with the specified codec usage tuning, sample rate and channels. /// </summary> /// <param name="optimized">The codec usage tuning.</param> /// <param name="sampleRate">The sample rate in the input audio.</param> /// <param name="audioChannels">The channels in the input audio - mono or stereo.</param> public OpusEncoder(OpusOptimizer optimized, OpusSampleRate sampleRate, OpusAudioChannels audioChannels) { if (!Enum.IsDefined(typeof(OpusOptimizer), optimized)) { throw new ArgumentException("Value is not defined in the enumeration.", nameof(optimized)); } if (!Enum.IsDefined(typeof(OpusSampleRate), sampleRate)) { throw new ArgumentException("Value is not defined in the enumeration.", nameof(sampleRate)); } if (!Enum.IsDefined(typeof(OpusAudioCHannels), audioChannels)) { throw new ArgumentException("Value is not defined in the enumeration.", nameof(audioChannels)); } _handle = FFI.opus_encoder_create((int)sampleRate, (int)audioChannels, (int)optimized, out int error); ThrowIfError(error); Optimized = optimized; SampleRate = sampleRate; AudioChannels = audioChannels; Bitrate = -1; }
private OpusDecoder(double frameSize, OpusSampleRate sampleRate, OpusAudioChannels audioChannels, bool frameSizeWasSpecified) { switch (frameSize) { case 2.5: case 5: case 10: case 20: case 40: case 60: break; default: throw new ArgumentException("Value must be one of the following: 2.5, 5, 10, 20, 40 or 60.", nameof(frameSize)); } if (!Enum.IsDefined(typeof(OpusSampleRate), sampleRate)) { throw new ArgumentException("Value is not defined in the enumeration.", nameof(sampleRate)); } if (!Enum.IsDefined(typeof(OpusAudioCHannels), audioChannels)) { throw new ArgumentException("Value is not defined in the enumeration.", nameof(audioChannels)); } if (frameSizeWasSpecified) { FrameSize = frameSize; } SampleRate = sampleRate; AudioChannels = audioChannels; _samples = GetSampleCount(frameSize); _pcmLength = GetPCMLength(_samples); _handle = FFI.opus_decoder_create((int)sampleRate, (int)audioChannels, out int error); ThrowIfError(error); }
/// <summary> /// Initializes a new <see cref="OpusEncoder"/> instance optimized for speed. /// </summary> /// <param name="sampleRate">The sample rate in the input audio.</param> /// <param name="audioChannels">The channels in the input audio - mono or stereo.</param> public OpusEncoder(OpusSampleRate sampleRate, OpusAudioChannels audioChannels) : this(OpusOptimizer.Speech, sampleRate, audioChannels) { }
/// <summary> /// Initializes a new <see cref="OpusDecoder"/> instance, with the specified sample rate and channels. /// </summary> /// <param name="sampleRate">The sample rate to decode to, 48000, 24000, 16000, 12000 or 8000 Hz.</param> /// <param name="audioChannels">The channels to decode to, mono or stereo.</param> public OpusDecoder(OpusSampleRate sampleRate, OpusAudioChannels audioChannels) : this(60, sampleRate, audioChannels, false) { }