private void set_config(AecConfig config) { if (config.SkewMode && config.SkewMode != true) { throw new ArgumentException(); } skewMode = config.SkewMode; if (config.NlpMode != AecNlpMode.KAecNlpConservative && config.NlpMode != AecNlpMode.KAecNlpModerate && config.NlpMode != AecNlpMode.KAecNlpAggressive) { throw new ArgumentException(); } nlpMode = config.NlpMode; aec.targetSupp = WebRtcConstants.targetSupp[(int)nlpMode]; aec.minOverDrive = WebRtcConstants.minOverDrive[(int)nlpMode]; if (config.MetricsMode && config.MetricsMode != true) { throw new ArgumentException(); } aec.metricsMode = config.MetricsMode; if (aec.metricsMode) { aec.InitMetrics(); } }
/// <summary> /// Constructs an instance of the WebRtcFilter. /// </summary> /// <param name="expectedAudioLatency">The expected audio latency in milliseconds</param> /// <param name="filterLength">The length of the echo cancellation filter in milliseconds</param> /// <param name="recordedAudioFormat">The audio format into which the recorded audio has been transformed prior to encoding (e.g., not the raw audio)</param> /// <param name="playedAudioFormat">The audio format which the audio must be transformed after decoding and before playing</param> /// <param name="enableAec">Whether to enable acoustic echo cancellation</param> /// <param name="enableDenoise">Whether to enable denoising</param> /// <param name="enableAgc">Whether to enable automatic gain control</param> /// <param name="playedResampler">The resampler which should be used on played audio</param> /// <param name="recordedResampler">The resampler which should be used on recorded audio</param> public WebRtcFilter(int expectedAudioLatency, int filterLength, AudioFormat recordedAudioFormat, AudioFormat playedAudioFormat, bool enableAec, bool enableDenoise, bool enableAgc, IAudioFilter playedResampler = null, IAudioFilter recordedResampler = null) : base(expectedAudioLatency, filterLength, recordedAudioFormat, playedAudioFormat, playedResampler, recordedResampler) { // Default settings. var aecConfig = new AecConfig(FilterLength, recordedAudioFormat.SamplesPerFrame, recordedAudioFormat.SamplesPerSecond) { NlpMode = AecNlpMode.KAecNlpModerate, SkewMode = false, MetricsMode = false }; _ns = new NoiseSuppressor(recordedAudioFormat); _aec = new AecCore(aecConfig); if (aecConfig.NlpMode != AecNlpMode.KAecNlpConservative && aecConfig.NlpMode != AecNlpMode.KAecNlpModerate && aecConfig.NlpMode != AecNlpMode.KAecNlpAggressive) { throw new ArgumentException(); } _aec.targetSupp = WebRtcConstants.targetSupp[(int)aecConfig.NlpMode]; _aec.minOverDrive = WebRtcConstants.minOverDrive[(int)aecConfig.NlpMode]; if (aecConfig.MetricsMode && aecConfig.MetricsMode != true) { throw new ArgumentException(); } _aec.metricsMode = aecConfig.MetricsMode; if (_aec.metricsMode) { _aec.InitMetrics(); } _enableAec = enableAec; _enableDenoise = enableDenoise; _enableAgc = enableAgc; _agc = new Agc(0, 255, Agc.AgcMode.AgcModeAdaptiveDigital, (uint)recordedAudioFormat.SamplesPerSecond); }