apm_flags = ['-DWEBRTC_APM_DEBUG_DUMP=0']

webrtc_audio_processing_sources = [
  'aec_dump/null_aec_dump_factory.cc',
  'aec3/adaptive_fir_filter.cc',
  'aec3/adaptive_fir_filter_erl.cc',
  'aec3/aec3_common.cc',
  'aec3/aec3_fft.cc',
  'aec3/aec_state.cc',
  'aec3/alignment_mixer.cc',
  'aec3/api_call_jitter_metrics.cc',
  'aec3/block_buffer.cc',
  'aec3/block_delay_buffer.cc',
  'aec3/block_framer.cc',
  'aec3/block_processor.cc',
  'aec3/block_processor_metrics.cc',
  'aec3/clockdrift_detector.cc',
  'aec3/coarse_filter_update_gain.cc',
  'aec3/comfort_noise_generator.cc',
  'aec3/config_selector.cc',
  'aec3/decimator.cc',
  'aec3/dominant_nearend_detector.cc',
  'aec3/downsampled_render_buffer.cc',
  'aec3/echo_audibility.cc',
  'aec3/echo_canceller3.cc',
  'aec3/echo_path_delay_estimator.cc',
  'aec3/echo_path_variability.cc',
  'aec3/echo_remover.cc',
  'aec3/echo_remover_metrics.cc',
  'aec3/erle_estimator.cc',
  'aec3/erl_estimator.cc',
  'aec3/fft_buffer.cc',
  'aec3/filter_analyzer.cc',
  'aec3/frame_blocker.cc',
  'aec3/fullband_erle_estimator.cc',
  'aec3/matched_filter.cc',
  'aec3/matched_filter_lag_aggregator.cc',
  'aec3/moving_average.cc',
  'aec3/multi_channel_content_detector.cc',
  'aec3/refined_filter_update_gain.cc',
  'aec3/render_buffer.cc',
  'aec3/render_delay_buffer.cc',
  'aec3/render_delay_controller.cc',
  'aec3/render_delay_controller_metrics.cc',
  'aec3/render_signal_analyzer.cc',
  'aec3/residual_echo_estimator.cc',
  'aec3/reverb_decay_estimator.cc',
  'aec3/reverb_frequency_response.cc',
  'aec3/reverb_model.cc',
  'aec3/reverb_model_estimator.cc',
  'aec3/signal_dependent_erle_estimator.cc',
  'aec3/spectrum_buffer.cc',
  'aec3/stationarity_estimator.cc',
  'aec3/subband_erle_estimator.cc',
  'aec3/subband_nearend_detector.cc',
  'aec3/subtractor.cc',
  'aec3/subtractor_output_analyzer.cc',
  'aec3/subtractor_output.cc',
  'aec3/suppression_filter.cc',
  'aec3/suppression_gain.cc',
  'aec3/transparent_mode.cc',
  'aecm/aecm_core.cc',
  'aecm/aecm_core_c.cc',
  'aecm/echo_control_mobile.cc',
  'agc/agc.cc',
  'agc/agc_manager_direct.cc',
  'agc/legacy/analog_agc.cc',
  'agc/legacy/digital_agc.cc',
  'agc/loudness_histogram.cc',
  'agc/utility.cc',
  'agc2/adaptive_digital_gain_controller.cc',
  'agc2/agc2_testing_common.cc',
  'agc2/biquad_filter.cc',
  'agc2/clipping_predictor.cc',
  'agc2/clipping_predictor_level_buffer.cc',
  'agc2/compute_interpolated_gain_curve.cc',
  'agc2/cpu_features.cc',
  'agc2/fixed_digital_level_estimator.cc',
  'agc2/gain_applier.cc',
  'agc2/input_volume_controller.cc',
  'agc2/input_volume_stats_reporter.cc',
  'agc2/interpolated_gain_curve.cc',
  'agc2/limiter.cc',
  'agc2/limiter_db_gain_curve.cc',
  'agc2/noise_level_estimator.cc',
  'agc2/rnn_vad/auto_correlation.cc',
  'agc2/rnn_vad/features_extraction.cc',
  'agc2/rnn_vad/lp_residual.cc',
  'agc2/rnn_vad/pitch_search.cc',
  'agc2/rnn_vad/pitch_search_internal.cc',
  'agc2/rnn_vad/rnn.cc',
  'agc2/rnn_vad/rnn_fc.cc',
  'agc2/rnn_vad/rnn_gru.cc',
  'agc2/rnn_vad/spectral_features.cc',
  'agc2/rnn_vad/spectral_features_internal.cc',
  'agc2/saturation_protector.cc',
  'agc2/saturation_protector_buffer.cc',
  'agc2/speech_level_estimator.cc',
  'agc2/speech_probability_buffer.cc',
  'agc2/vad_wrapper.cc',
  'agc2/vector_float_frame.cc',
  'audio_buffer.cc',
  'audio_processing_builder_impl.cc',
  'audio_processing_impl.cc',
  'capture_levels_adjuster/audio_samples_scaler.cc',
  'capture_levels_adjuster/capture_levels_adjuster.cc',
  'echo_control_mobile_impl.cc',
  'echo_detector/circular_buffer.cc',
  'echo_detector/mean_variance_estimator.cc',
  'echo_detector/moving_max.cc',
  'echo_detector/normalized_covariance_estimator.cc',
  'gain_control_impl.cc',
  'gain_controller2.cc',
  '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',
  'ns/noise_estimator.cc',
  'ns/noise_suppressor.cc',
  'ns/ns_fft.cc',
  'ns/prior_signal_model.cc',
  'ns/prior_signal_model_estimator.cc',
  'ns/quantile_noise_estimator.cc',
  'ns/signal_model.cc',
  'ns/signal_model_estimator.cc',
  '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',
  'utility/pffft_wrapper.cc',
  'vad/gmm.cc',
  'vad/pitch_based_vad.cc',
  'vad/pitch_internal.cc',
  'vad/pole_zero_filter.cc',
  'vad/standalone_vad.cc',
  'vad/vad_audio_proc.cc',
  'vad/vad_circular_buffer.cc',
  'vad/voice_activity_detector.cc',
]

