From b5c48b97f653e1b3d62bc484bde7372f91397eac Mon Sep 17 00:00:00 2001 From: Arun Raghavan Date: Tue, 24 Dec 2024 19:32:07 -0500 Subject: [PATCH] Bump to WebRTC M131 release Ongoing fixes and improvements, transient suppressor is gone. Also, dropping isac because it doesn't seem to be useful, and is just build system deadweight now. Upstream references: Version: 131.0.6778.200 WebRTC: 79aff54b0fa9238ce3518dd9eaf9610cd6f22e82 Chromium: 2a19506ad24af755f2a215a4c61f775393e0db42 --- .gitlab-ci.yml | 2 - meson.build | 20 - webrtc/BUILD.gn | 124 +- webrtc/api/array_view.h | 1 + webrtc/api/audio/audio_frame.cc | 125 +- webrtc/api/audio/audio_frame.h | 77 +- .../include => api/audio}/audio_processing.cc | 5 +- webrtc/api/audio/audio_processing.h | 944 +++++++ .../audio}/audio_processing_statistics.cc | 2 +- .../api/audio/audio_processing_statistics.h | 68 + webrtc/api/audio/audio_view.h | 269 ++ webrtc/api/audio_codecs/audio_decoder.cc | 11 +- webrtc/api/audio_codecs/audio_decoder.h | 8 +- webrtc/api/audio_codecs/audio_encoder.cc | 13 +- webrtc/api/audio_codecs/audio_encoder.h | 37 +- webrtc/api/function_view.h | 1 + webrtc/api/make_ref_counted.h | 18 +- webrtc/api/meson.build | 2 + webrtc/api/ref_count.h | 67 + webrtc/api/ref_counted_base.h | 11 +- webrtc/api/rtp_headers.cc | 15 +- webrtc/api/rtp_headers.h | 49 +- webrtc/api/rtp_packet_info.cc | 11 +- webrtc/api/rtp_packet_info.h | 20 +- webrtc/api/rtp_packet_infos.h | 1 - webrtc/api/scoped_refptr.h | 55 +- webrtc/api/sequence_checker.h | 1 + webrtc/api/task_queue/queued_task.h | 32 - webrtc/api/task_queue/task_queue_base.cc | 3 - webrtc/api/task_queue/task_queue_base.h | 1 - webrtc/api/units/data_rate.cc | 2 + webrtc/api/units/data_rate.h | 20 +- webrtc/api/units/data_size.cc | 2 + webrtc/api/units/data_size.h | 20 +- webrtc/api/units/frequency.cc | 3 + webrtc/api/units/frequency.h | 21 +- webrtc/api/units/time_delta.cc | 2 + webrtc/api/units/time_delta.h | 20 +- webrtc/api/units/timestamp.cc | 2 + webrtc/api/units/timestamp.h | 20 +- webrtc/api/video/color_space.cc | 12 +- webrtc/api/video/color_space.h | 4 +- webrtc/api/video/video_content_type.cc | 2 + webrtc/api/video/video_timing.cc | 2 + webrtc/audio/utility/BUILD.gn | 5 +- .../audio/utility/audio_frame_operations.cc | 152 +- webrtc/audio/utility/audio_frame_operations.h | 39 +- webrtc/common_audio/BUILD.gn | 2 +- webrtc/common_audio/channel_buffer.h | 38 + webrtc/common_audio/include/audio_util.h | 76 +- .../resampler/include/push_resampler.h | 47 +- .../common_audio/resampler/push_resampler.cc | 152 +- .../resampler/push_sinc_resampler.h | 7 + .../signal_processing/filter_ar.c | 4 +- .../include/signal_processing_library.h | 7 +- webrtc/common_audio/smoothing_filter.cc | 4 +- webrtc/common_audio/smoothing_filter.h | 8 +- webrtc/experiments/BUILD.gn | 26 + webrtc/experiments/field_trials.py | 1129 ++++++++ webrtc/experiments/registered_field_trials.h | 67 +- webrtc/modules/BUILD.gn | 3 - webrtc/modules/audio_coding/BUILD.gn | 175 +- .../isac/main/include/audio_decoder_isac.h | 22 - .../isac/main/include/audio_encoder_isac.h | 22 - .../codecs/isac/main/include/isac.h | 617 ----- .../codecs/isac/main/source/arith_routines.c | 60 - .../codecs/isac/main/source/arith_routines.h | 67 - .../isac/main/source/arith_routines_hist.c | 291 --- .../isac/main/source/arith_routines_logist.c | 303 --- .../isac/main/source/audio_decoder_isac.cc | 20 - .../isac/main/source/audio_encoder_isac.cc | 20 - .../isac/main/source/bandwidth_estimator.c | 1013 -------- .../isac/main/source/bandwidth_estimator.h | 165 -- .../codecs/isac/main/source/codec.h | 223 -- .../codecs/isac/main/source/crc.c | 111 - .../codecs/isac/main/source/crc.h | 41 - .../codecs/isac/main/source/decode.c | 303 --- .../codecs/isac/main/source/decode_bwe.c | 89 - .../codecs/isac/main/source/encode.c | 1260 --------- .../codecs/isac/main/source/encode_lpc_swb.c | 706 ----- .../codecs/isac/main/source/encode_lpc_swb.h | 246 -- .../codecs/isac/main/source/entropy_coding.c | 2066 --------------- .../codecs/isac/main/source/entropy_coding.h | 347 --- .../codecs/isac/main/source/filterbanks.c | 114 - .../codecs/isac/main/source/intialize.c | 72 - .../codecs/isac/main/source/isac.c | 2307 ----------------- .../codecs/isac/main/source/isac_float_type.h | 100 - .../codecs/isac/main/source/lattice.c | 219 -- .../codecs/isac/main/source/lpc_analysis.c | 496 ---- .../codecs/isac/main/source/lpc_analysis.h | 46 - .../isac/main/source/lpc_gain_swb_tables.c | 136 - .../isac/main/source/lpc_gain_swb_tables.h | 50 - .../isac/main/source/lpc_shape_swb12_tables.c | 158 -- .../isac/main/source/lpc_shape_swb12_tables.h | 66 - .../isac/main/source/lpc_shape_swb16_tables.c | 247 -- .../isac/main/source/lpc_shape_swb16_tables.h | 81 - .../codecs/isac/main/source/lpc_tables.c | 601 ----- .../codecs/isac/main/source/lpc_tables.h | 99 - .../isac/main/source/pitch_gain_tables.c | 104 - .../isac/main/source/pitch_gain_tables.h | 48 - .../isac/main/source/pitch_lag_tables.c | 277 -- .../isac/main/source/pitch_lag_tables.h | 116 - .../main/source/spectrum_ar_model_tables.c | 139 - .../main/source/spectrum_ar_model_tables.h | 79 - .../codecs/isac/main/source/transform.c | 126 - webrtc/modules/audio_coding/meson.build | 50 - webrtc/modules/audio_processing/BUILD.gn | 133 +- webrtc/modules/audio_processing/aec3/BUILD.gn | 9 +- .../audio_processing/aec3/aec_state.cc | 8 +- .../modules/audio_processing/aec3/aec_state.h | 10 +- .../audio_processing/aec3/block_processor.cc | 6 +- .../audio_processing/aec3/config_selector.cc | 2 +- .../audio_processing/aec3/config_selector.h | 12 +- .../audio_processing/aec3/echo_audibility.cc | 2 +- .../audio_processing/aec3/echo_audibility.h | 5 +- .../audio_processing/aec3/echo_canceller3.cc | 17 +- .../audio_processing/aec3/echo_canceller3.h | 13 +- .../aec3/echo_path_delay_estimator.cc | 6 +- .../aec3/echo_path_delay_estimator.h | 7 +- .../audio_processing/aec3/echo_remover.cc | 4 +- .../audio_processing/aec3/echo_remover.h | 4 +- .../audio_processing/aec3/erle_estimator.h | 4 +- .../aec3/fullband_erle_estimator.cc | 4 +- .../aec3/fullband_erle_estimator.h | 16 +- .../audio_processing/aec3/matched_filter.cc | 127 +- .../audio_processing/aec3/matched_filter.h | 23 +- .../aec3/matched_filter_avx2.cc | 30 +- .../aec3/matched_filter_lag_aggregator.cc | 12 +- .../aec3/matched_filter_lag_aggregator.h | 7 +- .../aec3/multi_channel_content_detector.cc | 6 +- .../aec3/multi_channel_content_detector.h | 5 +- .../aec3/render_delay_buffer.cc | 8 +- .../aec3/render_delay_controller.cc | 25 +- .../aec3/render_delay_controller.h | 5 +- .../aec3/render_delay_controller_metrics.cc | 4 +- .../aec3/render_delay_controller_metrics.h | 7 +- .../aec3/render_signal_analyzer.cc | 8 +- .../aec3/render_signal_analyzer.h | 8 +- .../aec3/residual_echo_estimator.h | 2 +- .../aec3/reverb_decay_estimator.cc | 2 +- .../aec3/reverb_decay_estimator.h | 4 +- .../aec3/reverb_frequency_response.cc | 2 +- .../aec3/reverb_frequency_response.h | 4 +- .../aec3/reverb_model_estimator.cc | 2 +- .../aec3/reverb_model_estimator.h | 4 +- .../aec3/subtractor_output_analyzer.cc | 2 +- .../audio_processing/aec3/suppression_gain.cc | 4 +- .../audio_processing/aec3/suppression_gain.h | 4 +- .../audio_processing/aec3/transparent_mode.cc | 5 +- .../aec_dump/aec_dump_factory.h | 36 +- .../aec_dump/null_aec_dump_factory.cc | 23 +- webrtc/modules/audio_processing/agc/BUILD.gn | 8 +- .../agc/agc_manager_direct.cc | 22 +- .../audio_processing/agc/agc_manager_direct.h | 22 +- webrtc/modules/audio_processing/agc2/BUILD.gn | 50 +- .../agc2/adaptive_digital_gain_controller.cc | 2 +- .../agc2/adaptive_digital_gain_controller.h | 6 +- .../agc2/clipping_predictor.cc | 38 +- .../agc2/clipping_predictor.h | 8 +- .../agc2/clipping_predictor_level_buffer.cc | 6 +- .../agc2/clipping_predictor_level_buffer.h | 5 +- .../agc2/fixed_digital_level_estimator.cc | 24 +- .../agc2/fixed_digital_level_estimator.h | 18 +- .../audio_processing/agc2/gain_applier.cc | 26 +- .../audio_processing/agc2/gain_applier.h | 8 +- .../agc2/input_volume_controller.cc | 14 +- .../agc2/input_volume_controller.h | 14 +- .../agc2/input_volume_stats_reporter.h | 5 +- .../modules/audio_processing/agc2/limiter.cc | 61 +- .../modules/audio_processing/agc2/limiter.h | 21 +- .../agc2/noise_level_estimator.cc | 11 +- .../agc2/noise_level_estimator.h | 4 +- .../audio_processing/agc2/rnn_vad/BUILD.gn | 5 +- .../agc2/saturation_protector_buffer.cc | 4 +- .../agc2/saturation_protector_buffer.h | 4 +- .../agc2/speech_level_estimator.h | 2 +- .../audio_processing/agc2/vad_wrapper.cc | 35 +- .../audio_processing/agc2/vad_wrapper.h | 14 +- .../agc2/vector_float_frame.cc | 28 +- .../agc2/vector_float_frame.h | 17 +- .../modules/audio_processing/audio_buffer.cc | 16 +- .../modules/audio_processing/audio_buffer.h | 14 +- .../audio_processing_builder_impl.cc | 2 +- .../audio_processing/audio_processing_impl.cc | 445 +--- .../audio_processing/audio_processing_impl.h | 112 +- .../echo_control_mobile_impl.cc | 2 +- .../echo_detector/circular_buffer.cc | 4 +- .../echo_detector/circular_buffer.h | 5 +- .../audio_processing/gain_control_impl.cc | 4 +- .../audio_processing/gain_control_impl.h | 6 +- .../audio_processing/gain_controller2.cc | 27 +- .../audio_processing/gain_controller2.h | 9 +- .../audio_processing/include/aec_dump.h | 6 +- .../include/audio_frame_proxies.cc | 2 +- .../include/audio_frame_view.h | 60 +- .../include/audio_processing.h | 929 +------ .../include/audio_processing_statistics.h | 55 +- .../audio_processing/include/config.cc | 23 - .../modules/audio_processing/include/config.h | 131 - .../logging/apm_data_dumper.cc | 2 +- .../logging/apm_data_dumper.h | 5 +- webrtc/modules/audio_processing/meson.build | 14 +- webrtc/modules/audio_processing/ns/BUILD.gn | 2 - .../optionally_built_submodule_creators.cc | 36 - .../optionally_built_submodule_creators.h | 42 - .../residual_echo_detector.cc | 4 +- .../audio_processing/residual_echo_detector.h | 2 +- webrtc/modules/audio_processing/rms_level.cc | 4 +- webrtc/modules/audio_processing/rms_level.h | 5 +- .../audio_processing/transient/BUILD.gn | 133 - .../audio_processing/transient/common.h | 27 - .../transient/daubechies_8_wavelet_coeffs.h | 44 - .../transient/dyadic_decimator.h | 68 - .../audio_processing/transient/file_utils.cc | 257 -- .../audio_processing/transient/file_utils.h | 117 - .../transient/moving_moments.cc | 50 - .../transient/moving_moments.h | 53 - .../transient/transient_detector.cc | 176 -- .../transient/transient_detector.h | 89 - .../transient/transient_suppressor.h | 75 - .../transient/transient_suppressor_impl.cc | 455 ---- .../transient/transient_suppressor_impl.h | 115 - .../transient/voice_probability_delay_unit.cc | 56 - .../transient/voice_probability_delay_unit.h | 43 - .../transient/windows_private.h | 557 ---- .../audio_processing/transient/wpd_node.cc | 72 - .../audio_processing/transient/wpd_node.h | 46 - .../audio_processing/transient/wpd_tree.cc | 118 - .../audio_processing/transient/wpd_tree.h | 92 - webrtc/rtc_base/BUILD.gn | 481 ++-- webrtc/rtc_base/checks.h | 8 +- webrtc/rtc_base/containers/BUILD.gn | 3 +- webrtc/rtc_base/event.cc | 22 +- webrtc/rtc_base/event.h | 4 +- webrtc/rtc_base/event_tracer.cc | 59 +- webrtc/rtc_base/event_tracer.h | 17 +- .../experiments/field_trial_parser.cc | 40 +- .../rtc_base/experiments/field_trial_parser.h | 71 +- webrtc/rtc_base/logging.h | 70 +- webrtc/rtc_base/memory/BUILD.gn | 4 +- webrtc/rtc_base/numerics/safe_compare.h | 1 - webrtc/rtc_base/numerics/safe_minmax.h | 1 + webrtc/rtc_base/platform_thread.cc | 14 +- webrtc/rtc_base/platform_thread.h | 7 +- webrtc/rtc_base/race_checker.h | 11 +- webrtc/rtc_base/ref_count.h | 60 +- webrtc/rtc_base/ref_counted_object.h | 55 +- webrtc/rtc_base/ref_counter.h | 6 +- webrtc/rtc_base/string_encode.cc | 77 +- webrtc/rtc_base/string_encode.h | 45 +- webrtc/rtc_base/string_to_number.cc | 26 +- webrtc/rtc_base/string_to_number.h | 24 +- webrtc/rtc_base/synchronization/BUILD.gn | 13 +- .../rtc_base/synchronization/mutex_pthread.h | 4 +- webrtc/rtc_base/system/BUILD.gn | 2 +- webrtc/rtc_base/system/file_wrapper.cc | 13 +- webrtc/rtc_base/system/file_wrapper.h | 4 +- webrtc/rtc_base/time_utils.h | 4 +- webrtc/rtc_base/trace_event.h | 368 +-- webrtc/rtc_base/type_traits.h | 1 + webrtc/rtc_base/units/unit_base.h | 1 - webrtc/system_wrappers/BUILD.gn | 11 +- webrtc/system_wrappers/source/cpu_features.cc | 4 +- 263 files changed, 4628 insertions(+), 20416 deletions(-) rename webrtc/{modules/audio_processing/include => api/audio}/audio_processing.cc (99%) create mode 100644 webrtc/api/audio/audio_processing.h rename webrtc/{modules/audio_processing/include => api/audio}/audio_processing_statistics.cc (89%) create mode 100644 webrtc/api/audio/audio_processing_statistics.h create mode 100644 webrtc/api/audio/audio_view.h create mode 100644 webrtc/api/ref_count.h delete mode 100644 webrtc/api/task_queue/queued_task.h create mode 100644 webrtc/experiments/BUILD.gn create mode 100755 webrtc/experiments/field_trials.py delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/include/audio_decoder_isac.h delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/include/audio_encoder_isac.h delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/include/isac.h delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/arith_routines.c delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/arith_routines.h delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/arith_routines_hist.c delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/arith_routines_logist.c delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/audio_decoder_isac.cc delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/audio_encoder_isac.cc delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/bandwidth_estimator.c delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/bandwidth_estimator.h delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/codec.h delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/crc.c delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/crc.h delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/decode.c delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/decode_bwe.c delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/encode.c delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/encode_lpc_swb.c delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/encode_lpc_swb.h delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/entropy_coding.c delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/entropy_coding.h delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/filterbanks.c delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/intialize.c delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/isac.c delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/isac_float_type.h delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/lattice.c delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/lpc_analysis.c delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/lpc_analysis.h delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/lpc_gain_swb_tables.c delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/lpc_gain_swb_tables.h delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/lpc_shape_swb12_tables.c delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/lpc_shape_swb12_tables.h delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/lpc_shape_swb16_tables.c delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/lpc_shape_swb16_tables.h delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/lpc_tables.c delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/lpc_tables.h delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/pitch_gain_tables.c delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/pitch_gain_tables.h delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/pitch_lag_tables.c delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/pitch_lag_tables.h delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/spectrum_ar_model_tables.c delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/spectrum_ar_model_tables.h delete mode 100644 webrtc/modules/audio_coding/codecs/isac/main/source/transform.c delete mode 100644 webrtc/modules/audio_processing/include/config.cc delete mode 100644 webrtc/modules/audio_processing/include/config.h delete mode 100644 webrtc/modules/audio_processing/optionally_built_submodule_creators.cc delete mode 100644 webrtc/modules/audio_processing/optionally_built_submodule_creators.h delete mode 100644 webrtc/modules/audio_processing/transient/BUILD.gn delete mode 100644 webrtc/modules/audio_processing/transient/common.h delete mode 100644 webrtc/modules/audio_processing/transient/daubechies_8_wavelet_coeffs.h delete mode 100644 webrtc/modules/audio_processing/transient/dyadic_decimator.h delete mode 100644 webrtc/modules/audio_processing/transient/file_utils.cc delete mode 100644 webrtc/modules/audio_processing/transient/file_utils.h delete mode 100644 webrtc/modules/audio_processing/transient/moving_moments.cc delete mode 100644 webrtc/modules/audio_processing/transient/moving_moments.h delete mode 100644 webrtc/modules/audio_processing/transient/transient_detector.cc delete mode 100644 webrtc/modules/audio_processing/transient/transient_detector.h delete mode 100644 webrtc/modules/audio_processing/transient/transient_suppressor.h delete mode 100644 webrtc/modules/audio_processing/transient/transient_suppressor_impl.cc delete mode 100644 webrtc/modules/audio_processing/transient/transient_suppressor_impl.h delete mode 100644 webrtc/modules/audio_processing/transient/voice_probability_delay_unit.cc delete mode 100644 webrtc/modules/audio_processing/transient/voice_probability_delay_unit.h delete mode 100644 webrtc/modules/audio_processing/transient/windows_private.h delete mode 100644 webrtc/modules/audio_processing/transient/wpd_node.cc delete mode 100644 webrtc/modules/audio_processing/transient/wpd_node.h delete mode 100644 webrtc/modules/audio_processing/transient/wpd_tree.cc delete mode 100644 webrtc/modules/audio_processing/transient/wpd_tree.h diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1e07d60..c176499 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -99,7 +99,6 @@ build-container-aarch64: - DESTDIR=$PWD/_install ninja install -C builddir # Test that the pc files are usable - PKG_CONFIG_PATH=$PWD/_install/usr/lib/pkgconfig pkg-config --cflags --libs webrtc-audio-processing-1 - - PKG_CONFIG_PATH=$PWD/_install/usr/lib/pkgconfig pkg-config --cflags --libs webrtc-audio-coding-1 artifacts: expire_in: '5 days' when: 'always' @@ -116,7 +115,6 @@ build-container-aarch64: - DESTDIR=$PWD/_install ninja install -C builddir # Test that the pc files are usable - PKG_CONFIG_LIBDIR=$PWD/_install/usr/lib/pkgconfig pkg-config --cflags --libs webrtc-audio-processing-1 - - PKG_CONFIG_LIBDIR=$PWD/_install/usr/lib/pkgconfig pkg-config --cflags --libs webrtc-audio-coding-1 artifacts: expire_in: '5 days' when: 'always' diff --git a/meson.build b/meson.build index 57591d5..539d060 100644 --- a/meson.build +++ b/meson.build @@ -21,10 +21,6 @@ apm_major_version = major_version apm_minor_version = minor_version apm_project_name = 'webrtc-audio-processing-' + apm_major_version -ac_major_version = major_version -ac_minor_version = minor_version -ac_project_name = 'webrtc-audio-coding-' + ac_major_version - include_subdir = apm_project_name cc = meson.get_compiler('c') @@ -203,20 +199,4 @@ audio_processing_dep = declare_dependency( meson.override_dependency(apm_project_name, audio_processing_dep) -pkgconfig.generate( - libwebrtc_audio_coding, - description: 'WebRTC Audio Coding library', - subdirs: include_subdir, - extra_cflags: [ - '-DWEBRTC_LIBRARY_IMPL', - ] + platform_cflags, -) - -audio_coding_dep = declare_dependency( - link_with: libwebrtc_audio_coding, - include_directories: [webrtc_inc] -) - -meson.override_dependency(ac_project_name, audio_coding_dep) - subdir('examples') diff --git a/webrtc/BUILD.gn b/webrtc/BUILD.gn index 7e8325e..580d34e 100644 --- a/webrtc/BUILD.gn +++ b/webrtc/BUILD.gn @@ -79,6 +79,9 @@ if (!build_with_chromium) { "video:sv_loopback", "video:video_loopback", ] + if (use_libfuzzer) { + deps += [ "test/fuzzers" ] + } if (!is_asan) { # Do not build :webrtc_lib_link_test because lld complains on some OS # (e.g. when target_os = "mac") when is_asan=true. For more details, @@ -139,10 +142,6 @@ config("common_inherited_config") { cflags = [] ldflags = [] - if (rtc_jni_generator_legacy_symbols) { - defines += [ "RTC_JNI_GENERATOR_LEGACY_SYMBOLS" ] - } - if (rtc_objc_prefix != "") { defines += [ "RTC_OBJC_TYPE_PREFIX=${rtc_objc_prefix}" ] } @@ -174,16 +173,18 @@ config("common_inherited_config") { defines += [ "RTC_ENABLE_WIN_WGC" ] } - # Some tests need to declare their own trace event handlers. If this define is - # not set, the first time TRACE_EVENT_* is called it will store the return - # value for the current handler in an static variable, so that subsequent - # changes to the handler for that TRACE_EVENT_* will be ignored. - # So when tests are included, we set this define, making it possible to use - # different event handlers in different tests. - if (rtc_include_tests) { - defines += [ "WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS=1" ] - } else { - defines += [ "WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS=0" ] + if (!rtc_use_perfetto) { + # Some tests need to declare their own trace event handlers. If this define is + # not set, the first time TRACE_EVENT_* is called it will store the return + # value for the current handler in an static variable, so that subsequent + # changes to the handler for that TRACE_EVENT_* will be ignored. + # So when tests are included, we set this define, making it possible to use + # different event handlers in different tests. + if (rtc_include_tests) { + defines += [ "WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS=1" ] + } else { + defines += [ "WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS=0" ] + } } if (build_with_chromium) { defines += [ "WEBRTC_CHROMIUM_BUILD" ] @@ -269,6 +270,33 @@ config("rtc_prod_config") { } } +group("tracing") { + all_dependent_configs = [ "//third_party/perfetto/gn:public_config" ] + if (rtc_use_perfetto) { + if (build_with_chromium) { + public_deps = # no-presubmit-check TODO(webrtc:8603) + [ "//third_party/perfetto:libperfetto" ] + } else { + public_deps = [ # no-presubmit-check TODO(webrtc:8603) + ":webrtc_libperfetto", + "//third_party/perfetto/include/perfetto/tracing", + ] + } + } else { + public_deps = # no-presubmit-check TODO(webrtc:8603) + [ "//third_party/perfetto/include/perfetto/tracing" ] + } +} + +if (rtc_use_perfetto) { + rtc_library("webrtc_libperfetto") { + deps = [ + "//third_party/perfetto/src/tracing:client_api_without_backends", + "//third_party/perfetto/src/tracing:platform_impl", + ] + } +} + config("common_config") { cflags = [] cflags_c = [] @@ -342,10 +370,6 @@ config("common_config") { defines += [ "RTC_DISABLE_METRICS" ] } - if (rtc_exclude_transient_suppressor) { - defines += [ "WEBRTC_EXCLUDE_TRANSIENT_SUPPRESSOR" ] - } - if (rtc_exclude_audio_processing_module) { defines += [ "WEBRTC_EXCLUDE_AUDIO_PROCESSING_MODULE" ] } @@ -395,19 +419,11 @@ config("common_config") { } if (is_clang) { - cflags += [ "-Wc++11-narrowing" ] - - if (!is_fuchsia) { - # Compiling with the Fuchsia SDK results in Wundef errors - # TODO(bugs.fuchsia.dev/100722): Remove from (!is_fuchsia) branch when - # Fuchsia build errors are fixed. - cflags += [ "-Wundef" ] - } - - if (!is_nacl) { - # Flags NaCl (Clang 3.7) do not recognize. - cflags += [ "-Wunused-lambda-capture" ] - } + cflags += [ + "-Wc++11-narrowing", + "-Wundef", + "-Wunused-lambda-capture", + ] } if (is_win && !is_clang) { @@ -478,12 +494,28 @@ config("common_config") { "/U_UNICODE", ] } + + if (rtc_use_perfetto) { + defines += [ "RTC_USE_PERFETTO" ] + } } config("common_objc") { frameworks = [ "Foundation.framework" ] } +if (!rtc_build_ssl) { + config("external_ssl_library") { + if (rtc_ssl_root != "") { + include_dirs = [ rtc_ssl_root ] + } + libs = [ + "crypto", + "ssl", + ] + } +} + if (!build_with_chromium) { # Target to build all the WebRTC production code. rtc_static_library("webrtc") { @@ -500,9 +532,11 @@ if (!build_with_chromium) { deps = [ "api:create_peerconnection_factory", + "api:enable_media", "api:libjingle_peerconnection_api", "api:rtc_error", "api:transport_api", + "api/audio_codecs:opus_audio_decoder_factory", "api/crypto", "api/rtc_event_log:rtc_event_log_factory", "api/task_queue", @@ -588,6 +622,16 @@ if (use_libfuzzer || use_afl) { } if (rtc_include_tests && !build_with_chromium) { + rtc_unittests_resources = [ "resources/reference_video_640x360_30fps.y4m" ] + + if (is_ios) { + bundle_data("rtc_unittests_bundle_data") { + testonly = true + sources = rtc_unittests_resources + outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ] + } + } + rtc_test("rtc_unittests") { testonly = true @@ -601,12 +645,15 @@ if (rtc_include_tests && !build_with_chromium) { "api/test/metrics:metrics_unittests", "api/transport:stun_unittest", "api/video/test:rtc_api_video_unittests", + "api/video_codecs:libaom_av1_encoder_factory_test", + "api/video_codecs:simple_encoder_wrapper_unittests", "api/video_codecs/test:video_codecs_api_unittests", "api/voip:compile_all_headers", "call:fake_network_pipe_unittests", "p2p:libstunprober_unittests", "p2p:rtc_p2p_unittests", "rtc_base:async_dns_resolver_unittests", + "rtc_base:async_packet_socket_unittest", "rtc_base:callback_list_unittests", "rtc_base:rtc_base_approved_unittests", "rtc_base:rtc_base_unittests", @@ -628,8 +675,17 @@ if (rtc_include_tests && !build_with_chromium) { "test/network:network_emulation_unittests", ] + data = rtc_unittests_resources + if (rtc_enable_protobuf) { - deps += [ "logging:rtc_event_log_tests" ] + deps += [ + "api/test/network_emulation:network_config_schedule_proto", + "logging:rtc_event_log_tests", + ] + } + + if (is_ios) { + deps += [ ":rtc_unittests_bundle_data" ] } if (is_android) { @@ -800,10 +856,10 @@ rtc_static_library("dcsctp") { group("poison_audio_codecs") { } -group("poison_default_task_queue") { +group("poison_default_echo_detector") { } -group("poison_default_echo_detector") { +group("poison_environment_construction") { } group("poison_software_video_codecs") { diff --git a/webrtc/api/array_view.h b/webrtc/api/array_view.h index 7e01959..4abd2bf 100644 --- a/webrtc/api/array_view.h +++ b/webrtc/api/array_view.h @@ -13,6 +13,7 @@ #include #include +#include #include #include diff --git a/webrtc/api/audio/audio_frame.cc b/webrtc/api/audio/audio_frame.cc index 3e12006..ae4380e 100644 --- a/webrtc/api/audio/audio_frame.cc +++ b/webrtc/api/audio/audio_frame.cc @@ -12,6 +12,13 @@ #include +#include +#include + +#include "api/array_view.h" +#include "api/audio/audio_view.h" +#include "api/audio/channel_layout.h" +#include "api/rtp_packet_infos.h" #include "rtc_base/checks.h" #include "rtc_base/time_utils.h" @@ -22,6 +29,20 @@ AudioFrame::AudioFrame() { static_assert(sizeof(data_) == kMaxDataSizeBytes, "kMaxDataSizeBytes"); } +AudioFrame::AudioFrame(int sample_rate_hz, + size_t num_channels, + ChannelLayout layout /*= CHANNEL_LAYOUT_UNSUPPORTED*/) + : samples_per_channel_(SampleRateToDefaultChannelSize(sample_rate_hz)), + sample_rate_hz_(sample_rate_hz), + num_channels_(num_channels), + channel_layout_(layout == CHANNEL_LAYOUT_UNSUPPORTED + ? GuessChannelLayout(num_channels) + : layout) { + RTC_DCHECK_LE(num_channels_, kMaxConcurrentChannels); + RTC_DCHECK_GT(sample_rate_hz_, 0); + RTC_DCHECK_GT(samples_per_channel_, 0u); +} + void AudioFrame::Reset() { ResetWithoutMuting(); muted_ = true; @@ -41,7 +62,7 @@ void AudioFrame::ResetWithoutMuting() { vad_activity_ = kVadUnknown; profile_timestamp_ms_ = 0; packet_infos_ = RtpPacketInfos(); - absolute_capture_timestamp_ms_ = absl::nullopt; + absolute_capture_timestamp_ms_ = std::nullopt; } void AudioFrame::UpdateFrame(uint32_t timestamp, @@ -51,6 +72,7 @@ void AudioFrame::UpdateFrame(uint32_t timestamp, SpeechType speech_type, VADActivity vad_activity, size_t num_channels) { + RTC_CHECK_LE(num_channels, kMaxConcurrentChannels); timestamp_ = timestamp; samples_per_channel_ = samples_per_channel; sample_rate_hz_ = sample_rate_hz; @@ -63,9 +85,9 @@ void AudioFrame::UpdateFrame(uint32_t timestamp, } const size_t length = samples_per_channel * num_channels; - RTC_CHECK_LE(length, kMaxDataSizeSamples); + RTC_CHECK_LE(length, data_.size()); if (data != nullptr) { - memcpy(data_, data, sizeof(int16_t) * length); + memcpy(data_.data(), data, sizeof(int16_t) * length); muted_ = false; } else { muted_ = true; @@ -76,6 +98,16 @@ void AudioFrame::CopyFrom(const AudioFrame& src) { if (this == &src) return; + if (muted_ && !src.muted()) { + // TODO: bugs.webrtc.org/5647 - Since the default value for `muted_` is + // false and `data_` may still be uninitialized (because we don't initialize + // data_ as part of construction), we clear the full buffer here before + // copying over new values. If we don't, msan might complain in some tests. + // Consider locking down construction, avoiding the default constructor and + // prefering construction that initializes all state. + ClearSamples(data_); + } + timestamp_ = src.timestamp_; elapsed_time_ms_ = src.elapsed_time_ms_; ntp_time_ms_ = src.ntp_time_ms_; @@ -89,11 +121,10 @@ void AudioFrame::CopyFrom(const AudioFrame& src) { channel_layout_ = src.channel_layout_; absolute_capture_timestamp_ms_ = src.absolute_capture_timestamp_ms(); - const size_t length = samples_per_channel_ * num_channels_; - RTC_CHECK_LE(length, kMaxDataSizeSamples); - if (!src.muted()) { - memcpy(data_, src.data(), sizeof(int16_t) * length); - muted_ = false; + auto data = src.data_view(); + RTC_CHECK_LE(data.size(), data_.size()); + if (!muted_ && !data.empty()) { + memcpy(&data_[0], &data[0], sizeof(int16_t) * data.size()); } } @@ -110,17 +141,56 @@ int64_t AudioFrame::ElapsedProfileTimeMs() const { } const int16_t* AudioFrame::data() const { - return muted_ ? empty_data() : data_; + return muted_ ? zeroed_data().begin() : data_.data(); +} + +InterleavedView AudioFrame::data_view() const { + // If you get a nullptr from `data_view()`, it's likely because the + // samples_per_channel_ and/or num_channels_ members haven't been properly + // set. Since `data_view()` returns an InterleavedView<> (which internally + // uses rtc::ArrayView<>), we inherit the behavior in InterleavedView when the + // view size is 0 that ArrayView<>::data() returns nullptr. So, even when an + // AudioFrame is muted and we want to return `zeroed_data()`, if + // samples_per_channel_ or num_channels_ is 0, the view will point to + // nullptr. + return InterleavedView(muted_ ? &zeroed_data()[0] : &data_[0], + samples_per_channel_, num_channels_); } -// TODO(henrik.lundin) Can we skip zeroing the buffer? -// See https://bugs.chromium.org/p/webrtc/issues/detail?id=5647. int16_t* AudioFrame::mutable_data() { + // TODO: bugs.webrtc.org/5647 - Can we skip zeroing the buffer? + // Consider instead if we should rather zero the buffer when `muted_` is set + // to `true`. if (muted_) { - memset(data_, 0, kMaxDataSizeBytes); + ClearSamples(data_); muted_ = false; } - return data_; + return &data_[0]; +} + +InterleavedView AudioFrame::mutable_data(size_t samples_per_channel, + size_t num_channels) { + const size_t total_samples = samples_per_channel * num_channels; + RTC_CHECK_LE(total_samples, data_.size()); + RTC_CHECK_LE(num_channels, kMaxConcurrentChannels); + // Sanity check for valid argument values during development. + // If `samples_per_channel` is < `num_channels` but larger than 0, + // then chances are the order of arguments is incorrect. + RTC_DCHECK((samples_per_channel == 0 && num_channels == 0) || + num_channels <= samples_per_channel) + << "samples_per_channel=" << samples_per_channel + << "num_channels=" << num_channels; + + // TODO: bugs.webrtc.org/5647 - Can we skip zeroing the buffer? + // Consider instead if we should rather zero the whole buffer when `muted_` is + // set to `true`. + if (muted_) { + ClearSamples(data_, total_samples); + muted_ = false; + } + samples_per_channel_ = samples_per_channel; + num_channels_ = num_channels; + return InterleavedView(&data_[0], samples_per_channel, num_channels); } void AudioFrame::Mute() { @@ -131,10 +201,35 @@ bool AudioFrame::muted() const { return muted_; } +void AudioFrame::SetLayoutAndNumChannels(ChannelLayout layout, + size_t num_channels) { + channel_layout_ = layout; + num_channels_ = num_channels; +#if RTC_DCHECK_IS_ON + // Do a sanity check that the layout and num_channels match. + // If this lookup yield 0u, then the layout is likely CHANNEL_LAYOUT_DISCRETE. + auto expected_num_channels = ChannelLayoutToChannelCount(layout); + if (expected_num_channels) { // If expected_num_channels is 0 + RTC_DCHECK_EQ(expected_num_channels, num_channels_); + } +#endif + RTC_CHECK_LE(samples_per_channel_ * num_channels_, data_.size()); +} + +void AudioFrame::SetSampleRateAndChannelSize(int sample_rate) { + sample_rate_hz_ = sample_rate; + // We could call `AudioProcessing::GetFrameSize()` here, but that requires + // adding a dependency on the ":audio_processing" build target, which can + // complicate the dependency tree. Some refactoring is probably in order to + // get some consistency around this since there are many places across the + // code that assume this default buffer size. + samples_per_channel_ = SampleRateToDefaultChannelSize(sample_rate_hz_); +} + // static -const int16_t* AudioFrame::empty_data() { +rtc::ArrayView AudioFrame::zeroed_data() { static int16_t* null_data = new int16_t[kMaxDataSizeSamples](); - return &null_data[0]; + return rtc::ArrayView(null_data, kMaxDataSizeSamples); } } // namespace webrtc diff --git a/webrtc/api/audio/audio_frame.h b/webrtc/api/audio/audio_frame.h index d5dcb5f..9afd516 100644 --- a/webrtc/api/audio/audio_frame.h +++ b/webrtc/api/audio/audio_frame.h @@ -14,11 +14,34 @@ #include #include +#include +#include + +#include "api/array_view.h" +#include "api/audio/audio_view.h" #include "api/audio/channel_layout.h" #include "api/rtp_packet_infos.h" +#include "rtc_base/checks.h" namespace webrtc { +// Default webrtc buffer size in milliseconds. +constexpr size_t kDefaultAudioBufferLengthMs = 10u; + +// Default total number of audio buffers per second based on the default length. +constexpr size_t kDefaultAudioBuffersPerSec = + 1000u / kDefaultAudioBufferLengthMs; + +// Returns the number of samples a buffer needs to hold for ~10ms of a single +// audio channel at a given sample rate. +// See also `AudioProcessing::GetFrameSize()`. +inline size_t SampleRateToDefaultChannelSize(size_t sample_rate) { + // Basic sanity check. 192kHz is the highest supported input sample rate. + RTC_DCHECK_LE(sample_rate, 192000); + return sample_rate / kDefaultAudioBuffersPerSec; +} +///////////////////////////////////////////////////////////////////// + /* This class holds up to 120 ms of super-wideband (32 kHz) stereo audio. It * allows for adding and subtracting frames while keeping track of the resulting * states. @@ -57,6 +80,15 @@ class AudioFrame { AudioFrame(); + // Construct an audio frame with frame length properties and channel + // information. `samples_per_channel()` will be initialized to a 10ms buffer + // size and if `layout` is not specified (default value of + // CHANNEL_LAYOUT_UNSUPPORTED is set), then the channel layout is derived + // (guessed) from `num_channels`. + AudioFrame(int sample_rate_hz, + size_t num_channels, + ChannelLayout layout = CHANNEL_LAYOUT_UNSUPPORTED); + AudioFrame(const AudioFrame&) = delete; AudioFrame& operator=(const AudioFrame&) = delete; @@ -68,6 +100,7 @@ class AudioFrame { // ResetWithoutMuting() to skip this wasteful zeroing. void ResetWithoutMuting(); + // TODO: b/335805780 - Accept InterleavedView. void UpdateFrame(uint32_t timestamp, const int16_t* data, size_t samples_per_channel, @@ -90,20 +123,40 @@ class AudioFrame { int64_t ElapsedProfileTimeMs() const; // data() returns a zeroed static buffer if the frame is muted. - // mutable_frame() always returns a non-static buffer; the first call to - // mutable_frame() zeros the non-static buffer and marks the frame unmuted. + // TODO: b/335805780 - Return InterleavedView. const int16_t* data() const; + + // Returns a read-only view of all the valid samples held by the AudioFrame. + // For a muted AudioFrame, the samples will all be 0. + InterleavedView data_view() const; + + // mutable_frame() always returns a non-static buffer; the first call to + // mutable_frame() zeros the buffer and marks the frame as unmuted. + // TODO: b/335805780 - Return an InterleavedView. int16_t* mutable_data(); + // Grants write access to the audio buffer. The size of the returned writable + // view is determined by the `samples_per_channel` and `num_channels` + // dimensions which the function checks for correctness and stores in the + // internal member variables; `samples_per_channel()` and `num_channels()` + // respectively. + // If the state is currently muted, the returned view will be zeroed out. + InterleavedView mutable_data(size_t samples_per_channel, + size_t num_channels); + // Prefer to mute frames using AudioFrameOperations::Mute. void Mute(); // Frame is muted by default. bool muted() const; - size_t max_16bit_samples() const { return kMaxDataSizeSamples; } + size_t max_16bit_samples() const { return data_.size(); } size_t samples_per_channel() const { return samples_per_channel_; } size_t num_channels() const { return num_channels_; } + ChannelLayout channel_layout() const { return channel_layout_; } + // Sets the `channel_layout` property as well as `num_channels`. + void SetLayoutAndNumChannels(ChannelLayout layout, size_t num_channels); + int sample_rate_hz() const { return sample_rate_hz_; } void set_absolute_capture_timestamp_ms( @@ -111,10 +164,14 @@ class AudioFrame { absolute_capture_timestamp_ms_ = absolute_capture_time_stamp_ms; } - absl::optional absolute_capture_timestamp_ms() const { + std::optional absolute_capture_timestamp_ms() const { return absolute_capture_timestamp_ms_; } + // Sets the sample_rate_hz and samples_per_channel properties based on a + // given sample rate and calculates a default 10ms samples_per_channel value. + void SetSampleRateAndChannelSize(int sample_rate); + // RTP timestamp of the first sample in the AudioFrame. uint32_t timestamp_ = 0; // Time since the first frame in milliseconds. @@ -126,14 +183,13 @@ class AudioFrame { size_t samples_per_channel_ = 0; int sample_rate_hz_ = 0; size_t num_channels_ = 0; - ChannelLayout channel_layout_ = CHANNEL_LAYOUT_NONE; SpeechType speech_type_ = kUndefined; VADActivity vad_activity_ = kVadUnknown; // Monotonically increasing timestamp intended for profiling of audio frames. // Typically used for measuring elapsed time between two different points in // the audio path. No lock is used to save resources and we are thread safe // by design. - // TODO(nisse@webrtc.org): consider using absl::optional. + // TODO(nisse@webrtc.org): consider using std::optional. int64_t profile_timestamp_ms_ = 0; // Information about packets used to assemble this audio frame. This is needed @@ -154,18 +210,19 @@ class AudioFrame { private: // A permanently zeroed out buffer to represent muted frames. This is a - // header-only class, so the only way to avoid creating a separate empty + // header-only class, so the only way to avoid creating a separate zeroed // buffer per translation unit is to wrap a static in an inline function. - static const int16_t* empty_data(); + static rtc::ArrayView zeroed_data(); - int16_t data_[kMaxDataSizeSamples]; + std::array data_; bool muted_ = true; + ChannelLayout channel_layout_ = CHANNEL_LAYOUT_NONE; // Absolute capture timestamp when this audio frame was originally captured. // This is only valid for audio frames captured on this machine. The absolute // capture timestamp of a received frame is found in `packet_infos_`. // This timestamp MUST be based on the same clock as rtc::TimeMillis(). - absl::optional absolute_capture_timestamp_ms_; + std::optional absolute_capture_timestamp_ms_; }; } // namespace webrtc diff --git a/webrtc/modules/audio_processing/include/audio_processing.cc b/webrtc/api/audio/audio_processing.cc similarity index 99% rename from webrtc/modules/audio_processing/include/audio_processing.cc rename to webrtc/api/audio/audio_processing.cc index 13ddcc5..2df2a78 100644 --- a/webrtc/modules/audio_processing/include/audio_processing.cc +++ b/webrtc/api/audio/audio_processing.cc @@ -8,10 +8,11 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "modules/audio_processing/include/audio_processing.h" +#include "api/audio/audio_processing.h" +#include +#include "rtc_base/checks.h" #include "rtc_base/strings/string_builder.h" -#include "rtc_base/system/arch.h" namespace webrtc { namespace { diff --git a/webrtc/api/audio/audio_processing.h b/webrtc/api/audio/audio_processing.h new file mode 100644 index 0000000..dca75f2 --- /dev/null +++ b/webrtc/api/audio/audio_processing.h @@ -0,0 +1,944 @@ +/* + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef API_AUDIO_AUDIO_PROCESSING_H_ +#define API_AUDIO_AUDIO_PROCESSING_H_ + +// MSVC++ requires this to be set before any other includes to get M_PI. +#ifndef _USE_MATH_DEFINES +#define _USE_MATH_DEFINES +#endif + +#include +#include // size_t +#include // FILE +#include + +#include +#include +#include +#include +#include +#include + +#include "absl/base/nullability.h" +#include "absl/strings/string_view.h" +#include "api/array_view.h" +#include "api/audio/audio_processing_statistics.h" +#include "api/audio/echo_control.h" +#include "api/ref_count.h" +#include "api/scoped_refptr.h" +#include "api/task_queue/task_queue_base.h" +#include "rtc_base/arraysize.h" +#include "rtc_base/checks.h" +#include "rtc_base/system/rtc_export.h" + +namespace webrtc { + +class AecDump; +class AudioBuffer; + +class StreamConfig; +class ProcessingConfig; + +class EchoDetector; + +// The Audio Processing Module (APM) provides a collection of voice processing +// components designed for real-time communications software. +// +// APM operates on two audio streams on a frame-by-frame basis. Frames of the +// primary stream, on which all processing is applied, are passed to +// `ProcessStream()`. Frames of the reverse direction stream are passed to +// `ProcessReverseStream()`. On the client-side, this will typically be the +// near-end (capture) and far-end (render) streams, respectively. APM should be +// placed in the signal chain as close to the audio hardware abstraction layer +// (HAL) as possible. +// +// On the server-side, the reverse stream will normally not be used, with +// processing occurring on each incoming stream. +// +// Component interfaces follow a similar pattern and are accessed through +// corresponding getters in APM. All components are disabled at create-time, +// with default settings that are recommended for most situations. New settings +// can be applied without enabling a component. Enabling a component triggers +// memory allocation and initialization to allow it to start processing the +// streams. +// +// Thread safety is provided with the following assumptions to reduce locking +// overhead: +// 1. The stream getters and setters are called from the same thread as +// ProcessStream(). More precisely, stream functions are never called +// concurrently with ProcessStream(). +// 2. Parameter getters are never called concurrently with the corresponding +// setter. +// +// APM accepts only linear PCM audio data in chunks of ~10 ms (see +// AudioProcessing::GetFrameSize() for details) and sample rates ranging from +// 8000 Hz to 384000 Hz. The int16 interfaces use interleaved data, while the +// float interfaces use deinterleaved data. +// +// Usage example, omitting error checking: +// rtc::scoped_refptr apm = AudioProcessingBuilder().Create(); +// +// AudioProcessing::Config config; +// config.echo_canceller.enabled = true; +// config.echo_canceller.mobile_mode = false; +// +// config.gain_controller1.enabled = true; +// config.gain_controller1.mode = +// AudioProcessing::Config::GainController1::kAdaptiveAnalog; +// config.gain_controller1.analog_level_minimum = 0; +// config.gain_controller1.analog_level_maximum = 255; +// +// config.gain_controller2.enabled = true; +// +// config.high_pass_filter.enabled = true; +// +// apm->ApplyConfig(config) +// +// // Start a voice call... +// +// // ... Render frame arrives bound for the audio HAL ... +// apm->ProcessReverseStream(render_frame); +// +// // ... Capture frame arrives from the audio HAL ... +// // Call required set_stream_ functions. +// apm->set_stream_delay_ms(delay_ms); +// apm->set_stream_analog_level(analog_level); +// +// apm->ProcessStream(capture_frame); +// +// // Call required stream_ functions. +// analog_level = apm->recommended_stream_analog_level(); +// has_voice = apm->stream_has_voice(); +// +// // Repeat render and capture processing for the duration of the call... +// // Start a new call... +// apm->Initialize(); +// +// // Close the application... +// apm.reset(); +// +class RTC_EXPORT AudioProcessing : public RefCountInterface { + public: + // The struct below constitutes the new parameter scheme for the audio + // processing. It is being introduced gradually and until it is fully + // introduced, it is prone to change. + // TODO(peah): Remove this comment once the new config scheme is fully rolled + // out. + // + // The parameters and behavior of the audio processing module are controlled + // by changing the default values in the AudioProcessing::Config struct. + // The config is applied by passing the struct to the ApplyConfig method. + // + // This config is intended to be used during setup, and to enable/disable + // top-level processing effects. Use during processing may cause undesired + // submodule resets, affecting the audio quality. Use the RuntimeSetting + // construct for runtime configuration. + struct RTC_EXPORT Config { + // Sets the properties of the audio processing pipeline. + struct RTC_EXPORT Pipeline { + // Ways to downmix a multi-channel track to mono. + enum class DownmixMethod { + kAverageChannels, // Average across channels. + kUseFirstChannel // Use the first channel. + }; + + // Maximum allowed processing rate used internally. May only be set to + // 32000 or 48000 and any differing values will be treated as 48000. + int maximum_internal_processing_rate = 48000; + // Allow multi-channel processing of render audio. + bool multi_channel_render = false; + // Allow multi-channel processing of capture audio when AEC3 is active + // or a custom AEC is injected.. + bool multi_channel_capture = false; + // Indicates how to downmix multi-channel capture audio to mono (when + // needed). + DownmixMethod capture_downmix_method = DownmixMethod::kAverageChannels; + } pipeline; + + // Enabled the pre-amplifier. It amplifies the capture signal + // before any other processing is done. + // TODO(webrtc:5298): Deprecate and use the pre-gain functionality in + // capture_level_adjustment instead. + struct PreAmplifier { + bool enabled = false; + float fixed_gain_factor = 1.0f; + } pre_amplifier; + + // Functionality for general level adjustment in the capture pipeline. This + // should not be used together with the legacy PreAmplifier functionality. + struct CaptureLevelAdjustment { + bool operator==(const CaptureLevelAdjustment& rhs) const; + bool operator!=(const CaptureLevelAdjustment& rhs) const { + return !(*this == rhs); + } + bool enabled = false; + // The `pre_gain_factor` scales the signal before any processing is done. + float pre_gain_factor = 1.0f; + // The `post_gain_factor` scales the signal after all processing is done. + float post_gain_factor = 1.0f; + struct AnalogMicGainEmulation { + bool operator==(const AnalogMicGainEmulation& rhs) const; + bool operator!=(const AnalogMicGainEmulation& rhs) const { + return !(*this == rhs); + } + bool enabled = false; + // Initial analog gain level to use for the emulated analog gain. Must + // be in the range [0...255]. + int initial_level = 255; + } analog_mic_gain_emulation; + } capture_level_adjustment; + + struct HighPassFilter { + bool enabled = false; + bool apply_in_full_band = true; + } high_pass_filter; + + struct EchoCanceller { + bool enabled = false; + bool mobile_mode = false; + bool export_linear_aec_output = false; + // Enforce the highpass filter to be on (has no effect for the mobile + // mode). + bool enforce_high_pass_filtering = true; + } echo_canceller; + + // Enables background noise suppression. + struct NoiseSuppression { + bool enabled = false; + enum Level { kLow, kModerate, kHigh, kVeryHigh }; + Level level = kModerate; + bool analyze_linear_aec_output_when_available = false; + } noise_suppression; + + // TODO(bugs.webrtc.org/357281131): Deprecated. Stop using and remove. + // Enables transient suppression. + struct TransientSuppression { + bool enabled = false; + } transient_suppression; + + // Enables automatic gain control (AGC) functionality. + // The automatic gain control (AGC) component brings the signal to an + // appropriate range. This is done by applying a digital gain directly and, + // in the analog mode, prescribing an analog gain to be applied at the audio + // HAL. + // Recommended to be enabled on the client-side. + struct RTC_EXPORT GainController1 { + bool operator==(const GainController1& rhs) const; + bool operator!=(const GainController1& rhs) const { + return !(*this == rhs); + } + + bool enabled = false; + enum Mode { + // Adaptive mode intended for use if an analog volume control is + // available on the capture device. It will require the user to provide + // coupling between the OS mixer controls and AGC through the + // stream_analog_level() functions. + // It consists of an analog gain prescription for the audio device and a + // digital compression stage. + kAdaptiveAnalog, + // Adaptive mode intended for situations in which an analog volume + // control is unavailable. It operates in a similar fashion to the + // adaptive analog mode, but with scaling instead applied in the digital + // domain. As with the analog mode, it additionally uses a digital + // compression stage. + kAdaptiveDigital, + // Fixed mode which enables only the digital compression stage also used + // by the two adaptive modes. + // It is distinguished from the adaptive modes by considering only a + // short time-window of the input signal. It applies a fixed gain + // through most of the input level range, and compresses (gradually + // reduces gain with increasing level) the input signal at higher + // levels. This mode is preferred on embedded devices where the capture + // signal level is predictable, so that a known gain can be applied. + kFixedDigital + }; + Mode mode = kAdaptiveAnalog; + // Sets the target peak level (or envelope) of the AGC in dBFs (decibels + // from digital full-scale). The convention is to use positive values. For + // instance, passing in a value of 3 corresponds to -3 dBFs, or a target + // level 3 dB below full-scale. Limited to [0, 31]. + int target_level_dbfs = 3; + // Sets the maximum gain the digital compression stage may apply, in dB. A + // higher number corresponds to greater compression, while a value of 0 + // will leave the signal uncompressed. Limited to [0, 90]. + // For updates after APM setup, use a RuntimeSetting instead. + int compression_gain_db = 9; + // When enabled, the compression stage will hard limit the signal to the + // target level. Otherwise, the signal will be compressed but not limited + // above the target level. + bool enable_limiter = true; + + // Enables the analog gain controller functionality. + struct AnalogGainController { + bool enabled = true; + // TODO(bugs.webrtc.org/7494): Deprecated. Stop using and remove. + int startup_min_volume = 0; + // Lowest analog microphone level that will be applied in response to + // clipping. + int clipped_level_min = 70; + // If true, an adaptive digital gain is applied. + bool enable_digital_adaptive = true; + // Amount the microphone level is lowered with every clipping event. + // Limited to (0, 255]. + int clipped_level_step = 15; + // Proportion of clipped samples required to declare a clipping event. + // Limited to (0.f, 1.f). + float clipped_ratio_threshold = 0.1f; + // Time in frames to wait after a clipping event before checking again. + // Limited to values higher than 0. + int clipped_wait_frames = 300; + + // Enables clipping prediction functionality. + struct ClippingPredictor { + bool enabled = false; + enum Mode { + // Clipping event prediction mode with fixed step estimation. + kClippingEventPrediction, + // Clipped peak estimation mode with adaptive step estimation. + kAdaptiveStepClippingPeakPrediction, + // Clipped peak estimation mode with fixed step estimation. + kFixedStepClippingPeakPrediction, + }; + Mode mode = kClippingEventPrediction; + // Number of frames in the sliding analysis window. + int window_length = 5; + // Number of frames in the sliding reference window. + int reference_window_length = 5; + // Reference window delay (unit: number of frames). + int reference_window_delay = 5; + // Clipping prediction threshold (dBFS). + float clipping_threshold = -1.0f; + // Crest factor drop threshold (dB). + float crest_factor_margin = 3.0f; + // If true, the recommended clipped level step is used to modify the + // analog gain. Otherwise, the predictor runs without affecting the + // analog gain. + bool use_predicted_step = true; + } clipping_predictor; + } analog_gain_controller; + } gain_controller1; + + // Parameters for AGC2, an Automatic Gain Control (AGC) sub-module which + // replaces the AGC sub-module parametrized by `gain_controller1`. + // AGC2 brings the captured audio signal to the desired level by combining + // three different controllers (namely, input volume controller, adapative + // digital controller and fixed digital controller) and a limiter. + // TODO(bugs.webrtc.org:7494): Name `GainController` when AGC1 removed. + struct RTC_EXPORT GainController2 { + bool operator==(const GainController2& rhs) const; + bool operator!=(const GainController2& rhs) const { + return !(*this == rhs); + } + + // AGC2 must be created if and only if `enabled` is true. + bool enabled = false; + + // Parameters for the input volume controller, which adjusts the input + // volume applied when the audio is captured (e.g., microphone volume on + // a soundcard, input volume on HAL). + struct InputVolumeController { + bool operator==(const InputVolumeController& rhs) const; + bool operator!=(const InputVolumeController& rhs) const { + return !(*this == rhs); + } + bool enabled = false; + } input_volume_controller; + + // Parameters for the adaptive digital controller, which adjusts and + // applies a digital gain after echo cancellation and after noise + // suppression. + struct RTC_EXPORT AdaptiveDigital { + bool operator==(const AdaptiveDigital& rhs) const; + bool operator!=(const AdaptiveDigital& rhs) const { + return !(*this == rhs); + } + bool enabled = false; + float headroom_db = 5.0f; + float max_gain_db = 50.0f; + float initial_gain_db = 15.0f; + float max_gain_change_db_per_second = 6.0f; + float max_output_noise_level_dbfs = -50.0f; + } adaptive_digital; + + // Parameters for the fixed digital controller, which applies a fixed + // digital gain after the adaptive digital controller and before the + // limiter. + struct FixedDigital { + // By setting `gain_db` to a value greater than zero, the limiter can be + // turned into a compressor that first applies a fixed gain. + float gain_db = 0.0f; + } fixed_digital; + } gain_controller2; + + std::string ToString() const; + }; + + // Specifies the properties of a setting to be passed to AudioProcessing at + // runtime. + class RuntimeSetting { + public: + enum class Type { + kNotSpecified, + kCapturePreGain, + kCaptureCompressionGain, + kCaptureFixedPostGain, + kPlayoutVolumeChange, + kCustomRenderProcessingRuntimeSetting, + kPlayoutAudioDeviceChange, + kCapturePostGain, + kCaptureOutputUsed + }; + + // Play-out audio device properties. + struct PlayoutAudioDeviceInfo { + int id; // Identifies the audio device. + int max_volume; // Maximum play-out volume. + }; + + RuntimeSetting() : type_(Type::kNotSpecified), value_(0.0f) {} + ~RuntimeSetting() = default; + + static RuntimeSetting CreateCapturePreGain(float gain) { + return {Type::kCapturePreGain, gain}; + } + + static RuntimeSetting CreateCapturePostGain(float gain) { + return {Type::kCapturePostGain, gain}; + } + + // Corresponds to Config::GainController1::compression_gain_db, but for + // runtime configuration. + static RuntimeSetting CreateCompressionGainDb(int gain_db) { + RTC_DCHECK_GE(gain_db, 0); + RTC_DCHECK_LE(gain_db, 90); + return {Type::kCaptureCompressionGain, static_cast(gain_db)}; + } + + // Corresponds to Config::GainController2::fixed_digital::gain_db, but for + // runtime configuration. + static RuntimeSetting CreateCaptureFixedPostGain(float gain_db) { + RTC_DCHECK_GE(gain_db, 0.0f); + RTC_DCHECK_LE(gain_db, 90.0f); + return {Type::kCaptureFixedPostGain, gain_db}; + } + + // Creates a runtime setting to notify play-out (aka render) audio device + // changes. + static RuntimeSetting CreatePlayoutAudioDeviceChange( + PlayoutAudioDeviceInfo audio_device) { + return {Type::kPlayoutAudioDeviceChange, audio_device}; + } + + // Creates a runtime setting to notify play-out (aka render) volume changes. + // `volume` is the unnormalized volume, the maximum of which + static RuntimeSetting CreatePlayoutVolumeChange(int volume) { + return {Type::kPlayoutVolumeChange, volume}; + } + + static RuntimeSetting CreateCustomRenderSetting(float payload) { + return {Type::kCustomRenderProcessingRuntimeSetting, payload}; + } + + static RuntimeSetting CreateCaptureOutputUsedSetting( + bool capture_output_used) { + return {Type::kCaptureOutputUsed, capture_output_used}; + } + + Type type() const { return type_; } + // Getters do not return a value but instead modify the argument to protect + // from implicit casting. + void GetFloat(float* value) const { + RTC_DCHECK(value); + *value = value_.float_value; + } + void GetInt(int* value) const { + RTC_DCHECK(value); + *value = value_.int_value; + } + void GetBool(bool* value) const { + RTC_DCHECK(value); + *value = value_.bool_value; + } + void GetPlayoutAudioDeviceInfo(PlayoutAudioDeviceInfo* value) const { + RTC_DCHECK(value); + *value = value_.playout_audio_device_info; + } + + private: + RuntimeSetting(Type id, float value) : type_(id), value_(value) {} + RuntimeSetting(Type id, int value) : type_(id), value_(value) {} + RuntimeSetting(Type id, PlayoutAudioDeviceInfo value) + : type_(id), value_(value) {} + Type type_; + union U { + U() {} + U(int value) : int_value(value) {} + U(float value) : float_value(value) {} + U(PlayoutAudioDeviceInfo value) : playout_audio_device_info(value) {} + float float_value; + int int_value; + bool bool_value; + PlayoutAudioDeviceInfo playout_audio_device_info; + } value_; + }; + + ~AudioProcessing() override {} + + // Initializes internal states, while retaining all user settings. This + // should be called before beginning to process a new audio stream. However, + // it is not necessary to call before processing the first stream after + // creation. + // + // It is also not necessary to call if the audio parameters (sample + // rate and number of channels) have changed. Passing updated parameters + // directly to `ProcessStream()` and `ProcessReverseStream()` is permissible. + // If the parameters are known at init-time though, they may be provided. + // TODO(webrtc:5298): Change to return void. + virtual int Initialize() = 0; + + // The int16 interfaces require: + // - only `NativeRate`s be used + // - that the input, output and reverse rates must match + // - that `processing_config.output_stream()` matches + // `processing_config.input_stream()`. + // + // The float interfaces accept arbitrary rates and support differing input and + // output layouts, but the output must have either one channel or the same + // number of channels as the input. + virtual int Initialize(const ProcessingConfig& processing_config) = 0; + + // TODO(peah): This method is a temporary solution used to take control + // over the parameters in the audio processing module and is likely to change. + virtual void ApplyConfig(const Config& config) = 0; + + // TODO(ajm): Only intended for internal use. Make private and friend the + // necessary classes? + virtual int proc_sample_rate_hz() const = 0; + virtual int proc_split_sample_rate_hz() const = 0; + virtual size_t num_input_channels() const = 0; + virtual size_t num_proc_channels() const = 0; + virtual size_t num_output_channels() const = 0; + virtual size_t num_reverse_channels() const = 0; + + // Set to true when the output of AudioProcessing will be muted or in some + // other way not used. Ideally, the captured audio would still be processed, + // but some components may change behavior based on this information. + // Default false. This method takes a lock. To achieve this in a lock-less + // manner the PostRuntimeSetting can instead be used. + virtual void set_output_will_be_muted(bool muted) = 0; + + // Enqueues a runtime setting. + virtual void SetRuntimeSetting(RuntimeSetting setting) = 0; + + // Enqueues a runtime setting. Returns a bool indicating whether the + // enqueueing was successfull. + virtual bool PostRuntimeSetting(RuntimeSetting setting) = 0; + + // Accepts and produces a ~10 ms frame of interleaved 16 bit integer audio as + // specified in `input_config` and `output_config`. `src` and `dest` may use + // the same memory, if desired. + virtual int ProcessStream(const int16_t* const src, + const StreamConfig& input_config, + const StreamConfig& output_config, + int16_t* const dest) = 0; + + // Accepts deinterleaved float audio with the range [-1, 1]. Each element of + // `src` points to a channel buffer, arranged according to `input_stream`. At + // output, the channels will be arranged according to `output_stream` in + // `dest`. + // + // The output must have one channel or as many channels as the input. `src` + // and `dest` may use the same memory, if desired. + virtual int ProcessStream(const float* const* src, + const StreamConfig& input_config, + const StreamConfig& output_config, + float* const* dest) = 0; + + // Accepts and produces a ~10 ms frame of interleaved 16 bit integer audio for + // the reverse direction audio stream as specified in `input_config` and + // `output_config`. `src` and `dest` may use the same memory, if desired. + virtual int ProcessReverseStream(const int16_t* const src, + const StreamConfig& input_config, + const StreamConfig& output_config, + int16_t* const dest) = 0; + + // Accepts deinterleaved float audio with the range [-1, 1]. Each element of + // `data` points to a channel buffer, arranged according to `reverse_config`. + virtual int ProcessReverseStream(const float* const* src, + const StreamConfig& input_config, + const StreamConfig& output_config, + float* const* dest) = 0; + + // Accepts deinterleaved float audio with the range [-1, 1]. Each element + // of `data` points to a channel buffer, arranged according to + // `reverse_config`. + virtual int AnalyzeReverseStream(const float* const* data, + const StreamConfig& reverse_config) = 0; + + // Returns the most recently produced ~10 ms of the linear AEC output at a + // rate of 16 kHz. If there is more than one capture channel, a mono + // representation of the input is returned. Returns true/false to indicate + // whether an output returned. + virtual bool GetLinearAecOutput( + rtc::ArrayView> linear_output) const = 0; + + // This must be called prior to ProcessStream() if and only if adaptive analog + // gain control is enabled, to pass the current analog level from the audio + // HAL. Must be within the range [0, 255]. + virtual void set_stream_analog_level(int level) = 0; + + // When an analog mode is set, this should be called after + // `set_stream_analog_level()` and `ProcessStream()` to obtain the recommended + // new analog level for the audio HAL. It is the user's responsibility to + // apply this level. + virtual int recommended_stream_analog_level() const = 0; + + // This must be called if and only if echo processing is enabled. + // + // Sets the `delay` in ms between ProcessReverseStream() receiving a far-end + // frame and ProcessStream() receiving a near-end frame containing the + // corresponding echo. On the client-side this can be expressed as + // delay = (t_render - t_analyze) + (t_process - t_capture) + // where, + // - t_analyze is the time a frame is passed to ProcessReverseStream() and + // t_render is the time the first sample of the same frame is rendered by + // the audio hardware. + // - t_capture is the time the first sample of a frame is captured by the + // audio hardware and t_process is the time the same frame is passed to + // ProcessStream(). + virtual int set_stream_delay_ms(int delay) = 0; + virtual int stream_delay_ms() const = 0; + + // Call to signal that a key press occurred (true) or did not occur (false) + // with this chunk of audio. + virtual void set_stream_key_pressed(bool key_pressed) = 0; + + // Creates and attaches an webrtc::AecDump for recording debugging + // information. + // The `worker_queue` may not be null and must outlive the created + // AecDump instance. |max_log_size_bytes == -1| means the log size + // will be unlimited. `handle` may not be null. The AecDump takes + // responsibility for `handle` and closes it in the destructor. A + // return value of true indicates that the file has been + // sucessfully opened, while a value of false indicates that + // opening the file failed. + virtual bool CreateAndAttachAecDump( + absl::string_view file_name, + int64_t max_log_size_bytes, + absl::Nonnull worker_queue) = 0; + virtual bool CreateAndAttachAecDump( + absl::Nonnull handle, + int64_t max_log_size_bytes, + absl::Nonnull worker_queue) = 0; + + // TODO(webrtc:5298) Deprecated variant. + // Attaches provided webrtc::AecDump for recording debugging + // information. Log file and maximum file size logic is supposed to + // be handled by implementing instance of AecDump. Calling this + // method when another AecDump is attached resets the active AecDump + // with a new one. This causes the d-tor of the earlier AecDump to + // be called. The d-tor call may block until all pending logging + // tasks are completed. + virtual void AttachAecDump(std::unique_ptr aec_dump) = 0; + + // If no AecDump is attached, this has no effect. If an AecDump is + // attached, it's destructor is called. The d-tor may block until + // all pending logging tasks are completed. + virtual void DetachAecDump() = 0; + + // Get audio processing statistics. + virtual AudioProcessingStats GetStatistics() = 0; + // TODO(webrtc:5298) Deprecated variant. The `has_remote_tracks` argument + // should be set if there are active remote tracks (this would usually be true + // during a call). If there are no remote tracks some of the stats will not be + // set by AudioProcessing, because they only make sense if there is at least + // one remote track. + virtual AudioProcessingStats GetStatistics(bool has_remote_tracks) = 0; + + // Returns the last applied configuration. + virtual AudioProcessing::Config GetConfig() const = 0; + + enum Error { + // Fatal errors. + kNoError = 0, + kUnspecifiedError = -1, + kCreationFailedError = -2, + kUnsupportedComponentError = -3, + kUnsupportedFunctionError = -4, + kNullPointerError = -5, + kBadParameterError = -6, + kBadSampleRateError = -7, + kBadDataLengthError = -8, + kBadNumberChannelsError = -9, + kFileError = -10, + kStreamParameterNotSetError = -11, + kNotEnabledError = -12, + + // Warnings are non-fatal. + // This results when a set_stream_ parameter is out of range. Processing + // will continue, but the parameter may have been truncated. + kBadStreamParameterWarning = -13 + }; + + // Native rates supported by the integer interfaces. + enum NativeRate { + kSampleRate8kHz = 8000, + kSampleRate16kHz = 16000, + kSampleRate32kHz = 32000, + kSampleRate48kHz = 48000 + }; + + // TODO(kwiberg): We currently need to support a compiler (Visual C++) that + // complains if we don't explicitly state the size of the array here. Remove + // the size when that's no longer the case. + static constexpr int kNativeSampleRatesHz[4] = { + kSampleRate8kHz, kSampleRate16kHz, kSampleRate32kHz, kSampleRate48kHz}; + static constexpr size_t kNumNativeSampleRates = + arraysize(kNativeSampleRatesHz); + static constexpr int kMaxNativeSampleRateHz = + kNativeSampleRatesHz[kNumNativeSampleRates - 1]; + + // APM processes audio in chunks of about 10 ms. See GetFrameSize() for + // details. + static constexpr int kChunkSizeMs = 10; + + // Returns floor(sample_rate_hz/100): the number of samples per channel used + // as input and output to the audio processing module in calls to + // ProcessStream, ProcessReverseStream, AnalyzeReverseStream, and + // GetLinearAecOutput. + // + // This is exactly 10 ms for sample rates divisible by 100. For example: + // - 48000 Hz (480 samples per channel), + // - 44100 Hz (441 samples per channel), + // - 16000 Hz (160 samples per channel). + // + // Sample rates not divisible by 100 are received/produced in frames of + // approximately 10 ms. For example: + // - 22050 Hz (220 samples per channel, or ~9.98 ms per frame), + // - 11025 Hz (110 samples per channel, or ~9.98 ms per frame). + // These nondivisible sample rates yield lower audio quality compared to + // multiples of 100. Internal resampling to 10 ms frames causes a simulated + // clock drift effect which impacts the performance of (for example) echo + // cancellation. + static int GetFrameSize(int sample_rate_hz) { return sample_rate_hz / 100; } +}; + +// Experimental interface for a custom analysis submodule. +class CustomAudioAnalyzer { + public: + // (Re-) Initializes the submodule. + virtual void Initialize(int sample_rate_hz, int num_channels) = 0; + // Analyzes the given capture or render signal. + virtual void Analyze(const AudioBuffer* audio) = 0; + // Returns a string representation of the module state. + virtual std::string ToString() const = 0; + + virtual ~CustomAudioAnalyzer() {} +}; + +// Interface for a custom processing submodule. +class CustomProcessing { + public: + // (Re-)Initializes the submodule. + virtual void Initialize(int sample_rate_hz, int num_channels) = 0; + // Processes the given capture or render signal. + virtual void Process(AudioBuffer* audio) = 0; + // Returns a string representation of the module state. + virtual std::string ToString() const = 0; + // Handles RuntimeSettings. TODO(webrtc:9262): make pure virtual + // after updating dependencies. + virtual void SetRuntimeSetting(AudioProcessing::RuntimeSetting setting); + + virtual ~CustomProcessing() {} +}; + +class RTC_EXPORT AudioProcessingBuilder { + public: + AudioProcessingBuilder(); + AudioProcessingBuilder(const AudioProcessingBuilder&) = delete; + AudioProcessingBuilder& operator=(const AudioProcessingBuilder&) = delete; + ~AudioProcessingBuilder(); + + // Sets the APM configuration. + AudioProcessingBuilder& SetConfig(const AudioProcessing::Config& config) { + config_ = config; + return *this; + } + + // Sets the echo controller factory to inject when APM is created. + AudioProcessingBuilder& SetEchoControlFactory( + std::unique_ptr echo_control_factory) { + echo_control_factory_ = std::move(echo_control_factory); + return *this; + } + + // Sets the capture post-processing sub-module to inject when APM is created. + AudioProcessingBuilder& SetCapturePostProcessing( + std::unique_ptr capture_post_processing) { + capture_post_processing_ = std::move(capture_post_processing); + return *this; + } + + // Sets the render pre-processing sub-module to inject when APM is created. + AudioProcessingBuilder& SetRenderPreProcessing( + std::unique_ptr render_pre_processing) { + render_pre_processing_ = std::move(render_pre_processing); + return *this; + } + + // Sets the echo detector to inject when APM is created. + AudioProcessingBuilder& SetEchoDetector( + rtc::scoped_refptr echo_detector) { + echo_detector_ = std::move(echo_detector); + return *this; + } + + // Sets the capture analyzer sub-module to inject when APM is created. + AudioProcessingBuilder& SetCaptureAnalyzer( + std::unique_ptr capture_analyzer) { + capture_analyzer_ = std::move(capture_analyzer); + return *this; + } + + // Creates an APM instance with the specified config or the default one if + // unspecified. Injects the specified components transferring the ownership + // to the newly created APM instance - i.e., except for the config, the + // builder is reset to its initial state. + rtc::scoped_refptr Create(); + + private: + AudioProcessing::Config config_; + std::unique_ptr echo_control_factory_; + std::unique_ptr capture_post_processing_; + std::unique_ptr render_pre_processing_; + rtc::scoped_refptr echo_detector_; + std::unique_ptr capture_analyzer_; +}; + +class StreamConfig { + public: + // sample_rate_hz: The sampling rate of the stream. + // num_channels: The number of audio channels in the stream. + StreamConfig(int sample_rate_hz = 0, + size_t num_channels = 0) // NOLINT(runtime/explicit) + : sample_rate_hz_(sample_rate_hz), + num_channels_(num_channels), + num_frames_(calculate_frames(sample_rate_hz)) {} + + void set_sample_rate_hz(int value) { + sample_rate_hz_ = value; + num_frames_ = calculate_frames(value); + } + void set_num_channels(size_t value) { num_channels_ = value; } + + int sample_rate_hz() const { return sample_rate_hz_; } + + // The number of channels in the stream. + size_t num_channels() const { return num_channels_; } + + size_t num_frames() const { return num_frames_; } + size_t num_samples() const { return num_channels_ * num_frames_; } + + bool operator==(const StreamConfig& other) const { + return sample_rate_hz_ == other.sample_rate_hz_ && + num_channels_ == other.num_channels_; + } + + bool operator!=(const StreamConfig& other) const { return !(*this == other); } + + private: + static size_t calculate_frames(int sample_rate_hz) { + return static_cast(AudioProcessing::GetFrameSize(sample_rate_hz)); + } + + int sample_rate_hz_; + size_t num_channels_; + size_t num_frames_; +}; + +class ProcessingConfig { + public: + enum StreamName { + kInputStream, + kOutputStream, + kReverseInputStream, + kReverseOutputStream, + kNumStreamNames, + }; + + const StreamConfig& input_stream() const { + return streams[StreamName::kInputStream]; + } + const StreamConfig& output_stream() const { + return streams[StreamName::kOutputStream]; + } + const StreamConfig& reverse_input_stream() const { + return streams[StreamName::kReverseInputStream]; + } + const StreamConfig& reverse_output_stream() const { + return streams[StreamName::kReverseOutputStream]; + } + + StreamConfig& input_stream() { return streams[StreamName::kInputStream]; } + StreamConfig& output_stream() { return streams[StreamName::kOutputStream]; } + StreamConfig& reverse_input_stream() { + return streams[StreamName::kReverseInputStream]; + } + StreamConfig& reverse_output_stream() { + return streams[StreamName::kReverseOutputStream]; + } + + bool operator==(const ProcessingConfig& other) const { + for (int i = 0; i < StreamName::kNumStreamNames; ++i) { + if (this->streams[i] != other.streams[i]) { + return false; + } + } + return true; + } + + bool operator!=(const ProcessingConfig& other) const { + return !(*this == other); + } + + StreamConfig streams[StreamName::kNumStreamNames]; +}; + +// Interface for an echo detector submodule. +class EchoDetector : public RefCountInterface { + public: + // (Re-)Initializes the submodule. + virtual void Initialize(int capture_sample_rate_hz, + int num_capture_channels, + int render_sample_rate_hz, + int num_render_channels) = 0; + + // Analysis (not changing) of the first channel of the render signal. + virtual void AnalyzeRenderAudio(rtc::ArrayView render_audio) = 0; + + // Analysis (not changing) of the capture signal. + virtual void AnalyzeCaptureAudio( + rtc::ArrayView capture_audio) = 0; + + struct Metrics { + std::optional echo_likelihood; + std::optional echo_likelihood_recent_max; + }; + + // Collect current metrics from the echo detector. + virtual Metrics GetMetrics() const = 0; +}; + +} // namespace webrtc + +#endif // API_AUDIO_AUDIO_PROCESSING_H_ diff --git a/webrtc/modules/audio_processing/include/audio_processing_statistics.cc b/webrtc/api/audio/audio_processing_statistics.cc similarity index 89% rename from webrtc/modules/audio_processing/include/audio_processing_statistics.cc rename to webrtc/api/audio/audio_processing_statistics.cc index 7139ee5..90da7e8 100644 --- a/webrtc/modules/audio_processing/include/audio_processing_statistics.cc +++ b/webrtc/api/audio/audio_processing_statistics.cc @@ -8,7 +8,7 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "modules/audio_processing/include/audio_processing_statistics.h" +#include "api/audio/audio_processing_statistics.h" namespace webrtc { diff --git a/webrtc/api/audio/audio_processing_statistics.h b/webrtc/api/audio/audio_processing_statistics.h new file mode 100644 index 0000000..d6f8b6e --- /dev/null +++ b/webrtc/api/audio/audio_processing_statistics.h @@ -0,0 +1,68 @@ +/* + * Copyright 2017 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef API_AUDIO_AUDIO_PROCESSING_STATISTICS_H_ +#define API_AUDIO_AUDIO_PROCESSING_STATISTICS_H_ + +#include + +#include + +#include "rtc_base/system/rtc_export.h" + +namespace webrtc { +// This version of the stats uses Optionals, it will replace the regular +// AudioProcessingStatistics struct. +struct RTC_EXPORT AudioProcessingStats { + AudioProcessingStats(); + AudioProcessingStats(const AudioProcessingStats& other); + ~AudioProcessingStats(); + + // Deprecated. + // TODO(bugs.webrtc.org/11226): Remove. + // True if voice is detected in the last capture frame, after processing. + // It is conservative in flagging audio as speech, with low likelihood of + // incorrectly flagging a frame as voice. + // Only reported if voice detection is enabled in AudioProcessing::Config. + std::optional voice_detected; + + // AEC Statistics. + // ERL = 10log_10(P_far / P_echo) + std::optional echo_return_loss; + // ERLE = 10log_10(P_echo / P_out) + std::optional echo_return_loss_enhancement; + // Fraction of time that the AEC linear filter is divergent, in a 1-second + // non-overlapped aggregation window. + std::optional divergent_filter_fraction; + + // The delay metrics consists of the delay median and standard deviation. It + // also consists of the fraction of delay estimates that can make the echo + // cancellation perform poorly. The values are aggregated until the first + // call to `GetStatistics()` and afterwards aggregated and updated every + // second. Note that if there are several clients pulling metrics from + // `GetStatistics()` during a session the first call from any of them will + // change to one second aggregation window for all. + std::optional delay_median_ms; + std::optional delay_standard_deviation_ms; + + // Residual echo detector likelihood. + std::optional residual_echo_likelihood; + // Maximum residual echo likelihood from the last time period. + std::optional residual_echo_likelihood_recent_max; + + // The instantaneous delay estimate produced in the AEC. The unit is in + // milliseconds and the value is the instantaneous value at the time of the + // call to `GetStatistics()`. + std::optional delay_ms; +}; + +} // namespace webrtc + +#endif // API_AUDIO_AUDIO_PROCESSING_STATISTICS_H_ diff --git a/webrtc/api/audio/audio_view.h b/webrtc/api/audio/audio_view.h new file mode 100644 index 0000000..e75769b --- /dev/null +++ b/webrtc/api/audio/audio_view.h @@ -0,0 +1,269 @@ +/* + * Copyright (c) 2024 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef API_AUDIO_AUDIO_VIEW_H_ +#define API_AUDIO_AUDIO_VIEW_H_ + +#include "api/array_view.h" +#include "api/audio/channel_layout.h" +#include "rtc_base/checks.h" + +namespace webrtc { + +// This file contains 3 types of view classes: +// +// * MonoView<>: A single channel contiguous buffer of samples. +// +// * InterleavedView<>: Channel samples are interleaved (side-by-side) in +// the buffer. A single channel InterleavedView<> is the same thing as a +// MonoView<> +// +// * DeinterleavedView<>: Each channel's samples are contiguous within the +// buffer. Channels can be enumerated and accessing the individual channel +// data is done via MonoView<>. +// +// The views are comparable to and built on rtc::ArrayView<> but add +// audio specific properties for the dimensions of the buffer and the above +// specialized [de]interleaved support. +// +// There are also a few generic utility functions that can simplify +// generic code for supporting more than one type of view. + +// MonoView<> represents a view over a single contiguous, audio buffer. This +// can be either an single channel (mono) interleaved buffer (e.g. AudioFrame), +// or a de-interleaved channel (e.g. from AudioBuffer). +template +using MonoView = rtc::ArrayView; + +// InterleavedView<> is a view over an interleaved audio buffer (e.g. from +// AudioFrame). +template +class InterleavedView { + public: + using value_type = T; + + InterleavedView() = default; + + template + InterleavedView(U* data, size_t samples_per_channel, size_t num_channels) + : num_channels_(num_channels), + samples_per_channel_(samples_per_channel), + data_(data, num_channels * samples_per_channel) { + RTC_DCHECK_LE(num_channels_, kMaxConcurrentChannels); + RTC_DCHECK(num_channels_ == 0u || samples_per_channel_ != 0u); + } + + // Construct an InterleavedView from a C-style array. Samples per channels + // is calculated based on the array size / num_channels. + template + InterleavedView(U (&array)[N], // NOLINT + size_t num_channels) + : InterleavedView(array, N / num_channels, num_channels) { + RTC_DCHECK_EQ(N % num_channels, 0u); + } + + template + InterleavedView(const InterleavedView& other) + : num_channels_(other.num_channels()), + samples_per_channel_(other.samples_per_channel()), + data_(other.data()) {} + + size_t num_channels() const { return num_channels_; } + size_t samples_per_channel() const { return samples_per_channel_; } + rtc::ArrayView data() const { return data_; } + bool empty() const { return data_.empty(); } + size_t size() const { return data_.size(); } + + MonoView AsMono() const { + RTC_DCHECK_EQ(num_channels(), 1u); + RTC_DCHECK_EQ(data_.size(), samples_per_channel_); + return data_; + } + + // A simple wrapper around memcpy that includes checks for properties. + // TODO(tommi): Consider if this can be utility function for both interleaved + // and deinterleaved views. + template + void CopyFrom(const InterleavedView& source) { + static_assert(sizeof(T) == sizeof(U), ""); + RTC_DCHECK_EQ(num_channels(), source.num_channels()); + RTC_DCHECK_EQ(samples_per_channel(), source.samples_per_channel()); + RTC_DCHECK_GE(data_.size(), source.data().size()); + const auto data = source.data(); + memcpy(&data_[0], &data[0], data.size() * sizeof(U)); + } + + T& operator[](size_t idx) const { return data_[idx]; } + T* begin() const { return data_.begin(); } + T* end() const { return data_.end(); } + const T* cbegin() const { return data_.cbegin(); } + const T* cend() const { return data_.cend(); } + std::reverse_iterator rbegin() const { return data_.rbegin(); } + std::reverse_iterator rend() const { return data_.rend(); } + std::reverse_iterator crbegin() const { return data_.crbegin(); } + std::reverse_iterator crend() const { return data_.crend(); } + + private: + // TODO(tommi): Consider having these both be stored as uint16_t to + // save a few bytes per view. Use `dchecked_cast` to support size_t during + // construction. + size_t num_channels_ = 0u; + size_t samples_per_channel_ = 0u; + rtc::ArrayView data_; +}; + +template +class DeinterleavedView { + public: + using value_type = T; + + DeinterleavedView() = default; + + template + DeinterleavedView(U* data, size_t samples_per_channel, size_t num_channels) + : num_channels_(num_channels), + samples_per_channel_(samples_per_channel), + data_(data, num_channels * samples_per_channel_) {} + + template + DeinterleavedView(const DeinterleavedView& other) + : num_channels_(other.num_channels()), + samples_per_channel_(other.samples_per_channel()), + data_(other.data()) {} + + // Returns a deinterleaved channel where `idx` is the zero based index, + // in the range [0 .. num_channels()-1]. + MonoView operator[](size_t idx) const { + RTC_DCHECK_LT(idx, num_channels_); + return MonoView(&data_[idx * samples_per_channel_], + samples_per_channel_); + } + + size_t num_channels() const { return num_channels_; } + size_t samples_per_channel() const { return samples_per_channel_; } + rtc::ArrayView data() const { return data_; } + bool empty() const { return data_.empty(); } + size_t size() const { return data_.size(); } + + // Returns the first (and possibly only) channel. + MonoView AsMono() const { + RTC_DCHECK_GE(num_channels(), 1u); + return (*this)[0]; + } + + private: + // TODO(tommi): Consider having these be stored as uint16_t to save a few + // bytes per view. Use `dchecked_cast` to support size_t during construction. + size_t num_channels_ = 0u; + size_t samples_per_channel_ = 0u; + rtc::ArrayView data_; +}; + +template +constexpr size_t NumChannels(const MonoView& view) { + return 1u; +} + +template +size_t NumChannels(const InterleavedView& view) { + return view.num_channels(); +} + +template +size_t NumChannels(const DeinterleavedView& view) { + return view.num_channels(); +} + +template +constexpr bool IsMono(const MonoView& view) { + return true; +} + +template +constexpr bool IsInterleavedView(const MonoView& view) { + return true; +} + +template +constexpr bool IsInterleavedView(const InterleavedView& view) { + return true; +} + +template +constexpr bool IsInterleavedView(const DeinterleavedView& view) { + return false; +} + +template +bool IsMono(const InterleavedView& view) { + return NumChannels(view) == 1u; +} + +template +bool IsMono(const DeinterleavedView& view) { + return NumChannels(view) == 1u; +} + +template +size_t SamplesPerChannel(const MonoView& view) { + return view.size(); +} + +template +size_t SamplesPerChannel(const InterleavedView& view) { + return view.samples_per_channel(); +} + +template +size_t SamplesPerChannel(const DeinterleavedView& view) { + return view.samples_per_channel(); +} +// A simple wrapper around memcpy that includes checks for properties. +// The parameter order is the same as for memcpy(), first destination then +// source. +template +void CopySamples(D& destination, const S& source) { + static_assert( + sizeof(typename D::value_type) == sizeof(typename S::value_type), ""); + // Here we'd really like to do + // static_assert(IsInterleavedView(destination) == IsInterleavedView(source), + // ""); + // but the compiler doesn't like it inside this template function for + // some reason. The following check is an approximation but unfortunately + // means that copying between a MonoView and single channel interleaved or + // deinterleaved views wouldn't work. + // static_assert(sizeof(destination) == sizeof(source), + // "Incompatible view types"); + RTC_DCHECK_EQ(NumChannels(destination), NumChannels(source)); + RTC_DCHECK_EQ(SamplesPerChannel(destination), SamplesPerChannel(source)); + RTC_DCHECK_GE(destination.size(), source.size()); + memcpy(&destination[0], &source[0], + source.size() * sizeof(typename S::value_type)); +} + +// Sets all the samples in a view to 0. This template function is a simple +// wrapper around `memset()` but adds the benefit of automatically calculating +// the byte size from the number of samples and sample type. +template +void ClearSamples(T& view) { + memset(&view[0], 0, view.size() * sizeof(typename T::value_type)); +} + +// Same as `ClearSamples()` above but allows for clearing only the first +// `sample_count` number of samples. +template +void ClearSamples(T& view, size_t sample_count) { + RTC_DCHECK_LE(sample_count, view.size()); + memset(&view[0], 0, sample_count * sizeof(typename T::value_type)); +} + +} // namespace webrtc + +#endif // API_AUDIO_AUDIO_VIEW_H_ diff --git a/webrtc/api/audio_codecs/audio_decoder.cc b/webrtc/api/audio_codecs/audio_decoder.cc index 0a131f1..23ef2c8 100644 --- a/webrtc/api/audio_codecs/audio_decoder.cc +++ b/webrtc/api/audio_codecs/audio_decoder.cc @@ -10,10 +10,15 @@ #include "api/audio_codecs/audio_decoder.h" +#include +#include #include +#include #include +#include #include "api/array_view.h" +#include "rtc_base/buffer.h" #include "rtc_base/checks.h" #include "rtc_base/sanitizer.h" #include "rtc_base/trace_event.h" @@ -32,14 +37,14 @@ class OldStyleEncodedFrame final : public AudioDecoder::EncodedAudioFrame { return ret < 0 ? 0 : static_cast(ret); } - absl::optional Decode( + std::optional Decode( rtc::ArrayView decoded) const override { auto speech_type = AudioDecoder::kSpeech; const int ret = decoder_->Decode( payload_.data(), payload_.size(), decoder_->SampleRateHz(), decoded.size() * sizeof(int16_t), decoded.data(), &speech_type); - return ret < 0 ? absl::nullopt - : absl::optional( + return ret < 0 ? std::nullopt + : std::optional( {static_cast(ret), speech_type}); } diff --git a/webrtc/api/audio_codecs/audio_decoder.h b/webrtc/api/audio_codecs/audio_decoder.h index 4113874..21d6056 100644 --- a/webrtc/api/audio_codecs/audio_decoder.h +++ b/webrtc/api/audio_codecs/audio_decoder.h @@ -15,9 +15,9 @@ #include #include +#include #include -#include "absl/types/optional.h" #include "api/array_view.h" #include "rtc_base/buffer.h" @@ -57,11 +57,11 @@ class AudioDecoder { // Decodes this frame of audio and writes the result in `decoded`. // `decoded` must be large enough to store as many samples as indicated by a - // call to Duration() . On success, returns an absl::optional containing the + // call to Duration() . On success, returns an std::optional containing the // total number of samples across all channels, as well as whether the // decoder produced comfort noise or speech. On failure, returns an empty - // absl::optional. Decode may be called at most once per frame object. - virtual absl::optional Decode( + // std::optional. Decode may be called at most once per frame object. + virtual std::optional Decode( rtc::ArrayView decoded) const = 0; }; diff --git a/webrtc/api/audio_codecs/audio_encoder.cc b/webrtc/api/audio_codecs/audio_encoder.cc index 31bb873..de64550 100644 --- a/webrtc/api/audio_codecs/audio_encoder.cc +++ b/webrtc/api/audio_codecs/audio_encoder.cc @@ -10,6 +10,15 @@ #include "api/audio_codecs/audio_encoder.h" +#include +#include +#include +#include +#include + +#include "api/array_view.h" +#include "api/call/bitrate_allocation.h" +#include "rtc_base/buffer.h" #include "rtc_base/checks.h" #include "rtc_base/trace_event.h" @@ -87,12 +96,12 @@ void AudioEncoder::OnReceivedUplinkRecoverablePacketLossFraction( } void AudioEncoder::OnReceivedTargetAudioBitrate(int target_audio_bitrate_bps) { - OnReceivedUplinkBandwidth(target_audio_bitrate_bps, absl::nullopt); + OnReceivedUplinkBandwidth(target_audio_bitrate_bps, std::nullopt); } void AudioEncoder::OnReceivedUplinkBandwidth( int target_audio_bitrate_bps, - absl::optional bwe_period_ms) {} + std::optional bwe_period_ms) {} void AudioEncoder::OnReceivedUplinkAllocation(BitrateAllocationUpdate update) { OnReceivedUplinkBandwidth(update.target_bitrate.bps(), diff --git a/webrtc/api/audio_codecs/audio_encoder.h b/webrtc/api/audio_codecs/audio_encoder.h index 7f5a342..d84d2b5 100644 --- a/webrtc/api/audio_codecs/audio_encoder.h +++ b/webrtc/api/audio_codecs/audio_encoder.h @@ -11,15 +11,19 @@ #ifndef API_AUDIO_CODECS_AUDIO_ENCODER_H_ #define API_AUDIO_CODECS_AUDIO_ENCODER_H_ +#include +#include + #include +#include #include #include #include #include "absl/base/attributes.h" -#include "absl/types/optional.h" #include "api/array_view.h" #include "api/call/bitrate_allocation.h" +#include "api/units/data_rate.h" #include "api/units/time_delta.h" #include "rtc_base/buffer.h" @@ -35,30 +39,30 @@ struct ANAStats { // Number of actions taken by the ANA bitrate controller since the start of // the call. If this value is not set, it indicates that the bitrate // controller is disabled. - absl::optional bitrate_action_counter; + std::optional bitrate_action_counter; // Number of actions taken by the ANA channel controller since the start of // the call. If this value is not set, it indicates that the channel // controller is disabled. - absl::optional channel_action_counter; + std::optional channel_action_counter; // Number of actions taken by the ANA DTX controller since the start of the // call. If this value is not set, it indicates that the DTX controller is // disabled. - absl::optional dtx_action_counter; + std::optional dtx_action_counter; // Number of actions taken by the ANA FEC controller since the start of the // call. If this value is not set, it indicates that the FEC controller is // disabled. - absl::optional fec_action_counter; + std::optional fec_action_counter; // Number of times the ANA frame length controller decided to increase the // frame length since the start of the call. If this value is not set, it // indicates that the frame length controller is disabled. - absl::optional frame_length_increase_counter; + std::optional frame_length_increase_counter; // Number of times the ANA frame length controller decided to decrease the // frame length since the start of the call. If this value is not set, it // indicates that the frame length controller is disabled. - absl::optional frame_length_decrease_counter; + std::optional frame_length_decrease_counter; // The uplink packet loss fractions as set by the ANA FEC controller. If this // value is not set, it indicates that the ANA FEC controller is not active. - absl::optional uplink_packet_loss_fraction; + std::optional uplink_packet_loss_fraction; }; // This is the interface class for encoders in AudioCoding module. Each codec @@ -219,7 +223,7 @@ class AudioEncoder { // Provides target audio bitrate and corresponding probing interval of // the bandwidth estimator to this encoder to allow it to adapt. virtual void OnReceivedUplinkBandwidth(int target_audio_bitrate_bps, - absl::optional bwe_period_ms); + std::optional bwe_period_ms); // Provides target audio bitrate and corresponding probing interval of // the bandwidth estimator to this encoder to allow it to adapt. @@ -240,12 +244,19 @@ class AudioEncoder { // Get statistics related to audio network adaptation. virtual ANAStats GetANAStats() const; - // The range of frame lengths that are supported or nullopt if there's no sch - // information. This is used to calculated the full bitrate range, including - // overhead. - virtual absl::optional> GetFrameLengthRange() + // The range of frame lengths that are supported or nullopt if there's no such + // information. This is used together with the bitrate range to calculate the + // full bitrate range, including overhead. + virtual std::optional> GetFrameLengthRange() const = 0; + // The range of payload bitrates that are supported. This is used together + // with the frame length range to calculate the full bitrate range, including + // overhead. + virtual std::optional> GetBitrateRange() const { + return std::nullopt; + } + // The maximum number of audio channels supported by WebRTC encoders. static constexpr int kMaxNumberOfChannels = 24; diff --git a/webrtc/api/function_view.h b/webrtc/api/function_view.h index 5ae1bd6..b191a05 100644 --- a/webrtc/api/function_view.h +++ b/webrtc/api/function_view.h @@ -11,6 +11,7 @@ #ifndef API_FUNCTION_VIEW_H_ #define API_FUNCTION_VIEW_H_ +#include #include #include diff --git a/webrtc/api/make_ref_counted.h b/webrtc/api/make_ref_counted.h index e958da9..b5f4e99 100644 --- a/webrtc/api/make_ref_counted.h +++ b/webrtc/api/make_ref_counted.h @@ -13,9 +13,12 @@ #include #include +#include "absl/base/nullability.h" +#include "api/ref_count.h" +#include "api/scoped_refptr.h" #include "rtc_base/ref_counted_object.h" -namespace rtc { +namespace webrtc { namespace webrtc_make_ref_counted_internal { // Determines if the given class has AddRef and Release methods. @@ -83,7 +86,7 @@ template < typename std::enable_if && std::is_abstract_v, T>::type* = nullptr> -scoped_refptr make_ref_counted(Args&&... args) { +absl::Nonnull> make_ref_counted(Args&&... args) { return scoped_refptr(new RefCountedObject(std::forward(args)...)); } @@ -96,7 +99,7 @@ template < !std::is_convertible_v && webrtc_make_ref_counted_internal::HasAddRefAndRelease::value, T>::type* = nullptr> -scoped_refptr make_ref_counted(Args&&... args) { +absl::Nonnull> make_ref_counted(Args&&... args) { return scoped_refptr(new T(std::forward(args)...)); } @@ -110,11 +113,18 @@ template < !webrtc_make_ref_counted_internal::HasAddRefAndRelease::value, T>::type* = nullptr> -scoped_refptr> make_ref_counted(Args&&... args) { +absl::Nonnull>> make_ref_counted( + Args&&... args) { return scoped_refptr>( new FinalRefCountedObject(std::forward(args)...)); } +} // namespace webrtc + +namespace rtc { +// Backwards compatibe alias. +// TODO: bugs.webrtc.org/42225969 - deprecate and remove. +using ::webrtc::make_ref_counted; } // namespace rtc #endif // API_MAKE_REF_COUNTED_H_ diff --git a/webrtc/api/meson.build b/webrtc/api/meson.build index 6db5400..1ff54fc 100644 --- a/webrtc/api/meson.build +++ b/webrtc/api/meson.build @@ -1,5 +1,7 @@ api_sources = [ 'audio/audio_frame.cc', + 'audio/audio_processing.cc', + 'audio/audio_processing_statistics.cc', 'audio/channel_layout.cc', 'audio/echo_canceller3_config.cc', 'audio_codecs/audio_decoder.cc', diff --git a/webrtc/api/ref_count.h b/webrtc/api/ref_count.h new file mode 100644 index 0000000..5209277 --- /dev/null +++ b/webrtc/api/ref_count.h @@ -0,0 +1,67 @@ +/* + * Copyright 2011 The WebRTC Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ +#ifndef API_REF_COUNT_H_ +#define API_REF_COUNT_H_ + +namespace webrtc { + +// Refcounted objects should implement the following informal interface: +// +// void AddRef() const ; +// RefCountReleaseStatus Release() const; +// +// You may access members of a reference-counted object, including the AddRef() +// and Release() methods, only if you already own a reference to it, or if +// you're borrowing someone else's reference. (A newly created object is a +// special case: the reference count is zero on construction, and the code that +// creates the object should immediately call AddRef(), bringing the reference +// count from zero to one, e.g., by constructing an rtc::scoped_refptr). +// +// AddRef() creates a new reference to the object. +// +// Release() releases a reference to the object; the caller now has one less +// reference than before the call. Returns kDroppedLastRef if the number of +// references dropped to zero because of this (in which case the object destroys +// itself). Otherwise, returns kOtherRefsRemained, to signal that at the precise +// time the caller's reference was dropped, other references still remained (but +// if other threads own references, this may of course have changed by the time +// Release() returns). +// +// The caller of Release() must treat it in the same way as a delete operation: +// Regardless of the return value from Release(), the caller mustn't access the +// object. The object might still be alive, due to references held by other +// users of the object, but the object can go away at any time, e.g., as the +// result of another thread calling Release(). +// +// Calling AddRef() and Release() manually is discouraged. It's recommended to +// use rtc::scoped_refptr to manage all pointers to reference counted objects. +// Note that rtc::scoped_refptr depends on compile-time duck-typing; formally +// implementing the below RefCountInterface is not required. + +enum class RefCountReleaseStatus { kDroppedLastRef, kOtherRefsRemained }; + +// Interfaces where refcounting is part of the public api should +// inherit this abstract interface. The implementation of these +// methods is usually provided by the RefCountedObject template class, +// applied as a leaf in the inheritance tree. +class RefCountInterface { + public: + virtual void AddRef() const = 0; + virtual RefCountReleaseStatus Release() const = 0; + + // Non-public destructor, because Release() has exclusive responsibility for + // destroying the object. + protected: + virtual ~RefCountInterface() {} +}; + +} // namespace webrtc + +#endif // API_REF_COUNT_H_ diff --git a/webrtc/api/ref_counted_base.h b/webrtc/api/ref_counted_base.h index f20228b..a47a8bb 100644 --- a/webrtc/api/ref_counted_base.h +++ b/webrtc/api/ref_counted_base.h @@ -12,9 +12,10 @@ #include +#include "api/ref_count.h" #include "rtc_base/ref_counter.h" -namespace rtc { +namespace webrtc { class RefCountedBase { public: @@ -93,6 +94,14 @@ class RefCountedNonVirtual { mutable webrtc::webrtc_impl::RefCounter ref_count_{0}; }; +} // namespace webrtc + +// Backwards compatibe aliases. +// TODO: https://issues.webrtc.org/42225969 - deprecate and remove. +namespace rtc { +using RefCountedBase = webrtc::RefCountedBase; +template +using RefCountedNonVirtual = webrtc::RefCountedNonVirtual; } // namespace rtc #endif // API_REF_COUNTED_BASE_H_ diff --git a/webrtc/api/rtp_headers.cc b/webrtc/api/rtp_headers.cc index 0573e54..c272cca 100644 --- a/webrtc/api/rtp_headers.cc +++ b/webrtc/api/rtp_headers.cc @@ -10,8 +10,20 @@ #include "api/rtp_headers.h" +#include "api/video/video_content_type.h" +#include "api/video/video_rotation.h" +#include "rtc_base/checks.h" + namespace webrtc { +AudioLevel::AudioLevel() : voice_activity_(false), audio_level_(0) {} + +AudioLevel::AudioLevel(bool voice_activity, int audio_level) + : voice_activity_(voice_activity), audio_level_(audio_level) { + RTC_CHECK_GE(audio_level, 0); + RTC_CHECK_LE(audio_level, 127); +} + RTPHeaderExtension::RTPHeaderExtension() : hasTransmissionTimeOffset(false), transmissionTimeOffset(0), @@ -19,9 +31,6 @@ RTPHeaderExtension::RTPHeaderExtension() absoluteSendTime(0), hasTransportSequenceNumber(false), transportSequenceNumber(0), - hasAudioLevel(false), - voiceActivity(false), - audioLevel(0), hasVideoRotation(false), videoRotation(kVideoRotation_0), hasVideoContentType(false), diff --git a/webrtc/api/rtp_headers.h b/webrtc/api/rtp_headers.h index 5d4d419..6ba3292 100644 --- a/webrtc/api/rtp_headers.h +++ b/webrtc/api/rtp_headers.h @@ -14,15 +14,16 @@ #include #include +#include #include -#include "absl/types/optional.h" -#include "api/array_view.h" #include "api/units/timestamp.h" #include "api/video/color_space.h" #include "api/video/video_content_type.h" #include "api/video/video_rotation.h" #include "api/video/video_timing.h" +#include "rtc_base/checks.h" +#include "rtc_base/system/rtc_export.h" namespace webrtc { @@ -74,7 +75,30 @@ struct AbsoluteCaptureTime { // system’s NTP clock: // // Capture NTP Clock = Sender NTP Clock + Capture Clock Offset - absl::optional estimated_capture_clock_offset; + std::optional estimated_capture_clock_offset; +}; + +// The audio level extension is used to indicate the voice activity and the +// audio level of the payload in the RTP stream. See: +// https://tools.ietf.org/html/rfc6464#section-3. +class AudioLevel { + public: + AudioLevel(); + AudioLevel(bool voice_activity, int audio_level); + AudioLevel(const AudioLevel& other) = default; + AudioLevel& operator=(const AudioLevel& other) = default; + + // Flag indicating whether the encoder believes the audio packet contains + // voice activity. + bool voice_activity() const { return voice_activity_; } + + // Audio level in -dBov. Values range from 0 to 127, representing 0 to -127 + // dBov. 127 represents digital silence. + int level() const { return audio_level_; } + + private: + bool voice_activity_; + int audio_level_; }; inline bool operator==(const AbsoluteCaptureTime& lhs, @@ -107,16 +131,18 @@ struct RTPHeaderExtension { int32_t transmissionTimeOffset; bool hasAbsoluteSendTime; uint32_t absoluteSendTime; - absl::optional absolute_capture_time; + std::optional absolute_capture_time; bool hasTransportSequenceNumber; uint16_t transportSequenceNumber; - absl::optional feedback_request; + std::optional feedback_request; // Audio Level includes both level in dBov and voiced/unvoiced bit. See: // https://tools.ietf.org/html/rfc6464#section-3 - bool hasAudioLevel; - bool voiceActivity; - uint8_t audioLevel; + std::optional audio_level() const { return audio_level_; } + + void set_audio_level(std::optional audio_level) { + audio_level_ = audio_level; + } // For Coordination of Video Orientation. See // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ @@ -124,7 +150,7 @@ struct RTPHeaderExtension { bool hasVideoRotation; VideoRotation videoRotation; - // TODO(ilnik): Refactor this and one above to be absl::optional() and remove + // TODO(ilnik): Refactor this and one above to be std::optional() and remove // a corresponding bool flag. bool hasVideoContentType; VideoContentType videoContentType; @@ -143,7 +169,10 @@ struct RTPHeaderExtension { // https://tools.ietf.org/html/rfc8843 std::string mid; - absl::optional color_space; + std::optional color_space; + + private: + std::optional audio_level_; }; enum { kRtpCsrcSize = 15 }; // RFC 3550 page 13 diff --git a/webrtc/api/rtp_packet_info.cc b/webrtc/api/rtp_packet_info.cc index cba274e..90cd275 100644 --- a/webrtc/api/rtp_packet_info.cc +++ b/webrtc/api/rtp_packet_info.cc @@ -10,8 +10,15 @@ #include "api/rtp_packet_info.h" +#include + #include +#include #include +#include + +#include "api/rtp_headers.h" +#include "api/units/timestamp.h" namespace webrtc { @@ -37,8 +44,8 @@ RtpPacketInfo::RtpPacketInfo(const RTPHeader& rtp_header, csrcs_.assign(&rtp_header.arrOfCSRCs[0], &rtp_header.arrOfCSRCs[csrcs_count]); - if (extension.hasAudioLevel) { - audio_level_ = extension.audioLevel; + if (extension.audio_level()) { + audio_level_ = extension.audio_level()->level(); } absolute_capture_time_ = extension.absolute_capture_time; diff --git a/webrtc/api/rtp_packet_info.h b/webrtc/api/rtp_packet_info.h index 8df12a3..8e8236d 100644 --- a/webrtc/api/rtp_packet_info.h +++ b/webrtc/api/rtp_packet_info.h @@ -12,10 +12,10 @@ #define API_RTP_PACKET_INFO_H_ #include +#include #include #include -#include "absl/types/optional.h" #include "api/rtp_headers.h" #include "api/units/time_delta.h" #include "api/units/timestamp.h" @@ -56,26 +56,26 @@ class RTC_EXPORT RtpPacketInfo { Timestamp receive_time() const { return receive_time_; } void set_receive_time(Timestamp value) { receive_time_ = value; } - absl::optional audio_level() const { return audio_level_; } - RtpPacketInfo& set_audio_level(absl::optional value) { + std::optional audio_level() const { return audio_level_; } + RtpPacketInfo& set_audio_level(std::optional value) { audio_level_ = value; return *this; } - const absl::optional& absolute_capture_time() const { + const std::optional& absolute_capture_time() const { return absolute_capture_time_; } RtpPacketInfo& set_absolute_capture_time( - const absl::optional& value) { + const std::optional& value) { absolute_capture_time_ = value; return *this; } - const absl::optional& local_capture_clock_offset() const { + const std::optional& local_capture_clock_offset() const { return local_capture_clock_offset_; } RtpPacketInfo& set_local_capture_clock_offset( - absl::optional value) { + std::optional value) { local_capture_clock_offset_ = value; return *this; } @@ -92,18 +92,18 @@ class RTC_EXPORT RtpPacketInfo { // Fields from the Audio Level header extension: // https://tools.ietf.org/html/rfc6464#section-3 - absl::optional audio_level_; + std::optional audio_level_; // Fields from the Absolute Capture Time header extension: // http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time - absl::optional absolute_capture_time_; + std::optional absolute_capture_time_; // Clock offset between the local clock and the capturer's clock. // Do not confuse with `AbsoluteCaptureTime::estimated_capture_clock_offset` // which instead represents the clock offset between a remote sender and the // capturer. The following holds: // Capture's NTP Clock = Local NTP Clock + Local-Capture Clock Offset - absl::optional local_capture_clock_offset_; + std::optional local_capture_clock_offset_; }; bool operator==(const RtpPacketInfo& lhs, const RtpPacketInfo& rhs); diff --git a/webrtc/api/rtp_packet_infos.h b/webrtc/api/rtp_packet_infos.h index 7445729..dfb4e1e 100644 --- a/webrtc/api/rtp_packet_infos.h +++ b/webrtc/api/rtp_packet_infos.h @@ -11,7 +11,6 @@ #ifndef API_RTP_PACKET_INFOS_H_ #define API_RTP_PACKET_INFOS_H_ -#include #include #include diff --git a/webrtc/api/scoped_refptr.h b/webrtc/api/scoped_refptr.h index e145509..c6fb560 100644 --- a/webrtc/api/scoped_refptr.h +++ b/webrtc/api/scoped_refptr.h @@ -22,13 +22,13 @@ // }; // // void some_function() { -// scoped_refptr foo = new MyFoo(); +// scoped_refptr foo = make_ref_counted(); // foo->Method(param); // // `foo` is released when this function returns // } // // void some_other_function() { -// scoped_refptr foo = new MyFoo(); +// scoped_refptr foo = make_ref_counted(); // ... // foo = nullptr; // explicitly releases `foo` // ... @@ -41,7 +41,7 @@ // references between the two objects, like so: // // { -// scoped_refptr a = new MyFoo(); +// scoped_refptr a = make_ref_counted(); // scoped_refptr b; // // b.swap(a); @@ -52,7 +52,7 @@ // object, simply use the assignment operator: // // { -// scoped_refptr a = new MyFoo(); +// scoped_refptr a = make_ref_counted(); // scoped_refptr b; // // b = a; @@ -63,20 +63,23 @@ #ifndef API_SCOPED_REFPTR_H_ #define API_SCOPED_REFPTR_H_ -#include +#include #include -namespace rtc { +#include "absl/base/nullability.h" + +namespace webrtc { template -class scoped_refptr { +class ABSL_NULLABILITY_COMPATIBLE scoped_refptr { public: - typedef T element_type; + using absl_nullability_compatible = void; + using element_type = T; scoped_refptr() : ptr_(nullptr) {} scoped_refptr(std::nullptr_t) : ptr_(nullptr) {} // NOLINT(runtime/explicit) - explicit scoped_refptr(T* p) : ptr_(p) { + explicit scoped_refptr(absl::Nullable p) : ptr_(p) { if (ptr_) ptr_->AddRef(); } @@ -119,7 +122,7 @@ class scoped_refptr { return retVal; } - scoped_refptr& operator=(T* p) { + scoped_refptr& operator=(absl::Nullable p) { // AddRef first so that self assignment should work if (p) p->AddRef(); @@ -149,7 +152,7 @@ class scoped_refptr { return *this; } - void swap(T** pp) noexcept { + void swap(absl::Nonnull pp) noexcept { T* p = ptr_; ptr_ = *pp; *pp = p; @@ -162,61 +165,65 @@ class scoped_refptr { }; template -bool operator==(const rtc::scoped_refptr& a, - const rtc::scoped_refptr& b) { +bool operator==(const scoped_refptr& a, const scoped_refptr& b) { return a.get() == b.get(); } template -bool operator!=(const rtc::scoped_refptr& a, - const rtc::scoped_refptr& b) { +bool operator!=(const scoped_refptr& a, const scoped_refptr& b) { return !(a == b); } template -bool operator==(const rtc::scoped_refptr& a, std::nullptr_t) { +bool operator==(const scoped_refptr& a, std::nullptr_t) { return a.get() == nullptr; } template -bool operator!=(const rtc::scoped_refptr& a, std::nullptr_t) { +bool operator!=(const scoped_refptr& a, std::nullptr_t) { return !(a == nullptr); } template -bool operator==(std::nullptr_t, const rtc::scoped_refptr& a) { +bool operator==(std::nullptr_t, const scoped_refptr& a) { return a.get() == nullptr; } template -bool operator!=(std::nullptr_t, const rtc::scoped_refptr& a) { +bool operator!=(std::nullptr_t, const scoped_refptr& a) { return !(a == nullptr); } // Comparison with raw pointer. template -bool operator==(const rtc::scoped_refptr& a, const U* b) { +bool operator==(const scoped_refptr& a, const U* b) { return a.get() == b; } template -bool operator!=(const rtc::scoped_refptr& a, const U* b) { +bool operator!=(const scoped_refptr& a, const U* b) { return !(a == b); } template -bool operator==(const T* a, const rtc::scoped_refptr& b) { +bool operator==(const T* a, const scoped_refptr& b) { return a == b.get(); } template -bool operator!=(const T* a, const rtc::scoped_refptr& b) { +bool operator!=(const T* a, const scoped_refptr& b) { return !(a == b); } // Ordered comparison, needed for use as a std::map key. template -bool operator<(const rtc::scoped_refptr& a, const rtc::scoped_refptr& b) { +bool operator<(const scoped_refptr& a, const scoped_refptr& b) { return a.get() < b.get(); } +} // namespace webrtc + +namespace rtc { +// Backwards compatible alias. +// TODO: bugs.webrtc.org/42225969 - Deprecate and remove. +using ::webrtc::scoped_refptr; } // namespace rtc #endif // API_SCOPED_REFPTR_H_ diff --git a/webrtc/api/sequence_checker.h b/webrtc/api/sequence_checker.h index 5ff5860..2c352f7 100644 --- a/webrtc/api/sequence_checker.h +++ b/webrtc/api/sequence_checker.h @@ -10,6 +10,7 @@ #ifndef API_SEQUENCE_CHECKER_H_ #define API_SEQUENCE_CHECKER_H_ +#include "api/task_queue/task_queue_base.h" #include "rtc_base/checks.h" #include "rtc_base/synchronization/sequence_checker_internal.h" #include "rtc_base/thread_annotations.h" diff --git a/webrtc/api/task_queue/queued_task.h b/webrtc/api/task_queue/queued_task.h deleted file mode 100644 index 5748628..0000000 --- a/webrtc/api/task_queue/queued_task.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2018 The WebRTC Project Authors. All rights reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ -#ifndef API_TASK_QUEUE_QUEUED_TASK_H_ -#define API_TASK_QUEUE_QUEUED_TASK_H_ - -namespace webrtc { - -// Base interface for asynchronously executed tasks. -// The interface basically consists of a single function, Run(), that executes -// on the target queue. For more details see the Run() method and TaskQueue. -class QueuedTask { - public: - virtual ~QueuedTask() = default; - - // Main routine that will run when the task is executed on the desired queue. - // The task should return |true| to indicate that it should be deleted or - // |false| to indicate that the queue should consider ownership of the task - // having been transferred. Returning |false| can be useful if a task has - // re-posted itself to a different queue or is otherwise being re-used. - virtual bool Run() = 0; -}; - -} // namespace webrtc - -#endif // API_TASK_QUEUE_QUEUED_TASK_H_ diff --git a/webrtc/api/task_queue/task_queue_base.cc b/webrtc/api/task_queue/task_queue_base.cc index ecdc7f7..6533aa0 100644 --- a/webrtc/api/task_queue/task_queue_base.cc +++ b/webrtc/api/task_queue/task_queue_base.cc @@ -11,9 +11,6 @@ #include "absl/base/attributes.h" #include "absl/base/config.h" -#include "absl/functional/any_invocable.h" -#include "api/units/time_delta.h" -#include "rtc_base/checks.h" #if defined(ABSL_HAVE_THREAD_LOCAL) diff --git a/webrtc/api/task_queue/task_queue_base.h b/webrtc/api/task_queue/task_queue_base.h index 89e9e9e..8b7bb1b 100644 --- a/webrtc/api/task_queue/task_queue_base.h +++ b/webrtc/api/task_queue/task_queue_base.h @@ -10,7 +10,6 @@ #ifndef API_TASK_QUEUE_TASK_QUEUE_BASE_H_ #define API_TASK_QUEUE_TASK_QUEUE_BASE_H_ -#include #include #include "absl/functional/any_invocable.h" diff --git a/webrtc/api/units/data_rate.cc b/webrtc/api/units/data_rate.cc index f9586c5..c1ad9b3 100644 --- a/webrtc/api/units/data_rate.cc +++ b/webrtc/api/units/data_rate.cc @@ -10,6 +10,8 @@ #include "api/units/data_rate.h" +#include + #include "api/array_view.h" #include "rtc_base/strings/string_builder.h" diff --git a/webrtc/api/units/data_rate.h b/webrtc/api/units/data_rate.h index d813c61..341f74e 100644 --- a/webrtc/api/units/data_rate.h +++ b/webrtc/api/units/data_rate.h @@ -11,10 +11,7 @@ #ifndef API_UNITS_DATA_RATE_H_ #define API_UNITS_DATA_RATE_H_ -#ifdef WEBRTC_UNIT_TEST -#include // no-presubmit-check TODO(webrtc:8982) -#endif // WEBRTC_UNIT_TEST - +#include #include #include #include @@ -23,6 +20,7 @@ #include "api/units/frequency.h" #include "api/units/time_delta.h" #include "rtc_base/checks.h" +#include "rtc_base/system/rtc_export.h" #include "rtc_base/units/unit_base.h" // IWYU pragma: export namespace webrtc { @@ -50,6 +48,9 @@ class DataRate final : public rtc_units_impl::RelativeUnit { DataRate() = delete; + template + friend void AbslStringify(Sink& sink, DataRate value); + template constexpr T bps() const { return ToValue(); @@ -137,18 +138,15 @@ inline constexpr DataRate operator*(const Frequency frequency, return size * frequency; } -std::string ToString(DataRate value); +RTC_EXPORT std::string ToString(DataRate value); inline std::string ToLogString(DataRate value) { return ToString(value); } -#ifdef WEBRTC_UNIT_TEST -inline std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982) - std::ostream& stream, // no-presubmit-check TODO(webrtc:8982) - DataRate value) { - return stream << ToString(value); +template +void AbslStringify(Sink& sink, DataRate value) { + sink.Append(ToString(value)); } -#endif // WEBRTC_UNIT_TEST } // namespace webrtc diff --git a/webrtc/api/units/data_size.cc b/webrtc/api/units/data_size.cc index 45487df..3d2cc6e 100644 --- a/webrtc/api/units/data_size.cc +++ b/webrtc/api/units/data_size.cc @@ -10,6 +10,8 @@ #include "api/units/data_size.h" +#include + #include "api/array_view.h" #include "rtc_base/strings/string_builder.h" diff --git a/webrtc/api/units/data_size.h b/webrtc/api/units/data_size.h index 9df6434..409df61 100644 --- a/webrtc/api/units/data_size.h +++ b/webrtc/api/units/data_size.h @@ -11,13 +11,11 @@ #ifndef API_UNITS_DATA_SIZE_H_ #define API_UNITS_DATA_SIZE_H_ -#ifdef WEBRTC_UNIT_TEST -#include // no-presubmit-check TODO(webrtc:8982) -#endif // WEBRTC_UNIT_TEST - +#include #include #include +#include "rtc_base/system/rtc_export.h" #include "rtc_base/units/unit_base.h" // IWYU pragma: export namespace webrtc { @@ -33,6 +31,9 @@ class DataSize final : public rtc_units_impl::RelativeUnit { DataSize() = delete; + template + friend void AbslStringify(Sink& sink, DataSize value); + template constexpr T bytes() const { return ToValue(); @@ -48,18 +49,15 @@ class DataSize final : public rtc_units_impl::RelativeUnit { static constexpr bool one_sided = true; }; -std::string ToString(DataSize value); +RTC_EXPORT std::string ToString(DataSize value); inline std::string ToLogString(DataSize value) { return ToString(value); } -#ifdef WEBRTC_UNIT_TEST -inline std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982) - std::ostream& stream, // no-presubmit-check TODO(webrtc:8982) - DataSize value) { - return stream << ToString(value); +template +void AbslStringify(Sink& sink, DataSize value) { + sink.Append(ToString(value)); } -#endif // WEBRTC_UNIT_TEST } // namespace webrtc diff --git a/webrtc/api/units/frequency.cc b/webrtc/api/units/frequency.cc index 2d938a2..3bf3118 100644 --- a/webrtc/api/units/frequency.cc +++ b/webrtc/api/units/frequency.cc @@ -9,6 +9,9 @@ */ #include "api/units/frequency.h" +#include +#include + #include "rtc_base/strings/string_builder.h" namespace webrtc { diff --git a/webrtc/api/units/frequency.h b/webrtc/api/units/frequency.h index 06081e4..225db55 100644 --- a/webrtc/api/units/frequency.h +++ b/webrtc/api/units/frequency.h @@ -10,16 +10,15 @@ #ifndef API_UNITS_FREQUENCY_H_ #define API_UNITS_FREQUENCY_H_ -#ifdef WEBRTC_UNIT_TEST -#include // no-presubmit-check TODO(webrtc:8982) -#endif // WEBRTC_UNIT_TEST - +#include #include #include #include #include #include "api/units/time_delta.h" +#include "rtc_base/checks.h" +#include "rtc_base/system/rtc_export.h" #include "rtc_base/units/unit_base.h" // IWYU pragma: export namespace webrtc { @@ -44,6 +43,9 @@ class Frequency final : public rtc_units_impl::RelativeUnit { Frequency() = delete; + template + friend void AbslStringify(Sink& sink, Frequency value); + template constexpr T hertz() const { return ToFraction<1000, T>(); @@ -84,18 +86,15 @@ inline constexpr double operator*(TimeDelta time_delta, Frequency frequency) { return frequency * time_delta; } -std::string ToString(Frequency value); +RTC_EXPORT std::string ToString(Frequency value); inline std::string ToLogString(Frequency value) { return ToString(value); } -#ifdef WEBRTC_UNIT_TEST -inline std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982) - std::ostream& stream, // no-presubmit-check TODO(webrtc:8982) - Frequency value) { - return stream << ToString(value); +template +void AbslStringify(Sink& sink, Frequency value) { + sink.Append(ToString(value)); } -#endif // WEBRTC_UNIT_TEST } // namespace webrtc #endif // API_UNITS_FREQUENCY_H_ diff --git a/webrtc/api/units/time_delta.cc b/webrtc/api/units/time_delta.cc index 31bf3e0..0788a9c 100644 --- a/webrtc/api/units/time_delta.cc +++ b/webrtc/api/units/time_delta.cc @@ -10,6 +10,8 @@ #include "api/units/time_delta.h" +#include + #include "api/array_view.h" #include "rtc_base/strings/string_builder.h" diff --git a/webrtc/api/units/time_delta.h b/webrtc/api/units/time_delta.h index 5981e32..c00b443 100644 --- a/webrtc/api/units/time_delta.h +++ b/webrtc/api/units/time_delta.h @@ -11,14 +11,12 @@ #ifndef API_UNITS_TIME_DELTA_H_ #define API_UNITS_TIME_DELTA_H_ -#ifdef WEBRTC_UNIT_TEST -#include // no-presubmit-check TODO(webrtc:8982) -#endif // WEBRTC_UNIT_TEST - +#include #include #include #include +#include "rtc_base/system/rtc_export.h" #include "rtc_base/units/unit_base.h" // IWYU pragma: export namespace webrtc { @@ -55,6 +53,9 @@ class TimeDelta final : public rtc_units_impl::RelativeUnit { TimeDelta() = delete; + template + friend void AbslStringify(Sink& sink, TimeDelta value); + template constexpr T seconds() const { return ToFraction<1000000, T>(); @@ -92,18 +93,15 @@ class TimeDelta final : public rtc_units_impl::RelativeUnit { static constexpr bool one_sided = false; }; -std::string ToString(TimeDelta value); +RTC_EXPORT std::string ToString(TimeDelta value); inline std::string ToLogString(TimeDelta value) { return ToString(value); } -#ifdef WEBRTC_UNIT_TEST -inline std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982) - std::ostream& stream, // no-presubmit-check TODO(webrtc:8982) - TimeDelta value) { - return stream << ToString(value); +template +void AbslStringify(Sink& sink, TimeDelta value) { + sink.Append(ToString(value)); } -#endif // WEBRTC_UNIT_TEST } // namespace webrtc diff --git a/webrtc/api/units/timestamp.cc b/webrtc/api/units/timestamp.cc index fc4f419..9c42a50 100644 --- a/webrtc/api/units/timestamp.cc +++ b/webrtc/api/units/timestamp.cc @@ -10,6 +10,8 @@ #include "api/units/timestamp.h" +#include + #include "api/array_view.h" #include "rtc_base/strings/string_builder.h" diff --git a/webrtc/api/units/timestamp.h b/webrtc/api/units/timestamp.h index 8aabe05..177bea1 100644 --- a/webrtc/api/units/timestamp.h +++ b/webrtc/api/units/timestamp.h @@ -11,15 +11,13 @@ #ifndef API_UNITS_TIMESTAMP_H_ #define API_UNITS_TIMESTAMP_H_ -#ifdef WEBRTC_UNIT_TEST -#include // no-presubmit-check TODO(webrtc:8982) -#endif // WEBRTC_UNIT_TEST - +#include #include #include #include "api/units/time_delta.h" #include "rtc_base/checks.h" +#include "rtc_base/system/rtc_export.h" #include "rtc_base/units/unit_base.h" // IWYU pragma: export namespace webrtc { @@ -47,6 +45,9 @@ class Timestamp final : public rtc_units_impl::UnitBase { Timestamp() = delete; + template + friend void AbslStringify(Sink& sink, Timestamp value); + template constexpr T seconds() const { return ToFraction<1000000, T>(); @@ -121,18 +122,15 @@ class Timestamp final : public rtc_units_impl::UnitBase { static constexpr bool one_sided = true; }; -std::string ToString(Timestamp value); +RTC_EXPORT std::string ToString(Timestamp value); inline std::string ToLogString(Timestamp value) { return ToString(value); } -#ifdef WEBRTC_UNIT_TEST -inline std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982) - std::ostream& stream, // no-presubmit-check TODO(webrtc:8982) - Timestamp value) { - return stream << ToString(value); +template +void AbslStringify(Sink& sink, Timestamp value) { + sink.Append(ToString(value)); } -#endif // WEBRTC_UNIT_TEST } // namespace webrtc diff --git a/webrtc/api/video/color_space.cc b/webrtc/api/video/color_space.cc index dcb9c67..99648a3 100644 --- a/webrtc/api/video/color_space.cc +++ b/webrtc/api/video/color_space.cc @@ -10,6 +10,12 @@ #include "api/video/color_space.h" +#include +#include +#include +#include + +#include "api/video/hdr_metadata.h" #include "rtc_base/strings/string_builder.h" namespace webrtc { @@ -95,8 +101,8 @@ ColorSpace::ColorSpace(PrimaryID primaries, range_(range), chroma_siting_horizontal_(chroma_siting_horz), chroma_siting_vertical_(chroma_siting_vert), - hdr_metadata_(hdr_metadata ? absl::make_optional(*hdr_metadata) - : absl::nullopt) {} + hdr_metadata_(hdr_metadata ? std::make_optional(*hdr_metadata) + : std::nullopt) {} ColorSpace::PrimaryID ColorSpace::primaries() const { return primaries_; @@ -257,7 +263,7 @@ bool ColorSpace::set_chroma_siting_vertical_from_uint8(uint8_t enum_value) { void ColorSpace::set_hdr_metadata(const HdrMetadata* hdr_metadata) { hdr_metadata_ = - hdr_metadata ? absl::make_optional(*hdr_metadata) : absl::nullopt; + hdr_metadata ? std::make_optional(*hdr_metadata) : std::nullopt; } } // namespace webrtc diff --git a/webrtc/api/video/color_space.h b/webrtc/api/video/color_space.h index 31963a1..00f5cb9 100644 --- a/webrtc/api/video/color_space.h +++ b/webrtc/api/video/color_space.h @@ -13,9 +13,9 @@ #include +#include #include -#include "absl/types/optional.h" #include "api/video/hdr_metadata.h" #include "rtc_base/system/rtc_export.h" @@ -174,7 +174,7 @@ class RTC_EXPORT ColorSpace { RangeID range_ = RangeID::kInvalid; ChromaSiting chroma_siting_horizontal_ = ChromaSiting::kUnspecified; ChromaSiting chroma_siting_vertical_ = ChromaSiting::kUnspecified; - absl::optional hdr_metadata_; + std::optional hdr_metadata_; }; } // namespace webrtc diff --git a/webrtc/api/video/video_content_type.cc b/webrtc/api/video/video_content_type.cc index 79da9ff..75beb5c 100644 --- a/webrtc/api/video/video_content_type.cc +++ b/webrtc/api/video/video_content_type.cc @@ -10,6 +10,8 @@ #include "api/video/video_content_type.h" +#include + #include "rtc_base/checks.h" namespace webrtc { diff --git a/webrtc/api/video/video_timing.cc b/webrtc/api/video/video_timing.cc index d16911f..8e9e9f0 100644 --- a/webrtc/api/video/video_timing.cc +++ b/webrtc/api/video/video_timing.cc @@ -11,6 +11,8 @@ #include "api/video/video_timing.h" #include +#include +#include #include "api/array_view.h" #include "api/units/time_delta.h" diff --git a/webrtc/audio/utility/BUILD.gn b/webrtc/audio/utility/BUILD.gn index 983b628..2ced9aa 100644 --- a/webrtc/audio/utility/BUILD.gn +++ b/webrtc/audio/utility/BUILD.gn @@ -23,14 +23,14 @@ rtc_library("audio_frame_operations") { ] deps = [ + "../../api:array_view", "../../api/audio:audio_frame_api", "../../common_audio", "../../rtc_base:checks", "../../rtc_base:logging", "../../rtc_base:safe_conversions", - "../../system_wrappers:field_trial", + "//third_party/abseil-cpp/absl/base:core_headers", ] - absl_deps = [ "//third_party/abseil-cpp/absl/base:core_headers" ] } if (rtc_include_tests) { @@ -48,7 +48,6 @@ if (rtc_include_tests) { "../../rtc_base:logging", "../../rtc_base:macromagic", "../../rtc_base:stringutils", - "../../test:field_trial", "../../test:test_support", "//testing/gtest", ] diff --git a/webrtc/audio/utility/audio_frame_operations.cc b/webrtc/audio/utility/audio_frame_operations.cc index 1b936c2..cf709e7 100644 --- a/webrtc/audio/utility/audio_frame_operations.cc +++ b/webrtc/audio/utility/audio_frame_operations.cc @@ -29,72 +29,17 @@ const float kMuteFadeInc = 1.0f / kMuteFadeFrames; } // namespace -void AudioFrameOperations::Add(const AudioFrame& frame_to_add, - AudioFrame* result_frame) { - // Sanity check. - RTC_DCHECK(result_frame); - RTC_DCHECK_GT(result_frame->num_channels_, 0); - RTC_DCHECK_EQ(result_frame->num_channels_, frame_to_add.num_channels_); - - bool no_previous_data = result_frame->muted(); - if (result_frame->samples_per_channel_ != frame_to_add.samples_per_channel_) { - // Special case we have no data to start with. - RTC_DCHECK_EQ(result_frame->samples_per_channel_, 0); - result_frame->samples_per_channel_ = frame_to_add.samples_per_channel_; - no_previous_data = true; - } - - if (result_frame->vad_activity_ == AudioFrame::kVadActive || - frame_to_add.vad_activity_ == AudioFrame::kVadActive) { - result_frame->vad_activity_ = AudioFrame::kVadActive; - } else if (result_frame->vad_activity_ == AudioFrame::kVadUnknown || - frame_to_add.vad_activity_ == AudioFrame::kVadUnknown) { - result_frame->vad_activity_ = AudioFrame::kVadUnknown; - } - - if (result_frame->speech_type_ != frame_to_add.speech_type_) - result_frame->speech_type_ = AudioFrame::kUndefined; - - if (!frame_to_add.muted()) { - const int16_t* in_data = frame_to_add.data(); - int16_t* out_data = result_frame->mutable_data(); - size_t length = - frame_to_add.samples_per_channel_ * frame_to_add.num_channels_; - if (no_previous_data) { - std::copy(in_data, in_data + length, out_data); - } else { - for (size_t i = 0; i < length; i++) { - const int32_t wrap_guard = static_cast(out_data[i]) + - static_cast(in_data[i]); - out_data[i] = rtc::saturated_cast(wrap_guard); - } - } - } -} - -int AudioFrameOperations::MonoToStereo(AudioFrame* frame) { - if (frame->num_channels_ != 1) { - return -1; - } - UpmixChannels(2, frame); - return 0; -} - -int AudioFrameOperations::StereoToMono(AudioFrame* frame) { - if (frame->num_channels_ != 2) { - return -1; - } - DownmixChannels(1, frame); - return frame->num_channels_ == 1 ? 0 : -1; -} - -void AudioFrameOperations::QuadToStereo(const int16_t* src_audio, - size_t samples_per_channel, - int16_t* dst_audio) { - for (size_t i = 0; i < samples_per_channel; i++) { - dst_audio[i * 2] = +void AudioFrameOperations::QuadToStereo( + InterleavedView src_audio, + InterleavedView dst_audio) { + RTC_DCHECK_EQ(NumChannels(src_audio), 4); + RTC_DCHECK_EQ(NumChannels(dst_audio), 2); + RTC_DCHECK_EQ(SamplesPerChannel(src_audio), SamplesPerChannel(dst_audio)); + for (size_t i = 0; i < SamplesPerChannel(src_audio); ++i) { + auto dst_frame = i * 2; + dst_audio[dst_frame] = (static_cast(src_audio[4 * i]) + src_audio[4 * i + 1]) >> 1; - dst_audio[i * 2 + 1] = + dst_audio[dst_frame + 1] = (static_cast(src_audio[4 * i + 2]) + src_audio[4 * i + 3]) >> 1; } @@ -109,30 +54,34 @@ int AudioFrameOperations::QuadToStereo(AudioFrame* frame) { AudioFrame::kMaxDataSizeSamples); if (!frame->muted()) { - QuadToStereo(frame->data(), frame->samples_per_channel_, - frame->mutable_data()); + // Note that `src` and `dst` will map in to the same buffer, but the call + // to `mutable_data()` changes the layout of `frame`, so `src` and `dst` + // will have different dimensions (important to call `data_view()` first). + auto src = frame->data_view(); + auto dst = frame->mutable_data(frame->samples_per_channel_, 2); + QuadToStereo(src, dst); + } else { + frame->num_channels_ = 2; } - frame->num_channels_ = 2; return 0; } -void AudioFrameOperations::DownmixChannels(const int16_t* src_audio, - size_t src_channels, - size_t samples_per_channel, - size_t dst_channels, - int16_t* dst_audio) { - if (src_channels > 1 && dst_channels == 1) { - DownmixInterleavedToMono(src_audio, samples_per_channel, src_channels, - dst_audio); - return; - } else if (src_channels == 4 && dst_channels == 2) { - QuadToStereo(src_audio, samples_per_channel, dst_audio); - return; +void AudioFrameOperations::DownmixChannels( + InterleavedView src_audio, + InterleavedView dst_audio) { + RTC_DCHECK_EQ(SamplesPerChannel(src_audio), SamplesPerChannel(dst_audio)); + if (NumChannels(src_audio) > 1 && IsMono(dst_audio)) { + // TODO(tommi): change DownmixInterleavedToMono to support InterleavedView + // and MonoView. + DownmixInterleavedToMono(&src_audio.data()[0], SamplesPerChannel(src_audio), + NumChannels(src_audio), &dst_audio.data()[0]); + } else if (NumChannels(src_audio) == 4 && NumChannels(dst_audio) == 2) { + QuadToStereo(src_audio, dst_audio); + } else { + RTC_DCHECK_NOTREACHED() << "src_channels: " << NumChannels(src_audio) + << ", dst_channels: " << NumChannels(dst_audio); } - - RTC_DCHECK_NOTREACHED() << "src_channels: " << src_channels - << ", dst_channels: " << dst_channels; } void AudioFrameOperations::DownmixChannels(size_t dst_channels, @@ -169,14 +118,16 @@ void AudioFrameOperations::UpmixChannels(size_t target_number_of_channels, if (!frame->muted()) { // Up-mixing done in place. Going backwards through the frame ensure nothing // is irrevocably overwritten. - int16_t* frame_data = frame->mutable_data(); - for (int i = frame->samples_per_channel_ - 1; i >= 0; i--) { + auto frame_data = frame->mutable_data(frame->samples_per_channel_, + target_number_of_channels); + for (int i = frame->samples_per_channel_ - 1; i >= 0; --i) { for (size_t j = 0; j < target_number_of_channels; ++j) { frame_data[target_number_of_channels * i + j] = frame_data[i]; } } + } else { + frame->num_channels_ = target_number_of_channels; } - frame->num_channels_ = target_number_of_channels; } void AudioFrameOperations::SwapStereoChannels(AudioFrame* frame) { @@ -250,35 +201,6 @@ void AudioFrameOperations::Mute(AudioFrame* frame) { Mute(frame, true, true); } -void AudioFrameOperations::ApplyHalfGain(AudioFrame* frame) { - RTC_DCHECK(frame); - RTC_DCHECK_GT(frame->num_channels_, 0); - if (frame->num_channels_ < 1 || frame->muted()) { - return; - } - - int16_t* frame_data = frame->mutable_data(); - for (size_t i = 0; i < frame->samples_per_channel_ * frame->num_channels_; - i++) { - frame_data[i] = frame_data[i] >> 1; - } -} - -int AudioFrameOperations::Scale(float left, float right, AudioFrame* frame) { - if (frame->num_channels_ != 2) { - return -1; - } else if (frame->muted()) { - return 0; - } - - int16_t* frame_data = frame->mutable_data(); - for (size_t i = 0; i < frame->samples_per_channel_; i++) { - frame_data[2 * i] = static_cast(left * frame_data[2 * i]); - frame_data[2 * i + 1] = static_cast(right * frame_data[2 * i + 1]); - } - return 0; -} - int AudioFrameOperations::ScaleWithSat(float scale, AudioFrame* frame) { if (frame->muted()) { return 0; diff --git a/webrtc/audio/utility/audio_frame_operations.h b/webrtc/audio/utility/audio_frame_operations.h index 2a5f29f..41ea05e 100644 --- a/webrtc/audio/utility/audio_frame_operations.h +++ b/webrtc/audio/utility/audio_frame_operations.h @@ -15,6 +15,7 @@ #include #include "absl/base/attributes.h" +#include "api/array_view.h" #include "api/audio/audio_frame.h" namespace webrtc { @@ -24,33 +25,11 @@ namespace webrtc { // than a class. class AudioFrameOperations { public: - // Add samples in `frame_to_add` with samples in `result_frame` - // putting the results in `results_frame`. The fields - // `vad_activity_` and `speech_type_` of the result frame are - // updated. If `result_frame` is empty (`samples_per_channel_`==0), - // the samples in `frame_to_add` are added to it. The number of - // channels and number of samples per channel must match except when - // `result_frame` is empty. - static void Add(const AudioFrame& frame_to_add, AudioFrame* result_frame); - - // `frame.num_channels_` will be updated. This version checks for sufficient - // buffer size and that `num_channels_` is mono. Use UpmixChannels - // instead. TODO(bugs.webrtc.org/8649): remove. - ABSL_DEPRECATED("bugs.webrtc.org/8649") - static int MonoToStereo(AudioFrame* frame); - - // `frame.num_channels_` will be updated. This version checks that - // `num_channels_` is stereo. Use DownmixChannels - // instead. TODO(bugs.webrtc.org/8649): remove. - ABSL_DEPRECATED("bugs.webrtc.org/8649") - static int StereoToMono(AudioFrame* frame); - // Downmixes 4 channels `src_audio` to stereo `dst_audio`. This is an in-place // operation, meaning `src_audio` and `dst_audio` may point to the same // buffer. - static void QuadToStereo(const int16_t* src_audio, - size_t samples_per_channel, - int16_t* dst_audio); + static void QuadToStereo(InterleavedView src_audio, + InterleavedView dst_audio); // `frame.num_channels_` will be updated. This version checks that // `num_channels_` is 4 channels. @@ -60,11 +39,8 @@ class AudioFrameOperations { // This is an in-place operation, meaning `src_audio` and `dst_audio` // may point to the same buffer. Supported channel combinations are // Stereo to Mono, Quad to Mono, and Quad to Stereo. - static void DownmixChannels(const int16_t* src_audio, - size_t src_channels, - size_t samples_per_channel, - size_t dst_channels, - int16_t* dst_audio); + static void DownmixChannels(InterleavedView src_audio, + InterleavedView dst_audio); // `frame.num_channels_` will be updated. This version checks that // `num_channels_` and `dst_channels` are valid and performs relevant downmix. @@ -94,11 +70,6 @@ class AudioFrameOperations { // Zero out contents of frame. static void Mute(AudioFrame* frame); - // Halve samples in `frame`. - static void ApplyHalfGain(AudioFrame* frame); - - static int Scale(float left, float right, AudioFrame* frame); - static int ScaleWithSat(float scale, AudioFrame* frame); }; diff --git a/webrtc/common_audio/BUILD.gn b/webrtc/common_audio/BUILD.gn index 2ae6d32..3d1688f 100644 --- a/webrtc/common_audio/BUILD.gn +++ b/webrtc/common_audio/BUILD.gn @@ -46,6 +46,7 @@ rtc_library("common_audio") { ":common_audio_c", ":sinc_resampler", "../api:array_view", + "../api/audio:audio_frame_api", "../rtc_base:checks", "../rtc_base:gtest_prod", "../rtc_base:logging", @@ -58,7 +59,6 @@ rtc_library("common_audio") { "../system_wrappers", "third_party/ooura:fft_size_256", ] - absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] defines = [] diff --git a/webrtc/common_audio/channel_buffer.h b/webrtc/common_audio/channel_buffer.h index 9f08d60..583f7d7 100644 --- a/webrtc/common_audio/channel_buffer.h +++ b/webrtc/common_audio/channel_buffer.h @@ -23,6 +23,44 @@ namespace webrtc { +// TODO: b/335805780 - Remove this method. Instead, use Deinterleave() from +// audio_util.h which requires size checked buffer views. +template +void Deinterleave(const T* interleaved, + size_t samples_per_channel, + size_t num_channels, + T* const* deinterleaved) { + for (size_t i = 0; i < num_channels; ++i) { + T* channel = deinterleaved[i]; + size_t interleaved_idx = i; + for (size_t j = 0; j < samples_per_channel; ++j) { + channel[j] = interleaved[interleaved_idx]; + interleaved_idx += num_channels; + } + } +} + +// `Interleave()` variant for cases where the deinterleaved channels aren't +// represented by a `DeinterleavedView`. +// TODO: b/335805780 - Remove this method. Instead, use Deinterleave() from +// audio_util.h which requires size checked buffer views. +template +void Interleave(const T* const* deinterleaved, + size_t samples_per_channel, + size_t num_channels, + InterleavedView& interleaved) { + RTC_DCHECK_EQ(NumChannels(interleaved), num_channels); + RTC_DCHECK_EQ(SamplesPerChannel(interleaved), samples_per_channel); + for (size_t i = 0; i < num_channels; ++i) { + const T* channel = deinterleaved[i]; + size_t interleaved_idx = i; + for (size_t j = 0; j < samples_per_channel; ++j) { + interleaved[interleaved_idx] = channel[j]; + interleaved_idx += num_channels; + } + } +} + // Helper to encapsulate a contiguous data buffer, full or split into frequency // bands, with access to a pointer arrays of the deinterleaved channels and // bands. The buffer is zero initialized at creation. diff --git a/webrtc/common_audio/include/audio_util.h b/webrtc/common_audio/include/audio_util.h index 4ce4680..672ebd1 100644 --- a/webrtc/common_audio/include/audio_util.h +++ b/webrtc/common_audio/include/audio_util.h @@ -18,12 +18,24 @@ #include #include +#include "api/audio/audio_view.h" #include "rtc_base/checks.h" namespace webrtc { typedef std::numeric_limits limits_int16; +// TODO(tommi, peah): Move these constants to their own header, e.g. +// `audio_constants.h`. Also consider if they should be in api/. + +// Absolute highest acceptable sample rate supported for audio processing, +// capture and codecs. Note that for some components some cases a lower limit +// applies which typically is 48000 but in some cases is lower. +constexpr int kMaxSampleRateHz = 384000; + +// Number of samples per channel for 10ms of audio at the highest sample rate. +constexpr size_t kMaxSamplesPerChannel10ms = kMaxSampleRateHz / 100u; + // The conversion functions use the following naming convention: // S16: int16_t [-32768, 32767] // Float: float [-1.0, 1.0] @@ -94,6 +106,7 @@ inline float FloatS16ToDbfs(float v) { // Copy audio from `src` channels to `dest` channels unless `src` and `dest` // point to the same address. `src` and `dest` must have the same number of // channels, and there must be sufficient space allocated in `dest`. +// TODO: b/335805780 - Accept ArrayView. template void CopyAudioIfNeeded(const T* const* src, int num_frames, @@ -111,12 +124,15 @@ void CopyAudioIfNeeded(const T* const* src, // `deinterleaved` buffers (`num_channel` buffers with `samples_per_channel` // per buffer). template -void Deinterleave(const T* interleaved, - size_t samples_per_channel, - size_t num_channels, - T* const* deinterleaved) { +void Deinterleave(const InterleavedView& interleaved, + const DeinterleavedView& deinterleaved) { + RTC_DCHECK_EQ(NumChannels(interleaved), NumChannels(deinterleaved)); + RTC_DCHECK_EQ(SamplesPerChannel(interleaved), + SamplesPerChannel(deinterleaved)); + const auto num_channels = NumChannels(interleaved); + const auto samples_per_channel = SamplesPerChannel(interleaved); for (size_t i = 0; i < num_channels; ++i) { - T* channel = deinterleaved[i]; + MonoView channel = deinterleaved[i]; size_t interleaved_idx = i; for (size_t j = 0; j < samples_per_channel; ++j) { channel[j] = interleaved[interleaved_idx]; @@ -129,52 +145,24 @@ void Deinterleave(const T* interleaved, // `interleaved`. There must be sufficient space allocated in `interleaved` // (`samples_per_channel` * `num_channels`). template -void Interleave(const T* const* deinterleaved, - size_t samples_per_channel, - size_t num_channels, - T* interleaved) { - for (size_t i = 0; i < num_channels; ++i) { - const T* channel = deinterleaved[i]; +void Interleave(const DeinterleavedView& deinterleaved, + const InterleavedView& interleaved) { + RTC_DCHECK_EQ(NumChannels(interleaved), NumChannels(deinterleaved)); + RTC_DCHECK_EQ(SamplesPerChannel(interleaved), + SamplesPerChannel(deinterleaved)); + for (size_t i = 0; i < deinterleaved.num_channels(); ++i) { + const auto channel = deinterleaved[i]; size_t interleaved_idx = i; - for (size_t j = 0; j < samples_per_channel; ++j) { + for (size_t j = 0; j < deinterleaved.samples_per_channel(); ++j) { interleaved[interleaved_idx] = channel[j]; - interleaved_idx += num_channels; + interleaved_idx += deinterleaved.num_channels(); } } } -// Copies audio from a single channel buffer pointed to by `mono` to each -// channel of `interleaved`. There must be sufficient space allocated in -// `interleaved` (`samples_per_channel` * `num_channels`). -template -void UpmixMonoToInterleaved(const T* mono, - int num_frames, - int num_channels, - T* interleaved) { - int interleaved_idx = 0; - for (int i = 0; i < num_frames; ++i) { - for (int j = 0; j < num_channels; ++j) { - interleaved[interleaved_idx++] = mono[i]; - } - } -} - -template -void DownmixToMono(const T* const* input_channels, - size_t num_frames, - int num_channels, - T* out) { - for (size_t i = 0; i < num_frames; ++i) { - Intermediate value = input_channels[0][i]; - for (int j = 1; j < num_channels; ++j) { - value += input_channels[j][i]; - } - out[i] = value / num_channels; - } -} - // Downmixes an interleaved multichannel signal to a single channel by averaging // all channels. +// TODO: b/335805780 - Accept InterleavedView and DeinterleavedView. template void DownmixInterleavedToMonoImpl(const T* interleaved, size_t num_frames, @@ -197,12 +185,14 @@ void DownmixInterleavedToMonoImpl(const T* interleaved, } } +// TODO: b/335805780 - Accept InterleavedView and DeinterleavedView. template void DownmixInterleavedToMono(const T* interleaved, size_t num_frames, int num_channels, T* deinterleaved); +// TODO: b/335805780 - Accept InterleavedView and DeinterleavedView. template <> void DownmixInterleavedToMono(const int16_t* interleaved, size_t num_frames, diff --git a/webrtc/common_audio/resampler/include/push_resampler.h b/webrtc/common_audio/resampler/include/push_resampler.h index 3da6712..394e96b 100644 --- a/webrtc/common_audio/resampler/include/push_resampler.h +++ b/webrtc/common_audio/resampler/include/push_resampler.h @@ -14,45 +14,44 @@ #include #include +#include "api/audio/audio_view.h" + namespace webrtc { class PushSincResampler; // Wraps PushSincResampler to provide stereo support. -// TODO(ajm): add support for an arbitrary number of channels. +// Note: This implementation assumes 10ms buffer sizes throughout. template -class PushResampler { +class PushResampler final { public: PushResampler(); - virtual ~PushResampler(); - - // Must be called whenever the parameters change. Free to be called at any - // time as it is a no-op if parameters have not changed since the last call. - int InitializeIfNeeded(int src_sample_rate_hz, - int dst_sample_rate_hz, - size_t num_channels); + PushResampler(size_t src_samples_per_channel, + size_t dst_samples_per_channel, + size_t num_channels); + ~PushResampler(); // Returns the total number of samples provided in destination (e.g. 32 kHz, // 2 channel audio gives 640 samples). - int Resample(const T* src, size_t src_length, T* dst, size_t dst_capacity); + int Resample(InterleavedView src, InterleavedView dst); + // For when a deinterleaved/mono channel already exists and we can skip the + // deinterleaved operation. + int Resample(MonoView src, MonoView dst); private: - int src_sample_rate_hz_; - int dst_sample_rate_hz_; - size_t num_channels_; - // Vector that is needed to provide the proper inputs and outputs to the - // interleave/de-interleave methods used in Resample. This needs to be - // heap-allocated on the state to support an arbitrary number of channels - // without doing run-time heap-allocations in the Resample method. - std::vector channel_data_array_; + // Ensures that source and destination buffers for deinterleaving are + // correctly configured prior to resampling that requires deinterleaving. + void EnsureInitialized(size_t src_samples_per_channel, + size_t dst_samples_per_channel, + size_t num_channels); - struct ChannelResampler { - std::unique_ptr resampler; - std::vector source; - std::vector destination; - }; + // Buffers used for when a deinterleaving step is necessary. + std::unique_ptr source_; + std::unique_ptr destination_; + DeinterleavedView source_view_; + DeinterleavedView destination_view_; - std::vector channel_resamplers_; + std::vector> resamplers_; }; } // namespace webrtc diff --git a/webrtc/common_audio/resampler/push_resampler.cc b/webrtc/common_audio/resampler/push_resampler.cc index 810d778..2e75679 100644 --- a/webrtc/common_audio/resampler/push_resampler.cc +++ b/webrtc/common_audio/resampler/push_resampler.cc @@ -15,105 +15,109 @@ #include +#include "api/audio/audio_frame.h" #include "common_audio/include/audio_util.h" #include "common_audio/resampler/push_sinc_resampler.h" #include "rtc_base/checks.h" namespace webrtc { -template -PushResampler::PushResampler() - : src_sample_rate_hz_(0), dst_sample_rate_hz_(0), num_channels_(0) {} +namespace { +// Maximum concurrent number of channels for `PushResampler<>`. +// Note that this may be different from what the maximum is for audio codecs. +constexpr int kMaxNumberOfChannels = 8; +} // namespace template -PushResampler::~PushResampler() {} +PushResampler::PushResampler() = default; template -int PushResampler::InitializeIfNeeded(int src_sample_rate_hz, - int dst_sample_rate_hz, - size_t num_channels) { - // These checks used to be factored out of this template function due to - // Windows debug build issues with clang. http://crbug.com/615050 - RTC_DCHECK_GT(src_sample_rate_hz, 0); - RTC_DCHECK_GT(dst_sample_rate_hz, 0); - RTC_DCHECK_GT(num_channels, 0); - - if (src_sample_rate_hz == src_sample_rate_hz_ && - dst_sample_rate_hz == dst_sample_rate_hz_ && - num_channels == num_channels_) { - // No-op if settings haven't changed. - return 0; - } - - if (src_sample_rate_hz <= 0 || dst_sample_rate_hz <= 0 || num_channels <= 0) { - return -1; - } - - src_sample_rate_hz_ = src_sample_rate_hz; - dst_sample_rate_hz_ = dst_sample_rate_hz; - num_channels_ = num_channels; - - const size_t src_size_10ms_mono = - static_cast(src_sample_rate_hz / 100); - const size_t dst_size_10ms_mono = - static_cast(dst_sample_rate_hz / 100); - channel_resamplers_.clear(); - for (size_t i = 0; i < num_channels; ++i) { - channel_resamplers_.push_back(ChannelResampler()); - auto channel_resampler = channel_resamplers_.rbegin(); - channel_resampler->resampler = std::make_unique( - src_size_10ms_mono, dst_size_10ms_mono); - channel_resampler->source.resize(src_size_10ms_mono); - channel_resampler->destination.resize(dst_size_10ms_mono); - } - - channel_data_array_.resize(num_channels_); - - return 0; +PushResampler::PushResampler(size_t src_samples_per_channel, + size_t dst_samples_per_channel, + size_t num_channels) { + EnsureInitialized(src_samples_per_channel, dst_samples_per_channel, + num_channels); } template -int PushResampler::Resample(const T* src, - size_t src_length, - T* dst, - size_t dst_capacity) { - // These checks used to be factored out of this template function due to - // Windows debug build issues with clang. http://crbug.com/615050 - const size_t src_size_10ms = (src_sample_rate_hz_ / 100) * num_channels_; - const size_t dst_size_10ms = (dst_sample_rate_hz_ / 100) * num_channels_; - RTC_DCHECK_EQ(src_length, src_size_10ms); - RTC_DCHECK_GE(dst_capacity, dst_size_10ms); +PushResampler::~PushResampler() = default; - if (src_sample_rate_hz_ == dst_sample_rate_hz_) { +template +void PushResampler::EnsureInitialized(size_t src_samples_per_channel, + size_t dst_samples_per_channel, + size_t num_channels) { + RTC_DCHECK_GT(src_samples_per_channel, 0); + RTC_DCHECK_GT(dst_samples_per_channel, 0); + RTC_DCHECK_GT(num_channels, 0); + RTC_DCHECK_LE(src_samples_per_channel, kMaxSamplesPerChannel10ms); + RTC_DCHECK_LE(dst_samples_per_channel, kMaxSamplesPerChannel10ms); + RTC_DCHECK_LE(num_channels, kMaxNumberOfChannels); + + if (src_samples_per_channel == SamplesPerChannel(source_view_) && + dst_samples_per_channel == SamplesPerChannel(destination_view_) && + num_channels == NumChannels(source_view_)) { + // No-op if settings haven't changed. + return; + } + + // Allocate two buffers for all source and destination channels. + // Then organize source and destination views together with an array of + // resamplers for each channel in the deinterlaved buffers. + source_.reset(new T[src_samples_per_channel * num_channels]); + destination_.reset(new T[dst_samples_per_channel * num_channels]); + source_view_ = DeinterleavedView(source_.get(), src_samples_per_channel, + num_channels); + destination_view_ = DeinterleavedView( + destination_.get(), dst_samples_per_channel, num_channels); + resamplers_.resize(num_channels); + for (size_t i = 0; i < num_channels; ++i) { + resamplers_[i] = std::make_unique( + src_samples_per_channel, dst_samples_per_channel); + } +} + +template +int PushResampler::Resample(InterleavedView src, + InterleavedView dst) { + EnsureInitialized(SamplesPerChannel(src), SamplesPerChannel(dst), + NumChannels(src)); + + RTC_DCHECK_EQ(NumChannels(src), NumChannels(source_view_)); + RTC_DCHECK_EQ(NumChannels(dst), NumChannels(destination_view_)); + RTC_DCHECK_EQ(SamplesPerChannel(src), SamplesPerChannel(source_view_)); + RTC_DCHECK_EQ(SamplesPerChannel(dst), SamplesPerChannel(destination_view_)); + + if (SamplesPerChannel(src) == SamplesPerChannel(dst)) { // The old resampler provides this memcpy facility in the case of matching // sample rates, so reproduce it here for the sinc resampler. - memcpy(dst, src, src_length * sizeof(T)); - return static_cast(src_length); + CopySamples(dst, src); + return static_cast(src.data().size()); } - const size_t src_length_mono = src_length / num_channels_; - const size_t dst_capacity_mono = dst_capacity / num_channels_; + Deinterleave(src, source_view_); - for (size_t ch = 0; ch < num_channels_; ++ch) { - channel_data_array_[ch] = channel_resamplers_[ch].source.data(); + for (size_t i = 0; i < resamplers_.size(); ++i) { + size_t dst_length_mono = + resamplers_[i]->Resample(source_view_[i], destination_view_[i]); + RTC_DCHECK_EQ(dst_length_mono, SamplesPerChannel(dst)); } - Deinterleave(src, src_length_mono, num_channels_, channel_data_array_.data()); + Interleave(destination_view_, dst); + return static_cast(dst.size()); +} - size_t dst_length_mono = 0; +template +int PushResampler::Resample(MonoView src, MonoView dst) { + RTC_DCHECK_EQ(resamplers_.size(), 1); + RTC_DCHECK_EQ(SamplesPerChannel(src), SamplesPerChannel(source_view_)); + RTC_DCHECK_EQ(SamplesPerChannel(dst), SamplesPerChannel(destination_view_)); - for (auto& resampler : channel_resamplers_) { - dst_length_mono = resampler.resampler->Resample( - resampler.source.data(), src_length_mono, resampler.destination.data(), - dst_capacity_mono); + if (SamplesPerChannel(src) == SamplesPerChannel(dst)) { + CopySamples(dst, src); + return static_cast(src.size()); } - for (size_t ch = 0; ch < num_channels_; ++ch) { - channel_data_array_[ch] = channel_resamplers_[ch].destination.data(); - } - - Interleave(channel_data_array_.data(), dst_length_mono, num_channels_, dst); - return static_cast(dst_length_mono * num_channels_); + return resamplers_[0]->Resample(src, dst); } // Explictly generate required instantiations. diff --git a/webrtc/common_audio/resampler/push_sinc_resampler.h b/webrtc/common_audio/resampler/push_sinc_resampler.h index 7946ef8..b2c7155 100644 --- a/webrtc/common_audio/resampler/push_sinc_resampler.h +++ b/webrtc/common_audio/resampler/push_sinc_resampler.h @@ -16,6 +16,7 @@ #include +#include "api/audio/audio_view.h" #include "common_audio/resampler/sinc_resampler.h" namespace webrtc { @@ -40,6 +41,12 @@ class PushSincResampler : public SincResamplerCallback { // at least as large as `destination_frames`. Returns the number of samples // provided in destination (for convenience, since this will always be equal // to `destination_frames`). + template + size_t Resample(const MonoView& source, const MonoView& destination) { + return Resample(&source[0], SamplesPerChannel(source), &destination[0], + SamplesPerChannel(destination)); + } + size_t Resample(const int16_t* source, size_t source_frames, int16_t* destination, diff --git a/webrtc/common_audio/signal_processing/filter_ar.c b/webrtc/common_audio/signal_processing/filter_ar.c index b1f666d..b76e388 100644 --- a/webrtc/common_audio/signal_processing/filter_ar.c +++ b/webrtc/common_audio/signal_processing/filter_ar.c @@ -26,10 +26,8 @@ size_t WebRtcSpl_FilterAR(const int16_t* a, int16_t* state, size_t state_length, int16_t* state_low, - size_t state_low_length, int16_t* filtered, - int16_t* filtered_low, - size_t filtered_low_length) + int16_t* filtered_low) { int64_t o; int32_t oLOW; diff --git a/webrtc/common_audio/signal_processing/include/signal_processing_library.h b/webrtc/common_audio/signal_processing/include/signal_processing_library.h index 48c9b30..ac0d277 100644 --- a/webrtc/common_audio/signal_processing/include/signal_processing_library.h +++ b/webrtc/common_audio/signal_processing/include/signal_processing_library.h @@ -621,10 +621,8 @@ size_t WebRtcSpl_FilterAR(const int16_t* ar_coef, int16_t* filter_state, size_t filter_state_length, int16_t* filter_state_low, - size_t filter_state_low_length, int16_t* out_vector, - int16_t* out_vector_low, - size_t out_vector_low_length); + int16_t* out_vector_low); // WebRtcSpl_FilterMAFastQ12(...) // @@ -1464,9 +1462,6 @@ void WebRtcSpl_SynthesisQMF(const int16_t* low_band, // - filter_state : Current state (higher part) of the filter. // - filter_state_length : Length (in samples) of `filter_state`. // - filter_state_low : Current state (lower part) of the filter. -// - filter_state_low_length : Length (in samples) of `filter_state_low`. -// - out_vector_low_length : Maximum length (in samples) of -// `out_vector_low`. // // Output: // - filter_state : Updated state (upper part) vector. diff --git a/webrtc/common_audio/smoothing_filter.cc b/webrtc/common_audio/smoothing_filter.cc index eaaf3a0..1c603f6 100644 --- a/webrtc/common_audio/smoothing_filter.cc +++ b/webrtc/common_audio/smoothing_filter.cc @@ -55,10 +55,10 @@ void SmoothingFilterImpl::AddSample(float sample) { last_sample_ = sample; } -absl::optional SmoothingFilterImpl::GetAverage() { +std::optional SmoothingFilterImpl::GetAverage() { if (!init_end_time_ms_) { // `init_end_time_ms_` undefined since we have not received any sample. - return absl::nullopt; + return std::nullopt; } ExtrapolateLastSample(rtc::TimeMillis()); return state_; diff --git a/webrtc/common_audio/smoothing_filter.h b/webrtc/common_audio/smoothing_filter.h index 3419de7..488cc97 100644 --- a/webrtc/common_audio/smoothing_filter.h +++ b/webrtc/common_audio/smoothing_filter.h @@ -13,7 +13,7 @@ #include -#include "absl/types/optional.h" +#include namespace webrtc { @@ -21,7 +21,7 @@ class SmoothingFilter { public: virtual ~SmoothingFilter() = default; virtual void AddSample(float sample) = 0; - virtual absl::optional GetAverage() = 0; + virtual std::optional GetAverage() = 0; virtual bool SetTimeConstantMs(int time_constant_ms) = 0; }; @@ -49,7 +49,7 @@ class SmoothingFilterImpl final : public SmoothingFilter { ~SmoothingFilterImpl() override; void AddSample(float sample) override; - absl::optional GetAverage() override; + std::optional GetAverage() override; bool SetTimeConstantMs(int time_constant_ms) override; // Methods used for unittests. @@ -63,7 +63,7 @@ class SmoothingFilterImpl final : public SmoothingFilter { const float init_factor_; const float init_const_; - absl::optional init_end_time_ms_; + std::optional init_end_time_ms_; float last_sample_; float alpha_; float state_; diff --git a/webrtc/experiments/BUILD.gn b/webrtc/experiments/BUILD.gn new file mode 100644 index 0000000..82fce7f --- /dev/null +++ b/webrtc/experiments/BUILD.gn @@ -0,0 +1,26 @@ +# Copyright (c) 2022 The WebRTC project authors. All Rights Reserved. +# +# Use of this source code is governed by a BSD-style license +# that can be found in the LICENSE file in the root of the source +# tree. An additional intellectual property rights grant can be found +# in the file PATENTS. All contributing project authors may +# be found in the AUTHORS file in the root of the source tree. + +import("../webrtc.gni") + +action("registered_field_trials_header") { + visibility = [ ":*" ] + script = "field_trials.py" + args = [ + "header", + "--output", + rebase_path(target_gen_dir, root_build_dir) + "/registered_field_trials.h", + ] + outputs = [ "$target_gen_dir/registered_field_trials.h" ] +} + +rtc_library("registered_field_trials") { + visibility = [ "*" ] + sources = get_target_outputs(":registered_field_trials_header") + deps = [ ":registered_field_trials_header" ] +} diff --git a/webrtc/experiments/field_trials.py b/webrtc/experiments/field_trials.py new file mode 100755 index 0000000..602b46a --- /dev/null +++ b/webrtc/experiments/field_trials.py @@ -0,0 +1,1129 @@ +#!/usr/bin/env vpython3 + +# Copyright (c) 2022 The WebRTC Project Authors. All Rights Reserved. +# +# Use of this source code is governed by a BSD-style license +# that can be found in the LICENSE file in the root of the source +# tree. An additional intellectual property rights grant can be found +# in the file PATENTS. All contributing project authors may +# be found in the AUTHORS file in the root of the source tree. + +import datetime +from datetime import date +import hashlib +import sys +from typing import FrozenSet, List, Set + +import argparse +import dataclasses + + +@dataclasses.dataclass(frozen=True) +class FieldTrial: + """Representation of all attributes associated with a field trial. + + Attributes: + key: Field trial key. + bug_id: Associated open bug containing more context. + end_date: Date when the field trial expires and must be deleted. + """ + key: str + bug_id: int + end_date: date + + def bug_url(self) -> str: + if self.bug_id <= 0: + return '' + return f'https://issues.webrtc.org/issues/{self.bug_id}' + + +# As per the policy in `g3doc/field-trials.md`, all field trials should be +# registered in the container below. +ACTIVE_FIELD_TRIALS: FrozenSet[FieldTrial] = frozenset([ + # keep-sorted start + FieldTrial('WebRTC-Aec3BufferingMaxAllowedExcessRenderBlocksOverride', + 337900458, + date(2024, 9, 1)), + FieldTrial('WebRTC-Audio-GainController2', + 42232605, + date(2024, 4, 1)), + FieldTrial('WebRTC-Audio-OpusGeneratePlc', + 42223518, + date(2025, 4, 1)), + FieldTrial('WebRTC-Audio-PriorityBitrate', + 42226125, + date(2024, 4, 1)), + FieldTrial('WebRTC-AV1-OverridePriorityBitrate', + 42226119, + date(2024, 4, 1)), + FieldTrial('WebRTC-Av1-GetEncoderInfoOverride', + 42225234, + date(2024, 4, 1)), + FieldTrial('WebRTC-BitrateAdjusterUseNewfangledHeadroomAdjustment', + 349561566, + date(2025, 8, 26)), + FieldTrial('WebRTC-Bwe-LimitPacingFactorByUpperLinkCapacityEstimate', + 42220543, + date(2025, 1, 1)), + FieldTrial('WebRTC-Bwe-ResetOnAdapterIdChange', + 42225231, + date(2025, 5, 30)), + FieldTrial('WebRTC-DataChannelMessageInterleaving', + 41481008, + date(2024, 10, 1)), + FieldTrial('WebRTC-DisableRtxRateLimiter', + 42225500, + date(2024, 4, 1)), + FieldTrial('WebRTC-ElasticBitrateAllocation', + 350555527, + date(2025, 3, 1)), + FieldTrial('WebRTC-EncoderDataDumpDirectory', + 296242528, + date(2024, 4, 1)), + FieldTrial('WebRTC-FrameCadenceAdapter-UseVideoFrameTimestamp', + 42226256, + date(2024, 10, 1)), + FieldTrial('WebRTC-IPv6NetworkResolutionFixes', + 42224598, + date(2024, 4, 1)), + FieldTrial('WebRTC-IncomingTimestampOnMarkerBitOnly', + 42224805, + date(2024, 4, 1)), + FieldTrial('WebRTC-IncreaseIceCandidatePriorityHostSrflx', + 42225331, + date(2024, 4, 1)), + FieldTrial('WebRTC-JitterEstimatorConfig', + 42224404, + date(2024, 4, 1)), + FieldTrial('WebRTC-LibaomAv1Encoder-AdaptiveMaxConsecDrops', + 351644568, + date(2025, 7, 1)), + FieldTrial('WebRTC-LibvpxVp8Encoder-AndroidSpecificThreadingSettings', + 42226191, + date(2024, 9, 1)), + FieldTrial('WebRTC-MixedCodecSimulcast', + 362277533, + date(2025, 9, 1)), + FieldTrial('WebRTC-Pacer-FastRetransmissions', + 40235589, + date(2024, 4, 1)), + FieldTrial('WebRTC-Pacer-KeyframeFlushing', + 42221435, + date(2024, 4, 1)), + FieldTrial('WebRTC-PermuteTlsClientHello', + 42225803, + date(2025, 1, 1)), + FieldTrial('WebRTC-DisableTlsSessionTicketKillswitch', + 367181089, + date(2025, 7, 1)), + FieldTrial('WebRTC-QCM-Dynamic-AV1', + 349860657, + date(2025, 7, 1)), + FieldTrial('WebRTC-QCM-Dynamic-VP8', + 349860657, + date(2025, 7, 1)), + FieldTrial('WebRTC-QCM-Dynamic-VP9', + 349860657, + date(2025, 7, 1)), + FieldTrial('WebRTC-QCM-Static-AV1', + 349860657, + date(2025, 7, 1)), + FieldTrial('WebRTC-QCM-Static-VP8', + 349860657, + date(2025, 7, 1)), + FieldTrial('WebRTC-QCM-Static-VP9', + 349860657, + date(2025, 7, 1)), + FieldTrial('WebRTC-ReceiveBufferSize', + 42225927, + date(2024, 4, 1)), + FieldTrial('WebRTC-RFC8888CongestionControlFeedback', + 42225697, + date(2025, 1, 30)), + FieldTrial('WebRTC-RtcEventLogEncodeDependencyDescriptor', + 42225280, + date(2024, 4, 1)), + FieldTrial('WebRTC-RtcEventLogEncodeNetEqSetMinimumDelayKillSwitch', + 42225058, + date(2024, 4, 1)), + FieldTrial('WebRTC-EncryptedRtpHeaderExtensions', + 358039777, + date(2025, 10, 4)), + FieldTrial('WebRTC-SetReadyToSendFalseIfSendFail', + 361124449, + date(2024, 12, 1)), + FieldTrial('WebRTC-SetCodecPreferences-ReceiveOnlyFilterInsteadOfThrow', + 40644399, + date(2024, 12, 1)), + FieldTrial('WebRTC-SrtpRemoveReceiveStream', + 42225949, + date(2024, 10, 1)), + FieldTrial('WebRTC-TaskQueue-ReplaceLibeventWithStdlib', + 42224654, + date(2024, 4, 1)), + FieldTrial('WebRTC-PayloadTypesInTransport', + 360058654, + date(2025, 9, 11)), + FieldTrial('WebRTC-UseNtpTimeAbsoluteSendTime', + 42226305, + date(2024, 9, 1)), + FieldTrial('WebRTC-VP8-MaxFrameInterval', + 42225870, + date(2024, 4, 1)), + FieldTrial('WebRTC-VP9-SvcForSimulcast', + 347737882, + date(2024, 10, 1)), + FieldTrial('WebRTC-Video-AV1EvenPayloadSizes', + 42226301, + date(2024, 11, 1)), + FieldTrial('WebRTC-Video-EnableRetransmitAllLayers', + 42225262, + date(2024, 4, 1)), + FieldTrial('WebRTC-Video-EncoderFallbackSettings', + 42231704, + date(2024, 4, 1)), + FieldTrial('WebRTC-Video-SimulcastIndependentFrameIds', + 42226243, + date(2024, 12, 1)), + FieldTrial('WebRTC-VideoEncoderSettings', + 40252667, + date(2024, 4, 1)), + FieldTrial('WebRTC-ZeroHertzQueueOverload', + 42225879, + date(2024, 7, 1)), + FieldTrial('WebRTC-Video-H26xPacketBuffer', + 41480904, + date(2024, 6, 1)), + FieldTrial('WebRTC-Video-Vp9FlexibleMode', + 329396373, + date(2025, 6, 26)), + # keep-sorted end +]) # yapf: disable + +NO_BUG = -1 +INDEFINITE = date(datetime.MAXYEAR, 1, 1) + +# These field trials precedes the policy in `g3doc/field-trials.md` and are +# therefore not required to follow it. Do not add any new field trials here. +# If you remove an entry you should also update +# POLICY_EXEMPT_FIELD_TRIALS_DIGEST. +POLICY_EXEMPT_FIELD_TRIALS: FrozenSet[FieldTrial] = frozenset([ + # keep-sorted start + FieldTrial('WebRTC-AddNetworkCostToVpn', + 42223280, + date(2024, 4, 1)), + FieldTrial('WebRTC-AddPacingToCongestionWindowPushback', + 42220204, + date(2024, 4, 1)), + FieldTrial('WebRTC-AdjustOpusBandwidth', + 42233664, + date(2024, 4, 1)), + FieldTrial('WebRTC-Aec3AecStateFullResetKillSwitch', + 42221578, + INDEFINITE), + FieldTrial('WebRTC-Aec3AecStateSubtractorAnalyzerResetKillSwitch', + 42221578, + INDEFINITE), + FieldTrial('WebRTC-Aec3AntiHowlingMinimizationKillSwitch', + 150764764, + INDEFINITE), + FieldTrial('WebRTC-Aec3ClampInstQualityToOneKillSwitch', + 42220991, + INDEFINITE), + FieldTrial('WebRTC-Aec3ClampInstQualityToZeroKillSwitch', + 42220991, + INDEFINITE), + FieldTrial('WebRTC-Aec3CoarseFilterResetHangoverKillSwitch', + 42222401, + date(2024, 4, 1)), + FieldTrial('WebRTC-Aec3ConservativeTailFreqResponse', + 42223361, + date(2024, 4, 1)), + FieldTrial('WebRTC-Aec3DeactivateInitialStateResetKillSwitch', + 42221578, + date(2024, 4, 1)), + FieldTrial('WebRTC-Aec3DelayEstimateSmoothingDelayFoundOverride', + 42222934, + date(2024, 4, 1)), + FieldTrial('WebRTC-Aec3DelayEstimateSmoothingOverride', + 42222934, + date(2024, 4, 1)), + FieldTrial('WebRTC-Aec3EchoSaturationDetectionKillSwitch', + 42221578, + INDEFINITE), + FieldTrial('WebRTC-Aec3EnforceCaptureDelayEstimationDownmixing', + 42221238, + INDEFINITE), + FieldTrial( + 'WebRTC-Aec3EnforceCaptureDelayEstimationLeftRightPrioritization', + 42221238, + INDEFINITE), + FieldTrial('WebRTC-Aec3EnforceConservativeHfSuppression', + 42222109, + date(2024, 4, 1)), + FieldTrial('WebRTC-Aec3EnforceLowActiveRenderLimit', + 42221578, + INDEFINITE), + FieldTrial('WebRTC-Aec3EnforceMoreTransparentNearendSuppressorHfTuning', + 42221589, + INDEFINITE), + FieldTrial('WebRTC-Aec3EnforceMoreTransparentNearendSuppressorTuning', + 42221578, + INDEFINITE), + FieldTrial('WebRTC-Aec3EnforceMoreTransparentNormalSuppressorHfTuning', + 42221589, + INDEFINITE), + FieldTrial('WebRTC-Aec3EnforceMoreTransparentNormalSuppressorTuning', + 42221578, + INDEFINITE), + FieldTrial('WebRTC-Aec3EnforceRapidlyAdjustingNearendSuppressorTunings', + 42221578, + INDEFINITE), + FieldTrial('WebRTC-Aec3EnforceRapidlyAdjustingNormalSuppressorTunings', + 42221578, + INDEFINITE), + FieldTrial('WebRTC-Aec3EnforceRenderDelayEstimationDownmixing', + 42221238, + INDEFINITE), + FieldTrial('WebRTC-Aec3EnforceSlowlyAdjustingNearendSuppressorTunings', + 42221578, + INDEFINITE), + FieldTrial('WebRTC-Aec3EnforceSlowlyAdjustingNormalSuppressorTunings', + 42221578, + INDEFINITE), + FieldTrial('WebRTC-Aec3EnforceStationarityProperties', + 42221578, + INDEFINITE), + FieldTrial('WebRTC-Aec3EnforceStationarityPropertiesAtInit', + 42221578, + INDEFINITE), + FieldTrial('WebRTC-Aec3EnforceVeryLowActiveRenderLimit', + 42221578, + INDEFINITE), + FieldTrial('WebRTC-Aec3HighPassFilterEchoReference', + 42222401, + date(2024, 4, 1)), + FieldTrial('WebRTC-Aec3MinErleDuringOnsetsKillSwitch', + 42220385, + date(2024, 4, 1)), + FieldTrial('WebRTC-Aec3NonlinearModeReverbKillSwitch', + 42222109, + date(2024, 4, 1)), + FieldTrial('WebRTC-Aec3OnsetDetectionKillSwitch', + 42221578, + INDEFINITE), + FieldTrial( + 'WebRTC-Aec3RenderDelayEstimationLeftRightPrioritizationKillSwitch', + 42221238, + date(2024, 4, 1)), + FieldTrial('WebRTC-Aec3SensitiveDominantNearendActivation', + 42221578, + INDEFINITE), + FieldTrial('WebRTC-Aec3SetupSpecificDefaultConfigDefaultsKillSwitch', + 42221236, + INDEFINITE), + FieldTrial('WebRTC-Aec3ShortHeadroomKillSwitch', + 42220385, + date(2024, 4, 1)), + FieldTrial('WebRTC-Aec3StereoContentDetectionKillSwitch', + 42225201, + INDEFINITE), + FieldTrial('WebRTC-Aec3SuppressorAntiHowlingGainOverride', + 42221589, + INDEFINITE), + FieldTrial('WebRTC-Aec3SuppressorDominantNearendEnrExitThresholdOverride', + 42221589, + INDEFINITE), + FieldTrial('WebRTC-Aec3SuppressorDominantNearendEnrThresholdOverride', + 42221589, + INDEFINITE), + FieldTrial('WebRTC-Aec3SuppressorDominantNearendHoldDurationOverride', + 42221589, + INDEFINITE), + FieldTrial('WebRTC-Aec3SuppressorDominantNearendSnrThresholdOverride', + 42221589, + INDEFINITE), + FieldTrial('WebRTC-Aec3SuppressorDominantNearendTriggerThresholdOverride', + 42221589, + INDEFINITE), + FieldTrial('WebRTC-Aec3SuppressorNearendHfMaskSuppressOverride', + 42221589, + INDEFINITE), + FieldTrial('WebRTC-Aec3SuppressorNearendHfMaskTransparentOverride', + 42221589, + INDEFINITE), + FieldTrial('WebRTC-Aec3SuppressorNearendLfMaskSuppressOverride', + 42221589, + INDEFINITE), + FieldTrial('WebRTC-Aec3SuppressorNearendLfMaskTransparentOverride', + 42221589, + date(2024, 4, 1)), + FieldTrial('WebRTC-Aec3SuppressorNearendMaxDecFactorLfOverride', + 42221589, + date(2024, 4, 1)), + FieldTrial('WebRTC-Aec3SuppressorNearendMaxIncFactorOverride', + 42221589, + date(2024, 4, 1)), + FieldTrial('WebRTC-Aec3SuppressorNormalHfMaskSuppressOverride', + 42221589, + date(2024, 4, 1)), + FieldTrial('WebRTC-Aec3SuppressorNormalHfMaskTransparentOverride', + 42221589, + date(2024, 4, 1)), + FieldTrial('WebRTC-Aec3SuppressorNormalLfMaskSuppressOverride', + 42221589, + date(2024, 4, 1)), + FieldTrial('WebRTC-Aec3SuppressorNormalLfMaskTransparentOverride', + 42221589, + date(2024, 4, 1)), + FieldTrial('WebRTC-Aec3SuppressorNormalMaxDecFactorLfOverride', + 42221589, + date(2024, 4, 1)), + FieldTrial('WebRTC-Aec3SuppressorNormalMaxIncFactorOverride', + 42221589, + date(2024, 4, 1)), + FieldTrial('WebRTC-Aec3SuppressorTuningOverride', + 42221589, + date(2024, 4, 1)), + FieldTrial('WebRTC-Aec3TransparentAntiHowlingGain', + 42221578, + date(2024, 4, 1)), + FieldTrial('WebRTC-Aec3TransparentModeHmm', + 42222401, + date(2024, 4, 1)), + FieldTrial('WebRTC-Aec3TransparentModeKillSwitch', + 42234438, + date(2024, 4, 1)), + FieldTrial('WebRTC-Aec3Use1Dot2SecondsInitialStateDuration', + 42221578, + date(2024, 4, 1)), + FieldTrial('WebRTC-Aec3Use1Dot6SecondsInitialStateDuration', + 42221578, + date(2024, 4, 1)), + FieldTrial('WebRTC-Aec3Use2Dot0SecondsInitialStateDuration', + 42221578, + date(2024, 4, 1)), + FieldTrial('WebRTC-Aec3UseDot1SecondsInitialStateDuration', + 42221578, + date(2024, 4, 1)), + FieldTrial('WebRTC-Aec3UseDot2SecondsInitialStateDuration', + 42221578, + date(2024, 4, 1)), + FieldTrial('WebRTC-Aec3UseDot3SecondsInitialStateDuration', + 42221578, + date(2024, 4, 1)), + FieldTrial('WebRTC-Aec3UseDot6SecondsInitialStateDuration', + 42221578, + date(2024, 4, 1)), + FieldTrial('WebRTC-Aec3UseDot9SecondsInitialStateDuration', + 42221578, + date(2024, 4, 1)), + FieldTrial('WebRTC-Aec3UseErleOnsetCompensationInDominantNearend', + 42222842, + date(2024, 4, 1)), + FieldTrial('WebRTC-Aec3UseLowEarlyReflectionsDefaultGain', + 42221578, + date(2024, 4, 1)), + FieldTrial('WebRTC-Aec3UseLowLateReflectionsDefaultGain', + 42221578, + date(2024, 4, 1)), + FieldTrial('WebRTC-Aec3UseNearendReverbLen', + 42223329, + INDEFINITE), + FieldTrial('WebRTC-Aec3UseShortConfigChangeDuration', + 42221578, + date(2024, 4, 1)), + FieldTrial('WebRTC-Aec3UseZeroInitialStateDuration', + 42221578, + date(2024, 4, 1)), + FieldTrial('WebRTC-Aec3VerySensitiveDominantNearendActivation', + 42221578, + date(2024, 4, 1)), + FieldTrial('WebRTC-Agc2SimdAvx2KillSwitch', + 42232605, + date(2024, 4, 1)), + FieldTrial('WebRTC-Agc2SimdNeonKillSwitch', + 42232605, + date(2024, 4, 1)), + FieldTrial('WebRTC-Agc2SimdSse2KillSwitch', + 42232605, + date(2024, 4, 1)), + FieldTrial('WebRTC-AllowMACBasedIPv6', + 41480878, + date(2024, 4, 1)), + FieldTrial('WebRTC-AlrDetectorParameters', + 42220590, + INDEFINITE), + FieldTrial('WebRTC-AndroidNetworkMonitor-IsAdapterAvailable', + 42223964, + date(2024, 4, 1)), + FieldTrial('WebRTC-ApmExperimentalMultiChannelCaptureKillSwitch', + 42225202, + INDEFINITE), + FieldTrial('WebRTC-ApmExperimentalMultiChannelRenderKillSwitch', + 42225203, + INDEFINITE), + FieldTrial('WebRTC-Audio-2ndAgcMinMicLevelExperiment', + 40207112, + date(2024, 4, 1)), + FieldTrial('WebRTC-Audio-ABWENoTWCC', + 42233370, + INDEFINITE), + FieldTrial('WebRTC-Audio-AdaptivePtime', + 40694579, + date(2024, 4, 1)), + FieldTrial('WebRTC-Audio-Allocation', + 42220324, + INDEFINITE), + FieldTrial('WebRTC-Audio-AlrProbing', + 42220234, + date(2024, 4, 1)), + FieldTrial('WebRTC-Audio-FecAdaptation', + 42233254, + date(2024, 4, 1)), + FieldTrial('WebRTC-Audio-LegacyOverhead', + 42221084, + INDEFINITE), + FieldTrial('WebRTC-Audio-MinimizeResamplingOnMobile', + 42231221, + date(2024, 4, 1)), + FieldTrial('WebRTC-Audio-NetEqDecisionLogicConfig', + 42223518, + date(2024, 4, 1)), + FieldTrial('WebRTC-Audio-NetEqDelayManagerConfig', + 42220376, + date(2024, 4, 1)), + FieldTrial('WebRTC-Audio-NetEqNackTrackerConfig', + 42220211, + date(2024, 4, 1)), + FieldTrial('WebRTC-Audio-NetEqSmartFlushing', + 42222334, + date(2024, 4, 1)), + FieldTrial('WebRTC-Audio-OpusBitrateMultipliers', + 42221139, + date(2024, 4, 1)), + FieldTrial('WebRTC-Audio-Red-For-Opus', + 42221750, + date(2024, 4, 1)), + FieldTrial('WebRTC-Audio-StableTargetAdaptation', + 42221061, + INDEFINITE), + FieldTrial('WebRTC-Audio-iOS-Holding', + 42233253, + date(2024, 4, 1)), + FieldTrial('WebRTC-AudioDevicePlayoutBufferSizeFactor', + 42221006, + date(2024, 4, 1)), + FieldTrial('WebRTC-BindUsingInterfaceName', + 42220770, + date(2024, 4, 1)), + FieldTrial('WebRTC-Bwe-AllocationProbing', + 42220440, + date(2024, 4, 1)), + FieldTrial('WebRTC-Bwe-AlrProbing', + 42220440, + date(2024, 4, 1)), + FieldTrial('WebRTC-Bwe-EstimateBoundedIncrease', + 42220543, + date(2024, 4, 1)), + FieldTrial('WebRTC-Bwe-ExponentialProbing', + 42220440, + date(2024, 4, 1)), + FieldTrial('WebRTC-Bwe-IgnoreProbesLowerThanNetworkStateEstimate', + 42220543, + date(2024, 4, 1)), + FieldTrial('WebRTC-Bwe-InitialProbing', + 42220440, + date(2024, 4, 1)), + FieldTrial('WebRTC-Bwe-InjectedCongestionController', + 'webrtc:8415', + INDEFINITE), + FieldTrial('WebRTC-Bwe-LimitProbesLowerThanThroughputEstimate', + 42221601, + date(2024, 4, 1)), + FieldTrial('WebRTC-Bwe-LossBasedBweV2', + 42222865, + date(2024, 4, 1)), + FieldTrial('WebRTC-Bwe-LossBasedControl', + NO_BUG, + date(2024, 4, 1)), + FieldTrial('WebRTC-Bwe-MaxRttLimit', + 42234928, + INDEFINITE), + FieldTrial('WebRTC-Bwe-MinAllocAsLowerBound', + NO_BUG, + date(2024, 4, 1)), + FieldTrial('WebRTC-Bwe-NetworkRouteConstraints', + 42221535, + date(2024, 4, 1)), + FieldTrial('WebRTC-Bwe-NoFeedbackReset', + 42234928, + date(2024, 4, 1)), + FieldTrial('WebRTC-Bwe-PaceAtMaxOfBweAndLowerLinkCapacity', + NO_BUG, + date(2024, 4, 1)), + FieldTrial('WebRTC-Bwe-ProbingBehavior', + 42220440, + date(2024, 4, 1)), + FieldTrial('WebRTC-Bwe-ProbingConfiguration', + 42220440, + date(2024, 4, 1)), + FieldTrial('WebRTC-Bwe-ReceiveTimeFix', + 42234228, + date(2024, 4, 1)), + FieldTrial('WebRTC-Bwe-ReceiverLimitCapsOnly', + 42222445, + date(2024, 4, 1)), + FieldTrial('WebRTC-Bwe-RobustThroughputEstimatorSettings', + 42220312, + date(2024, 4, 1)), + FieldTrial('WebRTC-Bwe-SafeResetOnRouteChange', + 42234928, + INDEFINITE), + FieldTrial('WebRTC-Bwe-SeparateAudioPackets', + 42221011, + date(2024, 4, 1)), + FieldTrial('WebRTC-Bwe-TrendlineEstimatorSettings', + 42221011, + date(2024, 4, 1)), + FieldTrial('WebRTC-BweBackOffFactor', + 42233342, + INDEFINITE), + FieldTrial('WebRTC-BweLossExperiment', + 42230863, + date(2024, 4, 1)), + FieldTrial('WebRTC-BweRapidRecoveryExperiment', + 42233136, + date(2024, 4, 1)), + FieldTrial('WebRTC-BweThroughputWindowConfig', + 42220312, + date(2024, 4, 1)), + FieldTrial('WebRTC-BweWindowSizeInPackets', + 42233342, + INDEFINITE), + FieldTrial('WebRTC-CongestionWindow', + 42225197, + INDEFINITE), + FieldTrial('WebRTC-CpuLoadEstimator', + 42233645, + date(2024, 4, 1)), + FieldTrial('WebRTC-Debugging-RtpDump', + 42220735, + INDEFINITE), + FieldTrial('WebRTC-DecoderDataDumpDirectory', + 42224491, + INDEFINITE), + FieldTrial('WebRTC-DefaultBitrateLimitsKillSwitch', + NO_BUG, + date(2024, 4, 1)), + FieldTrial('WebRTC-DependencyDescriptorAdvertised', + 42220386, + date(2024, 4, 1)), + FieldTrial('WebRTC-DisableUlpFecExperiment', + NO_BUG, + date(2024, 4, 1)), + FieldTrial('WebRTC-DontIncreaseDelayBasedBweInAlr', + 42220590, + date(2024, 4, 1)), + FieldTrial('WebRTC-DscpFieldTrial', + 42223835, + date(2024, 4, 1)), + FieldTrial('WebRTC-ExtraICEPing', + 42220311, + date(2024, 4, 1)), + FieldTrial('WebRTC-FakeNetworkReceiveConfig', + 42224493, + INDEFINITE), + FieldTrial('WebRTC-FakeNetworkSendConfig', + 42224493, + INDEFINITE), + FieldTrial('WebRTC-FilterAbsSendTimeExtension', + 42220271, + INDEFINITE), + FieldTrial('WebRTC-FindNetworkHandleWithoutIpv6TemporaryPart', + 42221149, + date(2024, 4, 1)), + FieldTrial('WebRTC-FlexFEC-03', + 42230680, + date(2024, 4, 1)), + FieldTrial('WebRTC-FlexFEC-03-Advertised', + 42230680, + date(2024, 4, 1)), + FieldTrial('WebRTC-ForcePlayoutDelay', + 42222016, + INDEFINITE), + FieldTrial('WebRTC-ForceSendPlayoutDelay', + 42222016, + INDEFINITE), + FieldTrial('WebRTC-ForceSimulatedOveruseIntervalMs', + 42224494, + INDEFINITE), + FieldTrial('WebRTC-FrameDropper', + 42234921, + INDEFINITE), + FieldTrial('WebRTC-FullBandHpfKillSwitch', + 42221279, + date(2024, 4, 1)), + FieldTrial('WebRTC-GenericCodecDependencyDescriptor', + 42225273, + INDEFINITE), + FieldTrial('WebRTC-GenericDescriptorAdvertised', + 42234553, + INDEFINITE), + FieldTrial('WebRTC-GenericDescriptorAuth', + 42220132, + INDEFINITE), + FieldTrial('WebRTC-GenericPictureId', + 42234553, + INDEFINITE), + FieldTrial('WebRTC-GetEncoderInfoOverride', + NO_BUG, + date(2024, 4, 1)), + FieldTrial('WebRTC-H264HighProfile', + 41481030, + date(2024, 4, 1)), + FieldTrial('WebRTC-IPv6Default', + NO_BUG, # chromium:413437 + date(2024, 4, 1)), + FieldTrial('WebRTC-IceControllerFieldTrials', + 40658968, + INDEFINITE), + FieldTrial('WebRTC-IceFieldTrials', + 42221103, + INDEFINITE), + FieldTrial('WebRTC-KeyframeInterval', + 42220470, + INDEFINITE), + FieldTrial('WebRTC-LegacyFrameIdJumpBehavior', + 42223541, + date(2024, 4, 1)), + FieldTrial('WebRTC-LegacySimulcastLayerLimit', + 42233936, + INDEFINITE), + FieldTrial('WebRTC-LegacyTlsProtocols', + 40644300, + date(2024, 4, 1)), + FieldTrial('WebRTC-LowresSimulcastBitrateInterpolation', + 42222558, + date(2024, 4, 1)), + FieldTrial('WebRTC-MutedStateKillSwitch', + 177830919, + date(2024, 4, 1)), + FieldTrial('WebRTC-Network-UseNWPathMonitor', + 42221045, + date(2024, 4, 1)), + FieldTrial('WebRTC-NetworkMonitorAutoDetect', + 42223964, + date(2024, 4, 1)), + FieldTrial('WebRTC-NormalizeSimulcastResolution', + NO_BUG, + INDEFINITE), + FieldTrial('WebRTC-Pacer-BlockAudio', + 42233548, + INDEFINITE), + FieldTrial('WebRTC-Pacer-DrainQueue', + 42233548, + date(2024, 4, 1)), + FieldTrial('WebRTC-Pacer-IgnoreTransportOverhead', + 42235102, + INDEFINITE), + FieldTrial('WebRTC-Pacer-PadInSilence', + 42233548, + date(2024, 4, 1)), + FieldTrial('WebRTC-PacketBufferMaxSize', + 42235070, + INDEFINITE), + FieldTrial('WebRTC-PcFactoryDefaultBitrates', + 42220941, + date(2024, 4, 1)), + FieldTrial('WebRTC-PiggybackIceCheckAcknowledgement', + NO_BUG, + date(2024, 4, 1)), + FieldTrial('WebRTC-PixelLimitResource', + 42222397, + INDEFINITE), + FieldTrial('WebRTC-ProbingScreenshareBwe', + 42232804, + date(2024, 4, 1)), + FieldTrial('WebRTC-ProtectionOverheadRateThreshold', + 42225198, + INDEFINITE), + FieldTrial('WebRTC-QpParsingKillSwitch', + 42222690, + date(2024, 4, 1)), + FieldTrial('WebRTC-RtcEventLogKillSwitch', + 42222210, + INDEFINITE), + FieldTrial('WebRTC-RtcEventLogNewFormat', + 42233237, + date(2024, 4, 1)), + FieldTrial('WebRTC-RtcpLossNotification', + 42220379, + date(2024, 4, 1)), + FieldTrial('WebRTC-SendBufferSizeBytes', + 42222026, + date(2024, 4, 1)), + FieldTrial('WebRTC-SendNackDelayMs', + 42235176, + date(2024, 4, 1)), + FieldTrial('WebRTC-SetSocketReceiveBuffer', + 42223976, + date(2024, 4, 1)), + FieldTrial('WebRTC-SimulcastEncoderAdapter-GetEncoderInfoOverride', + NO_BUG, + date(2024, 4, 1)), + FieldTrial('WebRTC-SimulcastLayerLimitRoundUp', + NO_BUG, + date(2024, 4, 1)), + FieldTrial('WebRTC-SpsPpsIdrIsH264Keyframe', + 42233557, + INDEFINITE), + FieldTrial('WebRTC-StableTargetRate', + 42220156, + date(2024, 4, 1)), + FieldTrial('WebRTC-StrictPacingAndProbing', + 42233198, + date(2024, 4, 1)), + FieldTrial('WebRTC-StunInterPacketDelay', + NO_BUG, + date(2024, 4, 1)), + FieldTrial('WebRTC-SurfaceCellularTypes', + 42221576, + date(2024, 4, 1)), + FieldTrial('WebRTC-SwitchEncoderOnInitializationFailures', + 42223783, + date(2024, 4, 1)), + FieldTrial('WebRTC-Target-Bitrate-Rtcp', + 42235192, + INDEFINITE), + FieldTrial('WebRTC-TransientSuppressorForcedOff', + 40172597, + INDEFINITE), + FieldTrial('WebRTC-UseBaseHeavyVP8TL3RateAllocation', + 42234670, + date(2024, 4, 1)), + FieldTrial('WebRTC-UseDifferentiatedCellularCosts', + 42221576, + date(2024, 4, 1)), + FieldTrial('WebRTC-UseStandardBytesStats', + 42220573, + date(2024, 4, 1)), + FieldTrial('WebRTC-UseTurnServerAsStunServer', + 42221142, + date(2024, 4, 1)), + FieldTrial('WebRTC-VP8-ForcePartitionResilience', + 42221952, + INDEFINITE), + FieldTrial('WebRTC-VP8-Forced-Fallback-Encoder-v2', + 42231704, + INDEFINITE), + FieldTrial('WebRTC-VP8-GetEncoderInfoOverride', + 42221952, + INDEFINITE), + FieldTrial('WebRTC-VP8-Postproc-Config', + 42221657, + date(2024, 4, 1)), + FieldTrial('WebRTC-VP8-Postproc-Config-Arm', + 42231704, + INDEFINITE), + FieldTrial('WebRTC-VP8IosMaxNumberOfThread', + 42220027, + date(2024, 4, 1)), + FieldTrial('WebRTC-VP9-GetEncoderInfoOverride', + NO_BUG, + date(2024, 4, 1)), + FieldTrial('WebRTC-VP9-LowTierOptimizations', + 42224122, + date(2024, 4, 1)), + FieldTrial('WebRTC-VP9-PerformanceFlags', + 42221657, + date(2024, 4, 1)), + FieldTrial('WebRTC-VP9QualityScaler', + 42221411, + date(2024, 4, 1)), + FieldTrial('WebRTC-Video-BalancedDegradation', + 42232717, + INDEFINITE), + FieldTrial('WebRTC-Video-BalancedDegradationSettings', + NO_BUG, + INDEFINITE), + FieldTrial('WebRTC-Video-DisableAutomaticResize', + 42221931, + date(2024, 4, 1)), + FieldTrial('WebRTC-Video-DiscardPacketsWithUnknownSsrc', + 42235091, + INDEFINITE), + FieldTrial('WebRTC-Video-ForcedSwDecoderFallback', + NO_BUG, + INDEFINITE), + FieldTrial('WebRTC-Video-InitialDecoderResolution', + 42222018, + date(2024, 4, 1)), + FieldTrial('WebRTC-Video-MinVideoBitrate', + 42220993, + date(2024, 4, 1)), + FieldTrial('WebRTC-Video-Pacing', + 42220062, + date(2024, 4, 1)), + FieldTrial('WebRTC-Video-PreferTemporalSupportOnBaseLayer', + 42221417, + INDEFINITE), + FieldTrial('WebRTC-Video-QualityScalerSettings', + NO_BUG, + INDEFINITE), + FieldTrial('WebRTC-Video-QualityScaling', + 42234348, + INDEFINITE), + FieldTrial('WebRTC-Video-UseFrameRateForOverhead', + 166341943, + date(2024, 4, 1)), + FieldTrial('WebRTC-VideoFrameTrackingIdAdvertised', + 42222747, + INDEFINITE), + FieldTrial('WebRTC-VideoLayersAllocationAdvertised', + 42222126, + INDEFINITE), + FieldTrial('WebRTC-VideoRateControl', + 42220259, + INDEFINITE), + FieldTrial('WebRTC-Vp9ExternalRefCtrl', + 42234783, + date(2024, 4, 1)), + FieldTrial('WebRTC-Vp9InterLayerPred', + NO_BUG, # chromium:949536 + INDEFINITE), + FieldTrial('WebRTC-Vp9IssueKeyFrameOnLayerDeactivation', + 40595338, + date(2024, 4, 1)), + FieldTrial('WebRTC-ZeroPlayoutDelay', + 40228487, + date(2024, 4, 1)), + # keep-sorted end +]) # yapf: disable + +POLICY_EXEMPT_FIELD_TRIALS_DIGEST: str = \ + 'e750429cb042c02921a227fa18291f2cea23ea3b' + +REGISTERED_FIELD_TRIALS: FrozenSet[FieldTrial] = ACTIVE_FIELD_TRIALS.union( + POLICY_EXEMPT_FIELD_TRIALS) + + +def todays_date() -> date: + now = datetime.datetime.now(datetime.timezone.utc) + return date(now.year, now.month, now.day) + + +def registry_header( + field_trials: FrozenSet[FieldTrial] = REGISTERED_FIELD_TRIALS) -> str: + """Generates a C++ header with all field trial keys. + + Args: + field_trials: Field trials to include in the header. + + Returns: + String representation of a C++ header file containing all field trial + keys. + + >>> trials = { + ... FieldTrial('B', '', date(1, 1, 1)), + ... FieldTrial('A', '', date(1, 1, 1)), + ... FieldTrial('B', '', date(2, 2, 2)), + ... } + >>> print(registry_header(trials)) + // This file was automatically generated. Do not edit. + + #ifndef GEN_REGISTERED_FIELD_TRIALS_H_ + #define GEN_REGISTERED_FIELD_TRIALS_H_ + + #include "absl/strings/string_view.h" + + namespace webrtc { + + inline constexpr absl::string_view kRegisteredFieldTrials[] = { + "A", + "B", + }; + + } // namespace webrtc + + #endif // GEN_REGISTERED_FIELD_TRIALS_H_ + + """ + registered_keys = {f.key for f in field_trials} + keys = '\n'.join(f' "{k}",' for k in sorted(registered_keys)) + return ('// This file was automatically generated. Do not edit.\n' + '\n' + '#ifndef GEN_REGISTERED_FIELD_TRIALS_H_\n' + '#define GEN_REGISTERED_FIELD_TRIALS_H_\n' + '\n' + '#include "absl/strings/string_view.h"\n' + '\n' + 'namespace webrtc {\n' + '\n' + 'inline constexpr absl::string_view kRegisteredFieldTrials[] = {\n' + f'{keys}\n' + '};\n' + '\n' + '} // namespace webrtc\n' + '\n' + '#endif // GEN_REGISTERED_FIELD_TRIALS_H_\n') + + +def expired_field_trials( + threshold: date, + field_trials: FrozenSet[FieldTrial] = REGISTERED_FIELD_TRIALS +) -> Set[FieldTrial]: + """Obtains expired field trials. + + Args: + threshold: Date from which to check end date. + field_trials: Field trials to validate. + + Returns: + All expired field trials. + + >>> trials = { + ... FieldTrial('Expired', '', date(1, 1, 1)), + ... FieldTrial('Not-Expired', '', date(1, 1, 2)), + ... } + >>> expired_field_trials(date(1, 1, 1), trials) + {FieldTrial(key='Expired', bug='', end_date=datetime.date(1, 1, 1))} + """ + return {f for f in field_trials if f.end_date <= threshold} + + +def validate_field_trials( + field_trials: FrozenSet[FieldTrial] = ACTIVE_FIELD_TRIALS +) -> List[str]: + """Validate that field trials conforms to the policy. + + Args: + field_trials: Field trials to validate. + + Returns: + A list of explanations for invalid field trials. + """ + invalid = [] + + sha1 = hashlib.sha1() + for trial in sorted(POLICY_EXEMPT_FIELD_TRIALS, key=lambda f: f.key): + sha1.update(trial.key.encode('ascii')) + if sha1.hexdigest() != POLICY_EXEMPT_FIELD_TRIALS_DIGEST: + invalid.append( + 'POLICY_EXEMPT_FIELD_TRIALS has been modified. Please note that ' + 'you must not add any new entries there. If you removed an entry ' + 'you should also update POLICY_EXEMPT_FIELD_TRIALS_DIGEST. The ' + f'new digest is "{sha1.hexdigest()}".') + + for trial in field_trials: + if not trial.key.startswith('WebRTC-'): + invalid.append(f'{trial.key} does not start with "WebRTC-".') + if trial.bug_id <= 0: + invalid.append(f'{trial.key} must have an associated bug.') + if trial.end_date >= INDEFINITE: + invalid.append(f'{trial.key} must have an end date.') + + return invalid + + +def cmd_header(args: argparse.Namespace) -> None: + if not args.no_validation: + if errors := validate_field_trials(): + print('\n'.join(sorted(errors))) + sys.exit(1) + + args.output.write(registry_header()) + + +def cmd_expired(args: argparse.Namespace) -> None: + today = todays_date() + diff = datetime.timedelta(days=args.in_days) + expired = expired_field_trials( + today + diff, + ACTIVE_FIELD_TRIALS if args.no_exempt else REGISTERED_FIELD_TRIALS) + + if len(expired) <= 0: + return + + expired_by_date = sorted(expired, key=lambda f: (f.end_date, f.key)) + print('\n'.join( + f'{f.key} ' + f'{f"<{f.bug_url()}> " if f.bug_url() else ""}' + f'{"expired" if f.end_date <= today else "expires"} on {f.end_date}' + for f in expired_by_date)) + if any(f.end_date <= today for f in expired_by_date): + sys.exit(1) + + +def cmd_validate(args: argparse.Namespace) -> None: + del args + invalid = validate_field_trials() + + if len(invalid) <= 0: + return + + print('\n'.join(sorted(invalid))) + sys.exit(1) + + +def main() -> None: + parser = argparse.ArgumentParser() + subcommand = parser.add_subparsers(dest='cmd') + + parser_header = subcommand.add_parser( + 'header', + help='generate C++ header file containing registered field trial keys') + parser_header.add_argument('--output', + default=sys.stdout, + type=argparse.FileType('w'), + required=False, + help='output file') + parser_header.add_argument( + '--no-validation', + default=False, + action='store_true', + required=False, + help='whether to validate the field trials before writing') + parser_header.set_defaults(cmd=cmd_header) + + parser_expired = subcommand.add_parser( + 'expired', + help='lists all expired field trials', + description=''' + Lists all expired field trials. Exits with a non-zero exit status if + any field trials has expired, ignoring the --in-days argument. + ''') + parser_expired.add_argument( + '--no-exempt', + default=False, + action='store_true', + required=False, + help='whether to include policy exempt field trials') + parser_expired.add_argument( + '--in-days', + default=0, + type=int, + required=False, + help='number of days relative to today to check') + parser_expired.set_defaults(cmd=cmd_expired) + + parser_validate = subcommand.add_parser( + 'validate', + help='validates that all field trials conforms to the policy.', + description=''' + Validates that all field trials conforms to the policy. Exits with a + non-zero exit status if any field trials does not. + ''') + parser_validate.set_defaults(cmd=cmd_validate) + + args = parser.parse_args() + + if not args.cmd: + parser.print_help(sys.stderr) + sys.exit(1) + + args.cmd(args) + + +if __name__ == '__main__': + main() diff --git a/webrtc/experiments/registered_field_trials.h b/webrtc/experiments/registered_field_trials.h index 811cd56..955ba31 100644 --- a/webrtc/experiments/registered_field_trials.h +++ b/webrtc/experiments/registered_field_trials.h @@ -8,13 +8,14 @@ namespace webrtc { inline constexpr absl::string_view kRegisteredFieldTrials[] = { - "UseTwccPlrForAna", + "WebRTC-AV1-OverridePriorityBitrate", "WebRTC-AddNetworkCostToVpn", "WebRTC-AddPacingToCongestionWindowPushback", "WebRTC-AdjustOpusBandwidth", "WebRTC-Aec3AecStateFullResetKillSwitch", "WebRTC-Aec3AecStateSubtractorAnalyzerResetKillSwitch", "WebRTC-Aec3AntiHowlingMinimizationKillSwitch", + "WebRTC-Aec3BufferingMaxAllowedExcessRenderBlocksOverride", "WebRTC-Aec3ClampInstQualityToOneKillSwitch", "WebRTC-Aec3ClampInstQualityToZeroKillSwitch", "WebRTC-Aec3CoarseFilterResetHangoverKillSwitch", @@ -22,7 +23,6 @@ inline constexpr absl::string_view kRegisteredFieldTrials[] = { "WebRTC-Aec3DeactivateInitialStateResetKillSwitch", "WebRTC-Aec3DelayEstimateSmoothingDelayFoundOverride", "WebRTC-Aec3DelayEstimateSmoothingOverride", - "WebRTC-Aec3DelayEstimatorDetectPreEcho", "WebRTC-Aec3EchoSaturationDetectionKillSwitch", "WebRTC-Aec3EnforceCaptureDelayEstimationDownmixing", "WebRTC-Aec3EnforceCaptureDelayEstimationLeftRightPrioritization", @@ -44,8 +44,6 @@ inline constexpr absl::string_view kRegisteredFieldTrials[] = { "WebRTC-Aec3MinErleDuringOnsetsKillSwitch", "WebRTC-Aec3NonlinearModeReverbKillSwitch", "WebRTC-Aec3OnsetDetectionKillSwitch", - "WebRTC-Aec3PenalyzeHighDelaysInitialPhase", - "WebRTC-Aec3PreEchoConfiguration", "WebRTC-Aec3RenderDelayEstimationLeftRightPrioritizationKillSwitch", "WebRTC-Aec3SensitiveDominantNearendActivation", "WebRTC-Aec3SetupSpecificDefaultConfigDefaultsKillSwitch", @@ -109,20 +107,16 @@ inline constexpr absl::string_view kRegisteredFieldTrials[] = { "WebRTC-Audio-NetEqDelayManagerConfig", "WebRTC-Audio-NetEqNackTrackerConfig", "WebRTC-Audio-NetEqSmartFlushing", - "WebRTC-Audio-OpusAvoidNoisePumpingDuringDtx", "WebRTC-Audio-OpusBitrateMultipliers", - "WebRTC-Audio-OpusPlcUsePrevDecodedSamples", - "WebRTC-Audio-OpusSetSignalVoiceWithDtx", + "WebRTC-Audio-OpusGeneratePlc", + "WebRTC-Audio-PriorityBitrate", "WebRTC-Audio-Red-For-Opus", "WebRTC-Audio-StableTargetAdaptation", "WebRTC-Audio-iOS-Holding", "WebRTC-AudioDevicePlayoutBufferSizeFactor", - "WebRTC-AutomaticAnimationDetectionScreenshare", "WebRTC-Av1-GetEncoderInfoOverride", - "WebRTC-Avx2SupportKillSwitch", "WebRTC-BindUsingInterfaceName", - "WebRTC-BoostedScreenshareQp", - "WebRTC-BurstyPacer", + "WebRTC-BitrateAdjusterUseNewfangledHeadroomAdjustment", "WebRTC-Bwe-AllocationProbing", "WebRTC-Bwe-AlrProbing", "WebRTC-Bwe-EstimateBoundedIncrease", @@ -130,8 +124,8 @@ inline constexpr absl::string_view kRegisteredFieldTrials[] = { "WebRTC-Bwe-IgnoreProbesLowerThanNetworkStateEstimate", "WebRTC-Bwe-InitialProbing", "WebRTC-Bwe-InjectedCongestionController", + "WebRTC-Bwe-LimitPacingFactorByUpperLinkCapacityEstimate", "WebRTC-Bwe-LimitProbesLowerThanThroughputEstimate", - "WebRTC-Bwe-LinkCapacity", "WebRTC-Bwe-LossBasedBweV2", "WebRTC-Bwe-LossBasedControl", "WebRTC-Bwe-MaxRttLimit", @@ -143,10 +137,10 @@ inline constexpr absl::string_view kRegisteredFieldTrials[] = { "WebRTC-Bwe-ProbingConfiguration", "WebRTC-Bwe-ReceiveTimeFix", "WebRTC-Bwe-ReceiverLimitCapsOnly", + "WebRTC-Bwe-ResetOnAdapterIdChange", "WebRTC-Bwe-RobustThroughputEstimatorSettings", "WebRTC-Bwe-SafeResetOnRouteChange", "WebRTC-Bwe-SeparateAudioPackets", - "WebRTC-Bwe-SubtractAdditionalBackoffTerm", "WebRTC-Bwe-TrendlineEstimatorSettings", "WebRTC-BweBackOffFactor", "WebRTC-BweLossExperiment", @@ -155,16 +149,19 @@ inline constexpr absl::string_view kRegisteredFieldTrials[] = { "WebRTC-BweWindowSizeInPackets", "WebRTC-CongestionWindow", "WebRTC-CpuLoadEstimator", + "WebRTC-DataChannelMessageInterleaving", "WebRTC-Debugging-RtpDump", "WebRTC-DecoderDataDumpDirectory", "WebRTC-DefaultBitrateLimitsKillSwitch", "WebRTC-DependencyDescriptorAdvertised", - "WebRTC-DisablePacerEmergencyStop", "WebRTC-DisableRtxRateLimiter", + "WebRTC-DisableTlsSessionTicketKillswitch", "WebRTC-DisableUlpFecExperiment", "WebRTC-DontIncreaseDelayBasedBweInAlr", "WebRTC-DscpFieldTrial", + "WebRTC-ElasticBitrateAllocation", "WebRTC-EncoderDataDumpDirectory", + "WebRTC-EncryptedRtpHeaderExtensions", "WebRTC-ExtraICEPing", "WebRTC-FakeNetworkReceiveConfig", "WebRTC-FakeNetworkSendConfig", @@ -175,6 +172,7 @@ inline constexpr absl::string_view kRegisteredFieldTrials[] = { "WebRTC-ForcePlayoutDelay", "WebRTC-ForceSendPlayoutDelay", "WebRTC-ForceSimulatedOveruseIntervalMs", + "WebRTC-FrameCadenceAdapter-UseVideoFrameTimestamp", "WebRTC-FrameDropper", "WebRTC-FullBandHpfKillSwitch", "WebRTC-GenericCodecDependencyDescriptor", @@ -194,8 +192,10 @@ inline constexpr absl::string_view kRegisteredFieldTrials[] = { "WebRTC-LegacyFrameIdJumpBehavior", "WebRTC-LegacySimulcastLayerLimit", "WebRTC-LegacyTlsProtocols", - "WebRTC-LibaomAv1Encoder-DisableFrameDropping", + "WebRTC-LibaomAv1Encoder-AdaptiveMaxConsecDrops", + "WebRTC-LibvpxVp8Encoder-AndroidSpecificThreadingSettings", "WebRTC-LowresSimulcastBitrateInterpolation", + "WebRTC-MixedCodecSimulcast", "WebRTC-MutedStateKillSwitch", "WebRTC-Network-UseNWPathMonitor", "WebRTC-NetworkMonitorAutoDetect", @@ -207,33 +207,37 @@ inline constexpr absl::string_view kRegisteredFieldTrials[] = { "WebRTC-Pacer-KeyframeFlushing", "WebRTC-Pacer-PadInSilence", "WebRTC-PacketBufferMaxSize", - "WebRTC-PaddingMode-RecentLargePacket", + "WebRTC-PayloadTypesInTransport", "WebRTC-PcFactoryDefaultBitrates", "WebRTC-PermuteTlsClientHello", "WebRTC-PiggybackIceCheckAcknowledgement", "WebRTC-PixelLimitResource", - "WebRTC-PreventSsrcGroupsWithUnexpectedSize", "WebRTC-ProbingScreenshareBwe", "WebRTC-ProtectionOverheadRateThreshold", + "WebRTC-QCM-Dynamic-AV1", + "WebRTC-QCM-Dynamic-VP8", + "WebRTC-QCM-Dynamic-VP9", + "WebRTC-QCM-Static-AV1", + "WebRTC-QCM-Static-VP8", + "WebRTC-QCM-Static-VP9", "WebRTC-QpParsingKillSwitch", + "WebRTC-RFC8888CongestionControlFeedback", "WebRTC-ReceiveBufferSize", "WebRTC-RtcEventLogEncodeDependencyDescriptor", "WebRTC-RtcEventLogEncodeNetEqSetMinimumDelayKillSwitch", "WebRTC-RtcEventLogKillSwitch", "WebRTC-RtcEventLogNewFormat", "WebRTC-RtcpLossNotification", - "WebRTC-RttMult", - "WebRTC-SCM-Timestamp", "WebRTC-SendBufferSizeBytes", "WebRTC-SendNackDelayMs", - "WebRTC-SendPacketsOnWorkerThread", + "WebRTC-SetCodecPreferences-ReceiveOnlyFilterInsteadOfThrow", + "WebRTC-SetReadyToSendFalseIfSendFail", "WebRTC-SetSocketReceiveBuffer", - "WebRTC-SignalNetworkPreferenceChange", "WebRTC-SimulcastEncoderAdapter-GetEncoderInfoOverride", "WebRTC-SimulcastLayerLimitRoundUp", "WebRTC-SpsPpsIdrIsH264Keyframe", + "WebRTC-SrtpRemoveReceiveStream", "WebRTC-StableTargetRate", - "WebRTC-Stats-RtxReceiveStats", "WebRTC-StrictPacingAndProbing", "WebRTC-StunInterPacketDelay", "WebRTC-SurfaceCellularTypes", @@ -243,52 +247,47 @@ inline constexpr absl::string_view kRegisteredFieldTrials[] = { "WebRTC-TransientSuppressorForcedOff", "WebRTC-UseBaseHeavyVP8TL3RateAllocation", "WebRTC-UseDifferentiatedCellularCosts", - "WebRTC-UseShortVP8TL2Pattern", - "WebRTC-UseShortVP8TL3Pattern", + "WebRTC-UseNtpTimeAbsoluteSendTime", "WebRTC-UseStandardBytesStats", "WebRTC-UseTurnServerAsStunServer", - "WebRTC-VP8-CpuSpeed-Arm", "WebRTC-VP8-ForcePartitionResilience", "WebRTC-VP8-Forced-Fallback-Encoder-v2", "WebRTC-VP8-GetEncoderInfoOverride", "WebRTC-VP8-MaxFrameInterval", "WebRTC-VP8-Postproc-Config", "WebRTC-VP8-Postproc-Config-Arm", - "WebRTC-VP8ConferenceTemporalLayers", "WebRTC-VP8IosMaxNumberOfThread", - "WebRTC-VP8VariableFramerateScreenshare", "WebRTC-VP9-GetEncoderInfoOverride", "WebRTC-VP9-LowTierOptimizations", "WebRTC-VP9-PerformanceFlags", + "WebRTC-VP9-SvcForSimulcast", "WebRTC-VP9QualityScaler", - "WebRTC-VP9VariableFramerateScreenshare", + "WebRTC-Video-AV1EvenPayloadSizes", "WebRTC-Video-BalancedDegradation", "WebRTC-Video-BalancedDegradationSettings", - "WebRTC-Video-BandwidthQualityScalerSettings", "WebRTC-Video-DisableAutomaticResize", "WebRTC-Video-DiscardPacketsWithUnknownSsrc", "WebRTC-Video-EnableRetransmitAllLayers", "WebRTC-Video-EncoderFallbackSettings", "WebRTC-Video-ForcedSwDecoderFallback", + "WebRTC-Video-H26xPacketBuffer", "WebRTC-Video-InitialDecoderResolution", "WebRTC-Video-MinVideoBitrate", "WebRTC-Video-Pacing", "WebRTC-Video-PreferTemporalSupportOnBaseLayer", - "WebRTC-Video-QualityRampupSettings", "WebRTC-Video-QualityScalerSettings", "WebRTC-Video-QualityScaling", - "WebRTC-Video-RequestedResolutionOverrideOutputFormatRequest", + "WebRTC-Video-SimulcastIndependentFrameIds", "WebRTC-Video-UseFrameRateForOverhead", - "WebRTC-Video-VariableStartScaleFactor", + "WebRTC-Video-Vp9FlexibleMode", "WebRTC-VideoEncoderSettings", "WebRTC-VideoFrameTrackingIdAdvertised", "WebRTC-VideoLayersAllocationAdvertised", "WebRTC-VideoRateControl", - "WebRTC-VoIPChannelRemixingAdjustmentKillSwitch", "WebRTC-Vp9ExternalRefCtrl", "WebRTC-Vp9InterLayerPred", "WebRTC-Vp9IssueKeyFrameOnLayerDeactivation", - "WebRTC-ZeroHertzScreenshare", + "WebRTC-ZeroHertzQueueOverload", "WebRTC-ZeroPlayoutDelay", }; diff --git a/webrtc/modules/BUILD.gn b/webrtc/modules/BUILD.gn index 4870cb3..21f866d 100644 --- a/webrtc/modules/BUILD.gn +++ b/webrtc/modules/BUILD.gn @@ -30,7 +30,6 @@ group("modules") { rtc_source_set("module_api_public") { sources = [ "include/module_common_types_public.h" ] - absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] } rtc_source_set("module_api") { @@ -143,7 +142,6 @@ if (rtc_include_tests && !build_with_chromium) { "../resources/audio_processing/transient/wpd5.dat", "../resources/audio_processing/transient/wpd6.dat", "../resources/audio_processing/transient/wpd7.dat", - "../resources/deflicker_before_cif_short.yuv", "../resources/far16_stereo.pcm", "../resources/far176_stereo.pcm", "../resources/far192_stereo.pcm", @@ -154,7 +152,6 @@ if (rtc_include_tests && !build_with_chromium) { "../resources/far88_stereo.pcm", "../resources/far8_stereo.pcm", "../resources/far96_stereo.pcm", - "../resources/foremanColorEnhanced_cif_short.yuv", "../resources/foreman_cif.yuv", "../resources/foreman_cif_short.yuv", "../resources/near16_stereo.pcm", diff --git a/webrtc/modules/audio_coding/BUILD.gn b/webrtc/modules/audio_coding/BUILD.gn index 61fecea..d74a595 100644 --- a/webrtc/modules/audio_coding/BUILD.gn +++ b/webrtc/modules/audio_coding/BUILD.gn @@ -22,8 +22,6 @@ rtc_source_set("audio_coding_module_typedefs") { rtc_library("audio_coding") { visibility += [ "*" ] sources = [ - "acm2/acm_receiver.cc", - "acm2/acm_receiver.h", "acm2/acm_remixing.cc", "acm2/acm_remixing.h", "acm2/acm_resampler.cc", @@ -38,7 +36,6 @@ rtc_library("audio_coding") { deps = [ ":audio_coding_module_typedefs", - ":default_neteq_factory", ":neteq", "..:module_api", "..:module_api_public", @@ -46,7 +43,10 @@ rtc_library("audio_coding") { "../../api:function_view", "../../api/audio:audio_frame_api", "../../api/audio_codecs:audio_codecs_api", + "../../api/environment", + "../../api/neteq:default_neteq_factory", "../../api/neteq:neteq_api", + "../../api/units:timestamp", "../../common_audio", "../../common_audio:common_audio_c", "../../rtc_base:audio_format_to_string", @@ -58,10 +58,8 @@ rtc_library("audio_coding") { "../../rtc_base/synchronization:mutex", "../../system_wrappers", "../../system_wrappers:metrics", - ] - absl_deps = [ "//third_party/abseil-cpp/absl/strings", - "//third_party/abseil-cpp/absl/types:optional", + "//third_party/abseil-cpp/absl/strings:string_view", ] } @@ -76,7 +74,6 @@ rtc_library("legacy_encoded_audio_frame") { "../../rtc_base:buffer", "../../rtc_base:checks", ] - absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] } rtc_library("webrtc_cng") { @@ -109,7 +106,6 @@ rtc_library("audio_encoder_cng") { "../../common_audio", "../../rtc_base:checks", ] - absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] } rtc_library("red") { @@ -129,10 +125,7 @@ rtc_library("red") { "../../rtc_base:byte_order", "../../rtc_base:checks", "../../rtc_base:logging", - ] - absl_deps = [ - "//third_party/abseil-cpp/absl/strings", - "//third_party/abseil-cpp/absl/types:optional", + "//third_party/abseil-cpp/absl/strings:string_view", ] } @@ -154,7 +147,6 @@ rtc_library("g711") { "../../rtc_base:buffer", "../../rtc_base:checks", ] - absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] public_deps += [ ":g711_c" ] # no-presubmit-check TODO(webrtc:8603) } @@ -187,7 +179,6 @@ rtc_library("g722") { "../../rtc_base:checks", "../../rtc_base:safe_conversions", ] - absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] public_deps += [ ":g722_c" ] # no-presubmit-check TODO(webrtc:8603) } @@ -222,7 +213,6 @@ rtc_library("ilbc") { "../../rtc_base:logging", "../../rtc_base:safe_conversions", ] - absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] public_deps += [ ":ilbc_c" ] # no-presubmit-check TODO(webrtc:8603) } @@ -377,8 +367,8 @@ rtc_library("ilbc_c") { "../../rtc_base:checks", "../../rtc_base:sanitizer", "../../rtc_base/system:arch", + "//third_party/abseil-cpp/absl/base:core_headers", ] - absl_deps = [ "//third_party/abseil-cpp/absl/base:core_headers" ] } rtc_library("isac_vad") { @@ -452,10 +442,7 @@ rtc_library("audio_coding_opus_common") { "../../api/audio_codecs:audio_codecs_api", "../../rtc_base:checks", "../../rtc_base:stringutils", - ] - absl_deps = [ - "//third_party/abseil-cpp/absl/strings", - "//third_party/abseil-cpp/absl/types:optional", + "//third_party/abseil-cpp/absl/strings:string_view", ] } @@ -473,8 +460,10 @@ rtc_library("webrtc_opus") { ":audio_coding_opus_common", ":audio_network_adaptor", "../../api:array_view", + "../../api:field_trials_view", "../../api/audio_codecs:audio_codecs_api", "../../api/audio_codecs/opus:audio_encoder_opus_config", + "../../api/environment", "../../common_audio", "../../rtc_base:buffer", "../../rtc_base:checks", @@ -486,11 +475,9 @@ rtc_library("webrtc_opus") { "../../rtc_base:safe_minmax", "../../rtc_base:stringutils", "../../rtc_base:timeutils", - "../../system_wrappers:field_trial", - ] - absl_deps = [ + "//third_party/abseil-cpp/absl/memory", "//third_party/abseil-cpp/absl/strings", - "//third_party/abseil-cpp/absl/types:optional", + "//third_party/abseil-cpp/absl/strings:string_view", ] public_deps += # no-presubmit-check TODO(webrtc:8603) [ ":webrtc_opus_wrapper" ] @@ -510,6 +497,7 @@ rtc_library("webrtc_multiopus") { deps = [ ":audio_coding_opus_common", + "../../api:array_view", "../../api/audio_codecs:audio_codecs_api", "../../api/audio_codecs/opus:audio_decoder_opus_config", "../../api/audio_codecs/opus:audio_encoder_opus_config", @@ -518,13 +506,11 @@ rtc_library("webrtc_multiopus") { "../../rtc_base:checks", "../../rtc_base:logging", "../../rtc_base:macromagic", + "../../rtc_base:safe_conversions", "../../rtc_base:safe_minmax", "../../rtc_base:stringutils", - ] - absl_deps = [ "//third_party/abseil-cpp/absl/memory", "//third_party/abseil-cpp/absl/strings", - "//third_party/abseil-cpp/absl/types:optional", ] public_deps += # no-presubmit-check TODO(webrtc:8603) [ ":webrtc_opus_wrapper" ] @@ -546,7 +532,6 @@ rtc_library("webrtc_opus_wrapper") { "../../api:array_view", "../../rtc_base:checks", "../../rtc_base:ignore_wundef", - "../../system_wrappers:field_trial", ] if (rtc_build_opus) { @@ -563,6 +548,7 @@ if (rtc_enable_protobuf) { sources = [ "audio_network_adaptor/debug_dump.proto" ] link_deps = [ ":ana_config_proto" ] proto_out_dir = "modules/audio_coding/audio_network_adaptor" + proto_data_sources = [ "audio_network_adaptor/config.proto" ] } proto_library("ana_config_proto") { visibility += [ "*" ] @@ -577,7 +563,6 @@ rtc_library("audio_network_adaptor_config") { "audio_network_adaptor/audio_network_adaptor_config.cc", "audio_network_adaptor/include/audio_network_adaptor_config.h", ] - absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] } rtc_library("audio_network_adaptor") { @@ -618,7 +603,6 @@ rtc_library("audio_network_adaptor") { "../../common_audio", "../../logging:rtc_event_audio", "../../rtc_base:checks", - "../../rtc_base:ignore_wundef", "../../rtc_base:logging", "../../rtc_base:protobuf_utils", "../../rtc_base:safe_conversions", @@ -626,11 +610,8 @@ rtc_library("audio_network_adaptor") { "../../rtc_base/system:file_wrapper", "../../system_wrappers", "../../system_wrappers:field_trial", - ] - absl_deps = [ "//third_party/abseil-cpp/absl/algorithm:container", - "//third_party/abseil-cpp/absl/strings", - "//third_party/abseil-cpp/absl/types:optional", + "//third_party/abseil-cpp/absl/strings:string_view", ] if (rtc_enable_protobuf) { @@ -662,6 +643,8 @@ rtc_library("neteq") { "neteq/decision_logic.h", "neteq/decoder_database.cc", "neteq/decoder_database.h", + "neteq/delay_constraints.cc", + "neteq/delay_constraints.h", "neteq/delay_manager.cc", "neteq/delay_manager.h", "neteq/dsp_helper.cc", @@ -690,8 +673,6 @@ rtc_library("neteq") { "neteq/packet_arrival_history.h", "neteq/packet_buffer.cc", "neteq/packet_buffer.h", - "neteq/post_decode_vad.cc", - "neteq/post_decode_vad.h", "neteq/preemptive_expand.cc", "neteq/preemptive_expand.h", "neteq/random_vector.cc", @@ -717,14 +698,17 @@ rtc_library("neteq") { ":webrtc_cng", "..:module_api_public", "../../api:array_view", + "../../api:field_trials_view", "../../api:rtp_headers", "../../api:rtp_packet_info", "../../api:scoped_refptr", "../../api/audio:audio_frame_api", "../../api/audio_codecs:audio_codecs_api", + "../../api/environment", "../../api/neteq:neteq_api", "../../api/neteq:neteq_controller_api", "../../api/neteq:tick_timer", + "../../api/units:timestamp", "../../common_audio", "../../common_audio:common_audio_c", "../../rtc_base:audio_format_to_string", @@ -741,28 +725,9 @@ rtc_library("neteq") { "../../rtc_base/experiments:field_trial_parser", "../../rtc_base/synchronization:mutex", "../../system_wrappers", - "../../system_wrappers:field_trial", "../../system_wrappers:metrics", - ] - absl_deps = [ "//third_party/abseil-cpp/absl/strings", - "//third_party/abseil-cpp/absl/types:optional", - ] -} - -rtc_source_set("default_neteq_factory") { - visibility += webrtc_default_visibility - sources = [ - "neteq/default_neteq_factory.cc", - "neteq/default_neteq_factory.h", - ] - deps = [ - ":neteq", - "../../api:scoped_refptr", - "../../api/audio_codecs:audio_codecs_api", - "../../api/neteq:default_neteq_controller_factory", - "../../api/neteq:neteq_api", - "../../system_wrappers:system_wrappers", + "//third_party/abseil-cpp/absl/strings:string_view", ] } @@ -788,16 +753,20 @@ rtc_library("neteq_tools_minimal") { ] deps = [ - ":default_neteq_factory", ":neteq", "../../api:array_view", + "../../api:field_trials", "../../api:neteq_simulator_api", "../../api:rtp_headers", "../../api/audio:audio_frame_api", "../../api/audio_codecs:audio_codecs_api", + "../../api/environment", + "../../api/environment:environment_factory", "../../api/neteq:custom_neteq_factory", "../../api/neteq:default_neteq_controller_factory", + "../../api/neteq:default_neteq_factory", "../../api/neteq:neteq_api", + "../../api/units:timestamp", "../../rtc_base:buffer", "../../rtc_base:checks", "../../rtc_base:copy_on_write_buffer", @@ -806,7 +775,6 @@ rtc_library("neteq_tools_minimal") { "../../system_wrappers", "../rtp_rtcp:rtp_rtcp_format", ] - absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] defines = audio_codec_defines } @@ -840,15 +808,13 @@ rtc_library("neteq_test_tools") { "../../common_audio", "../../rtc_base:buffer", "../../rtc_base:checks", - "../../rtc_base:ssl", + "../../rtc_base:copy_on_write_buffer", + "../../rtc_base:digest", "../../rtc_base:stringutils", "../../rtc_base/system:arch", "../../test:rtp_test_utils", "../rtp_rtcp:rtp_rtcp_format", - ] - absl_deps = [ - "//third_party/abseil-cpp/absl/strings", - "//third_party/abseil-cpp/absl/types:optional", + "//third_party/abseil-cpp/absl/strings:string_view", ] } @@ -880,10 +846,7 @@ rtc_library("neteq_tools") { "../../rtc_base:timeutils", "../rtp_rtcp", "../rtp_rtcp:rtp_rtcp_format", - ] - absl_deps = [ - "//third_party/abseil-cpp/absl/strings", - "//third_party/abseil-cpp/absl/types:optional", + "//third_party/abseil-cpp/absl/strings:string_view", ] if (rtc_enable_protobuf) { @@ -909,8 +872,8 @@ rtc_library("neteq_input_audio_tools") { deps = [ "../../common_audio", "../../rtc_base:checks", + "//third_party/abseil-cpp/absl/strings:string_view", ] - absl_deps = [ "//third_party/abseil-cpp/absl/strings" ] } if (rtc_enable_protobuf) { @@ -946,7 +909,6 @@ rtc_library("audio_coding_modules_tests_shared") { deps = [ ":audio_coding", ":audio_coding_module_typedefs", - ":default_neteq_factory", ":neteq_test_tools", ":neteq_tools_minimal", ":webrtc_opus_wrapper", @@ -955,19 +917,20 @@ rtc_library("audio_coding_modules_tests_shared") { "../../api/audio:audio_frame_api", "../../api/audio_codecs:builtin_audio_decoder_factory", "../../api/audio_codecs:builtin_audio_encoder_factory", + "../../api/environment", + "../../api/environment:environment_factory", + "../../api/neteq:default_neteq_factory", "../../api/neteq:neteq_api", + "../../api/units:timestamp", "../../rtc_base:checks", - "../../rtc_base:ignore_wundef", - "../../rtc_base:ssl", + "../../rtc_base:digest", "../../rtc_base:stringutils", "../../system_wrappers", "../../test:fileutils", "../../test:test_support", "//testing/gtest", - ] - absl_deps = [ "//third_party/abseil-cpp/absl/strings", - "//third_party/abseil-cpp/absl/types:optional", + "//third_party/abseil-cpp/absl/strings:string_view", ] defines = audio_coding_defines @@ -1087,6 +1050,11 @@ if (rtc_include_tests) { "../../api/audio_codecs/ilbc:audio_encoder_ilbc", "../../api/audio_codecs/opus:audio_decoder_opus", "../../api/audio_codecs/opus:audio_encoder_opus", + "../../api/environment", + "../../api/environment:environment_factory", + "../../api/neteq:default_neteq_factory", + "../../api/neteq:neteq_api", + "../../api/units:timestamp", "../../common_audio", "../../rtc_base:checks", "../../rtc_base:logging", @@ -1097,10 +1065,8 @@ if (rtc_include_tests) { "../../test:fileutils", "../../test:scoped_key_value_config", "../../test:test_support", - ] - absl_deps = [ "//third_party/abseil-cpp/absl/strings", - "//third_party/abseil-cpp/absl/types:optional", + "//third_party/abseil-cpp/absl/strings:string_view", ] defines = audio_coding_defines } @@ -1117,6 +1083,7 @@ if (rtc_include_tests) { ":neteq_test_support", ":neteq_test_tools", "../../api/audio_codecs/opus:audio_encoder_opus", + "../../api/environment:environment_factory", "../../api/test/metrics:global_metrics_logger_and_exporter", "../../api/test/metrics:metric", "../../rtc_base:macromagic", @@ -1125,8 +1092,8 @@ if (rtc_include_tests) { "../../test:fileutils", "../../test:test_flags", "../../test:test_support", + "//third_party/abseil-cpp/absl/flags:flag", ] - absl_deps = [ "//third_party/abseil-cpp/absl/flags:flag" ] } rtc_library("acm_receive_test") { @@ -1145,12 +1112,14 @@ if (rtc_include_tests) { "../../api:scoped_refptr", "../../api/audio_codecs:audio_codecs_api", "../../api/audio_codecs:builtin_audio_decoder_factory", + "../../api/environment:environment_factory", + "../../api/neteq:default_neteq_factory", + "../../api/neteq:neteq_api", "../../test:test_support", "//testing/gtest", ] deps += audio_coding_deps - absl_deps = [ "//third_party/abseil-cpp/absl/strings" ] } rtc_library("acm_send_test") { @@ -1171,13 +1140,16 @@ if (rtc_include_tests) { "../../api/audio_codecs:audio_codecs_api", "../../api/audio_codecs:builtin_audio_decoder_factory", "../../api/audio_codecs:builtin_audio_encoder_factory", + "../../api/environment", + "../../api/environment:environment_factory", "../../rtc_base:checks", "../../rtc_base:stringutils", "../../test:test_support", "//testing/gtest", + "//third_party/abseil-cpp/absl/strings", + "//third_party/abseil-cpp/absl/strings:string_view", ] deps += audio_coding_deps - absl_deps = [ "//third_party/abseil-cpp/absl/strings" ] } if (!build_with_chromium) { @@ -1205,8 +1177,10 @@ if (rtc_include_tests) { ":neteq_tools", "../../api/audio_codecs:audio_codecs_api", "../../api/audio_codecs/opus:audio_encoder_opus", + "../../api/environment:environment_factory", "../../common_audio", "../../rtc_base/system:arch", + "../../test:explicit_key_value_config", "../../test:fileutils", "../../test:test_main", "../../test:test_support", @@ -1242,10 +1216,7 @@ if (rtc_include_tests) { "../../rtc_base:checks", "../../rtc_base:refcount", "../../test:fileutils", - ] - absl_deps = [ - "//third_party/abseil-cpp/absl/strings", - "//third_party/abseil-cpp/absl/types:optional", + "//third_party/abseil-cpp/absl/strings:string_view", ] sources = [ "neteq/tools/neteq_test_factory.cc", @@ -1279,7 +1250,6 @@ if (rtc_include_tests) { "//third_party/abseil-cpp/absl/flags:flag", "//third_party/abseil-cpp/absl/flags:parse", "//third_party/abseil-cpp/absl/strings", - "//third_party/abseil-cpp/absl/types:optional", ] sources = [ "neteq/tools/neteq_rtpplay.cc" ] } @@ -1348,13 +1318,15 @@ if (rtc_include_tests) { ] deps = [ - ":default_neteq_factory", ":neteq", ":neteq_test_tools", ":pcm16b", "../../api/audio:audio_frame_api", "../../api/audio_codecs:audio_codecs_api", "../../api/audio_codecs:builtin_audio_decoder_factory", + "../../api/environment", + "../../api/environment:environment_factory", + "../../api/neteq:default_neteq_factory", "../../api/neteq:neteq_api", "../../rtc_base:checks", "../../system_wrappers", @@ -1373,23 +1345,23 @@ if (rtc_include_tests) { ] deps = [ - ":default_neteq_factory", ":neteq", ":neteq_input_audio_tools", ":neteq_test_tools", ":neteq_tools_minimal", "../../api/audio_codecs:builtin_audio_decoder_factory", + "../../api/environment:environment_factory", + "../../api/neteq:default_neteq_factory", "../../api/neteq:neteq_api", + "../../api/units:timestamp", "../../rtc_base:checks", "../../rtc_base:stringutils", "../../system_wrappers", "../../test:fileutils", "../../test:test_support", "//testing/gtest", - ] - absl_deps = [ "//third_party/abseil-cpp/absl/flags:flag", - "//third_party/abseil-cpp/absl/strings", + "//third_party/abseil-cpp/absl/strings:string_view", ] } @@ -1398,6 +1370,7 @@ if (rtc_include_tests) { deps = [ ":audio_coding", + ":audio_coding_module_typedefs", ":audio_encoder_cng", ":neteq_input_audio_tools", "../../api/audio:audio_frame_api", @@ -1406,10 +1379,12 @@ if (rtc_include_tests) { "../../api/audio_codecs/g722:audio_encoder_g722", "../../api/audio_codecs/ilbc:audio_encoder_ilbc", "../../api/audio_codecs/opus:audio_encoder_opus", + "../../api/environment:environment_factory", + "../../rtc_base:checks", + "../../rtc_base:ip_address", "../../rtc_base:safe_conversions", "//third_party/abseil-cpp/absl/flags:flag", "//third_party/abseil-cpp/absl/flags:parse", - "//third_party/abseil-cpp/absl/memory", ] deps += audio_coding_deps @@ -1596,7 +1571,6 @@ if (rtc_include_tests) { visibility += webrtc_default_visibility sources = [ - "acm2/acm_receiver_unittest.cc", "acm2/acm_remixing_unittest.cc", "acm2/audio_coding_module_unittest.cc", "acm2/call_statistics_unittest.cc", @@ -1629,6 +1603,7 @@ if (rtc_include_tests) { "neteq/comfort_noise_unittest.cc", "neteq/decision_logic_unittest.cc", "neteq/decoder_database_unittest.cc", + "neteq/delay_constraints_unittest.cc", "neteq/delay_manager_unittest.cc", "neteq/dsp_helper_unittest.cc", "neteq/dtmf_buffer_unittest.cc", @@ -1644,6 +1619,7 @@ if (rtc_include_tests) { "neteq/mock/mock_expand.h", "neteq/mock/mock_histogram.h", "neteq/mock/mock_neteq_controller.h", + "neteq/mock/mock_packet_arrival_history.h", "neteq/mock/mock_packet_buffer.h", "neteq/mock/mock_red_payload_splitter.h", "neteq/mock/mock_statistics_calculator.h", @@ -1656,7 +1632,6 @@ if (rtc_include_tests) { "neteq/normal_unittest.cc", "neteq/packet_arrival_history_unittest.cc", "neteq/packet_buffer_unittest.cc", - "neteq/post_decode_vad_unittest.cc", "neteq/random_vector_unittest.cc", "neteq/red_payload_splitter_unittest.cc", "neteq/reorder_optimizer_unittest.cc", @@ -1678,7 +1653,6 @@ if (rtc_include_tests) { ":audio_coding_opus_common", ":audio_encoder_cng", ":audio_network_adaptor", - ":default_neteq_factory", ":g711", ":ilbc", ":legacy_encoded_audio_frame", @@ -1704,12 +1678,16 @@ if (rtc_include_tests) { "../../api/audio_codecs/opus:audio_decoder_opus", "../../api/audio_codecs/opus:audio_encoder_multiopus", "../../api/audio_codecs/opus:audio_encoder_opus", + "../../api/environment", + "../../api/environment:environment_factory", "../../api/neteq:default_neteq_controller_factory", + "../../api/neteq:default_neteq_factory", "../../api/neteq:neteq_api", "../../api/neteq:neteq_controller_api", "../../api/neteq:tick_timer", "../../api/neteq:tick_timer_unittest", "../../api/rtc_event_log", + "../../api/units:timestamp", "../../common_audio", "../../common_audio:common_audio_c", "../../common_audio:mock_common_audio", @@ -1717,7 +1695,7 @@ if (rtc_include_tests) { "../../logging:rtc_event_audio", "../../modules/rtp_rtcp:rtp_rtcp_format", "../../rtc_base:checks", - "../../rtc_base:ignore_wundef", + "../../rtc_base:digest", "../../rtc_base:macromagic", "../../rtc_base:platform_thread", "../../rtc_base:refcount", @@ -1725,7 +1703,6 @@ if (rtc_include_tests) { "../../rtc_base:rtc_event", "../../rtc_base:safe_conversions", "../../rtc_base:sanitizer", - "../../rtc_base:ssl", "../../rtc_base:stringutils", "../../rtc_base:timeutils", "../../rtc_base/synchronization:mutex", @@ -1733,6 +1710,7 @@ if (rtc_include_tests) { "../../system_wrappers", "../../test:audio_codec_mocks", "../../test:audio_test_common", + "../../test:explicit_key_value_config", "../../test:field_trial", "../../test:fileutils", "../../test:rtc_expect_death", @@ -1743,12 +1721,9 @@ if (rtc_include_tests) { "codecs/opus/test", "codecs/opus/test:test_unittest", "//testing/gtest", - ] - absl_deps = [ "//third_party/abseil-cpp/absl/flags:flag", "//third_party/abseil-cpp/absl/memory", - "//third_party/abseil-cpp/absl/strings", - "//third_party/abseil-cpp/absl/types:optional", + "//third_party/abseil-cpp/absl/strings:string_view", ] defines = audio_coding_defines diff --git a/webrtc/modules/audio_coding/codecs/isac/main/include/audio_decoder_isac.h b/webrtc/modules/audio_coding/codecs/isac/main/include/audio_decoder_isac.h deleted file mode 100644 index fae2f3d..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/include/audio_decoder_isac.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_INCLUDE_AUDIO_DECODER_ISAC_H_ -#define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_INCLUDE_AUDIO_DECODER_ISAC_H_ - -#include "modules/audio_coding/codecs/isac/audio_decoder_isac_t.h" -#include "modules/audio_coding/codecs/isac/main/source/isac_float_type.h" - -namespace webrtc { - -using AudioDecoderIsacFloatImpl = AudioDecoderIsacT; - -} // namespace webrtc -#endif // MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_INCLUDE_AUDIO_ENCODER_ISAC_H_ diff --git a/webrtc/modules/audio_coding/codecs/isac/main/include/audio_encoder_isac.h b/webrtc/modules/audio_coding/codecs/isac/main/include/audio_encoder_isac.h deleted file mode 100644 index dc32bcd..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/include/audio_encoder_isac.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_INCLUDE_AUDIO_ENCODER_ISAC_H_ -#define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_INCLUDE_AUDIO_ENCODER_ISAC_H_ - -#include "modules/audio_coding/codecs/isac/audio_encoder_isac_t.h" -#include "modules/audio_coding/codecs/isac/main/source/isac_float_type.h" - -namespace webrtc { - -using AudioEncoderIsacFloatImpl = AudioEncoderIsacT; - -} // namespace webrtc -#endif // MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_INCLUDE_AUDIO_ENCODER_ISAC_H_ diff --git a/webrtc/modules/audio_coding/codecs/isac/main/include/isac.h b/webrtc/modules/audio_coding/codecs/isac/main/include/isac.h deleted file mode 100644 index 3d2caef..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/include/isac.h +++ /dev/null @@ -1,617 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_INCLUDE_ISAC_H_ -#define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_INCLUDE_ISAC_H_ - -#include - -#include "modules/audio_coding/codecs/isac/bandwidth_info.h" - -typedef struct WebRtcISACStruct ISACStruct; - -#if defined(__cplusplus) -extern "C" { -#endif - -/****************************************************************************** - * WebRtcIsac_Create(...) - * - * This function creates an ISAC instance, which will contain the state - * information for one coding/decoding channel. - * - * Input: - * - *ISAC_main_inst : a pointer to the coder instance. - * - * Return value : 0 - Ok - * -1 - Error - */ - -int16_t WebRtcIsac_Create(ISACStruct** ISAC_main_inst); - -/****************************************************************************** - * WebRtcIsac_Free(...) - * - * This function frees the ISAC instance created at the beginning. - * - * Input: - * - ISAC_main_inst : an ISAC instance. - * - * Return value : 0 - Ok - * -1 - Error - */ - -int16_t WebRtcIsac_Free(ISACStruct* ISAC_main_inst); - -/****************************************************************************** - * WebRtcIsac_EncoderInit(...) - * - * This function initializes an ISAC instance prior to the encoder calls. - * - * Input: - * - ISAC_main_inst : ISAC instance. - * - CodingMode : 0 -> Bit rate and frame length are - * automatically adjusted to available bandwidth - * on transmission channel, just valid if codec - * is created to work in wideband mode. - * 1 -> User sets a frame length and a target bit - * rate which is taken as the maximum - * short-term average bit rate. - * - * Return value : 0 - Ok - * -1 - Error - */ - -int16_t WebRtcIsac_EncoderInit(ISACStruct* ISAC_main_inst, int16_t CodingMode); - -/****************************************************************************** - * WebRtcIsac_Encode(...) - * - * This function encodes 10ms audio blocks and inserts it into a package. - * Input speech length has 160 samples if operating at 16 kHz sampling - * rate, or 320 if operating at 32 kHz sampling rate. The encoder buffers the - * input audio until the whole frame is buffered then proceeds with encoding. - * - * - * Input: - * - ISAC_main_inst : ISAC instance. - * - speechIn : input speech vector. - * - * Output: - * - encoded : the encoded data vector - * - * Return value: - * : >0 - Length (in bytes) of coded data - * : 0 - The buffer didn't reach the chosen - * frame-size so it keeps buffering speech - * samples. - * : -1 - Error - */ - -int WebRtcIsac_Encode(ISACStruct* ISAC_main_inst, - const int16_t* speechIn, - uint8_t* encoded); - -/****************************************************************************** - * WebRtcIsac_DecoderInit(...) - * - * This function initializes an ISAC instance prior to the decoder calls. - * - * Input: - * - ISAC_main_inst : ISAC instance. - */ - -void WebRtcIsac_DecoderInit(ISACStruct* ISAC_main_inst); - -/****************************************************************************** - * WebRtcIsac_UpdateBwEstimate(...) - * - * This function updates the estimate of the bandwidth. - * - * Input: - * - ISAC_main_inst : ISAC instance. - * - encoded : encoded ISAC frame(s). - * - packet_size : size of the packet. - * - rtp_seq_number : the RTP number of the packet. - * - send_ts : the RTP send timestamp, given in samples - * - arr_ts : the arrival time of the packet (from NetEq) - * in samples. - * - * Return value : 0 - Ok - * -1 - Error - */ - -int16_t WebRtcIsac_UpdateBwEstimate(ISACStruct* ISAC_main_inst, - const uint8_t* encoded, - size_t packet_size, - uint16_t rtp_seq_number, - uint32_t send_ts, - uint32_t arr_ts); - -/****************************************************************************** - * WebRtcIsac_Decode(...) - * - * This function decodes an ISAC frame. At 16 kHz sampling rate, the length - * of the output audio could be either 480 or 960 samples, equivalent to - * 30 or 60 ms respectively. At 32 kHz sampling rate, the length of the - * output audio is 960 samples, which is 30 ms. - * - * Input: - * - ISAC_main_inst : ISAC instance. - * - encoded : encoded ISAC frame(s). - * - len : bytes in encoded vector. - * - * Output: - * - decoded : The decoded vector. - * - * Return value : >0 - number of samples in decoded vector. - * -1 - Error. - */ - -int WebRtcIsac_Decode(ISACStruct* ISAC_main_inst, - const uint8_t* encoded, - size_t len, - int16_t* decoded, - int16_t* speechType); - -/****************************************************************************** - * WebRtcIsac_DecodePlc(...) - * - * This function conducts PLC for ISAC frame(s). Output speech length - * will be a multiple of frames, i.e. multiples of 30 ms audio. Therefore, - * the output is multiple of 480 samples if operating at 16 kHz and multiple - * of 960 if operating at 32 kHz. - * - * Input: - * - ISAC_main_inst : ISAC instance. - * - noOfLostFrames : Number of PLC frames to produce. - * - * Output: - * - decoded : The decoded vector. - * - * Return value : Number of samples in decoded PLC vector - */ - -size_t WebRtcIsac_DecodePlc(ISACStruct* ISAC_main_inst, - int16_t* decoded, - size_t noOfLostFrames); - -/****************************************************************************** - * WebRtcIsac_Control(...) - * - * This function sets the limit on the short-term average bit-rate and the - * frame length. Should be used only in Instantaneous mode. At 16 kHz sampling - * rate, an average bit-rate between 10000 to 32000 bps is valid and a - * frame-size of 30 or 60 ms is acceptable. At 32 kHz, an average bit-rate - * between 10000 to 56000 is acceptable, and the valid frame-size is 30 ms. - * - * Input: - * - ISAC_main_inst : ISAC instance. - * - rate : limit on the short-term average bit rate, - * in bits/second. - * - framesize : frame-size in millisecond. - * - * Return value : 0 - ok - * -1 - Error - */ - -int16_t WebRtcIsac_Control(ISACStruct* ISAC_main_inst, - int32_t rate, - int framesize); - -void WebRtcIsac_SetInitialBweBottleneck(ISACStruct* ISAC_main_inst, - int bottleneck_bits_per_second); - -/****************************************************************************** - * WebRtcIsac_ControlBwe(...) - * - * This function sets the initial values of bottleneck and frame-size if - * iSAC is used in channel-adaptive mode. Therefore, this API is not - * applicable if the codec is created to operate in super-wideband mode. - * - * Through this API, users can enforce a frame-size for all values of - * bottleneck. Then iSAC will not automatically change the frame-size. - * - * - * Input: - * - ISAC_main_inst : ISAC instance. - * - rateBPS : initial value of bottleneck in bits/second - * 10000 <= rateBPS <= 56000 is accepted - * For default bottleneck set rateBPS = 0 - * - frameSizeMs : number of milliseconds per frame (30 or 60) - * - enforceFrameSize : 1 to enforce the given frame-size through - * out the adaptation process, 0 to let iSAC - * change the frame-size if required. - * - * Return value : 0 - ok - * -1 - Error - */ - -int16_t WebRtcIsac_ControlBwe(ISACStruct* ISAC_main_inst, - int32_t rateBPS, - int frameSizeMs, - int16_t enforceFrameSize); - -/****************************************************************************** - * WebRtcIsac_ReadFrameLen(...) - * - * This function returns the length of the frame represented in the packet. - * - * Input: - * - encoded : Encoded bit-stream - * - * Output: - * - frameLength : Length of frame in packet (in samples) - * - */ - -int16_t WebRtcIsac_ReadFrameLen(const ISACStruct* ISAC_main_inst, - const uint8_t* encoded, - int16_t* frameLength); - -/****************************************************************************** - * WebRtcIsac_version(...) - * - * This function returns the version number. - * - * Output: - * - version : Pointer to character string - * - */ - -void WebRtcIsac_version(char* version); - -/****************************************************************************** - * WebRtcIsac_GetErrorCode(...) - * - * This function can be used to check the error code of an iSAC instance. When - * a function returns -1 a error code will be set for that instance. The - * function below extract the code of the last error that occurred in the - * specified instance. - * - * Input: - * - ISAC_main_inst : ISAC instance - * - * Return value : Error code - */ - -int16_t WebRtcIsac_GetErrorCode(ISACStruct* ISAC_main_inst); - -/**************************************************************************** - * WebRtcIsac_GetUplinkBw(...) - * - * This function outputs the target bottleneck of the codec. In - * channel-adaptive mode, the target bottleneck is specified through in-band - * signalling retreived by bandwidth estimator. - * In channel-independent, also called instantaneous mode, the target - * bottleneck is provided to the encoder by calling xxx_control(...). If - * xxx_control is never called the default values is returned. The default - * value for bottleneck at 16 kHz encoder sampling rate is 32000 bits/sec, - * and it is 56000 bits/sec for 32 kHz sampling rate. - * Note that the output is the iSAC internal operating bottleneck which might - * differ slightly from the one provided through xxx_control(). - * - * Input: - * - ISAC_main_inst : iSAC instance - * - * Output: - * - *bottleneck : bottleneck in bits/sec - * - * Return value : -1 if error happens - * 0 bit-rates computed correctly. - */ - -int16_t WebRtcIsac_GetUplinkBw(ISACStruct* ISAC_main_inst, int32_t* bottleneck); - -/****************************************************************************** - * WebRtcIsac_SetMaxPayloadSize(...) - * - * This function sets a limit for the maximum payload size of iSAC. The same - * value is used both for 30 and 60 ms packets. If the encoder sampling rate - * is 16 kHz the maximum payload size is between 120 and 400 bytes. If the - * encoder sampling rate is 32 kHz the maximum payload size is between 120 - * and 600 bytes. - * - * If an out of range limit is used, the function returns -1, but the closest - * valid value will be applied. - * - * --------------- - * IMPORTANT NOTES - * --------------- - * The size of a packet is limited to the minimum of 'max-payload-size' and - * 'max-rate.' For instance, let's assume the max-payload-size is set to - * 170 bytes, and max-rate is set to 40 kbps. Note that a limit of 40 kbps - * translates to 150 bytes for 30ms frame-size & 300 bytes for 60ms - * frame-size. Then a packet with a frame-size of 30 ms is limited to 150, - * i.e. min(170, 150), and a packet with 60 ms frame-size is limited to - * 170 bytes, i.e. min(170, 300). - * - * Input: - * - ISAC_main_inst : iSAC instance - * - maxPayloadBytes : maximum size of the payload in bytes - * valid values are between 120 and 400 bytes - * if encoder sampling rate is 16 kHz. For - * 32 kHz encoder sampling rate valid values - * are between 120 and 600 bytes. - * - * Return value : 0 if successful - * -1 if error happens - */ - -int16_t WebRtcIsac_SetMaxPayloadSize(ISACStruct* ISAC_main_inst, - int16_t maxPayloadBytes); - -/****************************************************************************** - * WebRtcIsac_SetMaxRate(...) - * - * This function sets the maximum rate which the codec may not exceed for - * any signal packet. The maximum rate is defined and payload-size per - * frame-size in bits per second. - * - * The codec has a maximum rate of 53400 bits per second (200 bytes per 30 - * ms) if the encoder sampling rate is 16kHz, and 160 kbps (600 bytes/30 ms) - * if the encoder sampling rate is 32 kHz. - * - * It is possible to set a maximum rate between 32000 and 53400 bits/sec - * in wideband mode, and 32000 to 160000 bits/sec in super-wideband mode. - * - * If an out of range limit is used, the function returns -1, but the closest - * valid value will be applied. - * - * --------------- - * IMPORTANT NOTES - * --------------- - * The size of a packet is limited to the minimum of 'max-payload-size' and - * 'max-rate.' For instance, let's assume the max-payload-size is set to - * 170 bytes, and max-rate is set to 40 kbps. Note that a limit of 40 kbps - * translates to 150 bytes for 30ms frame-size & 300 bytes for 60ms - * frame-size. Then a packet with a frame-size of 30 ms is limited to 150, - * i.e. min(170, 150), and a packet with 60 ms frame-size is limited to - * 170 bytes, min(170, 300). - * - * Input: - * - ISAC_main_inst : iSAC instance - * - maxRate : maximum rate in bits per second, - * valid values are 32000 to 53400 bits/sec in - * wideband mode, and 32000 to 160000 bits/sec in - * super-wideband mode. - * - * Return value : 0 if successful - * -1 if error happens - */ - -int16_t WebRtcIsac_SetMaxRate(ISACStruct* ISAC_main_inst, int32_t maxRate); - -/****************************************************************************** - * WebRtcIsac_DecSampRate() - * Return the sampling rate of the decoded audio. - * - * Input: - * - ISAC_main_inst : iSAC instance - * - * Return value : sampling frequency in Hertz. - * - */ - -uint16_t WebRtcIsac_DecSampRate(ISACStruct* ISAC_main_inst); - -/****************************************************************************** - * WebRtcIsac_EncSampRate() - * - * Input: - * - ISAC_main_inst : iSAC instance - * - * Return value : sampling rate in Hertz. - * - */ - -uint16_t WebRtcIsac_EncSampRate(ISACStruct* ISAC_main_inst); - -/****************************************************************************** - * WebRtcIsac_SetDecSampRate() - * Set the sampling rate of the decoder. Initialization of the decoder WILL - * NOT overwrite the sampling rate of the encoder. The default value is 16 kHz - * which is set when the instance is created. - * - * Input: - * - ISAC_main_inst : iSAC instance - * - sampRate : sampling rate in Hertz. - * - * Return value : 0 if successful - * -1 if failed. - */ - -int16_t WebRtcIsac_SetDecSampRate(ISACStruct* ISAC_main_inst, - uint16_t samp_rate_hz); - -/****************************************************************************** - * WebRtcIsac_SetEncSampRate() - * Set the sampling rate of the encoder. Initialization of the encoder WILL - * NOT overwrite the sampling rate of the encoder. The default value is 16 kHz - * which is set when the instance is created. The encoding-mode and the - * bottleneck remain unchanged by this call, however, the maximum rate and - * maximum payload-size will reset to their default value. - * - * Input: - * - ISAC_main_inst : iSAC instance - * - sampRate : sampling rate in Hertz. - * - * Return value : 0 if successful - * -1 if failed. - */ - -int16_t WebRtcIsac_SetEncSampRate(ISACStruct* ISAC_main_inst, - uint16_t sample_rate_hz); - -/****************************************************************************** - * WebRtcIsac_GetNewBitStream(...) - * - * This function returns encoded data, with the recieved bwe-index in the - * stream. If the rate is set to a value less than bottleneck of codec - * the new bistream will be re-encoded with the given target rate. - * It should always return a complete packet, i.e. only called once - * even for 60 msec frames. - * - * NOTE 1! This function does not write in the ISACStruct, it is not allowed. - * NOTE 2! Currently not implemented for SWB mode. - * NOTE 3! Rates larger than the bottleneck of the codec will be limited - * to the current bottleneck. - * - * Input: - * - ISAC_main_inst : ISAC instance. - * - bweIndex : Index of bandwidth estimate to put in new - * bitstream - * - rate : target rate of the transcoder is bits/sec. - * Valid values are the accepted rate in iSAC, - * i.e. 10000 to 56000. - * - isRCU : if the new bit-stream is an RCU - * stream. Note that the rate parameter always indicates the target rate of the - * main payload, regardless of 'isRCU' value. - * - * Output: - * - encoded : The encoded data vector - * - * Return value : >0 - Length (in bytes) of coded data - * -1 - Error or called in SWB mode - * NOTE! No error code is written to - * the struct since it is only allowed to read - * the struct. - */ -int16_t WebRtcIsac_GetNewBitStream(ISACStruct* ISAC_main_inst, - int16_t bweIndex, - int16_t jitterInfo, - int32_t rate, - uint8_t* encoded, - int16_t isRCU); - -/**************************************************************************** - * WebRtcIsac_GetDownLinkBwIndex(...) - * - * This function returns index representing the Bandwidth estimate from - * other side to this side. - * - * Input: - * - ISAC_main_inst : iSAC struct - * - * Output: - * - bweIndex : Bandwidth estimate to transmit to other side. - * - */ - -int16_t WebRtcIsac_GetDownLinkBwIndex(ISACStruct* ISAC_main_inst, - int16_t* bweIndex, - int16_t* jitterInfo); - -/**************************************************************************** - * WebRtcIsac_UpdateUplinkBw(...) - * - * This function takes an index representing the Bandwidth estimate from - * this side to other side and updates BWE. - * - * Input: - * - ISAC_main_inst : iSAC struct - * - bweIndex : Bandwidth estimate from other side. - * - */ - -int16_t WebRtcIsac_UpdateUplinkBw(ISACStruct* ISAC_main_inst, int16_t bweIndex); - -/**************************************************************************** - * WebRtcIsac_ReadBwIndex(...) - * - * This function returns the index of the Bandwidth estimate from the bitstream. - * - * Input: - * - encoded : Encoded bitstream - * - * Output: - * - frameLength : Length of frame in packet (in samples) - * - bweIndex : Bandwidth estimate in bitstream - * - */ - -int16_t WebRtcIsac_ReadBwIndex(const uint8_t* encoded, int16_t* bweIndex); - -/******************************************************************************* - * WebRtcIsac_GetNewFrameLen(...) - * - * returns the frame lenght (in samples) of the next packet. In the case of - * channel-adaptive mode, iSAC decides on its frame lenght based on the - * estimated bottleneck this allows a user to prepare for the next packet (at - * the encoder) - * - * The primary usage is in CE to make the iSAC works in channel-adaptive mode - * - * Input: - * - ISAC_main_inst : iSAC struct - * - * Return Value : frame lenght in samples - * - */ - -int16_t WebRtcIsac_GetNewFrameLen(ISACStruct* ISAC_main_inst); - -/**************************************************************************** - * WebRtcIsac_GetRedPayload(...) - * - * Populates "encoded" with the redundant payload of the recently encoded - * frame. This function has to be called once that WebRtcIsac_Encode(...) - * returns a positive value. Regardless of the frame-size this function will - * be called only once after encoding is completed. - * - * Input: - * - ISAC_main_inst : iSAC struct - * - * Output: - * - encoded : the encoded data vector - * - * - * Return value: - * : >0 - Length (in bytes) of coded data - * : -1 - Error - * - * - */ -int16_t WebRtcIsac_GetRedPayload(ISACStruct* ISAC_main_inst, uint8_t* encoded); - -/**************************************************************************** - * WebRtcIsac_DecodeRcu(...) - * - * This function decodes a redundant (RCU) iSAC frame. Function is called in - * NetEq with a stored RCU payload i case of packet loss. Output speech length - * will be a multiple of 480 samples: 480 or 960 samples, - * depending on the framesize (30 or 60 ms). - * - * Input: - * - ISAC_main_inst : ISAC instance. - * - encoded : encoded ISAC RCU frame(s) - * - len : bytes in encoded vector - * - * Output: - * - decoded : The decoded vector - * - * Return value : >0 - number of samples in decoded vector - * -1 - Error - */ -int WebRtcIsac_DecodeRcu(ISACStruct* ISAC_main_inst, - const uint8_t* encoded, - size_t len, - int16_t* decoded, - int16_t* speechType); - -/* If |inst| is a decoder but not an encoder: tell it what sample rate the - encoder is using, for bandwidth estimation purposes. */ -void WebRtcIsac_SetEncSampRateInDecoder(ISACStruct* inst, int sample_rate_hz); - -#if defined(__cplusplus) -} -#endif - -#endif /* MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_INCLUDE_ISAC_H_ */ diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/arith_routines.c b/webrtc/modules/audio_coding/codecs/isac/main/source/arith_routines.c deleted file mode 100644 index 9d5c693..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/arith_routines.c +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "modules/audio_coding/codecs/isac/main/source/arith_routines.h" -#include "modules/audio_coding/codecs/isac/main/source/settings.h" - - -/* - * terminate and return byte stream; - * returns the number of bytes in the stream - */ -int WebRtcIsac_EncTerminate(Bitstr *streamdata) /* in-/output struct containing bitstream */ -{ - uint8_t *stream_ptr; - - - /* point to the right place in the stream buffer */ - stream_ptr = streamdata->stream + streamdata->stream_index; - - /* find minimum length (determined by current interval width) */ - if ( streamdata->W_upper > 0x01FFFFFF ) - { - streamdata->streamval += 0x01000000; - /* add carry to buffer */ - if (streamdata->streamval < 0x01000000) - { - /* propagate carry */ - while ( !(++(*--stream_ptr)) ); - /* put pointer back to the old value */ - stream_ptr = streamdata->stream + streamdata->stream_index; - } - /* write remaining data to bitstream */ - *stream_ptr++ = (uint8_t) (streamdata->streamval >> 24); - } - else - { - streamdata->streamval += 0x00010000; - /* add carry to buffer */ - if (streamdata->streamval < 0x00010000) - { - /* propagate carry */ - while ( !(++(*--stream_ptr)) ); - /* put pointer back to the old value */ - stream_ptr = streamdata->stream + streamdata->stream_index; - } - /* write remaining data to bitstream */ - *stream_ptr++ = (uint8_t) (streamdata->streamval >> 24); - *stream_ptr++ = (uint8_t) ((streamdata->streamval >> 16) & 0x00FF); - } - - /* calculate stream length */ - return (int)(stream_ptr - streamdata->stream); -} diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/arith_routines.h b/webrtc/modules/audio_coding/codecs/isac/main/source/arith_routines.h deleted file mode 100644 index 6e7ea1d..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/arith_routines.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -/* - * arith_routines.h - * - * Functions for arithmetic coding. - * - */ - -#ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ARITH_ROUTINES_H_ -#define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ARITH_ROUTINES_H_ - -#include "modules/audio_coding/codecs/isac/main/source/structs.h" - -int WebRtcIsac_EncLogisticMulti2( - Bitstr* streamdata, /* in-/output struct containing bitstream */ - int16_t* dataQ7, /* input: data vector */ - const uint16_t* - env, /* input: side info vector defining the width of the pdf */ - const int N, /* input: data vector length */ - const int16_t isSWB12kHz); /* if the codec is working in 12kHz bandwidth */ - -/* returns the number of bytes in the stream */ -int WebRtcIsac_EncTerminate( - Bitstr* streamdata); /* in-/output struct containing bitstream */ - -/* returns the number of bytes in the stream so far */ -int WebRtcIsac_DecLogisticMulti2( - int16_t* data, /* output: data vector */ - Bitstr* streamdata, /* in-/output struct containing bitstream */ - const uint16_t* - env, /* input: side info vector defining the width of the pdf */ - const int16_t* dither, /* input: dither vector */ - const int N, /* input: data vector length */ - const int16_t isSWB12kHz); /* if the codec is working in 12kHz bandwidth */ - -void WebRtcIsac_EncHistMulti( - Bitstr* streamdata, /* in-/output struct containing bitstream */ - const int* data, /* input: data vector */ - const uint16_t* const* cdf, /* input: array of cdf arrays */ - const int N); /* input: data vector length */ - -int WebRtcIsac_DecHistBisectMulti( - int* data, /* output: data vector */ - Bitstr* streamdata, /* in-/output struct containing bitstream */ - const uint16_t* const* cdf, /* input: array of cdf arrays */ - const uint16_t* - cdf_size, /* input: array of cdf table sizes+1 (power of two: 2^k) */ - const int N); /* input: data vector length */ - -int WebRtcIsac_DecHistOneStepMulti( - int* data, /* output: data vector */ - Bitstr* streamdata, /* in-/output struct containing bitstream */ - const uint16_t* const* cdf, /* input: array of cdf arrays */ - const uint16_t* - init_index, /* input: vector of initial cdf table search entries */ - const int N); /* input: data vector length */ - -#endif /* MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ARITH_ROUTINES_H_ */ diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/arith_routines_hist.c b/webrtc/modules/audio_coding/codecs/isac/main/source/arith_routines_hist.c deleted file mode 100644 index e948979..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/arith_routines_hist.c +++ /dev/null @@ -1,291 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "modules/audio_coding/codecs/isac/main/source/settings.h" -#include "modules/audio_coding/codecs/isac/main/source/arith_routines.h" - - -/* - * code symbols into arithmetic bytestream - */ -void WebRtcIsac_EncHistMulti(Bitstr *streamdata, /* in-/output struct containing bitstream */ - const int *data, /* input: data vector */ - const uint16_t *const *cdf, /* input: array of cdf arrays */ - const int N) /* input: data vector length */ -{ - uint32_t W_lower, W_upper; - uint32_t W_upper_LSB, W_upper_MSB; - uint8_t *stream_ptr; - uint8_t *stream_ptr_carry; - uint32_t cdf_lo, cdf_hi; - int k; - - - /* point to beginning of stream buffer */ - stream_ptr = streamdata->stream + streamdata->stream_index; - W_upper = streamdata->W_upper; - - for (k=N; k>0; k--) - { - /* fetch cdf_lower and cdf_upper from cdf tables */ - cdf_lo = (uint32_t) *(*cdf + *data); - cdf_hi = (uint32_t) *(*cdf++ + *data++ + 1); - - /* update interval */ - W_upper_LSB = W_upper & 0x0000FFFF; - W_upper_MSB = W_upper >> 16; - W_lower = W_upper_MSB * cdf_lo; - W_lower += (W_upper_LSB * cdf_lo) >> 16; - W_upper = W_upper_MSB * cdf_hi; - W_upper += (W_upper_LSB * cdf_hi) >> 16; - - /* shift interval such that it begins at zero */ - W_upper -= ++W_lower; - - /* add integer to bitstream */ - streamdata->streamval += W_lower; - - /* handle carry */ - if (streamdata->streamval < W_lower) - { - /* propagate carry */ - stream_ptr_carry = stream_ptr; - while (!(++(*--stream_ptr_carry))); - } - - /* renormalize interval, store most significant byte of streamval and update streamval */ - while ( !(W_upper & 0xFF000000) ) /* W_upper < 2^24 */ - { - W_upper <<= 8; - *stream_ptr++ = (uint8_t) (streamdata->streamval >> 24); - streamdata->streamval <<= 8; - } - } - - /* calculate new stream_index */ - streamdata->stream_index = (int)(stream_ptr - streamdata->stream); - streamdata->W_upper = W_upper; - - return; -} - - - -/* - * function to decode more symbols from the arithmetic bytestream, using method of bisection - * cdf tables should be of size 2^k-1 (which corresponds to an alphabet size of 2^k-2) - */ -int WebRtcIsac_DecHistBisectMulti(int *data, /* output: data vector */ - Bitstr *streamdata, /* in-/output struct containing bitstream */ - const uint16_t *const *cdf, /* input: array of cdf arrays */ - const uint16_t *cdf_size, /* input: array of cdf table sizes+1 (power of two: 2^k) */ - const int N) /* input: data vector length */ -{ - uint32_t W_lower, W_upper; - uint32_t W_tmp; - uint32_t W_upper_LSB, W_upper_MSB; - uint32_t streamval; - const uint8_t *stream_ptr; - const uint16_t *cdf_ptr; - int size_tmp; - int k; - - W_lower = 0; //to remove warning -DH - stream_ptr = streamdata->stream + streamdata->stream_index; - W_upper = streamdata->W_upper; - if (W_upper == 0) - /* Should not be possible in normal operation */ - return -2; - - if (streamdata->stream_index == 0) /* first time decoder is called for this stream */ - { - /* read first word from bytestream */ - streamval = *stream_ptr << 24; - streamval |= *++stream_ptr << 16; - streamval |= *++stream_ptr << 8; - streamval |= *++stream_ptr; - } else { - streamval = streamdata->streamval; - } - - for (k=N; k>0; k--) - { - /* find the integer *data for which streamval lies in [W_lower+1, W_upper] */ - W_upper_LSB = W_upper & 0x0000FFFF; - W_upper_MSB = W_upper >> 16; - - /* start halfway the cdf range */ - size_tmp = *cdf_size++ >> 1; - cdf_ptr = *cdf + (size_tmp - 1); - - /* method of bisection */ - for ( ;; ) - { - W_tmp = W_upper_MSB * *cdf_ptr; - W_tmp += (W_upper_LSB * *cdf_ptr) >> 16; - size_tmp >>= 1; - if (size_tmp == 0) break; - if (streamval > W_tmp) - { - W_lower = W_tmp; - cdf_ptr += size_tmp; - } else { - W_upper = W_tmp; - cdf_ptr -= size_tmp; - } - } - if (streamval > W_tmp) - { - W_lower = W_tmp; - *data++ = (int)(cdf_ptr - *cdf++); - } else { - W_upper = W_tmp; - *data++ = (int)(cdf_ptr - *cdf++ - 1); - } - - /* shift interval to start at zero */ - W_upper -= ++W_lower; - - /* add integer to bitstream */ - streamval -= W_lower; - - /* renormalize interval and update streamval */ - while ( !(W_upper & 0xFF000000) ) /* W_upper < 2^24 */ - { - /* read next byte from stream */ - streamval = (streamval << 8) | *++stream_ptr; - W_upper <<= 8; - } - - if (W_upper == 0) - /* Should not be possible in normal operation */ - return -2; - - - } - - streamdata->stream_index = (int)(stream_ptr - streamdata->stream); - streamdata->W_upper = W_upper; - streamdata->streamval = streamval; - - - /* find number of bytes in original stream (determined by current interval width) */ - if ( W_upper > 0x01FFFFFF ) - return streamdata->stream_index - 2; - else - return streamdata->stream_index - 1; -} - - - -/* - * function to decode more symbols from the arithmetic bytestream, taking single step up or - * down at a time - * cdf tables can be of arbitrary size, but large tables may take a lot of iterations - */ -int WebRtcIsac_DecHistOneStepMulti(int *data, /* output: data vector */ - Bitstr *streamdata, /* in-/output struct containing bitstream */ - const uint16_t *const *cdf, /* input: array of cdf arrays */ - const uint16_t *init_index, /* input: vector of initial cdf table search entries */ - const int N) /* input: data vector length */ -{ - uint32_t W_lower, W_upper; - uint32_t W_tmp; - uint32_t W_upper_LSB, W_upper_MSB; - uint32_t streamval; - const uint8_t *stream_ptr; - const uint16_t *cdf_ptr; - int k; - - - stream_ptr = streamdata->stream + streamdata->stream_index; - W_upper = streamdata->W_upper; - if (W_upper == 0) - /* Should not be possible in normal operation */ - return -2; - - if (streamdata->stream_index == 0) /* first time decoder is called for this stream */ - { - /* read first word from bytestream */ - streamval = (uint32_t)(*stream_ptr) << 24; - streamval |= (uint32_t)(*++stream_ptr) << 16; - streamval |= (uint32_t)(*++stream_ptr) << 8; - streamval |= (uint32_t)(*++stream_ptr); - } else { - streamval = streamdata->streamval; - } - - - for (k=N; k>0; k--) - { - /* find the integer *data for which streamval lies in [W_lower+1, W_upper] */ - W_upper_LSB = W_upper & 0x0000FFFF; - W_upper_MSB = W_upper >> 16; - - /* start at the specified table entry */ - cdf_ptr = *cdf + (*init_index++); - W_tmp = W_upper_MSB * *cdf_ptr; - W_tmp += (W_upper_LSB * *cdf_ptr) >> 16; - if (streamval > W_tmp) - { - for ( ;; ) - { - W_lower = W_tmp; - if (cdf_ptr[0]==65535) - /* range check */ - return -3; - W_tmp = W_upper_MSB * *++cdf_ptr; - W_tmp += (W_upper_LSB * *cdf_ptr) >> 16; - if (streamval <= W_tmp) break; - } - W_upper = W_tmp; - *data++ = (int)(cdf_ptr - *cdf++ - 1); - } else { - for ( ;; ) - { - W_upper = W_tmp; - --cdf_ptr; - if (cdf_ptr<*cdf) { - /* range check */ - return -3; - } - W_tmp = W_upper_MSB * *cdf_ptr; - W_tmp += (W_upper_LSB * *cdf_ptr) >> 16; - if (streamval > W_tmp) break; - } - W_lower = W_tmp; - *data++ = (int)(cdf_ptr - *cdf++); - } - - /* shift interval to start at zero */ - W_upper -= ++W_lower; - /* add integer to bitstream */ - streamval -= W_lower; - - /* renormalize interval and update streamval */ - while ( !(W_upper & 0xFF000000) ) /* W_upper < 2^24 */ - { - /* read next byte from stream */ - streamval = (streamval << 8) | *++stream_ptr; - W_upper <<= 8; - } - } - - streamdata->stream_index = (int)(stream_ptr - streamdata->stream); - streamdata->W_upper = W_upper; - streamdata->streamval = streamval; - - - /* find number of bytes in original stream (determined by current interval width) */ - if ( W_upper > 0x01FFFFFF ) - return streamdata->stream_index - 2; - else - return streamdata->stream_index - 1; -} diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/arith_routines_logist.c b/webrtc/modules/audio_coding/codecs/isac/main/source/arith_routines_logist.c deleted file mode 100644 index 777780f..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/arith_routines_logist.c +++ /dev/null @@ -1,303 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -/* - * arith_routines.h - * - * This file contains functions for arithmatically encoding and - * decoding DFT coefficients. - * - */ - - -#include "modules/audio_coding/codecs/isac/main/source/arith_routines.h" - - - -static const int32_t kHistEdgesQ15[51] = { - -327680, -314573, -301466, -288359, -275252, -262144, -249037, -235930, -222823, -209716, - -196608, -183501, -170394, -157287, -144180, -131072, -117965, -104858, -91751, -78644, - -65536, -52429, -39322, -26215, -13108, 0, 13107, 26214, 39321, 52428, - 65536, 78643, 91750, 104857, 117964, 131072, 144179, 157286, 170393, 183500, - 196608, 209715, 222822, 235929, 249036, 262144, 275251, 288358, 301465, 314572, - 327680}; - - -static const int kCdfSlopeQ0[51] = { /* Q0 */ - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 13, 23, 47, 87, 154, 315, 700, 1088, - 2471, 6064, 14221, 21463, 36634, 36924, 19750, 13270, 5806, 2312, - 1095, 660, 316, 145, 86, 41, 32, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 2, 0}; - - -static const int kCdfQ16[51] = { /* Q16 */ - 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, - 20, 22, 24, 29, 38, 57, 92, 153, 279, 559, - 994, 1983, 4408, 10097, 18682, 33336, 48105, 56005, 61313, 63636, - 64560, 64998, 65262, 65389, 65447, 65481, 65497, 65510, 65512, 65514, - 65516, 65518, 65520, 65522, 65524, 65526, 65528, 65530, 65532, 65534, - 65535}; - - - -/* function to be converted to fixed point */ -static __inline uint32_t piecewise(int32_t xinQ15) { - - int32_t ind, qtmp1, qtmp2, qtmp3; - uint32_t tmpUW32; - - - qtmp2 = xinQ15; - - if (qtmp2 < kHistEdgesQ15[0]) { - qtmp2 = kHistEdgesQ15[0]; - } - if (qtmp2 > kHistEdgesQ15[50]) { - qtmp2 = kHistEdgesQ15[50]; - } - - qtmp1 = qtmp2 - kHistEdgesQ15[0]; /* Q15 - Q15 = Q15 */ - ind = (qtmp1 * 5) >> 16; /* 2^16 / 5 = 0.4 in Q15 */ - /* Q15 -> Q0 */ - qtmp1 = qtmp2 - kHistEdgesQ15[ind]; /* Q15 - Q15 = Q15 */ - qtmp2 = kCdfSlopeQ0[ind] * qtmp1; /* Q0 * Q15 = Q15 */ - qtmp3 = qtmp2>>15; /* Q15 -> Q0 */ - - tmpUW32 = kCdfQ16[ind] + qtmp3; /* Q0 + Q0 = Q0 */ - return tmpUW32; -} - - - -int WebRtcIsac_EncLogisticMulti2( - Bitstr *streamdata, /* in-/output struct containing bitstream */ - int16_t *dataQ7, /* input: data vector */ - const uint16_t *envQ8, /* input: side info vector defining the width of the pdf */ - const int N, /* input: data vector length / 2 */ - const int16_t isSWB12kHz) -{ - uint32_t W_lower, W_upper; - uint32_t W_upper_LSB, W_upper_MSB; - uint8_t *stream_ptr; - uint8_t *maxStreamPtr; - uint8_t *stream_ptr_carry; - uint32_t cdf_lo, cdf_hi; - int k; - - /* point to beginning of stream buffer */ - stream_ptr = streamdata->stream + streamdata->stream_index; - W_upper = streamdata->W_upper; - - maxStreamPtr = streamdata->stream + STREAM_SIZE_MAX_60 - 1; - for (k = 0; k < N; k++) - { - /* compute cdf_lower and cdf_upper by evaluating the piecewise linear cdf */ - cdf_lo = piecewise((*dataQ7 - 64) * *envQ8); - cdf_hi = piecewise((*dataQ7 + 64) * *envQ8); - - /* test and clip if probability gets too small */ - while (cdf_lo+1 >= cdf_hi) { - /* clip */ - if (*dataQ7 > 0) { - *dataQ7 -= 128; - cdf_hi = cdf_lo; - cdf_lo = piecewise((*dataQ7 - 64) * *envQ8); - } else { - *dataQ7 += 128; - cdf_lo = cdf_hi; - cdf_hi = piecewise((*dataQ7 + 64) * *envQ8); - } - } - - dataQ7++; - // increment only once per 4 iterations for SWB-16kHz or WB - // increment only once per 2 iterations for SWB-12kHz - envQ8 += (isSWB12kHz)? (k & 1):((k & 1) & (k >> 1)); - - - /* update interval */ - W_upper_LSB = W_upper & 0x0000FFFF; - W_upper_MSB = W_upper >> 16; - W_lower = W_upper_MSB * cdf_lo; - W_lower += (W_upper_LSB * cdf_lo) >> 16; - W_upper = W_upper_MSB * cdf_hi; - W_upper += (W_upper_LSB * cdf_hi) >> 16; - - /* shift interval such that it begins at zero */ - W_upper -= ++W_lower; - - /* add integer to bitstream */ - streamdata->streamval += W_lower; - - /* handle carry */ - if (streamdata->streamval < W_lower) - { - /* propagate carry */ - stream_ptr_carry = stream_ptr; - while (!(++(*--stream_ptr_carry))); - } - - /* renormalize interval, store most significant byte of streamval and update streamval */ - while ( !(W_upper & 0xFF000000) ) /* W_upper < 2^24 */ - { - W_upper <<= 8; - *stream_ptr++ = (uint8_t) (streamdata->streamval >> 24); - - if(stream_ptr > maxStreamPtr) - { - return -ISAC_DISALLOWED_BITSTREAM_LENGTH; - } - streamdata->streamval <<= 8; - } - } - - /* calculate new stream_index */ - streamdata->stream_index = (int)(stream_ptr - streamdata->stream); - streamdata->W_upper = W_upper; - - return 0; -} - - - -int WebRtcIsac_DecLogisticMulti2( - int16_t *dataQ7, /* output: data vector */ - Bitstr *streamdata, /* in-/output struct containing bitstream */ - const uint16_t *envQ8, /* input: side info vector defining the width of the pdf */ - const int16_t *ditherQ7,/* input: dither vector */ - const int N, /* input: data vector length */ - const int16_t isSWB12kHz) -{ - uint32_t W_lower, W_upper; - uint32_t W_tmp; - uint32_t W_upper_LSB, W_upper_MSB; - uint32_t streamval; - const uint8_t *stream_ptr; - uint32_t cdf_tmp; - int16_t candQ7; - int k; - - // Position just past the end of the stream. STREAM_SIZE_MAX_60 instead of - // STREAM_SIZE_MAX (which is the size of the allocated buffer) because that's - // the limit to how much data is filled in. - const uint8_t* const stream_end = streamdata->stream + STREAM_SIZE_MAX_60; - - stream_ptr = streamdata->stream + streamdata->stream_index; - W_upper = streamdata->W_upper; - if (streamdata->stream_index == 0) /* first time decoder is called for this stream */ - { - /* read first word from bytestream */ - if (stream_ptr + 3 >= stream_end) - return -1; // Would read out of bounds. Malformed input? - streamval = *stream_ptr << 24; - streamval |= *++stream_ptr << 16; - streamval |= *++stream_ptr << 8; - streamval |= *++stream_ptr; - } else { - streamval = streamdata->streamval; - } - - - for (k = 0; k < N; k++) - { - /* find the integer *data for which streamval lies in [W_lower+1, W_upper] */ - W_upper_LSB = W_upper & 0x0000FFFF; - W_upper_MSB = W_upper >> 16; - - /* find first candidate by inverting the logistic cdf */ - candQ7 = - *ditherQ7 + 64; - cdf_tmp = piecewise(candQ7 * *envQ8); - - W_tmp = W_upper_MSB * cdf_tmp; - W_tmp += (W_upper_LSB * cdf_tmp) >> 16; - if (streamval > W_tmp) - { - W_lower = W_tmp; - candQ7 += 128; - cdf_tmp = piecewise(candQ7 * *envQ8); - - W_tmp = W_upper_MSB * cdf_tmp; - W_tmp += (W_upper_LSB * cdf_tmp) >> 16; - while (streamval > W_tmp) - { - W_lower = W_tmp; - candQ7 += 128; - cdf_tmp = piecewise(candQ7 * *envQ8); - - W_tmp = W_upper_MSB * cdf_tmp; - W_tmp += (W_upper_LSB * cdf_tmp) >> 16; - - /* error check */ - if (W_lower == W_tmp) return -1; - } - W_upper = W_tmp; - - /* another sample decoded */ - *dataQ7 = candQ7 - 64; - } - else - { - W_upper = W_tmp; - candQ7 -= 128; - cdf_tmp = piecewise(candQ7 * *envQ8); - - W_tmp = W_upper_MSB * cdf_tmp; - W_tmp += (W_upper_LSB * cdf_tmp) >> 16; - while ( !(streamval > W_tmp) ) - { - W_upper = W_tmp; - candQ7 -= 128; - cdf_tmp = piecewise(candQ7 * *envQ8); - - W_tmp = W_upper_MSB * cdf_tmp; - W_tmp += (W_upper_LSB * cdf_tmp) >> 16; - - /* error check */ - if (W_upper == W_tmp) return -1; - } - W_lower = W_tmp; - - /* another sample decoded */ - *dataQ7 = candQ7 + 64; - } - ditherQ7++; - dataQ7++; - // increment only once per 4 iterations for SWB-16kHz or WB - // increment only once per 2 iterations for SWB-12kHz - envQ8 += (isSWB12kHz)? (k & 1):((k & 1) & (k >> 1)); - - /* shift interval to start at zero */ - W_upper -= ++W_lower; - - /* add integer to bitstream */ - streamval -= W_lower; - - /* renormalize interval and update streamval */ - while ( !(W_upper & 0xFF000000) ) /* W_upper < 2^24 */ - { - /* read next byte from stream */ - if (stream_ptr + 1 >= stream_end) - return -1; // Would read out of bounds. Malformed input? - streamval = (streamval << 8) | *++stream_ptr; - W_upper <<= 8; - } - } - - streamdata->stream_index = (int)(stream_ptr - streamdata->stream); - streamdata->W_upper = W_upper; - streamdata->streamval = streamval; - - /* find number of bytes in original stream (determined by current interval width) */ - if ( W_upper > 0x01FFFFFF ) - return streamdata->stream_index - 2; - else - return streamdata->stream_index - 1; -} diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/audio_decoder_isac.cc b/webrtc/modules/audio_coding/codecs/isac/main/source/audio_decoder_isac.cc deleted file mode 100644 index b671002..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/audio_decoder_isac.cc +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "modules/audio_coding/codecs/isac/main/include/audio_decoder_isac.h" - -#include "modules/audio_coding/codecs/isac/audio_decoder_isac_t_impl.h" - -namespace webrtc { - -// Explicit instantiation: -template class AudioDecoderIsacT; - -} // namespace webrtc diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/audio_encoder_isac.cc b/webrtc/modules/audio_coding/codecs/isac/main/source/audio_encoder_isac.cc deleted file mode 100644 index b7f2c0b..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/audio_encoder_isac.cc +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "modules/audio_coding/codecs/isac/main/include/audio_encoder_isac.h" - -#include "modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h" - -namespace webrtc { - -// Explicit instantiation: -template class AudioEncoderIsacT; - -} // namespace webrtc diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/bandwidth_estimator.c b/webrtc/modules/audio_coding/codecs/isac/main/source/bandwidth_estimator.c deleted file mode 100644 index 486cd95..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/bandwidth_estimator.c +++ /dev/null @@ -1,1013 +0,0 @@ -/* - * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -/* - * BwEstimator.c - * - * This file contains the code for the Bandwidth Estimator designed - * for iSAC. - * - */ - -#include -#include - -#include "modules/audio_coding/codecs/isac/main/source/bandwidth_estimator.h" -#include "modules/audio_coding/codecs/isac/main/source/settings.h" -#include "modules/audio_coding/codecs/isac/main/include/isac.h" -#include "rtc_base/checks.h" - -/* array of quantization levels for bottle neck info; Matlab code: */ -/* sprintf('%4.1ff, ', logspace(log10(5000), log10(40000), 12)) */ -static const float kQRateTableWb[12] = -{ - 10000.0f, 11115.3f, 12355.1f, 13733.1f, 15264.8f, 16967.3f, - 18859.8f, 20963.3f, 23301.4f, 25900.3f, 28789.0f, 32000.0f}; - - -static const float kQRateTableSwb[24] = -{ - 10000.0f, 11115.3f, 12355.1f, 13733.1f, 15264.8f, 16967.3f, - 18859.8f, 20963.3f, 23153.1f, 25342.9f, 27532.7f, 29722.5f, - 31912.3f, 34102.1f, 36291.9f, 38481.7f, 40671.4f, 42861.2f, - 45051.0f, 47240.8f, 49430.6f, 51620.4f, 53810.2f, 56000.0f, -}; - - - - -int32_t WebRtcIsac_InitBandwidthEstimator( - BwEstimatorstr* bwest_str, - enum IsacSamplingRate encoderSampRate, - enum IsacSamplingRate decoderSampRate) -{ - switch(encoderSampRate) - { - case kIsacWideband: - { - bwest_str->send_bw_avg = INIT_BN_EST_WB; - break; - } - case kIsacSuperWideband: - { - bwest_str->send_bw_avg = INIT_BN_EST_SWB; - break; - } - } - - switch(decoderSampRate) - { - case kIsacWideband: - { - bwest_str->prev_frame_length = INIT_FRAME_LEN_WB; - bwest_str->rec_bw_inv = 1.0f / - (INIT_BN_EST_WB + INIT_HDR_RATE_WB); - bwest_str->rec_bw = (int32_t)INIT_BN_EST_WB; - bwest_str->rec_bw_avg_Q = INIT_BN_EST_WB; - bwest_str->rec_bw_avg = INIT_BN_EST_WB + INIT_HDR_RATE_WB; - bwest_str->rec_header_rate = INIT_HDR_RATE_WB; - break; - } - case kIsacSuperWideband: - { - bwest_str->prev_frame_length = INIT_FRAME_LEN_SWB; - bwest_str->rec_bw_inv = 1.0f / - (INIT_BN_EST_SWB + INIT_HDR_RATE_SWB); - bwest_str->rec_bw = (int32_t)INIT_BN_EST_SWB; - bwest_str->rec_bw_avg_Q = INIT_BN_EST_SWB; - bwest_str->rec_bw_avg = INIT_BN_EST_SWB + INIT_HDR_RATE_SWB; - bwest_str->rec_header_rate = INIT_HDR_RATE_SWB; - break; - } - } - - bwest_str->prev_rec_rtp_number = 0; - bwest_str->prev_rec_arr_ts = 0; - bwest_str->prev_rec_send_ts = 0; - bwest_str->prev_rec_rtp_rate = 1.0f; - bwest_str->last_update_ts = 0; - bwest_str->last_reduction_ts = 0; - bwest_str->count_tot_updates_rec = -9; - bwest_str->rec_jitter = 10.0f; - bwest_str->rec_jitter_short_term = 0.0f; - bwest_str->rec_jitter_short_term_abs = 5.0f; - bwest_str->rec_max_delay = 10.0f; - bwest_str->rec_max_delay_avg_Q = 10.0f; - bwest_str->num_pkts_rec = 0; - - bwest_str->send_max_delay_avg = 10.0f; - - bwest_str->hsn_detect_rec = 0; - - bwest_str->num_consec_rec_pkts_over_30k = 0; - - bwest_str->hsn_detect_snd = 0; - - bwest_str->num_consec_snt_pkts_over_30k = 0; - - bwest_str->in_wait_period = 0; - - bwest_str->change_to_WB = 0; - - bwest_str->numConsecLatePkts = 0; - bwest_str->consecLatency = 0; - bwest_str->inWaitLatePkts = 0; - bwest_str->senderTimestamp = 0; - bwest_str->receiverTimestamp = 0; - - bwest_str->external_bw_info.in_use = 0; - - return 0; -} - -/* This function updates both bottle neck rates */ -/* Parameters: */ -/* rtp_number - value from RTP packet, from NetEq */ -/* frame length - length of signal frame in ms, from iSAC decoder */ -/* send_ts - value in RTP header giving send time in samples */ -/* arr_ts - value given by timeGetTime() time of arrival in samples of packet from NetEq */ -/* pksize - size of packet in bytes, from NetEq */ -/* Index - integer (range 0...23) indicating bottle neck & jitter as estimated by other side */ -/* returns 0 if everything went fine, -1 otherwise */ -int16_t WebRtcIsac_UpdateBandwidthEstimator( - BwEstimatorstr* bwest_str, - const uint16_t rtp_number, - const int32_t frame_length, - const uint32_t send_ts, - const uint32_t arr_ts, - const size_t pksize - /*, const uint16_t Index*/) -{ - float weight = 0.0f; - float curr_bw_inv = 0.0f; - float rec_rtp_rate; - float t_diff_proj; - float arr_ts_diff; - float send_ts_diff; - float arr_time_noise; - float arr_time_noise_abs; - - float delay_correction_factor = 1; - float late_diff = 0.0f; - int immediate_set = 0; - int num_pkts_expected; - - RTC_DCHECK(!bwest_str->external_bw_info.in_use); - - // We have to adjust the header-rate if the first packet has a - // frame-size different than the initialized value. - if ( frame_length != bwest_str->prev_frame_length ) - { - bwest_str->rec_header_rate = (float)HEADER_SIZE * 8.0f * - 1000.0f / (float)frame_length; /* bits/s */ - } - - /* UPDATE ESTIMATES ON THIS SIDE */ - /* compute far-side transmission rate */ - rec_rtp_rate = ((float)pksize * 8.0f * 1000.0f / (float)frame_length) + - bwest_str->rec_header_rate; - // rec_rtp_rate packet bits/s + header bits/s - - /* check for timer wrap-around */ - if (arr_ts < bwest_str->prev_rec_arr_ts) - { - bwest_str->prev_rec_arr_ts = arr_ts; - bwest_str->last_update_ts = arr_ts; - bwest_str->last_reduction_ts = arr_ts + 3*FS; - bwest_str->num_pkts_rec = 0; - - /* store frame length */ - bwest_str->prev_frame_length = frame_length; - - /* store far-side transmission rate */ - bwest_str->prev_rec_rtp_rate = rec_rtp_rate; - - /* store far-side RTP time stamp */ - bwest_str->prev_rec_rtp_number = rtp_number; - - return 0; - } - - bwest_str->num_pkts_rec++; - - /* check that it's not one of the first 9 packets */ - if ( bwest_str->count_tot_updates_rec > 0 ) - { - if(bwest_str->in_wait_period > 0 ) - { - bwest_str->in_wait_period--; - } - - bwest_str->inWaitLatePkts -= ((bwest_str->inWaitLatePkts > 0)? 1:0); - send_ts_diff = (float)(send_ts - bwest_str->prev_rec_send_ts); - - if (send_ts_diff <= (16 * frame_length)*2) - //doesn't allow for a dropped packet, not sure necessary to be - // that strict -DH - { - /* if not been updated for a long time, reduce the BN estimate */ - if((uint32_t)(arr_ts - bwest_str->last_update_ts) * - 1000.0f / FS > 3000) - { - //how many frames should have been received since the last - // update if too many have been dropped or there have been - // big delays won't allow this reduction may no longer need - // the send_ts_diff here - num_pkts_expected = (int)(((float)(arr_ts - - bwest_str->last_update_ts) * 1000.0f /(float) FS) / - (float)frame_length); - - if(((float)bwest_str->num_pkts_rec/(float)num_pkts_expected) > - 0.9) - { - float inv_bitrate = (float) pow( 0.99995, - (double)((uint32_t)(arr_ts - - bwest_str->last_reduction_ts)*1000.0f/FS) ); - - if ( inv_bitrate ) - { - bwest_str->rec_bw_inv /= inv_bitrate; - - //precautionary, likely never necessary - if (bwest_str->hsn_detect_snd && - bwest_str->hsn_detect_rec) - { - if (bwest_str->rec_bw_inv > 0.000066f) - { - bwest_str->rec_bw_inv = 0.000066f; - } - } - } - else - { - bwest_str->rec_bw_inv = 1.0f / - (INIT_BN_EST_WB + INIT_HDR_RATE_WB); - } - /* reset time-since-update counter */ - bwest_str->last_reduction_ts = arr_ts; - } - else - //reset here? - { - bwest_str->last_reduction_ts = arr_ts + 3*FS; - bwest_str->last_update_ts = arr_ts; - bwest_str->num_pkts_rec = 0; - } - } - } - else - { - bwest_str->last_reduction_ts = arr_ts + 3*FS; - bwest_str->last_update_ts = arr_ts; - bwest_str->num_pkts_rec = 0; - } - - - /* temporarily speed up adaptation if frame length has changed */ - if ( frame_length != bwest_str->prev_frame_length ) - { - bwest_str->count_tot_updates_rec = 10; - bwest_str->rec_header_rate = (float)HEADER_SIZE * 8.0f * - 1000.0f / (float)frame_length; /* bits/s */ - - bwest_str->rec_bw_inv = 1.0f /((float)bwest_str->rec_bw + - bwest_str->rec_header_rate); - } - - //////////////////////// - arr_ts_diff = (float)(arr_ts - bwest_str->prev_rec_arr_ts); - - if (send_ts_diff > 0 ) - { - late_diff = arr_ts_diff - send_ts_diff; - } - else - { - late_diff = arr_ts_diff - (float)(16 * frame_length); - } - - if((late_diff > 0) && !bwest_str->inWaitLatePkts) - { - bwest_str->numConsecLatePkts++; - bwest_str->consecLatency += late_diff; - } - else - { - bwest_str->numConsecLatePkts = 0; - bwest_str->consecLatency = 0; - } - if(bwest_str->numConsecLatePkts > 50) - { - float latencyMs = bwest_str->consecLatency/(FS/1000); - float averageLatencyMs = latencyMs / bwest_str->numConsecLatePkts; - delay_correction_factor = frame_length / (frame_length + averageLatencyMs); - immediate_set = 1; - bwest_str->inWaitLatePkts = (int16_t)((bwest_str->consecLatency/(FS/1000)) / 30);// + 150; - bwest_str->start_wait_period = arr_ts; - } - /////////////////////////////////////////////// - - - - /* update only if previous packet was not lost */ - if ( rtp_number == bwest_str->prev_rec_rtp_number + 1 ) - { - - - if (!(bwest_str->hsn_detect_snd && bwest_str->hsn_detect_rec)) - { - if ((arr_ts_diff > (float)(16 * frame_length))) - { - //1/2 second - if ((late_diff > 8000.0f) && !bwest_str->in_wait_period) - { - delay_correction_factor = 0.7f; - bwest_str->in_wait_period = 55; - bwest_str->start_wait_period = arr_ts; - immediate_set = 1; - } - //320 ms - else if (late_diff > 5120.0f && !bwest_str->in_wait_period) - { - delay_correction_factor = 0.8f; - immediate_set = 1; - bwest_str->in_wait_period = 44; - bwest_str->start_wait_period = arr_ts; - } - } - } - - - if ((bwest_str->prev_rec_rtp_rate > bwest_str->rec_bw_avg) && - (rec_rtp_rate > bwest_str->rec_bw_avg) && - !bwest_str->in_wait_period) - { - /* test if still in initiation period and increment counter */ - if (bwest_str->count_tot_updates_rec++ > 99) - { - /* constant weight after initiation part */ - weight = 0.01f; - } - else - { - /* weight decreases with number of updates */ - weight = 1.0f / (float) bwest_str->count_tot_updates_rec; - } - /* Bottle Neck Estimation */ - - /* limit outliers */ - /* if more than 25 ms too much */ - if (arr_ts_diff > frame_length * FS/1000 + 400.0f) - { - // in samples, why 25ms?? - arr_ts_diff = frame_length * FS/1000 + 400.0f; - } - if(arr_ts_diff < (frame_length * FS/1000) - 160.0f) - { - /* don't allow it to be less than frame rate - 10 ms */ - arr_ts_diff = (float)frame_length * FS/1000 - 160.0f; - } - - /* compute inverse receiving rate for last packet */ - curr_bw_inv = arr_ts_diff / ((float)(pksize + HEADER_SIZE) * - 8.0f * FS); // (180+35)*8*16000 = 27.5 Mbit.... - - - if(curr_bw_inv < - (1.0f / (MAX_ISAC_BW + bwest_str->rec_header_rate))) - { - // don't allow inv rate to be larger than MAX - curr_bw_inv = (1.0f / - (MAX_ISAC_BW + bwest_str->rec_header_rate)); - } - - /* update bottle neck rate estimate */ - bwest_str->rec_bw_inv = weight * curr_bw_inv + - (1.0f - weight) * bwest_str->rec_bw_inv; - - /* reset time-since-update counter */ - bwest_str->last_update_ts = arr_ts; - bwest_str->last_reduction_ts = arr_ts + 3 * FS; - bwest_str->num_pkts_rec = 0; - - /* Jitter Estimation */ - /* projected difference between arrival times */ - t_diff_proj = ((float)(pksize + HEADER_SIZE) * 8.0f * - 1000.0f) / bwest_str->rec_bw_avg; - - - // difference between projected and actual - // arrival time differences - arr_time_noise = (float)(arr_ts_diff*1000.0f/FS) - - t_diff_proj; - arr_time_noise_abs = (float) fabs( arr_time_noise ); - - /* long term averaged absolute jitter */ - bwest_str->rec_jitter = weight * arr_time_noise_abs + - (1.0f - weight) * bwest_str->rec_jitter; - if (bwest_str->rec_jitter > 10.0f) - { - bwest_str->rec_jitter = 10.0f; - } - /* short term averaged absolute jitter */ - bwest_str->rec_jitter_short_term_abs = 0.05f * - arr_time_noise_abs + 0.95f * - bwest_str->rec_jitter_short_term_abs; - - /* short term averaged jitter */ - bwest_str->rec_jitter_short_term = 0.05f * arr_time_noise + - 0.95f * bwest_str->rec_jitter_short_term; - } - } - } - else - { - // reset time-since-update counter when - // receiving the first 9 packets - bwest_str->last_update_ts = arr_ts; - bwest_str->last_reduction_ts = arr_ts + 3*FS; - bwest_str->num_pkts_rec = 0; - - bwest_str->count_tot_updates_rec++; - } - - /* limit minimum bottle neck rate */ - if (bwest_str->rec_bw_inv > 1.0f / ((float)MIN_ISAC_BW + - bwest_str->rec_header_rate)) - { - bwest_str->rec_bw_inv = 1.0f / ((float)MIN_ISAC_BW + - bwest_str->rec_header_rate); - } - - // limit maximum bitrate - if (bwest_str->rec_bw_inv < 1.0f / ((float)MAX_ISAC_BW + - bwest_str->rec_header_rate)) - { - bwest_str->rec_bw_inv = 1.0f / ((float)MAX_ISAC_BW + - bwest_str->rec_header_rate); - } - - /* store frame length */ - bwest_str->prev_frame_length = frame_length; - - /* store far-side transmission rate */ - bwest_str->prev_rec_rtp_rate = rec_rtp_rate; - - /* store far-side RTP time stamp */ - bwest_str->prev_rec_rtp_number = rtp_number; - - // Replace bwest_str->rec_max_delay by the new - // value (atomic operation) - bwest_str->rec_max_delay = 3.0f * bwest_str->rec_jitter; - - /* store send and arrival time stamp */ - bwest_str->prev_rec_arr_ts = arr_ts ; - bwest_str->prev_rec_send_ts = send_ts; - - /* Replace bwest_str->rec_bw by the new value (atomic operation) */ - bwest_str->rec_bw = (int32_t)(1.0f / bwest_str->rec_bw_inv - - bwest_str->rec_header_rate); - - if (immediate_set) - { - bwest_str->rec_bw = (int32_t) (delay_correction_factor * - (float) bwest_str->rec_bw); - - if (bwest_str->rec_bw < (int32_t) MIN_ISAC_BW) - { - bwest_str->rec_bw = (int32_t) MIN_ISAC_BW; - } - - bwest_str->rec_bw_avg = bwest_str->rec_bw + - bwest_str->rec_header_rate; - - bwest_str->rec_bw_avg_Q = (float) bwest_str->rec_bw; - - bwest_str->rec_jitter_short_term = 0.0f; - - bwest_str->rec_bw_inv = 1.0f / (bwest_str->rec_bw + - bwest_str->rec_header_rate); - - bwest_str->count_tot_updates_rec = 1; - - immediate_set = 0; - bwest_str->consecLatency = 0; - bwest_str->numConsecLatePkts = 0; - } - - return 0; -} - - -/* This function updates the send bottle neck rate */ -/* Index - integer (range 0...23) indicating bottle neck & jitter as estimated by other side */ -/* returns 0 if everything went fine, -1 otherwise */ -int16_t WebRtcIsac_UpdateUplinkBwImpl( - BwEstimatorstr* bwest_str, - int16_t index, - enum IsacSamplingRate encoderSamplingFreq) -{ - RTC_DCHECK(!bwest_str->external_bw_info.in_use); - - if((index < 0) || (index > 23)) - { - return -ISAC_RANGE_ERROR_BW_ESTIMATOR; - } - - /* UPDATE ESTIMATES FROM OTHER SIDE */ - if(encoderSamplingFreq == kIsacWideband) - { - if(index > 11) - { - index -= 12; - /* compute the jitter estimate as decoded on the other side */ - bwest_str->send_max_delay_avg = 0.9f * bwest_str->send_max_delay_avg + - 0.1f * (float)MAX_ISAC_MD; - } - else - { - /* compute the jitter estimate as decoded on the other side */ - bwest_str->send_max_delay_avg = 0.9f * bwest_str->send_max_delay_avg + - 0.1f * (float)MIN_ISAC_MD; - } - - /* compute the BN estimate as decoded on the other side */ - bwest_str->send_bw_avg = 0.9f * bwest_str->send_bw_avg + - 0.1f * kQRateTableWb[index]; - } - else - { - /* compute the BN estimate as decoded on the other side */ - bwest_str->send_bw_avg = 0.9f * bwest_str->send_bw_avg + - 0.1f * kQRateTableSwb[index]; - } - - if (bwest_str->send_bw_avg > (float) 28000 && !bwest_str->hsn_detect_snd) - { - bwest_str->num_consec_snt_pkts_over_30k++; - - if (bwest_str->num_consec_snt_pkts_over_30k >= 66) - { - //approx 2 seconds with 30ms frames - bwest_str->hsn_detect_snd = 1; - } - } - else if (!bwest_str->hsn_detect_snd) - { - bwest_str->num_consec_snt_pkts_over_30k = 0; - } - return 0; -} - -// called when there is upper-band bit-stream to update jitter -// statistics. -int16_t WebRtcIsac_UpdateUplinkJitter( - BwEstimatorstr* bwest_str, - int32_t index) -{ - RTC_DCHECK(!bwest_str->external_bw_info.in_use); - - if((index < 0) || (index > 23)) - { - return -ISAC_RANGE_ERROR_BW_ESTIMATOR; - } - - if(index > 0) - { - /* compute the jitter estimate as decoded on the other side */ - bwest_str->send_max_delay_avg = 0.9f * bwest_str->send_max_delay_avg + - 0.1f * (float)MAX_ISAC_MD; - } - else - { - /* compute the jitter estimate as decoded on the other side */ - bwest_str->send_max_delay_avg = 0.9f * bwest_str->send_max_delay_avg + - 0.1f * (float)MIN_ISAC_MD; - } - - return 0; -} - - - -// Returns the bandwidth/jitter estimation code (integer 0...23) -// to put in the sending iSAC payload -void -WebRtcIsac_GetDownlinkBwJitIndexImpl( - BwEstimatorstr* bwest_str, - int16_t* bottleneckIndex, - int16_t* jitterInfo, - enum IsacSamplingRate decoderSamplingFreq) -{ - float MaxDelay; - //uint16_t MaxDelayBit; - - float rate; - float r; - float e1, e2; - const float weight = 0.1f; - const float* ptrQuantizationTable; - int16_t addJitterInfo; - int16_t minInd; - int16_t maxInd; - int16_t midInd; - - if (bwest_str->external_bw_info.in_use) { - *bottleneckIndex = bwest_str->external_bw_info.bottleneck_idx; - *jitterInfo = bwest_str->external_bw_info.jitter_info; - return; - } - - /* Get Max Delay Bit */ - /* get unquantized max delay */ - MaxDelay = (float)WebRtcIsac_GetDownlinkMaxDelay(bwest_str); - - if ( ((1.f - weight) * bwest_str->rec_max_delay_avg_Q + weight * - MAX_ISAC_MD - MaxDelay) > (MaxDelay - (1.f-weight) * - bwest_str->rec_max_delay_avg_Q - weight * MIN_ISAC_MD) ) - { - jitterInfo[0] = 0; - /* update quantized average */ - bwest_str->rec_max_delay_avg_Q = - (1.f - weight) * bwest_str->rec_max_delay_avg_Q + weight * - (float)MIN_ISAC_MD; - } - else - { - jitterInfo[0] = 1; - /* update quantized average */ - bwest_str->rec_max_delay_avg_Q = - (1.f-weight) * bwest_str->rec_max_delay_avg_Q + weight * - (float)MAX_ISAC_MD; - } - - // Get unquantized rate. - rate = (float)WebRtcIsac_GetDownlinkBandwidth(bwest_str); - - /* Get Rate Index */ - if(decoderSamplingFreq == kIsacWideband) - { - ptrQuantizationTable = kQRateTableWb; - addJitterInfo = 1; - maxInd = 11; - } - else - { - ptrQuantizationTable = kQRateTableSwb; - addJitterInfo = 0; - maxInd = 23; - } - - minInd = 0; - while(maxInd > minInd + 1) - { - midInd = (maxInd + minInd) >> 1; - if(rate > ptrQuantizationTable[midInd]) - { - minInd = midInd; - } - else - { - maxInd = midInd; - } - } - // Chose the index which gives results an average which is closest - // to rate - r = (1 - weight) * bwest_str->rec_bw_avg_Q - rate; - e1 = weight * ptrQuantizationTable[minInd] + r; - e2 = weight * ptrQuantizationTable[maxInd] + r; - e1 = (e1 > 0)? e1:-e1; - e2 = (e2 > 0)? e2:-e2; - if(e1 < e2) - { - bottleneckIndex[0] = minInd; - } - else - { - bottleneckIndex[0] = maxInd; - } - - bwest_str->rec_bw_avg_Q = (1 - weight) * bwest_str->rec_bw_avg_Q + - weight * ptrQuantizationTable[bottleneckIndex[0]]; - bottleneckIndex[0] += jitterInfo[0] * 12 * addJitterInfo; - - bwest_str->rec_bw_avg = (1 - weight) * bwest_str->rec_bw_avg + weight * - (rate + bwest_str->rec_header_rate); -} - - - -/* get the bottle neck rate from far side to here, as estimated on this side */ -int32_t WebRtcIsac_GetDownlinkBandwidth( const BwEstimatorstr *bwest_str) -{ - int32_t rec_bw; - float jitter_sign; - float bw_adjust; - - RTC_DCHECK(!bwest_str->external_bw_info.in_use); - - /* create a value between -1.0 and 1.0 indicating "average sign" of jitter */ - jitter_sign = bwest_str->rec_jitter_short_term / - bwest_str->rec_jitter_short_term_abs; - - /* adjust bw proportionally to negative average jitter sign */ - bw_adjust = 1.0f - jitter_sign * (0.15f + 0.15f * jitter_sign * jitter_sign); - - /* adjust Rate if jitter sign is mostly constant */ - rec_bw = (int32_t)(bwest_str->rec_bw * bw_adjust); - - /* limit range of bottle neck rate */ - if (rec_bw < MIN_ISAC_BW) - { - rec_bw = MIN_ISAC_BW; - } - else if (rec_bw > MAX_ISAC_BW) - { - rec_bw = MAX_ISAC_BW; - } - return rec_bw; -} - -/* Returns the max delay (in ms) */ -int32_t -WebRtcIsac_GetDownlinkMaxDelay(const BwEstimatorstr *bwest_str) -{ - int32_t rec_max_delay; - - RTC_DCHECK(!bwest_str->external_bw_info.in_use); - - rec_max_delay = (int32_t)(bwest_str->rec_max_delay); - - /* limit range of jitter estimate */ - if (rec_max_delay < MIN_ISAC_MD) - { - rec_max_delay = MIN_ISAC_MD; - } - else if (rec_max_delay > MAX_ISAC_MD) - { - rec_max_delay = MAX_ISAC_MD; - } - return rec_max_delay; -} - -/* Clamp val to the closed interval [min,max]. */ -static int32_t clamp(int32_t val, int32_t min, int32_t max) { - RTC_DCHECK_LE(min, max); - return val < min ? min : (val > max ? max : val); -} - -int32_t WebRtcIsac_GetUplinkBandwidth(const BwEstimatorstr* bwest_str) { - return bwest_str->external_bw_info.in_use - ? bwest_str->external_bw_info.send_bw_avg - : clamp(bwest_str->send_bw_avg, MIN_ISAC_BW, MAX_ISAC_BW); -} - -int32_t WebRtcIsac_GetUplinkMaxDelay(const BwEstimatorstr* bwest_str) { - return bwest_str->external_bw_info.in_use - ? bwest_str->external_bw_info.send_max_delay_avg - : clamp(bwest_str->send_max_delay_avg, MIN_ISAC_MD, MAX_ISAC_MD); -} - -/* - * update long-term average bitrate and amount of data in buffer - * returns minimum payload size (bytes) - */ -int WebRtcIsac_GetMinBytes( - RateModel* State, - int StreamSize, /* bytes in bitstream */ - const int FrameSamples, /* samples per frame */ - const double BottleNeck, /* bottle neck rate; excl headers (bps) */ - const double DelayBuildUp, /* max delay from bottleneck buffering (ms) */ - enum ISACBandwidth bandwidth - /*,int16_t frequentLargePackets*/) -{ - double MinRate = 0.0; - int MinBytes; - double TransmissionTime; - int burstInterval = BURST_INTERVAL; - - // first 10 packets @ low rate, then INIT_BURST_LEN packets @ - // fixed rate of INIT_RATE bps - if (State->InitCounter > 0) - { - if (State->InitCounter-- <= INIT_BURST_LEN) - { - if(bandwidth == isac8kHz) - { - MinRate = INIT_RATE_WB; - } - else - { - MinRate = INIT_RATE_SWB; - } - } - else - { - MinRate = 0; - } - } - else - { - /* handle burst */ - if (State->BurstCounter) - { - if (State->StillBuffered < (1.0 - 1.0/BURST_LEN) * DelayBuildUp) - { - /* max bps derived from BottleNeck and DelayBuildUp values */ - MinRate = (1.0 + (FS/1000) * DelayBuildUp / - (double)(BURST_LEN * FrameSamples)) * BottleNeck; - } - else - { - // max bps derived from StillBuffered and DelayBuildUp - // values - MinRate = (1.0 + (FS/1000) * (DelayBuildUp - - State->StillBuffered) / (double)FrameSamples) * BottleNeck; - if (MinRate < 1.04 * BottleNeck) - { - MinRate = 1.04 * BottleNeck; - } - } - State->BurstCounter--; - } - } - - - /* convert rate from bits/second to bytes/packet */ - MinBytes = (int) (MinRate * FrameSamples / (8.0 * FS)); - - /* StreamSize will be adjusted if less than MinBytes */ - if (StreamSize < MinBytes) - { - StreamSize = MinBytes; - } - - /* keep track of when bottle neck was last exceeded by at least 1% */ - if (StreamSize * 8.0 * FS / FrameSamples > 1.01 * BottleNeck) { - if (State->PrevExceed) { - /* bottle_neck exceded twice in a row, decrease ExceedAgo */ - State->ExceedAgo -= /*BURST_INTERVAL*/ burstInterval / (BURST_LEN - 1); - if (State->ExceedAgo < 0) - State->ExceedAgo = 0; - } - else - { - State->ExceedAgo += (FrameSamples * 1000) / FS; /* ms */ - State->PrevExceed = 1; - } - } - else - { - State->PrevExceed = 0; - State->ExceedAgo += (FrameSamples * 1000) / FS; /* ms */ - } - - /* set burst flag if bottle neck not exceeded for long time */ - if ((State->ExceedAgo > burstInterval) && - (State->BurstCounter == 0)) - { - if (State->PrevExceed) - { - State->BurstCounter = BURST_LEN - 1; - } - else - { - State->BurstCounter = BURST_LEN; - } - } - - - /* Update buffer delay */ - TransmissionTime = StreamSize * 8.0 * 1000.0 / BottleNeck; /* ms */ - State->StillBuffered += TransmissionTime; - State->StillBuffered -= (FrameSamples * 1000) / FS; /* ms */ - if (State->StillBuffered < 0.0) - { - State->StillBuffered = 0.0; - } - - return MinBytes; -} - - -/* - * update long-term average bitrate and amount of data in buffer - */ -void WebRtcIsac_UpdateRateModel( - RateModel *State, - int StreamSize, /* bytes in bitstream */ - const int FrameSamples, /* samples per frame */ - const double BottleNeck) /* bottle neck rate; excl headers (bps) */ -{ - double TransmissionTime; - - /* avoid the initial "high-rate" burst */ - State->InitCounter = 0; - - /* Update buffer delay */ - TransmissionTime = StreamSize * 8.0 * 1000.0 / BottleNeck; /* ms */ - State->StillBuffered += TransmissionTime; - State->StillBuffered -= (FrameSamples * 1000) / FS; /* ms */ - if (State->StillBuffered < 0.0) - State->StillBuffered = 0.0; - -} - - -void WebRtcIsac_InitRateModel( - RateModel *State) -{ - State->PrevExceed = 0; /* boolean */ - State->ExceedAgo = 0; /* ms */ - State->BurstCounter = 0; /* packets */ - State->InitCounter = INIT_BURST_LEN + 10; /* packets */ - State->StillBuffered = 1.0; /* ms */ -} - -int WebRtcIsac_GetNewFrameLength( - double bottle_neck, - int current_framesamples) -{ - int new_framesamples; - - const int Thld_20_30 = 20000; - - //const int Thld_30_20 = 30000; - const int Thld_30_20 = 1000000; // disable 20 ms frames - - const int Thld_30_60 = 18000; - //const int Thld_30_60 = 0; // disable 60 ms frames - - const int Thld_60_30 = 27000; - - - new_framesamples = current_framesamples; - - /* find new framelength */ - switch(current_framesamples) { - case 320: - if (bottle_neck < Thld_20_30) - new_framesamples = 480; - break; - case 480: - if (bottle_neck < Thld_30_60) - new_framesamples = 960; - else if (bottle_neck > Thld_30_20) - new_framesamples = 320; - break; - case 960: - if (bottle_neck >= Thld_60_30) - new_framesamples = 480; - break; - } - - return new_framesamples; -} - -double WebRtcIsac_GetSnr( - double bottle_neck, - int framesamples) -{ - double s2nr; - - const double a_20 = -30.0; - const double b_20 = 0.8; - const double c_20 = 0.0; - - const double a_30 = -23.0; - const double b_30 = 0.48; - const double c_30 = 0.0; - - const double a_60 = -23.0; - const double b_60 = 0.53; - const double c_60 = 0.0; - - - /* find new SNR value */ - switch(framesamples) { - case 320: - s2nr = a_20 + b_20 * bottle_neck * 0.001 + c_20 * bottle_neck * - bottle_neck * 0.000001; - break; - case 480: - s2nr = a_30 + b_30 * bottle_neck * 0.001 + c_30 * bottle_neck * - bottle_neck * 0.000001; - break; - case 960: - s2nr = a_60 + b_60 * bottle_neck * 0.001 + c_60 * bottle_neck * - bottle_neck * 0.000001; - break; - default: - s2nr = 0; - } - - return s2nr; - -} diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/bandwidth_estimator.h b/webrtc/modules/audio_coding/codecs/isac/main/source/bandwidth_estimator.h deleted file mode 100644 index 221e65f..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/bandwidth_estimator.h +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -/* - * bandwidth_estimator.h - * - * This header file contains the API for the Bandwidth Estimator - * designed for iSAC. - * - */ - -#ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_BANDWIDTH_ESTIMATOR_H_ -#define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_BANDWIDTH_ESTIMATOR_H_ - -#include - -#include "modules/audio_coding/codecs/isac/main/source/settings.h" -#include "modules/audio_coding/codecs/isac/main/source/structs.h" - -#define MIN_ISAC_BW 10000 -#define MIN_ISAC_BW_LB 10000 -#define MIN_ISAC_BW_UB 25000 - -#define MAX_ISAC_BW 56000 -#define MAX_ISAC_BW_UB 32000 -#define MAX_ISAC_BW_LB 32000 - -#define MIN_ISAC_MD 5 -#define MAX_ISAC_MD 25 - -// assumed header size, in bytes; we don't know the exact number -// (header compression may be used) -#define HEADER_SIZE 35 - -// Initial Frame-Size, in ms, for Wideband & Super-Wideband Mode -#define INIT_FRAME_LEN_WB 60 -#define INIT_FRAME_LEN_SWB 30 - -// Initial Bottleneck Estimate, in bits/sec, for -// Wideband & Super-wideband mode -#define INIT_BN_EST_WB 20e3f -#define INIT_BN_EST_SWB 56e3f - -// Initial Header rate (header rate depends on frame-size), -// in bits/sec, for Wideband & Super-Wideband mode. -#define INIT_HDR_RATE_WB \ - ((float)HEADER_SIZE * 8.0f * 1000.0f / (float)INIT_FRAME_LEN_WB) -#define INIT_HDR_RATE_SWB \ - ((float)HEADER_SIZE * 8.0f * 1000.0f / (float)INIT_FRAME_LEN_SWB) - -// number of packets in a row for a high rate burst -#define BURST_LEN 3 - -// ms, max time between two full bursts -#define BURST_INTERVAL 500 - -// number of packets in a row for initial high rate burst -#define INIT_BURST_LEN 5 - -// bits/s, rate for the first BURST_LEN packets -#define INIT_RATE_WB INIT_BN_EST_WB -#define INIT_RATE_SWB INIT_BN_EST_SWB - -#if defined(__cplusplus) -extern "C" { -#endif - -/* This function initializes the struct */ -/* to be called before using the struct for anything else */ -/* returns 0 if everything went fine, -1 otherwise */ -int32_t WebRtcIsac_InitBandwidthEstimator( - BwEstimatorstr* bwest_str, - enum IsacSamplingRate encoderSampRate, - enum IsacSamplingRate decoderSampRate); - -/* This function updates the receiving estimate */ -/* Parameters: */ -/* rtp_number - value from RTP packet, from NetEq */ -/* frame length - length of signal frame in ms, from iSAC decoder */ -/* send_ts - value in RTP header giving send time in samples */ -/* arr_ts - value given by timeGetTime() time of arrival in samples of - * packet from NetEq */ -/* pksize - size of packet in bytes, from NetEq */ -/* Index - integer (range 0...23) indicating bottle neck & jitter as - * estimated by other side */ -/* returns 0 if everything went fine, -1 otherwise */ -int16_t WebRtcIsac_UpdateBandwidthEstimator(BwEstimatorstr* bwest_str, - const uint16_t rtp_number, - const int32_t frame_length, - const uint32_t send_ts, - const uint32_t arr_ts, - const size_t pksize); - -/* Update receiving estimates. Used when we only receive BWE index, no iSAC data - * packet. */ -int16_t WebRtcIsac_UpdateUplinkBwImpl( - BwEstimatorstr* bwest_str, - int16_t Index, - enum IsacSamplingRate encoderSamplingFreq); - -/* Returns the bandwidth/jitter estimation code (integer 0...23) to put in the - * sending iSAC payload */ -void WebRtcIsac_GetDownlinkBwJitIndexImpl( - BwEstimatorstr* bwest_str, - int16_t* bottleneckIndex, - int16_t* jitterInfo, - enum IsacSamplingRate decoderSamplingFreq); - -/* Returns the bandwidth estimation (in bps) */ -int32_t WebRtcIsac_GetDownlinkBandwidth(const BwEstimatorstr* bwest_str); - -/* Returns the max delay (in ms) */ -int32_t WebRtcIsac_GetDownlinkMaxDelay(const BwEstimatorstr* bwest_str); - -/* Returns the bandwidth that iSAC should send with in bps */ -int32_t WebRtcIsac_GetUplinkBandwidth(const BwEstimatorstr* bwest_str); - -/* Returns the max delay value from the other side in ms */ -int32_t WebRtcIsac_GetUplinkMaxDelay(const BwEstimatorstr* bwest_str); - -/* - * update amount of data in bottle neck buffer and burst handling - * returns minimum payload size (bytes) - */ -int WebRtcIsac_GetMinBytes( - RateModel* State, - int StreamSize, /* bytes in bitstream */ - const int FrameLen, /* ms per frame */ - const double BottleNeck, /* bottle neck rate; excl headers (bps) */ - const double DelayBuildUp, /* max delay from bottleneck buffering (ms) */ - enum ISACBandwidth bandwidth - /*,int16_t frequentLargePackets*/); - -/* - * update long-term average bitrate and amount of data in buffer - */ -void WebRtcIsac_UpdateRateModel( - RateModel* State, - int StreamSize, /* bytes in bitstream */ - const int FrameSamples, /* samples per frame */ - const double BottleNeck); /* bottle neck rate; excl headers (bps) */ - -void WebRtcIsac_InitRateModel(RateModel* State); - -/* Returns the new framelength value (input argument: bottle_neck) */ -int WebRtcIsac_GetNewFrameLength(double bottle_neck, int current_framelength); - -/* Returns the new SNR value (input argument: bottle_neck) */ -double WebRtcIsac_GetSnr(double bottle_neck, int new_framelength); - -int16_t WebRtcIsac_UpdateUplinkJitter(BwEstimatorstr* bwest_str, int32_t index); - -#if defined(__cplusplus) -} -#endif - -#endif /* MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_BANDWIDTH_ESTIMATOR_H_ \ - */ diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/codec.h b/webrtc/modules/audio_coding/codecs/isac/main/source/codec.h deleted file mode 100644 index a7c7ddc..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/codec.h +++ /dev/null @@ -1,223 +0,0 @@ -/* - * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -/* - * codec.h - * - * This header file contains the calls to the internal encoder - * and decoder functions. - * - */ - -#ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_CODEC_H_ -#define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_CODEC_H_ - -#include - -#include "modules/audio_coding/codecs/isac/main/source/structs.h" -#include "modules/third_party/fft/fft.h" - -void WebRtcIsac_ResetBitstream(Bitstr* bit_stream); - -int WebRtcIsac_EstimateBandwidth(BwEstimatorstr* bwest_str, - Bitstr* streamdata, - size_t packet_size, - uint16_t rtp_seq_number, - uint32_t send_ts, - uint32_t arr_ts, - enum IsacSamplingRate encoderSampRate, - enum IsacSamplingRate decoderSampRate); - -int WebRtcIsac_DecodeLb(const TransformTables* transform_tables, - float* signal_out, - ISACLBDecStruct* ISACdec_obj, - int16_t* current_framesamples, - int16_t isRCUPayload); - -int WebRtcIsac_DecodeRcuLb(float* signal_out, - ISACLBDecStruct* ISACdec_obj, - int16_t* current_framesamples); - -int WebRtcIsac_EncodeLb(const TransformTables* transform_tables, - float* in, - ISACLBEncStruct* ISACencLB_obj, - int16_t codingMode, - int16_t bottleneckIndex); - -int WebRtcIsac_EncodeStoredDataLb(const IsacSaveEncoderData* ISACSavedEnc_obj, - Bitstr* ISACBitStr_obj, - int BWnumber, - float scale); - -int WebRtcIsac_EncodeStoredDataUb( - const ISACUBSaveEncDataStruct* ISACSavedEnc_obj, - Bitstr* bitStream, - int32_t jitterInfo, - float scale, - enum ISACBandwidth bandwidth); - -int16_t WebRtcIsac_GetRedPayloadUb( - const ISACUBSaveEncDataStruct* ISACSavedEncObj, - Bitstr* bitStreamObj, - enum ISACBandwidth bandwidth); - -/****************************************************************************** - * WebRtcIsac_RateAllocation() - * Internal function to perform a rate-allocation for upper and lower-band, - * given a total rate. - * - * Input: - * - inRateBitPerSec : a total bit-rate in bits/sec. - * - * Output: - * - rateLBBitPerSec : a bit-rate allocated to the lower-band - * in bits/sec. - * - rateUBBitPerSec : a bit-rate allocated to the upper-band - * in bits/sec. - * - * Return value : 0 if rate allocation has been successful. - * -1 if failed to allocate rates. - */ - -int16_t WebRtcIsac_RateAllocation(int32_t inRateBitPerSec, - double* rateLBBitPerSec, - double* rateUBBitPerSec, - enum ISACBandwidth* bandwidthKHz); - -/****************************************************************************** - * WebRtcIsac_DecodeUb16() - * - * Decode the upper-band if the codec is in 0-16 kHz mode. - * - * Input/Output: - * -ISACdec_obj : pointer to the upper-band decoder object. The - * bit-stream is stored inside the decoder object. - * - * Output: - * -signal_out : decoded audio, 480 samples 30 ms. - * - * Return value : >0 number of decoded bytes. - * <0 if an error occurred. - */ -int WebRtcIsac_DecodeUb16(const TransformTables* transform_tables, - float* signal_out, - ISACUBDecStruct* ISACdec_obj, - int16_t isRCUPayload); - -/****************************************************************************** - * WebRtcIsac_DecodeUb12() - * - * Decode the upper-band if the codec is in 0-12 kHz mode. - * - * Input/Output: - * -ISACdec_obj : pointer to the upper-band decoder object. The - * bit-stream is stored inside the decoder object. - * - * Output: - * -signal_out : decoded audio, 480 samples 30 ms. - * - * Return value : >0 number of decoded bytes. - * <0 if an error occurred. - */ -int WebRtcIsac_DecodeUb12(const TransformTables* transform_tables, - float* signal_out, - ISACUBDecStruct* ISACdec_obj, - int16_t isRCUPayload); - -/****************************************************************************** - * WebRtcIsac_EncodeUb16() - * - * Encode the upper-band if the codec is in 0-16 kHz mode. - * - * Input: - * -in : upper-band audio, 160 samples (10 ms). - * - * Input/Output: - * -ISACdec_obj : pointer to the upper-band encoder object. The - * bit-stream is stored inside the encoder object. - * - * Return value : >0 number of encoded bytes. - * <0 if an error occurred. - */ -int WebRtcIsac_EncodeUb16(const TransformTables* transform_tables, - float* in, - ISACUBEncStruct* ISACenc_obj, - int32_t jitterInfo); - -/****************************************************************************** - * WebRtcIsac_EncodeUb12() - * - * Encode the upper-band if the codec is in 0-12 kHz mode. - * - * Input: - * -in : upper-band audio, 160 samples (10 ms). - * - * Input/Output: - * -ISACdec_obj : pointer to the upper-band encoder object. The - * bit-stream is stored inside the encoder object. - * - * Return value : >0 number of encoded bytes. - * <0 if an error occurred. - */ -int WebRtcIsac_EncodeUb12(const TransformTables* transform_tables, - float* in, - ISACUBEncStruct* ISACenc_obj, - int32_t jitterInfo); - -/************************** initialization functions *************************/ - -void WebRtcIsac_InitMasking(MaskFiltstr* maskdata); - -void WebRtcIsac_InitPostFilterbank(PostFiltBankstr* postfiltdata); - -/**************************** transform functions ****************************/ - -void WebRtcIsac_InitTransform(TransformTables* tables); - -void WebRtcIsac_Time2Spec(const TransformTables* tables, - double* inre1, - double* inre2, - int16_t* outre, - int16_t* outim, - FFTstr* fftstr_obj); - -void WebRtcIsac_Spec2time(const TransformTables* tables, - double* inre, - double* inim, - double* outre1, - double* outre2, - FFTstr* fftstr_obj); - -/***************************** filterbank functions **************************/ - -void WebRtcIsac_FilterAndCombineFloat(float* InLP, - float* InHP, - float* Out, - PostFiltBankstr* postfiltdata); - -/************************* normalized lattice filters ************************/ - -void WebRtcIsac_NormLatticeFilterMa(int orderCoef, - float* stateF, - float* stateG, - float* lat_in, - double* filtcoeflo, - double* lat_out); - -void WebRtcIsac_NormLatticeFilterAr(int orderCoef, - float* stateF, - float* stateG, - double* lat_in, - double* lo_filt_coef, - float* lat_out); - -void WebRtcIsac_Dir2Lat(double* a, int orderCoef, float* sth, float* cth); - -#endif /* MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_CODEC_H_ */ diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/crc.c b/webrtc/modules/audio_coding/codecs/isac/main/source/crc.c deleted file mode 100644 index 1bb0827..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/crc.c +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include - -#include "modules/audio_coding/codecs/isac/main/source/crc.h" -#include "common_audio/signal_processing/include/signal_processing_library.h" - -#define POLYNOMIAL 0x04c11db7L - - -static const uint32_t kCrcTable[256] = { - 0, 0x4c11db7, 0x9823b6e, 0xd4326d9, 0x130476dc, 0x17c56b6b, - 0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61, - 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, 0x4c11db70, 0x48d0c6c7, - 0x4593e01e, 0x4152fda9, 0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75, - 0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3, - 0x709f7b7a, 0x745e66cd, 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039, - 0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 0xbe2b5b58, 0xbaea46ef, - 0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d, - 0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49, 0xc7361b4c, 0xc3f706fb, - 0xceb42022, 0xca753d95, 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1, - 0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, 0x34867077, 0x30476dc0, - 0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072, - 0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16, 0x18aeb13, 0x54bf6a4, - 0x808d07d, 0xcc9cdca, 0x7897ab07, 0x7c56b6b0, 0x71159069, 0x75d48dde, - 0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02, 0x5e9f46bf, 0x5a5e5b08, - 0x571d7dd1, 0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba, - 0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b, 0xbb60adfc, - 0xb6238b25, 0xb2e29692, 0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6, - 0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a, 0xe0b41de7, 0xe4750050, - 0xe9362689, 0xedf73b3e, 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2, - 0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34, - 0xdc3abded, 0xd8fba05a, 0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637, - 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb, 0x4f040d56, 0x4bc510e1, - 0x46863638, 0x42472b8f, 0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53, - 0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5, - 0x3f9b762c, 0x3b5a6b9b, 0x315d626, 0x7d4cb91, 0xa97ed48, 0xe56f0ff, - 0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 0xf12f560e, 0xf5ee4bb9, - 0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b, - 0xd727bbb6, 0xd3e6a601, 0xdea580d8, 0xda649d6f, 0xc423cd6a, 0xc0e2d0dd, - 0xcda1f604, 0xc960ebb3, 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7, - 0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 0x9b3660c6, 0x9ff77d71, - 0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74, 0x857130c3, - 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640, 0x4e8ee645, 0x4a4ffbf2, - 0x470cdd2b, 0x43cdc09c, 0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8, - 0x68860bfd, 0x6c47164a, 0x61043093, 0x65c52d24, 0x119b4be9, 0x155a565e, - 0x18197087, 0x1cd86d30, 0x29f3d35, 0x65e2082, 0xb1d065b, 0xfdc1bec, - 0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d, 0x2056cd3a, - 0x2d15ebe3, 0x29d4f654, 0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0, - 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c, 0xe3a1cbc1, 0xe760d676, - 0xea23f0af, 0xeee2ed18, 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4, - 0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662, - 0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668, - 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4 -}; - - - - -/**************************************************************************** - * WebRtcIsac_GetCrc(...) - * - * This function returns a 32 bit CRC checksum of a bit stream - * - * Input: - * - bitstream : payload bitstream - * - len_bitstream_in_bytes : number of 8-bit words in the bit stream - * - * Output: - * - crc : checksum - * - * Return value : 0 - Ok - * -1 - Error - */ - -int WebRtcIsac_GetCrc(const int16_t* bitstream, - int len_bitstream_in_bytes, - uint32_t* crc) -{ - uint8_t* bitstream_ptr_uw8; - uint32_t crc_state; - int byte_cntr; - int crc_tbl_indx; - - /* Sanity Check. */ - if (bitstream == NULL) { - return -1; - } - /* cast to UWord8 pointer */ - bitstream_ptr_uw8 = (uint8_t *)bitstream; - - /* initialize */ - crc_state = 0xFFFFFFFF; - - for (byte_cntr = 0; byte_cntr < len_bitstream_in_bytes; byte_cntr++) { - crc_tbl_indx = (WEBRTC_SPL_RSHIFT_U32(crc_state, 24) ^ - bitstream_ptr_uw8[byte_cntr]) & 0xFF; - crc_state = (crc_state << 8) ^ kCrcTable[crc_tbl_indx]; - } - - *crc = ~crc_state; - return 0; -} diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/crc.h b/webrtc/modules/audio_coding/codecs/isac/main/source/crc.h deleted file mode 100644 index f031019..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/crc.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -/* - * crc.h - * - * Checksum functions - * - */ - -#ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_CRC_H_ -#define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_CRC_H_ - -#include - -/**************************************************************************** - * WebRtcIsac_GetCrc(...) - * - * This function returns a 32 bit CRC checksum of a bit stream - * - * Input: - * - encoded : payload bit stream - * - no_of_word8s : number of 8-bit words in the bit stream - * - * Output: - * - crc : checksum - * - * Return value : 0 - Ok - * -1 - Error - */ - -int WebRtcIsac_GetCrc(const int16_t* encoded, int no_of_word8s, uint32_t* crc); - -#endif /* MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_CRC_H_ */ diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/decode.c b/webrtc/modules/audio_coding/codecs/isac/main/source/decode.c deleted file mode 100644 index 6e114e4..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/decode.c +++ /dev/null @@ -1,303 +0,0 @@ -/* - * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -/* - * decode_B.c - * - * This file contains definition of funtions for decoding. - * Decoding of lower-band, including normal-decoding and RCU decoding. - * Decoding of upper-band, including 8-12 kHz, when the bandwidth is - * 0-12 kHz, and 8-16 kHz, when the bandwidth is 0-16 kHz. - * - */ - -#include -#include -#include - -#include "modules/audio_coding/codecs/isac/main/source/codec.h" -#include "modules/audio_coding/codecs/isac/main/source/entropy_coding.h" -#include "modules/audio_coding/codecs/isac/main/source/pitch_estimator.h" -#include "modules/audio_coding/codecs/isac/main/source/bandwidth_estimator.h" -#include "modules/audio_coding/codecs/isac/main/source/structs.h" -#include "modules/audio_coding/codecs/isac/main/source/settings.h" -#include "modules/audio_coding/codecs/isac/main/source/pitch_filter.h" - -/* - * function to decode the bitstream - * returns the total number of bytes in the stream - */ -int WebRtcIsac_DecodeLb(const TransformTables* transform_tables, - float* signal_out, ISACLBDecStruct* ISACdecLB_obj, - int16_t* current_framesamples, - int16_t isRCUPayload) { - int k; - int len, err; - int16_t bandwidthInd; - - float LP_dec_float[FRAMESAMPLES_HALF]; - float HP_dec_float[FRAMESAMPLES_HALF]; - - double LPw[FRAMESAMPLES_HALF]; - double HPw[FRAMESAMPLES_HALF]; - double LPw_pf[FRAMESAMPLES_HALF]; - - double lo_filt_coef[(ORDERLO + 1)*SUBFRAMES]; - double hi_filt_coef[(ORDERHI + 1)*SUBFRAMES]; - - double real_f[FRAMESAMPLES_HALF]; - double imag_f[FRAMESAMPLES_HALF]; - - double PitchLags[4]; - double PitchGains[4]; - double AvgPitchGain; - int16_t PitchGains_Q12[4]; - int16_t AvgPitchGain_Q12; - - float gain; - - int frame_nb; /* counter */ - int frame_mode; /* 0 30ms, 1 for 60ms */ - /* Processed_samples: 480 (30, 60 ms). Cannot take other values. */ - - WebRtcIsac_ResetBitstream(&(ISACdecLB_obj->bitstr_obj)); - - len = 0; - - /* Decode framelength and BW estimation - not used, - only for stream pointer*/ - err = WebRtcIsac_DecodeFrameLen(&ISACdecLB_obj->bitstr_obj, - current_framesamples); - if (err < 0) { - return err; - } - - /* Frame_mode: - * 0: indicates 30 ms frame (480 samples) - * 1: indicates 60 ms frame (960 samples) */ - frame_mode = *current_framesamples / MAX_FRAMESAMPLES; - - err = WebRtcIsac_DecodeSendBW(&ISACdecLB_obj->bitstr_obj, &bandwidthInd); - if (err < 0) { - return err; - } - - /* One loop if it's one frame (20 or 30ms), 2 loops if 2 frames - bundled together (60ms). */ - for (frame_nb = 0; frame_nb <= frame_mode; frame_nb++) { - /* Decode & de-quantize pitch parameters */ - err = WebRtcIsac_DecodePitchGain(&ISACdecLB_obj->bitstr_obj, - PitchGains_Q12); - if (err < 0) { - return err; - } - - err = WebRtcIsac_DecodePitchLag(&ISACdecLB_obj->bitstr_obj, PitchGains_Q12, - PitchLags); - if (err < 0) { - return err; - } - - AvgPitchGain_Q12 = (PitchGains_Q12[0] + PitchGains_Q12[1] + - PitchGains_Q12[2] + PitchGains_Q12[3]) >> 2; - - /* Decode & de-quantize filter coefficients. */ - err = WebRtcIsac_DecodeLpc(&ISACdecLB_obj->bitstr_obj, lo_filt_coef, - hi_filt_coef); - if (err < 0) { - return err; - } - /* Decode & de-quantize spectrum. */ - len = WebRtcIsac_DecodeSpec(&ISACdecLB_obj->bitstr_obj, AvgPitchGain_Q12, - kIsacLowerBand, real_f, imag_f); - if (len < 0) { - return len; - } - - /* Inverse transform. */ - WebRtcIsac_Spec2time(transform_tables, real_f, imag_f, LPw, HPw, - &ISACdecLB_obj->fftstr_obj); - - /* Convert PitchGains back to float for pitchfilter_post */ - for (k = 0; k < 4; k++) { - PitchGains[k] = ((float)PitchGains_Q12[k]) / 4096; - } - if (isRCUPayload) { - for (k = 0; k < 240; k++) { - LPw[k] *= RCU_TRANSCODING_SCALE_INVERSE; - HPw[k] *= RCU_TRANSCODING_SCALE_INVERSE; - } - } - - /* Inverse pitch filter. */ - WebRtcIsac_PitchfilterPost(LPw, LPw_pf, &ISACdecLB_obj->pitchfiltstr_obj, - PitchLags, PitchGains); - /* Convert AvgPitchGain back to float for computation of gain. */ - AvgPitchGain = ((float)AvgPitchGain_Q12) / 4096; - gain = 1.0f - 0.45f * (float)AvgPitchGain; - - for (k = 0; k < FRAMESAMPLES_HALF; k++) { - /* Reduce gain to compensate for pitch enhancer. */ - LPw_pf[k] *= gain; - } - - if (isRCUPayload) { - for (k = 0; k < FRAMESAMPLES_HALF; k++) { - /* Compensation for transcoding gain changes. */ - LPw_pf[k] *= RCU_TRANSCODING_SCALE; - HPw[k] *= RCU_TRANSCODING_SCALE; - } - } - /* Perceptual post-filtering (using normalized lattice filter). */ - WebRtcIsac_NormLatticeFilterAr( - ORDERLO, ISACdecLB_obj->maskfiltstr_obj.PostStateLoF, - (ISACdecLB_obj->maskfiltstr_obj).PostStateLoG, LPw_pf, lo_filt_coef, - LP_dec_float); - WebRtcIsac_NormLatticeFilterAr( - ORDERHI, ISACdecLB_obj->maskfiltstr_obj.PostStateHiF, - (ISACdecLB_obj->maskfiltstr_obj).PostStateHiG, HPw, hi_filt_coef, - HP_dec_float); - - /* Recombine the 2 bands. */ - WebRtcIsac_FilterAndCombineFloat(LP_dec_float, HP_dec_float, - signal_out + frame_nb * FRAMESAMPLES, - &ISACdecLB_obj->postfiltbankstr_obj); - } - return len; -} - - -/* - * This decode function is called when the codec is operating in 16 kHz - * bandwidth to decode the upperband, i.e. 8-16 kHz. - * - * Contrary to lower-band, the upper-band (8-16 kHz) is not split in - * frequency, but split to 12 sub-frames, i.e. twice as lower-band. - */ -int WebRtcIsac_DecodeUb16(const TransformTables* transform_tables, - float* signal_out, ISACUBDecStruct* ISACdecUB_obj, - int16_t isRCUPayload) { - int len, err; - - double halfFrameFirst[FRAMESAMPLES_HALF]; - double halfFrameSecond[FRAMESAMPLES_HALF]; - - double percepFilterParam[(UB_LPC_ORDER + 1) * (SUBFRAMES << 1) + - (UB_LPC_ORDER + 1)]; - - double real_f[FRAMESAMPLES_HALF]; - double imag_f[FRAMESAMPLES_HALF]; - const int16_t kAveragePitchGain = 0; /* No pitch-gain for upper-band. */ - len = 0; - - /* Decode & de-quantize filter coefficients. */ - memset(percepFilterParam, 0, sizeof(percepFilterParam)); - err = WebRtcIsac_DecodeInterpolLpcUb(&ISACdecUB_obj->bitstr_obj, - percepFilterParam, isac16kHz); - if (err < 0) { - return err; - } - - /* Decode & de-quantize spectrum. */ - len = WebRtcIsac_DecodeSpec(&ISACdecUB_obj->bitstr_obj, kAveragePitchGain, - kIsacUpperBand16, real_f, imag_f); - if (len < 0) { - return len; - } - if (isRCUPayload) { - int n; - for (n = 0; n < 240; n++) { - real_f[n] *= RCU_TRANSCODING_SCALE_UB_INVERSE; - imag_f[n] *= RCU_TRANSCODING_SCALE_UB_INVERSE; - } - } - /* Inverse transform. */ - WebRtcIsac_Spec2time(transform_tables, - real_f, imag_f, halfFrameFirst, halfFrameSecond, - &ISACdecUB_obj->fftstr_obj); - - /* Perceptual post-filtering (using normalized lattice filter). */ - WebRtcIsac_NormLatticeFilterAr( - UB_LPC_ORDER, ISACdecUB_obj->maskfiltstr_obj.PostStateLoF, - (ISACdecUB_obj->maskfiltstr_obj).PostStateLoG, halfFrameFirst, - &percepFilterParam[(UB_LPC_ORDER + 1)], signal_out); - - WebRtcIsac_NormLatticeFilterAr( - UB_LPC_ORDER, ISACdecUB_obj->maskfiltstr_obj.PostStateLoF, - (ISACdecUB_obj->maskfiltstr_obj).PostStateLoG, halfFrameSecond, - &percepFilterParam[(UB_LPC_ORDER + 1) * SUBFRAMES + (UB_LPC_ORDER + 1)], - &signal_out[FRAMESAMPLES_HALF]); - - return len; -} - -/* - * This decode function is called when the codec operates at 0-12 kHz - * bandwidth to decode the upperband, i.e. 8-12 kHz. - * - * At the encoder the upper-band is split into two band, 8-12 kHz & 12-16 - * kHz, and only 8-12 kHz is encoded. At the decoder, 8-12 kHz band is - * reconstructed and 12-16 kHz replaced with zeros. Then two bands - * are combined, to reconstruct the upperband 8-16 kHz. - */ -int WebRtcIsac_DecodeUb12(const TransformTables* transform_tables, - float* signal_out, ISACUBDecStruct* ISACdecUB_obj, - int16_t isRCUPayload) { - int len, err; - - float LP_dec_float[FRAMESAMPLES_HALF]; - float HP_dec_float[FRAMESAMPLES_HALF]; - - double LPw[FRAMESAMPLES_HALF]; - double HPw[FRAMESAMPLES_HALF]; - - double percepFilterParam[(UB_LPC_ORDER + 1)*SUBFRAMES]; - - double real_f[FRAMESAMPLES_HALF]; - double imag_f[FRAMESAMPLES_HALF]; - const int16_t kAveragePitchGain = 0; /* No pitch-gain for upper-band. */ - len = 0; - - /* Decode & dequantize filter coefficients. */ - err = WebRtcIsac_DecodeInterpolLpcUb(&ISACdecUB_obj->bitstr_obj, - percepFilterParam, isac12kHz); - if (err < 0) { - return err; - } - - /* Decode & de-quantize spectrum. */ - len = WebRtcIsac_DecodeSpec(&ISACdecUB_obj->bitstr_obj, kAveragePitchGain, - kIsacUpperBand12, real_f, imag_f); - if (len < 0) { - return len; - } - - if (isRCUPayload) { - int n; - for (n = 0; n < 240; n++) { - real_f[n] *= RCU_TRANSCODING_SCALE_UB_INVERSE; - imag_f[n] *= RCU_TRANSCODING_SCALE_UB_INVERSE; - } - } - /* Inverse transform. */ - WebRtcIsac_Spec2time(transform_tables, - real_f, imag_f, LPw, HPw, &ISACdecUB_obj->fftstr_obj); - /* perceptual post-filtering (using normalized lattice filter) */ - WebRtcIsac_NormLatticeFilterAr(UB_LPC_ORDER, - ISACdecUB_obj->maskfiltstr_obj.PostStateLoF, - (ISACdecUB_obj->maskfiltstr_obj).PostStateLoG, - LPw, percepFilterParam, LP_dec_float); - /* Zero for 12-16 kHz. */ - memset(HP_dec_float, 0, sizeof(float) * (FRAMESAMPLES_HALF)); - /* Recombine the 2 bands. */ - WebRtcIsac_FilterAndCombineFloat(HP_dec_float, LP_dec_float, signal_out, - &ISACdecUB_obj->postfiltbankstr_obj); - return len; -} diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/decode_bwe.c b/webrtc/modules/audio_coding/codecs/isac/main/source/decode_bwe.c deleted file mode 100644 index 89d970f..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/decode_bwe.c +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "modules/audio_coding/codecs/isac/main/source/structs.h" -#include "modules/audio_coding/codecs/isac/main/source/bandwidth_estimator.h" -#include "modules/audio_coding/codecs/isac/main/source/entropy_coding.h" -#include "modules/audio_coding/codecs/isac/main/source/codec.h" - - -int -WebRtcIsac_EstimateBandwidth( - BwEstimatorstr* bwest_str, - Bitstr* streamdata, - size_t packet_size, - uint16_t rtp_seq_number, - uint32_t send_ts, - uint32_t arr_ts, - enum IsacSamplingRate encoderSampRate, - enum IsacSamplingRate decoderSampRate) -{ - int16_t index; - int16_t frame_samples; - uint32_t sendTimestampIn16kHz; - uint32_t arrivalTimestampIn16kHz; - uint32_t diffSendTime; - uint32_t diffArrivalTime; - int err; - - /* decode framelength and BW estimation */ - err = WebRtcIsac_DecodeFrameLen(streamdata, &frame_samples); - if(err < 0) // error check - { - return err; - } - err = WebRtcIsac_DecodeSendBW(streamdata, &index); - if(err < 0) // error check - { - return err; - } - - /* UPDATE ESTIMATES FROM OTHER SIDE */ - err = WebRtcIsac_UpdateUplinkBwImpl(bwest_str, index, encoderSampRate); - if(err < 0) - { - return err; - } - - // We like BWE to work at 16 kHz sampling rate, - // therefore, we have to change the timestamps accordingly. - // translate the send timestamp if required - diffSendTime = (uint32_t)((uint32_t)send_ts - - (uint32_t)bwest_str->senderTimestamp); - bwest_str->senderTimestamp = send_ts; - - diffArrivalTime = (uint32_t)((uint32_t)arr_ts - - (uint32_t)bwest_str->receiverTimestamp); - bwest_str->receiverTimestamp = arr_ts; - - if(decoderSampRate == kIsacSuperWideband) - { - diffArrivalTime = (uint32_t)diffArrivalTime >> 1; - diffSendTime = (uint32_t)diffSendTime >> 1; - } - - // arrival timestamp in 16 kHz - arrivalTimestampIn16kHz = (uint32_t)((uint32_t) - bwest_str->prev_rec_arr_ts + (uint32_t)diffArrivalTime); - // send timestamp in 16 kHz - sendTimestampIn16kHz = (uint32_t)((uint32_t) - bwest_str->prev_rec_send_ts + (uint32_t)diffSendTime); - - err = WebRtcIsac_UpdateBandwidthEstimator(bwest_str, rtp_seq_number, - (frame_samples * 1000) / FS, sendTimestampIn16kHz, - arrivalTimestampIn16kHz, packet_size); - // error check - if(err < 0) - { - return err; - } - - return 0; -} diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/encode.c b/webrtc/modules/audio_coding/codecs/isac/main/source/encode.c deleted file mode 100644 index bf92d02..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/encode.c +++ /dev/null @@ -1,1260 +0,0 @@ -/* - * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -/* - * encode.c - * - * This file contains definition of funtions for encoding. - * Decoding of upper-band, including 8-12 kHz, when the bandwidth is - * 0-12 kHz, and 8-16 kHz, when the bandwidth is 0-16 kHz. - * - */ - -#include -#include -#include - -#include "modules/audio_coding/codecs/isac/main/source/structs.h" -#include "modules/audio_coding/codecs/isac/main/source/codec.h" -#include "modules/audio_coding/codecs/isac/main/source/pitch_estimator.h" -#include "modules/audio_coding/codecs/isac/main/source/entropy_coding.h" -#include "modules/audio_coding/codecs/isac/main/source/arith_routines.h" -#include "modules/audio_coding/codecs/isac/main/source/pitch_gain_tables.h" -#include "modules/audio_coding/codecs/isac/main/source/pitch_lag_tables.h" -#include "modules/audio_coding/codecs/isac/main/source/spectrum_ar_model_tables.h" -#include "modules/audio_coding/codecs/isac/main/source/lpc_tables.h" -#include "modules/audio_coding/codecs/isac/main/source/lpc_analysis.h" -#include "modules/audio_coding/codecs/isac/main/source/bandwidth_estimator.h" -#include "modules/audio_coding/codecs/isac/main/source/lpc_shape_swb12_tables.h" -#include "modules/audio_coding/codecs/isac/main/source/lpc_shape_swb16_tables.h" -#include "modules/audio_coding/codecs/isac/main/source/lpc_gain_swb_tables.h" -#include "modules/audio_coding/codecs/isac/main/source/isac_vad.h" -#include "modules/audio_coding/codecs/isac/main/source/pitch_filter.h" - - -#define UB_LOOKAHEAD 24 - - -/* - Rate allocation tables of lower and upper-band bottleneck for - 12kHz & 16kHz bandwidth. - - 12 kHz bandwidth - ----------------- - The overall bottleneck of the coder is between 38 kbps and 45 kbps. We have - considered 7 enteries, uniformly distributed in this interval, i.e. 38, - 39.17, 40.33, 41.5, 42.67, 43.83 and 45. For every entery, the lower-band - and the upper-band bottlenecks are specified in - 'kLowerBandBitRate12' and 'kUpperBandBitRate12' - tables, respectively. E.g. the overall rate of 41.5 kbps corresponts to a - bottleneck of 31 kbps for lower-band and 27 kbps for upper-band. Given an - overall bottleneck of the codec, we use linear interpolation to get - lower-band and upper-band bottlenecks. - - 16 kHz bandwidth - ----------------- - The overall bottleneck of the coder is between 50 kbps and 56 kbps. We have - considered 7 enteries, uniformly distributed in this interval, i.e. 50, 51.2, - 52.4, 53.6, 54.8 and 56. For every entery, the lower-band and the upper-band - bottlenecks are specified in 'kLowerBandBitRate16' and - 'kUpperBandBitRate16' tables, respectively. E.g. the overall rate - of 53.6 kbps corresponts to a bottleneck of 32 kbps for lower-band and 30 - kbps for upper-band. Given an overall bottleneck of the codec, we use linear - interpolation to get lower-band and upper-band bottlenecks. - - */ - -/* 38 39.17 40.33 41.5 42.67 43.83 45 */ -static const int16_t kLowerBandBitRate12[7] = { - 29000, 30000, 30000, 31000, 31000, 32000, 32000 }; -static const int16_t kUpperBandBitRate12[7] = { - 25000, 25000, 27000, 27000, 29000, 29000, 32000 }; - -/* 50 51.2 52.4 53.6 54.8 56 */ -static const int16_t kLowerBandBitRate16[6] = { - 31000, 31000, 32000, 32000, 32000, 32000 }; -static const int16_t kUpperBandBitRate16[6] = { - 28000, 29000, 29000, 30000, 31000, 32000 }; - -/****************************************************************************** - * WebRtcIsac_RateAllocation() - * Internal function to perform a rate-allocation for upper and lower-band, - * given a total rate. - * - * Input: - * - inRateBitPerSec : a total bottleneck in bits/sec. - * - * Output: - * - rateLBBitPerSec : a bottleneck allocated to the lower-band - * in bits/sec. - * - rateUBBitPerSec : a bottleneck allocated to the upper-band - * in bits/sec. - * - * Return value : 0 if rate allocation has been successful. - * -1 if failed to allocate rates. - */ - -int16_t WebRtcIsac_RateAllocation(int32_t inRateBitPerSec, - double* rateLBBitPerSec, - double* rateUBBitPerSec, - enum ISACBandwidth* bandwidthKHz) { - int16_t idx; - double idxD; - double idxErr; - if (inRateBitPerSec < 38000) { - /* If the given overall bottleneck is less than 38000 then - * then codec has to operate in wideband mode, i.e. 8 kHz - * bandwidth. */ - *rateLBBitPerSec = (int16_t)((inRateBitPerSec > 32000) ? - 32000 : inRateBitPerSec); - *rateUBBitPerSec = 0; - *bandwidthKHz = isac8kHz; - } else if ((inRateBitPerSec >= 38000) && (inRateBitPerSec < 50000)) { - /* At a bottleneck between 38 and 50 kbps the codec is operating - * at 12 kHz bandwidth. Using xxxBandBitRate12[] to calculates - * upper/lower bottleneck */ - - /* Find the bottlenecks by linear interpolation, - * step is (45000 - 38000)/6.0 we use the inverse of it. */ - const double stepSizeInv = 8.5714286e-4; - idxD = (inRateBitPerSec - 38000) * stepSizeInv; - idx = (idxD >= 6) ? 6 : ((int16_t)idxD); - idxErr = idxD - idx; - *rateLBBitPerSec = kLowerBandBitRate12[idx]; - *rateUBBitPerSec = kUpperBandBitRate12[idx]; - - if (idx < 6) { - *rateLBBitPerSec += (int16_t)( - idxErr * (kLowerBandBitRate12[idx + 1] - kLowerBandBitRate12[idx])); - *rateUBBitPerSec += (int16_t)( - idxErr * (kUpperBandBitRate12[idx + 1] - kUpperBandBitRate12[idx])); - } - *bandwidthKHz = isac12kHz; - } else if ((inRateBitPerSec >= 50000) && (inRateBitPerSec <= 56000)) { - /* A bottleneck between 50 and 56 kbps corresponds to bandwidth - * of 16 kHz. Using xxxBandBitRate16[] to calculates - * upper/lower bottleneck. */ - - /* Find the bottlenecks by linear interpolation - * step is (56000 - 50000)/5 we use the inverse of it. */ - const double stepSizeInv = 8.3333333e-4; - idxD = (inRateBitPerSec - 50000) * stepSizeInv; - idx = (idxD >= 5) ? 5 : ((int16_t)idxD); - idxErr = idxD - idx; - *rateLBBitPerSec = kLowerBandBitRate16[idx]; - *rateUBBitPerSec = kUpperBandBitRate16[idx]; - - if (idx < 5) { - *rateLBBitPerSec += (int16_t)(idxErr * - (kLowerBandBitRate16[idx + 1] - - kLowerBandBitRate16[idx])); - - *rateUBBitPerSec += (int16_t)(idxErr * - (kUpperBandBitRate16[idx + 1] - - kUpperBandBitRate16[idx])); - } - *bandwidthKHz = isac16kHz; - } else { - /* Out-of-range botlteneck value. */ - return -1; - } - - /* limit the values. */ - *rateLBBitPerSec = (*rateLBBitPerSec > 32000) ? 32000 : *rateLBBitPerSec; - *rateUBBitPerSec = (*rateUBBitPerSec > 32000) ? 32000 : *rateUBBitPerSec; - return 0; -} - - -void WebRtcIsac_ResetBitstream(Bitstr* bit_stream) { - bit_stream->W_upper = 0xFFFFFFFF; - bit_stream->stream_index = 0; - bit_stream->streamval = 0; -} - -int WebRtcIsac_EncodeLb(const TransformTables* transform_tables, - float* in, ISACLBEncStruct* ISACencLB_obj, - int16_t codingMode, - int16_t bottleneckIndex) { - int stream_length = 0; - int err; - int k; - int iterCntr; - - double lofilt_coef[(ORDERLO + 1)*SUBFRAMES]; - double hifilt_coef[(ORDERHI + 1)*SUBFRAMES]; - float LP[FRAMESAMPLES_HALF]; - float HP[FRAMESAMPLES_HALF]; - - double LP_lookahead[FRAMESAMPLES_HALF]; - double HP_lookahead[FRAMESAMPLES_HALF]; - double LP_lookahead_pf[FRAMESAMPLES_HALF + QLOOKAHEAD]; - double LPw[FRAMESAMPLES_HALF]; - - double HPw[FRAMESAMPLES_HALF]; - double LPw_pf[FRAMESAMPLES_HALF]; - int16_t fre[FRAMESAMPLES_HALF]; /* Q7 */ - int16_t fim[FRAMESAMPLES_HALF]; /* Q7 */ - - double PitchLags[4]; - double PitchGains[4]; - int16_t PitchGains_Q12[4]; - int16_t AvgPitchGain_Q12; - - int frame_mode; /* 0 for 30ms, 1 for 60ms */ - int status = 0; - int my_index; - transcode_obj transcodingParam; - double bytesLeftSpecCoding; - uint16_t payloadLimitBytes; - - /* Copy new frame-length and bottleneck rate only for the first 10 ms data */ - if (ISACencLB_obj->buffer_index == 0) { - /* Set the framelength for the next packet. */ - ISACencLB_obj->current_framesamples = ISACencLB_obj->new_framelength; - } - /* 'frame_mode' is 0 (30 ms) or 1 (60 ms). */ - frame_mode = ISACencLB_obj->current_framesamples / MAX_FRAMESAMPLES; - - /* buffer speech samples (by 10ms packet) until the frame-length */ - /* is reached (30 or 60 ms). */ - /*****************************************************************/ - - /* fill the buffer with 10ms input data */ - for (k = 0; k < FRAMESAMPLES_10ms; k++) { - ISACencLB_obj->data_buffer_float[k + ISACencLB_obj->buffer_index] = in[k]; - } - - /* If buffersize is not equal to current framesize then increase index - * and return. We do no encoding untill we have enough audio. */ - if (ISACencLB_obj->buffer_index + FRAMESAMPLES_10ms != FRAMESAMPLES) { - ISACencLB_obj->buffer_index += FRAMESAMPLES_10ms; - return 0; - } - /* If buffer reached the right size, reset index and continue with - * encoding the frame. */ - ISACencLB_obj->buffer_index = 0; - - /* End of buffer function. */ - /**************************/ - - /* Encoding */ - /************/ - - if (frame_mode == 0 || ISACencLB_obj->frame_nb == 0) { - /* This is to avoid Linux warnings until we change 'int' to 'Word32' - * at all places. */ - int intVar; - /* reset bitstream */ - WebRtcIsac_ResetBitstream(&(ISACencLB_obj->bitstr_obj)); - - if ((codingMode == 0) && (frame_mode == 0) && - (ISACencLB_obj->enforceFrameSize == 0)) { - ISACencLB_obj->new_framelength = WebRtcIsac_GetNewFrameLength( - ISACencLB_obj->bottleneck, ISACencLB_obj->current_framesamples); - } - - ISACencLB_obj->s2nr = WebRtcIsac_GetSnr( - ISACencLB_obj->bottleneck, ISACencLB_obj->current_framesamples); - - /* Encode frame length. */ - status = WebRtcIsac_EncodeFrameLen( - ISACencLB_obj->current_framesamples, &ISACencLB_obj->bitstr_obj); - if (status < 0) { - /* Wrong frame size. */ - return status; - } - /* Save framelength for multiple packets memory. */ - ISACencLB_obj->SaveEnc_obj.framelength = - ISACencLB_obj->current_framesamples; - - /* To be used for Redundant Coding. */ - ISACencLB_obj->lastBWIdx = bottleneckIndex; - intVar = (int)bottleneckIndex; - WebRtcIsac_EncodeReceiveBw(&intVar, &ISACencLB_obj->bitstr_obj); - } - - /* Split signal in two bands. */ - WebRtcIsac_SplitAndFilterFloat(ISACencLB_obj->data_buffer_float, LP, HP, - LP_lookahead, HP_lookahead, - &ISACencLB_obj->prefiltbankstr_obj); - - /* estimate pitch parameters and pitch-filter lookahead signal */ - WebRtcIsac_PitchAnalysis(LP_lookahead, LP_lookahead_pf, - &ISACencLB_obj->pitchanalysisstr_obj, PitchLags, - PitchGains); - - /* Encode in FIX Q12. */ - - /* Convert PitchGain to Fixed point. */ - for (k = 0; k < PITCH_SUBFRAMES; k++) { - PitchGains_Q12[k] = (int16_t)(PitchGains[k] * 4096.0); - } - - /* Set where to store data in multiple packets memory. */ - if (frame_mode == 0 || ISACencLB_obj->frame_nb == 0) { - ISACencLB_obj->SaveEnc_obj.startIdx = 0; - } else { - ISACencLB_obj->SaveEnc_obj.startIdx = 1; - } - - /* Quantize & encode pitch parameters. */ - WebRtcIsac_EncodePitchGain(PitchGains_Q12, &ISACencLB_obj->bitstr_obj, - &ISACencLB_obj->SaveEnc_obj); - WebRtcIsac_EncodePitchLag(PitchLags, PitchGains_Q12, - &ISACencLB_obj->bitstr_obj, - &ISACencLB_obj->SaveEnc_obj); - - AvgPitchGain_Q12 = (PitchGains_Q12[0] + PitchGains_Q12[1] + - PitchGains_Q12[2] + PitchGains_Q12[3]) >> 2; - - /* Find coefficients for perceptual pre-filters. */ - WebRtcIsac_GetLpcCoefLb(LP_lookahead_pf, HP_lookahead, - &ISACencLB_obj->maskfiltstr_obj, ISACencLB_obj->s2nr, - PitchGains_Q12, lofilt_coef, hifilt_coef); - - /* Code LPC model and shape - gains not quantized yet. */ - WebRtcIsac_EncodeLpcLb(lofilt_coef, hifilt_coef, &ISACencLB_obj->bitstr_obj, - &ISACencLB_obj->SaveEnc_obj); - - /* Convert PitchGains back to FLOAT for pitchfilter_pre. */ - for (k = 0; k < 4; k++) { - PitchGains[k] = ((float)PitchGains_Q12[k]) / 4096; - } - - /* Store the state of arithmetic coder before coding LPC gains. */ - transcodingParam.W_upper = ISACencLB_obj->bitstr_obj.W_upper; - transcodingParam.stream_index = ISACencLB_obj->bitstr_obj.stream_index; - transcodingParam.streamval = ISACencLB_obj->bitstr_obj.streamval; - transcodingParam.stream[0] = - ISACencLB_obj->bitstr_obj.stream[ISACencLB_obj->bitstr_obj.stream_index - - 2]; - transcodingParam.stream[1] = - ISACencLB_obj->bitstr_obj.stream[ISACencLB_obj->bitstr_obj.stream_index - - 1]; - transcodingParam.stream[2] = - ISACencLB_obj->bitstr_obj.stream[ISACencLB_obj->bitstr_obj.stream_index]; - - /* Store LPC Gains before encoding them. */ - for (k = 0; k < SUBFRAMES; k++) { - transcodingParam.loFiltGain[k] = lofilt_coef[(LPC_LOBAND_ORDER + 1) * k]; - transcodingParam.hiFiltGain[k] = hifilt_coef[(LPC_HIBAND_ORDER + 1) * k]; - } - - /* Code gains */ - WebRtcIsac_EncodeLpcGainLb(lofilt_coef, hifilt_coef, - &ISACencLB_obj->bitstr_obj, - &ISACencLB_obj->SaveEnc_obj); - - /* Get the correct value for the payload limit and calculate the - * number of bytes left for coding the spectrum. */ - if ((frame_mode == 1) && (ISACencLB_obj->frame_nb == 0)) { - /* It is a 60ms and we are in the first 30ms then the limit at - * this point should be half of the assigned value. */ - payloadLimitBytes = ISACencLB_obj->payloadLimitBytes60 >> 1; - } else if (frame_mode == 0) { - /* It is a 30ms frame */ - /* Subract 3 because termination process may add 3 bytes. */ - payloadLimitBytes = ISACencLB_obj->payloadLimitBytes30 - 3; - } else { - /* This is the second half of a 60ms frame. */ - /* Subract 3 because termination process may add 3 bytes. */ - payloadLimitBytes = ISACencLB_obj->payloadLimitBytes60 - 3; - } - bytesLeftSpecCoding = payloadLimitBytes - transcodingParam.stream_index; - - /* Perceptual pre-filtering (using normalized lattice filter). */ - /* Low-band filtering. */ - WebRtcIsac_NormLatticeFilterMa(ORDERLO, - ISACencLB_obj->maskfiltstr_obj.PreStateLoF, - ISACencLB_obj->maskfiltstr_obj.PreStateLoG, - LP, lofilt_coef, LPw); - /* High-band filtering. */ - WebRtcIsac_NormLatticeFilterMa(ORDERHI, - ISACencLB_obj->maskfiltstr_obj.PreStateHiF, - ISACencLB_obj->maskfiltstr_obj.PreStateHiG, - HP, hifilt_coef, HPw); - /* Pitch filter. */ - WebRtcIsac_PitchfilterPre(LPw, LPw_pf, &ISACencLB_obj->pitchfiltstr_obj, - PitchLags, PitchGains); - /* Transform */ - WebRtcIsac_Time2Spec(transform_tables, - LPw_pf, HPw, fre, fim, &ISACencLB_obj->fftstr_obj); - - /* Save data for multiple packets memory. */ - my_index = ISACencLB_obj->SaveEnc_obj.startIdx * FRAMESAMPLES_HALF; - memcpy(&ISACencLB_obj->SaveEnc_obj.fre[my_index], fre, sizeof(fre)); - memcpy(&ISACencLB_obj->SaveEnc_obj.fim[my_index], fim, sizeof(fim)); - - ISACencLB_obj->SaveEnc_obj.AvgPitchGain[ISACencLB_obj->SaveEnc_obj.startIdx] = - AvgPitchGain_Q12; - - /* Quantization and loss-less coding. */ - err = WebRtcIsac_EncodeSpec(fre, fim, AvgPitchGain_Q12, kIsacLowerBand, - &ISACencLB_obj->bitstr_obj); - if ((err < 0) && (err != -ISAC_DISALLOWED_BITSTREAM_LENGTH)) { - /* There has been an error but it was not too large payload - (we can cure too large payload). */ - if (frame_mode == 1 && ISACencLB_obj->frame_nb == 1) { - /* If this is the second 30ms of a 60ms frame reset - this such that in the next call encoder starts fresh. */ - ISACencLB_obj->frame_nb = 0; - } - return err; - } - iterCntr = 0; - while ((ISACencLB_obj->bitstr_obj.stream_index > payloadLimitBytes) || - (err == -ISAC_DISALLOWED_BITSTREAM_LENGTH)) { - double bytesSpecCoderUsed; - double transcodeScale; - - if (iterCntr >= MAX_PAYLOAD_LIMIT_ITERATION) { - /* We were not able to limit the payload size */ - if ((frame_mode == 1) && (ISACencLB_obj->frame_nb == 0)) { - /* This was the first 30ms of a 60ms frame. Although - the payload is larger than it should be but we let - the second 30ms be encoded. Maybe together we - won't exceed the limit. */ - ISACencLB_obj->frame_nb = 1; - return 0; - } else if ((frame_mode == 1) && (ISACencLB_obj->frame_nb == 1)) { - ISACencLB_obj->frame_nb = 0; - } - - if (err != -ISAC_DISALLOWED_BITSTREAM_LENGTH) { - return -ISAC_PAYLOAD_LARGER_THAN_LIMIT; - } else { - return status; - } - } - - if (err == -ISAC_DISALLOWED_BITSTREAM_LENGTH) { - bytesSpecCoderUsed = STREAM_SIZE_MAX; - /* Being conservative */ - transcodeScale = bytesLeftSpecCoding / bytesSpecCoderUsed * 0.5; - } else { - bytesSpecCoderUsed = ISACencLB_obj->bitstr_obj.stream_index - - transcodingParam.stream_index; - transcodeScale = bytesLeftSpecCoding / bytesSpecCoderUsed; - } - - /* To be safe, we reduce the scale depending on - the number of iterations. */ - transcodeScale *= (1.0 - (0.9 * (double)iterCntr / - (double)MAX_PAYLOAD_LIMIT_ITERATION)); - - /* Scale the LPC Gains. */ - for (k = 0; k < SUBFRAMES; k++) { - lofilt_coef[(LPC_LOBAND_ORDER + 1) * k] = - transcodingParam.loFiltGain[k] * transcodeScale; - hifilt_coef[(LPC_HIBAND_ORDER + 1) * k] = - transcodingParam.hiFiltGain[k] * transcodeScale; - transcodingParam.loFiltGain[k] = lofilt_coef[(LPC_LOBAND_ORDER + 1) * k]; - transcodingParam.hiFiltGain[k] = hifilt_coef[(LPC_HIBAND_ORDER + 1) * k]; - } - - /* Scale DFT coefficients. */ - for (k = 0; k < FRAMESAMPLES_HALF; k++) { - fre[k] = (int16_t)(fre[k] * transcodeScale); - fim[k] = (int16_t)(fim[k] * transcodeScale); - } - - /* Save data for multiple packets memory. */ - my_index = ISACencLB_obj->SaveEnc_obj.startIdx * FRAMESAMPLES_HALF; - memcpy(&ISACencLB_obj->SaveEnc_obj.fre[my_index], fre, sizeof(fre)); - memcpy(&ISACencLB_obj->SaveEnc_obj.fim[my_index], fim, sizeof(fim)); - - /* Re-store the state of arithmetic coder before coding LPC gains. */ - ISACencLB_obj->bitstr_obj.W_upper = transcodingParam.W_upper; - ISACencLB_obj->bitstr_obj.stream_index = transcodingParam.stream_index; - ISACencLB_obj->bitstr_obj.streamval = transcodingParam.streamval; - ISACencLB_obj->bitstr_obj.stream[transcodingParam.stream_index - 2] = - transcodingParam.stream[0]; - ISACencLB_obj->bitstr_obj.stream[transcodingParam.stream_index - 1] = - transcodingParam.stream[1]; - ISACencLB_obj->bitstr_obj.stream[transcodingParam.stream_index] = - transcodingParam.stream[2]; - - /* Code gains. */ - WebRtcIsac_EncodeLpcGainLb(lofilt_coef, hifilt_coef, - &ISACencLB_obj->bitstr_obj, - &ISACencLB_obj->SaveEnc_obj); - - /* Update the number of bytes left for encoding the spectrum. */ - bytesLeftSpecCoding = payloadLimitBytes - transcodingParam.stream_index; - - /* Encode the spectrum. */ - err = WebRtcIsac_EncodeSpec(fre, fim, AvgPitchGain_Q12, kIsacLowerBand, - &ISACencLB_obj->bitstr_obj); - - if ((err < 0) && (err != -ISAC_DISALLOWED_BITSTREAM_LENGTH)) { - /* There has been an error but it was not too large - payload (we can cure too large payload). */ - if (frame_mode == 1 && ISACencLB_obj->frame_nb == 1) { - /* If this is the second 30 ms of a 60 ms frame reset - this such that in the next call encoder starts fresh. */ - ISACencLB_obj->frame_nb = 0; - } - return err; - } - iterCntr++; - } - - /* If 60 ms frame-size and just processed the first 30 ms, */ - /* go back to main function to buffer the other 30 ms speech frame. */ - if (frame_mode == 1) { - if (ISACencLB_obj->frame_nb == 0) { - ISACencLB_obj->frame_nb = 1; - return 0; - } else if (ISACencLB_obj->frame_nb == 1) { - ISACencLB_obj->frame_nb = 0; - /* Also update the frame-length for next packet, - in Adaptive mode only. */ - if (codingMode == 0 && (ISACencLB_obj->enforceFrameSize == 0)) { - ISACencLB_obj->new_framelength = - WebRtcIsac_GetNewFrameLength(ISACencLB_obj->bottleneck, - ISACencLB_obj->current_framesamples); - } - } - } else { - ISACencLB_obj->frame_nb = 0; - } - - /* Complete arithmetic coding. */ - stream_length = WebRtcIsac_EncTerminate(&ISACencLB_obj->bitstr_obj); - return stream_length; -} - - - -static int LimitPayloadUb(ISACUBEncStruct* ISACencUB_obj, - uint16_t payloadLimitBytes, - double bytesLeftSpecCoding, - transcode_obj* transcodingParam, - int16_t* fre, int16_t* fim, - double* lpcGains, enum ISACBand band, int status) { - - int iterCntr = 0; - int k; - double bytesSpecCoderUsed; - double transcodeScale; - const int16_t kAveragePitchGain = 0.0; - - do { - if (iterCntr >= MAX_PAYLOAD_LIMIT_ITERATION) { - /* We were not able to limit the payload size. */ - return -ISAC_PAYLOAD_LARGER_THAN_LIMIT; - } - - if (status == -ISAC_DISALLOWED_BITSTREAM_LENGTH) { - bytesSpecCoderUsed = STREAM_SIZE_MAX; - /* Being conservative. */ - transcodeScale = bytesLeftSpecCoding / bytesSpecCoderUsed * 0.5; - } else { - bytesSpecCoderUsed = ISACencUB_obj->bitstr_obj.stream_index - - transcodingParam->stream_index; - transcodeScale = bytesLeftSpecCoding / bytesSpecCoderUsed; - } - - /* To be safe, we reduce the scale depending on the - number of iterations. */ - transcodeScale *= (1.0 - (0.9 * (double)iterCntr / - (double)MAX_PAYLOAD_LIMIT_ITERATION)); - - /* Scale the LPC Gains. */ - if (band == kIsacUpperBand16) { - /* Two sets of coefficients if 16 kHz. */ - for (k = 0; k < SUBFRAMES; k++) { - transcodingParam->loFiltGain[k] *= transcodeScale; - transcodingParam->hiFiltGain[k] *= transcodeScale; - } - } else { - /* One sets of coefficients if 12 kHz. */ - for (k = 0; k < SUBFRAMES; k++) { - transcodingParam->loFiltGain[k] *= transcodeScale; - } - } - - /* Scale DFT coefficients. */ - for (k = 0; k < FRAMESAMPLES_HALF; k++) { - fre[k] = (int16_t)(fre[k] * transcodeScale + 0.5); - fim[k] = (int16_t)(fim[k] * transcodeScale + 0.5); - } - /* Store FFT coefficients for multiple encoding. */ - memcpy(ISACencUB_obj->SaveEnc_obj.realFFT, fre, - sizeof(ISACencUB_obj->SaveEnc_obj.realFFT)); - memcpy(ISACencUB_obj->SaveEnc_obj.imagFFT, fim, - sizeof(ISACencUB_obj->SaveEnc_obj.imagFFT)); - - /* Store the state of arithmetic coder before coding LPC gains */ - ISACencUB_obj->bitstr_obj.W_upper = transcodingParam->W_upper; - ISACencUB_obj->bitstr_obj.stream_index = transcodingParam->stream_index; - ISACencUB_obj->bitstr_obj.streamval = transcodingParam->streamval; - ISACencUB_obj->bitstr_obj.stream[transcodingParam->stream_index - 2] = - transcodingParam->stream[0]; - ISACencUB_obj->bitstr_obj.stream[transcodingParam->stream_index - 1] = - transcodingParam->stream[1]; - ISACencUB_obj->bitstr_obj.stream[transcodingParam->stream_index] = - transcodingParam->stream[2]; - - /* Store the gains for multiple encoding. */ - memcpy(ISACencUB_obj->SaveEnc_obj.lpcGain, lpcGains, - SUBFRAMES * sizeof(double)); - /* Entropy Code lpc-gains, indices are stored for a later use.*/ - WebRtcIsac_EncodeLpcGainUb(transcodingParam->loFiltGain, - &ISACencUB_obj->bitstr_obj, - ISACencUB_obj->SaveEnc_obj.lpcGainIndex); - - /* If 16kHz should do one more set. */ - if (band == kIsacUpperBand16) { - /* Store the gains for multiple encoding. */ - memcpy(&ISACencUB_obj->SaveEnc_obj.lpcGain[SUBFRAMES], - &lpcGains[SUBFRAMES], SUBFRAMES * sizeof(double)); - /* Entropy Code lpc-gains, indices are stored for a later use.*/ - WebRtcIsac_EncodeLpcGainUb( - transcodingParam->hiFiltGain, &ISACencUB_obj->bitstr_obj, - &ISACencUB_obj->SaveEnc_obj.lpcGainIndex[SUBFRAMES]); - } - - /* Update the number of bytes left for encoding the spectrum. */ - bytesLeftSpecCoding = payloadLimitBytes - - ISACencUB_obj->bitstr_obj.stream_index; - - /* Save the bit-stream object at this point for FEC. */ - memcpy(&ISACencUB_obj->SaveEnc_obj.bitStreamObj, - &ISACencUB_obj->bitstr_obj, sizeof(Bitstr)); - - /* Encode the spectrum. */ - status = WebRtcIsac_EncodeSpec(fre, fim, kAveragePitchGain, - band, &ISACencUB_obj->bitstr_obj); - if ((status < 0) && (status != -ISAC_DISALLOWED_BITSTREAM_LENGTH)) { - /* There has been an error but it was not too large payload - (we can cure too large payload). */ - return status; - } - iterCntr++; - } while ((ISACencUB_obj->bitstr_obj.stream_index > payloadLimitBytes) || - (status == -ISAC_DISALLOWED_BITSTREAM_LENGTH)); - return 0; -} - -int WebRtcIsac_EncodeUb16(const TransformTables* transform_tables, - float* in, ISACUBEncStruct* ISACencUB_obj, - int32_t jitterInfo) { - int err; - int k; - - double lpcVecs[UB_LPC_ORDER * UB16_LPC_VEC_PER_FRAME]; - double percepFilterParams[(1 + UB_LPC_ORDER) * (SUBFRAMES << 1) + - (1 + UB_LPC_ORDER)]; - - double LP_lookahead[FRAMESAMPLES]; - int16_t fre[FRAMESAMPLES_HALF]; /* Q7 */ - int16_t fim[FRAMESAMPLES_HALF]; /* Q7 */ - - int status = 0; - - double varscale[2]; - double corr[SUBFRAMES << 1][UB_LPC_ORDER + 1]; - double lpcGains[SUBFRAMES << 1]; - transcode_obj transcodingParam; - uint16_t payloadLimitBytes; - double s2nr; - const int16_t kAveragePitchGain = 0.0; - int bytesLeftSpecCoding; - - /* Buffer speech samples (by 10ms packet) until the frame-length is */ - /* reached (30 ms). */ - /*********************************************************************/ - - /* fill the buffer with 10ms input data */ - memcpy(&ISACencUB_obj->data_buffer_float[ISACencUB_obj->buffer_index], in, - FRAMESAMPLES_10ms * sizeof(float)); - - /* If buffer size is not equal to current frame-size, and end of file is - * not reached yet, we don't do encoding unless we have the whole frame. */ - if (ISACencUB_obj->buffer_index + FRAMESAMPLES_10ms < FRAMESAMPLES) { - ISACencUB_obj->buffer_index += FRAMESAMPLES_10ms; - return 0; - } - - /* End of buffer function. */ - /**************************/ - - /* Encoding */ - /************/ - - /* Reset bit-stream */ - WebRtcIsac_ResetBitstream(&(ISACencUB_obj->bitstr_obj)); - - /* Encoding of bandwidth information. */ - WebRtcIsac_EncodeJitterInfo(jitterInfo, &ISACencUB_obj->bitstr_obj); - - status = WebRtcIsac_EncodeBandwidth(isac16kHz, &ISACencUB_obj->bitstr_obj); - if (status < 0) { - return status; - } - - s2nr = WebRtcIsac_GetSnr(ISACencUB_obj->bottleneck, FRAMESAMPLES); - - memcpy(lpcVecs, ISACencUB_obj->lastLPCVec, UB_LPC_ORDER * sizeof(double)); - - for (k = 0; k < FRAMESAMPLES; k++) { - LP_lookahead[k] = ISACencUB_obj->data_buffer_float[UB_LOOKAHEAD + k]; - } - - /* Find coefficients for perceptual pre-filters. */ - WebRtcIsac_GetLpcCoefUb(LP_lookahead, &ISACencUB_obj->maskfiltstr_obj, - &lpcVecs[UB_LPC_ORDER], corr, varscale, isac16kHz); - - memcpy(ISACencUB_obj->lastLPCVec, - &lpcVecs[(UB16_LPC_VEC_PER_FRAME - 1) * (UB_LPC_ORDER)], - sizeof(double) * UB_LPC_ORDER); - - /* Code LPC model and shape - gains not quantized yet. */ - WebRtcIsac_EncodeLpcUB(lpcVecs, &ISACencUB_obj->bitstr_obj, - percepFilterParams, isac16kHz, - &ISACencUB_obj->SaveEnc_obj); - - /* the first set of lpc parameters are from the last sub-frame of - * the previous frame. so we don't care about them. */ - WebRtcIsac_GetLpcGain(s2nr, &percepFilterParams[UB_LPC_ORDER + 1], - (SUBFRAMES << 1), lpcGains, corr, varscale); - - /* Store the state of arithmetic coder before coding LPC gains */ - transcodingParam.stream_index = ISACencUB_obj->bitstr_obj.stream_index; - transcodingParam.W_upper = ISACencUB_obj->bitstr_obj.W_upper; - transcodingParam.streamval = ISACencUB_obj->bitstr_obj.streamval; - transcodingParam.stream[0] = - ISACencUB_obj->bitstr_obj.stream[ISACencUB_obj->bitstr_obj.stream_index - - 2]; - transcodingParam.stream[1] = - ISACencUB_obj->bitstr_obj.stream[ISACencUB_obj->bitstr_obj.stream_index - - 1]; - transcodingParam.stream[2] = - ISACencUB_obj->bitstr_obj.stream[ISACencUB_obj->bitstr_obj.stream_index]; - - /* Store LPC Gains before encoding them. */ - for (k = 0; k < SUBFRAMES; k++) { - transcodingParam.loFiltGain[k] = lpcGains[k]; - transcodingParam.hiFiltGain[k] = lpcGains[SUBFRAMES + k]; - } - - /* Store the gains for multiple encoding. */ - memcpy(ISACencUB_obj->SaveEnc_obj.lpcGain, lpcGains, - (SUBFRAMES << 1) * sizeof(double)); - - WebRtcIsac_EncodeLpcGainUb(lpcGains, &ISACencUB_obj->bitstr_obj, - ISACencUB_obj->SaveEnc_obj.lpcGainIndex); - WebRtcIsac_EncodeLpcGainUb( - &lpcGains[SUBFRAMES], &ISACencUB_obj->bitstr_obj, - &ISACencUB_obj->SaveEnc_obj.lpcGainIndex[SUBFRAMES]); - - /* Get the correct value for the payload limit and calculate the number of - bytes left for coding the spectrum. It is a 30ms frame - Subract 3 because termination process may add 3 bytes */ - payloadLimitBytes = ISACencUB_obj->maxPayloadSizeBytes - - ISACencUB_obj->numBytesUsed - 3; - bytesLeftSpecCoding = payloadLimitBytes - - ISACencUB_obj->bitstr_obj.stream_index; - - for (k = 0; k < (SUBFRAMES << 1); k++) { - percepFilterParams[k * (UB_LPC_ORDER + 1) + (UB_LPC_ORDER + 1)] = - lpcGains[k]; - } - - /* LPC filtering (using normalized lattice filter), */ - /* first half-frame. */ - WebRtcIsac_NormLatticeFilterMa(UB_LPC_ORDER, - ISACencUB_obj->maskfiltstr_obj.PreStateLoF, - ISACencUB_obj->maskfiltstr_obj.PreStateLoG, - &ISACencUB_obj->data_buffer_float[0], - &percepFilterParams[UB_LPC_ORDER + 1], - &LP_lookahead[0]); - - /* Second half-frame filtering. */ - WebRtcIsac_NormLatticeFilterMa( - UB_LPC_ORDER, ISACencUB_obj->maskfiltstr_obj.PreStateLoF, - ISACencUB_obj->maskfiltstr_obj.PreStateLoG, - &ISACencUB_obj->data_buffer_float[FRAMESAMPLES_HALF], - &percepFilterParams[(UB_LPC_ORDER + 1) + SUBFRAMES * (UB_LPC_ORDER + 1)], - &LP_lookahead[FRAMESAMPLES_HALF]); - - WebRtcIsac_Time2Spec(transform_tables, - &LP_lookahead[0], &LP_lookahead[FRAMESAMPLES_HALF], - fre, fim, &ISACencUB_obj->fftstr_obj); - - /* Store FFT coefficients for multiple encoding. */ - memcpy(ISACencUB_obj->SaveEnc_obj.realFFT, fre, sizeof(fre)); - memcpy(ISACencUB_obj->SaveEnc_obj.imagFFT, fim, sizeof(fim)); - - /* Prepare the audio buffer for the next packet - * move the last 3 ms to the beginning of the buffer. */ - memcpy(ISACencUB_obj->data_buffer_float, - &ISACencUB_obj->data_buffer_float[FRAMESAMPLES], - LB_TOTAL_DELAY_SAMPLES * sizeof(float)); - /* start writing with 3 ms delay to compensate for the delay - * of the lower-band. */ - ISACencUB_obj->buffer_index = LB_TOTAL_DELAY_SAMPLES; - - /* Save the bit-stream object at this point for FEC. */ - memcpy(&ISACencUB_obj->SaveEnc_obj.bitStreamObj, &ISACencUB_obj->bitstr_obj, - sizeof(Bitstr)); - - /* Qantization and lossless coding */ - /* Note that there is no pitch-gain for this band so kAveragePitchGain = 0 - * is passed to the function. In fact, the function ignores the 3rd parameter - * for this band. */ - err = WebRtcIsac_EncodeSpec(fre, fim, kAveragePitchGain, kIsacUpperBand16, - &ISACencUB_obj->bitstr_obj); - if ((err < 0) && (err != -ISAC_DISALLOWED_BITSTREAM_LENGTH)) { - return err; - } - - if ((ISACencUB_obj->bitstr_obj.stream_index > payloadLimitBytes) || - (err == -ISAC_DISALLOWED_BITSTREAM_LENGTH)) { - err = LimitPayloadUb(ISACencUB_obj, payloadLimitBytes, bytesLeftSpecCoding, - &transcodingParam, fre, fim, lpcGains, - kIsacUpperBand16, err); - } - if (err < 0) { - return err; - } - /* Complete arithmetic coding. */ - return WebRtcIsac_EncTerminate(&ISACencUB_obj->bitstr_obj); -} - - -int WebRtcIsac_EncodeUb12(const TransformTables* transform_tables, - float* in, ISACUBEncStruct* ISACencUB_obj, - int32_t jitterInfo) { - int err; - int k; - - double lpcVecs[UB_LPC_ORDER * UB_LPC_VEC_PER_FRAME]; - - double percepFilterParams[(1 + UB_LPC_ORDER) * SUBFRAMES]; - float LP[FRAMESAMPLES_HALF]; - float HP[FRAMESAMPLES_HALF]; - - double LP_lookahead[FRAMESAMPLES_HALF]; - double HP_lookahead[FRAMESAMPLES_HALF]; - double LPw[FRAMESAMPLES_HALF]; - - double HPw[FRAMESAMPLES_HALF]; - int16_t fre[FRAMESAMPLES_HALF]; /* Q7 */ - int16_t fim[FRAMESAMPLES_HALF]; /* Q7 */ - - int status = 0; - - double varscale[1]; - - double corr[UB_LPC_GAIN_DIM][UB_LPC_ORDER + 1]; - double lpcGains[SUBFRAMES]; - transcode_obj transcodingParam; - uint16_t payloadLimitBytes; - double s2nr; - const int16_t kAveragePitchGain = 0.0; - double bytesLeftSpecCoding; - - /* Buffer speech samples (by 10ms packet) until the framelength is */ - /* reached (30 ms). */ - /********************************************************************/ - - /* Fill the buffer with 10ms input data. */ - memcpy(&ISACencUB_obj->data_buffer_float[ISACencUB_obj->buffer_index], in, - FRAMESAMPLES_10ms * sizeof(float)); - - /* if buffer-size is not equal to current frame-size then increase the - index and return. We do the encoding when we have enough audio. */ - if (ISACencUB_obj->buffer_index + FRAMESAMPLES_10ms < FRAMESAMPLES) { - ISACencUB_obj->buffer_index += FRAMESAMPLES_10ms; - return 0; - } - /* If buffer reached the right size, reset index and continue - with encoding the frame */ - ISACencUB_obj->buffer_index = 0; - - /* End of buffer function */ - /**************************/ - - /* Encoding */ - /************/ - - /* Reset bit-stream. */ - WebRtcIsac_ResetBitstream(&(ISACencUB_obj->bitstr_obj)); - - /* Encoding bandwidth information. */ - WebRtcIsac_EncodeJitterInfo(jitterInfo, &ISACencUB_obj->bitstr_obj); - status = WebRtcIsac_EncodeBandwidth(isac12kHz, &ISACencUB_obj->bitstr_obj); - if (status < 0) { - return status; - } - - s2nr = WebRtcIsac_GetSnr(ISACencUB_obj->bottleneck, FRAMESAMPLES); - - /* Split signal in two bands. */ - WebRtcIsac_SplitAndFilterFloat(ISACencUB_obj->data_buffer_float, HP, LP, - HP_lookahead, LP_lookahead, - &ISACencUB_obj->prefiltbankstr_obj); - - /* Find coefficients for perceptual pre-filters. */ - WebRtcIsac_GetLpcCoefUb(LP_lookahead, &ISACencUB_obj->maskfiltstr_obj, - lpcVecs, corr, varscale, isac12kHz); - - /* Code LPC model and shape - gains not quantized yet. */ - WebRtcIsac_EncodeLpcUB(lpcVecs, &ISACencUB_obj->bitstr_obj, - percepFilterParams, isac12kHz, - &ISACencUB_obj->SaveEnc_obj); - - WebRtcIsac_GetLpcGain(s2nr, percepFilterParams, SUBFRAMES, lpcGains, corr, - varscale); - - /* Store the state of arithmetic coder before coding LPC gains. */ - transcodingParam.W_upper = ISACencUB_obj->bitstr_obj.W_upper; - transcodingParam.stream_index = ISACencUB_obj->bitstr_obj.stream_index; - transcodingParam.streamval = ISACencUB_obj->bitstr_obj.streamval; - transcodingParam.stream[0] = - ISACencUB_obj->bitstr_obj.stream[ISACencUB_obj->bitstr_obj.stream_index - - 2]; - transcodingParam.stream[1] = - ISACencUB_obj->bitstr_obj.stream[ISACencUB_obj->bitstr_obj.stream_index - - 1]; - transcodingParam.stream[2] = - ISACencUB_obj->bitstr_obj.stream[ISACencUB_obj->bitstr_obj.stream_index]; - - /* Store LPC Gains before encoding them. */ - for (k = 0; k < SUBFRAMES; k++) { - transcodingParam.loFiltGain[k] = lpcGains[k]; - } - - /* Store the gains for multiple encoding. */ - memcpy(ISACencUB_obj->SaveEnc_obj.lpcGain, lpcGains, SUBFRAMES * - sizeof(double)); - - WebRtcIsac_EncodeLpcGainUb(lpcGains, &ISACencUB_obj->bitstr_obj, - ISACencUB_obj->SaveEnc_obj.lpcGainIndex); - - for (k = 0; k < SUBFRAMES; k++) { - percepFilterParams[k * (UB_LPC_ORDER + 1)] = lpcGains[k]; - } - - /* perceptual pre-filtering (using normalized lattice filter) */ - /* low-band filtering */ - WebRtcIsac_NormLatticeFilterMa(UB_LPC_ORDER, - ISACencUB_obj->maskfiltstr_obj.PreStateLoF, - ISACencUB_obj->maskfiltstr_obj.PreStateLoG, LP, - percepFilterParams, LPw); - - /* Get the correct value for the payload limit and calculate the number - of bytes left for coding the spectrum. It is a 30ms frame Subract 3 - because termination process may add 3 bytes */ - payloadLimitBytes = ISACencUB_obj->maxPayloadSizeBytes - - ISACencUB_obj->numBytesUsed - 3; - bytesLeftSpecCoding = payloadLimitBytes - - ISACencUB_obj->bitstr_obj.stream_index; - - memset(HPw, 0, sizeof(HPw)); - - /* Transform */ - WebRtcIsac_Time2Spec(transform_tables, - LPw, HPw, fre, fim, &ISACencUB_obj->fftstr_obj); - - /* Store FFT coefficients for multiple encoding. */ - memcpy(ISACencUB_obj->SaveEnc_obj.realFFT, fre, - sizeof(ISACencUB_obj->SaveEnc_obj.realFFT)); - memcpy(ISACencUB_obj->SaveEnc_obj.imagFFT, fim, - sizeof(ISACencUB_obj->SaveEnc_obj.imagFFT)); - - /* Save the bit-stream object at this point for FEC. */ - memcpy(&ISACencUB_obj->SaveEnc_obj.bitStreamObj, - &ISACencUB_obj->bitstr_obj, sizeof(Bitstr)); - - /* Quantization and loss-less coding */ - /* The 4th parameter to this function is pitch-gain, which is only used - * when encoding 0-8 kHz band, and irrelevant in this function, therefore, - * we insert zero here. */ - err = WebRtcIsac_EncodeSpec(fre, fim, kAveragePitchGain, kIsacUpperBand12, - &ISACencUB_obj->bitstr_obj); - if ((err < 0) && (err != -ISAC_DISALLOWED_BITSTREAM_LENGTH)) { - /* There has been an error but it was not too large - payload (we can cure too large payload) */ - return err; - } - - if ((ISACencUB_obj->bitstr_obj.stream_index > payloadLimitBytes) || - (err == -ISAC_DISALLOWED_BITSTREAM_LENGTH)) { - err = LimitPayloadUb(ISACencUB_obj, payloadLimitBytes, bytesLeftSpecCoding, - &transcodingParam, fre, fim, lpcGains, - kIsacUpperBand12, err); - } - if (err < 0) { - return err; - } - /* Complete arithmetic coding. */ - return WebRtcIsac_EncTerminate(&ISACencUB_obj->bitstr_obj); -} - - - - - - -/* This function is used to create a new bit-stream with new BWE. - The same data as previously encoded with the function WebRtcIsac_Encoder(). - The data needed is taken from the structure, where it was stored - when calling the encoder. */ - -int WebRtcIsac_EncodeStoredDataLb(const IsacSaveEncoderData* ISACSavedEnc_obj, - Bitstr* ISACBitStr_obj, int BWnumber, - float scale) { - int ii; - int status; - int BWno = BWnumber; - - const uint16_t* WebRtcIsac_kQPitchGainCdf_ptr[1]; - const uint16_t** cdf; - - double tmpLPCcoeffs_lo[(ORDERLO + 1)*SUBFRAMES * 2]; - double tmpLPCcoeffs_hi[(ORDERHI + 1)*SUBFRAMES * 2]; - int tmpLPCindex_g[12 * 2]; - int16_t tmp_fre[FRAMESAMPLES], tmp_fim[FRAMESAMPLES]; - const int kModel = 0; - - /* Sanity Check - possible values for BWnumber is 0 - 23. */ - if ((BWnumber < 0) || (BWnumber > 23)) { - return -ISAC_RANGE_ERROR_BW_ESTIMATOR; - } - - /* Reset bit-stream. */ - WebRtcIsac_ResetBitstream(ISACBitStr_obj); - - /* Encode frame length */ - status = WebRtcIsac_EncodeFrameLen(ISACSavedEnc_obj->framelength, - ISACBitStr_obj); - if (status < 0) { - /* Wrong frame size. */ - return status; - } - - /* Transcoding */ - if ((scale > 0.0) && (scale < 1.0)) { - /* Compensate LPC gain. */ - for (ii = 0; - ii < ((ORDERLO + 1)* SUBFRAMES * (1 + ISACSavedEnc_obj->startIdx)); - ii++) { - tmpLPCcoeffs_lo[ii] = scale * ISACSavedEnc_obj->LPCcoeffs_lo[ii]; - } - for (ii = 0; - ii < ((ORDERHI + 1) * SUBFRAMES * (1 + ISACSavedEnc_obj->startIdx)); - ii++) { - tmpLPCcoeffs_hi[ii] = scale * ISACSavedEnc_obj->LPCcoeffs_hi[ii]; - } - /* Scale DFT. */ - for (ii = 0; - ii < (FRAMESAMPLES_HALF * (1 + ISACSavedEnc_obj->startIdx)); - ii++) { - tmp_fre[ii] = (int16_t)((scale) * (float)ISACSavedEnc_obj->fre[ii]); - tmp_fim[ii] = (int16_t)((scale) * (float)ISACSavedEnc_obj->fim[ii]); - } - } else { - for (ii = 0; - ii < (KLT_ORDER_GAIN * (1 + ISACSavedEnc_obj->startIdx)); - ii++) { - tmpLPCindex_g[ii] = ISACSavedEnc_obj->LPCindex_g[ii]; - } - for (ii = 0; - ii < (FRAMESAMPLES_HALF * (1 + ISACSavedEnc_obj->startIdx)); - ii++) { - tmp_fre[ii] = ISACSavedEnc_obj->fre[ii]; - tmp_fim[ii] = ISACSavedEnc_obj->fim[ii]; - } - } - - /* Encode bandwidth estimate. */ - WebRtcIsac_EncodeReceiveBw(&BWno, ISACBitStr_obj); - - /* Loop over number of 30 msec */ - for (ii = 0; ii <= ISACSavedEnc_obj->startIdx; ii++) { - /* Encode pitch gains. */ - *WebRtcIsac_kQPitchGainCdf_ptr = WebRtcIsac_kQPitchGainCdf; - WebRtcIsac_EncHistMulti(ISACBitStr_obj, - &ISACSavedEnc_obj->pitchGain_index[ii], - WebRtcIsac_kQPitchGainCdf_ptr, 1); - - /* Entropy coding of quantization pitch lags */ - /* Voicing classification. */ - if (ISACSavedEnc_obj->meanGain[ii] < 0.2) { - cdf = WebRtcIsac_kQPitchLagCdfPtrLo; - } else if (ISACSavedEnc_obj->meanGain[ii] < 0.4) { - cdf = WebRtcIsac_kQPitchLagCdfPtrMid; - } else { - cdf = WebRtcIsac_kQPitchLagCdfPtrHi; - } - WebRtcIsac_EncHistMulti(ISACBitStr_obj, - &ISACSavedEnc_obj->pitchIndex[PITCH_SUBFRAMES * ii], - cdf, PITCH_SUBFRAMES); - - /* LPC */ - /* Only one model exists. The entropy coding is done only for backward - * compatibility. */ - WebRtcIsac_EncHistMulti(ISACBitStr_obj, &kModel, - WebRtcIsac_kQKltModelCdfPtr, 1); - /* Entropy coding of quantization indices - LPC shape only. */ - WebRtcIsac_EncHistMulti(ISACBitStr_obj, - &ISACSavedEnc_obj->LPCindex_s[KLT_ORDER_SHAPE * ii], - WebRtcIsac_kQKltCdfPtrShape, - KLT_ORDER_SHAPE); - - /* If transcoding, get new LPC gain indices */ - if (scale < 1.0) { - WebRtcIsac_TranscodeLPCCoef( - &tmpLPCcoeffs_lo[(ORDERLO + 1) * SUBFRAMES * ii], - &tmpLPCcoeffs_hi[(ORDERHI + 1)*SUBFRAMES * ii], - &tmpLPCindex_g[KLT_ORDER_GAIN * ii]); - } - - /* Entropy coding of quantization indices - LPC gain. */ - WebRtcIsac_EncHistMulti(ISACBitStr_obj, &tmpLPCindex_g[KLT_ORDER_GAIN * ii], - WebRtcIsac_kQKltCdfPtrGain, KLT_ORDER_GAIN); - - /* Quantization and loss-less coding. */ - status = WebRtcIsac_EncodeSpec(&tmp_fre[ii * FRAMESAMPLES_HALF], - &tmp_fim[ii * FRAMESAMPLES_HALF], - ISACSavedEnc_obj->AvgPitchGain[ii], - kIsacLowerBand, ISACBitStr_obj); - if (status < 0) { - return status; - } - } - /* Complete arithmetic coding. */ - return WebRtcIsac_EncTerminate(ISACBitStr_obj); -} - - -int WebRtcIsac_EncodeStoredDataUb( - const ISACUBSaveEncDataStruct* ISACSavedEnc_obj, - Bitstr* bitStream, - int32_t jitterInfo, - float scale, - enum ISACBandwidth bandwidth) { - int n; - int err; - double lpcGain[SUBFRAMES]; - int16_t realFFT[FRAMESAMPLES_HALF]; - int16_t imagFFT[FRAMESAMPLES_HALF]; - const uint16_t** shape_cdf; - int shape_len; - const int16_t kAveragePitchGain = 0.0; - enum ISACBand band; - /* Reset bitstream. */ - WebRtcIsac_ResetBitstream(bitStream); - - /* Encode jitter index. */ - WebRtcIsac_EncodeJitterInfo(jitterInfo, bitStream); - - err = WebRtcIsac_EncodeBandwidth(bandwidth, bitStream); - if (err < 0) { - return err; - } - - /* Encode LPC-shape. */ - if (bandwidth == isac12kHz) { - shape_cdf = WebRtcIsac_kLpcShapeCdfMatUb12; - shape_len = UB_LPC_ORDER * UB_LPC_VEC_PER_FRAME; - band = kIsacUpperBand12; - } else { - shape_cdf = WebRtcIsac_kLpcShapeCdfMatUb16; - shape_len = UB_LPC_ORDER * UB16_LPC_VEC_PER_FRAME; - band = kIsacUpperBand16; - } - WebRtcIsac_EncHistMulti(bitStream, ISACSavedEnc_obj->indexLPCShape, - shape_cdf, shape_len); - - if ((scale <= 0.0) || (scale >= 1.0)) { - /* We only consider scales between zero and one. */ - WebRtcIsac_EncHistMulti(bitStream, ISACSavedEnc_obj->lpcGainIndex, - WebRtcIsac_kLpcGainCdfMat, UB_LPC_GAIN_DIM); - if (bandwidth == isac16kHz) { - /* Store gain indices of the second half. */ - WebRtcIsac_EncHistMulti(bitStream, - &ISACSavedEnc_obj->lpcGainIndex[SUBFRAMES], - WebRtcIsac_kLpcGainCdfMat, UB_LPC_GAIN_DIM); - } - /* Store FFT coefficients. */ - err = WebRtcIsac_EncodeSpec(ISACSavedEnc_obj->realFFT, - ISACSavedEnc_obj->imagFFT, kAveragePitchGain, - band, bitStream); - } else { - /* Scale LPC gain and FFT coefficients. */ - for (n = 0; n < SUBFRAMES; n++) { - lpcGain[n] = scale * ISACSavedEnc_obj->lpcGain[n]; - } - /* Store LPC gains. */ - WebRtcIsac_StoreLpcGainUb(lpcGain, bitStream); - - if (bandwidth == isac16kHz) { - /* Scale and code the gains of the second half of the frame, if 16kHz. */ - for (n = 0; n < SUBFRAMES; n++) { - lpcGain[n] = scale * ISACSavedEnc_obj->lpcGain[n + SUBFRAMES]; - } - WebRtcIsac_StoreLpcGainUb(lpcGain, bitStream); - } - - for (n = 0; n < FRAMESAMPLES_HALF; n++) { - realFFT[n] = (int16_t)(scale * (float)ISACSavedEnc_obj->realFFT[n] + - 0.5f); - imagFFT[n] = (int16_t)(scale * (float)ISACSavedEnc_obj->imagFFT[n] + - 0.5f); - } - /* Store FFT coefficients. */ - err = WebRtcIsac_EncodeSpec(realFFT, imagFFT, kAveragePitchGain, - band, bitStream); - } - if (err < 0) { - /* Error happened while encoding FFT coefficients. */ - return err; - } - - /* Complete arithmetic coding. */ - return WebRtcIsac_EncTerminate(bitStream); -} - -int16_t WebRtcIsac_GetRedPayloadUb( - const ISACUBSaveEncDataStruct* ISACSavedEncObj, - Bitstr* bitStreamObj, - enum ISACBandwidth bandwidth) { - int n; - int16_t status; - int16_t realFFT[FRAMESAMPLES_HALF]; - int16_t imagFFT[FRAMESAMPLES_HALF]; - enum ISACBand band; - const int16_t kAveragePitchGain = 0.0; - /* Store bit-stream object. */ - memcpy(bitStreamObj, &ISACSavedEncObj->bitStreamObj, sizeof(Bitstr)); - - /* Scale FFT coefficients. */ - for (n = 0; n < FRAMESAMPLES_HALF; n++) { - realFFT[n] = (int16_t)((float)ISACSavedEncObj->realFFT[n] * - RCU_TRANSCODING_SCALE_UB + 0.5); - imagFFT[n] = (int16_t)((float)ISACSavedEncObj->imagFFT[n] * - RCU_TRANSCODING_SCALE_UB + 0.5); - } - - band = (bandwidth == isac12kHz) ? kIsacUpperBand12 : kIsacUpperBand16; - status = WebRtcIsac_EncodeSpec(realFFT, imagFFT, kAveragePitchGain, band, - bitStreamObj); - if (status < 0) { - return status; - } else { - /* Terminate entropy coding */ - return WebRtcIsac_EncTerminate(bitStreamObj); - } -} diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/encode_lpc_swb.c b/webrtc/modules/audio_coding/codecs/isac/main/source/encode_lpc_swb.c deleted file mode 100644 index 7b02e64..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/encode_lpc_swb.c +++ /dev/null @@ -1,706 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -/* - * code_LPC_UB.c - * - * This file contains definition of functions used to - * encode LPC parameters (Shape & gain) of the upper band. - * - */ - -#include -#include -#include - -#include "modules/audio_coding/codecs/isac/main/source/encode_lpc_swb.h" -#include "modules/audio_coding/codecs/isac/main/source/lpc_gain_swb_tables.h" -#include "modules/audio_coding/codecs/isac/main/source/lpc_shape_swb12_tables.h" -#include "modules/audio_coding/codecs/isac/main/source/lpc_shape_swb16_tables.h" -#include "modules/audio_coding/codecs/isac/main/source/settings.h" - -/****************************************************************************** - * WebRtcIsac_RemoveLarMean() - * - * Remove the means from LAR coefficients. - * - * Input: - * -lar : pointer to lar vectors. LAR vectors are - * concatenated. - * -bandwidth : indicates if the given LAR vectors belong - * to SWB-12kHz or SWB-16kHz. - * - * Output: - * -lar : pointer to mean-removed LAR:s. - * - * - */ -int16_t -WebRtcIsac_RemoveLarMean( - double* lar, - int16_t bandwidth) -{ - int16_t coeffCntr; - int16_t vecCntr; - int16_t numVec; - const double* meanLAR; - switch(bandwidth) - { - case isac12kHz: - { - numVec = UB_LPC_VEC_PER_FRAME; - meanLAR = WebRtcIsac_kMeanLarUb12; - break; - } - case isac16kHz: - { - numVec = UB16_LPC_VEC_PER_FRAME; - meanLAR = WebRtcIsac_kMeanLarUb16; - break; - } - default: - return -1; - } - - for(vecCntr = 0; vecCntr < numVec; vecCntr++) - { - for(coeffCntr = 0; coeffCntr < UB_LPC_ORDER; coeffCntr++) - { - // REMOVE MEAN - *lar++ -= meanLAR[coeffCntr]; - } - } - return 0; -} - -/****************************************************************************** - * WebRtcIsac_DecorrelateIntraVec() - * - * Remove the correlation amonge the components of LAR vectors. If LAR vectors - * of one frame are put in a matrix where each column is a LAR vector of a - * sub-frame, then this is equivalent to multiplying the LAR matrix with - * a decorrelting mtrix from left. - * - * Input: - * -inLar : pointer to mean-removed LAR vecrtors. - * -bandwidth : indicates if the given LAR vectors belong - * to SWB-12kHz or SWB-16kHz. - * - * Output: - * -out : decorrelated LAR vectors. - */ -int16_t -WebRtcIsac_DecorrelateIntraVec( - const double* data, - double* out, - int16_t bandwidth) -{ - const double* ptrData; - const double* ptrRow; - int16_t rowCntr; - int16_t colCntr; - int16_t larVecCntr; - int16_t numVec; - const double* decorrMat; - switch(bandwidth) - { - case isac12kHz: - { - decorrMat = &WebRtcIsac_kIntraVecDecorrMatUb12[0][0]; - numVec = UB_LPC_VEC_PER_FRAME; - break; - } - case isac16kHz: - { - decorrMat = &WebRtcIsac_kIintraVecDecorrMatUb16[0][0]; - numVec = UB16_LPC_VEC_PER_FRAME; - break; - } - default: - return -1; - } - - // - // decorrMat * data - // - // data is assumed to contain 'numVec' of LAR - // vectors (mean removed) each of dimension 'UB_LPC_ORDER' - // concatenated one after the other. - // - - ptrData = data; - for(larVecCntr = 0; larVecCntr < numVec; larVecCntr++) - { - for(rowCntr = 0; rowCntr < UB_LPC_ORDER; rowCntr++) - { - ptrRow = &decorrMat[rowCntr * UB_LPC_ORDER]; - *out = 0; - for(colCntr = 0; colCntr < UB_LPC_ORDER; colCntr++) - { - *out += ptrData[colCntr] * ptrRow[colCntr]; - } - out++; - } - ptrData += UB_LPC_ORDER; - } - return 0; -} - -/****************************************************************************** - * WebRtcIsac_DecorrelateInterVec() - * - * Remover the correlation among mean-removed LAR vectors. If LAR vectors - * of one frame are put in a matrix where each column is a LAR vector of a - * sub-frame, then this is equivalent to multiplying the LAR matrix with - * a decorrelting mtrix from right. - * - * Input: - * -data : pointer to matrix of LAR vectors. The matrix - * is stored column-wise. - * -bandwidth : indicates if the given LAR vectors belong - * to SWB-12kHz or SWB-16kHz. - * - * Output: - * -out : decorrelated LAR vectors. - */ -int16_t -WebRtcIsac_DecorrelateInterVec( - const double* data, - double* out, - int16_t bandwidth) -{ - int16_t coeffCntr; - int16_t rowCntr; - int16_t colCntr; - const double* decorrMat; - int16_t interVecDim; - - switch(bandwidth) - { - case isac12kHz: - { - decorrMat = &WebRtcIsac_kInterVecDecorrMatUb12[0][0]; - interVecDim = UB_LPC_VEC_PER_FRAME; - break; - } - case isac16kHz: - { - decorrMat = &WebRtcIsac_kInterVecDecorrMatUb16[0][0]; - interVecDim = UB16_LPC_VEC_PER_FRAME; - break; - } - default: - return -1; - } - - // - // data * decorrMat - // - // data is of size 'interVecDim' * 'UB_LPC_ORDER' - // That is 'interVecDim' of LAR vectors (mean removed) - // in columns each of dimension 'UB_LPC_ORDER'. - // matrix is stored column-wise. - // - - for(coeffCntr = 0; coeffCntr < UB_LPC_ORDER; coeffCntr++) - { - for(colCntr = 0; colCntr < interVecDim; colCntr++) - { - out[coeffCntr + colCntr * UB_LPC_ORDER] = 0; - for(rowCntr = 0; rowCntr < interVecDim; rowCntr++) - { - out[coeffCntr + colCntr * UB_LPC_ORDER] += - data[coeffCntr + rowCntr * UB_LPC_ORDER] * - decorrMat[rowCntr * interVecDim + colCntr]; - } - } - } - return 0; -} - -/****************************************************************************** - * WebRtcIsac_QuantizeUncorrLar() - * - * Quantize the uncorrelated parameters. - * - * Input: - * -data : uncorrelated LAR vectors. - * -bandwidth : indicates if the given LAR vectors belong - * to SWB-12kHz or SWB-16kHz. - * - * Output: - * -data : quantized version of the input. - * -idx : pointer to quantization indices. - */ -double -WebRtcIsac_QuantizeUncorrLar( - double* data, - int* recIdx, - int16_t bandwidth) -{ - int16_t cntr; - int32_t idx; - int16_t interVecDim; - const double* leftRecPoint; - double quantizationStepSize; - const int16_t* numQuantCell; - switch(bandwidth) - { - case isac12kHz: - { - leftRecPoint = WebRtcIsac_kLpcShapeLeftRecPointUb12; - quantizationStepSize = WebRtcIsac_kLpcShapeQStepSizeUb12; - numQuantCell = WebRtcIsac_kLpcShapeNumRecPointUb12; - interVecDim = UB_LPC_VEC_PER_FRAME; - break; - } - case isac16kHz: - { - leftRecPoint = WebRtcIsac_kLpcShapeLeftRecPointUb16; - quantizationStepSize = WebRtcIsac_kLpcShapeQStepSizeUb16; - numQuantCell = WebRtcIsac_kLpcShapeNumRecPointUb16; - interVecDim = UB16_LPC_VEC_PER_FRAME; - break; - } - default: - return -1; - } - - // - // Quantize the parametrs. - // - for(cntr = 0; cntr < UB_LPC_ORDER * interVecDim; cntr++) - { - idx = (int32_t)floor((*data - leftRecPoint[cntr]) / - quantizationStepSize + 0.5); - if(idx < 0) - { - idx = 0; - } - else if(idx >= numQuantCell[cntr]) - { - idx = numQuantCell[cntr] - 1; - } - - *data++ = leftRecPoint[cntr] + idx * quantizationStepSize; - *recIdx++ = idx; - } - return 0; -} - - -/****************************************************************************** - * WebRtcIsac_DequantizeLpcParam() - * - * Get the quantized value of uncorrelated LARs given the quantization indices. - * - * Input: - * -idx : pointer to quantiztion indices. - * -bandwidth : indicates if the given LAR vectors belong - * to SWB-12kHz or SWB-16kHz. - * - * Output: - * -out : pointer to quantized values. - */ -int16_t -WebRtcIsac_DequantizeLpcParam( - const int* idx, - double* out, - int16_t bandwidth) -{ - int16_t cntr; - int16_t interVecDim; - const double* leftRecPoint; - double quantizationStepSize; - - switch(bandwidth) - { - case isac12kHz: - { - leftRecPoint = WebRtcIsac_kLpcShapeLeftRecPointUb12; - quantizationStepSize = WebRtcIsac_kLpcShapeQStepSizeUb12; - interVecDim = UB_LPC_VEC_PER_FRAME; - break; - } - case isac16kHz: - { - leftRecPoint = WebRtcIsac_kLpcShapeLeftRecPointUb16; - quantizationStepSize = WebRtcIsac_kLpcShapeQStepSizeUb16; - interVecDim = UB16_LPC_VEC_PER_FRAME; - break; - } - default: - return -1; - } - - // - // Dequantize given the quantization indices - // - - for(cntr = 0; cntr < UB_LPC_ORDER * interVecDim; cntr++) - { - *out++ = leftRecPoint[cntr] + *idx++ * quantizationStepSize; - } - return 0; -} - - -/****************************************************************************** - * WebRtcIsac_CorrelateIntraVec() - * - * This is the inverse of WebRtcIsac_DecorrelateIntraVec(). - * - * Input: - * -data : uncorrelated parameters. - * -bandwidth : indicates if the given LAR vectors belong - * to SWB-12kHz or SWB-16kHz. - * - * Output: - * -out : correlated parametrs. - */ -int16_t -WebRtcIsac_CorrelateIntraVec( - const double* data, - double* out, - int16_t bandwidth) -{ - int16_t vecCntr; - int16_t rowCntr; - int16_t colCntr; - int16_t numVec; - const double* ptrData; - const double* intraVecDecorrMat; - - switch(bandwidth) - { - case isac12kHz: - { - numVec = UB_LPC_VEC_PER_FRAME; - intraVecDecorrMat = &WebRtcIsac_kIntraVecDecorrMatUb12[0][0]; - break; - } - case isac16kHz: - { - numVec = UB16_LPC_VEC_PER_FRAME; - intraVecDecorrMat = &WebRtcIsac_kIintraVecDecorrMatUb16[0][0]; - break; - } - default: - return -1; - } - - - ptrData = data; - for(vecCntr = 0; vecCntr < numVec; vecCntr++) - { - for(colCntr = 0; colCntr < UB_LPC_ORDER; colCntr++) - { - *out = 0; - for(rowCntr = 0; rowCntr < UB_LPC_ORDER; rowCntr++) - { - *out += ptrData[rowCntr] * - intraVecDecorrMat[rowCntr * UB_LPC_ORDER + colCntr]; - } - out++; - } - ptrData += UB_LPC_ORDER; - } - return 0; -} - -/****************************************************************************** - * WebRtcIsac_CorrelateInterVec() - * - * This is the inverse of WebRtcIsac_DecorrelateInterVec(). - * - * Input: - * -data - * -bandwidth : indicates if the given LAR vectors belong - * to SWB-12kHz or SWB-16kHz. - * - * Output: - * -out : correlated parametrs. - */ -int16_t -WebRtcIsac_CorrelateInterVec( - const double* data, - double* out, - int16_t bandwidth) -{ - int16_t coeffCntr; - int16_t rowCntr; - int16_t colCntr; - int16_t interVecDim; - double myVec[UB16_LPC_VEC_PER_FRAME] = {0.0}; - const double* interVecDecorrMat; - - switch(bandwidth) - { - case isac12kHz: - { - interVecDim = UB_LPC_VEC_PER_FRAME; - interVecDecorrMat = &WebRtcIsac_kInterVecDecorrMatUb12[0][0]; - break; - } - case isac16kHz: - { - interVecDim = UB16_LPC_VEC_PER_FRAME; - interVecDecorrMat = &WebRtcIsac_kInterVecDecorrMatUb16[0][0]; - break; - } - default: - return -1; - } - - for(coeffCntr = 0; coeffCntr < UB_LPC_ORDER; coeffCntr++) - { - for(rowCntr = 0; rowCntr < interVecDim; rowCntr++) - { - myVec[rowCntr] = 0; - for(colCntr = 0; colCntr < interVecDim; colCntr++) - { - myVec[rowCntr] += data[coeffCntr + colCntr * UB_LPC_ORDER] * //*ptrData * - interVecDecorrMat[rowCntr * interVecDim + colCntr]; - //ptrData += UB_LPC_ORDER; - } - } - - for(rowCntr = 0; rowCntr < interVecDim; rowCntr++) - { - out[coeffCntr + rowCntr * UB_LPC_ORDER] = myVec[rowCntr]; - } - } - return 0; -} - -/****************************************************************************** - * WebRtcIsac_AddLarMean() - * - * This is the inverse of WebRtcIsac_RemoveLarMean() - * - * Input: - * -data : pointer to mean-removed LAR:s. - * -bandwidth : indicates if the given LAR vectors belong - * to SWB-12kHz or SWB-16kHz. - * - * Output: - * -data : pointer to LARs. - */ -int16_t -WebRtcIsac_AddLarMean( - double* data, - int16_t bandwidth) -{ - int16_t coeffCntr; - int16_t vecCntr; - int16_t numVec; - const double* meanLAR; - - switch(bandwidth) - { - case isac12kHz: - { - numVec = UB_LPC_VEC_PER_FRAME; - meanLAR = WebRtcIsac_kMeanLarUb12; - break; - } - case isac16kHz: - { - numVec = UB16_LPC_VEC_PER_FRAME; - meanLAR = WebRtcIsac_kMeanLarUb16; - break; - } - default: - return -1; - } - - for(vecCntr = 0; vecCntr < numVec; vecCntr++) - { - for(coeffCntr = 0; coeffCntr < UB_LPC_ORDER; coeffCntr++) - { - *data++ += meanLAR[coeffCntr]; - } - } - return 0; -} - -/****************************************************************************** - * WebRtcIsac_ToLogDomainRemoveMean() - * - * Transform the LPC gain to log domain then remove the mean value. - * - * Input: - * -lpcGain : pointer to LPC Gain, expecting 6 LPC gains - * - * Output: - * -lpcGain : mean-removed in log domain. - */ -int16_t -WebRtcIsac_ToLogDomainRemoveMean( - double* data) -{ - int16_t coeffCntr; - for(coeffCntr = 0; coeffCntr < UB_LPC_GAIN_DIM; coeffCntr++) - { - data[coeffCntr] = log(data[coeffCntr]) - WebRtcIsac_kMeanLpcGain; - } - return 0; -} - - -/****************************************************************************** - * WebRtcIsac_DecorrelateLPGain() - * - * Decorrelate LPC gains. There are 6 LPC Gains per frame. This is like - * multiplying gain vector with decorrelating matrix. - * - * Input: - * -data : LPC gain in log-domain with mean removed. - * - * Output: - * -out : decorrelated parameters. - */ -int16_t WebRtcIsac_DecorrelateLPGain( - const double* data, - double* out) -{ - int16_t rowCntr; - int16_t colCntr; - - for(colCntr = 0; colCntr < UB_LPC_GAIN_DIM; colCntr++) - { - *out = 0; - for(rowCntr = 0; rowCntr < UB_LPC_GAIN_DIM; rowCntr++) - { - *out += data[rowCntr] * WebRtcIsac_kLpcGainDecorrMat[rowCntr][colCntr]; - } - out++; - } - return 0; -} - -/****************************************************************************** - * WebRtcIsac_QuantizeLpcGain() - * - * Quantize the decorrelated log-domain gains. - * - * Input: - * -lpcGain : uncorrelated LPC gains. - * - * Output: - * -idx : quantization indices - * -lpcGain : quantized value of the inpt. - */ -double WebRtcIsac_QuantizeLpcGain( - double* data, - int* idx) -{ - int16_t coeffCntr; - for(coeffCntr = 0; coeffCntr < UB_LPC_GAIN_DIM; coeffCntr++) - { - *idx = (int)floor((*data - WebRtcIsac_kLeftRecPointLpcGain[coeffCntr]) / - WebRtcIsac_kQSizeLpcGain + 0.5); - - if(*idx < 0) - { - *idx = 0; - } - else if(*idx >= WebRtcIsac_kNumQCellLpcGain[coeffCntr]) - { - *idx = WebRtcIsac_kNumQCellLpcGain[coeffCntr] - 1; - } - *data = WebRtcIsac_kLeftRecPointLpcGain[coeffCntr] + *idx * - WebRtcIsac_kQSizeLpcGain; - - data++; - idx++; - } - return 0; -} - -/****************************************************************************** - * WebRtcIsac_DequantizeLpcGain() - * - * Get the quantized values given the quantization indices. - * - * Input: - * -idx : pointer to quantization indices. - * - * Output: - * -lpcGains : quantized values of the given parametes. - */ -int16_t WebRtcIsac_DequantizeLpcGain( - const int* idx, - double* out) -{ - int16_t coeffCntr; - for(coeffCntr = 0; coeffCntr < UB_LPC_GAIN_DIM; coeffCntr++) - { - *out = WebRtcIsac_kLeftRecPointLpcGain[coeffCntr] + *idx * - WebRtcIsac_kQSizeLpcGain; - out++; - idx++; - } - return 0; -} - -/****************************************************************************** - * WebRtcIsac_CorrelateLpcGain() - * - * This is the inverse of WebRtcIsac_DecorrelateLPGain(). - * - * Input: - * -data : decorrelated parameters. - * - * Output: - * -out : correlated parameters. - */ -int16_t WebRtcIsac_CorrelateLpcGain( - const double* data, - double* out) -{ - int16_t rowCntr; - int16_t colCntr; - - for(rowCntr = 0; rowCntr < UB_LPC_GAIN_DIM; rowCntr++) - { - *out = 0; - for(colCntr = 0; colCntr < UB_LPC_GAIN_DIM; colCntr++) - { - *out += WebRtcIsac_kLpcGainDecorrMat[rowCntr][colCntr] * data[colCntr]; - } - out++; - } - - return 0; -} - - -/****************************************************************************** - * WebRtcIsac_AddMeanToLinearDomain() - * - * This is the inverse of WebRtcIsac_ToLogDomainRemoveMean(). - * - * Input: - * -lpcGain : LPC gain in log-domain & mean removed - * - * Output: - * -lpcGain : LPC gain in normal domain. - */ -int16_t WebRtcIsac_AddMeanToLinearDomain( - double* lpcGains) -{ - int16_t coeffCntr; - for(coeffCntr = 0; coeffCntr < UB_LPC_GAIN_DIM; coeffCntr++) - { - lpcGains[coeffCntr] = exp(lpcGains[coeffCntr] + WebRtcIsac_kMeanLpcGain); - } - return 0; -} diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/encode_lpc_swb.h b/webrtc/modules/audio_coding/codecs/isac/main/source/encode_lpc_swb.h deleted file mode 100644 index 8bc3d75..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/encode_lpc_swb.h +++ /dev/null @@ -1,246 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -/* - * encode_lpc_swb.h - * - * This file contains declaration of functions used to - * encode LPC parameters (Shape & gain) of the upper band. - * - */ - -#ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ENCODE_LPC_SWB_H_ -#define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ENCODE_LPC_SWB_H_ - -#include "modules/audio_coding/codecs/isac/main/source/settings.h" -#include "modules/audio_coding/codecs/isac/main/source/structs.h" - -/****************************************************************************** - * WebRtcIsac_RemoveLarMean() - * - * Remove the means from LAR coefficients. - * - * Input: - * -lar : pointer to lar vectors. LAR vectors are - * concatenated. - * -bandwidth : indicates if the given LAR vectors belong - * to SWB-12kHz or SWB-16kHz. - * - * Output: - * -lar : pointer to mean-removed LAR:s. - * - * - */ -int16_t WebRtcIsac_RemoveLarMean(double* lar, int16_t bandwidth); - -/****************************************************************************** - * WebRtcIsac_DecorrelateIntraVec() - * - * Remove the correlation amonge the components of LAR vectors. If LAR vectors - * of one frame are put in a matrix where each column is a LAR vector of a - * sub-frame, then this is equivalent to multiplying the LAR matrix with - * a decorrelting mtrix from left. - * - * Input: - * -inLar : pointer to mean-removed LAR vecrtors. - * -bandwidth : indicates if the given LAR vectors belong - * to SWB-12kHz or SWB-16kHz. - * - * Output: - * -out : decorrelated LAR vectors. - */ -int16_t WebRtcIsac_DecorrelateIntraVec(const double* inLAR, - double* out, - int16_t bandwidth); - -/****************************************************************************** - * WebRtcIsac_DecorrelateInterVec() - * - * Remover the correlation among mean-removed LAR vectors. If LAR vectors - * of one frame are put in a matrix where each column is a LAR vector of a - * sub-frame, then this is equivalent to multiplying the LAR matrix with - * a decorrelting mtrix from right. - * - * Input: - * -data : pointer to matrix of LAR vectors. The matrix - * is stored column-wise. - * -bandwidth : indicates if the given LAR vectors belong - * to SWB-12kHz or SWB-16kHz. - * - * Output: - * -out : decorrelated LAR vectors. - */ -int16_t WebRtcIsac_DecorrelateInterVec(const double* data, - double* out, - int16_t bandwidth); - -/****************************************************************************** - * WebRtcIsac_QuantizeUncorrLar() - * - * Quantize the uncorrelated parameters. - * - * Input: - * -data : uncorrelated LAR vectors. - * -bandwidth : indicates if the given LAR vectors belong - * to SWB-12kHz or SWB-16kHz. - * - * Output: - * -data : quantized version of the input. - * -idx : pointer to quantization indices. - */ -double WebRtcIsac_QuantizeUncorrLar(double* data, int* idx, int16_t bandwidth); - -/****************************************************************************** - * WebRtcIsac_CorrelateIntraVec() - * - * This is the inverse of WebRtcIsac_DecorrelateIntraVec(). - * - * Input: - * -data : uncorrelated parameters. - * -bandwidth : indicates if the given LAR vectors belong - * to SWB-12kHz or SWB-16kHz. - * - * Output: - * -out : correlated parametrs. - */ -int16_t WebRtcIsac_CorrelateIntraVec(const double* data, - double* out, - int16_t bandwidth); - -/****************************************************************************** - * WebRtcIsac_CorrelateInterVec() - * - * This is the inverse of WebRtcIsac_DecorrelateInterVec(). - * - * Input: - * -data - * -bandwidth : indicates if the given LAR vectors belong - * to SWB-12kHz or SWB-16kHz. - * - * Output: - * -out : correlated parametrs. - */ -int16_t WebRtcIsac_CorrelateInterVec(const double* data, - double* out, - int16_t bandwidth); - -/****************************************************************************** - * WebRtcIsac_AddLarMean() - * - * This is the inverse of WebRtcIsac_RemoveLarMean() - * - * Input: - * -data : pointer to mean-removed LAR:s. - * -bandwidth : indicates if the given LAR vectors belong - * to SWB-12kHz or SWB-16kHz. - * - * Output: - * -data : pointer to LARs. - */ -int16_t WebRtcIsac_AddLarMean(double* data, int16_t bandwidth); - -/****************************************************************************** - * WebRtcIsac_DequantizeLpcParam() - * - * Get the quantized value of uncorrelated LARs given the quantization indices. - * - * Input: - * -idx : pointer to quantiztion indices. - * -bandwidth : indicates if the given LAR vectors belong - * to SWB-12kHz or SWB-16kHz. - * - * Output: - * -out : pointer to quantized values. - */ -int16_t WebRtcIsac_DequantizeLpcParam(const int* idx, - double* out, - int16_t bandwidth); - -/****************************************************************************** - * WebRtcIsac_ToLogDomainRemoveMean() - * - * Transform the LPC gain to log domain then remove the mean value. - * - * Input: - * -lpcGain : pointer to LPC Gain, expecting 6 LPC gains - * - * Output: - * -lpcGain : mean-removed in log domain. - */ -int16_t WebRtcIsac_ToLogDomainRemoveMean(double* lpGains); - -/****************************************************************************** - * WebRtcIsac_DecorrelateLPGain() - * - * Decorrelate LPC gains. There are 6 LPC Gains per frame. This is like - * multiplying gain vector with decorrelating matrix. - * - * Input: - * -data : LPC gain in log-domain with mean removed. - * - * Output: - * -out : decorrelated parameters. - */ -int16_t WebRtcIsac_DecorrelateLPGain(const double* data, double* out); - -/****************************************************************************** - * WebRtcIsac_QuantizeLpcGain() - * - * Quantize the decorrelated log-domain gains. - * - * Input: - * -lpcGain : uncorrelated LPC gains. - * - * Output: - * -idx : quantization indices - * -lpcGain : quantized value of the inpt. - */ -double WebRtcIsac_QuantizeLpcGain(double* lpGains, int* idx); - -/****************************************************************************** - * WebRtcIsac_DequantizeLpcGain() - * - * Get the quantized values given the quantization indices. - * - * Input: - * -idx : pointer to quantization indices. - * - * Output: - * -lpcGains : quantized values of the given parametes. - */ -int16_t WebRtcIsac_DequantizeLpcGain(const int* idx, double* lpGains); - -/****************************************************************************** - * WebRtcIsac_CorrelateLpcGain() - * - * This is the inverse of WebRtcIsac_DecorrelateLPGain(). - * - * Input: - * -data : decorrelated parameters. - * - * Output: - * -out : correlated parameters. - */ -int16_t WebRtcIsac_CorrelateLpcGain(const double* data, double* out); - -/****************************************************************************** - * WebRtcIsac_AddMeanToLinearDomain() - * - * This is the inverse of WebRtcIsac_ToLogDomainRemoveMean(). - * - * Input: - * -lpcGain : LPC gain in log-domain & mean removed - * - * Output: - * -lpcGain : LPC gain in normal domain. - */ -int16_t WebRtcIsac_AddMeanToLinearDomain(double* lpcGains); - -#endif // MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ENCODE_LPC_SWB_H_ diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/entropy_coding.c b/webrtc/modules/audio_coding/codecs/isac/main/source/entropy_coding.c deleted file mode 100644 index 6692a51..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/entropy_coding.c +++ /dev/null @@ -1,2066 +0,0 @@ -/* - * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -/* - * entropy_coding.c - * - * This header file defines all of the functions used to arithmetically - * encode the iSAC bistream - * - */ - - -#include "common_audio/signal_processing/include/signal_processing_library.h" -#include "modules/audio_coding/codecs/isac/main/source/entropy_coding.h" -#include "modules/audio_coding/codecs/isac/main/source/settings.h" -#include "modules/audio_coding/codecs/isac/main/source/arith_routines.h" -#include "modules/audio_coding/codecs/isac/main/source/spectrum_ar_model_tables.h" -#include "modules/audio_coding/codecs/isac/main/source/lpc_tables.h" -#include "modules/audio_coding/codecs/isac/main/source/pitch_gain_tables.h" -#include "modules/audio_coding/codecs/isac/main/source/pitch_lag_tables.h" -#include "modules/audio_coding/codecs/isac/main/source/encode_lpc_swb.h" -#include "modules/audio_coding/codecs/isac/main/source/lpc_shape_swb12_tables.h" -#include "modules/audio_coding/codecs/isac/main/source/lpc_shape_swb16_tables.h" -#include "modules/audio_coding/codecs/isac/main/source/lpc_gain_swb_tables.h" -#include "modules/audio_coding/codecs/isac/main/source/os_specific_inline.h" - -#include -#include - -static const uint16_t kLpcVecPerSegmentUb12 = 5; -static const uint16_t kLpcVecPerSegmentUb16 = 4; - -/* CDF array for encoder bandwidth (12 vs 16 kHz) indicator. */ -static const uint16_t kOneBitEqualProbCdf[3] = { - 0, 32768, 65535 }; - -/* Pointer to cdf array for encoder bandwidth (12 vs 16 kHz) indicator. */ -static const uint16_t* const kOneBitEqualProbCdf_ptr[1] = { - kOneBitEqualProbCdf }; - -/* - * Initial cdf index for decoder of encoded bandwidth - * (12 vs 16 kHz) indicator. - */ -static const uint16_t kOneBitEqualProbInitIndex[1] = { 1 }; - - -static const int kIsSWB12 = 1; - -/* compute correlation from power spectrum */ -static void FindCorrelation(int32_t* PSpecQ12, int32_t* CorrQ7) { - int32_t summ[FRAMESAMPLES / 8]; - int32_t diff[FRAMESAMPLES / 8]; - const int16_t* CS_ptrQ9; - int32_t sum; - int k, n; - - for (k = 0; k < FRAMESAMPLES / 8; k++) { - summ[k] = (PSpecQ12[k] + PSpecQ12[FRAMESAMPLES_QUARTER - 1 - k] + 16) >> 5; - diff[k] = (PSpecQ12[k] - PSpecQ12[FRAMESAMPLES_QUARTER - 1 - k] + 16) >> 5; - } - - sum = 2; - for (n = 0; n < FRAMESAMPLES / 8; n++) { - sum += summ[n]; - } - CorrQ7[0] = sum; - - for (k = 0; k < AR_ORDER; k += 2) { - sum = 0; - CS_ptrQ9 = WebRtcIsac_kCos[k]; - for (n = 0; n < FRAMESAMPLES / 8; n++) - sum += (CS_ptrQ9[n] * diff[n] + 256) >> 9; - CorrQ7[k + 1] = sum; - } - - for (k = 1; k < AR_ORDER; k += 2) { - sum = 0; - CS_ptrQ9 = WebRtcIsac_kCos[k]; - for (n = 0; n < FRAMESAMPLES / 8; n++) - sum += (CS_ptrQ9[n] * summ[n] + 256) >> 9; - CorrQ7[k + 1] = sum; - } -} - -/* compute inverse AR power spectrum */ -/* Changed to the function used in iSAC FIX for compatibility reasons */ -static void FindInvArSpec(const int16_t* ARCoefQ12, - const int32_t gainQ10, - int32_t* CurveQ16) { - int32_t CorrQ11[AR_ORDER + 1]; - int64_t sum, tmpGain; - int32_t diffQ16[FRAMESAMPLES / 8]; - const int16_t* CS_ptrQ9; - int k, n; - int16_t round, shftVal = 0, sh; - - sum = 0; - for (n = 0; n < AR_ORDER + 1; n++) { - sum += WEBRTC_SPL_MUL(ARCoefQ12[n], ARCoefQ12[n]); /* Q24 */ - } - sum = ((sum >> 6) * 65 + 32768) >> 16; /* Q8 */ - CorrQ11[0] = (sum * gainQ10 + 256) >> 9; - - /* To avoid overflow, we shift down gainQ10 if it is large. - * We will not lose any precision */ - if (gainQ10 > 400000) { - tmpGain = gainQ10 >> 3; - round = 32; - shftVal = 6; - } else { - tmpGain = gainQ10; - round = 256; - shftVal = 9; - } - - for (k = 1; k < AR_ORDER + 1; k++) { - sum = 16384; - for (n = k; n < AR_ORDER + 1; n++) - sum += WEBRTC_SPL_MUL(ARCoefQ12[n - k], ARCoefQ12[n]); /* Q24 */ - sum >>= 15; - CorrQ11[k] = (sum * tmpGain + round) >> shftVal; - } - sum = CorrQ11[0] << 7; - for (n = 0; n < FRAMESAMPLES / 8; n++) { - CurveQ16[n] = sum; - } - for (k = 1; k < AR_ORDER; k += 2) { - for (n = 0; n < FRAMESAMPLES / 8; n++) { - CurveQ16[n] += (WebRtcIsac_kCos[k][n] * CorrQ11[k + 1] + 2) >> 2; - } - } - - CS_ptrQ9 = WebRtcIsac_kCos[0]; - - /* If CorrQ11[1] too large we avoid getting overflow in the - * calculation by shifting */ - sh = WebRtcSpl_NormW32(CorrQ11[1]); - if (CorrQ11[1] == 0) { /* Use next correlation */ - sh = WebRtcSpl_NormW32(CorrQ11[2]); - } - if (sh < 9) { - shftVal = 9 - sh; - } else { - shftVal = 0; - } - for (n = 0; n < FRAMESAMPLES / 8; n++) { - diffQ16[n] = (CS_ptrQ9[n] * (CorrQ11[1] >> shftVal) + 2) >> 2; - } - for (k = 2; k < AR_ORDER; k += 2) { - CS_ptrQ9 = WebRtcIsac_kCos[k]; - for (n = 0; n < FRAMESAMPLES / 8; n++) { - diffQ16[n] += (CS_ptrQ9[n] * (CorrQ11[k + 1] >> shftVal) + 2) >> 2; - } - } - - for (k = 0; k < FRAMESAMPLES / 8; k++) { - int32_t diff_q16_shifted = (int32_t)((uint32_t)(diffQ16[k]) << shftVal); - CurveQ16[FRAMESAMPLES_QUARTER - 1 - k] = CurveQ16[k] - diff_q16_shifted; - CurveQ16[k] += diff_q16_shifted; - } -} - -/* Generate array of dither samples in Q7. */ -static void GenerateDitherQ7Lb(int16_t* bufQ7, uint32_t seed, - int length, int16_t AvgPitchGain_Q12) { - int k, shft; - int16_t dither1_Q7, dither2_Q7, dither_gain_Q14; - - /* This threshold should be equal to that in decode_spec(). */ - if (AvgPitchGain_Q12 < 614) { - for (k = 0; k < length - 2; k += 3) { - /* New random unsigned int. */ - seed = (seed * 196314165) + 907633515; - - /* Fixed-point dither sample between -64 and 64 (Q7). */ - /* dither = seed * 128 / 4294967295 */ - dither1_Q7 = (int16_t)(((int32_t)(seed + 16777216)) >> 25); - - /* New random unsigned int. */ - seed = (seed * 196314165) + 907633515; - - /* Fixed-point dither sample between -64 and 64. */ - dither2_Q7 = (int16_t)(((int32_t)(seed + 16777216)) >> 25); - - shft = (seed >> 25) & 15; - if (shft < 5) { - bufQ7[k] = dither1_Q7; - bufQ7[k + 1] = dither2_Q7; - bufQ7[k + 2] = 0; - } else if (shft < 10) { - bufQ7[k] = dither1_Q7; - bufQ7[k + 1] = 0; - bufQ7[k + 2] = dither2_Q7; - } else { - bufQ7[k] = 0; - bufQ7[k + 1] = dither1_Q7; - bufQ7[k + 2] = dither2_Q7; - } - } - } else { - dither_gain_Q14 = (int16_t)(22528 - 10 * AvgPitchGain_Q12); - - /* Dither on half of the coefficients. */ - for (k = 0; k < length - 1; k += 2) { - /* New random unsigned int */ - seed = (seed * 196314165) + 907633515; - - /* Fixed-point dither sample between -64 and 64. */ - dither1_Q7 = (int16_t)(((int32_t)(seed + 16777216)) >> 25); - - /* Dither sample is placed in either even or odd index. */ - shft = (seed >> 25) & 1; /* Either 0 or 1 */ - - bufQ7[k + shft] = (((dither_gain_Q14 * dither1_Q7) + 8192) >> 14); - bufQ7[k + 1 - shft] = 0; - } - } -} - - - -/****************************************************************************** - * GenerateDitherQ7LbUB() - * - * generate array of dither samples in Q7 There are less zeros in dither - * vector compared to GenerateDitherQ7Lb. - * - * A uniform random number generator with the range of [-64 64] is employed - * but the generated dithers are scaled by 0.35, a heuristic scaling. - * - * Input: - * -seed : the initial seed for the random number generator. - * -length : the number of dither values to be generated. - * - * Output: - * -bufQ7 : pointer to a buffer where dithers are written to. - */ -static void GenerateDitherQ7LbUB( - int16_t* bufQ7, - uint32_t seed, - int length) { - int k; - for (k = 0; k < length; k++) { - /* new random unsigned int */ - seed = (seed * 196314165) + 907633515; - - /* Fixed-point dither sample between -64 and 64 (Q7). */ - /* bufQ7 = seed * 128 / 4294967295 */ - bufQ7[k] = (int16_t)(((int32_t)(seed + 16777216)) >> 25); - - /* Scale by 0.35. */ - bufQ7[k] = (int16_t)WEBRTC_SPL_MUL_16_16_RSFT(bufQ7[k], 2048, 13); - } -} - -/* - * Function to decode the complex spectrum from the bit stream - * returns the total number of bytes in the stream. - */ -int WebRtcIsac_DecodeSpec(Bitstr* streamdata, int16_t AvgPitchGain_Q12, - enum ISACBand band, double* fr, double* fi) { - int16_t DitherQ7[FRAMESAMPLES]; - int16_t data[FRAMESAMPLES]; - int32_t invARSpec2_Q16[FRAMESAMPLES_QUARTER]; - uint16_t invARSpecQ8[FRAMESAMPLES_QUARTER]; - int16_t ARCoefQ12[AR_ORDER + 1]; - int16_t RCQ15[AR_ORDER]; - int16_t gainQ10; - int32_t gain2_Q10, res; - int32_t in_sqrt; - int32_t newRes; - int k, len, i; - int is_12khz = !kIsSWB12; - int num_dft_coeff = FRAMESAMPLES; - /* Create dither signal. */ - if (band == kIsacLowerBand) { - GenerateDitherQ7Lb(DitherQ7, streamdata->W_upper, FRAMESAMPLES, - AvgPitchGain_Q12); - } else { - GenerateDitherQ7LbUB(DitherQ7, streamdata->W_upper, FRAMESAMPLES); - if (band == kIsacUpperBand12) { - is_12khz = kIsSWB12; - num_dft_coeff = FRAMESAMPLES_HALF; - } - } - - /* Decode model parameters. */ - if (WebRtcIsac_DecodeRc(streamdata, RCQ15) < 0) - return -ISAC_RANGE_ERROR_DECODE_SPECTRUM; - - WebRtcSpl_ReflCoefToLpc(RCQ15, AR_ORDER, ARCoefQ12); - - if (WebRtcIsac_DecodeGain2(streamdata, &gain2_Q10) < 0) - return -ISAC_RANGE_ERROR_DECODE_SPECTRUM; - - /* Compute inverse AR power spectrum. */ - FindInvArSpec(ARCoefQ12, gain2_Q10, invARSpec2_Q16); - - /* Convert to magnitude spectrum, - * by doing square-roots (modified from SPLIB). */ - res = 1 << (WebRtcSpl_GetSizeInBits(invARSpec2_Q16[0]) >> 1); - for (k = 0; k < FRAMESAMPLES_QUARTER; k++) { - in_sqrt = invARSpec2_Q16[k]; - i = 10; - - /* Negative values make no sense for a real sqrt-function. */ - if (in_sqrt < 0) - in_sqrt = -in_sqrt; - - newRes = (in_sqrt / res + res) >> 1; - do { - res = newRes; - newRes = (in_sqrt / res + res) >> 1; - } while (newRes != res && i-- > 0); - - invARSpecQ8[k] = (int16_t)newRes; - } - - len = WebRtcIsac_DecLogisticMulti2(data, streamdata, invARSpecQ8, DitherQ7, - num_dft_coeff, is_12khz); - /* Arithmetic decoding of spectrum. */ - if (len < 1) { - return -ISAC_RANGE_ERROR_DECODE_SPECTRUM; - } - - switch (band) { - case kIsacLowerBand: { - /* Scale down spectral samples with low SNR. */ - int32_t p1; - int32_t p2; - if (AvgPitchGain_Q12 <= 614) { - p1 = 30 << 10; - p2 = 32768 + (33 << 16); - } else { - p1 = 36 << 10; - p2 = 32768 + (40 << 16); - } - for (k = 0; k < FRAMESAMPLES; k += 4) { - gainQ10 = WebRtcSpl_DivW32W16ResW16(p1, (int16_t)( - (invARSpec2_Q16[k >> 2] + p2) >> 16)); - *fr++ = (double)((data[ k ] * gainQ10 + 512) >> 10) / 128.0; - *fi++ = (double)((data[k + 1] * gainQ10 + 512) >> 10) / 128.0; - *fr++ = (double)((data[k + 2] * gainQ10 + 512) >> 10) / 128.0; - *fi++ = (double)((data[k + 3] * gainQ10 + 512) >> 10) / 128.0; - } - break; - } - case kIsacUpperBand12: { - for (k = 0, i = 0; k < FRAMESAMPLES_HALF; k += 4) { - fr[i] = (double)data[ k ] / 128.0; - fi[i] = (double)data[k + 1] / 128.0; - i++; - fr[i] = (double)data[k + 2] / 128.0; - fi[i] = (double)data[k + 3] / 128.0; - i++; - } - /* The second half of real and imaginary coefficients is zero. This is - * due to using the old FFT module which requires two signals as input - * while in 0-12 kHz mode we only have 8-12 kHz band, and the second - * signal is set to zero. */ - memset(&fr[FRAMESAMPLES_QUARTER], 0, FRAMESAMPLES_QUARTER * - sizeof(double)); - memset(&fi[FRAMESAMPLES_QUARTER], 0, FRAMESAMPLES_QUARTER * - sizeof(double)); - break; - } - case kIsacUpperBand16: { - for (i = 0, k = 0; k < FRAMESAMPLES; k += 4, i++) { - fr[i] = (double)data[ k ] / 128.0; - fi[i] = (double)data[k + 1] / 128.0; - fr[(FRAMESAMPLES_HALF) - 1 - i] = (double)data[k + 2] / 128.0; - fi[(FRAMESAMPLES_HALF) - 1 - i] = (double)data[k + 3] / 128.0; - } - break; - } - } - return len; -} - - -int WebRtcIsac_EncodeSpec(const int16_t* fr, const int16_t* fi, - int16_t AvgPitchGain_Q12, enum ISACBand band, - Bitstr* streamdata) { - int16_t ditherQ7[FRAMESAMPLES]; - int16_t dataQ7[FRAMESAMPLES]; - int32_t PSpec[FRAMESAMPLES_QUARTER]; - int32_t invARSpec2_Q16[FRAMESAMPLES_QUARTER]; - uint16_t invARSpecQ8[FRAMESAMPLES_QUARTER]; - int32_t CorrQ7[AR_ORDER + 1]; - int32_t CorrQ7_norm[AR_ORDER + 1]; - int16_t RCQ15[AR_ORDER]; - int16_t ARCoefQ12[AR_ORDER + 1]; - int32_t gain2_Q10; - int16_t val; - int32_t nrg, res; - uint32_t sum; - int32_t in_sqrt; - int32_t newRes; - int16_t err; - uint32_t nrg_u32; - int shift_var; - int k, n, j, i; - int is_12khz = !kIsSWB12; - int num_dft_coeff = FRAMESAMPLES; - - /* Create dither signal. */ - if (band == kIsacLowerBand) { - GenerateDitherQ7Lb(ditherQ7, streamdata->W_upper, FRAMESAMPLES, - AvgPitchGain_Q12); - } else { - GenerateDitherQ7LbUB(ditherQ7, streamdata->W_upper, FRAMESAMPLES); - if (band == kIsacUpperBand12) { - is_12khz = kIsSWB12; - num_dft_coeff = FRAMESAMPLES_HALF; - } - } - - /* add dither and quantize, and compute power spectrum */ - switch (band) { - case kIsacLowerBand: { - for (k = 0; k < FRAMESAMPLES; k += 4) { - val = ((*fr++ + ditherQ7[k] + 64) & 0xFF80) - ditherQ7[k]; - dataQ7[k] = val; - sum = val * val; - - val = ((*fi++ + ditherQ7[k + 1] + 64) & 0xFF80) - ditherQ7[k + 1]; - dataQ7[k + 1] = val; - sum += val * val; - - val = ((*fr++ + ditherQ7[k + 2] + 64) & 0xFF80) - ditherQ7[k + 2]; - dataQ7[k + 2] = val; - sum += val * val; - - val = ((*fi++ + ditherQ7[k + 3] + 64) & 0xFF80) - ditherQ7[k + 3]; - dataQ7[k + 3] = val; - sum += val * val; - - PSpec[k >> 2] = sum >> 2; - } - break; - } - case kIsacUpperBand12: { - for (k = 0, j = 0; k < FRAMESAMPLES_HALF; k += 4) { - val = ((*fr++ + ditherQ7[k] + 64) & 0xFF80) - ditherQ7[k]; - dataQ7[k] = val; - sum = val * val; - - val = ((*fi++ + ditherQ7[k + 1] + 64) & 0xFF80) - ditherQ7[k + 1]; - dataQ7[k + 1] = val; - sum += val * val; - - PSpec[j++] = sum >> 1; - - val = ((*fr++ + ditherQ7[k + 2] + 64) & 0xFF80) - ditherQ7[k + 2]; - dataQ7[k + 2] = val; - sum = val * val; - - val = ((*fi++ + ditherQ7[k + 3] + 64) & 0xFF80) - ditherQ7[k + 3]; - dataQ7[k + 3] = val; - sum += val * val; - - PSpec[j++] = sum >> 1; - } - break; - } - case kIsacUpperBand16: { - for (j = 0, k = 0; k < FRAMESAMPLES; k += 4, j++) { - val = ((fr[j] + ditherQ7[k] + 64) & 0xFF80) - ditherQ7[k]; - dataQ7[k] = val; - sum = val * val; - - val = ((fi[j] + ditherQ7[k + 1] + 64) & 0xFF80) - ditherQ7[k + 1]; - dataQ7[k + 1] = val; - sum += val * val; - - val = ((fr[(FRAMESAMPLES_HALF) - 1 - j] + ditherQ7[k + 2] + 64) & - 0xFF80) - ditherQ7[k + 2]; - dataQ7[k + 2] = val; - sum += val * val; - - val = ((fi[(FRAMESAMPLES_HALF) - 1 - j] + ditherQ7[k + 3] + 64) & - 0xFF80) - ditherQ7[k + 3]; - dataQ7[k + 3] = val; - sum += val * val; - - PSpec[k >> 2] = sum >> 2; - } - break; - } - } - - /* compute correlation from power spectrum */ - FindCorrelation(PSpec, CorrQ7); - - /* Find AR coefficients */ - /* Aumber of bit shifts to 14-bit normalize CorrQ7[0] - * (leaving room for sign) */ - shift_var = WebRtcSpl_NormW32(CorrQ7[0]) - 18; - - if (shift_var > 0) { - for (k = 0; k < AR_ORDER + 1; k++) { - CorrQ7_norm[k] = CorrQ7[k] << shift_var; - } - } else { - for (k = 0; k < AR_ORDER + 1; k++) { - CorrQ7_norm[k] = CorrQ7[k] >> (-shift_var); - } - } - - /* Find RC coefficients. */ - WebRtcSpl_AutoCorrToReflCoef(CorrQ7_norm, AR_ORDER, RCQ15); - - /* Quantize & code RC Coefficient. */ - WebRtcIsac_EncodeRc(RCQ15, streamdata); - - /* RC -> AR coefficients */ - WebRtcSpl_ReflCoefToLpc(RCQ15, AR_ORDER, ARCoefQ12); - - /* Compute ARCoef' * Corr * ARCoef in Q19. */ - nrg = 0; - for (j = 0; j <= AR_ORDER; j++) { - for (n = 0; n <= j; n++) { - nrg += (ARCoefQ12[j] * ((CorrQ7_norm[j - n] * ARCoefQ12[n] + 256) >> 9) + - 4) >> 3; - } - for (n = j + 1; n <= AR_ORDER; n++) { - nrg += (ARCoefQ12[j] * ((CorrQ7_norm[n - j] * ARCoefQ12[n] + 256) >> 9) + - 4) >> 3; - } - } - - nrg_u32 = (uint32_t)nrg; - if (shift_var > 0) { - nrg_u32 = nrg_u32 >> shift_var; - } else { - nrg_u32 = nrg_u32 << (-shift_var); - } - if (nrg_u32 > 0x7FFFFFFF) { - nrg = 0x7FFFFFFF; - } else { - nrg = (int32_t)nrg_u32; - } - /* Also shifts 31 bits to the left! */ - gain2_Q10 = WebRtcSpl_DivResultInQ31(FRAMESAMPLES_QUARTER, nrg); - - /* Quantize & code gain2_Q10. */ - if (WebRtcIsac_EncodeGain2(&gain2_Q10, streamdata)) { - return -1; - } - - /* Compute inverse AR power spectrum. */ - FindInvArSpec(ARCoefQ12, gain2_Q10, invARSpec2_Q16); - /* Convert to magnitude spectrum, by doing square-roots - * (modified from SPLIB). */ - res = 1 << (WebRtcSpl_GetSizeInBits(invARSpec2_Q16[0]) >> 1); - for (k = 0; k < FRAMESAMPLES_QUARTER; k++) { - in_sqrt = invARSpec2_Q16[k]; - i = 10; - /* Negative values make no sense for a real sqrt-function. */ - if (in_sqrt < 0) { - in_sqrt = -in_sqrt; - } - newRes = (in_sqrt / res + res) >> 1; - do { - res = newRes; - newRes = (in_sqrt / res + res) >> 1; - } while (newRes != res && i-- > 0); - - invARSpecQ8[k] = (int16_t)newRes; - } - /* arithmetic coding of spectrum */ - err = WebRtcIsac_EncLogisticMulti2(streamdata, dataQ7, invARSpecQ8, - num_dft_coeff, is_12khz); - if (err < 0) { - return (err); - } - return 0; -} - - -/* step-up */ -void WebRtcIsac_Rc2Poly(double* RC, int N, double* a) { - int m, k; - double tmp[MAX_AR_MODEL_ORDER]; - - a[0] = 1.0; - tmp[0] = 1.0; - for (m = 1; m <= N; m++) { - /* copy */ - memcpy(&tmp[1], &a[1], (m - 1) * sizeof(double)); - a[m] = RC[m - 1]; - for (k = 1; k < m; k++) { - a[k] += RC[m - 1] * tmp[m - k]; - } - } - return; -} - -/* step-down */ -void WebRtcIsac_Poly2Rc(double* a, int N, double* RC) { - int m, k; - double tmp[MAX_AR_MODEL_ORDER]; - double tmp_inv; - - RC[N - 1] = a[N]; - for (m = N - 1; m > 0; m--) { - tmp_inv = 1.0 / (1.0 - RC[m] * RC[m]); - for (k = 1; k <= m; k++) { - tmp[k] = (a[k] - RC[m] * a[m - k + 1]) * tmp_inv; - } - - memcpy(&a[1], &tmp[1], (m - 1) * sizeof(double)); - RC[m - 1] = tmp[m]; - } - return; -} - - -#define MAX_ORDER 100 - -/* Matlab's LAR definition */ -void WebRtcIsac_Rc2Lar(const double* refc, double* lar, int order) { - int k; - for (k = 0; k < order; k++) { - lar[k] = log((1 + refc[k]) / (1 - refc[k])); - } -} - - -void WebRtcIsac_Lar2Rc(const double* lar, double* refc, int order) { - int k; - double tmp; - - for (k = 0; k < order; k++) { - tmp = exp(lar[k]); - refc[k] = (tmp - 1) / (tmp + 1); - } -} - -void WebRtcIsac_Poly2Lar(double* lowband, int orderLo, double* hiband, - int orderHi, int Nsub, double* lars) { - int k; - double rc[MAX_ORDER], *inpl, *inph, *outp; - - inpl = lowband; - inph = hiband; - outp = lars; - for (k = 0; k < Nsub; k++) { - /* gains */ - outp[0] = inpl[0]; - outp[1] = inph[0]; - outp += 2; - - /* Low band */ - inpl[0] = 1.0; - WebRtcIsac_Poly2Rc(inpl, orderLo, rc); - WebRtcIsac_Rc2Lar(rc, outp, orderLo); - outp += orderLo; - - /* High band */ - inph[0] = 1.0; - WebRtcIsac_Poly2Rc(inph, orderHi, rc); - WebRtcIsac_Rc2Lar(rc, outp, orderHi); - outp += orderHi; - - inpl += orderLo + 1; - inph += orderHi + 1; - } -} - - -int16_t WebRtcIsac_Poly2LarUB(double* lpcVecs, int16_t bandwidth) { - double poly[MAX_ORDER]; - double rc[MAX_ORDER]; - double* ptrIO; - int16_t vecCntr; - int16_t vecSize; - int16_t numVec; - - vecSize = UB_LPC_ORDER; - switch (bandwidth) { - case isac12kHz: { - numVec = UB_LPC_VEC_PER_FRAME; - break; - } - case isac16kHz: { - numVec = UB16_LPC_VEC_PER_FRAME; - break; - } - default: - return -1; - } - - ptrIO = lpcVecs; - poly[0] = 1.0; - for (vecCntr = 0; vecCntr < numVec; vecCntr++) { - memcpy(&poly[1], ptrIO, sizeof(double) * vecSize); - WebRtcIsac_Poly2Rc(poly, vecSize, rc); - WebRtcIsac_Rc2Lar(rc, ptrIO, vecSize); - ptrIO += vecSize; - } - return 0; -} - - -void WebRtcIsac_Lar2Poly(double* lars, double* lowband, int orderLo, - double* hiband, int orderHi, int Nsub) { - int k, orderTot; - double rc[MAX_ORDER], *outpl, *outph, *inp; - - orderTot = (orderLo + orderHi + 2); - outpl = lowband; - outph = hiband; - /* First two elements of 'inp' store gains*/ - inp = lars; - for (k = 0; k < Nsub; k++) { - /* Low band */ - WebRtcIsac_Lar2Rc(&inp[2], rc, orderLo); - WebRtcIsac_Rc2Poly(rc, orderLo, outpl); - - /* High band */ - WebRtcIsac_Lar2Rc(&inp[orderLo + 2], rc, orderHi); - WebRtcIsac_Rc2Poly(rc, orderHi, outph); - - /* gains */ - outpl[0] = inp[0]; - outph[0] = inp[1]; - - outpl += orderLo + 1; - outph += orderHi + 1; - inp += orderTot; - } -} - -/* - * assumes 2 LAR vectors interpolates to 'numPolyVec' A-polynomials - * Note: 'numPolyVecs' includes the first and the last point of the interval - */ -void WebRtcIsac_Lar2PolyInterpolUB(double* larVecs, double* percepFilterParams, - int numPolyVecs) { - int polyCntr, coeffCntr; - double larInterpol[UB_LPC_ORDER]; - double rc[UB_LPC_ORDER]; - double delta[UB_LPC_ORDER]; - - /* calculate the step-size for linear interpolation coefficients */ - for (coeffCntr = 0; coeffCntr < UB_LPC_ORDER; coeffCntr++) { - delta[coeffCntr] = (larVecs[UB_LPC_ORDER + coeffCntr] - - larVecs[coeffCntr]) / (numPolyVecs - 1); - } - - for (polyCntr = 0; polyCntr < numPolyVecs; polyCntr++) { - for (coeffCntr = 0; coeffCntr < UB_LPC_ORDER; coeffCntr++) { - larInterpol[coeffCntr] = larVecs[coeffCntr] + - delta[coeffCntr] * polyCntr; - } - WebRtcIsac_Lar2Rc(larInterpol, rc, UB_LPC_ORDER); - - /* convert to A-polynomial, the following function returns A[0] = 1; - * which is written where gains had to be written. Then we write the - * gain (outside this function). This way we say a memcpy. */ - WebRtcIsac_Rc2Poly(rc, UB_LPC_ORDER, percepFilterParams); - percepFilterParams += (UB_LPC_ORDER + 1); - } -} - -int WebRtcIsac_DecodeLpc(Bitstr* streamdata, double* LPCCoef_lo, - double* LPCCoef_hi) { - double lars[KLT_ORDER_GAIN + KLT_ORDER_SHAPE]; - int err; - - err = WebRtcIsac_DecodeLpcCoef(streamdata, lars); - if (err < 0) { - return -ISAC_RANGE_ERROR_DECODE_LPC; - } - WebRtcIsac_Lar2Poly(lars, LPCCoef_lo, ORDERLO, LPCCoef_hi, ORDERHI, - SUBFRAMES); - return 0; -} - -int16_t WebRtcIsac_DecodeInterpolLpcUb(Bitstr* streamdata, - double* percepFilterParams, - int16_t bandwidth) { - double lpcCoeff[UB_LPC_ORDER * UB16_LPC_VEC_PER_FRAME]; - int err; - int interpolCntr; - int subframeCntr; - int16_t numSegments; - int16_t numVecPerSegment; - int16_t numGains; - - double percepFilterGains[SUBFRAMES << 1]; - double* ptrOutParam = percepFilterParams; - - err = WebRtcIsac_DecodeLpcCoefUB(streamdata, lpcCoeff, percepFilterGains, - bandwidth); - if (err < 0) { - return -ISAC_RANGE_ERROR_DECODE_LPC; - } - - switch (bandwidth) { - case isac12kHz: { - numGains = SUBFRAMES; - numSegments = UB_LPC_VEC_PER_FRAME - 1; - numVecPerSegment = kLpcVecPerSegmentUb12; - break; - } - case isac16kHz: { - numGains = SUBFRAMES << 1; - numSegments = UB16_LPC_VEC_PER_FRAME - 1; - numVecPerSegment = kLpcVecPerSegmentUb16; - break; - } - default: - return -1; - } - - for (interpolCntr = 0; interpolCntr < numSegments; interpolCntr++) { - WebRtcIsac_Lar2PolyInterpolUB(&lpcCoeff[interpolCntr * UB_LPC_ORDER], - ptrOutParam, numVecPerSegment + 1); - ptrOutParam += (numVecPerSegment * (UB_LPC_ORDER + 1)); - } - - ptrOutParam = percepFilterParams; - - if (bandwidth == isac16kHz) { - ptrOutParam += (1 + UB_LPC_ORDER); - } - - for (subframeCntr = 0; subframeCntr < numGains; subframeCntr++) { - *ptrOutParam = percepFilterGains[subframeCntr]; - ptrOutParam += (1 + UB_LPC_ORDER); - } - return 0; -} - - -/* decode & dequantize LPC Coef */ -int WebRtcIsac_DecodeLpcCoef(Bitstr* streamdata, double* LPCCoef) { - int j, k, n, pos, pos2, posg, poss, offsg, offss, offs2; - int index_g[KLT_ORDER_GAIN], index_s[KLT_ORDER_SHAPE]; - double tmpcoeffs_g[KLT_ORDER_GAIN], tmpcoeffs_s[KLT_ORDER_SHAPE]; - double tmpcoeffs2_g[KLT_ORDER_GAIN], tmpcoeffs2_s[KLT_ORDER_SHAPE]; - double sum; - int err; - int model = 1; - - /* entropy decoding of model number */ - /* We are keeping this for backward compatibility of bit-streams. */ - err = WebRtcIsac_DecHistOneStepMulti(&model, streamdata, - WebRtcIsac_kQKltModelCdfPtr, - WebRtcIsac_kQKltModelInitIndex, 1); - if (err < 0) { - return err; - } - /* Only accepted value of model is 0. It is kept in bit-stream for backward - * compatibility. */ - if (model != 0) { - return -ISAC_DISALLOWED_LPC_MODEL; - } - - /* entropy decoding of quantization indices */ - err = WebRtcIsac_DecHistOneStepMulti( - index_s, streamdata, WebRtcIsac_kQKltCdfPtrShape, - WebRtcIsac_kQKltInitIndexShape, KLT_ORDER_SHAPE); - if (err < 0) { - return err; - } - err = WebRtcIsac_DecHistOneStepMulti( - index_g, streamdata, WebRtcIsac_kQKltCdfPtrGain, - WebRtcIsac_kQKltInitIndexGain, KLT_ORDER_GAIN); - if (err < 0) { - return err; - } - - /* find quantization levels for coefficients */ - for (k = 0; k < KLT_ORDER_SHAPE; k++) { - tmpcoeffs_s[k] = - WebRtcIsac_kQKltLevelsShape[WebRtcIsac_kQKltOffsetShape[k] + - index_s[k]]; - } - for (k = 0; k < KLT_ORDER_GAIN; k++) { - tmpcoeffs_g[k] = WebRtcIsac_kQKltLevelsGain[WebRtcIsac_kQKltOffsetGain[k] + - index_g[k]]; - } - - /* Inverse KLT */ - - /* Left transform, transpose matrix! */ - offsg = 0; - offss = 0; - posg = 0; - poss = 0; - for (j = 0; j < SUBFRAMES; j++) { - offs2 = 0; - for (k = 0; k < LPC_GAIN_ORDER; k++) { - sum = 0; - pos = offsg; - pos2 = offs2; - for (n = 0; n < LPC_GAIN_ORDER; n++) { - sum += tmpcoeffs_g[pos++] * WebRtcIsac_kKltT1Gain[pos2++]; - } - tmpcoeffs2_g[posg++] = sum; - offs2 += LPC_GAIN_ORDER; - } - offs2 = 0; - for (k = 0; k < LPC_SHAPE_ORDER; k++) { - sum = 0; - pos = offss; - pos2 = offs2; - for (n = 0; n < LPC_SHAPE_ORDER; n++) { - sum += tmpcoeffs_s[pos++] * WebRtcIsac_kKltT1Shape[pos2++]; - } - tmpcoeffs2_s[poss++] = sum; - offs2 += LPC_SHAPE_ORDER; - } - offsg += LPC_GAIN_ORDER; - offss += LPC_SHAPE_ORDER; - } - - /* Right transform, transpose matrix */ - offsg = 0; - offss = 0; - posg = 0; - poss = 0; - for (j = 0; j < SUBFRAMES; j++) { - posg = offsg; - for (k = 0; k < LPC_GAIN_ORDER; k++) { - sum = 0; - pos = k; - pos2 = j; - for (n = 0; n < SUBFRAMES; n++) { - sum += tmpcoeffs2_g[pos] * WebRtcIsac_kKltT2Gain[pos2]; - pos += LPC_GAIN_ORDER; - pos2 += SUBFRAMES; - - } - tmpcoeffs_g[posg++] = sum; - } - poss = offss; - for (k = 0; k < LPC_SHAPE_ORDER; k++) { - sum = 0; - pos = k; - pos2 = j; - for (n = 0; n < SUBFRAMES; n++) { - sum += tmpcoeffs2_s[pos] * WebRtcIsac_kKltT2Shape[pos2]; - pos += LPC_SHAPE_ORDER; - pos2 += SUBFRAMES; - } - tmpcoeffs_s[poss++] = sum; - } - offsg += LPC_GAIN_ORDER; - offss += LPC_SHAPE_ORDER; - } - - /* scaling, mean addition, and gain restoration */ - posg = 0; - poss = 0; - pos = 0; - for (k = 0; k < SUBFRAMES; k++) { - /* log gains */ - LPCCoef[pos] = tmpcoeffs_g[posg] / LPC_GAIN_SCALE; - LPCCoef[pos] += WebRtcIsac_kLpcMeansGain[posg]; - LPCCoef[pos] = exp(LPCCoef[pos]); - pos++; - posg++; - LPCCoef[pos] = tmpcoeffs_g[posg] / LPC_GAIN_SCALE; - LPCCoef[pos] += WebRtcIsac_kLpcMeansGain[posg]; - LPCCoef[pos] = exp(LPCCoef[pos]); - pos++; - posg++; - - /* Low-band LAR coefficients. */ - for (n = 0; n < LPC_LOBAND_ORDER; n++, pos++, poss++) { - LPCCoef[pos] = tmpcoeffs_s[poss] / LPC_LOBAND_SCALE; - LPCCoef[pos] += WebRtcIsac_kLpcMeansShape[poss]; - } - - /* High-band LAR coefficients. */ - for (n = 0; n < LPC_HIBAND_ORDER; n++, pos++, poss++) { - LPCCoef[pos] = tmpcoeffs_s[poss] / LPC_HIBAND_SCALE; - LPCCoef[pos] += WebRtcIsac_kLpcMeansShape[poss]; - } - } - return 0; -} - -/* Encode LPC in LAR domain. */ -void WebRtcIsac_EncodeLar(double* LPCCoef, Bitstr* streamdata, - IsacSaveEncoderData* encData) { - int j, k, n, pos, pos2, poss, offss, offs2; - int index_s[KLT_ORDER_SHAPE]; - int index_ovr_s[KLT_ORDER_SHAPE]; - double tmpcoeffs_s[KLT_ORDER_SHAPE]; - double tmpcoeffs2_s[KLT_ORDER_SHAPE]; - double sum; - const int kModel = 0; - - /* Mean removal and scaling. */ - poss = 0; - pos = 0; - for (k = 0; k < SUBFRAMES; k++) { - /* First two element are gains, move over them. */ - pos += 2; - - /* Low-band LAR coefficients. */ - for (n = 0; n < LPC_LOBAND_ORDER; n++, poss++, pos++) { - tmpcoeffs_s[poss] = LPCCoef[pos] - WebRtcIsac_kLpcMeansShape[poss]; - tmpcoeffs_s[poss] *= LPC_LOBAND_SCALE; - } - - /* High-band LAR coefficients. */ - for (n = 0; n < LPC_HIBAND_ORDER; n++, poss++, pos++) { - tmpcoeffs_s[poss] = LPCCoef[pos] - WebRtcIsac_kLpcMeansShape[poss]; - tmpcoeffs_s[poss] *= LPC_HIBAND_SCALE; - } - } - - /* KLT */ - - /* Left transform. */ - offss = 0; - for (j = 0; j < SUBFRAMES; j++) { - poss = offss; - for (k = 0; k < LPC_SHAPE_ORDER; k++) { - sum = 0; - pos = offss; - pos2 = k; - for (n = 0; n < LPC_SHAPE_ORDER; n++) { - sum += tmpcoeffs_s[pos++] * WebRtcIsac_kKltT1Shape[pos2]; - pos2 += LPC_SHAPE_ORDER; - } - tmpcoeffs2_s[poss++] = sum; - } - offss += LPC_SHAPE_ORDER; - } - - /* Right transform. */ - offss = 0; - offs2 = 0; - for (j = 0; j < SUBFRAMES; j++) { - poss = offss; - for (k = 0; k < LPC_SHAPE_ORDER; k++) { - sum = 0; - pos = k; - pos2 = offs2; - for (n = 0; n < SUBFRAMES; n++) { - sum += tmpcoeffs2_s[pos] * WebRtcIsac_kKltT2Shape[pos2++]; - pos += LPC_SHAPE_ORDER; - } - tmpcoeffs_s[poss++] = sum; - } - offs2 += SUBFRAMES; - offss += LPC_SHAPE_ORDER; - } - - /* Quantize coefficients. */ - for (k = 0; k < KLT_ORDER_SHAPE; k++) { - index_s[k] = (WebRtcIsac_lrint(tmpcoeffs_s[k] / KLT_STEPSIZE)) + - WebRtcIsac_kQKltQuantMinShape[k]; - if (index_s[k] < 0) { - index_s[k] = 0; - } else if (index_s[k] > WebRtcIsac_kQKltMaxIndShape[k]) { - index_s[k] = WebRtcIsac_kQKltMaxIndShape[k]; - } - index_ovr_s[k] = WebRtcIsac_kQKltOffsetShape[k] + index_s[k]; - } - - - /* Only one model remains in this version of the code, kModel = 0. We - * are keeping for bit-streams to be backward compatible. */ - /* entropy coding of model number */ - WebRtcIsac_EncHistMulti(streamdata, &kModel, WebRtcIsac_kQKltModelCdfPtr, 1); - - /* Save data for creation of multiple bit streams */ - /* Entropy coding of quantization indices - shape only. */ - WebRtcIsac_EncHistMulti(streamdata, index_s, WebRtcIsac_kQKltCdfPtrShape, - KLT_ORDER_SHAPE); - - /* Save data for creation of multiple bit streams. */ - for (k = 0; k < KLT_ORDER_SHAPE; k++) { - encData->LPCindex_s[KLT_ORDER_SHAPE * encData->startIdx + k] = index_s[k]; - } - - /* Find quantization levels for shape coefficients. */ - for (k = 0; k < KLT_ORDER_SHAPE; k++) { - tmpcoeffs_s[k] = WebRtcIsac_kQKltLevelsShape[index_ovr_s[k]]; - } - /* Inverse KLT. */ - /* Left transform, transpose matrix.! */ - offss = 0; - poss = 0; - for (j = 0; j < SUBFRAMES; j++) { - offs2 = 0; - for (k = 0; k < LPC_SHAPE_ORDER; k++) { - sum = 0; - pos = offss; - pos2 = offs2; - for (n = 0; n < LPC_SHAPE_ORDER; n++) { - sum += tmpcoeffs_s[pos++] * WebRtcIsac_kKltT1Shape[pos2++]; - } - tmpcoeffs2_s[poss++] = sum; - offs2 += LPC_SHAPE_ORDER; - } - offss += LPC_SHAPE_ORDER; - } - - /* Right transform, Transpose matrix */ - offss = 0; - poss = 0; - for (j = 0; j < SUBFRAMES; j++) { - poss = offss; - for (k = 0; k < LPC_SHAPE_ORDER; k++) { - sum = 0; - pos = k; - pos2 = j; - for (n = 0; n < SUBFRAMES; n++) { - sum += tmpcoeffs2_s[pos] * WebRtcIsac_kKltT2Shape[pos2]; - pos += LPC_SHAPE_ORDER; - pos2 += SUBFRAMES; - } - tmpcoeffs_s[poss++] = sum; - } - offss += LPC_SHAPE_ORDER; - } - - /* Scaling, mean addition, and gain restoration. */ - poss = 0; - pos = 0; - for (k = 0; k < SUBFRAMES; k++) { - /* Ignore gains. */ - pos += 2; - - /* Low band LAR coefficients. */ - for (n = 0; n < LPC_LOBAND_ORDER; n++, pos++, poss++) { - LPCCoef[pos] = tmpcoeffs_s[poss] / LPC_LOBAND_SCALE; - LPCCoef[pos] += WebRtcIsac_kLpcMeansShape[poss]; - } - - /* High band LAR coefficients. */ - for (n = 0; n < LPC_HIBAND_ORDER; n++, pos++, poss++) { - LPCCoef[pos] = tmpcoeffs_s[poss] / LPC_HIBAND_SCALE; - LPCCoef[pos] += WebRtcIsac_kLpcMeansShape[poss]; - } - } -} - - -void WebRtcIsac_EncodeLpcLb(double* LPCCoef_lo, double* LPCCoef_hi, - Bitstr* streamdata, IsacSaveEncoderData* encData) { - double lars[KLT_ORDER_GAIN + KLT_ORDER_SHAPE]; - int k; - - WebRtcIsac_Poly2Lar(LPCCoef_lo, ORDERLO, LPCCoef_hi, ORDERHI, SUBFRAMES, - lars); - WebRtcIsac_EncodeLar(lars, streamdata, encData); - WebRtcIsac_Lar2Poly(lars, LPCCoef_lo, ORDERLO, LPCCoef_hi, ORDERHI, - SUBFRAMES); - /* Save data for creation of multiple bit streams (and transcoding). */ - for (k = 0; k < (ORDERLO + 1)*SUBFRAMES; k++) { - encData->LPCcoeffs_lo[(ORDERLO + 1)*SUBFRAMES * encData->startIdx + k] = - LPCCoef_lo[k]; - } - for (k = 0; k < (ORDERHI + 1)*SUBFRAMES; k++) { - encData->LPCcoeffs_hi[(ORDERHI + 1)*SUBFRAMES * encData->startIdx + k] = - LPCCoef_hi[k]; - } -} - - -int16_t WebRtcIsac_EncodeLpcUB(double* lpcVecs, Bitstr* streamdata, - double* interpolLPCCoeff, - int16_t bandwidth, - ISACUBSaveEncDataStruct* encData) { - double U[UB_LPC_ORDER * UB16_LPC_VEC_PER_FRAME]; - int idx[UB_LPC_ORDER * UB16_LPC_VEC_PER_FRAME]; - int interpolCntr; - - WebRtcIsac_Poly2LarUB(lpcVecs, bandwidth); - WebRtcIsac_RemoveLarMean(lpcVecs, bandwidth); - WebRtcIsac_DecorrelateIntraVec(lpcVecs, U, bandwidth); - WebRtcIsac_DecorrelateInterVec(U, lpcVecs, bandwidth); - WebRtcIsac_QuantizeUncorrLar(lpcVecs, idx, bandwidth); - - WebRtcIsac_CorrelateInterVec(lpcVecs, U, bandwidth); - WebRtcIsac_CorrelateIntraVec(U, lpcVecs, bandwidth); - WebRtcIsac_AddLarMean(lpcVecs, bandwidth); - - switch (bandwidth) { - case isac12kHz: { - /* Store the indices to be used for multiple encoding. */ - memcpy(encData->indexLPCShape, idx, UB_LPC_ORDER * - UB_LPC_VEC_PER_FRAME * sizeof(int)); - WebRtcIsac_EncHistMulti(streamdata, idx, WebRtcIsac_kLpcShapeCdfMatUb12, - UB_LPC_ORDER * UB_LPC_VEC_PER_FRAME); - for (interpolCntr = 0; interpolCntr < UB_INTERPOL_SEGMENTS; - interpolCntr++) { - WebRtcIsac_Lar2PolyInterpolUB(lpcVecs, interpolLPCCoeff, - kLpcVecPerSegmentUb12 + 1); - lpcVecs += UB_LPC_ORDER; - interpolLPCCoeff += (kLpcVecPerSegmentUb12 * (UB_LPC_ORDER + 1)); - } - break; - } - case isac16kHz: { - /* Store the indices to be used for multiple encoding. */ - memcpy(encData->indexLPCShape, idx, UB_LPC_ORDER * - UB16_LPC_VEC_PER_FRAME * sizeof(int)); - WebRtcIsac_EncHistMulti(streamdata, idx, WebRtcIsac_kLpcShapeCdfMatUb16, - UB_LPC_ORDER * UB16_LPC_VEC_PER_FRAME); - for (interpolCntr = 0; interpolCntr < UB16_INTERPOL_SEGMENTS; - interpolCntr++) { - WebRtcIsac_Lar2PolyInterpolUB(lpcVecs, interpolLPCCoeff, - kLpcVecPerSegmentUb16 + 1); - lpcVecs += UB_LPC_ORDER; - interpolLPCCoeff += (kLpcVecPerSegmentUb16 * (UB_LPC_ORDER + 1)); - } - break; - } - default: - return -1; - } - return 0; -} - -void WebRtcIsac_EncodeLpcGainLb(double* LPCCoef_lo, double* LPCCoef_hi, - Bitstr* streamdata, - IsacSaveEncoderData* encData) { - int j, k, n, pos, pos2, posg, offsg, offs2; - int index_g[KLT_ORDER_GAIN]; - int index_ovr_g[KLT_ORDER_GAIN]; - double tmpcoeffs_g[KLT_ORDER_GAIN]; - double tmpcoeffs2_g[KLT_ORDER_GAIN]; - double sum; - /* log gains, mean removal and scaling */ - posg = 0; - for (k = 0; k < SUBFRAMES; k++) { - tmpcoeffs_g[posg] = log(LPCCoef_lo[(LPC_LOBAND_ORDER + 1) * k]); - tmpcoeffs_g[posg] -= WebRtcIsac_kLpcMeansGain[posg]; - tmpcoeffs_g[posg] *= LPC_GAIN_SCALE; - posg++; - tmpcoeffs_g[posg] = log(LPCCoef_hi[(LPC_HIBAND_ORDER + 1) * k]); - tmpcoeffs_g[posg] -= WebRtcIsac_kLpcMeansGain[posg]; - tmpcoeffs_g[posg] *= LPC_GAIN_SCALE; - posg++; - } - - /* KLT */ - - /* Left transform. */ - offsg = 0; - for (j = 0; j < SUBFRAMES; j++) { - posg = offsg; - for (k = 0; k < LPC_GAIN_ORDER; k++) { - sum = 0; - pos = offsg; - pos2 = k; - for (n = 0; n < LPC_GAIN_ORDER; n++) { - sum += tmpcoeffs_g[pos++] * WebRtcIsac_kKltT1Gain[pos2]; - pos2 += LPC_GAIN_ORDER; - } - tmpcoeffs2_g[posg++] = sum; - } - offsg += LPC_GAIN_ORDER; - } - - /* Right transform. */ - offsg = 0; - offs2 = 0; - for (j = 0; j < SUBFRAMES; j++) { - posg = offsg; - for (k = 0; k < LPC_GAIN_ORDER; k++) { - sum = 0; - pos = k; - pos2 = offs2; - for (n = 0; n < SUBFRAMES; n++) { - sum += tmpcoeffs2_g[pos] * WebRtcIsac_kKltT2Gain[pos2++]; - pos += LPC_GAIN_ORDER; - } - tmpcoeffs_g[posg++] = sum; - } - offs2 += SUBFRAMES; - offsg += LPC_GAIN_ORDER; - } - - /* Quantize coefficients. */ - for (k = 0; k < KLT_ORDER_GAIN; k++) { - /* Get index. */ - pos2 = WebRtcIsac_lrint(tmpcoeffs_g[k] / KLT_STEPSIZE); - index_g[k] = (pos2) + WebRtcIsac_kQKltQuantMinGain[k]; - if (index_g[k] < 0) { - index_g[k] = 0; - } else if (index_g[k] > WebRtcIsac_kQKltMaxIndGain[k]) { - index_g[k] = WebRtcIsac_kQKltMaxIndGain[k]; - } - index_ovr_g[k] = WebRtcIsac_kQKltOffsetGain[k] + index_g[k]; - - /* Find quantization levels for coefficients. */ - tmpcoeffs_g[k] = WebRtcIsac_kQKltLevelsGain[index_ovr_g[k]]; - - /* Save data for creation of multiple bit streams. */ - encData->LPCindex_g[KLT_ORDER_GAIN * encData->startIdx + k] = index_g[k]; - } - - /* Entropy coding of quantization indices - gain. */ - WebRtcIsac_EncHistMulti(streamdata, index_g, WebRtcIsac_kQKltCdfPtrGain, - KLT_ORDER_GAIN); - - /* Find quantization levels for coefficients. */ - /* Left transform. */ - offsg = 0; - posg = 0; - for (j = 0; j < SUBFRAMES; j++) { - offs2 = 0; - for (k = 0; k < LPC_GAIN_ORDER; k++) { - sum = 0; - pos = offsg; - pos2 = offs2; - for (n = 0; n < LPC_GAIN_ORDER; n++) - sum += tmpcoeffs_g[pos++] * WebRtcIsac_kKltT1Gain[pos2++]; - tmpcoeffs2_g[posg++] = sum; - offs2 += LPC_GAIN_ORDER; - } - offsg += LPC_GAIN_ORDER; - } - - /* Right transform, transpose matrix. */ - offsg = 0; - posg = 0; - for (j = 0; j < SUBFRAMES; j++) { - posg = offsg; - for (k = 0; k < LPC_GAIN_ORDER; k++) { - sum = 0; - pos = k; - pos2 = j; - for (n = 0; n < SUBFRAMES; n++) { - sum += tmpcoeffs2_g[pos] * WebRtcIsac_kKltT2Gain[pos2]; - pos += LPC_GAIN_ORDER; - pos2 += SUBFRAMES; - } - tmpcoeffs_g[posg++] = sum; - } - offsg += LPC_GAIN_ORDER; - } - - - /* Scaling, mean addition, and gain restoration. */ - posg = 0; - for (k = 0; k < SUBFRAMES; k++) { - sum = tmpcoeffs_g[posg] / LPC_GAIN_SCALE; - sum += WebRtcIsac_kLpcMeansGain[posg]; - LPCCoef_lo[k * (LPC_LOBAND_ORDER + 1)] = exp(sum); - pos++; - posg++; - sum = tmpcoeffs_g[posg] / LPC_GAIN_SCALE; - sum += WebRtcIsac_kLpcMeansGain[posg]; - LPCCoef_hi[k * (LPC_HIBAND_ORDER + 1)] = exp(sum); - pos++; - posg++; - } - -} - -void WebRtcIsac_EncodeLpcGainUb(double* lpGains, Bitstr* streamdata, - int* lpcGainIndex) { - double U[UB_LPC_GAIN_DIM]; - int idx[UB_LPC_GAIN_DIM]; - WebRtcIsac_ToLogDomainRemoveMean(lpGains); - WebRtcIsac_DecorrelateLPGain(lpGains, U); - WebRtcIsac_QuantizeLpcGain(U, idx); - /* Store the index for re-encoding for FEC. */ - memcpy(lpcGainIndex, idx, UB_LPC_GAIN_DIM * sizeof(int)); - WebRtcIsac_CorrelateLpcGain(U, lpGains); - WebRtcIsac_AddMeanToLinearDomain(lpGains); - WebRtcIsac_EncHistMulti(streamdata, idx, WebRtcIsac_kLpcGainCdfMat, - UB_LPC_GAIN_DIM); -} - - -void WebRtcIsac_StoreLpcGainUb(double* lpGains, Bitstr* streamdata) { - double U[UB_LPC_GAIN_DIM]; - int idx[UB_LPC_GAIN_DIM]; - WebRtcIsac_ToLogDomainRemoveMean(lpGains); - WebRtcIsac_DecorrelateLPGain(lpGains, U); - WebRtcIsac_QuantizeLpcGain(U, idx); - WebRtcIsac_EncHistMulti(streamdata, idx, WebRtcIsac_kLpcGainCdfMat, - UB_LPC_GAIN_DIM); -} - - - -int16_t WebRtcIsac_DecodeLpcGainUb(double* lpGains, Bitstr* streamdata) { - double U[UB_LPC_GAIN_DIM]; - int idx[UB_LPC_GAIN_DIM]; - int err; - err = WebRtcIsac_DecHistOneStepMulti(idx, streamdata, - WebRtcIsac_kLpcGainCdfMat, - WebRtcIsac_kLpcGainEntropySearch, - UB_LPC_GAIN_DIM); - if (err < 0) { - return -1; - } - WebRtcIsac_DequantizeLpcGain(idx, U); - WebRtcIsac_CorrelateLpcGain(U, lpGains); - WebRtcIsac_AddMeanToLinearDomain(lpGains); - return 0; -} - - - -/* decode & dequantize RC */ -int WebRtcIsac_DecodeRc(Bitstr* streamdata, int16_t* RCQ15) { - int k, err; - int index[AR_ORDER]; - - /* entropy decoding of quantization indices */ - err = WebRtcIsac_DecHistOneStepMulti(index, streamdata, - WebRtcIsac_kQArRcCdfPtr, - WebRtcIsac_kQArRcInitIndex, AR_ORDER); - if (err < 0) - return err; - - /* find quantization levels for reflection coefficients */ - for (k = 0; k < AR_ORDER; k++) { - RCQ15[k] = *(WebRtcIsac_kQArRcLevelsPtr[k] + index[k]); - } - return 0; -} - - -/* quantize & code RC */ -void WebRtcIsac_EncodeRc(int16_t* RCQ15, Bitstr* streamdata) { - int k; - int index[AR_ORDER]; - - /* quantize reflection coefficients (add noise feedback?) */ - for (k = 0; k < AR_ORDER; k++) { - index[k] = WebRtcIsac_kQArRcInitIndex[k]; - // The safe-guards in following while conditions are to suppress gcc 4.8.3 - // warnings, Issue 2888. Otherwise, first and last elements of - // |WebRtcIsac_kQArBoundaryLevels| are such that the following search - // *never* cause an out-of-boundary read. - if (RCQ15[k] > WebRtcIsac_kQArBoundaryLevels[index[k]]) { - while (index[k] + 1 < NUM_AR_RC_QUANT_BAUNDARY && - RCQ15[k] > WebRtcIsac_kQArBoundaryLevels[index[k] + 1]) { - index[k]++; - } - } else { - while (index[k] > 0 && - RCQ15[k] < WebRtcIsac_kQArBoundaryLevels[--index[k]]) ; - } - RCQ15[k] = *(WebRtcIsac_kQArRcLevelsPtr[k] + index[k]); - } - - /* entropy coding of quantization indices */ - WebRtcIsac_EncHistMulti(streamdata, index, WebRtcIsac_kQArRcCdfPtr, AR_ORDER); -} - - -/* decode & dequantize squared Gain */ -int WebRtcIsac_DecodeGain2(Bitstr* streamdata, int32_t* gainQ10) { - int index, err; - - /* entropy decoding of quantization index */ - err = WebRtcIsac_DecHistOneStepMulti(&index, streamdata, - WebRtcIsac_kQGainCdf_ptr, - WebRtcIsac_kQGainInitIndex, 1); - if (err < 0) { - return err; - } - /* find quantization level */ - *gainQ10 = WebRtcIsac_kQGain2Levels[index]; - return 0; -} - - -/* quantize & code squared Gain */ -int WebRtcIsac_EncodeGain2(int32_t* gainQ10, Bitstr* streamdata) { - int index; - - /* find quantization index */ - index = WebRtcIsac_kQGainInitIndex[0]; - if (*gainQ10 > WebRtcIsac_kQGain2BoundaryLevels[index]) { - while (*gainQ10 > WebRtcIsac_kQGain2BoundaryLevels[index + 1]) { - index++; - } - } else { - while (*gainQ10 < WebRtcIsac_kQGain2BoundaryLevels[--index]) ; - } - /* De-quantize */ - *gainQ10 = WebRtcIsac_kQGain2Levels[index]; - - /* entropy coding of quantization index */ - WebRtcIsac_EncHistMulti(streamdata, &index, WebRtcIsac_kQGainCdf_ptr, 1); - return 0; -} - - -/* code and decode Pitch Gains and Lags functions */ - -/* decode & dequantize Pitch Gains */ -int WebRtcIsac_DecodePitchGain(Bitstr* streamdata, - int16_t* PitchGains_Q12) { - int index_comb, err; - const uint16_t* WebRtcIsac_kQPitchGainCdf_ptr[1]; - - /* Entropy decoding of quantization indices */ - *WebRtcIsac_kQPitchGainCdf_ptr = WebRtcIsac_kQPitchGainCdf; - err = WebRtcIsac_DecHistBisectMulti(&index_comb, streamdata, - WebRtcIsac_kQPitchGainCdf_ptr, - WebRtcIsac_kQCdfTableSizeGain, 1); - /* Error check, Q_mean_Gain.. tables are of size 144 */ - if ((err < 0) || (index_comb < 0) || (index_comb >= 144)) { - return -ISAC_RANGE_ERROR_DECODE_PITCH_GAIN; - } - /* De-quantize back to pitch gains by table look-up. */ - PitchGains_Q12[0] = WebRtcIsac_kQMeanGain1Q12[index_comb]; - PitchGains_Q12[1] = WebRtcIsac_kQMeanGain2Q12[index_comb]; - PitchGains_Q12[2] = WebRtcIsac_kQMeanGain3Q12[index_comb]; - PitchGains_Q12[3] = WebRtcIsac_kQMeanGain4Q12[index_comb]; - return 0; -} - - -/* Quantize & code Pitch Gains. */ -void WebRtcIsac_EncodePitchGain(int16_t* PitchGains_Q12, - Bitstr* streamdata, - IsacSaveEncoderData* encData) { - int k, j; - double C; - double S[PITCH_SUBFRAMES]; - int index[3]; - int index_comb; - const uint16_t* WebRtcIsac_kQPitchGainCdf_ptr[1]; - double PitchGains[PITCH_SUBFRAMES] = {0, 0, 0, 0}; - - /* Take the asin. */ - for (k = 0; k < PITCH_SUBFRAMES; k++) { - PitchGains[k] = ((float)PitchGains_Q12[k]) / 4096; - S[k] = asin(PitchGains[k]); - } - - /* Find quantization index; only for the first three - * transform coefficients. */ - for (k = 0; k < 3; k++) { - /* transform */ - C = 0.0; - for (j = 0; j < PITCH_SUBFRAMES; j++) { - C += WebRtcIsac_kTransform[k][j] * S[j]; - } - /* Quantize */ - index[k] = WebRtcIsac_lrint(C / PITCH_GAIN_STEPSIZE); - - /* Check that the index is not outside the boundaries of the table. */ - if (index[k] < WebRtcIsac_kIndexLowerLimitGain[k]) { - index[k] = WebRtcIsac_kIndexLowerLimitGain[k]; - } else if (index[k] > WebRtcIsac_kIndexUpperLimitGain[k]) { - index[k] = WebRtcIsac_kIndexUpperLimitGain[k]; - } - index[k] -= WebRtcIsac_kIndexLowerLimitGain[k]; - } - - /* Calculate unique overall index. */ - index_comb = WebRtcIsac_kIndexMultsGain[0] * index[0] + - WebRtcIsac_kIndexMultsGain[1] * index[1] + index[2]; - - /* unquantize back to pitch gains by table look-up */ - PitchGains_Q12[0] = WebRtcIsac_kQMeanGain1Q12[index_comb]; - PitchGains_Q12[1] = WebRtcIsac_kQMeanGain2Q12[index_comb]; - PitchGains_Q12[2] = WebRtcIsac_kQMeanGain3Q12[index_comb]; - PitchGains_Q12[3] = WebRtcIsac_kQMeanGain4Q12[index_comb]; - - /* entropy coding of quantization pitch gains */ - *WebRtcIsac_kQPitchGainCdf_ptr = WebRtcIsac_kQPitchGainCdf; - WebRtcIsac_EncHistMulti(streamdata, &index_comb, - WebRtcIsac_kQPitchGainCdf_ptr, 1); - encData->pitchGain_index[encData->startIdx] = index_comb; -} - - - -/* Pitch LAG */ -/* Decode & de-quantize Pitch Lags. */ -int WebRtcIsac_DecodePitchLag(Bitstr* streamdata, int16_t* PitchGain_Q12, - double* PitchLags) { - int k, err; - double StepSize; - double C; - int index[PITCH_SUBFRAMES]; - double mean_gain; - const double* mean_val2, *mean_val3, *mean_val4; - const int16_t* lower_limit; - const uint16_t* init_index; - const uint16_t* cdf_size; - const uint16_t** cdf; - double PitchGain[4] = {0, 0, 0, 0}; - - /* compute mean pitch gain */ - mean_gain = 0.0; - for (k = 0; k < 4; k++) { - PitchGain[k] = ((float)PitchGain_Q12[k]) / 4096; - mean_gain += PitchGain[k]; - } - mean_gain /= 4.0; - - /* voicing classification. */ - if (mean_gain < 0.2) { - StepSize = WebRtcIsac_kQPitchLagStepsizeLo; - cdf = WebRtcIsac_kQPitchLagCdfPtrLo; - cdf_size = WebRtcIsac_kQPitchLagCdfSizeLo; - mean_val2 = WebRtcIsac_kQMeanLag2Lo; - mean_val3 = WebRtcIsac_kQMeanLag3Lo; - mean_val4 = WebRtcIsac_kQMeanLag4Lo; - lower_limit = WebRtcIsac_kQIndexLowerLimitLagLo; - init_index = WebRtcIsac_kQInitIndexLagLo; - } else if (mean_gain < 0.4) { - StepSize = WebRtcIsac_kQPitchLagStepsizeMid; - cdf = WebRtcIsac_kQPitchLagCdfPtrMid; - cdf_size = WebRtcIsac_kQPitchLagCdfSizeMid; - mean_val2 = WebRtcIsac_kQMeanLag2Mid; - mean_val3 = WebRtcIsac_kQMeanLag3Mid; - mean_val4 = WebRtcIsac_kQMeanLag4Mid; - lower_limit = WebRtcIsac_kQIndexLowerLimitLagMid; - init_index = WebRtcIsac_kQInitIndexLagMid; - } else { - StepSize = WebRtcIsac_kQPitchLagStepsizeHi; - cdf = WebRtcIsac_kQPitchLagCdfPtrHi; - cdf_size = WebRtcIsac_kQPitchLagCdfSizeHi; - mean_val2 = WebRtcIsac_kQMeanLag2Hi; - mean_val3 = WebRtcIsac_kQMeanLag3Hi; - mean_val4 = WebRtcIsac_kQMeanLag4Hi; - lower_limit = WebRtcIsac_kQindexLowerLimitLagHi; - init_index = WebRtcIsac_kQInitIndexLagHi; - } - - /* Entropy decoding of quantization indices. */ - err = WebRtcIsac_DecHistBisectMulti(index, streamdata, cdf, cdf_size, 1); - if ((err < 0) || (index[0] < 0)) { - return -ISAC_RANGE_ERROR_DECODE_PITCH_LAG; - } - err = WebRtcIsac_DecHistOneStepMulti(index + 1, streamdata, cdf + 1, - init_index, 3); - if (err < 0) { - return -ISAC_RANGE_ERROR_DECODE_PITCH_LAG; - } - - /* Unquantize back to transform coefficients and do the inverse transform: - * S = T'*C. */ - C = (index[0] + lower_limit[0]) * StepSize; - for (k = 0; k < PITCH_SUBFRAMES; k++) { - PitchLags[k] = WebRtcIsac_kTransformTranspose[k][0] * C; - } - C = mean_val2[index[1]]; - for (k = 0; k < PITCH_SUBFRAMES; k++) { - PitchLags[k] += WebRtcIsac_kTransformTranspose[k][1] * C; - } - C = mean_val3[index[2]]; - for (k = 0; k < PITCH_SUBFRAMES; k++) { - PitchLags[k] += WebRtcIsac_kTransformTranspose[k][2] * C; - } - C = mean_val4[index[3]]; - for (k = 0; k < PITCH_SUBFRAMES; k++) { - PitchLags[k] += WebRtcIsac_kTransformTranspose[k][3] * C; - } - return 0; -} - - - -/* Quantize & code pitch lags. */ -void WebRtcIsac_EncodePitchLag(double* PitchLags, int16_t* PitchGain_Q12, - Bitstr* streamdata, - IsacSaveEncoderData* encData) { - int k, j; - double StepSize; - double C; - int index[PITCH_SUBFRAMES]; - double mean_gain; - const double* mean_val2, *mean_val3, *mean_val4; - const int16_t* lower_limit, *upper_limit; - const uint16_t** cdf; - double PitchGain[4] = {0, 0, 0, 0}; - - /* compute mean pitch gain */ - mean_gain = 0.0; - for (k = 0; k < 4; k++) { - PitchGain[k] = ((float)PitchGain_Q12[k]) / 4096; - mean_gain += PitchGain[k]; - } - mean_gain /= 4.0; - - /* Save data for creation of multiple bit streams */ - encData->meanGain[encData->startIdx] = mean_gain; - - /* Voicing classification. */ - if (mean_gain < 0.2) { - StepSize = WebRtcIsac_kQPitchLagStepsizeLo; - cdf = WebRtcIsac_kQPitchLagCdfPtrLo; - mean_val2 = WebRtcIsac_kQMeanLag2Lo; - mean_val3 = WebRtcIsac_kQMeanLag3Lo; - mean_val4 = WebRtcIsac_kQMeanLag4Lo; - lower_limit = WebRtcIsac_kQIndexLowerLimitLagLo; - upper_limit = WebRtcIsac_kQIndexUpperLimitLagLo; - } else if (mean_gain < 0.4) { - StepSize = WebRtcIsac_kQPitchLagStepsizeMid; - cdf = WebRtcIsac_kQPitchLagCdfPtrMid; - mean_val2 = WebRtcIsac_kQMeanLag2Mid; - mean_val3 = WebRtcIsac_kQMeanLag3Mid; - mean_val4 = WebRtcIsac_kQMeanLag4Mid; - lower_limit = WebRtcIsac_kQIndexLowerLimitLagMid; - upper_limit = WebRtcIsac_kQIndexUpperLimitLagMid; - } else { - StepSize = WebRtcIsac_kQPitchLagStepsizeHi; - cdf = WebRtcIsac_kQPitchLagCdfPtrHi; - mean_val2 = WebRtcIsac_kQMeanLag2Hi; - mean_val3 = WebRtcIsac_kQMeanLag3Hi; - mean_val4 = WebRtcIsac_kQMeanLag4Hi; - lower_limit = WebRtcIsac_kQindexLowerLimitLagHi; - upper_limit = WebRtcIsac_kQindexUpperLimitLagHi; - } - - /* find quantization index */ - for (k = 0; k < 4; k++) { - /* transform */ - C = 0.0; - for (j = 0; j < PITCH_SUBFRAMES; j++) { - C += WebRtcIsac_kTransform[k][j] * PitchLags[j]; - } - /* quantize */ - index[k] = WebRtcIsac_lrint(C / StepSize); - - /* check that the index is not outside the boundaries of the table */ - if (index[k] < lower_limit[k]) { - index[k] = lower_limit[k]; - } else if (index[k] > upper_limit[k]) index[k] = upper_limit[k]; { - index[k] -= lower_limit[k]; - } - /* Save data for creation of multiple bit streams */ - encData->pitchIndex[PITCH_SUBFRAMES * encData->startIdx + k] = index[k]; - } - - /* Un-quantize back to transform coefficients and do the inverse transform: - * S = T'*C */ - C = (index[0] + lower_limit[0]) * StepSize; - for (k = 0; k < PITCH_SUBFRAMES; k++) { - PitchLags[k] = WebRtcIsac_kTransformTranspose[k][0] * C; - } - C = mean_val2[index[1]]; - for (k = 0; k < PITCH_SUBFRAMES; k++) { - PitchLags[k] += WebRtcIsac_kTransformTranspose[k][1] * C; - } - C = mean_val3[index[2]]; - for (k = 0; k < PITCH_SUBFRAMES; k++) { - PitchLags[k] += WebRtcIsac_kTransformTranspose[k][2] * C; - } - C = mean_val4[index[3]]; - for (k = 0; k < PITCH_SUBFRAMES; k++) { - PitchLags[k] += WebRtcIsac_kTransformTranspose[k][3] * C; - } - /* entropy coding of quantization pitch lags */ - WebRtcIsac_EncHistMulti(streamdata, index, cdf, PITCH_SUBFRAMES); -} - - - -/* Routines for in-band signaling of bandwidth estimation */ -/* Histograms based on uniform distribution of indices */ -/* Move global variables later! */ - - -/* cdf array for frame length indicator */ -const uint16_t WebRtcIsac_kFrameLengthCdf[4] = { - 0, 21845, 43690, 65535 }; - -/* pointer to cdf array for frame length indicator */ -const uint16_t* WebRtcIsac_kFrameLengthCdf_ptr[1] = { - WebRtcIsac_kFrameLengthCdf }; - -/* initial cdf index for decoder of frame length indicator */ -const uint16_t WebRtcIsac_kFrameLengthInitIndex[1] = { 1 }; - - -int WebRtcIsac_DecodeFrameLen(Bitstr* streamdata, int16_t* framesamples) { - int frame_mode, err; - err = 0; - /* entropy decoding of frame length [1:30ms,2:60ms] */ - err = WebRtcIsac_DecHistOneStepMulti(&frame_mode, streamdata, - WebRtcIsac_kFrameLengthCdf_ptr, - WebRtcIsac_kFrameLengthInitIndex, 1); - if (err < 0) - return -ISAC_RANGE_ERROR_DECODE_FRAME_LENGTH; - - switch (frame_mode) { - case 1: - *framesamples = 480; /* 30ms */ - break; - case 2: - *framesamples = 960; /* 60ms */ - break; - default: - err = -ISAC_DISALLOWED_FRAME_MODE_DECODER; - } - return err; -} - -int WebRtcIsac_EncodeFrameLen(int16_t framesamples, Bitstr* streamdata) { - int frame_mode, status; - - status = 0; - frame_mode = 0; - /* entropy coding of frame length [1:480 samples,2:960 samples] */ - switch (framesamples) { - case 480: - frame_mode = 1; - break; - case 960: - frame_mode = 2; - break; - default: - status = - ISAC_DISALLOWED_FRAME_MODE_ENCODER; - } - - if (status < 0) - return status; - - WebRtcIsac_EncHistMulti(streamdata, &frame_mode, - WebRtcIsac_kFrameLengthCdf_ptr, 1); - return status; -} - -/* cdf array for estimated bandwidth */ -static const uint16_t kBwCdf[25] = { - 0, 2731, 5461, 8192, 10923, 13653, 16384, 19114, 21845, 24576, 27306, 30037, - 32768, 35498, 38229, 40959, 43690, 46421, 49151, 51882, 54613, 57343, 60074, - 62804, 65535 }; - -/* pointer to cdf array for estimated bandwidth */ -static const uint16_t* const kBwCdfPtr[1] = { kBwCdf }; - -/* initial cdf index for decoder of estimated bandwidth*/ -static const uint16_t kBwInitIndex[1] = { 7 }; - - -int WebRtcIsac_DecodeSendBW(Bitstr* streamdata, int16_t* BWno) { - int BWno32, err; - - /* entropy decoding of sender's BW estimation [0..23] */ - err = WebRtcIsac_DecHistOneStepMulti(&BWno32, streamdata, kBwCdfPtr, - kBwInitIndex, 1); - if (err < 0) { - return -ISAC_RANGE_ERROR_DECODE_BANDWIDTH; - } - *BWno = (int16_t)BWno32; - return err; -} - -void WebRtcIsac_EncodeReceiveBw(int* BWno, Bitstr* streamdata) { - /* entropy encoding of receiver's BW estimation [0..23] */ - WebRtcIsac_EncHistMulti(streamdata, BWno, kBwCdfPtr, 1); -} - - -/* estimate code length of LPC Coef */ -void WebRtcIsac_TranscodeLPCCoef(double* LPCCoef_lo, double* LPCCoef_hi, - int* index_g) { - int j, k, n, pos, pos2, posg, offsg, offs2; - int index_ovr_g[KLT_ORDER_GAIN]; - double tmpcoeffs_g[KLT_ORDER_GAIN]; - double tmpcoeffs2_g[KLT_ORDER_GAIN]; - double sum; - - /* log gains, mean removal and scaling */ - posg = 0; - for (k = 0; k < SUBFRAMES; k++) { - tmpcoeffs_g[posg] = log(LPCCoef_lo[(LPC_LOBAND_ORDER + 1) * k]); - tmpcoeffs_g[posg] -= WebRtcIsac_kLpcMeansGain[posg]; - tmpcoeffs_g[posg] *= LPC_GAIN_SCALE; - posg++; - tmpcoeffs_g[posg] = log(LPCCoef_hi[(LPC_HIBAND_ORDER + 1) * k]); - tmpcoeffs_g[posg] -= WebRtcIsac_kLpcMeansGain[posg]; - tmpcoeffs_g[posg] *= LPC_GAIN_SCALE; - posg++; - } - - /* KLT */ - - /* Left transform. */ - offsg = 0; - for (j = 0; j < SUBFRAMES; j++) { - posg = offsg; - for (k = 0; k < LPC_GAIN_ORDER; k++) { - sum = 0; - pos = offsg; - pos2 = k; - for (n = 0; n < LPC_GAIN_ORDER; n++) { - sum += tmpcoeffs_g[pos++] * WebRtcIsac_kKltT1Gain[pos2]; - pos2 += LPC_GAIN_ORDER; - } - tmpcoeffs2_g[posg++] = sum; - } - offsg += LPC_GAIN_ORDER; - } - - /* Right transform. */ - offsg = 0; - offs2 = 0; - for (j = 0; j < SUBFRAMES; j++) { - posg = offsg; - for (k = 0; k < LPC_GAIN_ORDER; k++) { - sum = 0; - pos = k; - pos2 = offs2; - for (n = 0; n < SUBFRAMES; n++) { - sum += tmpcoeffs2_g[pos] * WebRtcIsac_kKltT2Gain[pos2++]; - pos += LPC_GAIN_ORDER; - } - tmpcoeffs_g[posg++] = sum; - } - offs2 += SUBFRAMES; - offsg += LPC_GAIN_ORDER; - } - - - /* quantize coefficients */ - for (k = 0; k < KLT_ORDER_GAIN; k++) { - /* Get index. */ - pos2 = WebRtcIsac_lrint(tmpcoeffs_g[k] / KLT_STEPSIZE); - index_g[k] = (pos2) + WebRtcIsac_kQKltQuantMinGain[k]; - if (index_g[k] < 0) { - index_g[k] = 0; - } else if (index_g[k] > WebRtcIsac_kQKltMaxIndGain[k]) { - index_g[k] = WebRtcIsac_kQKltMaxIndGain[k]; - } - index_ovr_g[k] = WebRtcIsac_kQKltOffsetGain[k] + index_g[k]; - - /* find quantization levels for coefficients */ - tmpcoeffs_g[k] = WebRtcIsac_kQKltLevelsGain[index_ovr_g[k]]; - } -} - - -/* Decode & de-quantize LPC Coefficients. */ -int WebRtcIsac_DecodeLpcCoefUB(Bitstr* streamdata, double* lpcVecs, - double* percepFilterGains, - int16_t bandwidth) { - int index_s[KLT_ORDER_SHAPE]; - - double U[UB_LPC_ORDER * UB16_LPC_VEC_PER_FRAME]; - int err; - - /* Entropy decoding of quantization indices. */ - switch (bandwidth) { - case isac12kHz: { - err = WebRtcIsac_DecHistOneStepMulti( - index_s, streamdata, WebRtcIsac_kLpcShapeCdfMatUb12, - WebRtcIsac_kLpcShapeEntropySearchUb12, UB_LPC_ORDER * - UB_LPC_VEC_PER_FRAME); - break; - } - case isac16kHz: { - err = WebRtcIsac_DecHistOneStepMulti( - index_s, streamdata, WebRtcIsac_kLpcShapeCdfMatUb16, - WebRtcIsac_kLpcShapeEntropySearchUb16, UB_LPC_ORDER * - UB16_LPC_VEC_PER_FRAME); - break; - } - default: - return -1; - } - - if (err < 0) { - return err; - } - - WebRtcIsac_DequantizeLpcParam(index_s, lpcVecs, bandwidth); - WebRtcIsac_CorrelateInterVec(lpcVecs, U, bandwidth); - WebRtcIsac_CorrelateIntraVec(U, lpcVecs, bandwidth); - WebRtcIsac_AddLarMean(lpcVecs, bandwidth); - WebRtcIsac_DecodeLpcGainUb(percepFilterGains, streamdata); - - if (bandwidth == isac16kHz) { - /* Decode another set of Gains. */ - WebRtcIsac_DecodeLpcGainUb(&percepFilterGains[SUBFRAMES], streamdata); - } - return 0; -} - -int16_t WebRtcIsac_EncodeBandwidth(enum ISACBandwidth bandwidth, - Bitstr* streamData) { - int bandwidthMode; - switch (bandwidth) { - case isac12kHz: { - bandwidthMode = 0; - break; - } - case isac16kHz: { - bandwidthMode = 1; - break; - } - default: - return -ISAC_DISALLOWED_ENCODER_BANDWIDTH; - } - WebRtcIsac_EncHistMulti(streamData, &bandwidthMode, kOneBitEqualProbCdf_ptr, - 1); - return 0; -} - -int16_t WebRtcIsac_DecodeBandwidth(Bitstr* streamData, - enum ISACBandwidth* bandwidth) { - int bandwidthMode; - if (WebRtcIsac_DecHistOneStepMulti(&bandwidthMode, streamData, - kOneBitEqualProbCdf_ptr, - kOneBitEqualProbInitIndex, 1) < 0) { - return -ISAC_RANGE_ERROR_DECODE_BANDWITH; - } - switch (bandwidthMode) { - case 0: { - *bandwidth = isac12kHz; - break; - } - case 1: { - *bandwidth = isac16kHz; - break; - } - default: - return -ISAC_DISALLOWED_BANDWIDTH_MODE_DECODER; - } - return 0; -} - -int16_t WebRtcIsac_EncodeJitterInfo(int32_t jitterIndex, - Bitstr* streamData) { - /* This is to avoid LINUX warning until we change 'int' to 'Word32'. */ - int intVar; - - if ((jitterIndex < 0) || (jitterIndex > 1)) { - return -1; - } - intVar = (int)(jitterIndex); - /* Use the same CDF table as for bandwidth - * both take two values with equal probability.*/ - WebRtcIsac_EncHistMulti(streamData, &intVar, kOneBitEqualProbCdf_ptr, 1); - return 0; -} - -int16_t WebRtcIsac_DecodeJitterInfo(Bitstr* streamData, - int32_t* jitterInfo) { - int intVar; - /* Use the same CDF table as for bandwidth - * both take two values with equal probability. */ - if (WebRtcIsac_DecHistOneStepMulti(&intVar, streamData, - kOneBitEqualProbCdf_ptr, - kOneBitEqualProbInitIndex, 1) < 0) { - return -ISAC_RANGE_ERROR_DECODE_BANDWITH; - } - *jitterInfo = (int16_t)(intVar); - return 0; -} diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/entropy_coding.h b/webrtc/modules/audio_coding/codecs/isac/main/source/entropy_coding.h deleted file mode 100644 index 6c2b8d3..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/entropy_coding.h +++ /dev/null @@ -1,347 +0,0 @@ -/* - * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -/* - * entropy_coding.h - * - * This header file declares all of the functions used to arithmetically - * encode the iSAC bistream - * - */ - -#ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ENTROPY_CODING_H_ -#define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ENTROPY_CODING_H_ - -#include "modules/audio_coding/codecs/isac/main/source/settings.h" -#include "modules/audio_coding/codecs/isac/main/source/structs.h" - -/****************************************************************************** - * WebRtcIsac_DecodeSpec() - * Decode real and imaginary part of the DFT coefficients, given a bit-stream. - * The decoded DFT coefficient can be transformed to time domain by - * WebRtcIsac_Time2Spec(). - * - * Input: - * - streamdata : pointer to a stucture containg the encoded - * data and theparameters needed for entropy - * coding. - * - AvgPitchGain_Q12 : average pitch-gain of the frame. This is only - * relevant for 0-4 kHz band, and the input value is - * not used in other bands. - * - band : specifies which band's DFT should be decoded. - * - * Output: - * - *fr : pointer to a buffer where the real part of DFT - * coefficients are written to. - * - *fi : pointer to a buffer where the imaginary part - * of DFT coefficients are written to. - * - * Return value : < 0 if an error occures - * 0 if succeeded. - */ -int WebRtcIsac_DecodeSpec(Bitstr* streamdata, - int16_t AvgPitchGain_Q12, - enum ISACBand band, - double* fr, - double* fi); - -/****************************************************************************** - * WebRtcIsac_EncodeSpec() - * Encode real and imaginary part of the DFT coefficients into the given - * bit-stream. - * - * Input: - * - *fr : pointer to a buffer where the real part of DFT - * coefficients are written to. - * - *fi : pointer to a buffer where the imaginary part - * of DFT coefficients are written to. - * - AvgPitchGain_Q12 : average pitch-gain of the frame. This is only - * relevant for 0-4 kHz band, and the input value is - * not used in other bands. - * - band : specifies which band's DFT should be decoded. - * - * Output: - * - streamdata : pointer to a stucture containg the encoded - * data and theparameters needed for entropy - * coding. - * - * Return value : < 0 if an error occures - * 0 if succeeded. - */ -int WebRtcIsac_EncodeSpec(const int16_t* fr, - const int16_t* fi, - int16_t AvgPitchGain_Q12, - enum ISACBand band, - Bitstr* streamdata); - -/* decode & dequantize LPC Coef */ -int WebRtcIsac_DecodeLpcCoef(Bitstr* streamdata, double* LPCCoef); -int WebRtcIsac_DecodeLpcCoefUB(Bitstr* streamdata, - double* lpcVecs, - double* percepFilterGains, - int16_t bandwidth); - -int WebRtcIsac_DecodeLpc(Bitstr* streamdata, - double* LPCCoef_lo, - double* LPCCoef_hi); - -/* quantize & code LPC Coef */ -void WebRtcIsac_EncodeLpcLb(double* LPCCoef_lo, - double* LPCCoef_hi, - Bitstr* streamdata, - IsacSaveEncoderData* encData); - -void WebRtcIsac_EncodeLpcGainLb(double* LPCCoef_lo, - double* LPCCoef_hi, - Bitstr* streamdata, - IsacSaveEncoderData* encData); - -/****************************************************************************** - * WebRtcIsac_EncodeLpcUB() - * Encode LPC parameters, given as A-polynomial, of upper-band. The encoding - * is performed in LAR domain. - * For the upper-band, we compute and encode LPC of some sub-frames, LPC of - * other sub-frames are computed by linear interpolation, in LAR domain. This - * function performs the interpolation and returns the LPC of all sub-frames. - * - * Inputs: - * - lpcCoef : a buffer containing A-polynomials of sub-frames - * (excluding first coefficient that is 1). - * - bandwidth : specifies if the codec is operating at 0-12 kHz - * or 0-16 kHz mode. - * - * Input/output: - * - streamdata : pointer to a structure containing the encoded - * data and the parameters needed for entropy - * coding. - * - * Output: - * - interpolLPCCoeff : Decoded and interpolated LPC (A-polynomial) - * of all sub-frames. - * If LP analysis is of order K, and there are N - * sub-frames then this is a buffer of size - * (k + 1) * N, each vector starts with the LPC gain - * of the corresponding sub-frame. The LPC gains - * are encoded and inserted after this function is - * called. The first A-coefficient which is 1 is not - * included. - * - * Return value : 0 if encoding is successful, - * <0 if failed to encode. - */ -int16_t WebRtcIsac_EncodeLpcUB(double* lpcCoeff, - Bitstr* streamdata, - double* interpolLPCCoeff, - int16_t bandwidth, - ISACUBSaveEncDataStruct* encData); - -/****************************************************************************** - * WebRtcIsac_DecodeInterpolLpcUb() - * Decode LPC coefficients and interpolate to get the coefficients fo all - * sub-frmaes. - * - * Inputs: - * - bandwidth : spepecifies if the codec is in 0-12 kHz or - * 0-16 kHz mode. - * - * Input/output: - * - streamdata : pointer to a stucture containg the encoded - * data and theparameters needed for entropy - * coding. - * - * Output: - * - percepFilterParam : Decoded and interpolated LPC (A-polynomial) of - * all sub-frames. - * If LP analysis is of order K, and there are N - * sub-frames then this is a buffer of size - * (k + 1) * N, each vector starts with the LPC gain - * of the corresponding sub-frame. The LPC gains - * are encoded and inserted after this function is - * called. The first A-coefficient which is 1 is not - * included. - * - * Return value : 0 if encoding is successful, - * <0 if failed to encode. - */ -int16_t WebRtcIsac_DecodeInterpolLpcUb(Bitstr* streamdata, - double* percepFilterParam, - int16_t bandwidth); - -/* Decode & dequantize RC */ -int WebRtcIsac_DecodeRc(Bitstr* streamdata, int16_t* RCQ15); - -/* Quantize & code RC */ -void WebRtcIsac_EncodeRc(int16_t* RCQ15, Bitstr* streamdata); - -/* Decode & dequantize squared Gain */ -int WebRtcIsac_DecodeGain2(Bitstr* streamdata, int32_t* Gain2); - -/* Quantize & code squared Gain (input is squared gain) */ -int WebRtcIsac_EncodeGain2(int32_t* gain2, Bitstr* streamdata); - -void WebRtcIsac_EncodePitchGain(int16_t* PitchGains_Q12, - Bitstr* streamdata, - IsacSaveEncoderData* encData); - -void WebRtcIsac_EncodePitchLag(double* PitchLags, - int16_t* PitchGain_Q12, - Bitstr* streamdata, - IsacSaveEncoderData* encData); - -int WebRtcIsac_DecodePitchGain(Bitstr* streamdata, int16_t* PitchGain_Q12); -int WebRtcIsac_DecodePitchLag(Bitstr* streamdata, - int16_t* PitchGain_Q12, - double* PitchLag); - -int WebRtcIsac_DecodeFrameLen(Bitstr* streamdata, int16_t* framelength); -int WebRtcIsac_EncodeFrameLen(int16_t framelength, Bitstr* streamdata); -int WebRtcIsac_DecodeSendBW(Bitstr* streamdata, int16_t* BWno); -void WebRtcIsac_EncodeReceiveBw(int* BWno, Bitstr* streamdata); - -/* Step-down */ -void WebRtcIsac_Poly2Rc(double* a, int N, double* RC); - -/* Step-up */ -void WebRtcIsac_Rc2Poly(double* RC, int N, double* a); - -void WebRtcIsac_TranscodeLPCCoef(double* LPCCoef_lo, - double* LPCCoef_hi, - int* index_g); - -/****************************************************************************** - * WebRtcIsac_EncodeLpcGainUb() - * Encode LPC gains of sub-Frames. - * - * Input/outputs: - * - lpGains : a buffer which contains 'SUBFRAME' number of - * LP gains to be encoded. The input values are - * overwritten by the quantized values. - * - streamdata : pointer to a stucture containg the encoded - * data and theparameters needed for entropy - * coding. - * - * Output: - * - lpcGainIndex : quantization indices for lpc gains, these will - * be stored to be used for FEC. - */ -void WebRtcIsac_EncodeLpcGainUb(double* lpGains, - Bitstr* streamdata, - int* lpcGainIndex); - -/****************************************************************************** - * WebRtcIsac_EncodeLpcGainUb() - * Store LPC gains of sub-Frames in 'streamdata'. - * - * Input: - * - lpGains : a buffer which contains 'SUBFRAME' number of - * LP gains to be encoded. - * Input/outputs: - * - streamdata : pointer to a stucture containg the encoded - * data and theparameters needed for entropy - * coding. - * - */ -void WebRtcIsac_StoreLpcGainUb(double* lpGains, Bitstr* streamdata); - -/****************************************************************************** - * WebRtcIsac_DecodeLpcGainUb() - * Decode the LPC gain of sub-frames. - * - * Input/output: - * - streamdata : pointer to a stucture containg the encoded - * data and theparameters needed for entropy - * coding. - * - * Output: - * - lpGains : a buffer where decoded LPC gians will be stored. - * - * Return value : 0 if succeeded. - * <0 if failed. - */ -int16_t WebRtcIsac_DecodeLpcGainUb(double* lpGains, Bitstr* streamdata); - -/****************************************************************************** - * WebRtcIsac_EncodeBandwidth() - * Encode if the bandwidth of encoded audio is 0-12 kHz or 0-16 kHz. - * - * Input: - * - bandwidth : an enumerator specifying if the codec in is - * 0-12 kHz or 0-16 kHz mode. - * - * Input/output: - * - streamdata : pointer to a stucture containg the encoded - * data and theparameters needed for entropy - * coding. - * - * Return value : 0 if succeeded. - * <0 if failed. - */ -int16_t WebRtcIsac_EncodeBandwidth(enum ISACBandwidth bandwidth, - Bitstr* streamData); - -/****************************************************************************** - * WebRtcIsac_DecodeBandwidth() - * Decode the bandwidth of the encoded audio, i.e. if the bandwidth is 0-12 kHz - * or 0-16 kHz. - * - * Input/output: - * - streamdata : pointer to a stucture containg the encoded - * data and theparameters needed for entropy - * coding. - * - * Output: - * - bandwidth : an enumerator specifying if the codec is in - * 0-12 kHz or 0-16 kHz mode. - * - * Return value : 0 if succeeded. - * <0 if failed. - */ -int16_t WebRtcIsac_DecodeBandwidth(Bitstr* streamData, - enum ISACBandwidth* bandwidth); - -/****************************************************************************** - * WebRtcIsac_EncodeJitterInfo() - * Decode the jitter information. - * - * Input/output: - * - streamdata : pointer to a stucture containg the encoded - * data and theparameters needed for entropy - * coding. - * - * Input: - * - jitterInfo : one bit of info specifying if the channel is - * in high/low jitter. Zero indicates low jitter - * and one indicates high jitter. - * - * Return value : 0 if succeeded. - * <0 if failed. - */ -int16_t WebRtcIsac_EncodeJitterInfo(int32_t jitterIndex, Bitstr* streamData); - -/****************************************************************************** - * WebRtcIsac_DecodeJitterInfo() - * Decode the jitter information. - * - * Input/output: - * - streamdata : pointer to a stucture containg the encoded - * data and theparameters needed for entropy - * coding. - * - * Output: - * - jitterInfo : one bit of info specifying if the channel is - * in high/low jitter. Zero indicates low jitter - * and one indicates high jitter. - * - * Return value : 0 if succeeded. - * <0 if failed. - */ -int16_t WebRtcIsac_DecodeJitterInfo(Bitstr* streamData, int32_t* jitterInfo); - -#endif /* MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ENTROPY_CODING_H_ */ diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/filterbanks.c b/webrtc/modules/audio_coding/codecs/isac/main/source/filterbanks.c deleted file mode 100644 index d57b550..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/filterbanks.c +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -/* - * filterbanks.c - * - * This file contains function WebRtcIsac_AllPassFilter2Float, - * WebRtcIsac_SplitAndFilter, and WebRtcIsac_FilterAndCombine - * which implement filterbanks that produce decimated lowpass and - * highpass versions of a signal, and performs reconstruction. - * - */ - -#include "modules/audio_coding/codecs/isac/main/source/settings.h" -#include "modules/audio_coding/codecs/isac/main/source/codec.h" -#include "modules/audio_coding/codecs/isac/main/source/isac_vad.h" - -/* Combining */ - -/* HPstcoeff_out_1 = {a1, a2, b1 - b0 * a1, b2 - b0 * a2}; */ -static const float kHpStCoefOut1Float[4] = -{-1.99701049409000f, 0.99714204490000f, 0.01701049409000f, -0.01704204490000f}; - -/* HPstcoeff_out_2 = {a1, a2, b1 - b0 * a1, b2 - b0 * a2}; */ -static const float kHpStCoefOut2Float[4] = -{-1.98645294509837f, 0.98672435560000f, 0.00645294509837f, -0.00662435560000f}; - - -/* Function WebRtcIsac_FilterAndCombine */ -/* This is a decoder function that takes the decimated - length FRAMESAMPLES_HALF input low-pass and - high-pass signals and creates a reconstructed fullband - output signal of length FRAMESAMPLES. WebRtcIsac_FilterAndCombine - is the sibling function of WebRtcIsac_SplitAndFilter */ -/* INPUTS: - inLP: a length FRAMESAMPLES_HALF array of input low-pass - samples. - inHP: a length FRAMESAMPLES_HALF array of input high-pass - samples. - postfiltdata: input data structure containing the filterbank - states from the previous decoding iteration. - OUTPUTS: - Out: a length FRAMESAMPLES array of output reconstructed - samples (fullband) based on the input low-pass and - high-pass signals. - postfiltdata: the input data structure containing the filterbank - states is updated for the next decoding iteration */ -void WebRtcIsac_FilterAndCombineFloat(float *InLP, - float *InHP, - float *Out, - PostFiltBankstr *postfiltdata) -{ - int k; - float tempin_ch1[FRAMESAMPLES+MAX_AR_MODEL_ORDER]; - float tempin_ch2[FRAMESAMPLES+MAX_AR_MODEL_ORDER]; - float ftmp, ftmp2; - - /* Form the polyphase signals*/ - for (k=0;kSTATE_0_UPPER_float); - - /* Now, all-pass filter the new lower channel signal. But since all-pass filter factors - at the decoder are swapped from the ones at the encoder, the 'upper' channel - all-pass filter factors (WebRtcIsac_kUpperApFactorsFloat) are used to filter this new - lower channel signal */ - WebRtcIsac_AllPassFilter2Float(tempin_ch2, WebRtcIsac_kUpperApFactorsFloat, - FRAMESAMPLES_HALF, NUMBEROFCHANNELAPSECTIONS,postfiltdata->STATE_0_LOWER_float); - - - /* Merge outputs to form the full length output signal.*/ - for (k=0;kHPstates1_float[0] + - kHpStCoefOut1Float[3] * postfiltdata->HPstates1_float[1]; - ftmp = Out[k] - kHpStCoefOut1Float[0] * postfiltdata->HPstates1_float[0] - - kHpStCoefOut1Float[1] * postfiltdata->HPstates1_float[1]; - postfiltdata->HPstates1_float[1] = postfiltdata->HPstates1_float[0]; - postfiltdata->HPstates1_float[0] = ftmp; - Out[k] = ftmp2; - } - - for (k=0;kHPstates2_float[0] + - kHpStCoefOut2Float[3] * postfiltdata->HPstates2_float[1]; - ftmp = Out[k] - kHpStCoefOut2Float[0] * postfiltdata->HPstates2_float[0] - - kHpStCoefOut2Float[1] * postfiltdata->HPstates2_float[1]; - postfiltdata->HPstates2_float[1] = postfiltdata->HPstates2_float[0]; - postfiltdata->HPstates2_float[0] = ftmp; - Out[k] = ftmp2; - } -} diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/intialize.c b/webrtc/modules/audio_coding/codecs/isac/main/source/intialize.c deleted file mode 100644 index 5c951f6..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/intialize.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -/* encode.c - Encoding function for the iSAC coder */ - -#include - -#include "modules/audio_coding/codecs/isac/main/source/structs.h" -#include "modules/audio_coding/codecs/isac/main/source/codec.h" -#include "modules/audio_coding/codecs/isac/main/source/pitch_estimator.h" - -void WebRtcIsac_InitMasking(MaskFiltstr *maskdata) { - - int k; - - for (k = 0; k < WINLEN; k++) { - maskdata->DataBufferLo[k] = 0.0; - maskdata->DataBufferHi[k] = 0.0; - } - for (k = 0; k < ORDERLO+1; k++) { - maskdata->CorrBufLo[k] = 0.0; - maskdata->PreStateLoF[k] = 0.0; - maskdata->PreStateLoG[k] = 0.0; - maskdata->PostStateLoF[k] = 0.0; - maskdata->PostStateLoG[k] = 0.0; - } - for (k = 0; k < ORDERHI+1; k++) { - maskdata->CorrBufHi[k] = 0.0; - maskdata->PreStateHiF[k] = 0.0; - maskdata->PreStateHiG[k] = 0.0; - maskdata->PostStateHiF[k] = 0.0; - maskdata->PostStateHiG[k] = 0.0; - } - - maskdata->OldEnergy = 10.0; - return; -} - -void WebRtcIsac_InitPostFilterbank(PostFiltBankstr *postfiltdata) -{ - int k; - - for (k = 0; k < 2*POSTQORDER; k++) { - postfiltdata->STATE_0_LOWER[k] = 0; - postfiltdata->STATE_0_UPPER[k] = 0; - - postfiltdata->STATE_0_LOWER_float[k] = 0; - postfiltdata->STATE_0_UPPER_float[k] = 0; - } - - /* High pass filter states */ - postfiltdata->HPstates1[0] = 0.0; - postfiltdata->HPstates1[1] = 0.0; - - postfiltdata->HPstates2[0] = 0.0; - postfiltdata->HPstates2[1] = 0.0; - - postfiltdata->HPstates1_float[0] = 0.0f; - postfiltdata->HPstates1_float[1] = 0.0f; - - postfiltdata->HPstates2_float[0] = 0.0f; - postfiltdata->HPstates2_float[1] = 0.0f; - - return; -} diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/isac.c b/webrtc/modules/audio_coding/codecs/isac/main/source/isac.c deleted file mode 100644 index 73f132c..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/isac.c +++ /dev/null @@ -1,2307 +0,0 @@ -/* - * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -/* - * isac.c - * - * This C file contains the functions for the ISAC API - * - */ - -#include "modules/audio_coding/codecs/isac/main/include/isac.h" - -#include -#include -#include -#include - -#include "rtc_base/checks.h" -#include "common_audio/signal_processing/include/signal_processing_library.h" -#include "modules/audio_coding/codecs/isac/main/source/bandwidth_estimator.h" -#include "modules/audio_coding/codecs/isac/main/source/codec.h" -#include "modules/audio_coding/codecs/isac/main/source/crc.h" -#include "modules/audio_coding/codecs/isac/main/source/entropy_coding.h" -#include "modules/audio_coding/codecs/isac/main/source/lpc_shape_swb16_tables.h" -#include "modules/audio_coding/codecs/isac/main/source/os_specific_inline.h" -#include "modules/audio_coding/codecs/isac/main/source/structs.h" -#include "modules/audio_coding/codecs/isac/main/source/isac_vad.h" -#include "rtc_base/system/arch.h" - -#define BIT_MASK_DEC_INIT 0x0001 -#define BIT_MASK_ENC_INIT 0x0002 - -#define LEN_CHECK_SUM_WORD8 4 -#define MAX_NUM_LAYERS 10 - - -/**************************************************************************** - * UpdatePayloadSizeLimit(...) - * - * Call this function to update the limit on the payload size. The limit on - * payload size might change i) if a user ''directly changes the limit by - * calling xxx_setMaxPayloadSize() or xxx_setMaxRate(), or ii) indirectly - * when bandwidth is changing. The latter might be the result of bandwidth - * adaptation, or direct change of the bottleneck in instantaneous mode. - * - * This function takes the current overall limit on payload, and translates it - * to the limits on lower and upper-band. If the codec is in wideband mode, - * then the overall limit and the limit on the lower-band is the same. - * Otherwise, a fraction of the limit should be allocated to lower-band - * leaving some room for the upper-band bit-stream. That is why an update - * of limit is required every time that the bandwidth is changing. - * - */ -static void UpdatePayloadSizeLimit(ISACMainStruct* instISAC) { - int16_t lim30MsPayloadBytes = WEBRTC_SPL_MIN( - (instISAC->maxPayloadSizeBytes), - (instISAC->maxRateBytesPer30Ms)); - int16_t lim60MsPayloadBytes = WEBRTC_SPL_MIN( - (instISAC->maxPayloadSizeBytes), - (instISAC->maxRateBytesPer30Ms << 1)); - - /* The only time that iSAC will have 60 ms - * frame-size is when operating in wideband, so - * there is no upper-band bit-stream. */ - - if (instISAC->bandwidthKHz == isac8kHz) { - /* At 8 kHz there is no upper-band bit-stream, - * therefore, the lower-band limit is the overall limit. */ - instISAC->instLB.ISACencLB_obj.payloadLimitBytes60 = - lim60MsPayloadBytes; - instISAC->instLB.ISACencLB_obj.payloadLimitBytes30 = - lim30MsPayloadBytes; - } else { - /* When in super-wideband, we only have 30 ms frames. - * Do a rate allocation for the given limit. */ - if (lim30MsPayloadBytes > 250) { - /* 4/5 to lower-band the rest for upper-band. */ - instISAC->instLB.ISACencLB_obj.payloadLimitBytes30 = - (lim30MsPayloadBytes << 2) / 5; - } else if (lim30MsPayloadBytes > 200) { - /* For the interval of 200 to 250 the share of - * upper-band linearly grows from 20 to 50. */ - instISAC->instLB.ISACencLB_obj.payloadLimitBytes30 = - (lim30MsPayloadBytes << 1) / 5 + 100; - } else { - /* Allocate only 20 for upper-band. */ - instISAC->instLB.ISACencLB_obj.payloadLimitBytes30 = - lim30MsPayloadBytes - 20; - } - instISAC->instUB.ISACencUB_obj.maxPayloadSizeBytes = - lim30MsPayloadBytes; - } -} - - -/**************************************************************************** - * UpdateBottleneck(...) - * - * This function updates the bottleneck only if the codec is operating in - * channel-adaptive mode. Furthermore, as the update of bottleneck might - * result in an update of bandwidth, therefore, the bottlenech should be - * updated just right before the first 10ms of a frame is pushed into encoder. - * - */ -static void UpdateBottleneck(ISACMainStruct* instISAC) { - /* Read the bottleneck from bandwidth estimator for the - * first 10 ms audio. This way, if there is a change - * in bandwidth, upper and lower-band will be in sync. */ - if ((instISAC->codingMode == 0) && - (instISAC->instLB.ISACencLB_obj.buffer_index == 0) && - (instISAC->instLB.ISACencLB_obj.frame_nb == 0)) { - int32_t bottleneck = - WebRtcIsac_GetUplinkBandwidth(&instISAC->bwestimator_obj); - - /* Adding hysteresis when increasing signal bandwidth. */ - if ((instISAC->bandwidthKHz == isac8kHz) - && (bottleneck > 37000) - && (bottleneck < 41000)) { - bottleneck = 37000; - } - - /* Switching from 12 kHz to 16 kHz is not allowed at this revision. - * If we let this happen, we have to take care of buffer_index and - * the last LPC vector. */ - if ((instISAC->bandwidthKHz != isac16kHz) && - (bottleneck > 46000)) { - bottleneck = 46000; - } - - /* We might need a rate allocation. */ - if (instISAC->encoderSamplingRateKHz == kIsacWideband) { - /* Wideband is the only choice we have here. */ - instISAC->instLB.ISACencLB_obj.bottleneck = - (bottleneck > 32000) ? 32000 : bottleneck; - instISAC->bandwidthKHz = isac8kHz; - } else { - /* Do the rate-allocation and get the new bandwidth. */ - enum ISACBandwidth bandwidth; - WebRtcIsac_RateAllocation(bottleneck, - &(instISAC->instLB.ISACencLB_obj.bottleneck), - &(instISAC->instUB.ISACencUB_obj.bottleneck), - &bandwidth); - if (bandwidth != isac8kHz) { - instISAC->instLB.ISACencLB_obj.new_framelength = 480; - } - if (bandwidth != instISAC->bandwidthKHz) { - /* Bandwidth is changing. */ - instISAC->bandwidthKHz = bandwidth; - UpdatePayloadSizeLimit(instISAC); - if (bandwidth == isac12kHz) { - instISAC->instLB.ISACencLB_obj.buffer_index = 0; - } - /* Currently we don't let the bandwidth to switch to 16 kHz - * if in adaptive mode. If we let this happen, we have to take - * care of buffer_index and the last LPC vector. */ - } - } - } -} - - -/**************************************************************************** - * GetSendBandwidthInfo(...) - * - * This is called to get the bandwidth info. This info is the bandwidth and - * the jitter of 'there-to-here' channel, estimated 'here.' These info - * is signaled in an in-band fashion to the other side. - * - * The call to the bandwidth estimator triggers a recursive averaging which - * has to be synchronized between encoder & decoder, therefore, the call to - * BWE should be once per packet. As the BWE info is inserted into bit-stream - * We need a valid info right before the encodeLB function is going to - * generate a bit-stream. That is when lower-band buffer has already 20ms - * of audio, and the 3rd block of 10ms is going to be injected into encoder. - * - * Inputs: - * - instISAC : iSAC instance. - * - * Outputs: - * - bandwidthIndex : an index which has to be encoded in - * lower-band bit-stream, indicating the - * bandwidth of there-to-here channel. - * - jitterInfo : this indicates if the jitter is high - * or low and it is encoded in upper-band - * bit-stream. - * - */ -static void GetSendBandwidthInfo(ISACMainStruct* instISAC, - int16_t* bandwidthIndex, - int16_t* jitterInfo) { - if ((instISAC->instLB.ISACencLB_obj.buffer_index == - (FRAMESAMPLES_10ms << 1)) && - (instISAC->instLB.ISACencLB_obj.frame_nb == 0)) { - /* Bandwidth estimation and coding. */ - WebRtcIsac_GetDownlinkBwJitIndexImpl(&(instISAC->bwestimator_obj), - bandwidthIndex, jitterInfo, - instISAC->decoderSamplingRateKHz); - } -} - - -/**************************************************************************** - * WebRtcIsac_Create(...) - * - * This function creates an ISAC instance, which will contain the state - * information for one coding/decoding channel. - * - * Input: - * - ISAC_main_inst : address of the pointer to the coder instance. - * - * Return value : 0 - Ok - * -1 - Error - */ -int16_t WebRtcIsac_Create(ISACStruct** ISAC_main_inst) { - ISACMainStruct* instISAC; - - if (ISAC_main_inst != NULL) { - instISAC = (ISACMainStruct*)malloc(sizeof(ISACMainStruct)); - *ISAC_main_inst = (ISACStruct*)instISAC; - if (*ISAC_main_inst != NULL) { - instISAC->errorCode = 0; - instISAC->initFlag = 0; - /* Default is wideband. */ - instISAC->bandwidthKHz = isac8kHz; - instISAC->encoderSamplingRateKHz = kIsacWideband; - instISAC->decoderSamplingRateKHz = kIsacWideband; - instISAC->in_sample_rate_hz = 16000; - - WebRtcIsac_InitTransform(&instISAC->transform_tables); - return 0; - } else { - return -1; - } - } else { - return -1; - } -} - - -/**************************************************************************** - * WebRtcIsac_Free(...) - * - * This function frees the ISAC instance created at the beginning. - * - * Input: - * - ISAC_main_inst : a ISAC instance. - * - * Return value : 0 - Ok - * -1 - Error - */ -int16_t WebRtcIsac_Free(ISACStruct* ISAC_main_inst) { - ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; - free(instISAC); - return 0; -} - - -/**************************************************************************** - * EncoderInitLb(...) - internal function for initialization of - * Lower Band - * EncoderInitUb(...) - internal function for initialization of - * Upper Band - * WebRtcIsac_EncoderInit(...) - API function - * - * This function initializes a ISAC instance prior to the encoder calls. - * - * Input: - * - ISAC_main_inst : ISAC instance. - * - CodingMode : 0 -> Bit rate and frame length are automatically - * adjusted to available bandwidth on - * transmission channel, applicable just to - * wideband mode. - * 1 -> User sets a frame length and a target bit - * rate which is taken as the maximum - * short-term average bit rate. - * - * Return value : 0 - Ok - * -1 - Error - */ -static int16_t EncoderInitLb(ISACLBStruct* instLB, - int16_t codingMode, - enum IsacSamplingRate sampRate) { - int16_t statusInit = 0; - int k; - - /* Init stream vector to zero */ - for (k = 0; k < STREAM_SIZE_MAX_60; k++) { - instLB->ISACencLB_obj.bitstr_obj.stream[k] = 0; - } - - if ((codingMode == 1) || (sampRate == kIsacSuperWideband)) { - /* 30 ms frame-size if either in super-wideband or - * instantaneous mode (I-mode). */ - instLB->ISACencLB_obj.new_framelength = 480; - } else { - instLB->ISACencLB_obj.new_framelength = INITIAL_FRAMESAMPLES; - } - - WebRtcIsac_InitMasking(&instLB->ISACencLB_obj.maskfiltstr_obj); - WebRtcIsac_InitPreFilterbank(&instLB->ISACencLB_obj.prefiltbankstr_obj); - WebRtcIsac_InitPitchFilter(&instLB->ISACencLB_obj.pitchfiltstr_obj); - WebRtcIsac_InitPitchAnalysis( - &instLB->ISACencLB_obj.pitchanalysisstr_obj); - - instLB->ISACencLB_obj.buffer_index = 0; - instLB->ISACencLB_obj.frame_nb = 0; - /* Default for I-mode. */ - instLB->ISACencLB_obj.bottleneck = 32000; - instLB->ISACencLB_obj.current_framesamples = 0; - instLB->ISACencLB_obj.s2nr = 0; - instLB->ISACencLB_obj.payloadLimitBytes30 = STREAM_SIZE_MAX_30; - instLB->ISACencLB_obj.payloadLimitBytes60 = STREAM_SIZE_MAX_60; - instLB->ISACencLB_obj.maxPayloadBytes = STREAM_SIZE_MAX_60; - instLB->ISACencLB_obj.maxRateInBytes = STREAM_SIZE_MAX_30; - instLB->ISACencLB_obj.enforceFrameSize = 0; - /* Invalid value prevents getRedPayload to - run before encoder is called. */ - instLB->ISACencLB_obj.lastBWIdx = -1; - return statusInit; -} - -static int16_t EncoderInitUb(ISACUBStruct* instUB, - int16_t bandwidth) { - int16_t statusInit = 0; - int k; - - /* Init stream vector to zero. */ - for (k = 0; k < STREAM_SIZE_MAX_60; k++) { - instUB->ISACencUB_obj.bitstr_obj.stream[k] = 0; - } - - WebRtcIsac_InitMasking(&instUB->ISACencUB_obj.maskfiltstr_obj); - WebRtcIsac_InitPreFilterbank(&instUB->ISACencUB_obj.prefiltbankstr_obj); - - if (bandwidth == isac16kHz) { - instUB->ISACencUB_obj.buffer_index = LB_TOTAL_DELAY_SAMPLES; - } else { - instUB->ISACencUB_obj.buffer_index = 0; - } - /* Default for I-mode. */ - instUB->ISACencUB_obj.bottleneck = 32000; - /* These store the limits for the wideband + super-wideband bit-stream. */ - instUB->ISACencUB_obj.maxPayloadSizeBytes = STREAM_SIZE_MAX_30 << 1; - /* This has to be updated after each lower-band encoding to guarantee - * a correct payload-limitation. */ - instUB->ISACencUB_obj.numBytesUsed = 0; - memset(instUB->ISACencUB_obj.data_buffer_float, 0, - (MAX_FRAMESAMPLES + LB_TOTAL_DELAY_SAMPLES) * sizeof(float)); - - memcpy(&(instUB->ISACencUB_obj.lastLPCVec), - WebRtcIsac_kMeanLarUb16, sizeof(double) * UB_LPC_ORDER); - - return statusInit; -} - - -int16_t WebRtcIsac_EncoderInit(ISACStruct* ISAC_main_inst, - int16_t codingMode) { - ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; - int16_t status; - - if ((codingMode != 0) && (codingMode != 1)) { - instISAC->errorCode = ISAC_DISALLOWED_CODING_MODE; - return -1; - } - /* Default bottleneck. */ - instISAC->bottleneck = MAX_ISAC_BW; - - if (instISAC->encoderSamplingRateKHz == kIsacWideband) { - instISAC->bandwidthKHz = isac8kHz; - instISAC->maxPayloadSizeBytes = STREAM_SIZE_MAX_60; - instISAC->maxRateBytesPer30Ms = STREAM_SIZE_MAX_30; - } else { - instISAC->bandwidthKHz = isac16kHz; - instISAC->maxPayloadSizeBytes = STREAM_SIZE_MAX; - instISAC->maxRateBytesPer30Ms = STREAM_SIZE_MAX; - } - - /* Channel-adaptive = 0; Instantaneous (Channel-independent) = 1. */ - instISAC->codingMode = codingMode; - - WebRtcIsac_InitBandwidthEstimator(&instISAC->bwestimator_obj, - instISAC->encoderSamplingRateKHz, - instISAC->decoderSamplingRateKHz); - - WebRtcIsac_InitRateModel(&instISAC->rate_data_obj); - /* Default for I-mode. */ - instISAC->MaxDelay = 10.0; - - status = EncoderInitLb(&instISAC->instLB, codingMode, - instISAC->encoderSamplingRateKHz); - if (status < 0) { - instISAC->errorCode = -status; - return -1; - } - - if (instISAC->encoderSamplingRateKHz == kIsacSuperWideband) { - /* Initialize encoder filter-bank. */ - memset(instISAC->analysisFBState1, 0, - FB_STATE_SIZE_WORD32 * sizeof(int32_t)); - memset(instISAC->analysisFBState2, 0, - FB_STATE_SIZE_WORD32 * sizeof(int32_t)); - - status = EncoderInitUb(&(instISAC->instUB), - instISAC->bandwidthKHz); - if (status < 0) { - instISAC->errorCode = -status; - return -1; - } - } - /* Initialization is successful, set the flag. */ - instISAC->initFlag |= BIT_MASK_ENC_INIT; - return 0; -} - - -/**************************************************************************** - * WebRtcIsac_Encode(...) - * - * This function encodes 10ms frame(s) and inserts it into a package. - * Input speech length has to be 160 samples (10ms). The encoder buffers those - * 10ms frames until it reaches the chosen Framesize (480 or 960 samples - * corresponding to 30 or 60 ms frames), and then proceeds to the encoding. - * - * Input: - * - ISAC_main_inst : ISAC instance. - * - speechIn : input speech vector. - * - * Output: - * - encoded : the encoded data vector - * - * Return value: - * : >0 - Length (in bytes) of coded data - * : 0 - The buffer didn't reach the chosen - * frameSize so it keeps buffering speech - * samples. - * : -1 - Error - */ -int WebRtcIsac_Encode(ISACStruct* ISAC_main_inst, - const int16_t* speechIn, - uint8_t* encoded) { - float inFrame[FRAMESAMPLES_10ms]; - int16_t speechInLB[FRAMESAMPLES_10ms]; - int16_t speechInUB[FRAMESAMPLES_10ms]; - int streamLenLB = 0; - int streamLenUB = 0; - int streamLen = 0; - size_t k = 0; - uint8_t garbageLen = 0; - int32_t bottleneck = 0; - int16_t bottleneckIdx = 0; - int16_t jitterInfo = 0; - - ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; - ISACLBStruct* instLB = &(instISAC->instLB); - ISACUBStruct* instUB = &(instISAC->instUB); - - /* Check if encoder initiated. */ - if ((instISAC->initFlag & BIT_MASK_ENC_INIT) != - BIT_MASK_ENC_INIT) { - instISAC->errorCode = ISAC_ENCODER_NOT_INITIATED; - return -1; - } - - if (instISAC->encoderSamplingRateKHz == kIsacSuperWideband) { - WebRtcSpl_AnalysisQMF(speechIn, SWBFRAMESAMPLES_10ms, speechInLB, - speechInUB, instISAC->analysisFBState1, - instISAC->analysisFBState2); - - /* Convert from fixed to floating point. */ - for (k = 0; k < FRAMESAMPLES_10ms; k++) { - inFrame[k] = (float)speechInLB[k]; - } - } else { - for (k = 0; k < FRAMESAMPLES_10ms; k++) { - inFrame[k] = (float) speechIn[k]; - } - } - - /* Add some noise to avoid denormal numbers. */ - inFrame[0] += (float)1.23455334e-3; - inFrame[1] -= (float)2.04324239e-3; - inFrame[2] += (float)1.90854954e-3; - inFrame[9] += (float)1.84854878e-3; - - /* This function will update the bottleneck if required. */ - UpdateBottleneck(instISAC); - - /* Get the bandwith information which has to be sent to the other side. */ - GetSendBandwidthInfo(instISAC, &bottleneckIdx, &jitterInfo); - - /* Encode lower-band. */ - streamLenLB = WebRtcIsac_EncodeLb(&instISAC->transform_tables, - inFrame, &instLB->ISACencLB_obj, - instISAC->codingMode, bottleneckIdx); - if (streamLenLB < 0) { - return -1; - } - - if (instISAC->encoderSamplingRateKHz == kIsacSuperWideband) { - instUB = &(instISAC->instUB); - - /* Convert to float. */ - for (k = 0; k < FRAMESAMPLES_10ms; k++) { - inFrame[k] = (float) speechInUB[k]; - } - - /* Add some noise to avoid denormal numbers. */ - inFrame[0] += (float)1.23455334e-3; - inFrame[1] -= (float)2.04324239e-3; - inFrame[2] += (float)1.90854954e-3; - inFrame[9] += (float)1.84854878e-3; - - /* Tell to upper-band the number of bytes used so far. - * This is for payload limitation. */ - instUB->ISACencUB_obj.numBytesUsed = - (int16_t)(streamLenLB + 1 + LEN_CHECK_SUM_WORD8); - /* Encode upper-band. */ - switch (instISAC->bandwidthKHz) { - case isac12kHz: { - streamLenUB = WebRtcIsac_EncodeUb12(&instISAC->transform_tables, - inFrame, &instUB->ISACencUB_obj, - jitterInfo); - break; - } - case isac16kHz: { - streamLenUB = WebRtcIsac_EncodeUb16(&instISAC->transform_tables, - inFrame, &instUB->ISACencUB_obj, - jitterInfo); - break; - } - case isac8kHz: { - streamLenUB = 0; - break; - } - } - - if ((streamLenUB < 0) && (streamLenUB != -ISAC_PAYLOAD_LARGER_THAN_LIMIT)) { - /* An error has happened but this is not the error due to a - * bit-stream larger than the limit. */ - return -1; - } - - if (streamLenLB == 0) { - return 0; - } - - /* One byte is allocated for the length. According to older decoders - so the length bit-stream plus one byte for size and - LEN_CHECK_SUM_WORD8 for the checksum should be less than or equal - to 255. */ - if ((streamLenUB > (255 - (LEN_CHECK_SUM_WORD8 + 1))) || - (streamLenUB == -ISAC_PAYLOAD_LARGER_THAN_LIMIT)) { - /* We have got a too long bit-stream we skip the upper-band - * bit-stream for this frame. */ - streamLenUB = 0; - } - - memcpy(encoded, instLB->ISACencLB_obj.bitstr_obj.stream, streamLenLB); - streamLen = streamLenLB; - if (streamLenUB > 0) { - encoded[streamLenLB] = (uint8_t)(streamLenUB + 1 + LEN_CHECK_SUM_WORD8); - memcpy(&encoded[streamLenLB + 1], - instUB->ISACencUB_obj.bitstr_obj.stream, - streamLenUB); - streamLen += encoded[streamLenLB]; - } else { - encoded[streamLenLB] = 0; - } - } else { - if (streamLenLB == 0) { - return 0; - } - memcpy(encoded, instLB->ISACencLB_obj.bitstr_obj.stream, streamLenLB); - streamLenUB = 0; - streamLen = streamLenLB; - } - - /* Add Garbage if required. */ - bottleneck = WebRtcIsac_GetUplinkBandwidth(&instISAC->bwestimator_obj); - if (instISAC->codingMode == 0) { - int minBytes; - int limit; - uint8_t* ptrGarbage; - - instISAC->MaxDelay = (double)WebRtcIsac_GetUplinkMaxDelay( - &instISAC->bwestimator_obj); - - /* Update rate model and get minimum number of bytes in this packet. */ - minBytes = WebRtcIsac_GetMinBytes( - &(instISAC->rate_data_obj), streamLen, - instISAC->instLB.ISACencLB_obj.current_framesamples, bottleneck, - instISAC->MaxDelay, instISAC->bandwidthKHz); - - /* Make sure MinBytes does not exceed packet size limit. */ - if (instISAC->bandwidthKHz == isac8kHz) { - if (instLB->ISACencLB_obj.current_framesamples == FRAMESAMPLES) { - limit = instLB->ISACencLB_obj.payloadLimitBytes30; - } else { - limit = instLB->ISACencLB_obj.payloadLimitBytes60; - } - } else { - limit = instUB->ISACencUB_obj.maxPayloadSizeBytes; - } - minBytes = (minBytes > limit) ? limit : minBytes; - - /* Make sure we don't allow more than 255 bytes of garbage data. - * We store the length of the garbage data in 8 bits in the bitstream, - * 255 is the max garbage length we can signal using 8 bits. */ - if ((instISAC->bandwidthKHz == isac8kHz) || - (streamLenUB == 0)) { - ptrGarbage = &encoded[streamLenLB]; - limit = streamLen + 255; - } else { - ptrGarbage = &encoded[streamLenLB + 1 + streamLenUB]; - limit = streamLen + (255 - encoded[streamLenLB]); - } - minBytes = (minBytes > limit) ? limit : minBytes; - - garbageLen = (minBytes > streamLen) ? (uint8_t)(minBytes - streamLen) : 0; - - /* Save data for creation of multiple bit-streams. */ - /* If bit-stream too short then add garbage at the end. */ - if (garbageLen > 0) { - /* Overwrite the garbage area to avoid leaking possibly sensitive data - over the network. This also makes the output deterministic. */ - memset(ptrGarbage, 0, garbageLen); - - /* For a correct length of the upper-band bit-stream together - * with the garbage. Garbage is embeded in upper-band bit-stream. - * That is the only way to preserve backward compatibility. */ - if ((instISAC->bandwidthKHz == isac8kHz) || - (streamLenUB == 0)) { - encoded[streamLenLB] = garbageLen; - } else { - encoded[streamLenLB] += garbageLen; - /* Write the length of the garbage at the end of the upper-band - * bit-stream, if exists. This helps for sanity check. */ - encoded[streamLenLB + 1 + streamLenUB] = garbageLen; - - } - streamLen += garbageLen; - } - } else { - /* update rate model */ - WebRtcIsac_UpdateRateModel( - &instISAC->rate_data_obj, streamLen, - instISAC->instLB.ISACencLB_obj.current_framesamples, bottleneck); - garbageLen = 0; - } - - /* Generate CRC if required. */ - if ((instISAC->bandwidthKHz != isac8kHz) && (streamLenUB > 0)) { - uint32_t crc; - - WebRtcIsac_GetCrc((int16_t*)(&(encoded[streamLenLB + 1])), - streamLenUB + garbageLen, &crc); -#ifndef WEBRTC_ARCH_BIG_ENDIAN - for (k = 0; k < LEN_CHECK_SUM_WORD8; k++) { - encoded[streamLen - LEN_CHECK_SUM_WORD8 + k] = - (uint8_t)(crc >> (24 - k * 8)); - } -#else - memcpy(&encoded[streamLenLB + streamLenUB + 1], &crc, LEN_CHECK_SUM_WORD8); -#endif - } - return streamLen; -} - - -/****************************************************************************** - * WebRtcIsac_GetNewBitStream(...) - * - * This function returns encoded data, with the recieved bwe-index in the - * stream. If the rate is set to a value less than bottleneck of codec - * the new bistream will be re-encoded with the given target rate. - * It should always return a complete packet, i.e. only called once - * even for 60 msec frames. - * - * NOTE 1! This function does not write in the ISACStruct, it is not allowed. - * NOTE 2! Rates larger than the bottleneck of the codec will be limited - * to the current bottleneck. - * - * Input: - * - ISAC_main_inst : ISAC instance. - * - bweIndex : Index of bandwidth estimate to put in new - * bitstream - * - rate : target rate of the transcoder is bits/sec. - * Valid values are the accepted rate in iSAC, - * i.e. 10000 to 56000. - * - * Output: - * - encoded : The encoded data vector - * - * Return value : >0 - Length (in bytes) of coded data - * -1 - Error or called in SWB mode - * NOTE! No error code is written to - * the struct since it is only allowed to read - * the struct. - */ -int16_t WebRtcIsac_GetNewBitStream(ISACStruct* ISAC_main_inst, - int16_t bweIndex, - int16_t jitterInfo, - int32_t rate, - uint8_t* encoded, - int16_t isRCU) { - Bitstr iSACBitStreamInst; /* Local struct for bitstream handling */ - int16_t streamLenLB; - int16_t streamLenUB; - int16_t totalStreamLen; - double gain2; - double gain1; - float scale; - enum ISACBandwidth bandwidthKHz; - double rateLB; - double rateUB; - int32_t currentBN; - uint32_t crc; -#ifndef WEBRTC_ARCH_BIG_ENDIAN - int16_t k; -#endif - ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; - - if ((instISAC->initFlag & BIT_MASK_ENC_INIT) != - BIT_MASK_ENC_INIT) { - return -1; - } - - /* Get the bottleneck of this iSAC and limit the - * given rate to the current bottleneck. */ - WebRtcIsac_GetUplinkBw(ISAC_main_inst, ¤tBN); - if (rate > currentBN) { - rate = currentBN; - } - - if (WebRtcIsac_RateAllocation(rate, &rateLB, &rateUB, &bandwidthKHz) < 0) { - return -1; - } - - /* Cannot transcode from 16 kHz to 12 kHz. */ - if ((bandwidthKHz == isac12kHz) && - (instISAC->bandwidthKHz == isac16kHz)) { - return -1; - } - - /* A gain [dB] for the given rate. */ - gain1 = WebRtcIsac_GetSnr( - rateLB, instISAC->instLB.ISACencLB_obj.current_framesamples); - /* The gain [dB] of this iSAC. */ - gain2 = WebRtcIsac_GetSnr( - instISAC->instLB.ISACencLB_obj.bottleneck, - instISAC->instLB.ISACencLB_obj.current_framesamples); - - /* Scale is the ratio of two gains in normal domain. */ - scale = (float)pow(10, (gain1 - gain2) / 20.0); - /* Change the scale if this is a RCU bit-stream. */ - scale = (isRCU) ? (scale * RCU_TRANSCODING_SCALE) : scale; - - streamLenLB = WebRtcIsac_EncodeStoredDataLb( - &instISAC->instLB.ISACencLB_obj.SaveEnc_obj, - &iSACBitStreamInst, bweIndex, scale); - - if (streamLenLB < 0) { - return -1; - } - - /* Convert from bytes to int16_t. */ - memcpy(encoded, iSACBitStreamInst.stream, streamLenLB); - - if (bandwidthKHz == isac8kHz) { - return streamLenLB; - } - - totalStreamLen = streamLenLB; - /* super-wideband is always at 30ms. - * These gains are in dB. - * Gain for the given rate. */ - gain1 = WebRtcIsac_GetSnr(rateUB, FRAMESAMPLES); - /* Gain of this iSAC */ - gain2 = WebRtcIsac_GetSnr(instISAC->instUB.ISACencUB_obj.bottleneck, - FRAMESAMPLES); - - /* Scale is the ratio of two gains in normal domain. */ - scale = (float)pow(10, (gain1 - gain2) / 20.0); - - /* Change the scale if this is a RCU bit-stream. */ - scale = (isRCU)? (scale * RCU_TRANSCODING_SCALE_UB) : scale; - - streamLenUB = WebRtcIsac_EncodeStoredDataUb( - &(instISAC->instUB.ISACencUB_obj.SaveEnc_obj), - &iSACBitStreamInst, jitterInfo, scale, - instISAC->bandwidthKHz); - - if (streamLenUB < 0) { - return -1; - } - - if (streamLenUB + 1 + LEN_CHECK_SUM_WORD8 > 255) { - return streamLenLB; - } - - totalStreamLen = streamLenLB + streamLenUB + 1 + LEN_CHECK_SUM_WORD8; - encoded[streamLenLB] = streamLenUB + 1 + LEN_CHECK_SUM_WORD8; - - memcpy(&encoded[streamLenLB + 1], iSACBitStreamInst.stream, - streamLenUB); - - WebRtcIsac_GetCrc((int16_t*)(&(encoded[streamLenLB + 1])), - streamLenUB, &crc); -#ifndef WEBRTC_ARCH_BIG_ENDIAN - for (k = 0; k < LEN_CHECK_SUM_WORD8; k++) { - encoded[totalStreamLen - LEN_CHECK_SUM_WORD8 + k] = - (uint8_t)((crc >> (24 - k * 8)) & 0xFF); - } -#else - memcpy(&encoded[streamLenLB + streamLenUB + 1], &crc, - LEN_CHECK_SUM_WORD8); -#endif - return totalStreamLen; -} - - -/**************************************************************************** - * DecoderInitLb(...) - internal function for initialization of - * Lower Band - * DecoderInitUb(...) - internal function for initialization of - * Upper Band - * WebRtcIsac_DecoderInit(...) - API function - * - * This function initializes a ISAC instance prior to the decoder calls. - * - * Input: - * - ISAC_main_inst : ISAC instance. - */ -static void DecoderInitLb(ISACLBStruct* instISAC) { - int i; - /* Initialize stream vector to zero. */ - for (i = 0; i < STREAM_SIZE_MAX_60; i++) { - instISAC->ISACdecLB_obj.bitstr_obj.stream[i] = 0; - } - - WebRtcIsac_InitMasking(&instISAC->ISACdecLB_obj.maskfiltstr_obj); - WebRtcIsac_InitPostFilterbank( - &instISAC->ISACdecLB_obj.postfiltbankstr_obj); - WebRtcIsac_InitPitchFilter(&instISAC->ISACdecLB_obj.pitchfiltstr_obj); -} - -static void DecoderInitUb(ISACUBStruct* instISAC) { - int i; - /* Init stream vector to zero */ - for (i = 0; i < STREAM_SIZE_MAX_60; i++) { - instISAC->ISACdecUB_obj.bitstr_obj.stream[i] = 0; - } - - WebRtcIsac_InitMasking(&instISAC->ISACdecUB_obj.maskfiltstr_obj); - WebRtcIsac_InitPostFilterbank( - &instISAC->ISACdecUB_obj.postfiltbankstr_obj); -} - -void WebRtcIsac_DecoderInit(ISACStruct* ISAC_main_inst) { - ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; - - DecoderInitLb(&instISAC->instLB); - if (instISAC->decoderSamplingRateKHz == kIsacSuperWideband) { - memset(instISAC->synthesisFBState1, 0, - FB_STATE_SIZE_WORD32 * sizeof(int32_t)); - memset(instISAC->synthesisFBState2, 0, - FB_STATE_SIZE_WORD32 * sizeof(int32_t)); - DecoderInitUb(&(instISAC->instUB)); - } - if ((instISAC->initFlag & BIT_MASK_ENC_INIT) != BIT_MASK_ENC_INIT) { - WebRtcIsac_InitBandwidthEstimator(&instISAC->bwestimator_obj, - instISAC->encoderSamplingRateKHz, - instISAC->decoderSamplingRateKHz); - } - instISAC->initFlag |= BIT_MASK_DEC_INIT; - instISAC->resetFlag_8kHz = 0; -} - - -/**************************************************************************** - * WebRtcIsac_UpdateBwEstimate(...) - * - * This function updates the estimate of the bandwidth. - * - * NOTE: - * The estimates of bandwidth is not valid if the sample rate of the far-end - * encoder is set to 48 kHz and send timestamps are increamented according to - * 48 kHz sampling rate. - * - * Input: - * - ISAC_main_inst : ISAC instance. - * - encoded : encoded ISAC frame(s). - * - packet_size : size of the packet. - * - rtp_seq_number : the RTP number of the packet. - * - arr_ts : the arrival time of the packet (from NetEq) - * in samples. - * - * Return value : 0 - Ok - * -1 - Error - */ -int16_t WebRtcIsac_UpdateBwEstimate(ISACStruct* ISAC_main_inst, - const uint8_t* encoded, - size_t packet_size, - uint16_t rtp_seq_number, - uint32_t send_ts, - uint32_t arr_ts) { - ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; - Bitstr streamdata; -#ifndef WEBRTC_ARCH_BIG_ENDIAN - int k; -#endif - int16_t err; - - /* Check if decoder initiated. */ - if ((instISAC->initFlag & BIT_MASK_DEC_INIT) != BIT_MASK_DEC_INIT) { - instISAC->errorCode = ISAC_DECODER_NOT_INITIATED; - return -1; - } - - /* Check that the size of the packet is valid, and if not return without - * updating the bandwidth estimate. A valid size is at least 10 bytes. */ - if (packet_size < 10) { - /* Return error code if the packet length is null. */ - instISAC->errorCode = ISAC_EMPTY_PACKET; - return -1; - } - - WebRtcIsac_ResetBitstream(&(streamdata)); - -#ifndef WEBRTC_ARCH_BIG_ENDIAN - for (k = 0; k < 10; k++) { - uint16_t ek = ((const uint16_t*)encoded)[k >> 1]; - streamdata.stream[k] = (uint8_t)((ek >> ((k & 1) << 3)) & 0xff); - } -#else - memcpy(streamdata.stream, encoded, 10); -#endif - - err = WebRtcIsac_EstimateBandwidth(&instISAC->bwestimator_obj, &streamdata, - packet_size, rtp_seq_number, send_ts, - arr_ts, instISAC->encoderSamplingRateKHz, - instISAC->decoderSamplingRateKHz); - if (err < 0) { - /* Return error code if something went wrong. */ - instISAC->errorCode = -err; - return -1; - } - return 0; -} - -static int Decode(ISACStruct* ISAC_main_inst, - const uint8_t* encoded, - size_t lenEncodedBytes, - int16_t* decoded, - int16_t* speechType, - int16_t isRCUPayload) { - /* Number of samples (480 or 960), output from decoder - that were actually used in the encoder/decoder - (determined on the fly). */ - int16_t numSamplesLB; - int16_t numSamplesUB; - int16_t speechIdx; - float outFrame[MAX_FRAMESAMPLES]; - int16_t outFrameLB[MAX_FRAMESAMPLES]; - int16_t outFrameUB[MAX_FRAMESAMPLES]; - int numDecodedBytesLBint; - size_t numDecodedBytesLB; - int numDecodedBytesUB; - size_t lenEncodedLBBytes; - int16_t validChecksum = 1; - int16_t k; - uint16_t numLayer; - size_t totSizeBytes; - int16_t err; - - ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; - ISACUBDecStruct* decInstUB = &(instISAC->instUB.ISACdecUB_obj); - ISACLBDecStruct* decInstLB = &(instISAC->instLB.ISACdecLB_obj); - - /* Check if decoder initiated. */ - if ((instISAC->initFlag & BIT_MASK_DEC_INIT) != - BIT_MASK_DEC_INIT) { - instISAC->errorCode = ISAC_DECODER_NOT_INITIATED; - return -1; - } - - if (lenEncodedBytes == 0) { - /* return error code if the packet length is null. */ - instISAC->errorCode = ISAC_EMPTY_PACKET; - return -1; - } - - /* The size of the encoded lower-band is bounded by - * STREAM_SIZE_MAX. If a payload with the size larger than STREAM_SIZE_MAX - * is received, it is not considered erroneous. */ - lenEncodedLBBytes = (lenEncodedBytes > STREAM_SIZE_MAX) ? - STREAM_SIZE_MAX : lenEncodedBytes; - - /* Copy to lower-band bit-stream structure. */ - memcpy(instISAC->instLB.ISACdecLB_obj.bitstr_obj.stream, encoded, - lenEncodedLBBytes); - - /* We need to initialize numSamplesLB to something; otherwise, in the test - for whether we should return -1 below, the compiler might generate code - that fools Memcheck (Valgrind) into thinking that the control flow depends - on the uninitialized value in numSamplesLB (since WebRtcIsac_DecodeLb will - not fill it in if it fails and returns -1). */ - numSamplesLB = 0; - - /* Regardless of that the current codec is setup to work in - * wideband or super-wideband, the decoding of the lower-band - * has to be performed. */ - numDecodedBytesLBint = WebRtcIsac_DecodeLb(&instISAC->transform_tables, - outFrame, decInstLB, - &numSamplesLB, isRCUPayload); - numDecodedBytesLB = (size_t)numDecodedBytesLBint; - if ((numDecodedBytesLBint < 0) || - (numDecodedBytesLB > lenEncodedLBBytes) || - (numSamplesLB > MAX_FRAMESAMPLES)) { - instISAC->errorCode = ISAC_LENGTH_MISMATCH; - return -1; - } - - /* Error Check, we accept multi-layer bit-stream This will limit number - * of iterations of the while loop. Even without this the number - * of iterations is limited. */ - numLayer = 1; - totSizeBytes = numDecodedBytesLB; - while (totSizeBytes != lenEncodedBytes) { - if ((totSizeBytes > lenEncodedBytes) || - (encoded[totSizeBytes] == 0) || - (numLayer > MAX_NUM_LAYERS)) { - instISAC->errorCode = ISAC_LENGTH_MISMATCH; - return -1; - } - totSizeBytes += encoded[totSizeBytes]; - numLayer++; - } - - if (instISAC->decoderSamplingRateKHz == kIsacWideband) { - for (k = 0; k < numSamplesLB; k++) { - if (outFrame[k] > 32767) { - decoded[k] = 32767; - } else if (outFrame[k] < -32768) { - decoded[k] = -32768; - } else { - decoded[k] = (int16_t)WebRtcIsac_lrint(outFrame[k]); - } - } - numSamplesUB = 0; - } else { - uint32_t crc; - /* We don't accept larger than 30ms (480 samples at lower-band) - * frame-size. */ - for (k = 0; k < numSamplesLB; k++) { - if (outFrame[k] > 32767) { - outFrameLB[k] = 32767; - } else if (outFrame[k] < -32768) { - outFrameLB[k] = -32768; - } else { - outFrameLB[k] = (int16_t)WebRtcIsac_lrint(outFrame[k]); - } - } - - /* Check for possible error, and if upper-band stream exists. */ - if (numDecodedBytesLB == lenEncodedBytes) { - /* Decoding was successful. No super-wideband bit-stream exists. */ - numSamplesUB = numSamplesLB; - memset(outFrameUB, 0, sizeof(int16_t) * numSamplesUB); - - /* Prepare for the potential increase of signal bandwidth. */ - instISAC->resetFlag_8kHz = 2; - } else { - /* This includes the checksum and the bytes that stores the length. */ - int16_t lenNextStream = encoded[numDecodedBytesLB]; - - /* Is this garbage or valid super-wideband bit-stream? - * Check if checksum is valid. */ - if (lenNextStream <= (LEN_CHECK_SUM_WORD8 + 1)) { - /* Such a small second layer cannot be super-wideband layer. - * It must be a short garbage. */ - validChecksum = 0; - } else { - /* Run CRC to see if the checksum match. */ - WebRtcIsac_GetCrc((int16_t*)(&encoded[numDecodedBytesLB + 1]), - lenNextStream - LEN_CHECK_SUM_WORD8 - 1, &crc); - - validChecksum = 1; - for (k = 0; k < LEN_CHECK_SUM_WORD8; k++) { - validChecksum &= (((crc >> (24 - k * 8)) & 0xFF) == - encoded[numDecodedBytesLB + lenNextStream - - LEN_CHECK_SUM_WORD8 + k]); - } - } - - if (!validChecksum) { - /* This is a garbage, we have received a wideband - * bit-stream with garbage. */ - numSamplesUB = numSamplesLB; - memset(outFrameUB, 0, sizeof(int16_t) * numSamplesUB); - } else { - /* A valid super-wideband biststream exists. */ - enum ISACBandwidth bandwidthKHz; - int32_t maxDelayBit; - - /* If we have super-wideband bit-stream, we cannot - * have 60 ms frame-size. */ - if (numSamplesLB > FRAMESAMPLES) { - instISAC->errorCode = ISAC_LENGTH_MISMATCH; - return -1; - } - - /* The rest of the bit-stream contains the upper-band - * bit-stream curently this is the only thing there, - * however, we might add more layers. */ - - /* Have to exclude one byte where the length is stored - * and last 'LEN_CHECK_SUM_WORD8' bytes where the - * checksum is stored. */ - lenNextStream -= (LEN_CHECK_SUM_WORD8 + 1); - - memcpy(decInstUB->bitstr_obj.stream, - &encoded[numDecodedBytesLB + 1], lenNextStream); - - /* Reset bit-stream object, this is the first decoding. */ - WebRtcIsac_ResetBitstream(&(decInstUB->bitstr_obj)); - - /* Decode jitter information. */ - err = WebRtcIsac_DecodeJitterInfo(&decInstUB->bitstr_obj, &maxDelayBit); - if (err < 0) { - instISAC->errorCode = -err; - return -1; - } - - /* Update jitter info which is in the upper-band bit-stream - * only if the encoder is in super-wideband. Otherwise, - * the jitter info is already embedded in bandwidth index - * and has been updated. */ - if (instISAC->encoderSamplingRateKHz == kIsacSuperWideband) { - err = WebRtcIsac_UpdateUplinkJitter( - &(instISAC->bwestimator_obj), maxDelayBit); - if (err < 0) { - instISAC->errorCode = -err; - return -1; - } - } - - /* Decode bandwidth information. */ - err = WebRtcIsac_DecodeBandwidth(&decInstUB->bitstr_obj, - &bandwidthKHz); - if (err < 0) { - instISAC->errorCode = -err; - return -1; - } - - switch (bandwidthKHz) { - case isac12kHz: { - numDecodedBytesUB = WebRtcIsac_DecodeUb12( - &instISAC->transform_tables, outFrame, decInstUB, isRCUPayload); - - /* Hang-over for transient alleviation - - * wait two frames to add the upper band going up from 8 kHz. */ - if (instISAC->resetFlag_8kHz > 0) { - if (instISAC->resetFlag_8kHz == 2) { - /* Silence first and a half frame. */ - memset(outFrame, 0, MAX_FRAMESAMPLES * - sizeof(float)); - } else { - const float rampStep = 2.0f / MAX_FRAMESAMPLES; - float rampVal = 0; - memset(outFrame, 0, (MAX_FRAMESAMPLES >> 1) * - sizeof(float)); - - /* Ramp up second half of second frame. */ - for (k = MAX_FRAMESAMPLES / 2; k < MAX_FRAMESAMPLES; k++) { - outFrame[k] *= rampVal; - rampVal += rampStep; - } - } - instISAC->resetFlag_8kHz -= 1; - } - - break; - } - case isac16kHz: { - numDecodedBytesUB = WebRtcIsac_DecodeUb16( - &instISAC->transform_tables, outFrame, decInstUB, isRCUPayload); - break; - } - default: - return -1; - } - - if (numDecodedBytesUB < 0) { - instISAC->errorCode = numDecodedBytesUB; - return -1; - } - if (numDecodedBytesLB + numDecodedBytesUB > lenEncodedBytes) { - // We have supposedly decoded more bytes than we were given. Likely - // caused by bad input data. - instISAC->errorCode = ISAC_LENGTH_MISMATCH; - return -1; - } - - /* It might be less due to garbage. */ - if ((numDecodedBytesUB != lenNextStream) && - (numDecodedBytesLB + 1 + numDecodedBytesUB >= lenEncodedBytes || - numDecodedBytesUB != - (lenNextStream - - encoded[numDecodedBytesLB + 1 + numDecodedBytesUB]))) { - instISAC->errorCode = ISAC_LENGTH_MISMATCH; - return -1; - } - - /* If there is no error Upper-band always decodes - * 30 ms (480 samples). */ - numSamplesUB = FRAMESAMPLES; - - /* Convert to W16. */ - for (k = 0; k < numSamplesUB; k++) { - if (outFrame[k] > 32767) { - outFrameUB[k] = 32767; - } else if (outFrame[k] < -32768) { - outFrameUB[k] = -32768; - } else { - outFrameUB[k] = (int16_t)WebRtcIsac_lrint( - outFrame[k]); - } - } - } - } - - speechIdx = 0; - while (speechIdx < numSamplesLB) { - WebRtcSpl_SynthesisQMF(&outFrameLB[speechIdx], &outFrameUB[speechIdx], - FRAMESAMPLES_10ms, &decoded[(speechIdx << 1)], - instISAC->synthesisFBState1, - instISAC->synthesisFBState2); - - speechIdx += FRAMESAMPLES_10ms; - } - } - *speechType = 0; - return (numSamplesLB + numSamplesUB); -} - - - - - - - -/**************************************************************************** - * WebRtcIsac_Decode(...) - * - * This function decodes a ISAC frame. Output speech length - * will be a multiple of 480 samples: 480 or 960 samples, - * depending on the frameSize (30 or 60 ms). - * - * Input: - * - ISAC_main_inst : ISAC instance. - * - encoded : encoded ISAC frame(s) - * - len : bytes in encoded vector - * - * Output: - * - decoded : The decoded vector - * - * Return value : >0 - number of samples in decoded vector - * -1 - Error - */ - -int WebRtcIsac_Decode(ISACStruct* ISAC_main_inst, - const uint8_t* encoded, - size_t lenEncodedBytes, - int16_t* decoded, - int16_t* speechType) { - int16_t isRCUPayload = 0; - return Decode(ISAC_main_inst, encoded, lenEncodedBytes, decoded, - speechType, isRCUPayload); -} - -/**************************************************************************** - * WebRtcIsac_DecodeRcu(...) - * - * This function decodes a redundant (RCU) iSAC frame. Function is called in - * NetEq with a stored RCU payload in case of packet loss. Output speech length - * will be a multiple of 480 samples: 480 or 960 samples, - * depending on the framesize (30 or 60 ms). - * - * Input: - * - ISAC_main_inst : ISAC instance. - * - encoded : encoded ISAC RCU frame(s) - * - len : bytes in encoded vector - * - * Output: - * - decoded : The decoded vector - * - * Return value : >0 - number of samples in decoded vector - * -1 - Error - */ - - - -int WebRtcIsac_DecodeRcu(ISACStruct* ISAC_main_inst, - const uint8_t* encoded, - size_t lenEncodedBytes, - int16_t* decoded, - int16_t* speechType) { - int16_t isRCUPayload = 1; - return Decode(ISAC_main_inst, encoded, lenEncodedBytes, decoded, - speechType, isRCUPayload); -} - - -/**************************************************************************** - * WebRtcIsac_DecodePlc(...) - * - * This function conducts PLC for ISAC frame(s). Output speech length - * will be a multiple of 480 samples: 480 or 960 samples, - * depending on the frameSize (30 or 60 ms). - * - * Input: - * - ISAC_main_inst : ISAC instance. - * - noOfLostFrames : Number of PLC frames to produce - * - * Output: - * - decoded : The decoded vector - * - * Return value : Number of samples in decoded PLC vector - */ -size_t WebRtcIsac_DecodePlc(ISACStruct* ISAC_main_inst, - int16_t* decoded, - size_t noOfLostFrames) { - size_t numSamples = 0; - ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; - - /* Limit number of frames to two = 60 millisecond. - * Otherwise we exceed data vectors. */ - if (noOfLostFrames > 2) { - noOfLostFrames = 2; - } - - /* Get the number of samples per frame */ - switch (instISAC->decoderSamplingRateKHz) { - case kIsacWideband: { - numSamples = 480 * noOfLostFrames; - break; - } - case kIsacSuperWideband: { - numSamples = 960 * noOfLostFrames; - break; - } - } - - /* Set output samples to zero. */ - memset(decoded, 0, numSamples * sizeof(int16_t)); - return numSamples; -} - - -/**************************************************************************** - * ControlLb(...) - Internal function for controlling Lower Band - * ControlUb(...) - Internal function for controlling Upper Band - * WebRtcIsac_Control(...) - API function - * - * This function sets the limit on the short-term average bit rate and the - * frame length. Should be used only in Instantaneous mode. - * - * Input: - * - ISAC_main_inst : ISAC instance. - * - rate : limit on the short-term average bit rate, - * in bits/second (between 10000 and 32000) - * - frameSize : number of milliseconds per frame (30 or 60) - * - * Return value : 0 - ok - * -1 - Error - */ -static int16_t ControlLb(ISACLBStruct* instISAC, double rate, - int16_t frameSize) { - if ((rate >= 10000) && (rate <= 32000)) { - instISAC->ISACencLB_obj.bottleneck = rate; - } else { - return -ISAC_DISALLOWED_BOTTLENECK; - } - - if ((frameSize == 30) || (frameSize == 60)) { - instISAC->ISACencLB_obj.new_framelength = (FS / 1000) * frameSize; - } else { - return -ISAC_DISALLOWED_FRAME_LENGTH; - } - - return 0; -} - -static int16_t ControlUb(ISACUBStruct* instISAC, double rate) { - if ((rate >= 10000) && (rate <= 32000)) { - instISAC->ISACencUB_obj.bottleneck = rate; - } else { - return -ISAC_DISALLOWED_BOTTLENECK; - } - return 0; -} - -int16_t WebRtcIsac_Control(ISACStruct* ISAC_main_inst, - int32_t bottleneckBPS, - int frameSize) { - ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; - int16_t status; - double rateLB; - double rateUB; - enum ISACBandwidth bandwidthKHz; - - if (instISAC->codingMode == 0) { - /* In adaptive mode. */ - instISAC->errorCode = ISAC_MODE_MISMATCH; - return -1; - } - - /* Check if encoder initiated */ - if ((instISAC->initFlag & BIT_MASK_ENC_INIT) != - BIT_MASK_ENC_INIT) { - instISAC->errorCode = ISAC_ENCODER_NOT_INITIATED; - return -1; - } - - if (instISAC->encoderSamplingRateKHz == kIsacWideband) { - /* If the sampling rate is 16kHz then bandwith should be 8kHz, - * regardless of bottleneck. */ - bandwidthKHz = isac8kHz; - rateLB = (bottleneckBPS > 32000) ? 32000 : bottleneckBPS; - rateUB = 0; - } else { - if (WebRtcIsac_RateAllocation(bottleneckBPS, &rateLB, &rateUB, - &bandwidthKHz) < 0) { - return -1; - } - } - - if ((instISAC->encoderSamplingRateKHz == kIsacSuperWideband) && - (frameSize != 30) && - (bandwidthKHz != isac8kHz)) { - /* Cannot have 60 ms in super-wideband. */ - instISAC->errorCode = ISAC_DISALLOWED_FRAME_LENGTH; - return -1; - } - - status = ControlLb(&instISAC->instLB, rateLB, (int16_t)frameSize); - if (status < 0) { - instISAC->errorCode = -status; - return -1; - } - if (bandwidthKHz != isac8kHz) { - status = ControlUb(&(instISAC->instUB), rateUB); - if (status < 0) { - instISAC->errorCode = -status; - return -1; - } - } - - - /* Check if bandwidth is changing from wideband to super-wideband - * then we have to synch data buffer of lower & upper-band. Also - * clean up the upper-band data buffer. */ - - if ((instISAC->bandwidthKHz == isac8kHz) && (bandwidthKHz != isac8kHz)) { - memset(instISAC->instUB.ISACencUB_obj.data_buffer_float, 0, - sizeof(float) * (MAX_FRAMESAMPLES + LB_TOTAL_DELAY_SAMPLES)); - - if (bandwidthKHz == isac12kHz) { - instISAC->instUB.ISACencUB_obj.buffer_index = - instISAC->instLB.ISACencLB_obj.buffer_index; - } else { - instISAC->instUB.ISACencUB_obj.buffer_index = - LB_TOTAL_DELAY_SAMPLES + instISAC->instLB.ISACencLB_obj.buffer_index; - - memcpy(&(instISAC->instUB.ISACencUB_obj.lastLPCVec), - WebRtcIsac_kMeanLarUb16, sizeof(double) * UB_LPC_ORDER); - } - } - - /* Update the payload limit if the bandwidth is changing. */ - if (instISAC->bandwidthKHz != bandwidthKHz) { - instISAC->bandwidthKHz = bandwidthKHz; - UpdatePayloadSizeLimit(instISAC); - } - instISAC->bottleneck = bottleneckBPS; - return 0; -} - -void WebRtcIsac_SetInitialBweBottleneck(ISACStruct* ISAC_main_inst, - int bottleneck_bits_per_second) { - ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; - RTC_DCHECK_GE(bottleneck_bits_per_second, 10000); - RTC_DCHECK_LE(bottleneck_bits_per_second, 32000); - instISAC->bwestimator_obj.send_bw_avg = (float)bottleneck_bits_per_second; -} - -/**************************************************************************** - * WebRtcIsac_ControlBwe(...) - * - * This function sets the initial values of bottleneck and frame-size if - * iSAC is used in channel-adaptive mode. Through this API, users can - * enforce a frame-size for all values of bottleneck. Then iSAC will not - * automatically change the frame-size. - * - * - * Input: - * - ISAC_main_inst : ISAC instance. - * - rateBPS : initial value of bottleneck in bits/second - * 10000 <= rateBPS <= 32000 is accepted - * For default bottleneck set rateBPS = 0 - * - frameSizeMs : number of milliseconds per frame (30 or 60) - * - enforceFrameSize : 1 to enforce the given frame-size through out - * the adaptation process, 0 to let iSAC change - * the frame-size if required. - * - * Return value : 0 - ok - * -1 - Error - */ -int16_t WebRtcIsac_ControlBwe(ISACStruct* ISAC_main_inst, - int32_t bottleneckBPS, - int frameSizeMs, - int16_t enforceFrameSize) { - ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; - enum ISACBandwidth bandwidth; - - /* Check if encoder initiated */ - if ((instISAC->initFlag & BIT_MASK_ENC_INIT) != - BIT_MASK_ENC_INIT) { - instISAC->errorCode = ISAC_ENCODER_NOT_INITIATED; - return -1; - } - - /* Check that we are in channel-adaptive mode, otherwise, return (-1) */ - if (instISAC->codingMode != 0) { - instISAC->errorCode = ISAC_MODE_MISMATCH; - return -1; - } - if ((frameSizeMs != 30) && - (instISAC->encoderSamplingRateKHz == kIsacSuperWideband)) { - return -1; - } - - /* Set structure variable if enforceFrameSize is set. ISAC will then - * keep the chosen frame size. */ - if (enforceFrameSize != 0) { - instISAC->instLB.ISACencLB_obj.enforceFrameSize = 1; - } else { - instISAC->instLB.ISACencLB_obj.enforceFrameSize = 0; - } - - /* Set the initial rate. If the input value is zero then the default intial - * rate is used. Otehrwise, values between 10 to 32 kbps are accepted. */ - if (bottleneckBPS != 0) { - double rateLB; - double rateUB; - if (WebRtcIsac_RateAllocation(bottleneckBPS, &rateLB, &rateUB, - &bandwidth) < 0) { - return -1; - } - instISAC->bwestimator_obj.send_bw_avg = (float)bottleneckBPS; - instISAC->bandwidthKHz = bandwidth; - } - - /* Set the initial frame-size. If 'enforceFrameSize' is set, the frame-size - * will not change */ - if (frameSizeMs != 0) { - if ((frameSizeMs == 30) || (frameSizeMs == 60)) { - instISAC->instLB.ISACencLB_obj.new_framelength = - (int16_t)((FS / 1000) * frameSizeMs); - } else { - instISAC->errorCode = ISAC_DISALLOWED_FRAME_LENGTH; - return -1; - } - } - return 0; -} - - -/**************************************************************************** - * WebRtcIsac_GetDownLinkBwIndex(...) - * - * This function returns index representing the Bandwidth estimate from - * the other side to this side. - * - * Input: - * - ISAC_main_inst : iSAC structure - * - * Output: - * - bweIndex : Bandwidth estimate to transmit to other side. - * - */ -int16_t WebRtcIsac_GetDownLinkBwIndex(ISACStruct* ISAC_main_inst, - int16_t* bweIndex, - int16_t* jitterInfo) { - ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; - - /* Check if encoder initialized. */ - if ((instISAC->initFlag & BIT_MASK_DEC_INIT) != - BIT_MASK_DEC_INIT) { - instISAC->errorCode = ISAC_ENCODER_NOT_INITIATED; - return -1; - } - - /* Call function to get Bandwidth Estimate. */ - WebRtcIsac_GetDownlinkBwJitIndexImpl(&(instISAC->bwestimator_obj), bweIndex, - jitterInfo, - instISAC->decoderSamplingRateKHz); - return 0; -} - - -/**************************************************************************** - * WebRtcIsac_UpdateUplinkBw(...) - * - * This function takes an index representing the Bandwidth estimate from - * this side to other side and updates BWE. - * - * Input: - * - ISAC_main_inst : iSAC structure - * - rateIndex : Bandwidth estimate from other side. - * - * Return value : 0 - ok - * -1 - index out of range - */ -int16_t WebRtcIsac_UpdateUplinkBw(ISACStruct* ISAC_main_inst, - int16_t bweIndex) { - ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; - int16_t returnVal; - - /* Check if encoder initiated. */ - if ((instISAC->initFlag & BIT_MASK_ENC_INIT) != - BIT_MASK_ENC_INIT) { - instISAC->errorCode = ISAC_ENCODER_NOT_INITIATED; - return -1; - } - - /* Call function to get Bandwidth Estimate. */ - returnVal = WebRtcIsac_UpdateUplinkBwImpl( - &(instISAC->bwestimator_obj), bweIndex, - instISAC->encoderSamplingRateKHz); - - if (returnVal < 0) { - instISAC->errorCode = -returnVal; - return -1; - } else { - return 0; - } -} - - -/**************************************************************************** - * WebRtcIsac_ReadBwIndex(...) - * - * This function returns the index of the Bandwidth estimate from the - * bit-stream. - * - * Input: - * - encoded : Encoded bit-stream - * - * Output: - * - frameLength : Length of frame in packet (in samples) - * - bweIndex : Bandwidth estimate in bit-stream - * - */ -int16_t WebRtcIsac_ReadBwIndex(const uint8_t* encoded, - int16_t* bweIndex) { - Bitstr streamdata; -#ifndef WEBRTC_ARCH_BIG_ENDIAN - int k; -#endif - int16_t err; - - WebRtcIsac_ResetBitstream(&(streamdata)); - -#ifndef WEBRTC_ARCH_BIG_ENDIAN - for (k = 0; k < 10; k++) { - int16_t ek2 = ((const int16_t*)encoded)[k >> 1]; - streamdata.stream[k] = (uint8_t)((ek2 >> ((k & 1) << 3)) & 0xff); - } -#else - memcpy(streamdata.stream, encoded, 10); -#endif - - /* Decode frame length. */ - err = WebRtcIsac_DecodeFrameLen(&streamdata, bweIndex); - if (err < 0) { - return err; - } - - /* Decode BW estimation. */ - err = WebRtcIsac_DecodeSendBW(&streamdata, bweIndex); - if (err < 0) { - return err; - } - - return 0; -} - - -/**************************************************************************** - * WebRtcIsac_ReadFrameLen(...) - * - * This function returns the number of samples the decoder will generate if - * the given payload is decoded. - * - * Input: - * - encoded : Encoded bitstream - * - * Output: - * - frameLength : Length of frame in packet (in samples) - * - */ -int16_t WebRtcIsac_ReadFrameLen(const ISACStruct* ISAC_main_inst, - const uint8_t* encoded, - int16_t* frameLength) { - Bitstr streamdata; -#ifndef WEBRTC_ARCH_BIG_ENDIAN - int k; -#endif - int16_t err; - ISACMainStruct* instISAC; - - WebRtcIsac_ResetBitstream(&(streamdata)); - -#ifndef WEBRTC_ARCH_BIG_ENDIAN - for (k = 0; k < 10; k++) { - int16_t ek2 = ((const int16_t*)encoded)[k >> 1]; - streamdata.stream[k] = (uint8_t)((ek2 >> ((k & 1) << 3)) & 0xff); - } -#else - memcpy(streamdata.stream, encoded, 10); -#endif - - /* Decode frame length. */ - err = WebRtcIsac_DecodeFrameLen(&streamdata, frameLength); - if (err < 0) { - return -1; - } - instISAC = (ISACMainStruct*)ISAC_main_inst; - - if (instISAC->decoderSamplingRateKHz == kIsacSuperWideband) { - /* The decoded frame length indicates the number of samples in - * lower-band in this case, multiply by 2 to get the total number - * of samples. */ - *frameLength <<= 1; - } - return 0; -} - - -/******************************************************************************* - * WebRtcIsac_GetNewFrameLen(...) - * - * This function returns the frame length (in samples) of the next packet. - * In the case of channel-adaptive mode, iSAC decides on its frame length based - * on the estimated bottleneck, this AOI allows a user to prepare for the next - * packet (at the encoder). - * - * The primary usage is in CE to make the iSAC works in channel-adaptive mode - * - * Input: - * - ISAC_main_inst : iSAC struct - * - * Return Value : frame lenght in samples - * - */ -int16_t WebRtcIsac_GetNewFrameLen(ISACStruct* ISAC_main_inst) { - ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; - - /* Return new frame length. */ - if (instISAC->in_sample_rate_hz == 16000) - return (instISAC->instLB.ISACencLB_obj.new_framelength); - else /* 32000 Hz */ - return ((instISAC->instLB.ISACencLB_obj.new_framelength) * 2); -} - - -/**************************************************************************** - * WebRtcIsac_GetErrorCode(...) - * - * This function can be used to check the error code of an iSAC instance. - * When a function returns -1 an error code will be set for that instance. - * The function below extracts the code of the last error that occurred in - * the specified instance. - * - * Input: - * - ISAC_main_inst : ISAC instance - * - * Return value : Error code - */ -int16_t WebRtcIsac_GetErrorCode(ISACStruct* ISAC_main_inst) { - return ((ISACMainStruct*)ISAC_main_inst)->errorCode; -} - - -/**************************************************************************** - * WebRtcIsac_GetUplinkBw(...) - * - * This function outputs the target bottleneck of the codec. In - * channel-adaptive mode, the target bottleneck is specified through an in-band - * signalling retrieved by bandwidth estimator. - * In channel-independent, also called instantaneous mode, the target - * bottleneck is provided to the encoder by calling xxx_control(...) (if - * xxx_control is never called, the default values are used.). - * Note that the output is the iSAC internal operating bottleneck which might - * differ slightly from the one provided through xxx_control(). - * - * Input: - * - ISAC_main_inst : iSAC instance - * - * Output: - * - *bottleneck : bottleneck in bits/sec - * - * Return value : -1 if error happens - * 0 bit-rates computed correctly. - */ -int16_t WebRtcIsac_GetUplinkBw(ISACStruct* ISAC_main_inst, - int32_t* bottleneck) { - ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; - - if (instISAC->codingMode == 0) { - /* We are in adaptive mode then get the bottleneck from BWE. */ - *bottleneck = (int32_t)instISAC->bwestimator_obj.send_bw_avg; - } else { - *bottleneck = instISAC->bottleneck; - } - - if ((*bottleneck > 32000) && (*bottleneck < 38000)) { - *bottleneck = 32000; - } else if ((*bottleneck > 45000) && (*bottleneck < 50000)) { - *bottleneck = 45000; - } else if (*bottleneck > 56000) { - *bottleneck = 56000; - } - return 0; -} - - -/****************************************************************************** - * WebRtcIsac_SetMaxPayloadSize(...) - * - * This function sets a limit for the maximum payload size of iSAC. The same - * value is used both for 30 and 60 ms packets. If the encoder sampling rate - * is 16 kHz the maximum payload size is between 120 and 400 bytes. If the - * encoder sampling rate is 32 kHz the maximum payload size is between 120 - * and 600 bytes. - * - * --------------- - * IMPORTANT NOTES - * --------------- - * The size of a packet is limited to the minimum of 'max-payload-size' and - * 'max-rate.' For instance, let's assume the max-payload-size is set to - * 170 bytes, and max-rate is set to 40 kbps. Note that a limit of 40 kbps - * translates to 150 bytes for 30ms frame-size & 300 bytes for 60ms - * frame-size. Then a packet with a frame-size of 30 ms is limited to 150, - * i.e. min(170, 150), and a packet with 60 ms frame-size is limited to - * 170 bytes, i.e. min(170, 300). - * - * Input: - * - ISAC_main_inst : iSAC instance - * - maxPayloadBytes : maximum size of the payload in bytes - * valid values are between 100 and 400 bytes - * if encoder sampling rate is 16 kHz. For - * 32 kHz encoder sampling rate valid values - * are between 100 and 600 bytes. - * - * Return value : 0 if successful - * -1 if error happens - */ -int16_t WebRtcIsac_SetMaxPayloadSize(ISACStruct* ISAC_main_inst, - int16_t maxPayloadBytes) { - ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; - int16_t status = 0; - - /* Check if encoder initiated */ - if ((instISAC->initFlag & BIT_MASK_ENC_INIT) != - BIT_MASK_ENC_INIT) { - instISAC->errorCode = ISAC_ENCODER_NOT_INITIATED; - return -1; - } - - if (instISAC->encoderSamplingRateKHz == kIsacSuperWideband) { - /* Sanity check. */ - if (maxPayloadBytes < 120) { - /* 'maxRate' is out of valid range - * set to the acceptable value and return -1. */ - maxPayloadBytes = 120; - status = -1; - } - - /* sanity check */ - if (maxPayloadBytes > STREAM_SIZE_MAX) { - /* maxRate is out of valid range, - * set to the acceptable value and return -1. */ - maxPayloadBytes = STREAM_SIZE_MAX; - status = -1; - } - } else { - if (maxPayloadBytes < 120) { - /* Max payload-size is out of valid range - * set to the acceptable value and return -1. */ - maxPayloadBytes = 120; - status = -1; - } - if (maxPayloadBytes > STREAM_SIZE_MAX_60) { - /* Max payload-size is out of valid range - * set to the acceptable value and return -1. */ - maxPayloadBytes = STREAM_SIZE_MAX_60; - status = -1; - } - } - instISAC->maxPayloadSizeBytes = maxPayloadBytes; - UpdatePayloadSizeLimit(instISAC); - return status; -} - - -/****************************************************************************** - * WebRtcIsac_SetMaxRate(...) - * - * This function sets the maximum rate which the codec may not exceed for - * any signal packet. The maximum rate is defined and payload-size per - * frame-size in bits per second. - * - * The codec has a maximum rate of 53400 bits per second (200 bytes per 30 - * ms) if the encoder sampling rate is 16kHz, and 160 kbps (600 bytes/30 ms) - * if the encoder sampling rate is 32 kHz. - * - * It is possible to set a maximum rate between 32000 and 53400 bits/sec - * in wideband mode, and 32000 to 160000 bits/sec in super-wideband mode. - * - * --------------- - * IMPORTANT NOTES - * --------------- - * The size of a packet is limited to the minimum of 'max-payload-size' and - * 'max-rate.' For instance, let's assume the max-payload-size is set to - * 170 bytes, and max-rate is set to 40 kbps. Note that a limit of 40 kbps - * translates to 150 bytes for 30ms frame-size & 300 bytes for 60ms - * frame-size. Then a packet with a frame-size of 30 ms is limited to 150, - * i.e. min(170, 150), and a packet with 60 ms frame-size is limited to - * 170 bytes, min(170, 300). - * - * Input: - * - ISAC_main_inst : iSAC instance - * - maxRate : maximum rate in bits per second, - * valid values are 32000 to 53400 bits/sec in - * wideband mode, and 32000 to 160000 bits/sec in - * super-wideband mode. - * - * Return value : 0 if successful - * -1 if error happens - */ -int16_t WebRtcIsac_SetMaxRate(ISACStruct* ISAC_main_inst, - int32_t maxRate) { - ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; - int16_t maxRateInBytesPer30Ms; - int16_t status = 0; - - /* check if encoder initiated */ - if ((instISAC->initFlag & BIT_MASK_ENC_INIT) != BIT_MASK_ENC_INIT) { - instISAC->errorCode = ISAC_ENCODER_NOT_INITIATED; - return -1; - } - /* Calculate maximum number of bytes per 30 msec packets for the - given maximum rate. Multiply with 30/1000 to get number of - bits per 30 ms, divide by 8 to get number of bytes per 30 ms: - maxRateInBytes = floor((maxRate * 30/1000) / 8); */ - maxRateInBytesPer30Ms = (int16_t)(maxRate * 3 / 800); - - if (instISAC->encoderSamplingRateKHz == kIsacWideband) { - if (maxRate < 32000) { - /* 'maxRate' is out of valid range. - * Set to the acceptable value and return -1. */ - maxRateInBytesPer30Ms = 120; - status = -1; - } - - if (maxRate > 53400) { - /* 'maxRate' is out of valid range. - * Set to the acceptable value and return -1. */ - maxRateInBytesPer30Ms = 200; - status = -1; - } - } else { - if (maxRateInBytesPer30Ms < 120) { - /* 'maxRate' is out of valid range - * Set to the acceptable value and return -1. */ - maxRateInBytesPer30Ms = 120; - status = -1; - } - - if (maxRateInBytesPer30Ms > STREAM_SIZE_MAX) { - /* 'maxRate' is out of valid range. - * Set to the acceptable value and return -1. */ - maxRateInBytesPer30Ms = STREAM_SIZE_MAX; - status = -1; - } - } - instISAC->maxRateBytesPer30Ms = maxRateInBytesPer30Ms; - UpdatePayloadSizeLimit(instISAC); - return status; -} - - -/**************************************************************************** - * WebRtcIsac_GetRedPayload(...) - * - * This function populates "encoded" with the redundant payload of the recently - * encodedframe. This function has to be called once that WebRtcIsac_Encode(...) - * returns a positive value. Regardless of the frame-size this function will - * be called only once after encoding is completed. The bit-stream is - * targeted for 16000 bit/sec. - * - * Input: - * - ISAC_main_inst : iSAC struct - * - * Output: - * - encoded : the encoded data vector - * - * - * Return value : >0 - Length (in bytes) of coded data - * : -1 - Error - */ -int16_t WebRtcIsac_GetRedPayload(ISACStruct* ISAC_main_inst, - uint8_t* encoded) { - Bitstr iSACBitStreamInst; - int16_t streamLenLB; - int16_t streamLenUB; - int16_t streamLen; - int16_t totalLenUB; - ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; -#ifndef WEBRTC_ARCH_BIG_ENDIAN - int k; -#endif - - if ((instISAC->initFlag & BIT_MASK_ENC_INIT) != - BIT_MASK_ENC_INIT) { - instISAC->errorCode = ISAC_ENCODER_NOT_INITIATED; - } - - WebRtcIsac_ResetBitstream(&(iSACBitStreamInst)); - - streamLenLB = WebRtcIsac_EncodeStoredDataLb( - &instISAC->instLB.ISACencLB_obj.SaveEnc_obj, - &iSACBitStreamInst, - instISAC->instLB.ISACencLB_obj.lastBWIdx, - RCU_TRANSCODING_SCALE); - if (streamLenLB < 0) { - return -1; - } - - /* convert from bytes to int16_t. */ - memcpy(encoded, iSACBitStreamInst.stream, streamLenLB); - streamLen = streamLenLB; - if (instISAC->bandwidthKHz == isac8kHz) { - return streamLenLB; - } - - streamLenUB = WebRtcIsac_GetRedPayloadUb( - &instISAC->instUB.ISACencUB_obj.SaveEnc_obj, - &iSACBitStreamInst, instISAC->bandwidthKHz); - if (streamLenUB < 0) { - /* An error has happened but this is not the error due to a - * bit-stream larger than the limit. */ - return -1; - } - - /* We have one byte to write the total length of the upper-band. - * The length includes the bit-stream length, check-sum and the - * single byte where the length is written to. This is according to - * iSAC wideband and how the "garbage" is dealt. */ - totalLenUB = streamLenUB + 1 + LEN_CHECK_SUM_WORD8; - if (totalLenUB > 255) { - streamLenUB = 0; - } - - /* Generate CRC if required. */ - if ((instISAC->bandwidthKHz != isac8kHz) && - (streamLenUB > 0)) { - uint32_t crc; - streamLen += totalLenUB; - encoded[streamLenLB] = (uint8_t)totalLenUB; - memcpy(&encoded[streamLenLB + 1], iSACBitStreamInst.stream, - streamLenUB); - - WebRtcIsac_GetCrc((int16_t*)(&(encoded[streamLenLB + 1])), - streamLenUB, &crc); -#ifndef WEBRTC_ARCH_BIG_ENDIAN - for (k = 0; k < LEN_CHECK_SUM_WORD8; k++) { - encoded[streamLen - LEN_CHECK_SUM_WORD8 + k] = - (uint8_t)((crc >> (24 - k * 8)) & 0xFF); - } -#else - memcpy(&encoded[streamLenLB + streamLenUB + 1], &crc, - LEN_CHECK_SUM_WORD8); -#endif - } - return streamLen; -} - - -/**************************************************************************** - * WebRtcIsac_version(...) - * - * This function returns the version number. - * - * Output: - * - version : Pointer to character string - * - */ -void WebRtcIsac_version(char* version) { - strcpy(version, "4.3.0"); -} - - -/****************************************************************************** - * WebRtcIsac_SetEncSampRate() - * This function sets the sampling rate of the encoder. Initialization of the - * encoder WILL NOT overwrite the sampling rate of the encoder. The default - * value is 16 kHz which is set when the instance is created. The encoding-mode - * and the bottleneck remain unchanged by this call, however, the maximum rate - * and maximum payload-size will be reset to their default values. - * - * Input: - * - ISAC_main_inst : iSAC instance - * - sample_rate_hz : sampling rate in Hertz, valid values are 16000 - * and 32000. - * - * Return value : 0 if successful - * -1 if failed. - */ -int16_t WebRtcIsac_SetEncSampRate(ISACStruct* ISAC_main_inst, - uint16_t sample_rate_hz) { - ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; - enum IsacSamplingRate encoder_operational_rate; - - if ((sample_rate_hz != 16000) && (sample_rate_hz != 32000)) { - /* Sampling Frequency is not supported. */ - instISAC->errorCode = ISAC_UNSUPPORTED_SAMPLING_FREQUENCY; - return -1; - } - if (sample_rate_hz == 16000) { - encoder_operational_rate = kIsacWideband; - } else { - encoder_operational_rate = kIsacSuperWideband; - } - - if ((instISAC->initFlag & BIT_MASK_ENC_INIT) != - BIT_MASK_ENC_INIT) { - if (encoder_operational_rate == kIsacWideband) { - instISAC->bandwidthKHz = isac8kHz; - } else { - instISAC->bandwidthKHz = isac16kHz; - } - } else { - ISACUBStruct* instUB = &(instISAC->instUB); - ISACLBStruct* instLB = &(instISAC->instLB); - int32_t bottleneck = instISAC->bottleneck; - int16_t codingMode = instISAC->codingMode; - int16_t frameSizeMs = instLB->ISACencLB_obj.new_framelength / - (FS / 1000); - - if ((encoder_operational_rate == kIsacWideband) && - (instISAC->encoderSamplingRateKHz == kIsacSuperWideband)) { - /* Changing from super-wideband to wideband. - * we don't need to re-initialize the encoder of the lower-band. */ - instISAC->bandwidthKHz = isac8kHz; - if (codingMode == 1) { - ControlLb(instLB, - (bottleneck > 32000) ? 32000 : bottleneck, FRAMESIZE); - } - instISAC->maxPayloadSizeBytes = STREAM_SIZE_MAX_60; - instISAC->maxRateBytesPer30Ms = STREAM_SIZE_MAX_30; - } else if ((encoder_operational_rate == kIsacSuperWideband) && - (instISAC->encoderSamplingRateKHz == kIsacWideband)) { - double bottleneckLB = 0; - double bottleneckUB = 0; - if (codingMode == 1) { - WebRtcIsac_RateAllocation(bottleneck, &bottleneckLB, &bottleneckUB, - &(instISAC->bandwidthKHz)); - } - - instISAC->bandwidthKHz = isac16kHz; - instISAC->maxPayloadSizeBytes = STREAM_SIZE_MAX; - instISAC->maxRateBytesPer30Ms = STREAM_SIZE_MAX; - - EncoderInitLb(instLB, codingMode, encoder_operational_rate); - EncoderInitUb(instUB, instISAC->bandwidthKHz); - - memset(instISAC->analysisFBState1, 0, - FB_STATE_SIZE_WORD32 * sizeof(int32_t)); - memset(instISAC->analysisFBState2, 0, - FB_STATE_SIZE_WORD32 * sizeof(int32_t)); - - if (codingMode == 1) { - instISAC->bottleneck = bottleneck; - ControlLb(instLB, bottleneckLB, - (instISAC->bandwidthKHz == isac8kHz) ? frameSizeMs:FRAMESIZE); - if (instISAC->bandwidthKHz > isac8kHz) { - ControlUb(instUB, bottleneckUB); - } - } else { - instLB->ISACencLB_obj.enforceFrameSize = 0; - instLB->ISACencLB_obj.new_framelength = FRAMESAMPLES; - } - } - } - instISAC->encoderSamplingRateKHz = encoder_operational_rate; - instISAC->in_sample_rate_hz = sample_rate_hz; - return 0; -} - - -/****************************************************************************** - * WebRtcIsac_SetDecSampRate() - * This function sets the sampling rate of the decoder. Initialization of the - * decoder WILL NOT overwrite the sampling rate of the encoder. The default - * value is 16 kHz which is set when the instance is created. - * - * Input: - * - ISAC_main_inst : iSAC instance - * - sample_rate_hz : sampling rate in Hertz, valid values are 16000 - * and 32000. - * - * Return value : 0 if successful - * -1 if failed. - */ -int16_t WebRtcIsac_SetDecSampRate(ISACStruct* ISAC_main_inst, - uint16_t sample_rate_hz) { - ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; - enum IsacSamplingRate decoder_operational_rate; - - if (sample_rate_hz == 16000) { - decoder_operational_rate = kIsacWideband; - } else if (sample_rate_hz == 32000) { - decoder_operational_rate = kIsacSuperWideband; - } else { - /* Sampling Frequency is not supported. */ - instISAC->errorCode = ISAC_UNSUPPORTED_SAMPLING_FREQUENCY; - return -1; - } - - if ((instISAC->decoderSamplingRateKHz == kIsacWideband) && - (decoder_operational_rate == kIsacSuperWideband)) { - /* Switching from wideband to super-wideband at the decoder - * we need to reset the filter-bank and initialize upper-band decoder. */ - memset(instISAC->synthesisFBState1, 0, - FB_STATE_SIZE_WORD32 * sizeof(int32_t)); - memset(instISAC->synthesisFBState2, 0, - FB_STATE_SIZE_WORD32 * sizeof(int32_t)); - - DecoderInitUb(&instISAC->instUB); - } - instISAC->decoderSamplingRateKHz = decoder_operational_rate; - return 0; -} - - -/****************************************************************************** - * WebRtcIsac_EncSampRate() - * - * Input: - * - ISAC_main_inst : iSAC instance - * - * Return value : sampling rate in Hertz. The input to encoder - * is expected to be sampled in this rate. - * - */ -uint16_t WebRtcIsac_EncSampRate(ISACStruct* ISAC_main_inst) { - ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; - return instISAC->in_sample_rate_hz; -} - - -/****************************************************************************** - * WebRtcIsac_DecSampRate() - * Return the sampling rate of the decoded audio. - * - * Input: - * - ISAC_main_inst : iSAC instance - * - * Return value : sampling rate in Hertz. Decoder output is - * sampled at this rate. - * - */ -uint16_t WebRtcIsac_DecSampRate(ISACStruct* ISAC_main_inst) { - ISACMainStruct* instISAC = (ISACMainStruct*)ISAC_main_inst; - return instISAC->decoderSamplingRateKHz == kIsacWideband ? 16000 : 32000; -} - -void WebRtcIsac_SetEncSampRateInDecoder(ISACStruct* inst, - int sample_rate_hz) { - ISACMainStruct* instISAC = (ISACMainStruct*)inst; - RTC_DCHECK_NE(0, instISAC->initFlag & BIT_MASK_DEC_INIT); - RTC_DCHECK(!(instISAC->initFlag & BIT_MASK_ENC_INIT)); - RTC_DCHECK(sample_rate_hz == 16000 || sample_rate_hz == 32000); - instISAC->encoderSamplingRateKHz = sample_rate_hz / 1000; -} diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/isac_float_type.h b/webrtc/modules/audio_coding/codecs/isac/main/source/isac_float_type.h deleted file mode 100644 index 511bc97..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/isac_float_type.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ISAC_FLOAT_TYPE_H_ -#define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ISAC_FLOAT_TYPE_H_ - -#include "modules/audio_coding/codecs/isac/main/include/isac.h" - -namespace webrtc { - -struct IsacFloat { - using instance_type = ISACStruct; - static const bool has_swb = true; - static inline int16_t Control(instance_type* inst, - int32_t rate, - int framesize) { - return WebRtcIsac_Control(inst, rate, framesize); - } - static inline int16_t ControlBwe(instance_type* inst, - int32_t rate_bps, - int frame_size_ms, - int16_t enforce_frame_size) { - return WebRtcIsac_ControlBwe(inst, rate_bps, frame_size_ms, - enforce_frame_size); - } - static inline int16_t Create(instance_type** inst) { - return WebRtcIsac_Create(inst); - } - static inline int DecodeInternal(instance_type* inst, - const uint8_t* encoded, - size_t len, - int16_t* decoded, - int16_t* speech_type) { - return WebRtcIsac_Decode(inst, encoded, len, decoded, speech_type); - } - static inline size_t DecodePlc(instance_type* inst, - int16_t* decoded, - size_t num_lost_frames) { - return WebRtcIsac_DecodePlc(inst, decoded, num_lost_frames); - } - - static inline void DecoderInit(instance_type* inst) { - WebRtcIsac_DecoderInit(inst); - } - static inline int Encode(instance_type* inst, - const int16_t* speech_in, - uint8_t* encoded) { - return WebRtcIsac_Encode(inst, speech_in, encoded); - } - static inline int16_t EncoderInit(instance_type* inst, int16_t coding_mode) { - return WebRtcIsac_EncoderInit(inst, coding_mode); - } - static inline uint16_t EncSampRate(instance_type* inst) { - return WebRtcIsac_EncSampRate(inst); - } - - static inline int16_t Free(instance_type* inst) { - return WebRtcIsac_Free(inst); - } - static inline int16_t GetErrorCode(instance_type* inst) { - return WebRtcIsac_GetErrorCode(inst); - } - - static inline int16_t GetNewFrameLen(instance_type* inst) { - return WebRtcIsac_GetNewFrameLen(inst); - } - static inline int16_t SetDecSampRate(instance_type* inst, - uint16_t sample_rate_hz) { - return WebRtcIsac_SetDecSampRate(inst, sample_rate_hz); - } - static inline int16_t SetEncSampRate(instance_type* inst, - uint16_t sample_rate_hz) { - return WebRtcIsac_SetEncSampRate(inst, sample_rate_hz); - } - static inline void SetEncSampRateInDecoder(instance_type* inst, - uint16_t sample_rate_hz) { - WebRtcIsac_SetEncSampRateInDecoder(inst, sample_rate_hz); - } - static inline void SetInitialBweBottleneck(instance_type* inst, - int bottleneck_bits_per_second) { - WebRtcIsac_SetInitialBweBottleneck(inst, bottleneck_bits_per_second); - } - static inline int16_t SetMaxPayloadSize(instance_type* inst, - int16_t max_payload_size_bytes) { - return WebRtcIsac_SetMaxPayloadSize(inst, max_payload_size_bytes); - } - static inline int16_t SetMaxRate(instance_type* inst, int32_t max_bit_rate) { - return WebRtcIsac_SetMaxRate(inst, max_bit_rate); - } -}; - -} // namespace webrtc -#endif // MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ISAC_FLOAT_TYPE_H_ diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/lattice.c b/webrtc/modules/audio_coding/codecs/isac/main/source/lattice.c deleted file mode 100644 index d9d2d65..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/lattice.c +++ /dev/null @@ -1,219 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -/* - * lattice.c - * - * contains the normalized lattice filter routines (MA and AR) for iSAC codec - * - */ - -#include -#include -#include -#ifdef WEBRTC_ANDROID -#include -#endif - -#include "modules/audio_coding/codecs/isac/main/source/settings.h" -#include "modules/audio_coding/codecs/isac/main/source/codec.h" - -/* filter the signal using normalized lattice filter */ -/* MA filter */ -void WebRtcIsac_NormLatticeFilterMa(int orderCoef, - float *stateF, - float *stateG, - float *lat_in, - double *filtcoeflo, - double *lat_out) -{ - int n,k,i,u,temp1; - int ord_1 = orderCoef+1; - float sth[MAX_AR_MODEL_ORDER]; - float cth[MAX_AR_MODEL_ORDER]; - float inv_cth[MAX_AR_MODEL_ORDER]; - double a[MAX_AR_MODEL_ORDER+1]; - float f[MAX_AR_MODEL_ORDER+1][HALF_SUBFRAMELEN], g[MAX_AR_MODEL_ORDER+1][HALF_SUBFRAMELEN]; - float gain1; - - for (u=0;u=0;i--) //get the state of f&g for the first input, for all orders - { - ARf[i][0] = cth[i]*ARf[i+1][0] - sth[i]*stateG[i]; - ARg[i+1][0] = sth[i]*ARf[i+1][0] + cth[i]* stateG[i]; - } - ARg[0][0] = ARf[0][0]; - - for(n=0;n<(HALF_SUBFRAMELEN-1);n++) - { - for(k=orderCoef-1;k>=0;k--) - { - ARf[k][n+1] = cth[k]*ARf[k+1][n+1] - sth[k]*ARg[k][n]; - ARg[k+1][n+1] = sth[k]*ARf[k+1][n+1] + cth[k]* ARg[k][n]; - } - ARg[0][n+1] = ARf[0][n+1]; - } - - memcpy(lat_out+u * HALF_SUBFRAMELEN, &(ARf[0][0]), sizeof(float) * HALF_SUBFRAMELEN); - - /* cannot use memcpy in the following */ - for (i=0;i0; m--) - { - tmp_inv = 1.0f / cth2; - for (k=1; k<=m; k++) - { - tmp[k] = ((float)a[k] - sth[m] * (float)a[m-k+1]) * tmp_inv; - } - - for (k=1; k -#include - -#include "modules/audio_coding/codecs/isac/main/source/lpc_analysis.h" -#include "modules/audio_coding/codecs/isac/main/source/settings.h" -#include "modules/audio_coding/codecs/isac/main/source/codec.h" -#include "modules/audio_coding/codecs/isac/main/source/entropy_coding.h" -#include "modules/audio_coding/codecs/isac/main/source/filter_functions.h" -#include "modules/audio_coding/codecs/isac/main/source/isac_vad.h" - -/* window */ -/* Matlab generation code: - * t = (1:256)/257; r = 1-(1-t).^.45; w = sin(r*pi).^3; w = w/sum(w); plot((1:256)/8, w); grid; - * for k=1:16, fprintf(1, '%.8f, ', w(k*16 + (-15:0))); fprintf(1, '\n'); end - */ -static const double kLpcCorrWindow[WINLEN] = { - 0.00000000, 0.00000001, 0.00000004, 0.00000010, 0.00000020, - 0.00000035, 0.00000055, 0.00000083, 0.00000118, 0.00000163, - 0.00000218, 0.00000283, 0.00000361, 0.00000453, 0.00000558, 0.00000679, - 0.00000817, 0.00000973, 0.00001147, 0.00001342, 0.00001558, - 0.00001796, 0.00002058, 0.00002344, 0.00002657, 0.00002997, - 0.00003365, 0.00003762, 0.00004190, 0.00004651, 0.00005144, 0.00005673, - 0.00006236, 0.00006837, 0.00007476, 0.00008155, 0.00008875, - 0.00009636, 0.00010441, 0.00011290, 0.00012186, 0.00013128, - 0.00014119, 0.00015160, 0.00016252, 0.00017396, 0.00018594, 0.00019846, - 0.00021155, 0.00022521, 0.00023946, 0.00025432, 0.00026978, - 0.00028587, 0.00030260, 0.00031998, 0.00033802, 0.00035674, - 0.00037615, 0.00039626, 0.00041708, 0.00043863, 0.00046092, 0.00048396, - 0.00050775, 0.00053233, 0.00055768, 0.00058384, 0.00061080, - 0.00063858, 0.00066720, 0.00069665, 0.00072696, 0.00075813, - 0.00079017, 0.00082310, 0.00085692, 0.00089164, 0.00092728, 0.00096384, - 0.00100133, 0.00103976, 0.00107914, 0.00111947, 0.00116077, - 0.00120304, 0.00124630, 0.00129053, 0.00133577, 0.00138200, - 0.00142924, 0.00147749, 0.00152676, 0.00157705, 0.00162836, 0.00168070, - 0.00173408, 0.00178850, 0.00184395, 0.00190045, 0.00195799, - 0.00201658, 0.00207621, 0.00213688, 0.00219860, 0.00226137, - 0.00232518, 0.00239003, 0.00245591, 0.00252284, 0.00259079, 0.00265977, - 0.00272977, 0.00280078, 0.00287280, 0.00294582, 0.00301984, - 0.00309484, 0.00317081, 0.00324774, 0.00332563, 0.00340446, - 0.00348421, 0.00356488, 0.00364644, 0.00372889, 0.00381220, 0.00389636, - 0.00398135, 0.00406715, 0.00415374, 0.00424109, 0.00432920, - 0.00441802, 0.00450754, 0.00459773, 0.00468857, 0.00478001, - 0.00487205, 0.00496464, 0.00505775, 0.00515136, 0.00524542, 0.00533990, - 0.00543476, 0.00552997, 0.00562548, 0.00572125, 0.00581725, - 0.00591342, 0.00600973, 0.00610612, 0.00620254, 0.00629895, - 0.00639530, 0.00649153, 0.00658758, 0.00668341, 0.00677894, 0.00687413, - 0.00696891, 0.00706322, 0.00715699, 0.00725016, 0.00734266, - 0.00743441, 0.00752535, 0.00761540, 0.00770449, 0.00779254, - 0.00787947, 0.00796519, 0.00804963, 0.00813270, 0.00821431, 0.00829437, - 0.00837280, 0.00844949, 0.00852436, 0.00859730, 0.00866822, - 0.00873701, 0.00880358, 0.00886781, 0.00892960, 0.00898884, - 0.00904542, 0.00909923, 0.00915014, 0.00919805, 0.00924283, 0.00928436, - 0.00932252, 0.00935718, 0.00938821, 0.00941550, 0.00943890, - 0.00945828, 0.00947351, 0.00948446, 0.00949098, 0.00949294, - 0.00949020, 0.00948262, 0.00947005, 0.00945235, 0.00942938, 0.00940099, - 0.00936704, 0.00932738, 0.00928186, 0.00923034, 0.00917268, - 0.00910872, 0.00903832, 0.00896134, 0.00887763, 0.00878706, - 0.00868949, 0.00858478, 0.00847280, 0.00835343, 0.00822653, 0.00809199, - 0.00794970, 0.00779956, 0.00764145, 0.00747530, 0.00730103, - 0.00711857, 0.00692787, 0.00672888, 0.00652158, 0.00630597, - 0.00608208, 0.00584994, 0.00560962, 0.00536124, 0.00510493, 0.00484089, - 0.00456935, 0.00429062, 0.00400505, 0.00371310, 0.00341532, - 0.00311238, 0.00280511, 0.00249452, 0.00218184, 0.00186864, - 0.00155690, 0.00124918, 0.00094895, 0.00066112, 0.00039320, 0.00015881 -}; - -static void WebRtcIsac_GetVars(const double* input, - const int16_t* pitchGains_Q12, - double* oldEnergy, - double* varscale) { - double nrg[4], chng, pg; - int k; - - double pitchGains[4]={0,0,0,0};; - - /* Calculate energies of first and second frame halfs */ - nrg[0] = 0.0001; - for (k = QLOOKAHEAD/2; k < (FRAMESAMPLES_QUARTER + QLOOKAHEAD) / 2; k++) { - nrg[0] += input[k]*input[k]; - } - nrg[1] = 0.0001; - for ( ; k < (FRAMESAMPLES_HALF + QLOOKAHEAD) / 2; k++) { - nrg[1] += input[k]*input[k]; - } - nrg[2] = 0.0001; - for ( ; k < (FRAMESAMPLES*3/4 + QLOOKAHEAD) / 2; k++) { - nrg[2] += input[k]*input[k]; - } - nrg[3] = 0.0001; - for ( ; k < (FRAMESAMPLES + QLOOKAHEAD) / 2; k++) { - nrg[3] += input[k]*input[k]; - } - - /* Calculate average level change */ - chng = 0.25 * (fabs(10.0 * log10(nrg[3] / nrg[2])) + - fabs(10.0 * log10(nrg[2] / nrg[1])) + - fabs(10.0 * log10(nrg[1] / nrg[0])) + - fabs(10.0 * log10(nrg[0] / *oldEnergy))); - - - /* Find average pitch gain */ - pg = 0.0; - for (k=0; k<4; k++) - { - pitchGains[k] = ((float)pitchGains_Q12[k])/4096; - pg += pitchGains[k]; - } - pg *= 0.25; - - /* If pitch gain is low and energy constant - increase noise level*/ - /* Matlab code: - pg = 0:.01:.45; plot(pg, 0.0 + 1.0 * exp( -1.0 * exp(-200.0 * pg.*pg.*pg) / (1.0 + 0.4 * 0) )) - */ - *varscale = 0.0 + 1.0 * exp( -1.4 * exp(-200.0 * pg*pg*pg) / (1.0 + 0.4 * chng) ); - - *oldEnergy = nrg[3]; -} - -static void WebRtcIsac_GetVarsUB(const double* input, - double* oldEnergy, - double* varscale) { - double nrg[4], chng; - int k; - - /* Calculate energies of first and second frame halfs */ - nrg[0] = 0.0001; - for (k = 0; k < (FRAMESAMPLES_QUARTER) / 2; k++) { - nrg[0] += input[k]*input[k]; - } - nrg[1] = 0.0001; - for ( ; k < (FRAMESAMPLES_HALF) / 2; k++) { - nrg[1] += input[k]*input[k]; - } - nrg[2] = 0.0001; - for ( ; k < (FRAMESAMPLES*3/4) / 2; k++) { - nrg[2] += input[k]*input[k]; - } - nrg[3] = 0.0001; - for ( ; k < (FRAMESAMPLES) / 2; k++) { - nrg[3] += input[k]*input[k]; - } - - /* Calculate average level change */ - chng = 0.25 * (fabs(10.0 * log10(nrg[3] / nrg[2])) + - fabs(10.0 * log10(nrg[2] / nrg[1])) + - fabs(10.0 * log10(nrg[1] / nrg[0])) + - fabs(10.0 * log10(nrg[0] / *oldEnergy))); - - - /* If pitch gain is low and energy constant - increase noise level*/ - /* Matlab code: - pg = 0:.01:.45; plot(pg, 0.0 + 1.0 * exp( -1.0 * exp(-200.0 * pg.*pg.*pg) / (1.0 + 0.4 * 0) )) - */ - *varscale = exp( -1.4 / (1.0 + 0.4 * chng) ); - - *oldEnergy = nrg[3]; -} - -void WebRtcIsac_GetLpcCoefLb(double *inLo, double *inHi, MaskFiltstr *maskdata, - double signal_noise_ratio, const int16_t *pitchGains_Q12, - double *lo_coeff, double *hi_coeff) -{ - int k, n, j, pos1, pos2; - double varscale; - - double DataLo[WINLEN], DataHi[WINLEN]; - double corrlo[ORDERLO+2], corrlo2[ORDERLO+1]; - double corrhi[ORDERHI+1]; - double k_veclo[ORDERLO], k_vechi[ORDERHI]; - - double a_LO[ORDERLO+1], a_HI[ORDERHI+1]; - double tmp, res_nrg; - - double FwdA, FwdB; - - /* hearing threshold level in dB; higher value gives more noise */ - const double HearThresOffset = -28.0; - - /* bandwdith expansion factors for low- and high band */ - const double gammaLo = 0.9; - const double gammaHi = 0.8; - - /* less-noise-at-low-frequencies factor */ - double aa; - - - /* convert from dB to signal level */ - const double H_T_H = pow(10.0, 0.05 * HearThresOffset); - double S_N_R = pow(10.0, 0.05 * signal_noise_ratio) / 3.46; /* divide by sqrt(12) */ - - /* change quallevel depending on pitch gains and level fluctuations */ - WebRtcIsac_GetVars(inLo, pitchGains_Q12, &(maskdata->OldEnergy), &varscale); - - /* less-noise-at-low-frequencies factor */ - aa = 0.35 * (0.5 + 0.5 * varscale); - - /* replace data in buffer by new look-ahead data */ - for (pos1 = 0; pos1 < QLOOKAHEAD; pos1++) - maskdata->DataBufferLo[pos1 + WINLEN - QLOOKAHEAD] = inLo[pos1]; - - for (k = 0; k < SUBFRAMES; k++) { - - /* Update input buffer and multiply signal with window */ - for (pos1 = 0; pos1 < WINLEN - UPDATE/2; pos1++) { - maskdata->DataBufferLo[pos1] = maskdata->DataBufferLo[pos1 + UPDATE/2]; - maskdata->DataBufferHi[pos1] = maskdata->DataBufferHi[pos1 + UPDATE/2]; - DataLo[pos1] = maskdata->DataBufferLo[pos1] * kLpcCorrWindow[pos1]; - DataHi[pos1] = maskdata->DataBufferHi[pos1] * kLpcCorrWindow[pos1]; - } - pos2 = k * UPDATE/2; - for (n = 0; n < UPDATE/2; n++, pos1++) { - maskdata->DataBufferLo[pos1] = inLo[QLOOKAHEAD + pos2]; - maskdata->DataBufferHi[pos1] = inHi[pos2++]; - DataLo[pos1] = maskdata->DataBufferLo[pos1] * kLpcCorrWindow[pos1]; - DataHi[pos1] = maskdata->DataBufferHi[pos1] * kLpcCorrWindow[pos1]; - } - - /* Get correlation coefficients */ - WebRtcIsac_AutoCorr(corrlo, DataLo, WINLEN, ORDERLO+1); /* computing autocorrelation */ - WebRtcIsac_AutoCorr(corrhi, DataHi, WINLEN, ORDERHI); - - - /* less noise for lower frequencies, by filtering/scaling autocorrelation sequences */ - corrlo2[0] = (1.0+aa*aa) * corrlo[0] - 2.0*aa * corrlo[1]; - tmp = (1.0 + aa*aa); - for (n = 1; n <= ORDERLO; n++) { - corrlo2[n] = tmp * corrlo[n] - aa * (corrlo[n-1] + corrlo[n+1]); - } - tmp = (1.0+aa) * (1.0+aa); - for (n = 0; n <= ORDERHI; n++) { - corrhi[n] = tmp * corrhi[n]; - } - - /* add white noise floor */ - corrlo2[0] += 1e-6; - corrhi[0] += 1e-6; - - - FwdA = 0.01; - FwdB = 0.01; - - /* recursive filtering of correlation over subframes */ - for (n = 0; n <= ORDERLO; n++) { - maskdata->CorrBufLo[n] = FwdA * maskdata->CorrBufLo[n] + corrlo2[n]; - corrlo2[n] = ((1.0-FwdA)*FwdB) * maskdata->CorrBufLo[n] + (1.0-FwdB) * corrlo2[n]; - } - for (n = 0; n <= ORDERHI; n++) { - maskdata->CorrBufHi[n] = FwdA * maskdata->CorrBufHi[n] + corrhi[n]; - corrhi[n] = ((1.0-FwdA)*FwdB) * maskdata->CorrBufHi[n] + (1.0-FwdB) * corrhi[n]; - } - - /* compute prediction coefficients */ - WebRtcIsac_LevDurb(a_LO, k_veclo, corrlo2, ORDERLO); - WebRtcIsac_LevDurb(a_HI, k_vechi, corrhi, ORDERHI); - - /* bandwidth expansion */ - tmp = gammaLo; - for (n = 1; n <= ORDERLO; n++) { - a_LO[n] *= tmp; - tmp *= gammaLo; - } - - /* residual energy */ - res_nrg = 0.0; - for (j = 0; j <= ORDERLO; j++) { - for (n = 0; n <= j; n++) { - res_nrg += a_LO[j] * corrlo2[j-n] * a_LO[n]; - } - for (n = j+1; n <= ORDERLO; n++) { - res_nrg += a_LO[j] * corrlo2[n-j] * a_LO[n]; - } - } - - /* add hearing threshold and compute the gain */ - *lo_coeff++ = S_N_R / (sqrt(res_nrg) / varscale + H_T_H); - - /* copy coefficients to output array */ - for (n = 1; n <= ORDERLO; n++) { - *lo_coeff++ = a_LO[n]; - } - - - /* bandwidth expansion */ - tmp = gammaHi; - for (n = 1; n <= ORDERHI; n++) { - a_HI[n] *= tmp; - tmp *= gammaHi; - } - - /* residual energy */ - res_nrg = 0.0; - for (j = 0; j <= ORDERHI; j++) { - for (n = 0; n <= j; n++) { - res_nrg += a_HI[j] * corrhi[j-n] * a_HI[n]; - } - for (n = j+1; n <= ORDERHI; n++) { - res_nrg += a_HI[j] * corrhi[n-j] * a_HI[n]; - } - } - - /* add hearing threshold and compute of the gain */ - *hi_coeff++ = S_N_R / (sqrt(res_nrg) / varscale + H_T_H); - - /* copy coefficients to output array */ - for (n = 1; n <= ORDERHI; n++) { - *hi_coeff++ = a_HI[n]; - } - } -} - - - -/****************************************************************************** - * WebRtcIsac_GetLpcCoefUb() - * - * Compute LP coefficients and correlation coefficients. At 12 kHz LP - * coefficients of the first and the last sub-frame is computed. At 16 kHz - * LP coefficients of 4th, 8th and 12th sub-frames are computed. We always - * compute correlation coefficients of all sub-frames. - * - * Inputs: - * -inSignal : Input signal - * -maskdata : a structure keeping signal from previous frame. - * -bandwidth : specifies if the codec is in 0-16 kHz mode or - * 0-12 kHz mode. - * - * Outputs: - * -lpCoeff : pointer to a buffer where A-polynomials are - * written to (first coeff is 1 and it is not - * written) - * -corrMat : a matrix where correlation coefficients of each - * sub-frame are written to one row. - * -varscale : a scale used to compute LPC gains. - */ -void -WebRtcIsac_GetLpcCoefUb( - double* inSignal, - MaskFiltstr* maskdata, - double* lpCoeff, - double corrMat[][UB_LPC_ORDER + 1], - double* varscale, - int16_t bandwidth) -{ - int frameCntr, activeFrameCntr, n, pos1, pos2; - int16_t criterion1; - int16_t criterion2; - int16_t numSubFrames = SUBFRAMES * (1 + (bandwidth == isac16kHz)); - double data[WINLEN]; - double corrSubFrame[UB_LPC_ORDER+2]; - double reflecCoeff[UB_LPC_ORDER]; - - double aPolynom[UB_LPC_ORDER+1]; - double tmp; - - /* bandwdith expansion factors */ - const double gamma = 0.9; - - /* change quallevel depending on pitch gains and level fluctuations */ - WebRtcIsac_GetVarsUB(inSignal, &(maskdata->OldEnergy), varscale); - - /* replace data in buffer by new look-ahead data */ - for(frameCntr = 0, activeFrameCntr = 0; frameCntr < numSubFrames; - frameCntr++) - { - if(frameCntr == SUBFRAMES) - { - // we are in 16 kHz - varscale++; - WebRtcIsac_GetVarsUB(&inSignal[FRAMESAMPLES_HALF], - &(maskdata->OldEnergy), varscale); - } - /* Update input buffer and multiply signal with window */ - for(pos1 = 0; pos1 < WINLEN - UPDATE/2; pos1++) - { - maskdata->DataBufferLo[pos1] = maskdata->DataBufferLo[pos1 + - UPDATE/2]; - data[pos1] = maskdata->DataBufferLo[pos1] * kLpcCorrWindow[pos1]; - } - pos2 = frameCntr * UPDATE/2; - for(n = 0; n < UPDATE/2; n++, pos1++, pos2++) - { - maskdata->DataBufferLo[pos1] = inSignal[pos2]; - data[pos1] = maskdata->DataBufferLo[pos1] * kLpcCorrWindow[pos1]; - } - - /* Get correlation coefficients */ - /* computing autocorrelation */ - WebRtcIsac_AutoCorr(corrSubFrame, data, WINLEN, UB_LPC_ORDER+1); - memcpy(corrMat[frameCntr], corrSubFrame, - (UB_LPC_ORDER+1)*sizeof(double)); - - criterion1 = ((frameCntr == 0) || (frameCntr == (SUBFRAMES - 1))) && - (bandwidth == isac12kHz); - criterion2 = (((frameCntr+1) % 4) == 0) && - (bandwidth == isac16kHz); - if(criterion1 || criterion2) - { - /* add noise */ - corrSubFrame[0] += 1e-6; - /* compute prediction coefficients */ - WebRtcIsac_LevDurb(aPolynom, reflecCoeff, corrSubFrame, - UB_LPC_ORDER); - - /* bandwidth expansion */ - tmp = gamma; - for (n = 1; n <= UB_LPC_ORDER; n++) - { - *lpCoeff++ = aPolynom[n] * tmp; - tmp *= gamma; - } - activeFrameCntr++; - } - } -} - - - -/****************************************************************************** - * WebRtcIsac_GetLpcGain() - * - * Compute the LPC gains for each sub-frame, given the LPC of each sub-frame - * and the corresponding correlation coefficients. - * - * Inputs: - * -signal_noise_ratio : the desired SNR in dB. - * -numVecs : number of sub-frames - * -corrMat : a matrix of correlation coefficients where - * each row is a set of correlation coefficients of - * one sub-frame. - * -varscale : a scale computed when WebRtcIsac_GetLpcCoefUb() - * is called. - * - * Outputs: - * -gain : pointer to a buffer where LP gains are written. - * - */ -void -WebRtcIsac_GetLpcGain( - double signal_noise_ratio, - const double* filtCoeffVecs, - int numVecs, - double* gain, - double corrMat[][UB_LPC_ORDER + 1], - const double* varscale) -{ - int16_t j, n; - int16_t subFrameCntr; - double aPolynom[ORDERLO + 1]; - double res_nrg; - - const double HearThresOffset = -28.0; - const double H_T_H = pow(10.0, 0.05 * HearThresOffset); - /* divide by sqrt(12) = 3.46 */ - const double S_N_R = pow(10.0, 0.05 * signal_noise_ratio) / 3.46; - - aPolynom[0] = 1; - for(subFrameCntr = 0; subFrameCntr < numVecs; subFrameCntr++) - { - if(subFrameCntr == SUBFRAMES) - { - // we are in second half of a SWB frame. use new varscale - varscale++; - } - memcpy(&aPolynom[1], &filtCoeffVecs[(subFrameCntr * (UB_LPC_ORDER + 1)) + - 1], sizeof(double) * UB_LPC_ORDER); - - /* residual energy */ - res_nrg = 0.0; - for(j = 0; j <= UB_LPC_ORDER; j++) - { - for(n = 0; n <= j; n++) - { - res_nrg += aPolynom[j] * corrMat[subFrameCntr][j-n] * - aPolynom[n]; - } - for(n = j+1; n <= UB_LPC_ORDER; n++) - { - res_nrg += aPolynom[j] * corrMat[subFrameCntr][n-j] * - aPolynom[n]; - } - } - - /* add hearing threshold and compute the gain */ - gain[subFrameCntr] = S_N_R / (sqrt(res_nrg) / *varscale + H_T_H); - } -} diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/lpc_analysis.h b/webrtc/modules/audio_coding/codecs/isac/main/source/lpc_analysis.h deleted file mode 100644 index 5503e2d..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/lpc_analysis.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -/* - * lpc_analysis.h - * - * LPC functions - * - */ - -#ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_ANALYSIS_H_ -#define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_ANALYSIS_H_ - -#include "modules/audio_coding/codecs/isac/main/source/settings.h" -#include "modules/audio_coding/codecs/isac/main/source/structs.h" - -void WebRtcIsac_GetLpcCoefLb(double* inLo, - double* inHi, - MaskFiltstr* maskdata, - double signal_noise_ratio, - const int16_t* pitchGains_Q12, - double* lo_coeff, - double* hi_coeff); - -void WebRtcIsac_GetLpcGain(double signal_noise_ratio, - const double* filtCoeffVecs, - int numVecs, - double* gain, - double corrLo[][UB_LPC_ORDER + 1], - const double* varscale); - -void WebRtcIsac_GetLpcCoefUb(double* inSignal, - MaskFiltstr* maskdata, - double* lpCoeff, - double corr[][UB_LPC_ORDER + 1], - double* varscale, - int16_t bandwidth); - -#endif /* MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_ANALYIS_H_ */ diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/lpc_gain_swb_tables.c b/webrtc/modules/audio_coding/codecs/isac/main/source/lpc_gain_swb_tables.c deleted file mode 100644 index 6707540..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/lpc_gain_swb_tables.c +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -/* - * SWB_KLT_Tables_LPCGain.c - * - * This file defines tables used for entropy coding of LPC Gain - * of upper-band. - * - */ - -#include "modules/audio_coding/codecs/isac/main/source/lpc_gain_swb_tables.h" -#include "modules/audio_coding/codecs/isac/main/source/settings.h" - -const double WebRtcIsac_kQSizeLpcGain = 0.100000; - -const double WebRtcIsac_kMeanLpcGain = -3.3822; - -/* -* The smallest reconstruction points for quantiztion of -* LPC gains. -*/ -const double WebRtcIsac_kLeftRecPointLpcGain[SUBFRAMES] = -{ - -0.800000, -1.000000, -1.200000, -2.200000, -3.000000, -12.700000 -}; - -/* -* Number of reconstruction points of quantizers for LPC Gains. -*/ -const int16_t WebRtcIsac_kNumQCellLpcGain[SUBFRAMES] = -{ - 17, 20, 25, 45, 77, 170 -}; -/* -* Starting index for entropy decoder to search for the right interval, -* one entry per LAR coefficient -*/ -const uint16_t WebRtcIsac_kLpcGainEntropySearch[SUBFRAMES] = -{ - 8, 10, 12, 22, 38, 85 -}; - -/* -* The following 6 vectors define CDF of 6 decorrelated LPC -* gains. -*/ -const uint16_t WebRtcIsac_kLpcGainCdfVec0[18] = -{ - 0, 10, 27, 83, 234, 568, 1601, 4683, 16830, 57534, 63437, - 64767, 65229, 65408, 65483, 65514, 65527, 65535 -}; - -const uint16_t WebRtcIsac_kLpcGainCdfVec1[21] = -{ - 0, 15, 33, 84, 185, 385, 807, 1619, 3529, 7850, 19488, - 51365, 62437, 64548, 65088, 65304, 65409, 65484, 65507, 65522, 65535 -}; - -const uint16_t WebRtcIsac_kLpcGainCdfVec2[26] = -{ - 0, 15, 29, 54, 89, 145, 228, 380, 652, 1493, 4260, - 12359, 34133, 50749, 57224, 60814, 62927, 64078, 64742, 65103, 65311, 65418, - 65473, 65509, 65521, 65535 -}; - -const uint16_t WebRtcIsac_kLpcGainCdfVec3[46] = -{ - 0, 8, 12, 16, 26, 42, 56, 76, 111, 164, 247, - 366, 508, 693, 1000, 1442, 2155, 3188, 4854, 7387, 11249, 17617, - 30079, 46711, 56291, 60127, 62140, 63258, 63954, 64384, 64690, 64891, 65031, - 65139, 65227, 65293, 65351, 65399, 65438, 65467, 65492, 65504, 65510, 65518, - 65523, 65535 -}; - -const uint16_t WebRtcIsac_kLpcGainCdfVec4[78] = -{ - 0, 17, 29, 39, 51, 70, 104, 154, 234, 324, 443, - 590, 760, 971, 1202, 1494, 1845, 2274, 2797, 3366, 4088, 4905, - 5899, 7142, 8683, 10625, 12983, 16095, 20637, 28216, 38859, 47237, 51537, - 54150, 56066, 57583, 58756, 59685, 60458, 61103, 61659, 62144, 62550, 62886, - 63186, 63480, 63743, 63954, 64148, 64320, 64467, 64600, 64719, 64837, 64939, - 65014, 65098, 65160, 65211, 65250, 65290, 65325, 65344, 65366, 65391, 65410, - 65430, 65447, 65460, 65474, 65487, 65494, 65501, 65509, 65513, 65518, 65520, - 65535 -}; - -const uint16_t WebRtcIsac_kLpcGainCdfVec5[171] = -{ - 0, 10, 12, 14, 16, 18, 23, 29, 35, 42, 51, - 58, 65, 72, 78, 87, 96, 103, 111, 122, 134, 150, - 167, 184, 202, 223, 244, 265, 289, 315, 346, 379, 414, - 450, 491, 532, 572, 613, 656, 700, 751, 802, 853, 905, - 957, 1021, 1098, 1174, 1250, 1331, 1413, 1490, 1565, 1647, 1730, - 1821, 1913, 2004, 2100, 2207, 2314, 2420, 2532, 2652, 2783, 2921, - 3056, 3189, 3327, 3468, 3640, 3817, 3993, 4171, 4362, 4554, 4751, - 4948, 5142, 5346, 5566, 5799, 6044, 6301, 6565, 6852, 7150, 7470, - 7797, 8143, 8492, 8835, 9181, 9547, 9919, 10315, 10718, 11136, 11566, - 12015, 12482, 12967, 13458, 13953, 14432, 14903, 15416, 15936, 16452, 16967, - 17492, 18024, 18600, 19173, 19736, 20311, 20911, 21490, 22041, 22597, 23157, - 23768, 24405, 25034, 25660, 26280, 26899, 27614, 28331, 29015, 29702, 30403, - 31107, 31817, 32566, 33381, 34224, 35099, 36112, 37222, 38375, 39549, 40801, - 42074, 43350, 44626, 45982, 47354, 48860, 50361, 51845, 53312, 54739, 56026, - 57116, 58104, 58996, 59842, 60658, 61488, 62324, 63057, 63769, 64285, 64779, - 65076, 65344, 65430, 65500, 65517, 65535 -}; - -/* -* An array of pointers to CDFs of decorrelated LPC Gains -*/ -const uint16_t* WebRtcIsac_kLpcGainCdfMat[SUBFRAMES] = -{ - WebRtcIsac_kLpcGainCdfVec0, WebRtcIsac_kLpcGainCdfVec1, - WebRtcIsac_kLpcGainCdfVec2, WebRtcIsac_kLpcGainCdfVec3, - WebRtcIsac_kLpcGainCdfVec4, WebRtcIsac_kLpcGainCdfVec5 -}; - -/* -* A matrix to decorrellate LPC gains of subframes. -*/ -const double WebRtcIsac_kLpcGainDecorrMat[SUBFRAMES][SUBFRAMES] = -{ - {-0.150860, 0.327872, 0.367220, 0.504613, 0.559270, 0.409234}, - { 0.457128, -0.613591, -0.289283, -0.029734, 0.393760, 0.418240}, - {-0.626043, 0.136489, -0.439118, -0.448323, 0.135987, 0.420869}, - { 0.526617, 0.480187, 0.242552, -0.488754, -0.158713, 0.411331}, - {-0.302587, -0.494953, 0.588112, -0.063035, -0.404290, 0.387510}, - { 0.086378, 0.147714, -0.428875, 0.548300, -0.570121, 0.401391} -}; diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/lpc_gain_swb_tables.h b/webrtc/modules/audio_coding/codecs/isac/main/source/lpc_gain_swb_tables.h deleted file mode 100644 index 39c4a24..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/lpc_gain_swb_tables.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -/* - * SWB_KLT_Tables_LPCGain.h - * - * This file declares tables used for entropy coding of LPC Gain - * of upper-band. - * - */ - -#ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_GAIN_SWB_TABLES_H_ -#define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_GAIN_SWB_TABLES_H_ - -#include - -#include "modules/audio_coding/codecs/isac/main/source/settings.h" - -extern const double WebRtcIsac_kQSizeLpcGain; - -extern const double WebRtcIsac_kLeftRecPointLpcGain[SUBFRAMES]; - -extern const int16_t WebRtcIsac_kNumQCellLpcGain[SUBFRAMES]; - -extern const uint16_t WebRtcIsac_kLpcGainEntropySearch[SUBFRAMES]; - -extern const uint16_t WebRtcIsac_kLpcGainCdfVec0[18]; - -extern const uint16_t WebRtcIsac_kLpcGainCdfVec1[21]; - -extern const uint16_t WebRtcIsac_kLpcGainCdfVec2[26]; - -extern const uint16_t WebRtcIsac_kLpcGainCdfVec3[46]; - -extern const uint16_t WebRtcIsac_kLpcGainCdfVec4[78]; - -extern const uint16_t WebRtcIsac_kLpcGainCdfVec5[171]; - -extern const uint16_t* WebRtcIsac_kLpcGainCdfMat[SUBFRAMES]; - -extern const double WebRtcIsac_kLpcGainDecorrMat[SUBFRAMES][SUBFRAMES]; - -#endif // MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_GAIN_SWB_TABLES_H_ diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/lpc_shape_swb12_tables.c b/webrtc/modules/audio_coding/codecs/isac/main/source/lpc_shape_swb12_tables.c deleted file mode 100644 index e3600a7..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/lpc_shape_swb12_tables.c +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -/* - * SWB_KLT_Tables.c - * - * This file defines tables used for entropy coding of LPC shape of - * upper-band signal if the bandwidth is 12 kHz. - * - */ - -#include "modules/audio_coding/codecs/isac/main/source/lpc_shape_swb12_tables.h" -#include "modules/audio_coding/codecs/isac/main/source/settings.h" - -/* -* Mean value of LAR -*/ -const double WebRtcIsac_kMeanLarUb12[UB_LPC_ORDER] = -{ - 0.03748928306641, 0.09453441192543, -0.01112522344398, 0.03800237516842 -}; - -/* -* A rotation matrix to decorrelate intra-vector correlation, -* i.e. correlation among components of LAR vector. -*/ -const double WebRtcIsac_kIntraVecDecorrMatUb12[UB_LPC_ORDER][UB_LPC_ORDER] = -{ - {-0.00075365493856, -0.05809964887743, -0.23397966154116, 0.97050367376411}, - { 0.00625021257734, -0.17299965610679, 0.95977735920651, 0.22104179375008}, - { 0.20543384258374, -0.96202143495696, -0.15301870801552, -0.09432375099565}, - {-0.97865075648479, -0.20300322280841, -0.02581111653779, -0.01913568980258} -}; - -/* -* A rotation matrix to remove correlation among LAR coefficients -* of different LAR vectors. One might guess that decorrelation matrix -* for the first component should differ from the second component -* but we haven't observed a significant benefit of having different -* decorrelation matrices for different components. -*/ -const double WebRtcIsac_kInterVecDecorrMatUb12 -[UB_LPC_VEC_PER_FRAME][UB_LPC_VEC_PER_FRAME] = -{ - { 0.70650597970460, -0.70770707262373}, - {-0.70770707262373, -0.70650597970460} -}; - -/* -* LAR quantization step-size. -*/ -const double WebRtcIsac_kLpcShapeQStepSizeUb12 = 0.150000; - -/* -* The smallest reconstruction points for quantiztion of LAR coefficients. -*/ -const double WebRtcIsac_kLpcShapeLeftRecPointUb12 -[UB_LPC_ORDER*UB_LPC_VEC_PER_FRAME] = -{ - -0.900000, -1.050000, -1.350000, -1.800000, -1.350000, -1.650000, - -2.250000, -3.450000 -}; - -/* -* Number of reconstruction points of quantizers for LAR coefficients. -*/ -const int16_t WebRtcIsac_kLpcShapeNumRecPointUb12 -[UB_LPC_ORDER * UB_LPC_VEC_PER_FRAME] = -{ - 13, 15, 19, 27, 19, 24, 32, 48 -}; - -/* -* Starting index for entropy decoder to search for the right interval, -* one entry per LAR coefficient -*/ -const uint16_t WebRtcIsac_kLpcShapeEntropySearchUb12 -[UB_LPC_ORDER * UB_LPC_VEC_PER_FRAME] = -{ - 6, 7, 9, 13, 9, 12, 16, 24 -}; - -/* -* The following 8 vectors define CDF of 8 decorrelated LAR -* coefficients. -*/ -const uint16_t WebRtcIsac_kLpcShapeCdfVec0Ub12[14] = -{ - 0, 13, 95, 418, 1687, 6498, 21317, 44200, 59029, 63849, 65147, - 65449, 65525, 65535 -}; - -const uint16_t WebRtcIsac_kLpcShapeCdfVec1Ub12[16] = -{ - 0, 10, 59, 255, 858, 2667, 8200, 22609, 42988, 57202, 62947, - 64743, 65308, 65476, 65522, 65535 -}; - -const uint16_t WebRtcIsac_kLpcShapeCdfVec2Ub12[20] = -{ - 0, 18, 40, 118, 332, 857, 2017, 4822, 11321, 24330, 41279, - 54342, 60637, 63394, 64659, 65184, 65398, 65482, 65518, 65535 -}; - -const uint16_t WebRtcIsac_kLpcShapeCdfVec3Ub12[28] = -{ - 0, 21, 38, 90, 196, 398, 770, 1400, 2589, 4650, 8211, - 14933, 26044, 39592, 50814, 57452, 60971, 62884, 63995, 64621, 65019, 65273, - 65410, 65480, 65514, 65522, 65531, 65535 -}; - -const uint16_t WebRtcIsac_kLpcShapeCdfVec4Ub12[20] = -{ - 0, 7, 46, 141, 403, 969, 2132, 4649, 10633, 24902, 43254, - 54665, 59928, 62674, 64173, 64938, 65293, 65464, 65523, 65535 -}; - -const uint16_t WebRtcIsac_kLpcShapeCdfVec5Ub12[25] = -{ - 0, 7, 22, 72, 174, 411, 854, 1737, 3545, 6774, 13165, - 25221, 40980, 52821, 58714, 61706, 63472, 64437, 64989, 65287, 65430, 65503, - 65525, 65529, 65535 -}; - -const uint16_t WebRtcIsac_kLpcShapeCdfVec6Ub12[33] = -{ - 0, 11, 21, 36, 65, 128, 228, 401, 707, 1241, 2126, - 3589, 6060, 10517, 18853, 31114, 42477, 49770, 54271, 57467, 59838, 61569, - 62831, 63772, 64433, 64833, 65123, 65306, 65419, 65466, 65499, 65519, 65535 -}; - -const uint16_t WebRtcIsac_kLpcShapeCdfVec7Ub12[49] = -{ - 0, 14, 34, 67, 107, 167, 245, 326, 449, 645, 861, - 1155, 1508, 2003, 2669, 3544, 4592, 5961, 7583, 9887, 13256, 18765, - 26519, 34077, 40034, 44349, 47795, 50663, 53262, 55473, 57458, 59122, 60592, - 61742, 62690, 63391, 63997, 64463, 64794, 65045, 65207, 65309, 65394, 65443, - 65478, 65504, 65514, 65523, 65535 -}; - -/* -* An array of pointers to CDFs of decorrelated LARs -*/ -const uint16_t* WebRtcIsac_kLpcShapeCdfMatUb12 -[UB_LPC_ORDER * UB_LPC_VEC_PER_FRAME] = -{ - WebRtcIsac_kLpcShapeCdfVec0Ub12, WebRtcIsac_kLpcShapeCdfVec1Ub12, - WebRtcIsac_kLpcShapeCdfVec2Ub12, WebRtcIsac_kLpcShapeCdfVec3Ub12, - WebRtcIsac_kLpcShapeCdfVec4Ub12, WebRtcIsac_kLpcShapeCdfVec5Ub12, - WebRtcIsac_kLpcShapeCdfVec6Ub12, WebRtcIsac_kLpcShapeCdfVec7Ub12 -}; diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/lpc_shape_swb12_tables.h b/webrtc/modules/audio_coding/codecs/isac/main/source/lpc_shape_swb12_tables.h deleted file mode 100644 index 7448a1e..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/lpc_shape_swb12_tables.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -/* - * lpc_shape_swb12_tables.h - * - * This file declares tables used for entropy coding of LPC shape of - * upper-band signal if the bandwidth is 12 kHz. - * - */ - -#ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_SHAPE_SWB12_TABLES_H_ -#define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_SHAPE_SWB12_TABLES_H_ - -#include - -#include "modules/audio_coding/codecs/isac/main/source/settings.h" - -extern const double WebRtcIsac_kMeanLarUb12[UB_LPC_ORDER]; - -extern const double WebRtcIsac_kMeanLpcGain; - -extern const double WebRtcIsac_kIntraVecDecorrMatUb12[UB_LPC_ORDER] - [UB_LPC_ORDER]; - -extern const double WebRtcIsac_kInterVecDecorrMatUb12[UB_LPC_VEC_PER_FRAME] - [UB_LPC_VEC_PER_FRAME]; - -extern const double WebRtcIsac_kLpcShapeQStepSizeUb12; - -extern const double - WebRtcIsac_kLpcShapeLeftRecPointUb12[UB_LPC_ORDER * UB_LPC_VEC_PER_FRAME]; - -extern const int16_t - WebRtcIsac_kLpcShapeNumRecPointUb12[UB_LPC_ORDER * UB_LPC_VEC_PER_FRAME]; - -extern const uint16_t - WebRtcIsac_kLpcShapeEntropySearchUb12[UB_LPC_ORDER * UB_LPC_VEC_PER_FRAME]; - -extern const uint16_t WebRtcIsac_kLpcShapeCdfVec0Ub12[14]; - -extern const uint16_t WebRtcIsac_kLpcShapeCdfVec1Ub12[16]; - -extern const uint16_t WebRtcIsac_kLpcShapeCdfVec2Ub12[20]; - -extern const uint16_t WebRtcIsac_kLpcShapeCdfVec3Ub12[28]; - -extern const uint16_t WebRtcIsac_kLpcShapeCdfVec4Ub12[20]; - -extern const uint16_t WebRtcIsac_kLpcShapeCdfVec5Ub12[25]; - -extern const uint16_t WebRtcIsac_kLpcShapeCdfVec6Ub12[33]; - -extern const uint16_t WebRtcIsac_kLpcShapeCdfVec7Ub12[49]; - -extern const uint16_t* - WebRtcIsac_kLpcShapeCdfMatUb12[UB_LPC_ORDER * UB_LPC_VEC_PER_FRAME]; - -#endif // MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_SHAPE_SWB12_TABLES_H_ diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/lpc_shape_swb16_tables.c b/webrtc/modules/audio_coding/codecs/isac/main/source/lpc_shape_swb16_tables.c deleted file mode 100644 index 59617fd..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/lpc_shape_swb16_tables.c +++ /dev/null @@ -1,247 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -/* - * SWB16_KLT_Tables.c - * - * This file defines tables used for entropy coding of LPC shape of - * upper-band signal if the bandwidth is 16 kHz. - * - */ - -#include "modules/audio_coding/codecs/isac/main/source/lpc_shape_swb16_tables.h" -#include "modules/audio_coding/codecs/isac/main/source/settings.h" - -/* -* Mean value of LAR -*/ -const double WebRtcIsac_kMeanLarUb16[UB_LPC_ORDER] = -{ -0.454978, 0.364747, 0.102999, 0.104523 -}; - -/* -* A rotation matrix to decorrelate intra-vector correlation, -* i.e. correlation among components of LAR vector. -*/ -const double WebRtcIsac_kIintraVecDecorrMatUb16[UB_LPC_ORDER][UB_LPC_ORDER] = -{ - {-0.020528, -0.085858, -0.002431, 0.996093}, - {-0.033155, 0.036102, 0.998786, 0.004866}, - { 0.202627, 0.974853, -0.028940, 0.088132}, - {-0.978479, 0.202454, -0.039785, -0.002811} -}; - -/* -* A rotation matrix to remove correlation among LAR coefficients -* of different LAR vectors. One might guess that decorrelation matrix -* for the first component should differ from the second component -* but we haven't observed a significant benefit of having different -* decorrelation matrices for different components. -*/ -const double WebRtcIsac_kInterVecDecorrMatUb16 -[UB16_LPC_VEC_PER_FRAME][UB16_LPC_VEC_PER_FRAME] = -{ - { 0.291675, -0.515786, 0.644927, 0.482658}, - {-0.647220, 0.479712, 0.289556, 0.516856}, - { 0.643084, 0.485489, -0.289307, 0.516763}, - {-0.287185, -0.517823, -0.645389, 0.482553} -}; - -/* -* The following 16 vectors define CDF of 16 decorrelated LAR -* coefficients. -*/ -const uint16_t WebRtcIsac_kLpcShapeCdfVec01Ub16[14] = -{ - 0, 2, 20, 159, 1034, 5688, 20892, 44653, - 59849, 64485, 65383, 65518, 65534, 65535 -}; - -const uint16_t WebRtcIsac_kLpcShapeCdfVec1Ub16[16] = -{ - 0, 1, 7, 43, 276, 1496, 6681, 21653, - 43891, 58859, 64022, 65248, 65489, 65529, 65534, 65535 -}; - -const uint16_t WebRtcIsac_kLpcShapeCdfVec2Ub16[18] = -{ - 0, 1, 9, 54, 238, 933, 3192, 9461, - 23226, 42146, 56138, 62413, 64623, 65300, 65473, 65521, - 65533, 65535 -}; - -const uint16_t WebRtcIsac_kLpcShapeCdfVec3Ub16[30] = -{ - 0, 2, 4, 8, 17, 36, 75, 155, - 329, 683, 1376, 2662, 5047, 9508, 17526, 29027, - 40363, 48997, 55096, 59180, 61789, 63407, 64400, 64967, - 65273, 65429, 65497, 65526, 65534, 65535 -}; - -const uint16_t WebRtcIsac_kLpcShapeCdfVec4Ub16[16] = -{ - 0, 1, 10, 63, 361, 1785, 7407, 22242, - 43337, 58125, 63729, 65181, 65472, 65527, 65534, 65535 -}; - -const uint16_t WebRtcIsac_kLpcShapeCdfVec5Ub16[17] = -{ - 0, 1, 7, 29, 134, 599, 2443, 8590, - 22962, 42635, 56911, 63060, 64940, 65408, 65513, 65531, - 65535 -}; - -const uint16_t WebRtcIsac_kLpcShapeCdfVec6Ub16[21] = -{ - 0, 1, 5, 16, 57, 191, 611, 1808, - 4847, 11755, 24612, 40910, 53789, 60698, 63729, 64924, - 65346, 65486, 65523, 65532, 65535 -}; - -const uint16_t WebRtcIsac_kLpcShapeCdfVec7Ub16[36] = -{ - 0, 1, 4, 12, 25, 55, 104, 184, - 314, 539, 926, 1550, 2479, 3861, 5892, 8845, - 13281, 20018, 29019, 38029, 45581, 51557, 56057, 59284, - 61517, 63047, 64030, 64648, 65031, 65261, 65402, 65480, - 65518, 65530, 65534, 65535 -}; - -const uint16_t WebRtcIsac_kLpcShapeCdfVec8Ub16[21] = -{ - 0, 1, 2, 7, 26, 103, 351, 1149, - 3583, 10204, 23846, 41711, 55361, 61917, 64382, 65186, - 65433, 65506, 65528, 65534, 65535 -}; - -const uint16_t WebRtcIsac_kLpcShapeCdfVec01Ub160[21] = -{ - 0, 6, 19, 63, 205, 638, 1799, 4784, - 11721, 24494, 40803, 53805, 60886, 63822, 64931, 65333, - 65472, 65517, 65530, 65533, 65535 -}; - -const uint16_t WebRtcIsac_kLpcShapeCdfVec01Ub161[28] = -{ - 0, 1, 3, 11, 31, 86, 221, 506, - 1101, 2296, 4486, 8477, 15356, 26079, 38941, 49952, - 57165, 61257, 63426, 64549, 65097, 65351, 65463, 65510, - 65526, 65532, 65534, 65535 -}; - -const uint16_t WebRtcIsac_kLpcShapeCdfVec01Ub162[55] = -{ - 0, 3, 12, 23, 42, 65, 89, 115, - 150, 195, 248, 327, 430, 580, 784, 1099, - 1586, 2358, 3651, 5899, 9568, 14312, 19158, 23776, - 28267, 32663, 36991, 41153, 45098, 48680, 51870, 54729, - 57141, 59158, 60772, 62029, 63000, 63761, 64322, 64728, - 65000, 65192, 65321, 65411, 65463, 65496, 65514, 65523, - 65527, 65529, 65531, 65532, 65533, 65534, 65535 -}; - -const uint16_t WebRtcIsac_kLpcShapeCdfVec01Ub163[26] = -{ - 0, 2, 4, 10, 21, 48, 114, 280, - 701, 1765, 4555, 11270, 24267, 41213, 54285, 61003, - 63767, 64840, 65254, 65421, 65489, 65514, 65526, 65532, - 65534, 65535 -}; - -const uint16_t WebRtcIsac_kLpcShapeCdfVec01Ub164[28] = -{ - 0, 1, 3, 6, 15, 36, 82, 196, - 453, 1087, 2557, 5923, 13016, 25366, 40449, 52582, - 59539, 62896, 64389, 65033, 65316, 65442, 65494, 65519, - 65529, 65533, 65534, 65535 -}; - -const uint16_t WebRtcIsac_kLpcShapeCdfVec01Ub165[34] = -{ - 0, 2, 4, 8, 18, 35, 73, 146, - 279, 524, 980, 1789, 3235, 5784, 10040, 16998, - 27070, 38543, 48499, 55421, 59712, 62257, 63748, 64591, - 65041, 65278, 65410, 65474, 65508, 65522, 65530, 65533, - 65534, 65535 -}; - -const uint16_t WebRtcIsac_kLpcShapeCdfVec01Ub166[71] = -{ - 0, 1, 2, 6, 13, 26, 55, 92, - 141, 191, 242, 296, 355, 429, 522, 636, - 777, 947, 1162, 1428, 1753, 2137, 2605, 3140, - 3743, 4409, 5164, 6016, 6982, 8118, 9451, 10993, - 12754, 14810, 17130, 19780, 22864, 26424, 30547, 35222, - 40140, 44716, 48698, 52056, 54850, 57162, 59068, 60643, - 61877, 62827, 63561, 64113, 64519, 64807, 65019, 65167, - 65272, 65343, 65399, 65440, 65471, 65487, 65500, 65509, - 65518, 65524, 65527, 65531, 65533, 65534, 65535 -}; - -/* -* An array of pointers to CDFs of decorrelated LARs -*/ -const uint16_t* WebRtcIsac_kLpcShapeCdfMatUb16 -[UB_LPC_ORDER * UB16_LPC_VEC_PER_FRAME] = { - WebRtcIsac_kLpcShapeCdfVec01Ub16, - WebRtcIsac_kLpcShapeCdfVec1Ub16, - WebRtcIsac_kLpcShapeCdfVec2Ub16, - WebRtcIsac_kLpcShapeCdfVec3Ub16, - WebRtcIsac_kLpcShapeCdfVec4Ub16, - WebRtcIsac_kLpcShapeCdfVec5Ub16, - WebRtcIsac_kLpcShapeCdfVec6Ub16, - WebRtcIsac_kLpcShapeCdfVec7Ub16, - WebRtcIsac_kLpcShapeCdfVec8Ub16, - WebRtcIsac_kLpcShapeCdfVec01Ub160, - WebRtcIsac_kLpcShapeCdfVec01Ub161, - WebRtcIsac_kLpcShapeCdfVec01Ub162, - WebRtcIsac_kLpcShapeCdfVec01Ub163, - WebRtcIsac_kLpcShapeCdfVec01Ub164, - WebRtcIsac_kLpcShapeCdfVec01Ub165, - WebRtcIsac_kLpcShapeCdfVec01Ub166 -}; - -/* -* The smallest reconstruction points for quantiztion of LAR coefficients. -*/ -const double WebRtcIsac_kLpcShapeLeftRecPointUb16 -[UB_LPC_ORDER * UB16_LPC_VEC_PER_FRAME] = -{ - -0.8250, -0.9750, -1.1250, -2.1750, -0.9750, -1.1250, -1.4250, - -2.6250, -1.4250, -1.2750, -1.8750, -3.6750, -1.7250, -1.8750, - -2.3250, -5.4750 -}; - -/* -* Number of reconstruction points of quantizers for LAR coefficients. -*/ -const int16_t WebRtcIsac_kLpcShapeNumRecPointUb16 -[UB_LPC_ORDER * UB16_LPC_VEC_PER_FRAME] = -{ - 13, 15, 17, 29, 15, 16, 20, 35, 20, - 20, 27, 54, 25, 27, 33, 70 -}; - -/* -* Starting index for entropy decoder to search for the right interval, -* one entry per LAR coefficient -*/ -const uint16_t WebRtcIsac_kLpcShapeEntropySearchUb16 -[UB_LPC_ORDER * UB16_LPC_VEC_PER_FRAME] = -{ - 6, 7, 8, 14, 7, 8, 10, 17, 10, - 10, 13, 27, 12, 13, 16, 35 -}; - -/* -* LAR quantization step-size. -*/ -const double WebRtcIsac_kLpcShapeQStepSizeUb16 = 0.150000; diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/lpc_shape_swb16_tables.h b/webrtc/modules/audio_coding/codecs/isac/main/source/lpc_shape_swb16_tables.h deleted file mode 100644 index 51101db..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/lpc_shape_swb16_tables.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -/* - * lpc_shape_swb16_tables.h - * - * This file declares tables used for entropy coding of LPC shape of - * upper-band signal if the bandwidth is 16 kHz. - * - */ - -#ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_SHAPE_SWB16_TABLES_H_ -#define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_SHAPE_SWB16_TABLES_H_ - -#include - -#include "modules/audio_coding/codecs/isac/main/source/settings.h" - -extern const double WebRtcIsac_kMeanLarUb16[UB_LPC_ORDER]; - -extern const double WebRtcIsac_kIintraVecDecorrMatUb16[UB_LPC_ORDER] - [UB_LPC_ORDER]; - -extern const double WebRtcIsac_kInterVecDecorrMatUb16[UB16_LPC_VEC_PER_FRAME] - [UB16_LPC_VEC_PER_FRAME]; - -extern const uint16_t WebRtcIsac_kLpcShapeCdfVec01Ub16[14]; - -extern const uint16_t WebRtcIsac_kLpcShapeCdfVec1Ub16[16]; - -extern const uint16_t WebRtcIsac_kLpcShapeCdfVec2Ub16[18]; - -extern const uint16_t WebRtcIsac_kLpcShapeCdfVec3Ub16[30]; - -extern const uint16_t WebRtcIsac_kLpcShapeCdfVec4Ub16[16]; - -extern const uint16_t WebRtcIsac_kLpcShapeCdfVec5Ub16[17]; - -extern const uint16_t WebRtcIsac_kLpcShapeCdfVec6Ub16[21]; - -extern const uint16_t WebRtcIsac_kLpcShapeCdfVec7Ub16[36]; - -extern const uint16_t WebRtcIsac_kLpcShapeCdfVec8Ub16[21]; - -extern const uint16_t WebRtcIsac_kLpcShapeCdfVec01Ub160[21]; - -extern const uint16_t WebRtcIsac_kLpcShapeCdfVec01Ub161[28]; - -extern const uint16_t WebRtcIsac_kLpcShapeCdfVec01Ub162[55]; - -extern const uint16_t WebRtcIsac_kLpcShapeCdfVec01Ub163[26]; - -extern const uint16_t WebRtcIsac_kLpcShapeCdfVec01Ub164[28]; - -extern const uint16_t WebRtcIsac_kLpcShapeCdfVec01Ub165[34]; - -extern const uint16_t WebRtcIsac_kLpcShapeCdfVec01Ub166[71]; - -extern const uint16_t* - WebRtcIsac_kLpcShapeCdfMatUb16[UB_LPC_ORDER * UB16_LPC_VEC_PER_FRAME]; - -extern const double - WebRtcIsac_kLpcShapeLeftRecPointUb16[UB_LPC_ORDER * UB16_LPC_VEC_PER_FRAME]; - -extern const int16_t - WebRtcIsac_kLpcShapeNumRecPointUb16[UB_LPC_ORDER * UB16_LPC_VEC_PER_FRAME]; - -extern const uint16_t - WebRtcIsac_kLpcShapeEntropySearchUb16[UB_LPC_ORDER * - UB16_LPC_VEC_PER_FRAME]; - -extern const double WebRtcIsac_kLpcShapeQStepSizeUb16; - -#endif // MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_SHAPE_SWB16_TABLES_H_ diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/lpc_tables.c b/webrtc/modules/audio_coding/codecs/isac/main/source/lpc_tables.c deleted file mode 100644 index 461b92e..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/lpc_tables.c +++ /dev/null @@ -1,601 +0,0 @@ -/* - * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -/* coding tables for the KLT coefficients */ - -#include "modules/audio_coding/codecs/isac/main/source/lpc_tables.h" -#include "modules/audio_coding/codecs/isac/main/source/settings.h" - -/* cdf array for model indicator */ -const uint16_t WebRtcIsac_kQKltModelCdf[4] = { - 0, 15434, 37548, 65535 }; - -/* pointer to cdf array for model indicator */ -const uint16_t *WebRtcIsac_kQKltModelCdfPtr[1] = { - WebRtcIsac_kQKltModelCdf }; - -/* initial cdf index for decoder of model indicator */ -const uint16_t WebRtcIsac_kQKltModelInitIndex[1] = { 1 }; - -/* offset to go from rounded value to quantization index */ -const short WebRtcIsac_kQKltQuantMinGain[12] = { - 3, 6, 4, 6, 6, 9, 5, 16, 11, 34, 32, 47 }; - - -const short WebRtcIsac_kQKltQuantMinShape[108] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - 1, 1, 1, 1, 2, 2, 2, 3, 0, 0, - 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, - 1, 1, 1, 2, 2, 3, 0, 0, 0, 0, - 1, 0, 1, 1, 1, 1, 1, 1, 1, 2, - 2, 4, 3, 5, 0, 0, 0, 0, 1, 1, - 1, 1, 1, 1, 2, 1, 2, 2, 3, 4, - 4, 7, 0, 0, 1, 1, 1, 1, 1, 1, - 1, 2, 3, 2, 3, 4, 4, 5, 7, 13, - 0, 1, 1, 2, 3, 2, 2, 2, 4, 4, - 5, 6, 7, 11, 9, 13, 12, 26 }; - -/* maximum quantization index */ -const uint16_t WebRtcIsac_kQKltMaxIndGain[12] = { - 6, 12, 8, 14, 10, 19, 12, 31, 22, 56, 52, 138 }; - -const uint16_t WebRtcIsac_kQKltMaxIndShape[108] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - 2, 2, 2, 2, 4, 4, 5, 6, 0, 0, - 0, 0, 1, 0, 0, 0, 0, 1, 2, 2, - 2, 2, 3, 4, 5, 7, 0, 0, 0, 0, - 2, 0, 2, 2, 2, 2, 3, 2, 2, 4, - 4, 6, 6, 9, 0, 0, 0, 0, 2, 2, - 2, 2, 2, 2, 3, 2, 4, 4, 7, 7, - 9, 13, 0, 0, 2, 2, 2, 2, 2, 2, - 3, 4, 5, 4, 6, 8, 8, 10, 16, 25, - 0, 2, 2, 4, 5, 4, 4, 4, 7, 8, - 9, 10, 13, 19, 17, 23, 25, 49 }; - -/* index offset */ -const uint16_t WebRtcIsac_kQKltOffsetGain[12] = { - 0, 7, 20, 29, 44, 55, 75, 88, 120, 143, 200, 253 }; - -const uint16_t WebRtcIsac_kQKltOffsetShape[108] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, - 11, 14, 17, 20, 23, 28, 33, 39, 46, 47, - 48, 49, 50, 52, 53, 54, 55, 56, 58, 61, - 64, 67, 70, 74, 79, 85, 93, 94, 95, 96, - 97, 100, 101, 104, 107, 110, 113, 117, 120, 123, - 128, 133, 140, 147, 157, 158, 159, 160, 161, 164, - 167, 170, 173, 176, 179, 183, 186, 191, 196, 204, - 212, 222, 236, 237, 238, 241, 244, 247, 250, 253, - 256, 260, 265, 271, 276, 283, 292, 301, 312, 329, - 355, 356, 359, 362, 367, 373, 378, 383, 388, 396, - 405, 415, 426, 440, 460, 478, 502, 528 }; - -/* initial cdf index for KLT coefficients */ -const uint16_t WebRtcIsac_kQKltInitIndexGain[12] = { - 3, 6, 4, 7, 5, 10, 6, 16, 11, 28, 26, 69}; - -const uint16_t WebRtcIsac_kQKltInitIndexShape[108] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - 1, 1, 1, 1, 2, 2, 3, 3, 0, 0, - 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, - 1, 1, 2, 2, 3, 4, 0, 0, 0, 0, - 1, 0, 1, 1, 1, 1, 2, 1, 1, 2, - 2, 3, 3, 5, 0, 0, 0, 0, 1, 1, - 1, 1, 1, 1, 2, 1, 2, 2, 4, 4, - 5, 7, 0, 0, 1, 1, 1, 1, 1, 1, - 2, 2, 3, 2, 3, 4, 4, 5, 8, 13, - 0, 1, 1, 2, 3, 2, 2, 2, 4, 4, - 5, 5, 7, 10, 9, 12, 13, 25 }; - - -/* quantizer representation levels */ -const double WebRtcIsac_kQKltLevelsGain[392] = { - -2.78127126, -1.76745590, -0.77913790, -0.00437329, 0.79961206, - 1.81775776, 2.81389782, -5.78753143, -4.88384084, -3.89320940, - -2.88133610, -1.92859977, -0.86347396, 0.02003888, 0.86140400, - 1.89667156, 2.97134967, 3.98781964, 4.91727277, 5.82865898, - -4.11195874, -2.80898424, -1.87547977, -0.80943825, -0.00679084, - 0.79573851, 1.83953397, 2.67586037, 3.76274082, -6.10933968, - -4.93034581, -3.89281296, -2.91530625, -1.89684163, -0.85319130, - -0.02275767, 0.86862017, 1.91578276, 2.96107339, 3.96543056, - 4.91369908, 5.91058154, 6.83848343, 8.07136925, -5.87470395, - -4.84703049, -3.84284597, -2.86168446, -1.89290192, -0.82798145, - -0.00080013, 0.82594974, 1.85754329, 2.88351798, 3.96172628, - -8.85684885, -7.87387461, -6.97811862, -5.93256270, -4.94301439, - -3.95513701, -2.96041544, -1.94031192, -0.87961478, -0.00456201, - 0.89911505, 1.91723376, 2.94011511, 3.93302540, 4.97990967, - 5.93133404, 7.02181199, 7.92407762, 8.80155440, 10.04665814, - -4.82396678, -3.85612158, -2.89482244, -1.89558408, -0.90036978, - -0.00677823, 0.90607989, 1.90937981, 2.91175777, 3.91637730, - 4.97565723, 5.84771228, 7.11145863, -16.07879840, -15.03776309, - -13.93905670, -12.95671800, -11.89171202, -10.95820934, -9.95923714, - -8.94357334, -7.99068299, -6.97481009, -5.94826231, -4.96673988, - -3.97490466, -2.97846970, -1.95130435, -0.94215262, -0.01444043, - 0.96770704, 1.95848598, 2.94107862, 3.95666119, 4.97253085, - 5.97191122, 6.93277360, 7.96608727, 8.87958779, 10.00264269, - 10.86560820, 12.07449071, 13.04491775, 13.97507061, 14.91845261, - -10.85696295, -9.83365357, -9.01245635, -7.95915145, -6.95625003, - -5.95362618, -4.93468444, -3.98760978, -2.95044407, -1.97041277, - -0.97701799, -0.00840234, 0.97834289, 1.98361415, 2.97802439, - 3.96415871, 4.95369042, 5.94101770, 6.92756798, 7.94063998, - 8.85951828, 9.97077022, 11.00068503, -33.92030406, -32.81426422, - -32.00000000, -31.13243639, -30.11886909, -29.06017570, -28.12598824, - -27.22045482, -25.81215858, -25.07849962, -23.93018013, -23.02097643, - -21.89529725, -20.99091085, -19.98889048, -18.94327044, -17.96562071, - -16.96126218, -15.95054062, -14.98516200, -13.97101012, -13.02106500, - -11.98438006, -11.03216748, -9.95930286, -8.97043946, -7.98085082, - -6.98360995, -5.98998802, -4.98668173, -4.00032906, -3.00420619, - -1.98701132, -0.99324682, -0.00609324, 0.98297834, 1.99483076, - 3.00305044, 3.97142097, 4.97525759, 5.98612258, 6.97448236, - 7.97575900, 9.01086211, 9.98665542, 11.00541438, 11.98078628, - 12.92352471, 14.06849675, 14.99949430, 15.94904834, 16.97440321, - 18.04040916, 18.88987609, 20.05312391, 21.00000000, 21.79443341, - -31.98578825, -31.00000000, -29.89060567, -28.98555686, -27.97114102, - -26.84935410, -26.02402230, -24.94195278, -23.92336849, -22.95552382, - -21.97932836, -20.96055470, -19.99649553, -19.03436122, -17.96706525, - -17.01139515, -16.01363516, -14.99154248, -14.00298333, -12.99630613, - -11.99955519, -10.99000421, -10.00819092, -8.99763648, -7.98431793, - -7.01769025, -5.99604690, -4.99980697, -3.99334671, -3.01748192, - -2.02051217, -1.00848371, -0.01942358, 1.00477757, 1.95477872, - 2.98593031, 3.98779079, 4.96862849, 6.02694771, 6.93983733, - 7.89874717, 8.99615862, 10.02367921, 10.96293452, 11.84351528, - 12.92207187, 13.85122329, 15.05146877, 15.99371264, 17.00000000, - 18.00000000, 19.00000000, 19.82763573, -47.00000000, -46.00000000, - -44.87138498, -44.00000000, -43.00000000, -42.00000000, -41.00000000, - -39.88966612, -38.98913239, -37.80306486, -37.23584325, -35.94200288, - -34.99881301, -34.11361858, -33.06507360, -32.13129135, -30.90891364, - -29.81511907, -28.99250380, -28.04535391, -26.99767800, -26.04418164, - -24.95687851, -24.04865595, -23.03392645, -21.89366707, -20.93517364, - -19.99388660, -18.91620943, -18.03749683, -16.99532379, -15.98683813, - -15.06421479, -13.99359211, -12.99714098, -11.97022520, -10.98500279, - -9.98834422, -8.95729330, -8.01232284, -7.00253661, -5.99681626, - -5.01207817, -3.95914904, -3.01232178, -1.96615919, -0.97687670, - 0.01228030, 0.98412288, 2.01753544, 3.00580570, 3.97783510, - 4.98846894, 6.01321400, 7.00867732, 8.00416375, 9.01771966, - 9.98637729, 10.98255180, 11.99194163, 13.01807333, 14.00999545, - 15.00118556, 16.00089224, 17.00584148, 17.98251763, 18.99942091, - 19.96917690, 20.97839265, 21.98207297, 23.00171271, 23.99930737, - 24.99746061, 26.00936304, 26.98240132, 28.01126868, 29.01395915, - 29.98153507, 31.01376711, 31.99876818, 33.00475317, 33.99753994, - 34.99493913, 35.98933585, 36.95620160, 37.98428461, 38.99317544, - 40.01832073, 40.98048133, 41.95999283, 42.98232091, 43.96523612, - 44.99574268, 45.99524194, 47.05464025, 48.03821548, 48.99354366, - 49.96400411, 50.98017973, 51.95184408, 52.96291806, 54.00194392, - 54.96603783, 55.95623778, 57.03076595, 58.05889901, 58.99081551, - 59.97928121, 61.05071612, 62.03971580, 63.01286038, 64.01290338, - 65.02074503, 65.99454594, 67.00399425, 67.96571257, 68.95305727, - 69.92030664, 70.95594862, 71.98088567, 73.04764124, 74.00285480, - 75.02696330, 75.89837673, 76.93459997, 78.16266309, 78.83317543, - 80.00000000, 80.87251574, 82.09803524, 83.10671664, 84.00000000, - 84.77023523, 86.00000000, 87.00000000, 87.92946897, 88.69159118, - 90.00000000, 90.90535270 }; - -const double WebRtcIsac_kQKltLevelsShape[578] = { - 0.00032397, 0.00008053, -0.00061202, -0.00012620, 0.00030437, - 0.00054764, -0.00027902, 0.00069360, 0.00029449, -0.80219239, - 0.00091089, -0.74514927, -0.00094283, 0.64030631, -0.60509119, - 0.00035575, 0.61851665, -0.62129957, 0.00375219, 0.60054900, - -0.61554359, 0.00054977, 0.63362016, -1.73118727, -0.65422341, - 0.00524568, 0.66165298, 1.76785515, -1.83182018, -0.65997434, - -0.00011887, 0.67524299, 1.79933938, -1.76344480, -0.72547708, - -0.00133017, 0.73104704, 1.75305377, 2.85164534, -2.80423916, - -1.71959639, -0.75419722, -0.00329945, 0.77196760, 1.72211069, - 2.87339653, 0.00031089, -0.00015311, 0.00018201, -0.00035035, - -0.77357251, 0.00154647, -0.00047625, -0.00045299, 0.00086590, - 0.00044762, -0.83383829, 0.00024787, -0.68526258, -0.00122472, - 0.64643255, -0.60904942, -0.00448987, 0.62309184, -0.59626442, - -0.00574132, 0.62296546, -0.63222115, 0.00013441, 0.63609545, - -0.66911055, -0.00369971, 0.66346095, 2.07281301, -1.77184694, - -0.67640425, -0.00010145, 0.64818392, 1.74948973, -1.69420224, - -0.71943894, -0.00004680, 0.75303493, 1.81075983, 2.80610041, - -2.80005755, -1.79866753, -0.77409777, -0.00084220, 0.80141293, - 1.78291081, 2.73954236, 3.82994169, 0.00015140, -0.00012766, - -0.00034241, -0.00119125, -0.76113497, 0.00069246, 0.76722027, - 0.00132862, -0.69107530, 0.00010656, 0.77061578, -0.78012970, - 0.00095947, 0.77828502, -0.64787758, 0.00217168, 0.63050167, - -0.58601125, 0.00306596, 0.59466308, -0.58603410, 0.00059779, - 0.64257970, 1.76512766, -0.61193600, -0.00259517, 0.59767574, - -0.61026273, 0.00315811, 0.61725479, -1.69169719, -0.65816029, - 0.00067575, 0.65576890, 2.00000000, -1.72689193, -0.69780808, - -0.00040990, 0.70668487, 1.74198458, -3.79028154, -3.00000000, - -1.73194459, -0.70179341, -0.00106695, 0.71302629, 1.76849782, - -2.89332364, -1.78585007, -0.78731491, -0.00132610, 0.79692976, - 1.75247009, 2.97828682, -5.26238694, -3.69559829, -2.87286122, - -1.84908818, -0.84434577, -0.01167975, 0.84641753, 1.84087672, - 2.87628156, 3.83556679, -0.00190204, 0.00092642, 0.00354385, - -0.00012982, -0.67742785, 0.00229509, 0.64935672, -0.58444751, - 0.00470733, 0.57299534, -0.58456202, -0.00097715, 0.64593607, - -0.64060330, -0.00638534, 0.59680157, -0.59287537, 0.00490772, - 0.58919707, -0.60306173, -0.00417464, 0.60562100, -1.75218757, - -0.63018569, -0.00225922, 0.63863300, -0.63949939, -0.00126421, - 0.64268914, -1.75851182, -0.68318060, 0.00510418, 0.69049211, - 1.88178506, -1.71136148, -0.72710534, -0.00815559, 0.73412917, - 1.79996711, -2.77111145, -1.73940498, -0.78212945, 0.01074476, - 0.77688916, 1.76873972, 2.87281379, 3.77554698, -3.75832725, - -2.95463235, -1.80451491, -0.80017226, 0.00149902, 0.80729206, - 1.78265046, 2.89391793, -3.78236148, -2.83640598, -1.82532067, - -0.88844327, -0.00620952, 0.88208030, 1.85757631, 2.81712391, - 3.88430176, 5.16179367, -7.00000000, -5.93805408, -4.87172597, - -3.87524433, -2.89399744, -1.92359563, -0.92136341, -0.00172725, - 0.93087018, 1.90528280, 2.89809686, 3.88085708, 4.89147740, - 5.89078692, -0.00239502, 0.00312564, -1.00000000, 0.00178325, - 1.00000000, -0.62198029, 0.00143254, 0.65344051, -0.59851220, - -0.00676987, 0.61510140, -0.58894151, 0.00385055, 0.59794203, - -0.59808568, -0.00038214, 0.57625703, -0.63009713, -0.01107985, - 0.61278758, -0.64206758, -0.00154369, 0.65480598, 1.80604162, - -1.80909286, -0.67810514, 0.00205762, 0.68571097, 1.79453891, - -3.22682422, -1.73808453, -0.71870305, -0.00738594, 0.71486172, - 1.73005326, -1.66891897, -0.73689615, -0.00616203, 0.74262409, - 1.73807899, -2.92417482, -1.73866741, -0.78133871, 0.00764425, - 0.80027264, 1.78668732, 2.74992588, -4.00000000, -2.75578740, - -1.83697516, -0.83117035, -0.00355191, 0.83527172, 1.82814700, - 2.77377675, 3.80718693, -3.81667698, -2.83575471, -1.83372350, - -0.86579471, 0.00547578, 0.87582281, 1.82858793, 2.87265007, - 3.91405377, -4.87521600, -3.78999094, -2.86437014, -1.86964365, - -0.90618018, 0.00128243, 0.91497811, 1.87374952, 2.83199819, - 3.91519130, 4.76632822, -6.68713448, -6.01252467, -4.94587936, - -3.88795368, -2.91299088, -1.92592211, -0.95504570, -0.00089980, - 0.94565200, 1.93239633, 2.91832808, 3.91363475, 4.88920034, - 5.96471415, 6.83905252, 7.86195009, 8.81571018,-12.96141759, - -11.73039516,-10.96459719, -9.97382433, -9.04414433, -7.89460619, - -6.96628608, -5.93236595, -4.93337924, -3.95479990, -2.96451499, - -1.96635876, -0.97271229, -0.00402238, 0.98343930, 1.98348291, - 2.96641164, 3.95456471, 4.95517089, 5.98975714, 6.90322073, - 7.90468849, 8.85639467, 9.97255498, 10.79006309, 11.81988596, - 0.04950500, -1.00000000, -0.01226628, 1.00000000, -0.59479469, - -0.10438305, 0.59822144, -2.00000000, -0.67109149, -0.09256692, - 0.65171621, 2.00000000, -3.00000000, -1.68391999, -0.76681039, - -0.03354151, 0.71509146, 1.77615472, -2.00000000, -0.68661511, - -0.02497881, 0.66478398, 2.00000000, -2.00000000, -0.67032784, - -0.00920582, 0.64892756, 2.00000000, -2.00000000, -0.68561894, - 0.03641869, 0.73021611, 1.68293863, -4.00000000, -2.72024184, - -1.80096059, -0.81696185, 0.03604685, 0.79232033, 1.70070730, - 3.00000000, -4.00000000, -2.71795670, -1.80482986, -0.86001162, - 0.03764903, 0.87723968, 1.79970771, 2.72685932, 3.67589143, - -5.00000000, -4.00000000, -2.85492548, -1.78996365, -0.83250358, - -0.01376828, 0.84195506, 1.78161105, 2.76754458, 4.00000000, - -6.00000000, -5.00000000, -3.82268811, -2.77563624, -1.82608163, - -0.86486114, -0.02671886, 0.86693165, 1.88422879, 2.86248347, - 3.95632216, -7.00000000, -6.00000000, -5.00000000, -3.77533988, - -2.86391432, -1.87052039, -0.90513658, 0.06271236, 0.91083620, - 1.85734756, 2.86031688, 3.82019418, 4.94420394, 6.00000000, - -11.00000000,-10.00000000, -9.00000000, -8.00000000, -6.91952415, - -6.00000000, -4.92044374, -3.87845165, -2.87392362, -1.88413020, - -0.91915740, 0.00318517, 0.91602800, 1.89664838, 2.88925058, - 3.84123856, 4.78988651, 5.94526812, 6.81953917, 8.00000000, - -9.00000000, -8.00000000, -7.03319143, -5.94530963, -4.86669720, - -3.92438007, -2.88620396, -1.92848070, -0.94365985, 0.01671855, - 0.97349410, 1.93419878, 2.89740109, 3.89662823, 4.83235583, - 5.88106535, 6.80328232, 8.00000000,-13.00000000,-12.00000000, - -11.00000000,-10.00000000, -9.00000000, -7.86033489, -6.83344055, - -5.89844215, -4.90811454, -3.94841298, -2.95820490, -1.98627966, - -0.99161468, -0.02286136, 0.96055651, 1.95052433, 2.93969396, - 3.94304346, 4.88522624, 5.87434241, 6.78309433, 7.87244101, - 9.00000000, 10.00000000,-12.09117356,-11.00000000,-10.00000000, - -8.84766108, -7.86934236, -6.98544896, -5.94233429, -4.95583292, - -3.95575986, -2.97085529, -1.98955811, -0.99359873, -0.00485413, - 0.98298870, 1.98093258, 2.96430203, 3.95540216, 4.96915010, - 5.96775124, 6.99236918, 7.96503302, 8.99864542, 9.85857723, - 10.96541926, 11.91647197, 12.71060069,-26.00000000,-25.00000000, - -24.00585596,-23.11642573,-22.14271284,-20.89800711,-19.87815799, - -19.05036354,-17.88555651,-16.86471209,-15.97711073,-14.94012359, - -14.02661226,-12.98243228,-11.97489256,-10.97402777, -9.96425624, - -9.01085220, -7.97372506, -6.98795002, -5.97271328, -5.00191694, - -3.98055849, -2.98458048, -1.99470442, -0.99656768, -0.00825666, - 1.00272004, 1.99922218, 2.99357669, 4.01407905, 5.01003897, - 5.98115528, 7.00018958, 8.00338125, 8.98981046, 9.98990318, - 10.96341479, 11.96866930, 12.99175139, 13.94580443, 14.95745083, - 15.98992869, 16.97484646, 17.99630043, 18.93396897, 19.88347741, - 20.96532482, 21.92191032, 23.22314702 }; - - -/* cdf tables for quantizer indices */ -const uint16_t WebRtcIsac_kQKltCdfGain[404] = { - 0, 13, 301, 3730, 61784, 65167, 65489, 65535, 0, 17, - 142, 314, 929, 2466, 7678, 56450, 63463, 64740, 65204, 65426, - 65527, 65535, 0, 8, 100, 724, 6301, 60105, 65125, 65510, - 65531, 65535, 0, 13, 117, 368, 1068, 3010, 11928, 53603, - 61177, 63404, 64505, 65108, 65422, 65502, 65531, 65535, 0, 4, - 17, 96, 410, 1859, 12125, 54361, 64103, 65305, 65497, 65535, - 0, 4, 88, 230, 469, 950, 1746, 3228, 6092, 16592, - 44756, 56848, 61256, 63308, 64325, 64920, 65309, 65460, 65502, - 65522, 65535, 0, 88, 352, 1675, 6339, 20749, 46686, 59284, 63525, - 64949, 65359, 65502, 65527, 65535, 0, 13, 38, 63, 117, - 234, 381, 641, 929, 1407, 2043, 2809, 4032, 5753, 8792, - 14407, 24308, 38941, 48947, 55403, 59293, 61411, 62688, 63630, - 64329, 64840, 65188, 65376, 65472, 65506, 65527, 65531, 65535, - 0, 8, 29, 75, 222, 615, 1327, 2801, 5623, 9931, 16094, 24966, - 34419, 43458, 50676, 56186, 60055, 62500, 63936, 64765, 65225, - 65435, 65514, 65535, 0, 8, 13, 15, 17, 21, 33, 59, - 71, 92, 151, 243, 360, 456, 674, 934, 1223, 1583, - 1989, 2504, 3031, 3617, 4354, 5154, 6163, 7411, 8780, 10747, - 12874, 15591, 18974, 23027, 27436, 32020, 36948, 41830, 46205, - 49797, 53042, 56094, 58418, 60360, 61763, 62818, 63559, 64103, - 64509, 64798, 65045, 65162, 65288, 65363, 65447, 65506, 65522, - 65531, 65533, 65535, 0, 4, 6, 25, 38, 71, 138, 264, 519, 808, - 1227, 1825, 2516, 3408, 4279, 5560, 7092, 9197, 11420, 14108, - 16947, 20300, 23926, 27459, 31164, 34827, 38575, 42178, 45540, - 48747, 51444, 54090, 56426, 58460, 60080, 61595, 62734, 63668, - 64275, 64673, 64936, 65112, 65217, 65334, 65426, 65464, 65477, - 65489, 65518, 65527, 65529, 65531, 65533, 65535, 0, 2, 4, 8, 10, - 12, 14, 16, 21, 33, 50, 71, 84, 92, 105, 138, 180, 255, 318, - 377, 435, 473, 511, 590, 682, 758, 913, 1097, 1256, 1449, 1671, - 1884, 2169, 2445, 2772, 3157, 3563, 3944, 4375, 4848, 5334, 5820, - 6448, 7101, 7716, 8378, 9102, 9956, 10752, 11648, 12707, 13670, - 14758, 15910, 17187, 18472, 19627, 20649, 21951, 23169, 24283, - 25552, 26862, 28227, 29391, 30764, 31882, 33213, 34432, 35600, - 36910, 38116, 39464, 40729, 41872, 43144, 44371, 45514, 46762, - 47813, 48968, 50069, 51032, 51974, 52908, 53737, 54603, 55445, - 56282, 56990, 57572, 58191, 58840, 59410, 59887, 60264, 60607, - 60946, 61269, 61516, 61771, 61960, 62198, 62408, 62558, 62776, - 62985, 63207, 63408, 63546, 63739, 63906, 64070, 64237, 64371, - 64551, 64677, 64836, 64999, 65095, 65213, 65284, 65338, 65380, - 65426, 65447, 65472, 65485, 65487, 65489, 65502, 65510, 65512, - 65514, 65516, 65518, 65522, 65531, 65533, 65535 }; - - -const uint16_t WebRtcIsac_kQKltCdfShape[686] = { - 0, 65535, 0, 65535, 0, 65535, 0, 65535, 0, 65535, - 0, 65535, 0, 65535, 0, 65535, 0, 65535, 0, 4, - 65535, 0, 8, 65514, 65535, 0, 29, 65481, 65535, 0, - 121, 65439, 65535, 0, 239, 65284, 65535, 0, 8, 779, - 64999, 65527, 65535, 0, 8, 888, 64693, 65522, 65535, 0, - 29, 2604, 62843, 65497, 65531, 65535, 0, 25, 176, 4576, - 61164, 65275, 65527, 65535, 0, 65535, 0, 65535, 0, 65535, - 0, 65535, 0, 4, 65535, 0, 65535, 0, 65535, 0, - 65535, 0, 65535, 0, 4, 65535, 0, 33, 65502, 65535, - 0, 54, 65481, 65535, 0, 251, 65309, 65535, 0, 611, - 65074, 65535, 0, 1273, 64292, 65527, 65535, 0, 4, 1809, - 63940, 65518, 65535, 0, 88, 4392, 60603, 65426, 65531, 65535, - 0, 25, 419, 7046, 57756, 64961, 65514, 65531, 65535, 0, - 65535, 0, 65535, 0, 65535, 0, 65535, 0, 4, 65531, - 65535, 0, 65535, 0, 8, 65531, 65535, 0, 4, 65527, - 65535, 0, 17, 65510, 65535, 0, 42, 65481, 65535, 0, - 197, 65342, 65531, 65535, 0, 385, 65154, 65535, 0, 1005, - 64522, 65535, 0, 8, 1985, 63469, 65533, 65535, 0, 38, - 3119, 61884, 65514, 65535, 0, 4, 6, 67, 4961, 60804, - 65472, 65535, 0, 17, 565, 9182, 56538, 65087, 65514, 65535, - 0, 8, 63, 327, 2118, 14490, 52774, 63839, 65376, 65522, - 65535, 0, 65535, 0, 65535, 0, 65535, 0, 65535, 0, - 17, 65522, 65535, 0, 59, 65489, 65535, 0, 50, 65522, - 65535, 0, 54, 65489, 65535, 0, 310, 65179, 65535, 0, - 615, 64836, 65535, 0, 4, 1503, 63965, 65535, 0, 2780, - 63383, 65535, 0, 21, 3919, 61051, 65527, 65535, 0, 84, - 6674, 59929, 65435, 65535, 0, 4, 255, 7976, 55784, 65150, - 65518, 65531, 65535, 0, 4, 8, 582, 10726, 53465, 64949, - 65518, 65535, 0, 29, 339, 3006, 17555, 49517, 62956, 65200, - 65497, 65531, 65535, 0, 2, 33, 138, 565, 2324, 7670, - 22089, 45966, 58949, 63479, 64966, 65380, 65518, 65535, 0, 65535, - 0, 65535, 0, 2, 65533, 65535, 0, 46, 65514, 65535, - 0, 414, 65091, 65535, 0, 540, 64911, 65535, 0, 419, - 65162, 65535, 0, 976, 64790, 65535, 0, 2977, 62495, 65531, - 65535, 0, 4, 3852, 61034, 65527, 65535, 0, 4, 29, - 6021, 60243, 65468, 65535, 0, 84, 6711, 58066, 65418, 65535, - 0, 13, 281, 9550, 54917, 65125, 65506, 65535, 0, 2, - 63, 984, 12108, 52644, 64342, 65435, 65527, 65535, 0, 29, - 251, 2014, 14871, 47553, 62881, 65229, 65518, 65535, 0, 13, - 142, 749, 4220, 18497, 45200, 60913, 64823, 65426, 65527, 65535, - 0, 13, 71, 264, 1176, 3789, 10500, 24480, 43488, 56324, - 62315, 64493, 65242, 65464, 65514, 65522, 65531, 65535, 0, 4, - 13, 38, 109, 205, 448, 850, 1708, 3429, 6276, 11371, - 19221, 29734, 40955, 49391, 55411, 59460, 62102, 63793, 64656, - 65150, 65401, 65485, 65522, 65531, 65535, 0, 65535, 0, 2, 65533, - 65535, 0, 1160, 65476, 65535, 0, 2, 6640, 64763, 65533, - 65535, 0, 2, 38, 9923, 61009, 65527, 65535, 0, 2, - 4949, 63092, 65533, 65535, 0, 2, 3090, 63398, 65533, 65535, - 0, 2, 2520, 58744, 65510, 65535, 0, 2, 13, 544, - 8784, 51403, 65148, 65533, 65535, 0, 2, 25, 1017, 10412, - 43550, 63651, 65489, 65527, 65535, 0, 2, 4, 29, 783, - 13377, 52462, 64524, 65495, 65533, 65535, 0, 2, 4, 6, - 100, 1817, 18451, 52590, 63559, 65376, 65531, 65535, 0, 2, - 4, 6, 46, 385, 2562, 11225, 37416, 60488, 65026, 65487, - 65529, 65533, 65535, 0, 2, 4, 6, 8, 10, 12, - 42, 222, 971, 5221, 19811, 45048, 60312, 64486, 65294, 65474, - 65525, 65529, 65533, 65535, 0, 2, 4, 8, 71, 167, - 666, 2533, 7875, 19622, 38082, 54359, 62108, 64633, 65290, 65495, - 65529, 65533, 65535, 0, 2, 4, 6, 8, 10, 13, - 109, 586, 1930, 4949, 11600, 22641, 36125, 48312, 56899, 61495, - 63927, 64932, 65389, 65489, 65518, 65531, 65533, 65535, 0, 4, - 6, 8, 67, 209, 712, 1838, 4195, 8432, 14432, 22834, - 31723, 40523, 48139, 53929, 57865, 60657, 62403, 63584, 64363, - 64907, 65167, 65372, 65472, 65514, 65535, 0, 2, 4, 13, 25, - 42, 46, 50, 75, 113, 147, 281, 448, 657, 909, - 1185, 1591, 1976, 2600, 3676, 5317, 7398, 9914, 12941, 16169, - 19477, 22885, 26464, 29851, 33360, 37228, 41139, 44802, 48654, - 52058, 55181, 57676, 59581, 61022, 62190, 63107, 63676, 64199, - 64547, 64924, 65158, 65313, 65430, 65481, 65518, 65535 }; - - -/* pointers to cdf tables for quantizer indices */ -const uint16_t *WebRtcIsac_kQKltCdfPtrGain[12] = { - WebRtcIsac_kQKltCdfGain +0 +0, WebRtcIsac_kQKltCdfGain +0 +8, - WebRtcIsac_kQKltCdfGain +0 +22, WebRtcIsac_kQKltCdfGain +0 +32, - WebRtcIsac_kQKltCdfGain +0 +48, WebRtcIsac_kQKltCdfGain +0 +60, - WebRtcIsac_kQKltCdfGain +0 +81, WebRtcIsac_kQKltCdfGain +0 +95, - WebRtcIsac_kQKltCdfGain +0 +128, WebRtcIsac_kQKltCdfGain +0 +152, - WebRtcIsac_kQKltCdfGain +0 +210, WebRtcIsac_kQKltCdfGain +0 +264 }; - -const uint16_t *WebRtcIsac_kQKltCdfPtrShape[108] = { - WebRtcIsac_kQKltCdfShape +0 +0, WebRtcIsac_kQKltCdfShape +0 +2, - WebRtcIsac_kQKltCdfShape +0 +4, WebRtcIsac_kQKltCdfShape +0 +6, - WebRtcIsac_kQKltCdfShape +0 +8, WebRtcIsac_kQKltCdfShape +0 +10, - WebRtcIsac_kQKltCdfShape +0 +12, WebRtcIsac_kQKltCdfShape +0 +14, - WebRtcIsac_kQKltCdfShape +0 +16, WebRtcIsac_kQKltCdfShape +0 +18, - WebRtcIsac_kQKltCdfShape +0 +21, WebRtcIsac_kQKltCdfShape +0 +25, - WebRtcIsac_kQKltCdfShape +0 +29, WebRtcIsac_kQKltCdfShape +0 +33, - WebRtcIsac_kQKltCdfShape +0 +37, WebRtcIsac_kQKltCdfShape +0 +43, - WebRtcIsac_kQKltCdfShape +0 +49, WebRtcIsac_kQKltCdfShape +0 +56, - WebRtcIsac_kQKltCdfShape +0 +64, WebRtcIsac_kQKltCdfShape +0 +66, - WebRtcIsac_kQKltCdfShape +0 +68, WebRtcIsac_kQKltCdfShape +0 +70, - WebRtcIsac_kQKltCdfShape +0 +72, WebRtcIsac_kQKltCdfShape +0 +75, - WebRtcIsac_kQKltCdfShape +0 +77, WebRtcIsac_kQKltCdfShape +0 +79, - WebRtcIsac_kQKltCdfShape +0 +81, WebRtcIsac_kQKltCdfShape +0 +83, - WebRtcIsac_kQKltCdfShape +0 +86, WebRtcIsac_kQKltCdfShape +0 +90, - WebRtcIsac_kQKltCdfShape +0 +94, WebRtcIsac_kQKltCdfShape +0 +98, - WebRtcIsac_kQKltCdfShape +0 +102, WebRtcIsac_kQKltCdfShape +0 +107, - WebRtcIsac_kQKltCdfShape +0 +113, WebRtcIsac_kQKltCdfShape +0 +120, - WebRtcIsac_kQKltCdfShape +0 +129, WebRtcIsac_kQKltCdfShape +0 +131, - WebRtcIsac_kQKltCdfShape +0 +133, WebRtcIsac_kQKltCdfShape +0 +135, - WebRtcIsac_kQKltCdfShape +0 +137, WebRtcIsac_kQKltCdfShape +0 +141, - WebRtcIsac_kQKltCdfShape +0 +143, WebRtcIsac_kQKltCdfShape +0 +147, - WebRtcIsac_kQKltCdfShape +0 +151, WebRtcIsac_kQKltCdfShape +0 +155, - WebRtcIsac_kQKltCdfShape +0 +159, WebRtcIsac_kQKltCdfShape +0 +164, - WebRtcIsac_kQKltCdfShape +0 +168, WebRtcIsac_kQKltCdfShape +0 +172, - WebRtcIsac_kQKltCdfShape +0 +178, WebRtcIsac_kQKltCdfShape +0 +184, - WebRtcIsac_kQKltCdfShape +0 +192, WebRtcIsac_kQKltCdfShape +0 +200, - WebRtcIsac_kQKltCdfShape +0 +211, WebRtcIsac_kQKltCdfShape +0 +213, - WebRtcIsac_kQKltCdfShape +0 +215, WebRtcIsac_kQKltCdfShape +0 +217, - WebRtcIsac_kQKltCdfShape +0 +219, WebRtcIsac_kQKltCdfShape +0 +223, - WebRtcIsac_kQKltCdfShape +0 +227, WebRtcIsac_kQKltCdfShape +0 +231, - WebRtcIsac_kQKltCdfShape +0 +235, WebRtcIsac_kQKltCdfShape +0 +239, - WebRtcIsac_kQKltCdfShape +0 +243, WebRtcIsac_kQKltCdfShape +0 +248, - WebRtcIsac_kQKltCdfShape +0 +252, WebRtcIsac_kQKltCdfShape +0 +258, - WebRtcIsac_kQKltCdfShape +0 +264, WebRtcIsac_kQKltCdfShape +0 +273, - WebRtcIsac_kQKltCdfShape +0 +282, WebRtcIsac_kQKltCdfShape +0 +293, - WebRtcIsac_kQKltCdfShape +0 +308, WebRtcIsac_kQKltCdfShape +0 +310, - WebRtcIsac_kQKltCdfShape +0 +312, WebRtcIsac_kQKltCdfShape +0 +316, - WebRtcIsac_kQKltCdfShape +0 +320, WebRtcIsac_kQKltCdfShape +0 +324, - WebRtcIsac_kQKltCdfShape +0 +328, WebRtcIsac_kQKltCdfShape +0 +332, - WebRtcIsac_kQKltCdfShape +0 +336, WebRtcIsac_kQKltCdfShape +0 +341, - WebRtcIsac_kQKltCdfShape +0 +347, WebRtcIsac_kQKltCdfShape +0 +354, - WebRtcIsac_kQKltCdfShape +0 +360, WebRtcIsac_kQKltCdfShape +0 +368, - WebRtcIsac_kQKltCdfShape +0 +378, WebRtcIsac_kQKltCdfShape +0 +388, - WebRtcIsac_kQKltCdfShape +0 +400, WebRtcIsac_kQKltCdfShape +0 +418, - WebRtcIsac_kQKltCdfShape +0 +445, WebRtcIsac_kQKltCdfShape +0 +447, - WebRtcIsac_kQKltCdfShape +0 +451, WebRtcIsac_kQKltCdfShape +0 +455, - WebRtcIsac_kQKltCdfShape +0 +461, WebRtcIsac_kQKltCdfShape +0 +468, - WebRtcIsac_kQKltCdfShape +0 +474, WebRtcIsac_kQKltCdfShape +0 +480, - WebRtcIsac_kQKltCdfShape +0 +486, WebRtcIsac_kQKltCdfShape +0 +495, - WebRtcIsac_kQKltCdfShape +0 +505, WebRtcIsac_kQKltCdfShape +0 +516, - WebRtcIsac_kQKltCdfShape +0 +528, WebRtcIsac_kQKltCdfShape +0 +543, - WebRtcIsac_kQKltCdfShape +0 +564, WebRtcIsac_kQKltCdfShape +0 +583, - WebRtcIsac_kQKltCdfShape +0 +608, WebRtcIsac_kQKltCdfShape +0 +635 }; - - -/* left KLT transforms */ -const double WebRtcIsac_kKltT1Gain[4] = { - -0.79742827, 0.60341375, 0.60341375, 0.79742827 }; - -const double WebRtcIsac_kKltT1Shape[324] = { - 0.00159597, 0.00049320, 0.00513821, 0.00021066, 0.01338581, - -0.00422367, -0.00272072, 0.00935107, 0.02047622, 0.02691189, - 0.00478236, 0.03969702, 0.00886698, 0.04877604, -0.10898362, - -0.05930891, -0.03415047, 0.98889721, 0.00293558, -0.00035282, - 0.01156321, -0.00195341, -0.00937631, 0.01052213, -0.02551163, - 0.01644059, 0.03189927, 0.07754773, -0.08742313, -0.03026338, - 0.05136248, -0.14395974, 0.17725040, 0.22664856, 0.93380230, - 0.07076411, 0.00557890, -0.00222834, 0.01377569, 0.01466808, - 0.02847361, -0.00603178, 0.02382480, -0.01210452, 0.03797267, - -0.02371480, 0.11260335, -0.07366682, 0.00453436, -0.04136941, - -0.07912843, -0.95031418, 0.25295337, -0.05302216, -0.00617554, - -0.00044040, -0.00653778, 0.01097838, 0.01529174, 0.01374431, - -0.00748512, -0.00020034, 0.02432713, 0.11101570, -0.08556891, - 0.09282249, -0.01029446, 0.67556443, -0.67454300, 0.06910063, - 0.20866865, -0.10318050, 0.00932175, 0.00524058, 0.00803610, - -0.00594676, -0.01082578, 0.01069906, 0.00546768, 0.01565291, - 0.06816200, 0.10201227, 0.16812734, 0.22984074, 0.58213170, - -0.54138651, -0.51379962, 0.06847390, -0.01920037, -0.04592324, - -0.00467394, 0.00328858, 0.00377424, -0.00987448, 0.08222096, - -0.00377301, 0.04551941, -0.02592517, 0.16317082, 0.13077530, - 0.22702921, -0.31215289, -0.69645962, -0.38047101, -0.39339411, - 0.11124777, 0.02508035, -0.00708074, 0.00400344, 0.00040331, - 0.01142402, 0.01725406, 0.01635170, 0.14285366, 0.03949233, - -0.05905676, 0.05877154, -0.17497577, -0.32479440, 0.80754464, - -0.38085603, -0.17055430, -0.03168622, -0.07531451, 0.02942002, - -0.02148095, -0.00754114, -0.00322372, 0.00567812, -0.01701521, - -0.12358320, 0.11473564, 0.09070136, 0.06533068, -0.22560802, - 0.19209022, 0.81605094, 0.36592275, -0.09919829, 0.16667122, - 0.16300725, 0.04803807, 0.06739263, -0.00156752, -0.01685302, - -0.00905240, -0.02297836, -0.00469939, 0.06310613, -0.16391930, - 0.10919511, 0.12529293, 0.85581322, -0.32145522, 0.24539076, - 0.07181839, 0.07289591, 0.14066759, 0.10406711, 0.05815518, - 0.01072680, -0.00759339, 0.00053486, -0.00044865, 0.03407361, - 0.01645348, 0.08758579, 0.27722240, 0.53665485, -0.74853376, - -0.01118192, -0.19805430, 0.06130619, -0.09675299, 0.08978480, - 0.03405255, -0.00706867, 0.05102045, 0.03250746, 0.01849966, - -0.01216314, -0.01184187, -0.01579288, 0.00114807, 0.11376166, - 0.88342114, -0.36425379, 0.13863190, 0.12524180, -0.13553892, - 0.04715856, -0.12341103, 0.04531568, 0.01899360, -0.00206897, - 0.00567768, -0.01444163, 0.00411946, -0.00855896, 0.00381663, - -0.01664861, -0.05534280, 0.21328278, 0.20161162, 0.72360394, - 0.59130708, -0.08043791, 0.08757349, -0.13893918, -0.05147377, - 0.02680690, -0.01144070, 0.00625162, -0.00634215, -0.01248947, - -0.00329455, -0.00609625, -0.00136305, -0.05097048, -0.01029851, - 0.25065384, -0.16856837, -0.07123372, 0.15992623, -0.39487617, - -0.79972301, 0.18118185, -0.04826639, -0.01805578, -0.02927253, - -0.16400618, 0.07472763, 0.10376449, 0.01705406, 0.01065801, - -0.01500498, 0.02039914, 0.37776349, -0.84484186, 0.10434286, - 0.15616990, 0.13474456, -0.00906238, -0.25238368, -0.03820885, - -0.10650905, -0.03880833, -0.03660028, -0.09640894, 0.00583314, - 0.01922097, 0.01489911, -0.02431117, -0.09372217, 0.39404721, - -0.84786223, -0.31277121, 0.03193850, 0.01974060, 0.01887901, - 0.00337911, -0.11359599, -0.02792521, -0.03220184, -0.01533311, - 0.00015962, -0.04225043, -0.00933965, 0.00675311, 0.00206060, - 0.15926771, 0.40199829, -0.80792558, -0.35591604, -0.17169764, - 0.02830436, 0.02459982, -0.03438589, 0.00718705, -0.01798329, - -0.01594508, -0.00702430, -0.00952419, -0.00962701, -0.01307212, - -0.01749740, 0.01299602, 0.00587270, -0.36103108, -0.82039266, - -0.43092844, -0.08500097, -0.04361674, -0.00333482, 0.01250434, - -0.02538295, -0.00921797, 0.01645071, -0.01400872, 0.00317607, - 0.00003277, -0.01617646, -0.00616863, -0.00882661, 0.00466157, - 0.00353237, 0.91803104, -0.39503305, -0.02048964, 0.00060125, - 0.01980634, 0.00300109, 0.00313880, 0.00657337, 0.00715163, - 0.00000261, 0.00854276, -0.00154825, -0.00516128, 0.00909527, - 0.00095609, 0.00701196, -0.00221867, -0.00156741 }; - -/* right KLT transforms */ -const double WebRtcIsac_kKltT2Gain[36] = { - 0.14572837, -0.45446306, 0.61990621, -0.52197033, 0.32145074, - -0.11026900, -0.20698282, 0.48962182, -0.27127933, -0.33627476, - 0.65094037, -0.32715751, 0.40262573, -0.47844405, -0.33876075, - 0.44130653, 0.37383966, -0.39964662, -0.51730480, 0.06611973, - 0.49030187, 0.47512886, -0.02141226, -0.51129451, -0.58578569, - -0.39132064, -0.13187771, 0.15649421, 0.40735596, 0.54396897, - 0.40381276, 0.40904942, 0.41179766, 0.41167576, 0.40840251, - 0.40468132 }; - -const double WebRtcIsac_kKltT2Shape[36] = { - 0.13427386, -0.35132558, 0.52506528, -0.59419077, 0.45075085, - -0.16312057, 0.29857439, -0.58660147, 0.34265431, 0.20879510, - -0.56063262, 0.30238345, 0.43308283, -0.41186999, -0.35288681, - 0.42768996, 0.36094634, -0.45284910, -0.47116680, 0.02893449, - 0.54326135, 0.45249040, -0.06264420, -0.52283830, 0.57137758, - 0.44298139, 0.12617554, -0.20819946, -0.42324603, -0.48876443, - 0.39597050, 0.40713935, 0.41389880, 0.41512486, 0.41130400, - 0.40575001 }; - -/* means of log gains and LAR coefficients*/ -const double WebRtcIsac_kLpcMeansGain[12] = { - -6.86881911, -5.35075273, -6.86792680, -5.36200897, -6.86401538, - -5.36921533, -6.86802969, -5.36893966, -6.86538097, -5.36315063, - -6.85535304, -5.35155315 }; - -const double WebRtcIsac_kLpcMeansShape[108] = { - -0.91232981, 0.26258634, -0.33716701, 0.08477430, -0.03378426, - 0.14423909, 0.07036185, 0.06155019, 0.01490385, 0.04138740, - 0.01427317, 0.01288970, 0.83872106, 0.25750199, 0.07988929, - -0.01957923, 0.00831390, 0.01770300, -0.90957164, 0.25732216, - -0.33385344, 0.08735740, -0.03715332, 0.14584917, 0.06998990, - 0.06131968, 0.01504379, 0.04067339, 0.01428039, 0.01406460, - 0.83846243, 0.26169862, 0.08109025, -0.01767055, 0.00970539, - 0.01954310, -0.90490803, 0.24656405, -0.33578607, 0.08843286, - -0.03749139, 0.14443959, 0.07214669, 0.06170993, 0.01449947, - 0.04134309, 0.01314762, 0.01413471, 0.83895203, 0.26748062, - 0.08197507, -0.01781298, 0.00885967, 0.01922394, -0.90922472, - 0.24495889, -0.33921540, 0.08877169, -0.03581332, 0.14199172, - 0.07444032, 0.06185940, 0.01502054, 0.04185113, 0.01276579, - 0.01355457, 0.83645358, 0.26631720, 0.08119697, -0.01835449, - 0.00788512, 0.01846446, -0.90482253, 0.24658310, -0.34019734, - 0.08281090, -0.03486038, 0.14359248, 0.07401336, 0.06001471, - 0.01528421, 0.04254560, 0.01321472, 0.01240799, 0.83857127, - 0.26281654, 0.08174380, -0.02099842, 0.00755176, 0.01699448, - -0.90132307, 0.25174308, -0.33838268, 0.07883863, -0.02877906, - 0.14105407, 0.07220290, 0.06000352, 0.01684879, 0.04226844, - 0.01331331, 0.01269244, 0.83832138, 0.25467485, 0.08118028, - -0.02120528, 0.00747832, 0.01567212 }; diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/lpc_tables.h b/webrtc/modules/audio_coding/codecs/isac/main/source/lpc_tables.h deleted file mode 100644 index 56ff22c..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/lpc_tables.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -/* - * lpc_tables.h - * - * header file for coding tables for the LPC coefficients - * - */ - -#ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_TABLES_H_ -#define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_TABLES_H_ - -#include "modules/audio_coding/codecs/isac/main/source/settings.h" -#include "modules/audio_coding/codecs/isac/main/source/structs.h" - -#define KLT_STEPSIZE 1.00000000 -#define KLT_NUM_AVG_GAIN 0 -#define KLT_NUM_AVG_SHAPE 0 -#define KLT_NUM_MODELS 3 -#define LPC_GAIN_SCALE 4.000f -#define LPC_LOBAND_SCALE 2.100f -#define LPC_LOBAND_ORDER ORDERLO -#define LPC_HIBAND_SCALE 0.450f -#define LPC_HIBAND_ORDER ORDERHI -#define LPC_GAIN_ORDER 2 - -#define LPC_SHAPE_ORDER (LPC_LOBAND_ORDER + LPC_HIBAND_ORDER) - -#define KLT_ORDER_GAIN (LPC_GAIN_ORDER * SUBFRAMES) -#define KLT_ORDER_SHAPE (LPC_SHAPE_ORDER * SUBFRAMES) - -/* cdf array for model indicator */ -extern const uint16_t WebRtcIsac_kQKltModelCdf[KLT_NUM_MODELS + 1]; - -/* pointer to cdf array for model indicator */ -extern const uint16_t* WebRtcIsac_kQKltModelCdfPtr[1]; - -/* initial cdf index for decoder of model indicator */ -extern const uint16_t WebRtcIsac_kQKltModelInitIndex[1]; - -/* offset to go from rounded value to quantization index */ -extern const short WebRtcIsac_kQKltQuantMinGain[12]; - -extern const short WebRtcIsac_kQKltQuantMinShape[108]; - -/* maximum quantization index */ -extern const uint16_t WebRtcIsac_kQKltMaxIndGain[12]; - -extern const uint16_t WebRtcIsac_kQKltMaxIndShape[108]; - -/* index offset */ -extern const uint16_t WebRtcIsac_kQKltOffsetGain[12]; - -extern const uint16_t WebRtcIsac_kQKltOffsetShape[108]; - -/* initial cdf index for KLT coefficients */ -extern const uint16_t WebRtcIsac_kQKltInitIndexGain[12]; - -extern const uint16_t WebRtcIsac_kQKltInitIndexShape[108]; - -/* quantizer representation levels */ -extern const double WebRtcIsac_kQKltLevelsGain[392]; - -extern const double WebRtcIsac_kQKltLevelsShape[578]; - -/* cdf tables for quantizer indices */ -extern const uint16_t WebRtcIsac_kQKltCdfGain[404]; - -extern const uint16_t WebRtcIsac_kQKltCdfShape[686]; - -/* pointers to cdf tables for quantizer indices */ -extern const uint16_t* WebRtcIsac_kQKltCdfPtrGain[12]; - -extern const uint16_t* WebRtcIsac_kQKltCdfPtrShape[108]; - -/* left KLT transforms */ -extern const double WebRtcIsac_kKltT1Gain[4]; - -extern const double WebRtcIsac_kKltT1Shape[324]; - -/* right KLT transforms */ -extern const double WebRtcIsac_kKltT2Gain[36]; - -extern const double WebRtcIsac_kKltT2Shape[36]; - -/* means of log gains and LAR coefficients */ -extern const double WebRtcIsac_kLpcMeansGain[12]; - -extern const double WebRtcIsac_kLpcMeansShape[108]; - -#endif /* MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_LPC_TABLES_H_ */ diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/pitch_gain_tables.c b/webrtc/modules/audio_coding/codecs/isac/main/source/pitch_gain_tables.c deleted file mode 100644 index 080432c..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/pitch_gain_tables.c +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "modules/audio_coding/codecs/isac/main/source/pitch_gain_tables.h" -#include "modules/audio_coding/codecs/isac/main/source/settings.h" - -/* header file for coding tables for the pitch filter side-info in the entropy coder */ -/********************* Pitch Filter Gain Coefficient Tables ************************/ -/* cdf for quantized pitch filter gains */ -const uint16_t WebRtcIsac_kQPitchGainCdf[255] = { - 0, 2, 4, 6, 64, 901, 903, 905, 16954, 16956, - 16961, 17360, 17362, 17364, 17366, 17368, 17370, 17372, 17374, 17411, - 17514, 17516, 17583, 18790, 18796, 18802, 20760, 20777, 20782, 21722, - 21724, 21728, 21738, 21740, 21742, 21744, 21746, 21748, 22224, 22227, - 22230, 23214, 23229, 23239, 25086, 25108, 25120, 26088, 26094, 26098, - 26175, 26177, 26179, 26181, 26183, 26185, 26484, 26507, 26522, 27705, - 27731, 27750, 29767, 29799, 29817, 30866, 30883, 30885, 31025, 31029, - 31031, 31033, 31035, 31037, 31114, 31126, 31134, 32687, 32722, 32767, - 35718, 35742, 35757, 36943, 36952, 36954, 37115, 37128, 37130, 37132, - 37134, 37136, 37143, 37145, 37152, 38843, 38863, 38897, 47458, 47467, - 47474, 49040, 49061, 49063, 49145, 49157, 49159, 49161, 49163, 49165, - 49167, 49169, 49171, 49757, 49770, 49782, 61333, 61344, 61346, 62860, - 62883, 62885, 62887, 62889, 62891, 62893, 62895, 62897, 62899, 62901, - 62903, 62905, 62907, 62909, 65496, 65498, 65500, 65521, 65523, 65525, - 65527, 65529, 65531, 65533, 65535, 65535, 65535, 65535, 65535, 65535, - 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, - 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, - 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, - 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, - 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, - 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, - 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, - 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, - 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, - 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, - 65535, 65535, 65535, 65535, 65535}; - -/* index limits and ranges */ -const int16_t WebRtcIsac_kIndexLowerLimitGain[3] = { - -7, -2, -1}; - -const int16_t WebRtcIsac_kIndexUpperLimitGain[3] = { - 0, 3, 1}; - -const uint16_t WebRtcIsac_kIndexMultsGain[2] = { - 18, 3}; - -/* size of cdf table */ -const uint16_t WebRtcIsac_kQCdfTableSizeGain[1] = { - 256}; - -///////////////////////////FIXED POINT -/* mean values of pitch filter gains in FIXED point */ -const int16_t WebRtcIsac_kQMeanGain1Q12[144] = { - 843, 1092, 1336, 1222, 1405, 1656, 1500, 1815, 1843, 1838, 1839, 1843, 1843, 1843, 1843, 1843, - 1843, 1843, 814, 846, 1092, 1013, 1174, 1383, 1391, 1511, 1584, 1734, 1753, 1843, 1843, 1843, - 1843, 1843, 1843, 1843, 524, 689, 777, 845, 947, 1069, 1090, 1263, 1380, 1447, 1559, 1676, - 1645, 1749, 1843, 1843, 1843, 1843, 81, 477, 563, 611, 706, 806, 849, 1012, 1192, 1128, - 1330, 1489, 1425, 1576, 1826, 1741, 1843, 1843, 0, 290, 305, 356, 488, 575, 602, 741, - 890, 835, 1079, 1196, 1182, 1376, 1519, 1506, 1680, 1843, 0, 47, 97, 69, 289, 381, - 385, 474, 617, 664, 803, 1079, 935, 1160, 1269, 1265, 1506, 1741, 0, 0, 0, 0, - 112, 120, 190, 283, 442, 343, 526, 809, 684, 935, 1134, 1020, 1265, 1506, 0, 0, - 0, 0, 0, 0, 0, 111, 256, 87, 373, 597, 430, 684, 935, 770, 1020, 1265}; - -const int16_t WebRtcIsac_kQMeanGain2Q12[144] = { - 1760, 1525, 1285, 1747, 1671, 1393, 1843, 1826, 1555, 1843, 1784, 1606, 1843, 1843, 1711, 1843, - 1843, 1814, 1389, 1275, 1040, 1564, 1414, 1252, 1610, 1495, 1343, 1753, 1592, 1405, 1804, 1720, - 1475, 1843, 1814, 1581, 1208, 1061, 856, 1349, 1148, 994, 1390, 1253, 1111, 1495, 1343, 1178, - 1770, 1465, 1234, 1814, 1581, 1342, 1040, 793, 713, 1053, 895, 737, 1128, 1003, 861, 1277, - 1094, 981, 1475, 1192, 1019, 1581, 1342, 1098, 855, 570, 483, 833, 648, 540, 948, 744, - 572, 1009, 844, 636, 1234, 934, 685, 1342, 1217, 984, 537, 318, 124, 603, 423, 350, - 687, 479, 322, 791, 581, 430, 987, 671, 488, 1098, 849, 597, 283, 27, 0, 397, - 222, 38, 513, 271, 124, 624, 325, 157, 737, 484, 233, 849, 597, 343, 27, 0, - 0, 141, 0, 0, 256, 69, 0, 370, 87, 0, 484, 229, 0, 597, 343, 87}; - -const int16_t WebRtcIsac_kQMeanGain3Q12[144] = { - 1843, 1843, 1711, 1843, 1818, 1606, 1843, 1827, 1511, 1814, 1639, 1393, 1760, 1525, 1285, 1656, - 1419, 1176, 1835, 1718, 1475, 1841, 1650, 1387, 1648, 1498, 1287, 1600, 1411, 1176, 1522, 1299, - 1040, 1419, 1176, 928, 1773, 1461, 1128, 1532, 1355, 1202, 1429, 1260, 1115, 1398, 1151, 1025, - 1172, 1080, 790, 1176, 928, 677, 1475, 1147, 1019, 1276, 1096, 922, 1214, 1010, 901, 1057, - 893, 800, 1040, 796, 734, 928, 677, 424, 1137, 897, 753, 1120, 830, 710, 875, 751, - 601, 795, 642, 583, 790, 544, 475, 677, 474, 140, 987, 750, 482, 697, 573, 450, - 691, 487, 303, 661, 394, 332, 537, 303, 220, 424, 168, 0, 737, 484, 229, 624, - 348, 153, 441, 261, 136, 397, 166, 51, 283, 27, 0, 168, 0, 0, 484, 229, - 0, 370, 57, 0, 256, 43, 0, 141, 0, 0, 27, 0, 0, 0, 0, 0}; - - -const int16_t WebRtcIsac_kQMeanGain4Q12[144] = { - 1843, 1843, 1843, 1843, 1841, 1843, 1500, 1821, 1843, 1222, 1434, 1656, 843, 1092, 1336, 504, - 757, 1007, 1843, 1843, 1843, 1838, 1791, 1843, 1265, 1505, 1599, 965, 1219, 1425, 730, 821, - 1092, 249, 504, 757, 1783, 1819, 1843, 1351, 1567, 1727, 1096, 1268, 1409, 805, 961, 1131, - 444, 670, 843, 0, 249, 504, 1425, 1655, 1743, 1096, 1324, 1448, 822, 1019, 1199, 490, - 704, 867, 81, 450, 555, 0, 0, 249, 1247, 1428, 1530, 881, 1073, 1283, 610, 759, - 939, 278, 464, 645, 0, 200, 270, 0, 0, 0, 935, 1163, 1410, 528, 790, 1068, - 377, 499, 717, 173, 240, 274, 0, 43, 62, 0, 0, 0, 684, 935, 1182, 343, - 551, 735, 161, 262, 423, 0, 55, 27, 0, 0, 0, 0, 0, 0, 430, 684, - 935, 87, 377, 597, 0, 46, 256, 0, 0, 0, 0, 0, 0, 0, 0, 0}; diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/pitch_gain_tables.h b/webrtc/modules/audio_coding/codecs/isac/main/source/pitch_gain_tables.h deleted file mode 100644 index 145fd4e..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/pitch_gain_tables.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -/* - * pitch_gain_tables.h - * - * This file contains tables for the pitch filter side-info in the entropy - * coder. - * - */ - -#ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_PITCH_GAIN_TABLES_H_ -#define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_PITCH_GAIN_TABLES_H_ - -#include - -/* header file for coding tables for the pitch filter side-info in the entropy - * coder */ -/********************* Pitch Filter Gain Coefficient Tables - * ************************/ -/* cdf for quantized pitch filter gains */ -extern const uint16_t WebRtcIsac_kQPitchGainCdf[255]; - -/* index limits and ranges */ -extern const int16_t WebRtcIsac_kIndexLowerLimitGain[3]; - -extern const int16_t WebRtcIsac_kIndexUpperLimitGain[3]; -extern const uint16_t WebRtcIsac_kIndexMultsGain[2]; - -/* mean values of pitch filter gains */ -//(Y) -extern const int16_t WebRtcIsac_kQMeanGain1Q12[144]; -extern const int16_t WebRtcIsac_kQMeanGain2Q12[144]; -extern const int16_t WebRtcIsac_kQMeanGain3Q12[144]; -extern const int16_t WebRtcIsac_kQMeanGain4Q12[144]; -//(Y) - -/* size of cdf table */ -extern const uint16_t WebRtcIsac_kQCdfTableSizeGain[1]; - -#endif /* MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_PITCH_GAIN_TABLES_H_ */ diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/pitch_lag_tables.c b/webrtc/modules/audio_coding/codecs/isac/main/source/pitch_lag_tables.c deleted file mode 100644 index 57d1202..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/pitch_lag_tables.c +++ /dev/null @@ -1,277 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "modules/audio_coding/codecs/isac/main/source/pitch_lag_tables.h" -#include "modules/audio_coding/codecs/isac/main/source/settings.h" - -/* header file for coding tables for the pitch filter side-info in the entropy coder */ -/********************* Pitch Filter Gain Coefficient Tables ************************/ - -/* tables for use with small pitch gain */ - -/* cdf for quantized pitch filter lags */ -const uint16_t WebRtcIsac_kQPitchLagCdf1Lo[127] = { - 0, 134, 336, 549, 778, 998, 1264, 1512, 1777, 2070, - 2423, 2794, 3051, 3361, 3708, 3979, 4315, 4610, 4933, 5269, - 5575, 5896, 6155, 6480, 6816, 7129, 7477, 7764, 8061, 8358, - 8718, 9020, 9390, 9783, 10177, 10543, 10885, 11342, 11795, 12213, - 12680, 13096, 13524, 13919, 14436, 14903, 15349, 15795, 16267, 16734, - 17266, 17697, 18130, 18632, 19080, 19447, 19884, 20315, 20735, 21288, - 21764, 22264, 22723, 23193, 23680, 24111, 24557, 25022, 25537, 26082, - 26543, 27090, 27620, 28139, 28652, 29149, 29634, 30175, 30692, 31273, - 31866, 32506, 33059, 33650, 34296, 34955, 35629, 36295, 36967, 37726, - 38559, 39458, 40364, 41293, 42256, 43215, 44231, 45253, 46274, 47359, - 48482, 49678, 50810, 51853, 53016, 54148, 55235, 56263, 57282, 58363, - 59288, 60179, 61076, 61806, 62474, 63129, 63656, 64160, 64533, 64856, - 65152, 65535, 65535, 65535, 65535, 65535, 65535}; - -const uint16_t WebRtcIsac_kQPitchLagCdf2Lo[20] = { - 0, 429, 3558, 5861, 8558, 11639, 15210, 19502, 24773, 31983, - 42602, 48567, 52601, 55676, 58160, 60172, 61889, 63235, 65383, 65535}; - -const uint16_t WebRtcIsac_kQPitchLagCdf3Lo[2] = { - 0, 65535}; - -const uint16_t WebRtcIsac_kQPitchLagCdf4Lo[10] = { - 0, 2966, 6368, 11182, 19431, 37793, 48532, 55353, 60626, 65535}; - -const uint16_t *WebRtcIsac_kQPitchLagCdfPtrLo[4] = {WebRtcIsac_kQPitchLagCdf1Lo, WebRtcIsac_kQPitchLagCdf2Lo, WebRtcIsac_kQPitchLagCdf3Lo, WebRtcIsac_kQPitchLagCdf4Lo}; - -/* size of first cdf table */ -const uint16_t WebRtcIsac_kQPitchLagCdfSizeLo[1] = {128}; - -/* index limits and ranges */ -const int16_t WebRtcIsac_kQIndexLowerLimitLagLo[4] = { --140, -9, 0, -4}; - -const int16_t WebRtcIsac_kQIndexUpperLimitLagLo[4] = { --20, 9, 0, 4}; - -/* initial index for arithmetic decoder */ -const uint16_t WebRtcIsac_kQInitIndexLagLo[3] = { - 10, 1, 5}; - -/* mean values of pitch filter lags */ -const double WebRtcIsac_kQMeanLag2Lo[19] = { --17.21385070, -15.82678944, -14.07123081, -12.03003877, -10.01311864, -8.00794627, -5.91162987, -3.89231876, -1.90220980, -0.01879275, - 1.89144232, 3.88123171, 5.92146992, 7.96435361, 9.98923648, 11.98266347, 13.96101002, 15.74855713, 17.10976611}; - -const double WebRtcIsac_kQMeanLag3Lo[1] = { - 0.00000000}; - -const double WebRtcIsac_kQMeanLag4Lo[9] = { --7.76246496, -5.92083980, -3.94095226, -1.89502305, 0.03724681, 1.93054221, 3.96443467, 5.91726366, 7.78434291}; - -const double WebRtcIsac_kQPitchLagStepsizeLo = 2.000000; - - -/* tables for use with medium pitch gain */ - -/* cdf for quantized pitch filter lags */ -const uint16_t WebRtcIsac_kQPitchLagCdf1Mid[255] = { - 0, 28, 61, 88, 121, 149, 233, 331, 475, 559, - 624, 661, 689, 712, 745, 791, 815, 843, 866, 922, - 959, 1024, 1061, 1117, 1178, 1238, 1280, 1350, 1453, 1513, - 1564, 1625, 1671, 1741, 1788, 1904, 2072, 2421, 2626, 2770, - 2840, 2900, 2942, 3012, 3068, 3115, 3147, 3194, 3254, 3319, - 3366, 3520, 3678, 3780, 3850, 3911, 3957, 4032, 4106, 4185, - 4292, 4474, 4683, 4842, 5019, 5191, 5321, 5428, 5540, 5675, - 5763, 5847, 5959, 6127, 6304, 6564, 6839, 7090, 7263, 7421, - 7556, 7728, 7872, 7984, 8142, 8361, 8580, 8743, 8938, 9227, - 9409, 9539, 9674, 9795, 9930, 10060, 10177, 10382, 10614, 10861, - 11038, 11271, 11415, 11629, 11792, 12044, 12193, 12416, 12574, 12821, - 13007, 13235, 13445, 13654, 13901, 14134, 14488, 15000, 15703, 16285, - 16504, 16797, 17086, 17328, 17579, 17807, 17998, 18268, 18538, 18836, - 19087, 19274, 19474, 19716, 19935, 20270, 20833, 21303, 21532, 21741, - 21978, 22207, 22523, 22770, 23054, 23613, 23943, 24204, 24399, 24651, - 24832, 25074, 25270, 25549, 25759, 26015, 26150, 26424, 26713, 27048, - 27342, 27504, 27681, 27854, 28021, 28207, 28412, 28664, 28859, 29064, - 29278, 29548, 29748, 30107, 30377, 30656, 30856, 31164, 31452, 31755, - 32011, 32328, 32626, 32919, 33319, 33789, 34329, 34925, 35396, 35973, - 36443, 36964, 37551, 38156, 38724, 39357, 40023, 40908, 41587, 42602, - 43924, 45037, 45810, 46597, 47421, 48291, 49092, 50051, 51448, 52719, - 53440, 54241, 54944, 55977, 56676, 57299, 57872, 58389, 59059, 59688, - 60237, 60782, 61094, 61573, 61890, 62290, 62658, 63030, 63217, 63454, - 63622, 63882, 64003, 64273, 64427, 64529, 64581, 64697, 64758, 64902, - 65414, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, - 65535, 65535, 65535, 65535, 65535}; - -const uint16_t WebRtcIsac_kQPitchLagCdf2Mid[36] = { - 0, 71, 335, 581, 836, 1039, 1323, 1795, 2258, 2608, - 3005, 3591, 4243, 5344, 7163, 10583, 16848, 28078, 49448, 57007, - 60357, 61850, 62837, 63437, 63872, 64188, 64377, 64614, 64774, 64949, - 65039, 65115, 65223, 65360, 65474, 65535}; - -const uint16_t WebRtcIsac_kQPitchLagCdf3Mid[2] = { - 0, 65535}; - -const uint16_t WebRtcIsac_kQPitchLagCdf4Mid[20] = { - 0, 28, 246, 459, 667, 1045, 1523, 2337, 4337, 11347, - 44231, 56709, 60781, 62243, 63161, 63969, 64608, 65062, 65502, 65535}; - -const uint16_t *WebRtcIsac_kQPitchLagCdfPtrMid[4] = {WebRtcIsac_kQPitchLagCdf1Mid, WebRtcIsac_kQPitchLagCdf2Mid, WebRtcIsac_kQPitchLagCdf3Mid, WebRtcIsac_kQPitchLagCdf4Mid}; - -/* size of first cdf table */ -const uint16_t WebRtcIsac_kQPitchLagCdfSizeMid[1] = {256}; - -/* index limits and ranges */ -const int16_t WebRtcIsac_kQIndexLowerLimitLagMid[4] = { --280, -17, 0, -9}; - -const int16_t WebRtcIsac_kQIndexUpperLimitLagMid[4] = { --40, 17, 0, 9}; - -/* initial index for arithmetic decoder */ -const uint16_t WebRtcIsac_kQInitIndexLagMid[3] = { - 18, 1, 10}; - -/* mean values of pitch filter lags */ -const double WebRtcIsac_kQMeanLag2Mid[35] = { --16.89183900, -15.86949778, -15.05476653, -14.00664348, -13.02793036, -12.07324237, -11.00542532, -10.11250602, -8.90792971, -8.02474753, --7.00426767, -5.94055287, -4.98251338, -3.91053158, -2.98820425, -1.93524245, -0.92978085, -0.01722509, 0.91317387, 1.92973955, - 2.96908851, 3.93728974, 4.96308471, 5.92244151, 7.08673497, 8.00993708, 9.04656316, 9.98538742, 10.97851694, 11.94772884, - 13.02426166, 14.00039951, 15.01347042, 15.80758023, 16.94086895}; - -const double WebRtcIsac_kQMeanLag3Mid[1] = { - 0.00000000}; - -const double WebRtcIsac_kQMeanLag4Mid[19] = { --8.60409403, -7.89198395, -7.03450280, -5.86260421, -4.93822322, -3.93078706, -2.91302322, -1.91824007, -0.87003282, 0.02822649, - 0.89951758, 1.87495484, 2.91802604, 3.96874074, 5.06571703, 5.93618227, 7.00520185, 7.88497726, 8.64160364}; - -const double WebRtcIsac_kQPitchLagStepsizeMid = 1.000000; - - -/* tables for use with large pitch gain */ - -/* cdf for quantized pitch filter lags */ -const uint16_t WebRtcIsac_kQPitchLagCdf1Hi[511] = { - 0, 7, 18, 33, 69, 105, 156, 228, 315, 612, - 680, 691, 709, 724, 735, 738, 742, 746, 749, 753, - 756, 760, 764, 774, 782, 785, 789, 796, 800, 803, - 807, 814, 818, 822, 829, 832, 847, 854, 858, 869, - 876, 883, 898, 908, 934, 977, 1010, 1050, 1060, 1064, - 1075, 1078, 1086, 1089, 1093, 1104, 1111, 1122, 1133, 1136, - 1151, 1162, 1183, 1209, 1252, 1281, 1339, 1364, 1386, 1401, - 1411, 1415, 1426, 1430, 1433, 1440, 1448, 1455, 1462, 1477, - 1487, 1495, 1502, 1506, 1509, 1516, 1524, 1531, 1535, 1542, - 1553, 1556, 1578, 1589, 1611, 1625, 1639, 1643, 1654, 1665, - 1672, 1687, 1694, 1705, 1708, 1719, 1730, 1744, 1752, 1759, - 1791, 1795, 1820, 1867, 1886, 1915, 1936, 1943, 1965, 1987, - 2041, 2099, 2161, 2175, 2200, 2211, 2226, 2233, 2244, 2251, - 2266, 2280, 2287, 2298, 2309, 2316, 2331, 2342, 2356, 2378, - 2403, 2418, 2447, 2497, 2544, 2602, 2863, 2895, 2903, 2935, - 2950, 2971, 3004, 3011, 3018, 3029, 3040, 3062, 3087, 3127, - 3152, 3170, 3199, 3243, 3293, 3322, 3340, 3377, 3402, 3427, - 3474, 3518, 3543, 3579, 3601, 3637, 3659, 3706, 3731, 3760, - 3818, 3847, 3869, 3901, 3920, 3952, 4068, 4169, 4220, 4271, - 4524, 4571, 4604, 4632, 4672, 4730, 4777, 4806, 4857, 4904, - 4951, 5002, 5031, 5060, 5107, 5150, 5212, 5266, 5331, 5382, - 5432, 5490, 5544, 5610, 5700, 5762, 5812, 5874, 5972, 6022, - 6091, 6163, 6232, 6305, 6402, 6540, 6685, 6880, 7090, 7271, - 7379, 7452, 7542, 7625, 7687, 7770, 7843, 7911, 7966, 8024, - 8096, 8190, 8252, 8320, 8411, 8501, 8585, 8639, 8751, 8842, - 8918, 8986, 9066, 9127, 9203, 9269, 9345, 9406, 9464, 9536, - 9612, 9667, 9735, 9844, 9931, 10036, 10119, 10199, 10260, 10358, - 10441, 10514, 10666, 10734, 10872, 10951, 11053, 11125, 11223, 11324, - 11516, 11664, 11737, 11816, 11892, 12008, 12120, 12200, 12280, 12392, - 12490, 12576, 12685, 12812, 12917, 13003, 13108, 13210, 13300, 13384, - 13470, 13579, 13673, 13771, 13879, 13999, 14136, 14201, 14368, 14614, - 14759, 14867, 14958, 15030, 15121, 15189, 15280, 15385, 15461, 15555, - 15653, 15768, 15884, 15971, 16069, 16145, 16210, 16279, 16380, 16463, - 16539, 16615, 16688, 16818, 16919, 17017, 18041, 18338, 18523, 18649, - 18790, 18917, 19047, 19167, 19315, 19460, 19601, 19731, 19858, 20068, - 20173, 20318, 20466, 20625, 20741, 20911, 21045, 21201, 21396, 21588, - 21816, 22022, 22305, 22547, 22786, 23072, 23322, 23600, 23879, 24168, - 24433, 24769, 25120, 25511, 25895, 26289, 26792, 27219, 27683, 28077, - 28566, 29094, 29546, 29977, 30491, 30991, 31573, 32105, 32594, 33173, - 33788, 34497, 35181, 35833, 36488, 37255, 37921, 38645, 39275, 39894, - 40505, 41167, 41790, 42431, 43096, 43723, 44385, 45134, 45858, 46607, - 47349, 48091, 48768, 49405, 49955, 50555, 51167, 51985, 52611, 53078, - 53494, 53965, 54435, 54996, 55601, 56125, 56563, 56838, 57244, 57566, - 57967, 58297, 58771, 59093, 59419, 59647, 59886, 60143, 60461, 60693, - 60917, 61170, 61416, 61634, 61891, 62122, 62310, 62455, 62632, 62839, - 63103, 63436, 63639, 63805, 63906, 64015, 64192, 64355, 64475, 64558, - 64663, 64742, 64811, 64865, 64916, 64956, 64981, 65025, 65068, 65115, - 65195, 65314, 65419, 65535, 65535, 65535, 65535, 65535, 65535, 65535, - 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, - 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, - 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, - 65535}; - -const uint16_t WebRtcIsac_kQPitchLagCdf2Hi[68] = { - 0, 7, 11, 22, 37, 52, 56, 59, 81, 85, - 89, 96, 115, 130, 137, 152, 170, 181, 193, 200, - 207, 233, 237, 259, 289, 318, 363, 433, 592, 992, - 1607, 3062, 6149, 12206, 25522, 48368, 58223, 61918, 63640, 64584, - 64943, 65098, 65206, 65268, 65294, 65335, 65350, 65372, 65387, 65402, - 65413, 65420, 65428, 65435, 65439, 65450, 65454, 65468, 65472, 65476, - 65483, 65491, 65498, 65505, 65516, 65520, 65528, 65535}; - -const uint16_t WebRtcIsac_kQPitchLagCdf3Hi[2] = { - 0, 65535}; - -const uint16_t WebRtcIsac_kQPitchLagCdf4Hi[35] = { - 0, 7, 19, 30, 41, 48, 63, 74, 82, 96, - 122, 152, 215, 330, 701, 2611, 10931, 48106, 61177, 64341, - 65112, 65238, 65309, 65338, 65364, 65379, 65401, 65427, 65453, 65465, - 65476, 65490, 65509, 65528, 65535}; - -const uint16_t *WebRtcIsac_kQPitchLagCdfPtrHi[4] = {WebRtcIsac_kQPitchLagCdf1Hi, WebRtcIsac_kQPitchLagCdf2Hi, WebRtcIsac_kQPitchLagCdf3Hi, WebRtcIsac_kQPitchLagCdf4Hi}; - -/* size of first cdf table */ -const uint16_t WebRtcIsac_kQPitchLagCdfSizeHi[1] = {512}; - -/* index limits and ranges */ -const int16_t WebRtcIsac_kQindexLowerLimitLagHi[4] = { --552, -34, 0, -16}; - -const int16_t WebRtcIsac_kQindexUpperLimitLagHi[4] = { --80, 32, 0, 17}; - -/* initial index for arithmetic decoder */ -const uint16_t WebRtcIsac_kQInitIndexLagHi[3] = { - 34, 1, 18}; - -/* mean values of pitch filter lags */ -const double WebRtcIsac_kQMeanLag2Hi[67] = { --17.07263295, -16.50000000, -15.83966081, -15.55613708, -14.96948007, -14.50000000, -14.00000000, -13.48377986, -13.00000000, -12.50000000, --11.93199636, -11.44530414, -11.04197641, -10.39910301, -10.15202337, -9.51322461, -8.93357741, -8.46456632, -8.10270672, -7.53751847, --6.98686404, -6.50000000, -6.08463150, -5.46872991, -5.00864717, -4.50163760, -4.01382410, -3.43856708, -2.96898001, -2.46554810, --1.96861004, -1.47106701, -0.97197237, -0.46561654, -0.00531409, 0.45767857, 0.96777907, 1.47507903, 1.97740425, 2.46695420, - 3.00695774, 3.47167185, 4.02712538, 4.49280007, 5.01087640, 5.48191963, 6.04916550, 6.51511058, 6.97297819, 7.46565499, - 8.01489405, 8.39912001, 8.91819757, 9.50000000, 10.11654065, 10.50000000, 11.03712583, 11.50000000, 12.00000000, 12.38964346, - 12.89466127, 13.43657881, 13.96013840, 14.46279912, 15.00000000, 15.39412269, 15.96662441}; - -const double WebRtcIsac_kQMeanLag3Hi[1] = { - 0.00000000}; - -const double WebRtcIsac_kQMeanLag4Hi[34] = { --7.98331221, -7.47988769, -7.03626557, -6.52708003, -6.06982173, -5.51856292, -5.05827033, -4.45909878, -3.99125864, -3.45308135, --3.02328139, -2.47297273, -1.94341995, -1.44699056, -0.93612243, -0.43012406, 0.01120357, 0.44054812, 0.93199883, 1.45669587, - 1.97218322, 2.50187419, 2.98748690, 3.49343202, 4.01660147, 4.50984306, 5.01402683, 5.58936797, 5.91787793, 6.59998900, - 6.85034315, 7.53503316, 7.87711194, 8.53631648}; - -const double WebRtcIsac_kQPitchLagStepsizeHi = 0.500000; - -/* transform matrix */ -const double WebRtcIsac_kTransform[4][4] = { -{-0.50000000, -0.50000000, -0.50000000, -0.50000000}, -{ 0.67082039, 0.22360680, -0.22360680, -0.67082039}, -{ 0.50000000, -0.50000000, -0.50000000, 0.50000000}, -{ 0.22360680, -0.67082039, 0.67082039, -0.22360680}}; - -/* transpose transform matrix */ -const double WebRtcIsac_kTransformTranspose[4][4] = { -{-0.50000000, 0.67082039, 0.50000000, 0.22360680}, -{-0.50000000, 0.22360680, -0.50000000, -0.67082039}, -{-0.50000000, -0.22360680, -0.50000000, 0.67082039}, -{-0.50000000, -0.67082039, 0.50000000, -0.22360680}}; - diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/pitch_lag_tables.h b/webrtc/modules/audio_coding/codecs/isac/main/source/pitch_lag_tables.h deleted file mode 100644 index b48e358..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/pitch_lag_tables.h +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -/* - * pitch_lag_tables.h - * - * This file contains tables for the pitch filter side-info in the entropy - * coder. - * - */ - -#ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_PITCH_LAG_TABLES_H_ -#define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_PITCH_LAG_TABLES_H_ - -#include - -/* header file for coding tables for the pitch filter side-info in the entropy - * coder */ -/********************* Pitch Filter Lag Coefficient Tables - * ************************/ - -/* tables for use with small pitch gain */ - -/* cdfs for quantized pitch lags */ -extern const uint16_t WebRtcIsac_kQPitchLagCdf1Lo[127]; -extern const uint16_t WebRtcIsac_kQPitchLagCdf2Lo[20]; -extern const uint16_t WebRtcIsac_kQPitchLagCdf3Lo[2]; -extern const uint16_t WebRtcIsac_kQPitchLagCdf4Lo[10]; - -extern const uint16_t* WebRtcIsac_kQPitchLagCdfPtrLo[4]; - -/* size of first cdf table */ -extern const uint16_t WebRtcIsac_kQPitchLagCdfSizeLo[1]; - -/* index limits and ranges */ -extern const int16_t WebRtcIsac_kQIndexLowerLimitLagLo[4]; -extern const int16_t WebRtcIsac_kQIndexUpperLimitLagLo[4]; - -/* initial index for arithmetic decoder */ -extern const uint16_t WebRtcIsac_kQInitIndexLagLo[3]; - -/* mean values of pitch filter lags */ -extern const double WebRtcIsac_kQMeanLag2Lo[19]; -extern const double WebRtcIsac_kQMeanLag3Lo[1]; -extern const double WebRtcIsac_kQMeanLag4Lo[9]; - -extern const double WebRtcIsac_kQPitchLagStepsizeLo; - -/* tables for use with medium pitch gain */ - -/* cdfs for quantized pitch lags */ -extern const uint16_t WebRtcIsac_kQPitchLagCdf1Mid[255]; -extern const uint16_t WebRtcIsac_kQPitchLagCdf2Mid[36]; -extern const uint16_t WebRtcIsac_kQPitchLagCdf3Mid[2]; -extern const uint16_t WebRtcIsac_kQPitchLagCdf4Mid[20]; - -extern const uint16_t* WebRtcIsac_kQPitchLagCdfPtrMid[4]; - -/* size of first cdf table */ -extern const uint16_t WebRtcIsac_kQPitchLagCdfSizeMid[1]; - -/* index limits and ranges */ -extern const int16_t WebRtcIsac_kQIndexLowerLimitLagMid[4]; -extern const int16_t WebRtcIsac_kQIndexUpperLimitLagMid[4]; - -/* initial index for arithmetic decoder */ -extern const uint16_t WebRtcIsac_kQInitIndexLagMid[3]; - -/* mean values of pitch filter lags */ -extern const double WebRtcIsac_kQMeanLag2Mid[35]; -extern const double WebRtcIsac_kQMeanLag3Mid[1]; -extern const double WebRtcIsac_kQMeanLag4Mid[19]; - -extern const double WebRtcIsac_kQPitchLagStepsizeMid; - -/* tables for use with large pitch gain */ - -/* cdfs for quantized pitch lags */ -extern const uint16_t WebRtcIsac_kQPitchLagCdf1Hi[511]; -extern const uint16_t WebRtcIsac_kQPitchLagCdf2Hi[68]; -extern const uint16_t WebRtcIsac_kQPitchLagCdf3Hi[2]; -extern const uint16_t WebRtcIsac_kQPitchLagCdf4Hi[35]; - -extern const uint16_t* WebRtcIsac_kQPitchLagCdfPtrHi[4]; - -/* size of first cdf table */ -extern const uint16_t WebRtcIsac_kQPitchLagCdfSizeHi[1]; - -/* index limits and ranges */ -extern const int16_t WebRtcIsac_kQindexLowerLimitLagHi[4]; -extern const int16_t WebRtcIsac_kQindexUpperLimitLagHi[4]; - -/* initial index for arithmetic decoder */ -extern const uint16_t WebRtcIsac_kQInitIndexLagHi[3]; - -/* mean values of pitch filter lags */ -extern const double WebRtcIsac_kQMeanLag2Hi[67]; -extern const double WebRtcIsac_kQMeanLag3Hi[1]; -extern const double WebRtcIsac_kQMeanLag4Hi[34]; - -extern const double WebRtcIsac_kQPitchLagStepsizeHi; - -/* transform matrix */ -extern const double WebRtcIsac_kTransform[4][4]; - -/* transpose transform matrix */ -extern const double WebRtcIsac_kTransformTranspose[4][4]; - -#endif /* MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_PITCH_LAG_TABLES_H_ */ diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/spectrum_ar_model_tables.c b/webrtc/modules/audio_coding/codecs/isac/main/source/spectrum_ar_model_tables.c deleted file mode 100644 index 839d5d4..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/spectrum_ar_model_tables.c +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "modules/audio_coding/codecs/isac/main/source/spectrum_ar_model_tables.h" -#include "modules/audio_coding/codecs/isac/main/source/settings.h" - -/********************* AR Coefficient Tables ************************/ -/* cdf for quantized reflection coefficient 1 */ -const uint16_t WebRtcIsac_kQArRc1Cdf[NUM_AR_RC_QUANT_BAUNDARY] = { - 0, 2, 4, 129, 7707, 57485, 65495, 65527, 65529, 65531, - 65533, 65535}; - -/* cdf for quantized reflection coefficient 2 */ -const uint16_t WebRtcIsac_kQArRc2Cdf[NUM_AR_RC_QUANT_BAUNDARY] = { - 0, 2, 4, 7, 531, 25298, 64525, 65526, 65529, 65531, - 65533, 65535}; - -/* cdf for quantized reflection coefficient 3 */ -const uint16_t WebRtcIsac_kQArRc3Cdf[NUM_AR_RC_QUANT_BAUNDARY] = { - 0, 2, 4, 6, 620, 22898, 64843, 65527, 65529, 65531, - 65533, 65535}; - -/* cdf for quantized reflection coefficient 4 */ -const uint16_t WebRtcIsac_kQArRc4Cdf[NUM_AR_RC_QUANT_BAUNDARY] = { - 0, 2, 4, 6, 35, 10034, 60733, 65506, 65529, 65531, - 65533, 65535}; - -/* cdf for quantized reflection coefficient 5 */ -const uint16_t WebRtcIsac_kQArRc5Cdf[NUM_AR_RC_QUANT_BAUNDARY] = { - 0, 2, 4, 6, 36, 7567, 56727, 65385, 65529, 65531, - 65533, 65535}; - -/* cdf for quantized reflection coefficient 6 */ -const uint16_t WebRtcIsac_kQArRc6Cdf[NUM_AR_RC_QUANT_BAUNDARY] = { - 0, 2, 4, 6, 14, 6579, 57360, 65409, 65529, 65531, - 65533, 65535}; - -/* representation levels for quantized reflection coefficient 1 */ -const int16_t WebRtcIsac_kQArRc1Levels[NUM_AR_RC_QUANT_BAUNDARY - 1] = { - -32104, -29007, -23202, -15496, -9279, -2577, 5934, 17535, 24512, 29503, 32104 -}; - -/* representation levels for quantized reflection coefficient 2 */ -const int16_t WebRtcIsac_kQArRc2Levels[NUM_AR_RC_QUANT_BAUNDARY - 1] = { - -32104, -29503, -23494, -15261, -7309, -1399, 6158, 16381, 24512, 29503, 32104 -}; - -/* representation levels for quantized reflection coefficient 3 */ -const int16_t WebRtcIsac_kQArRc3Levels[NUM_AR_RC_QUANT_BAUNDARY - 1] = { --32104, -29503, -23157, -15186, -7347, -1359, 5829, 17535, 24512, 29503, 32104 -}; - -/* representation levels for quantized reflection coefficient 4 */ -const int16_t WebRtcIsac_kQArRc4Levels[NUM_AR_RC_QUANT_BAUNDARY - 1] = { --32104, -29503, -24512, -15362, -6665, -342, 6596, 14585, 24512, 29503, 32104 -}; - -/* representation levels for quantized reflection coefficient 5 */ -const int16_t WebRtcIsac_kQArRc5Levels[NUM_AR_RC_QUANT_BAUNDARY - 1] = { --32104, -29503, -24512, -15005, -6564, -106, 7123, 14920, 24512, 29503, 32104 -}; - -/* representation levels for quantized reflection coefficient 6 */ -const int16_t WebRtcIsac_kQArRc6Levels[NUM_AR_RC_QUANT_BAUNDARY - 1] = { --32104, -29503, -24512, -15096, -6656, -37, 7036, 14847, 24512, 29503, 32104 -}; - -/* quantization boundary levels for reflection coefficients */ -const int16_t WebRtcIsac_kQArBoundaryLevels[NUM_AR_RC_QUANT_BAUNDARY] = { --32768, -31441, -27566, -21458, -13612, -4663, 4663, 13612, 21458, 27566, 31441, -32767 -}; - -/* initial index for AR reflection coefficient quantizer and cdf table search */ -const uint16_t WebRtcIsac_kQArRcInitIndex[6] = { - 5, 5, 5, 5, 5, 5}; - -/* pointers to AR cdf tables */ -const uint16_t *WebRtcIsac_kQArRcCdfPtr[AR_ORDER] = { - WebRtcIsac_kQArRc1Cdf, WebRtcIsac_kQArRc2Cdf, WebRtcIsac_kQArRc3Cdf, - WebRtcIsac_kQArRc4Cdf, WebRtcIsac_kQArRc5Cdf, WebRtcIsac_kQArRc6Cdf -}; - -/* pointers to AR representation levels tables */ -const int16_t *WebRtcIsac_kQArRcLevelsPtr[AR_ORDER] = { - WebRtcIsac_kQArRc1Levels, WebRtcIsac_kQArRc2Levels, WebRtcIsac_kQArRc3Levels, - WebRtcIsac_kQArRc4Levels, WebRtcIsac_kQArRc5Levels, WebRtcIsac_kQArRc6Levels -}; - - -/******************** GAIN Coefficient Tables ***********************/ -/* cdf for Gain coefficient */ -const uint16_t WebRtcIsac_kQGainCdf[19] = { - 0, 2, 4, 6, 8, 10, 12, 14, 16, 1172, - 11119, 29411, 51699, 64445, 65527, 65529, 65531, 65533, 65535}; - -/* representation levels for quantized squared Gain coefficient */ -const int32_t WebRtcIsac_kQGain2Levels[18] = { -// 17, 28, 46, 76, 128, 215, 364, 709, 1268, 1960, 3405, 6078, 11286, 17827, 51918, 134498, 487432, 2048000}; - 128, 128, 128, 128, 128, 215, 364, 709, 1268, 1960, 3405, 6078, 11286, 17827, 51918, 134498, 487432, 2048000}; -/* quantization boundary levels for squared Gain coefficient */ -const int32_t WebRtcIsac_kQGain2BoundaryLevels[19] = { -0, 21, 35, 59, 99, 166, 280, 475, 815, 1414, 2495, 4505, 8397, 16405, 34431, 81359, 240497, 921600, 0x7FFFFFFF}; - -/* pointers to Gain cdf table */ -const uint16_t *WebRtcIsac_kQGainCdf_ptr[1] = {WebRtcIsac_kQGainCdf}; - -/* Gain initial index for gain quantizer and cdf table search */ -const uint16_t WebRtcIsac_kQGainInitIndex[1] = {11}; - -/************************* Cosine Tables ****************************/ -/* Cosine table */ -const int16_t WebRtcIsac_kCos[6][60] = { -{512, 512, 511, 510, 508, 507, 505, 502, 499, 496, 493, 489, 485, 480, 476, 470, 465, 459, 453, 447, -440, 433, 426, 418, 410, 402, 394, 385, 376, 367, 357, 348, 338, 327, 317, 306, 295, 284, 273, 262, -250, 238, 226, 214, 202, 190, 177, 165, 152, 139, 126, 113, 100, 87, 73, 60, 47, 33, 20, 7}, -{512, 510, 508, 503, 498, 491, 483, 473, 462, 450, 437, 422, 406, 389, 371, 352, 333, 312, 290, 268, -244, 220, 196, 171, 145, 120, 93, 67, 40, 13, -13, -40, -67, -93, -120, -145, -171, -196, -220, -244, --268, -290, -312, -333, -352, -371, -389, -406, -422, -437, -450, -462, -473, -483, -491, -498, -503, -508, -510, -512}, -{512, 508, 502, 493, 480, 465, 447, 426, 402, 376, 348, 317, 284, 250, 214, 177, 139, 100, 60, 20, --20, -60, -100, -139, -177, -214, -250, -284, -317, -348, -376, -402, -426, -447, -465, -480, -493, -502, -508, -512, --512, -508, -502, -493, -480, -465, -447, -426, -402, -376, -348, -317, -284, -250, -214, -177, -139, -100, -60, -20}, -{511, 506, 495, 478, 456, 429, 398, 362, 322, 279, 232, 183, 133, 80, 27, -27, -80, -133, -183, -232, --279, -322, -362, -398, -429, -456, -478, -495, -506, -511, -511, -506, -495, -478, -456, -429, -398, -362, -322, -279, --232, -183, -133, -80, -27, 27, 80, 133, 183, 232, 279, 322, 362, 398, 429, 456, 478, 495, 506, 511}, -{511, 502, 485, 459, 426, 385, 338, 284, 226, 165, 100, 33, -33, -100, -165, -226, -284, -338, -385, -426, --459, -485, -502, -511, -511, -502, -485, -459, -426, -385, -338, -284, -226, -165, -100, -33, 33, 100, 165, 226, -284, 338, 385, 426, 459, 485, 502, 511, 511, 502, 485, 459, 426, 385, 338, 284, 226, 165, 100, 33}, -{510, 498, 473, 437, 389, 333, 268, 196, 120, 40, -40, -120, -196, -268, -333, -389, -437, -473, -498, -510, --510, -498, -473, -437, -389, -333, -268, -196, -120, -40, 40, 120, 196, 268, 333, 389, 437, 473, 498, 510, -510, 498, 473, 437, 389, 333, 268, 196, 120, 40, -40, -120, -196, -268, -333, -389, -437, -473, -498, -510} -}; diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/spectrum_ar_model_tables.h b/webrtc/modules/audio_coding/codecs/isac/main/source/spectrum_ar_model_tables.h deleted file mode 100644 index d272be0..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/spectrum_ar_model_tables.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -/* - * spectrum_ar_model_tables.h - * - * This file contains definitions of tables with AR coefficients, - * Gain coefficients and cosine tables. - * - */ - -#ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_SPECTRUM_AR_MODEL_TABLES_H_ -#define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_SPECTRUM_AR_MODEL_TABLES_H_ - -#include "modules/audio_coding/codecs/isac/main/source/structs.h" - -#define NUM_AR_RC_QUANT_BAUNDARY 12 - -/********************* AR Coefficient Tables ************************/ -/* cdf for quantized reflection coefficient 1 */ -extern const uint16_t WebRtcIsac_kQArRc1Cdf[NUM_AR_RC_QUANT_BAUNDARY]; - -/* cdf for quantized reflection coefficient 2 */ -extern const uint16_t WebRtcIsac_kQArRc2Cdf[NUM_AR_RC_QUANT_BAUNDARY]; - -/* cdf for quantized reflection coefficient 3 */ -extern const uint16_t WebRtcIsac_kQArRc3Cdf[NUM_AR_RC_QUANT_BAUNDARY]; - -/* cdf for quantized reflection coefficient 4 */ -extern const uint16_t WebRtcIsac_kQArRc4Cdf[NUM_AR_RC_QUANT_BAUNDARY]; - -/* cdf for quantized reflection coefficient 5 */ -extern const uint16_t WebRtcIsac_kQArRc5Cdf[NUM_AR_RC_QUANT_BAUNDARY]; - -/* cdf for quantized reflection coefficient 6 */ -extern const uint16_t WebRtcIsac_kQArRc6Cdf[NUM_AR_RC_QUANT_BAUNDARY]; - -/* quantization boundary levels for reflection coefficients */ -extern const int16_t WebRtcIsac_kQArBoundaryLevels[NUM_AR_RC_QUANT_BAUNDARY]; - -/* initial indices for AR reflection coefficient quantizer and cdf table search - */ -extern const uint16_t WebRtcIsac_kQArRcInitIndex[AR_ORDER]; - -/* pointers to AR cdf tables */ -extern const uint16_t* WebRtcIsac_kQArRcCdfPtr[AR_ORDER]; - -/* pointers to AR representation levels tables */ -extern const int16_t* WebRtcIsac_kQArRcLevelsPtr[AR_ORDER]; - -/******************** GAIN Coefficient Tables ***********************/ -/* cdf for Gain coefficient */ -extern const uint16_t WebRtcIsac_kQGainCdf[19]; - -/* representation levels for quantized Gain coefficient */ -extern const int32_t WebRtcIsac_kQGain2Levels[18]; - -/* squared quantization boundary levels for Gain coefficient */ -extern const int32_t WebRtcIsac_kQGain2BoundaryLevels[19]; - -/* pointer to Gain cdf table */ -extern const uint16_t* WebRtcIsac_kQGainCdf_ptr[1]; - -/* Gain initial index for gain quantizer and cdf table search */ -extern const uint16_t WebRtcIsac_kQGainInitIndex[1]; - -/************************* Cosine Tables ****************************/ -/* Cosine table */ -extern const int16_t WebRtcIsac_kCos[6][60]; - -#endif /* MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_SPECTRUM_AR_MODEL_TABLES_H_ \ - */ diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/transform.c b/webrtc/modules/audio_coding/codecs/isac/main/source/transform.c deleted file mode 100644 index 082ad94..0000000 --- a/webrtc/modules/audio_coding/codecs/isac/main/source/transform.c +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include - -#include "modules/audio_coding/codecs/isac/main/source/settings.h" -#include "modules/audio_coding/codecs/isac/main/source/codec.h" -#include "modules/audio_coding/codecs/isac/main/source/os_specific_inline.h" -#include "modules/third_party/fft/fft.h" - -void WebRtcIsac_InitTransform(TransformTables* tables) { - int k; - double fact, phase; - - fact = PI / (FRAMESAMPLES_HALF); - phase = 0.0; - for (k = 0; k < FRAMESAMPLES_HALF; k++) { - tables->costab1[k] = cos(phase); - tables->sintab1[k] = sin(phase); - phase += fact; - } - - fact = PI * ((double) (FRAMESAMPLES_HALF - 1)) / ((double) FRAMESAMPLES_HALF); - phase = 0.5 * fact; - for (k = 0; k < FRAMESAMPLES_QUARTER; k++) { - tables->costab2[k] = cos(phase); - tables->sintab2[k] = sin(phase); - phase += fact; - } -} - -void WebRtcIsac_Time2Spec(const TransformTables* tables, - double* inre1, - double* inre2, - int16_t* outreQ7, - int16_t* outimQ7, - FFTstr* fftstr_obj) { - int k; - int dims[1]; - double tmp1r, tmp1i, xr, xi, yr, yi, fact; - double tmpre[FRAMESAMPLES_HALF], tmpim[FRAMESAMPLES_HALF]; - - - dims[0] = FRAMESAMPLES_HALF; - - - /* Multiply with complex exponentials and combine into one complex vector */ - fact = 0.5 / sqrt(FRAMESAMPLES_HALF); - for (k = 0; k < FRAMESAMPLES_HALF; k++) { - tmp1r = tables->costab1[k]; - tmp1i = tables->sintab1[k]; - tmpre[k] = (inre1[k] * tmp1r + inre2[k] * tmp1i) * fact; - tmpim[k] = (inre2[k] * tmp1r - inre1[k] * tmp1i) * fact; - } - - - /* Get DFT */ - WebRtcIsac_Fftns(1, dims, tmpre, tmpim, -1, 1.0, fftstr_obj); - - /* Use symmetry to separate into two complex vectors and center frames in time around zero */ - for (k = 0; k < FRAMESAMPLES_QUARTER; k++) { - xr = tmpre[k] + tmpre[FRAMESAMPLES_HALF - 1 - k]; - yi = -tmpre[k] + tmpre[FRAMESAMPLES_HALF - 1 - k]; - xi = tmpim[k] - tmpim[FRAMESAMPLES_HALF - 1 - k]; - yr = tmpim[k] + tmpim[FRAMESAMPLES_HALF - 1 - k]; - - tmp1r = tables->costab2[k]; - tmp1i = tables->sintab2[k]; - outreQ7[k] = (int16_t)WebRtcIsac_lrint((xr * tmp1r - xi * tmp1i) * 128.0); - outimQ7[k] = (int16_t)WebRtcIsac_lrint((xr * tmp1i + xi * tmp1r) * 128.0); - outreQ7[FRAMESAMPLES_HALF - 1 - k] = (int16_t)WebRtcIsac_lrint((-yr * tmp1i - yi * tmp1r) * 128.0); - outimQ7[FRAMESAMPLES_HALF - 1 - k] = (int16_t)WebRtcIsac_lrint((-yr * tmp1r + yi * tmp1i) * 128.0); - } -} - -void WebRtcIsac_Spec2time(const TransformTables* tables, - double* inre, - double* inim, - double* outre1, - double* outre2, - FFTstr* fftstr_obj) { - int k; - double tmp1r, tmp1i, xr, xi, yr, yi, fact; - - int dims; - - dims = FRAMESAMPLES_HALF; - - for (k = 0; k < FRAMESAMPLES_QUARTER; k++) { - /* Move zero in time to beginning of frames */ - tmp1r = tables->costab2[k]; - tmp1i = tables->sintab2[k]; - xr = inre[k] * tmp1r + inim[k] * tmp1i; - xi = inim[k] * tmp1r - inre[k] * tmp1i; - yr = -inim[FRAMESAMPLES_HALF - 1 - k] * tmp1r - inre[FRAMESAMPLES_HALF - 1 - k] * tmp1i; - yi = -inre[FRAMESAMPLES_HALF - 1 - k] * tmp1r + inim[FRAMESAMPLES_HALF - 1 - k] * tmp1i; - - /* Combine into one vector, z = x + j * y */ - outre1[k] = xr - yi; - outre1[FRAMESAMPLES_HALF - 1 - k] = xr + yi; - outre2[k] = xi + yr; - outre2[FRAMESAMPLES_HALF - 1 - k] = -xi + yr; - } - - - /* Get IDFT */ - WebRtcIsac_Fftns(1, &dims, outre1, outre2, 1, FRAMESAMPLES_HALF, fftstr_obj); - - - /* Demodulate and separate */ - fact = sqrt(FRAMESAMPLES_HALF); - for (k = 0; k < FRAMESAMPLES_HALF; k++) { - tmp1r = tables->costab1[k]; - tmp1i = tables->sintab1[k]; - xr = (outre1[k] * tmp1r - outre2[k] * tmp1i) * fact; - outre2[k] = (outre2[k] * tmp1r + outre1[k] * tmp1i) * fact; - outre1[k] = xr; - } -} diff --git a/webrtc/modules/audio_coding/meson.build b/webrtc/modules/audio_coding/meson.build index 1c46571..1e6fd70 100644 --- a/webrtc/modules/audio_coding/meson.build +++ b/webrtc/modules/audio_coding/meson.build @@ -6,53 +6,3 @@ isac_vad_sources = [ ] isac_vad_dep = declare_dependency(sources: isac_vad_sources) - -webrtc_audio_coding_sources = [ - 'codecs/isac/main/source/arith_routines.c', - 'codecs/isac/main/source/arith_routines_hist.c', - 'codecs/isac/main/source/arith_routines_logist.c', - 'codecs/isac/main/source/audio_decoder_isac.cc', - 'codecs/isac/main/source/audio_encoder_isac.cc', - 'codecs/isac/main/source/bandwidth_estimator.c', - 'codecs/isac/main/source/crc.c', - 'codecs/isac/main/source/decode_bwe.c', - 'codecs/isac/main/source/decode.c', - 'codecs/isac/main/source/encode.c', - 'codecs/isac/main/source/encode_lpc_swb.c', - 'codecs/isac/main/source/entropy_coding.c', - 'codecs/isac/main/source/filterbanks.c', - 'codecs/isac/main/source/intialize.c', - 'codecs/isac/main/source/isac.c', - 'codecs/isac/main/source/lattice.c', - 'codecs/isac/main/source/lpc_analysis.c', - 'codecs/isac/main/source/lpc_gain_swb_tables.c', - 'codecs/isac/main/source/lpc_shape_swb12_tables.c', - 'codecs/isac/main/source/lpc_shape_swb16_tables.c', - 'codecs/isac/main/source/lpc_tables.c', - 'codecs/isac/main/source/pitch_gain_tables.c', - 'codecs/isac/main/source/pitch_lag_tables.c', - 'codecs/isac/main/source/spectrum_ar_model_tables.c', - 'codecs/isac/main/source/transform.c', -] - -libwebrtc_audio_coding = library(ac_project_name, - webrtc_audio_coding_sources, - dependencies: [base_dep, api_dep, common_audio_dep, system_wrappers_dep, fft_dep, isac_vad_dep] + common_deps, - include_directories: webrtc_inc, - c_args: common_cflags, - cpp_args: common_cxxflags, - soversion: ac_minor_version, - install: true -) - -install_headers(['codecs/isac/bandwidth_info.h'], - subdir: join_paths(include_subdir, 'modules', 'audio_coding', 'codecs', 'isac') -) - -install_headers(['codecs/isac/main/source/settings.h'], - subdir: join_paths(include_subdir, 'modules', 'audio_coding', 'codecs', 'isac', 'main', 'source') -) - -install_headers(['codecs/isac/main/include/isac.h'], - subdir: join_paths(include_subdir, 'modules', 'audio_coding', 'codecs', 'isac', 'main', 'include') -) diff --git a/webrtc/modules/audio_processing/BUILD.gn b/webrtc/modules/audio_processing/BUILD.gn index 2b81427..a9c8895 100644 --- a/webrtc/modules/audio_processing/BUILD.gn +++ b/webrtc/modules/audio_processing/BUILD.gn @@ -21,30 +21,8 @@ config("apm_debug_dump") { rtc_library("api") { visibility = [ "*" ] - sources = [ - "include/audio_processing.cc", - "include/audio_processing.h", - ] - deps = [ - ":audio_frame_view", - ":audio_processing_statistics", - "../../api:array_view", - "../../api:scoped_refptr", - "../../api/audio:aec3_config", - "../../api/audio:audio_frame_api", - "../../api/audio:echo_control", - "../../rtc_base:macromagic", - "../../rtc_base:refcount", - "../../rtc_base:stringutils", - "../../rtc_base/system:arch", - "../../rtc_base/system:file_wrapper", - "../../rtc_base/system:rtc_export", - "agc:gain_control_interface", - ] - absl_deps = [ - "//third_party/abseil-cpp/absl/strings", - "//third_party/abseil-cpp/absl/types:optional", - ] + sources = [ "include/audio_processing.h" ] + deps = [ "../../api/audio:audio_processing" ] } rtc_library("audio_frame_proxies") { @@ -54,9 +32,9 @@ rtc_library("audio_frame_proxies") { "include/audio_frame_proxies.h", ] deps = [ - ":api", ":audio_frame_view", "../../api/audio:audio_frame_api", + "../../api/audio:audio_processing", ] } @@ -77,8 +55,9 @@ rtc_library("audio_buffer") { defines = [] deps = [ - ":api", "../../api:array_view", + "../../api/audio:audio_frame_api", + "../../api/audio:audio_processing", "../../common_audio", "../../common_audio:common_audio_c", "../../rtc_base:checks", @@ -111,12 +90,9 @@ rtc_source_set("aec_dump_interface") { ] deps = [ - ":api", ":audio_frame_view", - ] - absl_deps = [ + "../../api/audio:audio_processing", "//third_party/abseil-cpp/absl/base:core_headers", - "//third_party/abseil-cpp/absl/types:optional", ] } @@ -129,10 +105,11 @@ rtc_library("gain_controller2") { defines = [] deps = [ ":aec_dump_interface", - ":api", ":apm_logging", ":audio_buffer", ":audio_frame_view", + "../../api/audio:audio_frame_api", + "../../api/audio:audio_processing", "../../common_audio", "../../rtc_base:checks", "../../rtc_base:logging", @@ -168,29 +145,28 @@ rtc_library("audio_processing") { defines = [] deps = [ ":aec_dump_interface", - ":api", ":apm_logging", ":audio_buffer", ":audio_frame_proxies", ":audio_frame_view", - ":audio_processing_statistics", ":gain_controller2", ":high_pass_filter", - ":optionally_built_submodule_creators", ":rms_level", "../../api:array_view", "../../api:function_view", "../../api:make_ref_counted", "../../api/audio:aec3_config", "../../api/audio:audio_frame_api", + "../../api/audio:audio_processing", + "../../api/audio:audio_processing_statistics", "../../api/audio:echo_control", + "../../api/task_queue", "../../audio/utility:audio_frame_operations", "../../common_audio:common_audio_c", "../../common_audio/third_party/ooura:fft_size_256", "../../rtc_base:checks", "../../rtc_base:event_tracer", "../../rtc_base:gtest_prod", - "../../rtc_base:ignore_wundef", "../../rtc_base:logging", "../../rtc_base:macromagic", "../../rtc_base:safe_minmax", @@ -213,12 +189,10 @@ rtc_library("audio_processing") { "agc2:input_volume_stats_reporter", "capture_levels_adjuster", "ns", - "transient:transient_suppressor_api", "vad", - ] - absl_deps = [ + "//third_party/abseil-cpp/absl/base:nullability", "//third_party/abseil-cpp/absl/strings", - "//third_party/abseil-cpp/absl/types:optional", + "//third_party/abseil-cpp/absl/strings:string_view", ] deps += [ @@ -251,25 +225,13 @@ rtc_library("residual_echo_detector") { "residual_echo_detector.h", ] deps = [ - ":api", ":apm_logging", "../../api:array_view", + "../../api/audio:audio_processing", "../../rtc_base:checks", "../../rtc_base:logging", "../../system_wrappers:metrics", ] - absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] -} - -rtc_library("optionally_built_submodule_creators") { - sources = [ - "optionally_built_submodule_creators.cc", - "optionally_built_submodule_creators.h", - ] - deps = [ - "transient:transient_suppressor_api", - "transient:transient_suppressor_impl", - ] } rtc_source_set("rms_level") { @@ -282,22 +244,17 @@ rtc_source_set("rms_level") { "../../api:array_view", "../../rtc_base:checks", ] - absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] } rtc_library("audio_processing_statistics") { visibility = [ "*" ] - sources = [ - "include/audio_processing_statistics.cc", - "include/audio_processing_statistics.h", - ] - deps = [ "../../rtc_base/system:rtc_export" ] - absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] + sources = [ "include/audio_processing_statistics.h" ] + deps = [ "../../api/audio:audio_processing_statistics" ] } rtc_source_set("audio_frame_view") { sources = [ "include/audio_frame_view.h" ] - deps = [ "../../api:array_view" ] + deps = [ "../../api/audio:audio_frame_api" ] } if (rtc_enable_protobuf) { @@ -319,10 +276,7 @@ rtc_library("apm_logging") { "../../common_audio", "../../rtc_base:checks", "../../rtc_base:stringutils", - ] - absl_deps = [ - "//third_party/abseil-cpp/absl/strings", - "//third_party/abseil-cpp/absl/types:optional", + "//third_party/abseil-cpp/absl/strings:string_view", ] defines = [] } @@ -333,23 +287,21 @@ if (rtc_include_tests) { sources = [ "include/mock_audio_processing.h" ] deps = [ ":aec_dump_interface", - ":api", ":audio_buffer", ":audio_processing", - ":audio_processing_statistics", + "../../api/audio:audio_processing", + "../../api/audio:audio_processing_statistics", + "../../api/task_queue", "../../test:test_support", + "//third_party/abseil-cpp/absl/base:nullability", + "//third_party/abseil-cpp/absl/strings:string_view", ] - absl_deps = [ "//third_party/abseil-cpp/absl/strings" ] } if (!build_with_chromium) { group("audio_processing_tests") { testonly = true - deps = [ - ":audioproc_test_utils", - "transient:click_annotate", - "transient:transient_suppression_test", - ] + deps = [ ":audioproc_test_utils" ] if (rtc_enable_protobuf) { deps += [ @@ -378,7 +330,6 @@ if (rtc_include_tests) { deps = [ ":aec3_config_json", ":analog_mic_simulation", - ":api", ":apm_logging", ":audio_buffer", ":audio_frame_view", @@ -392,12 +343,13 @@ if (rtc_include_tests) { "../../api:scoped_refptr", "../../api/audio:aec3_config", "../../api/audio:aec3_factory", + "../../api/audio:audio_frame_api", + "../../api/audio:audio_processing", "../../api/audio:echo_detector_creator", "../../common_audio", "../../common_audio:common_audio_c", "../../rtc_base:checks", "../../rtc_base:gtest_prod", - "../../rtc_base:ignore_wundef", "../../rtc_base:macromagic", "../../rtc_base:platform_thread", "../../rtc_base:protobuf_utils", @@ -437,15 +389,11 @@ if (rtc_include_tests) { "capture_levels_adjuster", "capture_levels_adjuster:capture_levels_adjuster_unittests", "test/conversational_speech:unittest", - "transient:transient_suppression_unittests", "utility:legacy_delay_estimator_unittest", "utility:pffft_wrapper_unittest", "vad:vad_unittests", "//testing/gtest", - ] - absl_deps = [ - "//third_party/abseil-cpp/absl/strings", - "//third_party/abseil-cpp/absl/types:optional", + "//third_party/abseil-cpp/absl/strings:string_view", ] defines = [] @@ -463,18 +411,16 @@ if (rtc_include_tests) { ":audioproc_protobuf_utils", ":audioproc_test_utils", ":audioproc_unittest_proto", - ":optionally_built_submodule_creators", ":residual_echo_detector", ":rms_level", ":runtime_settings_protobuf_utils", "../../api/audio:audio_frame_api", "../../api/audio:echo_control", "../../rtc_base:rtc_base_tests_utils", - "../../rtc_base:rtc_task_queue", "aec_dump", "aec_dump:aec_dump_unittests", + "//third_party/abseil-cpp/absl/flags:flag", ] - absl_deps += [ "//third_party/abseil-cpp/absl/flags:flag" ] sources += [ "audio_processing_impl_locking_unittest.cc", "audio_processing_impl_unittest.cc", @@ -520,8 +466,8 @@ if (rtc_include_tests) { "../../rtc_base:safe_conversions", "../../system_wrappers", "../../test:test_support", + "//third_party/abseil-cpp/absl/strings:string_view", ] - absl_deps = [ "//third_party/abseil-cpp/absl/strings" ] } rtc_library("analog_mic_simulation") { @@ -539,7 +485,6 @@ if (rtc_include_tests) { "../../rtc_base:safe_minmax", "agc2:gain_map", ] - absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] } if (rtc_enable_protobuf && !build_with_chromium) { @@ -562,7 +507,6 @@ if (rtc_include_tests) { deps = [ ":aec3_config_json", ":analog_mic_simulation", - ":api", ":apm_logging", ":audio_processing", ":audioproc_debug_proto", @@ -570,10 +514,10 @@ if (rtc_include_tests) { ":audioproc_test_utils", ":runtime_settings_protobuf_utils", "../../api/audio:aec3_factory", + "../../api/audio:audio_processing", "../../api/audio:echo_detector_creator", "../../common_audio", "../../rtc_base:checks", - "../../rtc_base:ignore_wundef", "../../rtc_base:logging", "../../rtc_base:protobuf_utils", "../../rtc_base:rtc_json", @@ -588,12 +532,9 @@ if (rtc_include_tests) { "aec_dump", "aec_dump:aec_dump_impl", "//testing/gtest", - ] - absl_deps = [ "//third_party/abseil-cpp/absl/flags:flag", "//third_party/abseil-cpp/absl/flags:parse", - "//third_party/abseil-cpp/absl/strings", - "//third_party/abseil-cpp/absl/types:optional", + "//third_party/abseil-cpp/absl/strings:string_view", ] } # audioproc_f_impl } @@ -613,7 +554,6 @@ if (rtc_include_tests) { deps = [ ":audioproc_debug_proto", "../../rtc_base:checks", - "../../rtc_base:ignore_wundef", "../../rtc_base:protobuf_utils", "../../rtc_base/system:arch", ] @@ -627,9 +567,9 @@ if (rtc_include_tests) { ] deps = [ - ":api", ":audioproc_debug_proto", ":audioproc_protobuf_utils", + "../../api/audio:audio_processing", "../../rtc_base:checks", ] } @@ -657,11 +597,11 @@ rtc_library("audioproc_test_utils") { configs += [ ":apm_debug_dump" ] deps = [ - ":api", ":audio_buffer", ":audio_processing", "../../api:array_view", "../../api/audio:audio_frame_api", + "../../api/audio:audio_processing", "../../common_audio", "../../rtc_base:checks", "../../rtc_base:random", @@ -671,10 +611,7 @@ rtc_library("audioproc_test_utils") { "../../test:test_support", "../audio_coding:neteq_input_audio_tools", "//testing/gtest", - ] - absl_deps = [ - "//third_party/abseil-cpp/absl/strings", - "//third_party/abseil-cpp/absl/types:optional", + "//third_party/abseil-cpp/absl/strings:string_view", ] } @@ -692,6 +629,6 @@ rtc_library("aec3_config_json") { "../../rtc_base:rtc_json", "../../rtc_base:stringutils", "../../rtc_base/system:rtc_export", + "//third_party/abseil-cpp/absl/strings:string_view", ] - absl_deps = [ "//third_party/abseil-cpp/absl/strings" ] } diff --git a/webrtc/modules/audio_processing/aec3/BUILD.gn b/webrtc/modules/audio_processing/aec3/BUILD.gn index f5eb5d5..12a32b8 100644 --- a/webrtc/modules/audio_processing/aec3/BUILD.gn +++ b/webrtc/modules/audio_processing/aec3/BUILD.gn @@ -156,10 +156,7 @@ rtc_library("aec3") { "../../../system_wrappers:field_trial", "../../../system_wrappers:metrics", "../utility:cascaded_biquad_filter", - ] - absl_deps = [ - "//third_party/abseil-cpp/absl/strings", - "//third_party/abseil-cpp/absl/types:optional", + "//third_party/abseil-cpp/absl/strings:string_view", ] if (current_cpu == "x86" || current_cpu == "x64") { @@ -210,8 +207,8 @@ rtc_source_set("adaptive_fir_filter") { "..:apm_logging", "../../../api:array_view", "../../../rtc_base/system:arch", + "//third_party/abseil-cpp/absl/strings:string_view", ] - absl_deps = [ "//third_party/abseil-cpp/absl/strings" ] } rtc_source_set("adaptive_fir_filter_erl") { @@ -231,7 +228,6 @@ rtc_source_set("matched_filter") { "../../../rtc_base:gtest_prod", "../../../rtc_base/system:arch", ] - absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] } rtc_source_set("vector_math") { @@ -329,7 +325,6 @@ if (rtc_include_tests) { "../../../test:test_support", "../utility:cascaded_biquad_filter", ] - absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] defines = [] diff --git a/webrtc/modules/audio_processing/aec3/aec_state.cc b/webrtc/modules/audio_processing/aec3/aec_state.cc index 81fd91f..e3e9795 100644 --- a/webrtc/modules/audio_processing/aec3/aec_state.cc +++ b/webrtc/modules/audio_processing/aec3/aec_state.cc @@ -14,9 +14,9 @@ #include #include +#include #include -#include "absl/types/optional.h" #include "api/array_view.h" #include "modules/audio_processing/aec3/aec3_common.h" #include "modules/audio_processing/logging/apm_data_dumper.h" @@ -170,7 +170,7 @@ void AecState::HandleEchoPathChange( } void AecState::Update( - const absl::optional& external_delay, + const std::optional& external_delay, rtc::ArrayView>> adaptive_filter_frequency_responses, rtc::ArrayView> adaptive_filter_impulse_responses, @@ -359,7 +359,7 @@ AecState::FilterDelay::FilterDelay(const EchoCanceller3Config& config, void AecState::FilterDelay::Update( rtc::ArrayView analyzer_filter_delay_estimates_blocks, - const absl::optional& external_delay, + const std::optional& external_delay, size_t blocks_with_proper_filter_adaptation) { // Update the delay based on the external delay. if (external_delay && @@ -405,7 +405,7 @@ void AecState::FilteringQualityAnalyzer::Update( bool active_render, bool transparent_mode, bool saturated_capture, - const absl::optional& external_delay, + const std::optional& external_delay, bool any_filter_converged) { // Update blocks counter. const bool filter_update = active_render && !saturated_capture; diff --git a/webrtc/modules/audio_processing/aec3/aec_state.h b/webrtc/modules/audio_processing/aec3/aec_state.h index a39325c..e80b377 100644 --- a/webrtc/modules/audio_processing/aec3/aec_state.h +++ b/webrtc/modules/audio_processing/aec3/aec_state.h @@ -16,9 +16,9 @@ #include #include #include +#include #include -#include "absl/types/optional.h" #include "api/array_view.h" #include "api/audio/echo_canceller3_config.h" #include "modules/audio_processing/aec3/aec3_common.h" @@ -138,7 +138,7 @@ class AecState { // Updates the aec state. // TODO(bugs.webrtc.org/10913): Compute multi-channel ERL. void Update( - const absl::optional& external_delay, + const std::optional& external_delay, rtc::ArrayView>> adaptive_filter_frequency_responses, rtc::ArrayView> @@ -213,7 +213,7 @@ class AecState { // Updates the delay estimates based on new data. void Update( rtc::ArrayView analyzer_filter_delay_estimates_blocks, - const absl::optional& external_delay, + const std::optional& external_delay, size_t blocks_with_proper_filter_adaptation); private: @@ -221,7 +221,7 @@ class AecState { bool external_delay_reported_ = false; std::vector filter_delays_blocks_; int min_filter_delay_; - absl::optional external_delay_; + std::optional external_delay_; } delay_state_; // Classifier for toggling transparent mode when there is no echo. @@ -253,7 +253,7 @@ class AecState { void Update(bool active_render, bool transparent_mode, bool saturated_capture, - const absl::optional& external_delay, + const std::optional& external_delay, bool any_filter_converged); private: diff --git a/webrtc/modules/audio_processing/aec3/block_processor.cc b/webrtc/modules/audio_processing/aec3/block_processor.cc index 63e3d9c..ad3702e 100644 --- a/webrtc/modules/audio_processing/aec3/block_processor.cc +++ b/webrtc/modules/audio_processing/aec3/block_processor.cc @@ -13,10 +13,10 @@ #include #include +#include #include #include -#include "absl/types/optional.h" #include "api/audio/echo_canceller3_config.h" #include "api/audio/echo_control.h" #include "modules/audio_processing/aec3/aec3_common.h" @@ -76,7 +76,7 @@ class BlockProcessorImpl final : public BlockProcessor { BlockProcessorMetrics metrics_; RenderDelayBuffer::BufferingEvent render_event_; size_t capture_call_counter_ = 0; - absl::optional estimated_delay_; + std::optional estimated_delay_; }; std::atomic BlockProcessorImpl::instance_count_(0); @@ -223,7 +223,7 @@ void BlockProcessorImpl::UpdateEchoLeakageStatus(bool leakage_detected) { void BlockProcessorImpl::GetMetrics(EchoControl::Metrics* metrics) const { echo_remover_->GetMetrics(metrics); constexpr int block_size_ms = 4; - absl::optional delay = render_buffer_->Delay(); + std::optional delay = render_buffer_->Delay(); metrics->delay_ms = delay ? static_cast(*delay) * block_size_ms : 0; } diff --git a/webrtc/modules/audio_processing/aec3/config_selector.cc b/webrtc/modules/audio_processing/aec3/config_selector.cc index c55344d..e6bd829 100644 --- a/webrtc/modules/audio_processing/aec3/config_selector.cc +++ b/webrtc/modules/audio_processing/aec3/config_selector.cc @@ -47,7 +47,7 @@ bool CompatibleConfigs(const EchoCanceller3Config& mono_config, ConfigSelector::ConfigSelector( const EchoCanceller3Config& config, - const absl::optional& multichannel_config, + const std::optional& multichannel_config, int num_render_input_channels) : config_(config), multichannel_config_(multichannel_config) { if (multichannel_config_.has_value()) { diff --git a/webrtc/modules/audio_processing/aec3/config_selector.h b/webrtc/modules/audio_processing/aec3/config_selector.h index 3b3f94e..f56f7ba 100644 --- a/webrtc/modules/audio_processing/aec3/config_selector.h +++ b/webrtc/modules/audio_processing/aec3/config_selector.h @@ -11,7 +11,8 @@ #ifndef MODULES_AUDIO_PROCESSING_AEC3_CONFIG_SELECTOR_H_ #define MODULES_AUDIO_PROCESSING_AEC3_CONFIG_SELECTOR_H_ -#include "absl/types/optional.h" +#include + #include "api/audio/echo_canceller3_config.h" namespace webrtc { @@ -19,10 +20,9 @@ namespace webrtc { // Selects the config to use. class ConfigSelector { public: - ConfigSelector( - const EchoCanceller3Config& config, - const absl::optional& multichannel_config, - int num_render_input_channels); + ConfigSelector(const EchoCanceller3Config& config, + const std::optional& multichannel_config, + int num_render_input_channels); // Updates the config selection based on the detection of multichannel // content. @@ -32,7 +32,7 @@ class ConfigSelector { private: const EchoCanceller3Config config_; - const absl::optional multichannel_config_; + const std::optional multichannel_config_; const EchoCanceller3Config* active_config_ = nullptr; }; diff --git a/webrtc/modules/audio_processing/aec3/echo_audibility.cc b/webrtc/modules/audio_processing/aec3/echo_audibility.cc index 142a33d..d52b5ff 100644 --- a/webrtc/modules/audio_processing/aec3/echo_audibility.cc +++ b/webrtc/modules/audio_processing/aec3/echo_audibility.cc @@ -45,7 +45,7 @@ void EchoAudibility::Update(const RenderBuffer& render_buffer, void EchoAudibility::Reset() { render_stationarity_.Reset(); non_zero_render_seen_ = false; - render_spectrum_write_prev_ = absl::nullopt; + render_spectrum_write_prev_ = std::nullopt; } void EchoAudibility::UpdateRenderStationarityFlags( diff --git a/webrtc/modules/audio_processing/aec3/echo_audibility.h b/webrtc/modules/audio_processing/aec3/echo_audibility.h index b9d6f87..0bf20cd 100644 --- a/webrtc/modules/audio_processing/aec3/echo_audibility.h +++ b/webrtc/modules/audio_processing/aec3/echo_audibility.h @@ -13,7 +13,8 @@ #include -#include "absl/types/optional.h" +#include + #include "api/array_view.h" #include "modules/audio_processing/aec3/block_buffer.h" #include "modules/audio_processing/aec3/render_buffer.h" @@ -73,7 +74,7 @@ class EchoAudibility { // values. bool IsRenderTooLow(const BlockBuffer& block_buffer); - absl::optional render_spectrum_write_prev_; + std::optional render_spectrum_write_prev_; int render_block_write_prev_; bool non_zero_render_seen_; const bool use_render_stationarity_at_init_; diff --git a/webrtc/modules/audio_processing/aec3/echo_canceller3.cc b/webrtc/modules/audio_processing/aec3/echo_canceller3.cc index e8e2175..00010ce 100644 --- a/webrtc/modules/audio_processing/aec3/echo_canceller3.cc +++ b/webrtc/modules/audio_processing/aec3/echo_canceller3.cc @@ -378,14 +378,6 @@ EchoCanceller3Config AdjustConfig(const EchoCanceller3Config& config) { false; } - if (field_trial::IsEnabled("WebRTC-Aec3DelayEstimatorDetectPreEcho")) { - adjusted_cfg.delay.detect_pre_echo = true; - } - - if (field_trial::IsDisabled("WebRTC-Aec3DelayEstimatorDetectPreEcho")) { - adjusted_cfg.delay.detect_pre_echo = false; - } - if (field_trial::IsEnabled("WebRTC-Aec3SensitiveDominantNearendActivation")) { adjusted_cfg.suppressor.dominant_nearend_detection.enr_threshold = 0.5f; } else if (field_trial::IsEnabled( @@ -641,6 +633,13 @@ EchoCanceller3Config AdjustConfig(const EchoCanceller3Config& config) { "WebRTC-Aec3DelayEstimateSmoothingDelayFoundOverride", 0.f, 1.f, &adjusted_cfg.delay.delay_estimate_smoothing_delay_found); + int max_allowed_excess_render_blocks_override = + adjusted_cfg.buffering.max_allowed_excess_render_blocks; + RetrieveFieldTrialValue( + "WebRTC-Aec3BufferingMaxAllowedExcessRenderBlocksOverride", 0, 20, + &max_allowed_excess_render_blocks_override); + adjusted_cfg.buffering.max_allowed_excess_render_blocks = + max_allowed_excess_render_blocks_override; return adjusted_cfg; } @@ -719,7 +718,7 @@ std::atomic EchoCanceller3::instance_count_(0); EchoCanceller3::EchoCanceller3( const EchoCanceller3Config& config, - const absl::optional& multichannel_config, + const std::optional& multichannel_config, int sample_rate_hz, size_t num_render_channels, size_t num_capture_channels) diff --git a/webrtc/modules/audio_processing/aec3/echo_canceller3.h b/webrtc/modules/audio_processing/aec3/echo_canceller3.h index 7bf8e51..b05b3d9 100644 --- a/webrtc/modules/audio_processing/aec3/echo_canceller3.h +++ b/webrtc/modules/audio_processing/aec3/echo_canceller3.h @@ -15,9 +15,9 @@ #include #include +#include #include -#include "absl/types/optional.h" #include "api/array_view.h" #include "api/audio/echo_canceller3_config.h" #include "api/audio/echo_control.h" @@ -88,12 +88,11 @@ class Aec3RenderQueueItemVerifier { // AnalyzeRender call which can be called concurrently with the other methods. class EchoCanceller3 : public EchoControl { public: - EchoCanceller3( - const EchoCanceller3Config& config, - const absl::optional& multichannel_config, - int sample_rate_hz, - size_t num_render_channels, - size_t num_capture_channels); + EchoCanceller3(const EchoCanceller3Config& config, + const std::optional& multichannel_config, + int sample_rate_hz, + size_t num_render_channels, + size_t num_capture_channels); ~EchoCanceller3() override; diff --git a/webrtc/modules/audio_processing/aec3/echo_path_delay_estimator.cc b/webrtc/modules/audio_processing/aec3/echo_path_delay_estimator.cc index 510e4b8..1326779 100644 --- a/webrtc/modules/audio_processing/aec3/echo_path_delay_estimator.cc +++ b/webrtc/modules/audio_processing/aec3/echo_path_delay_estimator.cc @@ -58,7 +58,7 @@ void EchoPathDelayEstimator::Reset(bool reset_delay_confidence) { Reset(true, reset_delay_confidence); } -absl::optional EchoPathDelayEstimator::EstimateDelay( +std::optional EchoPathDelayEstimator::EstimateDelay( const DownsampledRenderBuffer& render_buffer, const Block& capture) { std::array downsampled_capture_data; @@ -74,7 +74,7 @@ absl::optional EchoPathDelayEstimator::EstimateDelay( matched_filter_.Update(render_buffer, downsampled_capture, matched_filter_lag_aggregator_.ReliableDelayFound()); - absl::optional aggregated_matched_filter_lag = + std::optional aggregated_matched_filter_lag = matched_filter_lag_aggregator_.Aggregate( matched_filter_.GetBestLagEstimate()); @@ -121,7 +121,7 @@ void EchoPathDelayEstimator::Reset(bool reset_lag_aggregator, matched_filter_lag_aggregator_.Reset(reset_delay_confidence); } matched_filter_.Reset(/*full_reset=*/reset_lag_aggregator); - old_aggregated_lag_ = absl::nullopt; + old_aggregated_lag_ = std::nullopt; consistent_estimate_counter_ = 0; } } // namespace webrtc diff --git a/webrtc/modules/audio_processing/aec3/echo_path_delay_estimator.h b/webrtc/modules/audio_processing/aec3/echo_path_delay_estimator.h index b24d0a2..bd5c3b0 100644 --- a/webrtc/modules/audio_processing/aec3/echo_path_delay_estimator.h +++ b/webrtc/modules/audio_processing/aec3/echo_path_delay_estimator.h @@ -13,7 +13,8 @@ #include -#include "absl/types/optional.h" +#include + #include "api/array_view.h" #include "modules/audio_processing/aec3/alignment_mixer.h" #include "modules/audio_processing/aec3/block.h" @@ -45,7 +46,7 @@ class EchoPathDelayEstimator { void Reset(bool reset_delay_confidence); // Produce a delay estimate if such is avaliable. - absl::optional EstimateDelay( + std::optional EstimateDelay( const DownsampledRenderBuffer& render_buffer, const Block& capture); @@ -68,7 +69,7 @@ class EchoPathDelayEstimator { Decimator capture_decimator_; MatchedFilter matched_filter_; MatchedFilterLagAggregator matched_filter_lag_aggregator_; - absl::optional old_aggregated_lag_; + std::optional old_aggregated_lag_; size_t consistent_estimate_counter_ = 0; ClockdriftDetector clockdrift_detector_; diff --git a/webrtc/modules/audio_processing/aec3/echo_remover.cc b/webrtc/modules/audio_processing/aec3/echo_remover.cc index 673d88a..e5c1b4c 100644 --- a/webrtc/modules/audio_processing/aec3/echo_remover.cc +++ b/webrtc/modules/audio_processing/aec3/echo_remover.cc @@ -120,7 +120,7 @@ class EchoRemoverImpl final : public EchoRemover { // signal. void ProcessCapture(EchoPathVariability echo_path_variability, bool capture_signal_saturation, - const absl::optional& external_delay, + const std::optional& external_delay, RenderBuffer* render_buffer, Block* linear_output, Block* capture) override; @@ -239,7 +239,7 @@ void EchoRemoverImpl::GetMetrics(EchoControl::Metrics* metrics) const { void EchoRemoverImpl::ProcessCapture( EchoPathVariability echo_path_variability, bool capture_signal_saturation, - const absl::optional& external_delay, + const std::optional& external_delay, RenderBuffer* render_buffer, Block* linear_output, Block* capture) { diff --git a/webrtc/modules/audio_processing/aec3/echo_remover.h b/webrtc/modules/audio_processing/aec3/echo_remover.h index f2f4f5e..db3992c 100644 --- a/webrtc/modules/audio_processing/aec3/echo_remover.h +++ b/webrtc/modules/audio_processing/aec3/echo_remover.h @@ -11,9 +11,9 @@ #ifndef MODULES_AUDIO_PROCESSING_AEC3_ECHO_REMOVER_H_ #define MODULES_AUDIO_PROCESSING_AEC3_ECHO_REMOVER_H_ +#include #include -#include "absl/types/optional.h" #include "api/audio/echo_canceller3_config.h" #include "api/audio/echo_control.h" #include "modules/audio_processing/aec3/block.h" @@ -41,7 +41,7 @@ class EchoRemover { virtual void ProcessCapture( EchoPathVariability echo_path_variability, bool capture_signal_saturation, - const absl::optional& external_delay, + const std::optional& external_delay, RenderBuffer* render_buffer, Block* linear_output, Block* capture) = 0; diff --git a/webrtc/modules/audio_processing/aec3/erle_estimator.h b/webrtc/modules/audio_processing/aec3/erle_estimator.h index 5579759..ac9c738 100644 --- a/webrtc/modules/audio_processing/aec3/erle_estimator.h +++ b/webrtc/modules/audio_processing/aec3/erle_estimator.h @@ -15,9 +15,9 @@ #include #include +#include #include -#include "absl/types/optional.h" #include "api/array_view.h" #include "api/audio/echo_canceller3_config.h" #include "modules/audio_processing/aec3/aec3_common.h" @@ -91,7 +91,7 @@ class ErleEstimator { // vector with content between 0 and 1 where 1 indicates that, at this current // time instant, the linear filter is reaching its maximum subtraction // performance. - rtc::ArrayView> GetInstLinearQualityEstimates() + rtc::ArrayView> GetInstLinearQualityEstimates() const { return fullband_erle_estimator_.GetInstLinearQualityEstimates(); } diff --git a/webrtc/modules/audio_processing/aec3/fullband_erle_estimator.cc b/webrtc/modules/audio_processing/aec3/fullband_erle_estimator.cc index e56674e..5545b93 100644 --- a/webrtc/modules/audio_processing/aec3/fullband_erle_estimator.cc +++ b/webrtc/modules/audio_processing/aec3/fullband_erle_estimator.cc @@ -13,8 +13,8 @@ #include #include #include +#include -#include "absl/types/optional.h" #include "api/array_view.h" #include "modules/audio_processing/aec3/aec3_common.h" #include "modules/audio_processing/logging/apm_data_dumper.h" @@ -142,7 +142,7 @@ void FullBandErleEstimator::ErleInstantaneous::Reset() { } void FullBandErleEstimator::ErleInstantaneous::ResetAccumulators() { - erle_log2_ = absl::nullopt; + erle_log2_ = std::nullopt; inst_quality_estimate_ = 0.f; num_points_ = 0; E2_acum_ = 0.f; diff --git a/webrtc/modules/audio_processing/aec3/fullband_erle_estimator.h b/webrtc/modules/audio_processing/aec3/fullband_erle_estimator.h index 7a08217..cc828b2 100644 --- a/webrtc/modules/audio_processing/aec3/fullband_erle_estimator.h +++ b/webrtc/modules/audio_processing/aec3/fullband_erle_estimator.h @@ -12,9 +12,9 @@ #define MODULES_AUDIO_PROCESSING_AEC3_FULLBAND_ERLE_ESTIMATOR_H_ #include +#include #include -#include "absl/types/optional.h" #include "api/array_view.h" #include "api/audio/echo_canceller3_config.h" #include "modules/audio_processing/aec3/aec3_common.h" @@ -49,7 +49,7 @@ class FullBandErleEstimator { // Returns an estimation of the current linear filter quality. It returns a // float number between 0 and 1 mapping 1 to the highest possible quality. - rtc::ArrayView> GetInstLinearQualityEstimates() + rtc::ArrayView> GetInstLinearQualityEstimates() const { return linear_filters_qualities_; } @@ -73,10 +73,10 @@ class FullBandErleEstimator { // Resets the members related with an instantaneous estimate. void ResetAccumulators(); // Returns the instantaneous ERLE in log2 units. - absl::optional GetInstErleLog2() const { return erle_log2_; } + std::optional GetInstErleLog2() const { return erle_log2_; } // Gets an indication between 0 and 1 of the performance of the linear // filter for the current time instant. - absl::optional GetQualityEstimate() const { + std::optional GetQualityEstimate() const { if (erle_log2_) { float value = inst_quality_estimate_; if (clamp_inst_quality_to_zero_) { @@ -85,9 +85,9 @@ class FullBandErleEstimator { if (clamp_inst_quality_to_one_) { value = std::min(1.f, value); } - return absl::optional(value); + return std::optional(value); } - return absl::nullopt; + return std::nullopt; } void Dump(const std::unique_ptr& data_dumper) const; @@ -96,7 +96,7 @@ class FullBandErleEstimator { void UpdateQualityEstimate(); const bool clamp_inst_quality_to_zero_; const bool clamp_inst_quality_to_one_; - absl::optional erle_log2_; + std::optional erle_log2_; float inst_quality_estimate_; float max_erle_log2_; float min_erle_log2_; @@ -110,7 +110,7 @@ class FullBandErleEstimator { std::vector hold_counters_instantaneous_erle_; std::vector erle_time_domain_log2_; std::vector instantaneous_erle_; - std::vector> linear_filters_qualities_; + std::vector> linear_filters_qualities_; }; } // namespace webrtc diff --git a/webrtc/modules/audio_processing/aec3/matched_filter.cc b/webrtc/modules/audio_processing/aec3/matched_filter.cc index edaa2a4..59a3b46 100644 --- a/webrtc/modules/audio_processing/aec3/matched_filter.cc +++ b/webrtc/modules/audio_processing/aec3/matched_filter.cc @@ -23,8 +23,8 @@ #include #include #include +#include -#include "absl/types/optional.h" #include "api/array_view.h" #include "modules/audio_processing/aec3/downsampled_render_buffer.h" #include "modules/audio_processing/logging/apm_data_dumper.h" @@ -43,8 +43,8 @@ constexpr int kAccumulatedErrorSubSampleRate = 4; void UpdateAccumulatedError( const rtc::ArrayView instantaneous_accumulated_error, const rtc::ArrayView accumulated_error, - float one_over_error_sum_anchor, - float smooth_constant_increases) { + float one_over_error_sum_anchor) { + static constexpr float kSmoothConstantIncreases = 0.015f; for (size_t k = 0; k < instantaneous_accumulated_error.size(); ++k) { float error_norm = instantaneous_accumulated_error[k] * one_over_error_sum_anchor; @@ -52,97 +52,30 @@ void UpdateAccumulatedError( accumulated_error[k] = error_norm; } else { accumulated_error[k] += - smooth_constant_increases * (error_norm - accumulated_error[k]); + kSmoothConstantIncreases * (error_norm - accumulated_error[k]); } } } size_t ComputePreEchoLag( - const webrtc::MatchedFilter::PreEchoConfiguration& pre_echo_configuration, const rtc::ArrayView accumulated_error, size_t lag, size_t alignment_shift_winner) { + static constexpr float kPreEchoThreshold = 0.5f; RTC_DCHECK_GE(lag, alignment_shift_winner); size_t pre_echo_lag_estimate = lag - alignment_shift_winner; size_t maximum_pre_echo_lag = std::min(pre_echo_lag_estimate / kAccumulatedErrorSubSampleRate, accumulated_error.size()); - switch (pre_echo_configuration.mode) { - case 0: - // Mode 0: Pre echo lag is defined as the first coefficient with an error - // lower than a threshold with a certain decrease slope. - for (size_t k = 1; k < maximum_pre_echo_lag; ++k) { - if (accumulated_error[k] < - pre_echo_configuration.threshold * accumulated_error[k - 1] && - accumulated_error[k] < pre_echo_configuration.threshold) { - pre_echo_lag_estimate = (k + 1) * kAccumulatedErrorSubSampleRate - 1; - break; - } - } - break; - case 1: - // Mode 1: Pre echo lag is defined as the first coefficient with an error - // lower than a certain threshold. - for (size_t k = 0; k < maximum_pre_echo_lag; ++k) { - if (accumulated_error[k] < pre_echo_configuration.threshold) { - pre_echo_lag_estimate = (k + 1) * kAccumulatedErrorSubSampleRate - 1; - break; - } - } - break; - case 2: - case 3: - // Mode 2,3: Pre echo lag is defined as the closest coefficient to the lag - // with an error lower than a certain threshold. - for (int k = static_cast(maximum_pre_echo_lag) - 1; k >= 0; --k) { - if (accumulated_error[k] > pre_echo_configuration.threshold) { - break; - } - pre_echo_lag_estimate = (k + 1) * kAccumulatedErrorSubSampleRate - 1; - } - break; - default: - RTC_DCHECK_NOTREACHED(); + for (int k = static_cast(maximum_pre_echo_lag) - 1; k >= 0; --k) { + if (accumulated_error[k] > kPreEchoThreshold) { break; + } + pre_echo_lag_estimate = (k + 1) * kAccumulatedErrorSubSampleRate - 1; } return pre_echo_lag_estimate + alignment_shift_winner; } -webrtc::MatchedFilter::PreEchoConfiguration FetchPreEchoConfiguration() { - constexpr float kDefaultThreshold = 0.5f; - constexpr int kDefaultMode = 3; - float threshold = kDefaultThreshold; - int mode = kDefaultMode; - const std::string pre_echo_configuration_field_trial = - webrtc::field_trial::FindFullName("WebRTC-Aec3PreEchoConfiguration"); - webrtc::FieldTrialParameter threshold_field_trial_parameter( - /*key=*/"threshold", /*default_value=*/kDefaultThreshold); - webrtc::FieldTrialParameter mode_field_trial_parameter( - /*key=*/"mode", /*default_value=*/kDefaultMode); - webrtc::ParseFieldTrial( - {&threshold_field_trial_parameter, &mode_field_trial_parameter}, - pre_echo_configuration_field_trial); - float threshold_read = - static_cast(threshold_field_trial_parameter.Get()); - int mode_read = mode_field_trial_parameter.Get(); - if (threshold_read < 1.0f && threshold_read > 0.0f) { - threshold = threshold_read; - } else { - RTC_LOG(LS_ERROR) - << "AEC3: Pre echo configuration: wrong input, threshold = " - << threshold_read << "."; - } - if (mode_read >= 0 && mode_read <= 3) { - mode = mode_read; - } else { - RTC_LOG(LS_ERROR) << "AEC3: Pre echo configuration: wrong input, mode = " - << mode_read << "."; - } - RTC_LOG(LS_INFO) << "AEC3: Pre echo configuration: threshold = " << threshold - << ", mode = " << mode << "."; - return {.threshold = threshold, .mode = mode}; -} - } // namespace namespace webrtc { @@ -685,8 +618,7 @@ MatchedFilter::MatchedFilter(ApmDataDumper* data_dumper, smoothing_fast_(smoothing_fast), smoothing_slow_(smoothing_slow), matching_filter_threshold_(matching_filter_threshold), - detect_pre_echo_(detect_pre_echo), - pre_echo_config_(FetchPreEchoConfiguration()) { + detect_pre_echo_(detect_pre_echo) { RTC_DCHECK(data_dumper); RTC_DCHECK_LT(0, window_size_sub_blocks); RTC_DCHECK((kBlockSize % sub_block_size) == 0); @@ -715,9 +647,9 @@ void MatchedFilter::Reset(bool full_reset) { std::fill(f.begin(), f.end(), 0.f); } - winner_lag_ = absl::nullopt; - reported_lag_estimate_ = absl::nullopt; - if (pre_echo_config_.mode != 3 || full_reset) { + winner_lag_ = std::nullopt; + reported_lag_estimate_ = std::nullopt; + if (full_reset) { for (auto& e : accumulated_error_) { std::fill(e.begin(), e.end(), 1.0f); } @@ -745,10 +677,10 @@ void MatchedFilter::Update(const DownsampledRenderBuffer& render_buffer, // Apply all matched filters. float winner_error_sum = error_sum_anchor; - winner_lag_ = absl::nullopt; - reported_lag_estimate_ = absl::nullopt; + winner_lag_ = std::nullopt; + reported_lag_estimate_ = std::nullopt; size_t alignment_shift = 0; - absl::optional previous_lag_estimate; + std::optional previous_lag_estimate; const int num_filters = static_cast(filters_.size()); int winner_index = -1; for (int n = 0; n < num_filters; ++n) { @@ -823,22 +755,16 @@ void MatchedFilter::Update(const DownsampledRenderBuffer& render_buffer, reported_lag_estimate_ = LagEstimate(winner_lag_.value(), /*pre_echo_lag=*/winner_lag_.value()); if (detect_pre_echo_ && last_detected_best_lag_filter_ == winner_index) { - const float energy_threshold = - pre_echo_config_.mode == 3 ? 1.0f : 30.0f * 30.0f * y.size(); - - if (error_sum_anchor > energy_threshold) { - const float smooth_constant_increases = - pre_echo_config_.mode != 3 ? 0.01f : 0.015f; - - UpdateAccumulatedError( - instantaneous_accumulated_error_, accumulated_error_[winner_index], - 1.0f / error_sum_anchor, smooth_constant_increases); + static constexpr float kEnergyThreshold = 1.0f; + if (error_sum_anchor > kEnergyThreshold) { + UpdateAccumulatedError(instantaneous_accumulated_error_, + accumulated_error_[winner_index], + 1.0f / error_sum_anchor); number_pre_echo_updates_++; } - if (pre_echo_config_.mode != 3 || number_pre_echo_updates_ >= 50) { + if (number_pre_echo_updates_ >= 50) { reported_lag_estimate_->pre_echo_lag = ComputePreEchoLag( - pre_echo_config_, accumulated_error_[winner_index], - winner_lag_.value(), + accumulated_error_[winner_index], winner_lag_.value(), winner_index * filter_intra_lag_shift_ /*alignment_shift_winner*/); } else { reported_lag_estimate_->pre_echo_lag = winner_lag_.value(); @@ -885,10 +811,9 @@ void MatchedFilter::Dump() { "aec3_correlator_error_" + std::to_string(n) + "_h"; data_dumper_->DumpRaw(dumper_error.c_str(), accumulated_error_[n]); - size_t pre_echo_lag = - ComputePreEchoLag(pre_echo_config_, accumulated_error_[n], - lag_estimate + n * filter_intra_lag_shift_, - n * filter_intra_lag_shift_); + size_t pre_echo_lag = ComputePreEchoLag( + accumulated_error_[n], lag_estimate + n * filter_intra_lag_shift_, + n * filter_intra_lag_shift_); std::string dumper_pre_lag = "aec3_correlator_pre_echo_lag_" + std::to_string(n); data_dumper_->DumpRaw(dumper_pre_lag.c_str(), pre_echo_lag); diff --git a/webrtc/modules/audio_processing/aec3/matched_filter.h b/webrtc/modules/audio_processing/aec3/matched_filter.h index bb54fba..bb111c5 100644 --- a/webrtc/modules/audio_processing/aec3/matched_filter.h +++ b/webrtc/modules/audio_processing/aec3/matched_filter.h @@ -13,9 +13,9 @@ #include +#include #include -#include "absl/types/optional.h" #include "api/array_view.h" #include "modules/audio_processing/aec3/aec3_common.h" #include "rtc_base/gtest_prod_util.h" @@ -106,11 +106,6 @@ class MatchedFilter { size_t pre_echo_lag = 0; }; - struct PreEchoConfiguration { - const float threshold; - const int mode; - }; - MatchedFilter(ApmDataDumper* data_dumper, Aec3Optimization optimization, size_t sub_block_size, @@ -138,7 +133,7 @@ class MatchedFilter { void Reset(bool full_reset); // Returns the current lag estimates. - absl::optional GetBestLagEstimate() const { + std::optional GetBestLagEstimate() const { return reported_lag_estimate_; } @@ -153,15 +148,6 @@ class MatchedFilter { size_t downsampling_factor) const; private: - FRIEND_TEST_ALL_PREFIXES(MatchedFilterFieldTrialTest, - PreEchoConfigurationTest); - FRIEND_TEST_ALL_PREFIXES(MatchedFilterFieldTrialTest, - WrongPreEchoConfigurationTest); - - // Only for testing. Gets the pre echo detection configuration. - const PreEchoConfiguration& GetPreEchoConfiguration() const { - return pre_echo_config_; - } void Dump(); ApmDataDumper* const data_dumper_; @@ -172,8 +158,8 @@ class MatchedFilter { std::vector> accumulated_error_; std::vector instantaneous_accumulated_error_; std::vector scratch_memory_; - absl::optional reported_lag_estimate_; - absl::optional winner_lag_; + std::optional reported_lag_estimate_; + std::optional winner_lag_; int last_detected_best_lag_filter_ = -1; std::vector filters_offsets_; int number_pre_echo_updates_ = 0; @@ -182,7 +168,6 @@ class MatchedFilter { const float smoothing_slow_; const float matching_filter_threshold_; const bool detect_pre_echo_; - const PreEchoConfiguration pre_echo_config_; }; } // namespace webrtc diff --git a/webrtc/modules/audio_processing/aec3/matched_filter_avx2.cc b/webrtc/modules/audio_processing/aec3/matched_filter_avx2.cc index 65a1b76..8c2ffcb 100644 --- a/webrtc/modules/audio_processing/aec3/matched_filter_avx2.cc +++ b/webrtc/modules/audio_processing/aec3/matched_filter_avx2.cc @@ -13,16 +13,6 @@ #include "modules/audio_processing/aec3/matched_filter.h" #include "rtc_base/checks.h" -#ifdef _MSC_VER -// Visual Studio -#define LOOKUP_M128(v, i) v.m128_f32[i] -#define LOOKUP_M256(v, i) v.m256_f32[i] -#else -// GCC/Clang -#define LOOKUP_M128(v, i) v[i] -#define LOOKUP_M256(v, i) v[i] -#endif - namespace webrtc { namespace aec3 { @@ -91,14 +81,14 @@ void MatchedFilterCore_AccumulatedError_AVX2( s_inst_256_8 = _mm256_mul_ps(h_k_8, x_k_8); s_inst_hadd_256 = _mm256_hadd_ps(s_inst_256, s_inst_256_8); s_inst_hadd_256 = _mm256_hadd_ps(s_inst_hadd_256, s_inst_hadd_256); - s_acum += LOOKUP_M256(s_inst_hadd_256, 0); - LOOKUP_M128(e_128, 0) = s_acum - y[i]; - s_acum += LOOKUP_M256(s_inst_hadd_256,4); - LOOKUP_M128(e_128, 1) = s_acum - y[i]; - s_acum += LOOKUP_M256(s_inst_hadd_256,1); - LOOKUP_M128(e_128, 2) = s_acum - y[i]; - s_acum += LOOKUP_M256(s_inst_hadd_256,5); - LOOKUP_M128(e_128, 3) = s_acum - y[i]; + s_acum += s_inst_hadd_256[0]; + e_128[0] = s_acum - y[i]; + s_acum += s_inst_hadd_256[4]; + e_128[1] = s_acum - y[i]; + s_acum += s_inst_hadd_256[1]; + e_128[2] = s_acum - y[i]; + s_acum += s_inst_hadd_256[5]; + e_128[3] = s_acum - y[i]; __m128 accumulated_error = _mm_load_ps(a_p); accumulated_error = _mm_fmadd_ps(e_128, e_128, accumulated_error); @@ -219,8 +209,8 @@ void MatchedFilterCore_AVX2(size_t x_start_index, x2_sum_256 = _mm256_add_ps(x2_sum_256, x2_sum_256_8); s_256 = _mm256_add_ps(s_256, s_256_8); __m128 sum = hsum_ab(x2_sum_256, s_256); - x2_sum += LOOKUP_M128(sum, 0); - s += LOOKUP_M128(sum, 1); + x2_sum += sum[0]; + s += sum[1]; // Compute the matched filter error. float e = y[i] - s; diff --git a/webrtc/modules/audio_processing/aec3/matched_filter_lag_aggregator.cc b/webrtc/modules/audio_processing/aec3/matched_filter_lag_aggregator.cc index c8ac417..a7c886a 100644 --- a/webrtc/modules/audio_processing/aec3/matched_filter_lag_aggregator.cc +++ b/webrtc/modules/audio_processing/aec3/matched_filter_lag_aggregator.cc @@ -15,7 +15,6 @@ #include "modules/audio_processing/logging/apm_data_dumper.h" #include "rtc_base/checks.h" #include "rtc_base/numerics/safe_minmax.h" -#include "system_wrappers/include/field_trial.h" namespace webrtc { namespace { @@ -63,8 +62,8 @@ void MatchedFilterLagAggregator::Reset(bool hard_reset) { } } -absl::optional MatchedFilterLagAggregator::Aggregate( - const absl::optional& lag_estimate) { +std::optional MatchedFilterLagAggregator::Aggregate( + const std::optional& lag_estimate) { if (lag_estimate && pre_echo_lag_aggregator_) { pre_echo_lag_aggregator_->Dump(data_dumper_); pre_echo_lag_aggregator_->Aggregate( @@ -91,7 +90,7 @@ absl::optional MatchedFilterLagAggregator::Aggregate( } } - return absl::nullopt; + return std::nullopt; } MatchedFilterLagAggregator::HighestPeakAggregator::HighestPeakAggregator( @@ -124,8 +123,6 @@ MatchedFilterLagAggregator::PreEchoLagAggregator::PreEchoLagAggregator( size_t max_filter_lag, size_t down_sampling_factor) : block_size_log2_(GetDownSamplingBlockSizeLog2(down_sampling_factor)), - penalize_high_delays_initial_phase_(!field_trial::IsDisabled( - "WebRTC-Aec3PenalyzeHighDelaysInitialPhase")), histogram_( ((max_filter_lag + 1) * down_sampling_factor) >> kBlockSizeLog2, 0) { @@ -156,8 +153,7 @@ void MatchedFilterLagAggregator::PreEchoLagAggregator::Aggregate( ++histogram_[histogram_data_[histogram_data_index_]]; histogram_data_index_ = (histogram_data_index_ + 1) % histogram_data_.size(); int pre_echo_candidate_block_size = 0; - if (penalize_high_delays_initial_phase_ && - number_updates_ < kNumBlocksPerSecond * 2) { + if (number_updates_ < kNumBlocksPerSecond * 2) { number_updates_++; float penalization_per_delay = 1.0f; float max_histogram_value = -1.0f; diff --git a/webrtc/modules/audio_processing/aec3/matched_filter_lag_aggregator.h b/webrtc/modules/audio_processing/aec3/matched_filter_lag_aggregator.h index 1287b38..9022424 100644 --- a/webrtc/modules/audio_processing/aec3/matched_filter_lag_aggregator.h +++ b/webrtc/modules/audio_processing/aec3/matched_filter_lag_aggregator.h @@ -11,9 +11,9 @@ #ifndef MODULES_AUDIO_PROCESSING_AEC3_MATCHED_FILTER_LAG_AGGREGATOR_H_ #define MODULES_AUDIO_PROCESSING_AEC3_MATCHED_FILTER_LAG_AGGREGATOR_H_ +#include #include -#include "absl/types/optional.h" #include "api/audio/echo_canceller3_config.h" #include "modules/audio_processing/aec3/delay_estimate.h" #include "modules/audio_processing/aec3/matched_filter.h" @@ -41,8 +41,8 @@ class MatchedFilterLagAggregator { void Reset(bool hard_reset); // Aggregates the provided lag estimates. - absl::optional Aggregate( - const absl::optional& lag_estimate); + std::optional Aggregate( + const std::optional& lag_estimate); // Returns whether a reliable delay estimate has been found. bool ReliableDelayFound() const { return significant_candidate_found_; } @@ -64,7 +64,6 @@ class MatchedFilterLagAggregator { private: const int block_size_log2_; - const bool penalize_high_delays_initial_phase_; std::array histogram_data_; std::vector histogram_; int histogram_data_index_ = 0; diff --git a/webrtc/modules/audio_processing/aec3/multi_channel_content_detector.cc b/webrtc/modules/audio_processing/aec3/multi_channel_content_detector.cc index 9806896..2b07585 100644 --- a/webrtc/modules/audio_processing/aec3/multi_channel_content_detector.cc +++ b/webrtc/modules/audio_processing/aec3/multi_channel_content_detector.cc @@ -94,9 +94,9 @@ MultiChannelContentDetector::MultiChannelContentDetector( detection_threshold_(detection_threshold), detection_timeout_threshold_frames_( stereo_detection_timeout_threshold_seconds > 0 - ? absl::make_optional(stereo_detection_timeout_threshold_seconds * - kNumFramesPerSecond) - : absl::nullopt), + ? std::make_optional(stereo_detection_timeout_threshold_seconds * + kNumFramesPerSecond) + : std::nullopt), stereo_detection_hysteresis_frames_(static_cast( stereo_detection_hysteresis_seconds * kNumFramesPerSecond)), metrics_logger_((detect_stereo_content && num_render_input_channels > 1) diff --git a/webrtc/modules/audio_processing/aec3/multi_channel_content_detector.h b/webrtc/modules/audio_processing/aec3/multi_channel_content_detector.h index be8717f..2b2f3b8 100644 --- a/webrtc/modules/audio_processing/aec3/multi_channel_content_detector.h +++ b/webrtc/modules/audio_processing/aec3/multi_channel_content_detector.h @@ -14,10 +14,9 @@ #include #include +#include #include -#include "absl/types/optional.h" - namespace webrtc { // Analyzes audio content to determine whether the contained audio is proper @@ -76,7 +75,7 @@ class MultiChannelContentDetector { const bool detect_stereo_content_; const float detection_threshold_; - const absl::optional detection_timeout_threshold_frames_; + const std::optional detection_timeout_threshold_frames_; const int stereo_detection_hysteresis_frames_; // Collects and reports metrics on the amount of multichannel content diff --git a/webrtc/modules/audio_processing/aec3/render_delay_buffer.cc b/webrtc/modules/audio_processing/aec3/render_delay_buffer.cc index ca77a58..f4721d4 100644 --- a/webrtc/modules/audio_processing/aec3/render_delay_buffer.cc +++ b/webrtc/modules/audio_processing/aec3/render_delay_buffer.cc @@ -17,9 +17,9 @@ #include #include #include +#include #include -#include "absl/types/optional.h" #include "api/array_view.h" #include "api/audio/echo_canceller3_config.h" #include "modules/audio_processing/aec3/aec3_common.h" @@ -80,7 +80,7 @@ class RenderDelayBufferImpl final : public RenderDelayBuffer { BlockBuffer blocks_; SpectrumBuffer spectra_; FftBuffer ffts_; - absl::optional delay_; + std::optional delay_; RenderBuffer echo_remover_buffer_; DownsampledRenderBuffer low_rate_; AlignmentMixer render_mixer_; @@ -95,7 +95,7 @@ class RenderDelayBufferImpl final : public RenderDelayBuffer { int64_t render_call_counter_ = 0; bool render_activity_ = false; size_t render_activity_counter_ = 0; - absl::optional external_audio_buffer_delay_; + std::optional external_audio_buffer_delay_; bool external_audio_buffer_delay_verified_after_reset_ = false; size_t min_latency_blocks_ = 0; size_t excess_render_detection_counter_ = 0; @@ -193,7 +193,7 @@ void RenderDelayBufferImpl::Reset() { ApplyTotalDelay(config_.delay.default_delay); // Unset the delays which are set by AlignFromDelay. - delay_ = absl::nullopt; + delay_ = std::nullopt; } } diff --git a/webrtc/modules/audio_processing/aec3/render_delay_controller.cc b/webrtc/modules/audio_processing/aec3/render_delay_controller.cc index 465e77f..df594ea 100644 --- a/webrtc/modules/audio_processing/aec3/render_delay_controller.cc +++ b/webrtc/modules/audio_processing/aec3/render_delay_controller.cc @@ -14,8 +14,8 @@ #include #include #include +#include -#include "absl/types/optional.h" #include "api/array_view.h" #include "api/audio/echo_canceller3_config.h" #include "modules/audio_processing/aec3/aec3_common.h" @@ -44,7 +44,7 @@ class RenderDelayControllerImpl final : public RenderDelayController { ~RenderDelayControllerImpl() override; void Reset(bool reset_delay_confidence) override; void LogRenderCall() override; - absl::optional GetDelay( + std::optional GetDelay( const DownsampledRenderBuffer& render_buffer, size_t render_delay_buffer_delay, const Block& capture) override; @@ -54,17 +54,17 @@ class RenderDelayControllerImpl final : public RenderDelayController { static std::atomic instance_count_; std::unique_ptr data_dumper_; const int hysteresis_limit_blocks_; - absl::optional delay_; + std::optional delay_; EchoPathDelayEstimator delay_estimator_; RenderDelayControllerMetrics metrics_; - absl::optional delay_samples_; + std::optional delay_samples_; size_t capture_call_counter_ = 0; int delay_change_counter_ = 0; DelayEstimate::Quality last_delay_estimate_quality_; }; DelayEstimate ComputeBufferDelay( - const absl::optional& current_delay, + const std::optional& current_delay, int hysteresis_limit_blocks, DelayEstimate estimated_delay) { // Compute the buffer delay increase required to achieve the desired latency. @@ -100,8 +100,8 @@ RenderDelayControllerImpl::RenderDelayControllerImpl( RenderDelayControllerImpl::~RenderDelayControllerImpl() = default; void RenderDelayControllerImpl::Reset(bool reset_delay_confidence) { - delay_ = absl::nullopt; - delay_samples_ = absl::nullopt; + delay_ = std::nullopt; + delay_samples_ = std::nullopt; delay_estimator_.Reset(reset_delay_confidence); delay_change_counter_ = 0; if (reset_delay_confidence) { @@ -111,7 +111,7 @@ void RenderDelayControllerImpl::Reset(bool reset_delay_confidence) { void RenderDelayControllerImpl::LogRenderCall() {} -absl::optional RenderDelayControllerImpl::GetDelay( +std::optional RenderDelayControllerImpl::GetDelay( const DownsampledRenderBuffer& render_buffer, size_t render_delay_buffer_delay, const Block& capture) { @@ -155,11 +155,10 @@ absl::optional RenderDelayControllerImpl::GetDelay( last_delay_estimate_quality_ = delay_samples_->quality; } - metrics_.Update( - delay_samples_ ? absl::optional(delay_samples_->delay) - : absl::nullopt, - delay_ ? absl::optional(delay_->delay) : absl::nullopt, - delay_estimator_.Clockdrift()); + metrics_.Update(delay_samples_ ? std::optional(delay_samples_->delay) + : std::nullopt, + delay_ ? std::optional(delay_->delay) : std::nullopt, + delay_estimator_.Clockdrift()); data_dumper_->DumpRaw("aec3_render_delay_controller_delay", delay_samples ? delay_samples->delay : 0); diff --git a/webrtc/modules/audio_processing/aec3/render_delay_controller.h b/webrtc/modules/audio_processing/aec3/render_delay_controller.h index 4a18a11..b74c161 100644 --- a/webrtc/modules/audio_processing/aec3/render_delay_controller.h +++ b/webrtc/modules/audio_processing/aec3/render_delay_controller.h @@ -11,7 +11,8 @@ #ifndef MODULES_AUDIO_PROCESSING_AEC3_RENDER_DELAY_CONTROLLER_H_ #define MODULES_AUDIO_PROCESSING_AEC3_RENDER_DELAY_CONTROLLER_H_ -#include "absl/types/optional.h" +#include + #include "api/array_view.h" #include "api/audio/echo_canceller3_config.h" #include "modules/audio_processing/aec3/block.h" @@ -38,7 +39,7 @@ class RenderDelayController { virtual void LogRenderCall() = 0; // Aligns the render buffer content with the capture signal. - virtual absl::optional GetDelay( + virtual std::optional GetDelay( const DownsampledRenderBuffer& render_buffer, size_t render_delay_buffer_delay, const Block& capture) = 0; diff --git a/webrtc/modules/audio_processing/aec3/render_delay_controller_metrics.cc b/webrtc/modules/audio_processing/aec3/render_delay_controller_metrics.cc index 1e0a0f4..8d3f415 100644 --- a/webrtc/modules/audio_processing/aec3/render_delay_controller_metrics.cc +++ b/webrtc/modules/audio_processing/aec3/render_delay_controller_metrics.cc @@ -42,8 +42,8 @@ enum class DelayChangesCategory { RenderDelayControllerMetrics::RenderDelayControllerMetrics() = default; void RenderDelayControllerMetrics::Update( - absl::optional delay_samples, - absl::optional buffer_delay_blocks, + std::optional delay_samples, + std::optional buffer_delay_blocks, ClockdriftDetector::Level clockdrift) { ++call_counter_; diff --git a/webrtc/modules/audio_processing/aec3/render_delay_controller_metrics.h b/webrtc/modules/audio_processing/aec3/render_delay_controller_metrics.h index b81833b..0a6f30e 100644 --- a/webrtc/modules/audio_processing/aec3/render_delay_controller_metrics.h +++ b/webrtc/modules/audio_processing/aec3/render_delay_controller_metrics.h @@ -13,7 +13,8 @@ #include -#include "absl/types/optional.h" +#include + #include "modules/audio_processing/aec3/clockdrift_detector.h" namespace webrtc { @@ -28,8 +29,8 @@ class RenderDelayControllerMetrics { delete; // Updates the metric with new data. - void Update(absl::optional delay_samples, - absl::optional buffer_delay_blocks, + void Update(std::optional delay_samples, + std::optional buffer_delay_blocks, ClockdriftDetector::Level clockdrift); private: diff --git a/webrtc/modules/audio_processing/aec3/render_signal_analyzer.cc b/webrtc/modules/audio_processing/aec3/render_signal_analyzer.cc index bfbeb0e..a3e78e4 100644 --- a/webrtc/modules/audio_processing/aec3/render_signal_analyzer.cc +++ b/webrtc/modules/audio_processing/aec3/render_signal_analyzer.cc @@ -27,7 +27,7 @@ constexpr size_t kCounterThreshold = 5; // Identifies local bands with narrow characteristics. void IdentifySmallNarrowBandRegions( const RenderBuffer& render_buffer, - const absl::optional& delay_partitions, + const std::optional& delay_partitions, std::array* narrow_band_counters) { RTC_DCHECK(narrow_band_counters); @@ -56,14 +56,14 @@ void IdentifySmallNarrowBandRegions( // Identifies whether the signal has a single strong narrow-band component. void IdentifyStrongNarrowBandComponent(const RenderBuffer& render_buffer, int strong_peak_freeze_duration, - absl::optional* narrow_peak_band, + std::optional* narrow_peak_band, size_t* narrow_peak_counter) { RTC_DCHECK(narrow_peak_band); RTC_DCHECK(narrow_peak_counter); if (*narrow_peak_band && ++(*narrow_peak_counter) > static_cast(strong_peak_freeze_duration)) { - *narrow_peak_band = absl::nullopt; + *narrow_peak_band = std::nullopt; } const Block& x_latest = render_buffer.GetBlock(0); @@ -125,7 +125,7 @@ RenderSignalAnalyzer::~RenderSignalAnalyzer() = default; void RenderSignalAnalyzer::Update( const RenderBuffer& render_buffer, - const absl::optional& delay_partitions) { + const std::optional& delay_partitions) { // Identify bands of narrow nature. IdentifySmallNarrowBandRegions(render_buffer, delay_partitions, &narrow_band_counters_); diff --git a/webrtc/modules/audio_processing/aec3/render_signal_analyzer.h b/webrtc/modules/audio_processing/aec3/render_signal_analyzer.h index 2e4aaa4..058b292 100644 --- a/webrtc/modules/audio_processing/aec3/render_signal_analyzer.h +++ b/webrtc/modules/audio_processing/aec3/render_signal_analyzer.h @@ -14,8 +14,8 @@ #include #include #include +#include -#include "absl/types/optional.h" #include "api/audio/echo_canceller3_config.h" #include "modules/audio_processing/aec3/aec3_common.h" #include "modules/audio_processing/aec3/render_buffer.h" @@ -34,7 +34,7 @@ class RenderSignalAnalyzer { // Updates the render signal analysis with the most recent render signal. void Update(const RenderBuffer& render_buffer, - const absl::optional& delay_partitions); + const std::optional& delay_partitions); // Returns true if the render signal is poorly exciting. bool PoorSignalExcitation() const { @@ -48,12 +48,12 @@ class RenderSignalAnalyzer { void MaskRegionsAroundNarrowBands( std::array* v) const; - absl::optional NarrowPeakBand() const { return narrow_peak_band_; } + std::optional NarrowPeakBand() const { return narrow_peak_band_; } private: const int strong_peak_freeze_duration_; std::array narrow_band_counters_; - absl::optional narrow_peak_band_; + std::optional narrow_peak_band_; size_t narrow_peak_counter_; }; diff --git a/webrtc/modules/audio_processing/aec3/residual_echo_estimator.h b/webrtc/modules/audio_processing/aec3/residual_echo_estimator.h index c468764..3bed698 100644 --- a/webrtc/modules/audio_processing/aec3/residual_echo_estimator.h +++ b/webrtc/modules/audio_processing/aec3/residual_echo_estimator.h @@ -13,8 +13,8 @@ #include #include +#include -#include "absl/types/optional.h" #include "api/audio/echo_canceller3_config.h" #include "modules/audio_processing/aec3/aec3_common.h" #include "modules/audio_processing/aec3/aec_state.h" diff --git a/webrtc/modules/audio_processing/aec3/reverb_decay_estimator.cc b/webrtc/modules/audio_processing/aec3/reverb_decay_estimator.cc index 2daf376..ddff1c9 100644 --- a/webrtc/modules/audio_processing/aec3/reverb_decay_estimator.cc +++ b/webrtc/modules/audio_processing/aec3/reverb_decay_estimator.cc @@ -102,7 +102,7 @@ ReverbDecayEstimator::ReverbDecayEstimator(const EchoCanceller3Config& config) ReverbDecayEstimator::~ReverbDecayEstimator() = default; void ReverbDecayEstimator::Update(rtc::ArrayView filter, - const absl::optional& filter_quality, + const std::optional& filter_quality, int filter_delay_blocks, bool usable_linear_filter, bool stationary_signal) { diff --git a/webrtc/modules/audio_processing/aec3/reverb_decay_estimator.h b/webrtc/modules/audio_processing/aec3/reverb_decay_estimator.h index fee5421..6d9d849 100644 --- a/webrtc/modules/audio_processing/aec3/reverb_decay_estimator.h +++ b/webrtc/modules/audio_processing/aec3/reverb_decay_estimator.h @@ -12,9 +12,9 @@ #define MODULES_AUDIO_PROCESSING_AEC3_REVERB_DECAY_ESTIMATOR_H_ #include +#include #include -#include "absl/types/optional.h" #include "api/array_view.h" #include "modules/audio_processing/aec3/aec3_common.h" // kMaxAdaptiveFilter... @@ -30,7 +30,7 @@ class ReverbDecayEstimator { ~ReverbDecayEstimator(); // Updates the decay estimate. void Update(rtc::ArrayView filter, - const absl::optional& filter_quality, + const std::optional& filter_quality, int filter_delay_blocks, bool usable_linear_filter, bool stationary_signal); diff --git a/webrtc/modules/audio_processing/aec3/reverb_frequency_response.cc b/webrtc/modules/audio_processing/aec3/reverb_frequency_response.cc index 6e7282a..e96930a 100644 --- a/webrtc/modules/audio_processing/aec3/reverb_frequency_response.cc +++ b/webrtc/modules/audio_processing/aec3/reverb_frequency_response.cc @@ -62,7 +62,7 @@ void ReverbFrequencyResponse::Update( const std::vector>& frequency_response, int filter_delay_blocks, - const absl::optional& linear_filter_quality, + const std::optional& linear_filter_quality, bool stationary_block) { if (stationary_block || !linear_filter_quality) { return; diff --git a/webrtc/modules/audio_processing/aec3/reverb_frequency_response.h b/webrtc/modules/audio_processing/aec3/reverb_frequency_response.h index 69b16b5..8bb9313 100644 --- a/webrtc/modules/audio_processing/aec3/reverb_frequency_response.h +++ b/webrtc/modules/audio_processing/aec3/reverb_frequency_response.h @@ -12,9 +12,9 @@ #define MODULES_AUDIO_PROCESSING_AEC3_REVERB_FREQUENCY_RESPONSE_H_ #include +#include #include -#include "absl/types/optional.h" #include "api/array_view.h" #include "modules/audio_processing/aec3/aec3_common.h" @@ -31,7 +31,7 @@ class ReverbFrequencyResponse { void Update(const std::vector>& frequency_response, int filter_delay_blocks, - const absl::optional& linear_filter_quality, + const std::optional& linear_filter_quality, bool stationary_block); // Returns the estimated frequency response for the reverb. diff --git a/webrtc/modules/audio_processing/aec3/reverb_model_estimator.cc b/webrtc/modules/audio_processing/aec3/reverb_model_estimator.cc index 5cd7a78..8a815e6 100644 --- a/webrtc/modules/audio_processing/aec3/reverb_model_estimator.cc +++ b/webrtc/modules/audio_processing/aec3/reverb_model_estimator.cc @@ -31,7 +31,7 @@ void ReverbModelEstimator::Update( rtc::ArrayView> impulse_responses, rtc::ArrayView>> frequency_responses, - rtc::ArrayView> linear_filter_qualities, + rtc::ArrayView> linear_filter_qualities, rtc::ArrayView filter_delays_blocks, const std::vector& usable_linear_estimates, bool stationary_block) { diff --git a/webrtc/modules/audio_processing/aec3/reverb_model_estimator.h b/webrtc/modules/audio_processing/aec3/reverb_model_estimator.h index 63bade9..550239c 100644 --- a/webrtc/modules/audio_processing/aec3/reverb_model_estimator.h +++ b/webrtc/modules/audio_processing/aec3/reverb_model_estimator.h @@ -13,9 +13,9 @@ #include #include +#include #include -#include "absl/types/optional.h" #include "api/array_view.h" #include "api/audio/echo_canceller3_config.h" #include "modules/audio_processing/aec3/aec3_common.h" // kFftLengthBy2Plus1 @@ -38,7 +38,7 @@ class ReverbModelEstimator { rtc::ArrayView> impulse_responses, rtc::ArrayView>> frequency_responses, - rtc::ArrayView> linear_filter_qualities, + rtc::ArrayView> linear_filter_qualities, rtc::ArrayView filter_delays_blocks, const std::vector& usable_linear_estimates, bool stationary_block); diff --git a/webrtc/modules/audio_processing/aec3/subtractor_output_analyzer.cc b/webrtc/modules/audio_processing/aec3/subtractor_output_analyzer.cc index baf0600..2b8c4c6 100644 --- a/webrtc/modules/audio_processing/aec3/subtractor_output_analyzer.cc +++ b/webrtc/modules/audio_processing/aec3/subtractor_output_analyzer.cc @@ -44,7 +44,7 @@ void SubtractorOutputAnalyzer::Update( bool coarse_filter_converged_strict = e2_coarse < 0.05f * y2 && y2 > kConvergenceThreshold; bool coarse_filter_converged_relaxed = - e2_coarse < 0.2f * y2 && y2 > kConvergenceThresholdLowLevel; + e2_coarse < 0.3f * y2 && y2 > kConvergenceThresholdLowLevel; float min_e2 = std::min(e2_refined, e2_coarse); bool filter_diverged = min_e2 > 1.5f * y2 && y2 > 30.f * 30.f * kBlockSize; filters_converged_[ch] = diff --git a/webrtc/modules/audio_processing/aec3/suppression_gain.cc b/webrtc/modules/audio_processing/aec3/suppression_gain.cc index 037daba..26797fc 100644 --- a/webrtc/modules/audio_processing/aec3/suppression_gain.cc +++ b/webrtc/modules/audio_processing/aec3/suppression_gain.cc @@ -107,7 +107,7 @@ float SuppressionGain::UpperBandsGain( rtc::ArrayView> echo_spectrum, rtc::ArrayView> comfort_noise_spectrum, - const absl::optional& narrow_peak_band, + const std::optional& narrow_peak_band, bool saturated_echo, const Block& render, const std::array& low_band_gain) const { @@ -394,7 +394,7 @@ void SuppressionGain::GetGain( low_band_gain); // Compute the gain for the upper bands. - const absl::optional narrow_peak_band = + const std::optional narrow_peak_band = render_signal_analyzer.NarrowPeakBand(); *high_bands_gain = diff --git a/webrtc/modules/audio_processing/aec3/suppression_gain.h b/webrtc/modules/audio_processing/aec3/suppression_gain.h index c19ddd7..806334c 100644 --- a/webrtc/modules/audio_processing/aec3/suppression_gain.h +++ b/webrtc/modules/audio_processing/aec3/suppression_gain.h @@ -14,9 +14,9 @@ #include #include #include +#include #include -#include "absl/types/optional.h" #include "api/array_view.h" #include "api/audio/echo_canceller3_config.h" #include "modules/audio_processing/aec3/aec3_common.h" @@ -70,7 +70,7 @@ class SuppressionGain { rtc::ArrayView> echo_spectrum, rtc::ArrayView> comfort_noise_spectrum, - const absl::optional& narrow_peak_band, + const std::optional& narrow_peak_band, bool saturated_echo, const Block& render, const std::array& low_band_gain) const; diff --git a/webrtc/modules/audio_processing/aec3/transparent_mode.cc b/webrtc/modules/audio_processing/aec3/transparent_mode.cc index 489f53f..4d6937f 100644 --- a/webrtc/modules/audio_processing/aec3/transparent_mode.cc +++ b/webrtc/modules/audio_processing/aec3/transparent_mode.cc @@ -19,6 +19,7 @@ namespace { constexpr size_t kBlocksSinceConvergencedFilterInit = 10000; constexpr size_t kBlocksSinceConsistentEstimateInit = 10000; +constexpr float kInitialTransparentStateProbability = 0.2f; bool DeactivateTransparentMode() { return field_trial::IsEnabled("WebRTC-Aec3TransparentModeKillSwitch"); @@ -41,7 +42,7 @@ class TransparentModeImpl : public TransparentMode { transparency_activated_ = false; // The estimated probability of being transparent mode. - prob_transparent_state_ = 0.f; + prob_transparent_state_ = kInitialTransparentStateProbability; } void Update(int filter_delay_blocks, @@ -118,7 +119,7 @@ class TransparentModeImpl : public TransparentMode { private: bool transparency_activated_ = false; - float prob_transparent_state_ = 0.f; + float prob_transparent_state_ = kInitialTransparentStateProbability; }; // Legacy classifier for toggling transparent mode. diff --git a/webrtc/modules/audio_processing/aec_dump/aec_dump_factory.h b/webrtc/modules/audio_processing/aec_dump/aec_dump_factory.h index 20718c3..0d258a9 100644 --- a/webrtc/modules/audio_processing/aec_dump/aec_dump_factory.h +++ b/webrtc/modules/audio_processing/aec_dump/aec_dump_factory.h @@ -13,34 +13,34 @@ #include +#include "absl/base/nullability.h" #include "absl/strings/string_view.h" +#include "api/task_queue/task_queue_base.h" #include "modules/audio_processing/include/aec_dump.h" #include "rtc_base/system/file_wrapper.h" #include "rtc_base/system/rtc_export.h" -namespace rtc { -class TaskQueue; -} // namespace rtc - namespace webrtc { class RTC_EXPORT AecDumpFactory { public: - // The `worker_queue` may not be null and must outlive the created - // AecDump instance. `max_log_size_bytes == -1` means the log size - // will be unlimited. `handle` may not be null. The AecDump takes - // responsibility for `handle` and closes it in the destructor. A - // non-null return value indicates that the file has been + // The `worker_queue` must outlive the created AecDump instance. + // `max_log_size_bytes == -1` means the log size will be unlimited. + // The AecDump takes responsibility for `handle` and closes it in the + // destructor. A non-null return value indicates that the file has been // sucessfully opened. - static std::unique_ptr Create(webrtc::FileWrapper file, - int64_t max_log_size_bytes, - rtc::TaskQueue* worker_queue); - static std::unique_ptr Create(absl::string_view file_name, - int64_t max_log_size_bytes, - rtc::TaskQueue* worker_queue); - static std::unique_ptr Create(FILE* handle, - int64_t max_log_size_bytes, - rtc::TaskQueue* worker_queue); + static absl::Nullable> Create( + FileWrapper file, + int64_t max_log_size_bytes, + absl::Nonnull worker_queue); + static absl::Nullable> Create( + absl::string_view file_name, + int64_t max_log_size_bytes, + absl::Nonnull worker_queue); + static absl::Nullable> Create( + absl::Nonnull handle, + int64_t max_log_size_bytes, + absl::Nonnull worker_queue); }; } // namespace webrtc diff --git a/webrtc/modules/audio_processing/aec_dump/null_aec_dump_factory.cc b/webrtc/modules/audio_processing/aec_dump/null_aec_dump_factory.cc index 9bd9745..63929af 100644 --- a/webrtc/modules/audio_processing/aec_dump/null_aec_dump_factory.cc +++ b/webrtc/modules/audio_processing/aec_dump/null_aec_dump_factory.cc @@ -8,27 +8,32 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include "absl/base/nullability.h" #include "absl/strings/string_view.h" +#include "api/task_queue/task_queue_base.h" #include "modules/audio_processing/aec_dump/aec_dump_factory.h" #include "modules/audio_processing/include/aec_dump.h" namespace webrtc { -std::unique_ptr AecDumpFactory::Create(webrtc::FileWrapper file, - int64_t max_log_size_bytes, - rtc::TaskQueue* worker_queue) { +absl::Nullable> AecDumpFactory::Create( + FileWrapper file, + int64_t max_log_size_bytes, + absl::Nonnull worker_queue) { return nullptr; } -std::unique_ptr AecDumpFactory::Create(absl::string_view file_name, - int64_t max_log_size_bytes, - rtc::TaskQueue* worker_queue) { +absl::Nullable> AecDumpFactory::Create( + absl::string_view file_name, + int64_t max_log_size_bytes, + absl::Nonnull worker_queue) { return nullptr; } -std::unique_ptr AecDumpFactory::Create(FILE* handle, - int64_t max_log_size_bytes, - rtc::TaskQueue* worker_queue) { +absl::Nullable> AecDumpFactory::Create( + absl::Nonnull handle, + int64_t max_log_size_bytes, + absl::Nonnull worker_queue) { return nullptr; } } // namespace webrtc diff --git a/webrtc/modules/audio_processing/agc/BUILD.gn b/webrtc/modules/audio_processing/agc/BUILD.gn index 508f901..f5bb272 100644 --- a/webrtc/modules/audio_processing/agc/BUILD.gn +++ b/webrtc/modules/audio_processing/agc/BUILD.gn @@ -21,11 +21,11 @@ rtc_library("agc") { deps = [ ":gain_control_interface", ":level_estimation", - "..:api", "..:apm_logging", "..:audio_buffer", "..:audio_frame_view", "../../../api:array_view", + "../../../api/audio:audio_processing", "../../../common_audio", "../../../common_audio:common_audio_c", "../../../rtc_base:checks", @@ -39,7 +39,6 @@ rtc_library("agc") { "../agc2:input_volume_stats_reporter", "../vad", ] - absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] } rtc_library("level_estimation") { @@ -117,10 +116,7 @@ if (rtc_include_tests) { "../../../test:fileutils", "../../../test:test_support", "//testing/gtest", - ] - absl_deps = [ - "//third_party/abseil-cpp/absl/strings", - "//third_party/abseil-cpp/absl/types:optional", + "//third_party/abseil-cpp/absl/strings:string_view", ] } } diff --git a/webrtc/modules/audio_processing/agc/agc_manager_direct.cc b/webrtc/modules/audio_processing/agc/agc_manager_direct.cc index b8ad4a8..18d84d8 100644 --- a/webrtc/modules/audio_processing/agc/agc_manager_direct.cc +++ b/webrtc/modules/audio_processing/agc/agc_manager_direct.cc @@ -69,11 +69,11 @@ using AnalogAgcConfig = // string. Returns an unspecified value if the field trial is not specified, if // disabled or if it cannot be parsed. Example: // 'WebRTC-Audio-2ndAgcMinMicLevelExperiment/Enabled-80' => returns 80. -absl::optional GetMinMicLevelOverride() { +std::optional GetMinMicLevelOverride() { constexpr char kMinMicLevelFieldTrial[] = "WebRTC-Audio-2ndAgcMinMicLevelExperiment"; if (!webrtc::field_trial::IsEnabled(kMinMicLevelFieldTrial)) { - return absl::nullopt; + return std::nullopt; } const auto field_trial_string = webrtc::field_trial::FindFullName(kMinMicLevelFieldTrial); @@ -84,7 +84,7 @@ absl::optional GetMinMicLevelOverride() { } else { RTC_LOG(LS_WARNING) << "[agc] Invalid parameter for " << kMinMicLevelFieldTrial << ", ignored."; - return absl::nullopt; + return std::nullopt; } } @@ -189,8 +189,8 @@ void MonoAgc::Initialize() { } void MonoAgc::Process(rtc::ArrayView audio, - absl::optional rms_error_override) { - new_compression_to_set_ = absl::nullopt; + std::optional rms_error_override) { + new_compression_to_set_ = std::nullopt; if (check_volume_on_next_process_) { check_volume_on_next_process_ = false; @@ -617,13 +617,13 @@ void AgcManagerDirect::AnalyzePreProcess(const AudioBuffer& audio_buffer) { } void AgcManagerDirect::Process(const AudioBuffer& audio_buffer) { - Process(audio_buffer, /*speech_probability=*/absl::nullopt, - /*speech_level_dbfs=*/absl::nullopt); + Process(audio_buffer, /*speech_probability=*/std::nullopt, + /*speech_level_dbfs=*/std::nullopt); } void AgcManagerDirect::Process(const AudioBuffer& audio_buffer, - absl::optional speech_probability, - absl::optional speech_level_dbfs) { + std::optional speech_probability, + std::optional speech_level_dbfs) { AggregateChannelLevels(); const int volume_after_clipping_handling = recommended_input_volume_; @@ -632,7 +632,7 @@ void AgcManagerDirect::Process(const AudioBuffer& audio_buffer, } const size_t num_frames_per_band = audio_buffer.num_frames_per_band(); - absl::optional rms_error_override = absl::nullopt; + std::optional rms_error_override = std::nullopt; if (speech_probability.has_value() && speech_level_dbfs.has_value()) { rms_error_override = GetSpeechLevelErrorDb(*speech_level_dbfs, *speech_probability); @@ -656,7 +656,7 @@ void AgcManagerDirect::Process(const AudioBuffer& audio_buffer, } } -absl::optional AgcManagerDirect::GetDigitalComressionGain() { +std::optional AgcManagerDirect::GetDigitalComressionGain() { return new_compressions_to_set_[channel_controlling_gain_]; } diff --git a/webrtc/modules/audio_processing/agc/agc_manager_direct.h b/webrtc/modules/audio_processing/agc/agc_manager_direct.h index adb2f5a..db2d27b 100644 --- a/webrtc/modules/audio_processing/agc/agc_manager_direct.h +++ b/webrtc/modules/audio_processing/agc/agc_manager_direct.h @@ -13,13 +13,13 @@ #include #include +#include -#include "absl/types/optional.h" #include "api/array_view.h" +#include "api/audio/audio_processing.h" #include "modules/audio_processing/agc/agc.h" #include "modules/audio_processing/agc2/clipping_predictor.h" #include "modules/audio_processing/audio_buffer.h" -#include "modules/audio_processing/include/audio_processing.h" #include "modules/audio_processing/logging/apm_data_dumper.h" #include "rtc_base/gtest_prod_util.h" @@ -75,8 +75,8 @@ class AgcManagerDirect final { // TODO(webrtc:7494): This signature is needed for testing purposes, unify // the signatures when the clean-up is done. void Process(const AudioBuffer& audio_buffer, - absl::optional speech_probability, - absl::optional speech_level_dbfs); + std::optional speech_probability, + std::optional speech_level_dbfs); // Processes `audio_buffer`. Chooses a digital compression gain and the new // input volume to recommend. Must be called after `AnalyzePreProcess()`. @@ -100,7 +100,7 @@ class AgcManagerDirect final { // If available, returns the latest digital compression gain that has been // chosen. - absl::optional GetDigitalComressionGain(); + std::optional GetDigitalComressionGain(); // Returns true if clipping prediction is enabled. bool clipping_predictor_enabled() const { return !!clipping_predictor_; } @@ -150,7 +150,7 @@ class AgcManagerDirect final { const bool analog_controller_enabled_; - const absl::optional min_mic_level_override_; + const std::optional min_mic_level_override_; std::unique_ptr data_dumper_; static std::atomic instance_counter_; const int num_capture_channels_; @@ -176,7 +176,7 @@ class AgcManagerDirect final { const int clipped_wait_frames_; std::vector> channel_agcs_; - std::vector> new_compressions_to_set_; + std::vector> new_compressions_to_set_; const std::unique_ptr clipping_predictor_; const bool use_clipping_predictor_step_; @@ -213,16 +213,14 @@ class MonoAgc { // after `HandleClipping()`. If `rms_error_override` has a value, RMS error // from AGC is overridden by it. void Process(rtc::ArrayView audio, - absl::optional rms_error_override); + std::optional rms_error_override); // Returns the recommended input volume. Must be called after `Process()`. int recommended_analog_level() const { return recommended_input_volume_; } float voice_probability() const { return agc_->voice_probability(); } void ActivateLogging() { log_to_histograms_ = true; } - absl::optional new_compression() const { - return new_compression_to_set_; - } + std::optional new_compression() const { return new_compression_to_set_; } // Only used for testing. void set_agc(Agc* agc) { agc_.reset(agc); } @@ -263,7 +261,7 @@ class MonoAgc { // recommended input volume. int recommended_input_volume_ = 0; - absl::optional new_compression_to_set_; + std::optional new_compression_to_set_; bool log_to_histograms_ = false; const int clipped_level_min_; diff --git a/webrtc/modules/audio_processing/agc2/BUILD.gn b/webrtc/modules/audio_processing/agc2/BUILD.gn index bd59ad3..5da168a 100644 --- a/webrtc/modules/audio_processing/agc2/BUILD.gn +++ b/webrtc/modules/audio_processing/agc2/BUILD.gn @@ -23,9 +23,9 @@ rtc_library("speech_level_estimator") { deps = [ ":common", - "..:api", "..:apm_logging", "../../../api:array_view", + "../../../api/audio:audio_processing", "../../../rtc_base:checks", "../../../rtc_base:logging", "../../../rtc_base:safe_minmax", @@ -48,9 +48,9 @@ rtc_library("adaptive_digital_gain_controller") { deps = [ ":common", ":gain_applier", - "..:api", "..:apm_logging", - "..:audio_frame_view", + "../../../api/audio:audio_frame_api", + "../../../api/audio:audio_processing", "../../../common_audio", "../../../rtc_base:checks", "../../../rtc_base:logging", @@ -81,8 +81,6 @@ rtc_library("saturation_protector") { "../../../rtc_base:safe_compare", "../../../rtc_base:safe_minmax", ] - - absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] } rtc_library("biquad_filter") { @@ -112,15 +110,13 @@ rtc_library("clipping_predictor") { deps = [ ":gain_map", - "..:api", "..:audio_frame_view", + "../../../api/audio:audio_processing", "../../../common_audio", "../../../rtc_base:checks", "../../../rtc_base:logging", "../../../rtc_base:safe_minmax", ] - - absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] } rtc_source_set("common") { @@ -150,6 +146,7 @@ rtc_library("fixed_digital") { "..:apm_logging", "..:audio_frame_view", "../../../api:array_view", + "../../../api/audio:audio_frame_api", "../../../common_audio", "../../../rtc_base:checks", "../../../rtc_base:gtest_prod", @@ -157,8 +154,8 @@ rtc_library("fixed_digital") { "../../../rtc_base:safe_minmax", "../../../rtc_base:stringutils", "../../../system_wrappers:metrics", + "//third_party/abseil-cpp/absl/strings:string_view", ] - absl_deps = [ "//third_party/abseil-cpp/absl/strings" ] } rtc_library("gain_applier") { @@ -175,7 +172,7 @@ rtc_library("gain_applier") { deps = [ ":common", "..:audio_frame_view", - "../../../api:array_view", + "../../../api/audio:audio_frame_api", "../../../rtc_base:safe_minmax", ] } @@ -209,10 +206,10 @@ rtc_library("input_volume_controller") { ":clipping_predictor", ":gain_map", ":input_volume_stats_reporter", - "..:api", "..:audio_buffer", "..:audio_frame_view", "../../../api:array_view", + "../../../api/audio:audio_processing", "../../../rtc_base:checks", "../../../rtc_base:checks", "../../../rtc_base:gtest_prod", @@ -222,8 +219,6 @@ rtc_library("input_volume_controller") { "../../../system_wrappers:field_trial", "../../../system_wrappers:metrics", ] - - absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] } rtc_library("noise_level_estimator") { @@ -234,8 +229,7 @@ rtc_library("noise_level_estimator") { deps = [ ":biquad_filter", "..:apm_logging", - "..:audio_frame_view", - "../../../api:array_view", + "../../../api/audio:audio_frame_api", "../../../rtc_base:checks", "../../../system_wrappers", ] @@ -268,8 +262,7 @@ rtc_library("vad_wrapper") { deps = [ ":common", ":cpu_features", - "..:audio_frame_view", - "../../../api:array_view", + "../../../api/audio:audio_frame_api", "../../../common_audio", "../../../rtc_base:checks", "rnn_vad", @@ -303,8 +296,8 @@ rtc_library("speech_level_estimator_unittest") { deps = [ ":common", ":speech_level_estimator", - "..:api", "..:apm_logging", + "../../../api/audio:audio_processing", "../../../rtc_base:gunit_helpers", "../../../test:test_support", ] @@ -320,9 +313,9 @@ rtc_library("adaptive_digital_gain_controller_unittest") { ":adaptive_digital_gain_controller", ":common", ":test_utils", - "..:api", "..:apm_logging", "..:audio_frame_view", + "../../../api/audio:audio_processing", "../../../common_audio", "../../../rtc_base:gunit_helpers", "../../../test:test_support", @@ -337,7 +330,7 @@ rtc_library("gain_applier_unittest") { deps = [ ":gain_applier", ":test_utils", - "..:audio_frame_view", + "../../../api/audio:audio_frame_api", "../../../rtc_base:gunit_helpers", "../../../test:test_support", ] @@ -391,6 +384,7 @@ rtc_library("fixed_digital_unittests") { "..:apm_logging", "..:audio_frame_view", "../../../api:array_view", + "../../../api/audio:audio_frame_api", "../../../common_audio", "../../../rtc_base:checks", "../../../rtc_base:gunit_helpers", @@ -413,7 +407,6 @@ rtc_library("input_volume_controller_unittests") { ":clipping_predictor", ":gain_map", ":input_volume_controller", - "..:api", "../../../api:array_view", "../../../rtc_base:checks", "../../../rtc_base:random", @@ -426,8 +419,6 @@ rtc_library("input_volume_controller_unittests") { "../../../test:test_support", "//testing/gtest", ] - - absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] } rtc_library("noise_estimator_unittests") { @@ -439,9 +430,8 @@ rtc_library("noise_estimator_unittests") { ":noise_level_estimator", ":test_utils", "..:apm_logging", - "..:audio_frame_view", - "../../../api:array_view", "../../../api:function_view", + "../../../api/audio:audio_frame_api", "../../../rtc_base:checks", "../../../rtc_base:gunit_helpers", ] @@ -453,7 +443,7 @@ rtc_library("vad_wrapper_unittests") { deps = [ ":common", ":vad_wrapper", - "..:audio_frame_view", + "../../../api/audio:audio_frame_api", "../../../rtc_base:checks", "../../../rtc_base:gunit_helpers", "../../../rtc_base:safe_compare", @@ -475,6 +465,7 @@ rtc_library("test_utils") { ] deps = [ "..:audio_frame_view", + "../../../api/audio:audio_frame_api", "../../../rtc_base:checks", "../../../rtc_base:random", ] @@ -491,10 +482,7 @@ rtc_library("input_volume_stats_reporter") { "../../../rtc_base:safe_minmax", "../../../rtc_base:stringutils", "../../../system_wrappers:metrics", - ] - absl_deps = [ - "//third_party/abseil-cpp/absl/strings", - "//third_party/abseil-cpp/absl/types:optional", + "//third_party/abseil-cpp/absl/strings:string_view", ] } @@ -506,6 +494,6 @@ rtc_library("input_volume_stats_reporter_unittests") { "../../../rtc_base:stringutils", "../../../system_wrappers:metrics", "../../../test:test_support", + "//third_party/abseil-cpp/absl/strings:string_view", ] - absl_deps = [ "//third_party/abseil-cpp/absl/strings" ] } diff --git a/webrtc/modules/audio_processing/agc2/adaptive_digital_gain_controller.cc b/webrtc/modules/audio_processing/agc2/adaptive_digital_gain_controller.cc index e8edab6..5f924cb 100644 --- a/webrtc/modules/audio_processing/agc2/adaptive_digital_gain_controller.cc +++ b/webrtc/modules/audio_processing/agc2/adaptive_digital_gain_controller.cc @@ -124,7 +124,7 @@ AdaptiveDigitalGainController::AdaptiveDigitalGainController( } void AdaptiveDigitalGainController::Process(const FrameInfo& info, - AudioFrameView frame) { + DeinterleavedView frame) { RTC_DCHECK_GE(info.speech_level_dbfs, -150.0f); RTC_DCHECK_GE(frame.num_channels(), 1); RTC_DCHECK( diff --git a/webrtc/modules/audio_processing/agc2/adaptive_digital_gain_controller.h b/webrtc/modules/audio_processing/agc2/adaptive_digital_gain_controller.h index 01335e7..d464dc6 100644 --- a/webrtc/modules/audio_processing/agc2/adaptive_digital_gain_controller.h +++ b/webrtc/modules/audio_processing/agc2/adaptive_digital_gain_controller.h @@ -13,9 +13,9 @@ #include +#include "api/audio/audio_processing.h" +#include "api/audio/audio_view.h" #include "modules/audio_processing/agc2/gain_applier.h" -#include "modules/audio_processing/include/audio_frame_view.h" -#include "modules/audio_processing/include/audio_processing.h" namespace webrtc { @@ -46,7 +46,7 @@ class AdaptiveDigitalGainController { // Analyzes `info`, updates the digital gain and applies it to a 10 ms // `frame`. Supports any sample rate supported by APM. - void Process(const FrameInfo& info, AudioFrameView frame); + void Process(const FrameInfo& info, DeinterleavedView frame); private: ApmDataDumper* const apm_data_dumper_; diff --git a/webrtc/modules/audio_processing/agc2/clipping_predictor.cc b/webrtc/modules/audio_processing/agc2/clipping_predictor.cc index fd759c6..06115a3 100644 --- a/webrtc/modules/audio_processing/agc2/clipping_predictor.cc +++ b/webrtc/modules/audio_processing/agc2/clipping_predictor.cc @@ -131,11 +131,11 @@ class ClippingEventPredictor : public ClippingPredictor { // if at least `GetMinFramesProcessed()` frames have been processed since the // last reset and a clipping event is predicted. `level`, `min_mic_level`, and // `max_mic_level` are limited to [0, 255] and `default_step` to [1, 255]. - absl::optional EstimateClippedLevelStep(int channel, - int level, - int default_step, - int min_mic_level, - int max_mic_level) const { + std::optional EstimateClippedLevelStep(int channel, + int level, + int default_step, + int min_mic_level, + int max_mic_level) const { RTC_CHECK_GE(channel, 0); RTC_CHECK_LT(channel, ch_buffers_.size()); RTC_DCHECK_GE(level, 0); @@ -147,7 +147,7 @@ class ClippingEventPredictor : public ClippingPredictor { RTC_DCHECK_GE(max_mic_level, 0); RTC_DCHECK_LE(max_mic_level, 255); if (level <= min_mic_level) { - return absl::nullopt; + return std::nullopt; } if (PredictClippingEvent(channel)) { const int new_level = @@ -157,7 +157,7 @@ class ClippingEventPredictor : public ClippingPredictor { return step; } } - return absl::nullopt; + return std::nullopt; } private: @@ -271,11 +271,11 @@ class ClippingPeakPredictor : public ClippingPredictor { // least `GetMinFramesProcessed()` frames have been processed since the last // reset and a clipping event is predicted. `level`, `min_mic_level`, and // `max_mic_level` are limited to [0, 255] and `default_step` to [1, 255]. - absl::optional EstimateClippedLevelStep(int channel, - int level, - int default_step, - int min_mic_level, - int max_mic_level) const { + std::optional EstimateClippedLevelStep(int channel, + int level, + int default_step, + int min_mic_level, + int max_mic_level) const { RTC_DCHECK_GE(channel, 0); RTC_DCHECK_LT(channel, ch_buffers_.size()); RTC_DCHECK_GE(level, 0); @@ -287,9 +287,9 @@ class ClippingPeakPredictor : public ClippingPredictor { RTC_DCHECK_GE(max_mic_level, 0); RTC_DCHECK_LE(max_mic_level, 255); if (level <= min_mic_level) { - return absl::nullopt; + return std::nullopt; } - absl::optional estimate_db = EstimatePeakValue(channel); + std::optional estimate_db = EstimatePeakValue(channel); if (estimate_db.has_value() && estimate_db.value() > clipping_threshold_) { int step = 0; if (!adaptive_step_estimation_) { @@ -309,7 +309,7 @@ class ClippingPeakPredictor : public ClippingPredictor { return level - new_level; } } - return absl::nullopt; + return std::nullopt; } private: @@ -319,18 +319,18 @@ class ClippingPeakPredictor : public ClippingPredictor { // Predicts clipping sample peaks based on the processed audio frames. // Returns the estimated peak value if clipping is predicted. Otherwise - // returns absl::nullopt. - absl::optional EstimatePeakValue(int channel) const { + // returns std::nullopt. + std::optional EstimatePeakValue(int channel) const { const auto reference_metrics = ch_buffers_[channel]->ComputePartialMetrics( reference_window_delay_, reference_window_length_); if (!reference_metrics.has_value()) { - return absl::nullopt; + return std::nullopt; } const auto metrics = ch_buffers_[channel]->ComputePartialMetrics(0, window_length_); if (!metrics.has_value() || !(FloatS16ToDbfs(metrics.value().max) > clipping_threshold_)) { - return absl::nullopt; + return std::nullopt; } const float reference_crest_factor = ComputeCrestFactor(reference_metrics.value()); diff --git a/webrtc/modules/audio_processing/agc2/clipping_predictor.h b/webrtc/modules/audio_processing/agc2/clipping_predictor.h index 1461250..3fd1086 100644 --- a/webrtc/modules/audio_processing/agc2/clipping_predictor.h +++ b/webrtc/modules/audio_processing/agc2/clipping_predictor.h @@ -12,11 +12,11 @@ #define MODULES_AUDIO_PROCESSING_AGC2_CLIPPING_PREDICTOR_H_ #include +#include #include -#include "absl/types/optional.h" +#include "api/audio/audio_processing.h" #include "modules/audio_processing/include/audio_frame_view.h" -#include "modules/audio_processing/include/audio_processing.h" namespace webrtc { @@ -35,12 +35,12 @@ class ClippingPredictor { // Predicts if clipping is going to occur for the specified `channel` in the // near-future and, if so, it returns a recommended analog mic level decrease - // step. Returns absl::nullopt if clipping is not predicted. + // step. Returns std::nullopt if clipping is not predicted. // `level` is the current analog mic level, `default_step` is the amount the // mic level is lowered by the analog controller with every clipping event and // `min_mic_level` and `max_mic_level` is the range of allowed analog mic // levels. - virtual absl::optional EstimateClippedLevelStep( + virtual std::optional EstimateClippedLevelStep( int channel, int level, int default_step, diff --git a/webrtc/modules/audio_processing/agc2/clipping_predictor_level_buffer.cc b/webrtc/modules/audio_processing/agc2/clipping_predictor_level_buffer.cc index fe4cf2a..acc114c 100644 --- a/webrtc/modules/audio_processing/agc2/clipping_predictor_level_buffer.cc +++ b/webrtc/modules/audio_processing/agc2/clipping_predictor_level_buffer.cc @@ -50,7 +50,7 @@ void ClippingPredictorLevelBuffer::Push(Level level) { } // TODO(bugs.webrtc.org/12774): Optimize partial computation for long buffers. -absl::optional +std::optional ClippingPredictorLevelBuffer::ComputePartialMetrics(int delay, int num_items) const { RTC_DCHECK_GE(delay, 0); @@ -59,7 +59,7 @@ ClippingPredictorLevelBuffer::ComputePartialMetrics(int delay, RTC_DCHECK_LE(num_items, Capacity()); RTC_DCHECK_LE(delay + num_items, Capacity()); if (delay + num_items > Size()) { - return absl::nullopt; + return std::nullopt; } float sum = 0.0f; float max = 0.0f; @@ -71,7 +71,7 @@ ClippingPredictorLevelBuffer::ComputePartialMetrics(int delay, sum += data_[idx].average; max = std::fmax(data_[idx].max, max); } - return absl::optional({sum / static_cast(num_items), max}); + return std::optional({sum / static_cast(num_items), max}); } } // namespace webrtc diff --git a/webrtc/modules/audio_processing/agc2/clipping_predictor_level_buffer.h b/webrtc/modules/audio_processing/agc2/clipping_predictor_level_buffer.h index c903277..21e9b46 100644 --- a/webrtc/modules/audio_processing/agc2/clipping_predictor_level_buffer.h +++ b/webrtc/modules/audio_processing/agc2/clipping_predictor_level_buffer.h @@ -12,10 +12,9 @@ #define MODULES_AUDIO_PROCESSING_AGC2_CLIPPING_PREDICTOR_LEVEL_BUFFER_H_ #include +#include #include -#include "absl/types/optional.h" - namespace webrtc { // A circular buffer to store frame-wise `Level` items for clipping prediction. @@ -58,7 +57,7 @@ class ClippingPredictorLevelBuffer { // from `delay` to `delay` - `num_items` (a delay equal to zero corresponds // to the most recently pushed item). The value of `delay` is limited to // [0, N] and `num_items` to [1, M] where N + M is the capacity of the buffer. - absl::optional ComputePartialMetrics(int delay, int num_items) const; + std::optional ComputePartialMetrics(int delay, int num_items) const; private: int tail_; diff --git a/webrtc/modules/audio_processing/agc2/fixed_digital_level_estimator.cc b/webrtc/modules/audio_processing/agc2/fixed_digital_level_estimator.cc index 1995b24..73edcf0 100644 --- a/webrtc/modules/audio_processing/agc2/fixed_digital_level_estimator.cc +++ b/webrtc/modules/audio_processing/agc2/fixed_digital_level_estimator.cc @@ -14,6 +14,7 @@ #include #include "api/array_view.h" +#include "api/audio/audio_frame.h" #include "modules/audio_processing/logging/apm_data_dumper.h" #include "rtc_base/checks.h" @@ -34,14 +35,17 @@ constexpr float kDecayFilterConstant = 0.9971259f; } // namespace FixedDigitalLevelEstimator::FixedDigitalLevelEstimator( - int sample_rate_hz, + size_t samples_per_channel, ApmDataDumper* apm_data_dumper) : apm_data_dumper_(apm_data_dumper), filter_state_level_(kInitialFilterStateLevel) { - SetSampleRate(sample_rate_hz); + SetSamplesPerChannel(samples_per_channel); CheckParameterCombination(); RTC_DCHECK(apm_data_dumper_); - apm_data_dumper_->DumpRaw("agc2_level_estimator_samplerate", sample_rate_hz); + // Convert `samples_per_channel` to sample rate for + // `agc2_level_estimator_samplerate`. + apm_data_dumper_->DumpRaw("agc2_level_estimator_samplerate", + samples_per_channel * kDefaultAudioBuffersPerSec); } void FixedDigitalLevelEstimator::CheckParameterCombination() { @@ -52,15 +56,15 @@ void FixedDigitalLevelEstimator::CheckParameterCombination() { } std::array FixedDigitalLevelEstimator::ComputeLevel( - const AudioFrameView& float_frame) { + DeinterleavedView float_frame) { RTC_DCHECK_GT(float_frame.num_channels(), 0); RTC_DCHECK_EQ(float_frame.samples_per_channel(), samples_in_frame_); // Compute max envelope without smoothing. std::array envelope{}; - for (int channel_idx = 0; channel_idx < float_frame.num_channels(); + for (size_t channel_idx = 0; channel_idx < float_frame.num_channels(); ++channel_idx) { - const auto channel = float_frame.channel(channel_idx); + const auto channel = float_frame[channel_idx]; for (int sub_frame = 0; sub_frame < kSubFramesInFrame; ++sub_frame) { for (int sample_in_sub_frame = 0; sample_in_sub_frame < samples_in_sub_frame_; ++sample_in_sub_frame) { @@ -95,7 +99,7 @@ std::array FixedDigitalLevelEstimator::ComputeLevel( // Dump data for debug. RTC_DCHECK(apm_data_dumper_); - const auto channel = float_frame.channel(0); + const auto channel = float_frame[0]; apm_data_dumper_->DumpRaw("agc2_level_estimator_samples", samples_in_sub_frame_, &channel[sub_frame * samples_in_sub_frame_]); @@ -106,9 +110,9 @@ std::array FixedDigitalLevelEstimator::ComputeLevel( return envelope; } -void FixedDigitalLevelEstimator::SetSampleRate(int sample_rate_hz) { - samples_in_frame_ = - rtc::CheckedDivExact(sample_rate_hz * kFrameDurationMs, 1000); +void FixedDigitalLevelEstimator::SetSamplesPerChannel( + size_t samples_per_channel) { + samples_in_frame_ = static_cast(samples_per_channel); samples_in_sub_frame_ = rtc::CheckedDivExact(samples_in_frame_, kSubFramesInFrame); CheckParameterCombination(); diff --git a/webrtc/modules/audio_processing/agc2/fixed_digital_level_estimator.h b/webrtc/modules/audio_processing/agc2/fixed_digital_level_estimator.h index d26b559..1669acd 100644 --- a/webrtc/modules/audio_processing/agc2/fixed_digital_level_estimator.h +++ b/webrtc/modules/audio_processing/agc2/fixed_digital_level_estimator.h @@ -25,12 +25,16 @@ class ApmDataDumper; // filtering. class FixedDigitalLevelEstimator { public: - // Sample rates are allowed if the number of samples in a frame - // (sample_rate_hz * kFrameDurationMs / 1000) is divisible by + // `samples_per_channel` is expected to be derived from this formula: + // sample_rate_hz * kFrameDurationMs / 1000 + // or, for a 10ms duration: + // sample_rate_hz / 100 + // I.e. the number of samples for 10ms of the given sample rate. The + // expectation is that samples per channel is divisible by // kSubFramesInSample. For kFrameDurationMs=10 and - // kSubFramesInSample=20, this means that sample_rate_hz has to be - // divisible by 2000. - FixedDigitalLevelEstimator(int sample_rate_hz, + // kSubFramesInSample=20, this means that the original sample rate has to be + // divisible by 2000 and therefore `samples_per_channel` by 20. + FixedDigitalLevelEstimator(size_t samples_per_channel, ApmDataDumper* apm_data_dumper); FixedDigitalLevelEstimator(const FixedDigitalLevelEstimator&) = delete; @@ -42,11 +46,11 @@ class FixedDigitalLevelEstimator { // ms of audio produces a level estimates in the same scale. The // level estimate contains kSubFramesInFrame values. std::array ComputeLevel( - const AudioFrameView& float_frame); + DeinterleavedView float_frame); // Rate may be changed at any time (but not concurrently) from the // value passed to the constructor. The class is not thread safe. - void SetSampleRate(int sample_rate_hz); + void SetSamplesPerChannel(size_t samples_per_channel); // Resets the level estimator internal state. void Reset(); diff --git a/webrtc/modules/audio_processing/agc2/gain_applier.cc b/webrtc/modules/audio_processing/agc2/gain_applier.cc index f9e276d..f833ad1 100644 --- a/webrtc/modules/audio_processing/agc2/gain_applier.cc +++ b/webrtc/modules/audio_processing/agc2/gain_applier.cc @@ -10,7 +10,7 @@ #include "modules/audio_processing/agc2/gain_applier.h" -#include "api/array_view.h" +#include "api/audio/audio_view.h" #include "modules/audio_processing/agc2/agc2_common.h" #include "rtc_base/numerics/safe_minmax.h" @@ -24,9 +24,9 @@ bool GainCloseToOne(float gain_factor) { gain_factor <= 1.f + 1.f / kMaxFloatS16Value; } -void ClipSignal(AudioFrameView signal) { - for (int k = 0; k < signal.num_channels(); ++k) { - rtc::ArrayView channel_view = signal.channel(k); +void ClipSignal(DeinterleavedView signal) { + for (size_t k = 0; k < signal.num_channels(); ++k) { + MonoView channel_view = signal[k]; for (auto& sample : channel_view) { sample = rtc::SafeClamp(sample, kMinFloatS16Value, kMaxFloatS16Value); } @@ -36,7 +36,7 @@ void ClipSignal(AudioFrameView signal) { void ApplyGainWithRamping(float last_gain_linear, float gain_at_end_of_frame_linear, float inverse_samples_per_channel, - AudioFrameView float_frame) { + DeinterleavedView float_frame) { // Do not modify the signal. if (last_gain_linear == gain_at_end_of_frame_linear && GainCloseToOne(gain_at_end_of_frame_linear)) { @@ -45,8 +45,8 @@ void ApplyGainWithRamping(float last_gain_linear, // Gain is constant and different from 1. if (last_gain_linear == gain_at_end_of_frame_linear) { - for (int k = 0; k < float_frame.num_channels(); ++k) { - rtc::ArrayView channel_view = float_frame.channel(k); + for (size_t k = 0; k < float_frame.num_channels(); ++k) { + MonoView channel_view = float_frame[k]; for (auto& sample : channel_view) { sample *= gain_at_end_of_frame_linear; } @@ -57,12 +57,12 @@ void ApplyGainWithRamping(float last_gain_linear, // The gain changes. We have to change slowly to avoid discontinuities. const float increment = (gain_at_end_of_frame_linear - last_gain_linear) * inverse_samples_per_channel; - float gain = last_gain_linear; - for (int i = 0; i < float_frame.samples_per_channel(); ++i) { - for (int ch = 0; ch < float_frame.num_channels(); ++ch) { - float_frame.channel(ch)[i] *= gain; + for (size_t ch = 0; ch < float_frame.num_channels(); ++ch) { + float gain = last_gain_linear; + for (float& sample : float_frame[ch]) { + sample *= gain; + gain += increment; } - gain += increment; } } @@ -73,7 +73,7 @@ GainApplier::GainApplier(bool hard_clip_samples, float initial_gain_factor) last_gain_factor_(initial_gain_factor), current_gain_factor_(initial_gain_factor) {} -void GainApplier::ApplyGain(AudioFrameView signal) { +void GainApplier::ApplyGain(DeinterleavedView signal) { if (static_cast(signal.samples_per_channel()) != samples_per_channel_) { Initialize(signal.samples_per_channel()); } diff --git a/webrtc/modules/audio_processing/agc2/gain_applier.h b/webrtc/modules/audio_processing/agc2/gain_applier.h index ba8a4a4..82ae82e 100644 --- a/webrtc/modules/audio_processing/agc2/gain_applier.h +++ b/webrtc/modules/audio_processing/agc2/gain_applier.h @@ -13,6 +13,7 @@ #include +#include "api/audio/audio_view.h" #include "modules/audio_processing/include/audio_frame_view.h" namespace webrtc { @@ -20,10 +21,15 @@ class GainApplier { public: GainApplier(bool hard_clip_samples, float initial_gain_factor); - void ApplyGain(AudioFrameView signal); + void ApplyGain(DeinterleavedView signal); void SetGainFactor(float gain_factor); float GetGainFactor() const { return current_gain_factor_; } + [[deprecated("Use DeinterleavedView<> version")]] void ApplyGain( + AudioFrameView signal) { + ApplyGain(signal.view()); + } + private: void Initialize(int samples_per_channel); diff --git a/webrtc/modules/audio_processing/agc2/input_volume_controller.cc b/webrtc/modules/audio_processing/agc2/input_volume_controller.cc index bcc650f..fcb8f1d 100644 --- a/webrtc/modules/audio_processing/agc2/input_volume_controller.cc +++ b/webrtc/modules/audio_processing/agc2/input_volume_controller.cc @@ -173,7 +173,7 @@ void MonoInputVolumeController::Initialize() { // previous update and the ratio of non-silence frames (i.e., frames with a // `speech_probability` higher than `speech_probability_threshold_`) is at least // `speech_ratio_threshold_`. -void MonoInputVolumeController::Process(absl::optional rms_error_db, +void MonoInputVolumeController::Process(std::optional rms_error_db, float speech_probability) { if (check_volume_on_next_process_) { check_volume_on_next_process_ = false; @@ -404,7 +404,7 @@ void InputVolumeController::Initialize() { clipping_rate_log_ = 0.0f; clipping_rate_log_counter_ = 0; - applied_input_volume_ = absl::nullopt; + applied_input_volume_ = std::nullopt; } void InputVolumeController::AnalyzeInputAudio(int applied_input_volume, @@ -498,13 +498,13 @@ void InputVolumeController::AnalyzeInputAudio(int applied_input_volume, AggregateChannelLevels(); } -absl::optional InputVolumeController::RecommendInputVolume( +std::optional InputVolumeController::RecommendInputVolume( float speech_probability, - absl::optional speech_level_dbfs) { + std::optional speech_level_dbfs) { // Only process if applied input volume is set. if (!applied_input_volume_.has_value()) { RTC_LOG(LS_ERROR) << "[AGC2] Applied input volume not set."; - return absl::nullopt; + return std::nullopt; } AggregateChannelLevels(); @@ -514,7 +514,7 @@ absl::optional InputVolumeController::RecommendInputVolume( return applied_input_volume_; } - absl::optional rms_error_db; + std::optional rms_error_db; if (speech_level_dbfs.has_value()) { // Compute the error for all frames (both speech and non-speech frames). rms_error_db = GetSpeechLevelRmsErrorDb( @@ -533,7 +533,7 @@ absl::optional InputVolumeController::RecommendInputVolume( recommended_input_volume_); } - applied_input_volume_ = absl::nullopt; + applied_input_volume_ = std::nullopt; return recommended_input_volume(); } diff --git a/webrtc/modules/audio_processing/agc2/input_volume_controller.h b/webrtc/modules/audio_processing/agc2/input_volume_controller.h index 2140554..60e76d8 100644 --- a/webrtc/modules/audio_processing/agc2/input_volume_controller.h +++ b/webrtc/modules/audio_processing/agc2/input_volume_controller.h @@ -12,13 +12,13 @@ #define MODULES_AUDIO_PROCESSING_AGC2_INPUT_VOLUME_CONTROLLER_H_ #include +#include #include -#include "absl/types/optional.h" #include "api/array_view.h" +#include "api/audio/audio_processing.h" #include "modules/audio_processing/agc2/clipping_predictor.h" #include "modules/audio_processing/audio_buffer.h" -#include "modules/audio_processing/include/audio_processing.h" #include "rtc_base/gtest_prod_util.h" namespace webrtc { @@ -50,7 +50,7 @@ class InputVolumeController final { // Limited to values higher than 0. int clipped_wait_frames = 300; // Enables clipping prediction functionality. - bool enable_clipping_predictor = false; + bool enable_clipping_predictor = true; // Speech level target range (dBFS). If the speech level is in the range // [`target_range_min_dbfs`, `target_range_max_dbfs`], no input volume // adjustments are done based on the speech level. For speech levels below @@ -95,9 +95,9 @@ class InputVolumeController final { // suppression are applied. Returns a non-empty input volume recommendation if // available. If `capture_output_used_` is true, returns the applied input // volume. - absl::optional RecommendInputVolume( + std::optional RecommendInputVolume( float speech_probability, - absl::optional speech_level_dbfs); + std::optional speech_level_dbfs); // Stores whether the capture output will be used or not. Call when the // capture stream output has been flagged to be used/not-used. If unused, the @@ -155,7 +155,7 @@ class InputVolumeController final { int recommended_input_volume_ = 0; // Applied input volume. After `SetAppliedInputVolume()` is called it holds // the current applied volume. - absl::optional applied_input_volume_; + std::optional applied_input_volume_; bool capture_output_used_; @@ -213,7 +213,7 @@ class MonoInputVolumeController { // result of `HandleClipping()` and on `rms_error_dbfs`. Updates are only // allowed for active speech segments and when `rms_error_dbfs` is not empty. // Must be called after `HandleClipping()`. - void Process(absl::optional rms_error_dbfs, float speech_probability); + void Process(std::optional rms_error_dbfs, float speech_probability); // Returns the recommended input volume. Must be called after `Process()`. int recommended_analog_level() const { return recommended_input_volume_; } diff --git a/webrtc/modules/audio_processing/agc2/input_volume_stats_reporter.h b/webrtc/modules/audio_processing/agc2/input_volume_stats_reporter.h index 31b1100..2f31aa0 100644 --- a/webrtc/modules/audio_processing/agc2/input_volume_stats_reporter.h +++ b/webrtc/modules/audio_processing/agc2/input_volume_stats_reporter.h @@ -11,7 +11,8 @@ #ifndef MODULES_AUDIO_PROCESSING_AGC2_INPUT_VOLUME_STATS_REPORTER_H_ #define MODULES_AUDIO_PROCESSING_AGC2_INPUT_VOLUME_STATS_REPORTER_H_ -#include "absl/types/optional.h" +#include + #include "rtc_base/gtest_prod_util.h" #include "system_wrappers/include/metrics.h" @@ -83,7 +84,7 @@ class InputVolumeStatsReporter { const bool cannot_log_stats_; int log_volume_update_stats_counter_ = 0; - absl::optional previous_input_volume_ = absl::nullopt; + std::optional previous_input_volume_ = std::nullopt; }; // Updates the histogram that keeps track of recommended input volume changes diff --git a/webrtc/modules/audio_processing/agc2/limiter.cc b/webrtc/modules/audio_processing/agc2/limiter.cc index 7a1e220..7a99b94 100644 --- a/webrtc/modules/audio_processing/agc2/limiter.cc +++ b/webrtc/modules/audio_processing/agc2/limiter.cc @@ -46,22 +46,20 @@ void InterpolateFirstSubframe(float last_factor, void ComputePerSampleSubframeFactors( const std::array& scaling_factors, - int samples_per_channel, - rtc::ArrayView per_sample_scaling_factors) { - const int num_subframes = scaling_factors.size() - 1; - const int subframe_size = - rtc::CheckedDivExact(samples_per_channel, num_subframes); + MonoView per_sample_scaling_factors) { + const size_t num_subframes = scaling_factors.size() - 1; + const int subframe_size = rtc::CheckedDivExact( + SamplesPerChannel(per_sample_scaling_factors), num_subframes); // Handle first sub-frame differently in case of attack. const bool is_attack = scaling_factors[0] > scaling_factors[1]; if (is_attack) { InterpolateFirstSubframe( scaling_factors[0], scaling_factors[1], - rtc::ArrayView( - per_sample_scaling_factors.subview(0, subframe_size))); + per_sample_scaling_factors.subview(0, subframe_size)); } - for (int i = is_attack ? 1 : 0; i < num_subframes; ++i) { + for (size_t i = is_attack ? 1 : 0; i < num_subframes; ++i) { const int subframe_start = i * subframe_size; const float scaling_start = scaling_factors[i]; const float scaling_end = scaling_factors[i + 1]; @@ -73,39 +71,36 @@ void ComputePerSampleSubframeFactors( } } -void ScaleSamples(rtc::ArrayView per_sample_scaling_factors, - AudioFrameView signal) { +void ScaleSamples(MonoView per_sample_scaling_factors, + DeinterleavedView signal) { const int samples_per_channel = signal.samples_per_channel(); - RTC_DCHECK_EQ(samples_per_channel, per_sample_scaling_factors.size()); - for (int i = 0; i < signal.num_channels(); ++i) { - rtc::ArrayView channel = signal.channel(i); + RTC_DCHECK_EQ(samples_per_channel, + SamplesPerChannel(per_sample_scaling_factors)); + for (size_t i = 0; i < signal.num_channels(); ++i) { + MonoView channel = signal[i]; for (int j = 0; j < samples_per_channel; ++j) { channel[j] = rtc::SafeClamp(channel[j] * per_sample_scaling_factors[j], kMinFloatS16Value, kMaxFloatS16Value); } } } - -void CheckLimiterSampleRate(int sample_rate_hz) { - // Check that per_sample_scaling_factors_ is large enough. - RTC_DCHECK_LE(sample_rate_hz, - kMaximalNumberOfSamplesPerChannel * 1000 / kFrameDurationMs); -} - } // namespace -Limiter::Limiter(int sample_rate_hz, - ApmDataDumper* apm_data_dumper, +Limiter::Limiter(ApmDataDumper* apm_data_dumper, + size_t samples_per_channel, absl::string_view histogram_name) : interp_gain_curve_(apm_data_dumper, histogram_name), - level_estimator_(sample_rate_hz, apm_data_dumper), + level_estimator_(samples_per_channel, apm_data_dumper), apm_data_dumper_(apm_data_dumper) { - CheckLimiterSampleRate(sample_rate_hz); + RTC_DCHECK_LE(samples_per_channel, kMaximalNumberOfSamplesPerChannel); } Limiter::~Limiter() = default; -void Limiter::Process(AudioFrameView signal) { +void Limiter::Process(DeinterleavedView signal) { + RTC_DCHECK_LE(signal.samples_per_channel(), + kMaximalNumberOfSamplesPerChannel); + const std::array level_estimate = level_estimator_.ComputeLevel(signal); @@ -116,13 +111,9 @@ void Limiter::Process(AudioFrameView signal) { return interp_gain_curve_.LookUpGainToApply(x); }); - const int samples_per_channel = signal.samples_per_channel(); - RTC_DCHECK_LE(samples_per_channel, kMaximalNumberOfSamplesPerChannel); - - auto per_sample_scaling_factors = rtc::ArrayView( - &per_sample_scaling_factors_[0], samples_per_channel); - ComputePerSampleSubframeFactors(scaling_factors_, samples_per_channel, - per_sample_scaling_factors); + MonoView per_sample_scaling_factors(&per_sample_scaling_factors_[0], + signal.samples_per_channel()); + ComputePerSampleSubframeFactors(scaling_factors_, per_sample_scaling_factors); ScaleSamples(per_sample_scaling_factors, signal); last_scaling_factor_ = scaling_factors_.back(); @@ -139,9 +130,9 @@ InterpolatedGainCurve::Stats Limiter::GetGainCurveStats() const { return interp_gain_curve_.get_stats(); } -void Limiter::SetSampleRate(int sample_rate_hz) { - CheckLimiterSampleRate(sample_rate_hz); - level_estimator_.SetSampleRate(sample_rate_hz); +void Limiter::SetSamplesPerChannel(size_t samples_per_channel) { + RTC_DCHECK_LE(samples_per_channel, kMaximalNumberOfSamplesPerChannel); + level_estimator_.SetSamplesPerChannel(samples_per_channel); } void Limiter::Reset() { diff --git a/webrtc/modules/audio_processing/agc2/limiter.h b/webrtc/modules/audio_processing/agc2/limiter.h index d4d5563..55cb1a5 100644 --- a/webrtc/modules/audio_processing/agc2/limiter.h +++ b/webrtc/modules/audio_processing/agc2/limiter.h @@ -14,6 +14,7 @@ #include #include "absl/strings/string_view.h" +#include "api/audio/audio_frame.h" #include "modules/audio_processing/agc2/fixed_digital_level_estimator.h" #include "modules/audio_processing/agc2/interpolated_gain_curve.h" #include "modules/audio_processing/include/audio_frame_view.h" @@ -23,23 +24,25 @@ class ApmDataDumper; class Limiter { public: - Limiter(int sample_rate_hz, - ApmDataDumper* apm_data_dumper, + // See `SetSamplesPerChannel()` for valid values for `samples_per_channel`. + Limiter(ApmDataDumper* apm_data_dumper, + size_t samples_per_channel, absl::string_view histogram_name_prefix); + Limiter(const Limiter& limiter) = delete; Limiter& operator=(const Limiter& limiter) = delete; ~Limiter(); // Applies limiter and hard-clipping to `signal`. - void Process(AudioFrameView signal); + void Process(DeinterleavedView signal); + InterpolatedGainCurve::Stats GetGainCurveStats() const; - // Supported rates must be - // * supported by FixedDigitalLevelEstimator - // * below kMaximalNumberOfSamplesPerChannel*1000/kFrameDurationMs - // so that samples_per_channel fit in the - // per_sample_scaling_factors_ array. - void SetSampleRate(int sample_rate_hz); + // Supported values must be + // * Supported by FixedDigitalLevelEstimator + // * Below or equal to kMaximalNumberOfSamplesPerChannel so that samples + // fit in the per_sample_scaling_factors_ array. + void SetSamplesPerChannel(size_t samples_per_channel); // Resets the internal state. void Reset(); diff --git a/webrtc/modules/audio_processing/agc2/noise_level_estimator.cc b/webrtc/modules/audio_processing/agc2/noise_level_estimator.cc index 691513b..c43738a 100644 --- a/webrtc/modules/audio_processing/agc2/noise_level_estimator.cc +++ b/webrtc/modules/audio_processing/agc2/noise_level_estimator.cc @@ -16,7 +16,7 @@ #include #include -#include "api/array_view.h" +#include "api/audio/audio_view.h" #include "modules/audio_processing/logging/apm_data_dumper.h" #include "rtc_base/checks.h" @@ -25,11 +25,12 @@ namespace { constexpr int kFramesPerSecond = 100; -float FrameEnergy(const AudioFrameView& audio) { +float FrameEnergy(DeinterleavedView audio) { float energy = 0.0f; - for (int k = 0; k < audio.num_channels(); ++k) { + for (size_t k = 0; k < audio.num_channels(); ++k) { + MonoView ch = audio[k]; float channel_energy = - std::accumulate(audio.channel(k).begin(), audio.channel(k).end(), 0.0f, + std::accumulate(ch.begin(), ch.end(), 0.0f, [](float a, float b) -> float { return a + b * b; }); energy = std::max(channel_energy, energy); } @@ -81,7 +82,7 @@ class NoiseFloorEstimator : public NoiseLevelEstimator { NoiseFloorEstimator& operator=(const NoiseFloorEstimator&) = delete; ~NoiseFloorEstimator() = default; - float Analyze(const AudioFrameView& frame) override { + float Analyze(DeinterleavedView frame) override { // Detect sample rate changes. const int sample_rate_hz = static_cast(frame.samples_per_channel() * kFramesPerSecond); diff --git a/webrtc/modules/audio_processing/agc2/noise_level_estimator.h b/webrtc/modules/audio_processing/agc2/noise_level_estimator.h index 9f3b957..8df4cbc 100644 --- a/webrtc/modules/audio_processing/agc2/noise_level_estimator.h +++ b/webrtc/modules/audio_processing/agc2/noise_level_estimator.h @@ -13,7 +13,7 @@ #include -#include "modules/audio_processing/include/audio_frame_view.h" +#include "api/audio/audio_view.h" namespace webrtc { class ApmDataDumper; @@ -24,7 +24,7 @@ class NoiseLevelEstimator { virtual ~NoiseLevelEstimator() = default; // Analyzes a 10 ms `frame`, updates the noise level estimation and returns // the value for the latter in dBFS. - virtual float Analyze(const AudioFrameView& frame) = 0; + virtual float Analyze(DeinterleavedView frame) = 0; }; // Creates a noise level estimator based on noise floor detection. diff --git a/webrtc/modules/audio_processing/agc2/rnn_vad/BUILD.gn b/webrtc/modules/audio_processing/agc2/rnn_vad/BUILD.gn index 9093a68..a0dd394 100644 --- a/webrtc/modules/audio_processing/agc2/rnn_vad/BUILD.gn +++ b/webrtc/modules/audio_processing/agc2/rnn_vad/BUILD.gn @@ -100,12 +100,12 @@ rtc_source_set("rnn_vad_layers") { "../../../../api:function_view", "../../../../rtc_base:checks", "../../../../rtc_base:safe_conversions", + "//third_party/abseil-cpp/absl/strings:string_view", "//third_party/rnnoise:rnn_vad", ] if (current_cpu == "x86" || current_cpu == "x64") { deps += [ ":vector_math_avx2" ] } - absl_deps = [ "//third_party/abseil-cpp/absl/strings" ] } rtc_source_set("vector_math") { @@ -229,8 +229,8 @@ if (rtc_include_tests) { "../../../../rtc_base:safe_compare", "../../../../test:fileutils", "../../../../test:test_support", + "//third_party/abseil-cpp/absl/strings:string_view", ] - absl_deps = [ "//third_party/abseil-cpp/absl/strings" ] } unittest_resources = [ @@ -306,7 +306,6 @@ if (rtc_include_tests) { if (current_cpu == "x86" || current_cpu == "x64") { deps += [ ":vector_math_avx2" ] } - absl_deps = [ "//third_party/abseil-cpp/absl/memory" ] data = unittest_resources if (is_ios) { deps += [ ":unittests_bundle_data" ] diff --git a/webrtc/modules/audio_processing/agc2/saturation_protector_buffer.cc b/webrtc/modules/audio_processing/agc2/saturation_protector_buffer.cc index 41efdad..1f9083f 100644 --- a/webrtc/modules/audio_processing/agc2/saturation_protector_buffer.cc +++ b/webrtc/modules/audio_processing/agc2/saturation_protector_buffer.cc @@ -62,9 +62,9 @@ void SaturationProtectorBuffer::PushBack(float v) { } } -absl::optional SaturationProtectorBuffer::Front() const { +std::optional SaturationProtectorBuffer::Front() const { if (size_ == 0) { - return absl::nullopt; + return std::nullopt; } RTC_DCHECK_LT(FrontIndex(), buffer_.size()); return buffer_[FrontIndex()]; diff --git a/webrtc/modules/audio_processing/agc2/saturation_protector_buffer.h b/webrtc/modules/audio_processing/agc2/saturation_protector_buffer.h index e17d099..3965e93 100644 --- a/webrtc/modules/audio_processing/agc2/saturation_protector_buffer.h +++ b/webrtc/modules/audio_processing/agc2/saturation_protector_buffer.h @@ -12,8 +12,8 @@ #define MODULES_AUDIO_PROCESSING_AGC2_SATURATION_PROTECTOR_BUFFER_H_ #include +#include -#include "absl/types/optional.h" #include "modules/audio_processing/agc2/agc2_common.h" namespace webrtc { @@ -43,7 +43,7 @@ class SaturationProtectorBuffer { // Returns the oldest item in the buffer. Returns an empty value if the // buffer is empty. - absl::optional Front() const; + std::optional Front() const; private: int FrontIndex() const; diff --git a/webrtc/modules/audio_processing/agc2/speech_level_estimator.h b/webrtc/modules/audio_processing/agc2/speech_level_estimator.h index 4d9f106..adbf84c 100644 --- a/webrtc/modules/audio_processing/agc2/speech_level_estimator.h +++ b/webrtc/modules/audio_processing/agc2/speech_level_estimator.h @@ -15,8 +15,8 @@ #include +#include "api/audio/audio_processing.h" #include "modules/audio_processing/agc2/agc2_common.h" -#include "modules/audio_processing/include/audio_processing.h" namespace webrtc { class ApmDataDumper; diff --git a/webrtc/modules/audio_processing/agc2/vad_wrapper.cc b/webrtc/modules/audio_processing/agc2/vad_wrapper.cc index af6325d..8de8abd 100644 --- a/webrtc/modules/audio_processing/agc2/vad_wrapper.cc +++ b/webrtc/modules/audio_processing/agc2/vad_wrapper.cc @@ -13,7 +13,6 @@ #include #include -#include "api/array_view.h" #include "common_audio/resampler/include/push_resampler.h" #include "modules/audio_processing/agc2/agc2_common.h" #include "modules/audio_processing/agc2/rnn_vad/common.h" @@ -36,7 +35,7 @@ class MonoVadImpl : public VoiceActivityDetectorWrapper::MonoVad { int SampleRateHz() const override { return rnn_vad::kSampleRate24kHz; } void Reset() override { rnn_vad_.Reset(); } - float Analyze(rtc::ArrayView frame) override { + float Analyze(MonoView frame) override { RTC_DCHECK_EQ(frame.size(), rnn_vad::kFrameSize10ms24kHz); std::array feature_vector; const bool is_silence = features_extractor_.CheckSilenceComputeFeatures( @@ -73,39 +72,33 @@ VoiceActivityDetectorWrapper::VoiceActivityDetectorWrapper( int sample_rate_hz) : vad_reset_period_frames_( rtc::CheckedDivExact(vad_reset_period_ms, kFrameDurationMs)), + frame_size_(rtc::CheckedDivExact(sample_rate_hz, kNumFramesPerSecond)), time_to_vad_reset_(vad_reset_period_frames_), - vad_(std::move(vad)) { - RTC_DCHECK(vad_); + vad_(std::move(vad)), + resampled_buffer_( + rtc::CheckedDivExact(vad_->SampleRateHz(), kNumFramesPerSecond)), + resampler_(frame_size_, + resampled_buffer_.size(), + /*num_channels=*/1) { RTC_DCHECK_GT(vad_reset_period_frames_, 1); - resampled_buffer_.resize( - rtc::CheckedDivExact(vad_->SampleRateHz(), kNumFramesPerSecond)); - Initialize(sample_rate_hz); + vad_->Reset(); } VoiceActivityDetectorWrapper::~VoiceActivityDetectorWrapper() = default; -void VoiceActivityDetectorWrapper::Initialize(int sample_rate_hz) { - RTC_DCHECK_GT(sample_rate_hz, 0); - frame_size_ = rtc::CheckedDivExact(sample_rate_hz, kNumFramesPerSecond); - int status = - resampler_.InitializeIfNeeded(sample_rate_hz, vad_->SampleRateHz(), - /*num_channels=*/1); - constexpr int kStatusOk = 0; - RTC_DCHECK_EQ(status, kStatusOk); - vad_->Reset(); -} - -float VoiceActivityDetectorWrapper::Analyze(AudioFrameView frame) { +float VoiceActivityDetectorWrapper::Analyze( + DeinterleavedView frame) { // Periodically reset the VAD. time_to_vad_reset_--; if (time_to_vad_reset_ <= 0) { vad_->Reset(); time_to_vad_reset_ = vad_reset_period_frames_; } + // Resample the first channel of `frame`. RTC_DCHECK_EQ(frame.samples_per_channel(), frame_size_); - resampler_.Resample(frame.channel(0).data(), frame_size_, - resampled_buffer_.data(), resampled_buffer_.size()); + MonoView dst(resampled_buffer_.data(), resampled_buffer_.size()); + resampler_.Resample(frame[0], dst); return vad_->Analyze(resampled_buffer_); } diff --git a/webrtc/modules/audio_processing/agc2/vad_wrapper.h b/webrtc/modules/audio_processing/agc2/vad_wrapper.h index 459c471..025a48e 100644 --- a/webrtc/modules/audio_processing/agc2/vad_wrapper.h +++ b/webrtc/modules/audio_processing/agc2/vad_wrapper.h @@ -14,10 +14,9 @@ #include #include -#include "api/array_view.h" +#include "api/audio/audio_view.h" #include "common_audio/resampler/include/push_resampler.h" #include "modules/audio_processing/agc2/cpu_features.h" -#include "modules/audio_processing/include/audio_frame_view.h" namespace webrtc { @@ -37,7 +36,7 @@ class VoiceActivityDetectorWrapper { // Resets the internal state. virtual void Reset() = 0; // Analyzes an audio frame and returns the speech probability. - virtual float Analyze(rtc::ArrayView frame) = 0; + virtual float Analyze(MonoView frame) = 0; }; // Ctor. Uses `cpu_features` to instantiate the default VAD. @@ -60,21 +59,18 @@ class VoiceActivityDetectorWrapper { delete; ~VoiceActivityDetectorWrapper(); - // Initializes the VAD wrapper. - void Initialize(int sample_rate_hz); - // Analyzes the first channel of `frame` and returns the speech probability. // `frame` must be a 10 ms frame with the sample rate specified in the last // `Initialize()` call. - float Analyze(AudioFrameView frame); + float Analyze(DeinterleavedView frame); private: const int vad_reset_period_frames_; - int frame_size_; + const int frame_size_; int time_to_vad_reset_; - PushResampler resampler_; std::unique_ptr vad_; std::vector resampled_buffer_; + PushResampler resampler_; }; } // namespace webrtc diff --git a/webrtc/modules/audio_processing/agc2/vector_float_frame.cc b/webrtc/modules/audio_processing/agc2/vector_float_frame.cc index a70d815..85dd7fe 100644 --- a/webrtc/modules/audio_processing/agc2/vector_float_frame.cc +++ b/webrtc/modules/audio_processing/agc2/vector_float_frame.cc @@ -12,28 +12,20 @@ namespace webrtc { -namespace { - -std::vector ConstructChannelPointers( - std::vector>* x) { - std::vector channel_ptrs; - for (auto& v : *x) { - channel_ptrs.push_back(v.data()); - } - return channel_ptrs; -} -} // namespace - VectorFloatFrame::VectorFloatFrame(int num_channels, int samples_per_channel, float start_value) - : channels_(num_channels, - std::vector(samples_per_channel, start_value)), - channel_ptrs_(ConstructChannelPointers(&channels_)), - float_frame_view_(channel_ptrs_.data(), - channels_.size(), - samples_per_channel) {} + : channels_(num_channels * samples_per_channel, start_value), + view_(channels_.data(), samples_per_channel, num_channels) {} VectorFloatFrame::~VectorFloatFrame() = default; +AudioFrameView VectorFloatFrame::float_frame_view() { + return AudioFrameView(view_); +} + +AudioFrameView VectorFloatFrame::float_frame_view() const { + return AudioFrameView(view_); +} + } // namespace webrtc diff --git a/webrtc/modules/audio_processing/agc2/vector_float_frame.h b/webrtc/modules/audio_processing/agc2/vector_float_frame.h index b521f34..e2a3211 100644 --- a/webrtc/modules/audio_processing/agc2/vector_float_frame.h +++ b/webrtc/modules/audio_processing/agc2/vector_float_frame.h @@ -13,6 +13,7 @@ #include +#include "api/audio/audio_view.h" #include "modules/audio_processing/include/audio_frame_view.h" namespace webrtc { @@ -24,17 +25,17 @@ class VectorFloatFrame { VectorFloatFrame(int num_channels, int samples_per_channel, float start_value); - const AudioFrameView& float_frame_view() { return float_frame_view_; } - AudioFrameView float_frame_view() const { - return float_frame_view_; - } - ~VectorFloatFrame(); + AudioFrameView float_frame_view(); + AudioFrameView float_frame_view() const; + + DeinterleavedView view() { return view_; } + DeinterleavedView view() const { return view_; } + private: - std::vector> channels_; - std::vector channel_ptrs_; - AudioFrameView float_frame_view_; + std::vector channels_; + DeinterleavedView view_; }; } // namespace webrtc diff --git a/webrtc/modules/audio_processing/audio_buffer.cc b/webrtc/modules/audio_processing/audio_buffer.cc index 3dbe1fe..c48d444 100644 --- a/webrtc/modules/audio_processing/audio_buffer.cc +++ b/webrtc/modules/audio_processing/audio_buffer.cc @@ -15,7 +15,6 @@ #include #include "common_audio/channel_buffer.h" -#include "common_audio/include/audio_util.h" #include "common_audio/resampler/push_sinc_resampler.h" #include "modules/audio_processing/splitting_filter.h" #include "rtc_base/checks.h" @@ -25,7 +24,6 @@ namespace { constexpr size_t kSamplesPer32kHzChannel = 320; constexpr size_t kSamplesPer48kHzChannel = 480; -constexpr size_t kMaxSamplesPerChannel = AudioBuffer::kMaxSampleRate / 100; size_t NumBandsFromFramesPerChannel(size_t num_frames) { if (num_frames == kSamplesPer32kHzChannel) { @@ -110,9 +108,9 @@ void AudioBuffer::CopyFrom(const float* const* stacked_data, const bool resampling_needed = input_num_frames_ != buffer_num_frames_; if (downmix_needed) { - RTC_DCHECK_GE(kMaxSamplesPerChannel, input_num_frames_); + RTC_DCHECK_GE(kMaxSamplesPerChannel10ms, input_num_frames_); - std::array downmix; + std::array downmix; if (downmix_by_averaging_) { const float kOneByNumChannels = 1.f / input_num_channels_; for (size_t i = 0; i < input_num_frames_; ++i) { @@ -230,7 +228,7 @@ void AudioBuffer::CopyFrom(const int16_t* const interleaved_data, if (num_channels_ == 1) { if (input_num_channels_ == 1) { if (resampling_required) { - std::array float_buffer; + std::array float_buffer; S16ToFloatS16(interleaved, input_num_frames_, float_buffer.data()); input_resamplers_[0]->Resample(float_buffer.data(), input_num_frames_, data_->channels()[0], @@ -239,7 +237,7 @@ void AudioBuffer::CopyFrom(const int16_t* const interleaved_data, S16ToFloatS16(interleaved, input_num_frames_, data_->channels()[0]); } } else { - std::array float_buffer; + std::array float_buffer; float* downmixed_data = resampling_required ? float_buffer.data() : data_->channels()[0]; if (downmix_by_averaging_) { @@ -274,7 +272,7 @@ void AudioBuffer::CopyFrom(const int16_t* const interleaved_data, }; if (resampling_required) { - std::array float_buffer; + std::array float_buffer; for (size_t i = 0; i < num_channels_; ++i) { deinterleave_channel(i, num_channels_, input_num_frames_, interleaved, float_buffer.data()); @@ -302,7 +300,7 @@ void AudioBuffer::CopyTo(const StreamConfig& stream_config, int16_t* interleaved = interleaved_data; if (num_channels_ == 1) { - std::array float_buffer; + std::array float_buffer; if (resampling_required) { output_resamplers_[0]->Resample(data_->channels()[0], buffer_num_frames_, @@ -335,7 +333,7 @@ void AudioBuffer::CopyTo(const StreamConfig& stream_config, if (resampling_required) { for (size_t i = 0; i < num_channels_; ++i) { - std::array float_buffer; + std::array float_buffer; output_resamplers_[i]->Resample(data_->channels()[i], buffer_num_frames_, float_buffer.data(), output_num_frames_); diff --git a/webrtc/modules/audio_processing/audio_buffer.h b/webrtc/modules/audio_processing/audio_buffer.h index b9ea300..9369572 100644 --- a/webrtc/modules/audio_processing/audio_buffer.h +++ b/webrtc/modules/audio_processing/audio_buffer.h @@ -17,8 +17,10 @@ #include #include +#include "api/audio/audio_processing.h" +#include "api/audio/audio_view.h" #include "common_audio/channel_buffer.h" -#include "modules/audio_processing/include/audio_processing.h" +#include "common_audio/include/audio_util.h" namespace webrtc { @@ -32,7 +34,8 @@ enum Band { kBand0To8kHz = 0, kBand8To16kHz = 1, kBand16To24kHz = 2 }; class AudioBuffer { public: static const int kSplitBandSize = 160; - static const int kMaxSampleRate = 384000; + // TODO(tommi): Remove this (`AudioBuffer::kMaxSampleRate`) constant. + static const int kMaxSampleRate = webrtc::kMaxSampleRateHz; AudioBuffer(size_t input_rate, size_t input_num_channels, size_t buffer_rate, @@ -56,6 +59,13 @@ class AudioBuffer { // reset at each call to CopyFrom or InterleaveFrom. void set_num_channels(size_t num_channels); + // Returns a DeinterleavedView<> over the channel data. + DeinterleavedView view() { + return DeinterleavedView( + num_channels_ && buffer_num_frames_ ? channels()[0] : nullptr, + buffer_num_frames_, num_channels_); + } + size_t num_channels() const { return num_channels_; } size_t num_frames() const { return buffer_num_frames_; } size_t num_frames_per_band() const { return num_split_frames_; } diff --git a/webrtc/modules/audio_processing/audio_processing_builder_impl.cc b/webrtc/modules/audio_processing/audio_processing_builder_impl.cc index a246448..d02ac82 100644 --- a/webrtc/modules/audio_processing/audio_processing_builder_impl.cc +++ b/webrtc/modules/audio_processing/audio_processing_builder_impl.cc @@ -10,9 +10,9 @@ #include +#include "api/audio/audio_processing.h" #include "api/make_ref_counted.h" #include "modules/audio_processing/audio_processing_impl.h" -#include "modules/audio_processing/include/audio_processing.h" namespace webrtc { diff --git a/webrtc/modules/audio_processing/audio_processing_impl.cc b/webrtc/modules/audio_processing/audio_processing_impl.cc index c80cc76..a1cba51 100644 --- a/webrtc/modules/audio_processing/audio_processing_impl.cc +++ b/webrtc/modules/audio_processing/audio_processing_impl.cc @@ -14,22 +14,23 @@ #include #include #include +#include #include #include #include +#include "absl/base/nullability.h" #include "absl/strings/match.h" #include "absl/strings/string_view.h" -#include "absl/types/optional.h" #include "api/array_view.h" #include "api/audio/audio_frame.h" +#include "api/task_queue/task_queue_base.h" #include "common_audio/audio_converter.h" #include "common_audio/include/audio_util.h" #include "modules/audio_processing/aec_dump/aec_dump_factory.h" #include "modules/audio_processing/audio_buffer.h" #include "modules/audio_processing/include/audio_frame_view.h" #include "modules/audio_processing/logging/apm_data_dumper.h" -#include "modules/audio_processing/optionally_built_submodule_creators.h" #include "rtc_base/checks.h" #include "rtc_base/experiments/field_trial_parser.h" #include "rtc_base/logging.h" @@ -322,231 +323,6 @@ constexpr int kUnspecifiedDataDumpInputVolume = -100; // Throughout webrtc, it's assumed that success is represented by zero. static_assert(AudioProcessing::kNoError == 0, "kNoError must be zero"); -absl::optional -AudioProcessingImpl::GetGainController2ExperimentParams() { - constexpr char kFieldTrialName[] = "WebRTC-Audio-GainController2"; - - if (!field_trial::IsEnabled(kFieldTrialName)) { - return absl::nullopt; - } - - FieldTrialFlag enabled("Enabled", false); - - // Whether the gain control should switch to AGC2. Enabled by default. - FieldTrialParameter switch_to_agc2("switch_to_agc2", true); - - // AGC2 input volume controller configuration. - constexpr InputVolumeController::Config kDefaultInputVolumeControllerConfig; - FieldTrialConstrained min_input_volume( - "min_input_volume", kDefaultInputVolumeControllerConfig.min_input_volume, - 0, 255); - FieldTrialConstrained clipped_level_min( - "clipped_level_min", - kDefaultInputVolumeControllerConfig.clipped_level_min, 0, 255); - FieldTrialConstrained clipped_level_step( - "clipped_level_step", - kDefaultInputVolumeControllerConfig.clipped_level_step, 0, 255); - FieldTrialConstrained clipped_ratio_threshold( - "clipped_ratio_threshold", - kDefaultInputVolumeControllerConfig.clipped_ratio_threshold, 0, 1); - FieldTrialConstrained clipped_wait_frames( - "clipped_wait_frames", - kDefaultInputVolumeControllerConfig.clipped_wait_frames, 0, - absl::nullopt); - FieldTrialParameter enable_clipping_predictor( - "enable_clipping_predictor", - kDefaultInputVolumeControllerConfig.enable_clipping_predictor); - FieldTrialConstrained target_range_max_dbfs( - "target_range_max_dbfs", - kDefaultInputVolumeControllerConfig.target_range_max_dbfs, -90, 30); - FieldTrialConstrained target_range_min_dbfs( - "target_range_min_dbfs", - kDefaultInputVolumeControllerConfig.target_range_min_dbfs, -90, 30); - FieldTrialConstrained update_input_volume_wait_frames( - "update_input_volume_wait_frames", - kDefaultInputVolumeControllerConfig.update_input_volume_wait_frames, 0, - absl::nullopt); - FieldTrialConstrained speech_probability_threshold( - "speech_probability_threshold", - kDefaultInputVolumeControllerConfig.speech_probability_threshold, 0, 1); - FieldTrialConstrained speech_ratio_threshold( - "speech_ratio_threshold", - kDefaultInputVolumeControllerConfig.speech_ratio_threshold, 0, 1); - - // AGC2 adaptive digital controller configuration. - constexpr AudioProcessing::Config::GainController2::AdaptiveDigital - kDefaultAdaptiveDigitalConfig; - FieldTrialConstrained headroom_db( - "headroom_db", kDefaultAdaptiveDigitalConfig.headroom_db, 0, - absl::nullopt); - FieldTrialConstrained max_gain_db( - "max_gain_db", kDefaultAdaptiveDigitalConfig.max_gain_db, 0, - absl::nullopt); - FieldTrialConstrained initial_gain_db( - "initial_gain_db", kDefaultAdaptiveDigitalConfig.initial_gain_db, 0, - absl::nullopt); - FieldTrialConstrained max_gain_change_db_per_second( - "max_gain_change_db_per_second", - kDefaultAdaptiveDigitalConfig.max_gain_change_db_per_second, 0, - absl::nullopt); - FieldTrialConstrained max_output_noise_level_dbfs( - "max_output_noise_level_dbfs", - kDefaultAdaptiveDigitalConfig.max_output_noise_level_dbfs, absl::nullopt, - 0); - - // Transient suppressor. - FieldTrialParameter disallow_transient_suppressor_usage( - "disallow_transient_suppressor_usage", false); - - // Field-trial based override for the input volume controller and adaptive - // digital configs. - ParseFieldTrial( - {&enabled, &switch_to_agc2, &min_input_volume, &clipped_level_min, - &clipped_level_step, &clipped_ratio_threshold, &clipped_wait_frames, - &enable_clipping_predictor, &target_range_max_dbfs, - &target_range_min_dbfs, &update_input_volume_wait_frames, - &speech_probability_threshold, &speech_ratio_threshold, &headroom_db, - &max_gain_db, &initial_gain_db, &max_gain_change_db_per_second, - &max_output_noise_level_dbfs, &disallow_transient_suppressor_usage}, - field_trial::FindFullName(kFieldTrialName)); - // Checked already by `IsEnabled()` before parsing, therefore always true. - RTC_DCHECK(enabled); - - const bool do_not_change_agc_config = !switch_to_agc2.Get(); - if (do_not_change_agc_config && !disallow_transient_suppressor_usage.Get()) { - // Return an unspecifed value since, in this case, both the AGC2 and TS - // configurations won't be adjusted. - return absl::nullopt; - } - using Params = AudioProcessingImpl::GainController2ExperimentParams; - if (do_not_change_agc_config) { - // Return a value that leaves the AGC2 config unchanged and that always - // disables TS. - return Params{.agc2_config = absl::nullopt, - .disallow_transient_suppressor_usage = true}; - } - // Return a value that switches all the gain control to AGC2. - return Params{ - .agc2_config = - Params::Agc2Config{ - .input_volume_controller = - { - .min_input_volume = min_input_volume.Get(), - .clipped_level_min = clipped_level_min.Get(), - .clipped_level_step = clipped_level_step.Get(), - .clipped_ratio_threshold = - static_cast(clipped_ratio_threshold.Get()), - .clipped_wait_frames = clipped_wait_frames.Get(), - .enable_clipping_predictor = - enable_clipping_predictor.Get(), - .target_range_max_dbfs = target_range_max_dbfs.Get(), - .target_range_min_dbfs = target_range_min_dbfs.Get(), - .update_input_volume_wait_frames = - update_input_volume_wait_frames.Get(), - .speech_probability_threshold = static_cast( - speech_probability_threshold.Get()), - .speech_ratio_threshold = - static_cast(speech_ratio_threshold.Get()), - }, - .adaptive_digital_controller = - { - .headroom_db = static_cast(headroom_db.Get()), - .max_gain_db = static_cast(max_gain_db.Get()), - .initial_gain_db = - static_cast(initial_gain_db.Get()), - .max_gain_change_db_per_second = static_cast( - max_gain_change_db_per_second.Get()), - .max_output_noise_level_dbfs = - static_cast(max_output_noise_level_dbfs.Get()), - }}, - .disallow_transient_suppressor_usage = - disallow_transient_suppressor_usage.Get()}; -} - -AudioProcessing::Config AudioProcessingImpl::AdjustConfig( - const AudioProcessing::Config& config, - const absl::optional& - experiment_params) { - if (!experiment_params.has_value() || - (!experiment_params->agc2_config.has_value() && - !experiment_params->disallow_transient_suppressor_usage)) { - // When the experiment parameters are unspecified or when the AGC and TS - // configuration are not overridden, return the unmodified configuration. - return config; - } - - AudioProcessing::Config adjusted_config = config; - - // Override the transient suppressor configuration. - if (experiment_params->disallow_transient_suppressor_usage) { - adjusted_config.transient_suppression.enabled = false; - } - - // Override the auto gain control configuration if the AGC1 analog gain - // controller is active and `experiment_params->agc2_config` is specified. - const bool agc1_analog_enabled = - config.gain_controller1.enabled && - (config.gain_controller1.mode == - AudioProcessing::Config::GainController1::kAdaptiveAnalog || - config.gain_controller1.analog_gain_controller.enabled); - if (agc1_analog_enabled && experiment_params->agc2_config.has_value()) { - // Check that the unadjusted AGC config meets the preconditions. - const bool hybrid_agc_config_detected = - config.gain_controller1.enabled && - config.gain_controller1.analog_gain_controller.enabled && - !config.gain_controller1.analog_gain_controller - .enable_digital_adaptive && - config.gain_controller2.enabled && - config.gain_controller2.adaptive_digital.enabled; - const bool full_agc1_config_detected = - config.gain_controller1.enabled && - config.gain_controller1.analog_gain_controller.enabled && - config.gain_controller1.analog_gain_controller - .enable_digital_adaptive && - !config.gain_controller2.enabled; - const bool one_and_only_one_input_volume_controller = - hybrid_agc_config_detected != full_agc1_config_detected; - const bool agc2_input_volume_controller_enabled = - config.gain_controller2.enabled && - config.gain_controller2.input_volume_controller.enabled; - if (!one_and_only_one_input_volume_controller || - agc2_input_volume_controller_enabled) { - RTC_LOG(LS_ERROR) << "Cannot adjust AGC config (precondition failed)"; - if (!one_and_only_one_input_volume_controller) - RTC_LOG(LS_ERROR) - << "One and only one input volume controller must be enabled."; - if (agc2_input_volume_controller_enabled) - RTC_LOG(LS_ERROR) - << "The AGC2 input volume controller must be disabled."; - } else { - adjusted_config.gain_controller1.enabled = false; - adjusted_config.gain_controller1.analog_gain_controller.enabled = false; - - adjusted_config.gain_controller2.enabled = true; - adjusted_config.gain_controller2.input_volume_controller.enabled = true; - adjusted_config.gain_controller2.adaptive_digital = - experiment_params->agc2_config->adaptive_digital_controller; - adjusted_config.gain_controller2.adaptive_digital.enabled = true; - } - } - - return adjusted_config; -} - -bool AudioProcessingImpl::UseApmVadSubModule( - const AudioProcessing::Config& config, - const absl::optional& experiment_params) { - // The VAD as an APM sub-module is needed only in one case, that is when TS - // and AGC2 are both enabled and when the AGC2 experiment is running and its - // parameters require to fully switch the gain control to AGC2. - return config.transient_suppression.enabled && - config.gain_controller2.enabled && - (config.gain_controller2.input_volume_controller.enabled || - config.gain_controller2.adaptive_digital.enabled) && - experiment_params.has_value() && - experiment_params->agc2_config.has_value(); -} - AudioProcessingImpl::SubmoduleStates::SubmoduleStates( bool capture_post_processor_enabled, bool render_pre_processor_enabled, @@ -561,10 +337,8 @@ bool AudioProcessingImpl::SubmoduleStates::Update( bool noise_suppressor_enabled, bool adaptive_gain_controller_enabled, bool gain_controller2_enabled, - bool voice_activity_detector_enabled, bool gain_adjustment_enabled, - bool echo_controller_enabled, - bool transient_suppressor_enabled) { + bool echo_controller_enabled) { bool changed = false; changed |= (high_pass_filter_enabled != high_pass_filter_enabled_); changed |= @@ -573,21 +347,16 @@ bool AudioProcessingImpl::SubmoduleStates::Update( changed |= (adaptive_gain_controller_enabled != adaptive_gain_controller_enabled_); changed |= (gain_controller2_enabled != gain_controller2_enabled_); - changed |= - (voice_activity_detector_enabled != voice_activity_detector_enabled_); changed |= (gain_adjustment_enabled != gain_adjustment_enabled_); changed |= (echo_controller_enabled != echo_controller_enabled_); - changed |= (transient_suppressor_enabled != transient_suppressor_enabled_); if (changed) { high_pass_filter_enabled_ = high_pass_filter_enabled; mobile_echo_controller_enabled_ = mobile_echo_controller_enabled; noise_suppressor_enabled_ = noise_suppressor_enabled; adaptive_gain_controller_enabled_ = adaptive_gain_controller_enabled; gain_controller2_enabled_ = gain_controller2_enabled; - voice_activity_detector_enabled_ = voice_activity_detector_enabled; gain_adjustment_enabled_ = gain_adjustment_enabled; echo_controller_enabled_ = echo_controller_enabled; - transient_suppressor_enabled_ = transient_suppressor_enabled; } changed |= first_update_; @@ -664,14 +433,12 @@ AudioProcessingImpl::AudioProcessingImpl( : data_dumper_(new ApmDataDumper(instance_count_.fetch_add(1) + 1)), use_setup_specific_default_aec3_config_( UseSetupSpecificDefaultAec3Congfig()), - gain_controller2_experiment_params_(GetGainController2ExperimentParams()), - transient_suppressor_vad_mode_(TransientSuppressor::VadMode::kDefault), capture_runtime_settings_(RuntimeSettingQueueSize()), render_runtime_settings_(RuntimeSettingQueueSize()), capture_runtime_settings_enqueuer_(&capture_runtime_settings_), render_runtime_settings_enqueuer_(&render_runtime_settings_), echo_control_factory_(std::move(echo_control_factory)), - config_(AdjustConfig(config, gain_controller2_experiment_params_)), + config_(config), submodule_states_(!!capture_post_processor, !!render_pre_processor, !!capture_analyzer), @@ -684,8 +451,7 @@ AudioProcessingImpl::AudioProcessingImpl( !field_trial::IsEnabled( "WebRTC-ApmExperimentalMultiChannelCaptureKillSwitch"), EnforceSplitBandHpf(), - MinimizeProcessingForUnusedOutput(), - field_trial::IsEnabled("WebRTC-TransientSuppressorForcedOff")), + MinimizeProcessingForUnusedOutput()), capture_(), capture_nonlocked_(), applied_input_volume_stats_reporter_( @@ -806,12 +572,10 @@ void AudioProcessingImpl::InitializeLocked() { AllocateRenderQueue(); InitializeGainController1(); - InitializeTransientSuppressor(); InitializeHighPassFilter(true); InitializeResidualEchoDetector(); InitializeEchoController(); InitializeGainController2(); - InitializeVoiceActivityDetector(); InitializeNoiseSuppressor(); InitializeAnalyzer(); InitializePostProcessor(); @@ -906,52 +670,41 @@ void AudioProcessingImpl::ApplyConfig(const AudioProcessing::Config& config) { MutexLock lock_render(&mutex_render_); MutexLock lock_capture(&mutex_capture_); - const auto adjusted_config = - AdjustConfig(config, gain_controller2_experiment_params_); - RTC_LOG(LS_INFO) << "AudioProcessing::ApplyConfig: " - << adjusted_config.ToString(); + RTC_LOG(LS_INFO) << "AudioProcessing::ApplyConfig: " << config.ToString(); const bool pipeline_config_changed = config_.pipeline.multi_channel_render != - adjusted_config.pipeline.multi_channel_render || + config.pipeline.multi_channel_render || config_.pipeline.multi_channel_capture != - adjusted_config.pipeline.multi_channel_capture || + config.pipeline.multi_channel_capture || config_.pipeline.maximum_internal_processing_rate != - adjusted_config.pipeline.maximum_internal_processing_rate || + config.pipeline.maximum_internal_processing_rate || config_.pipeline.capture_downmix_method != - adjusted_config.pipeline.capture_downmix_method; + config.pipeline.capture_downmix_method; const bool aec_config_changed = - config_.echo_canceller.enabled != - adjusted_config.echo_canceller.enabled || - config_.echo_canceller.mobile_mode != - adjusted_config.echo_canceller.mobile_mode; + config_.echo_canceller.enabled != config.echo_canceller.enabled || + config_.echo_canceller.mobile_mode != config.echo_canceller.mobile_mode; const bool agc1_config_changed = - config_.gain_controller1 != adjusted_config.gain_controller1; + config_.gain_controller1 != config.gain_controller1; const bool agc2_config_changed = - config_.gain_controller2 != adjusted_config.gain_controller2; + config_.gain_controller2 != config.gain_controller2; const bool ns_config_changed = - config_.noise_suppression.enabled != - adjusted_config.noise_suppression.enabled || - config_.noise_suppression.level != - adjusted_config.noise_suppression.level; - - const bool ts_config_changed = config_.transient_suppression.enabled != - adjusted_config.transient_suppression.enabled; + config_.noise_suppression.enabled != config.noise_suppression.enabled || + config_.noise_suppression.level != config.noise_suppression.level; const bool pre_amplifier_config_changed = - config_.pre_amplifier.enabled != adjusted_config.pre_amplifier.enabled || + config_.pre_amplifier.enabled != config.pre_amplifier.enabled || config_.pre_amplifier.fixed_gain_factor != - adjusted_config.pre_amplifier.fixed_gain_factor; + config.pre_amplifier.fixed_gain_factor; const bool gain_adjustment_config_changed = - config_.capture_level_adjustment != - adjusted_config.capture_level_adjustment; + config_.capture_level_adjustment != config.capture_level_adjustment; - config_ = adjusted_config; + config_ = config; if (aec_config_changed) { InitializeEchoController(); @@ -961,10 +714,6 @@ void AudioProcessingImpl::ApplyConfig(const AudioProcessing::Config& config) { InitializeNoiseSuppressor(); } - if (ts_config_changed) { - InitializeTransientSuppressor(); - } - InitializeHighPassFilter(false); if (agc1_config_changed) { @@ -978,11 +727,8 @@ void AudioProcessingImpl::ApplyConfig(const AudioProcessing::Config& config) { config_.gain_controller2 = AudioProcessing::Config::GainController2(); } - if (agc2_config_changed || ts_config_changed) { - // AGC2 also depends on TS because of the possible dependency on the APM VAD - // sub-module. + if (agc2_config_changed) { InitializeGainController2(); - InitializeVoiceActivityDetector(); } if (pre_amplifier_config_changed || gain_adjustment_config_changed) { @@ -996,12 +742,6 @@ void AudioProcessingImpl::ApplyConfig(const AudioProcessing::Config& config) { } } -void AudioProcessingImpl::OverrideSubmoduleCreationForTesting( - const ApmSubmoduleCreationOverrides& overrides) { - MutexLock lock(&mutex_capture_); - submodule_creation_overrides_ = overrides; -} - int AudioProcessingImpl::proc_sample_rate_hz() const { // Used as callback from submodules, hence locking is not allowed. return capture_nonlocked_.capture_processing_format.sample_rate_hz(); @@ -1660,7 +1400,7 @@ int AudioProcessingImpl::ProcessCaptureStreamLocked() { if (submodules_.agc_manager) { submodules_.agc_manager->Process(*capture_buffer); - absl::optional new_digital_gain = + std::optional new_digital_gain = submodules_.agc_manager->GetDigitalComressionGain(); if (new_digital_gain && submodules_.gain_control) { submodules_.gain_control->set_compression_gain_db(*new_digital_gain); @@ -1697,44 +1437,6 @@ int AudioProcessingImpl::ProcessCaptureStreamLocked() { capture_buffer->num_frames())); } - absl::optional voice_probability; - if (!!submodules_.voice_activity_detector) { - voice_probability = submodules_.voice_activity_detector->Analyze( - AudioFrameView(capture_buffer->channels(), - capture_buffer->num_channels(), - capture_buffer->num_frames())); - } - - if (submodules_.transient_suppressor) { - float transient_suppressor_voice_probability = 1.0f; - switch (transient_suppressor_vad_mode_) { - case TransientSuppressor::VadMode::kDefault: - if (submodules_.agc_manager) { - transient_suppressor_voice_probability = - submodules_.agc_manager->voice_probability(); - } - break; - case TransientSuppressor::VadMode::kRnnVad: - RTC_DCHECK(voice_probability.has_value()); - transient_suppressor_voice_probability = *voice_probability; - break; - case TransientSuppressor::VadMode::kNoVad: - // The transient suppressor will ignore `voice_probability`. - break; - } - float delayed_voice_probability = - submodules_.transient_suppressor->Suppress( - capture_buffer->channels()[0], capture_buffer->num_frames(), - capture_buffer->num_channels(), - capture_buffer->split_bands_const(0)[kBand0To8kHz], - capture_buffer->num_frames_per_band(), - /*reference_data=*/nullptr, /*reference_length=*/0, - transient_suppressor_voice_probability, capture_.key_pressed); - if (voice_probability.has_value()) { - *voice_probability = delayed_voice_probability; - } - } - // Experimental APM sub-module that analyzes `capture_buffer`. if (submodules_.capture_analyzer) { submodules_.capture_analyzer->Analyze(capture_buffer); @@ -1744,8 +1446,8 @@ int AudioProcessingImpl::ProcessCaptureStreamLocked() { // TODO(bugs.webrtc.org/7494): Let AGC2 detect applied input volume // changes. submodules_.gain_controller2->Process( - voice_probability, capture_.applied_input_volume_changed, - capture_buffer); + /*speech_probability=*/std::nullopt, + capture_.applied_input_volume_changed, capture_buffer); } if (submodules_.capture_post_processor) { @@ -2023,7 +1725,7 @@ void AudioProcessingImpl::set_stream_analog_level_locked(int level) { // Invalidate any previously recommended input volume which will be updated by // `ProcessStream()`. - capture_.recommended_input_volume = absl::nullopt; + capture_.recommended_input_volume = std::nullopt; if (submodules_.agc_manager) { submodules_.agc_manager->set_stream_analog_level(level); @@ -2056,7 +1758,7 @@ void AudioProcessingImpl::UpdateRecommendedInputVolumeLocked() { if (!capture_.applied_input_volume.has_value()) { // When `set_stream_analog_level()` is not called, no input level can be // recommended. - capture_.recommended_input_volume = absl::nullopt; + capture_.recommended_input_volume = std::nullopt; return; } @@ -2082,9 +1784,10 @@ void AudioProcessingImpl::UpdateRecommendedInputVolumeLocked() { capture_.recommended_input_volume = capture_.applied_input_volume; } -bool AudioProcessingImpl::CreateAndAttachAecDump(absl::string_view file_name, - int64_t max_log_size_bytes, - rtc::TaskQueue* worker_queue) { +bool AudioProcessingImpl::CreateAndAttachAecDump( + absl::string_view file_name, + int64_t max_log_size_bytes, + absl::Nonnull worker_queue) { std::unique_ptr aec_dump = AecDumpFactory::Create(file_name, max_log_size_bytes, worker_queue); if (!aec_dump) { @@ -2095,9 +1798,10 @@ bool AudioProcessingImpl::CreateAndAttachAecDump(absl::string_view file_name, return true; } -bool AudioProcessingImpl::CreateAndAttachAecDump(FILE* handle, - int64_t max_log_size_bytes, - rtc::TaskQueue* worker_queue) { +bool AudioProcessingImpl::CreateAndAttachAecDump( + FILE* handle, + int64_t max_log_size_bytes, + absl::Nonnull worker_queue) { std::unique_ptr aec_dump = AecDumpFactory::Create(handle, max_log_size_bytes, worker_queue); if (!aec_dump) { @@ -2142,43 +1846,9 @@ bool AudioProcessingImpl::UpdateActiveSubmoduleStates() { return submodule_states_.Update( config_.high_pass_filter.enabled, !!submodules_.echo_control_mobile, !!submodules_.noise_suppressor, !!submodules_.gain_control, - !!submodules_.gain_controller2, !!submodules_.voice_activity_detector, + !!submodules_.gain_controller2, config_.pre_amplifier.enabled || config_.capture_level_adjustment.enabled, - capture_nonlocked_.echo_controller_enabled, - !!submodules_.transient_suppressor); -} - -void AudioProcessingImpl::InitializeTransientSuppressor() { - // Choose the VAD mode for TS and detect a VAD mode change. - const TransientSuppressor::VadMode previous_vad_mode = - transient_suppressor_vad_mode_; - transient_suppressor_vad_mode_ = TransientSuppressor::VadMode::kDefault; - if (UseApmVadSubModule(config_, gain_controller2_experiment_params_)) { - transient_suppressor_vad_mode_ = TransientSuppressor::VadMode::kRnnVad; - } - const bool vad_mode_changed = - previous_vad_mode != transient_suppressor_vad_mode_; - - if (config_.transient_suppression.enabled && - !constants_.transient_suppressor_forced_off) { - // Attempt to create a transient suppressor, if one is not already created. - if (!submodules_.transient_suppressor || vad_mode_changed) { - submodules_.transient_suppressor = CreateTransientSuppressor( - submodule_creation_overrides_, transient_suppressor_vad_mode_, - proc_fullband_sample_rate_hz(), capture_nonlocked_.split_rate, - num_proc_channels()); - if (!submodules_.transient_suppressor) { - RTC_LOG(LS_WARNING) - << "No transient suppressor created (probably disabled)"; - } - } else { - submodules_.transient_suppressor->Initialize( - proc_fullband_sample_rate_hz(), capture_nonlocked_.split_rate, - num_proc_channels()); - } - } else { - submodules_.transient_suppressor.reset(); - } + capture_nonlocked_.echo_controller_enabled); } void AudioProcessingImpl::InitializeHighPassFilter(bool forced_reset) { @@ -2220,7 +1890,7 @@ void AudioProcessingImpl::InitializeEchoController() { RTC_DCHECK(submodules_.echo_controller); } else { EchoCanceller3Config config; - absl::optional multichannel_config; + std::optional multichannel_config; if (use_setup_specific_default_aec3_config_) { multichannel_config = EchoCanceller3::CreateDefaultMultichannelConfig(); } @@ -2361,46 +2031,19 @@ void AudioProcessingImpl::InitializeGainController2() { submodules_.gain_controller2.reset(); return; } - // Override the input volume controller configuration if the AGC2 experiment - // is running and its parameters require to fully switch the gain control to + // Input volume controller configuration if the AGC2 is running + // and its parameters require to fully switch the gain control to // AGC2. - const bool input_volume_controller_config_overridden = - gain_controller2_experiment_params_.has_value() && - gain_controller2_experiment_params_->agc2_config.has_value(); const InputVolumeController::Config input_volume_controller_config = - input_volume_controller_config_overridden - ? gain_controller2_experiment_params_->agc2_config - ->input_volume_controller - : InputVolumeController::Config{}; - // If the APM VAD sub-module is not used, let AGC2 use its internal VAD. - const bool use_internal_vad = - !UseApmVadSubModule(config_, gain_controller2_experiment_params_); + InputVolumeController::Config{}; submodules_.gain_controller2 = std::make_unique( config_.gain_controller2, input_volume_controller_config, - proc_fullband_sample_rate_hz(), num_proc_channels(), use_internal_vad); + proc_fullband_sample_rate_hz(), num_output_channels(), + /*use_internal_vad=*/true); submodules_.gain_controller2->SetCaptureOutputUsed( capture_.capture_output_used); } -void AudioProcessingImpl::InitializeVoiceActivityDetector() { - if (!UseApmVadSubModule(config_, gain_controller2_experiment_params_)) { - submodules_.voice_activity_detector.reset(); - return; - } - - if (!submodules_.voice_activity_detector) { - RTC_DCHECK(!!submodules_.gain_controller2); - // TODO(bugs.webrtc.org/13663): Cache CPU features in APM and use here. - submodules_.voice_activity_detector = - std::make_unique( - submodules_.gain_controller2->GetCpuFeatures(), - proc_fullband_sample_rate_hz()); - } else { - submodules_.voice_activity_detector->Initialize( - proc_fullband_sample_rate_hz()); - } -} - void AudioProcessingImpl::InitializeNoiseSuppressor() { submodules_.noise_suppressor.reset(); @@ -2535,8 +2178,6 @@ void AudioProcessingImpl::WriteAecDumpConfigMessage(bool forced) { apm_config.ns_enabled = config_.noise_suppression.enabled; apm_config.ns_level = static_cast(config_.noise_suppression.level); - apm_config.transient_suppression_enabled = - config_.transient_suppression.enabled; apm_config.experiments_description = experiments_description; apm_config.pre_amplifier_enabled = config_.pre_amplifier.enabled; apm_config.pre_amplifier_fixed_gain_factor = diff --git a/webrtc/modules/audio_processing/audio_processing_impl.h b/webrtc/modules/audio_processing/audio_processing_impl.h index fe80e0d..ecdc055 100644 --- a/webrtc/modules/audio_processing/audio_processing_impl.h +++ b/webrtc/modules/audio_processing/audio_processing_impl.h @@ -16,13 +16,17 @@ #include #include #include +#include #include #include +#include "absl/base/nullability.h" #include "absl/strings/string_view.h" -#include "absl/types/optional.h" #include "api/array_view.h" +#include "api/audio/audio_processing.h" +#include "api/audio/audio_processing_statistics.h" #include "api/function_view.h" +#include "api/task_queue/task_queue_base.h" #include "modules/audio_processing/aec3/echo_canceller3.h" #include "modules/audio_processing/agc/agc_manager_direct.h" #include "modules/audio_processing/agc/gain_control.h" @@ -35,15 +39,10 @@ #include "modules/audio_processing/high_pass_filter.h" #include "modules/audio_processing/include/aec_dump.h" #include "modules/audio_processing/include/audio_frame_proxies.h" -#include "modules/audio_processing/include/audio_processing.h" -#include "modules/audio_processing/include/audio_processing_statistics.h" #include "modules/audio_processing/ns/noise_suppressor.h" -#include "modules/audio_processing/optionally_built_submodule_creators.h" #include "modules/audio_processing/render_queue_item_verifier.h" #include "modules/audio_processing/rms_level.h" -#include "modules/audio_processing/transient/transient_suppressor.h" #include "rtc_base/gtest_prod_util.h" -#include "rtc_base/ignore_wundef.h" #include "rtc_base/swap_queue.h" #include "rtc_base/synchronization/mutex.h" #include "rtc_base/thread_annotations.h" @@ -72,12 +71,14 @@ class AudioProcessingImpl : public AudioProcessing { int Initialize() override; int Initialize(const ProcessingConfig& processing_config) override; void ApplyConfig(const AudioProcessing::Config& config) override; - bool CreateAndAttachAecDump(absl::string_view file_name, - int64_t max_log_size_bytes, - rtc::TaskQueue* worker_queue) override; - bool CreateAndAttachAecDump(FILE* handle, - int64_t max_log_size_bytes, - rtc::TaskQueue* worker_queue) override; + bool CreateAndAttachAecDump( + absl::string_view file_name, + int64_t max_log_size_bytes, + absl::Nonnull worker_queue) override; + bool CreateAndAttachAecDump( + FILE* handle, + int64_t max_log_size_bytes, + absl::Nonnull worker_queue) override; // TODO(webrtc:5298) Deprecated variant. void AttachAecDump(std::unique_ptr aec_dump) override; void DetachAecDump() override; @@ -154,24 +155,12 @@ class AudioProcessingImpl : public AudioProcessing { FRIEND_TEST_ALL_PREFIXES(ApmConfiguration, DefaultBehavior); FRIEND_TEST_ALL_PREFIXES(ApmConfiguration, ValidConfigBehavior); FRIEND_TEST_ALL_PREFIXES(ApmConfiguration, InValidConfigBehavior); - FRIEND_TEST_ALL_PREFIXES(ApmWithSubmodulesExcludedTest, - ToggleTransientSuppressor); - FRIEND_TEST_ALL_PREFIXES(ApmWithSubmodulesExcludedTest, - ReinitializeTransientSuppressor); - FRIEND_TEST_ALL_PREFIXES(ApmWithSubmodulesExcludedTest, - BitexactWithDisabledModules); - FRIEND_TEST_ALL_PREFIXES( - AudioProcessingImplGainController2FieldTrialParametrizedTest, - ConfigAdjustedWhenExperimentEnabled); void set_stream_analog_level_locked(int level) RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_); void UpdateRecommendedInputVolumeLocked() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_); - void OverrideSubmoduleCreationForTesting( - const ApmSubmoduleCreationOverrides& overrides); - // Class providing thread-safe message pipe functionality for // `runtime_settings_`. class RuntimeSettingEnqueuer { @@ -191,49 +180,6 @@ class AudioProcessingImpl : public AudioProcessing { static std::atomic instance_count_; const bool use_setup_specific_default_aec3_config_; - // Parameters for the "GainController2" experiment which determines whether - // the following APM sub-modules are created and, if so, their configurations: - // AGC2 (`gain_controller2`), AGC1 (`gain_control`, `agc_manager`) and TS - // (`transient_suppressor`). - // TODO(bugs.webrtc.org/7494): Remove when the "WebRTC-Audio-GainController2" - // field trial is removed. - struct GainController2ExperimentParams { - struct Agc2Config { - InputVolumeController::Config input_volume_controller; - AudioProcessing::Config::GainController2::AdaptiveDigital - adaptive_digital_controller; - }; - // When `agc2_config` is specified, all gain control switches to AGC2 and - // the configuration is overridden. - absl::optional agc2_config; - // When true, the transient suppressor submodule is never created regardless - // of the APM configuration. - bool disallow_transient_suppressor_usage; - }; - // Specified when the "WebRTC-Audio-GainController2" field trial is specified. - // TODO(bugs.webrtc.org/7494): Remove when the "WebRTC-Audio-GainController2" - // field trial is removed. - const absl::optional - gain_controller2_experiment_params_; - - // Parses the "WebRTC-Audio-GainController2" field trial. If disabled, returns - // an unspecified value. - static absl::optional - GetGainController2ExperimentParams(); - - // When `experiment_params` is specified, returns an APM configuration - // modified according to the experiment parameters. Otherwise returns - // `config`. - static AudioProcessing::Config AdjustConfig( - const AudioProcessing::Config& config, - const absl::optional& experiment_params); - // Returns true if the APM VAD sub-module should be used. - static bool UseApmVadSubModule( - const AudioProcessing::Config& config, - const absl::optional& experiment_params); - - TransientSuppressor::VadMode transient_suppressor_vad_mode_; - SwapQueue capture_runtime_settings_; SwapQueue render_runtime_settings_; @@ -254,10 +200,8 @@ class AudioProcessingImpl : public AudioProcessing { bool noise_suppressor_enabled, bool adaptive_gain_controller_enabled, bool gain_controller2_enabled, - bool voice_activity_detector_enabled, bool gain_adjustment_enabled, - bool echo_controller_enabled, - bool transient_suppressor_enabled); + bool echo_controller_enabled); bool CaptureMultiBandSubModulesActive() const; bool CaptureMultiBandProcessingPresent() const; bool CaptureMultiBandProcessingActive(bool ec_processing_active) const; @@ -276,11 +220,9 @@ class AudioProcessingImpl : public AudioProcessing { bool mobile_echo_controller_enabled_ = false; bool noise_suppressor_enabled_ = false; bool adaptive_gain_controller_enabled_ = false; - bool voice_activity_detector_enabled_ = false; bool gain_controller2_enabled_ = false; bool gain_adjustment_enabled_ = false; bool echo_controller_enabled_ = false; - bool transient_suppressor_enabled_ = false; bool first_update_ = true; }; @@ -317,18 +259,9 @@ class AudioProcessingImpl : public AudioProcessing { void InitializeHighPassFilter(bool forced_reset) RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_); void InitializeGainController1() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_); - void InitializeTransientSuppressor() - RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_); // Initializes the `GainController2` sub-module. If the sub-module is enabled, // recreates it. void InitializeGainController2() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_); - // Initializes the `VoiceActivityDetectorWrapper` sub-module. If the - // sub-module is enabled, recreates it. Call `InitializeGainController2()` - // first. - // TODO(bugs.webrtc.org/13663): Remove if TS is removed otherwise remove call - // order requirement - i.e., decouple from `InitializeGainController2()`. - void InitializeVoiceActivityDetector() - RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_); void InitializeNoiseSuppressor() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_); void InitializeCaptureLevelsAdjuster() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_); @@ -423,10 +356,6 @@ class AudioProcessingImpl : public AudioProcessing { // Struct containing the Config specifying the behavior of APM. AudioProcessing::Config config_; - // Overrides for testing the exclusion of some submodules from the build. - ApmSubmoduleCreationOverrides submodule_creation_overrides_ - RTC_GUARDED_BY(mutex_capture_); - // Class containing information about what submodules are active. SubmoduleStates submodule_states_; @@ -448,12 +377,10 @@ class AudioProcessingImpl : public AudioProcessing { std::unique_ptr agc_manager; std::unique_ptr gain_control; std::unique_ptr gain_controller2; - std::unique_ptr voice_activity_detector; std::unique_ptr high_pass_filter; std::unique_ptr echo_controller; std::unique_ptr echo_control_mobile; std::unique_ptr noise_suppressor; - std::unique_ptr transient_suppressor; std::unique_ptr capture_levels_adjuster; } submodules_; @@ -479,19 +406,16 @@ class AudioProcessingImpl : public AudioProcessing { ApmConstants(bool multi_channel_render_support, bool multi_channel_capture_support, bool enforce_split_band_hpf, - bool minimize_processing_for_unused_output, - bool transient_suppressor_forced_off) + bool minimize_processing_for_unused_output) : multi_channel_render_support(multi_channel_render_support), multi_channel_capture_support(multi_channel_capture_support), enforce_split_band_hpf(enforce_split_band_hpf), minimize_processing_for_unused_output( - minimize_processing_for_unused_output), - transient_suppressor_forced_off(transient_suppressor_forced_off) {} + minimize_processing_for_unused_output) {} bool multi_channel_render_support; bool multi_channel_capture_support; bool enforce_split_band_hpf; bool minimize_processing_for_unused_output; - bool transient_suppressor_forced_off; } constants_; struct ApmCaptureState { @@ -516,12 +440,12 @@ class AudioProcessingImpl : public AudioProcessing { AudioProcessingStats stats; // Input volume applied on the audio input device when the audio is // acquired. Unspecified when unknown. - absl::optional applied_input_volume; + std::optional applied_input_volume; bool applied_input_volume_changed; // Recommended input volume to apply on the audio input device the next time // that audio is acquired. Unspecified when no input volume can be // recommended. - absl::optional recommended_input_volume; + std::optional recommended_input_volume; } capture_ RTC_GUARDED_BY(mutex_capture_); struct ApmCaptureNonLockedState { diff --git a/webrtc/modules/audio_processing/echo_control_mobile_impl.cc b/webrtc/modules/audio_processing/echo_control_mobile_impl.cc index fa5cb8f..1dc66ab 100644 --- a/webrtc/modules/audio_processing/echo_control_mobile_impl.cc +++ b/webrtc/modules/audio_processing/echo_control_mobile_impl.cc @@ -14,9 +14,9 @@ #include +#include "api/audio/audio_processing.h" #include "modules/audio_processing/aecm/echo_control_mobile.h" #include "modules/audio_processing/audio_buffer.h" -#include "modules/audio_processing/include/audio_processing.h" #include "rtc_base/checks.h" namespace webrtc { diff --git a/webrtc/modules/audio_processing/echo_detector/circular_buffer.cc b/webrtc/modules/audio_processing/echo_detector/circular_buffer.cc index a6d10ed..c24f920 100644 --- a/webrtc/modules/audio_processing/echo_detector/circular_buffer.cc +++ b/webrtc/modules/audio_processing/echo_detector/circular_buffer.cc @@ -28,9 +28,9 @@ void CircularBuffer::Push(float value) { RTC_DCHECK_LE(nr_elements_in_buffer_, buffer_.size()); } -absl::optional CircularBuffer::Pop() { +std::optional CircularBuffer::Pop() { if (nr_elements_in_buffer_ == 0) { - return absl::nullopt; + return std::nullopt; } const size_t index = (buffer_.size() + next_insertion_index_ - nr_elements_in_buffer_) % diff --git a/webrtc/modules/audio_processing/echo_detector/circular_buffer.h b/webrtc/modules/audio_processing/echo_detector/circular_buffer.h index db1aeae..5cce0d7 100644 --- a/webrtc/modules/audio_processing/echo_detector/circular_buffer.h +++ b/webrtc/modules/audio_processing/echo_detector/circular_buffer.h @@ -13,10 +13,9 @@ #include +#include #include -#include "absl/types/optional.h" - namespace webrtc { // Ring buffer containing floating point values. @@ -26,7 +25,7 @@ struct CircularBuffer { ~CircularBuffer(); void Push(float value); - absl::optional Pop(); + std::optional Pop(); size_t Size() const { return nr_elements_in_buffer_; } // This function fills the buffer with zeros, but does not change its size. void Clear(); diff --git a/webrtc/modules/audio_processing/gain_control_impl.cc b/webrtc/modules/audio_processing/gain_control_impl.cc index 5f2b487..56f56b5 100644 --- a/webrtc/modules/audio_processing/gain_control_impl.cc +++ b/webrtc/modules/audio_processing/gain_control_impl.cc @@ -11,11 +11,11 @@ #include "modules/audio_processing/gain_control_impl.h" #include +#include -#include "absl/types/optional.h" +#include "api/audio/audio_processing.h" #include "modules/audio_processing/agc/legacy/gain_control.h" #include "modules/audio_processing/audio_buffer.h" -#include "modules/audio_processing/include/audio_processing.h" #include "modules/audio_processing/logging/apm_data_dumper.h" #include "rtc_base/checks.h" #include "rtc_base/logging.h" diff --git a/webrtc/modules/audio_processing/gain_control_impl.h b/webrtc/modules/audio_processing/gain_control_impl.h index 8aea8f2..1a2cafe 100644 --- a/webrtc/modules/audio_processing/gain_control_impl.h +++ b/webrtc/modules/audio_processing/gain_control_impl.h @@ -15,9 +15,9 @@ #include #include +#include #include -#include "absl/types/optional.h" #include "api/array_view.h" #include "modules/audio_processing/agc/gain_control.h" @@ -81,8 +81,8 @@ class GainControlImpl : public GainControl { std::vector> mono_agcs_; std::vector capture_levels_; - absl::optional num_proc_channels_; - absl::optional sample_rate_hz_; + std::optional num_proc_channels_; + std::optional sample_rate_hz_; static int instance_counter_; }; diff --git a/webrtc/modules/audio_processing/gain_controller2.cc b/webrtc/modules/audio_processing/gain_controller2.cc index dd35212..b8f72ce 100644 --- a/webrtc/modules/audio_processing/gain_controller2.cc +++ b/webrtc/modules/audio_processing/gain_controller2.cc @@ -13,6 +13,7 @@ #include #include +#include "api/audio/audio_frame.h" #include "common_audio/include/audio_util.h" #include "modules/audio_processing/agc2/agc2_common.h" #include "modules/audio_processing/agc2/cpu_features.h" @@ -63,11 +64,11 @@ struct SpeechLevel { }; // Computes the audio levels for the first channel in `frame`. -AudioLevels ComputeAudioLevels(AudioFrameView frame, +AudioLevels ComputeAudioLevels(DeinterleavedView frame, ApmDataDumper& data_dumper) { float peak = 0.0f; float rms = 0.0f; - for (const auto& x : frame.channel(0)) { + for (const auto& x : frame[0]) { peak = std::max(std::fabs(x), peak); rms += x * x; } @@ -94,7 +95,9 @@ GainController2::GainController2( fixed_gain_applier_( /*hard_clip_samples=*/false, /*initial_gain_factor=*/DbToRatio(config.fixed_digital.gain_db)), - limiter_(sample_rate_hz, &data_dumper_, /*histogram_name_prefix=*/"Agc2"), + limiter_(&data_dumper_, + SampleRateToDefaultChannelSize(sample_rate_hz), + /*histogram_name_prefix=*/"Agc2"), calls_since_last_limiter_log_(0) { RTC_DCHECK(Validate(config)); data_dumper_.InitiateNewSetOfRecordings(); @@ -153,7 +156,7 @@ void GainController2::SetFixedGainDb(float gain_db) { void GainController2::Analyze(int applied_input_volume, const AudioBuffer& audio_buffer) { - recommended_input_volume_ = absl::nullopt; + recommended_input_volume_ = std::nullopt; RTC_DCHECK_GE(applied_input_volume, 0); RTC_DCHECK_LE(applied_input_volume, 255); @@ -164,10 +167,10 @@ void GainController2::Analyze(int applied_input_volume, } } -void GainController2::Process(absl::optional speech_probability, +void GainController2::Process(std::optional speech_probability, bool input_volume_changed, AudioBuffer* audio) { - recommended_input_volume_ = absl::nullopt; + recommended_input_volume_ = std::nullopt; data_dumper_.DumpRaw("agc2_applied_input_volume_changed", input_volume_changed); @@ -179,8 +182,8 @@ void GainController2::Process(absl::optional speech_probability, saturation_protector_->Reset(); } - AudioFrameView float_frame(audio->channels(), audio->num_channels(), - audio->num_frames()); + DeinterleavedView float_frame = audio->view(); + // Compute speech probability. if (vad_) { // When the VAD component runs, `speech_probability` should not be specified @@ -200,13 +203,13 @@ void GainController2::Process(absl::optional speech_probability, // Compute audio, noise and speech levels. AudioLevels audio_levels = ComputeAudioLevels(float_frame, data_dumper_); - absl::optional noise_rms_dbfs; + std::optional noise_rms_dbfs; if (noise_level_estimator_) { // TODO(bugs.webrtc.org/7494): Pass `audio_levels` to remove duplicated // computation in `noise_level_estimator_`. noise_rms_dbfs = noise_level_estimator_->Analyze(float_frame); } - absl::optional speech_level; + std::optional speech_level; if (speech_level_estimator_) { RTC_DCHECK(speech_probability.has_value()); speech_level_estimator_->Update( @@ -225,8 +228,8 @@ void GainController2::Process(absl::optional speech_probability, input_volume_controller_->RecommendInputVolume( *speech_probability, speech_level->is_confident - ? absl::optional(speech_level->rms_dbfs) - : absl::nullopt); + ? std::optional(speech_level->rms_dbfs) + : std::nullopt); } } diff --git a/webrtc/modules/audio_processing/gain_controller2.h b/webrtc/modules/audio_processing/gain_controller2.h index 43b5828..d192a20 100644 --- a/webrtc/modules/audio_processing/gain_controller2.h +++ b/webrtc/modules/audio_processing/gain_controller2.h @@ -15,6 +15,7 @@ #include #include +#include "api/audio/audio_processing.h" #include "modules/audio_processing/agc2/adaptive_digital_gain_controller.h" #include "modules/audio_processing/agc2/cpu_features.h" #include "modules/audio_processing/agc2/gain_applier.h" @@ -24,7 +25,6 @@ #include "modules/audio_processing/agc2/saturation_protector.h" #include "modules/audio_processing/agc2/speech_level_estimator.h" #include "modules/audio_processing/agc2/vad_wrapper.h" -#include "modules/audio_processing/include/audio_processing.h" #include "modules/audio_processing/logging/apm_data_dumper.h" namespace webrtc { @@ -68,7 +68,8 @@ class GainController2 { // computes the speech probability via `vad_`. // Handles input volume changes; if the caller cannot determine whether an // input volume change occurred, set `input_volume_changed` to false. - void Process(absl::optional speech_probability, + // TODO(bugs.webrtc.org/7494): Remove `speech_probability`. + void Process(std::optional speech_probability, bool input_volume_changed, AudioBuffer* audio); @@ -76,7 +77,7 @@ class GainController2 { AvailableCpuFeatures GetCpuFeatures() const { return cpu_features_; } - absl::optional recommended_input_volume() const { + std::optional recommended_input_volume() const { return recommended_input_volume_; } @@ -102,7 +103,7 @@ class GainController2 { // Recommended input volume from `InputVolumecontroller`. Non-empty after // `Process()` if input volume controller is enabled and // `InputVolumeController::Process()` has returned a non-empty value. - absl::optional recommended_input_volume_; + std::optional recommended_input_volume_; }; } // namespace webrtc diff --git a/webrtc/modules/audio_processing/include/aec_dump.h b/webrtc/modules/audio_processing/include/aec_dump.h index 6f2eb64..532fa21 100644 --- a/webrtc/modules/audio_processing/include/aec_dump.h +++ b/webrtc/modules/audio_processing/include/aec_dump.h @@ -13,12 +13,12 @@ #include +#include #include #include "absl/base/attributes.h" -#include "absl/types/optional.h" +#include "api/audio/audio_processing.h" #include "modules/audio_processing/include/audio_frame_view.h" -#include "modules/audio_processing/include/audio_processing.h" namespace webrtc { @@ -68,7 +68,7 @@ class AecDump { struct AudioProcessingState { int delay; int drift; - absl::optional applied_input_volume; + std::optional applied_input_volume; bool keypress; }; diff --git a/webrtc/modules/audio_processing/include/audio_frame_proxies.cc b/webrtc/modules/audio_processing/include/audio_frame_proxies.cc index 7cc4fb7..e37645e 100644 --- a/webrtc/modules/audio_processing/include/audio_frame_proxies.cc +++ b/webrtc/modules/audio_processing/include/audio_frame_proxies.cc @@ -11,7 +11,7 @@ #include "modules/audio_processing/include/audio_frame_proxies.h" #include "api/audio/audio_frame.h" -#include "modules/audio_processing/include/audio_processing.h" +#include "api/audio/audio_processing.h" namespace webrtc { diff --git a/webrtc/modules/audio_processing/include/audio_frame_view.h b/webrtc/modules/audio_processing/include/audio_frame_view.h index 164784a..27e2009 100644 --- a/webrtc/modules/audio_processing/include/audio_frame_view.h +++ b/webrtc/modules/audio_processing/include/audio_frame_view.h @@ -11,7 +11,7 @@ #ifndef MODULES_AUDIO_PROCESSING_INCLUDE_AUDIO_FRAME_VIEW_H_ #define MODULES_AUDIO_PROCESSING_INCLUDE_AUDIO_FRAME_VIEW_H_ -#include "api/array_view.h" +#include "api/audio/audio_view.h" namespace webrtc { @@ -22,46 +22,44 @@ class AudioFrameView { // `num_channels` and `channel_size` describe the T** // `audio_samples`. `audio_samples` is assumed to point to a // two-dimensional |num_channels * channel_size| array of floats. + // + // Note: The implementation now only requires the first channel pointer. + // The previous implementation retained a pointer to externally owned array + // of channel pointers, but since the channel size and count are provided + // and the array is assumed to be a single two-dimensional array, the other + // channel pointers can be calculated based on that (which is what the class + // now uses `DeinterleavedView<>` internally for). AudioFrameView(T* const* audio_samples, int num_channels, int channel_size) - : audio_samples_(audio_samples), - num_channels_(num_channels), - channel_size_(channel_size) { - RTC_DCHECK_GE(num_channels_, 0); - RTC_DCHECK_GE(channel_size_, 0); + : view_(num_channels && channel_size ? audio_samples[0] : nullptr, + channel_size, + num_channels) { + RTC_DCHECK_GE(view_.num_channels(), 0); + RTC_DCHECK_GE(view_.samples_per_channel(), 0); } - // Implicit cast to allow converting Frame to - // Frame. + // Implicit cast to allow converting AudioFrameView to + // AudioFrameView. template - AudioFrameView(AudioFrameView other) - : audio_samples_(other.data()), - num_channels_(other.num_channels()), - channel_size_(other.samples_per_channel()) {} + AudioFrameView(AudioFrameView other) : view_(other.view()) {} + + // Allow constructing AudioFrameView from a DeinterleavedView. + template + explicit AudioFrameView(DeinterleavedView view) : view_(view) {} AudioFrameView() = delete; - int num_channels() const { return num_channels_; } + int num_channels() const { return view_.num_channels(); } + int samples_per_channel() const { return view_.samples_per_channel(); } + MonoView channel(int idx) { return view_[idx]; } + MonoView channel(int idx) const { return view_[idx]; } + MonoView operator[](int idx) { return view_[idx]; } + MonoView operator[](int idx) const { return view_[idx]; } - int samples_per_channel() const { return channel_size_; } - - rtc::ArrayView channel(int idx) { - RTC_DCHECK_LE(0, idx); - RTC_DCHECK_LE(idx, num_channels_); - return rtc::ArrayView(audio_samples_[idx], channel_size_); - } - - rtc::ArrayView channel(int idx) const { - RTC_DCHECK_LE(0, idx); - RTC_DCHECK_LE(idx, num_channels_); - return rtc::ArrayView(audio_samples_[idx], channel_size_); - } - - T* const* data() { return audio_samples_; } + DeinterleavedView view() { return view_; } + DeinterleavedView view() const { return view_; } private: - T* const* audio_samples_; - int num_channels_; - int channel_size_; + DeinterleavedView view_; }; } // namespace webrtc diff --git a/webrtc/modules/audio_processing/include/audio_processing.h b/webrtc/modules/audio_processing/include/audio_processing.h index f613a38..fe938f8 100644 --- a/webrtc/modules/audio_processing/include/audio_processing.h +++ b/webrtc/modules/audio_processing/include/audio_processing.h @@ -11,931 +11,8 @@ #ifndef MODULES_AUDIO_PROCESSING_INCLUDE_AUDIO_PROCESSING_H_ #define MODULES_AUDIO_PROCESSING_INCLUDE_AUDIO_PROCESSING_H_ -// MSVC++ requires this to be set before any other includes to get M_PI. -#ifndef _USE_MATH_DEFINES -#define _USE_MATH_DEFINES -#endif - -#include -#include // size_t -#include // FILE -#include - -#include - -#include "absl/strings/string_view.h" -#include "absl/types/optional.h" -#include "api/array_view.h" -#include "api/audio/echo_canceller3_config.h" -#include "api/audio/echo_control.h" -#include "api/scoped_refptr.h" -#include "modules/audio_processing/include/audio_processing_statistics.h" -#include "rtc_base/arraysize.h" -#include "rtc_base/ref_count.h" -#include "rtc_base/system/file_wrapper.h" -#include "rtc_base/system/rtc_export.h" - -namespace rtc { -class TaskQueue; -} // namespace rtc - -namespace webrtc { - -class AecDump; -class AudioBuffer; - -class StreamConfig; -class ProcessingConfig; - -class EchoDetector; -class CustomAudioAnalyzer; -class CustomProcessing; - -// The Audio Processing Module (APM) provides a collection of voice processing -// components designed for real-time communications software. -// -// APM operates on two audio streams on a frame-by-frame basis. Frames of the -// primary stream, on which all processing is applied, are passed to -// `ProcessStream()`. Frames of the reverse direction stream are passed to -// `ProcessReverseStream()`. On the client-side, this will typically be the -// near-end (capture) and far-end (render) streams, respectively. APM should be -// placed in the signal chain as close to the audio hardware abstraction layer -// (HAL) as possible. -// -// On the server-side, the reverse stream will normally not be used, with -// processing occurring on each incoming stream. -// -// Component interfaces follow a similar pattern and are accessed through -// corresponding getters in APM. All components are disabled at create-time, -// with default settings that are recommended for most situations. New settings -// can be applied without enabling a component. Enabling a component triggers -// memory allocation and initialization to allow it to start processing the -// streams. -// -// Thread safety is provided with the following assumptions to reduce locking -// overhead: -// 1. The stream getters and setters are called from the same thread as -// ProcessStream(). More precisely, stream functions are never called -// concurrently with ProcessStream(). -// 2. Parameter getters are never called concurrently with the corresponding -// setter. -// -// APM accepts only linear PCM audio data in chunks of ~10 ms (see -// AudioProcessing::GetFrameSize() for details) and sample rates ranging from -// 8000 Hz to 384000 Hz. The int16 interfaces use interleaved data, while the -// float interfaces use deinterleaved data. -// -// Usage example, omitting error checking: -// rtc::scoped_refptr apm = AudioProcessingBuilder().Create(); -// -// AudioProcessing::Config config; -// config.echo_canceller.enabled = true; -// config.echo_canceller.mobile_mode = false; -// -// config.gain_controller1.enabled = true; -// config.gain_controller1.mode = -// AudioProcessing::Config::GainController1::kAdaptiveAnalog; -// config.gain_controller1.analog_level_minimum = 0; -// config.gain_controller1.analog_level_maximum = 255; -// -// config.gain_controller2.enabled = true; -// -// config.high_pass_filter.enabled = true; -// -// apm->ApplyConfig(config) -// -// // Start a voice call... -// -// // ... Render frame arrives bound for the audio HAL ... -// apm->ProcessReverseStream(render_frame); -// -// // ... Capture frame arrives from the audio HAL ... -// // Call required set_stream_ functions. -// apm->set_stream_delay_ms(delay_ms); -// apm->set_stream_analog_level(analog_level); -// -// apm->ProcessStream(capture_frame); -// -// // Call required stream_ functions. -// analog_level = apm->recommended_stream_analog_level(); -// has_voice = apm->stream_has_voice(); -// -// // Repeat render and capture processing for the duration of the call... -// // Start a new call... -// apm->Initialize(); -// -// // Close the application... -// apm.reset(); -// -class RTC_EXPORT AudioProcessing : public rtc::RefCountInterface { - public: - // The struct below constitutes the new parameter scheme for the audio - // processing. It is being introduced gradually and until it is fully - // introduced, it is prone to change. - // TODO(peah): Remove this comment once the new config scheme is fully rolled - // out. - // - // The parameters and behavior of the audio processing module are controlled - // by changing the default values in the AudioProcessing::Config struct. - // The config is applied by passing the struct to the ApplyConfig method. - // - // This config is intended to be used during setup, and to enable/disable - // top-level processing effects. Use during processing may cause undesired - // submodule resets, affecting the audio quality. Use the RuntimeSetting - // construct for runtime configuration. - struct RTC_EXPORT Config { - // Sets the properties of the audio processing pipeline. - struct RTC_EXPORT Pipeline { - // Ways to downmix a multi-channel track to mono. - enum class DownmixMethod { - kAverageChannels, // Average across channels. - kUseFirstChannel // Use the first channel. - }; - - // Maximum allowed processing rate used internally. May only be set to - // 32000 or 48000 and any differing values will be treated as 48000. - int maximum_internal_processing_rate = 48000; - // Allow multi-channel processing of render audio. - bool multi_channel_render = false; - // Allow multi-channel processing of capture audio when AEC3 is active - // or a custom AEC is injected.. - bool multi_channel_capture = false; - // Indicates how to downmix multi-channel capture audio to mono (when - // needed). - DownmixMethod capture_downmix_method = DownmixMethod::kAverageChannels; - } pipeline; - - // Enabled the pre-amplifier. It amplifies the capture signal - // before any other processing is done. - // TODO(webrtc:5298): Deprecate and use the pre-gain functionality in - // capture_level_adjustment instead. - struct PreAmplifier { - bool enabled = false; - float fixed_gain_factor = 1.0f; - } pre_amplifier; - - // Functionality for general level adjustment in the capture pipeline. This - // should not be used together with the legacy PreAmplifier functionality. - struct CaptureLevelAdjustment { - bool operator==(const CaptureLevelAdjustment& rhs) const; - bool operator!=(const CaptureLevelAdjustment& rhs) const { - return !(*this == rhs); - } - bool enabled = false; - // The `pre_gain_factor` scales the signal before any processing is done. - float pre_gain_factor = 1.0f; - // The `post_gain_factor` scales the signal after all processing is done. - float post_gain_factor = 1.0f; - struct AnalogMicGainEmulation { - bool operator==(const AnalogMicGainEmulation& rhs) const; - bool operator!=(const AnalogMicGainEmulation& rhs) const { - return !(*this == rhs); - } - bool enabled = false; - // Initial analog gain level to use for the emulated analog gain. Must - // be in the range [0...255]. - int initial_level = 255; - } analog_mic_gain_emulation; - } capture_level_adjustment; - - struct HighPassFilter { - bool enabled = false; - bool apply_in_full_band = true; - } high_pass_filter; - - struct EchoCanceller { - bool enabled = false; - bool mobile_mode = false; - bool export_linear_aec_output = false; - // Enforce the highpass filter to be on (has no effect for the mobile - // mode). - bool enforce_high_pass_filtering = true; - } echo_canceller; - - // Enables background noise suppression. - struct NoiseSuppression { - bool enabled = false; - enum Level { kLow, kModerate, kHigh, kVeryHigh }; - Level level = kModerate; - bool analyze_linear_aec_output_when_available = false; - } noise_suppression; - - // Enables transient suppression. - struct TransientSuppression { - bool enabled = false; - } transient_suppression; - - // Enables automatic gain control (AGC) functionality. - // The automatic gain control (AGC) component brings the signal to an - // appropriate range. This is done by applying a digital gain directly and, - // in the analog mode, prescribing an analog gain to be applied at the audio - // HAL. - // Recommended to be enabled on the client-side. - struct RTC_EXPORT GainController1 { - bool operator==(const GainController1& rhs) const; - bool operator!=(const GainController1& rhs) const { - return !(*this == rhs); - } - - bool enabled = false; - enum Mode { - // Adaptive mode intended for use if an analog volume control is - // available on the capture device. It will require the user to provide - // coupling between the OS mixer controls and AGC through the - // stream_analog_level() functions. - // It consists of an analog gain prescription for the audio device and a - // digital compression stage. - kAdaptiveAnalog, - // Adaptive mode intended for situations in which an analog volume - // control is unavailable. It operates in a similar fashion to the - // adaptive analog mode, but with scaling instead applied in the digital - // domain. As with the analog mode, it additionally uses a digital - // compression stage. - kAdaptiveDigital, - // Fixed mode which enables only the digital compression stage also used - // by the two adaptive modes. - // It is distinguished from the adaptive modes by considering only a - // short time-window of the input signal. It applies a fixed gain - // through most of the input level range, and compresses (gradually - // reduces gain with increasing level) the input signal at higher - // levels. This mode is preferred on embedded devices where the capture - // signal level is predictable, so that a known gain can be applied. - kFixedDigital - }; - Mode mode = kAdaptiveAnalog; - // Sets the target peak level (or envelope) of the AGC in dBFs (decibels - // from digital full-scale). The convention is to use positive values. For - // instance, passing in a value of 3 corresponds to -3 dBFs, or a target - // level 3 dB below full-scale. Limited to [0, 31]. - int target_level_dbfs = 3; - // Sets the maximum gain the digital compression stage may apply, in dB. A - // higher number corresponds to greater compression, while a value of 0 - // will leave the signal uncompressed. Limited to [0, 90]. - // For updates after APM setup, use a RuntimeSetting instead. - int compression_gain_db = 9; - // When enabled, the compression stage will hard limit the signal to the - // target level. Otherwise, the signal will be compressed but not limited - // above the target level. - bool enable_limiter = true; - - // Enables the analog gain controller functionality. - struct AnalogGainController { - bool enabled = true; - // TODO(bugs.webrtc.org/7494): Deprecated. Stop using and remove. - int startup_min_volume = 0; - // Lowest analog microphone level that will be applied in response to - // clipping. - int clipped_level_min = 70; - // If true, an adaptive digital gain is applied. - bool enable_digital_adaptive = true; - // Amount the microphone level is lowered with every clipping event. - // Limited to (0, 255]. - int clipped_level_step = 15; - // Proportion of clipped samples required to declare a clipping event. - // Limited to (0.f, 1.f). - float clipped_ratio_threshold = 0.1f; - // Time in frames to wait after a clipping event before checking again. - // Limited to values higher than 0. - int clipped_wait_frames = 300; - - // Enables clipping prediction functionality. - struct ClippingPredictor { - bool enabled = false; - enum Mode { - // Clipping event prediction mode with fixed step estimation. - kClippingEventPrediction, - // Clipped peak estimation mode with adaptive step estimation. - kAdaptiveStepClippingPeakPrediction, - // Clipped peak estimation mode with fixed step estimation. - kFixedStepClippingPeakPrediction, - }; - Mode mode = kClippingEventPrediction; - // Number of frames in the sliding analysis window. - int window_length = 5; - // Number of frames in the sliding reference window. - int reference_window_length = 5; - // Reference window delay (unit: number of frames). - int reference_window_delay = 5; - // Clipping prediction threshold (dBFS). - float clipping_threshold = -1.0f; - // Crest factor drop threshold (dB). - float crest_factor_margin = 3.0f; - // If true, the recommended clipped level step is used to modify the - // analog gain. Otherwise, the predictor runs without affecting the - // analog gain. - bool use_predicted_step = true; - } clipping_predictor; - } analog_gain_controller; - } gain_controller1; - - // Parameters for AGC2, an Automatic Gain Control (AGC) sub-module which - // replaces the AGC sub-module parametrized by `gain_controller1`. - // AGC2 brings the captured audio signal to the desired level by combining - // three different controllers (namely, input volume controller, adapative - // digital controller and fixed digital controller) and a limiter. - // TODO(bugs.webrtc.org:7494): Name `GainController` when AGC1 removed. - struct RTC_EXPORT GainController2 { - bool operator==(const GainController2& rhs) const; - bool operator!=(const GainController2& rhs) const { - return !(*this == rhs); - } - - // AGC2 must be created if and only if `enabled` is true. - bool enabled = false; - - // Parameters for the input volume controller, which adjusts the input - // volume applied when the audio is captured (e.g., microphone volume on - // a soundcard, input volume on HAL). - struct InputVolumeController { - bool operator==(const InputVolumeController& rhs) const; - bool operator!=(const InputVolumeController& rhs) const { - return !(*this == rhs); - } - bool enabled = false; - } input_volume_controller; - - // Parameters for the adaptive digital controller, which adjusts and - // applies a digital gain after echo cancellation and after noise - // suppression. - struct RTC_EXPORT AdaptiveDigital { - bool operator==(const AdaptiveDigital& rhs) const; - bool operator!=(const AdaptiveDigital& rhs) const { - return !(*this == rhs); - } - bool enabled = false; - float headroom_db = 6.0f; - float max_gain_db = 30.0f; - float initial_gain_db = 8.0f; - float max_gain_change_db_per_second = 3.0f; - float max_output_noise_level_dbfs = -50.0f; - } adaptive_digital; - - // Parameters for the fixed digital controller, which applies a fixed - // digital gain after the adaptive digital controller and before the - // limiter. - struct FixedDigital { - // By setting `gain_db` to a value greater than zero, the limiter can be - // turned into a compressor that first applies a fixed gain. - float gain_db = 0.0f; - } fixed_digital; - } gain_controller2; - - std::string ToString() const; - }; - - // Specifies the properties of a setting to be passed to AudioProcessing at - // runtime. - class RuntimeSetting { - public: - enum class Type { - kNotSpecified, - kCapturePreGain, - kCaptureCompressionGain, - kCaptureFixedPostGain, - kPlayoutVolumeChange, - kCustomRenderProcessingRuntimeSetting, - kPlayoutAudioDeviceChange, - kCapturePostGain, - kCaptureOutputUsed - }; - - // Play-out audio device properties. - struct PlayoutAudioDeviceInfo { - int id; // Identifies the audio device. - int max_volume; // Maximum play-out volume. - }; - - RuntimeSetting() : type_(Type::kNotSpecified), value_(0.0f) {} - ~RuntimeSetting() = default; - - static RuntimeSetting CreateCapturePreGain(float gain) { - return {Type::kCapturePreGain, gain}; - } - - static RuntimeSetting CreateCapturePostGain(float gain) { - return {Type::kCapturePostGain, gain}; - } - - // Corresponds to Config::GainController1::compression_gain_db, but for - // runtime configuration. - static RuntimeSetting CreateCompressionGainDb(int gain_db) { - RTC_DCHECK_GE(gain_db, 0); - RTC_DCHECK_LE(gain_db, 90); - return {Type::kCaptureCompressionGain, static_cast(gain_db)}; - } - - // Corresponds to Config::GainController2::fixed_digital::gain_db, but for - // runtime configuration. - static RuntimeSetting CreateCaptureFixedPostGain(float gain_db) { - RTC_DCHECK_GE(gain_db, 0.0f); - RTC_DCHECK_LE(gain_db, 90.0f); - return {Type::kCaptureFixedPostGain, gain_db}; - } - - // Creates a runtime setting to notify play-out (aka render) audio device - // changes. - static RuntimeSetting CreatePlayoutAudioDeviceChange( - PlayoutAudioDeviceInfo audio_device) { - return {Type::kPlayoutAudioDeviceChange, audio_device}; - } - - // Creates a runtime setting to notify play-out (aka render) volume changes. - // `volume` is the unnormalized volume, the maximum of which - static RuntimeSetting CreatePlayoutVolumeChange(int volume) { - return {Type::kPlayoutVolumeChange, volume}; - } - - static RuntimeSetting CreateCustomRenderSetting(float payload) { - return {Type::kCustomRenderProcessingRuntimeSetting, payload}; - } - - static RuntimeSetting CreateCaptureOutputUsedSetting( - bool capture_output_used) { - return {Type::kCaptureOutputUsed, capture_output_used}; - } - - Type type() const { return type_; } - // Getters do not return a value but instead modify the argument to protect - // from implicit casting. - void GetFloat(float* value) const { - RTC_DCHECK(value); - *value = value_.float_value; - } - void GetInt(int* value) const { - RTC_DCHECK(value); - *value = value_.int_value; - } - void GetBool(bool* value) const { - RTC_DCHECK(value); - *value = value_.bool_value; - } - void GetPlayoutAudioDeviceInfo(PlayoutAudioDeviceInfo* value) const { - RTC_DCHECK(value); - *value = value_.playout_audio_device_info; - } - - private: - RuntimeSetting(Type id, float value) : type_(id), value_(value) {} - RuntimeSetting(Type id, int value) : type_(id), value_(value) {} - RuntimeSetting(Type id, PlayoutAudioDeviceInfo value) - : type_(id), value_(value) {} - Type type_; - union U { - U() {} - U(int value) : int_value(value) {} - U(float value) : float_value(value) {} - U(PlayoutAudioDeviceInfo value) : playout_audio_device_info(value) {} - float float_value; - int int_value; - bool bool_value; - PlayoutAudioDeviceInfo playout_audio_device_info; - } value_; - }; - - ~AudioProcessing() override {} - - // Initializes internal states, while retaining all user settings. This - // should be called before beginning to process a new audio stream. However, - // it is not necessary to call before processing the first stream after - // creation. - // - // It is also not necessary to call if the audio parameters (sample - // rate and number of channels) have changed. Passing updated parameters - // directly to `ProcessStream()` and `ProcessReverseStream()` is permissible. - // If the parameters are known at init-time though, they may be provided. - // TODO(webrtc:5298): Change to return void. - virtual int Initialize() = 0; - - // The int16 interfaces require: - // - only `NativeRate`s be used - // - that the input, output and reverse rates must match - // - that `processing_config.output_stream()` matches - // `processing_config.input_stream()`. - // - // The float interfaces accept arbitrary rates and support differing input and - // output layouts, but the output must have either one channel or the same - // number of channels as the input. - virtual int Initialize(const ProcessingConfig& processing_config) = 0; - - // TODO(peah): This method is a temporary solution used to take control - // over the parameters in the audio processing module and is likely to change. - virtual void ApplyConfig(const Config& config) = 0; - - // TODO(ajm): Only intended for internal use. Make private and friend the - // necessary classes? - virtual int proc_sample_rate_hz() const = 0; - virtual int proc_split_sample_rate_hz() const = 0; - virtual size_t num_input_channels() const = 0; - virtual size_t num_proc_channels() const = 0; - virtual size_t num_output_channels() const = 0; - virtual size_t num_reverse_channels() const = 0; - - // Set to true when the output of AudioProcessing will be muted or in some - // other way not used. Ideally, the captured audio would still be processed, - // but some components may change behavior based on this information. - // Default false. This method takes a lock. To achieve this in a lock-less - // manner the PostRuntimeSetting can instead be used. - virtual void set_output_will_be_muted(bool muted) = 0; - - // Enqueues a runtime setting. - virtual void SetRuntimeSetting(RuntimeSetting setting) = 0; - - // Enqueues a runtime setting. Returns a bool indicating whether the - // enqueueing was successfull. - virtual bool PostRuntimeSetting(RuntimeSetting setting) = 0; - - // Accepts and produces a ~10 ms frame of interleaved 16 bit integer audio as - // specified in `input_config` and `output_config`. `src` and `dest` may use - // the same memory, if desired. - virtual int ProcessStream(const int16_t* const src, - const StreamConfig& input_config, - const StreamConfig& output_config, - int16_t* const dest) = 0; - - // Accepts deinterleaved float audio with the range [-1, 1]. Each element of - // `src` points to a channel buffer, arranged according to `input_stream`. At - // output, the channels will be arranged according to `output_stream` in - // `dest`. - // - // The output must have one channel or as many channels as the input. `src` - // and `dest` may use the same memory, if desired. - virtual int ProcessStream(const float* const* src, - const StreamConfig& input_config, - const StreamConfig& output_config, - float* const* dest) = 0; - - // Accepts and produces a ~10 ms frame of interleaved 16 bit integer audio for - // the reverse direction audio stream as specified in `input_config` and - // `output_config`. `src` and `dest` may use the same memory, if desired. - virtual int ProcessReverseStream(const int16_t* const src, - const StreamConfig& input_config, - const StreamConfig& output_config, - int16_t* const dest) = 0; - - // Accepts deinterleaved float audio with the range [-1, 1]. Each element of - // `data` points to a channel buffer, arranged according to `reverse_config`. - virtual int ProcessReverseStream(const float* const* src, - const StreamConfig& input_config, - const StreamConfig& output_config, - float* const* dest) = 0; - - // Accepts deinterleaved float audio with the range [-1, 1]. Each element - // of `data` points to a channel buffer, arranged according to - // `reverse_config`. - virtual int AnalyzeReverseStream(const float* const* data, - const StreamConfig& reverse_config) = 0; - - // Returns the most recently produced ~10 ms of the linear AEC output at a - // rate of 16 kHz. If there is more than one capture channel, a mono - // representation of the input is returned. Returns true/false to indicate - // whether an output returned. - virtual bool GetLinearAecOutput( - rtc::ArrayView> linear_output) const = 0; - - // This must be called prior to ProcessStream() if and only if adaptive analog - // gain control is enabled, to pass the current analog level from the audio - // HAL. Must be within the range [0, 255]. - virtual void set_stream_analog_level(int level) = 0; - - // When an analog mode is set, this should be called after - // `set_stream_analog_level()` and `ProcessStream()` to obtain the recommended - // new analog level for the audio HAL. It is the user's responsibility to - // apply this level. - virtual int recommended_stream_analog_level() const = 0; - - // This must be called if and only if echo processing is enabled. - // - // Sets the `delay` in ms between ProcessReverseStream() receiving a far-end - // frame and ProcessStream() receiving a near-end frame containing the - // corresponding echo. On the client-side this can be expressed as - // delay = (t_render - t_analyze) + (t_process - t_capture) - // where, - // - t_analyze is the time a frame is passed to ProcessReverseStream() and - // t_render is the time the first sample of the same frame is rendered by - // the audio hardware. - // - t_capture is the time the first sample of a frame is captured by the - // audio hardware and t_process is the time the same frame is passed to - // ProcessStream(). - virtual int set_stream_delay_ms(int delay) = 0; - virtual int stream_delay_ms() const = 0; - - // Call to signal that a key press occurred (true) or did not occur (false) - // with this chunk of audio. - virtual void set_stream_key_pressed(bool key_pressed) = 0; - - // Creates and attaches an webrtc::AecDump for recording debugging - // information. - // The `worker_queue` may not be null and must outlive the created - // AecDump instance. |max_log_size_bytes == -1| means the log size - // will be unlimited. `handle` may not be null. The AecDump takes - // responsibility for `handle` and closes it in the destructor. A - // return value of true indicates that the file has been - // sucessfully opened, while a value of false indicates that - // opening the file failed. - virtual bool CreateAndAttachAecDump(absl::string_view file_name, - int64_t max_log_size_bytes, - rtc::TaskQueue* worker_queue) = 0; - virtual bool CreateAndAttachAecDump(FILE* handle, - int64_t max_log_size_bytes, - rtc::TaskQueue* worker_queue) = 0; - - // TODO(webrtc:5298) Deprecated variant. - // Attaches provided webrtc::AecDump for recording debugging - // information. Log file and maximum file size logic is supposed to - // be handled by implementing instance of AecDump. Calling this - // method when another AecDump is attached resets the active AecDump - // with a new one. This causes the d-tor of the earlier AecDump to - // be called. The d-tor call may block until all pending logging - // tasks are completed. - virtual void AttachAecDump(std::unique_ptr aec_dump) = 0; - - // If no AecDump is attached, this has no effect. If an AecDump is - // attached, it's destructor is called. The d-tor may block until - // all pending logging tasks are completed. - virtual void DetachAecDump() = 0; - - // Get audio processing statistics. - virtual AudioProcessingStats GetStatistics() = 0; - // TODO(webrtc:5298) Deprecated variant. The `has_remote_tracks` argument - // should be set if there are active remote tracks (this would usually be true - // during a call). If there are no remote tracks some of the stats will not be - // set by AudioProcessing, because they only make sense if there is at least - // one remote track. - virtual AudioProcessingStats GetStatistics(bool has_remote_tracks) = 0; - - // Returns the last applied configuration. - virtual AudioProcessing::Config GetConfig() const = 0; - - enum Error { - // Fatal errors. - kNoError = 0, - kUnspecifiedError = -1, - kCreationFailedError = -2, - kUnsupportedComponentError = -3, - kUnsupportedFunctionError = -4, - kNullPointerError = -5, - kBadParameterError = -6, - kBadSampleRateError = -7, - kBadDataLengthError = -8, - kBadNumberChannelsError = -9, - kFileError = -10, - kStreamParameterNotSetError = -11, - kNotEnabledError = -12, - - // Warnings are non-fatal. - // This results when a set_stream_ parameter is out of range. Processing - // will continue, but the parameter may have been truncated. - kBadStreamParameterWarning = -13 - }; - - // Native rates supported by the integer interfaces. - enum NativeRate { - kSampleRate8kHz = 8000, - kSampleRate16kHz = 16000, - kSampleRate32kHz = 32000, - kSampleRate48kHz = 48000 - }; - - // TODO(kwiberg): We currently need to support a compiler (Visual C++) that - // complains if we don't explicitly state the size of the array here. Remove - // the size when that's no longer the case. - static constexpr int kNativeSampleRatesHz[4] = { - kSampleRate8kHz, kSampleRate16kHz, kSampleRate32kHz, kSampleRate48kHz}; - static constexpr size_t kNumNativeSampleRates = - arraysize(kNativeSampleRatesHz); - static constexpr int kMaxNativeSampleRateHz = - kNativeSampleRatesHz[kNumNativeSampleRates - 1]; - - // APM processes audio in chunks of about 10 ms. See GetFrameSize() for - // details. - static constexpr int kChunkSizeMs = 10; - - // Returns floor(sample_rate_hz/100): the number of samples per channel used - // as input and output to the audio processing module in calls to - // ProcessStream, ProcessReverseStream, AnalyzeReverseStream, and - // GetLinearAecOutput. - // - // This is exactly 10 ms for sample rates divisible by 100. For example: - // - 48000 Hz (480 samples per channel), - // - 44100 Hz (441 samples per channel), - // - 16000 Hz (160 samples per channel). - // - // Sample rates not divisible by 100 are received/produced in frames of - // approximately 10 ms. For example: - // - 22050 Hz (220 samples per channel, or ~9.98 ms per frame), - // - 11025 Hz (110 samples per channel, or ~9.98 ms per frame). - // These nondivisible sample rates yield lower audio quality compared to - // multiples of 100. Internal resampling to 10 ms frames causes a simulated - // clock drift effect which impacts the performance of (for example) echo - // cancellation. - static int GetFrameSize(int sample_rate_hz) { return sample_rate_hz / 100; } -}; - -class RTC_EXPORT AudioProcessingBuilder { - public: - AudioProcessingBuilder(); - AudioProcessingBuilder(const AudioProcessingBuilder&) = delete; - AudioProcessingBuilder& operator=(const AudioProcessingBuilder&) = delete; - ~AudioProcessingBuilder(); - - // Sets the APM configuration. - AudioProcessingBuilder& SetConfig(const AudioProcessing::Config& config) { - config_ = config; - return *this; - } - - // Sets the echo controller factory to inject when APM is created. - AudioProcessingBuilder& SetEchoControlFactory( - std::unique_ptr echo_control_factory) { - echo_control_factory_ = std::move(echo_control_factory); - return *this; - } - - // Sets the capture post-processing sub-module to inject when APM is created. - AudioProcessingBuilder& SetCapturePostProcessing( - std::unique_ptr capture_post_processing) { - capture_post_processing_ = std::move(capture_post_processing); - return *this; - } - - // Sets the render pre-processing sub-module to inject when APM is created. - AudioProcessingBuilder& SetRenderPreProcessing( - std::unique_ptr render_pre_processing) { - render_pre_processing_ = std::move(render_pre_processing); - return *this; - } - - // Sets the echo detector to inject when APM is created. - AudioProcessingBuilder& SetEchoDetector( - rtc::scoped_refptr echo_detector) { - echo_detector_ = std::move(echo_detector); - return *this; - } - - // Sets the capture analyzer sub-module to inject when APM is created. - AudioProcessingBuilder& SetCaptureAnalyzer( - std::unique_ptr capture_analyzer) { - capture_analyzer_ = std::move(capture_analyzer); - return *this; - } - - // Creates an APM instance with the specified config or the default one if - // unspecified. Injects the specified components transferring the ownership - // to the newly created APM instance - i.e., except for the config, the - // builder is reset to its initial state. - rtc::scoped_refptr Create(); - - private: - AudioProcessing::Config config_; - std::unique_ptr echo_control_factory_; - std::unique_ptr capture_post_processing_; - std::unique_ptr render_pre_processing_; - rtc::scoped_refptr echo_detector_; - std::unique_ptr capture_analyzer_; -}; - -class StreamConfig { - public: - // sample_rate_hz: The sampling rate of the stream. - // num_channels: The number of audio channels in the stream. - StreamConfig(int sample_rate_hz = 0, size_t num_channels = 0) - : sample_rate_hz_(sample_rate_hz), - num_channels_(num_channels), - num_frames_(calculate_frames(sample_rate_hz)) {} - - void set_sample_rate_hz(int value) { - sample_rate_hz_ = value; - num_frames_ = calculate_frames(value); - } - void set_num_channels(size_t value) { num_channels_ = value; } - - int sample_rate_hz() const { return sample_rate_hz_; } - - // The number of channels in the stream. - size_t num_channels() const { return num_channels_; } - - size_t num_frames() const { return num_frames_; } - size_t num_samples() const { return num_channels_ * num_frames_; } - - bool operator==(const StreamConfig& other) const { - return sample_rate_hz_ == other.sample_rate_hz_ && - num_channels_ == other.num_channels_; - } - - bool operator!=(const StreamConfig& other) const { return !(*this == other); } - - private: - static size_t calculate_frames(int sample_rate_hz) { - return static_cast(AudioProcessing::GetFrameSize(sample_rate_hz)); - } - - int sample_rate_hz_; - size_t num_channels_; - size_t num_frames_; -}; - -class ProcessingConfig { - public: - enum StreamName { - kInputStream, - kOutputStream, - kReverseInputStream, - kReverseOutputStream, - kNumStreamNames, - }; - - const StreamConfig& input_stream() const { - return streams[StreamName::kInputStream]; - } - const StreamConfig& output_stream() const { - return streams[StreamName::kOutputStream]; - } - const StreamConfig& reverse_input_stream() const { - return streams[StreamName::kReverseInputStream]; - } - const StreamConfig& reverse_output_stream() const { - return streams[StreamName::kReverseOutputStream]; - } - - StreamConfig& input_stream() { return streams[StreamName::kInputStream]; } - StreamConfig& output_stream() { return streams[StreamName::kOutputStream]; } - StreamConfig& reverse_input_stream() { - return streams[StreamName::kReverseInputStream]; - } - StreamConfig& reverse_output_stream() { - return streams[StreamName::kReverseOutputStream]; - } - - bool operator==(const ProcessingConfig& other) const { - for (int i = 0; i < StreamName::kNumStreamNames; ++i) { - if (this->streams[i] != other.streams[i]) { - return false; - } - } - return true; - } - - bool operator!=(const ProcessingConfig& other) const { - return !(*this == other); - } - - StreamConfig streams[StreamName::kNumStreamNames]; -}; - -// Experimental interface for a custom analysis submodule. -class CustomAudioAnalyzer { - public: - // (Re-) Initializes the submodule. - virtual void Initialize(int sample_rate_hz, int num_channels) = 0; - // Analyzes the given capture or render signal. - virtual void Analyze(const AudioBuffer* audio) = 0; - // Returns a string representation of the module state. - virtual std::string ToString() const = 0; - - virtual ~CustomAudioAnalyzer() {} -}; - -// Interface for a custom processing submodule. -class CustomProcessing { - public: - // (Re-)Initializes the submodule. - virtual void Initialize(int sample_rate_hz, int num_channels) = 0; - // Processes the given capture or render signal. - virtual void Process(AudioBuffer* audio) = 0; - // Returns a string representation of the module state. - virtual std::string ToString() const = 0; - // Handles RuntimeSettings. TODO(webrtc:9262): make pure virtual - // after updating dependencies. - virtual void SetRuntimeSetting(AudioProcessing::RuntimeSetting setting); - - virtual ~CustomProcessing() {} -}; - -// Interface for an echo detector submodule. -class EchoDetector : public rtc::RefCountInterface { - public: - // (Re-)Initializes the submodule. - virtual void Initialize(int capture_sample_rate_hz, - int num_capture_channels, - int render_sample_rate_hz, - int num_render_channels) = 0; - - // Analysis (not changing) of the first channel of the render signal. - virtual void AnalyzeRenderAudio(rtc::ArrayView render_audio) = 0; - - // Analysis (not changing) of the capture signal. - virtual void AnalyzeCaptureAudio( - rtc::ArrayView capture_audio) = 0; - - struct Metrics { - absl::optional echo_likelihood; - absl::optional echo_likelihood_recent_max; - }; - - // Collect current metrics from the echo detector. - virtual Metrics GetMetrics() const = 0; -}; - -} // namespace webrtc +// This is a transitional header forwarding to the new version in the api/ +// folder. +#include "api/audio/audio_processing.h" #endif // MODULES_AUDIO_PROCESSING_INCLUDE_AUDIO_PROCESSING_H_ diff --git a/webrtc/modules/audio_processing/include/audio_processing_statistics.h b/webrtc/modules/audio_processing/include/audio_processing_statistics.h index 3b43319..594d3f5 100644 --- a/webrtc/modules/audio_processing/include/audio_processing_statistics.h +++ b/webrtc/modules/audio_processing/include/audio_processing_statistics.h @@ -11,57 +11,8 @@ #ifndef MODULES_AUDIO_PROCESSING_INCLUDE_AUDIO_PROCESSING_STATISTICS_H_ #define MODULES_AUDIO_PROCESSING_INCLUDE_AUDIO_PROCESSING_STATISTICS_H_ -#include - -#include "absl/types/optional.h" -#include "rtc_base/system/rtc_export.h" - -namespace webrtc { -// This version of the stats uses Optionals, it will replace the regular -// AudioProcessingStatistics struct. -struct RTC_EXPORT AudioProcessingStats { - AudioProcessingStats(); - AudioProcessingStats(const AudioProcessingStats& other); - ~AudioProcessingStats(); - - // Deprecated. - // TODO(bugs.webrtc.org/11226): Remove. - // True if voice is detected in the last capture frame, after processing. - // It is conservative in flagging audio as speech, with low likelihood of - // incorrectly flagging a frame as voice. - // Only reported if voice detection is enabled in AudioProcessing::Config. - absl::optional voice_detected; - - // AEC Statistics. - // ERL = 10log_10(P_far / P_echo) - absl::optional echo_return_loss; - // ERLE = 10log_10(P_echo / P_out) - absl::optional echo_return_loss_enhancement; - // Fraction of time that the AEC linear filter is divergent, in a 1-second - // non-overlapped aggregation window. - absl::optional divergent_filter_fraction; - - // The delay metrics consists of the delay median and standard deviation. It - // also consists of the fraction of delay estimates that can make the echo - // cancellation perform poorly. The values are aggregated until the first - // call to `GetStatistics()` and afterwards aggregated and updated every - // second. Note that if there are several clients pulling metrics from - // `GetStatistics()` during a session the first call from any of them will - // change to one second aggregation window for all. - absl::optional delay_median_ms; - absl::optional delay_standard_deviation_ms; - - // Residual echo detector likelihood. - absl::optional residual_echo_likelihood; - // Maximum residual echo likelihood from the last time period. - absl::optional residual_echo_likelihood_recent_max; - - // The instantaneous delay estimate produced in the AEC. The unit is in - // milliseconds and the value is the instantaneous value at the time of the - // call to `GetStatistics()`. - absl::optional delay_ms; -}; - -} // namespace webrtc +// This is a transitional header forwarding to the new version in the api/ +// folder. +#include "api/audio/audio_processing_statistics.h" #endif // MODULES_AUDIO_PROCESSING_INCLUDE_AUDIO_PROCESSING_STATISTICS_H_ diff --git a/webrtc/modules/audio_processing/include/config.cc b/webrtc/modules/audio_processing/include/config.cc deleted file mode 100644 index 14240db..0000000 --- a/webrtc/modules/audio_processing/include/config.cc +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "modules/audio_processing/include/config.h" - -namespace webrtc { - -Config::Config() {} - -Config::~Config() { - for (OptionMap::iterator it = options_.begin(); it != options_.end(); ++it) { - delete it->second; - } -} - -} // namespace webrtc diff --git a/webrtc/modules/audio_processing/include/config.h b/webrtc/modules/audio_processing/include/config.h deleted file mode 100644 index 7fab178..0000000 --- a/webrtc/modules/audio_processing/include/config.h +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef MODULES_AUDIO_PROCESSING_INCLUDE_CONFIG_H_ -#define MODULES_AUDIO_PROCESSING_INCLUDE_CONFIG_H_ - -#include - -#include "rtc_base/system/rtc_export.h" - -namespace webrtc { - -// Only add new values to the end of the enumeration and never remove (only -// deprecate) to maintain binary compatibility. -enum class ConfigOptionID { - kMyExperimentForTest, - kAlgo1CostFunctionForTest, - kTemporalLayersFactory, // Deprecated - kNetEqCapacityConfig, // Deprecated - kNetEqFastAccelerate, // Deprecated - kVoicePacing, // Deprecated - kExtendedFilter, // Deprecated - kDelayAgnostic, // Deprecated - kExperimentalAgc, - kExperimentalNs, - kBeamforming, // Deprecated - kIntelligibility, // Deprecated - kEchoCanceller3, // Deprecated - kAecRefinedAdaptiveFilter, // Deprecated - kLevelControl // Deprecated -}; - -// Class Config is designed to ease passing a set of options across webrtc code. -// Options are identified by typename in order to avoid incorrect casts. -// -// Usage: -// * declaring an option: -// struct Algo1_CostFunction { -// virtual float cost(int x) const { return x; } -// virtual ~Algo1_CostFunction() {} -// }; -// -// * accessing an option: -// config.Get().cost(value); -// -// * setting an option: -// struct SqrCost : Algo1_CostFunction { -// virtual float cost(int x) const { return x*x; } -// }; -// config.Set(new SqrCost()); -// -// Note: This class is thread-compatible (like STL containers). -class RTC_EXPORT Config { - public: - // Returns the option if set or a default constructed one. - // Callers that access options too often are encouraged to cache the result. - // Returned references are owned by this. - // - // Requires std::is_default_constructible - template - const T& Get() const; - - // Set the option, deleting any previous instance of the same. - // This instance gets ownership of the newly set value. - template - void Set(T* value); - - Config(); - ~Config(); - - private: - struct BaseOption { - virtual ~BaseOption() {} - }; - - template - struct Option : BaseOption { - explicit Option(T* v) : value(v) {} - ~Option() { delete value; } - T* value; - }; - - template - static ConfigOptionID identifier() { - return T::identifier; - } - - // Used to instantiate a default constructed object that doesn't needs to be - // owned. This allows Get to be implemented without requiring explicitly - // locks. - template - static const T& default_value() { - static const T* const def = new T(); - return *def; - } - - typedef std::map OptionMap; - OptionMap options_; - - Config(const Config&); - void operator=(const Config&); -}; - -template -const T& Config::Get() const { - OptionMap::const_iterator it = options_.find(identifier()); - if (it != options_.end()) { - const T* t = static_cast*>(it->second)->value; - if (t) { - return *t; - } - } - return default_value(); -} - -template -void Config::Set(T* value) { - BaseOption*& it = options_[identifier()]; - delete it; - it = new Option(value); -} -} // namespace webrtc - -#endif // MODULES_AUDIO_PROCESSING_INCLUDE_CONFIG_H_ diff --git a/webrtc/modules/audio_processing/logging/apm_data_dumper.cc b/webrtc/modules/audio_processing/logging/apm_data_dumper.cc index 65d2167..283f739 100644 --- a/webrtc/modules/audio_processing/logging/apm_data_dumper.cc +++ b/webrtc/modules/audio_processing/logging/apm_data_dumper.cc @@ -61,7 +61,7 @@ ApmDataDumper::~ApmDataDumper() = default; #if WEBRTC_APM_DEBUG_DUMP == 1 bool ApmDataDumper::recording_activated_ = false; -absl::optional ApmDataDumper::dump_set_to_use_; +std::optional ApmDataDumper::dump_set_to_use_; char ApmDataDumper::output_dir_[] = ""; FILE* ApmDataDumper::GetRawFile(absl::string_view name) { diff --git a/webrtc/modules/audio_processing/logging/apm_data_dumper.h b/webrtc/modules/audio_processing/logging/apm_data_dumper.h index 76f8b34..5186854 100644 --- a/webrtc/modules/audio_processing/logging/apm_data_dumper.h +++ b/webrtc/modules/audio_processing/logging/apm_data_dumper.h @@ -20,8 +20,9 @@ #include #endif +#include + #include "absl/strings/string_view.h" -#include "absl/types/optional.h" #include "api/array_view.h" #if WEBRTC_APM_DEBUG_DUMP == 1 #include "common_audio/wav_file.h" @@ -391,7 +392,7 @@ class ApmDataDumper { private: #if WEBRTC_APM_DEBUG_DUMP == 1 static bool recording_activated_; - static absl::optional dump_set_to_use_; + static std::optional dump_set_to_use_; static constexpr size_t kOutputDirMaxLength = 1024; static char output_dir_[kOutputDirMaxLength]; const int instance_index_; diff --git a/webrtc/modules/audio_processing/meson.build b/webrtc/modules/audio_processing/meson.build index 91382db..2a2b23b 100644 --- a/webrtc/modules/audio_processing/meson.build +++ b/webrtc/modules/audio_processing/meson.build @@ -114,9 +114,6 @@ webrtc_audio_processing_sources = [ 'high_pass_filter.cc', 'include/aec_dump.cc', 'include/audio_frame_proxies.cc', - 'include/audio_processing.cc', - 'include/audio_processing_statistics.cc', - 'include/config.cc', 'logging/apm_data_dumper.cc', 'ns/fast_math.cc', 'ns/histograms.cc', @@ -131,18 +128,10 @@ webrtc_audio_processing_sources = [ 'ns/speech_probability_estimator.cc', 'ns/suppression_params.cc', 'ns/wiener_filter.cc', - 'optionally_built_submodule_creators.cc', 'residual_echo_detector.cc', 'rms_level.cc', 'splitting_filter.cc', 'three_band_filter_bank.cc', - 'transient/file_utils.cc', - 'transient/moving_moments.cc', - 'transient/transient_detector.cc', - 'transient/transient_suppressor_impl.cc', - 'transient/voice_probability_delay_unit.cc', - 'transient/wpd_node.cc', - 'transient/wpd_tree.cc', 'utility/cascaded_biquad_filter.cc', 'utility/delay_estimator.cc', 'utility/delay_estimator_wrapper.cc', @@ -160,7 +149,6 @@ webrtc_audio_processing_sources = [ webrtc_audio_processing_include_headers = [ 'include/audio_processing.h', 'include/audio_processing_statistics.h', - 'include/config.h', ] extra_libs = [] @@ -204,9 +192,9 @@ libwebrtc_audio_processing = library(apm_project_name, dependencies: [ base_dep, api_dep, - isac_vad_dep, system_wrappers_dep, common_audio_dep, + isac_vad_dep, pffft_dep, rnnoise_dep, ] + common_deps, diff --git a/webrtc/modules/audio_processing/ns/BUILD.gn b/webrtc/modules/audio_processing/ns/BUILD.gn index d818e23..31ad611 100644 --- a/webrtc/modules/audio_processing/ns/BUILD.gn +++ b/webrtc/modules/audio_processing/ns/BUILD.gn @@ -64,7 +64,6 @@ rtc_static_library("ns") { "../../../system_wrappers:metrics", "../utility:cascaded_biquad_filter", ] - absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] } if (rtc_include_tests) { @@ -89,7 +88,6 @@ if (rtc_include_tests) { "../../../test:test_support", "../utility:cascaded_biquad_filter", ] - absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] defines = [] diff --git a/webrtc/modules/audio_processing/optionally_built_submodule_creators.cc b/webrtc/modules/audio_processing/optionally_built_submodule_creators.cc deleted file mode 100644 index cea5c83..0000000 --- a/webrtc/modules/audio_processing/optionally_built_submodule_creators.cc +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2020 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "modules/audio_processing/optionally_built_submodule_creators.h" - -#include - -#include "modules/audio_processing/transient/transient_suppressor_impl.h" - -namespace webrtc { - -std::unique_ptr CreateTransientSuppressor( - const ApmSubmoduleCreationOverrides& overrides, - TransientSuppressor::VadMode vad_mode, - int sample_rate_hz, - int detection_rate_hz, - int num_channels) { -#ifdef WEBRTC_EXCLUDE_TRANSIENT_SUPPRESSOR - return nullptr; -#else - if (overrides.transient_suppression) { - return nullptr; - } - return std::make_unique( - vad_mode, sample_rate_hz, detection_rate_hz, num_channels); -#endif -} - -} // namespace webrtc diff --git a/webrtc/modules/audio_processing/optionally_built_submodule_creators.h b/webrtc/modules/audio_processing/optionally_built_submodule_creators.h deleted file mode 100644 index 1be2743..0000000 --- a/webrtc/modules/audio_processing/optionally_built_submodule_creators.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2020 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef MODULES_AUDIO_PROCESSING_OPTIONALLY_BUILT_SUBMODULE_CREATORS_H_ -#define MODULES_AUDIO_PROCESSING_OPTIONALLY_BUILT_SUBMODULE_CREATORS_H_ - -#include - -#include "modules/audio_processing/transient/transient_suppressor.h" - -namespace webrtc { - -// These overrides are only to be used for testing purposes. -// Each flag emulates a preprocessor macro to exclude a submodule of APM from -// the build, e.g. WEBRTC_EXCLUDE_TRANSIENT_SUPPRESSOR. If the corresponding -// flag `transient_suppression` is enabled, then the creators will return -// nullptr instead of a submodule instance, as if the macro had been defined. -struct ApmSubmoduleCreationOverrides { - bool transient_suppression = false; -}; - -// Creates a transient suppressor. -// Will instead return nullptr if one of the following is true: -// * WEBRTC_EXCLUDE_TRANSIENT_SUPPRESSOR is defined -// * The corresponding override in `overrides` is enabled. -std::unique_ptr CreateTransientSuppressor( - const ApmSubmoduleCreationOverrides& overrides, - TransientSuppressor::VadMode vad_mode, - int sample_rate_hz, - int detection_rate_hz, - int num_channels); - -} // namespace webrtc - -#endif // MODULES_AUDIO_PROCESSING_OPTIONALLY_BUILT_SUBMODULE_CREATORS_H_ diff --git a/webrtc/modules/audio_processing/residual_echo_detector.cc b/webrtc/modules/audio_processing/residual_echo_detector.cc index 2a564fc..06ac149 100644 --- a/webrtc/modules/audio_processing/residual_echo_detector.cc +++ b/webrtc/modules/audio_processing/residual_echo_detector.cc @@ -12,8 +12,8 @@ #include #include +#include -#include "absl/types/optional.h" #include "modules/audio_processing/logging/apm_data_dumper.h" #include "rtc_base/checks.h" #include "rtc_base/logging.h" @@ -89,7 +89,7 @@ void ResidualEchoDetector::AnalyzeCaptureAudio( } // Get the next render value. - const absl::optional buffered_render_power = render_buffer_.Pop(); + const std::optional buffered_render_power = render_buffer_.Pop(); if (!buffered_render_power) { // This can happen in a few cases: at the start of a call, due to a glitch // or due to clock drift. The excess capture value will be ignored. diff --git a/webrtc/modules/audio_processing/residual_echo_detector.h b/webrtc/modules/audio_processing/residual_echo_detector.h index ac554b1..83773ae 100644 --- a/webrtc/modules/audio_processing/residual_echo_detector.h +++ b/webrtc/modules/audio_processing/residual_echo_detector.h @@ -15,11 +15,11 @@ #include #include "api/array_view.h" +#include "api/audio/audio_processing.h" #include "modules/audio_processing/echo_detector/circular_buffer.h" #include "modules/audio_processing/echo_detector/mean_variance_estimator.h" #include "modules/audio_processing/echo_detector/moving_max.h" #include "modules/audio_processing/echo_detector/normalized_covariance_estimator.h" -#include "modules/audio_processing/include/audio_processing.h" namespace webrtc { diff --git a/webrtc/modules/audio_processing/rms_level.cc b/webrtc/modules/audio_processing/rms_level.cc index b0a45cb..1c00e83 100644 --- a/webrtc/modules/audio_processing/rms_level.cc +++ b/webrtc/modules/audio_processing/rms_level.cc @@ -54,7 +54,7 @@ void RmsLevel::Reset() { sum_square_ = 0.f; sample_count_ = 0; max_sum_square_ = 0.f; - block_size_ = absl::nullopt; + block_size_ = std::nullopt; } void RmsLevel::Analyze(rtc::ArrayView data) { @@ -119,7 +119,7 @@ int RmsLevel::Average() { RmsLevel::Levels RmsLevel::AverageAndPeak() { // Note that block_size_ should by design always be non-empty when - // sample_count_ != 0. Also, the * operator of absl::optional enforces this + // sample_count_ != 0. Also, the * operator of std::optional enforces this // with a DCHECK. Levels levels = (sample_count_ == 0) ? Levels{RmsLevel::kMinLevelDb, RmsLevel::kMinLevelDb} diff --git a/webrtc/modules/audio_processing/rms_level.h b/webrtc/modules/audio_processing/rms_level.h index fbece19..b2a5ba0 100644 --- a/webrtc/modules/audio_processing/rms_level.h +++ b/webrtc/modules/audio_processing/rms_level.h @@ -14,7 +14,8 @@ #include #include -#include "absl/types/optional.h" +#include + #include "api/array_view.h" namespace webrtc { @@ -69,7 +70,7 @@ class RmsLevel { float sum_square_; size_t sample_count_; float max_sum_square_; - absl::optional block_size_; + std::optional block_size_; }; } // namespace webrtc diff --git a/webrtc/modules/audio_processing/transient/BUILD.gn b/webrtc/modules/audio_processing/transient/BUILD.gn deleted file mode 100644 index 41aeab0..0000000 --- a/webrtc/modules/audio_processing/transient/BUILD.gn +++ /dev/null @@ -1,133 +0,0 @@ -# Copyright (c) 2020 The WebRTC project authors. All Rights Reserved. -# -# Use of this source code is governed by a BSD-style license -# that can be found in the LICENSE file in the root of the source -# tree. An additional intellectual property rights grant can be found -# in the file PATENTS. All contributing project authors may -# be found in the AUTHORS file in the root of the source tree. - -import("../../../webrtc.gni") - -rtc_source_set("transient_suppressor_api") { - sources = [ "transient_suppressor.h" ] -} - -rtc_library("transient_suppressor_impl") { - visibility = [ - ":click_annotate", - ":transient_suppression_test", - ":transient_suppression_unittests", - "..:optionally_built_submodule_creators", - ] - sources = [ - "common.h", - "daubechies_8_wavelet_coeffs.h", - "dyadic_decimator.h", - "moving_moments.cc", - "moving_moments.h", - "transient_detector.cc", - "transient_detector.h", - "transient_suppressor_impl.cc", - "transient_suppressor_impl.h", - "windows_private.h", - "wpd_node.cc", - "wpd_node.h", - "wpd_tree.cc", - "wpd_tree.h", - ] - deps = [ - ":transient_suppressor_api", - ":voice_probability_delay_unit", - "../../../common_audio:common_audio", - "../../../common_audio:common_audio_c", - "../../../common_audio:fir_filter", - "../../../common_audio:fir_filter_factory", - "../../../common_audio/third_party/ooura:fft_size_256", - "../../../rtc_base:checks", - "../../../rtc_base:gtest_prod", - "../../../rtc_base:logging", - ] -} - -rtc_library("voice_probability_delay_unit") { - sources = [ - "voice_probability_delay_unit.cc", - "voice_probability_delay_unit.h", - ] - deps = [ "../../../rtc_base:checks" ] -} - -if (rtc_include_tests) { - if (!build_with_chromium) { - rtc_executable("click_annotate") { - testonly = true - sources = [ - "click_annotate.cc", - "file_utils.cc", - "file_utils.h", - ] - deps = [ - ":transient_suppressor_impl", - "..:audio_processing", - "../../../rtc_base/system:file_wrapper", - "../../../system_wrappers", - ] - } - - rtc_executable("transient_suppression_test") { - testonly = true - sources = [ - "file_utils.cc", - "file_utils.h", - "transient_suppression_test.cc", - "voice_probability_delay_unit_unittest.cc", - ] - deps = [ - ":transient_suppressor_api", - ":transient_suppressor_impl", - ":voice_probability_delay_unit", - "..:audio_processing", - "../../../common_audio", - "../../../rtc_base/system:file_wrapper", - "../../../system_wrappers", - "../../../test:fileutils", - "../../../test:test_support", - "../agc:level_estimation", - "//testing/gtest", - "//third_party/abseil-cpp/absl/flags:flag", - "//third_party/abseil-cpp/absl/flags:parse", - "//third_party/abseil-cpp/absl/types:optional", - ] - } - } - - rtc_library("transient_suppression_unittests") { - testonly = true - sources = [ - "dyadic_decimator_unittest.cc", - "file_utils.cc", - "file_utils.h", - "file_utils_unittest.cc", - "moving_moments_unittest.cc", - "transient_detector_unittest.cc", - "transient_suppressor_unittest.cc", - "voice_probability_delay_unit_unittest.cc", - "wpd_node_unittest.cc", - "wpd_tree_unittest.cc", - ] - deps = [ - ":transient_suppressor_api", - ":transient_suppressor_impl", - ":voice_probability_delay_unit", - "../../../rtc_base:stringutils", - "../../../rtc_base/system:file_wrapper", - "../../../test:fileutils", - "../../../test:test_support", - "//testing/gtest", - ] - absl_deps = [ - "//third_party/abseil-cpp/absl/strings", - "//third_party/abseil-cpp/absl/types:optional", - ] - } -} diff --git a/webrtc/modules/audio_processing/transient/common.h b/webrtc/modules/audio_processing/transient/common.h deleted file mode 100644 index 63c9a7b..0000000 --- a/webrtc/modules/audio_processing/transient/common.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef MODULES_AUDIO_PROCESSING_TRANSIENT_COMMON_H_ -#define MODULES_AUDIO_PROCESSING_TRANSIENT_COMMON_H_ -namespace webrtc { -namespace ts { - -static const float kPi = 3.14159265358979323846f; -static const int kChunkSizeMs = 10; -enum { - kSampleRate8kHz = 8000, - kSampleRate16kHz = 16000, - kSampleRate32kHz = 32000, - kSampleRate48kHz = 48000 -}; - -} // namespace ts -} // namespace webrtc -#endif // MODULES_AUDIO_PROCESSING_TRANSIENT_COMMON_H_ diff --git a/webrtc/modules/audio_processing/transient/daubechies_8_wavelet_coeffs.h b/webrtc/modules/audio_processing/transient/daubechies_8_wavelet_coeffs.h deleted file mode 100644 index 92233bf..0000000 --- a/webrtc/modules/audio_processing/transient/daubechies_8_wavelet_coeffs.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -// This header file defines the coefficients of the FIR based approximation of -// the Meyer Wavelet -#ifndef MODULES_AUDIO_PROCESSING_TRANSIENT_DAUBECHIES_8_WAVELET_COEFFS_H_ -#define MODULES_AUDIO_PROCESSING_TRANSIENT_DAUBECHIES_8_WAVELET_COEFFS_H_ - -// Decomposition coefficients Daubechies 8. - -namespace webrtc { - -const int kDaubechies8CoefficientsLength = 16; - -const float kDaubechies8HighPassCoefficients[kDaubechies8CoefficientsLength] = { - -5.44158422430816093862e-02f, 3.12871590914465924627e-01f, - -6.75630736298012846142e-01f, 5.85354683654869090148e-01f, - 1.58291052560238926228e-02f, -2.84015542962428091389e-01f, - -4.72484573997972536787e-04f, 1.28747426620186011803e-01f, - 1.73693010020221083600e-02f, -4.40882539310647192377e-02f, - -1.39810279170155156436e-02f, 8.74609404701565465445e-03f, - 4.87035299301066034600e-03f, -3.91740372995977108837e-04f, - -6.75449405998556772109e-04f, -1.17476784002281916305e-04f}; - -const float kDaubechies8LowPassCoefficients[kDaubechies8CoefficientsLength] = { - -1.17476784002281916305e-04f, 6.75449405998556772109e-04f, - -3.91740372995977108837e-04f, -4.87035299301066034600e-03f, - 8.74609404701565465445e-03f, 1.39810279170155156436e-02f, - -4.40882539310647192377e-02f, -1.73693010020221083600e-02f, - 1.28747426620186011803e-01f, 4.72484573997972536787e-04f, - -2.84015542962428091389e-01f, -1.58291052560238926228e-02f, - 5.85354683654869090148e-01f, 6.75630736298012846142e-01f, - 3.12871590914465924627e-01f, 5.44158422430816093862e-02f}; - -} // namespace webrtc - -#endif // MODULES_AUDIO_PROCESSING_TRANSIENT_DAUBECHIES_8_WAVELET_COEFFS_H_ diff --git a/webrtc/modules/audio_processing/transient/dyadic_decimator.h b/webrtc/modules/audio_processing/transient/dyadic_decimator.h deleted file mode 100644 index 52467e8..0000000 --- a/webrtc/modules/audio_processing/transient/dyadic_decimator.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef MODULES_AUDIO_PROCESSING_TRANSIENT_DYADIC_DECIMATOR_H_ -#define MODULES_AUDIO_PROCESSING_TRANSIENT_DYADIC_DECIMATOR_H_ - -#include - -// Provides a set of static methods to perform dyadic decimations. - -namespace webrtc { - -// Returns the proper length of the output buffer that you should use for the -// given `in_length` and decimation `odd_sequence`. -// Return -1 on error. -inline size_t GetOutLengthToDyadicDecimate(size_t in_length, - bool odd_sequence) { - size_t out_length = in_length / 2; - - if (in_length % 2 == 1 && !odd_sequence) { - ++out_length; - } - - return out_length; -} - -// Performs a dyadic decimation: removes every odd/even member of a sequence -// halving its overall length. -// Arguments: -// in: array of `in_length`. -// odd_sequence: If false, the odd members will be removed (1, 3, 5, ...); -// if true, the even members will be removed (0, 2, 4, ...). -// out: array of `out_length`. `out_length` must be large enough to -// hold the decimated output. The necessary length can be provided by -// GetOutLengthToDyadicDecimate(). -// Must be previously allocated. -// Returns the number of output samples, -1 on error. -template -static size_t DyadicDecimate(const T* in, - size_t in_length, - bool odd_sequence, - T* out, - size_t out_length) { - size_t half_length = GetOutLengthToDyadicDecimate(in_length, odd_sequence); - - if (!in || !out || in_length <= 0 || out_length < half_length) { - return 0; - } - - size_t output_samples = 0; - size_t index_adjustment = odd_sequence ? 1 : 0; - for (output_samples = 0; output_samples < half_length; ++output_samples) { - out[output_samples] = in[output_samples * 2 + index_adjustment]; - } - - return output_samples; -} - -} // namespace webrtc - -#endif // MODULES_AUDIO_PROCESSING_TRANSIENT_DYADIC_DECIMATOR_H_ diff --git a/webrtc/modules/audio_processing/transient/file_utils.cc b/webrtc/modules/audio_processing/transient/file_utils.cc deleted file mode 100644 index 58f9932..0000000 --- a/webrtc/modules/audio_processing/transient/file_utils.cc +++ /dev/null @@ -1,257 +0,0 @@ -/* - * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "modules/audio_processing/transient/file_utils.h" - -#include - -#include "rtc_base/system/file_wrapper.h" - -namespace webrtc { - -int ConvertByteArrayToFloat(const uint8_t bytes[4], float* out) { - if (!bytes || !out) { - return -1; - } - - uint32_t binary_value = 0; - for (int i = 3; i >= 0; --i) { - binary_value <<= 8; - binary_value += bytes[i]; - } - - *out = bit_cast(binary_value); - - return 0; -} - -int ConvertByteArrayToDouble(const uint8_t bytes[8], double* out) { - if (!bytes || !out) { - return -1; - } - - uint64_t binary_value = 0; - for (int i = 7; i >= 0; --i) { - binary_value <<= 8; - binary_value += bytes[i]; - } - - *out = bit_cast(binary_value); - - return 0; -} - -int ConvertFloatToByteArray(float value, uint8_t out_bytes[4]) { - if (!out_bytes) { - return -1; - } - - uint32_t binary_value = bit_cast(value); - for (size_t i = 0; i < 4; ++i) { - out_bytes[i] = binary_value; - binary_value >>= 8; - } - - return 0; -} - -int ConvertDoubleToByteArray(double value, uint8_t out_bytes[8]) { - if (!out_bytes) { - return -1; - } - - uint64_t binary_value = bit_cast(value); - for (size_t i = 0; i < 8; ++i) { - out_bytes[i] = binary_value; - binary_value >>= 8; - } - - return 0; -} - -size_t ReadInt16BufferFromFile(FileWrapper* file, - size_t length, - int16_t* buffer) { - if (!file || !file->is_open() || !buffer || length <= 0) { - return 0; - } - - std::unique_ptr byte_array(new uint8_t[2]); - - size_t int16s_read = 0; - - while (int16s_read < length) { - size_t bytes_read = file->Read(byte_array.get(), 2); - if (bytes_read < 2) { - break; - } - int16_t value = byte_array[1]; - value <<= 8; - value += byte_array[0]; - buffer[int16s_read] = value; - ++int16s_read; - } - - return int16s_read; -} - -size_t ReadInt16FromFileToFloatBuffer(FileWrapper* file, - size_t length, - float* buffer) { - if (!file || !file->is_open() || !buffer || length <= 0) { - return 0; - } - - std::unique_ptr buffer16(new int16_t[length]); - - size_t int16s_read = ReadInt16BufferFromFile(file, length, buffer16.get()); - - for (size_t i = 0; i < int16s_read; ++i) { - buffer[i] = buffer16[i]; - } - - return int16s_read; -} - -size_t ReadInt16FromFileToDoubleBuffer(FileWrapper* file, - size_t length, - double* buffer) { - if (!file || !file->is_open() || !buffer || length <= 0) { - return 0; - } - - std::unique_ptr buffer16(new int16_t[length]); - - size_t int16s_read = ReadInt16BufferFromFile(file, length, buffer16.get()); - - for (size_t i = 0; i < int16s_read; ++i) { - buffer[i] = buffer16[i]; - } - - return int16s_read; -} - -size_t ReadFloatBufferFromFile(FileWrapper* file, - size_t length, - float* buffer) { - if (!file || !file->is_open() || !buffer || length <= 0) { - return 0; - } - - std::unique_ptr byte_array(new uint8_t[4]); - - size_t floats_read = 0; - - while (floats_read < length) { - size_t bytes_read = file->Read(byte_array.get(), 4); - if (bytes_read < 4) { - break; - } - ConvertByteArrayToFloat(byte_array.get(), &buffer[floats_read]); - ++floats_read; - } - - return floats_read; -} - -size_t ReadDoubleBufferFromFile(FileWrapper* file, - size_t length, - double* buffer) { - if (!file || !file->is_open() || !buffer || length <= 0) { - return 0; - } - - std::unique_ptr byte_array(new uint8_t[8]); - - size_t doubles_read = 0; - - while (doubles_read < length) { - size_t bytes_read = file->Read(byte_array.get(), 8); - if (bytes_read < 8) { - break; - } - ConvertByteArrayToDouble(byte_array.get(), &buffer[doubles_read]); - ++doubles_read; - } - - return doubles_read; -} - -size_t WriteInt16BufferToFile(FileWrapper* file, - size_t length, - const int16_t* buffer) { - if (!file || !file->is_open() || !buffer || length <= 0) { - return 0; - } - - std::unique_ptr byte_array(new uint8_t[2]); - - size_t int16s_written = 0; - - for (int16s_written = 0; int16s_written < length; ++int16s_written) { - // Get byte representation. - byte_array[0] = buffer[int16s_written] & 0xFF; - byte_array[1] = (buffer[int16s_written] >> 8) & 0xFF; - - file->Write(byte_array.get(), 2); - } - - file->Flush(); - - return int16s_written; -} - -size_t WriteFloatBufferToFile(FileWrapper* file, - size_t length, - const float* buffer) { - if (!file || !file->is_open() || !buffer || length <= 0) { - return 0; - } - - std::unique_ptr byte_array(new uint8_t[4]); - - size_t floats_written = 0; - - for (floats_written = 0; floats_written < length; ++floats_written) { - // Get byte representation. - ConvertFloatToByteArray(buffer[floats_written], byte_array.get()); - - file->Write(byte_array.get(), 4); - } - - file->Flush(); - - return floats_written; -} - -size_t WriteDoubleBufferToFile(FileWrapper* file, - size_t length, - const double* buffer) { - if (!file || !file->is_open() || !buffer || length <= 0) { - return 0; - } - - std::unique_ptr byte_array(new uint8_t[8]); - - size_t doubles_written = 0; - - for (doubles_written = 0; doubles_written < length; ++doubles_written) { - // Get byte representation. - ConvertDoubleToByteArray(buffer[doubles_written], byte_array.get()); - - file->Write(byte_array.get(), 8); - } - - file->Flush(); - - return doubles_written; -} - -} // namespace webrtc diff --git a/webrtc/modules/audio_processing/transient/file_utils.h b/webrtc/modules/audio_processing/transient/file_utils.h deleted file mode 100644 index b748337..0000000 --- a/webrtc/modules/audio_processing/transient/file_utils.h +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef MODULES_AUDIO_PROCESSING_TRANSIENT_FILE_UTILS_H_ -#define MODULES_AUDIO_PROCESSING_TRANSIENT_FILE_UTILS_H_ - -#include - -#include "rtc_base/system/file_wrapper.h" - -namespace webrtc { - -// This is a copy of the cast included in the Chromium codebase here: -// http://cs.chromium.org/src/third_party/cld/base/casts.h -template -inline Dest bit_cast(const Source& source) { - // A compile error here means your Dest and Source have different sizes. - static_assert(sizeof(Dest) == sizeof(Source), - "Dest and Source have different sizes"); - - Dest dest; - memcpy(&dest, &source, sizeof(dest)); - return dest; -} - -// Converts the byte array with binary float representation to float. -// Bytes must be in little-endian order. -// Returns 0 if correct, -1 on error. -int ConvertByteArrayToFloat(const uint8_t bytes[4], float* out); - -// Converts the byte array with binary double representation to double. -// Bytes must be in little-endian order. -// Returns 0 if correct, -1 on error. -int ConvertByteArrayToDouble(const uint8_t bytes[8], double* out); - -// Converts a float to a byte array with binary float representation. -// Bytes will be in little-endian order. -// Returns 0 if correct, -1 on error. -int ConvertFloatToByteArray(float value, uint8_t out_bytes[4]); - -// Converts a double to a byte array with binary double representation. -// Bytes will be in little-endian order. -// Returns 0 if correct, -1 on error. -int ConvertDoubleToByteArray(double value, uint8_t out_bytes[8]); - -// Reads `length` 16-bit integers from `file` to `buffer`. -// `file` must be previously opened. -// Returns the number of 16-bit integers read or -1 on error. -size_t ReadInt16BufferFromFile(FileWrapper* file, - size_t length, - int16_t* buffer); - -// Reads `length` 16-bit integers from `file` and stores those values -// (converting them) in `buffer`. -// `file` must be previously opened. -// Returns the number of 16-bit integers read or -1 on error. -size_t ReadInt16FromFileToFloatBuffer(FileWrapper* file, - size_t length, - float* buffer); - -// Reads `length` 16-bit integers from `file` and stores those values -// (converting them) in `buffer`. -// `file` must be previously opened. -// Returns the number of 16-bit integers read or -1 on error. -size_t ReadInt16FromFileToDoubleBuffer(FileWrapper* file, - size_t length, - double* buffer); - -// Reads `length` floats in binary representation (4 bytes) from `file` to -// `buffer`. -// `file` must be previously opened. -// Returns the number of floats read or -1 on error. -size_t ReadFloatBufferFromFile(FileWrapper* file, size_t length, float* buffer); - -// Reads `length` doubles in binary representation (8 bytes) from `file` to -// `buffer`. -// `file` must be previously opened. -// Returns the number of doubles read or -1 on error. -size_t ReadDoubleBufferFromFile(FileWrapper* file, - size_t length, - double* buffer); - -// Writes `length` 16-bit integers from `buffer` in binary representation (2 -// bytes) to `file`. It flushes `file`, so after this call there are no -// writings pending. -// `file` must be previously opened. -// Returns the number of doubles written or -1 on error. -size_t WriteInt16BufferToFile(FileWrapper* file, - size_t length, - const int16_t* buffer); - -// Writes `length` floats from `buffer` in binary representation (4 bytes) to -// `file`. It flushes `file`, so after this call there are no writtings pending. -// `file` must be previously opened. -// Returns the number of doubles written or -1 on error. -size_t WriteFloatBufferToFile(FileWrapper* file, - size_t length, - const float* buffer); - -// Writes `length` doubles from `buffer` in binary representation (8 bytes) to -// `file`. It flushes `file`, so after this call there are no writings pending. -// `file` must be previously opened. -// Returns the number of doubles written or -1 on error. -size_t WriteDoubleBufferToFile(FileWrapper* file, - size_t length, - const double* buffer); - -} // namespace webrtc - -#endif // MODULES_AUDIO_PROCESSING_TRANSIENT_FILE_UTILS_H_ diff --git a/webrtc/modules/audio_processing/transient/moving_moments.cc b/webrtc/modules/audio_processing/transient/moving_moments.cc deleted file mode 100644 index 83810bf..0000000 --- a/webrtc/modules/audio_processing/transient/moving_moments.cc +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "modules/audio_processing/transient/moving_moments.h" - -#include - -#include "rtc_base/checks.h" - -namespace webrtc { - -MovingMoments::MovingMoments(size_t length) - : length_(length), queue_(), sum_(0.0), sum_of_squares_(0.0) { - RTC_DCHECK_GT(length, 0); - for (size_t i = 0; i < length; ++i) { - queue_.push(0.0); - } -} - -MovingMoments::~MovingMoments() {} - -void MovingMoments::CalculateMoments(const float* in, - size_t in_length, - float* first, - float* second) { - RTC_DCHECK(in); - RTC_DCHECK_GT(in_length, 0); - RTC_DCHECK(first); - RTC_DCHECK(second); - - for (size_t i = 0; i < in_length; ++i) { - const float old_value = queue_.front(); - queue_.pop(); - queue_.push(in[i]); - - sum_ += in[i] - old_value; - sum_of_squares_ += in[i] * in[i] - old_value * old_value; - first[i] = sum_ / length_; - second[i] = std::max(0.f, sum_of_squares_ / length_); - } -} - -} // namespace webrtc diff --git a/webrtc/modules/audio_processing/transient/moving_moments.h b/webrtc/modules/audio_processing/transient/moving_moments.h deleted file mode 100644 index 70451dc..0000000 --- a/webrtc/modules/audio_processing/transient/moving_moments.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef MODULES_AUDIO_PROCESSING_TRANSIENT_MOVING_MOMENTS_H_ -#define MODULES_AUDIO_PROCESSING_TRANSIENT_MOVING_MOMENTS_H_ - -#include - -#include - -namespace webrtc { - -// Calculates the first and second moments for each value of a buffer taking -// into account a given number of previous values. -// It preserves its state, so it can be multiple-called. -// TODO(chadan): Implement a function that takes a buffer of first moments and a -// buffer of second moments; and calculates the variances. When needed. -// TODO(chadan): Add functionality to update with a buffer but only output are -// the last values of the moments. When needed. -class MovingMoments { - public: - // Creates a Moving Moments object, that uses the last `length` values - // (including the new value introduced in every new calculation). - explicit MovingMoments(size_t length); - ~MovingMoments(); - - // Calculates the new values using `in`. Results will be in the out buffers. - // `first` and `second` must be allocated with at least `in_length`. - void CalculateMoments(const float* in, - size_t in_length, - float* first, - float* second); - - private: - size_t length_; - // A queue holding the `length_` latest input values. - std::queue queue_; - // Sum of the values of the queue. - float sum_; - // Sum of the squares of the values of the queue. - float sum_of_squares_; -}; - -} // namespace webrtc - -#endif // MODULES_AUDIO_PROCESSING_TRANSIENT_MOVING_MOMENTS_H_ diff --git a/webrtc/modules/audio_processing/transient/transient_detector.cc b/webrtc/modules/audio_processing/transient/transient_detector.cc deleted file mode 100644 index 5c35505..0000000 --- a/webrtc/modules/audio_processing/transient/transient_detector.cc +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "modules/audio_processing/transient/transient_detector.h" - -#include -#include - -#include -#include - -#include "modules/audio_processing/transient/common.h" -#include "modules/audio_processing/transient/daubechies_8_wavelet_coeffs.h" -#include "modules/audio_processing/transient/moving_moments.h" -#include "modules/audio_processing/transient/wpd_node.h" -#include "modules/audio_processing/transient/wpd_tree.h" -#include "rtc_base/checks.h" - -namespace webrtc { - -static const int kTransientLengthMs = 30; -static const int kChunksAtStartupLeftToDelete = - kTransientLengthMs / ts::kChunkSizeMs; -static const float kDetectThreshold = 16.f; - -TransientDetector::TransientDetector(int sample_rate_hz) - : samples_per_chunk_(sample_rate_hz * ts::kChunkSizeMs / 1000), - last_first_moment_(), - last_second_moment_(), - chunks_at_startup_left_to_delete_(kChunksAtStartupLeftToDelete), - reference_energy_(1.f), - using_reference_(false) { - RTC_DCHECK(sample_rate_hz == ts::kSampleRate8kHz || - sample_rate_hz == ts::kSampleRate16kHz || - sample_rate_hz == ts::kSampleRate32kHz || - sample_rate_hz == ts::kSampleRate48kHz); - int samples_per_transient = sample_rate_hz * kTransientLengthMs / 1000; - // Adjustment to avoid data loss while downsampling, making - // `samples_per_chunk_` and `samples_per_transient` always divisible by - // `kLeaves`. - samples_per_chunk_ -= samples_per_chunk_ % kLeaves; - samples_per_transient -= samples_per_transient % kLeaves; - - tree_leaves_data_length_ = samples_per_chunk_ / kLeaves; - wpd_tree_.reset(new WPDTree(samples_per_chunk_, - kDaubechies8HighPassCoefficients, - kDaubechies8LowPassCoefficients, - kDaubechies8CoefficientsLength, kLevels)); - for (size_t i = 0; i < kLeaves; ++i) { - moving_moments_[i].reset( - new MovingMoments(samples_per_transient / kLeaves)); - } - - first_moments_.reset(new float[tree_leaves_data_length_]); - second_moments_.reset(new float[tree_leaves_data_length_]); - - for (int i = 0; i < kChunksAtStartupLeftToDelete; ++i) { - previous_results_.push_back(0.f); - } -} - -TransientDetector::~TransientDetector() {} - -float TransientDetector::Detect(const float* data, - size_t data_length, - const float* reference_data, - size_t reference_length) { - RTC_DCHECK(data); - RTC_DCHECK_EQ(samples_per_chunk_, data_length); - - // TODO(aluebs): Check if these errors can logically happen and if not assert - // on them. - if (wpd_tree_->Update(data, samples_per_chunk_) != 0) { - return -1.f; - } - - float result = 0.f; - - for (size_t i = 0; i < kLeaves; ++i) { - WPDNode* leaf = wpd_tree_->NodeAt(kLevels, i); - - moving_moments_[i]->CalculateMoments(leaf->data(), tree_leaves_data_length_, - first_moments_.get(), - second_moments_.get()); - - // Add value delayed (Use the last moments from the last call to Detect). - float unbiased_data = leaf->data()[0] - last_first_moment_[i]; - result += - unbiased_data * unbiased_data / (last_second_moment_[i] + FLT_MIN); - - // Add new values. - for (size_t j = 1; j < tree_leaves_data_length_; ++j) { - unbiased_data = leaf->data()[j] - first_moments_[j - 1]; - result += - unbiased_data * unbiased_data / (second_moments_[j - 1] + FLT_MIN); - } - - last_first_moment_[i] = first_moments_[tree_leaves_data_length_ - 1]; - last_second_moment_[i] = second_moments_[tree_leaves_data_length_ - 1]; - } - - result /= tree_leaves_data_length_; - - result *= ReferenceDetectionValue(reference_data, reference_length); - - if (chunks_at_startup_left_to_delete_ > 0) { - chunks_at_startup_left_to_delete_--; - result = 0.f; - } - - if (result >= kDetectThreshold) { - result = 1.f; - } else { - // Get proportional value. - // Proportion achieved with a squared raised cosine function with domain - // [0, kDetectThreshold) and image [0, 1), it's always increasing. - const float horizontal_scaling = ts::kPi / kDetectThreshold; - const float kHorizontalShift = ts::kPi; - const float kVerticalScaling = 0.5f; - const float kVerticalShift = 1.f; - - result = (std::cos(result * horizontal_scaling + kHorizontalShift) + - kVerticalShift) * - kVerticalScaling; - result *= result; - } - - previous_results_.pop_front(); - previous_results_.push_back(result); - - // In the current implementation we return the max of the current result and - // the previous results, so the high results have a width equals to - // `transient_length`. - return *std::max_element(previous_results_.begin(), previous_results_.end()); -} - -// Looks for the highest slope and compares it with the previous ones. -// An exponential transformation takes this to the [0, 1] range. This value is -// multiplied by the detection result to avoid false positives. -float TransientDetector::ReferenceDetectionValue(const float* data, - size_t length) { - if (data == NULL) { - using_reference_ = false; - return 1.f; - } - static const float kEnergyRatioThreshold = 0.2f; - static const float kReferenceNonLinearity = 20.f; - static const float kMemory = 0.99f; - float reference_energy = 0.f; - for (size_t i = 1; i < length; ++i) { - reference_energy += data[i] * data[i]; - } - if (reference_energy == 0.f) { - using_reference_ = false; - return 1.f; - } - RTC_DCHECK_NE(0, reference_energy_); - float result = 1.f / (1.f + std::exp(kReferenceNonLinearity * - (kEnergyRatioThreshold - - reference_energy / reference_energy_))); - reference_energy_ = - kMemory * reference_energy_ + (1.f - kMemory) * reference_energy; - - using_reference_ = true; - - return result; -} - -} // namespace webrtc diff --git a/webrtc/modules/audio_processing/transient/transient_detector.h b/webrtc/modules/audio_processing/transient/transient_detector.h deleted file mode 100644 index a3dbb7f..0000000 --- a/webrtc/modules/audio_processing/transient/transient_detector.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef MODULES_AUDIO_PROCESSING_TRANSIENT_TRANSIENT_DETECTOR_H_ -#define MODULES_AUDIO_PROCESSING_TRANSIENT_TRANSIENT_DETECTOR_H_ - -#include - -#include -#include - -#include "modules/audio_processing/transient/moving_moments.h" -#include "modules/audio_processing/transient/wpd_tree.h" - -namespace webrtc { - -// This is an implementation of the transient detector described in "Causal -// Wavelet based transient detector". -// Calculates the log-likelihood of a transient to happen on a signal at any -// given time based on the previous samples; it uses a WPD tree to analyze the -// signal. It preserves its state, so it can be multiple-called. -class TransientDetector { - public: - // TODO(chadan): The only supported wavelet is Daubechies 8 using a WPD tree - // of 3 levels. Make an overloaded constructor to allow different wavelets and - // depths of the tree. When needed. - - // Creates a wavelet based transient detector. - TransientDetector(int sample_rate_hz); - - ~TransientDetector(); - - // Calculates the log-likelihood of the existence of a transient in `data`. - // `data_length` has to be equal to `samples_per_chunk_`. - // Returns a value between 0 and 1, as a non linear representation of this - // likelihood. - // Returns a negative value on error. - float Detect(const float* data, - size_t data_length, - const float* reference_data, - size_t reference_length); - - bool using_reference() { return using_reference_; } - - private: - float ReferenceDetectionValue(const float* data, size_t length); - - static const size_t kLevels = 3; - static const size_t kLeaves = 1 << kLevels; - - size_t samples_per_chunk_; - - std::unique_ptr wpd_tree_; - size_t tree_leaves_data_length_; - - // A MovingMoments object is needed for each leaf in the WPD tree. - std::unique_ptr moving_moments_[kLeaves]; - - std::unique_ptr first_moments_; - std::unique_ptr second_moments_; - - // Stores the last calculated moments from the previous detection. - float last_first_moment_[kLeaves]; - float last_second_moment_[kLeaves]; - - // We keep track of the previous results from the previous chunks, so it can - // be used to effectively give results according to the `transient_length`. - std::deque previous_results_; - - // Number of chunks that are going to return only zeros at the beginning of - // the detection. It helps to avoid infs and nans due to the lack of - // information. - int chunks_at_startup_left_to_delete_; - - float reference_energy_; - - bool using_reference_; -}; - -} // namespace webrtc - -#endif // MODULES_AUDIO_PROCESSING_TRANSIENT_TRANSIENT_DETECTOR_H_ diff --git a/webrtc/modules/audio_processing/transient/transient_suppressor.h b/webrtc/modules/audio_processing/transient/transient_suppressor.h deleted file mode 100644 index ecb3c3b..0000000 --- a/webrtc/modules/audio_processing/transient/transient_suppressor.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2020 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef MODULES_AUDIO_PROCESSING_TRANSIENT_TRANSIENT_SUPPRESSOR_H_ -#define MODULES_AUDIO_PROCESSING_TRANSIENT_TRANSIENT_SUPPRESSOR_H_ - -#include - -namespace webrtc { - -// Detects transients in an audio stream and suppress them using a simple -// restoration algorithm that attenuates unexpected spikes in the spectrum. -class TransientSuppressor { - public: - // Type of VAD used by the caller to compute the `voice_probability` argument - // `Suppress()`. - enum class VadMode { - // By default, `TransientSuppressor` assumes that `voice_probability` is - // computed by `AgcManagerDirect`. - kDefault = 0, - // Use this mode when `TransientSuppressor` must assume that - // `voice_probability` is computed by the RNN VAD. - kRnnVad, - // Use this mode to let `TransientSuppressor::Suppressor()` ignore - // `voice_probability` and behave as if voice information is unavailable - // (regardless of the passed value). - kNoVad, - }; - - virtual ~TransientSuppressor() {} - - virtual void Initialize(int sample_rate_hz, - int detector_rate_hz, - int num_channels) = 0; - - // Processes a `data` chunk, and returns it with keystrokes suppressed from - // it. The float format is assumed to be int16 ranged. If there are more than - // one channel, the chunks are concatenated one after the other in `data`. - // `data_length` must be equal to `data_length_`. - // `num_channels` must be equal to `num_channels_`. - // A sub-band, ideally the higher, can be used as `detection_data`. If it is - // NULL, `data` is used for the detection too. The `detection_data` is always - // assumed mono. - // If a reference signal (e.g. keyboard microphone) is available, it can be - // passed in as `reference_data`. It is assumed mono and must have the same - // length as `data`. NULL is accepted if unavailable. - // This suppressor performs better if voice information is available. - // `voice_probability` is the probability of voice being present in this chunk - // of audio. If voice information is not available, `voice_probability` must - // always be set to 1. - // `key_pressed` determines if a key was pressed on this audio chunk. - // Returns a delayed version of `voice_probability` according to the - // algorithmic delay introduced by this method. In this way, the modified - // `data` and the returned voice probability will be temporally aligned. - virtual float Suppress(float* data, - size_t data_length, - int num_channels, - const float* detection_data, - size_t detection_length, - const float* reference_data, - size_t reference_length, - float voice_probability, - bool key_pressed) = 0; -}; - -} // namespace webrtc - -#endif // MODULES_AUDIO_PROCESSING_TRANSIENT_TRANSIENT_SUPPRESSOR_H_ diff --git a/webrtc/modules/audio_processing/transient/transient_suppressor_impl.cc b/webrtc/modules/audio_processing/transient/transient_suppressor_impl.cc deleted file mode 100644 index 9042846..0000000 --- a/webrtc/modules/audio_processing/transient/transient_suppressor_impl.cc +++ /dev/null @@ -1,455 +0,0 @@ -/* - * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "modules/audio_processing/transient/transient_suppressor_impl.h" - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "common_audio/include/audio_util.h" -#include "common_audio/signal_processing/include/signal_processing_library.h" -#include "common_audio/third_party/ooura/fft_size_256/fft4g.h" -#include "modules/audio_processing/transient/common.h" -#include "modules/audio_processing/transient/transient_detector.h" -#include "modules/audio_processing/transient/transient_suppressor.h" -#include "modules/audio_processing/transient/windows_private.h" -#include "rtc_base/checks.h" -#include "rtc_base/logging.h" - -namespace webrtc { - -static const float kMeanIIRCoefficient = 0.5f; - -// TODO(aluebs): Check if these values work also for 48kHz. -static const size_t kMinVoiceBin = 3; -static const size_t kMaxVoiceBin = 60; - -namespace { - -float ComplexMagnitude(float a, float b) { - return std::abs(a) + std::abs(b); -} - -std::string GetVadModeLabel(TransientSuppressor::VadMode vad_mode) { - switch (vad_mode) { - case TransientSuppressor::VadMode::kDefault: - return "default"; - case TransientSuppressor::VadMode::kRnnVad: - return "RNN VAD"; - case TransientSuppressor::VadMode::kNoVad: - return "no VAD"; - } -} - -} // namespace - -TransientSuppressorImpl::TransientSuppressorImpl(VadMode vad_mode, - int sample_rate_hz, - int detector_rate_hz, - int num_channels) - : vad_mode_(vad_mode), - voice_probability_delay_unit_(/*delay_num_samples=*/0, sample_rate_hz), - analyzed_audio_is_silent_(false), - data_length_(0), - detection_length_(0), - analysis_length_(0), - buffer_delay_(0), - complex_analysis_length_(0), - num_channels_(0), - window_(NULL), - detector_smoothed_(0.f), - keypress_counter_(0), - chunks_since_keypress_(0), - detection_enabled_(false), - suppression_enabled_(false), - use_hard_restoration_(false), - chunks_since_voice_change_(0), - seed_(182), - using_reference_(false) { - RTC_LOG(LS_INFO) << "VAD mode: " << GetVadModeLabel(vad_mode_); - Initialize(sample_rate_hz, detector_rate_hz, num_channels); -} - -TransientSuppressorImpl::~TransientSuppressorImpl() {} - -void TransientSuppressorImpl::Initialize(int sample_rate_hz, - int detection_rate_hz, - int num_channels) { - RTC_DCHECK(sample_rate_hz == ts::kSampleRate8kHz || - sample_rate_hz == ts::kSampleRate16kHz || - sample_rate_hz == ts::kSampleRate32kHz || - sample_rate_hz == ts::kSampleRate48kHz); - RTC_DCHECK(detection_rate_hz == ts::kSampleRate8kHz || - detection_rate_hz == ts::kSampleRate16kHz || - detection_rate_hz == ts::kSampleRate32kHz || - detection_rate_hz == ts::kSampleRate48kHz); - RTC_DCHECK_GT(num_channels, 0); - - switch (sample_rate_hz) { - case ts::kSampleRate8kHz: - analysis_length_ = 128u; - window_ = kBlocks80w128; - break; - case ts::kSampleRate16kHz: - analysis_length_ = 256u; - window_ = kBlocks160w256; - break; - case ts::kSampleRate32kHz: - analysis_length_ = 512u; - window_ = kBlocks320w512; - break; - case ts::kSampleRate48kHz: - analysis_length_ = 1024u; - window_ = kBlocks480w1024; - break; - default: - RTC_DCHECK_NOTREACHED(); - return; - } - - detector_.reset(new TransientDetector(detection_rate_hz)); - data_length_ = sample_rate_hz * ts::kChunkSizeMs / 1000; - RTC_DCHECK_LE(data_length_, analysis_length_); - buffer_delay_ = analysis_length_ - data_length_; - - voice_probability_delay_unit_.Initialize(/*delay_num_samples=*/buffer_delay_, - sample_rate_hz); - - complex_analysis_length_ = analysis_length_ / 2 + 1; - RTC_DCHECK_GE(complex_analysis_length_, kMaxVoiceBin); - num_channels_ = num_channels; - in_buffer_.reset(new float[analysis_length_ * num_channels_]); - memset(in_buffer_.get(), 0, - analysis_length_ * num_channels_ * sizeof(in_buffer_[0])); - detection_length_ = detection_rate_hz * ts::kChunkSizeMs / 1000; - detection_buffer_.reset(new float[detection_length_]); - memset(detection_buffer_.get(), 0, - detection_length_ * sizeof(detection_buffer_[0])); - out_buffer_.reset(new float[analysis_length_ * num_channels_]); - memset(out_buffer_.get(), 0, - analysis_length_ * num_channels_ * sizeof(out_buffer_[0])); - // ip[0] must be zero to trigger initialization using rdft(). - size_t ip_length = 2 + sqrtf(analysis_length_); - ip_.reset(new size_t[ip_length]()); - memset(ip_.get(), 0, ip_length * sizeof(ip_[0])); - wfft_.reset(new float[complex_analysis_length_ - 1]); - memset(wfft_.get(), 0, (complex_analysis_length_ - 1) * sizeof(wfft_[0])); - spectral_mean_.reset(new float[complex_analysis_length_ * num_channels_]); - memset(spectral_mean_.get(), 0, - complex_analysis_length_ * num_channels_ * sizeof(spectral_mean_[0])); - fft_buffer_.reset(new float[analysis_length_ + 2]); - memset(fft_buffer_.get(), 0, (analysis_length_ + 2) * sizeof(fft_buffer_[0])); - magnitudes_.reset(new float[complex_analysis_length_]); - memset(magnitudes_.get(), 0, - complex_analysis_length_ * sizeof(magnitudes_[0])); - mean_factor_.reset(new float[complex_analysis_length_]); - - static const float kFactorHeight = 10.f; - static const float kLowSlope = 1.f; - static const float kHighSlope = 0.3f; - for (size_t i = 0; i < complex_analysis_length_; ++i) { - mean_factor_[i] = - kFactorHeight / - (1.f + std::exp(kLowSlope * static_cast(i - kMinVoiceBin))) + - kFactorHeight / - (1.f + std::exp(kHighSlope * static_cast(kMaxVoiceBin - i))); - } - detector_smoothed_ = 0.f; - keypress_counter_ = 0; - chunks_since_keypress_ = 0; - detection_enabled_ = false; - suppression_enabled_ = false; - use_hard_restoration_ = false; - chunks_since_voice_change_ = 0; - seed_ = 182; - using_reference_ = false; -} - -float TransientSuppressorImpl::Suppress(float* data, - size_t data_length, - int num_channels, - const float* detection_data, - size_t detection_length, - const float* reference_data, - size_t reference_length, - float voice_probability, - bool key_pressed) { - if (!data || data_length != data_length_ || num_channels != num_channels_ || - detection_length != detection_length_ || voice_probability < 0 || - voice_probability > 1) { - // The audio is not modified, so the voice probability is returned as is - // (delay not applied). - return voice_probability; - } - - UpdateKeypress(key_pressed); - UpdateBuffers(data); - - if (detection_enabled_) { - UpdateRestoration(voice_probability); - - if (!detection_data) { - // Use the input data of the first channel if special detection data is - // not supplied. - detection_data = &in_buffer_[buffer_delay_]; - } - - float detector_result = detector_->Detect(detection_data, detection_length, - reference_data, reference_length); - if (detector_result < 0) { - // The audio is not modified, so the voice probability is returned as is - // (delay not applied). - return voice_probability; - } - - using_reference_ = detector_->using_reference(); - - // `detector_smoothed_` follows the `detector_result` when this last one is - // increasing, but has an exponential decaying tail to be able to suppress - // the ringing of keyclicks. - float smooth_factor = using_reference_ ? 0.6 : 0.1; - detector_smoothed_ = detector_result >= detector_smoothed_ - ? detector_result - : smooth_factor * detector_smoothed_ + - (1 - smooth_factor) * detector_result; - - for (int i = 0; i < num_channels_; ++i) { - Suppress(&in_buffer_[i * analysis_length_], - &spectral_mean_[i * complex_analysis_length_], - &out_buffer_[i * analysis_length_]); - } - } - - // If the suppression isn't enabled, we use the in buffer to delay the signal - // appropriately. This also gives time for the out buffer to be refreshed with - // new data between detection and suppression getting enabled. - for (int i = 0; i < num_channels_; ++i) { - memcpy(&data[i * data_length_], - suppression_enabled_ ? &out_buffer_[i * analysis_length_] - : &in_buffer_[i * analysis_length_], - data_length_ * sizeof(*data)); - } - - // The audio has been modified, return the delayed voice probability. - return voice_probability_delay_unit_.Delay(voice_probability); -} - -// This should only be called when detection is enabled. UpdateBuffers() must -// have been called. At return, `out_buffer_` will be filled with the -// processed output. -void TransientSuppressorImpl::Suppress(float* in_ptr, - float* spectral_mean, - float* out_ptr) { - // Go to frequency domain. - for (size_t i = 0; i < analysis_length_; ++i) { - // TODO(aluebs): Rename windows - fft_buffer_[i] = in_ptr[i] * window_[i]; - } - - WebRtc_rdft(analysis_length_, 1, fft_buffer_.get(), ip_.get(), wfft_.get()); - - // Since WebRtc_rdft puts R[n/2] in fft_buffer_[1], we move it to the end - // for convenience. - fft_buffer_[analysis_length_] = fft_buffer_[1]; - fft_buffer_[analysis_length_ + 1] = 0.f; - fft_buffer_[1] = 0.f; - - for (size_t i = 0; i < complex_analysis_length_; ++i) { - magnitudes_[i] = - ComplexMagnitude(fft_buffer_[i * 2], fft_buffer_[i * 2 + 1]); - } - // Restore audio if necessary. - if (suppression_enabled_) { - if (use_hard_restoration_) { - HardRestoration(spectral_mean); - } else { - SoftRestoration(spectral_mean); - } - } - - // Update the spectral mean. - for (size_t i = 0; i < complex_analysis_length_; ++i) { - spectral_mean[i] = (1 - kMeanIIRCoefficient) * spectral_mean[i] + - kMeanIIRCoefficient * magnitudes_[i]; - } - - // Back to time domain. - // Put R[n/2] back in fft_buffer_[1]. - fft_buffer_[1] = fft_buffer_[analysis_length_]; - - WebRtc_rdft(analysis_length_, -1, fft_buffer_.get(), ip_.get(), wfft_.get()); - const float fft_scaling = 2.f / analysis_length_; - - for (size_t i = 0; i < analysis_length_; ++i) { - out_ptr[i] += fft_buffer_[i] * window_[i] * fft_scaling; - } -} - -void TransientSuppressorImpl::UpdateKeypress(bool key_pressed) { - const int kKeypressPenalty = 1000 / ts::kChunkSizeMs; - const int kIsTypingThreshold = 1000 / ts::kChunkSizeMs; - const int kChunksUntilNotTyping = 4000 / ts::kChunkSizeMs; // 4 seconds. - - if (key_pressed) { - keypress_counter_ += kKeypressPenalty; - chunks_since_keypress_ = 0; - detection_enabled_ = true; - } - keypress_counter_ = std::max(0, keypress_counter_ - 1); - - if (keypress_counter_ > kIsTypingThreshold) { - if (!suppression_enabled_) { - RTC_LOG(LS_INFO) << "[ts] Transient suppression is now enabled."; - } - suppression_enabled_ = true; - keypress_counter_ = 0; - } - - if (detection_enabled_ && ++chunks_since_keypress_ > kChunksUntilNotTyping) { - if (suppression_enabled_) { - RTC_LOG(LS_INFO) << "[ts] Transient suppression is now disabled."; - } - detection_enabled_ = false; - suppression_enabled_ = false; - keypress_counter_ = 0; - } -} - -void TransientSuppressorImpl::UpdateRestoration(float voice_probability) { - bool not_voiced; - switch (vad_mode_) { - case TransientSuppressor::VadMode::kDefault: { - constexpr float kVoiceThreshold = 0.02f; - not_voiced = voice_probability < kVoiceThreshold; - break; - } - case TransientSuppressor::VadMode::kRnnVad: { - constexpr float kVoiceThreshold = 0.7f; - not_voiced = voice_probability < kVoiceThreshold; - break; - } - case TransientSuppressor::VadMode::kNoVad: - // Always assume that voice is detected. - not_voiced = false; - break; - } - - if (not_voiced == use_hard_restoration_) { - chunks_since_voice_change_ = 0; - } else { - ++chunks_since_voice_change_; - - // Number of 10 ms frames to wait to transition to and from hard - // restoration. - constexpr int kHardRestorationOffsetDelay = 3; - constexpr int kHardRestorationOnsetDelay = 80; - - if ((use_hard_restoration_ && - chunks_since_voice_change_ > kHardRestorationOffsetDelay) || - (!use_hard_restoration_ && - chunks_since_voice_change_ > kHardRestorationOnsetDelay)) { - use_hard_restoration_ = not_voiced; - chunks_since_voice_change_ = 0; - } - } -} - -// Shift buffers to make way for new data. Must be called after -// `detection_enabled_` is updated by UpdateKeypress(). -void TransientSuppressorImpl::UpdateBuffers(float* data) { - // TODO(aluebs): Change to ring buffer. - memmove(in_buffer_.get(), &in_buffer_[data_length_], - (buffer_delay_ + (num_channels_ - 1) * analysis_length_) * - sizeof(in_buffer_[0])); - // Copy new chunk to buffer. - for (int i = 0; i < num_channels_; ++i) { - memcpy(&in_buffer_[buffer_delay_ + i * analysis_length_], - &data[i * data_length_], data_length_ * sizeof(*data)); - } - if (detection_enabled_) { - // Shift previous chunk in out buffer. - memmove(out_buffer_.get(), &out_buffer_[data_length_], - (buffer_delay_ + (num_channels_ - 1) * analysis_length_) * - sizeof(out_buffer_[0])); - // Initialize new chunk in out buffer. - for (int i = 0; i < num_channels_; ++i) { - memset(&out_buffer_[buffer_delay_ + i * analysis_length_], 0, - data_length_ * sizeof(out_buffer_[0])); - } - } -} - -// Restores the unvoiced signal if a click is present. -// Attenuates by a certain factor every peak in the `fft_buffer_` that exceeds -// the spectral mean. The attenuation depends on `detector_smoothed_`. -// If a restoration takes place, the `magnitudes_` are updated to the new value. -void TransientSuppressorImpl::HardRestoration(float* spectral_mean) { - const float detector_result = - 1.f - std::pow(1.f - detector_smoothed_, using_reference_ ? 200.f : 50.f); - // To restore, we get the peaks in the spectrum. If higher than the previous - // spectral mean we adjust them. - for (size_t i = 0; i < complex_analysis_length_; ++i) { - if (magnitudes_[i] > spectral_mean[i] && magnitudes_[i] > 0) { - // RandU() generates values on [0, int16::max()] - const float phase = 2 * ts::kPi * WebRtcSpl_RandU(&seed_) / - std::numeric_limits::max(); - const float scaled_mean = detector_result * spectral_mean[i]; - - fft_buffer_[i * 2] = (1 - detector_result) * fft_buffer_[i * 2] + - scaled_mean * cosf(phase); - fft_buffer_[i * 2 + 1] = (1 - detector_result) * fft_buffer_[i * 2 + 1] + - scaled_mean * sinf(phase); - magnitudes_[i] = magnitudes_[i] - - detector_result * (magnitudes_[i] - spectral_mean[i]); - } - } -} - -// Restores the voiced signal if a click is present. -// Attenuates by a certain factor every peak in the `fft_buffer_` that exceeds -// the spectral mean and that is lower than some function of the current block -// frequency mean. The attenuation depends on `detector_smoothed_`. -// If a restoration takes place, the `magnitudes_` are updated to the new value. -void TransientSuppressorImpl::SoftRestoration(float* spectral_mean) { - // Get the spectral magnitude mean of the current block. - float block_frequency_mean = 0; - for (size_t i = kMinVoiceBin; i < kMaxVoiceBin; ++i) { - block_frequency_mean += magnitudes_[i]; - } - block_frequency_mean /= (kMaxVoiceBin - kMinVoiceBin); - - // To restore, we get the peaks in the spectrum. If higher than the - // previous spectral mean and lower than a factor of the block mean - // we adjust them. The factor is a double sigmoid that has a minimum in the - // voice frequency range (300Hz - 3kHz). - for (size_t i = 0; i < complex_analysis_length_; ++i) { - if (magnitudes_[i] > spectral_mean[i] && magnitudes_[i] > 0 && - (using_reference_ || - magnitudes_[i] < block_frequency_mean * mean_factor_[i])) { - const float new_magnitude = - magnitudes_[i] - - detector_smoothed_ * (magnitudes_[i] - spectral_mean[i]); - const float magnitude_ratio = new_magnitude / magnitudes_[i]; - - fft_buffer_[i * 2] *= magnitude_ratio; - fft_buffer_[i * 2 + 1] *= magnitude_ratio; - magnitudes_[i] = new_magnitude; - } - } -} - -} // namespace webrtc diff --git a/webrtc/modules/audio_processing/transient/transient_suppressor_impl.h b/webrtc/modules/audio_processing/transient/transient_suppressor_impl.h deleted file mode 100644 index 4005a16..0000000 --- a/webrtc/modules/audio_processing/transient/transient_suppressor_impl.h +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef MODULES_AUDIO_PROCESSING_TRANSIENT_TRANSIENT_SUPPRESSOR_IMPL_H_ -#define MODULES_AUDIO_PROCESSING_TRANSIENT_TRANSIENT_SUPPRESSOR_IMPL_H_ - -#include -#include - -#include - -#include "modules/audio_processing/transient/transient_suppressor.h" -#include "modules/audio_processing/transient/voice_probability_delay_unit.h" -#include "rtc_base/gtest_prod_util.h" - -namespace webrtc { - -class TransientDetector; - -// Detects transients in an audio stream and suppress them using a simple -// restoration algorithm that attenuates unexpected spikes in the spectrum. -class TransientSuppressorImpl : public TransientSuppressor { - public: - TransientSuppressorImpl(VadMode vad_mode, - int sample_rate_hz, - int detector_rate_hz, - int num_channels); - ~TransientSuppressorImpl() override; - - void Initialize(int sample_rate_hz, - int detector_rate_hz, - int num_channels) override; - - float Suppress(float* data, - size_t data_length, - int num_channels, - const float* detection_data, - size_t detection_length, - const float* reference_data, - size_t reference_length, - float voice_probability, - bool key_pressed) override; - - private: - FRIEND_TEST_ALL_PREFIXES(TransientSuppressorVadModeParametrization, - TypingDetectionLogicWorksAsExpectedForMono); - void Suppress(float* in_ptr, float* spectral_mean, float* out_ptr); - - void UpdateKeypress(bool key_pressed); - void UpdateRestoration(float voice_probability); - - void UpdateBuffers(float* data); - - void HardRestoration(float* spectral_mean); - void SoftRestoration(float* spectral_mean); - - const VadMode vad_mode_; - VoiceProbabilityDelayUnit voice_probability_delay_unit_; - - std::unique_ptr detector_; - - bool analyzed_audio_is_silent_; - - size_t data_length_; - size_t detection_length_; - size_t analysis_length_; - size_t buffer_delay_; - size_t complex_analysis_length_; - int num_channels_; - // Input buffer where the original samples are stored. - std::unique_ptr in_buffer_; - std::unique_ptr detection_buffer_; - // Output buffer where the restored samples are stored. - std::unique_ptr out_buffer_; - - // Arrays for fft. - std::unique_ptr ip_; - std::unique_ptr wfft_; - - std::unique_ptr spectral_mean_; - - // Stores the data for the fft. - std::unique_ptr fft_buffer_; - - std::unique_ptr magnitudes_; - - const float* window_; - - std::unique_ptr mean_factor_; - - float detector_smoothed_; - - int keypress_counter_; - int chunks_since_keypress_; - bool detection_enabled_; - bool suppression_enabled_; - - bool use_hard_restoration_; - int chunks_since_voice_change_; - - uint32_t seed_; - - bool using_reference_; -}; - -} // namespace webrtc - -#endif // MODULES_AUDIO_PROCESSING_TRANSIENT_TRANSIENT_SUPPRESSOR_IMPL_H_ diff --git a/webrtc/modules/audio_processing/transient/voice_probability_delay_unit.cc b/webrtc/modules/audio_processing/transient/voice_probability_delay_unit.cc deleted file mode 100644 index 27b2b42..0000000 --- a/webrtc/modules/audio_processing/transient/voice_probability_delay_unit.cc +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2022 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "modules/audio_processing/transient/voice_probability_delay_unit.h" - -#include - -#include "rtc_base/checks.h" - -namespace webrtc { - -VoiceProbabilityDelayUnit::VoiceProbabilityDelayUnit(int delay_num_samples, - int sample_rate_hz) { - Initialize(delay_num_samples, sample_rate_hz); -} - -void VoiceProbabilityDelayUnit::Initialize(int delay_num_samples, - int sample_rate_hz) { - RTC_DCHECK_GE(delay_num_samples, 0); - RTC_DCHECK_LE(delay_num_samples, sample_rate_hz / 50) - << "The implementation does not support delays greater than 20 ms."; - int frame_size = rtc::CheckedDivExact(sample_rate_hz, 100); // 10 ms. - if (delay_num_samples <= frame_size) { - weights_[0] = 0.0f; - weights_[1] = static_cast(delay_num_samples) / frame_size; - weights_[2] = - static_cast(frame_size - delay_num_samples) / frame_size; - } else { - delay_num_samples -= frame_size; - weights_[0] = static_cast(delay_num_samples) / frame_size; - weights_[1] = - static_cast(frame_size - delay_num_samples) / frame_size; - weights_[2] = 0.0f; - } - - // Resets the delay unit. - last_probabilities_.fill(0.0f); -} - -float VoiceProbabilityDelayUnit::Delay(float voice_probability) { - float weighted_probability = weights_[0] * last_probabilities_[0] + - weights_[1] * last_probabilities_[1] + - weights_[2] * voice_probability; - last_probabilities_[0] = last_probabilities_[1]; - last_probabilities_[1] = voice_probability; - return weighted_probability; -} - -} // namespace webrtc diff --git a/webrtc/modules/audio_processing/transient/voice_probability_delay_unit.h b/webrtc/modules/audio_processing/transient/voice_probability_delay_unit.h deleted file mode 100644 index 0596166..0000000 --- a/webrtc/modules/audio_processing/transient/voice_probability_delay_unit.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2022 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef MODULES_AUDIO_PROCESSING_TRANSIENT_VOICE_PROBABILITY_DELAY_UNIT_H_ -#define MODULES_AUDIO_PROCESSING_TRANSIENT_VOICE_PROBABILITY_DELAY_UNIT_H_ - -#include - -namespace webrtc { - -// Iteratively produces a sequence of delayed voice probability values given a -// fixed delay between 0 and 20 ms and given a sequence of voice probability -// values observed every 10 ms. Supports fractional delays, that are delays -// which are not a multiple integer of 10 ms. Applies interpolation with -// fractional delays; otherwise, returns a previously observed value according -// to the given fixed delay. -class VoiceProbabilityDelayUnit { - public: - // Ctor. `delay_num_samples` is the delay in number of samples and it must be - // non-negative and less than 20 ms. - VoiceProbabilityDelayUnit(int delay_num_samples, int sample_rate_hz); - - // Handles delay and sample rate changes and resets the delay unit. - void Initialize(int delay_num_samples, int sample_rate_hz); - - // Observes `voice_probability` and returns a delayed voice probability. - float Delay(float voice_probability); - - private: - std::array weights_; - std::array last_probabilities_; -}; - -} // namespace webrtc - -#endif // MODULES_AUDIO_PROCESSING_TRANSIENT_VOICE_PROBABILITY_DELAY_UNIT_H_ diff --git a/webrtc/modules/audio_processing/transient/windows_private.h b/webrtc/modules/audio_processing/transient/windows_private.h deleted file mode 100644 index 54e3c25..0000000 --- a/webrtc/modules/audio_processing/transient/windows_private.h +++ /dev/null @@ -1,557 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef MODULES_AUDIO_PROCESSING_TRANSIENT_WINDOWS_PRIVATE_H_ -#define MODULES_AUDIO_PROCESSING_TRANSIENT_WINDOWS_PRIVATE_H_ - -namespace webrtc { - -// Hanning window for 4ms 16kHz -static const float kHanning64w128[128] = { - 0.00000000000000f, 0.02454122852291f, 0.04906767432742f, 0.07356456359967f, - 0.09801714032956f, 0.12241067519922f, 0.14673047445536f, 0.17096188876030f, - 0.19509032201613f, 0.21910124015687f, 0.24298017990326f, 0.26671275747490f, - 0.29028467725446f, 0.31368174039889f, 0.33688985339222f, 0.35989503653499f, - 0.38268343236509f, 0.40524131400499f, 0.42755509343028f, 0.44961132965461f, - 0.47139673682600f, 0.49289819222978f, 0.51410274419322f, 0.53499761988710f, - 0.55557023301960f, 0.57580819141785f, 0.59569930449243f, 0.61523159058063f, - 0.63439328416365f, 0.65317284295378f, 0.67155895484702f, 0.68954054473707f, - 0.70710678118655f, 0.72424708295147f, 0.74095112535496f, 0.75720884650648f, - 0.77301045336274f, 0.78834642762661f, 0.80320753148064f, 0.81758481315158f, - 0.83146961230255f, 0.84485356524971f, 0.85772861000027f, 0.87008699110871f, - 0.88192126434835f, 0.89322430119552f, 0.90398929312344f, 0.91420975570353f, - 0.92387953251129f, 0.93299279883474f, 0.94154406518302f, 0.94952818059304f, - 0.95694033573221f, 0.96377606579544f, 0.97003125319454f, 0.97570213003853f, - 0.98078528040323f, 0.98527764238894f, 0.98917650996478f, 0.99247953459871f, - 0.99518472667220f, 0.99729045667869f, 0.99879545620517f, 0.99969881869620f, - 1.00000000000000f, 0.99969881869620f, 0.99879545620517f, 0.99729045667869f, - 0.99518472667220f, 0.99247953459871f, 0.98917650996478f, 0.98527764238894f, - 0.98078528040323f, 0.97570213003853f, 0.97003125319454f, 0.96377606579544f, - 0.95694033573221f, 0.94952818059304f, 0.94154406518302f, 0.93299279883474f, - 0.92387953251129f, 0.91420975570353f, 0.90398929312344f, 0.89322430119552f, - 0.88192126434835f, 0.87008699110871f, 0.85772861000027f, 0.84485356524971f, - 0.83146961230255f, 0.81758481315158f, 0.80320753148064f, 0.78834642762661f, - 0.77301045336274f, 0.75720884650648f, 0.74095112535496f, 0.72424708295147f, - 0.70710678118655f, 0.68954054473707f, 0.67155895484702f, 0.65317284295378f, - 0.63439328416365f, 0.61523159058063f, 0.59569930449243f, 0.57580819141785f, - 0.55557023301960f, 0.53499761988710f, 0.51410274419322f, 0.49289819222978f, - 0.47139673682600f, 0.44961132965461f, 0.42755509343028f, 0.40524131400499f, - 0.38268343236509f, 0.35989503653499f, 0.33688985339222f, 0.31368174039889f, - 0.29028467725446f, 0.26671275747490f, 0.24298017990326f, 0.21910124015687f, - 0.19509032201613f, 0.17096188876030f, 0.14673047445536f, 0.12241067519922f, - 0.09801714032956f, 0.07356456359967f, 0.04906767432742f, 0.02454122852291f}; - -// hybrib Hanning & flat window -static const float kBlocks80w128[128] = { - 0.00000000f, 0.03271908f, 0.06540313f, 0.09801714f, 0.13052619f, - 0.16289547f, 0.19509032f, 0.22707626f, 0.25881905f, 0.29028468f, - 0.32143947f, 0.35225005f, 0.38268343f, 0.41270703f, 0.44228869f, - 0.47139674f, 0.50000000f, 0.52806785f, 0.55557023f, 0.58247770f, - 0.60876143f, 0.63439328f, 0.65934582f, 0.68359230f, 0.70710678f, - 0.72986407f, 0.75183981f, 0.77301045f, 0.79335334f, 0.81284668f, - 0.83146961f, 0.84920218f, 0.86602540f, 0.88192126f, 0.89687274f, - 0.91086382f, 0.92387953f, 0.93590593f, 0.94693013f, 0.95694034f, - 0.96592583f, 0.97387698f, 0.98078528f, 0.98664333f, 0.99144486f, - 0.99518473f, 0.99785892f, 0.99946459f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 0.99946459f, 0.99785892f, 0.99518473f, 0.99144486f, - 0.98664333f, 0.98078528f, 0.97387698f, 0.96592583f, 0.95694034f, - 0.94693013f, 0.93590593f, 0.92387953f, 0.91086382f, 0.89687274f, - 0.88192126f, 0.86602540f, 0.84920218f, 0.83146961f, 0.81284668f, - 0.79335334f, 0.77301045f, 0.75183981f, 0.72986407f, 0.70710678f, - 0.68359230f, 0.65934582f, 0.63439328f, 0.60876143f, 0.58247770f, - 0.55557023f, 0.52806785f, 0.50000000f, 0.47139674f, 0.44228869f, - 0.41270703f, 0.38268343f, 0.35225005f, 0.32143947f, 0.29028468f, - 0.25881905f, 0.22707626f, 0.19509032f, 0.16289547f, 0.13052619f, - 0.09801714f, 0.06540313f, 0.03271908f}; - -// hybrib Hanning & flat window -static const float kBlocks160w256[256] = { - 0.00000000f, 0.01636173f, 0.03271908f, 0.04906767f, 0.06540313f, - 0.08172107f, 0.09801714f, 0.11428696f, 0.13052619f, 0.14673047f, - 0.16289547f, 0.17901686f, 0.19509032f, 0.21111155f, 0.22707626f, - 0.24298018f, 0.25881905f, 0.27458862f, 0.29028468f, 0.30590302f, - 0.32143947f, 0.33688985f, 0.35225005f, 0.36751594f, 0.38268343f, - 0.39774847f, 0.41270703f, 0.42755509f, 0.44228869f, 0.45690388f, - 0.47139674f, 0.48576339f, 0.50000000f, 0.51410274f, 0.52806785f, - 0.54189158f, 0.55557023f, 0.56910015f, 0.58247770f, 0.59569930f, - 0.60876143f, 0.62166057f, 0.63439328f, 0.64695615f, 0.65934582f, - 0.67155895f, 0.68359230f, 0.69544264f, 0.70710678f, 0.71858162f, - 0.72986407f, 0.74095113f, 0.75183981f, 0.76252720f, 0.77301045f, - 0.78328675f, 0.79335334f, 0.80320753f, 0.81284668f, 0.82226822f, - 0.83146961f, 0.84044840f, 0.84920218f, 0.85772861f, 0.86602540f, - 0.87409034f, 0.88192126f, 0.88951608f, 0.89687274f, 0.90398929f, - 0.91086382f, 0.91749450f, 0.92387953f, 0.93001722f, 0.93590593f, - 0.94154407f, 0.94693013f, 0.95206268f, 0.95694034f, 0.96156180f, - 0.96592583f, 0.97003125f, 0.97387698f, 0.97746197f, 0.98078528f, - 0.98384601f, 0.98664333f, 0.98917651f, 0.99144486f, 0.99344778f, - 0.99518473f, 0.99665524f, 0.99785892f, 0.99879546f, 0.99946459f, - 0.99986614f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 0.99986614f, 0.99946459f, 0.99879546f, 0.99785892f, - 0.99665524f, 0.99518473f, 0.99344778f, 0.99144486f, 0.98917651f, - 0.98664333f, 0.98384601f, 0.98078528f, 0.97746197f, 0.97387698f, - 0.97003125f, 0.96592583f, 0.96156180f, 0.95694034f, 0.95206268f, - 0.94693013f, 0.94154407f, 0.93590593f, 0.93001722f, 0.92387953f, - 0.91749450f, 0.91086382f, 0.90398929f, 0.89687274f, 0.88951608f, - 0.88192126f, 0.87409034f, 0.86602540f, 0.85772861f, 0.84920218f, - 0.84044840f, 0.83146961f, 0.82226822f, 0.81284668f, 0.80320753f, - 0.79335334f, 0.78328675f, 0.77301045f, 0.76252720f, 0.75183981f, - 0.74095113f, 0.72986407f, 0.71858162f, 0.70710678f, 0.69544264f, - 0.68359230f, 0.67155895f, 0.65934582f, 0.64695615f, 0.63439328f, - 0.62166057f, 0.60876143f, 0.59569930f, 0.58247770f, 0.56910015f, - 0.55557023f, 0.54189158f, 0.52806785f, 0.51410274f, 0.50000000f, - 0.48576339f, 0.47139674f, 0.45690388f, 0.44228869f, 0.42755509f, - 0.41270703f, 0.39774847f, 0.38268343f, 0.36751594f, 0.35225005f, - 0.33688985f, 0.32143947f, 0.30590302f, 0.29028468f, 0.27458862f, - 0.25881905f, 0.24298018f, 0.22707626f, 0.21111155f, 0.19509032f, - 0.17901686f, 0.16289547f, 0.14673047f, 0.13052619f, 0.11428696f, - 0.09801714f, 0.08172107f, 0.06540313f, 0.04906767f, 0.03271908f, - 0.01636173f}; - -// hybrib Hanning & flat window: for 20ms -static const float kBlocks320w512[512] = { - 0.00000000f, 0.00818114f, 0.01636173f, 0.02454123f, 0.03271908f, - 0.04089475f, 0.04906767f, 0.05723732f, 0.06540313f, 0.07356456f, - 0.08172107f, 0.08987211f, 0.09801714f, 0.10615561f, 0.11428696f, - 0.12241068f, 0.13052619f, 0.13863297f, 0.14673047f, 0.15481816f, - 0.16289547f, 0.17096189f, 0.17901686f, 0.18705985f, 0.19509032f, - 0.20310773f, 0.21111155f, 0.21910124f, 0.22707626f, 0.23503609f, - 0.24298018f, 0.25090801f, 0.25881905f, 0.26671276f, 0.27458862f, - 0.28244610f, 0.29028468f, 0.29810383f, 0.30590302f, 0.31368174f, - 0.32143947f, 0.32917568f, 0.33688985f, 0.34458148f, 0.35225005f, - 0.35989504f, 0.36751594f, 0.37511224f, 0.38268343f, 0.39022901f, - 0.39774847f, 0.40524131f, 0.41270703f, 0.42014512f, 0.42755509f, - 0.43493645f, 0.44228869f, 0.44961133f, 0.45690388f, 0.46416584f, - 0.47139674f, 0.47859608f, 0.48576339f, 0.49289819f, 0.50000000f, - 0.50706834f, 0.51410274f, 0.52110274f, 0.52806785f, 0.53499762f, - 0.54189158f, 0.54874927f, 0.55557023f, 0.56235401f, 0.56910015f, - 0.57580819f, 0.58247770f, 0.58910822f, 0.59569930f, 0.60225052f, - 0.60876143f, 0.61523159f, 0.62166057f, 0.62804795f, 0.63439328f, - 0.64069616f, 0.64695615f, 0.65317284f, 0.65934582f, 0.66547466f, - 0.67155895f, 0.67759830f, 0.68359230f, 0.68954054f, 0.69544264f, - 0.70129818f, 0.70710678f, 0.71286806f, 0.71858162f, 0.72424708f, - 0.72986407f, 0.73543221f, 0.74095113f, 0.74642045f, 0.75183981f, - 0.75720885f, 0.76252720f, 0.76779452f, 0.77301045f, 0.77817464f, - 0.78328675f, 0.78834643f, 0.79335334f, 0.79830715f, 0.80320753f, - 0.80805415f, 0.81284668f, 0.81758481f, 0.82226822f, 0.82689659f, - 0.83146961f, 0.83598698f, 0.84044840f, 0.84485357f, 0.84920218f, - 0.85349396f, 0.85772861f, 0.86190585f, 0.86602540f, 0.87008699f, - 0.87409034f, 0.87803519f, 0.88192126f, 0.88574831f, 0.88951608f, - 0.89322430f, 0.89687274f, 0.90046115f, 0.90398929f, 0.90745693f, - 0.91086382f, 0.91420976f, 0.91749450f, 0.92071783f, 0.92387953f, - 0.92697940f, 0.93001722f, 0.93299280f, 0.93590593f, 0.93875641f, - 0.94154407f, 0.94426870f, 0.94693013f, 0.94952818f, 0.95206268f, - 0.95453345f, 0.95694034f, 0.95928317f, 0.96156180f, 0.96377607f, - 0.96592583f, 0.96801094f, 0.97003125f, 0.97198664f, 0.97387698f, - 0.97570213f, 0.97746197f, 0.97915640f, 0.98078528f, 0.98234852f, - 0.98384601f, 0.98527764f, 0.98664333f, 0.98794298f, 0.98917651f, - 0.99034383f, 0.99144486f, 0.99247953f, 0.99344778f, 0.99434953f, - 0.99518473f, 0.99595331f, 0.99665524f, 0.99729046f, 0.99785892f, - 0.99836060f, 0.99879546f, 0.99916346f, 0.99946459f, 0.99969882f, - 0.99986614f, 0.99996653f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, 1.00000000f, - 1.00000000f, 0.99996653f, 0.99986614f, 0.99969882f, 0.99946459f, - 0.99916346f, 0.99879546f, 0.99836060f, 0.99785892f, 0.99729046f, - 0.99665524f, 0.99595331f, 0.99518473f, 0.99434953f, 0.99344778f, - 0.99247953f, 0.99144486f, 0.99034383f, 0.98917651f, 0.98794298f, - 0.98664333f, 0.98527764f, 0.98384601f, 0.98234852f, 0.98078528f, - 0.97915640f, 0.97746197f, 0.97570213f, 0.97387698f, 0.97198664f, - 0.97003125f, 0.96801094f, 0.96592583f, 0.96377607f, 0.96156180f, - 0.95928317f, 0.95694034f, 0.95453345f, 0.95206268f, 0.94952818f, - 0.94693013f, 0.94426870f, 0.94154407f, 0.93875641f, 0.93590593f, - 0.93299280f, 0.93001722f, 0.92697940f, 0.92387953f, 0.92071783f, - 0.91749450f, 0.91420976f, 0.91086382f, 0.90745693f, 0.90398929f, - 0.90046115f, 0.89687274f, 0.89322430f, 0.88951608f, 0.88574831f, - 0.88192126f, 0.87803519f, 0.87409034f, 0.87008699f, 0.86602540f, - 0.86190585f, 0.85772861f, 0.85349396f, 0.84920218f, 0.84485357f, - 0.84044840f, 0.83598698f, 0.83146961f, 0.82689659f, 0.82226822f, - 0.81758481f, 0.81284668f, 0.80805415f, 0.80320753f, 0.79830715f, - 0.79335334f, 0.78834643f, 0.78328675f, 0.77817464f, 0.77301045f, - 0.76779452f, 0.76252720f, 0.75720885f, 0.75183981f, 0.74642045f, - 0.74095113f, 0.73543221f, 0.72986407f, 0.72424708f, 0.71858162f, - 0.71286806f, 0.70710678f, 0.70129818f, 0.69544264f, 0.68954054f, - 0.68359230f, 0.67759830f, 0.67155895f, 0.66547466f, 0.65934582f, - 0.65317284f, 0.64695615f, 0.64069616f, 0.63439328f, 0.62804795f, - 0.62166057f, 0.61523159f, 0.60876143f, 0.60225052f, 0.59569930f, - 0.58910822f, 0.58247770f, 0.57580819f, 0.56910015f, 0.56235401f, - 0.55557023f, 0.54874927f, 0.54189158f, 0.53499762f, 0.52806785f, - 0.52110274f, 0.51410274f, 0.50706834f, 0.50000000f, 0.49289819f, - 0.48576339f, 0.47859608f, 0.47139674f, 0.46416584f, 0.45690388f, - 0.44961133f, 0.44228869f, 0.43493645f, 0.42755509f, 0.42014512f, - 0.41270703f, 0.40524131f, 0.39774847f, 0.39022901f, 0.38268343f, - 0.37511224f, 0.36751594f, 0.35989504f, 0.35225005f, 0.34458148f, - 0.33688985f, 0.32917568f, 0.32143947f, 0.31368174f, 0.30590302f, - 0.29810383f, 0.29028468f, 0.28244610f, 0.27458862f, 0.26671276f, - 0.25881905f, 0.25090801f, 0.24298018f, 0.23503609f, 0.22707626f, - 0.21910124f, 0.21111155f, 0.20310773f, 0.19509032f, 0.18705985f, - 0.17901686f, 0.17096189f, 0.16289547f, 0.15481816f, 0.14673047f, - 0.13863297f, 0.13052619f, 0.12241068f, 0.11428696f, 0.10615561f, - 0.09801714f, 0.08987211f, 0.08172107f, 0.07356456f, 0.06540313f, - 0.05723732f, 0.04906767f, 0.04089475f, 0.03271908f, 0.02454123f, - 0.01636173f, 0.00818114f}; - -// Hanning window: for 15ms at 16kHz with symmetric zeros -static const float kBlocks240w512[512] = { - 0.00000000f, 0.00000000f, 0.00000000f, 0.00000000f, 0.00000000f, - 0.00000000f, 0.00000000f, 0.00000000f, 0.00000000f, 0.00000000f, - 0.00000000f, 0.00000000f, 0.00000000f, 0.00000000f, 0.00000000f, - 0.00000000f, 0.00000000f, 0.00654494f, 0.01308960f, 0.01963369f, - 0.02617695f, 0.03271908f, 0.03925982f, 0.04579887f, 0.05233596f, - 0.05887080f, 0.06540313f, 0.07193266f, 0.07845910f, 0.08498218f, - 0.09150162f, 0.09801714f, 0.10452846f, 0.11103531f, 0.11753740f, - 0.12403446f, 0.13052620f, 0.13701233f, 0.14349262f, 0.14996676f, - 0.15643448f, 0.16289547f, 0.16934951f, 0.17579629f, 0.18223552f, - 0.18866697f, 0.19509032f, 0.20150533f, 0.20791170f, 0.21430916f, - 0.22069745f, 0.22707628f, 0.23344538f, 0.23980446f, 0.24615330f, - 0.25249159f, 0.25881904f, 0.26513544f, 0.27144045f, 0.27773386f, - 0.28401536f, 0.29028466f, 0.29654160f, 0.30278578f, 0.30901700f, - 0.31523499f, 0.32143945f, 0.32763019f, 0.33380687f, 0.33996925f, - 0.34611708f, 0.35225007f, 0.35836795f, 0.36447051f, 0.37055743f, - 0.37662852f, 0.38268346f, 0.38872197f, 0.39474389f, 0.40074885f, - 0.40673664f, 0.41270703f, 0.41865975f, 0.42459452f, 0.43051112f, - 0.43640924f, 0.44228873f, 0.44814920f, 0.45399052f, 0.45981237f, - 0.46561453f, 0.47139674f, 0.47715878f, 0.48290035f, 0.48862126f, - 0.49432120f, 0.50000000f, 0.50565743f, 0.51129311f, 0.51690692f, - 0.52249855f, 0.52806789f, 0.53361452f, 0.53913832f, 0.54463905f, - 0.55011642f, 0.55557024f, 0.56100029f, 0.56640625f, 0.57178795f, - 0.57714522f, 0.58247769f, 0.58778524f, 0.59306765f, 0.59832460f, - 0.60355598f, 0.60876143f, 0.61394083f, 0.61909395f, 0.62422055f, - 0.62932038f, 0.63439333f, 0.63943899f, 0.64445734f, 0.64944810f, - 0.65441096f, 0.65934587f, 0.66425246f, 0.66913062f, 0.67398012f, - 0.67880076f, 0.68359232f, 0.68835455f, 0.69308740f, 0.69779050f, - 0.70246369f, 0.70710677f, 0.71171963f, 0.71630198f, 0.72085363f, - 0.72537440f, 0.72986406f, 0.73432255f, 0.73874950f, 0.74314487f, - 0.74750835f, 0.75183982f, 0.75613910f, 0.76040596f, 0.76464027f, - 0.76884186f, 0.77301043f, 0.77714598f, 0.78124821f, 0.78531694f, - 0.78935206f, 0.79335338f, 0.79732066f, 0.80125386f, 0.80515265f, - 0.80901700f, 0.81284672f, 0.81664157f, 0.82040149f, 0.82412618f, - 0.82781565f, 0.83146966f, 0.83508795f, 0.83867061f, 0.84221727f, - 0.84572780f, 0.84920216f, 0.85264021f, 0.85604161f, 0.85940641f, - 0.86273444f, 0.86602545f, 0.86927933f, 0.87249607f, 0.87567532f, - 0.87881714f, 0.88192129f, 0.88498765f, 0.88801610f, 0.89100653f, - 0.89395881f, 0.89687276f, 0.89974827f, 0.90258533f, 0.90538365f, - 0.90814316f, 0.91086388f, 0.91354549f, 0.91618794f, 0.91879123f, - 0.92135513f, 0.92387950f, 0.92636442f, 0.92880958f, 0.93121493f, - 0.93358046f, 0.93590593f, 0.93819135f, 0.94043654f, 0.94264150f, - 0.94480604f, 0.94693011f, 0.94901365f, 0.95105654f, 0.95305866f, - 0.95501995f, 0.95694035f, 0.95881975f, 0.96065807f, 0.96245527f, - 0.96421117f, 0.96592581f, 0.96759909f, 0.96923089f, 0.97082120f, - 0.97236991f, 0.97387701f, 0.97534233f, 0.97676587f, 0.97814763f, - 0.97948742f, 0.98078531f, 0.98204112f, 0.98325491f, 0.98442656f, - 0.98555607f, 0.98664331f, 0.98768836f, 0.98869103f, 0.98965138f, - 0.99056935f, 0.99144489f, 0.99227792f, 0.99306846f, 0.99381649f, - 0.99452192f, 0.99518472f, 0.99580491f, 0.99638247f, 0.99691731f, - 0.99740952f, 0.99785894f, 0.99826562f, 0.99862951f, 0.99895066f, - 0.99922901f, 0.99946457f, 0.99965733f, 0.99980724f, 0.99991435f, - 0.99997860f, 1.00000000f, 0.99997860f, 0.99991435f, 0.99980724f, - 0.99965733f, 0.99946457f, 0.99922901f, 0.99895066f, 0.99862951f, - 0.99826562f, 0.99785894f, 0.99740946f, 0.99691731f, 0.99638247f, - 0.99580491f, 0.99518472f, 0.99452192f, 0.99381644f, 0.99306846f, - 0.99227792f, 0.99144489f, 0.99056935f, 0.98965138f, 0.98869103f, - 0.98768836f, 0.98664331f, 0.98555607f, 0.98442656f, 0.98325491f, - 0.98204112f, 0.98078525f, 0.97948742f, 0.97814757f, 0.97676587f, - 0.97534227f, 0.97387695f, 0.97236991f, 0.97082120f, 0.96923089f, - 0.96759909f, 0.96592581f, 0.96421117f, 0.96245521f, 0.96065807f, - 0.95881969f, 0.95694029f, 0.95501995f, 0.95305860f, 0.95105648f, - 0.94901365f, 0.94693011f, 0.94480604f, 0.94264150f, 0.94043654f, - 0.93819129f, 0.93590593f, 0.93358046f, 0.93121493f, 0.92880952f, - 0.92636436f, 0.92387950f, 0.92135507f, 0.91879123f, 0.91618794f, - 0.91354543f, 0.91086382f, 0.90814310f, 0.90538365f, 0.90258527f, - 0.89974827f, 0.89687276f, 0.89395875f, 0.89100647f, 0.88801610f, - 0.88498759f, 0.88192123f, 0.87881714f, 0.87567532f, 0.87249595f, - 0.86927933f, 0.86602539f, 0.86273432f, 0.85940641f, 0.85604161f, - 0.85264009f, 0.84920216f, 0.84572780f, 0.84221715f, 0.83867055f, - 0.83508795f, 0.83146954f, 0.82781565f, 0.82412612f, 0.82040137f, - 0.81664157f, 0.81284660f, 0.80901700f, 0.80515265f, 0.80125374f, - 0.79732066f, 0.79335332f, 0.78935200f, 0.78531694f, 0.78124815f, - 0.77714586f, 0.77301049f, 0.76884180f, 0.76464021f, 0.76040596f, - 0.75613904f, 0.75183970f, 0.74750835f, 0.74314481f, 0.73874938f, - 0.73432249f, 0.72986400f, 0.72537428f, 0.72085363f, 0.71630186f, - 0.71171951f, 0.70710677f, 0.70246363f, 0.69779032f, 0.69308734f, - 0.68835449f, 0.68359220f, 0.67880070f, 0.67398006f, 0.66913044f, - 0.66425240f, 0.65934575f, 0.65441096f, 0.64944804f, 0.64445722f, - 0.63943905f, 0.63439327f, 0.62932026f, 0.62422055f, 0.61909389f, - 0.61394072f, 0.60876143f, 0.60355592f, 0.59832448f, 0.59306765f, - 0.58778518f, 0.58247757f, 0.57714522f, 0.57178789f, 0.56640613f, - 0.56100023f, 0.55557019f, 0.55011630f, 0.54463905f, 0.53913826f, - 0.53361434f, 0.52806783f, 0.52249849f, 0.51690674f, 0.51129305f, - 0.50565726f, 0.50000006f, 0.49432117f, 0.48862115f, 0.48290038f, - 0.47715873f, 0.47139663f, 0.46561456f, 0.45981231f, 0.45399037f, - 0.44814920f, 0.44228864f, 0.43640912f, 0.43051112f, 0.42459446f, - 0.41865960f, 0.41270703f, 0.40673658f, 0.40074870f, 0.39474386f, - 0.38872188f, 0.38268328f, 0.37662849f, 0.37055734f, 0.36447033f, - 0.35836792f, 0.35224995f, 0.34611690f, 0.33996922f, 0.33380675f, - 0.32763001f, 0.32143945f, 0.31523487f, 0.30901679f, 0.30278572f, - 0.29654145f, 0.29028472f, 0.28401530f, 0.27773371f, 0.27144048f, - 0.26513538f, 0.25881892f, 0.25249159f, 0.24615324f, 0.23980433f, - 0.23344538f, 0.22707619f, 0.22069728f, 0.21430916f, 0.20791161f, - 0.20150517f, 0.19509031f, 0.18866688f, 0.18223536f, 0.17579627f, - 0.16934940f, 0.16289529f, 0.15643445f, 0.14996666f, 0.14349243f, - 0.13701232f, 0.13052608f, 0.12403426f, 0.11753736f, 0.11103519f, - 0.10452849f, 0.09801710f, 0.09150149f, 0.08498220f, 0.07845904f, - 0.07193252f, 0.06540315f, 0.05887074f, 0.05233581f, 0.04579888f, - 0.03925974f, 0.03271893f, 0.02617695f, 0.01963361f, 0.01308943f, - 0.00654493f, 0.00000000f, 0.00000000f, 0.00000000f, 0.00000000f, - 0.00000000f, 0.00000000f, 0.00000000f, 0.00000000f, 0.00000000f, - 0.00000000f, 0.00000000f, 0.00000000f, 0.00000000f, 0.00000000f, - 0.00000000f, 0.00000000f}; - -// Hanning window: for 30ms with 1024 fft with symmetric zeros at 16kHz -static const float kBlocks480w1024[1024] = { - 0.00000000f, 0.00000000f, 0.00000000f, 0.00000000f, 0.00000000f, - 0.00000000f, 0.00000000f, 0.00000000f, 0.00000000f, 0.00000000f, - 0.00000000f, 0.00000000f, 0.00000000f, 0.00000000f, 0.00000000f, - 0.00000000f, 0.00000000f, 0.00000000f, 0.00000000f, 0.00000000f, - 0.00000000f, 0.00000000f, 0.00000000f, 0.00000000f, 0.00000000f, - 0.00000000f, 0.00000000f, 0.00000000f, 0.00000000f, 0.00000000f, - 0.00000000f, 0.00000000f, 0.00000000f, 0.00327249f, 0.00654494f, - 0.00981732f, 0.01308960f, 0.01636173f, 0.01963369f, 0.02290544f, - 0.02617695f, 0.02944817f, 0.03271908f, 0.03598964f, 0.03925982f, - 0.04252957f, 0.04579887f, 0.04906768f, 0.05233596f, 0.05560368f, - 0.05887080f, 0.06213730f, 0.06540313f, 0.06866825f, 0.07193266f, - 0.07519628f, 0.07845910f, 0.08172107f, 0.08498218f, 0.08824237f, - 0.09150162f, 0.09475989f, 0.09801714f, 0.10127335f, 0.10452846f, - 0.10778246f, 0.11103531f, 0.11428697f, 0.11753740f, 0.12078657f, - 0.12403446f, 0.12728101f, 0.13052620f, 0.13376999f, 0.13701233f, - 0.14025325f, 0.14349262f, 0.14673047f, 0.14996676f, 0.15320145f, - 0.15643448f, 0.15966582f, 0.16289547f, 0.16612339f, 0.16934951f, - 0.17257382f, 0.17579629f, 0.17901687f, 0.18223552f, 0.18545224f, - 0.18866697f, 0.19187967f, 0.19509032f, 0.19829889f, 0.20150533f, - 0.20470962f, 0.20791170f, 0.21111156f, 0.21430916f, 0.21750447f, - 0.22069745f, 0.22388805f, 0.22707628f, 0.23026206f, 0.23344538f, - 0.23662618f, 0.23980446f, 0.24298020f, 0.24615330f, 0.24932377f, - 0.25249159f, 0.25565669f, 0.25881904f, 0.26197866f, 0.26513544f, - 0.26828939f, 0.27144045f, 0.27458861f, 0.27773386f, 0.28087610f, - 0.28401536f, 0.28715158f, 0.29028466f, 0.29341471f, 0.29654160f, - 0.29966527f, 0.30278578f, 0.30590302f, 0.30901700f, 0.31212768f, - 0.31523499f, 0.31833893f, 0.32143945f, 0.32453656f, 0.32763019f, - 0.33072028f, 0.33380687f, 0.33688986f, 0.33996925f, 0.34304500f, - 0.34611708f, 0.34918544f, 0.35225007f, 0.35531089f, 0.35836795f, - 0.36142117f, 0.36447051f, 0.36751595f, 0.37055743f, 0.37359497f, - 0.37662852f, 0.37965801f, 0.38268346f, 0.38570479f, 0.38872197f, - 0.39173502f, 0.39474389f, 0.39774847f, 0.40074885f, 0.40374491f, - 0.40673664f, 0.40972406f, 0.41270703f, 0.41568562f, 0.41865975f, - 0.42162940f, 0.42459452f, 0.42755508f, 0.43051112f, 0.43346250f, - 0.43640924f, 0.43935132f, 0.44228873f, 0.44522133f, 0.44814920f, - 0.45107228f, 0.45399052f, 0.45690390f, 0.45981237f, 0.46271592f, - 0.46561453f, 0.46850815f, 0.47139674f, 0.47428030f, 0.47715878f, - 0.48003215f, 0.48290035f, 0.48576337f, 0.48862126f, 0.49147385f, - 0.49432120f, 0.49716330f, 0.50000000f, 0.50283140f, 0.50565743f, - 0.50847799f, 0.51129311f, 0.51410276f, 0.51690692f, 0.51970553f, - 0.52249855f, 0.52528602f, 0.52806789f, 0.53084403f, 0.53361452f, - 0.53637928f, 0.53913832f, 0.54189163f, 0.54463905f, 0.54738063f, - 0.55011642f, 0.55284631f, 0.55557024f, 0.55828828f, 0.56100029f, - 0.56370628f, 0.56640625f, 0.56910014f, 0.57178795f, 0.57446963f, - 0.57714522f, 0.57981455f, 0.58247769f, 0.58513463f, 0.58778524f, - 0.59042960f, 0.59306765f, 0.59569931f, 0.59832460f, 0.60094351f, - 0.60355598f, 0.60616195f, 0.60876143f, 0.61135441f, 0.61394083f, - 0.61652070f, 0.61909395f, 0.62166059f, 0.62422055f, 0.62677383f, - 0.62932038f, 0.63186020f, 0.63439333f, 0.63691956f, 0.63943899f, - 0.64195162f, 0.64445734f, 0.64695615f, 0.64944810f, 0.65193301f, - 0.65441096f, 0.65688187f, 0.65934587f, 0.66180271f, 0.66425246f, - 0.66669512f, 0.66913062f, 0.67155898f, 0.67398012f, 0.67639405f, - 0.67880076f, 0.68120021f, 0.68359232f, 0.68597710f, 0.68835455f, - 0.69072467f, 0.69308740f, 0.69544262f, 0.69779050f, 0.70013082f, - 0.70246369f, 0.70478904f, 0.70710677f, 0.70941699f, 0.71171963f, - 0.71401459f, 0.71630198f, 0.71858168f, 0.72085363f, 0.72311789f, - 0.72537440f, 0.72762316f, 0.72986406f, 0.73209721f, 0.73432255f, - 0.73653996f, 0.73874950f, 0.74095118f, 0.74314487f, 0.74533057f, - 0.74750835f, 0.74967808f, 0.75183982f, 0.75399351f, 0.75613910f, - 0.75827658f, 0.76040596f, 0.76252723f, 0.76464027f, 0.76674515f, - 0.76884186f, 0.77093029f, 0.77301043f, 0.77508241f, 0.77714598f, - 0.77920127f, 0.78124821f, 0.78328675f, 0.78531694f, 0.78733873f, - 0.78935206f, 0.79135692f, 0.79335338f, 0.79534125f, 0.79732066f, - 0.79929149f, 0.80125386f, 0.80320752f, 0.80515265f, 0.80708915f, - 0.80901700f, 0.81093621f, 0.81284672f, 0.81474853f, 0.81664157f, - 0.81852591f, 0.82040149f, 0.82226825f, 0.82412618f, 0.82597536f, - 0.82781565f, 0.82964706f, 0.83146966f, 0.83328325f, 0.83508795f, - 0.83688378f, 0.83867061f, 0.84044838f, 0.84221727f, 0.84397703f, - 0.84572780f, 0.84746957f, 0.84920216f, 0.85092574f, 0.85264021f, - 0.85434544f, 0.85604161f, 0.85772866f, 0.85940641f, 0.86107504f, - 0.86273444f, 0.86438453f, 0.86602545f, 0.86765707f, 0.86927933f, - 0.87089235f, 0.87249607f, 0.87409031f, 0.87567532f, 0.87725097f, - 0.87881714f, 0.88037390f, 0.88192129f, 0.88345921f, 0.88498765f, - 0.88650668f, 0.88801610f, 0.88951612f, 0.89100653f, 0.89248741f, - 0.89395881f, 0.89542055f, 0.89687276f, 0.89831537f, 0.89974827f, - 0.90117162f, 0.90258533f, 0.90398932f, 0.90538365f, 0.90676826f, - 0.90814316f, 0.90950841f, 0.91086388f, 0.91220951f, 0.91354549f, - 0.91487163f, 0.91618794f, 0.91749454f, 0.91879123f, 0.92007810f, - 0.92135513f, 0.92262226f, 0.92387950f, 0.92512691f, 0.92636442f, - 0.92759192f, 0.92880958f, 0.93001723f, 0.93121493f, 0.93240267f, - 0.93358046f, 0.93474817f, 0.93590593f, 0.93705362f, 0.93819135f, - 0.93931901f, 0.94043654f, 0.94154406f, 0.94264150f, 0.94372880f, - 0.94480604f, 0.94587320f, 0.94693011f, 0.94797695f, 0.94901365f, - 0.95004016f, 0.95105654f, 0.95206273f, 0.95305866f, 0.95404440f, - 0.95501995f, 0.95598525f, 0.95694035f, 0.95788521f, 0.95881975f, - 0.95974404f, 0.96065807f, 0.96156180f, 0.96245527f, 0.96333838f, - 0.96421117f, 0.96507370f, 0.96592581f, 0.96676767f, 0.96759909f, - 0.96842021f, 0.96923089f, 0.97003126f, 0.97082120f, 0.97160077f, - 0.97236991f, 0.97312868f, 0.97387701f, 0.97461486f, 0.97534233f, - 0.97605932f, 0.97676587f, 0.97746199f, 0.97814763f, 0.97882277f, - 0.97948742f, 0.98014158f, 0.98078531f, 0.98141843f, 0.98204112f, - 0.98265332f, 0.98325491f, 0.98384601f, 0.98442656f, 0.98499662f, - 0.98555607f, 0.98610497f, 0.98664331f, 0.98717111f, 0.98768836f, - 0.98819500f, 0.98869103f, 0.98917651f, 0.98965138f, 0.99011570f, - 0.99056935f, 0.99101239f, 0.99144489f, 0.99186671f, 0.99227792f, - 0.99267852f, 0.99306846f, 0.99344778f, 0.99381649f, 0.99417448f, - 0.99452192f, 0.99485862f, 0.99518472f, 0.99550015f, 0.99580491f, - 0.99609905f, 0.99638247f, 0.99665523f, 0.99691731f, 0.99716878f, - 0.99740952f, 0.99763954f, 0.99785894f, 0.99806762f, 0.99826562f, - 0.99845290f, 0.99862951f, 0.99879545f, 0.99895066f, 0.99909520f, - 0.99922901f, 0.99935216f, 0.99946457f, 0.99956632f, 0.99965733f, - 0.99973762f, 0.99980724f, 0.99986613f, 0.99991435f, 0.99995178f, - 0.99997860f, 0.99999464f, 1.00000000f, 0.99999464f, 0.99997860f, - 0.99995178f, 0.99991435f, 0.99986613f, 0.99980724f, 0.99973762f, - 0.99965733f, 0.99956632f, 0.99946457f, 0.99935216f, 0.99922901f, - 0.99909520f, 0.99895066f, 0.99879545f, 0.99862951f, 0.99845290f, - 0.99826562f, 0.99806762f, 0.99785894f, 0.99763954f, 0.99740946f, - 0.99716872f, 0.99691731f, 0.99665523f, 0.99638247f, 0.99609905f, - 0.99580491f, 0.99550015f, 0.99518472f, 0.99485862f, 0.99452192f, - 0.99417448f, 0.99381644f, 0.99344778f, 0.99306846f, 0.99267852f, - 0.99227792f, 0.99186671f, 0.99144489f, 0.99101239f, 0.99056935f, - 0.99011564f, 0.98965138f, 0.98917651f, 0.98869103f, 0.98819494f, - 0.98768836f, 0.98717111f, 0.98664331f, 0.98610497f, 0.98555607f, - 0.98499656f, 0.98442656f, 0.98384601f, 0.98325491f, 0.98265326f, - 0.98204112f, 0.98141843f, 0.98078525f, 0.98014158f, 0.97948742f, - 0.97882277f, 0.97814757f, 0.97746193f, 0.97676587f, 0.97605932f, - 0.97534227f, 0.97461486f, 0.97387695f, 0.97312862f, 0.97236991f, - 0.97160077f, 0.97082120f, 0.97003126f, 0.96923089f, 0.96842015f, - 0.96759909f, 0.96676761f, 0.96592581f, 0.96507365f, 0.96421117f, - 0.96333838f, 0.96245521f, 0.96156180f, 0.96065807f, 0.95974404f, - 0.95881969f, 0.95788515f, 0.95694029f, 0.95598525f, 0.95501995f, - 0.95404440f, 0.95305860f, 0.95206267f, 0.95105648f, 0.95004016f, - 0.94901365f, 0.94797695f, 0.94693011f, 0.94587314f, 0.94480604f, - 0.94372880f, 0.94264150f, 0.94154406f, 0.94043654f, 0.93931895f, - 0.93819129f, 0.93705362f, 0.93590593f, 0.93474817f, 0.93358046f, - 0.93240267f, 0.93121493f, 0.93001723f, 0.92880952f, 0.92759192f, - 0.92636436f, 0.92512691f, 0.92387950f, 0.92262226f, 0.92135507f, - 0.92007804f, 0.91879123f, 0.91749448f, 0.91618794f, 0.91487157f, - 0.91354543f, 0.91220951f, 0.91086382f, 0.90950835f, 0.90814310f, - 0.90676820f, 0.90538365f, 0.90398932f, 0.90258527f, 0.90117157f, - 0.89974827f, 0.89831525f, 0.89687276f, 0.89542055f, 0.89395875f, - 0.89248741f, 0.89100647f, 0.88951600f, 0.88801610f, 0.88650662f, - 0.88498759f, 0.88345915f, 0.88192123f, 0.88037384f, 0.87881714f, - 0.87725091f, 0.87567532f, 0.87409031f, 0.87249595f, 0.87089223f, - 0.86927933f, 0.86765701f, 0.86602539f, 0.86438447f, 0.86273432f, - 0.86107504f, 0.85940641f, 0.85772860f, 0.85604161f, 0.85434544f, - 0.85264009f, 0.85092574f, 0.84920216f, 0.84746951f, 0.84572780f, - 0.84397697f, 0.84221715f, 0.84044844f, 0.83867055f, 0.83688372f, - 0.83508795f, 0.83328319f, 0.83146954f, 0.82964706f, 0.82781565f, - 0.82597530f, 0.82412612f, 0.82226813f, 0.82040137f, 0.81852591f, - 0.81664157f, 0.81474847f, 0.81284660f, 0.81093609f, 0.80901700f, - 0.80708915f, 0.80515265f, 0.80320752f, 0.80125374f, 0.79929143f, - 0.79732066f, 0.79534125f, 0.79335332f, 0.79135686f, 0.78935200f, - 0.78733861f, 0.78531694f, 0.78328675f, 0.78124815f, 0.77920121f, - 0.77714586f, 0.77508223f, 0.77301049f, 0.77093029f, 0.76884180f, - 0.76674509f, 0.76464021f, 0.76252711f, 0.76040596f, 0.75827658f, - 0.75613904f, 0.75399339f, 0.75183970f, 0.74967796f, 0.74750835f, - 0.74533057f, 0.74314481f, 0.74095106f, 0.73874938f, 0.73653996f, - 0.73432249f, 0.73209721f, 0.72986400f, 0.72762305f, 0.72537428f, - 0.72311789f, 0.72085363f, 0.71858162f, 0.71630186f, 0.71401453f, - 0.71171951f, 0.70941705f, 0.70710677f, 0.70478898f, 0.70246363f, - 0.70013070f, 0.69779032f, 0.69544268f, 0.69308734f, 0.69072461f, - 0.68835449f, 0.68597704f, 0.68359220f, 0.68120021f, 0.67880070f, - 0.67639399f, 0.67398006f, 0.67155886f, 0.66913044f, 0.66669512f, - 0.66425240f, 0.66180259f, 0.65934575f, 0.65688181f, 0.65441096f, - 0.65193301f, 0.64944804f, 0.64695609f, 0.64445722f, 0.64195150f, - 0.63943905f, 0.63691956f, 0.63439327f, 0.63186014f, 0.62932026f, - 0.62677372f, 0.62422055f, 0.62166059f, 0.61909389f, 0.61652064f, - 0.61394072f, 0.61135429f, 0.60876143f, 0.60616189f, 0.60355592f, - 0.60094339f, 0.59832448f, 0.59569913f, 0.59306765f, 0.59042960f, - 0.58778518f, 0.58513451f, 0.58247757f, 0.57981461f, 0.57714522f, - 0.57446963f, 0.57178789f, 0.56910002f, 0.56640613f, 0.56370628f, - 0.56100023f, 0.55828822f, 0.55557019f, 0.55284619f, 0.55011630f, - 0.54738069f, 0.54463905f, 0.54189152f, 0.53913826f, 0.53637916f, - 0.53361434f, 0.53084403f, 0.52806783f, 0.52528596f, 0.52249849f, - 0.51970541f, 0.51690674f, 0.51410276f, 0.51129305f, 0.50847787f, - 0.50565726f, 0.50283122f, 0.50000006f, 0.49716327f, 0.49432117f, - 0.49147379f, 0.48862115f, 0.48576325f, 0.48290038f, 0.48003212f, - 0.47715873f, 0.47428021f, 0.47139663f, 0.46850798f, 0.46561456f, - 0.46271589f, 0.45981231f, 0.45690379f, 0.45399037f, 0.45107210f, - 0.44814920f, 0.44522130f, 0.44228864f, 0.43935123f, 0.43640912f, - 0.43346232f, 0.43051112f, 0.42755505f, 0.42459446f, 0.42162928f, - 0.41865960f, 0.41568545f, 0.41270703f, 0.40972400f, 0.40673658f, - 0.40374479f, 0.40074870f, 0.39774850f, 0.39474386f, 0.39173496f, - 0.38872188f, 0.38570464f, 0.38268328f, 0.37965804f, 0.37662849f, - 0.37359491f, 0.37055734f, 0.36751580f, 0.36447033f, 0.36142117f, - 0.35836792f, 0.35531086f, 0.35224995f, 0.34918529f, 0.34611690f, - 0.34304500f, 0.33996922f, 0.33688980f, 0.33380675f, 0.33072016f, - 0.32763001f, 0.32453656f, 0.32143945f, 0.31833887f, 0.31523487f, - 0.31212750f, 0.30901679f, 0.30590302f, 0.30278572f, 0.29966521f, - 0.29654145f, 0.29341453f, 0.29028472f, 0.28715155f, 0.28401530f, - 0.28087601f, 0.27773371f, 0.27458847f, 0.27144048f, 0.26828936f, - 0.26513538f, 0.26197854f, 0.25881892f, 0.25565651f, 0.25249159f, - 0.24932374f, 0.24615324f, 0.24298008f, 0.23980433f, 0.23662600f, - 0.23344538f, 0.23026201f, 0.22707619f, 0.22388794f, 0.22069728f, - 0.21750426f, 0.21430916f, 0.21111152f, 0.20791161f, 0.20470949f, - 0.20150517f, 0.19829892f, 0.19509031f, 0.19187963f, 0.18866688f, - 0.18545210f, 0.18223536f, 0.17901689f, 0.17579627f, 0.17257376f, - 0.16934940f, 0.16612324f, 0.16289529f, 0.15966584f, 0.15643445f, - 0.15320137f, 0.14996666f, 0.14673033f, 0.14349243f, 0.14025325f, - 0.13701232f, 0.13376991f, 0.13052608f, 0.12728085f, 0.12403426f, - 0.12078657f, 0.11753736f, 0.11428688f, 0.11103519f, 0.10778230f, - 0.10452849f, 0.10127334f, 0.09801710f, 0.09475980f, 0.09150149f, - 0.08824220f, 0.08498220f, 0.08172106f, 0.07845904f, 0.07519618f, - 0.07193252f, 0.06866808f, 0.06540315f, 0.06213728f, 0.05887074f, - 0.05560357f, 0.05233581f, 0.04906749f, 0.04579888f, 0.04252954f, - 0.03925974f, 0.03598953f, 0.03271893f, 0.02944798f, 0.02617695f, - 0.02290541f, 0.01963361f, 0.01636161f, 0.01308943f, 0.00981712f, - 0.00654493f, 0.00327244f, 0.00000000f, 0.00000000f, 0.00000000f, - 0.00000000f, 0.00000000f, 0.00000000f, 0.00000000f, 0.00000000f, - 0.00000000f, 0.00000000f, 0.00000000f, 0.00000000f, 0.00000000f, - 0.00000000f, 0.00000000f, 0.00000000f, 0.00000000f, 0.00000000f, - 0.00000000f, 0.00000000f, 0.00000000f, 0.00000000f, 0.00000000f, - 0.00000000f, 0.00000000f, 0.00000000f, 0.00000000f, 0.00000000f, - 0.00000000f, 0.00000000f, 0.00000000f, 0.00000000f}; - -} // namespace webrtc - -#endif // MODULES_AUDIO_PROCESSING_TRANSIENT_WINDOWS_PRIVATE_H_ diff --git a/webrtc/modules/audio_processing/transient/wpd_node.cc b/webrtc/modules/audio_processing/transient/wpd_node.cc deleted file mode 100644 index 2e0ee7e..0000000 --- a/webrtc/modules/audio_processing/transient/wpd_node.cc +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "modules/audio_processing/transient/wpd_node.h" - -#include -#include - -#include "common_audio/fir_filter.h" -#include "common_audio/fir_filter_factory.h" -#include "modules/audio_processing/transient/dyadic_decimator.h" -#include "rtc_base/checks.h" - -namespace webrtc { - -WPDNode::WPDNode(size_t length, - const float* coefficients, - size_t coefficients_length) - : // The data buffer has parent data length to be able to contain and - // filter it. - data_(new float[2 * length + 1]), - length_(length), - filter_( - CreateFirFilter(coefficients, coefficients_length, 2 * length + 1)) { - RTC_DCHECK_GT(length, 0); - RTC_DCHECK(coefficients); - RTC_DCHECK_GT(coefficients_length, 0); - memset(data_.get(), 0.f, (2 * length + 1) * sizeof(data_[0])); -} - -WPDNode::~WPDNode() {} - -int WPDNode::Update(const float* parent_data, size_t parent_data_length) { - if (!parent_data || (parent_data_length / 2) != length_) { - return -1; - } - - // Filter data. - filter_->Filter(parent_data, parent_data_length, data_.get()); - - // Decimate data. - const bool kOddSequence = true; - size_t output_samples = DyadicDecimate(data_.get(), parent_data_length, - kOddSequence, data_.get(), length_); - if (output_samples != length_) { - return -1; - } - - // Get abs to all values. - for (size_t i = 0; i < length_; ++i) { - data_[i] = fabs(data_[i]); - } - - return 0; -} - -int WPDNode::set_data(const float* new_data, size_t length) { - if (!new_data || length != length_) { - return -1; - } - memcpy(data_.get(), new_data, length * sizeof(data_[0])); - return 0; -} - -} // namespace webrtc diff --git a/webrtc/modules/audio_processing/transient/wpd_node.h b/webrtc/modules/audio_processing/transient/wpd_node.h deleted file mode 100644 index 645bc5f..0000000 --- a/webrtc/modules/audio_processing/transient/wpd_node.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef MODULES_AUDIO_PROCESSING_TRANSIENT_WPD_NODE_H_ -#define MODULES_AUDIO_PROCESSING_TRANSIENT_WPD_NODE_H_ - -#include -#include - -namespace webrtc { - -class FIRFilter; - -// A single node of a Wavelet Packet Decomposition (WPD) tree. -class WPDNode { - public: - // Creates a WPDNode. The data vector will contain zeros. The filter will have - // the coefficients provided. - WPDNode(size_t length, const float* coefficients, size_t coefficients_length); - ~WPDNode(); - - // Updates the node data. `parent_data` / 2 must be equals to `length_`. - // Returns 0 if correct, and -1 otherwise. - int Update(const float* parent_data, size_t parent_data_length); - - const float* data() const { return data_.get(); } - // Returns 0 if correct, and -1 otherwise. - int set_data(const float* new_data, size_t length); - size_t length() const { return length_; } - - private: - std::unique_ptr data_; - size_t length_; - std::unique_ptr filter_; -}; - -} // namespace webrtc - -#endif // MODULES_AUDIO_PROCESSING_TRANSIENT_WPD_NODE_H_ diff --git a/webrtc/modules/audio_processing/transient/wpd_tree.cc b/webrtc/modules/audio_processing/transient/wpd_tree.cc deleted file mode 100644 index c8aa615..0000000 --- a/webrtc/modules/audio_processing/transient/wpd_tree.cc +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "modules/audio_processing/transient/wpd_tree.h" - -#include - -#include "modules/audio_processing/transient/wpd_node.h" -#include "rtc_base/checks.h" - -namespace webrtc { - -WPDTree::WPDTree(size_t data_length, - const float* high_pass_coefficients, - const float* low_pass_coefficients, - size_t coefficients_length, - int levels) - : data_length_(data_length), - levels_(levels), - num_nodes_((1 << (levels + 1)) - 1) { - RTC_DCHECK_GT(data_length, (static_cast(1) << levels)); - RTC_DCHECK(high_pass_coefficients); - RTC_DCHECK(low_pass_coefficients); - RTC_DCHECK_GT(levels, 0); - // Size is 1 more, so we can use the array as 1-based. nodes_[0] is never - // allocated. - nodes_.reset(new std::unique_ptr[num_nodes_ + 1]); - - // Create the first node - const float kRootCoefficient = 1.f; // Identity Coefficient. - nodes_[1].reset(new WPDNode(data_length, &kRootCoefficient, 1)); - // Variables used to create the rest of the nodes. - size_t index = 1; - size_t index_left_child = 0; - size_t index_right_child = 0; - - int num_nodes_at_curr_level = 0; - - // Branching each node in each level to create its children. The last level is - // not branched (all the nodes of that level are leaves). - for (int current_level = 0; current_level < levels; ++current_level) { - num_nodes_at_curr_level = 1 << current_level; - for (int i = 0; i < num_nodes_at_curr_level; ++i) { - index = (1 << current_level) + i; - // Obtain the index of the current node children. - index_left_child = index * 2; - index_right_child = index_left_child + 1; - nodes_[index_left_child].reset(new WPDNode(nodes_[index]->length() / 2, - low_pass_coefficients, - coefficients_length)); - nodes_[index_right_child].reset(new WPDNode(nodes_[index]->length() / 2, - high_pass_coefficients, - coefficients_length)); - } - } -} - -WPDTree::~WPDTree() {} - -WPDNode* WPDTree::NodeAt(int level, int index) { - if (level < 0 || level > levels_ || index < 0 || index >= 1 << level) { - return NULL; - } - - return nodes_[(1 << level) + index].get(); -} - -int WPDTree::Update(const float* data, size_t data_length) { - if (!data || data_length != data_length_) { - return -1; - } - - // Update the root node. - int update_result = nodes_[1]->set_data(data, data_length); - if (update_result != 0) { - return -1; - } - - // Variables used to update the rest of the nodes. - size_t index = 1; - size_t index_left_child = 0; - size_t index_right_child = 0; - - int num_nodes_at_curr_level = 0; - - for (int current_level = 0; current_level < levels_; ++current_level) { - num_nodes_at_curr_level = 1 << current_level; - for (int i = 0; i < num_nodes_at_curr_level; ++i) { - index = (1 << current_level) + i; - // Obtain the index of the current node children. - index_left_child = index * 2; - index_right_child = index_left_child + 1; - - update_result = nodes_[index_left_child]->Update(nodes_[index]->data(), - nodes_[index]->length()); - if (update_result != 0) { - return -1; - } - - update_result = nodes_[index_right_child]->Update( - nodes_[index]->data(), nodes_[index]->length()); - if (update_result != 0) { - return -1; - } - } - } - - return 0; -} - -} // namespace webrtc diff --git a/webrtc/modules/audio_processing/transient/wpd_tree.h b/webrtc/modules/audio_processing/transient/wpd_tree.h deleted file mode 100644 index 13cb8d9..0000000 --- a/webrtc/modules/audio_processing/transient/wpd_tree.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef MODULES_AUDIO_PROCESSING_TRANSIENT_WPD_TREE_H_ -#define MODULES_AUDIO_PROCESSING_TRANSIENT_WPD_TREE_H_ - -#include - -#include - -#include "modules/audio_processing/transient/wpd_node.h" - -namespace webrtc { - -// Tree of a Wavelet Packet Decomposition (WPD). -// -// The root node contains all the data provided; for each node in the tree, the -// left child contains the approximation coefficients extracted from the node, -// and the right child contains the detail coefficients. -// It preserves its state, so it can be multiple-called. -// -// The number of nodes in the tree will be 2 ^ levels - 1. -// -// Implementation details: Since the tree always will be a complete binary tree, -// it is implemented using a single linear array instead of managing the -// relationships in each node. For convience is better to use a array that -// starts in 1 (instead of 0). Taking that into account, the following formulas -// apply: -// Root node index: 1. -// Node(Level, Index in that level): 2 ^ Level + (Index in that level). -// Left Child: Current node index * 2. -// Right Child: Current node index * 2 + 1. -// Parent: Current Node Index / 2 (Integer division). -class WPDTree { - public: - // Creates a WPD tree using the data length and coefficients provided. - WPDTree(size_t data_length, - const float* high_pass_coefficients, - const float* low_pass_coefficients, - size_t coefficients_length, - int levels); - ~WPDTree(); - - // Returns the number of nodes at any given level. - static int NumberOfNodesAtLevel(int level) { return 1 << level; } - - // Returns a pointer to the node at the given level and index(of that level). - // Level goes from 0 to levels(). - // Index goes from 0 to the number of NumberOfNodesAtLevel(level) - 1. - // - // You can use the following formulas to get any node within the tree: - // Notation: (Level, Index of node in that level). - // Root node: (0/0). - // Left Child: (Current node level + 1, Current node index * 2). - // Right Child: (Current node level + 1, Current node index * 2 + 1). - // Parent: (Current node level - 1, Current node index / 2) (Integer division) - // - // If level or index are out of bounds the function will return NULL. - WPDNode* NodeAt(int level, int index); - - // Updates all the nodes of the tree with the new data. `data_length` must be - // teh same that was used for the creation of the tree. - // Returns 0 if correct, and -1 otherwise. - int Update(const float* data, size_t data_length); - - // Returns the total number of levels below the root. Root is cosidered level - // 0. - int levels() const { return levels_; } - - // Returns the total number of nodes. - int num_nodes() const { return num_nodes_; } - - // Returns the total number of leaves. - int num_leaves() const { return 1 << levels_; } - - private: - size_t data_length_; - int levels_; - int num_nodes_; - std::unique_ptr[]> nodes_; -}; - -} // namespace webrtc - -#endif // MODULES_AUDIO_PROCESSING_TRANSIENT_WPD_TREE_H_ diff --git a/webrtc/rtc_base/BUILD.gn b/webrtc/rtc_base/BUILD.gn index 6abae80..a18e695 100644 --- a/webrtc/rtc_base/BUILD.gn +++ b/webrtc/rtc_base/BUILD.gn @@ -13,14 +13,6 @@ if (is_android) { import("//build/config/android/rules.gni") } -if (!rtc_build_ssl) { - config("external_ssl_library") { - assert(rtc_ssl_root != "", - "You must specify rtc_ssl_root when rtc_build_ssl==0.") - include_dirs = [ rtc_ssl_root ] - } -} - rtc_source_set("protobuf_utils") { sources = [ "protobuf_utils.h" ] if (rtc_enable_protobuf) { @@ -38,11 +30,9 @@ rtc_source_set("bitstream_reader") { ":checks", ":safe_conversions", "../api:array_view", - ] - absl_deps = [ "//third_party/abseil-cpp/absl/base:core_headers", "//third_party/abseil-cpp/absl/numeric:bits", - "//third_party/abseil-cpp/absl/strings", + "//third_party/abseil-cpp/absl/strings:string_view", ] } @@ -82,8 +72,8 @@ rtc_source_set("buffer") { ":type_traits", ":zero_memory", "../api:array_view", + "//third_party/abseil-cpp/absl/strings:string_view", ] - absl_deps = [ "//third_party/abseil-cpp/absl/strings" ] } rtc_source_set("byte_order") { @@ -102,7 +92,6 @@ rtc_source_set("moving_max_counter") { visibility = [ "*" ] sources = [ "numerics/moving_max_counter.h" ] deps = [ ":checks" ] - absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] } rtc_source_set("one_time_event") { @@ -119,8 +108,10 @@ rtc_source_set("strong_alias") { rtc_source_set("swap_queue") { visibility = [ "*" ] sources = [ "swap_queue.h" ] - deps = [ ":checks" ] - absl_deps = [ "//third_party/abseil-cpp/absl/base:core_headers" ] + deps = [ + ":checks", + "//third_party/abseil-cpp/absl/base:core_headers", + ] } rtc_source_set("macromagic") { @@ -140,10 +131,8 @@ rtc_library("bit_buffer") { deps = [ ":checks", "../api/units:data_size", - ] - absl_deps = [ "//third_party/abseil-cpp/absl/numeric:bits", - "//third_party/abseil-cpp/absl/strings:strings", + "//third_party/abseil-cpp/absl/strings:string_view", ] } @@ -156,8 +145,10 @@ rtc_library("byte_buffer") { deps = [ ":buffer", ":byte_order", + "../api:array_view", + "//third_party/abseil-cpp/absl/base:core_headers", + "//third_party/abseil-cpp/absl/strings:string_view", ] - absl_deps = [ "//third_party/abseil-cpp/absl/strings" ] } rtc_library("buffer_queue") { @@ -187,8 +178,8 @@ rtc_library("copy_on_write_buffer") { ":type_traits", "../api:scoped_refptr", "system:rtc_export", + "//third_party/abseil-cpp/absl/strings:string_view", ] - absl_deps = [ "//third_party/abseil-cpp/absl/strings" ] } rtc_library("event_tracer") { @@ -206,11 +197,18 @@ rtc_library("event_tracer") { ":platform_thread_types", ":rtc_event", ":timeutils", + "..:tracing", "../api:sequence_checker", "synchronization:mutex", "system:rtc_export", + "//third_party/abseil-cpp/absl/strings:string_view", ] - absl_deps = [ "//third_party/abseil-cpp/absl/strings" ] + if (rtc_use_perfetto) { + sources += [ + "trace_categories.cc", + "trace_categories.h", + ] + } } rtc_library("histogram_percentile_counter") { @@ -220,7 +218,6 @@ rtc_library("histogram_percentile_counter") { "numerics/histogram_percentile_counter.h", ] deps = [ ":checks" ] - absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] } rtc_library("race_checker") { @@ -262,7 +259,6 @@ rtc_library("bitrate_tracker") { "../api/units:timestamp", "system:rtc_export", ] - absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] } rtc_library("frequency_tracker") { @@ -278,7 +274,6 @@ rtc_library("frequency_tracker") { "../api/units:timestamp", "system:rtc_export", ] - absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] } rtc_library("rate_statistics") { @@ -295,7 +290,6 @@ rtc_library("rate_statistics") { ":safe_conversions", "system:rtc_export", ] - absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] } rtc_library("rate_tracker") { @@ -320,7 +314,6 @@ rtc_library("sample_counter") { ":checks", ":safe_conversions", ] - absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] } rtc_library("timestamp_aligner") { @@ -369,6 +362,7 @@ rtc_source_set("refcount") { ] deps = [ ":macromagic", + "../api:ref_count", "../api:scoped_refptr", ] } @@ -399,11 +393,7 @@ rtc_library("platform_thread") { ":rtc_event", ":timeutils", "../api:sequence_checker", - ] - absl_deps = [ - "//third_party/abseil-cpp/absl/memory", - "//third_party/abseil-cpp/absl/strings", - "//third_party/abseil-cpp/absl/types:optional", + "//third_party/abseil-cpp/absl/strings:string_view", ] } @@ -431,7 +421,6 @@ rtc_library("rtc_event") { "synchronization:yield_policy", "system:warn_current_thread_is_deadlocked", ] - absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] } } @@ -448,14 +437,13 @@ rtc_library("logging") { ":platform_thread_types", ":stringutils", ":timeutils", + ":type_traits", "../api/units:timestamp", "synchronization:mutex", - ] - absl_deps = [ "//third_party/abseil-cpp/absl/base:core_headers", "//third_party/abseil-cpp/absl/meta:type_traits", "//third_party/abseil-cpp/absl/strings", - "//third_party/abseil-cpp/absl/types:optional", + "//third_party/abseil-cpp/absl/strings:string_view", ] if (build_with_chromium) { @@ -499,18 +487,18 @@ rtc_library("checks") { ] deps = [ ":safe_compare", + ":type_traits", "../api:scoped_refptr", "system:inline", "system:rtc_export", + "//third_party/abseil-cpp/absl/meta:type_traits", + "//third_party/abseil-cpp/absl/strings", + "//third_party/abseil-cpp/absl/strings:string_view", ] if (build_with_chromium) { sources += [ "../../webrtc_overrides/rtc_base/checks_overrides.cc" ] deps += [ "//base" ] } - absl_deps = [ - "//third_party/abseil-cpp/absl/meta:type_traits", - "//third_party/abseil-cpp/absl/strings", - ] if (is_android) { libs += [ "log" ] } @@ -527,12 +515,11 @@ rtc_library("rate_limiter") { "../system_wrappers", "synchronization:mutex", ] - absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] } rtc_source_set("sanitizer") { sources = [ "sanitizer.h" ] - absl_deps = [ "//third_party/abseil-cpp/absl/meta:type_traits" ] + deps = [ "//third_party/abseil-cpp/absl/meta:type_traits" ] } rtc_source_set("bounded_inline_vector") { @@ -605,6 +592,7 @@ rtc_library("stringutils") { "string_to_number.h", "string_utils.cc", "string_utils.h", + "strings/str_join.h", "strings/string_builder.cc", "strings/string_builder.h", "strings/string_format.cc", @@ -615,10 +603,8 @@ rtc_library("stringutils") { ":macromagic", ":safe_minmax", "../api:array_view", - ] - absl_deps = [ "//third_party/abseil-cpp/absl/strings", - "//third_party/abseil-cpp/absl/types:optional", + "//third_party/abseil-cpp/absl/strings:string_view", ] } @@ -637,23 +623,6 @@ rtc_source_set("type_traits") { sources = [ "type_traits.h" ] } -rtc_library("rtc_task_queue") { - visibility = [ "*" ] - sources = [ - "task_queue.cc", - "task_queue.h", - ] - deps = [ - ":macromagic", - "../api/task_queue", - "system:rtc_export", - ] - absl_deps = [ - "//third_party/abseil-cpp/absl/functional:any_invocable", - "//third_party/abseil-cpp/absl/memory", - ] -} - rtc_source_set("rtc_operations_chain") { visibility = [ "*" ] sources = [ @@ -670,7 +639,6 @@ rtc_source_set("rtc_operations_chain") { "../api:sequence_checker", "system:no_unique_address", ] - absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] } if (rtc_enable_libevent) { @@ -691,11 +659,9 @@ if (rtc_enable_libevent) { "../api/task_queue", "../api/units:time_delta", "synchronization:mutex", - ] - absl_deps = [ "//third_party/abseil-cpp/absl/container:inlined_vector", "//third_party/abseil-cpp/absl/functional:any_invocable", - "//third_party/abseil-cpp/absl/strings", + "//third_party/abseil-cpp/absl/strings:string_view", ] if (rtc_build_libevent) { deps += [ "//third_party/libevent" ] @@ -718,10 +684,8 @@ if (is_mac || is_ios) { "../api/units:time_delta", "synchronization:mutex", "system:gcd_helpers", - ] - absl_deps = [ "//third_party/abseil-cpp/absl/functional:any_invocable", - "//third_party/abseil-cpp/absl/strings", + "//third_party/abseil-cpp/absl/strings:string_view", ] } } @@ -745,11 +709,8 @@ if (is_win) { "../api/units:time_delta", "../api/units:timestamp", "synchronization:mutex", - ] - absl_deps = [ "//third_party/abseil-cpp/absl/functional:any_invocable", - "//third_party/abseil-cpp/absl/strings", - "//third_party/abseil-cpp/absl/types:optional", + "//third_party/abseil-cpp/absl/strings:string_view", ] } } @@ -771,10 +732,8 @@ rtc_library("rtc_task_queue_stdlib") { "../api/task_queue", "../api/units:time_delta", "synchronization:mutex", - ] - absl_deps = [ "//third_party/abseil-cpp/absl/functional:any_invocable", - "//third_party/abseil-cpp/absl/strings", + "//third_party/abseil-cpp/absl/strings:string_view", ] } @@ -785,8 +744,13 @@ if (rtc_include_tests) { sources = [ "task_queue_stdlib_unittest.cc" ] deps = [ ":gunit_helpers", + ":logging", + ":rtc_event", ":rtc_task_queue_stdlib", + "../api/task_queue", "../api/task_queue:task_queue_test", + "../api/units:time_delta", + "../system_wrappers", "../test:test_main", "../test:test_support", ] @@ -799,6 +763,8 @@ rtc_library("weak_ptr") { "weak_ptr.h", ] deps = [ + ":checks", + ":macromagic", ":refcount", "../api:scoped_refptr", "../api:sequence_checker", @@ -817,6 +783,7 @@ rtc_library("rtc_numerics") { "numerics/moving_average.h", "numerics/moving_percentile_filter.h", "numerics/percentile_filter.h", + "numerics/rational.h", "numerics/running_statistics.h", "numerics/sequence_number_unwrapper.h", "numerics/sequence_number_util.h", @@ -825,7 +792,6 @@ rtc_library("rtc_numerics") { ":checks", ":mod_ops", ] - absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] } rtc_library("rtc_stats_counters") { @@ -836,12 +802,12 @@ rtc_library("rtc_stats_counters") { "numerics/sample_stats.h", ] deps = [ + ":checks", "../api/numerics", "../api/units:data_rate", "../api/units:time_delta", "../api/units:timestamp", ] - absl_deps = [] } config("rtc_json_suppressions") { @@ -862,14 +828,16 @@ rtc_library("rtc_json") { "strings/json.cc", "strings/json.h", ] - deps = [ ":stringutils" ] + deps = [ + ":stringutils", + "//third_party/abseil-cpp/absl/strings:string_view", + ] all_dependent_configs = [ "//third_party/jsoncpp:jsoncpp_config" ] if (rtc_build_json) { deps += [ "//third_party/jsoncpp" ] } else { include_dirs = [ "$rtc_jsoncpp_root" ] } - absl_deps = [ "//third_party/abseil-cpp/absl/strings" ] } rtc_library("net_helpers") { @@ -878,7 +846,10 @@ rtc_library("net_helpers") { "net_helpers.cc", "net_helpers.h", ] - deps = [ "system:rtc_export" ] + deps = [ + "system:rtc_export", + "//third_party/abseil-cpp/absl/strings:string_view", + ] if (is_android) { deps += [ ":ifaddrs_android" ] } @@ -888,7 +859,6 @@ rtc_library("net_helpers") { "win:windows_version", ] } - absl_deps = [ "//third_party/abseil-cpp/absl/strings" ] } rtc_library("net_test_helpers") { @@ -911,20 +881,6 @@ rtc_library("net_test_helpers") { } } -rtc_library("async_resolver_interface") { - visibility = [ "*" ] - sources = [ - "async_resolver_interface.cc", - "async_resolver_interface.h", - ] - deps = [ - ":checks", - ":socket_address", - "system:rtc_export", - "third_party/sigslot", - ] -} - rtc_library("async_dns_resolver") { sources = [ "async_dns_resolver.cc", @@ -965,11 +921,11 @@ rtc_library("ip_address") { ":net_helpers", ":stringutils", "system:rtc_export", + "//third_party/abseil-cpp/absl/strings:string_view", ] if (is_win) { deps += [ ":win32" ] } - absl_deps = [ "//third_party/abseil-cpp/absl/strings" ] } rtc_library("socket_address") { @@ -987,11 +943,11 @@ rtc_library("socket_address") { ":safe_conversions", ":stringutils", "system:rtc_export", + "//third_party/abseil-cpp/absl/strings:string_view", ] if (is_win) { deps += [ ":win32" ] } - absl_deps = [ "//third_party/abseil-cpp/absl/strings" ] } rtc_library("null_socket_server") { @@ -1023,8 +979,6 @@ rtc_library("threading") { visibility = [ "*" ] sources = [ - "async_resolver.cc", - "async_resolver.h", "internal/default_socket_server.cc", "internal/default_socket_server.h", "network_monitor.cc", @@ -1036,17 +990,8 @@ rtc_library("threading") { "thread.cc", "thread.h", ] - absl_deps = [ - "//third_party/abseil-cpp/absl/algorithm:container", - "//third_party/abseil-cpp/absl/base:core_headers", - "//third_party/abseil-cpp/absl/cleanup", - "//third_party/abseil-cpp/absl/functional:any_invocable", - "//third_party/abseil-cpp/absl/memory", - "//third_party/abseil-cpp/absl/strings", - ] deps = [ ":async_dns_resolver", - ":async_resolver_interface", ":byte_order", ":checks", ":criticalsection", @@ -1060,7 +1005,6 @@ rtc_library("threading") { ":platform_thread_types", ":refcount", ":rtc_event", - ":rtc_task_queue", ":socket", ":socket_address", ":socket_server", @@ -1075,10 +1019,16 @@ rtc_library("threading") { "../api/task_queue:pending_task_safety_flag", "../api/units:time_delta", "../system_wrappers:field_trial", + "./network:ecn_marking", "synchronization:mutex", "system:no_unique_address", "system:rtc_export", "third_party/sigslot", + "//third_party/abseil-cpp/absl/algorithm:container", + "//third_party/abseil-cpp/absl/base:core_headers", + "//third_party/abseil-cpp/absl/cleanup", + "//third_party/abseil-cpp/absl/functional:any_invocable", + "//third_party/abseil-cpp/absl/strings:string_view", ] if (is_android) { deps += [ ":ifaddrs_android" ] @@ -1106,8 +1056,8 @@ rtc_library("async_socket") { ":socket", ":socket_address", "third_party/sigslot", + "//third_party/abseil-cpp/absl/memory", ] - absl_deps = [ "//third_party/abseil-cpp/absl/memory" ] } rtc_library("socket") { @@ -1116,8 +1066,15 @@ rtc_library("socket") { "socket.h", ] deps = [ + ":buffer", + ":checks", + ":ip_address", ":macromagic", + ":net_helpers", ":socket_address", + "../api/units:timestamp", + "./network:ecn_marking", + "system:rtc_export", "third_party/sigslot", ] if (is_win) { @@ -1144,7 +1101,7 @@ if (is_android) { "log", "GLESv2", ] - absl_deps = [ "//third_party/abseil-cpp/absl/cleanup" ] + deps = [ "//third_party/abseil-cpp/absl/cleanup" ] } } @@ -1222,8 +1179,8 @@ if (!build_with_chromium) { ":checks", ":file_rotating_stream", ":logging", + "//third_party/abseil-cpp/absl/strings:string_view", ] - absl_deps = [ "//third_party/abseil-cpp/absl/strings" ] } } @@ -1254,12 +1211,11 @@ rtc_library("network") { "memory:always_valid_pointer", "system:rtc_export", "third_party/sigslot", - ] - absl_deps = [ "//third_party/abseil-cpp/absl/algorithm:container", "//third_party/abseil-cpp/absl/base:core_headers", "//third_party/abseil-cpp/absl/memory", "//third_party/abseil-cpp/absl/strings", + "//third_party/abseil-cpp/absl/strings:string_view", ] if (is_win) { @@ -1281,8 +1237,10 @@ rtc_library("net_helper") { "net_helper.cc", "net_helper.h", ] - absl_deps = [ "//third_party/abseil-cpp/absl/strings" ] - deps = [ "system:rtc_export" ] + deps = [ + "system:rtc_export", + "//third_party/abseil-cpp/absl/strings:string_view", + ] } rtc_library("socket_adapters") { @@ -1296,14 +1254,13 @@ rtc_library("socket_adapters") { ":buffer", ":byte_buffer", ":checks", - ":crypt_string", - ":http_common", ":logging", ":stringutils", ":zero_memory", "../api:array_view", + "//third_party/abseil-cpp/absl/strings", + "//third_party/abseil-cpp/absl/strings:string_view", ] - absl_deps = [ "//third_party/abseil-cpp/absl/strings" ] } rtc_library("network_route") { @@ -1353,11 +1310,12 @@ rtc_library("async_udp_socket") { ":socket_factory", ":timeutils", "../api:sequence_checker", + "../api/units:time_delta", "../system_wrappers:field_trial", + "network:received_packet", "network:sent_packet", "system:no_unique_address", ] - absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] } rtc_library("async_packet_socket") { @@ -1368,10 +1326,12 @@ rtc_library("async_packet_socket") { ] deps = [ ":callback_list", + ":checks", ":dscp", ":socket", ":timeutils", "../api:sequence_checker", + "network:received_packet", "network:sent_packet", "system:no_unique_address", "system:rtc_export", @@ -1379,28 +1339,34 @@ rtc_library("async_packet_socket") { ] } +if (rtc_include_tests) { + rtc_library("async_packet_socket_unittest") { + testonly = true + visibility = [ "*" ] + sources = [ "async_packet_socket_unittest.cc" ] + deps = [ + ":async_packet_socket", + ":gunit_helpers", + ":socket_address", + "../test:test_support", + "network:received_packet", + "third_party/sigslot", + ] + } +} + rtc_library("mdns_responder_interface") { sources = [ "mdns_responder_interface.h" ] - deps = [ ":ip_address" ] - absl_deps = [ "//third_party/abseil-cpp/absl/strings" ] + deps = [ + ":ip_address", + "//third_party/abseil-cpp/absl/strings:string_view", + ] } rtc_library("dscp") { sources = [ "dscp.h" ] } -rtc_library("proxy_info") { - visibility = [ "*" ] - sources = [ - "proxy_info.cc", - "proxy_info.h", - ] - deps = [ - ":crypt_string", - ":socket_address", - ] -} - rtc_library("file_rotating_stream") { sources = [ "file_rotating_stream.cc", @@ -1411,11 +1377,9 @@ rtc_library("file_rotating_stream") { ":logging", ":stringutils", "system:file_wrapper", - ] - absl_deps = [ "//third_party/abseil-cpp/absl/algorithm:container", "//third_party/abseil-cpp/absl/strings", - "//third_party/abseil-cpp/absl/types:optional", + "//third_party/abseil-cpp/absl/strings:string_view", ] } @@ -1433,14 +1397,14 @@ rtc_library("unique_id_generator") { "unique_id_generator.h", ] deps = [ - ":ssl", + ":crypto_random", ":stringutils", "../api:array_view", "../api:sequence_checker", "synchronization:mutex", "system:no_unique_address", + "//third_party/abseil-cpp/absl/strings:string_view", ] - absl_deps = [ "//third_party/abseil-cpp/absl/strings" ] } rtc_library("crc32") { @@ -1448,8 +1412,10 @@ rtc_library("crc32") { "crc32.cc", "crc32.h", ] - deps = [ ":macromagic" ] - absl_deps = [ "//third_party/abseil-cpp/absl/strings" ] + deps = [ + ":macromagic", + "//third_party/abseil-cpp/absl/strings:string_view", + ] } rtc_library("stream") { @@ -1461,10 +1427,15 @@ rtc_library("stream") { deps = [ ":buffer", ":checks", + ":logging", + ":macromagic", ":threading", "../api:array_view", + "../api:sequence_checker", + "system:no_unique_address", "system:rtc_export", "third_party/sigslot", + "//third_party/abseil-cpp/absl/functional:any_invocable", ] } @@ -1480,81 +1451,101 @@ rtc_library("rtc_certificate_generator") { ":threading", "../api:scoped_refptr", "system:rtc_export", - ] - absl_deps = [ "//third_party/abseil-cpp/absl/functional:any_invocable", - "//third_party/abseil-cpp/absl/types:optional", ] } +rtc_source_set("ssl_header") { + visibility = [ "*" ] + sources = [ "openssl.h" ] + deps = [] + if (is_win) { + deps += [ ":win32" ] + } +} + +rtc_source_set("digest") { + visibility = [ "*" ] + sources = [ + "message_digest.cc", + "message_digest.h", + "openssl_digest.cc", + "openssl_digest.h", + ] + deps = [ + ":checks", + ":ssl_header", + ":stringutils", + "//third_party/abseil-cpp/absl/strings:string_view", + ] + + # If we are building the SSL library ourselves, we know it's BoringSSL. + if (rtc_build_ssl) { + deps += [ "//third_party/boringssl" ] + } else { + configs += [ "..:external_ssl_library" ] + } +} + +rtc_library("crypto_random") { + visibility = [ "*" ] + sources = [ + "crypto_random.cc", + "crypto_random.h", + ] + deps = [ + ":checks", + ":logging", + "synchronization:mutex", + "system:rtc_export", + "//third_party/abseil-cpp/absl/strings:string_view", + ] + + # If we are building the SSL library ourselves, we know it's BoringSSL. + if (rtc_build_ssl) { + deps += [ "//third_party/boringssl" ] + } else { + configs += [ "..:external_ssl_library" ] + } +} + rtc_library("ssl") { visibility = [ "*" ] sources = [ - "helpers.cc", - "helpers.h", - "message_digest.cc", - "message_digest.h", - "openssl.h", - "openssl_adapter.cc", - "openssl_adapter.h", - "openssl_digest.cc", - "openssl_digest.h", "openssl_key_pair.cc", "openssl_key_pair.h", - "openssl_session_cache.cc", - "openssl_session_cache.h", - "openssl_stream_adapter.cc", - "openssl_stream_adapter.h", "openssl_utility.cc", "openssl_utility.h", "rtc_certificate.cc", "rtc_certificate.h", - "ssl_adapter.cc", - "ssl_adapter.h", "ssl_certificate.cc", "ssl_certificate.h", "ssl_fingerprint.cc", "ssl_fingerprint.h", "ssl_identity.cc", "ssl_identity.h", - "ssl_stream_adapter.cc", - "ssl_stream_adapter.h", ] deps = [ - ":async_socket", ":buffer", ":checks", ":copy_on_write_buffer", + ":digest", ":logging", ":macromagic", ":safe_conversions", - ":socket", - ":socket_address", - ":stream", + ":ssl_header", ":stringutils", - ":threading", ":timeutils", "../api:array_view", "../api:refcountedbase", "../api:scoped_refptr", - "../api/task_queue:pending_task_safety_flag", - "../api/units:time_delta", - "../system_wrappers:field_trial", - "synchronization:mutex", "system:rtc_export", - "task_utils:repeating_task", "third_party/base64", - "third_party/sigslot", - ] - - absl_deps = [ "//third_party/abseil-cpp/absl/algorithm:container", "//third_party/abseil-cpp/absl/base:core_headers", - "//third_party/abseil-cpp/absl/functional:any_invocable", "//third_party/abseil-cpp/absl/memory", - "//third_party/abseil-cpp/absl/strings", - "//third_party/abseil-cpp/absl/types:optional", + "//third_party/abseil-cpp/absl/strings:string_view", ] # If we are building the SSL library ourselves, we know it's BoringSSL. @@ -1566,7 +1557,10 @@ rtc_library("ssl") { "boringssl_identity.h", ] - deps += [ "//third_party/boringssl" ] + deps += [ + ":crypto_random", + "//third_party/boringssl", + ] } else { sources += [ "openssl_certificate.cc", @@ -1574,8 +1568,9 @@ rtc_library("ssl") { "openssl_identity.cc", "openssl_identity.h", ] + deps += [ ":crypto_random" ] - configs += [ ":external_ssl_library" ] + configs += [ "..:external_ssl_library" ] } if (build_with_chromium) { @@ -1589,29 +1584,54 @@ rtc_library("ssl") { } } -rtc_library("crypt_string") { +rtc_library("ssl_adapter") { + visibility = [ "*" ] sources = [ - "crypt_string.cc", - "crypt_string.h", + "openssl_adapter.cc", + "openssl_adapter.h", + "openssl_session_cache.cc", + "openssl_session_cache.h", + "openssl_stream_adapter.cc", + "openssl_stream_adapter.h", + "ssl_adapter.cc", + "ssl_adapter.h", + "ssl_stream_adapter.cc", + "ssl_stream_adapter.h", ] -} -rtc_library("http_common") { - sources = [ - "http_common.cc", - "http_common.h", - ] deps = [ - ":crypt_string", + ":async_socket", + ":buffer", + ":checks", + ":digest", ":logging", + ":safe_conversions", + ":socket", ":socket_address", ":ssl", + ":ssl_header", + ":stream", ":stringutils", - ":zero_memory", - "third_party/base64", + ":threading", + ":timeutils", + "../api:array_view", + "../api:sequence_checker", + "../api/task_queue:pending_task_safety_flag", + "../api/units:time_delta", + "../system_wrappers:field_trial", + "system:rtc_export", + "task_utils:repeating_task", + "//third_party/abseil-cpp/absl/functional:any_invocable", + "//third_party/abseil-cpp/absl/memory", + "//third_party/abseil-cpp/absl/strings", ] - absl_deps = [ "//third_party/abseil-cpp/absl/strings" ] + # If we are building the SSL library ourselves, we know it's BoringSSL. + if (rtc_build_ssl) { + deps += [ "//third_party/boringssl" ] + } else { + configs += [ "..:external_ssl_library" ] + } } rtc_source_set("gtest_prod") { @@ -1620,18 +1640,15 @@ rtc_source_set("gtest_prod") { rtc_library("gunit_helpers") { testonly = true - sources = [ - "gunit.cc", - "gunit.h", - ] + sources = [ "gunit.h" ] deps = [ ":logging", ":rtc_base_tests_utils", ":stringutils", ":threading", "../test:test_support", + "//third_party/abseil-cpp/absl/strings:string_view", ] - absl_deps = [ "//third_party/abseil-cpp/absl/strings" ] } rtc_library("testclient") { @@ -1642,10 +1659,13 @@ rtc_library("testclient") { ] deps = [ ":async_udp_socket", + ":buffer", ":gunit_helpers", ":rtc_base_tests_utils", ":threading", ":timeutils", + "../api/units:timestamp", + "network:received_packet", "synchronization:mutex", ] } @@ -1690,8 +1710,6 @@ rtc_library("rtc_base_tests_utils") { "server_socket_adapters.cc", "server_socket_adapters.h", "sigslot_tester.h", - "socket_stream.cc", - "socket_stream.h", "test_base64.h", "test_certificate_verifier.h", "test_echo_server.cc", @@ -1706,8 +1724,10 @@ rtc_library("rtc_base_tests_utils") { ":async_socket", ":async_tcp_socket", ":async_udp_socket", + ":buffer", ":byte_buffer", ":checks", + ":digest", ":ip_address", ":logging", ":macromagic", @@ -1725,23 +1745,23 @@ rtc_library("rtc_base_tests_utils") { ":stringutils", ":threading", ":timeutils", + "../api:array_view", "../api:make_ref_counted", "../api:refcountedbase", "../api:scoped_refptr", + "../api:sequence_checker", "../api/task_queue", "../api/units:time_delta", "../api/units:timestamp", "../test:scoped_key_value_config", "memory:always_valid_pointer", "memory:fifo_buffer", + "network:received_packet", "synchronization:mutex", "third_party/sigslot", - ] - absl_deps = [ "//third_party/abseil-cpp/absl/algorithm:container", "//third_party/abseil-cpp/absl/memory", - "//third_party/abseil-cpp/absl/strings", - "//third_party/abseil-cpp/absl/types:optional", + "//third_party/abseil-cpp/absl/strings:string_view", ] if (is_fuchsia) { deps += [ "//third_party/fuchsia-sdk/sdk/pkg/zx" ] @@ -1757,16 +1777,12 @@ rtc_library("task_queue_for_test") { ] deps = [ ":checks", - ":macromagic", ":rtc_event", - ":rtc_task_queue", "../api:function_view", "../api/task_queue", "../api/task_queue:default_task_queue_factory", - ] - absl_deps = [ "//third_party/abseil-cpp/absl/cleanup", - "//third_party/abseil-cpp/absl/strings", + "//third_party/abseil-cpp/absl/strings:string_view", ] } @@ -1840,6 +1856,7 @@ if (rtc_include_tests) { ":threading", ":timeutils", "../api/units:time_delta", + "../api/units:timestamp", "../system_wrappers", "../test:field_trial", "../test:fileutils", @@ -1847,10 +1864,8 @@ if (rtc_include_tests) { "../test:test_support", "third_party/sigslot", "//testing/gtest", - ] - absl_deps = [ "//third_party/abseil-cpp/absl/memory", - "//third_party/abseil-cpp/absl/strings", + "//third_party/abseil-cpp/absl/strings:string_view", ] } @@ -1891,6 +1906,7 @@ if (rtc_include_tests) { "string_encode_unittest.cc", "string_to_number_unittest.cc", "string_utils_unittest.cc", + "strings/str_join_unittest.cc", "strings/string_builder_unittest.cc", "strings/string_format_unittest.cc", "strong_alias_unittest.cc", @@ -1915,6 +1931,7 @@ if (rtc_include_tests) { ":checks", ":copy_on_write_buffer", ":criticalsection", + ":crypto_random", ":divide_round", ":event_tracer", ":frequency_tracker", @@ -1925,6 +1942,7 @@ if (rtc_include_tests) { ":macromagic", ":mod_ops", ":moving_max_counter", + ":net_helpers", ":null_socket_server", ":one_time_event", ":platform_thread", @@ -1936,7 +1954,6 @@ if (rtc_include_tests) { ":rtc_base_tests_utils", ":rtc_event", ":rtc_numerics", - ":rtc_task_queue", ":safe_compare", ":safe_minmax", ":sample_counter", @@ -1955,6 +1972,7 @@ if (rtc_include_tests) { ":zero_memory", "../api:array_view", "../api:make_ref_counted", + "../api:ref_count", "../api:scoped_refptr", "../api/numerics", "../api/units:data_rate", @@ -1969,17 +1987,15 @@ if (rtc_include_tests) { "containers:flat_map", "containers:unittests", "memory:unittests", + "network:received_packet", "synchronization:mutex", "task_utils:repeating_task", "third_party/base64", "third_party/sigslot", - ] - absl_deps = [ "//third_party/abseil-cpp/absl/base:core_headers", "//third_party/abseil-cpp/absl/memory", "//third_party/abseil-cpp/absl/numeric:bits", - "//third_party/abseil-cpp/absl/strings", - "//third_party/abseil-cpp/absl/types:optional", + "//third_party/abseil-cpp/absl/strings:string_view", ] if (is_win) { @@ -1995,14 +2011,13 @@ if (rtc_include_tests) { ":gunit_helpers", ":rtc_base_tests_utils", ":rtc_event", - ":rtc_task_queue", ":task_queue_for_test", ":timeutils", "../api/units:time_delta", "../test:test_main", "../test:test_support", + "//third_party/abseil-cpp/absl/memory", ] - absl_deps = [ "//third_party/abseil-cpp/absl/memory" ] } rtc_library("weak_ptr_unittests") { @@ -2034,12 +2049,13 @@ if (rtc_include_tests) { "numerics/sequence_number_util_unittest.cc", ] deps = [ + ":mod_ops", ":rtc_numerics", ":timeutils", "../test:test_main", "../test:test_support", + "//third_party/abseil-cpp/absl/algorithm:container", ] - absl_deps = [ "//third_party/abseil-cpp/absl/algorithm:container" ] } rtc_library("rtc_json_unittests") { @@ -2061,16 +2077,15 @@ if (rtc_include_tests) { sources = [ "crc32_unittest.cc", + "crypto_random_unittest.cc", "data_rate_limiter_unittest.cc", "fake_clock_unittest.cc", - "helpers_unittest.cc", "ip_address_unittest.cc", "memory_usage_unittest.cc", "message_digest_unittest.cc", "nat_unittest.cc", "network_route_unittest.cc", "network_unittest.cc", - "proxy_unittest.cc", "rolling_accumulator_unittest.cc", "rtc_certificate_generator_unittest.cc", "rtc_certificate_unittest.cc", @@ -2087,7 +2102,9 @@ if (rtc_include_tests) { ":buffer_queue", ":checks", ":crc32", + ":crypto_random", ":data_rate_limiter", + ":digest", ":gunit_helpers", ":ifaddrs_converter", ":ip_address", @@ -2110,6 +2127,8 @@ if (rtc_include_tests) { ":socket_factory", ":socket_server", ":ssl", + ":ssl_adapter", + ":ssl_header", ":stream", ":stringutils", ":testclient", @@ -2119,6 +2138,7 @@ if (rtc_include_tests) { "../api:array_view", "../api:field_trials_view", "../api:make_ref_counted", + "../api:sequence_checker", "../api/task_queue", "../api/task_queue:pending_task_safety_flag", "../api/task_queue:task_queue_test", @@ -2130,8 +2150,15 @@ if (rtc_include_tests) { "../test:test_main", "../test:test_support", "memory:fifo_buffer", + "network:received_packet", "synchronization:mutex", "third_party/sigslot", + "//testing/gtest", + "//third_party/abseil-cpp/absl/algorithm:container", + "//third_party/abseil-cpp/absl/functional:any_invocable", + "//third_party/abseil-cpp/absl/memory", + "//third_party/abseil-cpp/absl/strings", + "//third_party/abseil-cpp/absl/strings:string_view", ] if (rtc_enable_google_benchmarks) { deps += [ "synchronization:synchronization_unittests" ] @@ -2149,14 +2176,8 @@ if (rtc_include_tests) { "ssl_identity_unittest.cc", "ssl_stream_adapter_unittest.cc", ] + deps += [ ":callback_list" ] } - absl_deps = [ - "//third_party/abseil-cpp/absl/algorithm:container", - "//third_party/abseil-cpp/absl/functional:any_invocable", - "//third_party/abseil-cpp/absl/memory", - "//third_party/abseil-cpp/absl/strings", - "//third_party/abseil-cpp/absl/types:optional", - ] if (build_with_chromium) { include_dirs = [ "../../boringssl/src/include" ] @@ -2164,7 +2185,7 @@ if (rtc_include_tests) { if (rtc_build_ssl) { deps += [ "//third_party/boringssl" ] } else { - configs += [ ":external_ssl_library" ] + configs += [ "..:external_ssl_library" ] } } } diff --git a/webrtc/rtc_base/checks.h b/webrtc/rtc_base/checks.h index 99fee97..5842d58 100644 --- a/webrtc/rtc_base/checks.h +++ b/webrtc/rtc_base/checks.h @@ -55,11 +55,14 @@ RTC_NORETURN void rtc_FatalMessage(const char* file, int line, const char* msg); #include #include "absl/meta/type_traits.h" +#include "absl/strings/has_absl_stringify.h" +#include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" #include "api/scoped_refptr.h" #include "rtc_base/numerics/safe_compare.h" #include "rtc_base/system/inline.h" #include "rtc_base/system/rtc_export.h" +#include "rtc_base/type_traits.h" // The macros here print a message to stderr and abort under various // conditions. All will accept additional stream messages. For example: @@ -215,9 +218,10 @@ inline decltype(MakeVal(std::declval>())) MakeVal( return {static_cast>(x)}; } -template ()))* = nullptr> +template ::value>* = nullptr> ToStringVal MakeVal(const T& x) { - return {ToLogString(x)}; + return {absl::StrCat(x)}; } // Ephemeral type that represents the result of the logging << operator. diff --git a/webrtc/rtc_base/containers/BUILD.gn b/webrtc/rtc_base/containers/BUILD.gn index 621b612..a2a2115 100644 --- a/webrtc/rtc_base/containers/BUILD.gn +++ b/webrtc/rtc_base/containers/BUILD.gn @@ -19,8 +19,8 @@ rtc_library("flat_containers_internal") { deps = [ "..:checks", "../system:no_unique_address", + "//third_party/abseil-cpp/absl/algorithm:container", ] - absl_deps = [ "//third_party/abseil-cpp/absl/algorithm:container" ] visibility = [ ":*" ] } @@ -52,5 +52,4 @@ rtc_library("unittests") { "//testing/gmock:gmock", "//testing/gtest:gtest", ] - absl_deps = [ "//third_party/abseil-cpp/absl/algorithm:container" ] } diff --git a/webrtc/rtc_base/event.cc b/webrtc/rtc_base/event.cc index c2f6f8a..37d3f63 100644 --- a/webrtc/rtc_base/event.cc +++ b/webrtc/rtc_base/event.cc @@ -21,7 +21,8 @@ #error "Must define either WEBRTC_WIN or WEBRTC_POSIX." #endif -#include "absl/types/optional.h" +#include + #include "rtc_base/checks.h" #include "rtc_base/synchronization/yield_policy.h" #include "rtc_base/system/warn_current_thread_is_deadlocked.h" @@ -148,27 +149,26 @@ bool Event::Wait(TimeDelta give_up_after, TimeDelta warn_after) { // Instant when we'll log a warning message (because we've been waiting so // long it might be a bug), but not yet give up waiting. nullopt if we // shouldn't log a warning. - const absl::optional warn_ts = - warn_after >= give_up_after - ? absl::nullopt - : absl::make_optional(GetTimespec(warn_after)); + const std::optional warn_ts = + warn_after >= give_up_after ? std::nullopt + : std::make_optional(GetTimespec(warn_after)); // Instant when we'll stop waiting and return an error. nullopt if we should // never give up. - const absl::optional give_up_ts = + const std::optional give_up_ts = give_up_after.IsPlusInfinity() - ? absl::nullopt - : absl::make_optional(GetTimespec(give_up_after)); + ? std::nullopt + : std::make_optional(GetTimespec(give_up_after)); ScopedYieldPolicy::YieldExecution(); pthread_mutex_lock(&event_mutex_); // Wait for `event_cond_` to trigger and `event_status_` to be set, with the // given timeout (or without a timeout if none is given). - const auto wait = [&](const absl::optional timeout_ts) { + const auto wait = [&](const std::optional timeout_ts) { int error = 0; while (!event_status_ && error == 0) { - if (timeout_ts == absl::nullopt) { + if (timeout_ts == std::nullopt) { error = pthread_cond_wait(&event_cond_, &event_mutex_); } else { #if USE_PTHREAD_COND_TIMEDWAIT_MONOTONIC_NP @@ -184,7 +184,7 @@ bool Event::Wait(TimeDelta give_up_after, TimeDelta warn_after) { }; int error; - if (warn_ts == absl::nullopt) { + if (warn_ts == std::nullopt) { error = wait(give_up_ts); } else { error = wait(warn_ts); diff --git a/webrtc/rtc_base/event.h b/webrtc/rtc_base/event.h index 12f6a7d..78b3c16 100644 --- a/webrtc/rtc_base/event.h +++ b/webrtc/rtc_base/event.h @@ -58,6 +58,8 @@ class Event { // TODO(bugs.webrtc.org/14366): Consider removing this redundant alias. static constexpr webrtc::TimeDelta kForever = webrtc::TimeDelta::PlusInfinity(); + static constexpr webrtc::TimeDelta kDefaultWarnDuration = + webrtc::TimeDelta::Seconds(3); Event(); Event(bool manual_reset, bool initially_signaled); @@ -83,7 +85,7 @@ class Event { // Waits with the given timeout and a reasonable default warning timeout. bool Wait(webrtc::TimeDelta give_up_after) { return Wait(give_up_after, give_up_after.IsPlusInfinity() - ? webrtc::TimeDelta::Seconds(3) + ? kDefaultWarnDuration : kForever); } diff --git a/webrtc/rtc_base/event_tracer.cc b/webrtc/rtc_base/event_tracer.cc index 992a2b5..fcd2055 100644 --- a/webrtc/rtc_base/event_tracer.cc +++ b/webrtc/rtc_base/event_tracer.cc @@ -7,11 +7,19 @@ * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ + #include "rtc_base/event_tracer.h" +#include + +#include "rtc_base/trace_event.h" + +#if defined(RTC_USE_PERFETTO) +#include "rtc_base/trace_categories.h" +#include "third_party/perfetto/include/perfetto/tracing/tracing.h" +#else #include #include -#include #include #include @@ -28,21 +36,27 @@ #include "rtc_base/synchronization/mutex.h" #include "rtc_base/thread_annotations.h" #include "rtc_base/time_utils.h" -#include "rtc_base/trace_event.h" - -// This is a guesstimate that should be enough in most cases. -static const size_t kEventLoggerArgsStrBufferInitialSize = 256; -static const size_t kTraceArgBufferLength = 32; +#endif namespace webrtc { namespace { +#if !defined(RTC_USE_PERFETTO) GetCategoryEnabledPtr g_get_category_enabled_ptr = nullptr; AddTraceEventPtr g_add_trace_event_ptr = nullptr; +#endif } // namespace +#if defined(RTC_USE_PERFETTO) +void RegisterPerfettoTrackEvents() { + if (perfetto::Tracing::IsInitialized()) { + webrtc::TrackEvent::Register(); + } +} +#else + void SetupEventTracer(GetCategoryEnabledPtr get_category_enabled_ptr, AddTraceEventPtr add_trace_event_ptr) { g_get_category_enabled_ptr = get_category_enabled_ptr; @@ -73,9 +87,28 @@ void EventTracer::AddTraceEvent(char phase, arg_names, arg_types, arg_values, flags); } } +#endif } // namespace webrtc +#if defined(RTC_USE_PERFETTO) +// TODO(bugs.webrtc.org/15917): Implement for perfetto. +namespace rtc::tracing { +void SetupInternalTracer(bool enable_all_categories) {} +bool StartInternalCapture(absl::string_view filename) { + return false; +} +void StartInternalCaptureToFile(FILE* file) {} +void StopInternalCapture() {} +void ShutdownInternalTracer() {} + +} // namespace rtc::tracing +#else + +// This is a guesstimate that should be enough in most cases. +static const size_t kEventLoggerArgsStrBufferInitialSize = 256; +static const size_t kTraceArgBufferLength = 32; + namespace rtc { namespace tracing { namespace { @@ -96,7 +129,7 @@ class EventLogger final { const unsigned char* arg_types, const unsigned long long* arg_values, uint64_t timestamp, - int pid, + int /* pid */, rtc::PlatformThreadId thread_id) { std::vector args(num_args); for (int i = 0; i < num_args; ++i) { @@ -206,12 +239,14 @@ class EventLogger final { // Finally start, everything should be set up now. logging_thread_ = PlatformThread::SpawnJoinable([this] { Log(); }, "EventTracingThread"); - TRACE_EVENT_INSTANT0("webrtc", "EventLogger::Start"); + TRACE_EVENT_INSTANT0("webrtc", "EventLogger::Start", + TRACE_EVENT_SCOPE_GLOBAL); } void Stop() { RTC_DCHECK(thread_checker_.IsCurrent()); - TRACE_EVENT_INSTANT0("webrtc", "EventLogger::Stop"); + TRACE_EVENT_INSTANT0("webrtc", "EventLogger::Stop", + TRACE_EVENT_SCOPE_GLOBAL); // Try to stop. Abort if we're not currently logging. int one = 1; if (g_event_logging_active.compare_exchange_strong(one, 0)) @@ -344,12 +379,12 @@ const unsigned char* InternalEnableAllCategories(const char* name) { void InternalAddTraceEvent(char phase, const unsigned char* category_enabled, const char* name, - unsigned long long id, + unsigned long long /* id */, int num_args, const char** arg_names, const unsigned char* arg_types, const unsigned long long* arg_values, - unsigned char flags) { + unsigned char /* flags */) { // Fast path for when event tracing is inactive. if (g_event_logging_active.load() == 0) return; @@ -410,3 +445,5 @@ void ShutdownInternalTracer() { } // namespace tracing } // namespace rtc + +#endif // defined(RTC_USE_PERFETTO) diff --git a/webrtc/rtc_base/event_tracer.h b/webrtc/rtc_base/event_tracer.h index dc2eaed..7f8d3e6 100644 --- a/webrtc/rtc_base/event_tracer.h +++ b/webrtc/rtc_base/event_tracer.h @@ -8,6 +8,9 @@ * be found in the AUTHORS file in the root of the source tree. */ +#ifndef RTC_BASE_EVENT_TRACER_H_ +#define RTC_BASE_EVENT_TRACER_H_ + // This file defines the interface for event tracing in WebRTC. // // Event log handlers are set through SetupEventTracer(). User of this API will @@ -23,9 +26,6 @@ // // Parameters for the above two functions are described in trace_event.h. -#ifndef RTC_BASE_EVENT_TRACER_H_ -#define RTC_BASE_EVENT_TRACER_H_ - #include #include "absl/strings/string_view.h" @@ -33,6 +33,9 @@ namespace webrtc { +#if defined(RTC_USE_PERFETTO) +void RegisterPerfettoTrackEvents(); +#else typedef const unsigned char* (*GetCategoryEnabledPtr)(const char* name); typedef void (*AddTraceEventPtr)(char phase, const unsigned char* category_enabled, @@ -67,19 +70,19 @@ class EventTracer { const unsigned long long* arg_values, unsigned char flags); }; +#endif } // namespace webrtc -namespace rtc { -namespace tracing { +namespace rtc::tracing { // Set up internal event tracer. +// TODO(webrtc:15917): Implement for perfetto. RTC_EXPORT void SetupInternalTracer(bool enable_all_categories = true); RTC_EXPORT bool StartInternalCapture(absl::string_view filename); RTC_EXPORT void StartInternalCaptureToFile(FILE* file); RTC_EXPORT void StopInternalCapture(); // Make sure we run this, this will tear down the internal tracing. RTC_EXPORT void ShutdownInternalTracer(); -} // namespace tracing -} // namespace rtc +} // namespace rtc::tracing #endif // RTC_BASE_EVENT_TRACER_H_ diff --git a/webrtc/rtc_base/experiments/field_trial_parser.cc b/webrtc/rtc_base/experiments/field_trial_parser.cc index 78d5489..d27fbba 100644 --- a/webrtc/rtc_base/experiments/field_trial_parser.cc +++ b/webrtc/rtc_base/experiments/field_trial_parser.cc @@ -60,7 +60,7 @@ void ParseFieldTrial( while (!tail.empty()) { size_t key_end = tail.find_first_of(",:"); absl::string_view key = tail.substr(0, key_end); - absl::optional opt_value; + std::optional opt_value; if (key_end == absl::string_view::npos) { tail = ""; } else if (tail[key_end] == ':') { @@ -112,17 +112,17 @@ void ParseFieldTrial( } template <> -absl::optional ParseTypedParameter(absl::string_view str) { +std::optional ParseTypedParameter(absl::string_view str) { if (str == "true" || str == "1") { return true; } else if (str == "false" || str == "0") { return false; } - return absl::nullopt; + return std::nullopt; } template <> -absl::optional ParseTypedParameter(absl::string_view str) { +std::optional ParseTypedParameter(absl::string_view str) { double value; char unit[2]{0, 0}; if (sscanf(std::string(str).c_str(), "%lf%1s", &value, unit) >= 1) { @@ -130,56 +130,56 @@ absl::optional ParseTypedParameter(absl::string_view str) { return value / 100; return value; } else { - return absl::nullopt; + return std::nullopt; } } template <> -absl::optional ParseTypedParameter(absl::string_view str) { +std::optional ParseTypedParameter(absl::string_view str) { int64_t value; if (sscanf(std::string(str).c_str(), "%" SCNd64, &value) == 1) { if (rtc::IsValueInRangeForNumericType(value)) { return static_cast(value); } } - return absl::nullopt; + return std::nullopt; } template <> -absl::optional ParseTypedParameter(absl::string_view str) { +std::optional ParseTypedParameter(absl::string_view str) { int64_t value; if (sscanf(std::string(str).c_str(), "%" SCNd64, &value) == 1) { if (rtc::IsValueInRangeForNumericType(value)) { return static_cast(value); } } - return absl::nullopt; + return std::nullopt; } template <> -absl::optional ParseTypedParameter( +std::optional ParseTypedParameter( absl::string_view str) { return std::string(str); } template <> -absl::optional> ParseTypedParameter>( +std::optional> ParseTypedParameter>( absl::string_view str) { return ParseOptionalParameter(str); } template <> -absl::optional> ParseTypedParameter>( +std::optional> ParseTypedParameter>( absl::string_view str) { return ParseOptionalParameter(str); } template <> -absl::optional> -ParseTypedParameter>(absl::string_view str) { +std::optional> +ParseTypedParameter>(absl::string_view str) { return ParseOptionalParameter(str); } template <> -absl::optional> -ParseTypedParameter>(absl::string_view str) { +std::optional> ParseTypedParameter>( + absl::string_view str) { return ParseOptionalParameter(str); } @@ -197,10 +197,10 @@ webrtc::FieldTrialFlag::operator bool() const { return value_; } -bool FieldTrialFlag::Parse(absl::optional str_value) { +bool FieldTrialFlag::Parse(std::optional str_value) { // Only set the flag if there is no argument provided. if (str_value) { - absl::optional opt_value = ParseTypedParameter(*str_value); + std::optional opt_value = ParseTypedParameter(*str_value); if (!opt_value) return false; value_ = *opt_value; @@ -224,14 +224,14 @@ AbstractFieldTrialEnum::AbstractFieldTrialEnum(const AbstractFieldTrialEnum&) = default; AbstractFieldTrialEnum::~AbstractFieldTrialEnum() = default; -bool AbstractFieldTrialEnum::Parse(absl::optional str_value) { +bool AbstractFieldTrialEnum::Parse(std::optional str_value) { if (str_value) { auto it = enum_mapping_.find(*str_value); if (it != enum_mapping_.end()) { value_ = it->second; return true; } - absl::optional value = ParseTypedParameter(*str_value); + std::optional value = ParseTypedParameter(*str_value); if (value.has_value() && (valid_values_.find(*value) != valid_values_.end())) { value_ = *value; diff --git a/webrtc/rtc_base/experiments/field_trial_parser.h b/webrtc/rtc_base/experiments/field_trial_parser.h index 822895e..890da80 100644 --- a/webrtc/rtc_base/experiments/field_trial_parser.h +++ b/webrtc/rtc_base/experiments/field_trial_parser.h @@ -14,12 +14,12 @@ #include #include +#include #include #include #include #include "absl/strings/string_view.h" -#include "absl/types/optional.h" // Field trial parser functionality. Provides funcitonality to parse field trial // argument strings in key:value format. Each parameter is described using @@ -51,7 +51,7 @@ class FieldTrialParameterInterface { std::initializer_list fields, absl::string_view trial_string); void MarkAsUsed() { used_ = true; } - virtual bool Parse(absl::optional str_value) = 0; + virtual bool Parse(std::optional str_value) = 0; virtual void ParseDone() {} @@ -68,10 +68,10 @@ void ParseFieldTrial( std::initializer_list fields, absl::string_view trial_string); -// Specialize this in code file for custom types. Should return absl::nullopt if +// Specialize this in code file for custom types. Should return std::nullopt if // the given string cannot be properly parsed. template -absl::optional ParseTypedParameter(absl::string_view); +std::optional ParseTypedParameter(absl::string_view); // This class uses the ParseTypedParameter function to implement a parameter // implementation with an enforced default value. @@ -87,9 +87,9 @@ class FieldTrialParameter : public FieldTrialParameterInterface { void SetForTest(T value) { value_ = value; } protected: - bool Parse(absl::optional str_value) override { + bool Parse(std::optional str_value) override { if (str_value) { - absl::optional value = ParseTypedParameter(*str_value); + std::optional value = ParseTypedParameter(*str_value); if (value.has_value()) { value_ = value.value(); return true; @@ -110,8 +110,8 @@ class FieldTrialConstrained : public FieldTrialParameterInterface { public: FieldTrialConstrained(absl::string_view key, T default_value, - absl::optional lower_limit, - absl::optional upper_limit) + std::optional lower_limit, + std::optional upper_limit) : FieldTrialParameterInterface(key), value_(default_value), lower_limit_(lower_limit), @@ -121,9 +121,9 @@ class FieldTrialConstrained : public FieldTrialParameterInterface { const T* operator->() const { return &value_; } protected: - bool Parse(absl::optional str_value) override { + bool Parse(std::optional str_value) override { if (str_value) { - absl::optional value = ParseTypedParameter(*str_value); + std::optional value = ParseTypedParameter(*str_value); if (value && (!lower_limit_ || *value >= *lower_limit_) && (!upper_limit_ || *value <= *upper_limit_)) { value_ = *value; @@ -135,8 +135,8 @@ class FieldTrialConstrained : public FieldTrialParameterInterface { private: T value_; - absl::optional lower_limit_; - absl::optional upper_limit_; + std::optional lower_limit_; + std::optional upper_limit_; }; class AbstractFieldTrialEnum : public FieldTrialParameterInterface { @@ -148,7 +148,7 @@ class AbstractFieldTrialEnum : public FieldTrialParameterInterface { AbstractFieldTrialEnum(const AbstractFieldTrialEnum&); protected: - bool Parse(absl::optional str_value) override; + bool Parse(std::optional str_value) override; protected: int value_; @@ -181,35 +181,35 @@ class FieldTrialEnum : public AbstractFieldTrialEnum { }; // This class uses the ParseTypedParameter function to implement an optional -// parameter implementation that can default to absl::nullopt. +// parameter implementation that can default to std::nullopt. template class FieldTrialOptional : public FieldTrialParameterInterface { public: explicit FieldTrialOptional(absl::string_view key) : FieldTrialParameterInterface(key) {} - FieldTrialOptional(absl::string_view key, absl::optional default_value) + FieldTrialOptional(absl::string_view key, std::optional default_value) : FieldTrialParameterInterface(key), value_(default_value) {} - absl::optional GetOptional() const { return value_; } + std::optional GetOptional() const { return value_; } const T& Value() const { return value_.value(); } const T& operator*() const { return value_.value(); } const T* operator->() const { return &value_.value(); } explicit operator bool() const { return value_.has_value(); } protected: - bool Parse(absl::optional str_value) override { + bool Parse(std::optional str_value) override { if (str_value) { - absl::optional value = ParseTypedParameter(*str_value); + std::optional value = ParseTypedParameter(*str_value); if (!value.has_value()) return false; value_ = value.value(); } else { - value_ = absl::nullopt; + value_ = std::nullopt; } return true; } private: - absl::optional value_; + std::optional value_; }; // Equivalent to a FieldTrialParameter in the case that both key and value @@ -223,47 +223,46 @@ class FieldTrialFlag : public FieldTrialParameterInterface { explicit operator bool() const; protected: - bool Parse(absl::optional str_value) override; + bool Parse(std::optional str_value) override; private: bool value_; }; template -absl::optional> ParseOptionalParameter( - absl::string_view str) { +std::optional> ParseOptionalParameter(absl::string_view str) { if (str.empty()) - return absl::optional(); + return std::optional(); auto parsed = ParseTypedParameter(str); if (parsed.has_value()) return parsed; - return absl::nullopt; + return std::nullopt; } template <> -absl::optional ParseTypedParameter(absl::string_view str); +std::optional ParseTypedParameter(absl::string_view str); template <> -absl::optional ParseTypedParameter(absl::string_view str); +std::optional ParseTypedParameter(absl::string_view str); template <> -absl::optional ParseTypedParameter(absl::string_view str); +std::optional ParseTypedParameter(absl::string_view str); template <> -absl::optional ParseTypedParameter(absl::string_view str); +std::optional ParseTypedParameter(absl::string_view str); template <> -absl::optional ParseTypedParameter( +std::optional ParseTypedParameter( absl::string_view str); template <> -absl::optional> ParseTypedParameter>( +std::optional> ParseTypedParameter>( absl::string_view str); template <> -absl::optional> ParseTypedParameter>( +std::optional> ParseTypedParameter>( absl::string_view str); template <> -absl::optional> -ParseTypedParameter>(absl::string_view str); +std::optional> +ParseTypedParameter>(absl::string_view str); template <> -absl::optional> -ParseTypedParameter>(absl::string_view str); +std::optional> ParseTypedParameter>( + absl::string_view str); // Accepts true, false, else parsed with sscanf %i, true if != 0. extern template class FieldTrialParameter; diff --git a/webrtc/rtc_base/logging.h b/webrtc/rtc_base/logging.h index b171cfe..2a8f9ba 100644 --- a/webrtc/rtc_base/logging.h +++ b/webrtc/rtc_base/logging.h @@ -21,7 +21,7 @@ // RTC_LOG(sev) logs the given stream at severity "sev", which must be a // compile-time constant of the LoggingSeverity type, without the namespace // prefix. -// RTC_LOG_IF(sev, condition) logs the given stream at severitye "sev" if +// RTC_LOG_IF(sev, condition) logs the given stream at severity "sev" if // "condition" is true. // RTC_LOG_V(sev) Like RTC_LOG(), but sev is a run-time variable of the // LoggingSeverity type (basically, it just doesn't prepend the namespace). @@ -51,6 +51,7 @@ #include #include +#include #include // no-presubmit-check TODO(webrtc:8982) #include #include @@ -58,12 +59,14 @@ #include "absl/base/attributes.h" #include "absl/meta/type_traits.h" +#include "absl/strings/has_absl_stringify.h" +#include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" -#include "absl/types/optional.h" #include "api/units/timestamp.h" #include "rtc_base/platform_thread_types.h" #include "rtc_base/strings/string_builder.h" #include "rtc_base/system/inline.h" +#include "rtc_base/type_traits.h" #if !defined(NDEBUG) || defined(DLOG_ALWAYS_ON) #define RTC_DLOG_IS_ON 1 @@ -118,7 +121,7 @@ class LogLineRef { absl::string_view message() const { return message_; } absl::string_view filename() const { return filename_; } int line() const { return line_; } - absl::optional thread_id() const { return thread_id_; } + std::optional thread_id() const { return thread_id_; } webrtc::Timestamp timestamp() const { return timestamp_; } absl::string_view tag() const { return tag_; } LoggingSeverity severity() const { return severity_; } @@ -134,7 +137,7 @@ class LogLineRef { void set_message(std::string message) { message_ = std::move(message); } void set_filename(absl::string_view filename) { filename_ = filename; } void set_line(int line) { line_ = line; } - void set_thread_id(absl::optional thread_id) { + void set_thread_id(std::optional thread_id) { thread_id_ = thread_id; } void set_timestamp(webrtc::Timestamp timestamp) { timestamp_ = timestamp; } @@ -144,7 +147,7 @@ class LogLineRef { std::string message_; absl::string_view filename_; int line_ = 0; - absl::optional thread_id_; + std::optional thread_id_; webrtc::Timestamp timestamp_ = webrtc::Timestamp::MinusInfinity(); // The default Android debug output tag. absl::string_view tag_ = "libjingle"; @@ -282,6 +285,7 @@ inline Val MakeVal( inline Val MakeVal(double x) { return {x}; } + inline Val MakeVal(long double x) { return {x}; } @@ -327,33 +331,25 @@ inline Val MakeVal( } #endif -template -struct has_to_log_string : std::false_type {}; -template -struct has_to_log_string())), - std::string>::value>> : std::true_type {}; - -template ::value>* = nullptr> +template ::value>* = nullptr> ToStringVal MakeVal(const T& x) { - return {ToLogString(x)}; + return {absl::StrCat(x)}; } // Handle arbitrary types other than the above by falling back to stringstream. // TODO(bugs.webrtc.org/9278): Get rid of this overload when callers don't need // it anymore. No in-tree caller does, but some external callers still do. -template < - typename T, - typename T1 = absl::decay_t, - absl::enable_if_t::value && - !std::is_same::value && - !std::is_same::value && - !has_to_log_string::value && +template , + std::enable_if_t::value && // + !std::is_same::value && // + !std::is_same::value && // + !absl::HasAbslStringify::value && #ifdef WEBRTC_ANDROID - !std::is_same::value && + !std::is_same::value && // #endif - !std::is_same::value>* = nullptr> + !std::is_same::value>* = nullptr> ToStringVal MakeVal(const T& x) { std::ostringstream os; // no-presubmit-check TODO(webrtc:8982) os << x; @@ -376,18 +372,7 @@ class LogStreamer; template <> class LogStreamer<> final { public: - template ())), - absl::enable_if_t::value || - std::is_enum::value>* = nullptr> - RTC_FORCE_INLINE LogStreamer operator<<(U arg) const { - return LogStreamer(MakeVal(arg), this); - } - - template ())), - absl::enable_if_t::value && - !std::is_enum::value>* = nullptr> + template ()))> RTC_FORCE_INLINE LogStreamer operator<<(const U& arg) const { return LogStreamer(MakeVal(arg), this); } @@ -407,18 +392,7 @@ class LogStreamer final { RTC_FORCE_INLINE LogStreamer(T arg, const LogStreamer* prior) : arg_(arg), prior_(prior) {} - template ())), - absl::enable_if_t::value || - std::is_enum::value>* = nullptr> - RTC_FORCE_INLINE LogStreamer operator<<(U arg) const { - return LogStreamer(MakeVal(arg), this); - } - - template ())), - absl::enable_if_t::value && - !std::is_enum::value>* = nullptr> + template ()))> RTC_FORCE_INLINE LogStreamer operator<<(const U& arg) const { return LogStreamer(MakeVal(arg), this); } diff --git a/webrtc/rtc_base/memory/BUILD.gn b/webrtc/rtc_base/memory/BUILD.gn index ee3baa4..0037851 100644 --- a/webrtc/rtc_base/memory/BUILD.gn +++ b/webrtc/rtc_base/memory/BUILD.gn @@ -33,10 +33,12 @@ rtc_library("fifo_buffer") { "fifo_buffer.h", ] deps = [ + "..:macromagic", "..:stream", "..:threading", + "../../api:array_view", + "../../api:sequence_checker", "../../api/task_queue:pending_task_safety_flag", - "../synchronization:mutex", ] } diff --git a/webrtc/rtc_base/numerics/safe_compare.h b/webrtc/rtc_base/numerics/safe_compare.h index 85f0a30..d3d918d 100644 --- a/webrtc/rtc_base/numerics/safe_compare.h +++ b/webrtc/rtc_base/numerics/safe_compare.h @@ -35,7 +35,6 @@ #include #include -#include #include "rtc_base/type_traits.h" diff --git a/webrtc/rtc_base/numerics/safe_minmax.h b/webrtc/rtc_base/numerics/safe_minmax.h index 8356536..cdb6da2 100644 --- a/webrtc/rtc_base/numerics/safe_minmax.h +++ b/webrtc/rtc_base/numerics/safe_minmax.h @@ -76,6 +76,7 @@ #ifndef RTC_BASE_NUMERICS_SAFE_MINMAX_H_ #define RTC_BASE_NUMERICS_SAFE_MINMAX_H_ +#include #include #include diff --git a/webrtc/rtc_base/platform_thread.cc b/webrtc/rtc_base/platform_thread.cc index 6d369d7..6af1f3f 100644 --- a/webrtc/rtc_base/platform_thread.cc +++ b/webrtc/rtc_base/platform_thread.cc @@ -41,8 +41,10 @@ bool SetPriority(ThreadPriority priority) { #if defined(WEBRTC_WIN) return SetThreadPriority(GetCurrentThread(), Win32PriorityFromThreadPriority(priority)) != FALSE; -#elif defined(__native_client__) || defined(WEBRTC_FUCHSIA) - // Setting thread priorities is not supported in NaCl or Fuchsia. +#elif defined(__native_client__) || defined(WEBRTC_FUCHSIA) || \ + (defined(__EMSCRIPTEN__) && !defined(__EMSCRIPTEN_PTHREADS__)) + // Setting thread priorities is not supported in NaCl, Fuchsia or Emscripten + // without pthreads. return true; #elif defined(WEBRTC_CHROMIUM_BUILD) && defined(WEBRTC_LINUX) // TODO(tommi): Switch to the same mechanism as Chromium uses for changing @@ -111,14 +113,14 @@ PlatformThread::PlatformThread(Handle handle, bool joinable) PlatformThread::PlatformThread(PlatformThread&& rhs) : handle_(rhs.handle_), joinable_(rhs.joinable_) { - rhs.handle_ = absl::nullopt; + rhs.handle_ = std::nullopt; } PlatformThread& PlatformThread::operator=(PlatformThread&& rhs) { Finalize(); handle_ = rhs.handle_; joinable_ = rhs.joinable_; - rhs.handle_ = absl::nullopt; + rhs.handle_ = std::nullopt; return *this; } @@ -142,7 +144,7 @@ PlatformThread PlatformThread::SpawnDetached( /*joinable=*/false); } -absl::optional PlatformThread::GetHandle() const { +std::optional PlatformThread::GetHandle() const { return handle_; } @@ -165,7 +167,7 @@ void PlatformThread::Finalize() { if (joinable_) RTC_CHECK_EQ(0, pthread_join(*handle_, nullptr)); #endif - handle_ = absl::nullopt; + handle_ = std::nullopt; } PlatformThread PlatformThread::SpawnThread( diff --git a/webrtc/rtc_base/platform_thread.h b/webrtc/rtc_base/platform_thread.h index befd618..cfc9d17 100644 --- a/webrtc/rtc_base/platform_thread.h +++ b/webrtc/rtc_base/platform_thread.h @@ -17,8 +17,9 @@ #include #endif +#include + #include "absl/strings/string_view.h" -#include "absl/types/optional.h" #include "rtc_base/platform_thread_types.h" namespace rtc { @@ -97,7 +98,7 @@ class PlatformThread final { ThreadAttributes attributes = ThreadAttributes()); // Returns the base platform thread handle of this thread. - absl::optional GetHandle() const; + std::optional GetHandle() const; #if defined(WEBRTC_WIN) // Queue a Windows APC function that runs when the thread is alertable. @@ -111,7 +112,7 @@ class PlatformThread final { ThreadAttributes attributes, bool joinable); - absl::optional handle_; + std::optional handle_; bool joinable_ = false; }; diff --git a/webrtc/rtc_base/race_checker.h b/webrtc/rtc_base/race_checker.h index 4d57460..00bab52 100644 --- a/webrtc/rtc_base/race_checker.h +++ b/webrtc/rtc_base/race_checker.h @@ -62,9 +62,14 @@ class RTC_SCOPED_LOCKABLE RaceCheckerScopeDoNothing { } // namespace internal } // namespace rtc -#define RTC_CHECK_RUNS_SERIALIZED(x) \ - rtc::internal::RaceCheckerScope race_checker(x); \ - RTC_CHECK(!race_checker.RaceDetected()) +#define RTC_CHECK_RUNS_SERIALIZED(x) RTC_CHECK_RUNS_SERIALIZED_NEXT(x, __LINE__) + +#define RTC_CHECK_RUNS_SERIALIZED_NEXT(x, suffix) \ + RTC_CHECK_RUNS_SERIALIZED_IMPL(x, suffix) + +#define RTC_CHECK_RUNS_SERIALIZED_IMPL(x, suffix) \ + rtc::internal::RaceCheckerScope race_checker##suffix(x); \ + RTC_CHECK(!race_checker##suffix.RaceDetected()) #if RTC_DCHECK_IS_ON #define RTC_DCHECK_RUNS_SERIALIZED(x) \ diff --git a/webrtc/rtc_base/ref_count.h b/webrtc/rtc_base/ref_count.h index d8d652a..45940e2 100644 --- a/webrtc/rtc_base/ref_count.h +++ b/webrtc/rtc_base/ref_count.h @@ -10,57 +10,19 @@ #ifndef RTC_BASE_REF_COUNT_H_ #define RTC_BASE_REF_COUNT_H_ +// Transition file for backwards compatibility with source code +// that includes the non-API file. + +#include "api/ref_count.h" + namespace rtc { -// Refcounted objects should implement the following informal interface: -// -// void AddRef() const ; -// RefCountReleaseStatus Release() const; -// -// You may access members of a reference-counted object, including the AddRef() -// and Release() methods, only if you already own a reference to it, or if -// you're borrowing someone else's reference. (A newly created object is a -// special case: the reference count is zero on construction, and the code that -// creates the object should immediately call AddRef(), bringing the reference -// count from zero to one, e.g., by constructing an rtc::scoped_refptr). -// -// AddRef() creates a new reference to the object. -// -// Release() releases a reference to the object; the caller now has one less -// reference than before the call. Returns kDroppedLastRef if the number of -// references dropped to zero because of this (in which case the object destroys -// itself). Otherwise, returns kOtherRefsRemained, to signal that at the precise -// time the caller's reference was dropped, other references still remained (but -// if other threads own references, this may of course have changed by the time -// Release() returns). -// -// The caller of Release() must treat it in the same way as a delete operation: -// Regardless of the return value from Release(), the caller mustn't access the -// object. The object might still be alive, due to references held by other -// users of the object, but the object can go away at any time, e.g., as the -// result of another thread calling Release(). -// -// Calling AddRef() and Release() manually is discouraged. It's recommended to -// use rtc::scoped_refptr to manage all pointers to reference counted objects. -// Note that rtc::scoped_refptr depends on compile-time duck-typing; formally -// implementing the below RefCountInterface is not required. - -enum class RefCountReleaseStatus { kDroppedLastRef, kOtherRefsRemained }; - -// Interfaces where refcounting is part of the public api should -// inherit this abstract interface. The implementation of these -// methods is usually provided by the RefCountedObject template class, -// applied as a leaf in the inheritance tree. -class RefCountInterface { - public: - virtual void AddRef() const = 0; - virtual RefCountReleaseStatus Release() const = 0; - - // Non-public destructor, because Release() has exclusive responsibility for - // destroying the object. - protected: - virtual ~RefCountInterface() {} -}; +// TODO(bugs.webrtc.org/15622): Deprecate and remove these aliases. +using RefCountInterface [[deprecated("Use webrtc::RefCountInterface")]] = + webrtc::RefCountInterface; +using RefCountReleaseStatus + [[deprecated("Use webrtc::RefCountReleaseStatus")]] = + webrtc::RefCountReleaseStatus; } // namespace rtc diff --git a/webrtc/rtc_base/ref_counted_object.h b/webrtc/rtc_base/ref_counted_object.h index 418c3d8..007e9f9 100644 --- a/webrtc/rtc_base/ref_counted_object.h +++ b/webrtc/rtc_base/ref_counted_object.h @@ -14,7 +14,7 @@ #include "rtc_base/ref_count.h" #include "rtc_base/ref_counter.h" -namespace rtc { +namespace webrtc { template class RefCountedObject : public T { @@ -84,6 +84,59 @@ class FinalRefCountedObject final : public T { mutable webrtc::webrtc_impl::RefCounter ref_count_{0}; }; +} // namespace webrtc + +// Backwards compatibe aliases. +// TODO: https://issues.webrtc.org/42225969 - deprecate and remove. +namespace rtc { +// Because there are users of this template that use "friend +// rtc::RefCountedObject<>" to give access to a private destructor, some +// indirection is needed; "friend" declarations cannot span an "using" +// declaration. Since a templated class on top of a templated class can't access +// the subclass' protected members, we duplicate the entire class instead. +template +class RefCountedObject : public T { + public: + RefCountedObject() {} + + RefCountedObject(const RefCountedObject&) = delete; + RefCountedObject& operator=(const RefCountedObject&) = delete; + + template + explicit RefCountedObject(P0&& p0) : T(std::forward(p0)) {} + + template + RefCountedObject(P0&& p0, P1&& p1, Args&&... args) + : T(std::forward(p0), + std::forward(p1), + std::forward(args)...) {} + + void AddRef() const override { ref_count_.IncRef(); } + + webrtc::RefCountReleaseStatus Release() const override { + const auto status = ref_count_.DecRef(); + if (status == webrtc::RefCountReleaseStatus::kDroppedLastRef) { + delete this; + } + return status; + } + + // Return whether the reference count is one. If the reference count is used + // in the conventional way, a reference count of 1 implies that the current + // thread owns the reference and no other thread shares it. This call + // performs the test for a reference count of one, and performs the memory + // barrier needed for the owning thread to act on the object, knowing that it + // has exclusive access to the object. + virtual bool HasOneRef() const { return ref_count_.HasOneRef(); } + + protected: + ~RefCountedObject() override {} + + mutable webrtc::webrtc_impl::RefCounter ref_count_{0}; +}; + +template +using FinalRefCountedObject = webrtc::FinalRefCountedObject; } // namespace rtc #endif // RTC_BASE_REF_COUNTED_OBJECT_H_ diff --git a/webrtc/rtc_base/ref_counter.h b/webrtc/rtc_base/ref_counter.h index 6ffeda8..93ae3d2 100644 --- a/webrtc/rtc_base/ref_counter.h +++ b/webrtc/rtc_base/ref_counter.h @@ -34,7 +34,7 @@ class RefCounter { // Otherwise, returns kOtherRefsRemained (note that in case of multithreading, // some other caller may have dropped the last reference by the time this call // returns; all we know is that we didn't do it). - rtc::RefCountReleaseStatus DecRef() { + RefCountReleaseStatus DecRef() { // Use release-acquire barrier to ensure all actions on the protected // resource are finished before the resource can be freed. // When ref_count_after_subtract > 0, this function require @@ -47,8 +47,8 @@ class RefCounter { int ref_count_after_subtract = ref_count_.fetch_sub(1, std::memory_order_acq_rel) - 1; return ref_count_after_subtract == 0 - ? rtc::RefCountReleaseStatus::kDroppedLastRef - : rtc::RefCountReleaseStatus::kOtherRefsRemained; + ? RefCountReleaseStatus::kDroppedLastRef + : RefCountReleaseStatus::kOtherRefsRemained; } // Return whether the reference count is one. If the reference count is used diff --git a/webrtc/rtc_base/string_encode.cc b/webrtc/rtc_base/string_encode.cc index 434d1e6..e5fd061 100644 --- a/webrtc/rtc_base/string_encode.cc +++ b/webrtc/rtc_base/string_encode.cc @@ -187,88 +187,19 @@ std::vector split(absl::string_view source, char delimiter) { return fields; } -std::string ToString(const bool b) { +template <> +std::string ToString(bool b) { return b ? "true" : "false"; } -std::string ToString(absl::string_view s) { - return std::string(s); -} - -std::string ToString(const char* s) { - return std::string(s); -} - -std::string ToString(const short s) { - char buf[32]; - const int len = std::snprintf(&buf[0], arraysize(buf), "%hd", s); - RTC_DCHECK_LE(len, arraysize(buf)); - return std::string(&buf[0], len); -} -std::string ToString(const unsigned short s) { - char buf[32]; - const int len = std::snprintf(&buf[0], arraysize(buf), "%hu", s); - RTC_DCHECK_LE(len, arraysize(buf)); - return std::string(&buf[0], len); -} -std::string ToString(const int s) { - char buf[32]; - const int len = std::snprintf(&buf[0], arraysize(buf), "%d", s); - RTC_DCHECK_LE(len, arraysize(buf)); - return std::string(&buf[0], len); -} -std::string ToString(const unsigned int s) { - char buf[32]; - const int len = std::snprintf(&buf[0], arraysize(buf), "%u", s); - RTC_DCHECK_LE(len, arraysize(buf)); - return std::string(&buf[0], len); -} -std::string ToString(const long int s) { - char buf[32]; - const int len = std::snprintf(&buf[0], arraysize(buf), "%ld", s); - RTC_DCHECK_LE(len, arraysize(buf)); - return std::string(&buf[0], len); -} -std::string ToString(const unsigned long int s) { - char buf[32]; - const int len = std::snprintf(&buf[0], arraysize(buf), "%lu", s); - RTC_DCHECK_LE(len, arraysize(buf)); - return std::string(&buf[0], len); -} -std::string ToString(const long long int s) { - char buf[32]; - const int len = std::snprintf(&buf[0], arraysize(buf), "%lld", s); - RTC_DCHECK_LE(len, arraysize(buf)); - return std::string(&buf[0], len); -} -std::string ToString(const unsigned long long int s) { - char buf[32]; - const int len = std::snprintf(&buf[0], arraysize(buf), "%llu", s); - RTC_DCHECK_LE(len, arraysize(buf)); - return std::string(&buf[0], len); -} - -std::string ToString(const double d) { - char buf[32]; - const int len = std::snprintf(&buf[0], arraysize(buf), "%g", d); - RTC_DCHECK_LE(len, arraysize(buf)); - return std::string(&buf[0], len); -} - -std::string ToString(const long double d) { +template <> +std::string ToString(long double d) { char buf[32]; const int len = std::snprintf(&buf[0], arraysize(buf), "%Lg", d); RTC_DCHECK_LE(len, arraysize(buf)); return std::string(&buf[0], len); } -std::string ToString(const void* const p) { - char buf[32]; - const int len = std::snprintf(&buf[0], arraysize(buf), "%p", p); - RTC_DCHECK_LE(len, arraysize(buf)); - return std::string(&buf[0], len); -} - bool FromString(absl::string_view s, bool* b) { if (s == "false") { *b = false; diff --git a/webrtc/rtc_base/string_encode.h b/webrtc/rtc_base/string_encode.h index 82a9dfd..836f236 100644 --- a/webrtc/rtc_base/string_encode.h +++ b/webrtc/rtc_base/string_encode.h @@ -13,12 +13,13 @@ #include +#include #include #include #include +#include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" -#include "absl/types/optional.h" #include "api/array_view.h" #include "rtc_base/checks.h" #include "rtc_base/string_to_number.h" @@ -62,28 +63,32 @@ bool tokenize_first(absl::string_view source, std::string* token, std::string* rest); -// Convert arbitrary values to/from a string. -// TODO(jonasolsson): Remove these when absl::StrCat becomes available. +template ::value || + std::is_convertible::value>::type* = nullptr> +std::string ToString(T value) { + return {absl::StrCat(value)}; +} + +// Versions that behave differently from StrCat +template <> std::string ToString(bool b); -std::string ToString(absl::string_view s); -// The const char* overload is needed for correct overload resolution because of -// the const void* version of ToString() below. -std::string ToString(const char* s); - -std::string ToString(short s); -std::string ToString(unsigned short s); -std::string ToString(int s); -std::string ToString(unsigned int s); -std::string ToString(long int s); -std::string ToString(unsigned long int s); -std::string ToString(long long int s); -std::string ToString(unsigned long long int s); - -std::string ToString(double t); +// Versions not supported by StrCat: +template <> std::string ToString(long double t); -std::string ToString(const void* p); +template ::value && + !std::is_convertible::value>::type* = nullptr> +std::string ToString(T p) { + char buf[32]; + const int len = std::snprintf(&buf[0], std::size(buf), "%p", p); + RTC_DCHECK_LE(len, std::size(buf)); + return std::string(&buf[0], len); +} template ::value && @@ -91,7 +96,7 @@ template ::type = 0> static bool FromString(absl::string_view s, T* t) { RTC_DCHECK(t); - absl::optional result = StringToNumber(s); + std::optional result = StringToNumber(s); if (result) *t = *result; diff --git a/webrtc/rtc_base/string_to_number.cc b/webrtc/rtc_base/string_to_number.cc index 1209ece..b02288b 100644 --- a/webrtc/rtc_base/string_to_number.cc +++ b/webrtc/rtc_base/string_to_number.cc @@ -20,9 +20,9 @@ namespace rtc { namespace string_to_number_internal { -absl::optional ParseSigned(absl::string_view str, int base) { +std::optional ParseSigned(absl::string_view str, int base) { if (str.empty()) - return absl::nullopt; + return std::nullopt; if (isdigit(static_cast(str[0])) || str[0] == '-') { std::string str_str(str); @@ -35,12 +35,12 @@ absl::optional ParseSigned(absl::string_view str, int base) { return value; } } - return absl::nullopt; + return std::nullopt; } -absl::optional ParseUnsigned(absl::string_view str, int base) { +std::optional ParseUnsigned(absl::string_view str, int base) { if (str.empty()) - return absl::nullopt; + return std::nullopt; if (isdigit(static_cast(str[0])) || str[0] == '-') { std::string str_str(str); @@ -58,7 +58,7 @@ absl::optional ParseUnsigned(absl::string_view str, int base) { return value; } } - return absl::nullopt; + return std::nullopt; } template @@ -80,12 +80,12 @@ inline long double StrToT(const char* str, char** str_end) { } template -absl::optional ParseFloatingPoint(absl::string_view str) { +std::optional ParseFloatingPoint(absl::string_view str) { if (str.empty()) - return absl::nullopt; + return std::nullopt; if (str[0] == '\0') - return absl::nullopt; + return std::nullopt; std::string str_str(str); char* end = nullptr; errno = 0; @@ -93,12 +93,12 @@ absl::optional ParseFloatingPoint(absl::string_view str) { if (end == str_str.c_str() + str_str.size() && errno == 0) { return value; } - return absl::nullopt; + return std::nullopt; } -template absl::optional ParseFloatingPoint(absl::string_view str); -template absl::optional ParseFloatingPoint(absl::string_view str); -template absl::optional ParseFloatingPoint(absl::string_view str); +template std::optional ParseFloatingPoint(absl::string_view str); +template std::optional ParseFloatingPoint(absl::string_view str); +template std::optional ParseFloatingPoint(absl::string_view str); } // namespace string_to_number_internal } // namespace rtc diff --git a/webrtc/rtc_base/string_to_number.h b/webrtc/rtc_base/string_to_number.h index 1d704ee..5e8aea5 100644 --- a/webrtc/rtc_base/string_to_number.h +++ b/webrtc/rtc_base/string_to_number.h @@ -12,11 +12,11 @@ #define RTC_BASE_STRING_TO_NUMBER_H_ #include +#include #include #include #include "absl/strings/string_view.h" -#include "absl/types/optional.h" namespace rtc { @@ -27,7 +27,7 @@ namespace rtc { // are disabled in WebRTC. // // Integers are parsed using: -// absl::optional StringToNumber(absl::string_view str, +// std::optional StringToNumber(absl::string_view str, // int base = 10); // // These functions parse a value from the beginning of a string into one of the @@ -44,16 +44,16 @@ namespace string_to_number_internal { using unsigned_type = unsigned long long; // NOLINT(runtime/int) using signed_type = long long; // NOLINT(runtime/int) -absl::optional ParseSigned(absl::string_view str, int base); -absl::optional ParseUnsigned(absl::string_view str, int base); +std::optional ParseSigned(absl::string_view str, int base); +std::optional ParseUnsigned(absl::string_view str, int base); template -absl::optional ParseFloatingPoint(absl::string_view str); +std::optional ParseFloatingPoint(absl::string_view str); } // namespace string_to_number_internal template typename std::enable_if::value && std::is_signed::value, - absl::optional>::type + std::optional>::type StringToNumber(absl::string_view str, int base = 10) { using string_to_number_internal::signed_type; static_assert( @@ -62,36 +62,36 @@ StringToNumber(absl::string_view str, int base = 10) { std::numeric_limits::lowest() >= std::numeric_limits::lowest(), "StringToNumber only supports signed integers as large as long long int"); - absl::optional value = + std::optional value = string_to_number_internal::ParseSigned(str, base); if (value && *value >= std::numeric_limits::lowest() && *value <= std::numeric_limits::max()) { return static_cast(*value); } - return absl::nullopt; + return std::nullopt; } template typename std::enable_if::value && std::is_unsigned::value, - absl::optional>::type + std::optional>::type StringToNumber(absl::string_view str, int base = 10) { using string_to_number_internal::unsigned_type; static_assert(std::numeric_limits::max() <= std::numeric_limits::max(), "StringToNumber only supports unsigned integers as large as " "unsigned long long int"); - absl::optional value = + std::optional value = string_to_number_internal::ParseUnsigned(str, base); if (value && *value <= std::numeric_limits::max()) { return static_cast(*value); } - return absl::nullopt; + return std::nullopt; } template typename std::enable_if::value, - absl::optional>::type + std::optional>::type StringToNumber(absl::string_view str, int base = 10) { static_assert( std::numeric_limits::max() <= std::numeric_limits::max(), diff --git a/webrtc/rtc_base/synchronization/BUILD.gn b/webrtc/rtc_base/synchronization/BUILD.gn index 5cab524..6b05f5c 100644 --- a/webrtc/rtc_base/synchronization/BUILD.gn +++ b/webrtc/rtc_base/synchronization/BUILD.gn @@ -36,15 +36,18 @@ rtc_source_set("mutex") { "..:macromagic", "..:platform_thread_types", "../system:no_unique_address", + "//third_party/abseil-cpp/absl/base:core_headers", ] - absl_deps = [ "//third_party/abseil-cpp/absl/base:core_headers" ] if (rtc_use_absl_mutex) { - absl_deps += [ "//third_party/abseil-cpp/absl/synchronization" ] + deps += [ "//third_party/abseil-cpp/absl/synchronization" ] } } rtc_library("sequence_checker_internal") { - visibility = [ "../../api:sequence_checker" ] + visibility = [ + "../../api:rtc_api_unittests", + "../../api:sequence_checker", + ] sources = [ "sequence_checker_internal.cc", "sequence_checker_internal.h", @@ -65,8 +68,8 @@ rtc_library("yield_policy") { "yield_policy.cc", "yield_policy.h", ] - deps = [ "..:checks" ] - absl_deps = [ + deps = [ + "..:checks", "//third_party/abseil-cpp/absl/base:config", "//third_party/abseil-cpp/absl/base:core_headers", ] diff --git a/webrtc/rtc_base/synchronization/mutex_pthread.h b/webrtc/rtc_base/synchronization/mutex_pthread.h index c749a20..a532bd2 100644 --- a/webrtc/rtc_base/synchronization/mutex_pthread.h +++ b/webrtc/rtc_base/synchronization/mutex_pthread.h @@ -76,8 +76,8 @@ class RTC_LOCKABLE MutexImpl final { } private: - // Use two separate primitive types, rather than absl::optional, since the - // data race described below might invalidate absl::optional invariants. + // Use two separate primitive types, rather than std::optional, since the + // data race described below might invalidate std::optional invariants. bool is_owned_ = false; pthread_t latest_owner_ = pthread_self(); #endif diff --git a/webrtc/rtc_base/system/BUILD.gn b/webrtc/rtc_base/system/BUILD.gn index 77f5139..b18114f 100644 --- a/webrtc/rtc_base/system/BUILD.gn +++ b/webrtc/rtc_base/system/BUILD.gn @@ -29,8 +29,8 @@ rtc_library("file_wrapper") { "..:checks", "..:criticalsection", "..:safe_conversions", + "//third_party/abseil-cpp/absl/strings:string_view", ] - absl_deps = [ "//third_party/abseil-cpp/absl/strings" ] } if (rtc_include_tests) { diff --git a/webrtc/rtc_base/system/file_wrapper.cc b/webrtc/rtc_base/system/file_wrapper.cc index af34d0e..12c27a5 100644 --- a/webrtc/rtc_base/system/file_wrapper.cc +++ b/webrtc/rtc_base/system/file_wrapper.cc @@ -14,6 +14,7 @@ #include #include +#include #include #include "absl/strings/string_view.h" @@ -81,20 +82,20 @@ bool FileWrapper::SeekTo(int64_t position) { return fseek(file_, rtc::checked_cast(position), SEEK_SET) == 0; } -long FileWrapper::FileSize() { +std::optional FileWrapper::FileSize() { if (file_ == nullptr) - return -1; + return std::nullopt; long original_position = ftell(file_); if (original_position < 0) - return -1; + return std::nullopt; int seek_error = fseek(file_, 0, SEEK_END); if (seek_error) - return -1; + return std::nullopt; long file_size = ftell(file_); seek_error = fseek(file_, original_position, SEEK_SET); if (seek_error) - return -1; - return file_size; + return std::nullopt; + return rtc::checked_cast(file_size); } bool FileWrapper::Flush() { diff --git a/webrtc/rtc_base/system/file_wrapper.h b/webrtc/rtc_base/system/file_wrapper.h index 7e73577..a1553ff 100644 --- a/webrtc/rtc_base/system/file_wrapper.h +++ b/webrtc/rtc_base/system/file_wrapper.h @@ -14,8 +14,8 @@ #include #include #include -#include +#include #include #include "absl/strings/string_view.h" @@ -90,7 +90,7 @@ class FileWrapper final { // Returns the file size or -1 if a size could not be determined. // (A file size might not exists for non-seekable files or file-like // objects, for example /dev/tty on unix.) - long FileSize(); + std::optional FileSize(); // Returns number of bytes read. Short count indicates EOF or error. size_t Read(void* buf, size_t length); diff --git a/webrtc/rtc_base/time_utils.h b/webrtc/rtc_base/time_utils.h index 271c1d6..872ae4a 100644 --- a/webrtc/rtc_base/time_utils.h +++ b/webrtc/rtc_base/time_utils.h @@ -129,11 +129,11 @@ int64_t TmToSeconds(const tm& tm); // system time is changed, e.g., by some other process calling // settimeofday. Always use rtc::TimeMicros(), not this function, for // measuring time intervals and timeouts. -int64_t TimeUTCMicros(); +RTC_EXPORT int64_t TimeUTCMicros(); // Return the number of milliseconds since January 1, 1970, UTC. // See above. -int64_t TimeUTCMillis(); +RTC_EXPORT int64_t TimeUTCMillis(); } // namespace rtc diff --git a/webrtc/rtc_base/trace_event.h b/webrtc/rtc_base/trace_event.h index 6689bc0..2aee713 100644 --- a/webrtc/rtc_base/trace_event.h +++ b/webrtc/rtc_base/trace_event.h @@ -1,25 +1,48 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file under third_party_mods/chromium or at: -// http://src.chromium.org/svn/trunk/src/LICENSE +/* + * Copyright (c) 2024 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ #ifndef RTC_BASE_TRACE_EVENT_H_ #define RTC_BASE_TRACE_EVENT_H_ -#include - -#include "rtc_base/event_tracer.h" - -#if defined(TRACE_EVENT0) -#error "Another copy of trace_event.h has already been included." -#endif - #if defined(RTC_DISABLE_TRACE_EVENTS) #define RTC_TRACE_EVENTS_ENABLED 0 #else #define RTC_TRACE_EVENTS_ENABLED 1 #endif +// IWYU pragma: begin_exports +#if defined(RTC_USE_PERFETTO) +#include "rtc_base/trace_categories.h" +#include "third_party/perfetto/include/perfetto/tracing/event_context.h" +#include "third_party/perfetto/include/perfetto/tracing/track.h" +#include "third_party/perfetto/include/perfetto/tracing/track_event_args.h" +#endif +// IWYU pragma: end_exports + +#if !defined(RTC_USE_PERFETTO) +#include + +#include "rtc_base/event_tracer.h" + +#define RTC_NOOP() \ + do { \ + } while (0) + +// TODO(b/42226290): Add implementation for these events with Perfetto. +#define TRACE_EVENT_BEGIN(category, name, ...) RTC_NOOP(); +#define TRACE_EVENT_END(category, ...) RTC_NOOP(); +#define TRACE_EVENT(category, name, ...) RTC_NOOP(); +#define TRACE_EVENT_INSTANT(category, name, ...) RTC_NOOP(); +#define TRACE_EVENT_CATEGORY_ENABLED(category) RTC_NOOP(); +#define TRACE_COUNTER(category, track, ...) RTC_NOOP(); + // Type values for identifying types in the TraceValue union. #define TRACE_VALUE_TYPE_BOOL (static_cast(1)) #define TRACE_VALUE_TYPE_UINT (static_cast(2)) @@ -29,6 +52,10 @@ #define TRACE_VALUE_TYPE_STRING (static_cast(6)) #define TRACE_VALUE_TYPE_COPY_STRING (static_cast(7)) +#if defined(TRACE_EVENT0) +#error "Another copy of trace_event.h has already been included." +#endif + #if RTC_TRACE_EVENTS_ENABLED // Extracted from Chromium's src/base/debug/trace_event.h. @@ -127,21 +154,6 @@ // application. In Chrome's case, navigating to about:tracing will turn on // tracing and display data collected across all active processes. // -// -// Memory scoping note: -// Tracing copies the pointers, not the string content, of the strings passed -// in for category, name, and arg_names. Thus, the following code will -// cause problems: -// char* str = strdup("impprtantName"); -// TRACE_EVENT_INSTANT0("SUBSYSTEM", str); // BAD! -// free(str); // Trace system now has dangling pointer -// -// To avoid this issue with the `name` and `arg_name` parameters, use the -// TRACE_EVENT_COPY_XXX overloads of the macros at additional runtime overhead. -// Notes: The category must always be in a long-lived char* (i.e. static const). -// The `arg_values`, when used, are always deep copied with the _COPY -// macros. -// // When are string argument values copied: // const char* arg_values are only referenced by default: // TRACE_EVENT1("category", "name", @@ -185,32 +197,27 @@ INTERNAL_TRACE_EVENT_ADD_SCOPED(category, name, arg1_name, arg1_val, \ arg2_name, arg2_val) +// Enum reflecting the scope of an INSTANT event. Must fit within +// TRACE_EVENT_FLAG_SCOPE_MASK. +static constexpr uint8_t TRACE_EVENT_SCOPE_GLOBAL = 0u << 2; +static constexpr uint8_t TRACE_EVENT_SCOPE_PROCESS = 1u << 2; +static constexpr uint8_t TRACE_EVENT_SCOPE_THREAD = 2u << 2; + // Records a single event called "name" immediately, with 0, 1 or 2 // associated arguments. If the category is not enabled, then this // does nothing. // - category and name strings must have application lifetime (statics or // literals). They may not include " chars. -#define TRACE_EVENT_INSTANT0(category, name) \ +#define TRACE_EVENT_INSTANT0(category, name, scope) \ INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category, name, \ TRACE_EVENT_FLAG_NONE) -#define TRACE_EVENT_INSTANT1(category, name, arg1_name, arg1_val) \ - INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category, name, \ +#define TRACE_EVENT_INSTANT1(category, name, scope, arg1_name, arg1_val) \ + INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category, name, \ TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val) -#define TRACE_EVENT_INSTANT2(category, name, arg1_name, arg1_val, arg2_name, \ - arg2_val) \ - INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category, name, \ - TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, \ - arg2_name, arg2_val) -#define TRACE_EVENT_COPY_INSTANT0(category, name) \ - INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category, name, \ - TRACE_EVENT_FLAG_COPY) -#define TRACE_EVENT_COPY_INSTANT1(category, name, arg1_name, arg1_val) \ - INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category, name, \ - TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val) -#define TRACE_EVENT_COPY_INSTANT2(category, name, arg1_name, arg1_val, \ - arg2_name, arg2_val) \ - INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category, name, \ - TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \ +#define TRACE_EVENT_INSTANT2(category, name, scope, arg1_name, arg1_val, \ + arg2_name, arg2_val) \ + INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category, name, \ + TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, \ arg2_name, arg2_val) // Records a single BEGIN event called "name" immediately, with 0, 1 or 2 @@ -229,17 +236,6 @@ INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category, name, \ TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, \ arg2_name, arg2_val) -#define TRACE_EVENT_COPY_BEGIN0(category, name) \ - INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category, name, \ - TRACE_EVENT_FLAG_COPY) -#define TRACE_EVENT_COPY_BEGIN1(category, name, arg1_name, arg1_val) \ - INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category, name, \ - TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val) -#define TRACE_EVENT_COPY_BEGIN2(category, name, arg1_name, arg1_val, \ - arg2_name, arg2_val) \ - INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, category, name, \ - TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \ - arg2_name, arg2_val) // Records a single END event for "name" immediately. If the category // is not enabled, then this does nothing. @@ -256,17 +252,6 @@ INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category, name, \ TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, \ arg2_name, arg2_val) -#define TRACE_EVENT_COPY_END0(category, name) \ - INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category, name, \ - TRACE_EVENT_FLAG_COPY) -#define TRACE_EVENT_COPY_END1(category, name, arg1_name, arg1_val) \ - INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category, name, \ - TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val) -#define TRACE_EVENT_COPY_END2(category, name, arg1_name, arg1_val, arg2_name, \ - arg2_val) \ - INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, category, name, \ - TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \ - arg2_name, arg2_val) // Records the value of a counter called "name" immediately. Value // must be representable as a 32 bit integer. @@ -276,10 +261,6 @@ INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, category, name, \ TRACE_EVENT_FLAG_NONE, "value", \ static_cast(value)) -#define TRACE_COPY_COUNTER1(category, name, value) \ - INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, category, name, \ - TRACE_EVENT_FLAG_COPY, "value", \ - static_cast(value)) // Records the values of a multi-parted counter called "name" immediately. // The UI will treat value1 and value2 as parts of a whole, displaying their @@ -292,12 +273,6 @@ TRACE_EVENT_FLAG_NONE, value1_name, \ static_cast(value1_val), value2_name, \ static_cast(value2_val)) -#define TRACE_COPY_COUNTER2(category, name, value1_name, value1_val, \ - value2_name, value2_val) \ - INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, category, name, \ - TRACE_EVENT_FLAG_COPY, value1_name, \ - static_cast(value1_val), value2_name, \ - static_cast(value2_val)) // Records the value of a counter called "name" immediately. Value // must be representable as a 32 bit integer. @@ -311,10 +286,6 @@ INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, category, name, \ id, TRACE_EVENT_FLAG_NONE, "value", \ static_cast(value)) -#define TRACE_COPY_COUNTER_ID1(category, name, id, value) \ - INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, category, name, \ - id, TRACE_EVENT_FLAG_COPY, "value", \ - static_cast(value)) // Records the values of a multi-parted counter called "name" immediately. // The UI will treat value1 and value2 as parts of a whole, displaying their @@ -331,12 +302,6 @@ id, TRACE_EVENT_FLAG_NONE, value1_name, \ static_cast(value1_val), value2_name, \ static_cast(value2_val)) -#define TRACE_COPY_COUNTER_ID2(category, name, id, value1_name, value1_val, \ - value2_name, value2_val) \ - INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_COUNTER, category, name, \ - id, TRACE_EVENT_FLAG_COPY, value1_name, \ - static_cast(value1_val), value2_name, \ - static_cast(value2_val)) // Records a single ASYNC_BEGIN event called "name" immediately, with 0, 1 or 2 // associated arguments. If the category is not enabled, then this @@ -367,40 +332,20 @@ INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, category, \ name, id, TRACE_EVENT_FLAG_NONE, arg1_name, \ arg1_val, arg2_name, arg2_val) -#define TRACE_EVENT_COPY_ASYNC_BEGIN0(category, name, id) \ - INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, category, \ - name, id, TRACE_EVENT_FLAG_COPY) -#define TRACE_EVENT_COPY_ASYNC_BEGIN1(category, name, id, arg1_name, arg1_val) \ - INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, category, \ - name, id, TRACE_EVENT_FLAG_COPY, arg1_name, \ - arg1_val) -#define TRACE_EVENT_COPY_ASYNC_BEGIN2(category, name, id, arg1_name, arg1_val, \ - arg2_name, arg2_val) \ - INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN, category, \ - name, id, TRACE_EVENT_FLAG_COPY, arg1_name, \ - arg1_val, arg2_name, arg2_val) // Records a single ASYNC_STEP event for `step` immediately. If the category // is not enabled, then this does nothing. The `name` and `id` must match the // ASYNC_BEGIN event above. The `step` param identifies this step within the // async event. This should be called at the beginning of the next phase of an // asynchronous operation. -#define TRACE_EVENT_ASYNC_STEP0(category, name, id, step) \ +#define TRACE_EVENT_ASYNC_STEP_INTO0(category, name, id, step) \ INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP, category, \ name, id, TRACE_EVENT_FLAG_NONE, "step", \ step) -#define TRACE_EVENT_ASYNC_STEP1(category, name, id, step, arg1_name, arg1_val) \ - INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP, category, \ - name, id, TRACE_EVENT_FLAG_NONE, "step", \ - step, arg1_name, arg1_val) -#define TRACE_EVENT_COPY_ASYNC_STEP0(category, name, id, step) \ - INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP, category, \ - name, id, TRACE_EVENT_FLAG_COPY, "step", \ - step) -#define TRACE_EVENT_COPY_ASYNC_STEP1(category, name, id, step, arg1_name, \ +#define TRACE_EVENT_ASYNC_STEP_INTO1(category, name, id, step, arg1_name, \ arg1_val) \ INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_STEP, category, \ - name, id, TRACE_EVENT_FLAG_COPY, "step", \ + name, id, TRACE_EVENT_FLAG_NONE, "step", \ step, arg1_name, arg1_val) // Records a single ASYNC_END event for "name" immediately. If the category @@ -417,112 +362,6 @@ INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, category, \ name, id, TRACE_EVENT_FLAG_NONE, arg1_name, \ arg1_val, arg2_name, arg2_val) -#define TRACE_EVENT_COPY_ASYNC_END0(category, name, id) \ - INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, category, \ - name, id, TRACE_EVENT_FLAG_COPY) -#define TRACE_EVENT_COPY_ASYNC_END1(category, name, id, arg1_name, arg1_val) \ - INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, category, \ - name, id, TRACE_EVENT_FLAG_COPY, arg1_name, \ - arg1_val) -#define TRACE_EVENT_COPY_ASYNC_END2(category, name, id, arg1_name, arg1_val, \ - arg2_name, arg2_val) \ - INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END, category, \ - name, id, TRACE_EVENT_FLAG_COPY, arg1_name, \ - arg1_val, arg2_name, arg2_val) - -// Records a single FLOW_BEGIN event called "name" immediately, with 0, 1 or 2 -// associated arguments. If the category is not enabled, then this -// does nothing. -// - category and name strings must have application lifetime (statics or -// literals). They may not include " chars. -// - `id` is used to match the FLOW_BEGIN event with the FLOW_END event. FLOW -// events are considered to match if their category, name and id values all -// match. `id` must either be a pointer or an integer value up to 64 bits. If -// it's a pointer, the bits will be xored with a hash of the process ID so -// that the same pointer on two different processes will not collide. -// FLOW events are different from ASYNC events in how they are drawn by the -// tracing UI. A FLOW defines asynchronous data flow, such as posting a task -// (FLOW_BEGIN) and later executing that task (FLOW_END). Expect FLOWs to be -// drawn as lines or arrows from FLOW_BEGIN scopes to FLOW_END scopes. Similar -// to ASYNC, a FLOW can consist of multiple phases. The first phase is defined -// by the FLOW_BEGIN calls. Additional phases can be defined using the FLOW_STEP -// macros. When the operation completes, call FLOW_END. An async operation can -// span threads and processes, but all events in that operation must use the -// same `name` and `id`. Each event can have its own args. -#define TRACE_EVENT_FLOW_BEGIN0(category, name, id) \ - INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, category, \ - name, id, TRACE_EVENT_FLAG_NONE) -#define TRACE_EVENT_FLOW_BEGIN1(category, name, id, arg1_name, arg1_val) \ - INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, category, \ - name, id, TRACE_EVENT_FLAG_NONE, arg1_name, \ - arg1_val) -#define TRACE_EVENT_FLOW_BEGIN2(category, name, id, arg1_name, arg1_val, \ - arg2_name, arg2_val) \ - INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, category, \ - name, id, TRACE_EVENT_FLAG_NONE, arg1_name, \ - arg1_val, arg2_name, arg2_val) -#define TRACE_EVENT_COPY_FLOW_BEGIN0(category, name, id) \ - INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, category, \ - name, id, TRACE_EVENT_FLAG_COPY) -#define TRACE_EVENT_COPY_FLOW_BEGIN1(category, name, id, arg1_name, arg1_val) \ - INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, category, \ - name, id, TRACE_EVENT_FLAG_COPY, arg1_name, \ - arg1_val) -#define TRACE_EVENT_COPY_FLOW_BEGIN2(category, name, id, arg1_name, arg1_val, \ - arg2_name, arg2_val) \ - INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_BEGIN, category, \ - name, id, TRACE_EVENT_FLAG_COPY, arg1_name, \ - arg1_val, arg2_name, arg2_val) - -// Records a single FLOW_STEP event for `step` immediately. If the category -// is not enabled, then this does nothing. The `name` and `id` must match the -// FLOW_BEGIN event above. The `step` param identifies this step within the -// async event. This should be called at the beginning of the next phase of an -// asynchronous operation. -#define TRACE_EVENT_FLOW_STEP0(category, name, id, step) \ - INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, category, \ - name, id, TRACE_EVENT_FLAG_NONE, "step", \ - step) -#define TRACE_EVENT_FLOW_STEP1(category, name, id, step, arg1_name, arg1_val) \ - INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, category, \ - name, id, TRACE_EVENT_FLAG_NONE, "step", \ - step, arg1_name, arg1_val) -#define TRACE_EVENT_COPY_FLOW_STEP0(category, name, id, step) \ - INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, category, \ - name, id, TRACE_EVENT_FLAG_COPY, "step", \ - step) -#define TRACE_EVENT_COPY_FLOW_STEP1(category, name, id, step, arg1_name, \ - arg1_val) \ - INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_STEP, category, \ - name, id, TRACE_EVENT_FLAG_COPY, "step", \ - step, arg1_name, arg1_val) - -// Records a single FLOW_END event for "name" immediately. If the category -// is not enabled, then this does nothing. -#define TRACE_EVENT_FLOW_END0(category, name, id) \ - INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category, name, \ - id, TRACE_EVENT_FLAG_NONE) -#define TRACE_EVENT_FLOW_END1(category, name, id, arg1_name, arg1_val) \ - INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category, name, \ - id, TRACE_EVENT_FLAG_NONE, arg1_name, \ - arg1_val) -#define TRACE_EVENT_FLOW_END2(category, name, id, arg1_name, arg1_val, \ - arg2_name, arg2_val) \ - INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category, name, \ - id, TRACE_EVENT_FLAG_NONE, arg1_name, \ - arg1_val, arg2_name, arg2_val) -#define TRACE_EVENT_COPY_FLOW_END0(category, name, id) \ - INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category, name, \ - id, TRACE_EVENT_FLAG_COPY) -#define TRACE_EVENT_COPY_FLOW_END1(category, name, id, arg1_name, arg1_val) \ - INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category, name, \ - id, TRACE_EVENT_FLAG_COPY, arg1_name, \ - arg1_val) -#define TRACE_EVENT_COPY_FLOW_END2(category, name, id, arg1_name, arg1_val, \ - arg2_name, arg2_val) \ - INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, category, name, \ - id, TRACE_EVENT_FLAG_COPY, arg1_name, \ - arg1_val, arg2_name, arg2_val) //////////////////////////////////////////////////////////////////////////////// // Implementation specific tracing API definitions. @@ -630,15 +469,11 @@ #define TRACE_EVENT_PHASE_ASYNC_BEGIN ('S') #define TRACE_EVENT_PHASE_ASYNC_STEP ('T') #define TRACE_EVENT_PHASE_ASYNC_END ('F') -#define TRACE_EVENT_PHASE_FLOW_BEGIN ('s') -#define TRACE_EVENT_PHASE_FLOW_STEP ('t') -#define TRACE_EVENT_PHASE_FLOW_END ('f') #define TRACE_EVENT_PHASE_METADATA ('M') #define TRACE_EVENT_PHASE_COUNTER ('C') // Flags for changing the behavior of TRACE_EVENT_API_ADD_TRACE_EVENT. #define TRACE_EVENT_FLAG_NONE (static_cast(0)) -#define TRACE_EVENT_FLAG_COPY (static_cast(1 << 0)) #define TRACE_EVENT_FLAG_HAS_ID (static_cast(1 << 1)) #define TRACE_EVENT_FLAG_MANGLE_ID (static_cast(1 << 2)) @@ -898,18 +733,13 @@ class TraceEndOnScopeClose { } // namespace trace_event_internal } // namespace webrtc + #else //////////////////////////////////////////////////////////////////////////////// // This section defines no-op alternatives to the tracing macros when // RTC_DISABLE_TRACE_EVENTS is defined. -#define RTC_NOOP() \ - do { \ - } while (0) - -#define TRACE_STR_COPY(str) RTC_NOOP() - #define TRACE_DISABLED_BY_DEFAULT(name) "disabled-by-default-" name #define TRACE_ID_MANGLE(id) 0 @@ -919,18 +749,12 @@ class TraceEndOnScopeClose { #define TRACE_EVENT2(category, name, arg1_name, arg1_val, arg2_name, arg2_val) \ RTC_NOOP() -#define TRACE_EVENT_INSTANT0(category, name) RTC_NOOP() -#define TRACE_EVENT_INSTANT1(category, name, arg1_name, arg1_val) RTC_NOOP() - -#define TRACE_EVENT_INSTANT2(category, name, arg1_name, arg1_val, arg2_name, \ - arg2_val) \ +#define TRACE_EVENT_INSTANT0(category, name, scope) RTC_NOOP() +#define TRACE_EVENT_INSTANT1(category, name, scope, arg1_name, arg1_val) \ RTC_NOOP() -#define TRACE_EVENT_COPY_INSTANT0(category, name) RTC_NOOP() -#define TRACE_EVENT_COPY_INSTANT1(category, name, arg1_name, arg1_val) \ - RTC_NOOP() -#define TRACE_EVENT_COPY_INSTANT2(category, name, arg1_name, arg1_val, \ - arg2_name, arg2_val) \ +#define TRACE_EVENT_INSTANT2(category, name, scope, arg1_name, arg1_val, \ + arg2_name, arg2_val) \ RTC_NOOP() #define TRACE_EVENT_BEGIN0(category, name) RTC_NOOP() @@ -938,42 +762,24 @@ class TraceEndOnScopeClose { #define TRACE_EVENT_BEGIN2(category, name, arg1_name, arg1_val, arg2_name, \ arg2_val) \ RTC_NOOP() -#define TRACE_EVENT_COPY_BEGIN0(category, name) RTC_NOOP() -#define TRACE_EVENT_COPY_BEGIN1(category, name, arg1_name, arg1_val) RTC_NOOP() -#define TRACE_EVENT_COPY_BEGIN2(category, name, arg1_name, arg1_val, \ - arg2_name, arg2_val) \ - RTC_NOOP() #define TRACE_EVENT_END0(category, name) RTC_NOOP() #define TRACE_EVENT_END1(category, name, arg1_name, arg1_val) RTC_NOOP() #define TRACE_EVENT_END2(category, name, arg1_name, arg1_val, arg2_name, \ arg2_val) \ RTC_NOOP() -#define TRACE_EVENT_COPY_END0(category, name) RTC_NOOP() -#define TRACE_EVENT_COPY_END1(category, name, arg1_name, arg1_val) RTC_NOOP() -#define TRACE_EVENT_COPY_END2(category, name, arg1_name, arg1_val, arg2_name, \ - arg2_val) \ - RTC_NOOP() #define TRACE_COUNTER1(category, name, value) RTC_NOOP() -#define TRACE_COPY_COUNTER1(category, name, value) RTC_NOOP() #define TRACE_COUNTER2(category, name, value1_name, value1_val, value2_name, \ value2_val) \ RTC_NOOP() -#define TRACE_COPY_COUNTER2(category, name, value1_name, value1_val, \ - value2_name, value2_val) \ - RTC_NOOP() #define TRACE_COUNTER_ID1(category, name, id, value) RTC_NOOP() -#define TRACE_COPY_COUNTER_ID1(category, name, id, value) RTC_NOOP() #define TRACE_COUNTER_ID2(category, name, id, value1_name, value1_val, \ value2_name, value2_val) \ RTC_NOOP() -#define TRACE_COPY_COUNTER_ID2(category, name, id, value1_name, value1_val, \ - value2_name, value2_val) \ - RTC_NOOP() #define TRACE_EVENT_ASYNC_BEGIN0(category, name, id) RTC_NOOP() #define TRACE_EVENT_ASYNC_BEGIN1(category, name, id, arg1_name, arg1_val) \ @@ -981,18 +787,9 @@ class TraceEndOnScopeClose { #define TRACE_EVENT_ASYNC_BEGIN2(category, name, id, arg1_name, arg1_val, \ arg2_name, arg2_val) \ RTC_NOOP() -#define TRACE_EVENT_COPY_ASYNC_BEGIN0(category, name, id) RTC_NOOP() -#define TRACE_EVENT_COPY_ASYNC_BEGIN1(category, name, id, arg1_name, arg1_val) \ - RTC_NOOP() -#define TRACE_EVENT_COPY_ASYNC_BEGIN2(category, name, id, arg1_name, arg1_val, \ - arg2_name, arg2_val) \ - RTC_NOOP() -#define TRACE_EVENT_ASYNC_STEP0(category, name, id, step) RTC_NOOP() -#define TRACE_EVENT_ASYNC_STEP1(category, name, id, step, arg1_name, arg1_val) \ - RTC_NOOP() -#define TRACE_EVENT_COPY_ASYNC_STEP0(category, name, id, step) RTC_NOOP() -#define TRACE_EVENT_COPY_ASYNC_STEP1(category, name, id, step, arg1_name, \ +#define TRACE_EVENT_ASYNC_STEP_INTO0(category, name, id, step) RTC_NOOP() +#define TRACE_EVENT_ASYNC_STEP_INTO1(category, name, id, step, arg1_name, \ arg1_val) \ RTC_NOOP() @@ -1002,51 +799,12 @@ class TraceEndOnScopeClose { #define TRACE_EVENT_ASYNC_END2(category, name, id, arg1_name, arg1_val, \ arg2_name, arg2_val) \ RTC_NOOP() -#define TRACE_EVENT_COPY_ASYNC_END0(category, name, id) RTC_NOOP() -#define TRACE_EVENT_COPY_ASYNC_END1(category, name, id, arg1_name, arg1_val) \ - RTC_NOOP() -#define TRACE_EVENT_COPY_ASYNC_END2(category, name, id, arg1_name, arg1_val, \ - arg2_name, arg2_val) \ - RTC_NOOP() - -#define TRACE_EVENT_FLOW_BEGIN0(category, name, id) RTC_NOOP() -#define TRACE_EVENT_FLOW_BEGIN1(category, name, id, arg1_name, arg1_val) \ - RTC_NOOP() -#define TRACE_EVENT_FLOW_BEGIN2(category, name, id, arg1_name, arg1_val, \ - arg2_name, arg2_val) \ - RTC_NOOP() -#define TRACE_EVENT_COPY_FLOW_BEGIN0(category, name, id) RTC_NOOP() -#define TRACE_EVENT_COPY_FLOW_BEGIN1(category, name, id, arg1_name, arg1_val) \ - RTC_NOOP() -#define TRACE_EVENT_COPY_FLOW_BEGIN2(category, name, id, arg1_name, arg1_val, \ - arg2_name, arg2_val) \ - RTC_NOOP() - -#define TRACE_EVENT_FLOW_STEP0(category, name, id, step) RTC_NOOP() -#define TRACE_EVENT_FLOW_STEP1(category, name, id, step, arg1_name, arg1_val) \ - RTC_NOOP() -#define TRACE_EVENT_COPY_FLOW_STEP0(category, name, id, step) RTC_NOOP() -#define TRACE_EVENT_COPY_FLOW_STEP1(category, name, id, step, arg1_name, \ - arg1_val) \ - RTC_NOOP() - -#define TRACE_EVENT_FLOW_END0(category, name, id) RTC_NOOP() -#define TRACE_EVENT_FLOW_END1(category, name, id, arg1_name, arg1_val) \ - RTC_NOOP() -#define TRACE_EVENT_FLOW_END2(category, name, id, arg1_name, arg1_val, \ - arg2_name, arg2_val) \ - RTC_NOOP() -#define TRACE_EVENT_COPY_FLOW_END0(category, name, id) RTC_NOOP() -#define TRACE_EVENT_COPY_FLOW_END1(category, name, id, arg1_name, arg1_val) \ - RTC_NOOP() -#define TRACE_EVENT_COPY_FLOW_END2(category, name, id, arg1_name, arg1_val, \ - arg2_name, arg2_val) \ - RTC_NOOP() #define TRACE_EVENT_API_GET_CATEGORY_ENABLED "" #define TRACE_EVENT_API_ADD_TRACE_EVENT RTC_NOOP() #endif // RTC_TRACE_EVENTS_ENABLED +#endif // RTC_USE_PERFETTO #endif // RTC_BASE_TRACE_EVENT_H_ diff --git a/webrtc/rtc_base/type_traits.h b/webrtc/rtc_base/type_traits.h index 0cb899c..8f90a88 100644 --- a/webrtc/rtc_base/type_traits.h +++ b/webrtc/rtc_base/type_traits.h @@ -12,6 +12,7 @@ #define RTC_BASE_TYPE_TRAITS_H_ #include +#include #include namespace rtc { diff --git a/webrtc/rtc_base/units/unit_base.h b/webrtc/rtc_base/units/unit_base.h index a6bdbf5..fff6959 100644 --- a/webrtc/rtc_base/units/unit_base.h +++ b/webrtc/rtc_base/units/unit_base.h @@ -110,7 +110,6 @@ class UnitBase { } else if (value == -std::numeric_limits::infinity()) { return MinusInfinity(); } else { - RTC_DCHECK(!std::isnan(value)); return FromValue(rtc::dchecked_cast(value)); } } diff --git a/webrtc/system_wrappers/BUILD.gn b/webrtc/system_wrappers/BUILD.gn index 2576d4e..5e66d4b 100644 --- a/webrtc/system_wrappers/BUILD.gn +++ b/webrtc/system_wrappers/BUILD.gn @@ -31,7 +31,6 @@ rtc_library("system_wrappers") { defines = [] libs = [] deps = [ - ":field_trial", "../api:array_view", "../api/units:timestamp", "../modules:module_api_public", @@ -43,7 +42,6 @@ rtc_library("system_wrappers") { "../rtc_base/system:arch", "../rtc_base/system:rtc_export", ] - absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] if (is_android) { if (build_with_mozilla) { @@ -92,10 +90,8 @@ rtc_library("field_trial") { "../rtc_base:logging", "../rtc_base:stringutils", "../rtc_base/containers:flat_set", - ] - absl_deps = [ "//third_party/abseil-cpp/absl/algorithm:container", - "//third_party/abseil-cpp/absl/strings", + "//third_party/abseil-cpp/absl/strings:string_view", ] } @@ -111,8 +107,8 @@ rtc_library("metrics") { "../rtc_base:macromagic", "../rtc_base:stringutils", "../rtc_base/synchronization:mutex", + "//third_party/abseil-cpp/absl/strings:string_view", ] - absl_deps = [ "//third_party/abseil-cpp/absl/strings" ] } rtc_library("denormal_disabler") { @@ -153,10 +149,9 @@ if (rtc_include_tests && !build_with_chromium) { "../test:test_main", "../test:test_support", "//testing/gtest", + "//third_party/abseil-cpp/absl/strings:string_view", ] - absl_deps = [ "//third_party/abseil-cpp/absl/strings" ] - if (is_android) { deps += [ "//testing/android/native_test:native_test_support" ] diff --git a/webrtc/system_wrappers/source/cpu_features.cc b/webrtc/system_wrappers/source/cpu_features.cc index 8cd701e..4a6170c 100644 --- a/webrtc/system_wrappers/source/cpu_features.cc +++ b/webrtc/system_wrappers/source/cpu_features.cc @@ -12,7 +12,6 @@ #include "rtc_base/system/arch.h" #include "system_wrappers/include/cpu_features_wrapper.h" -#include "system_wrappers/include/field_trial.h" #if defined(WEBRTC_ARCH_X86_FAMILY) && defined(_MSC_VER) #include @@ -78,8 +77,7 @@ int GetCPUInfo(CPUFeature feature) { return 0 != (cpu_info[2] & 0x00000001); } #if defined(WEBRTC_ENABLE_AVX2) - if (feature == kAVX2 && - !webrtc::field_trial::IsEnabled("WebRTC-Avx2SupportKillSwitch")) { + if (feature == kAVX2) { int cpu_info7[4]; __cpuid(cpu_info7, 0); int num_ids = cpu_info7[0];