WebRTC音视频之噪音消除功能
WebRTC对于iOS和Android的音频处理,是有很大的不同的,WebRTC基本上是使用的iOS自身的音频降噪、环境音处理、人声增益处理,因为WebRTC认为iOS的音频处理已经满足相对理想的效果,所以在算法处理上进行了iOS和Android的区分。
但是我研究发现,如果将WebRTC用于Android的算法,也用于iOS,在部分手机上还是有相当的效果,现在就是将修改的噪音消除的代码奉上,以供参考。
bool WebRtcVoiceEngine::ApplyOptions(const AudioOptions& options_in) {RTC_DCHECK(worker_thread_checker_.IsCurrent());RTC_LOG(LS_INFO) << "WebRtcVoiceEngine::ApplyOptions: "<< options_in.ToString();AudioOptions options = options_in; // The options are modified below.// Set and adjust echo canceller options.// kEcConference is AEC with high suppression.webrtc::EcModes ec_mode = webrtc::kEcConference;#if defined(WEBRTC_IOS)if (options.ios_force_software_aec_HACK &&*options.ios_force_software_aec_HACK) {// EC may be forced on for a device known to have non-functioning platform// AEC.options.echo_cancellation = true;RTC_LOG(LS_WARNING)<< "Force software AEC on iOS. May conflict with platform AEC.";} else {// On iOS, VPIO provides built-in EC.options.echo_cancellation = false;RTC_LOG(LS_INFO) << "Always disable AEC on iOS. Use built-in instead.";}
#elif defined(WEBRTC_ANDROID)ec_mode = webrtc::kEcAecm;
#endif// Set and adjust noise suppressor options.
#if defined(WEBRTC_IOS)// On iOS, VPIO provides built-in NS.//修改处//options.noise_suppression = false;options.typing_detection = false;options.experimental_ns = false;RTC_LOG(LS_INFO) << "Always disable NS on iOS. Use built-in instead.";
#elif defined(WEBRTC_ANDROID)options.typing_detection = false;options.experimental_ns = false;
#endif// Set and adjust gain control options.
#if defined(WEBRTC_IOS)// On iOS, VPIO provides built-in AGC.//修改处//options.auto_gain_control = false;options.experimental_agc = false;RTC_LOG(LS_INFO) << "Always disable AGC on iOS. Use built-in instead.";
#elif defined(WEBRTC_ANDROID)options.experimental_agc = false;
#endif#if defined(WEBRTC_IOS) || defined(WEBRTC_ANDROID)// Turn off the gain control if specified by the field trial.// The purpose of the field trial is to reduce the amount of resampling// performed inside the audio processing module on mobile platforms by// whenever possible turning off the fixed AGC mode and the high-pass filter.// (https://bugs.chromium.org/p/webrtc/issues/detail?id=6181).if (webrtc::field_trial::IsEnabled("WebRTC-Audio-MinimizeResamplingOnMobile")) {options.auto_gain_control = false;RTC_LOG(LS_INFO) << "Disable AGC according to field trial.";if (!(options.noise_suppression.value_or(false) ||options.echo_cancellation.value_or(false))) {// If possible, turn off the high-pass filter.RTC_LOG(LS_INFO)<< "Disable high-pass filter in response to field trial.";options.highpass_filter = false;}}
#endifif (options.echo_cancellation) {// Check if platform supports built-in EC. Currently only supported on// Android and in combination with Java based audio layer.// TODO(henrika): investigate possibility to support built-in EC also// in combination with Open SL ES audio.const bool built_in_aec = adm()->BuiltInAECIsAvailable();if (built_in_aec) {// Built-in EC exists on this device. Enable/Disable it according to the// echo_cancellation audio option.const bool enable_built_in_aec = *options.echo_cancellation;if (adm()->EnableBuiltInAEC(enable_built_in_aec) == 0 &&enable_built_in_aec) {// Disable internal software EC if built-in EC is enabled,// i.e., replace the software EC with the built-in EC.options.echo_cancellation = false;RTC_LOG(LS_INFO)<< "Disabling EC since built-in EC will be used instead";}}webrtc::apm_helpers::SetEcStatus(apm(), *options.echo_cancellation,ec_mode);}if (options.auto_gain_control) {bool built_in_agc_avaliable = adm()->BuiltInAGCIsAvailable();if (built_in_agc_avaliable) {if (adm()->EnableBuiltInAGC(*options.auto_gain_control) == 0 &&*options.auto_gain_control) {// Disable internal software AGC if built-in AGC is enabled,// i.e., replace the software AGC with the built-in AGC.options.auto_gain_control = false;RTC_LOG(LS_INFO)<< "Disabling AGC since built-in AGC will be used instead";}}}if (options.noise_suppression) {if (adm()->BuiltInNSIsAvailable()) {bool builtin_ns = *options.noise_suppression;if (adm()->EnableBuiltInNS(builtin_ns) == 0 && builtin_ns) {// Disable internal software NS if built-in NS is enabled,// i.e., replace the software NS with the built-in NS.options.noise_suppression = false;RTC_LOG(LS_INFO)<< "Disabling NS since built-in NS will be used instead";}}}if (options.stereo_swapping) {RTC_LOG(LS_INFO) << "Stereo swapping enabled? " << *options.stereo_swapping;audio_state()->SetStereoChannelSwapping(*options.stereo_swapping);}if (options.audio_jitter_buffer_max_packets) {RTC_LOG(LS_INFO) << "NetEq capacity is "<< *options.audio_jitter_buffer_max_packets;audio_jitter_buffer_max_packets_ =std::max(20, *options.audio_jitter_buffer_max_packets);}if (options.audio_jitter_buffer_fast_accelerate) {RTC_LOG(LS_INFO) << "NetEq fast mode? "<< *options.audio_jitter_buffer_fast_accelerate;audio_jitter_buffer_fast_accelerate_ =*options.audio_jitter_buffer_fast_accelerate;}if (options.audio_jitter_buffer_min_delay_ms) {RTC_LOG(LS_INFO) << "NetEq minimum delay is "<< *options.audio_jitter_buffer_min_delay_ms;audio_jitter_buffer_min_delay_ms_ =*options.audio_jitter_buffer_min_delay_ms;}if (options.audio_jitter_buffer_enable_rtx_handling) {RTC_LOG(LS_INFO) << "NetEq handle reordered packets? "<< *options.audio_jitter_buffer_enable_rtx_handling;audio_jitter_buffer_enable_rtx_handling_ =*options.audio_jitter_buffer_enable_rtx_handling;}webrtc::Config config;if (options.experimental_ns) {experimental_ns_ = options.experimental_ns;}if (experimental_ns_) {RTC_LOG(LS_INFO) << "Experimental ns is enabled? " << *experimental_ns_;config.Set<webrtc::ExperimentalNs>(new webrtc::ExperimentalNs(*experimental_ns_));}webrtc::AudioProcessing::Config apm_config = apm()->GetConfig();if (options.auto_gain_control) {const bool enabled = *options.auto_gain_control;apm_config.gain_controller1.enabled = enabled;RTC_LOG(LS_INFO) << "Setting AGC to " << enabled;}if (options.tx_agc_target_dbov) {apm_config.gain_controller1.target_level_dbfs = *options.tx_agc_target_dbov;}if (options.tx_agc_digital_compression_gain) {apm_config.gain_controller1.compression_gain_db =*options.tx_agc_digital_compression_gain;}if (options.tx_agc_limiter) {apm_config.gain_controller1.enable_limiter = *options.tx_agc_limiter;}if (options.highpass_filter) {apm_config.high_pass_filter.enabled = *options.highpass_filter;}if (options.residual_echo_detector) {apm_config.residual_echo_detector.enabled = *options.residual_echo_detector;}if (options.noise_suppression) {const bool enabled = *options.noise_suppression;apm_config.noise_suppression.enabled = enabled;apm_config.noise_suppression.level =webrtc::AudioProcessing::Config::NoiseSuppression::Level::kHigh;RTC_LOG(LS_INFO) << "NS set to " << enabled;}if (options.typing_detection) {RTC_LOG(LS_INFO) << "Typing detection is enabled? "<< *options.typing_detection;apm_config.voice_detection.enabled = *options.typing_detection;}apm()->SetExtraOptions(config);apm()->ApplyConfig(apm_config);return true;
}
使用方式:
NSMutableDictionary *mandatory = [NSMutableDictionary dictionary];if (_closeNoiseSuppression) {[mandatory setValue:@"false" forKey:@"googNoiseSuppression"];[mandatory setValue:@"false" forKey:@"googAutoGainControl"];}NSMutableDictionary *optional = [NSMutableDictionary dictionary];RTCMediaConstraints *constraints = [[RTCMediaConstraints alloc] initWithMandatoryConstraints:mandatory optionalConstraints:optional];_audioSource = [_factory audioSourceWithConstraints:constraints];_audioTrack = [_factory audioTrackWithSource:_audioSource trackId:kSmoothAudioTrackId];
WebRTC音视频之噪音消除功能相关推荐
- 转:Android IOS WebRTC 音视频开发总结 (系列文章集合)
随笔分类 - webrtc Android IOS WebRTC 音视频开发总结(七八)-- 为什么WebRTC端到端监控很关键? 摘要: 本文主要介绍WebRTC端到端监控(我们翻译和整理的,译者: ...
- Android IOS WebRTC 音视频开发
转 自:http://www.cnblogs.com/lingyunhu/category/626157.html 作者:lingyunhu rtc.blacker@gmail.com 随笔分类 - ...
- Android IOS WebRTC 音视频开发总结(四一)-- QQ和webrtc打洞能力pk
Android IOS WebRTC 音视频开发总结(四一)-- QQ和webrtc打洞能力pk 很多人知道webrtc打洞能力很强,到底有多强但是不知道,比较好的方法就是跟QQ对比,但大多数公司很难 ...
- Android IOS WebRTC 音视频开发总结(五一)-- 降噪基本原理
Android IOS WebRTC 音视频开发总结(五一)-- 降噪基本原理 文章主要介绍噪声消除,文章来自博客园RTC.Blacker,支持原创,转载必须说明出处,欢迎关注微信公众号blacker ...
- python音视频开发_Python音视频开发:消除抖音短视频Logo的图形化工具实现
一.引言 在<Python音视频开发:消除抖音短视频Logo和去电视台标的实现详解>节介绍了怎么通过Python+Moviepy+OpenCV实现消除视频Logo的四种方法,并提供了详细的 ...
- Python音视频开发:消除抖音短视频Logo的图形化工具实现
☞ ░ 前往老猿Python博文目录 ░ 一.引言 在<Python音视频开发:消除抖音短视频Logo和去电视台标的实现详解>节介绍了怎么通过Python+Moviepy+OpenCV实现 ...
- webRTC(四):Webrtc音视频数据采集录制采集屏面数据
WebRTC音视频数据采集 var constraints={video: true,audio: true,}navigator.mediaDevices.getUserMedia(constrai ...
- Android IOS WebRTC 音视频开发总结
Android IOS WebRTC 音视频开发总结(八十五)-- 使用WebRTC广播网络摄像头视频(下) RTC.Blacker 2016-09-13 11:18 阅读:132 评论:0 An ...
- Android IOS WebRTC 音视频开发总结(三八)-- tx help
Android IOS WebRTC 音视频开发总结(三八)-- tx help 本文主要介绍帮一个程序员解决webrtc疑问的过程,文章来自博客园RTC.Blacker,支持原创,转载请说明出处(w ...
最新文章
- nginx LB服务器配置
- 迁移学习的魔法:任何人都将能使用深度学习
- 不要光仅仅知道ipconfig了,你out了
- BCGControlBar使用(九)
- Java IO: PipedOutputStream
- 切记!构造函数里面别一定不要初始化其他类,踩过坑的都知道
- 解决Javascript疲劳的方法-以及其他所有疲劳
- (pytorch-深度学习系列)卷积神经网络中的填充(padding)和步幅(stride)
- Linux网络协议栈(三)——网络设备(1)
- Sql Server系列:键和约束
- 通俗易懂理解朴素贝叶斯分类的拉普拉斯平滑
- 使用struct与typedef定义结构体
- 虚幻引擎5亮点整理,5大核心一目了然
- JMeter下载和安装
- structs2本地(国际)化
- 2B市场 面向2025年技术趋势与5大机会
- 两个线程交替打印A1B2C3D4E5输出,6种实现方式
- python人像录制加声音_Python自动化测试入门必读
- 学习使用ffmpeg命令给视频添加一张设计好的背景图片
- python小练习6--lambda表达式的使用