From aaf0bf5aa83f7bb999808459b1d99da9c7acad13 Mon Sep 17 00:00:00 2001 From: Jim Gustafson Date: Tue, 27 Feb 2024 17:01:48 -0800 Subject: [PATCH] Move all DRED encoding/decoding files to dnn/ dir (#1) --- opus_ng/opus/BUILD.gn | 6 +-- opus_ng/setup.sh | 2 +- ringrtc/opus/BUILD.gn | 101 ++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 102 insertions(+), 7 deletions(-) diff --git a/opus_ng/opus/BUILD.gn b/opus_ng/opus/BUILD.gn index 27028ef18f..b0fd0a8fd3 100644 --- a/opus_ng/opus/BUILD.gn +++ b/opus_ng/opus/BUILD.gn @@ -474,9 +474,9 @@ static_library("opus") { "src/dnn/dred_rdovae_dec.c", "src/dnn/dred_rdovae_dec_data.c", "src/dnn/dred_rdovae_stats_data.c", - "src/silk/dred_encoder.c", - "src/silk/dred_coding.c", - "src/silk/dred_decoder.c", + "src/dnn/dred_encoder.c", + "src/dnn/dred_coding.c", + "src/dnn/dred_decoder.c", "src/dnn/nnet_arch.h", "src/dnn/nnet_default.c", "src/dnn/pitchdnn_data.c", diff --git a/opus_ng/setup.sh b/opus_ng/setup.sh index d77fd462ca..36b533def7 100755 --- a/opus_ng/setup.sh +++ b/opus_ng/setup.sh @@ -6,7 +6,7 @@ cd ./src/opus_ng/opus rm -rf src git clone -b main https://gitlab.xiph.org/xiph/opus.git src cd ./src -git reset --hard 57901a6758c3bdc7481d61669812bde13d2085b8 +git reset --hard dcce2fd455b1f407bf4e1347ce5358a6d0096bd2 ./dnn/download_model.sh "735117b" popd rm -rf ./src/third_party/opus diff --git a/ringrtc/opus/BUILD.gn b/ringrtc/opus/BUILD.gn index d0ee667956..bc225c0cb7 100644 --- a/ringrtc/opus/BUILD.gn +++ b/ringrtc/opus/BUILD.gn @@ -5,10 +5,14 @@ import("//build/config/arm.gni") import("//testing/test.gni") +declare_args() { + opus_codec_support_dred = false +} + # If ARM optimizations shall be used to accelerate performance. use_opus_arm_optimization = current_cpu == "arm" || - (current_cpu == "arm64" && (is_fuchsia || is_ios || is_win)) + (current_cpu == "arm64" && (is_fuchsia || is_ios || is_win || is_mac)) # NaCl, unlike Chrome, doesn't target SSE2 minimum, so skip optimizations for # the sake of simplicity. @@ -30,6 +34,7 @@ config("opus_private_config") { "OPUS_BUILD", "OPUS_EXPORT=", "ENABLE_HARDENING", + "DISABLE_DEBUG_FLOAT", # Prefer alloca() over variable length arrays which are often inefficient; # the opus code will automatically handle this correctly per-platform. @@ -40,6 +45,7 @@ config("opus_private_config") { include_dirs = [ "src", "src/celt", + "src/dnn", "src/silk", "src/silk/fixed", "src/silk/float", @@ -47,6 +53,13 @@ config("opus_private_config") { cflags = [] + if (opus_codec_support_dred) { + defines += [ + "ENABLE_DEEP_PLC", + "ENABLE_DRED", + ] + } + if (is_win) { defines += [ "inline=__inline" ] @@ -76,6 +89,7 @@ config("opus_private_config") { # Run Time CPU Detections (RTCD) is always enabled for x86. "OPUS_HAVE_RTCD", "CPU_INFO_BY_ASM", + "FLOAT_APPROX", # Chrome always targets SSE2+. "OPUS_X86_MAY_HAVE_SSE", @@ -88,7 +102,7 @@ config("opus_private_config") { # At present libopus has no AVX functions so no sources are add for this, # if you see linker errors on AVX code the this flag is why. - "OPUS_X86_MAY_HAVE_AVX", + "OPUS_X86_MAY_HAVE_AVX2", ] } @@ -179,6 +193,11 @@ if (use_opus_x86_optimization) { "src/silk/x86/VAD_sse4_1.c", "src/silk/x86/VQ_WMat_EC_sse4_1.c", ] + if (opus_codec_support_dred) { + sources += [ + "src/dnn/x86/nnet_sse4_1.c", + ] + } configs -= [ "//build/config/compiler:chromium_code" ] configs += [ "//build/config/compiler:no_chromium_code" ] @@ -187,11 +206,44 @@ if (use_opus_x86_optimization) { ":opus_config", ] + if (!is_debug) { + configs -= [ "//build/config/compiler:default_optimization" ] + configs += [ "//build/config/compiler:optimize_speed" ] + } + if (!is_win || is_clang) { cflags = [ "-msse4.1" ] } } - # TODO(dalecurtis): If libopus ever adds AVX support, add an opus_avx block. + + source_set("opus_avx2") { + sources = [ + "src/celt/x86/pitch_avx.c", + "src/silk/x86/NSQ_del_dec_avx2.c", + "src/silk/float/x86/inner_product_FLP_avx2.c", + ] + if (opus_codec_support_dred) { + sources += [ + "src/dnn/x86/nnet_avx2.c", + ] + } + + configs -= [ "//build/config/compiler:chromium_code" ] + configs += [ "//build/config/compiler:no_chromium_code" ] + configs += [ + ":opus_private_config", + ":opus_config", + ] + + if (!is_debug) { + configs -= [ "//build/config/compiler:default_optimization" ] + configs += [ "//build/config/compiler:optimize_speed" ] + } + + if (!is_win || is_clang) { + cflags = [ "-mavx", "-mfma", "-mavx2" ] + } + } } # Note: Do not add any defines or include_dirs to this target, those should all @@ -350,6 +402,7 @@ static_library("opus") { "src/silk/typedef.h", "src/src/analysis.c", "src/src/analysis.h", + "src/src/extensions.c", "src/src/mapping_matrix.c", "src/src/mapping_matrix.h", "src/src/mlp.c", @@ -402,6 +455,34 @@ static_library("opus") { "src/silk/float/warped_autocorrelation_FLP.c", "src/silk/float/wrappers_FLP.c", ] + + if (opus_codec_support_dred) { + sources += [ + "src/dnn/burg.c", + "src/dnn/freq.c", + "src/dnn/fargan.c", + "src/dnn/fargan_data.c", + "src/dnn/lpcnet_enc.c", + "src/dnn/lpcnet_plc.c", + "src/dnn/lpcnet_tables.c", + "src/dnn/nnet.c", + "src/dnn/plc_data.c", + "src/dnn/parse_lpcnet_weights.c", + "src/dnn/pitchdnn.c", + "src/dnn/dred_rdovae_enc.c", + "src/dnn/dred_rdovae_enc_data.c", + "src/dnn/dred_rdovae_dec.c", + "src/dnn/dred_rdovae_dec_data.c", + "src/dnn/dred_rdovae_stats_data.c", + "src/dnn/dred_encoder.c", + "src/dnn/dred_coding.c", + "src/dnn/dred_decoder.c", + "src/dnn/nnet_arch.h", + "src/dnn/nnet_default.c", + "src/dnn/pitchdnn_data.c", + "src/dnn/pitchdnn_data.h", + ] + } configs -= [ "//build/config/compiler:chromium_code" ] configs += [ @@ -436,7 +517,14 @@ static_library("opus") { "src/silk/x86/main_sse.h", "src/silk/x86/x86_silk_map.c", ] + if (opus_codec_support_dred) { + sources += [ + "src/dnn/x86/x86_dnn_map.c", + "src/dnn/x86/nnet_sse2.c", + ] + } deps += [ ":opus_sse41" ] + deps += [ ":opus_avx2" ] } if (use_opus_arm_optimization) { @@ -482,6 +570,13 @@ static_library("opus") { "src/silk/arm/biquad_alt_arm.h", "src/silk/arm/biquad_alt_neon_intr.c", ] + if (opus_codec_support_dred) { + sources += [ + "src/dnn/arm/arm_dnn_map.c", + "src/dnn/arm/nnet_dotprod.c", + "src/dnn/arm/nnet_neon.c", + ] + } } } }