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(); } }
public AecPc(int filterLengthInSamples, int samplesPerFrame, int samplesPerSecond) { // Default settings. aecConfig = new AecConfig(filterLengthInSamples, samplesPerFrame, samplesPerSecond); aecConfig.NlpMode = AecNlpMode.KAecNlpModerate; aecConfig.SkewMode = false; aecConfig.MetricsMode = false; farendOld = new List <short[]> { new short[aecConfig.SamplesPerFrame], new short[aecConfig.SamplesPerFrame] }; set_config(aecConfig); aec = new AecCore(aecConfig); farendBuf = new RingBuffer(aecConfig.BufSizeSamp); //if (WebRtcAec_CreateResampler(&aecpc->resampler) == -1) sampFreq = 16000; scSampFreq = 48000; //WebRtcAec_InitResampler(aecpc->resampler, aecpc->scSampFreq) splitSampFreq = sampFreq; skewFrCtr = 0; activity = 0; delayChange = 1; delayCtr = 0; sum = 0; counter = 0; checkBuffSize = true; firstVal = 0; ECstartup = true; bufSizeStart = 0; checkBufSizeCtr = 0; filtDelay = 0; timeForDelayChange = 0; knownDelay = 0; lastDelayDiff = 0; skew = 0; resample = false; highSkewCtr = 0; sampFactor = (scSampFreq * 1.0f) / splitSampFreq; }
/// <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); }