public OpusCodec(int samplerate, int channels, VoiceApplication application) { if (!AllowedSampleRates.Contains(samplerate)) { throw new ArgumentOutOfRangeException(nameof(samplerate), string.Concat("Sample rate must be one of ", string.Join(", ", AllowedSampleRates))); } if (!AllowedChannelCounts.Contains(channels)) { throw new ArgumentOutOfRangeException(nameof(channels), string.Concat("Channel count must be one of ", string.Join(", ", AllowedChannelCounts))); } this.SampleRate = samplerate; this.Channels = channels; this.Application = application; var err = OpusError.OPUS_OK; this.Encoder = CreateEncoder(this.SampleRate, this.Channels, (int)this.Application, out err); this.Errors = err; if (this.Errors != OpusError.OPUS_OK) { throw new Exception(this.Errors.ToString()); } }
// Token: 0x06000165 RID: 357 RVA: 0x00004858 File Offset: 0x00002A58 public Opus(AudioFormat audioFormat) { if (!audioFormat.IsValid()) { throw new ArgumentException("Invalid audio format specified.", "audioFormat"); } this.AudioFormat = audioFormat; this.Encoder = Interop.OpusCreateEncoder(this.AudioFormat); OpusSignal value = OpusSignal.Auto; VoiceApplication voiceApplication = this.AudioFormat.VoiceApplication; if (voiceApplication != VoiceApplication.Voice) { if (voiceApplication == VoiceApplication.Music) { value = OpusSignal.Music; } } else { value = OpusSignal.Voice; } Interop.OpusSetEncoderOption(this.Encoder, OpusControl.SetSignal, (int)value); Interop.OpusSetEncoderOption(this.Encoder, OpusControl.SetPacketLossPercent, 15); Interop.OpusSetEncoderOption(this.Encoder, OpusControl.SetInBandFec, 1); Interop.OpusSetEncoderOption(this.Encoder, OpusControl.SetBitrate, 131072); this.ManagedDecoders = new List <OpusDecoder>(); }
public OpusCodec(int sampleRate, int channels, VoiceApplication application) { if (!AllowedSampleRates.Contains(sampleRate)) { throw new ArgumentOutOfRangeException(nameof(sampleRate), string.Concat("Sample rate must be one of ", string.Join(", ", AllowedSampleRates))); } if (!AllowedChannelCounts.Contains(channels)) { throw new ArgumentOutOfRangeException(nameof(channels), string.Concat("Channel count must be one of ", string.Join(", ", AllowedChannelCounts))); } this.SampleRate = sampleRate; this.Channels = channels; this.Application = application; this.Encoder = CreateEncoder(this.SampleRate, this.Channels, (int)this.Application, out var err); this.CheckForError(err); var sig = OpusSignal.Auto; switch (application) { case VoiceApplication.Music: sig = OpusSignal.Music; break; case VoiceApplication.Voice: sig = OpusSignal.Voice; break; } err = EncoderControl(this.Encoder, OpusControl.SetSignal, (int)sig); this.CheckForError(err); err = EncoderControl(this.Encoder, OpusControl.SetPacketLossPercent, 15); this.CheckForError(err); err = EncoderControl(this.Encoder, OpusControl.SetInBandFec, 1); this.CheckForError(err); err = EncoderControl(this.Encoder, OpusControl.SetBitrate, 131072); this.CheckForError(err); #if !NETSTANDARD1_1 this.Decoder = CreateDecoder(this.SampleRate, this.Channels, out err); this.CheckForError(err); #endif }
/// <summary> /// Creates a new audio format for use with Opus encoder. /// </summary> /// <param name="sampleRate">Audio sampling rate in Hz.</param> /// <param name="channelCount">Number of audio channels in the data.</param> /// <param name="voiceApplication">Encoder preset to use.</param> // Token: 0x06000008 RID: 8 RVA: 0x00002084 File Offset: 0x00000284 public AudioFormat(int sampleRate = 48000, int channelCount = 2, VoiceApplication voiceApplication = VoiceApplication.Music) { if (!AudioFormat.AllowedSampleRates.Contains(sampleRate)) { throw new ArgumentOutOfRangeException("sampleRate", "Invalid sample rate specified."); } if (!AudioFormat.AllowedChannelCounts.Contains(channelCount)) { throw new ArgumentOutOfRangeException("channelCount", "Invalid channel count specified."); } if (voiceApplication != VoiceApplication.Music && voiceApplication != VoiceApplication.Voice && voiceApplication != VoiceApplication.LowLatency) { throw new ArgumentOutOfRangeException("voiceApplication", "Invalid voice application specified."); } this.SampleRate = sampleRate; this.ChannelCount = channelCount; this.VoiceApplication = voiceApplication; }