project(VocieProcess)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include(FetchContent)

set(ABSL_PROPAGATE_CXX_STD ON)
FetchContent_Declare(absl
    GIT_REPOSITORY https://github.com/abseil/abseil-cpp.git
)
FetchContent_MakeAvailable(absl)


add_library(VocieProcess
    api/rtp_headers.h api/rtp_headers.cc
    api/rtp_packet_info.h api/rtp_packet_info.cc

    api/audio/audio_frame.h api/audio/audio_frame.cc
    api/audio/audio_processing_statistics.h api/audio/audio_processing_statistics.cc
    api/audio/audio_processing.h api/audio/audio_processing.cc
    api/audio/channel_layout.h api/audio/channel_layout.cc
    api/audio/echo_canceller3_config.h api/audio/echo_canceller3_config.cc
    api/audio/echo_canceller3_factory.h api/audio/echo_canceller3_factory.cc

    api/task_queue/task_queue_base.h api/task_queue/task_queue_base.cc

    api/units/time_delta.h api/units/time_delta.cc
    api/units/timestamp.h api/units/timestamp.cc

    api/video/color_space.h api/video/color_space.cc
    api/video/hdr_metadata.h api/video/hdr_metadata.cc
    api/video/video_content_type.h api/video/video_content_type.cc
    api/video/video_timing.h api/video/video_timing.cc

    common_audio/audio_converter.h common_audio/audio_converter.cc
    common_audio/audio_util.cc
    common_audio/channel_buffer.h common_audio/channel_buffer.cc
    $<$<BOOL:${CROSS_BUILD}>:common_audio/fir_filter_neon.h common_audio/fir_filter_neon.cc>
    common_audio/ring_buffer.h common_audio/ring_buffer.c
    common_audio/wav_file.h common_audio/wav_file.cc
    common_audio/wav_header.h common_audio/wav_header.cc

    common_audio/resampler/push_sinc_resampler.h common_audio/resampler/push_sinc_resampler.cc
    common_audio/resampler/sinc_resampler.h common_audio/resampler/sinc_resampler.cc
    $<$<BOOL:${CROSS_BUILD}>:common_audio/resampler/sinc_resampler_neon.cc>
    $<$<PLATFORM_ID:Windows>:common_audio/resampler/sinc_resampler_sse.cc>
    $<$<PLATFORM_ID:Windows>:common_audio/resampler/sinc_resampler_avx2.cc>

    common_audio/signal_processing/complex_bit_reverse.c
    common_audio/signal_processing/complex_fft.c
    common_audio/signal_processing/cross_correlation.c
    common_audio/signal_processing/division_operations.c
    common_audio/signal_processing/dot_product_with_scale.h common_audio/signal_processing/dot_product_with_scale.cc
    common_audio/signal_processing/downsample_fast.c
    $<$<BOOL:${CROSS_BUILD}>:common_audio/signal_processing/cross_correlation_neon.c>
    $<$<BOOL:${CROSS_BUILD}>:common_audio/signal_processing/downsample_fast_neon.c>
    $<$<BOOL:${CROSS_BUILD}>:common_audio/signal_processing/min_max_operations_neon.c>
    common_audio/signal_processing/min_max_operations.c
    common_audio/signal_processing/randomization_functions.c
    common_audio/signal_processing/real_fft.c
    common_audio/signal_processing/spl_init.c
    common_audio/signal_processing/splitting_filter.c
    common_audio/signal_processing/vector_scaling_operations.c

    common_audio/third_party/ooura/fft_size_128/ooura_fft.h common_audio/third_party/ooura/fft_size_128/ooura_fft.cc
    $<$<BOOL:${CROSS_BUILD}>:common_audio/third_party/ooura/fft_size_128/ooura_fft_neon.cc>
    $<$<PLATFORM_ID:Windows>:common_audio/third_party/ooura/fft_size_128/ooura_fft_sse2.cc>
    common_audio/third_party/ooura/fft_size_256/fft4g.h common_audio/third_party/ooura/fft_size_256/fft4g.cc
    common_audio/third_party/spl_sqrt_floor/spl_sqrt_floor.h common_audio/third_party/spl_sqrt_floor/spl_sqrt_floor.c

    rtc_base/checks.h rtc_base/checks.cc
    rtc_base/event_tracer.h rtc_base/event_tracer.cc
    rtc_base/event.h rtc_base/event.cc
    rtc_base/logging.h rtc_base/logging.cc
    rtc_base/platform_thread_types.h rtc_base/platform_thread_types.cc
    rtc_base/platform_thread.h rtc_base/platform_thread.cc
    rtc_base/race_checker.h rtc_base/race_checker.cc
    rtc_base/string_encode.h rtc_base/string_encode.cc
    rtc_base/string_to_number.h rtc_base/string_to_number.cc
    rtc_base/string_utils.h rtc_base/string_utils.cc
    rtc_base/system_time.h rtc_base/system_time.cc
    rtc_base/time_utils.h rtc_base/time_utils.cc
    $<$<PLATFORM_ID:Windows>:rtc_base/win32.h rtc_base/win32.cc>

    rtc_base/containers/flat_tree.h rtc_base/containers/flat_tree.cc

    rtc_base/experiments/field_trial_parser.h rtc_base/experiments/field_trial_parser.cc

    rtc_base/memory/aligned_malloc.h rtc_base/memory/aligned_malloc.cc

    rtc_base/strings/string_builder.h rtc_base/strings/string_builder.cc

    rtc_base/synchronization/sequence_checker_internal.h rtc_base/synchronization/sequence_checker_internal.cc
    rtc_base/synchronization/yield_policy.h rtc_base/synchronization/yield_policy.cc

    rtc_base/system/file_wrapper.h rtc_base/system/file_wrapper.cc
    rtc_base/system/warn_current_thread_is_deadlocked.h rtc_base/system/warn_current_thread_is_deadlocked.cc

    modules/audio_coding/codecs/isac/main/source/filter_functions.h modules/audio_coding/codecs/isac/main/source/filter_functions.c
    modules/audio_coding/codecs/isac/main/source/isac_vad.h modules/audio_coding/codecs/isac/main/source/isac_vad.c
    modules/audio_coding/codecs/isac/main/source/pitch_estimator.h modules/audio_coding/codecs/isac/main/source/pitch_estimator.c
    modules/audio_coding/codecs/isac/main/source/pitch_filter.h modules/audio_coding/codecs/isac/main/source/pitch_filter.c

    modules/audio_processing/audio_buffer.h modules/audio_processing/audio_buffer.cc
    modules/audio_processing/echo_control_mobile_impl.h modules/audio_processing/echo_control_mobile_impl.cc
    modules/audio_processing/high_pass_filter.h modules/audio_processing/high_pass_filter.cc
    modules/audio_processing/rms_level.h modules/audio_processing/rms_level.cc
    modules/audio_processing/splitting_filter.h modules/audio_processing/splitting_filter.cc
    modules/audio_processing/three_band_filter_bank.h modules/audio_processing/three_band_filter_bank.cc

    modules/audio_processing/include/aec_dump.h modules/audio_processing/include/aec_dump.cc
    modules/audio_processing/include/audio_frame_proxies.h modules/audio_processing/include/audio_frame_proxies.cc

    $<$<PLATFORM_ID:Windows>:modules/audio_processing/aec3/adaptive_fir_filter_avx2.cc>
    $<$<PLATFORM_ID:Windows>:modules/audio_processing/aec3/adaptive_fir_filter_erl_avx2.cc>
    modules/audio_processing/aec3/adaptive_fir_filter_erl.h modules/audio_processing/aec3/adaptive_fir_filter_erl.cc
    modules/audio_processing/aec3/adaptive_fir_filter.h modules/audio_processing/aec3/adaptive_fir_filter.cc
    modules/audio_processing/aec3/aec_state.h modules/audio_processing/aec3/aec_state.cc
    modules/audio_processing/aec3/aec3_common.h modules/audio_processing/aec3/aec3_common.cc
    modules/audio_processing/aec3/aec3_fft.h modules/audio_processing/aec3/aec3_fft.cc
    modules/audio_processing/aec3/alignment_mixer.h modules/audio_processing/aec3/alignment_mixer.cc
    modules/audio_processing/aec3/api_call_jitter_metrics.h modules/audio_processing/aec3/api_call_jitter_metrics.cc
    modules/audio_processing/aec3/block_buffer.h modules/audio_processing/aec3/block_buffer.cc
    modules/audio_processing/aec3/block_delay_buffer.h modules/audio_processing/aec3/block_delay_buffer.cc
    modules/audio_processing/aec3/block_framer.h modules/audio_processing/aec3/block_framer.cc
    modules/audio_processing/aec3/block_processor_metrics.h modules/audio_processing/aec3/block_processor_metrics.cc
    modules/audio_processing/aec3/block_processor.h modules/audio_processing/aec3/block_processor.cc
    modules/audio_processing/aec3/clockdrift_detector.h modules/audio_processing/aec3/clockdrift_detector.cc
    modules/audio_processing/aec3/coarse_filter_update_gain.h modules/audio_processing/aec3/coarse_filter_update_gain.cc
    modules/audio_processing/aec3/comfort_noise_generator.h modules/audio_processing/aec3/comfort_noise_generator.cc
    modules/audio_processing/aec3/config_selector.h modules/audio_processing/aec3/config_selector.cc
    modules/audio_processing/aec3/decimator.h modules/audio_processing/aec3/decimator.cc
    modules/audio_processing/aec3/dominant_nearend_detector.h modules/audio_processing/aec3/dominant_nearend_detector.cc
    modules/audio_processing/aec3/downsampled_render_buffer.h modules/audio_processing/aec3/downsampled_render_buffer.cc
    modules/audio_processing/aec3/echo_audibility.h modules/audio_processing/aec3/echo_audibility.cc
    modules/audio_processing/aec3/echo_canceller3.h modules/audio_processing/aec3/echo_canceller3.cc
    modules/audio_processing/aec3/echo_path_delay_estimator.h modules/audio_processing/aec3/echo_path_delay_estimator.cc
    modules/audio_processing/aec3/echo_path_variability.h modules/audio_processing/aec3/echo_path_variability.cc
    modules/audio_processing/aec3/echo_remover_metrics.h modules/audio_processing/aec3/echo_remover_metrics.cc
    modules/audio_processing/aec3/echo_remover.h modules/audio_processing/aec3/echo_remover.cc
    modules/audio_processing/aec3/erl_estimator.h modules/audio_processing/aec3/erl_estimator.cc
    modules/audio_processing/aec3/erle_estimator.h modules/audio_processing/aec3/erle_estimator.cc
    modules/audio_processing/aec3/fft_buffer.h modules/audio_processing/aec3/fft_buffer.cc
    $<$<PLATFORM_ID:Windows>:modules/audio_processing/aec3/fft_data_avx2.cc>
    modules/audio_processing/aec3/filter_analyzer.h modules/audio_processing/aec3/filter_analyzer.cc
    modules/audio_processing/aec3/frame_blocker.h modules/audio_processing/aec3/frame_blocker.cc
    modules/audio_processing/aec3/fullband_erle_estimator.h modules/audio_processing/aec3/fullband_erle_estimator.cc
    $<$<PLATFORM_ID:Windows>:modules/audio_processing/aec3/matched_filter_avx2.cc>
    modules/audio_processing/aec3/matched_filter_lag_aggregator.h modules/audio_processing/aec3/matched_filter_lag_aggregator.cc
    modules/audio_processing/aec3/matched_filter.h modules/audio_processing/aec3/matched_filter.cc
    modules/audio_processing/aec3/moving_average.h modules/audio_processing/aec3/moving_average.cc
    modules/audio_processing/aec3/multi_channel_content_detector.h modules/audio_processing/aec3/multi_channel_content_detector.cc
    modules/audio_processing/aec3/refined_filter_update_gain.h modules/audio_processing/aec3/refined_filter_update_gain.cc
    modules/audio_processing/aec3/render_buffer.h modules/audio_processing/aec3/render_buffer.cc
    modules/audio_processing/aec3/render_delay_buffer.h modules/audio_processing/aec3/render_delay_buffer.cc
    modules/audio_processing/aec3/render_delay_controller_metrics.h modules/audio_processing/aec3/render_delay_controller_metrics.cc
    modules/audio_processing/aec3/render_delay_controller.h modules/audio_processing/aec3/render_delay_controller.cc
    modules/audio_processing/aec3/render_signal_analyzer.h modules/audio_processing/aec3/render_signal_analyzer.cc
    modules/audio_processing/aec3/residual_echo_estimator.h modules/audio_processing/aec3/residual_echo_estimator.cc
    modules/audio_processing/aec3/reverb_decay_estimator.h modules/audio_processing/aec3/reverb_decay_estimator.cc
    modules/audio_processing/aec3/reverb_frequency_response.h modules/audio_processing/aec3/reverb_frequency_response.cc
    modules/audio_processing/aec3/reverb_model_estimator.h modules/audio_processing/aec3/reverb_model_estimator.cc
    modules/audio_processing/aec3/reverb_model.h modules/audio_processing/aec3/reverb_model.cc
    modules/audio_processing/aec3/signal_dependent_erle_estimator.h modules/audio_processing/aec3/signal_dependent_erle_estimator.cc
    modules/audio_processing/aec3/spectrum_buffer.h modules/audio_processing/aec3/spectrum_buffer.cc
    modules/audio_processing/aec3/stationarity_estimator.h modules/audio_processing/aec3/stationarity_estimator.cc
    modules/audio_processing/aec3/subband_erle_estimator.h modules/audio_processing/aec3/subband_erle_estimator.cc
    modules/audio_processing/aec3/subband_nearend_detector.h modules/audio_processing/aec3/subband_nearend_detector.cc
    modules/audio_processing/aec3/subtractor_output_analyzer.h modules/audio_processing/aec3/subtractor_output_analyzer.cc
    modules/audio_processing/aec3/subtractor_output.h modules/audio_processing/aec3/subtractor_output.cc
    modules/audio_processing/aec3/subtractor.h modules/audio_processing/aec3/subtractor.cc
    modules/audio_processing/aec3/suppression_filter.h modules/audio_processing/aec3/suppression_filter.cc
    modules/audio_processing/aec3/suppression_gain.h modules/audio_processing/aec3/suppression_gain.cc
    modules/audio_processing/aec3/transparent_mode.h modules/audio_processing/aec3/transparent_mode.cc
    $<$<PLATFORM_ID:Windows>:modules/audio_processing/aec3/vector_math_avx2.cc>

    modules/audio_processing/aecm/aecm_core.h modules/audio_processing/aecm/aecm_core.cc modules/audio_processing/aecm/aecm_core_c.cc
    $<$<BOOL:${CROSS_BUILD}>:modules/audio_processing/aecm/aecm_core_neon.cc>
    modules/audio_processing/aecm/echo_control_mobile.h  modules/audio_processing/aecm/echo_control_mobile.cc

    modules/audio_processing/capture_levels_adjuster/audio_samples_scaler.h modules/audio_processing/capture_levels_adjuster/audio_samples_scaler.cc
    modules/audio_processing/capture_levels_adjuster/capture_levels_adjuster.h modules/audio_processing/capture_levels_adjuster/capture_levels_adjuster.cc

    modules/audio_processing/logging/apm_data_dumper.h modules/audio_processing/logging/apm_data_dumper.cc

    modules/audio_processing/ns/fast_math.h modules/audio_processing/ns/fast_math.cc
    modules/audio_processing/ns/histograms.h modules/audio_processing/ns/histograms.cc
    modules/audio_processing/ns/noise_estimator.h modules/audio_processing/ns/noise_estimator.cc
    modules/audio_processing/ns/noise_suppressor.h modules/audio_processing/ns/noise_suppressor.cc
    modules/audio_processing/ns/ns_fft.h modules/audio_processing/ns/ns_fft.cc
    modules/audio_processing/ns/prior_signal_model_estimator.h modules/audio_processing/ns/prior_signal_model_estimator.cc
    modules/audio_processing/ns/prior_signal_model.h modules/audio_processing/ns/prior_signal_model.cc
    modules/audio_processing/ns/quantile_noise_estimator.h modules/audio_processing/ns/quantile_noise_estimator.cc
    modules/audio_processing/ns/signal_model_estimator.h modules/audio_processing/ns/signal_model_estimator.cc
    modules/audio_processing/ns/signal_model.h modules/audio_processing/ns/signal_model.cc
    modules/audio_processing/ns/speech_probability_estimator.h modules/audio_processing/ns/speech_probability_estimator.cc
    modules/audio_processing/ns/suppression_params.h modules/audio_processing/ns/suppression_params.cc
    modules/audio_processing/ns/wiener_filter.h modules/audio_processing/ns/wiener_filter.cc

    modules/audio_processing/utility/cascaded_biquad_filter.h modules/audio_processing/utility/cascaded_biquad_filter.cc
    modules/audio_processing/utility/delay_estimator_wrapper.h  modules/audio_processing/utility/delay_estimator_wrapper.cc
    modules/audio_processing/utility/delay_estimator.h modules/audio_processing/utility/delay_estimator.cc

    modules/audio_processing/vad/gmm.h modules/audio_processing/vad/gmm.cc
    modules/audio_processing/vad/pitch_based_vad.h modules/audio_processing/vad/pitch_based_vad.cc
    modules/audio_processing/vad/pitch_internal.h modules/audio_processing/vad/pitch_internal.cc
    modules/audio_processing/vad/pole_zero_filter.h modules/audio_processing/vad/pole_zero_filter.cc
    modules/audio_processing/vad/standalone_vad.h modules/audio_processing/vad/standalone_vad.cc
    modules/audio_processing/vad/vad_audio_proc.h modules/audio_processing/vad/vad_audio_proc.cc
    modules/audio_processing/vad/vad_circular_buffer.h modules/audio_processing/vad/vad_circular_buffer.cc
    modules/audio_processing/vad/voice_activity_detector.h modules/audio_processing/vad/voice_activity_detector.cc

    modules/third_party/fft/fft.h modules/third_party/fft/fft.c

    system_wrappers/source/cpu_features_linux.cc
    system_wrappers/source/cpu_features.cc
    system_wrappers/source/field_trial.cc
    system_wrappers/source/metrics.cc
)

if(NOT CROSS_BUILD)
    target_compile_options(VocieProcess 
        PRIVATE -Wpsabi -mavx2 -mfma
    )
endif()

target_compile_definitions(VocieProcess
    PRIVATE NOMINMAX # <windows.h>
    # PRIVATE RTC_DISABLE_LOGGING
    # PUBLIC RTC_DISABLE_METRICS
    PUBLIC WEBRTC_APM_DEBUG_DUMP=1
    $<$<PLATFORM_ID:Windows>:WEBRTC_WIN>
    $<$<PLATFORM_ID:Linux>:WEBRTC_POSIX WEBRTC_LINUX>
    $<$<BOOL:${CROSS_BUILD}>:WEBRTC_HAS_NEON>
)

target_include_directories(VocieProcess
    PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
    INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
)

target_link_libraries(VocieProcess
    PRIVATE absl::optional
)