webrtc_audio_processing_include_headers = [
  'include/audio_processing.h',
  'include/audio_processing_statistics.h',
  'include/config.h',
]

extra_libs = []
if have_x86
  extra_libs += [
    static_library('webrtc_audio_processing_privatearch',
      [
        'aec3/adaptive_fir_filter_avx2.cc',
        'aec3/adaptive_fir_filter_erl_avx2.cc',
        'aec3/fft_data_avx2.cc',
        'aec3/matched_filter_avx2.cc',
        'aec3/vector_math_avx2.cc',
        'agc2/rnn_vad/vector_math_avx2.cc',
      ],
      dependencies: common_deps,
      include_directories: webrtc_inc,
      c_args: common_cflags + apm_flags + avx_flags,
      cpp_args: common_cxxflags + apm_flags + avx_flags
    )
  ]
endif

if have_mips
  webrtc_audio_processing_sources += [
    'aecm/aecm_core_mips.cc',
  ]
endif

if have_neon
  webrtc_audio_processing_sources += [
    'aecm/aecm_core_neon.cc',
  ]
endif

install_headers(webrtc_audio_processing_include_headers,
    subdir: join_paths(include_subdir, 'modules', 'audio_processing', 'include')
)

libwebrtc_audio_processing = library(apm_project_name,
    webrtc_audio_processing_sources,
    dependencies: [
      base_dep,
      api_dep,
      isac_vad_dep,
      system_wrappers_dep,
      common_audio_dep,
      pffft_dep,
      rnnoise_dep,
    ] + common_deps,
    link_with: extra_libs,
    include_directories: webrtc_inc,
    c_args: common_cflags + apm_flags,
    cpp_args: common_cxxflags + apm_flags,
    soversion: apm_minor_version,
    install: true
)
