Пример #1
0
        /// <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>
        public AudioFormat(int sampleRate = 48000, int channelCount = 2, VoiceApplication voiceApplication = VoiceApplication.Music)
        {
            if (!AllowedSampleRates.Contains(sampleRate))
            {
                throw new ArgumentOutOfRangeException(nameof(sampleRate), "Invalid sample rate specified.");
            }

            if (!AllowedChannelCounts.Contains(channelCount))
            {
                throw new ArgumentOutOfRangeException(nameof(channelCount), "Invalid channel count specified.");
            }

            if (voiceApplication != VoiceApplication.Music && voiceApplication != VoiceApplication.Voice && voiceApplication != VoiceApplication.LowLatency)
            {
                throw new ArgumentOutOfRangeException(nameof(voiceApplication), "Invalid voice application specified.");
            }

            this.SampleRate       = sampleRate;
            this.ChannelCount     = channelCount;
            this.VoiceApplication = voiceApplication;
        }
Пример #2
0
 internal bool IsValid()
 => AllowedSampleRates.Contains(this.SampleRate) && AllowedChannelCounts.Contains(this.ChannelCount) &&
 (this.VoiceApplication == VoiceApplication.Music || this.VoiceApplication == VoiceApplication.Voice || this.VoiceApplication == VoiceApplication.LowLatency);