WebKit Bugzilla
Attachment 357897 Details for
Bug 192867
: Resync opus to M72
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-192867-20181220162042.patch (text/plain), 1.61 MB, created by
youenn fablet
on 2018-12-20 16:20:45 PST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
youenn fablet
Created:
2018-12-20 16:20:45 PST
Size:
1.61 MB
patch
obsolete
>Subversion Revision: 239467 >diff --git a/Source/ThirdParty/libwebrtc/ChangeLog b/Source/ThirdParty/libwebrtc/ChangeLog >index e55dc3ac6aafe17966f741905485ec777295e563..ab95d32ba244ca79a3b1985a9a6ee7c08391fa9c 100644 >--- a/Source/ThirdParty/libwebrtc/ChangeLog >+++ b/Source/ThirdParty/libwebrtc/ChangeLog >@@ -1,3 +1,13 @@ >+2018-12-20 Youenn Fablet <youenn@apple.com> >+ >+ Resync opus to M72 >+ https://bugs.webkit.org/show_bug.cgi?id=192867 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * Configurations/opus.xcconfig: Updated compilation flag. >+ * Source/third_party/opus: Resynced to Chrome M72 branch. >+ > 2018-12-20 Youenn Fablet <youenn@apple.com> > > Resync libsrtp to M72 >diff --git a/Source/ThirdParty/libwebrtc/Configurations/opus.xcconfig b/Source/ThirdParty/libwebrtc/Configurations/opus.xcconfig >index d058c76406ab438765767af1a1883639ba8fb9cf..443d55c85c313fc6e89911cd06a498e01823d697 100644 >--- a/Source/ThirdParty/libwebrtc/Configurations/opus.xcconfig >+++ b/Source/ThirdParty/libwebrtc/Configurations/opus.xcconfig >@@ -13,11 +13,12 @@ INSTALL_PATH = /usr/local/lib; > PUBLIC_HEADERS_FOLDER_PATH = /usr/local/include/libwebrtc; > USE_HEADERMAP = NO; > WARNING_CFLAGS = -Wno-incompatible-pointer-types $(inherited) >-GCC_PREPROCESSOR_DEFINITIONS = VAR_ARRAYS OPUS_BUILD OPUS_EXPORT= HAVE_LRINT HAVE_LRINTF OPUS_X86_MAY_HAVE_SSE2 $(inherited); >+GCC_PREPROCESSOR_DEFINITIONS = VAR_ARRAYS OPUS_BUILD OPUS_EXPORT= HAVE_LRINT HAVE_LRINTF $(inherited); > GCC_PREPROCESSOR_DEFINITIONS[arch=arm64*] = $(inherited) OPUS_ARM_PRESUME_AARCH64_NEON_INTR; >-GCC_PREPROCESSOR_DEFINITIONS[arch=x86_64] = $(inherited) $(SSE4_FLAG); >+GCC_PREPROCESSOR_DEFINITIONS[arch=x86_64] = $(inherited) OPUS_X86_MAY_HAVE_SSE2 OPUS_X86_PRESUME_SSE2 $(SSE4_FLAG); > >-EXCLUDED_SOURCE_FILE_NAMES[sdk=iphone*] = *_sse.c *_sse2.c; >+EXCLUDED_SOURCE_FILE_NAMES[sdk=iphonesimulator*] = *_sse.c *_sse4_1.c x86_silk_map.c; >+EXCLUDED_SOURCE_FILE_NAMES[sdk=iphoneos*] = *_sse.c *_sse2.c *_sse4_1.c x86_silk_map.c; > EXCLUDED_SOURCE_FILE_NAMES[sdk=macosx*] = $(EXCLUDED_SOURCE_FILE_NAMES_macosx_$(TARGET_MAC_OS_X_VERSION_MAJOR)); > > // The iOS Simulator can't use SSE4 intrinsics, but macOS can. >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/BUILD.gn b/Source/ThirdParty/libwebrtc/Source/third_party/opus/BUILD.gn >index 3bb5e0df499e92c269ff84536333fbf7aa45ba25..b54f85688230e3b17c1adfe0130e85fad49e0a2a 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/BUILD.gn >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/BUILD.gn >@@ -9,12 +9,19 @@ import("//testing/test.gni") > use_opus_fixed_point = current_cpu == "arm" || current_cpu == "arm64" > > # If ARM optimizations shall be used to accelerate performance. >-use_opus_arm_optimization = current_cpu == "arm" >+# TODO(scottmg): Disabled on Fuchsia for now, see https://crbug.com/775272. >+use_opus_arm_optimization = >+ current_cpu == "arm" || (current_cpu == "arm64" && is_ios) >+ >+# NaCl, unlike Chrome, doesn't target SSE2 minimum, so skip optimizations for >+# the sake of simplicity. >+use_opus_x86_optimization = >+ !is_nacl && (current_cpu == "x86" || current_cpu == "x64") > > # If OPUS Run Time CPU Detections (RTCD) shall be used. > # Based on the conditions in celt/arm/armcpu.c: > # defined(_MSC_VER) || defined(__linux__). >-use_opus_rtcd = current_cpu == "arm" && (is_win || is_android || is_linux) >+use_opus_arm_rtcd = current_cpu == "arm" && (is_win || is_android || is_linux) > > config("opus_config") { > include_dirs = [ "src/include" ] >@@ -24,6 +31,106 @@ config("opus_config") { > } > } > >+config("opus_private_config") { >+ defines = [ >+ "OPUS_BUILD", >+ "OPUS_EXPORT=", >+ >+ # Prefer alloca() over variable length arrays which are often inefficient; >+ # the opus code will automatically handle this correctly per-platform. >+ "USE_ALLOCA", >+ "HAVE_ALLOCA_H", >+ ] >+ >+ include_dirs = [ >+ "src", >+ "src/celt", >+ "src/silk", >+ ] >+ >+ cflags = [] >+ >+ if (is_win) { >+ defines += [ "inline=__inline" ] >+ >+ cflags += [ >+ "/wd4305", # Disable truncation warning in celt/pitch.c . >+ "/wd4334", # Disable 32-bit shift warning in src/opus_encoder.c . >+ ] >+ } else { >+ defines += [ >+ "HAVE_LRINT", >+ "HAVE_LRINTF", >+ ] >+ } >+ >+ if (is_debug) { >+ # Turn off a warning in opus_decoder.c when compiling without optimization. >+ defines += [ "OPUS_WILL_BE_SLOW" ] >+ } >+ >+ if (use_opus_x86_optimization) { >+ defines += [ >+ # Run Time CPU Detections (RTCD) is always enabled for x86. >+ "OPUS_HAVE_RTCD", >+ "CPU_INFO_BY_ASM", >+ >+ # Chrome always targets SSE2+. >+ "OPUS_X86_MAY_HAVE_SSE", >+ "OPUS_X86_MAY_HAVE_SSE2", >+ "OPUS_X86_PRESUME_SSE", >+ "OPUS_X86_PRESUME_SSE2", >+ >+ # Some systems may have SSE4.1+ support. >+ "OPUS_X86_MAY_HAVE_SSE4_1", >+ >+ # 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", >+ ] >+ } >+ >+ if (use_opus_fixed_point) { >+ defines += [ "FIXED_POINT" ] >+ include_dirs += [ "src/silk/fixed" ] >+ } else { >+ include_dirs += [ "src/silk/float" ] >+ } >+ >+ if (use_opus_arm_optimization) { >+ if (current_cpu == "arm") { >+ defines += [ >+ "OPUS_ARM_ASM", >+ "OPUS_ARM_INLINE_ASM", >+ "OPUS_ARM_INLINE_EDSP", >+ ] >+ } >+ >+ if (use_opus_arm_rtcd) { >+ defines += [ >+ "OPUS_ARM_MAY_HAVE_EDSP", >+ "OPUS_ARM_MAY_HAVE_MEDIA", >+ "OPUS_HAVE_RTCD", >+ ] >+ } >+ >+ if (arm_use_neon) { >+ defines += [ >+ "OPUS_ARM_MAY_HAVE_NEON", >+ "OPUS_ARM_MAY_HAVE_NEON_INTR", >+ ] >+ } >+ >+ if (is_ios && current_cpu == "arm64") { >+ # Runtime detection of CPU features not available on iOS. >+ defines += [ >+ "OPUS_ARM_PRESUME_NEON_INTR", >+ "OPUS_ARM_PRESUME_AARCH64_NEON_INTR", >+ ] >+ } >+ } >+} >+ > config("opus_test_config") { > include_dirs = [ > "src/celt", >@@ -41,7 +148,7 @@ config("opus_test_config") { > } > } > >-if (use_opus_rtcd) { >+if (use_opus_arm_rtcd) { > action("convert_rtcd_assembler") { > script = "convert_rtcd_assembler.py" > outputs = [ >@@ -56,6 +163,31 @@ if (use_opus_rtcd) { > } > } > >+if (use_opus_x86_optimization) { >+ source_set("opus_sse41") { >+ sources = [ >+ "src/celt/x86/pitch_sse4_1.c", >+ "src/silk/x86/NSQ_del_dec_sse.c", >+ "src/silk/x86/NSQ_sse.c", >+ "src/silk/x86/VAD_sse.c", >+ ] >+ >+ configs -= [ "//build/config/compiler:chromium_code" ] >+ configs += [ "//build/config/compiler:no_chromium_code" ] >+ configs += [ >+ ":opus_private_config", >+ ":opus_config", >+ ] >+ >+ if (!is_win || is_clang) { >+ cflags = [ "-msse4.1" ] >+ } >+ } >+ # TODO(dalecurtis): If libopus ever adds AVX support, add an opus_avx block. >+} >+ >+# Note: Do not add any defines or include_dirs to this target, those should all >+# go in the opus_private_config so they can be shared with intrinsic targets. > static_library("opus") { > sources = [ > "src/celt/_kiss_fft_guts.h", >@@ -115,6 +247,7 @@ static_library("opus") { > "src/silk/HP_variable_cutoff.c", > "src/silk/Inlines.h", > "src/silk/LPC_analysis_filter.c", >+ "src/silk/LPC_fit.c", > "src/silk/LPC_inv_pred_gain.c", > "src/silk/LP_variable_cutoff.c", > "src/silk/MacroCount.h", >@@ -221,47 +354,14 @@ static_library("opus") { > "src/src/tansig_table.h", > ] > >- defines = [ >- "OPUS_BUILD", >- "OPUS_EXPORT=", >- ] >- >- include_dirs = [ >- "src/celt", >- "src/silk", >- ] >- > configs -= [ "//build/config/compiler:chromium_code" ] >- configs += [ "//build/config/compiler:no_chromium_code" ] >+ configs += [ >+ "//build/config/compiler:no_chromium_code", >+ ":opus_private_config", >+ ] > public_configs = [ ":opus_config" ] >- cflags = [] >- >- if (is_win) { >- defines += [ >- "USE_ALLOCA", >- "inline=__inline", >- ] > >- cflags += [ >- "/wd4305", # Disable truncation warning in celt/pitch.c . >- "/wd4334", # Disable 32-bit shift warning in src/opus_encoder.c . >- ] >- } else { >- defines += [ >- "HAVE_LRINT", >- "HAVE_LRINTF", >- "VAR_ARRAYS", >- ] >- } >- >- if (is_posix && !is_android) { >- # Suppress a warning given by opus_decoder.c that tells us >- # optimizations are turned off. >- cflags += [ "-Wno-#pragma-messages" ] >- } >- >- if (!is_debug && is_posix && >- (current_cpu == "arm" || current_cpu == "arm64")) { >+ if (!is_debug && (current_cpu == "arm" || current_cpu == "arm64")) { > configs -= [ "//build/config/compiler:default_optimization" ] > > # TODO(crbug.com/621335) Rework this so that we don't have the confusion >@@ -269,6 +369,26 @@ static_library("opus") { > configs += [ "//build/config/compiler:optimize_speed" ] > } > >+ deps = [] >+ >+ if (use_opus_x86_optimization) { >+ sources += [ >+ "src/celt/x86/celt_lpc_sse.h", >+ "src/celt/x86/pitch_sse.c", >+ "src/celt/x86/pitch_sse.h", >+ "src/celt/x86/pitch_sse2.c", >+ "src/celt/x86/vq_sse.h", >+ "src/celt/x86/vq_sse2.c", >+ "src/celt/x86/x86_celt_map.c", >+ "src/celt/x86/x86cpu.c", >+ "src/celt/x86/x86cpu.h", >+ "src/silk/x86/SigProc_FIX_sse.h", >+ "src/silk/x86/main_sse.h", >+ "src/silk/x86/x86_silk_map.c", >+ ] >+ deps += [ ":opus_sse41" ] >+ } >+ > if (use_opus_fixed_point) { > sources += [ > "src/silk/fixed/LTP_analysis_filter_FIX.c", >@@ -287,22 +407,16 @@ static_library("opus") { > "src/silk/fixed/main_FIX.h", > "src/silk/fixed/noise_shape_analysis_FIX.c", > "src/silk/fixed/pitch_analysis_core_FIX.c", >- "src/silk/fixed/prefilter_FIX.c", > "src/silk/fixed/process_gains_FIX.c", > "src/silk/fixed/regularize_correlations_FIX.c", > "src/silk/fixed/residual_energy16_FIX.c", > "src/silk/fixed/residual_energy_FIX.c", > "src/silk/fixed/schur64_FIX.c", > "src/silk/fixed/schur_FIX.c", >- "src/silk/fixed/solve_LS_FIX.c", > "src/silk/fixed/structs_FIX.h", > "src/silk/fixed/vector_ops_FIX.c", > "src/silk/fixed/warped_autocorrelation_FIX.c", > ] >- >- defines += [ "FIXED_POINT" ] >- >- include_dirs += [ "src/silk/fixed" ] > } else { > sources += [ > "src/silk/float/LPC_analysis_filter_FLP.c", >@@ -323,25 +437,20 @@ static_library("opus") { > "src/silk/float/find_pred_coefs_FLP.c", > "src/silk/float/inner_product_FLP.c", > "src/silk/float/k2a_FLP.c", >- "src/silk/float/levinsondurbin_FLP.c", > "src/silk/float/main_FLP.h", > "src/silk/float/noise_shape_analysis_FLP.c", > "src/silk/float/pitch_analysis_core_FLP.c", >- "src/silk/float/prefilter_FLP.c", > "src/silk/float/process_gains_FLP.c", > "src/silk/float/regularize_correlations_FLP.c", > "src/silk/float/residual_energy_FLP.c", > "src/silk/float/scale_copy_vector_FLP.c", > "src/silk/float/scale_vector_FLP.c", > "src/silk/float/schur_FLP.c", >- "src/silk/float/solve_LS_FLP.c", > "src/silk/float/sort_FLP.c", > "src/silk/float/structs_FLP.h", > "src/silk/float/warped_autocorrelation_FLP.c", > "src/silk/float/wrappers_FLP.c", > ] >- >- include_dirs += [ "src/silk/float" ] > } > > if (use_opus_arm_optimization) { >@@ -359,39 +468,34 @@ static_library("opus") { > "src/silk/arm/macros_armv5e.h", > ] > >- defines += [ >- "OPUS_ARM_ASM", >- "OPUS_ARM_INLINE_ASM", >- "OPUS_ARM_INLINE_EDSP", >- ] >- >- if (use_opus_rtcd) { >+ if (use_opus_arm_rtcd) { > sources += [ > "$target_gen_dir/celt_pitch_xcorr_arm_gnu.S", > "src/celt/arm/arm_celt_map.c", > "src/celt/arm/armcpu.c", > "src/celt/arm/armcpu.h", >- "src/celt/arm/celt_neon_intr.c", > "src/celt/arm/fft_arm.h", > "src/celt/arm/mdct_arm.h", > "src/celt/arm/pitch_arm.h", >- "src/silk/arm/NSQ_neon.c", >- "src/silk/arm/NSQ_neon.h", > "src/silk/arm/arm_silk_map.c", > ] >+ deps += [ ":convert_rtcd_assembler" ] >+ } > >- include_dirs += [ "src" ] >- >- defines += [ >- "OPUS_ARM_MAY_HAVE_EDSP", >- "OPUS_ARM_MAY_HAVE_MEDIA", >- "OPUS_ARM_MAY_HAVE_NEON", >- "OPUS_ARM_MAY_HAVE_NEON_INTR", >- "OPUS_HAVE_RTCD", >- ] >- >- deps = [ >- ":convert_rtcd_assembler", >+ if (arm_use_neon) { >+ sources += [ >+ "src/celt/arm/celt_neon_intr.c", >+ "src/celt/arm/pitch_neon_intr.c", >+ "src/silk/arm/LPC_inv_pred_gain_arm.h", >+ "src/silk/arm/LPC_inv_pred_gain_neon_intr.c", >+ "src/silk/arm/NSQ_del_dec_arm.h", >+ "src/silk/arm/NSQ_del_dec_neon_intr.c", >+ "src/silk/arm/NSQ_neon.c", >+ "src/silk/arm/NSQ_neon.h", >+ "src/silk/arm/biquad_alt_arm.h", >+ "src/silk/arm/biquad_alt_neon_intr.c", >+ "src/silk/fixed/arm/warped_autocorrelation_FIX_arm.h", >+ "src/silk/fixed/arm/warped_autocorrelation_FIX_neon_intr.c", > ] > } > } >@@ -410,7 +514,6 @@ executable("opus_compare") { > > deps = [ > ":opus", >- "//build/config/sanitizers:deps", > "//build/win:default_exe_manifest", > ] > } >@@ -428,7 +531,6 @@ executable("opus_demo") { > > deps = [ > ":opus", >- "//build/config/sanitizers:deps", > "//build/win:default_exe_manifest", > ] > } >@@ -451,6 +553,7 @@ test("test_opus_api") { > > test("test_opus_encode") { > sources = [ >+ "src/tests/opus_encode_regressions.c", > "src/tests/test_opus_encode.c", > ] > >@@ -473,7 +576,7 @@ config("test_opus_decode_config") { > # marked as requiring a non-null value by the nonnull function attribute, > # and expects opus_decode() to fail. Disable the -Wnonnull option to avoid > # a compilation error if -Werror is specified. >- if (is_posix) { >+ if (is_clang) { > cflags = [ "-Wno-nonnull" ] > } > } >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/DEPS b/Source/ThirdParty/libwebrtc/Source/third_party/opus/DEPS >index 7e5bd26ee6928acc96e0352a4576562eea06128e..fffcaa5ffc3525827d4c87b22ea722ce9c023a8f 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/DEPS >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/DEPS >@@ -1,5 +1,7 @@ > include_rules = [ > "+arm", >+ "+celt", >+ "+fixed", > "+mips", > "+x86", > ] >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/README.chromium b/Source/ThirdParty/libwebrtc/Source/third_party/opus/README.chromium >index 7111d028c0d6f670291dc7115c9e5c6b38c3de8f..8bd3197af2732000c351de3f79861f3e9824edd1 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/README.chromium >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/README.chromium >@@ -1,6 +1,6 @@ > Name: opus >-URL: http://downloads.xiph.org/releases/opus/opus-1.1.3.tar.gz >-Version: 1.1.3 >+URL: https://git.xiph.org/?p=opus.git;a=snapshot;h=3fe744ea04fdcc418fb85c2c133d13372ebb019b;sf=tgz >+Version: 3fe744ea04fdcc418fb85c2c133d13372ebb019b > License: BSD > License File: src/COPYING > Security Critical: yes >@@ -14,7 +14,9 @@ encoding/decoding. > Local changes: > * copy .gitignore from https://git.xiph.org/?p=opus.git;a=tree > * set 'x' flags: "chmod 750 win32/genversion.bat" >-* Apply patches from >- https://git.xiph.org/?p=opus.git;a=commit;h=79e8f527b0344b0897a65be35e77f7885bd99409 >- https://git.xiph.org/?p=opus.git;a=commitdiff;h=e5ad26169502c1f0b067916e782c2b3fdea6fba9 >- https://git.xiph.org/?p=opus.git;a=commitdiff;h=5da0498a3e23339aaceba659a97e935031d5693d >+* Apply https://git.xiph.org/?p=opus.git;a=commitdiff;h=46560534fcb5710a894a341c2f9526db58fd7087#patch1 >+* Apply https://github.com/xiph/opus/pull/73 >+* Apply https://github.com/xiph/opus/pull/87 >+* Make sure HB_gain is not NaN in an attempt to fix chromium:826914 >+* Saturate add to avoid int overflow to fix chromium:842528. This should be >+ reverted when updating to v1.3 >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/convert_rtcd_assembler.py b/Source/ThirdParty/libwebrtc/Source/third_party/opus/convert_rtcd_assembler.py >index dc63c641f57f4c7ce49bda7f32bf976f87225ec7..2f6071f4121861bc0d079893572dd7092ac1c042 100755 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/convert_rtcd_assembler.py >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/convert_rtcd_assembler.py >@@ -45,7 +45,6 @@ def main(argv): > 'sed "s/OPUS_ARM_MAY_HAVE_[A-Z]*/1/g" | ' > 'sed "/.include/d" ' > '> %s') % (arm2gnu_script, input_file, output_file) >- print cmd > return os.system(cmd) > > if __name__ == '__main__': >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/.gitignore b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/.gitignore >new file mode 100644 >index 0000000000000000000000000000000000000000..33127c9fe0a663b60669530b7bdb65a67d1beca5 >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/.gitignore >@@ -0,0 +1,83 @@ >+Doxyfile >+Makefile >+Makefile.in >+TAGS >+aclocal.m4 >+autom4te.cache >+*.kdevelop.pcs >+*.kdevses >+compile >+config.guess >+config.h >+config.h.in >+config.log >+config.status >+config.sub >+configure >+depcomp >+INSTALL >+install-sh >+.deps >+.libs >+.dirstamp >+*.a >+*.exe >+*.la >+*-gnu.S >+testcelt >+libtool >+ltmain.sh >+missing >+m4/libtool.m4 >+m4/ltoptions.m4 >+m4/ltsugar.m4 >+m4/ltversion.m4 >+m4/lt~obsolete.m4 >+opus_compare >+opus_demo >+repacketizer_demo >+stamp-h1 >+test-driver >+*.sw* >+*.o >+*.lo >+*.pc >+*.tar.gz >+*~ >+tests/*test >+tests/test_opus_api >+tests/test_opus_decode >+tests/test_opus_encode >+tests/test_opus_padding >+celt/arm/armopts.s >+celt/dump_modes/dump_modes >+celt/tests/test_unit_cwrs32 >+celt/tests/test_unit_dft >+celt/tests/test_unit_entropy >+celt/tests/test_unit_laplace >+celt/tests/test_unit_mathops >+celt/tests/test_unit_mdct >+celt/tests/test_unit_rotation >+celt/tests/test_unit_types >+doc/doxygen_sqlite3.db >+doc/doxygen-build.stamp >+doc/html >+doc/latex >+doc/man >+package_version >+version.h >+celt/Debug >+celt/Release >+celt/x64 >+silk/Debug >+silk/Release >+silk/x64 >+silk/fixed/Debug >+silk/fixed/Release >+silk/fixed/x64 >+silk/float/Debug >+silk/float/Release >+silk/float/x64 >+src/Debug >+src/Release >+src/x64 >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/LICENSE_PLEASE_READ.txt b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/LICENSE_PLEASE_READ.txt >new file mode 100644 >index 0000000000000000000000000000000000000000..bc88efa6cb05789a6a6e697577ae6d8e5532e5df >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/LICENSE_PLEASE_READ.txt >@@ -0,0 +1,22 @@ >+Contributions to the collaboration shall not be considered confidential. >+ >+Each contributor represents and warrants that it has the right and >+authority to license copyright in its contributions to the collaboration. >+ >+Each contributor agrees to license the copyright in the contributions >+under the Modified (2-clause or 3-clause) BSD License or the Clear BSD License. >+ >+Please see the IPR statements submitted to the IETF for the complete >+patent licensing details: >+ >+Xiph.Org Foundation: >+https://datatracker.ietf.org/ipr/1524/ >+ >+Microsoft Corporation: >+https://datatracker.ietf.org/ipr/1914/ >+ >+Skype Limited: >+https://datatracker.ietf.org/ipr/1602/ >+ >+Broadcom Corporation: >+https://datatracker.ietf.org/ipr/1526/ >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/Makefile.am b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/Makefile.am >index 7a691140e553d4554c6ec2b7cbac0298e3d16b2c..5b57b3372e56cca599c4d45aaa01fe3d37186232 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/Makefile.am >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/Makefile.am >@@ -21,6 +21,9 @@ SILK_SOURCES += $(SILK_SOURCES_FIXED) > if HAVE_SSE4_1 > SILK_SOURCES += $(SILK_SOURCES_SSE4_1) $(SILK_SOURCES_FIXED_SSE4_1) > endif >+if HAVE_ARM_NEON_INTR >+SILK_SOURCES += $(SILK_SOURCES_FIXED_ARM_NEON_INTR) >+endif > else > SILK_SOURCES += $(SILK_SOURCES_FLOAT) > if HAVE_SSE4_1 >@@ -84,9 +87,36 @@ pkginclude_HEADERS = include/opus.h include/opus_multistream.h include/opus_type > noinst_HEADERS = $(OPUS_HEAD) $(SILK_HEAD) $(CELT_HEAD) > > if EXTRA_PROGRAMS >-noinst_PROGRAMS = opus_demo repacketizer_demo opus_compare tests/test_opus_api tests/test_opus_encode tests/test_opus_decode tests/test_opus_padding celt/tests/test_unit_cwrs32 celt/tests/test_unit_dft celt/tests/test_unit_entropy celt/tests/test_unit_laplace celt/tests/test_unit_mathops celt/tests/test_unit_mdct celt/tests/test_unit_rotation celt/tests/test_unit_types >- >-TESTS = celt/tests/test_unit_types celt/tests/test_unit_mathops celt/tests/test_unit_entropy celt/tests/test_unit_laplace celt/tests/test_unit_dft celt/tests/test_unit_mdct celt/tests/test_unit_rotation celt/tests/test_unit_cwrs32 tests/test_opus_api tests/test_opus_decode tests/test_opus_encode tests/test_opus_padding >+noinst_PROGRAMS = celt/tests/test_unit_cwrs32 \ >+ celt/tests/test_unit_dft \ >+ celt/tests/test_unit_entropy \ >+ celt/tests/test_unit_laplace \ >+ celt/tests/test_unit_mathops \ >+ celt/tests/test_unit_mdct \ >+ celt/tests/test_unit_rotation \ >+ celt/tests/test_unit_types \ >+ opus_compare \ >+ opus_demo \ >+ repacketizer_demo \ >+ silk/tests/test_unit_LPC_inv_pred_gain \ >+ tests/test_opus_api \ >+ tests/test_opus_decode \ >+ tests/test_opus_encode \ >+ tests/test_opus_padding >+ >+TESTS = celt/tests/test_unit_cwrs32 \ >+ celt/tests/test_unit_dft \ >+ celt/tests/test_unit_entropy \ >+ celt/tests/test_unit_laplace \ >+ celt/tests/test_unit_mathops \ >+ celt/tests/test_unit_mdct \ >+ celt/tests/test_unit_rotation \ >+ celt/tests/test_unit_types \ >+ silk/tests/test_unit_LPC_inv_pred_gain \ >+ tests/test_opus_api \ >+ tests/test_opus_decode \ >+ tests/test_opus_encode \ >+ tests/test_opus_padding > > opus_demo_SOURCES = src/opus_demo.c > >@@ -102,7 +132,7 @@ opus_compare_LDADD = $(LIBM) > tests_test_opus_api_SOURCES = tests/test_opus_api.c tests/test_opus_common.h > tests_test_opus_api_LDADD = libopus.la $(NE10_LIBS) $(LIBM) > >-tests_test_opus_encode_SOURCES = tests/test_opus_encode.c tests/test_opus_common.h >+tests_test_opus_encode_SOURCES = tests/test_opus_encode.c tests/opus_encode_regressions.c tests/test_opus_common.h > tests_test_opus_encode_LDADD = libopus.la $(NE10_LIBS) $(LIBM) > > tests_test_opus_decode_SOURCES = tests/test_opus_decode.c tests/test_opus_common.h >@@ -111,11 +141,20 @@ tests_test_opus_decode_LDADD = libopus.la $(NE10_LIBS) $(LIBM) > tests_test_opus_padding_SOURCES = tests/test_opus_padding.c tests/test_opus_common.h > tests_test_opus_padding_LDADD = libopus.la $(NE10_LIBS) $(LIBM) > >+CELT_OBJ = $(CELT_SOURCES:.c=.lo) >+SILK_OBJ = $(SILK_SOURCES:.c=.lo) >+ >+silk_tests_test_unit_LPC_inv_pred_gain_SOURCES = silk/tests/test_unit_LPC_inv_pred_gain.c >+silk_tests_test_unit_LPC_inv_pred_gain_LDADD = $(SILK_OBJ) $(CELT_OBJ) $(NE10_LIBS) $(LIBM) >+if OPUS_ARM_EXTERNAL_ASM >+silk_tests_test_unit_LPC_inv_pred_gain_LDADD += libarmasm.la >+endif >+ > celt_tests_test_unit_cwrs32_SOURCES = celt/tests/test_unit_cwrs32.c > celt_tests_test_unit_cwrs32_LDADD = $(LIBM) > > celt_tests_test_unit_dft_SOURCES = celt/tests/test_unit_dft.c >-celt_tests_test_unit_dft_LDADD = $(NE10_LIBS) $(LIBM) >+celt_tests_test_unit_dft_LDADD = $(CELT_OBJ) $(NE10_LIBS) $(LIBM) > if OPUS_ARM_EXTERNAL_ASM > celt_tests_test_unit_dft_LDADD += libarmasm.la > endif >@@ -127,19 +166,19 @@ celt_tests_test_unit_laplace_SOURCES = celt/tests/test_unit_laplace.c > celt_tests_test_unit_laplace_LDADD = $(LIBM) > > celt_tests_test_unit_mathops_SOURCES = celt/tests/test_unit_mathops.c >-celt_tests_test_unit_mathops_LDADD = $(NE10_LIBS) $(LIBM) >+celt_tests_test_unit_mathops_LDADD = $(CELT_OBJ) $(NE10_LIBS) $(LIBM) > if OPUS_ARM_EXTERNAL_ASM > celt_tests_test_unit_mathops_LDADD += libarmasm.la > endif > > celt_tests_test_unit_mdct_SOURCES = celt/tests/test_unit_mdct.c >-celt_tests_test_unit_mdct_LDADD = $(NE10_LIBS) $(LIBM) >+celt_tests_test_unit_mdct_LDADD = $(CELT_OBJ) $(NE10_LIBS) $(LIBM) > if OPUS_ARM_EXTERNAL_ASM > celt_tests_test_unit_mdct_LDADD += libarmasm.la > endif > > celt_tests_test_unit_rotation_SOURCES = celt/tests/test_unit_rotation.c >-celt_tests_test_unit_rotation_LDADD = $(NE10_LIBS) $(LIBM) >+celt_tests_test_unit_rotation_LDADD = $(CELT_OBJ) $(NE10_LIBS) $(LIBM) > if OPUS_ARM_EXTERNAL_ASM > celt_tests_test_unit_rotation_LDADD += libarmasm.la > endif >@@ -157,8 +196,7 @@ opus_custom_demo_LDADD = libopus.la $(LIBM) > endif > endif > >-EXTRA_DIST = version.mk \ >- opus.pc.in \ >+EXTRA_DIST = opus.pc.in \ > opus-uninstalled.pc.in \ > opus.m4 \ > Makefile.mips \ >@@ -166,25 +204,18 @@ EXTRA_DIST = version.mk \ > tests/run_vectors.sh \ > celt/arm/arm2gnu.pl \ > celt/arm/celt_pitch_xcorr_arm.s \ >- win32/VS2015/silk_float.vcxproj \ >- win32/VS2015/celt.vcxproj.filters \ > win32/VS2015/opus.vcxproj \ >- win32/VS2015/silk_common.vcxproj.filters \ >- win32/VS2015/silk_float.vcxproj.filters \ > win32/VS2015/test_opus_encode.vcxproj.filters \ >- win32/VS2015/silk_common.vcxproj \ > win32/VS2015/test_opus_encode.vcxproj \ > win32/VS2015/opus_demo.vcxproj \ > win32/VS2015/test_opus_api.vcxproj.filters \ > win32/VS2015/test_opus_api.vcxproj \ > win32/VS2015/test_opus_decode.vcxproj.filters \ >- win32/VS2015/silk_fixed.vcxproj.filters \ > win32/VS2015/opus_demo.vcxproj.filters \ >- win32/VS2015/silk_fixed.vcxproj \ > win32/VS2015/opus.vcxproj.filters \ > win32/VS2015/test_opus_decode.vcxproj \ >- win32/VS2015/celt.vcxproj \ > win32/VS2015/opus.sln \ >+ win32/VS2015/common.props \ > win32/genversion.bat \ > win32/config.h > >@@ -276,27 +307,30 @@ $(CELT_SOURCES_ARM_ASM:%.s=%-gnu.S): $(top_srcdir)/celt/arm/arm2gnu.pl > OPT_UNIT_TEST_OBJ = $(celt_tests_test_unit_mathops_SOURCES:.c=.o) \ > $(celt_tests_test_unit_rotation_SOURCES:.c=.o) \ > $(celt_tests_test_unit_mdct_SOURCES:.c=.o) \ >- $(celt_tests_test_unit_dft_SOURCES:.c=.o) >+ $(celt_tests_test_unit_dft_SOURCES:.c=.o) \ >+ $(silk_tests_test_unit_LPC_inv_pred_gain_SOURCES:.c=.o) > > if HAVE_SSE > SSE_OBJ = $(CELT_SOURCES_SSE:.c=.lo) >-$(SSE_OBJ) $(OPT_UNIT_TEST_OBJ): CFLAGS += $(OPUS_X86_SSE_CFLAGS) >+$(SSE_OBJ): CFLAGS += $(OPUS_X86_SSE_CFLAGS) > endif > > if HAVE_SSE2 > SSE2_OBJ = $(CELT_SOURCES_SSE2:.c=.lo) >-$(SSE2_OBJ) $(OPT_UNIT_TEST_OBJ): CFLAGS += $(OPUS_X86_SSE2_CFLAGS) >+$(SSE2_OBJ): CFLAGS += $(OPUS_X86_SSE2_CFLAGS) > endif > > if HAVE_SSE4_1 > SSE4_1_OBJ = $(CELT_SOURCES_SSE4_1:.c=.lo) \ > $(SILK_SOURCES_SSE4_1:.c=.lo) \ > $(SILK_SOURCES_FIXED_SSE4_1:.c=.lo) >-$(SSE4_1_OBJ) $(OPT_UNIT_TEST_OBJ): CFLAGS += $(OPUS_X86_SSE4_1_CFLAGS) >+$(SSE4_1_OBJ): CFLAGS += $(OPUS_X86_SSE4_1_CFLAGS) > endif > > if HAVE_ARM_NEON_INTR >-ARM_NEON_INTR_OBJ = $(CELT_SOURCES_ARM_NEON_INTR:.c=.lo) $(SILK_SOURCES_ARM_NEON_INTR:.c=.lo) >-$(ARM_NEON_INTR_OBJ) $(OPT_UNIT_TEST_OBJ): CFLAGS += \ >+ARM_NEON_INTR_OBJ = $(CELT_SOURCES_ARM_NEON_INTR:.c=.lo) \ >+ $(SILK_SOURCES_ARM_NEON_INTR:.c=.lo) \ >+ $(SILK_SOURCES_FIXED_ARM_NEON_INTR:.c=.lo) >+$(ARM_NEON_INTR_OBJ): CFLAGS += \ > $(OPUS_ARM_NEON_INTR_CFLAGS) $(NE10_CFLAGS) > endif >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/Makefile.mips b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/Makefile.mips >index 56a506238f646a672547c3456a4d5aaaf3428267..d25af8cbc28e5e69f53fe87b25f258ba385f5d29 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/Makefile.mips >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/Makefile.mips >@@ -99,7 +99,7 @@ TESTOPUSAPI_OBJS := $(patsubst %.c,%$(OBJSUFFIX),$(TESTOPUSAPI_SRCS_C)) > TESTOPUSDECODE_SRCS_C = tests/test_opus_decode.c > TESTOPUSDECODE_OBJS := $(patsubst %.c,%$(OBJSUFFIX),$(TESTOPUSDECODE_SRCS_C)) > >-TESTOPUSENCODE_SRCS_C = tests/test_opus_encode.c >+TESTOPUSENCODE_SRCS_C = tests/test_opus_encode.c tests/opus_encode_regressions.c > TESTOPUSENCODE_OBJS := $(patsubst %.c,%$(OBJSUFFIX),$(TESTOPUSENCODE_SRCS_C)) > > TESTOPUSPADDING_SRCS_C = tests/test_opus_padding.c >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/Makefile.unix b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/Makefile.unix >index b13230e8fbebf5ea94a557e193c0d5a5724fd45c..90a48f0cc0e92e514f270bb2af552fe6f66b3e4f 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/Makefile.unix >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/Makefile.unix >@@ -97,7 +97,7 @@ TESTOPUSAPI_OBJS := $(patsubst %.c,%$(OBJSUFFIX),$(TESTOPUSAPI_SRCS_C)) > TESTOPUSDECODE_SRCS_C = tests/test_opus_decode.c > TESTOPUSDECODE_OBJS := $(patsubst %.c,%$(OBJSUFFIX),$(TESTOPUSDECODE_SRCS_C)) > >-TESTOPUSENCODE_SRCS_C = tests/test_opus_encode.c >+TESTOPUSENCODE_SRCS_C = tests/test_opus_encode.c tests/opus_encode_regressions.c > TESTOPUSENCODE_OBJS := $(patsubst %.c,%$(OBJSUFFIX),$(TESTOPUSENCODE_SRCS_C)) > > TESTOPUSPADDING_SRCS_C = tests/test_opus_padding.c >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/README b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/README >index ac6264ec2923839e02945e8eaa2684e3580e4cf1..9a06811654b5c233823a097426683531341a6d22 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/README >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/README >@@ -43,25 +43,43 @@ or on the main Opus website: > > To build from a distribution tarball, you only need to do the following: > >-% ./configure >-% make >+ % ./configure >+ % make > > To build from the git repository, the following steps are necessary: > >+0) Set up a development environment: >+ >+On an Ubuntu or Debian family Linux distribution: >+ >+ % sudo apt-get install git autoconf automake libtool gcc make >+ >+On a Fedora/Redhat based Linux: >+ >+ % sudo dnf install git autoconf automake libtool gcc make >+ >+Or for older Redhat/Centos Linux releases: >+ >+ % sudo yum install git autoconf automake libtool gcc make >+ >+On Apple macOS, install Xcode and brew.sh, then in the Terminal enter: >+ >+ % brew install autoconf automake libtool >+ > 1) Clone the repository: > >-% git clone https://git.xiph.org/opus.git >-% cd opus >+ % git clone https://git.xiph.org/opus.git >+ % cd opus > > 2) Compiling the source > >-% ./autogen.sh >-% ./configure >-% make >+ % ./autogen.sh >+ % ./configure >+ % make > > 3) Install the codec libraries (optional) > >-% sudo make install >+ % sudo make install > > Once you have compiled the codec, there will be a opus_demo executable > in the top directory. >@@ -102,7 +120,8 @@ which SHOULD be run after compiling the package especially the first > time it is run on a new platform. > > To run the integrated tests: >-% make check >+ >+ % make check > > There is also collection of standard test vectors which are not > included in this package for size reasons but can be obtained from: >@@ -110,9 +129,9 @@ https://opus-codec.org/testvectors/opus_testvectors.tar.gz > > To run compare the code to these test vectors: > >-% curl -O https://opus-codec.org/testvectors/opus_testvectors.tar.gz >-% tar -zxf opus_testvectors.tar.gz >-% ./tests/run_vectors.sh ./ opus_testvectors 48000 >+ % curl -OL https://opus-codec.org/testvectors/opus_testvectors.tar.gz >+ % tar -zxf opus_testvectors.tar.gz >+ % ./tests/run_vectors.sh ./ opus_testvectors 48000 > > == Portability notes == > >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/README.draft b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/README.draft >new file mode 100644 >index 0000000000000000000000000000000000000000..8d8e24df22ff84a6d1a2b9ae669187fb287a324b >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/README.draft >@@ -0,0 +1,54 @@ >+To build this source code, simply type: >+ >+% make >+ >+If this does not work, or if you want to change the default configuration >+(e.g., to compile for a fixed-point architecture), simply edit the options >+in the Makefile. >+ >+An up-to-date implementation conforming to this standard is available in a >+Git repository at https://git.xiph.org/opus.git or on a website at: >+https://opus-codec.org/ >+However, although that implementation is expected to remain conformant >+with the standard, it is the code in this RFC that shall remain normative. >+To build from the git repository instead of using this RFC, follow these >+steps: >+ >+1) Clone the repository (latest implementation of this standard at the time >+of publication) >+ >+% git clone https://git.xiph.org/opus.git >+% cd opus >+ >+2) Compile >+ >+% ./autogen.sh >+% ./configure >+% make >+ >+Once you have compiled the codec, there will be a opus_demo executable in >+the top directory. >+ >+Usage: opus_demo [-e] <application> <sampling rate (Hz)> <channels (1/2)> >+ <bits per second> [options] <input> <output> >+ opus_demo -d <sampling rate (Hz)> <channels (1/2)> [options] >+ <input> <output> >+ >+mode: voip | audio | restricted-lowdelay >+options: >+-e : only runs the encoder (output the bit-stream) >+-d : only runs the decoder (reads the bit-stream as input) >+-cbr : enable constant bitrate; default: variable bitrate >+-cvbr : enable constrained variable bitrate; default: unconstrained >+-bandwidth <NB|MB|WB|SWB|FB> : audio bandwidth (from narrowband to fullband); >+ default: sampling rate >+-framesize <2.5|5|10|20|40|60> : frame size in ms; default: 20 >+-max_payload <bytes> : maximum payload size in bytes, default: 1024 >+-complexity <comp> : complexity, 0 (lowest) ... 10 (highest); default: 10 >+-inbandfec : enable SILK inband FEC >+-forcemono : force mono encoding, even for stereo input >+-dtx : enable SILK DTX >+-loss <perc> : simulate packet loss, in percent (0-100); default: 0 >+ >+input and output are little endian signed 16-bit PCM files or opus bitstreams >+with simple opus_demo proprietary framing. >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/autogen.sh b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/autogen.sh >new file mode 100644 >index 0000000000000000000000000000000000000000..380d1f3ca6dccbc471ecf2deade836d8ed8f2a20 >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/autogen.sh >@@ -0,0 +1,14 @@ >+#!/bin/sh >+# Copyright (c) 2010-2015 Xiph.Org Foundation and contributors. >+# Use of this source code is governed by a BSD-style license that can be >+# found in the COPYING file. >+ >+# Run this to set up the build system: configure, makefiles, etc. >+set -e >+ >+srcdir=`dirname $0` >+test -n "$srcdir" && cd "$srcdir" >+ >+echo "Updating build configuration files, please wait...." >+ >+autoreconf -isf >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/_kiss_fft_guts.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/_kiss_fft_guts.h >index 5e3d58fd6641e53dfb56a2f32d58c8cd9717a47f..17392b3e90977b74049049b7fa01a9f8cb0fc093 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/_kiss_fft_guts.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/_kiss_fft_guts.h >@@ -58,12 +58,12 @@ > # define S_MUL(a,b) MULT16_32_Q15(b, a) > > # define C_MUL(m,a,b) \ >- do{ (m).r = SUB32(S_MUL((a).r,(b).r) , S_MUL((a).i,(b).i)); \ >- (m).i = ADD32(S_MUL((a).r,(b).i) , S_MUL((a).i,(b).r)); }while(0) >+ do{ (m).r = SUB32_ovflw(S_MUL((a).r,(b).r) , S_MUL((a).i,(b).i)); \ >+ (m).i = ADD32_ovflw(S_MUL((a).r,(b).i) , S_MUL((a).i,(b).r)); }while(0) > > # define C_MULC(m,a,b) \ >- do{ (m).r = ADD32(S_MUL((a).r,(b).r) , S_MUL((a).i,(b).i)); \ >- (m).i = SUB32(S_MUL((a).i,(b).r) , S_MUL((a).r,(b).i)); }while(0) >+ do{ (m).r = ADD32_ovflw(S_MUL((a).r,(b).r) , S_MUL((a).i,(b).i)); \ >+ (m).i = SUB32_ovflw(S_MUL((a).i,(b).r) , S_MUL((a).r,(b).i)); }while(0) > > # define C_MULBYSCALAR( c, s ) \ > do{ (c).r = S_MUL( (c).r , s ) ;\ >@@ -77,17 +77,17 @@ > DIVSCALAR( (c).i , div); }while (0) > > #define C_ADD( res, a,b)\ >- do {(res).r=ADD32((a).r,(b).r); (res).i=ADD32((a).i,(b).i); \ >+ do {(res).r=ADD32_ovflw((a).r,(b).r); (res).i=ADD32_ovflw((a).i,(b).i); \ > }while(0) > #define C_SUB( res, a,b)\ >- do {(res).r=SUB32((a).r,(b).r); (res).i=SUB32((a).i,(b).i); \ >+ do {(res).r=SUB32_ovflw((a).r,(b).r); (res).i=SUB32_ovflw((a).i,(b).i); \ > }while(0) > #define C_ADDTO( res , a)\ >- do {(res).r = ADD32((res).r, (a).r); (res).i = ADD32((res).i,(a).i);\ >+ do {(res).r = ADD32_ovflw((res).r, (a).r); (res).i = ADD32_ovflw((res).i,(a).i);\ > }while(0) > > #define C_SUBFROM( res , a)\ >- do {(res).r = ADD32((res).r,(a).r); (res).i = SUB32((res).i,(a).i); \ >+ do {(res).r = ADD32_ovflw((res).r,(a).r); (res).i = SUB32_ovflw((res).i,(a).i); \ > }while(0) > > #if defined(OPUS_ARM_INLINE_ASM) >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arch.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arch.h >index 8ceab5fe10e934113592ade9339939771f4a2a01..d1e6457c54a07c6ec5c3a030510da8ab42355008 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arch.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arch.h >@@ -46,6 +46,14 @@ > # endif > # endif > >+#if OPUS_GNUC_PREREQ(3, 0) >+#define opus_likely(x) (__builtin_expect(!!(x), 1)) >+#define opus_unlikely(x) (__builtin_expect(!!(x), 0)) >+#else >+#define opus_likely(x) (!!(x)) >+#define opus_unlikely(x) (!!(x)) >+#endif >+ > #define CELT_SIG_SCALE 32768.f > > #define celt_fatal(str) _celt_fatal(str, __FILE__, __LINE__); >@@ -93,6 +101,7 @@ static OPUS_INLINE void _celt_fatal(const char *str, const char *file, int line) > > typedef opus_int16 opus_val16; > typedef opus_int32 opus_val32; >+typedef opus_int64 opus_val64; > > typedef opus_val32 celt_sig; > typedef opus_val16 celt_norm; >@@ -101,6 +110,9 @@ typedef opus_val32 celt_ener; > #define Q15ONE 32767 > > #define SIG_SHIFT 12 >+/* Safe saturation value for 32-bit signals. Should be less than >+ 2^31*(1-0.85) to avoid blowing up on DC at deemphasis.*/ >+#define SIG_SAT (300000000) > > #define NORM_SCALING 16384 > >@@ -147,6 +159,7 @@ static OPUS_INLINE opus_int16 SAT16(opus_int32 x) { > > typedef float opus_val16; > typedef float opus_val32; >+typedef float opus_val64; > > typedef float celt_sig; > typedef float celt_norm; >@@ -186,6 +199,7 @@ static OPUS_INLINE int celt_isnan(float x) > > #define NEG16(x) (-(x)) > #define NEG32(x) (-(x)) >+#define NEG32_ovflw(x) (-(x)) > #define EXTRACT16(x) (x) > #define EXTEND32(x) (x) > #define SHR16(a,shift) (a) >@@ -202,6 +216,7 @@ static OPUS_INLINE int celt_isnan(float x) > #define SATURATE16(x) (x) > > #define ROUND16(a,shift) (a) >+#define SROUND16(a,shift) (a) > #define HALF16(x) (.5f*(x)) > #define HALF32(x) (.5f*(x)) > >@@ -209,6 +224,8 @@ static OPUS_INLINE int celt_isnan(float x) > #define SUB16(a,b) ((a)-(b)) > #define ADD32(a,b) ((a)+(b)) > #define SUB32(a,b) ((a)-(b)) >+#define ADD32_ovflw(a,b) ((a)+(b)) >+#define SUB32_ovflw(a,b) ((a)-(b)) > #define MULT16_16_16(a,b) ((a)*(b)) > #define MULT16_16(a,b) ((opus_val32)(a)*(opus_val32)(b)) > #define MAC16_16(c,a,b) ((c)+(opus_val32)(a)*(opus_val32)(b)) >@@ -243,9 +260,9 @@ static OPUS_INLINE int celt_isnan(float x) > > #ifndef GLOBAL_STACK_SIZE > #ifdef FIXED_POINT >-#define GLOBAL_STACK_SIZE 100000 >+#define GLOBAL_STACK_SIZE 120000 > #else >-#define GLOBAL_STACK_SIZE 100000 >+#define GLOBAL_STACK_SIZE 120000 > #endif > #endif > >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/arm2gnu.pl b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/arm2gnu.pl >index 6c922ac819d7e0889bdbb72c4e8bec9cf6be5d4b..a2895f7445e89433669152e3c489116d0860a7b9 100755 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/arm2gnu.pl >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/arm2gnu.pl >@@ -164,11 +164,11 @@ while (<>) { > $prefix = ""; > if ($proc) > { >- $prefix = $prefix.sprintf("\t.type\t%s, %%function; ",$proc) unless ($apple); >+ $prefix = $prefix.sprintf("\t.type\t%s, %%function", $proc) unless ($apple); > # Make sure we $prefix isn't empty here (for the $apple case). > # We handle mangling the label here, make sure it doesn't match > # the label handling below (if $prefix would be empty). >- $prefix = "; "; >+ $prefix = $prefix."; "; > push(@proc_stack, $proc); > s/^[A-Za-z_\.]\w+/$symprefix$&:/; > } >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/arm_celt_map.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/arm_celt_map.c >index 4d4d069a86fc277aa62a0904e3125604fc969cc9..ca988b66f55d17c116f0b7a19db1c6a1bcb4b621 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/arm_celt_map.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/arm_celt_map.c >@@ -35,12 +35,29 @@ > > #if defined(OPUS_HAVE_RTCD) > >+# if defined(OPUS_ARM_MAY_HAVE_NEON_INTR) && !defined(OPUS_ARM_PRESUME_NEON_INTR) >+opus_val32 (*const CELT_INNER_PROD_IMPL[OPUS_ARCHMASK+1])(const opus_val16 *x, const opus_val16 *y, int N) = { >+ celt_inner_prod_c, /* ARMv4 */ >+ celt_inner_prod_c, /* EDSP */ >+ celt_inner_prod_c, /* Media */ >+ celt_inner_prod_neon /* NEON */ >+}; >+ >+void (*const DUAL_INNER_PROD_IMPL[OPUS_ARCHMASK+1])(const opus_val16 *x, const opus_val16 *y01, const opus_val16 *y02, >+ int N, opus_val32 *xy1, opus_val32 *xy2) = { >+ dual_inner_prod_c, /* ARMv4 */ >+ dual_inner_prod_c, /* EDSP */ >+ dual_inner_prod_c, /* Media */ >+ dual_inner_prod_neon /* NEON */ >+}; >+# endif >+ > # if defined(FIXED_POINT) > # if ((defined(OPUS_ARM_MAY_HAVE_NEON) && !defined(OPUS_ARM_PRESUME_NEON)) || \ > (defined(OPUS_ARM_MAY_HAVE_MEDIA) && !defined(OPUS_ARM_PRESUME_MEDIA)) || \ > (defined(OPUS_ARM_MAY_HAVE_EDSP) && !defined(OPUS_ARM_PRESUME_EDSP))) > opus_val32 (*const CELT_PITCH_XCORR_IMPL[OPUS_ARCHMASK+1])(const opus_val16 *, >- const opus_val16 *, opus_val32 *, int , int) = { >+ const opus_val16 *, opus_val32 *, int, int, int) = { > celt_pitch_xcorr_c, /* ARMv4 */ > MAY_HAVE_EDSP(celt_pitch_xcorr), /* EDSP */ > MAY_HAVE_MEDIA(celt_pitch_xcorr), /* Media */ >@@ -51,7 +68,7 @@ opus_val32 (*const CELT_PITCH_XCORR_IMPL[OPUS_ARCHMASK+1])(const opus_val16 *, > # else /* !FIXED_POINT */ > # if defined(OPUS_ARM_MAY_HAVE_NEON_INTR) && !defined(OPUS_ARM_PRESUME_NEON_INTR) > void (*const CELT_PITCH_XCORR_IMPL[OPUS_ARCHMASK+1])(const opus_val16 *, >- const opus_val16 *, opus_val32 *, int, int) = { >+ const opus_val16 *, opus_val32 *, int, int, int) = { > celt_pitch_xcorr_c, /* ARMv4 */ > celt_pitch_xcorr_c, /* EDSP */ > celt_pitch_xcorr_c, /* Media */ >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/celt_ne10_fft.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/celt_ne10_fft.c >index 42d96a711760e3a6ddf4be61cdf7bf971aa78aa3..b8c60abe98b83571a0bc8585081a57facb5a56a9 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/celt_ne10_fft.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/celt_ne10_fft.c >@@ -36,7 +36,6 @@ > #endif > #endif > >-#include <NE10_init.h> > #include <NE10_dsp.h> > #include "os_support.h" > #include "kiss_fft.h" >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/celt_neon_intr.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/celt_neon_intr.c >index 47bbe3dc22ec93cfeb9398248bd144128c333975..cf443988ce5fe5323b8445cb656a991a98da514f 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/celt_neon_intr.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/celt_neon_intr.c >@@ -191,107 +191,10 @@ static void xcorr_kernel_neon_float(const float32_t *x, const float32_t *y, > vst1q_f32(sum, SUMM); > } > >-/* >- * Function: xcorr_kernel_neon_float_process1 >- * --------------------------------- >- * Computes single correlation values and stores in *sum >- */ >-static void xcorr_kernel_neon_float_process1(const float32_t *x, >- const float32_t *y, float32_t *sum, int len) { >- float32x4_t XX[4]; >- float32x4_t YY[4]; >- float32x2_t XX_2; >- float32x2_t YY_2; >- float32x4_t SUMM; >- float32x2_t SUMM_2[2]; >- const float32_t *xi = x; >- const float32_t *yi = y; >- >- SUMM = vdupq_n_f32(0); >- >- /* Work on 16 values per iteration */ >- while (len >= 16) { >- XX[0] = vld1q_f32(xi); >- xi += 4; >- XX[1] = vld1q_f32(xi); >- xi += 4; >- XX[2] = vld1q_f32(xi); >- xi += 4; >- XX[3] = vld1q_f32(xi); >- xi += 4; >- >- YY[0] = vld1q_f32(yi); >- yi += 4; >- YY[1] = vld1q_f32(yi); >- yi += 4; >- YY[2] = vld1q_f32(yi); >- yi += 4; >- YY[3] = vld1q_f32(yi); >- yi += 4; >- >- SUMM = vmlaq_f32(SUMM, YY[0], XX[0]); >- SUMM = vmlaq_f32(SUMM, YY[1], XX[1]); >- SUMM = vmlaq_f32(SUMM, YY[2], XX[2]); >- SUMM = vmlaq_f32(SUMM, YY[3], XX[3]); >- len -= 16; >- } >- >- /* Work on 8 values */ >- if (len >= 8) { >- XX[0] = vld1q_f32(xi); >- xi += 4; >- XX[1] = vld1q_f32(xi); >- xi += 4; >- >- YY[0] = vld1q_f32(yi); >- yi += 4; >- YY[1] = vld1q_f32(yi); >- yi += 4; >- >- SUMM = vmlaq_f32(SUMM, YY[0], XX[0]); >- SUMM = vmlaq_f32(SUMM, YY[1], XX[1]); >- len -= 8; >- } >- >- /* Work on 4 values */ >- if (len >= 4) { >- XX[0] = vld1q_f32(xi); >- xi += 4; >- YY[0] = vld1q_f32(yi); >- yi += 4; >- SUMM = vmlaq_f32(SUMM, YY[0], XX[0]); >- len -= 4; >- } >- >- /* Start accumulating results */ >- SUMM_2[0] = vget_low_f32(SUMM); >- if (len >= 2) { >- /* While at it, consume 2 more values if available */ >- XX_2 = vld1_f32(xi); >- xi += 2; >- YY_2 = vld1_f32(yi); >- yi += 2; >- SUMM_2[0] = vmla_f32(SUMM_2[0], YY_2, XX_2); >- len -= 2; >- } >- SUMM_2[1] = vget_high_f32(SUMM); >- SUMM_2[0] = vadd_f32(SUMM_2[0], SUMM_2[1]); >- SUMM_2[0] = vpadd_f32(SUMM_2[0], SUMM_2[0]); >- /* Ok, now we have result accumulated in SUMM_2[0].0 */ >- >- if (len > 0) { >- /* Case when you have one value left */ >- XX_2 = vld1_dup_f32(xi); >- YY_2 = vld1_dup_f32(yi); >- SUMM_2[0] = vmla_f32(SUMM_2[0], XX_2, YY_2); >- } >- >- vst1_lane_f32(sum, SUMM_2[0], 0); >-} >- > void celt_pitch_xcorr_float_neon(const opus_val16 *_x, const opus_val16 *_y, >- opus_val32 *xcorr, int len, int max_pitch) { >+ opus_val32 *xcorr, int len, int max_pitch, int arch) { > int i; >+ (void)arch; > celt_assert(max_pitch > 0); > celt_assert((((unsigned char *)_x-(unsigned char *)NULL)&3)==0); > >@@ -300,12 +203,9 @@ void celt_pitch_xcorr_float_neon(const opus_val16 *_x, const opus_val16 *_y, > (float32_t *)xcorr+i, len); > } > >- /* In case max_pitch isn't multiple of 4 >- * compute single correlation value per iteration >- */ >+ /* In case max_pitch isn't a multiple of 4, do non-unrolled version. */ > for (; i < max_pitch; i++) { >- xcorr_kernel_neon_float_process1((const float32_t *)_x, >- (const float32_t *)_y+i, (float32_t *)xcorr+i, len); >+ xcorr[i] = celt_inner_prod_neon(_x, _y+i, len); > } > } > #endif >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/celt_pitch_xcorr_arm.s b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/celt_pitch_xcorr_arm.s >index f96e0a88bbe609ed638b1a44b67e9038a3ed3447..6e873afc3712724fed83734b4b3ce8184e1919f7 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/celt_pitch_xcorr_arm.s >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/celt_pitch_xcorr_arm.s >@@ -153,7 +153,7 @@ xcorr_kernel_neon_process1 > ENDP > > ; opus_val32 celt_pitch_xcorr_neon(opus_val16 *_x, opus_val16 *_y, >-; opus_val32 *xcorr, int len, int max_pitch) >+; opus_val32 *xcorr, int len, int max_pitch, int arch) > celt_pitch_xcorr_neon PROC > ; input: > ; r0 = opus_val16 *_x >@@ -168,6 +168,8 @@ celt_pitch_xcorr_neon PROC > ; r6 = int max_pitch > ; r12 = int j > ; q15 = int maxcorr[4] (q15 is not used by xcorr_kernel_neon()) >+ ; ignored: >+ ; int arch > STMFD sp!, {r4-r6, lr} > LDR r6, [sp, #16] > VMOV.S32 q15, #1 >@@ -358,6 +360,8 @@ celt_pitch_xcorr_edsp PROC > ; r9 = opus_val32 sum3 > ; r1 = int max_pitch > ; r12 = int j >+ ; ignored: >+ ; int arch > STMFD sp!, {r4-r11, lr} > MOV r5, r1 > LDR r1, [sp, #36] >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/fft_arm.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/fft_arm.h >index 0cb55d8e22d2b87e69c0e55806da49e58a58dfd4..0b78175f3a9aa632045f13fafb20d4e91799d2b5 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/fft_arm.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/fft_arm.h >@@ -34,7 +34,6 @@ > #if !defined(FFT_ARM_H) > #define FFT_ARM_H > >-#include "config.h" > #include "kiss_fft.h" > > #if defined(HAVE_ARM_NE10) >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/fixed_armv4.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/fixed_armv4.h >index efb3b1896a866b1d5ec861fedbb334575a464c4d..d84888a772acf9b8534b8e030f204189dffe748c 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/fixed_armv4.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/fixed_armv4.h >@@ -37,7 +37,7 @@ static OPUS_INLINE opus_val32 MULT16_32_Q16_armv4(opus_val16 a, opus_val32 b) > "#MULT16_32_Q16\n\t" > "smull %0, %1, %2, %3\n\t" > : "=&r"(rd_lo), "=&r"(rd_hi) >- : "%r"(b),"r"(a<<16) >+ : "%r"(b),"r"(SHL32(a,16)) > ); > return rd_hi; > } >@@ -54,10 +54,10 @@ static OPUS_INLINE opus_val32 MULT16_32_Q15_armv4(opus_val16 a, opus_val32 b) > "#MULT16_32_Q15\n\t" > "smull %0, %1, %2, %3\n\t" > : "=&r"(rd_lo), "=&r"(rd_hi) >- : "%r"(b), "r"(a<<16) >+ : "%r"(b), "r"(SHL32(a,16)) > ); > /*We intentionally don't OR in the high bit of rd_lo for speed.*/ >- return rd_hi<<1; >+ return SHL32(rd_hi,1); > } > #define MULT16_32_Q15(a, b) (MULT16_32_Q15_armv4(a, b)) > >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/fixed_armv5e.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/fixed_armv5e.h >index 36a6321101357e447d299d37d2a55d751c30d909..6bf73cbace346bf3c2887d2399b508b6b8ba5d77 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/fixed_armv5e.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/fixed_armv5e.h >@@ -59,7 +59,7 @@ static OPUS_INLINE opus_val32 MULT16_32_Q15_armv5e(opus_val16 a, opus_val32 b) > : "=r"(res) > : "r"(b), "r"(a) > ); >- return res<<1; >+ return SHL32(res,1); > } > #define MULT16_32_Q15(a, b) (MULT16_32_Q15_armv5e(a, b)) > >@@ -76,7 +76,7 @@ static OPUS_INLINE opus_val32 MAC16_32_Q15_armv5e(opus_val32 c, opus_val16 a, > "#MAC16_32_Q15\n\t" > "smlawb %0, %1, %2, %3;\n" > : "=r"(res) >- : "r"(b<<1), "r"(a), "r"(c) >+ : "r"(SHL32(b,1)), "r"(a), "r"(c) > ); > return res; > } >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/mdct_arm.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/mdct_arm.h >index 49cbb4457602891e4c306b57d7a09979452d4fc2..14200bac4b3463c6e722ecf2a21e98c9fda33d09 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/mdct_arm.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/mdct_arm.h >@@ -33,7 +33,6 @@ > #if !defined(MDCT_ARM_H) > #define MDCT_ARM_H > >-#include "config.h" > #include "mdct.h" > > #if defined(HAVE_ARM_NE10) >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/pitch_arm.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/pitch_arm.h >index 14331169eeb7b27a5adb3152b1bc813f3afd2421..bed8b04eac11fc6ed779fca97d04b4d2d01e4b51 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/pitch_arm.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/pitch_arm.h >@@ -30,11 +30,47 @@ > > # include "armcpu.h" > >+# if defined(OPUS_ARM_MAY_HAVE_NEON_INTR) >+opus_val32 celt_inner_prod_neon(const opus_val16 *x, const opus_val16 *y, int N); >+void dual_inner_prod_neon(const opus_val16 *x, const opus_val16 *y01, >+ const opus_val16 *y02, int N, opus_val32 *xy1, opus_val32 *xy2); >+ >+# if !defined(OPUS_HAVE_RTCD) && defined(OPUS_ARM_PRESUME_NEON) >+# define OVERRIDE_CELT_INNER_PROD (1) >+# define OVERRIDE_DUAL_INNER_PROD (1) >+# define celt_inner_prod(x, y, N, arch) ((void)(arch), PRESUME_NEON(celt_inner_prod)(x, y, N)) >+# define dual_inner_prod(x, y01, y02, N, xy1, xy2, arch) ((void)(arch), PRESUME_NEON(dual_inner_prod)(x, y01, y02, N, xy1, xy2)) >+# endif >+# endif >+ >+# if !defined(OVERRIDE_CELT_INNER_PROD) >+# if defined(OPUS_HAVE_RTCD) && (defined(OPUS_ARM_MAY_HAVE_NEON_INTR) && !defined(OPUS_ARM_PRESUME_NEON_INTR)) >+extern opus_val32 (*const CELT_INNER_PROD_IMPL[OPUS_ARCHMASK+1])(const opus_val16 *x, const opus_val16 *y, int N); >+# define OVERRIDE_CELT_INNER_PROD (1) >+# define celt_inner_prod(x, y, N, arch) ((*CELT_INNER_PROD_IMPL[(arch)&OPUS_ARCHMASK])(x, y, N)) >+# elif defined(OPUS_ARM_PRESUME_NEON_INTR) >+# define OVERRIDE_CELT_INNER_PROD (1) >+# define celt_inner_prod(x, y, N, arch) ((void)(arch), celt_inner_prod_neon(x, y, N)) >+# endif >+# endif >+ >+# if !defined(OVERRIDE_DUAL_INNER_PROD) >+# if defined(OPUS_HAVE_RTCD) && (defined(OPUS_ARM_MAY_HAVE_NEON_INTR) && !defined(OPUS_ARM_PRESUME_NEON_INTR)) >+extern void (*const DUAL_INNER_PROD_IMPL[OPUS_ARCHMASK+1])(const opus_val16 *x, >+ const opus_val16 *y01, const opus_val16 *y02, int N, opus_val32 *xy1, opus_val32 *xy2); >+# define OVERRIDE_DUAL_INNER_PROD (1) >+# define dual_inner_prod(x, y01, y02, N, xy1, xy2, arch) ((*DUAL_INNER_PROD_IMPL[(arch)&OPUS_ARCHMASK])(x, y01, y02, N, xy1, xy2)) >+# elif defined(OPUS_ARM_PRESUME_NEON_INTR) >+# define OVERRIDE_DUAL_INNER_PROD (1) >+# define dual_inner_prod(x, y01, y02, N, xy1, xy2, arch) ((void)(arch), dual_inner_prod_neon(x, y01, y02, N, xy1, xy2)) >+# endif >+# endif >+ > # if defined(FIXED_POINT) > > # if defined(OPUS_ARM_MAY_HAVE_NEON) > opus_val32 celt_pitch_xcorr_neon(const opus_val16 *_x, const opus_val16 *_y, >- opus_val32 *xcorr, int len, int max_pitch); >+ opus_val32 *xcorr, int len, int max_pitch, int arch); > # endif > > # if defined(OPUS_ARM_MAY_HAVE_MEDIA) >@@ -43,7 +79,7 @@ opus_val32 celt_pitch_xcorr_neon(const opus_val16 *_x, const opus_val16 *_y, > > # if defined(OPUS_ARM_MAY_HAVE_EDSP) > opus_val32 celt_pitch_xcorr_edsp(const opus_val16 *_x, const opus_val16 *_y, >- opus_val32 *xcorr, int len, int max_pitch); >+ opus_val32 *xcorr, int len, int max_pitch, int arch); > # endif > > # if defined(OPUS_HAVE_RTCD) && \ >@@ -52,18 +88,17 @@ opus_val32 celt_pitch_xcorr_edsp(const opus_val16 *_x, const opus_val16 *_y, > (defined(OPUS_ARM_MAY_HAVE_EDSP) && !defined(OPUS_ARM_PRESUME_EDSP))) > extern opus_val32 > (*const CELT_PITCH_XCORR_IMPL[OPUS_ARCHMASK+1])(const opus_val16 *, >- const opus_val16 *, opus_val32 *, int, int); >+ const opus_val16 *, opus_val32 *, int, int, int); > # define OVERRIDE_PITCH_XCORR (1) > # define celt_pitch_xcorr(_x, _y, xcorr, len, max_pitch, arch) \ > ((*CELT_PITCH_XCORR_IMPL[(arch)&OPUS_ARCHMASK])(_x, _y, \ >- xcorr, len, max_pitch)) >+ xcorr, len, max_pitch, arch)) > > # elif defined(OPUS_ARM_PRESUME_EDSP) || \ > defined(OPUS_ARM_PRESUME_MEDIA) || \ > defined(OPUS_ARM_PRESUME_NEON) > # define OVERRIDE_PITCH_XCORR (1) >-# define celt_pitch_xcorr(_x, _y, xcorr, len, max_pitch, arch) \ >- ((void)(arch),PRESUME_NEON(celt_pitch_xcorr)(_x, _y, xcorr, len, max_pitch)) >+# define celt_pitch_xcorr (PRESUME_NEON(celt_pitch_xcorr)) > > # endif > >@@ -99,25 +134,24 @@ extern void (*const XCORR_KERNEL_IMPL[OPUS_ARCHMASK + 1])( > /* Float case */ > #if defined(OPUS_ARM_MAY_HAVE_NEON_INTR) > void celt_pitch_xcorr_float_neon(const opus_val16 *_x, const opus_val16 *_y, >- opus_val32 *xcorr, int len, int max_pitch); >+ opus_val32 *xcorr, int len, int max_pitch, int arch); > #endif > > # if defined(OPUS_HAVE_RTCD) && \ > (defined(OPUS_ARM_MAY_HAVE_NEON_INTR) && !defined(OPUS_ARM_PRESUME_NEON_INTR)) > extern void > (*const CELT_PITCH_XCORR_IMPL[OPUS_ARCHMASK+1])(const opus_val16 *, >- const opus_val16 *, opus_val32 *, int, int); >+ const opus_val16 *, opus_val32 *, int, int, int); > > # define OVERRIDE_PITCH_XCORR (1) > # define celt_pitch_xcorr(_x, _y, xcorr, len, max_pitch, arch) \ > ((*CELT_PITCH_XCORR_IMPL[(arch)&OPUS_ARCHMASK])(_x, _y, \ >- xcorr, len, max_pitch)) >+ xcorr, len, max_pitch, arch)) > > # elif defined(OPUS_ARM_PRESUME_NEON_INTR) > > # define OVERRIDE_PITCH_XCORR (1) >-# define celt_pitch_xcorr(_x, _y, xcorr, len, max_pitch, arch) \ >- ((void)(arch),celt_pitch_xcorr_float_neon(_x, _y, xcorr, len, max_pitch)) >+# define celt_pitch_xcorr celt_pitch_xcorr_float_neon > > # endif > >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/pitch_neon_intr.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/pitch_neon_intr.c >new file mode 100644 >index 0000000000000000000000000000000000000000..1ac38c433a8a785535f95f93aefce1d43613fa80 >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/arm/pitch_neon_intr.c >@@ -0,0 +1,290 @@ >+/*********************************************************************** >+Copyright (c) 2017 Google Inc. >+Redistribution and use in source and binary forms, with or without >+modification, are permitted provided that the following conditions >+are met: >+- Redistributions of source code must retain the above copyright notice, >+this list of conditions and the following disclaimer. >+- Redistributions in binary form must reproduce the above copyright >+notice, this list of conditions and the following disclaimer in the >+documentation and/or other materials provided with the distribution. >+- Neither the name of Internet Society, IETF or IETF Trust, nor the >+names of specific contributors, may be used to endorse or promote >+products derived from this software without specific prior written >+permission. >+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" >+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE >+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE >+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE >+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE >+POSSIBILITY OF SUCH DAMAGE. >+***********************************************************************/ >+ >+#ifdef HAVE_CONFIG_H >+#include "config.h" >+#endif >+ >+#include <arm_neon.h> >+#include "pitch.h" >+ >+#ifdef FIXED_POINT >+ >+opus_val32 celt_inner_prod_neon(const opus_val16 *x, const opus_val16 *y, int N) >+{ >+ int i; >+ opus_val32 xy; >+ int16x8_t x_s16x8, y_s16x8; >+ int32x4_t xy_s32x4 = vdupq_n_s32(0); >+ int64x2_t xy_s64x2; >+ int64x1_t xy_s64x1; >+ >+ for (i = 0; i < N - 7; i += 8) { >+ x_s16x8 = vld1q_s16(&x[i]); >+ y_s16x8 = vld1q_s16(&y[i]); >+ xy_s32x4 = vmlal_s16(xy_s32x4, vget_low_s16 (x_s16x8), vget_low_s16 (y_s16x8)); >+ xy_s32x4 = vmlal_s16(xy_s32x4, vget_high_s16(x_s16x8), vget_high_s16(y_s16x8)); >+ } >+ >+ if (N - i >= 4) { >+ const int16x4_t x_s16x4 = vld1_s16(&x[i]); >+ const int16x4_t y_s16x4 = vld1_s16(&y[i]); >+ xy_s32x4 = vmlal_s16(xy_s32x4, x_s16x4, y_s16x4); >+ i += 4; >+ } >+ >+ xy_s64x2 = vpaddlq_s32(xy_s32x4); >+ xy_s64x1 = vadd_s64(vget_low_s64(xy_s64x2), vget_high_s64(xy_s64x2)); >+ xy = vget_lane_s32(vreinterpret_s32_s64(xy_s64x1), 0); >+ >+ for (; i < N; i++) { >+ xy = MAC16_16(xy, x[i], y[i]); >+ } >+ >+#ifdef OPUS_CHECK_ASM >+ celt_assert(celt_inner_prod_c(x, y, N) == xy); >+#endif >+ >+ return xy; >+} >+ >+void dual_inner_prod_neon(const opus_val16 *x, const opus_val16 *y01, const opus_val16 *y02, >+ int N, opus_val32 *xy1, opus_val32 *xy2) >+{ >+ int i; >+ opus_val32 xy01, xy02; >+ int16x8_t x_s16x8, y01_s16x8, y02_s16x8; >+ int32x4_t xy01_s32x4 = vdupq_n_s32(0); >+ int32x4_t xy02_s32x4 = vdupq_n_s32(0); >+ int64x2_t xy01_s64x2, xy02_s64x2; >+ int64x1_t xy01_s64x1, xy02_s64x1; >+ >+ for (i = 0; i < N - 7; i += 8) { >+ x_s16x8 = vld1q_s16(&x[i]); >+ y01_s16x8 = vld1q_s16(&y01[i]); >+ y02_s16x8 = vld1q_s16(&y02[i]); >+ xy01_s32x4 = vmlal_s16(xy01_s32x4, vget_low_s16 (x_s16x8), vget_low_s16 (y01_s16x8)); >+ xy02_s32x4 = vmlal_s16(xy02_s32x4, vget_low_s16 (x_s16x8), vget_low_s16 (y02_s16x8)); >+ xy01_s32x4 = vmlal_s16(xy01_s32x4, vget_high_s16(x_s16x8), vget_high_s16(y01_s16x8)); >+ xy02_s32x4 = vmlal_s16(xy02_s32x4, vget_high_s16(x_s16x8), vget_high_s16(y02_s16x8)); >+ } >+ >+ if (N - i >= 4) { >+ const int16x4_t x_s16x4 = vld1_s16(&x[i]); >+ const int16x4_t y01_s16x4 = vld1_s16(&y01[i]); >+ const int16x4_t y02_s16x4 = vld1_s16(&y02[i]); >+ xy01_s32x4 = vmlal_s16(xy01_s32x4, x_s16x4, y01_s16x4); >+ xy02_s32x4 = vmlal_s16(xy02_s32x4, x_s16x4, y02_s16x4); >+ i += 4; >+ } >+ >+ xy01_s64x2 = vpaddlq_s32(xy01_s32x4); >+ xy02_s64x2 = vpaddlq_s32(xy02_s32x4); >+ xy01_s64x1 = vadd_s64(vget_low_s64(xy01_s64x2), vget_high_s64(xy01_s64x2)); >+ xy02_s64x1 = vadd_s64(vget_low_s64(xy02_s64x2), vget_high_s64(xy02_s64x2)); >+ xy01 = vget_lane_s32(vreinterpret_s32_s64(xy01_s64x1), 0); >+ xy02 = vget_lane_s32(vreinterpret_s32_s64(xy02_s64x1), 0); >+ >+ for (; i < N; i++) { >+ xy01 = MAC16_16(xy01, x[i], y01[i]); >+ xy02 = MAC16_16(xy02, x[i], y02[i]); >+ } >+ *xy1 = xy01; >+ *xy2 = xy02; >+ >+#ifdef OPUS_CHECK_ASM >+ { >+ opus_val32 xy1_c, xy2_c; >+ dual_inner_prod_c(x, y01, y02, N, &xy1_c, &xy2_c); >+ celt_assert(xy1_c == *xy1); >+ celt_assert(xy2_c == *xy2); >+ } >+#endif >+} >+ >+#else /* !FIXED_POINT */ >+ >+/* ========================================================================== */ >+ >+#ifdef OPUS_CHECK_ASM >+ >+/* This part of code simulates floating-point NEON operations. */ >+ >+/* celt_inner_prod_neon_float_c_simulation() simulates the floating-point */ >+/* operations of celt_inner_prod_neon(), and both functions should have bit */ >+/* exact output. */ >+static opus_val32 celt_inner_prod_neon_float_c_simulation(const opus_val16 *x, const opus_val16 *y, int N) >+{ >+ int i; >+ opus_val32 xy, xy0 = 0, xy1 = 0, xy2 = 0, xy3 = 0; >+ for (i = 0; i < N - 3; i += 4) { >+ xy0 = MAC16_16(xy0, x[i + 0], y[i + 0]); >+ xy1 = MAC16_16(xy1, x[i + 1], y[i + 1]); >+ xy2 = MAC16_16(xy2, x[i + 2], y[i + 2]); >+ xy3 = MAC16_16(xy3, x[i + 3], y[i + 3]); >+ } >+ xy0 += xy2; >+ xy1 += xy3; >+ xy = xy0 + xy1; >+ for (; i < N; i++) { >+ xy = MAC16_16(xy, x[i], y[i]); >+ } >+ return xy; >+} >+ >+/* dual_inner_prod_neon_float_c_simulation() simulates the floating-point */ >+/* operations of dual_inner_prod_neon(), and both functions should have bit */ >+/* exact output. */ >+static void dual_inner_prod_neon_float_c_simulation(const opus_val16 *x, const opus_val16 *y01, const opus_val16 *y02, >+ int N, opus_val32 *xy1, opus_val32 *xy2) >+{ >+ int i; >+ opus_val32 xy01, xy02, xy01_0 = 0, xy01_1 = 0, xy01_2 = 0, xy01_3 = 0, xy02_0 = 0, xy02_1 = 0, xy02_2 = 0, xy02_3 = 0; >+ for (i = 0; i < N - 3; i += 4) { >+ xy01_0 = MAC16_16(xy01_0, x[i + 0], y01[i + 0]); >+ xy01_1 = MAC16_16(xy01_1, x[i + 1], y01[i + 1]); >+ xy01_2 = MAC16_16(xy01_2, x[i + 2], y01[i + 2]); >+ xy01_3 = MAC16_16(xy01_3, x[i + 3], y01[i + 3]); >+ xy02_0 = MAC16_16(xy02_0, x[i + 0], y02[i + 0]); >+ xy02_1 = MAC16_16(xy02_1, x[i + 1], y02[i + 1]); >+ xy02_2 = MAC16_16(xy02_2, x[i + 2], y02[i + 2]); >+ xy02_3 = MAC16_16(xy02_3, x[i + 3], y02[i + 3]); >+ } >+ xy01_0 += xy01_2; >+ xy02_0 += xy02_2; >+ xy01_1 += xy01_3; >+ xy02_1 += xy02_3; >+ xy01 = xy01_0 + xy01_1; >+ xy02 = xy02_0 + xy02_1; >+ for (; i < N; i++) { >+ xy01 = MAC16_16(xy01, x[i], y01[i]); >+ xy02 = MAC16_16(xy02, x[i], y02[i]); >+ } >+ *xy1 = xy01; >+ *xy2 = xy02; >+} >+ >+#endif /* OPUS_CHECK_ASM */ >+ >+/* ========================================================================== */ >+ >+opus_val32 celt_inner_prod_neon(const opus_val16 *x, const opus_val16 *y, int N) >+{ >+ int i; >+ opus_val32 xy; >+ float32x4_t xy_f32x4 = vdupq_n_f32(0); >+ float32x2_t xy_f32x2; >+ >+ for (i = 0; i < N - 7; i += 8) { >+ float32x4_t x_f32x4, y_f32x4; >+ x_f32x4 = vld1q_f32(&x[i]); >+ y_f32x4 = vld1q_f32(&y[i]); >+ xy_f32x4 = vmlaq_f32(xy_f32x4, x_f32x4, y_f32x4); >+ x_f32x4 = vld1q_f32(&x[i + 4]); >+ y_f32x4 = vld1q_f32(&y[i + 4]); >+ xy_f32x4 = vmlaq_f32(xy_f32x4, x_f32x4, y_f32x4); >+ } >+ >+ if (N - i >= 4) { >+ const float32x4_t x_f32x4 = vld1q_f32(&x[i]); >+ const float32x4_t y_f32x4 = vld1q_f32(&y[i]); >+ xy_f32x4 = vmlaq_f32(xy_f32x4, x_f32x4, y_f32x4); >+ i += 4; >+ } >+ >+ xy_f32x2 = vadd_f32(vget_low_f32(xy_f32x4), vget_high_f32(xy_f32x4)); >+ xy_f32x2 = vpadd_f32(xy_f32x2, xy_f32x2); >+ xy = vget_lane_f32(xy_f32x2, 0); >+ >+ for (; i < N; i++) { >+ xy = MAC16_16(xy, x[i], y[i]); >+ } >+ >+#ifdef OPUS_CHECK_ASM >+ celt_assert(ABS32(celt_inner_prod_neon_float_c_simulation(x, y, N) - xy) <= VERY_SMALL); >+#endif >+ >+ return xy; >+} >+ >+void dual_inner_prod_neon(const opus_val16 *x, const opus_val16 *y01, const opus_val16 *y02, >+ int N, opus_val32 *xy1, opus_val32 *xy2) >+{ >+ int i; >+ opus_val32 xy01, xy02; >+ float32x4_t xy01_f32x4 = vdupq_n_f32(0); >+ float32x4_t xy02_f32x4 = vdupq_n_f32(0); >+ float32x2_t xy01_f32x2, xy02_f32x2; >+ >+ for (i = 0; i < N - 7; i += 8) { >+ float32x4_t x_f32x4, y01_f32x4, y02_f32x4; >+ x_f32x4 = vld1q_f32(&x[i]); >+ y01_f32x4 = vld1q_f32(&y01[i]); >+ y02_f32x4 = vld1q_f32(&y02[i]); >+ xy01_f32x4 = vmlaq_f32(xy01_f32x4, x_f32x4, y01_f32x4); >+ xy02_f32x4 = vmlaq_f32(xy02_f32x4, x_f32x4, y02_f32x4); >+ x_f32x4 = vld1q_f32(&x[i + 4]); >+ y01_f32x4 = vld1q_f32(&y01[i + 4]); >+ y02_f32x4 = vld1q_f32(&y02[i + 4]); >+ xy01_f32x4 = vmlaq_f32(xy01_f32x4, x_f32x4, y01_f32x4); >+ xy02_f32x4 = vmlaq_f32(xy02_f32x4, x_f32x4, y02_f32x4); >+ } >+ >+ if (N - i >= 4) { >+ const float32x4_t x_f32x4 = vld1q_f32(&x[i]); >+ const float32x4_t y01_f32x4 = vld1q_f32(&y01[i]); >+ const float32x4_t y02_f32x4 = vld1q_f32(&y02[i]); >+ xy01_f32x4 = vmlaq_f32(xy01_f32x4, x_f32x4, y01_f32x4); >+ xy02_f32x4 = vmlaq_f32(xy02_f32x4, x_f32x4, y02_f32x4); >+ i += 4; >+ } >+ >+ xy01_f32x2 = vadd_f32(vget_low_f32(xy01_f32x4), vget_high_f32(xy01_f32x4)); >+ xy02_f32x2 = vadd_f32(vget_low_f32(xy02_f32x4), vget_high_f32(xy02_f32x4)); >+ xy01_f32x2 = vpadd_f32(xy01_f32x2, xy01_f32x2); >+ xy02_f32x2 = vpadd_f32(xy02_f32x2, xy02_f32x2); >+ xy01 = vget_lane_f32(xy01_f32x2, 0); >+ xy02 = vget_lane_f32(xy02_f32x2, 0); >+ >+ for (; i < N; i++) { >+ xy01 = MAC16_16(xy01, x[i], y01[i]); >+ xy02 = MAC16_16(xy02, x[i], y02[i]); >+ } >+ *xy1 = xy01; >+ *xy2 = xy02; >+ >+#ifdef OPUS_CHECK_ASM >+ { >+ opus_val32 xy1_c, xy2_c; >+ dual_inner_prod_neon_float_c_simulation(x, y01, y02, N, &xy1_c, &xy2_c); >+ celt_assert(ABS32(xy1_c - *xy1) <= VERY_SMALL); >+ celt_assert(ABS32(xy2_c - *xy2) <= VERY_SMALL); >+ } >+#endif >+} >+ >+#endif /* FIXED_POINT */ >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/bands.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/bands.c >index f5307ae2edb67a03a974bb5dece6485d806965c6..3b1f5cfbbe8a81c7f47b700ac87899d809906285 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/bands.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/bands.c >@@ -65,7 +65,7 @@ opus_uint32 celt_lcg_rand(opus_uint32 seed) > > /* This is a cos() approximation designed to be bit-exact on any platform. Bit exactness > with this approximation is important because it has an impact on the bit allocation */ >-static opus_int16 bitexact_cos(opus_int16 x) >+opus_int16 bitexact_cos(opus_int16 x) > { > opus_int32 tmp; > opus_int16 x2; >@@ -77,7 +77,7 @@ static opus_int16 bitexact_cos(opus_int16 x) > return 1+x2; > } > >-static int bitexact_log2tan(int isin,int icos) >+int bitexact_log2tan(int isin,int icos) > { > int lc; > int ls; >@@ -92,10 +92,11 @@ static int bitexact_log2tan(int isin,int icos) > > #ifdef FIXED_POINT > /* Compute the amplitude (sqrt energy) in each of the bands */ >-void compute_band_energies(const CELTMode *m, const celt_sig *X, celt_ener *bandE, int end, int C, int LM) >+void compute_band_energies(const CELTMode *m, const celt_sig *X, celt_ener *bandE, int end, int C, int LM, int arch) > { > int i, c, N; > const opus_int16 *eBands = m->eBands; >+ (void)arch; > N = m->shortMdctSize<<LM; > c=0; do { > for (i=0;i<end;i++) >@@ -155,7 +156,7 @@ void normalise_bands(const CELTMode *m, const celt_sig * OPUS_RESTRICT freq, cel > > #else /* FIXED_POINT */ > /* Compute the amplitude (sqrt energy) in each of the bands */ >-void compute_band_energies(const CELTMode *m, const celt_sig *X, celt_ener *bandE, int end, int C, int LM) >+void compute_band_energies(const CELTMode *m, const celt_sig *X, celt_ener *bandE, int end, int C, int LM, int arch) > { > int i, c, N; > const opus_int16 *eBands = m->eBands; >@@ -164,7 +165,7 @@ void compute_band_energies(const CELTMode *m, const celt_sig *X, celt_ener *band > for (i=0;i<end;i++) > { > opus_val32 sum; >- sum = 1e-27f + celt_inner_prod_c(&X[c*N+(eBands[i]<<LM)], &X[c*N+(eBands[i]<<LM)], (eBands[i+1]-eBands[i])<<LM); >+ sum = 1e-27f + celt_inner_prod(&X[c*N+(eBands[i]<<LM)], &X[c*N+(eBands[i]<<LM)], (eBands[i+1]-eBands[i])<<LM, arch); > bandE[i+c*m->nbEBands] = celt_sqrt(sum); > /*printf ("%f ", bandE[i+c*m->nbEBands]);*/ > } >@@ -224,7 +225,7 @@ void denormalise_bands(const CELTMode *m, const celt_norm * OPUS_RESTRICT X, > #endif > j=M*eBands[i]; > band_end = M*eBands[i+1]; >- lg = ADD16(bandLogE[i], SHL16((opus_val16)eMeans[i],6)); >+ lg = SATURATE16(ADD32(bandLogE[i], SHL32((opus_val32)eMeans[i],6))); > #ifndef FIXED_POINT > g = celt_exp2(MIN32(32.f, lg)); > #else >@@ -241,12 +242,12 @@ void denormalise_bands(const CELTMode *m, const celt_norm * OPUS_RESTRICT X, > /* Handle extreme gains with negative shift. */ > if (shift<0) > { >- /* For shift < -2 we'd be likely to overflow, so we're capping >- the gain here. This shouldn't happen unless the bitstream is >- already corrupted. */ >- if (shift < -2) >+ /* For shift <= -2 and g > 16384 we'd be likely to overflow, so we're >+ capping the gain here, which is equivalent to a cap of 18 on lg. >+ This shouldn't trigger unless the bitstream is already corrupted. */ >+ if (shift <= -2) > { >- g = 32767; >+ g = 16384; > shift = -2; > } > do { >@@ -360,6 +361,30 @@ void anti_collapse(const CELTMode *m, celt_norm *X_, unsigned char *collapse_mas > } > } > >+/* Compute the weights to use for optimizing normalized distortion across >+ channels. We use the amplitude to weight square distortion, which means >+ that we use the square root of the value we would have been using if we >+ wanted to minimize the MSE in the non-normalized domain. This roughly >+ corresponds to some quick-and-dirty perceptual experiments I ran to >+ measure inter-aural masking (there doesn't seem to be any published data >+ on the topic). */ >+static void compute_channel_weights(celt_ener Ex, celt_ener Ey, opus_val16 w[2]) >+{ >+ celt_ener minE; >+#if FIXED_POINT >+ int shift; >+#endif >+ minE = MIN32(Ex, Ey); >+ /* Adjustment to make the weights a bit more conservative. */ >+ Ex = ADD32(Ex, minE/3); >+ Ey = ADD32(Ey, minE/3); >+#if FIXED_POINT >+ shift = celt_ilog2(EPSILON+MAX32(Ex, Ey))-14; >+#endif >+ w[0] = VSHR32(Ex, shift); >+ w[1] = VSHR32(Ey, shift); >+} >+ > static void intensity_stereo(const CELTMode *m, celt_norm * OPUS_RESTRICT X, const celt_norm * OPUS_RESTRICT Y, const celt_ener *bandE, int bandID, int N) > { > int i = bandID; >@@ -647,6 +672,7 @@ static int compute_qn(int N, int b, int offset, int pulse_cap, int stereo) > > struct band_ctx { > int encode; >+ int resynth; > const CELTMode *m; > int i; > int intensity; >@@ -657,6 +683,9 @@ struct band_ctx { > const celt_ener *bandE; > opus_uint32 seed; > int arch; >+ int theta_round; >+ int disable_inv; >+ int avoid_split_noise; > }; > > struct split_ctx { >@@ -714,8 +743,35 @@ static void compute_theta(struct band_ctx *ctx, struct split_ctx *sctx, > if (qn!=1) > { > if (encode) >- itheta = (itheta*(opus_int32)qn+8192)>>14; >- >+ { >+ if (!stereo || ctx->theta_round == 0) >+ { >+ itheta = (itheta*(opus_int32)qn+8192)>>14; >+ if (!stereo && ctx->avoid_split_noise && itheta > 0 && itheta < qn) >+ { >+ /* Check if the selected value of theta will cause the bit allocation >+ to inject noise on one side. If so, make sure the energy of that side >+ is zero. */ >+ int unquantized = celt_udiv((opus_int32)itheta*16384, qn); >+ imid = bitexact_cos((opus_int16)unquantized); >+ iside = bitexact_cos((opus_int16)(16384-unquantized)); >+ delta = FRAC_MUL16((N-1)<<7,bitexact_log2tan(iside,imid)); >+ if (delta > *b) >+ itheta = qn; >+ else if (delta < -*b) >+ itheta = 0; >+ } >+ } else { >+ int down; >+ /* Bias quantization towards itheta=0 and itheta=16384. */ >+ int bias = itheta > 8192 ? 32767/qn : -32767/qn; >+ down = IMIN(qn-1, IMAX(0, (itheta*(opus_int32)qn + bias)>>14)); >+ if (ctx->theta_round < 0) >+ itheta = down; >+ else >+ itheta = down+1; >+ } >+ } > /* Entropy coding of the angle. We use a uniform pdf for the > time split, a step for stereo, and a triangular one for the rest. */ > if (stereo && N>2) >@@ -793,7 +849,7 @@ static void compute_theta(struct band_ctx *ctx, struct split_ctx *sctx, > } else if (stereo) { > if (encode) > { >- inv = itheta > 8192; >+ inv = itheta > 8192 && !ctx->disable_inv; > if (inv) > { > int j; >@@ -810,6 +866,9 @@ static void compute_theta(struct band_ctx *ctx, struct split_ctx *sctx, > inv = ec_dec_bit_logp(ec, 2); > } else > inv = 0; >+ /* inv flag override to avoid problems with downmixing. */ >+ if (ctx->disable_inv) >+ inv = 0; > itheta = 0; > } > qalloc = ec_tell_frac(ec) - tell; >@@ -845,11 +904,6 @@ static void compute_theta(struct band_ctx *ctx, struct split_ctx *sctx, > static unsigned quant_band_n1(struct band_ctx *ctx, celt_norm *X, celt_norm *Y, int b, > celt_norm *lowband_out) > { >-#ifdef RESYNTH >- int resynth = 1; >-#else >- int resynth = !ctx->encode; >-#endif > int c; > int stereo; > celt_norm *x = X; >@@ -874,7 +928,7 @@ static unsigned quant_band_n1(struct band_ctx *ctx, celt_norm *X, celt_norm *Y, > ctx->remaining_bits -= 1<<BITRES; > b-=1<<BITRES; > } >- if (resynth) >+ if (ctx->resynth) > x[0] = sign ? -NORM_SCALING : NORM_SCALING; > x = Y; > } while (++c<1+stereo); >@@ -899,11 +953,6 @@ static unsigned quant_partition(struct band_ctx *ctx, celt_norm *X, > int B0=B; > opus_val16 mid=0, side=0; > unsigned cm=0; >-#ifdef RESYNTH >- int resynth = 1; >-#else >- int resynth = !ctx->encode; >-#endif > celt_norm *Y=NULL; > int encode; > const CELTMode *m; >@@ -935,8 +984,7 @@ static unsigned quant_partition(struct band_ctx *ctx, celt_norm *X, > fill = (fill&1)|(fill<<1); > B = (B+1)>>1; > >- compute_theta(ctx, &sctx, X, Y, N, &b, B, B0, >- LM, 0, &fill); >+ compute_theta(ctx, &sctx, X, Y, N, &b, B, B0, LM, 0, &fill); > imid = sctx.imid; > iside = sctx.iside; > delta = sctx.delta; >@@ -970,24 +1018,20 @@ static unsigned quant_partition(struct band_ctx *ctx, celt_norm *X, > rebalance = ctx->remaining_bits; > if (mbits >= sbits) > { >- cm = quant_partition(ctx, X, N, mbits, B, >- lowband, LM, >+ cm = quant_partition(ctx, X, N, mbits, B, lowband, LM, > MULT16_16_P15(gain,mid), fill); > rebalance = mbits - (rebalance-ctx->remaining_bits); > if (rebalance > 3<<BITRES && itheta!=0) > sbits += rebalance - (3<<BITRES); >- cm |= quant_partition(ctx, Y, N, sbits, B, >- next_lowband2, LM, >+ cm |= quant_partition(ctx, Y, N, sbits, B, next_lowband2, LM, > MULT16_16_P15(gain,side), fill>>B)<<(B0>>1); > } else { >- cm = quant_partition(ctx, Y, N, sbits, B, >- next_lowband2, LM, >+ cm = quant_partition(ctx, Y, N, sbits, B, next_lowband2, LM, > MULT16_16_P15(gain,side), fill>>B)<<(B0>>1); > rebalance = sbits - (rebalance-ctx->remaining_bits); > if (rebalance > 3<<BITRES && itheta!=16384) > mbits += rebalance - (3<<BITRES); >- cm |= quant_partition(ctx, X, N, mbits, B, >- lowband, LM, >+ cm |= quant_partition(ctx, X, N, mbits, B, lowband, LM, > MULT16_16_P15(gain,mid), fill); > } > } else { >@@ -1012,18 +1056,14 @@ static unsigned quant_partition(struct band_ctx *ctx, celt_norm *X, > /* Finally do the actual quantization */ > if (encode) > { >- cm = alg_quant(X, N, K, spread, B, ec >-#ifdef RESYNTH >- , gain >-#endif >- ); >+ cm = alg_quant(X, N, K, spread, B, ec, gain, ctx->resynth, ctx->arch); > } else { > cm = alg_unquant(X, N, K, spread, B, ec, gain); > } > } else { > /* If there's no pulse, fill the band anyway */ > int j; >- if (resynth) >+ if (ctx->resynth) > { > unsigned cm_mask; > /* B can be as large as 16, so this shift might overflow an int on a >@@ -1080,11 +1120,6 @@ static unsigned quant_band(struct band_ctx *ctx, celt_norm *X, > int recombine=0; > int longBlocks; > unsigned cm=0; >-#ifdef RESYNTH >- int resynth = 1; >-#else >- int resynth = !ctx->encode; >-#endif > int k; > int encode; > int tf_change; >@@ -1151,11 +1186,10 @@ static unsigned quant_band(struct band_ctx *ctx, celt_norm *X, > deinterleave_hadamard(lowband, N_B>>recombine, B0<<recombine, longBlocks); > } > >- cm = quant_partition(ctx, X, N, b, B, lowband, >- LM, gain, fill); >+ cm = quant_partition(ctx, X, N, b, B, lowband, LM, gain, fill); > > /* This code is used by the decoder and by the resynthesis-enabled encoder */ >- if (resynth) >+ if (ctx->resynth) > { > /* Undo the sample reorganization going from time order to frequency order */ > if (B0>1) >@@ -1208,11 +1242,6 @@ static unsigned quant_band_stereo(struct band_ctx *ctx, celt_norm *X, celt_norm > int inv = 0; > opus_val16 mid=0, side=0; > unsigned cm=0; >-#ifdef RESYNTH >- int resynth = 1; >-#else >- int resynth = !ctx->encode; >-#endif > int mbits, sbits, delta; > int itheta; > int qalloc; >@@ -1232,8 +1261,7 @@ static unsigned quant_band_stereo(struct band_ctx *ctx, celt_norm *X, celt_norm > > orig_fill = fill; > >- compute_theta(ctx, &sctx, X, Y, N, &b, B, B, >- LM, 1, &fill); >+ compute_theta(ctx, &sctx, X, Y, N, &b, B, B, LM, 1, &fill); > inv = sctx.inv; > imid = sctx.imid; > iside = sctx.iside; >@@ -1281,13 +1309,13 @@ static unsigned quant_band_stereo(struct band_ctx *ctx, celt_norm *X, celt_norm > sign = 1-2*sign; > /* We use orig_fill here because we want to fold the side, but if > itheta==16384, we'll have cleared the low bits of fill. */ >- cm = quant_band(ctx, x2, N, mbits, B, lowband, >- LM, lowband_out, Q15ONE, lowband_scratch, orig_fill); >+ cm = quant_band(ctx, x2, N, mbits, B, lowband, LM, lowband_out, Q15ONE, >+ lowband_scratch, orig_fill); > /* We don't split N=2 bands, so cm is either 1 or 0 (for a fold-collapse), > and there's no need to worry about mixing with the other channel. */ > y2[0] = -sign*x2[1]; > y2[1] = sign*x2[0]; >- if (resynth) >+ if (ctx->resynth) > { > celt_norm tmp; > X[0] = MULT16_16_Q15(mid, X[0]); >@@ -1314,38 +1342,32 @@ static unsigned quant_band_stereo(struct band_ctx *ctx, celt_norm *X, celt_norm > { > /* In stereo mode, we do not apply a scaling to the mid because we need the normalized > mid for folding later. */ >- cm = quant_band(ctx, X, N, mbits, B, >- lowband, LM, lowband_out, >- Q15ONE, lowband_scratch, fill); >+ cm = quant_band(ctx, X, N, mbits, B, lowband, LM, lowband_out, Q15ONE, >+ lowband_scratch, fill); > rebalance = mbits - (rebalance-ctx->remaining_bits); > if (rebalance > 3<<BITRES && itheta!=0) > sbits += rebalance - (3<<BITRES); > > /* For a stereo split, the high bits of fill are always zero, so no > folding will be done to the side. */ >- cm |= quant_band(ctx, Y, N, sbits, B, >- NULL, LM, NULL, >- side, NULL, fill>>B); >+ cm |= quant_band(ctx, Y, N, sbits, B, NULL, LM, NULL, side, NULL, fill>>B); > } else { > /* For a stereo split, the high bits of fill are always zero, so no > folding will be done to the side. */ >- cm = quant_band(ctx, Y, N, sbits, B, >- NULL, LM, NULL, >- side, NULL, fill>>B); >+ cm = quant_band(ctx, Y, N, sbits, B, NULL, LM, NULL, side, NULL, fill>>B); > rebalance = sbits - (rebalance-ctx->remaining_bits); > if (rebalance > 3<<BITRES && itheta!=16384) > mbits += rebalance - (3<<BITRES); > /* In stereo mode, we do not apply a scaling to the mid because we need the normalized > mid for folding later. */ >- cm |= quant_band(ctx, X, N, mbits, B, >- lowband, LM, lowband_out, >- Q15ONE, lowband_scratch, fill); >+ cm |= quant_band(ctx, X, N, mbits, B, lowband, LM, lowband_out, Q15ONE, >+ lowband_scratch, fill); > } > } > > > /* This code is used by the decoder and by the resynthesis-enabled encoder */ >- if (resynth) >+ if (ctx->resynth) > { > if (N!=2) > stereo_merge(X, Y, mid, N, ctx->arch); >@@ -1359,19 +1381,38 @@ static unsigned quant_band_stereo(struct band_ctx *ctx, celt_norm *X, celt_norm > return cm; > } > >+static void special_hybrid_folding(const CELTMode *m, celt_norm *norm, celt_norm *norm2, int start, int M, int dual_stereo) >+{ >+ int n1, n2; >+ const opus_int16 * OPUS_RESTRICT eBands = m->eBands; >+ n1 = M*(eBands[start+1]-eBands[start]); >+ n2 = M*(eBands[start+2]-eBands[start+1]); >+ /* Duplicate enough of the first band folding data to be able to fold the second band. >+ Copies no data for CELT-only mode. */ >+ OPUS_COPY(&norm[n1], &norm[2*n1 - n2], n2-n1); >+ if (dual_stereo) >+ OPUS_COPY(&norm2[n1], &norm2[2*n1 - n2], n2-n1); >+} > > void quant_all_bands(int encode, const CELTMode *m, int start, int end, > celt_norm *X_, celt_norm *Y_, unsigned char *collapse_masks, > const celt_ener *bandE, int *pulses, int shortBlocks, int spread, > int dual_stereo, int intensity, int *tf_res, opus_int32 total_bits, > opus_int32 balance, ec_ctx *ec, int LM, int codedBands, >- opus_uint32 *seed, int arch) >+ opus_uint32 *seed, int complexity, int arch, int disable_inv) > { > int i; > opus_int32 remaining_bits; > const opus_int16 * OPUS_RESTRICT eBands = m->eBands; > celt_norm * OPUS_RESTRICT norm, * OPUS_RESTRICT norm2; > VARDECL(celt_norm, _norm); >+ VARDECL(celt_norm, _lowband_scratch); >+ VARDECL(celt_norm, X_save); >+ VARDECL(celt_norm, Y_save); >+ VARDECL(celt_norm, X_save2); >+ VARDECL(celt_norm, Y_save2); >+ VARDECL(celt_norm, norm_save2); >+ int resynth_alloc; > celt_norm *lowband_scratch; > int B; > int M; >@@ -1379,10 +1420,11 @@ void quant_all_bands(int encode, const CELTMode *m, int start, int end, > int update_lowband = 1; > int C = Y_ != NULL ? 2 : 1; > int norm_offset; >+ int theta_rdo = encode && Y_!=NULL && !dual_stereo && complexity>=8; > #ifdef RESYNTH > int resynth = 1; > #else >- int resynth = !encode; >+ int resynth = !encode || theta_rdo; > #endif > struct band_ctx ctx; > SAVE_STACK; >@@ -1395,9 +1437,24 @@ void quant_all_bands(int encode, const CELTMode *m, int start, int end, > ALLOC(_norm, C*(M*eBands[m->nbEBands-1]-norm_offset), celt_norm); > norm = _norm; > norm2 = norm + M*eBands[m->nbEBands-1]-norm_offset; >- /* We can use the last band as scratch space because we don't need that >- scratch space for the last band. */ >- lowband_scratch = X_+M*eBands[m->nbEBands-1]; >+ >+ /* For decoding, we can use the last band as scratch space because we don't need that >+ scratch space for the last band and we don't care about the data there until we're >+ decoding the last band. */ >+ if (encode && resynth) >+ resynth_alloc = M*(eBands[m->nbEBands]-eBands[m->nbEBands-1]); >+ else >+ resynth_alloc = ALLOC_NONE; >+ ALLOC(_lowband_scratch, resynth_alloc, celt_norm); >+ if (encode && resynth) >+ lowband_scratch = _lowband_scratch; >+ else >+ lowband_scratch = X_+M*eBands[m->nbEBands-1]; >+ ALLOC(X_save, resynth_alloc, celt_norm); >+ ALLOC(Y_save, resynth_alloc, celt_norm); >+ ALLOC(X_save2, resynth_alloc, celt_norm); >+ ALLOC(Y_save2, resynth_alloc, celt_norm); >+ ALLOC(norm_save2, resynth_alloc, celt_norm); > > lowband_offset = 0; > ctx.bandE = bandE; >@@ -1408,6 +1465,11 @@ void quant_all_bands(int encode, const CELTMode *m, int start, int end, > ctx.seed = *seed; > ctx.spread = spread; > ctx.arch = arch; >+ ctx.disable_inv = disable_inv; >+ ctx.resynth = resynth; >+ ctx.theta_round = 0; >+ /* Avoid injecting noise in the first band on transients. */ >+ ctx.avoid_split_noise = B > 1; > for (i=start;i<end;i++) > { > opus_int32 tell; >@@ -1445,8 +1507,15 @@ void quant_all_bands(int encode, const CELTMode *m, int start, int end, > b = 0; > } > >+#ifdef ENABLE_UPDATE_DRAFT >+ if (resynth && (M*eBands[i]-N >= M*eBands[start] || i==start+1) && (update_lowband || lowband_offset==0)) >+ lowband_offset = i; >+ if (i == start+1) >+ special_hybrid_folding(m, norm, norm2, start, M, dual_stereo); >+#else > if (resynth && M*eBands[i]-N >= M*eBands[start] && (update_lowband || lowband_offset==0)) > lowband_offset = i; >+#endif > > tf_change = tf_res[i]; > ctx.tf_change = tf_change; >@@ -1457,7 +1526,7 @@ void quant_all_bands(int encode, const CELTMode *m, int start, int end, > Y = norm; > lowband_scratch = NULL; > } >- if (i==end-1) >+ if (last && !theta_rdo) > lowband_scratch = NULL; > > /* Get a conservative estimate of the collapse_mask's for the bands we're >@@ -1472,7 +1541,11 @@ void quant_all_bands(int encode, const CELTMode *m, int start, int end, > fold_start = lowband_offset; > while(M*eBands[--fold_start] > effective_lowband+norm_offset); > fold_end = lowband_offset-1; >+#ifdef ENABLE_UPDATE_DRAFT >+ while(++fold_end < i && M*eBands[fold_end] < effective_lowband+norm_offset+N); >+#else > while(M*eBands[++fold_end] < effective_lowband+norm_offset+N); >+#endif > x_cm = y_cm = 0; > fold_i = fold_start; do { > x_cm |= collapse_masks[fold_i*C+0]; >@@ -1505,13 +1578,77 @@ void quant_all_bands(int encode, const CELTMode *m, int start, int end, > } else { > if (Y!=NULL) > { >- x_cm = quant_band_stereo(&ctx, X, Y, N, b, B, >- effective_lowband != -1 ? norm+effective_lowband : NULL, LM, >- last?NULL:norm+M*eBands[i]-norm_offset, lowband_scratch, x_cm|y_cm); >+ if (theta_rdo && i < intensity) >+ { >+ ec_ctx ec_save, ec_save2; >+ struct band_ctx ctx_save, ctx_save2; >+ opus_val32 dist0, dist1; >+ unsigned cm, cm2; >+ int nstart_bytes, nend_bytes, save_bytes; >+ unsigned char *bytes_buf; >+ unsigned char bytes_save[1275]; >+ opus_val16 w[2]; >+ compute_channel_weights(bandE[i], bandE[i+m->nbEBands], w); >+ /* Make a copy. */ >+ cm = x_cm|y_cm; >+ ec_save = *ec; >+ ctx_save = ctx; >+ OPUS_COPY(X_save, X, N); >+ OPUS_COPY(Y_save, Y, N); >+ /* Encode and round down. */ >+ ctx.theta_round = -1; >+ x_cm = quant_band_stereo(&ctx, X, Y, N, b, B, >+ effective_lowband != -1 ? norm+effective_lowband : NULL, LM, >+ last?NULL:norm+M*eBands[i]-norm_offset, lowband_scratch, cm); >+ dist0 = MULT16_32_Q15(w[0], celt_inner_prod(X_save, X, N, arch)) + MULT16_32_Q15(w[1], celt_inner_prod(Y_save, Y, N, arch)); >+ >+ /* Save first result. */ >+ cm2 = x_cm; >+ ec_save2 = *ec; >+ ctx_save2 = ctx; >+ OPUS_COPY(X_save2, X, N); >+ OPUS_COPY(Y_save2, Y, N); >+ if (!last) >+ OPUS_COPY(norm_save2, norm+M*eBands[i]-norm_offset, N); >+ nstart_bytes = ec_save.offs; >+ nend_bytes = ec_save.storage; >+ bytes_buf = ec_save.buf+nstart_bytes; >+ save_bytes = nend_bytes-nstart_bytes; >+ OPUS_COPY(bytes_save, bytes_buf, save_bytes); >+ >+ /* Restore */ >+ *ec = ec_save; >+ ctx = ctx_save; >+ OPUS_COPY(X, X_save, N); >+ OPUS_COPY(Y, Y_save, N); >+ if (i == start+1) >+ special_hybrid_folding(m, norm, norm2, start, M, dual_stereo); >+ /* Encode and round up. */ >+ ctx.theta_round = 1; >+ x_cm = quant_band_stereo(&ctx, X, Y, N, b, B, >+ effective_lowband != -1 ? norm+effective_lowband : NULL, LM, >+ last?NULL:norm+M*eBands[i]-norm_offset, lowband_scratch, cm); >+ dist1 = MULT16_32_Q15(w[0], celt_inner_prod(X_save, X, N, arch)) + MULT16_32_Q15(w[1], celt_inner_prod(Y_save, Y, N, arch)); >+ if (dist0 >= dist1) { >+ x_cm = cm2; >+ *ec = ec_save2; >+ ctx = ctx_save2; >+ OPUS_COPY(X, X_save2, N); >+ OPUS_COPY(Y, Y_save2, N); >+ if (!last) >+ OPUS_COPY(norm+M*eBands[i]-norm_offset, norm_save2, N); >+ OPUS_COPY(bytes_buf, bytes_save, save_bytes); >+ } >+ } else { >+ ctx.theta_round = 0; >+ x_cm = quant_band_stereo(&ctx, X, Y, N, b, B, >+ effective_lowband != -1 ? norm+effective_lowband : NULL, LM, >+ last?NULL:norm+M*eBands[i]-norm_offset, lowband_scratch, x_cm|y_cm); >+ } > } else { > x_cm = quant_band(&ctx, X, N, b, B, > effective_lowband != -1 ? norm+effective_lowband : NULL, LM, >- last?NULL:norm+M*eBands[i]-norm_offset, Q15ONE, lowband_scratch, x_cm|y_cm); >+ last?NULL:norm+M*eBands[i]-norm_offset, Q15ONE, lowband_scratch, x_cm|y_cm); > } > y_cm = x_cm; > } >@@ -1521,6 +1658,9 @@ void quant_all_bands(int encode, const CELTMode *m, int start, int end, > > /* Update the folding position only as long as we have 1 bit/sample depth. */ > update_lowband = b>(N<<BITRES); >+ /* We only need to avoid noise on a split for the first band. After that, we >+ have folding. */ >+ ctx.avoid_split_noise = 0; > } > *seed = ctx.seed; > >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/bands.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/bands.h >index e8bef4bad0e0b254d91062c36b7aae25d31dc78a..2488c1852130d65c1e760bf57ee85f65ec1bb3b0 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/bands.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/bands.h >@@ -36,12 +36,15 @@ > #include "entdec.h" > #include "rate.h" > >+opus_int16 bitexact_cos(opus_int16 x); >+int bitexact_log2tan(int isin,int icos); >+ > /** Compute the amplitude (sqrt energy) in each of the bands > * @param m Mode data > * @param X Spectrum > * @param bandE Square root of the energy for each band (returned) > */ >-void compute_band_energies(const CELTMode *m, const celt_sig *X, celt_ener *bandE, int end, int C, int LM); >+void compute_band_energies(const CELTMode *m, const celt_sig *X, celt_ener *bandE, int end, int C, int LM, int arch); > > /*void compute_noise_energies(const CELTMode *m, const celt_sig *X, const opus_val16 *tonality, celt_ener *bandE);*/ > >@@ -105,7 +108,7 @@ void quant_all_bands(int encode, const CELTMode *m, int start, int end, > const celt_ener *bandE, int *pulses, int shortBlocks, int spread, > int dual_stereo, int intensity, int *tf_res, opus_int32 total_bits, > opus_int32 balance, ec_ctx *ec, int M, int codedBands, opus_uint32 *seed, >- int arch); >+ int complexity, int arch, int disable_inv); > > void anti_collapse(const CELTMode *m, celt_norm *X_, > unsigned char *collapse_masks, int LM, int C, int size, int start, >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/celt.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/celt.c >index b121c51a1faa6486071950ee4a4595eda05e8bc9..9ce234695ce0d314279022861df15caba5190d83 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/celt.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/celt.c >@@ -111,26 +111,31 @@ void comb_filter_const_c(opus_val32 *y, opus_val32 *x, int T, int N, > t = MAC16_32_Q16(x[i], g10, x2); > t = MAC16_32_Q16(t, g11, ADD32(x1,x3)); > t = MAC16_32_Q16(t, g12, ADD32(x0,x4)); >+ t = SATURATE(t, SIG_SAT); > y[i] = t; > x4=SHL32(x[i-T+3],1); > t = MAC16_32_Q16(x[i+1], g10, x1); > t = MAC16_32_Q16(t, g11, ADD32(x0,x2)); > t = MAC16_32_Q16(t, g12, ADD32(x4,x3)); >+ t = SATURATE(t, SIG_SAT); > y[i+1] = t; > x3=SHL32(x[i-T+4],1); > t = MAC16_32_Q16(x[i+2], g10, x0); > t = MAC16_32_Q16(t, g11, ADD32(x4,x1)); > t = MAC16_32_Q16(t, g12, ADD32(x3,x2)); >+ t = SATURATE(t, SIG_SAT); > y[i+2] = t; > x2=SHL32(x[i-T+5],1); > t = MAC16_32_Q16(x[i+3], g10, x4); > t = MAC16_32_Q16(t, g11, ADD32(x3,x0)); > t = MAC16_32_Q16(t, g12, ADD32(x2,x1)); >+ t = SATURATE(t, SIG_SAT); > y[i+3] = t; > x1=SHL32(x[i-T+6],1); > t = MAC16_32_Q16(x[i+4], g10, x3); > t = MAC16_32_Q16(t, g11, ADD32(x2,x4)); > t = MAC16_32_Q16(t, g12, ADD32(x1,x0)); >+ t = SATURATE(t, SIG_SAT); > y[i+4] = t; > } > #ifdef CUSTOM_MODES >@@ -141,6 +146,7 @@ void comb_filter_const_c(opus_val32 *y, opus_val32 *x, int T, int N, > t = MAC16_32_Q16(x[i], g10, x2); > t = MAC16_32_Q16(t, g11, ADD32(x1,x3)); > t = MAC16_32_Q16(t, g12, ADD32(x0,x4)); >+ t = SATURATE(t, SIG_SAT); > y[i] = t; > x4=x3; > x3=x2; >@@ -169,6 +175,7 @@ void comb_filter_const_c(opus_val32 *y, opus_val32 *x, int T, int N, > + MULT16_32_Q15(g10,x2) > + MULT16_32_Q15(g11,ADD32(x1,x3)) > + MULT16_32_Q15(g12,ADD32(x0,x4)); >+ y[i] = SATURATE(y[i], SIG_SAT); > x4=x3; > x3=x2; > x2=x1; >@@ -200,6 +207,10 @@ void comb_filter(opus_val32 *y, opus_val32 *x, int T0, int T1, int N, > OPUS_MOVE(y, x, N); > return; > } >+ /* When the gain is zero, T0 and/or T1 is set to zero. We need >+ to have then be at least 2 to avoid processing garbage data. */ >+ T0 = IMAX(T0, COMBFILTER_MINPERIOD); >+ T1 = IMAX(T1, COMBFILTER_MINPERIOD); > g00 = MULT16_16_P15(g0, gains[tapset0][0]); > g01 = MULT16_16_P15(g0, gains[tapset0][1]); > g02 = MULT16_16_P15(g0, gains[tapset0][2]); >@@ -225,6 +236,7 @@ void comb_filter(opus_val32 *y, opus_val32 *x, int T0, int T1, int N, > + MULT16_32_Q15(MULT16_16_Q15(f,g10),x2) > + MULT16_32_Q15(MULT16_16_Q15(f,g11),ADD32(x1,x3)) > + MULT16_32_Q15(MULT16_16_Q15(f,g12),ADD32(x0,x4)); >+ y[i] = SATURATE(y[i], SIG_SAT); > x4=x3; > x3=x2; > x2=x1; >@@ -244,11 +256,16 @@ void comb_filter(opus_val32 *y, opus_val32 *x, int T0, int T1, int N, > } > #endif /* OVERRIDE_comb_filter */ > >+/* TF change table. Positive values mean better frequency resolution (longer >+ effective window), whereas negative values mean better time resolution >+ (shorter effective window). The second index is computed as: >+ 4*isTransient + 2*tf_select + per_band_flag */ > const signed char tf_select_table[4][8] = { >- {0, -1, 0, -1, 0,-1, 0,-1}, >- {0, -1, 0, -2, 1, 0, 1,-1}, >- {0, -2, 0, -3, 2, 0, 1,-1}, >- {0, -2, 0, -3, 3, 0, 1,-1}, >+ /*isTransient=0 isTransient=1 */ >+ {0, -1, 0, -1, 0,-1, 0,-1}, /* 2.5 ms */ >+ {0, -1, 0, -2, 1, 0, 1,-1}, /* 5 ms */ >+ {0, -2, 0, -3, 2, 0, 1,-1}, /* 10 ms */ >+ {0, -2, 0, -3, 3, 0, 1,-1}, /* 20 ms */ > }; > > >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/celt.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/celt.h >index d1f7eb690db3f641047b31bac7c41328cfba3058..7017530100a3d90456b766a558445db9ae43086d 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/celt.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/celt.h >@@ -50,6 +50,8 @@ extern "C" { > #define CELTDecoder OpusCustomDecoder > #define CELTMode OpusCustomMode > >+#define LEAK_BANDS 19 >+ > typedef struct { > int valid; > float tonality; >@@ -57,17 +59,25 @@ typedef struct { > float noisiness; > float activity; > float music_prob; >- int bandwidth; >-}AnalysisInfo; >+ float vad_prob; >+ int bandwidth; >+ float activity_probability; >+ /* Store as Q6 char to save space. */ >+ unsigned char leak_boost[LEAK_BANDS]; >+} AnalysisInfo; >+ >+typedef struct { >+ int signalType; >+ int offset; >+} SILKInfo; > > #define __celt_check_mode_ptr_ptr(ptr) ((ptr) + ((ptr) - (const CELTMode**)(ptr))) > > #define __celt_check_analysis_ptr(ptr) ((ptr) + ((ptr) - (const AnalysisInfo*)(ptr))) > >-/* Encoder/decoder Requests */ >+#define __celt_check_silkinfo_ptr(ptr) ((ptr) + ((ptr) - (const SILKInfo*)(ptr))) > >-/* Expose this option again when variable framesize actually works */ >-#define OPUS_FRAMESIZE_VARIABLE 5010 /**< Optimize the frame size dynamically */ >+/* Encoder/decoder Requests */ > > > #define CELT_SET_PREDICTION_REQUEST 10002 >@@ -116,6 +126,9 @@ typedef struct { > #define OPUS_SET_ENERGY_MASK_REQUEST 10026 > #define OPUS_SET_ENERGY_MASK(x) OPUS_SET_ENERGY_MASK_REQUEST, __opus_check_val16_ptr(x) > >+#define CELT_SET_SILK_INFO_REQUEST 10028 >+#define CELT_SET_SILK_INFO(x) CELT_SET_SILK_INFO_REQUEST, __celt_check_silkinfo_ptr(x) >+ > /* Encoder stuff */ > > int celt_encoder_get_size(int channels); >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/celt_decoder.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/celt_decoder.c >index b978bb34d1b7015817637cd0172425aa8fabb60b..567d745649b98ad9c661fbf53f73d0a7da0a78b0 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/celt_decoder.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/celt_decoder.c >@@ -73,6 +73,7 @@ struct OpusCustomDecoder { > int downsample; > int start, end; > int signalling; >+ int disable_inv; > int arch; > > /* Everything beyond this point gets cleared on a reset */ >@@ -163,6 +164,11 @@ OPUS_CUSTOM_NOSTATIC int opus_custom_decoder_init(CELTDecoder *st, const CELTMod > st->start = 0; > st->end = st->mode->effEBands; > st->signalling = 1; >+#ifdef ENABLE_UPDATE_DRAFT >+ st->disable_inv = channels == 1; >+#else >+ st->disable_inv = 0; >+#endif > st->arch = opus_select_arch(); > > opus_custom_decoder_ctl(st, OPUS_RESET_STATE); >@@ -177,6 +183,36 @@ void opus_custom_decoder_destroy(CELTDecoder *st) > } > #endif /* CUSTOM_MODES */ > >+#ifndef CUSTOM_MODES >+/* Special case for stereo with no downsampling and no accumulation. This is >+ quite common and we can make it faster by processing both channels in the >+ same loop, reducing overhead due to the dependency loop in the IIR filter. */ >+static void deemphasis_stereo_simple(celt_sig *in[], opus_val16 *pcm, int N, const opus_val16 coef0, >+ celt_sig *mem) >+{ >+ celt_sig * OPUS_RESTRICT x0; >+ celt_sig * OPUS_RESTRICT x1; >+ celt_sig m0, m1; >+ int j; >+ x0=in[0]; >+ x1=in[1]; >+ m0 = mem[0]; >+ m1 = mem[1]; >+ for (j=0;j<N;j++) >+ { >+ celt_sig tmp0, tmp1; >+ /* Add VERY_SMALL to x[] first to reduce dependency chain. */ >+ tmp0 = x0[j] + VERY_SMALL + m0; >+ tmp1 = x1[j] + VERY_SMALL + m1; >+ m0 = MULT16_32_Q15(coef0, tmp0); >+ m1 = MULT16_32_Q15(coef0, tmp1); >+ pcm[2*j ] = SCALEOUT(SIG2WORD16(tmp0)); >+ pcm[2*j+1] = SCALEOUT(SIG2WORD16(tmp1)); >+ } >+ mem[0] = m0; >+ mem[1] = m1; >+} >+#endif > > #ifndef RESYNTH > static >@@ -190,6 +226,14 @@ void deemphasis(celt_sig *in[], opus_val16 *pcm, int N, int C, int downsample, c > opus_val16 coef0; > VARDECL(celt_sig, scratch); > SAVE_STACK; >+#ifndef CUSTOM_MODES >+ /* Short version for common case. */ >+ if (downsample == 1 && C == 2 && !accum) >+ { >+ deemphasis_stereo_simple(in, pcm, N, coef[0], mem); >+ return; >+ } >+#endif > #ifndef FIXED_POINT > (void)accum; > celt_assert(accum==0); >@@ -225,7 +269,7 @@ void deemphasis(celt_sig *in[], opus_val16 *pcm, int N, int C, int downsample, c > /* Shortcut for the standard (non-custom modes) case */ > for (j=0;j<N;j++) > { >- celt_sig tmp = x[j] + m + VERY_SMALL; >+ celt_sig tmp = x[j] + VERY_SMALL + m; > m = MULT16_32_Q15(coef0, tmp); > scratch[j] = tmp; > } >@@ -246,7 +290,7 @@ void deemphasis(celt_sig *in[], opus_val16 *pcm, int N, int C, int downsample, c > { > for (j=0;j<N;j++) > { >- celt_sig tmp = x[j] + m + VERY_SMALL; >+ celt_sig tmp = x[j] + VERY_SMALL + m; > m = MULT16_32_Q15(coef0, tmp); > y[j*C] = SCALEOUT(SIG2WORD16(tmp)); > } >@@ -333,7 +377,7 @@ void celt_synthesis(const CELTMode *mode, celt_norm *X, celt_sig * out_syn[], > denormalise_bands(mode, X+N, freq2, oldBandE+nbEBands, start, effEnd, M, > downsample, silence); > for (i=0;i<N;i++) >- freq[i] = HALF32(ADD32(freq[i],freq2[i])); >+ freq[i] = ADD32(HALF32(freq[i]), HALF32(freq2[i])); > for (b=0;b<B;b++) > clt_mdct_backward(&mode->mdct, &freq[b], out_syn[0]+NB*b, mode->window, overlap, shift, B, arch); > } else { >@@ -345,6 +389,12 @@ void celt_synthesis(const CELTMode *mode, celt_norm *X, celt_sig * out_syn[], > clt_mdct_backward(&mode->mdct, &freq[b], out_syn[c]+NB*b, mode->window, overlap, shift, B, arch); > } while (++c<CC); > } >+ /* Saturate IMDCT output so that we can't overflow in the pitch postfilter >+ or in the */ >+ c=0; do { >+ for (i=0;i<N;i++) >+ out_syn[c][i] = SATURATE(out_syn[c][i], SIG_SAT); >+ } while (++c<CC); > RESTORE_STACK; > } > >@@ -506,10 +556,11 @@ static void celt_decode_lost(CELTDecoder * OPUS_RESTRICT st, int N, int LM) > } else { > /* Pitch-based PLC */ > const opus_val16 *window; >+ opus_val16 *exc; > opus_val16 fade = Q15ONE; > int pitch_index; > VARDECL(opus_val32, etmp); >- VARDECL(opus_val16, exc); >+ VARDECL(opus_val16, _exc); > > if (loss_count == 0) > { >@@ -520,7 +571,8 @@ static void celt_decode_lost(CELTDecoder * OPUS_RESTRICT st, int N, int LM) > } > > ALLOC(etmp, overlap, opus_val32); >- ALLOC(exc, MAX_PERIOD, opus_val16); >+ ALLOC(_exc, MAX_PERIOD+LPC_ORDER, opus_val16); >+ exc = _exc+LPC_ORDER; > window = mode->window; > c=0; do { > opus_val16 decay; >@@ -561,6 +613,23 @@ static void celt_decode_lost(CELTDecoder * OPUS_RESTRICT st, int N, int LM) > #endif > } > _celt_lpc(lpc+c*LPC_ORDER, ac, LPC_ORDER); >+#ifdef FIXED_POINT >+ /* For fixed-point, apply bandwidth expansion until we can guarantee that >+ no overflow can happen in the IIR filter. This means: >+ 32768*sum(abs(filter)) < 2^31 */ >+ while (1) { >+ opus_val16 tmp=Q15ONE; >+ opus_val32 sum=QCONST16(1., SIG_SHIFT); >+ for (i=0;i<LPC_ORDER;i++) >+ sum += ABS16(lpc[c*LPC_ORDER+i]); >+ if (sum < 65535) break; >+ for (i=0;i<LPC_ORDER;i++) >+ { >+ tmp = MULT16_16_Q15(QCONST16(.99f,15), tmp); >+ lpc[c*LPC_ORDER+i] = MULT16_16_Q15(lpc[c*LPC_ORDER+i], tmp); >+ } >+ } >+#endif > } > /* We want the excitation for 2 pitch periods in order to look for a > decaying signal, but we can't get more than MAX_PERIOD. */ >@@ -568,15 +637,14 @@ static void celt_decode_lost(CELTDecoder * OPUS_RESTRICT st, int N, int LM) > /* Initialize the LPC history with the samples just before the start > of the region for which we're computing the excitation. */ > { >- opus_val16 lpc_mem[LPC_ORDER]; > for (i=0;i<LPC_ORDER;i++) > { >- lpc_mem[i] = >- ROUND16(buf[DECODE_BUFFER_SIZE-exc_length-1-i], SIG_SHIFT); >+ exc[MAX_PERIOD-exc_length-LPC_ORDER+i] = >+ ROUND16(buf[DECODE_BUFFER_SIZE-exc_length-LPC_ORDER+i], SIG_SHIFT); > } > /* Compute the excitation for exc_length samples before the loss. */ > celt_fir(exc+MAX_PERIOD-exc_length, lpc+c*LPC_ORDER, >- exc+MAX_PERIOD-exc_length, exc_length, LPC_ORDER, lpc_mem, st->arch); >+ exc+MAX_PERIOD-exc_length, exc_length, LPC_ORDER, st->arch); > } > > /* Check if the waveform is decaying, and if so how fast. >@@ -630,9 +698,8 @@ static void celt_decode_lost(CELTDecoder * OPUS_RESTRICT st, int N, int LM) > tmp = ROUND16( > buf[DECODE_BUFFER_SIZE-MAX_PERIOD-N+extrapolation_offset+j], > SIG_SHIFT); >- S1 += SHR32(MULT16_16(tmp, tmp), 8); >+ S1 += SHR32(MULT16_16(tmp, tmp), 10); > } >- > { > opus_val16 lpc_mem[LPC_ORDER]; > /* Copy the last decoded samples (prior to the overlap region) to >@@ -644,6 +711,10 @@ static void celt_decode_lost(CELTDecoder * OPUS_RESTRICT st, int N, int LM) > celt_iir(buf+DECODE_BUFFER_SIZE-N, lpc+c*LPC_ORDER, > buf+DECODE_BUFFER_SIZE-N, extrapolation_len, LPC_ORDER, > lpc_mem, st->arch); >+#ifdef FIXED_POINT >+ for (i=0; i < extrapolation_len; i++) >+ buf[DECODE_BUFFER_SIZE-N+i] = SATURATE(buf[DECODE_BUFFER_SIZE-N+i], SIG_SAT); >+#endif > } > > /* Check if the synthesis energy is higher than expected, which can >@@ -654,7 +725,7 @@ static void celt_decode_lost(CELTDecoder * OPUS_RESTRICT st, int N, int LM) > for (i=0;i<extrapolation_len;i++) > { > opus_val16 tmp = ROUND16(buf[DECODE_BUFFER_SIZE-N+i], SIG_SHIFT); >- S2 += SHR32(MULT16_16(tmp, tmp), 8); >+ S2 += SHR32(MULT16_16(tmp, tmp), 10); > } > /* This checks for an "explosion" in the synthesis. */ > #ifdef FIXED_POINT >@@ -979,7 +1050,8 @@ int celt_decode_with_ec(CELTDecoder * OPUS_RESTRICT st, const unsigned char *dat > > quant_all_bands(0, mode, start, end, X, C==2 ? X+N : NULL, collapse_masks, > NULL, pulses, shortBlocks, spread_decision, dual_stereo, intensity, tf_res, >- len*(8<<BITRES)-anti_collapse_rsv, balance, dec, LM, codedBands, &st->rng, st->arch); >+ len*(8<<BITRES)-anti_collapse_rsv, balance, dec, LM, codedBands, &st->rng, 0, >+ st->arch, st->disable_inv); > > if (anti_collapse_rsv > 0) > { >@@ -1234,6 +1306,26 @@ int opus_custom_decoder_ctl(CELTDecoder * OPUS_RESTRICT st, int request, ...) > *value=st->rng; > } > break; >+ case OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST: >+ { >+ opus_int32 value = va_arg(ap, opus_int32); >+ if(value<0 || value>1) >+ { >+ goto bad_arg; >+ } >+ st->disable_inv = value; >+ } >+ break; >+ case OPUS_GET_PHASE_INVERSION_DISABLED_REQUEST: >+ { >+ opus_int32 *value = va_arg(ap, opus_int32*); >+ if (!value) >+ { >+ goto bad_arg; >+ } >+ *value = st->disable_inv; >+ } >+ break; > default: > goto bad_request; > } >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/celt_encoder.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/celt_encoder.c >index 3ee7a4d3f7a1dceb71e6a1bef14306ac9d217a32..053e5a3b2900c16f2907fb03be537ce3b5b1092b 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/celt_encoder.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/celt_encoder.c >@@ -73,8 +73,8 @@ struct OpusCustomEncoder { > int constrained_vbr; /* If zero, VBR can do whatever it likes with the rate */ > int loss_rate; > int lsb_depth; >- int variable_duration; > int lfe; >+ int disable_inv; > int arch; > > /* Everything beyond this point gets cleared on a reset */ >@@ -98,6 +98,7 @@ struct OpusCustomEncoder { > #endif > int consec_transient; > AnalysisInfo analysis; >+ SILKInfo silk_info; > > opus_val32 preemph_memE[2]; > opus_val32 preemph_memD[2]; >@@ -123,6 +124,7 @@ struct OpusCustomEncoder { > /* opus_val16 oldBandE[], Size = channels*mode->nbEBands */ > /* opus_val16 oldLogE[], Size = channels*mode->nbEBands */ > /* opus_val16 oldLogE2[], Size = channels*mode->nbEBands */ >+ /* opus_val16 energyError[], Size = channels*mode->nbEBands */ > }; > > int celt_encoder_get_size(int channels) >@@ -136,9 +138,10 @@ OPUS_CUSTOM_NOSTATIC int opus_custom_encoder_get_size(const CELTMode *mode, int > int size = sizeof(struct CELTEncoder) > + (channels*mode->overlap-1)*sizeof(celt_sig) /* celt_sig in_mem[channels*mode->overlap]; */ > + channels*COMBFILTER_MAXPERIOD*sizeof(celt_sig) /* celt_sig prefilter_mem[channels*COMBFILTER_MAXPERIOD]; */ >- + 3*channels*mode->nbEBands*sizeof(opus_val16); /* opus_val16 oldBandE[channels*mode->nbEBands]; */ >+ + 4*channels*mode->nbEBands*sizeof(opus_val16); /* opus_val16 oldBandE[channels*mode->nbEBands]; */ > /* opus_val16 oldLogE[channels*mode->nbEBands]; */ > /* opus_val16 oldLogE2[channels*mode->nbEBands]; */ >+ /* opus_val16 energyError[channels*mode->nbEBands]; */ > return size; > } > >@@ -178,7 +181,6 @@ static int opus_custom_encoder_init_arch(CELTEncoder *st, const CELTMode *mode, > st->start = 0; > st->end = st->mode->effEBands; > st->signalling = 1; >- > st->arch = arch; > > st->constrained_vbr = 1; >@@ -223,7 +225,8 @@ void opus_custom_encoder_destroy(CELTEncoder *st) > > > static int transient_analysis(const opus_val32 * OPUS_RESTRICT in, int len, int C, >- opus_val16 *tf_estimate, int *tf_chan) >+ opus_val16 *tf_estimate, int *tf_chan, int allow_weak_transients, >+ int *weak_transient) > { > int i; > VARDECL(opus_val16, tmp); >@@ -233,6 +236,12 @@ static int transient_analysis(const opus_val32 * OPUS_RESTRICT in, int len, int > int c; > opus_val16 tf_max; > int len2; >+ /* Forward masking: 6.7 dB/ms. */ >+#ifdef FIXED_POINT >+ int forward_shift = 4; >+#else >+ opus_val16 forward_decay = QCONST16(.0625f,15); >+#endif > /* Table of 6*64/x, trained on real data to minimize the average error */ > static const unsigned char inv_table[128] = { > 255,255,156,110, 86, 70, 59, 51, 45, 40, 37, 33, 31, 28, 26, 25, >@@ -247,6 +256,19 @@ static int transient_analysis(const opus_val32 * OPUS_RESTRICT in, int len, int > SAVE_STACK; > ALLOC(tmp, len, opus_val16); > >+ *weak_transient = 0; >+ /* For lower bitrates, let's be more conservative and have a forward masking >+ decay of 3.3 dB/ms. This avoids having to code transients at very low >+ bitrate (mostly for hybrid), which can result in unstable energy and/or >+ partial collapse. */ >+ if (allow_weak_transients) >+ { >+#ifdef FIXED_POINT >+ forward_shift = 5; >+#else >+ forward_decay = QCONST16(.03125f,15); >+#endif >+ } > len2=len/2; > for (c=0;c<C;c++) > { >@@ -269,7 +291,7 @@ static int transient_analysis(const opus_val32 * OPUS_RESTRICT in, int len, int > mem0 = mem1 + y - 2*x; > mem1 = x - .5f*y; > #endif >- tmp[i] = EXTRACT16(SHR32(y,2)); >+ tmp[i] = SROUND16(y, 2); > /*printf("%f ", tmp[i]);*/ > } > /*printf("\n");*/ >@@ -280,7 +302,7 @@ static int transient_analysis(const opus_val32 * OPUS_RESTRICT in, int len, int > /* Normalize tmp to max range */ > { > int shift=0; >- shift = 14-celt_ilog2(1+celt_maxabs16(tmp, len)); >+ shift = 14-celt_ilog2(MAX16(1, celt_maxabs16(tmp, len))); > if (shift!=0) > { > for (i=0;i<len;i++) >@@ -299,9 +321,9 @@ static int transient_analysis(const opus_val32 * OPUS_RESTRICT in, int len, int > mean += x2; > #ifdef FIXED_POINT > /* FIXME: Use PSHR16() instead */ >- tmp[i] = mem0 + PSHR32(x2-mem0,4); >+ tmp[i] = mem0 + PSHR32(x2-mem0,forward_shift); > #else >- tmp[i] = mem0 + MULT16_16_P15(QCONST16(.0625f,15),x2-mem0); >+ tmp[i] = mem0 + MULT16_16_P15(forward_decay,x2-mem0); > #endif > mem0 = tmp[i]; > } >@@ -311,6 +333,7 @@ static int transient_analysis(const opus_val32 * OPUS_RESTRICT in, int len, int > /* Backward pass to compute the pre-echo threshold */ > for (i=len2-1;i>=0;i--) > { >+ /* Backward masking: 13.9 dB/ms. */ > #ifdef FIXED_POINT > /* FIXME: Use PSHR16() instead */ > tmp[i] = mem0 + PSHR32(tmp[i]-mem0,3); >@@ -359,7 +382,12 @@ static int transient_analysis(const opus_val32 * OPUS_RESTRICT in, int len, int > } > } > is_transient = mask_metric>200; >- >+ /* For low bitrates, define "weak transients" that need to be >+ handled differently to avoid partial collapse. */ >+ if (allow_weak_transients && is_transient && mask_metric<600) { >+ is_transient = 0; >+ *weak_transient = 1; >+ } > /* Arbitrary metric for VBR boost */ > tf_max = MAX16(0,celt_sqrt(27*mask_metric)-42); > /* *tf_estimate = 1 + MIN16(1, sqrt(MAX16(0, tf_max-30))/20); */ >@@ -549,7 +577,7 @@ static opus_val32 l1_metric(const celt_norm *tmp, int N, int LM, opus_val16 bias > > static int tf_analysis(const CELTMode *m, int len, int isTransient, > int *tf_res, int lambda, celt_norm *X, int N0, int LM, >- int *tf_sum, opus_val16 tf_estimate, int tf_chan) >+ opus_val16 tf_estimate, int tf_chan) > { > int i; > VARDECL(int, metric); >@@ -574,7 +602,6 @@ static int tf_analysis(const CELTMode *m, int len, int isTransient, > ALLOC(path0, len, int); > ALLOC(path1, len, int); > >- *tf_sum = 0; > for (i=0;i<len;i++) > { > int k, N; >@@ -629,7 +656,6 @@ static int tf_analysis(const CELTMode *m, int len, int isTransient, > metric[i] = 2*best_level; > else > metric[i] = -2*best_level; >- *tf_sum += (isTransient ? LM : 0) - metric[i]/2; > /* For bands that can't be split to -1, set the metric to the half-way point to avoid > biasing the decision */ > if (narrow && (metric[i]==0 || metric[i]==-2*LM)) >@@ -754,7 +780,7 @@ static void tf_encode(int start, int end, int isTransient, int *tf_res, int LM, > static int alloc_trim_analysis(const CELTMode *m, const celt_norm *X, > const opus_val16 *bandLogE, int end, int LM, int C, int N0, > AnalysisInfo *analysis, opus_val16 *stereo_saving, opus_val16 tf_estimate, >- int intensity, opus_val16 surround_trim, int arch) >+ int intensity, opus_val16 surround_trim, opus_int32 equiv_rate, int arch) > { > int i; > opus_val32 diff=0; >@@ -762,6 +788,14 @@ static int alloc_trim_analysis(const CELTMode *m, const celt_norm *X, > int trim_index; > opus_val16 trim = QCONST16(5.f, 8); > opus_val16 logXC, logXC2; >+ /* At low bitrate, reducing the trim seems to help. At higher bitrates, it's less >+ clear what's best, so we're keeping it as it was before, at least for now. */ >+ if (equiv_rate < 64000) { >+ trim = QCONST16(4.f, 8); >+ } else if (equiv_rate < 80000) { >+ opus_int32 frac = (equiv_rate-64000) >> 10; >+ trim = QCONST16(4.f, 8) + QCONST16(1.f/16.f, 8)*frac; >+ } > if (C==2) > { > opus_val16 sum = 0; /* Q10 */ >@@ -809,7 +843,7 @@ static int alloc_trim_analysis(const CELTMode *m, const celt_norm *X, > } while (++c<C); > diff /= C*(end-1); > /*printf("%f\n", diff);*/ >- trim -= MAX16(-QCONST16(2.f, 8), MIN16(QCONST16(2.f, 8), SHR16(diff+QCONST16(1.f, DB_SHIFT),DB_SHIFT-8)/6 )); >+ trim -= MAX32(-QCONST16(2.f, 8), MIN32(QCONST16(2.f, 8), SHR32(diff+QCONST16(1.f, DB_SHIFT),DB_SHIFT-8)/6 )); > trim -= SHR16(surround_trim, DB_SHIFT-8); > trim -= 2*SHR16(tf_estimate, 14-8); > #ifndef DISABLE_FLOAT_API >@@ -930,7 +964,7 @@ static opus_val16 median_of_3(const opus_val16 *x) > static opus_val16 dynalloc_analysis(const opus_val16 *bandLogE, const opus_val16 *bandLogE2, > int nbEBands, int start, int end, int C, int *offsets, int lsb_depth, const opus_int16 *logN, > int isTransient, int vbr, int constrained_vbr, const opus_int16 *eBands, int LM, >- int effectiveBytes, opus_int32 *tot_boost_, int lfe, opus_val16 *surround_dynalloc) >+ int effectiveBytes, opus_int32 *tot_boost_, int lfe, opus_val16 *surround_dynalloc, AnalysisInfo *analysis) > { > int i, c; > opus_int32 tot_boost=0; >@@ -1020,14 +1054,26 @@ static opus_val16 dynalloc_analysis(const opus_val16 *bandLogE, const opus_val16 > } > for (i=start;i<end;i++) > { >- int width; >- int boost; >- int boost_bits; >- > if (i<8) > follower[i] *= 2; > if (i>=12) > follower[i] = HALF16(follower[i]); >+ } >+#ifdef DISABLE_FLOAT_API >+ (void)analysis; >+#else >+ if (analysis->valid) >+ { >+ for (i=start;i<IMIN(LEAK_BANDS, end);i++) >+ follower[i] = follower[i] + QCONST16(1.f/64.f, DB_SHIFT)*analysis->leak_boost[i]; >+ } >+#endif >+ for (i=start;i<end;i++) >+ { >+ int width; >+ int boost; >+ int boost_bits; >+ > follower[i] = MIN16(follower[i], QCONST16(4, DB_SHIFT)); > > width = C*(eBands[i+1]-eBands[i])<<LM; >@@ -1042,11 +1088,11 @@ static opus_val16 dynalloc_analysis(const opus_val16 *bandLogE, const opus_val16 > boost = (int)SHR32(EXTEND32(follower[i])*width/6,DB_SHIFT); > boost_bits = boost*6<<BITRES; > } >- /* For CBR and non-transient CVBR frames, limit dynalloc to 1/4 of the bits */ >+ /* For CBR and non-transient CVBR frames, limit dynalloc to 2/3 of the bits */ > if ((!vbr || (constrained_vbr&&!isTransient)) >- && (tot_boost+boost_bits)>>BITRES>>3 > effectiveBytes/4) >+ && (tot_boost+boost_bits)>>BITRES>>3 > 2*effectiveBytes/3) > { >- opus_int32 cap = ((effectiveBytes/4)<<BITRES<<3); >+ opus_int32 cap = ((2*effectiveBytes/3)<<BITRES<<3); > offsets[i] = cap-tot_boost; > tot_boost = cap; > break; >@@ -1193,7 +1239,7 @@ static int compute_vbr(const CELTMode *mode, AnalysisInfo *analysis, opus_int32 > int LM, opus_int32 bitrate, int lastCodedBands, int C, int intensity, > int constrained_vbr, opus_val16 stereo_saving, int tot_boost, > opus_val16 tf_estimate, int pitch_change, opus_val16 maxDepth, >- int variable_duration, int lfe, int has_surround_mask, opus_val16 surround_masking, >+ int lfe, int has_surround_mask, opus_val16 surround_masking, > opus_val16 temporal_vbr) > { > /* The target rate in 8th bits per frame */ >@@ -1235,10 +1281,9 @@ static int compute_vbr(const CELTMode *mode, AnalysisInfo *analysis, opus_int32 > SHR32(MULT16_16(stereo_saving-QCONST16(0.1f,8),(coded_stereo_dof<<BITRES)),8)); > } > /* Boost the rate according to dynalloc (minus the dynalloc average for calibration). */ >- target += tot_boost-(16<<LM); >+ target += tot_boost-(19<<LM); > /* Apply transient boost, compensating for average boost. */ >- tf_calibration = variable_duration==OPUS_FRAMESIZE_VARIABLE ? >- QCONST16(0.02f,14) : QCONST16(0.04f,14); >+ tf_calibration = QCONST16(0.044f,14); > target += (opus_int32)SHL32(MULT16_32_Q15(tf_estimate-tf_calibration, target),1); > > #ifndef DISABLE_FLOAT_API >@@ -1249,7 +1294,7 @@ static int compute_vbr(const CELTMode *mode, AnalysisInfo *analysis, opus_int32 > float tonal; > > /* Tonality boost (compensating for the average). */ >- tonal = MAX16(0.f,analysis->tonality-.15f)-0.09f; >+ tonal = MAX16(0.f,analysis->tonality-.15f)-0.12f; > tonal_target = target + (opus_int32)((coded_bins<<BITRES)*1.2f*tonal); > if (pitch_change) > tonal_target += (opus_int32)((coded_bins<<BITRES)*.8f); >@@ -1279,21 +1324,11 @@ static int compute_vbr(const CELTMode *mode, AnalysisInfo *analysis, opus_int32 > /*printf("%f %d\n", maxDepth, floor_depth);*/ > } > >- if ((!has_surround_mask||lfe) && (constrained_vbr || bitrate<64000)) >+ /* Make VBR less aggressive for constrained VBR because we can't keep a higher bitrate >+ for long. Needs tuning. */ >+ if ((!has_surround_mask||lfe) && constrained_vbr) > { >- opus_val16 rate_factor = Q15ONE; >- if (bitrate < 64000) >- { >-#ifdef FIXED_POINT >- rate_factor = MAX16(0,(bitrate-32000)); >-#else >- rate_factor = MAX16(0,(1.f/32768)*(bitrate-32000)); >-#endif >- } >- if (constrained_vbr) >- rate_factor = MIN16(rate_factor, QCONST16(0.67f, 15)); >- target = base_target + (opus_int32)MULT16_32_Q15(rate_factor, target-base_target); >- >+ target = base_target + (opus_int32)MULT16_32_Q15(QCONST16(0.67f, 15), target-base_target); > } > > if (!has_surround_mask && tf_estimate < QCONST16(.2f, 14)) >@@ -1331,7 +1366,7 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm, > VARDECL(int, tf_res); > VARDECL(unsigned char, collapse_masks); > celt_sig *prefilter_mem; >- opus_val16 *oldBandE, *oldLogE, *oldLogE2; >+ opus_val16 *oldBandE, *oldLogE, *oldLogE2, *energyError; > int shortBlocks=0; > int isTransient=0; > const int CC = st->channels; >@@ -1343,7 +1378,6 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm, > int end; > int effEnd; > int codedBands; >- int tf_sum; > int alloc_trim; > int pitch_index=COMBFILTER_MINPERIOD; > opus_val16 gain1 = 0; >@@ -1355,6 +1389,7 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm, > opus_int32 total_boost; > opus_int32 balance; > opus_int32 tell; >+ opus_int32 tell0_frac; > int prefilter_tapset=0; > int pf_on; > int anti_collapse_rsv; >@@ -1376,7 +1411,9 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm, > opus_val16 surround_masking=0; > opus_val16 temporal_vbr=0; > opus_val16 surround_trim = 0; >- opus_int32 equiv_rate = 510000; >+ opus_int32 equiv_rate; >+ int hybrid; >+ int weak_transient = 0; > VARDECL(opus_val16, surround_dynalloc); > ALLOC_STACK; > >@@ -1386,6 +1423,7 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm, > eBands = mode->eBands; > start = st->start; > end = st->end; >+ hybrid = start != 0; > tf_estimate = 0; > if (nbCompressedBytes<2 || pcm==NULL) > { >@@ -1409,12 +1447,14 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm, > oldBandE = (opus_val16*)(st->in_mem+CC*(overlap+COMBFILTER_MAXPERIOD)); > oldLogE = oldBandE + CC*nbEBands; > oldLogE2 = oldLogE + CC*nbEBands; >+ energyError = oldLogE2 + CC*nbEBands; > > if (enc==NULL) > { >- tell=1; >+ tell0_frac=tell=1; > nbFilledBytes=0; > } else { >+ tell0_frac=tell=ec_tell_frac(enc); > tell=ec_tell(enc); > nbFilledBytes=(tell+4)>>3; > } >@@ -1467,10 +1507,11 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm, > if (st->bitrate!=OPUS_BITRATE_MAX) > nbCompressedBytes = IMAX(2, IMIN(nbCompressedBytes, > (tmp+4*mode->Fs)/(8*mode->Fs)-!!st->signalling)); >- effectiveBytes = nbCompressedBytes; >+ effectiveBytes = nbCompressedBytes - nbFilledBytes; > } >+ equiv_rate = ((opus_int32)nbCompressedBytes*8*50 >> (3-LM)) - (40*C+20)*((400>>LM) - 50); > if (st->bitrate != OPUS_BITRATE_MAX) >- equiv_rate = st->bitrate - (40*C+20)*((400>>LM) - 50); >+ equiv_rate = IMIN(equiv_rate, st->bitrate - (40*C+20)*((400>>LM) - 50)); > > if (enc==NULL) > { >@@ -1558,8 +1599,8 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm, > { > int enabled; > int qg; >- enabled = ((st->lfe&&nbAvailableBytes>3) || nbAvailableBytes>12*C) && start==0 && !silence && !st->disable_pf >- && st->complexity >= 5 && !(st->consec_transient && LM!=3 && st->variable_duration==OPUS_FRAMESIZE_VARIABLE); >+ enabled = ((st->lfe&&nbAvailableBytes>3) || nbAvailableBytes>12*C) && !hybrid && !silence && !st->disable_pf >+ && st->complexity >= 5; > > prefilter_tapset = st->tapset_decision; > pf_on = run_prefilter(st, in, prefilter_mem, CC, N, prefilter_tapset, &pitch_index, &gain1, &qg, enabled, nbAvailableBytes); >@@ -1568,7 +1609,7 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm, > pitch_change = 1; > if (pf_on==0) > { >- if(start==0 && tell+16<=total_bits) >+ if(!hybrid && tell+16<=total_bits) > ec_enc_bit_logp(enc, 0, 1); > } else { > /*This block is not gated by a total bits check only because >@@ -1589,8 +1630,12 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm, > shortBlocks = 0; > if (st->complexity >= 1 && !st->lfe) > { >+ /* Reduces the likelihood of energy instability on fricatives at low bitrate >+ in hybrid mode. It seems like we still want to have real transients on vowels >+ though (small SILK quantization offset value). */ >+ int allow_weak_transients = hybrid && effectiveBytes<15 && st->silk_info.offset >= 100; > isTransient = transient_analysis(in, N+overlap, CC, >- &tf_estimate, &tf_chan); >+ &tf_estimate, &tf_chan, allow_weak_transients, &weak_transient); > } > if (LM>0 && ec_tell(enc)+3<=total_bits) > { >@@ -1610,7 +1655,7 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm, > if (secondMdct) > { > compute_mdcts(mode, 0, in, freq, C, CC, LM, st->upsample, st->arch); >- compute_band_energies(mode, freq, bandE, effEnd, C, LM); >+ compute_band_energies(mode, freq, bandE, effEnd, C, LM, st->arch); > amp2Log2(mode, effEnd, end, bandE, bandLogE2, C); > for (i=0;i<C*nbEBands;i++) > bandLogE2[i] += HALF16(SHL16(LM, DB_SHIFT)); >@@ -1619,7 +1664,7 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm, > compute_mdcts(mode, shortBlocks, in, freq, C, CC, LM, st->upsample, st->arch); > if (CC==2&&C==1) > tf_chan = 0; >- compute_band_energies(mode, freq, bandE, effEnd, C, LM); >+ compute_band_energies(mode, freq, bandE, effEnd, C, LM, st->arch); > > if (st->lfe) > { >@@ -1634,7 +1679,7 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm, > ALLOC(surround_dynalloc, C*nbEBands, opus_val16); > OPUS_CLEAR(surround_dynalloc, end); > /* This computes how much masking takes place between surround channels */ >- if (start==0&&st->energy_mask&&!st->lfe) >+ if (!hybrid&&st->energy_mask&&!st->lfe) > { > int mask_end; > int midband; >@@ -1736,14 +1781,14 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm, > > /* Last chance to catch any transient we might have missed in the > time-domain analysis */ >- if (LM>0 && ec_tell(enc)+3<=total_bits && !isTransient && st->complexity>=5 && !st->lfe) >+ if (LM>0 && ec_tell(enc)+3<=total_bits && !isTransient && st->complexity>=5 && !st->lfe && !hybrid) > { > if (patch_transient_decision(bandLogE, oldBandE, nbEBands, start, end, C)) > { > isTransient = 1; > shortBlocks = M; > compute_mdcts(mode, shortBlocks, in, freq, C, CC, LM, st->upsample, st->arch); >- compute_band_energies(mode, freq, bandE, effEnd, C, LM); >+ compute_band_energies(mode, freq, bandE, effEnd, C, LM, st->arch); > amp2Log2(mode, effEnd, end, bandE, bandLogE, C); > /* Compensate for the scaling of short vs long mdcts */ > for (i=0;i<C*nbEBands;i++) >@@ -1762,29 +1807,47 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm, > > ALLOC(tf_res, nbEBands, int); > /* Disable variable tf resolution for hybrid and at very low bitrate */ >- if (effectiveBytes>=15*C && start==0 && st->complexity>=2 && !st->lfe) >+ if (effectiveBytes>=15*C && !hybrid && st->complexity>=2 && !st->lfe) > { > int lambda; >- if (effectiveBytes<40) >- lambda = 12; >- else if (effectiveBytes<60) >- lambda = 6; >- else if (effectiveBytes<100) >- lambda = 4; >- else >- lambda = 3; >- lambda*=2; >- tf_select = tf_analysis(mode, effEnd, isTransient, tf_res, lambda, X, N, LM, &tf_sum, tf_estimate, tf_chan); >+ lambda = IMAX(5, 1280/effectiveBytes + 2); >+ tf_select = tf_analysis(mode, effEnd, isTransient, tf_res, lambda, X, N, LM, tf_estimate, tf_chan); > for (i=effEnd;i<end;i++) > tf_res[i] = tf_res[effEnd-1]; >+ } else if (hybrid && weak_transient) >+ { >+ /* For weak transients, we rely on the fact that improving time resolution using >+ TF on a long window is imperfect and will not result in an energy collapse at >+ low bitrate. */ >+ for (i=0;i<end;i++) >+ tf_res[i] = 1; >+ tf_select=0; >+ } else if (hybrid && effectiveBytes<15) >+ { >+ /* For low bitrate hybrid, we force temporal resolution to 5 ms rather than 2.5 ms. */ >+ for (i=0;i<end;i++) >+ tf_res[i] = 0; >+ tf_select=isTransient; > } else { >- tf_sum = 0; > for (i=0;i<end;i++) > tf_res[i] = isTransient; > tf_select=0; > } > > ALLOC(error, C*nbEBands, opus_val16); >+ c=0; >+ do { >+ for (i=start;i<end;i++) >+ { >+ /* When the energy is stable, slightly bias energy quantization towards >+ the previous error to make the gain more stable (a constant offset is >+ better than fluctuations). */ >+ if (ABS32(SUB32(bandLogE[i+c*nbEBands], oldBandE[i+c*nbEBands])) < QCONST16(2.f, DB_SHIFT)) >+ { >+ bandLogE[i+c*nbEBands] -= MULT16_16_Q15(energyError[i+c*nbEBands], QCONST16(0.25f, 15)); >+ } >+ } >+ } while (++c < C); > quant_coarse_energy(mode, start, end, effEnd, bandLogE, > oldBandE, total_bits, error, enc, > C, LM, nbAvailableBytes, st->force_intra, >@@ -1798,7 +1861,15 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm, > { > st->tapset_decision = 0; > st->spread_decision = SPREAD_NORMAL; >- } else if (shortBlocks || st->complexity < 3 || nbAvailableBytes < 10*C || start != 0) >+ } else if (hybrid) >+ { >+ if (st->complexity == 0) >+ st->spread_decision = SPREAD_NONE; >+ else if (isTransient) >+ st->spread_decision = SPREAD_NORMAL; >+ else >+ st->spread_decision = SPREAD_AGGRESSIVE; >+ } else if (shortBlocks || st->complexity < 3 || nbAvailableBytes < 10*C) > { > if (st->complexity == 0) > st->spread_decision = SPREAD_NONE; >@@ -1834,7 +1905,7 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm, > > maxDepth = dynalloc_analysis(bandLogE, bandLogE2, nbEBands, start, end, C, offsets, > st->lsb_depth, mode->logN, isTransient, st->vbr, st->constrained_vbr, >- eBands, LM, effectiveBytes, &tot_boost, st->lfe, surround_dynalloc); >+ eBands, LM, effectiveBytes, &tot_boost, st->lfe, surround_dynalloc, &st->analysis); > /* For LFE, everything interesting is in the first band */ > if (st->lfe) > offsets[0] = IMIN(8, effectiveBytes/3); >@@ -1896,12 +1967,15 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm, > alloc_trim = 5; > if (tell+(6<<BITRES) <= total_bits - total_boost) > { >- if (st->lfe) >+ if (start > 0 || st->lfe) >+ { >+ st->stereo_saving = 0; > alloc_trim = 5; >- else >+ } else { > alloc_trim = alloc_trim_analysis(mode, X, bandLogE, > end, LM, C, N, &st->analysis, &st->stereo_saving, tf_estimate, >- st->intensity, surround_trim, st->arch); >+ st->intensity, surround_trim, equiv_rate, st->arch); >+ } > ec_enc_icdf(enc, alloc_trim, trim_icdf, 7); > tell = ec_tell_frac(enc); > } >@@ -1919,17 +1993,36 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm, > /* Don't attempt to use more than 510 kb/s, even for frames smaller than 20 ms. > The CELT allocator will just not be able to use more than that anyway. */ > nbCompressedBytes = IMIN(nbCompressedBytes,1275>>(3-LM)); >- base_target = vbr_rate - ((40*C+20)<<BITRES); >+ if (!hybrid) >+ { >+ base_target = vbr_rate - ((40*C+20)<<BITRES); >+ } else { >+ base_target = IMAX(0, vbr_rate - ((9*C+4)<<BITRES)); >+ } > > if (st->constrained_vbr) > base_target += (st->vbr_offset>>lm_diff); > >- target = compute_vbr(mode, &st->analysis, base_target, LM, equiv_rate, >+ if (!hybrid) >+ { >+ target = compute_vbr(mode, &st->analysis, base_target, LM, equiv_rate, > st->lastCodedBands, C, st->intensity, st->constrained_vbr, > st->stereo_saving, tot_boost, tf_estimate, pitch_change, maxDepth, >- st->variable_duration, st->lfe, st->energy_mask!=NULL, surround_masking, >+ st->lfe, st->energy_mask!=NULL, surround_masking, > temporal_vbr); >- >+ } else { >+ target = base_target; >+ /* Tonal frames (offset<100) need more bits than noisy (offset>100) ones. */ >+ if (st->silk_info.offset < 100) target += 12 << BITRES >> (3-LM); >+ if (st->silk_info.offset > 100) target -= 18 << BITRES >> (3-LM); >+ /* Boosting bitrate on transients and vowels with significant temporal >+ spikes. */ >+ target += (opus_int32)MULT16_16_Q14(tf_estimate-QCONST16(.25f,14), (50<<BITRES)); >+ /* If we have a strong transient, let's make sure it has enough bits to code >+ the first two bands, so that it can use folding rather than noise. */ >+ if (tf_estimate > QCONST16(.7f,14)) >+ target = IMAX(target, 50<<BITRES); >+ } > /* The current offset is removed from the target and the space used > so far is added*/ > target=target+tell; >@@ -1937,11 +2030,16 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm, > result in the encoder running out of bits. > The margin of 2 bytes ensures that none of the bust-prevention logic > in the decoder will have triggered so far. */ >- min_allowed = ((tell+total_boost+(1<<(BITRES+3))-1)>>(BITRES+3)) + 2 - nbFilledBytes; >+ min_allowed = ((tell+total_boost+(1<<(BITRES+3))-1)>>(BITRES+3)) + 2; >+ /* Take into account the 37 bits we need to have left in the packet to >+ signal a redundant frame in hybrid mode. Creating a shorter packet would >+ create an entropy coder desync. */ >+ if (hybrid) >+ min_allowed = IMAX(min_allowed, (tell0_frac+(37<<BITRES)+total_boost+(1<<(BITRES+3))-1)>>(BITRES+3)); > > nbAvailableBytes = (target+(1<<(BITRES+2)))>>(BITRES+3); > nbAvailableBytes = IMAX(min_allowed,nbAvailableBytes); >- nbAvailableBytes = IMIN(nbCompressedBytes,nbAvailableBytes+nbFilledBytes) - nbFilledBytes; >+ nbAvailableBytes = IMIN(nbCompressedBytes,nbAvailableBytes); > > /* By how much did we "miss" the target on that frame */ > delta = target - vbr_rate; >@@ -1988,7 +2086,7 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm, > st->vbr_reservoir = 0; > /*printf ("+%d\n", adjust);*/ > } >- nbCompressedBytes = IMIN(nbCompressedBytes,nbAvailableBytes+nbFilledBytes); >+ nbCompressedBytes = IMIN(nbCompressedBytes,nbAvailableBytes); > /*printf("%d\n", nbCompressedBytes*50*8);*/ > /* This moves the raw bits to take into account the new compressed size */ > ec_enc_shrink(enc, nbCompressedBytes); >@@ -2038,7 +2136,7 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm, > quant_all_bands(1, mode, start, end, X, C==2 ? X+N : NULL, collapse_masks, > bandE, pulses, shortBlocks, st->spread_decision, > dual_stereo, st->intensity, tf_res, nbCompressedBytes*(8<<BITRES)-anti_collapse_rsv, >- balance, enc, LM, codedBands, &st->rng, st->arch); >+ balance, enc, LM, codedBands, &st->rng, st->complexity, st->arch, st->disable_inv); > > if (anti_collapse_rsv > 0) > { >@@ -2049,6 +2147,14 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm, > ec_enc_bits(enc, anti_collapse_on, 1); > } > quant_energy_finalise(mode, start, end, oldBandE, error, fine_quant, fine_priority, nbCompressedBytes*8-ec_tell(enc), enc, C); >+ OPUS_CLEAR(energyError, nbEBands*CC); >+ c=0; >+ do { >+ for (i=start;i<end;i++) >+ { >+ energyError[i+c*nbEBands] = MAX16(-QCONST16(0.5f, 15), MIN16(QCONST16(0.5f, 15), error[i+c*nbEBands])); >+ } >+ } while (++c < C); > > if (silence) > { >@@ -2321,10 +2427,24 @@ int opus_custom_encoder_ctl(CELTEncoder * OPUS_RESTRICT st, int request, ...) > *value=st->lsb_depth; > } > break; >- case OPUS_SET_EXPERT_FRAME_DURATION_REQUEST: >+ case OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST: > { > opus_int32 value = va_arg(ap, opus_int32); >- st->variable_duration = value; >+ if(value<0 || value>1) >+ { >+ goto bad_arg; >+ } >+ st->disable_inv = value; >+ } >+ break; >+ case OPUS_GET_PHASE_INVERSION_DISABLED_REQUEST: >+ { >+ opus_int32 *value = va_arg(ap, opus_int32*); >+ if (!value) >+ { >+ goto bad_arg; >+ } >+ *value = st->disable_inv; > } > break; > case OPUS_RESET_STATE: >@@ -2368,6 +2488,13 @@ int opus_custom_encoder_ctl(CELTEncoder * OPUS_RESTRICT st, int request, ...) > OPUS_COPY(&st->analysis, info, 1); > } > break; >+ case CELT_SET_SILK_INFO_REQUEST: >+ { >+ SILKInfo *info = va_arg(ap, SILKInfo *); >+ if (info) >+ OPUS_COPY(&st->silk_info, info, 1); >+ } >+ break; > case CELT_GET_MODE_REQUEST: > { > const CELTMode ** value = va_arg(ap, const CELTMode**); >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/celt_lpc.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/celt_lpc.c >index b410a21c5f6bf095f2f16c7350a9b471141fed89..57bc5f3dd3fd886162fe4c3a7fdb87197fc53ebd 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/celt_lpc.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/celt_lpc.c >@@ -89,58 +89,40 @@ int p > > > void celt_fir_c( >- const opus_val16 *_x, >+ const opus_val16 *x, > const opus_val16 *num, >- opus_val16 *_y, >+ opus_val16 *y, > int N, > int ord, >- opus_val16 *mem, > int arch) > { > int i,j; > VARDECL(opus_val16, rnum); >- VARDECL(opus_val16, x); > SAVE_STACK; > > ALLOC(rnum, ord, opus_val16); >- ALLOC(x, N+ord, opus_val16); > for(i=0;i<ord;i++) > rnum[i] = num[ord-i-1]; >- for(i=0;i<ord;i++) >- x[i] = mem[ord-i-1]; >- for (i=0;i<N;i++) >- x[i+ord]=_x[i]; >- for(i=0;i<ord;i++) >- mem[i] = _x[N-i-1]; >-#ifdef SMALL_FOOTPRINT >- (void)arch; >- for (i=0;i<N;i++) >- { >- opus_val32 sum = SHL32(EXTEND32(_x[i]), SIG_SHIFT); >- for (j=0;j<ord;j++) >- { >- sum = MAC16_16(sum,rnum[j],x[i+j]); >- } >- _y[i] = SATURATE16(PSHR32(sum, SIG_SHIFT)); >- } >-#else > for (i=0;i<N-3;i+=4) > { >- opus_val32 sum[4]={0,0,0,0}; >- xcorr_kernel(rnum, x+i, sum, ord, arch); >- _y[i ] = SATURATE16(ADD32(EXTEND32(_x[i ]), PSHR32(sum[0], SIG_SHIFT))); >- _y[i+1] = SATURATE16(ADD32(EXTEND32(_x[i+1]), PSHR32(sum[1], SIG_SHIFT))); >- _y[i+2] = SATURATE16(ADD32(EXTEND32(_x[i+2]), PSHR32(sum[2], SIG_SHIFT))); >- _y[i+3] = SATURATE16(ADD32(EXTEND32(_x[i+3]), PSHR32(sum[3], SIG_SHIFT))); >+ opus_val32 sum[4]; >+ sum[0] = SHL32(EXTEND32(x[i ]), SIG_SHIFT); >+ sum[1] = SHL32(EXTEND32(x[i+1]), SIG_SHIFT), >+ sum[2] = SHL32(EXTEND32(x[i+2]), SIG_SHIFT); >+ sum[3] = SHL32(EXTEND32(x[i+3]), SIG_SHIFT); >+ xcorr_kernel(rnum, x+i-ord, sum, ord, arch); >+ y[i ] = ROUND16(sum[0], SIG_SHIFT); >+ y[i+1] = ROUND16(sum[1], SIG_SHIFT); >+ y[i+2] = ROUND16(sum[2], SIG_SHIFT); >+ y[i+3] = ROUND16(sum[3], SIG_SHIFT); > } > for (;i<N;i++) > { >- opus_val32 sum = 0; >+ opus_val32 sum = SHL32(EXTEND32(x[i]), SIG_SHIFT); > for (j=0;j<ord;j++) >- sum = MAC16_16(sum,rnum[j],x[i+j]); >- _y[i] = SATURATE16(ADD32(EXTEND32(_x[i]), PSHR32(sum, SIG_SHIFT))); >+ sum = MAC16_16(sum,rnum[j],x[i+j-ord]); >+ y[i] = ROUND16(sum, SIG_SHIFT); > } >-#endif > RESTORE_STACK; > } > >@@ -166,7 +148,7 @@ void celt_iir(const opus_val32 *_x, > { > mem[j]=mem[j-1]; > } >- mem[0] = ROUND16(sum,SIG_SHIFT); >+ mem[0] = SROUND16(sum, SIG_SHIFT); > _y[i] = sum; > } > #else >@@ -195,20 +177,20 @@ void celt_iir(const opus_val32 *_x, > xcorr_kernel(rden, y+i, sum, ord, arch); > > /* Patch up the result to compensate for the fact that this is an IIR */ >- y[i+ord ] = -ROUND16(sum[0],SIG_SHIFT); >+ y[i+ord ] = -SROUND16(sum[0],SIG_SHIFT); > _y[i ] = sum[0]; > sum[1] = MAC16_16(sum[1], y[i+ord ], den[0]); >- y[i+ord+1] = -ROUND16(sum[1],SIG_SHIFT); >+ y[i+ord+1] = -SROUND16(sum[1],SIG_SHIFT); > _y[i+1] = sum[1]; > sum[2] = MAC16_16(sum[2], y[i+ord+1], den[0]); > sum[2] = MAC16_16(sum[2], y[i+ord ], den[1]); >- y[i+ord+2] = -ROUND16(sum[2],SIG_SHIFT); >+ y[i+ord+2] = -SROUND16(sum[2],SIG_SHIFT); > _y[i+2] = sum[2]; > > sum[3] = MAC16_16(sum[3], y[i+ord+2], den[0]); > sum[3] = MAC16_16(sum[3], y[i+ord+1], den[1]); > sum[3] = MAC16_16(sum[3], y[i+ord ], den[2]); >- y[i+ord+3] = -ROUND16(sum[3],SIG_SHIFT); >+ y[i+ord+3] = -SROUND16(sum[3],SIG_SHIFT); > _y[i+3] = sum[3]; > } > for (;i<N;i++) >@@ -216,7 +198,7 @@ void celt_iir(const opus_val32 *_x, > opus_val32 sum = _x[i]; > for (j=0;j<ord;j++) > sum -= MULT16_16(rden[j],y[i+j]); >- y[i+ord] = ROUND16(sum,SIG_SHIFT); >+ y[i+ord] = SROUND16(sum,SIG_SHIFT); > _y[i] = sum; > } > for(i=0;i<ord;i++) >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/celt_lpc.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/celt_lpc.h >index 323459eb1a83156664784742ddca78e1c44e6dc0..a4c5fd6ea5dca312fadb9c361db2abd5e1be7f68 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/celt_lpc.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/celt_lpc.h >@@ -45,12 +45,11 @@ void celt_fir_c( > opus_val16 *y, > int N, > int ord, >- opus_val16 *mem, > int arch); > > #if !defined(OVERRIDE_CELT_FIR) >-#define celt_fir(x, num, y, N, ord, mem, arch) \ >- (celt_fir_c(x, num, y, N, ord, mem, arch)) >+#define celt_fir(x, num, y, N, ord, arch) \ >+ (celt_fir_c(x, num, y, N, ord, arch)) > #endif > > void celt_iir(const opus_val32 *x, >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/dump_modes/dump_modes.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/dump_modes/dump_modes.c >new file mode 100644 >index 0000000000000000000000000000000000000000..9105a5344e3bf34aef9cac247c1062f69bf4471e >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/dump_modes/dump_modes.c >@@ -0,0 +1,353 @@ >+/* Copyright (c) 2008 CSIRO >+ Copyright (c) 2008-2009 Xiph.Org Foundation >+ Written by Jean-Marc Valin */ >+/* >+ Redistribution and use in source and binary forms, with or without >+ modification, are permitted provided that the following conditions >+ are met: >+ >+ - Redistributions of source code must retain the above copyright >+ notice, this list of conditions and the following disclaimer. >+ >+ - Redistributions in binary form must reproduce the above copyright >+ notice, this list of conditions and the following disclaimer in the >+ documentation and/or other materials provided with the distribution. >+ >+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS >+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT >+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR >+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER >+ OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, >+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, >+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR >+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF >+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING >+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS >+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+*/ >+ >+#ifdef HAVE_CONFIG_H >+#include "config.h" >+#endif >+ >+#include <stdlib.h> >+#include <stdio.h> >+#include "modes.h" >+#include "celt.h" >+#include "rate.h" >+#include "dump_modes_arch.h" >+ >+#define INT16 "%d" >+#define INT32 "%d" >+#define FLOAT "%#0.8gf" >+ >+#ifdef FIXED_POINT >+#define WORD16 INT16 >+#define WORD32 INT32 >+#else >+#define WORD16 FLOAT >+#define WORD32 FLOAT >+#endif >+ >+void dump_modes(FILE *file, CELTMode **modes, int nb_modes) >+{ >+ int i, j, k; >+ int mdct_twiddles_size; >+ fprintf(file, "/* The contents of this file was automatically generated by dump_modes.c\n"); >+ fprintf(file, " with arguments:"); >+ for (i=0;i<nb_modes;i++) >+ { >+ CELTMode *mode = modes[i]; >+ fprintf(file, " %d %d",mode->Fs,mode->shortMdctSize*mode->nbShortMdcts); >+ } >+ fprintf(file, "\n It contains static definitions for some pre-defined modes. */\n"); >+ fprintf(file, "#include \"modes.h\"\n"); >+ fprintf(file, "#include \"rate.h\"\n"); >+ fprintf(file, "\n#ifdef HAVE_ARM_NE10\n"); >+ fprintf(file, "#define OVERRIDE_FFT 1\n"); >+ fprintf(file, "#include \"%s\"\n", ARM_NE10_ARCH_FILE_NAME); >+ fprintf(file, "#endif\n"); >+ >+ fprintf(file, "\n"); >+ >+ for (i=0;i<nb_modes;i++) >+ { >+ CELTMode *mode = modes[i]; >+ int mdctSize; >+ int standard, framerate; >+ >+ mdctSize = mode->shortMdctSize*mode->nbShortMdcts; >+ standard = (mode->Fs == 400*(opus_int32)mode->shortMdctSize); >+ framerate = mode->Fs/mode->shortMdctSize; >+ >+ if (!standard) >+ { >+ fprintf(file, "#ifndef DEF_EBANDS%d_%d\n", mode->Fs, mdctSize); >+ fprintf(file, "#define DEF_EBANDS%d_%d\n", mode->Fs, mdctSize); >+ fprintf (file, "static const opus_int16 eBands%d_%d[%d] = {\n", mode->Fs, mdctSize, mode->nbEBands+2); >+ for (j=0;j<mode->nbEBands+2;j++) >+ fprintf (file, "%d, ", mode->eBands[j]); >+ fprintf (file, "};\n"); >+ fprintf(file, "#endif\n"); >+ fprintf(file, "\n"); >+ } >+ >+ fprintf(file, "#ifndef DEF_WINDOW%d\n", mode->overlap); >+ fprintf(file, "#define DEF_WINDOW%d\n", mode->overlap); >+ fprintf (file, "static const opus_val16 window%d[%d] = {\n", mode->overlap, mode->overlap); >+ for (j=0;j<mode->overlap;j++) >+ fprintf (file, WORD16 ",%c", mode->window[j],(j+6)%5==0?'\n':' '); >+ fprintf (file, "};\n"); >+ fprintf(file, "#endif\n"); >+ fprintf(file, "\n"); >+ >+ if (!standard) >+ { >+ fprintf(file, "#ifndef DEF_ALLOC_VECTORS%d_%d\n", mode->Fs, mdctSize); >+ fprintf(file, "#define DEF_ALLOC_VECTORS%d_%d\n", mode->Fs, mdctSize); >+ fprintf (file, "static const unsigned char allocVectors%d_%d[%d] = {\n", mode->Fs, mdctSize, mode->nbEBands*mode->nbAllocVectors); >+ for (j=0;j<mode->nbAllocVectors;j++) >+ { >+ for (k=0;k<mode->nbEBands;k++) >+ fprintf (file, "%2d, ", mode->allocVectors[j*mode->nbEBands+k]); >+ fprintf (file, "\n"); >+ } >+ fprintf (file, "};\n"); >+ fprintf(file, "#endif\n"); >+ fprintf(file, "\n"); >+ } >+ >+ fprintf(file, "#ifndef DEF_LOGN%d\n", framerate); >+ fprintf(file, "#define DEF_LOGN%d\n", framerate); >+ fprintf (file, "static const opus_int16 logN%d[%d] = {\n", framerate, mode->nbEBands); >+ for (j=0;j<mode->nbEBands;j++) >+ fprintf (file, "%d, ", mode->logN[j]); >+ fprintf (file, "};\n"); >+ fprintf(file, "#endif\n"); >+ fprintf(file, "\n"); >+ >+ /* Pulse cache */ >+ fprintf(file, "#ifndef DEF_PULSE_CACHE%d\n", mode->Fs/mdctSize); >+ fprintf(file, "#define DEF_PULSE_CACHE%d\n", mode->Fs/mdctSize); >+ fprintf (file, "static const opus_int16 cache_index%d[%d] = {\n", mode->Fs/mdctSize, (mode->maxLM+2)*mode->nbEBands); >+ for (j=0;j<mode->nbEBands*(mode->maxLM+2);j++) >+ fprintf (file, "%d,%c", mode->cache.index[j],(j+16)%15==0?'\n':' '); >+ fprintf (file, "};\n"); >+ fprintf (file, "static const unsigned char cache_bits%d[%d] = {\n", mode->Fs/mdctSize, mode->cache.size); >+ for (j=0;j<mode->cache.size;j++) >+ fprintf (file, "%d,%c", mode->cache.bits[j],(j+16)%15==0?'\n':' '); >+ fprintf (file, "};\n"); >+ fprintf (file, "static const unsigned char cache_caps%d[%d] = {\n", mode->Fs/mdctSize, (mode->maxLM+1)*2*mode->nbEBands); >+ for (j=0;j<(mode->maxLM+1)*2*mode->nbEBands;j++) >+ fprintf (file, "%d,%c", mode->cache.caps[j],(j+16)%15==0?'\n':' '); >+ fprintf (file, "};\n"); >+ >+ fprintf(file, "#endif\n"); >+ fprintf(file, "\n"); >+ >+ /* FFT twiddles */ >+ fprintf(file, "#ifndef FFT_TWIDDLES%d_%d\n", mode->Fs, mdctSize); >+ fprintf(file, "#define FFT_TWIDDLES%d_%d\n", mode->Fs, mdctSize); >+ fprintf (file, "static const kiss_twiddle_cpx fft_twiddles%d_%d[%d] = {\n", >+ mode->Fs, mdctSize, mode->mdct.kfft[0]->nfft); >+ for (j=0;j<mode->mdct.kfft[0]->nfft;j++) >+ fprintf (file, "{" WORD16 ", " WORD16 "},%c", mode->mdct.kfft[0]->twiddles[j].r, mode->mdct.kfft[0]->twiddles[j].i,(j+3)%2==0?'\n':' '); >+ fprintf (file, "};\n"); >+ >+#ifdef OVERRIDE_FFT >+ dump_mode_arch(mode); >+#endif >+ /* FFT Bitrev tables */ >+ for (k=0;k<=mode->mdct.maxshift;k++) >+ { >+ fprintf(file, "#ifndef FFT_BITREV%d\n", mode->mdct.kfft[k]->nfft); >+ fprintf(file, "#define FFT_BITREV%d\n", mode->mdct.kfft[k]->nfft); >+ fprintf (file, "static const opus_int16 fft_bitrev%d[%d] = {\n", >+ mode->mdct.kfft[k]->nfft, mode->mdct.kfft[k]->nfft); >+ for (j=0;j<mode->mdct.kfft[k]->nfft;j++) >+ fprintf (file, "%d,%c", mode->mdct.kfft[k]->bitrev[j],(j+16)%15==0?'\n':' '); >+ fprintf (file, "};\n"); >+ >+ fprintf(file, "#endif\n"); >+ fprintf(file, "\n"); >+ } >+ >+ /* FFT States */ >+ for (k=0;k<=mode->mdct.maxshift;k++) >+ { >+ fprintf(file, "#ifndef FFT_STATE%d_%d_%d\n", mode->Fs, mdctSize, k); >+ fprintf(file, "#define FFT_STATE%d_%d_%d\n", mode->Fs, mdctSize, k); >+ fprintf (file, "static const kiss_fft_state fft_state%d_%d_%d = {\n", >+ mode->Fs, mdctSize, k); >+ fprintf (file, "%d, /* nfft */\n", mode->mdct.kfft[k]->nfft); >+ fprintf (file, WORD16 ", /* scale */\n", mode->mdct.kfft[k]->scale); >+#ifdef FIXED_POINT >+ fprintf (file, "%d, /* scale_shift */\n", mode->mdct.kfft[k]->scale_shift); >+#endif >+ fprintf (file, "%d, /* shift */\n", mode->mdct.kfft[k]->shift); >+ fprintf (file, "{"); >+ for (j=0;j<2*MAXFACTORS;j++) >+ fprintf (file, "%d, ", mode->mdct.kfft[k]->factors[j]); >+ fprintf (file, "}, /* factors */\n"); >+ fprintf (file, "fft_bitrev%d, /* bitrev */\n", mode->mdct.kfft[k]->nfft); >+ fprintf (file, "fft_twiddles%d_%d, /* bitrev */\n", mode->Fs, mdctSize); >+ >+ fprintf (file, "#ifdef OVERRIDE_FFT\n"); >+ fprintf (file, "(arch_fft_state *)&cfg_arch_%d,\n", mode->mdct.kfft[k]->nfft); >+ fprintf (file, "#else\n"); >+ fprintf (file, "NULL,\n"); >+ fprintf(file, "#endif\n"); >+ >+ fprintf (file, "};\n"); >+ >+ fprintf(file, "#endif\n"); >+ fprintf(file, "\n"); >+ } >+ >+ fprintf(file, "#endif\n"); >+ fprintf(file, "\n"); >+ >+ /* MDCT twiddles */ >+ mdct_twiddles_size = mode->mdct.n-(mode->mdct.n/2>>mode->mdct.maxshift); >+ fprintf(file, "#ifndef MDCT_TWIDDLES%d\n", mdctSize); >+ fprintf(file, "#define MDCT_TWIDDLES%d\n", mdctSize); >+ fprintf (file, "static const opus_val16 mdct_twiddles%d[%d] = {\n", >+ mdctSize, mdct_twiddles_size); >+ for (j=0;j<mdct_twiddles_size;j++) >+ fprintf (file, WORD16 ",%c", mode->mdct.trig[j],(j+6)%5==0?'\n':' '); >+ fprintf (file, "};\n"); >+ >+ fprintf(file, "#endif\n"); >+ fprintf(file, "\n"); >+ >+ >+ /* Print the actual mode data */ >+ fprintf(file, "static const CELTMode mode%d_%d_%d = {\n", mode->Fs, mdctSize, mode->overlap); >+ fprintf(file, INT32 ", /* Fs */\n", mode->Fs); >+ fprintf(file, "%d, /* overlap */\n", mode->overlap); >+ fprintf(file, "%d, /* nbEBands */\n", mode->nbEBands); >+ fprintf(file, "%d, /* effEBands */\n", mode->effEBands); >+ fprintf(file, "{"); >+ for (j=0;j<4;j++) >+ fprintf(file, WORD16 ", ", mode->preemph[j]); >+ fprintf(file, "}, /* preemph */\n"); >+ if (standard) >+ fprintf(file, "eband5ms, /* eBands */\n"); >+ else >+ fprintf(file, "eBands%d_%d, /* eBands */\n", mode->Fs, mdctSize); >+ >+ fprintf(file, "%d, /* maxLM */\n", mode->maxLM); >+ fprintf(file, "%d, /* nbShortMdcts */\n", mode->nbShortMdcts); >+ fprintf(file, "%d, /* shortMdctSize */\n", mode->shortMdctSize); >+ >+ fprintf(file, "%d, /* nbAllocVectors */\n", mode->nbAllocVectors); >+ if (standard) >+ fprintf(file, "band_allocation, /* allocVectors */\n"); >+ else >+ fprintf(file, "allocVectors%d_%d, /* allocVectors */\n", mode->Fs, mdctSize); >+ >+ fprintf(file, "logN%d, /* logN */\n", framerate); >+ fprintf(file, "window%d, /* window */\n", mode->overlap); >+ fprintf(file, "{%d, %d, {", mode->mdct.n, mode->mdct.maxshift); >+ for (k=0;k<=mode->mdct.maxshift;k++) >+ fprintf(file, "&fft_state%d_%d_%d, ", mode->Fs, mdctSize, k); >+ fprintf (file, "}, mdct_twiddles%d}, /* mdct */\n", mdctSize); >+ >+ fprintf(file, "{%d, cache_index%d, cache_bits%d, cache_caps%d}, /* cache */\n", >+ mode->cache.size, mode->Fs/mdctSize, mode->Fs/mdctSize, mode->Fs/mdctSize); >+ fprintf(file, "};\n"); >+ } >+ fprintf(file, "\n"); >+ fprintf(file, "/* List of all the available modes */\n"); >+ fprintf(file, "#define TOTAL_MODES %d\n", nb_modes); >+ fprintf(file, "static const CELTMode * const static_mode_list[TOTAL_MODES] = {\n"); >+ for (i=0;i<nb_modes;i++) >+ { >+ CELTMode *mode = modes[i]; >+ int mdctSize; >+ mdctSize = mode->shortMdctSize*mode->nbShortMdcts; >+ fprintf(file, "&mode%d_%d_%d,\n", mode->Fs, mdctSize, mode->overlap); >+ } >+ fprintf(file, "};\n"); >+} >+ >+void dump_header(FILE *file, CELTMode **modes, int nb_modes) >+{ >+ int i; >+ int channels = 0; >+ int frame_size = 0; >+ int overlap = 0; >+ fprintf (file, "/* This header file is generated automatically*/\n"); >+ for (i=0;i<nb_modes;i++) >+ { >+ CELTMode *mode = modes[i]; >+ if (frame_size==0) >+ frame_size = mode->shortMdctSize*mode->nbShortMdcts; >+ else if (frame_size != mode->shortMdctSize*mode->nbShortMdcts) >+ frame_size = -1; >+ if (overlap==0) >+ overlap = mode->overlap; >+ else if (overlap != mode->overlap) >+ overlap = -1; >+ } >+ if (channels>0) >+ { >+ fprintf (file, "#define CHANNELS(mode) %d\n", channels); >+ if (channels==1) >+ fprintf (file, "#define DISABLE_STEREO\n"); >+ } >+ if (frame_size>0) >+ { >+ fprintf (file, "#define FRAMESIZE(mode) %d\n", frame_size); >+ } >+ if (overlap>0) >+ { >+ fprintf (file, "#define OVERLAP(mode) %d\n", overlap); >+ } >+} >+ >+#ifdef FIXED_POINT >+#define BASENAME "static_modes_fixed" >+#else >+#define BASENAME "static_modes_float" >+#endif >+ >+int main(int argc, char **argv) >+{ >+ int i, nb; >+ FILE *file; >+ CELTMode **m; >+ if (argc%2 != 1 || argc<3) >+ { >+ fprintf (stderr, "Usage: %s rate frame_size [rate frame_size] [rate frame_size]...\n",argv[0]); >+ return 1; >+ } >+ nb = (argc-1)/2; >+ m = malloc(nb*sizeof(CELTMode*)); >+ for (i=0;i<nb;i++) >+ { >+ int Fs, frame; >+ Fs = atoi(argv[2*i+1]); >+ frame = atoi(argv[2*i+2]); >+ m[i] = opus_custom_mode_create(Fs, frame, NULL); >+ if (m[i]==NULL) >+ { >+ fprintf(stderr,"Error creating mode with Fs=%s, frame_size=%s\n", >+ argv[2*i+1],argv[2*i+2]); >+ return EXIT_FAILURE; >+ } >+ } >+ file = fopen(BASENAME ".h", "w"); >+#ifdef OVERRIDE_FFT >+ dump_modes_arch_init(m, nb); >+#endif >+ dump_modes(file, m, nb); >+ fclose(file); >+#ifdef OVERRIDE_FFT >+ dump_modes_arch_finalize(); >+#endif >+ for (i=0;i<nb;i++) >+ opus_custom_mode_destroy(m[i]); >+ free(m); >+ return 0; >+} >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/dump_modes/dump_modes_arch.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/dump_modes/dump_modes_arch.h >new file mode 100644 >index 0000000000000000000000000000000000000000..cc0d4be1ec7308dacd853f65219465820ec71c14 >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/dump_modes/dump_modes_arch.h >@@ -0,0 +1,45 @@ >+/* Copyright (c) 2015 Xiph.Org Foundation >+ Written by Viswanath Puttagunta */ >+/* >+ Redistribution and use in source and binary forms, with or without >+ modification, are permitted provided that the following conditions >+ are met: >+ >+ - Redistributions of source code must retain the above copyright >+ notice, this list of conditions and the following disclaimer. >+ >+ - Redistributions in binary form must reproduce the above copyright >+ notice, this list of conditions and the following disclaimer in the >+ documentation and/or other materials provided with the distribution. >+ >+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS >+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT >+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR >+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER >+ OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, >+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, >+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR >+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF >+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING >+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS >+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+*/ >+ >+#ifndef DUMP_MODE_ARCH_H >+#define DUMP_MODE_ARCH_H >+ >+void dump_modes_arch_init(); >+void dump_mode_arch(CELTMode *mode); >+void dump_modes_arch_finalize(); >+ >+#if !defined(FIXED_POINT) >+#define ARM_NE10_ARCH_FILE_NAME "static_modes_float_arm_ne10.h" >+#else >+#define ARM_NE10_ARCH_FILE_NAME "static_modes_fixed_arm_ne10.h" >+#endif >+ >+#if defined(HAVE_ARM_NE10) >+#define OVERRIDE_FFT (1) >+#endif >+ >+#endif >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/dump_modes/dump_modes_arm_ne10.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/dump_modes/dump_modes_arm_ne10.c >new file mode 100644 >index 0000000000000000000000000000000000000000..828e7b9fff31f81bd761695a247926df056a41af >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/dump_modes/dump_modes_arm_ne10.c >@@ -0,0 +1,152 @@ >+/* Copyright (c) 2015 Xiph.Org Foundation >+ Written by Viswanath Puttagunta */ >+/* >+ Redistribution and use in source and binary forms, with or without >+ modification, are permitted provided that the following conditions >+ are met: >+ >+ - Redistributions of source code must retain the above copyright >+ notice, this list of conditions and the following disclaimer. >+ >+ - Redistributions in binary form must reproduce the above copyright >+ notice, this list of conditions and the following disclaimer in the >+ documentation and/or other materials provided with the distribution. >+ >+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS >+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT >+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR >+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER >+ OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, >+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, >+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR >+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF >+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING >+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS >+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+*/ >+ >+#if defined(HAVE_CONFIG_H) >+# include "config.h" >+#endif >+ >+#include <stdio.h> >+#include <stdlib.h> >+#include "modes.h" >+#include "dump_modes_arch.h" >+#include <NE10_dsp.h> >+ >+#if !defined(FIXED_POINT) >+# define NE10_FFT_CFG_TYPE_T ne10_fft_cfg_float32_t >+# define NE10_FFT_CPX_TYPE_T_STR "ne10_fft_cpx_float32_t" >+# define NE10_FFT_STATE_TYPE_T_STR "ne10_fft_state_float32_t" >+#else >+# define NE10_FFT_CFG_TYPE_T ne10_fft_cfg_int32_t >+# define NE10_FFT_CPX_TYPE_T_STR "ne10_fft_cpx_int32_t" >+# define NE10_FFT_STATE_TYPE_T_STR "ne10_fft_state_int32_t" >+#endif >+ >+static FILE *file; >+ >+void dump_modes_arch_init(CELTMode **modes, int nb_modes) >+{ >+ int i; >+ >+ file = fopen(ARM_NE10_ARCH_FILE_NAME, "w"); >+ fprintf(file, "/* The contents of this file was automatically generated by\n"); >+ fprintf(file, " * dump_mode_arm_ne10.c with arguments:"); >+ for (i=0;i<nb_modes;i++) >+ { >+ CELTMode *mode = modes[i]; >+ fprintf(file, " %d %d",mode->Fs,mode->shortMdctSize*mode->nbShortMdcts); >+ } >+ fprintf(file, "\n * It contains static definitions for some pre-defined modes. */\n"); >+ fprintf(file, "#include <NE10_types.h>\n\n"); >+} >+ >+void dump_modes_arch_finalize() >+{ >+ fclose(file); >+} >+ >+void dump_mode_arch(CELTMode *mode) >+{ >+ int k, j; >+ int mdctSize; >+ >+ mdctSize = mode->shortMdctSize*mode->nbShortMdcts; >+ >+ fprintf(file, "#ifndef NE10_FFT_PARAMS%d_%d\n", mode->Fs, mdctSize); >+ fprintf(file, "#define NE10_FFT_PARAMS%d_%d\n", mode->Fs, mdctSize); >+ /* cfg->factors */ >+ for(k=0;k<=mode->mdct.maxshift;k++) { >+ NE10_FFT_CFG_TYPE_T cfg; >+ cfg = (NE10_FFT_CFG_TYPE_T)mode->mdct.kfft[k]->arch_fft->priv; >+ if (!cfg) >+ continue; >+ fprintf(file, "static const ne10_int32_t ne10_factors_%d[%d] = {\n", >+ mode->mdct.kfft[k]->nfft, (NE10_MAXFACTORS * 2)); >+ for(j=0;j<(NE10_MAXFACTORS * 2);j++) { >+ fprintf(file, "%d,%c", cfg->factors[j],(j+16)%15==0?'\n':' '); >+ } >+ fprintf (file, "};\n"); >+ } >+ >+ /* cfg->twiddles */ >+ for(k=0;k<=mode->mdct.maxshift;k++) { >+ NE10_FFT_CFG_TYPE_T cfg; >+ cfg = (NE10_FFT_CFG_TYPE_T)mode->mdct.kfft[k]->arch_fft->priv; >+ if (!cfg) >+ continue; >+ fprintf(file, "static const %s ne10_twiddles_%d[%d] = {\n", >+ NE10_FFT_CPX_TYPE_T_STR, mode->mdct.kfft[k]->nfft, >+ mode->mdct.kfft[k]->nfft); >+ for(j=0;j<mode->mdct.kfft[k]->nfft;j++) { >+#if !defined(FIXED_POINT) >+ fprintf(file, "{%#0.8gf,%#0.8gf},%c", >+ cfg->twiddles[j].r, cfg->twiddles[j].i,(j+4)%3==0?'\n':' '); >+#else >+ fprintf(file, "{%d,%d},%c", >+ cfg->twiddles[j].r, cfg->twiddles[j].i,(j+4)%3==0?'\n':' '); >+#endif >+ } >+ fprintf (file, "};\n"); >+ } >+ >+ for(k=0;k<=mode->mdct.maxshift;k++) { >+ NE10_FFT_CFG_TYPE_T cfg; >+ cfg = (NE10_FFT_CFG_TYPE_T)mode->mdct.kfft[k]->arch_fft->priv; >+ if (!cfg) { >+ fprintf(file, "/* Ne10 does not support scaled FFT for length = %d */\n", >+ mode->mdct.kfft[k]->nfft); >+ fprintf(file, "static const arch_fft_state cfg_arch_%d = {\n", mode->mdct.kfft[k]->nfft); >+ fprintf(file, "0,\n"); >+ fprintf(file, "NULL\n"); >+ fprintf(file, "};\n"); >+ continue; >+ } >+ fprintf(file, "static const %s %s_%d = {\n", NE10_FFT_STATE_TYPE_T_STR, >+ NE10_FFT_STATE_TYPE_T_STR, mode->mdct.kfft[k]->nfft); >+ fprintf(file, "%d,\n", cfg->nfft); >+ fprintf(file, "(ne10_int32_t *)ne10_factors_%d,\n", mode->mdct.kfft[k]->nfft); >+ fprintf(file, "(%s *)ne10_twiddles_%d,\n", >+ NE10_FFT_CPX_TYPE_T_STR, mode->mdct.kfft[k]->nfft); >+ fprintf(file, "NULL,\n"); /* buffer */ >+ fprintf(file, "(%s *)&ne10_twiddles_%d[%d],\n", >+ NE10_FFT_CPX_TYPE_T_STR, mode->mdct.kfft[k]->nfft, cfg->nfft); >+#if !defined(FIXED_POINT) >+ fprintf(file, "/* is_forward_scaled = true */\n"); >+ fprintf(file, "(ne10_int32_t) 1,\n"); >+ fprintf(file, "/* is_backward_scaled = false */\n"); >+ fprintf(file, "(ne10_int32_t) 0,\n"); >+#endif >+ fprintf(file, "};\n"); >+ >+ fprintf(file, "static const arch_fft_state cfg_arch_%d = {\n", >+ mode->mdct.kfft[k]->nfft); >+ fprintf(file, "1,\n"); >+ fprintf(file, "(void *)&%s_%d,\n", >+ NE10_FFT_STATE_TYPE_T_STR, mode->mdct.kfft[k]->nfft); >+ fprintf(file, "};\n\n"); >+ } >+ fprintf(file, "#endif /* end NE10_FFT_PARAMS%d_%d */\n", mode->Fs, mdctSize); >+} >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/fixed_c5x.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/fixed_c5x.h >new file mode 100644 >index 0000000000000000000000000000000000000000..ea95a998c3c3f879e10ccd72eff200d1cece9720 >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/fixed_c5x.h >@@ -0,0 +1,79 @@ >+/* Copyright (C) 2003 Jean-Marc Valin */ >+/** >+ @file fixed_c5x.h >+ @brief Fixed-point operations for the TI C5x DSP family >+*/ >+/* >+ Redistribution and use in source and binary forms, with or without >+ modification, are permitted provided that the following conditions >+ are met: >+ >+ - Redistributions of source code must retain the above copyright >+ notice, this list of conditions and the following disclaimer. >+ >+ - Redistributions in binary form must reproduce the above copyright >+ notice, this list of conditions and the following disclaimer in the >+ documentation and/or other materials provided with the distribution. >+ >+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS >+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT >+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR >+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER >+ OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, >+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, >+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR >+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF >+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING >+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS >+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+*/ >+ >+#ifndef FIXED_C5X_H >+#define FIXED_C5X_H >+ >+#include "dsplib.h" >+ >+#undef IMUL32 >+static OPUS_INLINE long IMUL32(long i, long j) >+{ >+ long ac0, ac1; >+ ac0 = _lmpy(i>>16,j); >+ ac1 = ac0 + _lmpy(i,j>>16); >+ return _lmpyu(i,j) + (ac1<<16); >+} >+ >+#undef MAX16 >+#define MAX16(a,b) _max(a,b) >+ >+#undef MIN16 >+#define MIN16(a,b) _min(a,b) >+ >+#undef MAX32 >+#define MAX32(a,b) _lmax(a,b) >+ >+#undef MIN32 >+#define MIN32(a,b) _lmin(a,b) >+ >+#undef VSHR32 >+#define VSHR32(a, shift) _lshl(a,-(shift)) >+ >+#undef MULT16_16_Q15 >+#define MULT16_16_Q15(a,b) (_smpy(a,b)) >+ >+#undef MULT16_16SU >+#define MULT16_16SU(a,b) _lmpysu(a,b) >+ >+#undef MULT_16_16 >+#define MULT_16_16(a,b) _lmpy(a,b) >+ >+/* FIXME: This is technically incorrect and is bound to cause problems. Is there any cleaner solution? */ >+#undef MULT16_32_Q15 >+#define MULT16_32_Q15(a,b) ADD32(SHL(MULT16_16((a),SHR((b),16)),1), SHR(MULT16_16SU((a),(b)),15)) >+ >+#define celt_ilog2(x) (30 - _lnorm(x)) >+#define OVERRIDE_CELT_ILOG2 >+ >+#define celt_maxabs16(x, len) MAX32(EXTEND32(maxval((DATA *)x, len)),-EXTEND32(minval((DATA *)x, len))) >+#define OVERRIDE_CELT_MAXABS16 >+ >+#endif /* FIXED_C5X_H */ >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/fixed_c6x.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/fixed_c6x.h >new file mode 100644 >index 0000000000000000000000000000000000000000..bb6ad927803f9fabc155e10bd7da845fce2e8ce8 >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/fixed_c6x.h >@@ -0,0 +1,70 @@ >+/* Copyright (C) 2008 CSIRO */ >+/** >+ @file fixed_c6x.h >+ @brief Fixed-point operations for the TI C6x DSP family >+*/ >+/* >+ Redistribution and use in source and binary forms, with or without >+ modification, are permitted provided that the following conditions >+ are met: >+ >+ - Redistributions of source code must retain the above copyright >+ notice, this list of conditions and the following disclaimer. >+ >+ - Redistributions in binary form must reproduce the above copyright >+ notice, this list of conditions and the following disclaimer in the >+ documentation and/or other materials provided with the distribution. >+ >+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS >+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT >+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR >+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER >+ OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, >+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, >+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR >+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF >+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING >+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS >+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+*/ >+ >+#ifndef FIXED_C6X_H >+#define FIXED_C6X_H >+ >+#undef MULT16_16SU >+#define MULT16_16SU(a,b) _mpysu(a,b) >+ >+#undef MULT_16_16 >+#define MULT_16_16(a,b) _mpy(a,b) >+ >+#define celt_ilog2(x) (30 - _norm(x)) >+#define OVERRIDE_CELT_ILOG2 >+ >+#undef MULT16_32_Q15 >+#define MULT16_32_Q15(a,b) (_mpylill(a, b) >> 15) >+ >+#if 0 >+#include "dsplib.h" >+ >+#undef MAX16 >+#define MAX16(a,b) _max(a,b) >+ >+#undef MIN16 >+#define MIN16(a,b) _min(a,b) >+ >+#undef MAX32 >+#define MAX32(a,b) _lmax(a,b) >+ >+#undef MIN32 >+#define MIN32(a,b) _lmin(a,b) >+ >+#undef VSHR32 >+#define VSHR32(a, shift) _lshl(a,-(shift)) >+ >+#undef MULT16_16_Q15 >+#define MULT16_16_Q15(a,b) (_smpy(a,b)) >+ >+#define celt_maxabs16(x, len) MAX32(EXTEND32(maxval((DATA *)x, len)),-EXTEND32(minval((DATA *)x, len))) >+#define OVERRIDE_CELT_MAXABS16 >+ >+#endif /* FIXED_C6X_H */ >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/fixed_debug.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/fixed_debug.h >index d28227f5dc72879ced944d8b5db8880ba3465f03..f435295234cffb53cb054fcdd0ca0885f786d0fa 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/fixed_debug.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/fixed_debug.h >@@ -59,6 +59,14 @@ extern opus_int64 celt_mips; > #define SHR(a,b) SHR32(a,b) > #define PSHR(a,b) PSHR32(a,b) > >+/** Add two 32-bit values, ignore any overflows */ >+#define ADD32_ovflw(a,b) (celt_mips+=2,(opus_val32)((opus_uint32)(a)+(opus_uint32)(b))) >+/** Subtract two 32-bit values, ignore any overflows */ >+#define SUB32_ovflw(a,b) (celt_mips+=2,(opus_val32)((opus_uint32)(a)-(opus_uint32)(b))) >+/* Avoid MSVC warning C4146: unary minus operator applied to unsigned type */ >+/** Negate 32-bit value, ignore any overflows */ >+#define NEG32_ovflw(a) (celt_mips+=2,(opus_val32)(0-(opus_uint32)(a))) >+ > static OPUS_INLINE short NEG16(int x) > { > int res; >@@ -227,12 +235,11 @@ static OPUS_INLINE int SHL32_(opus_int64 a, int shift, char *file, int line) > #define VSHR32(a, shift) (((shift)>0) ? SHR32(a, shift) : SHL32(a, -(shift))) > > #define ROUND16(x,a) (celt_mips--,EXTRACT16(PSHR32((x),(a)))) >+#define SROUND16(x,a) (celt_mips--,EXTRACT16(SATURATE(PSHR32(x,a), 32767))); >+ > #define HALF16(x) (SHR16(x,1)) > #define HALF32(x) (SHR32(x,1)) > >-//#define SHR(a,shift) ((a) >> (shift)) >-//#define SHL(a,shift) ((a) << (shift)) >- > #define ADD16(a, b) ADD16_(a, b, __FILE__, __LINE__) > static OPUS_INLINE short ADD16_(int a, int b, char *file, int line) > { >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/fixed_generic.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/fixed_generic.h >index 1cfd6d698906bd4fde87a0ba0e87469bdc3ffde5..5f4abda76ed8c096fd30f957df200ef70915e7e3 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/fixed_generic.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/fixed_generic.h >@@ -104,6 +104,9 @@ > > /** Shift by a and round-to-neareast 32-bit value. Result is a 16-bit value */ > #define ROUND16(x,a) (EXTRACT16(PSHR32((x),(a)))) >+/** Shift by a and round-to-neareast 32-bit value. Result is a saturated 16-bit value */ >+#define SROUND16(x,a) EXTRACT16(SATURATE(PSHR32(x,a), 32767)); >+ > /** Divide by two */ > #define HALF16(x) (SHR16(x,1)) > #define HALF32(x) (SHR32(x,1)) >@@ -117,6 +120,14 @@ > /** Subtract two 32-bit values */ > #define SUB32(a,b) ((opus_val32)(a)-(opus_val32)(b)) > >+/** Add two 32-bit values, ignore any overflows */ >+#define ADD32_ovflw(a,b) ((opus_val32)((opus_uint32)(a)+(opus_uint32)(b))) >+/** Subtract two 32-bit values, ignore any overflows */ >+#define SUB32_ovflw(a,b) ((opus_val32)((opus_uint32)(a)-(opus_uint32)(b))) >+/* Avoid MSVC warning C4146: unary minus operator applied to unsigned type */ >+/** Negate 32-bit value, ignore any overflows */ >+#define NEG32_ovflw(a) ((opus_val32)(0-(opus_uint32)(a))) >+ > /** 16x16 multiplication where the result fits in 16 bits */ > #define MULT16_16_16(a,b) ((((opus_val16)(a))*((opus_val16)(b)))) > >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/float_cast.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/float_cast.h >index ed5a39b5433b58f2fa08432d2eb6189d6cbe8f6c..98b40abcf65f5df7a51d3d9d67d61869a5535fe9 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/float_cast.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/float_cast.h >@@ -61,7 +61,13 @@ > ** the config.h file. > */ > >-#if (HAVE_LRINTF) >+/* With GCC, when SSE is available, the fastest conversion is cvtss2si. */ >+#if defined(__GNUC__) && defined(__SSE__) >+ >+#include <xmmintrin.h> >+static OPUS_INLINE opus_int32 float2int(float x) {return _mm_cvt_ss2si(_mm_set_ss(x));} >+ >+#elif defined(HAVE_LRINTF) > > /* These defines enable functionality introduced with the 1999 ISO C > ** standard. They must be defined before the inclusion of math.h to >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/kiss_fft.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/kiss_fft.c >index 1f8fd05321a40204a3a66ad55818e464aac9a99c..83775165d866fb01d58bca71fcf563cf9db8c8eb 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/kiss_fft.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/kiss_fft.c >@@ -82,8 +82,8 @@ static void kf_bfly2( > C_SUB( Fout2[0] , Fout[0] , t ); > C_ADDTO( Fout[0] , t ); > >- t.r = S_MUL(Fout2[1].r+Fout2[1].i, tw); >- t.i = S_MUL(Fout2[1].i-Fout2[1].r, tw); >+ t.r = S_MUL(ADD32_ovflw(Fout2[1].r, Fout2[1].i), tw); >+ t.i = S_MUL(SUB32_ovflw(Fout2[1].i, Fout2[1].r), tw); > C_SUB( Fout2[1] , Fout[1] , t ); > C_ADDTO( Fout[1] , t ); > >@@ -92,8 +92,8 @@ static void kf_bfly2( > C_SUB( Fout2[2] , Fout[2] , t ); > C_ADDTO( Fout[2] , t ); > >- t.r = S_MUL(Fout2[3].i-Fout2[3].r, tw); >- t.i = S_MUL(-Fout2[3].i-Fout2[3].r, tw); >+ t.r = S_MUL(SUB32_ovflw(Fout2[3].i, Fout2[3].r), tw); >+ t.i = S_MUL(NEG32_ovflw(ADD32_ovflw(Fout2[3].i, Fout2[3].r)), tw); > C_SUB( Fout2[3] , Fout[3] , t ); > C_ADDTO( Fout[3] , t ); > Fout += 8; >@@ -126,10 +126,10 @@ static void kf_bfly4( > C_ADDTO( *Fout , scratch1 ); > C_SUB( scratch1 , Fout[1] , Fout[3] ); > >- Fout[1].r = scratch0.r + scratch1.i; >- Fout[1].i = scratch0.i - scratch1.r; >- Fout[3].r = scratch0.r - scratch1.i; >- Fout[3].i = scratch0.i + scratch1.r; >+ Fout[1].r = ADD32_ovflw(scratch0.r, scratch1.i); >+ Fout[1].i = SUB32_ovflw(scratch0.i, scratch1.r); >+ Fout[3].r = SUB32_ovflw(scratch0.r, scratch1.i); >+ Fout[3].i = ADD32_ovflw(scratch0.i, scratch1.r); > Fout+=4; > } > } else { >@@ -160,10 +160,10 @@ static void kf_bfly4( > tw3 += fstride*3; > C_ADDTO( *Fout , scratch[3] ); > >- Fout[m].r = scratch[5].r + scratch[4].i; >- Fout[m].i = scratch[5].i - scratch[4].r; >- Fout[m3].r = scratch[5].r - scratch[4].i; >- Fout[m3].i = scratch[5].i + scratch[4].r; >+ Fout[m].r = ADD32_ovflw(scratch[5].r, scratch[4].i); >+ Fout[m].i = SUB32_ovflw(scratch[5].i, scratch[4].r); >+ Fout[m3].r = SUB32_ovflw(scratch[5].r, scratch[4].i); >+ Fout[m3].i = ADD32_ovflw(scratch[5].i, scratch[4].r); > ++Fout; > } > } >@@ -212,18 +212,18 @@ static void kf_bfly3( > tw1 += fstride; > tw2 += fstride*2; > >- Fout[m].r = Fout->r - HALF_OF(scratch[3].r); >- Fout[m].i = Fout->i - HALF_OF(scratch[3].i); >+ Fout[m].r = SUB32_ovflw(Fout->r, HALF_OF(scratch[3].r)); >+ Fout[m].i = SUB32_ovflw(Fout->i, HALF_OF(scratch[3].i)); > > C_MULBYSCALAR( scratch[0] , epi3.i ); > > C_ADDTO(*Fout,scratch[3]); > >- Fout[m2].r = Fout[m].r + scratch[0].i; >- Fout[m2].i = Fout[m].i - scratch[0].r; >+ Fout[m2].r = ADD32_ovflw(Fout[m].r, scratch[0].i); >+ Fout[m2].i = SUB32_ovflw(Fout[m].i, scratch[0].r); > >- Fout[m].r -= scratch[0].i; >- Fout[m].i += scratch[0].r; >+ Fout[m].r = SUB32_ovflw(Fout[m].r, scratch[0].i); >+ Fout[m].i = ADD32_ovflw(Fout[m].i, scratch[0].r); > > ++Fout; > } while(--k); >@@ -282,22 +282,22 @@ static void kf_bfly5( > C_ADD( scratch[8],scratch[2],scratch[3]); > C_SUB( scratch[9],scratch[2],scratch[3]); > >- Fout0->r += scratch[7].r + scratch[8].r; >- Fout0->i += scratch[7].i + scratch[8].i; >+ Fout0->r = ADD32_ovflw(Fout0->r, ADD32_ovflw(scratch[7].r, scratch[8].r)); >+ Fout0->i = ADD32_ovflw(Fout0->i, ADD32_ovflw(scratch[7].i, scratch[8].i)); > >- scratch[5].r = scratch[0].r + S_MUL(scratch[7].r,ya.r) + S_MUL(scratch[8].r,yb.r); >- scratch[5].i = scratch[0].i + S_MUL(scratch[7].i,ya.r) + S_MUL(scratch[8].i,yb.r); >+ scratch[5].r = ADD32_ovflw(scratch[0].r, ADD32_ovflw(S_MUL(scratch[7].r,ya.r), S_MUL(scratch[8].r,yb.r))); >+ scratch[5].i = ADD32_ovflw(scratch[0].i, ADD32_ovflw(S_MUL(scratch[7].i,ya.r), S_MUL(scratch[8].i,yb.r))); > >- scratch[6].r = S_MUL(scratch[10].i,ya.i) + S_MUL(scratch[9].i,yb.i); >- scratch[6].i = -S_MUL(scratch[10].r,ya.i) - S_MUL(scratch[9].r,yb.i); >+ scratch[6].r = ADD32_ovflw(S_MUL(scratch[10].i,ya.i), S_MUL(scratch[9].i,yb.i)); >+ scratch[6].i = NEG32_ovflw(ADD32_ovflw(S_MUL(scratch[10].r,ya.i), S_MUL(scratch[9].r,yb.i))); > > C_SUB(*Fout1,scratch[5],scratch[6]); > C_ADD(*Fout4,scratch[5],scratch[6]); > >- scratch[11].r = scratch[0].r + S_MUL(scratch[7].r,yb.r) + S_MUL(scratch[8].r,ya.r); >- scratch[11].i = scratch[0].i + S_MUL(scratch[7].i,yb.r) + S_MUL(scratch[8].i,ya.r); >- scratch[12].r = - S_MUL(scratch[10].i,yb.i) + S_MUL(scratch[9].i,ya.i); >- scratch[12].i = S_MUL(scratch[10].r,yb.i) - S_MUL(scratch[9].r,ya.i); >+ scratch[11].r = ADD32_ovflw(scratch[0].r, ADD32_ovflw(S_MUL(scratch[7].r,yb.r), S_MUL(scratch[8].r,ya.r))); >+ scratch[11].i = ADD32_ovflw(scratch[0].i, ADD32_ovflw(S_MUL(scratch[7].i,yb.r), S_MUL(scratch[8].i,ya.r))); >+ scratch[12].r = SUB32_ovflw(S_MUL(scratch[9].i,ya.i), S_MUL(scratch[10].i,yb.i)); >+ scratch[12].i = SUB32_ovflw(S_MUL(scratch[10].r,yb.i), S_MUL(scratch[9].r,ya.i)); > > C_ADD(*Fout2,scratch[11],scratch[12]); > C_SUB(*Fout3,scratch[11],scratch[12]); >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/mathops.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/mathops.h >index a0525a961030ae5df1674ff59612f2054453a921..1f8a20cb4540255ffc4ea0a5f6716a31798c6a6f 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/mathops.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/mathops.h >@@ -38,11 +38,44 @@ > #include "entcode.h" > #include "os_support.h" > >+#define PI 3.141592653f >+ > /* Multiplies two 16-bit fractional values. Bit-exactness of this macro is important */ > #define FRAC_MUL16(a,b) ((16384+((opus_int32)(opus_int16)(a)*(opus_int16)(b)))>>15) > > unsigned isqrt32(opus_uint32 _val); > >+/* CELT doesn't need it for fixed-point, by analysis.c does. */ >+#if !defined(FIXED_POINT) || defined(ANALYSIS_C) >+#define cA 0.43157974f >+#define cB 0.67848403f >+#define cC 0.08595542f >+#define cE ((float)PI/2) >+static OPUS_INLINE float fast_atan2f(float y, float x) { >+ float x2, y2; >+ x2 = x*x; >+ y2 = y*y; >+ /* For very small values, we don't care about the answer, so >+ we can just return 0. */ >+ if (x2 + y2 < 1e-18f) >+ { >+ return 0; >+ } >+ if(x2<y2){ >+ float den = (y2 + cB*x2) * (y2 + cC*x2); >+ return -x*y*(y2 + cA*x2) / den + (y<0 ? -cE : cE); >+ }else{ >+ float den = (x2 + cB*y2) * (x2 + cC*y2); >+ return x*y*(x2 + cA*y2) / den + (y<0 ? -cE : cE) - (x*y<0 ? -cE : cE); >+ } >+} >+#undef cA >+#undef cB >+#undef cC >+#undef cD >+#endif >+ >+ > #ifndef OVERRIDE_CELT_MAXABS16 > static OPUS_INLINE opus_val32 celt_maxabs16(const opus_val16 *x, int len) > { >@@ -80,7 +113,6 @@ static OPUS_INLINE opus_val32 celt_maxabs32(const opus_val32 *x, int len) > > #ifndef FIXED_POINT > >-#define PI 3.141592653f > #define celt_sqrt(x) ((float)sqrt(x)) > #define celt_rsqrt(x) (1.f/celt_sqrt(x)) > #define celt_rsqrt_norm(x) (celt_rsqrt(x)) >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/mdct.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/mdct.c >index 5315ad11a37bba9211d49b55def55ee7f152c22c..5c6dab5b757a64af912936f0ce6fe22b8fc112e2 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/mdct.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/mdct.c >@@ -270,8 +270,8 @@ void clt_mdct_backward_c(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_sca > int rev; > kiss_fft_scalar yr, yi; > rev = *bitrev++; >- yr = S_MUL(*xp2, t[i]) + S_MUL(*xp1, t[N4+i]); >- yi = S_MUL(*xp1, t[i]) - S_MUL(*xp2, t[N4+i]); >+ yr = ADD32_ovflw(S_MUL(*xp2, t[i]), S_MUL(*xp1, t[N4+i])); >+ yi = SUB32_ovflw(S_MUL(*xp1, t[i]), S_MUL(*xp2, t[N4+i])); > /* We swap real and imag because we use an FFT instead of an IFFT. */ > yp[2*rev+1] = yr; > yp[2*rev] = yi; >@@ -301,8 +301,8 @@ void clt_mdct_backward_c(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_sca > t0 = t[i]; > t1 = t[N4+i]; > /* We'd scale up by 2 here, but instead it's done when mixing the windows */ >- yr = S_MUL(re,t0) + S_MUL(im,t1); >- yi = S_MUL(re,t1) - S_MUL(im,t0); >+ yr = ADD32_ovflw(S_MUL(re,t0), S_MUL(im,t1)); >+ yi = SUB32_ovflw(S_MUL(re,t1), S_MUL(im,t0)); > /* We swap real and imag because we're using an FFT instead of an IFFT. */ > re = yp1[1]; > im = yp1[0]; >@@ -312,8 +312,8 @@ void clt_mdct_backward_c(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_sca > t0 = t[(N4-i-1)]; > t1 = t[(N2-i-1)]; > /* We'd scale up by 2 here, but instead it's done when mixing the windows */ >- yr = S_MUL(re,t0) + S_MUL(im,t1); >- yi = S_MUL(re,t1) - S_MUL(im,t0); >+ yr = ADD32_ovflw(S_MUL(re,t0), S_MUL(im,t1)); >+ yi = SUB32_ovflw(S_MUL(re,t1), S_MUL(im,t0)); > yp1[0] = yr; > yp0[1] = yi; > yp0 += 2; >@@ -333,8 +333,8 @@ void clt_mdct_backward_c(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_sca > kiss_fft_scalar x1, x2; > x1 = *xp1; > x2 = *yp1; >- *yp1++ = MULT16_32_Q15(*wp2, x2) - MULT16_32_Q15(*wp1, x1); >- *xp1-- = MULT16_32_Q15(*wp1, x2) + MULT16_32_Q15(*wp2, x1); >+ *yp1++ = SUB32_ovflw(MULT16_32_Q15(*wp2, x2), MULT16_32_Q15(*wp1, x1)); >+ *xp1-- = ADD32_ovflw(MULT16_32_Q15(*wp1, x2), MULT16_32_Q15(*wp2, x1)); > wp1++; > wp2--; > } >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/mips/vq_mipsr1.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/mips/vq_mipsr1.h >index 54cef8613375409717b86eeaafb7346d12eaa800..fd18eab7a966046539a60b8a22ddeed2f1a0a5b6 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/mips/vq_mipsr1.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/mips/vq_mipsr1.h >@@ -36,9 +36,6 @@ > #include "mathops.h" > #include "arch.h" > >-static unsigned extract_collapse_mask(int *iy, int N, int B); >-static void normalise_residual(int * OPUS_RESTRICT iy, celt_norm * OPUS_RESTRICT X, int N, opus_val32 Ryy, opus_val16 gain); >-static void exp_rotation(celt_norm *X, int len, int dir, int stride, int K, int spread); > static void renormalise_vector_mips(celt_norm *X, int N, opus_val16 gain, int arch); > > #define OVERRIDE_vq_exp_rotation1 >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/modes.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/modes.c >index 911686e905522986b34f4db57d1623ae423aacd8..390c5e8aeb36aa48b16d2ffa202554dc174da661 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/modes.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/modes.c >@@ -427,7 +427,7 @@ void opus_custom_mode_destroy(CELTMode *mode) > } > #endif /* CUSTOM_MODES_ONLY */ > opus_free((opus_int16*)mode->eBands); >- opus_free((opus_int16*)mode->allocVectors); >+ opus_free((unsigned char*)mode->allocVectors); > > opus_free((opus_val16*)mode->window); > opus_free((opus_int16*)mode->logN); >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/pitch.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/pitch.c >index bf46e7d562b39f62752c30091e90064e4344b372..5b061d860f452b8c3539f50b86dfd1230b7ec521 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/pitch.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/pitch.c >@@ -220,13 +220,8 @@ opus_val32 > #else > void > #endif >-#if defined(OVERRIDE_PITCH_XCORR) > celt_pitch_xcorr_c(const opus_val16 *_x, const opus_val16 *_y, >- opus_val32 *xcorr, int len, int max_pitch) >-#else >-celt_pitch_xcorr(const opus_val16 *_x, const opus_val16 *_y, > opus_val32 *xcorr, int len, int max_pitch, int arch) >-#endif > { > > #if 0 /* This is a simple version of the pitch correlation that should work >@@ -265,11 +260,7 @@ celt_pitch_xcorr(const opus_val16 *_x, const opus_val16 *_y, > for (i=0;i<max_pitch-3;i+=4) > { > opus_val32 sum[4]={0,0,0,0}; >-#if defined(OVERRIDE_PITCH_XCORR) >- xcorr_kernel_c(_x, _y+i, sum, len); >-#else > xcorr_kernel(_x, _y+i, sum, len, arch); >-#endif > xcorr[i]=sum[0]; > xcorr[i+1]=sum[1]; > xcorr[i+2]=sum[2]; >@@ -285,11 +276,7 @@ celt_pitch_xcorr(const opus_val16 *_x, const opus_val16 *_y, > for (;i<max_pitch;i++) > { > opus_val32 sum; >-#if defined(OVERRIDE_PITCH_XCORR) >- sum = celt_inner_prod_c(_x, _y+i, len); >-#else > sum = celt_inner_prod(_x, _y+i, len, arch); >-#endif > xcorr[i] = sum; > #ifdef FIXED_POINT > maxcorr = MAX32(maxcorr, sum); >@@ -378,7 +365,7 @@ void pitch_search(const opus_val16 * OPUS_RESTRICT x_lp, opus_val16 * OPUS_RESTR > for (j=0;j<len>>1;j++) > sum += SHR32(MULT16_16(x_lp[j],y[i+j]), shift); > #else >- sum = celt_inner_prod_c(x_lp, y+i, len>>1); >+ sum = celt_inner_prod(x_lp, y+i, len>>1, arch); > #endif > xcorr[i] = MAX32(-1, sum); > #ifdef FIXED_POINT >@@ -424,7 +411,7 @@ static opus_val16 compute_pitch_gain(opus_val32 xy, opus_val32 xx, opus_val32 yy > sx = celt_ilog2(xx)-14; > sy = celt_ilog2(yy)-14; > shift = sx + sy; >- x2y2 = MULT16_16_Q14(VSHR32(xx, sx), VSHR32(yy, sy)); >+ x2y2 = SHR32(MULT16_16(VSHR32(xx, sx), VSHR32(yy, sy)), 14); > if (shift & 1) { > if (x2y2 < 32768) > { >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/pitch.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/pitch.h >index d3503532a080b378755dc01ba26c055ddab225c5..e425f56aeaa892a9acdc7a6bc58d9e57ddce7246 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/pitch.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/pitch.h >@@ -46,8 +46,7 @@ > #include "mips/pitch_mipsr1.h" > #endif > >-#if ((defined(OPUS_ARM_ASM) && defined(FIXED_POINT)) \ >- || defined(OPUS_ARM_MAY_HAVE_NEON_INTR)) >+#if (defined(OPUS_ARM_ASM) || defined(OPUS_ARM_MAY_HAVE_NEON_INTR)) > # include "arm/pitch_arm.h" > #endif > >@@ -184,17 +183,10 @@ opus_val32 > void > #endif > celt_pitch_xcorr_c(const opus_val16 *_x, const opus_val16 *_y, >- opus_val32 *xcorr, int len, int max_pitch); >- >-#if !defined(OVERRIDE_PITCH_XCORR) >-#ifdef FIXED_POINT >-opus_val32 >-#else >-void >-#endif >-celt_pitch_xcorr(const opus_val16 *_x, const opus_val16 *_y, > opus_val32 *xcorr, int len, int max_pitch, int arch); > >+#ifndef OVERRIDE_PITCH_XCORR >+# define celt_pitch_xcorr celt_pitch_xcorr_c > #endif > > #endif >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/quant_bands.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/quant_bands.c >index 95076e0af2d4ee07b25b5b3330542773e24497b2..56101b1cfecb8f5811c07618830d7ee3842aeb48 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/quant_bands.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/quant_bands.c >@@ -418,6 +418,7 @@ void quant_energy_finalise(const CELTMode *m, int start, int end, opus_val16 *ol > offset = (q2-.5f)*(1<<(14-fine_quant[i]-1))*(1.f/16384); > #endif > oldEBands[i+c*m->nbEBands] += offset; >+ error[i+c*m->nbEBands] -= offset; > bits_left--; > } while (++c < C); > } >@@ -547,9 +548,15 @@ void amp2Log2(const CELTMode *m, int effEnd, int end, > c=0; > do { > for (i=0;i<effEnd;i++) >+ { > bandLogE[i+c*m->nbEBands] = >- celt_log2(SHL32(bandE[i+c*m->nbEBands],2)) >+ celt_log2(bandE[i+c*m->nbEBands]) > - SHL16((opus_val16)eMeans[i],6); >+#ifdef FIXED_POINT >+ /* Compensate for bandE[] being Q12 but celt_log2() taking a Q14 input. */ >+ bandLogE[i+c*m->nbEBands] += QCONST16(2.f, DB_SHIFT); >+#endif >+ } > for (i=effEnd;i<end;i++) > bandLogE[c*m->nbEBands+i] = -QCONST16(14.f,DB_SHIFT); > } while (++c < C); >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/rate.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/rate.c >index 7dfa5be8a639268415ea1cf46b6e49730e389496..ca4cc870eaa412f52a45f41a938282b5a0c7d4e9 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/rate.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/rate.c >@@ -348,12 +348,17 @@ static OPUS_INLINE int interp_bits2pulses(const CELTMode *m, int start, int end, > /*This if() block is the only part of the allocation function that > is not a mandatory part of the bitstream: any bands we choose to > skip here must be explicitly signaled.*/ >- /*Choose a threshold with some hysteresis to keep bands from >- fluctuating in and out.*/ >+ int depth_threshold; >+ /*We choose a threshold with some hysteresis to keep bands from >+ fluctuating in and out, but we try not to fold below a certain point. */ >+ if (codedBands > 17) >+ depth_threshold = j<prev ? 7 : 9; >+ else >+ depth_threshold = 0; > #ifdef FUZZING > if ((rand()&0x1) == 0) > #else >- if (codedBands<=start+2 || (band_bits > ((j<prev?7:9)*band_width<<LM<<BITRES)>>4 && j<=signalBandwidth)) >+ if (codedBands<=start+2 || (band_bits > (depth_threshold*band_width<<LM<<BITRES)>>4 && j<=signalBandwidth)) > #endif > { > ec_enc_bit_logp(ec, 1, 1); >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/static_modes_fixed_arm_ne10.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/static_modes_fixed_arm_ne10.h >index b8ef0cee9838c345cfbddba785e383f00c639722..7623092192507ede3682b118abb8046466c42178 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/static_modes_fixed_arm_ne10.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/static_modes_fixed_arm_ne10.h >@@ -1,7 +1,7 @@ > /* The contents of this file was automatically generated by > * dump_mode_arm_ne10.c with arguments: 48000 960 > * It contains static definitions for some pre-defined modes. */ >-#include <NE10_init.h> >+#include <NE10_types.h> > > #ifndef NE10_FFT_PARAMS48000_960 > #define NE10_FFT_PARAMS48000_960 >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/static_modes_float_arm_ne10.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/static_modes_float_arm_ne10.h >index 934a82a420a296c2fb5ec0794f9c6fde5bb76049..66e1abb1013279302e453dd10785cf29fa1c6dce 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/static_modes_float_arm_ne10.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/static_modes_float_arm_ne10.h >@@ -1,7 +1,7 @@ > /* The contents of this file was automatically generated by > * dump_mode_arm_ne10.c with arguments: 48000 960 > * It contains static definitions for some pre-defined modes. */ >-#include <NE10_init.h> >+#include <NE10_types.h> > > #ifndef NE10_FFT_PARAMS48000_960 > #define NE10_FFT_PARAMS48000_960 >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/tests/test_unit_dft.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/tests/test_unit_dft.c >index 6166eb0e4fa93c3e0d0f5222f19e8cc3f7114674..70f8f4937ba8d0bca670ea95d1d75124e914d5b6 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/tests/test_unit_dft.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/tests/test_unit_dft.c >@@ -29,38 +29,12 @@ > #include "config.h" > #endif > >-#define SKIP_CONFIG_H >- >-#ifndef CUSTOM_MODES >-#define CUSTOM_MODES >-#endif >- > #include <stdio.h> > >-#define CELT_C >-#define TEST_UNIT_DFT_C > #include "stack_alloc.h" > #include "kiss_fft.h" >-#include "kiss_fft.c" >-#include "mathops.c" >-#include "entcode.c" >- >-#if defined(OPUS_X86_MAY_HAVE_SSE2) || defined(OPUS_X86_MAY_HAVE_SSE4_1) >-# include "x86/x86cpu.c" >-#elif defined(OPUS_ARM_ASM) || defined(OPUS_ARM_MAY_HAVE_NEON_INTR) >-# include "arm/armcpu.c" >-# include "celt_lpc.c" >-# include "pitch.c" >-# if defined(OPUS_ARM_MAY_HAVE_NEON_INTR) >-# include "arm/celt_neon_intr.c" >-# if defined(HAVE_ARM_NE10) >-# include "mdct.c" >-# include "arm/celt_ne10_fft.c" >-# include "arm/celt_ne10_mdct.c" >-# endif >-# endif >-# include "arm/arm_celt_map.c" >-#endif >+#include "mathops.h" >+#include "modes.h" > > #ifndef M_PI > #define M_PI 3.141592653 >@@ -112,11 +86,25 @@ void check(kiss_fft_cpx * in,kiss_fft_cpx * out,int nfft,int isinverse) > void test1d(int nfft,int isinverse,int arch) > { > size_t buflen = sizeof(kiss_fft_cpx)*nfft; >- >- kiss_fft_cpx * in = (kiss_fft_cpx*)malloc(buflen); >- kiss_fft_cpx * out= (kiss_fft_cpx*)malloc(buflen); >- kiss_fft_state *cfg = opus_fft_alloc(nfft,0,0,arch); >+ kiss_fft_cpx *in; >+ kiss_fft_cpx *out; > int k; >+#ifdef CUSTOM_MODES >+ kiss_fft_state *cfg = opus_fft_alloc(nfft,0,0,arch); >+#else >+ int id; >+ const kiss_fft_state *cfg; >+ CELTMode *mode = opus_custom_mode_create(48000, 960, NULL); >+ if (nfft == 480) id = 0; >+ else if (nfft == 240) id = 1; >+ else if (nfft == 120) id = 2; >+ else if (nfft == 60) id = 3; >+ else return; >+ cfg = mode->mdct.kfft[id]; >+#endif >+ >+ in = (kiss_fft_cpx*)malloc(buflen); >+ out = (kiss_fft_cpx*)malloc(buflen); > > for (k=0;k<nfft;++k) { > in[k].r = (rand() % 32767) - 16384; >@@ -149,7 +137,9 @@ void test1d(int nfft,int isinverse,int arch) > > free(in); > free(out); >+#ifdef CUSTOM_MODES > opus_fft_free(cfg, arch); >+#endif > } > > int main(int argc,char ** argv) >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/tests/test_unit_mathops.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/tests/test_unit_mathops.c >index fd3319da91ceb3ecfa94c702d1eff3dab738c87a..874e9adf0fbf161f7417f3ae511b8a9fe7515d6e 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/tests/test_unit_mathops.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/tests/test_unit_mathops.c >@@ -34,48 +34,10 @@ > #define CUSTOM_MODES > #endif > >-#define CELT_C >- > #include <stdio.h> > #include <math.h> >-#include "mathops.c" >-#include "entenc.c" >-#include "entdec.c" >-#include "entcode.c" >-#include "bands.c" >-#include "quant_bands.c" >-#include "laplace.c" >-#include "vq.c" >-#include "cwrs.c" >-#include "pitch.c" >-#include "celt_lpc.c" >-#include "celt.c" >- >-#if defined(OPUS_X86_MAY_HAVE_SSE) || defined(OPUS_X86_MAY_HAVE_SSE2) || defined(OPUS_X86_MAY_HAVE_SSE4_1) >-# if defined(OPUS_X86_MAY_HAVE_SSE) >-# include "x86/pitch_sse.c" >-# endif >-# if defined(OPUS_X86_MAY_HAVE_SSE2) >-# include "x86/pitch_sse2.c" >-# endif >-# if defined(OPUS_X86_MAY_HAVE_SSE4_1) >-# include "x86/pitch_sse4_1.c" >-# include "x86/celt_lpc_sse.c" >-# endif >-# include "x86/x86_celt_map.c" >-#elif defined(OPUS_ARM_ASM) || defined(OPUS_ARM_MAY_HAVE_NEON_INTR) >-# include "arm/armcpu.c" >-# if defined(OPUS_ARM_MAY_HAVE_NEON_INTR) >-# include "arm/celt_neon_intr.c" >-# if defined(HAVE_ARM_NE10) >-# include "kiss_fft.c" >-# include "mdct.c" >-# include "arm/celt_ne10_fft.c" >-# include "arm/celt_ne10_mdct.c" >-# endif >-# endif >-# include "arm/arm_celt_map.c" >-#endif >+#include "mathops.h" >+#include "bands.h" > > #ifdef FIXED_POINT > #define WORD "%d" >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/tests/test_unit_mdct.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/tests/test_unit_mdct.c >index 8dbb9caa2e8cfe85b8fc38e413b2903811c37c84..4a563ccfe3c92878be0018fe93bb52c8fd58f8a1 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/tests/test_unit_mdct.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/tests/test_unit_mdct.c >@@ -29,38 +29,13 @@ > #include "config.h" > #endif > >-#define SKIP_CONFIG_H >- >-#ifndef CUSTOM_MODES >-#define CUSTOM_MODES >-#endif >- > #include <stdio.h> > >-#define CELT_C > #include "mdct.h" > #include "stack_alloc.h" >- >-#include "kiss_fft.c" >-#include "mdct.c" >-#include "mathops.c" >-#include "entcode.c" >- >-#if defined(OPUS_X86_MAY_HAVE_SSE2) || defined(OPUS_X86_MAY_HAVE_SSE4_1) >-# include "x86/x86cpu.c" >-#elif defined(OPUS_ARM_ASM) || defined(OPUS_ARM_MAY_HAVE_NEON_INTR) >-# include "arm/armcpu.c" >-# include "pitch.c" >-# include "celt_lpc.c" >-# if defined(OPUS_ARM_MAY_HAVE_NEON_INTR) >-# include "arm/celt_neon_intr.c" >-# if defined(HAVE_ARM_NE10) >-# include "arm/celt_ne10_fft.c" >-# include "arm/celt_ne10_mdct.c" >-# endif >-# endif >-# include "arm/arm_celt_map.c" >-#endif >+#include "kiss_fft.h" >+#include "mdct.h" >+#include "modes.h" > > #ifndef M_PI > #define M_PI 3.141592653 >@@ -130,16 +105,36 @@ void check_inv(kiss_fft_scalar * in,kiss_fft_scalar * out,int nfft,int isinver > > void test1d(int nfft,int isinverse,int arch) > { >- mdct_lookup cfg; > size_t buflen = sizeof(kiss_fft_scalar)*nfft; >- >- kiss_fft_scalar * in = (kiss_fft_scalar*)malloc(buflen); >- kiss_fft_scalar * in_copy = (kiss_fft_scalar*)malloc(buflen); >- kiss_fft_scalar * out= (kiss_fft_scalar*)malloc(buflen); >- opus_val16 * window= (opus_val16*)malloc(sizeof(opus_val16)*nfft/2); >+ kiss_fft_scalar *in; >+ kiss_fft_scalar *in_copy; >+ kiss_fft_scalar *out; >+ opus_val16 *window; > int k; > >- clt_mdct_init(&cfg, nfft, 0, arch); >+#ifdef CUSTOM_MODES >+ int shift = 0; >+ const mdct_lookup *cfg; >+ mdct_lookup _cfg; >+ clt_mdct_init(&_cfg, nfft, 0, arch); >+ cfg = &_cfg; >+#else >+ int shift; >+ const mdct_lookup *cfg; >+ CELTMode *mode = opus_custom_mode_create(48000, 960, NULL); >+ if (nfft == 1920) shift = 0; >+ else if (nfft == 960) shift = 1; >+ else if (nfft == 480) shift = 2; >+ else if (nfft == 240) shift = 3; >+ else return; >+ cfg = &mode->mdct; >+#endif >+ >+ in = (kiss_fft_scalar*)malloc(buflen); >+ in_copy = (kiss_fft_scalar*)malloc(buflen); >+ out = (kiss_fft_scalar*)malloc(buflen); >+ window = (opus_val16*)malloc(sizeof(opus_val16)*nfft/2); >+ > for (k=0;k<nfft;++k) { > in[k] = (rand() % 32768) - 16384; > } >@@ -166,13 +161,13 @@ void test1d(int nfft,int isinverse,int arch) > { > for (k=0;k<nfft;++k) > out[k] = 0; >- clt_mdct_backward(&cfg,in,out, window, nfft/2, 0, 1, arch); >+ clt_mdct_backward(cfg,in,out, window, nfft/2, shift, 1, arch); > /* apply TDAC because clt_mdct_backward() no longer does that */ > for (k=0;k<nfft/4;++k) > out[nfft-k-1] = out[nfft/2+k]; > check_inv(in,out,nfft,isinverse); > } else { >- clt_mdct_forward(&cfg,in,out,window, nfft/2, 0, 1, arch); >+ clt_mdct_forward(cfg,in,out,window, nfft/2, shift, 1, arch); > check(in_copy,out,nfft,isinverse); > } > /*for (k=0;k<nfft;++k) printf("%d %d ", out[k].r, out[k].i);printf("\n");*/ >@@ -182,7 +177,9 @@ void test1d(int nfft,int isinverse,int arch) > free(in_copy); > free(out); > free(window); >- clt_mdct_clear(&cfg, arch); >+#ifdef CUSTOM_MODES >+ clt_mdct_clear(&_cfg, arch); >+#endif > } > > int main(int argc,char ** argv) >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/tests/test_unit_rotation.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/tests/test_unit_rotation.c >index 1080c2085d02c5c975fd0f5ef9dd832303ad9e45..267b98301ac838cccc3f582b5b22933a66d6c1e7 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/tests/test_unit_rotation.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/tests/test_unit_rotation.c >@@ -37,43 +37,11 @@ > > #include <stdio.h> > #include <stdlib.h> >-#include "vq.c" >-#include "cwrs.c" >-#include "entcode.c" >-#include "entenc.c" >-#include "entdec.c" >-#include "mathops.c" >+#include "vq.h" > #include "bands.h" >-#include "pitch.c" >-#include "celt_lpc.c" >-#include "celt.c" >+#include "stack_alloc.h" > #include <math.h> > >-#if defined(OPUS_X86_MAY_HAVE_SSE) || defined(OPUS_X86_MAY_HAVE_SSE2) || defined(OPUS_X86_MAY_HAVE_SSE4_1) >-# if defined(OPUS_X86_MAY_HAVE_SSE) >-# include "x86/pitch_sse.c" >-# endif >-# if defined(OPUS_X86_MAY_HAVE_SSE2) >-# include "x86/pitch_sse2.c" >-# endif >-# if defined(OPUS_X86_MAY_HAVE_SSE4_1) >-# include "x86/pitch_sse4_1.c" >-# include "x86/celt_lpc_sse.c" >-# endif >-# include "x86/x86_celt_map.c" >-#elif defined(OPUS_ARM_ASM) || defined(OPUS_ARM_MAY_HAVE_NEON_INTR) >-# include "arm/armcpu.c" >-# if defined(OPUS_ARM_MAY_HAVE_NEON_INTR) >-# include "arm/celt_neon_intr.c" >-# if defined(HAVE_ARM_NE10) >-# include "kiss_fft.c" >-# include "mdct.c" >-# include "arm/celt_ne10_fft.c" >-# include "arm/celt_ne10_mdct.c" >-# endif >-# endif >-# include "arm/arm_celt_map.c" >-#endif > > #define MAX_SIZE 100 > >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/vq.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/vq.c >index d29f38fd8ef79015b63d8819a48d478ca8bce6e6..8ef80e507f262dad55e5eb6dbbf5ae2b143ad107 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/vq.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/vq.c >@@ -67,7 +67,7 @@ static void exp_rotation1(celt_norm *X, int len, int stride, opus_val16 c, opus_ > } > #endif /* OVERRIDE_vq_exp_rotation1 */ > >-static void exp_rotation(celt_norm *X, int len, int dir, int stride, int K, int spread) >+void exp_rotation(celt_norm *X, int len, int dir, int stride, int K, int spread) > { > static const int SPREAD_FACTOR[3]={15,10,5}; > int i; >@@ -158,42 +158,27 @@ static unsigned extract_collapse_mask(int *iy, int N, int B) > return collapse_mask; > } > >-unsigned alg_quant(celt_norm *X, int N, int K, int spread, int B, ec_enc *enc >-#ifdef RESYNTH >- , opus_val16 gain >-#endif >- ) >+opus_val16 op_pvq_search_c(celt_norm *X, int *iy, int K, int N, int arch) > { > VARDECL(celt_norm, y); >- VARDECL(int, iy); >- VARDECL(opus_val16, signx); >+ VARDECL(int, signx); > int i, j; >- opus_val16 s; > int pulsesLeft; > opus_val32 sum; > opus_val32 xy; > opus_val16 yy; >- unsigned collapse_mask; > SAVE_STACK; > >- celt_assert2(K>0, "alg_quant() needs at least one pulse"); >- celt_assert2(N>1, "alg_quant() needs at least two dimensions"); >- >+ (void)arch; > ALLOC(y, N, celt_norm); >- ALLOC(iy, N, int); >- ALLOC(signx, N, opus_val16); >- >- exp_rotation(X, N, 1, B, K, spread); >+ ALLOC(signx, N, int); > > /* Get rid of the sign */ > sum = 0; > j=0; do { >- if (X[j]>0) >- signx[j]=1; >- else { >- signx[j]=-1; >- X[j]=-X[j]; >- } >+ signx[j] = X[j]<0; >+ /* OPT: Make sure the compiler doesn't use a branch on ABS16(). */ >+ X[j] = ABS16(X[j]); > iy[j] = 0; > y[j] = 0; > } while (++j<N); >@@ -225,7 +210,12 @@ unsigned alg_quant(celt_norm *X, int N, int K, int spread, int B, ec_enc *enc > while (++j<N); > sum = QCONST16(1.f,14); > } >- rcp = EXTRACT16(MULT16_32_Q16(K-1, celt_rcp(sum))); >+#ifdef FIXED_POINT >+ rcp = EXTRACT16(MULT16_32_Q16(K, celt_rcp(sum))); >+#else >+ /* Using K+e with e < 1 guarantees we cannot get more than K pulses. */ >+ rcp = EXTRACT16(MULT16_32_Q16(K+0.8f, celt_rcp(sum))); >+#endif > j=0; do { > #ifdef FIXED_POINT > /* It's really important to round *towards zero* here */ >@@ -240,7 +230,7 @@ unsigned alg_quant(celt_norm *X, int N, int K, int spread, int B, ec_enc *enc > pulsesLeft -= iy[j]; > } while (++j<N); > } >- celt_assert2(pulsesLeft>=1, "Allocated too many pulses in the quick pass"); >+ celt_assert2(pulsesLeft>=0, "Allocated too many pulses in the quick pass"); > > /* This should never happen, but just in case it does (e.g. on silence) > we fill the first bin with pulses. */ >@@ -256,12 +246,12 @@ unsigned alg_quant(celt_norm *X, int N, int K, int spread, int B, ec_enc *enc > pulsesLeft=0; > } > >- s = 1; > for (i=0;i<pulsesLeft;i++) > { >+ opus_val16 Rxy, Ryy; > int best_id; >- opus_val32 best_num = -VERY_LARGE16; >- opus_val16 best_den = 0; >+ opus_val32 best_num; >+ opus_val16 best_den; > #ifdef FIXED_POINT > int rshift; > #endif >@@ -272,9 +262,22 @@ unsigned alg_quant(celt_norm *X, int N, int K, int spread, int B, ec_enc *enc > /* The squared magnitude term gets added anyway, so we might as well > add it outside the loop */ > yy = ADD16(yy, 1); >- j=0; >+ >+ /* Calculations for position 0 are out of the loop, in part to reduce >+ mispredicted branches (since the if condition is usually false) >+ in the loop. */ >+ /* Temporary sums of the new pulse(s) */ >+ Rxy = EXTRACT16(SHR32(ADD32(xy, EXTEND32(X[0])),rshift)); >+ /* We're multiplying y[j] by two so we don't have to do it here */ >+ Ryy = ADD16(yy, y[0]); >+ >+ /* Approximate score: we maximise Rxy/sqrt(Ryy) (we're guaranteed that >+ Rxy is positive because the sign is pre-computed) */ >+ Rxy = MULT16_16_Q15(Rxy,Rxy); >+ best_den = Ryy; >+ best_num = Rxy; >+ j=1; > do { >- opus_val16 Rxy, Ryy; > /* Temporary sums of the new pulse(s) */ > Rxy = EXTRACT16(SHR32(ADD32(xy, EXTEND32(X[j])),rshift)); > /* We're multiplying y[j] by two so we don't have to do it here */ >@@ -285,8 +288,11 @@ unsigned alg_quant(celt_norm *X, int N, int K, int spread, int B, ec_enc *enc > Rxy = MULT16_16_Q15(Rxy,Rxy); > /* The idea is to check for num/den >= best_num/best_den, but that way > we can do it without any division */ >- /* OPT: Make sure to use conditional moves here */ >- if (MULT16_16(best_den, Rxy) > MULT16_16(Ryy, best_num)) >+ /* OPT: It's not clear whether a cmov is faster than a branch here >+ since the condition is more often false than true and using >+ a cmov introduces data dependencies across iterations. The optimal >+ choice may be architecture-dependent. */ >+ if (opus_unlikely(MULT16_16(best_den, Rxy) > MULT16_16(Ryy, best_num))) > { > best_den = Ryy; > best_num = Rxy; >@@ -301,23 +307,47 @@ unsigned alg_quant(celt_norm *X, int N, int K, int spread, int B, ec_enc *enc > > /* Only now that we've made the final choice, update y/iy */ > /* Multiplying y[j] by 2 so we don't have to do it everywhere else */ >- y[best_id] += 2*s; >+ y[best_id] += 2; > iy[best_id]++; > } > > /* Put the original sign back */ > j=0; > do { >- X[j] = MULT16_16(signx[j],X[j]); >- if (signx[j] < 0) >- iy[j] = -iy[j]; >+ /*iy[j] = signx[j] ? -iy[j] : iy[j];*/ >+ /* OPT: The is more likely to be compiled without a branch than the code above >+ but has the same performance otherwise. */ >+ iy[j] = (iy[j]^-signx[j]) + signx[j]; > } while (++j<N); >+ RESTORE_STACK; >+ return yy; >+} >+ >+unsigned alg_quant(celt_norm *X, int N, int K, int spread, int B, ec_enc *enc, >+ opus_val16 gain, int resynth, int arch) >+{ >+ VARDECL(int, iy); >+ opus_val16 yy; >+ unsigned collapse_mask; >+ SAVE_STACK; >+ >+ celt_assert2(K>0, "alg_quant() needs at least one pulse"); >+ celt_assert2(N>1, "alg_quant() needs at least two dimensions"); >+ >+ /* Covers vectorization by up to 4. */ >+ ALLOC(iy, N+3, int); >+ >+ exp_rotation(X, N, 1, B, K, spread); >+ >+ yy = op_pvq_search(X, iy, K, N, arch); >+ > encode_pulses(iy, N, K, enc); > >-#ifdef RESYNTH >- normalise_residual(iy, X, N, yy, gain); >- exp_rotation(X, N, -1, B, K, spread); >-#endif >+ if (resynth) >+ { >+ normalise_residual(iy, X, N, yy, gain); >+ exp_rotation(X, N, -1, B, K, spread); >+ } > > collapse_mask = extract_collapse_mask(iy, N, B); > RESTORE_STACK; >@@ -401,7 +431,7 @@ int stereo_itheta(const celt_norm *X, const celt_norm *Y, int stereo, int N, int > /* 0.63662 = 2/pi */ > itheta = MULT16_16_Q15(QCONST16(0.63662f,15),celt_atan2p(side, mid)); > #else >- itheta = (int)floor(.5f+16384*0.63662f*atan2(side,mid)); >+ itheta = (int)floor(.5f+16384*0.63662f*fast_atan2f(side,mid)); > #endif > > return itheta; >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/vq.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/vq.h >index 5cfcbe50ea05e0721d114a283339b5dca4928527..0dfe6af05823986cad27f11ead601252a3048563 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/vq.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/vq.h >@@ -37,10 +37,22 @@ > #include "entdec.h" > #include "modes.h" > >+#if (defined(OPUS_X86_MAY_HAVE_SSE2) && !defined(FIXED_POINT)) >+#include "x86/vq_sse.h" >+#endif >+ > #if defined(MIPSr1_ASM) > #include "mips/vq_mipsr1.h" > #endif > >+void exp_rotation(celt_norm *X, int len, int dir, int stride, int K, int spread); >+ >+opus_val16 op_pvq_search_c(celt_norm *X, int *iy, int K, int N, int arch); >+ >+#if !defined(OVERRIDE_OP_PVQ_SEARCH) >+#define op_pvq_search(x, iy, K, N, arch) \ >+ (op_pvq_search_c(x, iy, K, N, arch)) >+#endif > > /** Algebraic pulse-vector quantiser. The signal x is replaced by the sum of > * the pitch and a combination of pulses such that its norm is still equal >@@ -51,12 +63,8 @@ > * @param enc Entropy encoder state > * @ret A mask indicating which blocks in the band received pulses > */ >-unsigned alg_quant(celt_norm *X, int N, int K, int spread, int B, >- ec_enc *enc >-#ifdef RESYNTH >- , opus_val16 gain >-#endif >- ); >+unsigned alg_quant(celt_norm *X, int N, int K, int spread, int B, ec_enc *enc, >+ opus_val16 gain, int resynth, int arch); > > /** Algebraic pulse decoder > * @param X Decoded normalised spectrum (returned) >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/x86/celt_lpc_sse.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/x86/celt_lpc_sse.c >index 67e5592acf3ca6b7f817d6dd9f17d99de1da25b0..5478568849aa42ea78db6db2682abf7ed150ffa6 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/x86/celt_lpc_sse.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/x86/celt_lpc_sse.c >@@ -40,65 +40,23 @@ > > #if defined(FIXED_POINT) > >-void celt_fir_sse4_1(const opus_val16 *_x, >+void celt_fir_sse4_1(const opus_val16 *x, > const opus_val16 *num, >- opus_val16 *_y, >+ opus_val16 *y, > int N, > int ord, >- opus_val16 *mem, > int arch) > { > int i,j; > VARDECL(opus_val16, rnum); >- VARDECL(opus_val16, x); > > __m128i vecNoA; > opus_int32 noA ; > SAVE_STACK; > > ALLOC(rnum, ord, opus_val16); >- ALLOC(x, N+ord, opus_val16); > for(i=0;i<ord;i++) > rnum[i] = num[ord-i-1]; >- for(i=0;i<ord;i++) >- x[i] = mem[ord-i-1]; >- >- for (i=0;i<N-7;i+=8) >- { >- x[i+ord ]=_x[i ]; >- x[i+ord+1]=_x[i+1]; >- x[i+ord+2]=_x[i+2]; >- x[i+ord+3]=_x[i+3]; >- x[i+ord+4]=_x[i+4]; >- x[i+ord+5]=_x[i+5]; >- x[i+ord+6]=_x[i+6]; >- x[i+ord+7]=_x[i+7]; >- } >- >- for (;i<N-3;i+=4) >- { >- x[i+ord ]=_x[i ]; >- x[i+ord+1]=_x[i+1]; >- x[i+ord+2]=_x[i+2]; >- x[i+ord+3]=_x[i+3]; >- } >- >- for (;i<N;i++) >- x[i+ord]=_x[i]; >- >- for(i=0;i<ord;i++) >- mem[i] = _x[N-i-1]; >-#ifdef SMALL_FOOTPRINT >- for (i=0;i<N;i++) >- { >- opus_val32 sum = SHL32(EXTEND32(_x[i]), SIG_SHIFT); >- for (j=0;j<ord;j++) >- { >- sum = MAC16_16(sum,rnum[j],x[i+j]); >- } >- _y[i] = SATURATE16(PSHR32(sum, SIG_SHIFT)); >- } >-#else > noA = EXTEND32(1) << SIG_SHIFT >> 1; > vecNoA = _mm_set_epi32(noA, noA, noA, noA); > >@@ -107,25 +65,24 @@ void celt_fir_sse4_1(const opus_val16 *_x, > opus_val32 sums[4] = {0}; > __m128i vecSum, vecX; > >- xcorr_kernel(rnum, x+i, sums, ord, arch); >+ xcorr_kernel(rnum, x+i-ord, sums, ord, arch); > > vecSum = _mm_loadu_si128((__m128i *)sums); > vecSum = _mm_add_epi32(vecSum, vecNoA); > vecSum = _mm_srai_epi32(vecSum, SIG_SHIFT); >- vecX = OP_CVTEPI16_EPI32_M64(_x + i); >+ vecX = OP_CVTEPI16_EPI32_M64(x + i); > vecSum = _mm_add_epi32(vecSum, vecX); > vecSum = _mm_packs_epi32(vecSum, vecSum); >- _mm_storel_epi64((__m128i *)(_y + i), vecSum); >+ _mm_storel_epi64((__m128i *)(y + i), vecSum); > } > for (;i<N;i++) > { > opus_val32 sum = 0; > for (j=0;j<ord;j++) >- sum = MAC16_16(sum, rnum[j], x[i + j]); >- _y[i] = SATURATE16(ADD32(EXTEND32(_x[i]), PSHR32(sum, SIG_SHIFT))); >+ sum = MAC16_16(sum, rnum[j], x[i+j-ord]); >+ y[i] = SATURATE16(ADD32(EXTEND32(x[i]), PSHR32(sum, SIG_SHIFT))); > } > >-#endif > RESTORE_STACK; > } > >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/x86/celt_lpc_sse.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/x86/celt_lpc_sse.h >index c5ec796ed525e0ff614b65b1d3f3928e7c941f3e..7d1ecf7533282dbc782fe5be54593f4e235a40d5 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/x86/celt_lpc_sse.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/x86/celt_lpc_sse.h >@@ -41,12 +41,11 @@ void celt_fir_sse4_1( > opus_val16 *y, > int N, > int ord, >- opus_val16 *mem, > int arch); > > #if defined(OPUS_X86_PRESUME_SSE4_1) >-#define celt_fir(x, num, y, N, ord, mem, arch) \ >- ((void)arch, celt_fir_sse4_1(x, num, y, N, ord, mem, arch)) >+#define celt_fir(x, num, y, N, ord, arch) \ >+ ((void)arch, celt_fir_sse4_1(x, num, y, N, ord, arch)) > > #else > >@@ -56,11 +55,10 @@ extern void (*const CELT_FIR_IMPL[OPUS_ARCHMASK + 1])( > opus_val16 *y, > int N, > int ord, >- opus_val16 *mem, > int arch); > >-# define celt_fir(x, num, y, N, ord, mem, arch) \ >- ((*CELT_FIR_IMPL[(arch) & OPUS_ARCHMASK])(x, num, y, N, ord, mem, arch)) >+# define celt_fir(x, num, y, N, ord, arch) \ >+ ((*CELT_FIR_IMPL[(arch) & OPUS_ARCHMASK])(x, num, y, N, ord, arch)) > > #endif > #endif >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/x86/vq_sse.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/x86/vq_sse.h >new file mode 100644 >index 0000000000000000000000000000000000000000..b4efe8f249f893ed160040ec825b2a7647e192bb >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/x86/vq_sse.h >@@ -0,0 +1,50 @@ >+/* Copyright (c) 2016 Jean-Marc Valin */ >+/* >+ Redistribution and use in source and binary forms, with or without >+ modification, are permitted provided that the following conditions >+ are met: >+ >+ - Redistributions of source code must retain the above copyright >+ notice, this list of conditions and the following disclaimer. >+ >+ - Redistributions in binary form must reproduce the above copyright >+ notice, this list of conditions and the following disclaimer in the >+ documentation and/or other materials provided with the distribution. >+ >+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS >+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT >+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR >+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER >+ OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, >+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, >+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR >+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF >+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING >+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS >+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+*/ >+ >+#ifndef VQ_SSE_H >+#define VQ_SSE_H >+ >+#if defined(OPUS_X86_MAY_HAVE_SSE2) && !defined(FIXED_POINT) >+#define OVERRIDE_OP_PVQ_SEARCH >+ >+opus_val16 op_pvq_search_sse2(celt_norm *_X, int *iy, int K, int N, int arch); >+ >+#if defined(OPUS_X86_PRESUME_SSE2) >+#define op_pvq_search(x, iy, K, N, arch) \ >+ (op_pvq_search_sse2(x, iy, K, N, arch)) >+ >+#else >+ >+extern opus_val16 (*const OP_PVQ_SEARCH_IMPL[OPUS_ARCHMASK + 1])( >+ celt_norm *_X, int *iy, int K, int N, int arch); >+ >+# define op_pvq_search(X, iy, K, N, arch) \ >+ ((*OP_PVQ_SEARCH_IMPL[(arch) & OPUS_ARCHMASK])(X, iy, K, N, arch)) >+ >+#endif >+#endif >+ >+#endif >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/x86/vq_sse2.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/x86/vq_sse2.c >new file mode 100644 >index 0000000000000000000000000000000000000000..6a31770358b7d416471e1576dd852c8b20878be7 >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/x86/vq_sse2.c >@@ -0,0 +1,217 @@ >+/* Copyright (c) 2007-2008 CSIRO >+ Copyright (c) 2007-2009 Xiph.Org Foundation >+ Copyright (c) 2007-2016 Jean-Marc Valin */ >+/* >+ Redistribution and use in source and binary forms, with or without >+ modification, are permitted provided that the following conditions >+ are met: >+ >+ - Redistributions of source code must retain the above copyright >+ notice, this list of conditions and the following disclaimer. >+ >+ - Redistributions in binary form must reproduce the above copyright >+ notice, this list of conditions and the following disclaimer in the >+ documentation and/or other materials provided with the distribution. >+ >+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS >+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT >+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR >+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER >+ OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, >+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, >+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR >+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF >+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING >+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS >+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+*/ >+ >+#ifdef HAVE_CONFIG_H >+#include "config.h" >+#endif >+ >+#include <xmmintrin.h> >+#include <emmintrin.h> >+#include "celt_lpc.h" >+#include "stack_alloc.h" >+#include "mathops.h" >+#include "vq.h" >+#include "x86cpu.h" >+ >+ >+#ifndef FIXED_POINT >+ >+opus_val16 op_pvq_search_sse2(celt_norm *_X, int *iy, int K, int N, int arch) >+{ >+ int i, j; >+ int pulsesLeft; >+ float xy, yy; >+ VARDECL(celt_norm, y); >+ VARDECL(celt_norm, X); >+ VARDECL(float, signy); >+ __m128 signmask; >+ __m128 sums; >+ __m128i fours; >+ SAVE_STACK; >+ >+ (void)arch; >+ /* All bits set to zero, except for the sign bit. */ >+ signmask = _mm_set_ps1(-0.f); >+ fours = _mm_set_epi32(4, 4, 4, 4); >+ ALLOC(y, N+3, celt_norm); >+ ALLOC(X, N+3, celt_norm); >+ ALLOC(signy, N+3, float); >+ >+ OPUS_COPY(X, _X, N); >+ X[N] = X[N+1] = X[N+2] = 0; >+ sums = _mm_setzero_ps(); >+ for (j=0;j<N;j+=4) >+ { >+ __m128 x4, s4; >+ x4 = _mm_loadu_ps(&X[j]); >+ s4 = _mm_cmplt_ps(x4, _mm_setzero_ps()); >+ /* Get rid of the sign */ >+ x4 = _mm_andnot_ps(signmask, x4); >+ sums = _mm_add_ps(sums, x4); >+ /* Clear y and iy in case we don't do the projection. */ >+ _mm_storeu_ps(&y[j], _mm_setzero_ps()); >+ _mm_storeu_si128((__m128i*)&iy[j], _mm_setzero_si128()); >+ _mm_storeu_ps(&X[j], x4); >+ _mm_storeu_ps(&signy[j], s4); >+ } >+ sums = _mm_add_ps(sums, _mm_shuffle_ps(sums, sums, _MM_SHUFFLE(1, 0, 3, 2))); >+ sums = _mm_add_ps(sums, _mm_shuffle_ps(sums, sums, _MM_SHUFFLE(2, 3, 0, 1))); >+ >+ xy = yy = 0; >+ >+ pulsesLeft = K; >+ >+ /* Do a pre-search by projecting on the pyramid */ >+ if (K > (N>>1)) >+ { >+ __m128i pulses_sum; >+ __m128 yy4, xy4; >+ __m128 rcp4; >+ opus_val32 sum = _mm_cvtss_f32(sums); >+ /* If X is too small, just replace it with a pulse at 0 */ >+ /* Prevents infinities and NaNs from causing too many pulses >+ to be allocated. 64 is an approximation of infinity here. */ >+ if (!(sum > EPSILON && sum < 64)) >+ { >+ X[0] = QCONST16(1.f,14); >+ j=1; do >+ X[j]=0; >+ while (++j<N); >+ sums = _mm_set_ps1(1.f); >+ } >+ /* Using K+e with e < 1 guarantees we cannot get more than K pulses. */ >+ rcp4 = _mm_mul_ps(_mm_set_ps1((float)(K+.8)), _mm_rcp_ps(sums)); >+ xy4 = yy4 = _mm_setzero_ps(); >+ pulses_sum = _mm_setzero_si128(); >+ for (j=0;j<N;j+=4) >+ { >+ __m128 rx4, x4, y4; >+ __m128i iy4; >+ x4 = _mm_loadu_ps(&X[j]); >+ rx4 = _mm_mul_ps(x4, rcp4); >+ iy4 = _mm_cvttps_epi32(rx4); >+ pulses_sum = _mm_add_epi32(pulses_sum, iy4); >+ _mm_storeu_si128((__m128i*)&iy[j], iy4); >+ y4 = _mm_cvtepi32_ps(iy4); >+ xy4 = _mm_add_ps(xy4, _mm_mul_ps(x4, y4)); >+ yy4 = _mm_add_ps(yy4, _mm_mul_ps(y4, y4)); >+ /* double the y[] vector so we don't have to do it in the search loop. */ >+ _mm_storeu_ps(&y[j], _mm_add_ps(y4, y4)); >+ } >+ pulses_sum = _mm_add_epi32(pulses_sum, _mm_shuffle_epi32(pulses_sum, _MM_SHUFFLE(1, 0, 3, 2))); >+ pulses_sum = _mm_add_epi32(pulses_sum, _mm_shuffle_epi32(pulses_sum, _MM_SHUFFLE(2, 3, 0, 1))); >+ pulsesLeft -= _mm_cvtsi128_si32(pulses_sum); >+ xy4 = _mm_add_ps(xy4, _mm_shuffle_ps(xy4, xy4, _MM_SHUFFLE(1, 0, 3, 2))); >+ xy4 = _mm_add_ps(xy4, _mm_shuffle_ps(xy4, xy4, _MM_SHUFFLE(2, 3, 0, 1))); >+ xy = _mm_cvtss_f32(xy4); >+ yy4 = _mm_add_ps(yy4, _mm_shuffle_ps(yy4, yy4, _MM_SHUFFLE(1, 0, 3, 2))); >+ yy4 = _mm_add_ps(yy4, _mm_shuffle_ps(yy4, yy4, _MM_SHUFFLE(2, 3, 0, 1))); >+ yy = _mm_cvtss_f32(yy4); >+ } >+ X[N] = X[N+1] = X[N+2] = -100; >+ y[N] = y[N+1] = y[N+2] = 100; >+ celt_assert2(pulsesLeft>=0, "Allocated too many pulses in the quick pass"); >+ >+ /* This should never happen, but just in case it does (e.g. on silence) >+ we fill the first bin with pulses. */ >+ if (pulsesLeft > N+3) >+ { >+ opus_val16 tmp = (opus_val16)pulsesLeft; >+ yy = MAC16_16(yy, tmp, tmp); >+ yy = MAC16_16(yy, tmp, y[0]); >+ iy[0] += pulsesLeft; >+ pulsesLeft=0; >+ } >+ >+ for (i=0;i<pulsesLeft;i++) >+ { >+ int best_id; >+ __m128 xy4, yy4; >+ __m128 max, max2; >+ __m128i count; >+ __m128i pos; >+ /* The squared magnitude term gets added anyway, so we might as well >+ add it outside the loop */ >+ yy = ADD16(yy, 1); >+ xy4 = _mm_load1_ps(&xy); >+ yy4 = _mm_load1_ps(&yy); >+ max = _mm_setzero_ps(); >+ pos = _mm_setzero_si128(); >+ count = _mm_set_epi32(3, 2, 1, 0); >+ for (j=0;j<N;j+=4) >+ { >+ __m128 x4, y4, r4; >+ x4 = _mm_loadu_ps(&X[j]); >+ y4 = _mm_loadu_ps(&y[j]); >+ x4 = _mm_add_ps(x4, xy4); >+ y4 = _mm_add_ps(y4, yy4); >+ y4 = _mm_rsqrt_ps(y4); >+ r4 = _mm_mul_ps(x4, y4); >+ /* Update the index of the max. */ >+ pos = _mm_max_epi16(pos, _mm_and_si128(count, _mm_castps_si128(_mm_cmpgt_ps(r4, max)))); >+ /* Update the max. */ >+ max = _mm_max_ps(max, r4); >+ /* Update the indices (+4) */ >+ count = _mm_add_epi32(count, fours); >+ } >+ /* Horizontal max */ >+ max2 = _mm_max_ps(max, _mm_shuffle_ps(max, max, _MM_SHUFFLE(1, 0, 3, 2))); >+ max2 = _mm_max_ps(max2, _mm_shuffle_ps(max2, max2, _MM_SHUFFLE(2, 3, 0, 1))); >+ /* Now that max2 contains the max at all positions, look at which value(s) of the >+ partial max is equal to the global max. */ >+ pos = _mm_and_si128(pos, _mm_castps_si128(_mm_cmpeq_ps(max, max2))); >+ pos = _mm_max_epi16(pos, _mm_unpackhi_epi64(pos, pos)); >+ pos = _mm_max_epi16(pos, _mm_shufflelo_epi16(pos, _MM_SHUFFLE(1, 0, 3, 2))); >+ best_id = _mm_cvtsi128_si32(pos); >+ >+ /* Updating the sums of the new pulse(s) */ >+ xy = ADD32(xy, EXTEND32(X[best_id])); >+ /* We're multiplying y[j] by two so we don't have to do it here */ >+ yy = ADD16(yy, y[best_id]); >+ >+ /* Only now that we've made the final choice, update y/iy */ >+ /* Multiplying y[j] by 2 so we don't have to do it everywhere else */ >+ y[best_id] += 2; >+ iy[best_id]++; >+ } >+ >+ /* Put the original sign back */ >+ for (j=0;j<N;j+=4) >+ { >+ __m128i y4; >+ __m128i s4; >+ y4 = _mm_loadu_si128((__m128i*)&iy[j]); >+ s4 = _mm_castps_si128(_mm_loadu_ps(&signy[j])); >+ y4 = _mm_xor_si128(_mm_add_epi32(y4, s4), s4); >+ _mm_storeu_si128((__m128i*)&iy[j], y4); >+ } >+ RESTORE_STACK; >+ return yy; >+} >+ >+#endif >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/x86/x86_celt_map.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/x86/x86_celt_map.c >index 47ba41b9eefd5e3dcf4e4f8f5908b1cb0c5eae5a..d39d88edecd5719397315701ae3b93dbcf0a767e 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/x86/x86_celt_map.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/celt/x86/x86_celt_map.c >@@ -33,6 +33,7 @@ > #include "celt_lpc.h" > #include "pitch.h" > #include "pitch_sse.h" >+#include "vq.h" > > #if defined(OPUS_HAVE_RTCD) > >@@ -46,7 +47,6 @@ void (*const CELT_FIR_IMPL[OPUS_ARCHMASK + 1])( > opus_val16 *y, > int N, > int ord, >- opus_val16 *mem, > int arch > ) = { > celt_fir_c, /* non-sse */ >@@ -151,5 +151,17 @@ void (*const COMB_FILTER_CONST_IMPL[OPUS_ARCHMASK + 1])( > > #endif > >+#if defined(OPUS_X86_MAY_HAVE_SSE2) && !defined(OPUS_X86_PRESUME_SSE2) >+opus_val16 (*const OP_PVQ_SEARCH_IMPL[OPUS_ARCHMASK + 1])( >+ celt_norm *_X, int *iy, int K, int N, int arch >+) = { >+ op_pvq_search_c, /* non-sse */ >+ op_pvq_search_c, >+ MAY_HAVE_SSE2(op_pvq_search), >+ MAY_HAVE_SSE2(op_pvq_search), >+ MAY_HAVE_SSE2(op_pvq_search) >+}; >+#endif >+ > #endif > #endif >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/configure.ac b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/configure.ac >index c527e3684d6cf5eacfc27805afe3e3d7f823a107..5ffa2d38e70ce65c390d9020b41134b9f57d2092 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/configure.ac >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/configure.ac >@@ -22,9 +22,9 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) > > # For libtool. > dnl Please update these for releases. >-OPUS_LT_CURRENT=5 >-OPUS_LT_REVISION=3 >-OPUS_LT_AGE=5 >+OPUS_LT_CURRENT=6 >+OPUS_LT_REVISION=1 >+OPUS_LT_AGE=6 > > AC_SUBST(OPUS_LT_CURRENT) > AC_SUBST(OPUS_LT_REVISION) >@@ -421,12 +421,12 @@ AC_DEFUN([OPUS_PATH_NE10], > fi > > AC_MSG_CHECKING(for NE10) >- save_CFLAGS="$CFLAGS"; CFLAGS="$NE10_CFLAGS" >- save_LIBS="$LIBS"; LIBS="$NE10_LIBS $LIBM" >+ save_CFLAGS="$CFLAGS"; CFLAGS="$CFLAGS $NE10_CFLAGS" >+ save_LIBS="$LIBS"; LIBS="$LIBS $NE10_LIBS $LIBM" > AC_LINK_IFELSE( > [ > AC_LANG_PROGRAM( >- [[#include <NE10_init.h> >+ [[#include <NE10_dsp.h> > ]], > [[ > ne10_fft_cfg_float32_t cfg; >@@ -715,7 +715,7 @@ AS_IF([test x"$enable_intrinsics" = x"yes"],[ > ]])], > [AC_MSG_RESULT([C method]) > AC_DEFINE([CPU_INFO_BY_C], [1], [Get CPU Info by c method])], >- [AC_MSG_ERROR([no supported Get CPU Info method, please disable intrinsics])])])]) >+ [AC_MSG_ERROR([no supported Get CPU Info method, please disable run-time CPU capabilities detection or intrinsics])])])]) > ], > [ > AC_MSG_WARN([No intrinsics support for your architecture]) >@@ -767,6 +767,15 @@ AS_IF([test "$enable_fuzzing" = "yes"], [ > AC_DEFINE([FUZZING], [1], [Fuzzing]) > ]) > >+AC_ARG_ENABLE([check-asm], >+ [AS_HELP_STRING([--enable-check-asm], >+ [enable bit-exactness checks between optimized and c implementations])],, >+ [enable_check_asm=no]) >+ >+AS_IF([test "$enable_check_asm" = "yes"], [ >+ AC_DEFINE([OPUS_CHECK_ASM], [1], [Run bit-exactness checks between optimized and c implementations]) >+]) >+ > AC_ARG_ENABLE([ambisonics], > [AS_HELP_STRING([--enable-ambisonics],[enable experimental ambisonic encoding and decoding support])],, > [enable_ambisonics=no]) >@@ -781,6 +790,7 @@ AC_ARG_ENABLE([doc], > > AS_IF([test "$enable_doc" = "yes"], [ > AC_CHECK_PROG(HAVE_DOXYGEN, [doxygen], [yes], [no]) >+ AC_CHECK_PROG(HAVE_DOT, [dot], [yes], [no]) > ],[ > HAVE_DOXYGEN=no > ]) >@@ -794,6 +804,15 @@ AC_ARG_ENABLE([extra-programs], > AM_CONDITIONAL([EXTRA_PROGRAMS], [test "$enable_extra_programs" = "yes"]) > > >+AC_ARG_ENABLE([update-draft], >+ AS_HELP_STRING([--enable-update-draft], [Enable bitstream changes from draft-ietf-codec-opus-update]),, >+ [enable_update_draft=no]) >+ >+AS_IF([test "$enable_update_draft" = "yes"], [ >+ AC_DEFINE([ENABLE_UPDATE_DRAFT], [1], [Enable bitstream changes from draft-ietf-codec-opus-update]) >+]) >+ >+ > saved_CFLAGS="$CFLAGS" > CFLAGS="$CFLAGS -fvisibility=hidden" > AC_MSG_CHECKING([if ${CC} supports -fvisibility=hidden]) >@@ -859,7 +878,8 @@ AC_MSG_NOTICE([ > Custom modes: .................. ${enable_custom_modes} > Assertion checking: ............ ${enable_assertions} > Fuzzing: ....................... ${enable_fuzzing} >- Ambisonics support: .............${enable_ambisonics} >+ Check ASM: ..................... ${enable_check_asm} >+ Ambisonics support: ............ ${enable_ambisonics} > > API documentation: ............. ${enable_doc} > Extra programs: ................ ${enable_extra_programs} >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/Doxyfile.in b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/Doxyfile.in >index cd776752d4967dde618f900727d6705e5dc87a0f..36eee0b5380b80432796310267852cb162a46bd1 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/Doxyfile.in >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/Doxyfile.in >@@ -318,3 +318,18 @@ PREDEFINED = OPUS_EXPORT= \ > OPUS_CUSTOM_EXPORT_STATIC= \ > OPUS_WARN_UNUSED_RESULT= \ > OPUS_ARG_NONNULL(_x)= >+ >+#--------------------------------------------------------------------------- >+# Configuration options related to the dot tool >+#--------------------------------------------------------------------------- >+ >+# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is >+# available from the path. This tool is part of Graphviz (see: >+# http://www.graphviz.org/), a graph visualization toolkit from AT&T and Lucent >+# Bell Labs. >+ >+# Debian defaults to YES here, while Fedora and Homebrew default to NO. >+# So we set this based on whether the graphviz package is available at >+# configure time. >+# >+HAVE_DOT = @HAVE_DOT@ >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/TODO b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/TODO >deleted file mode 100644 >index 9e1c2d513c4d49f4a1d2ebf123ecc1b5f7c1a667..0000000000000000000000000000000000000000 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/TODO >+++ /dev/null >@@ -1,7 +0,0 @@ >-define audio bandwidth as frequency range >- >-repeat padding recommendation >- >-ptime: refer to RFC >- >-Opus does not provide any confidentiality or integrity protection >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/build_draft.sh b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/build_draft.sh >new file mode 100644 >index 0000000000000000000000000000000000000000..d15b22a79b346c0eafd044ee1e0b4a2627584d92 >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/build_draft.sh >@@ -0,0 +1,104 @@ >+#!/bin/sh >+ >+# Copyright (c) 2011-2012 Xiph.Org Foundation and Mozilla Corporation >+# >+# This file is extracted from RFC6716. Please see that RFC for additional >+# information. >+# >+# Redistribution and use in source and binary forms, with or without >+# modification, are permitted provided that the following conditions >+# are met: >+# >+# - Redistributions of source code must retain the above copyright >+# notice, this list of conditions and the following disclaimer. >+# >+# - Redistributions in binary form must reproduce the above copyright >+# notice, this list of conditions and the following disclaimer in the >+# documentation and/or other materials provided with the distribution. >+# >+# - Neither the name of Internet Society, IETF or IETF Trust, nor the >+# names of specific contributors, may be used to endorse or promote >+# products derived from this software without specific prior written >+# permission. >+# >+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS >+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT >+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR >+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER >+# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, >+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, >+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR >+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF >+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING >+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS >+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+ >+#Stop on errors >+set -e >+#Set the CWD to the location of this script >+[ -n "${0%/*}" ] && cd "${0%/*}" >+ >+toplevel=".." >+destdir="opus_source" >+ >+echo packaging source code >+rm -rf "${destdir}" >+mkdir "${destdir}" >+mkdir "${destdir}/src" >+mkdir "${destdir}/silk" >+mkdir "${destdir}/silk/float" >+mkdir "${destdir}/silk/fixed" >+mkdir "${destdir}/celt" >+mkdir "${destdir}/include" >+for f in `cat "${toplevel}"/opus_sources.mk "${toplevel}"/celt_sources.mk \ >+ "${toplevel}"/silk_sources.mk "${toplevel}"/opus_headers.mk \ >+ "${toplevel}"/celt_headers.mk "${toplevel}"/silk_headers.mk \ >+ | grep '\.[ch]' | sed -e 's/^.*=//' -e 's/\\\\//'` ; do >+ cp -a "${toplevel}/${f}" "${destdir}/${f}" >+done >+cp -a "${toplevel}"/src/opus_demo.c "${destdir}"/src/ >+cp -a "${toplevel}"/src/opus_compare.c "${destdir}"/src/ >+cp -a "${toplevel}"/celt/opus_custom_demo.c "${destdir}"/celt/ >+cp -a "${toplevel}"/Makefile.unix "${destdir}"/Makefile >+cp -a "${toplevel}"/opus_sources.mk "${destdir}"/ >+cp -a "${toplevel}"/celt_sources.mk "${destdir}"/ >+cp -a "${toplevel}"/silk_sources.mk "${destdir}"/ >+cp -a "${toplevel}"/README.draft "${destdir}"/README >+cp -a "${toplevel}"/COPYING "${destdir}"/COPYING >+cp -a "${toplevel}"/tests/run_vectors.sh "${destdir}"/ >+ >+GZIP=-9 tar --owner=root --group=root --format=v7 -czf opus_source.tar.gz "${destdir}" >+echo building base64 version >+cat opus_source.tar.gz| base64 | tr -d '\n' | fold -w 64 | \ >+ sed -e 's/^/\<spanx style="vbare"\>###/' -e 's/$/\<\/spanx\>\<vspace\/\>/' > \ >+ opus_source.base64 >+ >+ >+#echo '<figure>' > opus_compare_escaped.c >+#echo '<artwork>' >> opus_compare_escaped.c >+#echo '<![CDATA[' >> opus_compare_escaped.c >+#cat opus_compare.c >> opus_compare_escaped.c >+#echo ']]>' >> opus_compare_escaped.c >+#echo '</artwork>' >> opus_compare_escaped.c >+#echo '</figure>' >> opus_compare_escaped.c >+ >+if [[ ! -d ../opus_testvectors ]] ; then >+ echo "Downloading test vectors..." >+ wget 'http://opus-codec.org/testvectors/opus_testvectors.tar.gz' >+ tar -C .. -xvzf opus_testvectors.tar.gz >+fi >+echo '<figure>' > testvectors_sha1 >+echo '<artwork>' >> testvectors_sha1 >+echo '<![CDATA[' >> testvectors_sha1 >+(cd ../opus_testvectors; sha1sum *.bit *.dec) >> testvectors_sha1 >+#cd opus_testvectors >+#sha1sum *.bit *.dec >> ../testvectors_sha1 >+#cd .. >+echo ']]>' >> testvectors_sha1 >+echo '</artwork>' >> testvectors_sha1 >+echo '</figure>' >> testvectors_sha1 >+ >+echo running xml2rfc >+xml2rfc draft-ietf-codec-opus.xml draft-ietf-codec-opus.html & >+xml2rfc draft-ietf-codec-opus.xml >+wait >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/build_isobmff.sh b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/build_isobmff.sh >new file mode 100644 >index 0000000000000000000000000000000000000000..95ea202e4afeedf495cfe28aa328c8b9ebef5cf8 >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/build_isobmff.sh >@@ -0,0 +1,50 @@ >+#!/bin/sh >+ >+# Copyright (c) 2014 Xiph.Org Foundation and Mozilla Foundation >+# >+# Redistribution and use in source and binary forms, with or without >+# modification, are permitted provided that the following conditions >+# are met: >+# >+# - Redistributions of source code must retain the above copyright >+# notice, this list of conditions and the following disclaimer. >+# >+# - Redistributions in binary form must reproduce the above copyright >+# notice, this list of conditions and the following disclaimer in the >+# documentation and/or other materials provided with the distribution. >+# >+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS >+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT >+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR >+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER >+# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, >+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, >+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR >+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF >+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING >+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS >+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+ >+#Stop on errors >+set -e >+#Set the CWD to the location of this script >+[ -n "${0%/*}" ] && cd "${0%/*}" >+ >+HTML=opus_in_isobmff.html >+ >+echo downloading updates... >+CSS=${HTML%%.html}.css >+wget -q http://vfrmaniac.fushizen.eu/contents/${HTML} -O ${HTML} >+wget -q http://vfrmaniac.fushizen.eu/style.css -O ${CSS} >+ >+echo updating links... >+cat ${HTML} | sed -e "s/\\.\\.\\/style.css/${CSS}/" > ${HTML}+ && mv ${HTML}+ ${HTML} >+ >+echo stripping... >+cat ${HTML} | sed -e 's/<!--.*-->//g' > ${HTML}+ && mv ${HTML}+ ${HTML} >+cat ${HTML} | sed -e 's/ *$//g' > ${HTML}+ && mv ${HTML}+ ${HTML} >+cat ${CSS} | sed -e 's/ *$//g' > ${CSS}+ && mv ${CSS}+ ${CSS} >+ >+ >+VERSION=$(fgrep Version ${HTML} | sed 's/.*Version \([0-9]\.[0-9]\.[0-9]\).*/\1/') >+echo Now at version ${VERSION} >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/build_oggdraft.sh b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/build_oggdraft.sh >new file mode 100644 >index 0000000000000000000000000000000000000000..30ee534b0d6067503f44a2dd472274cb7023d548 >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/build_oggdraft.sh >@@ -0,0 +1,52 @@ >+#!/bin/sh >+ >+# Copyright (c) 2012 Xiph.Org Foundation and Mozilla Corporation >+# >+# This file is extracted from RFC6716. Please see that RFC for additional >+# information. >+# >+# Redistribution and use in source and binary forms, with or without >+# modification, are permitted provided that the following conditions >+# are met: >+# >+# - Redistributions of source code must retain the above copyright >+# notice, this list of conditions and the following disclaimer. >+# >+# - Redistributions in binary form must reproduce the above copyright >+# notice, this list of conditions and the following disclaimer in the >+# documentation and/or other materials provided with the distribution. >+# >+# - Neither the name of Internet Society, IETF or IETF Trust, nor the >+# names of specific contributors, may be used to endorse or promote >+# products derived from this software without specific prior written >+# permission. >+# >+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS >+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT >+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR >+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER >+# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, >+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, >+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR >+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF >+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING >+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS >+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+ >+#Stop on errors >+set -e >+#Set the CWD to the location of this script >+[ -n "${0%/*}" ] && cd "${0%/*}" >+ >+if test -z `which xml2rfc 2> /dev/null`; then >+ echo "Error: couldn't find xml2rfc." >+ echo >+ echo "Please install xml2rfc version 2 or later." >+ echo "E.g. 'pip install xml2rfc' or follow the instructions" >+ echo "on http://pypi.python.org/pypi/xml2rfc/ or tools.ietf.org." >+ exit 1 >+fi >+ >+echo running xml2rfc >+# version 2 syntax >+xml2rfc draft-ietf-codec-oggopus.xml --text --html >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/draft-ietf-codec-oggopus.xml b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/draft-ietf-codec-oggopus.xml >new file mode 100644 >index 0000000000000000000000000000000000000000..128816e935e859c63035cd95ff04a75dd5f5ee18 >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/draft-ietf-codec-oggopus.xml >@@ -0,0 +1,1873 @@ >+<?xml version="1.0" encoding="utf-8"?> >+<!-- >+ Copyright (c) 2012-2016 Xiph.Org Foundation and contributors >+ >+ Redistribution and use in source and binary forms, with or without >+ modification, are permitted provided that the following conditions >+ are met: >+ >+ - Redistributions of source code must retain the above copyright >+ notice, this list of conditions and the following disclaimer. >+ >+ - Redistributions in binary form must reproduce the above copyright >+ notice, this list of conditions and the following disclaimer in the >+ documentation and/or other materials provided with the distribution. >+ >+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS >+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT >+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR >+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER >+ OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, >+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, >+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR >+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF >+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING >+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS >+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+ >+ Special permission is granted to remove the above copyright notice, list of >+ conditions, and disclaimer when submitting this document, with or without >+ modification, to the IETF. >+--> >+<!DOCTYPE rfc SYSTEM 'rfc2629.dtd' [ >+<!ENTITY rfc2119 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml'> >+<!ENTITY rfc3533 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.3533.xml'> >+<!ENTITY rfc3629 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.3629.xml'> >+<!ENTITY rfc4732 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.4732.xml'> >+<!ENTITY rfc5226 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.5226.xml'> >+<!ENTITY rfc5334 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.5334.xml'> >+<!ENTITY rfc6381 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.6381.xml'> >+<!ENTITY rfc6716 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.6716.xml'> >+<!ENTITY rfc6982 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.6982.xml'> >+<!ENTITY rfc7587 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.7587.xml'> >+]> >+<?rfc toc="yes" symrefs="yes" ?> >+ >+<rfc ipr="trust200902" category="std" docName="draft-ietf-codec-oggopus-14" >+ updates="5334"> >+ >+<front> >+<title abbrev="Ogg Opus">Ogg Encapsulation for the Opus Audio Codec</title> >+<author initials="T.B." surname="Terriberry" fullname="Timothy B. Terriberry"> >+<organization>Mozilla Corporation</organization> >+<address> >+<postal> >+<street>650 Castro Street</street> >+<city>Mountain View</city> >+<region>CA</region> >+<code>94041</code> >+<country>USA</country> >+</postal> >+<phone>+1 650 903-0800</phone> >+<email>tterribe@xiph.org</email> >+</address> >+</author> >+ >+<author initials="R." surname="Lee" fullname="Ron Lee"> >+<organization>Voicetronix</organization> >+<address> >+<postal> >+<street>246 Pulteney Street, Level 1</street> >+<city>Adelaide</city> >+<region>SA</region> >+<code>5000</code> >+<country>Australia</country> >+</postal> >+<phone>+61 8 8232 9112</phone> >+<email>ron@debian.org</email> >+</address> >+</author> >+ >+<author initials="R." surname="Giles" fullname="Ralph Giles"> >+<organization>Mozilla Corporation</organization> >+<address> >+<postal> >+<street>163 West Hastings Street</street> >+<city>Vancouver</city> >+<region>BC</region> >+<code>V6B 1H5</code> >+<country>Canada</country> >+</postal> >+<phone>+1 778 785 1540</phone> >+<email>giles@xiph.org</email> >+</address> >+</author> >+ >+<date day="22" month="February" year="2016"/> >+<area>RAI</area> >+<workgroup>codec</workgroup> >+ >+<abstract> >+<t> >+This document defines the Ogg encapsulation for the Opus interactive speech and >+ audio codec. >+This allows data encoded in the Opus format to be stored in an Ogg logical >+ bitstream. >+</t> >+</abstract> >+</front> >+ >+<middle> >+<section anchor="intro" title="Introduction"> >+<t> >+The IETF Opus codec is a low-latency audio codec optimized for both voice and >+ general-purpose audio. >+See <xref target="RFC6716"/> for technical details. >+This document defines the encapsulation of Opus in a continuous, logical Ogg >+ bitstream <xref target="RFC3533"/>. >+Ogg encapsulation provides Opus with a long-term storage format supporting >+ all of the essential features, including metadata, fast and accurate seeking, >+ corruption detection, recapture after errors, low overhead, and the ability to >+ multiplex Opus with other codecs (including video) with minimal buffering. >+It also provides a live streamable format, capable of delivery over a reliable >+ stream-oriented transport, without requiring all the data, or even the total >+ length of the data, up-front, in a form that is identical to the on-disk >+ storage format. >+</t> >+<t> >+Ogg bitstreams are made up of a series of 'pages', each of which contains data >+ from one or more 'packets'. >+Pages are the fundamental unit of multiplexing in an Ogg stream. >+Each page is associated with a particular logical stream and contains a capture >+ pattern and checksum, flags to mark the beginning and end of the logical >+ stream, and a 'granule position' that represents an absolute position in the >+ stream, to aid seeking. >+A single page can contain up to 65,025 octets of packet data from up to 255 >+ different packets. >+Packets can be split arbitrarily across pages, and continued from one page to >+ the next (allowing packets much larger than would fit on a single page). >+Each page contains 'lacing values' that indicate how the data is partitioned >+ into packets, allowing a demultiplexer (demuxer) to recover the packet >+ boundaries without examining the encoded data. >+A packet is said to 'complete' on a page when the page contains the final >+ lacing value corresponding to that packet. >+</t> >+<t> >+This encapsulation defines the contents of the packet data, including >+ the necessary headers, the organization of those packets into a logical >+ stream, and the interpretation of the codec-specific granule position field. >+It does not attempt to describe or specify the existing Ogg container format. >+Readers unfamiliar with the basic concepts mentioned above are encouraged to >+ review the details in <xref target="RFC3533"/>. >+</t> >+ >+</section> >+ >+<section anchor="terminology" title="Terminology"> >+<t> >+The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", >+ "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this >+ document are to be interpreted as described in <xref target="RFC2119"/>. >+</t> >+ >+</section> >+ >+<section anchor="packet_organization" title="Packet Organization"> >+<t> >+An Ogg Opus stream is organized as follows (see >+ <xref target="packet-org-example"/> for an example). >+</t> >+ >+<figure anchor="packet-org-example" >+ title="Example packet organization for a logical Ogg Opus stream" >+ align="center"> >+<artwork align="center"><![CDATA[ >+ Page 0 Pages 1 ... n Pages (n+1) ... >+ +------------+ +---+ +---+ ... +---+ +-----------+ +---------+ +-- >+ | | | | | | | | | | | | | >+ |+----------+| |+-----------------+| |+-------------------+ +----- >+ |||ID Header|| || Comment Header || ||Audio Data Packet 1| | ... >+ |+----------+| |+-----------------+| |+-------------------+ +----- >+ | | | | | | | | | | | | | >+ +------------+ +---+ +---+ ... +---+ +-----------+ +---------+ +-- >+ ^ ^ ^ >+ | | | >+ | | Mandatory Page Break >+ | | >+ | ID header is contained on a single page >+ | >+ 'Beginning Of Stream' >+]]></artwork> >+</figure> >+ >+<t> >+There are two mandatory header packets. >+The first packet in the logical Ogg bitstream MUST contain the identification >+ (ID) header, which uniquely identifies a stream as Opus audio. >+The format of this header is defined in <xref target="id_header"/>. >+It is placed alone (without any other packet data) on the first page of >+ the logical Ogg bitstream, and completes on that page. >+This page has its 'beginning of stream' flag set. >+</t> >+<t> >+The second packet in the logical Ogg bitstream MUST contain the comment header, >+ which contains user-supplied metadata. >+The format of this header is defined in <xref target="comment_header"/>. >+It MAY span multiple pages, beginning on the second page of the logical >+ stream. >+However many pages it spans, the comment header packet MUST finish the page on >+ which it completes. >+</t> >+<t> >+All subsequent pages are audio data pages, and the Ogg packets they contain are >+ audio data packets. >+Each audio data packet contains one Opus packet for each of N different >+ streams, where N is typically one for mono or stereo, but MAY be greater than >+ one for multichannel audio. >+The value N is specified in the ID header (see >+ <xref target="channel_mapping"/>), and is fixed over the entire length of the >+ logical Ogg bitstream. >+</t> >+<t> >+The first (N - 1) Opus packets, if any, are packed one after another >+ into the Ogg packet, using the self-delimiting framing from Appendix B of >+ <xref target="RFC6716"/>. >+The remaining Opus packet is packed at the end of the Ogg packet using the >+ regular, undelimited framing from Section 3 of <xref target="RFC6716"/>. >+All of the Opus packets in a single Ogg packet MUST be constrained to have the >+ same duration. >+An implementation of this specification SHOULD treat any Opus packet whose >+ duration is different from that of the first Opus packet in an Ogg packet as >+ if it were a malformed Opus packet with an invalid Table Of Contents (TOC) >+ sequence. >+</t> >+<t> >+The TOC sequence at the beginning of each Opus packet indicates the coding >+ mode, audio bandwidth, channel count, duration (frame size), and number of >+ frames per packet, as described in Section 3.1 >+ of <xref target="RFC6716"/>. >+The coding mode is one of SILK, Hybrid, or Constrained Energy Lapped Transform >+ (CELT). >+The combination of coding mode, audio bandwidth, and frame size is referred to >+ as the configuration of an Opus packet. >+</t> >+<t> >+Packets are placed into Ogg pages in order until the end of stream. >+Audio data packets might span page boundaries. >+The first audio data page could have the 'continued packet' flag set >+ (indicating the first audio data packet is continued from a previous page) if, >+ for example, it was a live stream joined mid-broadcast, with the headers >+ pasted on the front. >+If a page has the 'continued packet' flag set and one of the following >+ conditions is also true: >+<list style="symbols"> >+<t>the previous page with packet data does not end in a continued packet (does >+ not end with a lacing value of 255) OR</t> >+<t>the page sequence numbers are not consecutive,</t> >+</list> >+ then a demuxer MUST NOT attempt to decode the data for the first packet on the >+ page unless the demuxer has some special knowledge that would allow it to >+ interpret this data despite the missing pieces. >+An implementation MUST treat a zero-octet audio data packet as if it were a >+ malformed Opus packet as described in >+ Section 3.4 of <xref target="RFC6716"/>. >+</t> >+<t> >+A logical stream ends with a page with the 'end of stream' flag set, but >+ implementations need to be prepared to deal with truncated streams that do not >+ have a page marked 'end of stream'. >+There is no reason for the final packet on the last page to be a continued >+ packet, i.e., for the final lacing value to be 255. >+However, demuxers might encounter such streams, possibly as the result of a >+ transfer that did not complete or of corruption. >+If a packet continues onto a subsequent page (i.e., when the page ends with a >+ lacing value of 255) and one of the following conditions is also true: >+<list style="symbols"> >+<t>the next page with packet data does not have the 'continued packet' flag >+ set OR</t> >+<t>there is no next page with packet data OR</t> >+<t>the page sequence numbers are not consecutive,</t> >+</list> >+ then a demuxer MUST NOT attempt to decode the data from that packet unless the >+ demuxer has some special knowledge that would allow it to interpret this data >+ despite the missing pieces. >+There MUST NOT be any more pages in an Opus logical bitstream after a page >+ marked 'end of stream'. >+</t> >+</section> >+ >+<section anchor="granpos" title="Granule Position"> >+<t> >+The granule position MUST be zero for the ID header page and the >+ page where the comment header completes. >+That is, the first page in the logical stream, and the last header >+ page before the first audio data page both have a granule position of zero. >+</t> >+<t> >+The granule position of an audio data page encodes the total number of PCM >+ samples in the stream up to and including the last fully-decodable sample from >+ the last packet completed on that page. >+The granule position of the first audio data page will usually be larger than >+ zero, as described in <xref target="start_granpos_restrictions"/>. >+</t> >+ >+<t> >+A page that is entirely spanned by a single packet (that completes on a >+ subsequent page) has no granule position, and the granule position field is >+ set to the special value '-1' in two's complement. >+</t> >+ >+<t> >+The granule position of an audio data page is in units of PCM audio samples at >+ a fixed rate of 48 kHz (per channel; a stereo stream's granule position >+ does not increment at twice the speed of a mono stream). >+It is possible to run an Opus decoder at other sampling rates, >+ but all Opus packets encode samples at a sampling rate that evenly divides >+ 48 kHz. >+Therefore, the value in the granule position field always counts samples >+ assuming a 48 kHz decoding rate, and the rest of this specification makes >+ the same assumption. >+</t> >+ >+<t> >+The duration of an Opus packet as defined in <xref target="RFC6716"/> can be >+ any multiple of 2.5 ms, up to a maximum of 120 ms. >+This duration is encoded in the TOC sequence at the beginning of each packet. >+The number of samples returned by a decoder corresponds to this duration >+ exactly, even for the first few packets. >+For example, a 20 ms packet fed to a decoder running at 48 kHz will >+ always return 960 samples. >+A demuxer can parse the TOC sequence at the beginning of each Ogg packet to >+ work backwards or forwards from a packet with a known granule position (i.e., >+ the last packet completed on some page) in order to assign granule positions >+ to every packet, or even every individual sample. >+The one exception is the last page in the stream, as described below. >+</t> >+ >+<t> >+All other pages with completed packets after the first MUST have a granule >+ position equal to the number of samples contained in packets that complete on >+ that page plus the granule position of the most recent page with completed >+ packets. >+This guarantees that a demuxer can assign individual packets the same granule >+ position when working forwards as when working backwards. >+For this to work, there cannot be any gaps. >+</t> >+ >+<section anchor="gap-repair" title="Repairing Gaps in Real-time Streams"> >+<t> >+In order to support capturing a real-time stream that has lost or not >+ transmitted packets, a multiplexer (muxer) SHOULD emit packets that explicitly >+ request the use of Packet Loss Concealment (PLC) in place of the missing >+ packets. >+Implementations that fail to do so still MUST NOT increment the granule >+ position for a page by anything other than the number of samples contained in >+ packets that actually complete on that page. >+</t> >+<t> >+Only gaps that are a multiple of 2.5 ms are repairable, as these are the >+ only durations that can be created by packet loss or discontinuous >+ transmission. >+Muxers need not handle other gap sizes. >+Creating the necessary packets involves synthesizing a TOC byte (defined in >+Section 3.1 of <xref target="RFC6716"/>)—and whatever >+ additional internal framing is needed—to indicate the packet duration >+ for each stream. >+The actual length of each missing Opus frame inside the packet is zero bytes, >+ as defined in Section 3.2.1 of <xref target="RFC6716"/>. >+</t> >+ >+<t> >+Zero-byte frames MAY be packed into packets using any of codes 0, 1, >+ 2, or 3. >+When successive frames have the same configuration, the higher code packings >+ reduce overhead. >+Likewise, if the TOC configuration matches, the muxer MAY further combine the >+ empty frames with previous or subsequent non-zero-length frames (using >+ code 2 or VBR code 3). >+</t> >+ >+<t> >+<xref target="RFC6716"/> does not impose any requirements on the PLC, but this >+ section outlines choices that are expected to have a positive influence on >+ most PLC implementations, including the reference implementation. >+Synthesized TOC sequences SHOULD maintain the same mode, audio bandwidth, >+ channel count, and frame size as the previous packet (if any). >+This is the simplest and usually the most well-tested case for the PLC to >+ handle and it covers all losses that do not include a configuration switch, >+ as defined in Section 4.5 of <xref target="RFC6716"/>. >+</t> >+ >+<t> >+When a previous packet is available, keeping the audio bandwidth and channel >+ count the same allows the PLC to provide maximum continuity in the concealment >+ data it generates. >+However, if the size of the gap is not a multiple of the most recent frame >+ size, then the frame size will have to change for at least some frames. >+Such changes SHOULD be delayed as long as possible to simplify >+ things for PLC implementations. >+</t> >+ >+<t> >+As an example, a 95 ms gap could be encoded as nineteen 5 ms frames >+ in two bytes with a single CBR code 3 packet. >+If the previous frame size was 20 ms, using four 20 ms frames >+ followed by three 5 ms frames requires 4 bytes (plus an extra byte >+ of Ogg lacing overhead), but allows the PLC to use its well-tested steady >+ state behavior for as long as possible. >+The total bitrate of the latter approach, including Ogg overhead, is about >+ 0.4 kbps, so the impact on file size is minimal. >+</t> >+ >+<t> >+Changing modes is discouraged, since this causes some decoder implementations >+ to reset their PLC state. >+However, SILK and Hybrid mode frames cannot fill gaps that are not a multiple >+ of 10 ms. >+If switching to CELT mode is needed to match the gap size, a muxer SHOULD do >+ so at the end of the gap to allow the PLC to function for as long as possible. >+</t> >+ >+<t> >+In the example above, if the previous frame was a 20 ms SILK mode frame, >+ the better solution is to synthesize a packet describing four 20 ms SILK >+ frames, followed by a packet with a single 10 ms SILK >+ frame, and finally a packet with a 5 ms CELT frame, to fill the 95 ms >+ gap. >+This also requires four bytes to describe the synthesized packet data (two >+ bytes for a CBR code 3 and one byte each for two code 0 packets) but three >+ bytes of Ogg lacing overhead are needed to mark the packet boundaries. >+At 0.6 kbps, this is still a minimal bitrate impact over a naive, low quality >+ solution. >+</t> >+ >+<t> >+Since medium-band audio is an option only in the SILK mode, wideband frames >+ SHOULD be generated if switching from that configuration to CELT mode, to >+ ensure that any PLC implementation which does try to migrate state between >+ the modes will be able to preserve all of the available audio bandwidth. >+</t> >+ >+</section> >+ >+<section anchor="preskip" title="Pre-skip"> >+<t> >+There is some amount of latency introduced during the decoding process, to >+ allow for overlap in the CELT mode, stereo mixing in the SILK mode, and >+ resampling. >+The encoder might have introduced additional latency through its own resampling >+ and analysis (though the exact amount is not specified). >+Therefore, the first few samples produced by the decoder do not correspond to >+ real input audio, but are instead composed of padding inserted by the encoder >+ to compensate for this latency. >+These samples need to be stored and decoded, as Opus is an asymptotically >+ convergent predictive codec, meaning the decoded contents of each frame depend >+ on the recent history of decoder inputs. >+However, a player will want to skip these samples after decoding them. >+</t> >+ >+<t> >+A 'pre-skip' field in the ID header (see <xref target="id_header"/>) signals >+ the number of samples that SHOULD be skipped (decoded but discarded) at the >+ beginning of the stream, though some specific applications might have a reason >+ for looking at that data. >+This amount need not be a multiple of 2.5 ms, MAY be smaller than a single >+ packet, or MAY span the contents of several packets. >+These samples are not valid audio. >+</t> >+ >+<t> >+For example, if the first Opus frame uses the CELT mode, it will always >+ produce 120 samples of windowed overlap-add data. >+However, the overlap data is initially all zeros (since there is no prior >+ frame), meaning this cannot, in general, accurately represent the original >+ audio. >+The SILK mode requires additional delay to account for its analysis and >+ resampling latency. >+The encoder delays the original audio to avoid this problem. >+</t> >+ >+<t> >+The pre-skip field MAY also be used to perform sample-accurate cropping of >+ already encoded streams. >+In this case, a value of at least 3840 samples (80 ms) provides >+ sufficient history to the decoder that it will have converged >+ before the stream's output begins. >+</t> >+ >+</section> >+ >+<section anchor="pcm_sample_position" title="PCM Sample Position"> >+<t> >+The PCM sample position is determined from the granule position using the >+ formula >+</t> >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+'PCM sample position' = 'granule position' - 'pre-skip' . >+]]></artwork> >+</figure> >+ >+<t> >+For example, if the granule position of the first audio data page is 59,971, >+ and the pre-skip is 11,971, then the PCM sample position of the last decoded >+ sample from that page is 48,000. >+</t> >+<t> >+This can be converted into a playback time using the formula >+</t> >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+ 'PCM sample position' >+'playback time' = --------------------- . >+ 48000.0 >+]]></artwork> >+</figure> >+ >+<t> >+The initial PCM sample position before any samples are played is normally '0'. >+In this case, the PCM sample position of the first audio sample to be played >+ starts at '1', because it marks the time on the clock >+ <spanx style="emph">after</spanx> that sample has been played, and a stream >+ that is exactly one second long has a final PCM sample position of '48000', >+ as in the example here. >+</t> >+ >+<t> >+Vorbis streams use a granule position smaller than the number of audio samples >+ contained in the first audio data page to indicate that some of those samples >+ are trimmed from the output (see <xref target="vorbis-trim"/>). >+However, to do so, Vorbis requires that the first audio data page contains >+ exactly two packets, in order to allow the decoder to perform PCM position >+ adjustments before needing to return any PCM data. >+Opus uses the pre-skip mechanism for this purpose instead, since the encoder >+ might introduce more than a single packet's worth of latency, and since very >+ large packets in streams with a very large number of channels might not fit >+ on a single page. >+</t> >+</section> >+ >+<section anchor="end_trimming" title="End Trimming"> >+<t> >+The page with the 'end of stream' flag set MAY have a granule position that >+ indicates the page contains less audio data than would normally be returned by >+ decoding up through the final packet. >+This is used to end the stream somewhere other than an even frame boundary. >+The granule position of the most recent audio data page with completed packets >+ is used to make this determination, or '0' is used if there were no previous >+ audio data pages with a completed packet. >+The difference between these granule positions indicates how many samples to >+ keep after decoding the packets that completed on the final page. >+The remaining samples are discarded. >+The number of discarded samples SHOULD be no larger than the number decoded >+ from the last packet. >+</t> >+</section> >+ >+<section anchor="start_granpos_restrictions" >+ title="Restrictions on the Initial Granule Position"> >+<t> >+The granule position of the first audio data page with a completed packet MAY >+ be larger than the number of samples contained in packets that complete on >+ that page, however it MUST NOT be smaller, unless that page has the 'end of >+ stream' flag set. >+Allowing a granule position larger than the number of samples allows the >+ beginning of a stream to be cropped or a live stream to be joined without >+ rewriting the granule position of all the remaining pages. >+This means that the PCM sample position just before the first sample to be >+ played MAY be larger than '0'. >+Synchronization when multiplexing with other logical streams still uses the PCM >+ sample position relative to '0' to compute sample times. >+This does not affect the behavior of pre-skip: exactly 'pre-skip' samples >+ SHOULD be skipped from the beginning of the decoded output, even if the >+ initial PCM sample position is greater than zero. >+</t> >+ >+<t> >+On the other hand, a granule position that is smaller than the number of >+ decoded samples prevents a demuxer from working backwards to assign each >+ packet or each individual sample a valid granule position, since granule >+ positions are non-negative. >+An implementation MUST treat any stream as invalid if the granule position >+ is smaller than the number of samples contained in packets that complete on >+ the first audio data page with a completed packet, unless that page has the >+ 'end of stream' flag set. >+It MAY defer this action until it decodes the last packet completed on that >+ page. >+</t> >+ >+<t> >+If that page has the 'end of stream' flag set, a demuxer MUST treat any stream >+ as invalid if its granule position is smaller than the 'pre-skip' amount. >+This would indicate that there are more samples to be skipped from the initial >+ decoded output than exist in the stream. >+If the granule position is smaller than the number of decoded samples produced >+ by the packets that complete on that page, then a demuxer MUST use an initial >+ granule position of '0', and can work forwards from '0' to timestamp >+ individual packets. >+If the granule position is larger than the number of decoded samples available, >+ then the demuxer MUST still work backwards as described above, even if the >+ 'end of stream' flag is set, to determine the initial granule position, and >+ thus the initial PCM sample position. >+Both of these will be greater than '0' in this case. >+</t> >+</section> >+ >+<section anchor="seeking_and_preroll" title="Seeking and Pre-roll"> >+<t> >+Seeking in Ogg files is best performed using a bisection search for a page >+ whose granule position corresponds to a PCM position at or before the seek >+ target. >+With appropriately weighted bisection, accurate seeking can be performed in >+ just one or two bisections on average, even in multi-gigabyte files. >+See <xref target="seeking"/> for an example of general implementation guidance. >+</t> >+ >+<t> >+When seeking within an Ogg Opus stream, an implementation SHOULD start decoding >+ (and discarding the output) at least 3840 samples (80 ms) prior to >+ the seek target in order to ensure that the output audio is correct by the >+ time it reaches the seek target. >+This 'pre-roll' is separate from, and unrelated to, the 'pre-skip' used at the >+ beginning of the stream. >+If the point 80 ms prior to the seek target comes before the initial PCM >+ sample position, an implementation SHOULD start decoding from the beginning of >+ the stream, applying pre-skip as normal, regardless of whether the pre-skip is >+ larger or smaller than 80 ms, and then continue to discard samples >+ to reach the seek target (if any). >+</t> >+</section> >+ >+</section> >+ >+<section anchor="headers" title="Header Packets"> >+<t> >+An Ogg Opus logical stream contains exactly two mandatory header packets: >+ an identification header and a comment header. >+</t> >+ >+<section anchor="id_header" title="Identification Header"> >+ >+<figure anchor="id_header_packet" title="ID Header Packet" align="center"> >+<artwork align="center"><![CDATA[ >+ 0 1 2 3 >+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| 'O' | 'p' | 'u' | 's' | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| 'H' | 'e' | 'a' | 'd' | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| Version = 1 | Channel Count | Pre-skip | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| Input Sample Rate (Hz) | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| Output Gain (Q7.8 in dB) | Mapping Family| | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ : >+| | >+: Optional Channel Mapping Table... : >+| | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+]]></artwork> >+</figure> >+ >+<t> >+The fields in the identification (ID) header have the following meaning: >+<list style="numbers"> >+<t>Magic Signature: >+<vspace blankLines="1"/> >+This is an 8-octet (64-bit) field that allows codec identification and is >+ human-readable. >+It contains, in order, the magic numbers: >+<list style="empty"> >+<t>0x4F 'O'</t> >+<t>0x70 'p'</t> >+<t>0x75 'u'</t> >+<t>0x73 's'</t> >+<t>0x48 'H'</t> >+<t>0x65 'e'</t> >+<t>0x61 'a'</t> >+<t>0x64 'd'</t> >+</list> >+Starting with "Op" helps distinguish it from audio data packets, as this is an >+ invalid TOC sequence. >+<vspace blankLines="1"/> >+</t> >+<t>Version (8 bits, unsigned): >+<vspace blankLines="1"/> >+The version number MUST always be '1' for this version of the encapsulation >+ specification. >+Implementations SHOULD treat streams where the upper four bits of the version >+ number match that of a recognized specification as backwards-compatible with >+ that specification. >+That is, the version number can be split into "major" and "minor" version >+ sub-fields, with changes to the "minor" sub-field (in the lower four bits) >+ signaling compatible changes. >+For example, an implementation of this specification SHOULD accept any stream >+ with a version number of '15' or less, and SHOULD assume any stream with a >+ version number '16' or greater is incompatible. >+The initial version '1' was chosen to keep implementations from relying on this >+ octet as a null terminator for the "OpusHead" string. >+<vspace blankLines="1"/> >+</t> >+<t>Output Channel Count 'C' (8 bits, unsigned): >+<vspace blankLines="1"/> >+This is the number of output channels. >+This might be different than the number of encoded channels, which can change >+ on a packet-by-packet basis. >+This value MUST NOT be zero. >+The maximum allowable value depends on the channel mapping family, and might be >+ as large as 255. >+See <xref target="channel_mapping"/> for details. >+<vspace blankLines="1"/> >+</t> >+<t>Pre-skip (16 bits, unsigned, little >+ endian): >+<vspace blankLines="1"/> >+This is the number of samples (at 48 kHz) to discard from the decoder >+ output when starting playback, and also the number to subtract from a page's >+ granule position to calculate its PCM sample position. >+When cropping the beginning of existing Ogg Opus streams, a pre-skip of at >+ least 3,840 samples (80 ms) is RECOMMENDED to ensure complete >+ convergence in the decoder. >+<vspace blankLines="1"/> >+</t> >+<t>Input Sample Rate (32 bits, unsigned, little >+ endian): >+<vspace blankLines="1"/> >+This is the sample rate of the original input (before encoding), in Hz. >+This field is <spanx style="emph">not</spanx> the sample rate to use for >+ playback of the encoded data. >+<vspace blankLines="1"/> >+Opus can switch between internal audio bandwidths of 4, 6, 8, 12, and >+ 20 kHz. >+Each packet in the stream can have a different audio bandwidth. >+Regardless of the audio bandwidth, the reference decoder supports decoding any >+ stream at a sample rate of 8, 12, 16, 24, or 48 kHz. >+The original sample rate of the audio passed to the encoder is not preserved >+ by the lossy compression. >+<vspace blankLines="1"/> >+An Ogg Opus player SHOULD select the playback sample rate according to the >+ following procedure: >+<list style="numbers"> >+<t>If the hardware supports 48 kHz playback, decode at 48 kHz.</t> >+<t>Otherwise, if the hardware's highest available sample rate is a supported >+ rate, decode at this sample rate.</t> >+<t>Otherwise, if the hardware's highest available sample rate is less than >+ 48 kHz, decode at the next higher Opus supported rate above the highest >+ available hardware rate and resample.</t> >+<t>Otherwise, decode at 48 kHz and resample.</t> >+</list> >+However, the 'Input Sample Rate' field allows the muxer to pass the sample >+ rate of the original input stream as metadata. >+This is useful when the user requires the output sample rate to match the >+ input sample rate. >+For example, when not playing the output, an implementation writing PCM format >+ samples to disk might choose to resample the audio back to the original input >+ sample rate to reduce surprise to the user, who might reasonably expect to get >+ back a file with the same sample rate. >+<vspace blankLines="1"/> >+A value of zero indicates 'unspecified'. >+Muxers SHOULD write the actual input sample rate or zero, but implementations >+ which do something with this field SHOULD take care to behave sanely if given >+ crazy values (e.g., do not actually upsample the output to 10 MHz if >+ requested). >+Implementations SHOULD support input sample rates between 8 kHz and >+ 192 kHz (inclusive). >+Rates outside this range MAY be ignored by falling back to the default rate of >+ 48 kHz instead. >+<vspace blankLines="1"/> >+</t> >+<t>Output Gain (16 bits, signed, little endian): >+<vspace blankLines="1"/> >+This is a gain to be applied when decoding. >+It is 20*log10 of the factor by which to scale the decoder output to achieve >+ the desired playback volume, stored in a 16-bit, signed, two's complement >+ fixed-point value with 8 fractional bits (i.e., >+ Q7.8 <xref target="q-notation"/>). >+<vspace blankLines="1"/> >+To apply the gain, an implementation could use >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+sample *= pow(10, output_gain/(20.0*256)) , >+]]></artwork> >+</figure> >+ where output_gain is the raw 16-bit value from the header. >+<vspace blankLines="1"/> >+Players and media frameworks SHOULD apply it by default. >+If a player chooses to apply any volume adjustment or gain modification, such >+ as the R128_TRACK_GAIN (see <xref target="comment_header"/>), the adjustment >+ MUST be applied in addition to this output gain in order to achieve playback >+ at the normalized volume. >+<vspace blankLines="1"/> >+A muxer SHOULD set this field to zero, and instead apply any gain prior to >+ encoding, when this is possible and does not conflict with the user's wishes. >+A nonzero output gain indicates the gain was adjusted after encoding, or that >+ a user wished to adjust the gain for playback while preserving the ability >+ to recover the original signal amplitude. >+<vspace blankLines="1"/> >+Although the output gain has enormous range (+/- 128 dB, enough to amplify >+ inaudible sounds to the threshold of physical pain), most applications can >+ only reasonably use a small portion of this range around zero. >+The large range serves in part to ensure that gain can always be losslessly >+ transferred between OpusHead and R128 gain tags (see below) without >+ saturating. >+<vspace blankLines="1"/> >+</t> >+<t>Channel Mapping Family (8 bits, unsigned): >+<vspace blankLines="1"/> >+This octet indicates the order and semantic meaning of the output channels. >+<vspace blankLines="1"/> >+Each currently specified value of this octet indicates a mapping family, which >+ defines a set of allowed channel counts, and the ordered set of channel names >+ for each allowed channel count. >+The details are described in <xref target="channel_mapping"/>. >+</t> >+<t>Channel Mapping Table: >+This table defines the mapping from encoded streams to output channels. >+Its contents are specified in <xref target="channel_mapping"/>. >+</t> >+</list> >+</t> >+ >+<t> >+All fields in the ID headers are REQUIRED, except for the channel mapping >+ table, which MUST be omitted when the channel mapping family is 0, but >+ is REQUIRED otherwise. >+Implementations SHOULD treat a stream as invalid if it contains an ID header >+ that does not have enough data for these fields, even if it contain a valid >+ Magic Signature. >+Future versions of this specification, even backwards-compatible versions, >+ might include additional fields in the ID header. >+If an ID header has a compatible major version, but a larger minor version, >+ an implementation MUST NOT treat it as invalid for containing additional data >+ not specified here, provided it still completes on the first page. >+</t> >+ >+<section anchor="channel_mapping" title="Channel Mapping"> >+<t> >+An Ogg Opus stream allows mapping one number of Opus streams (N) to a possibly >+ larger number of decoded channels (M + N) to yet another number of >+ output channels (C), which might be larger or smaller than the number of >+ decoded channels. >+The order and meaning of these channels are defined by a channel mapping, >+ which consists of the 'channel mapping family' octet and, for channel mapping >+ families other than family 0, a channel mapping table, as illustrated in >+ <xref target="channel_mapping_table"/>. >+</t> >+ >+<figure anchor="channel_mapping_table" title="Channel Mapping Table" >+ align="center"> >+<artwork align="center"><![CDATA[ >+ 0 1 2 3 >+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 >+ +-+-+-+-+-+-+-+-+ >+ | Stream Count | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| Coupled Count | Channel Mapping... : >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+]]></artwork> >+</figure> >+ >+<t> >+The fields in the channel mapping table have the following meaning: >+<list style="numbers" counter="8"> >+<t>Stream Count 'N' (8 bits, unsigned): >+<vspace blankLines="1"/> >+This is the total number of streams encoded in each Ogg packet. >+This value is necessary to correctly parse the packed Opus packets inside an >+ Ogg packet, as described in <xref target="packet_organization"/>. >+This value MUST NOT be zero, as without at least one Opus packet with a valid >+ TOC sequence, a demuxer cannot recover the duration of an Ogg packet. >+<vspace blankLines="1"/> >+For channel mapping family 0, this value defaults to 1, and is not coded. >+<vspace blankLines="1"/> >+</t> >+<t>Coupled Stream Count 'M' (8 bits, unsigned): >+This is the number of streams whose decoders are to be configured to produce >+ two channels (stereo). >+This MUST be no larger than the total number of streams, N. >+<vspace blankLines="1"/> >+Each packet in an Opus stream has an internal channel count of 1 or 2, which >+ can change from packet to packet. >+This is selected by the encoder depending on the bitrate and the audio being >+ encoded. >+The original channel count of the audio passed to the encoder is not >+ necessarily preserved by the lossy compression. >+<vspace blankLines="1"/> >+Regardless of the internal channel count, any Opus stream can be decoded as >+ mono (a single channel) or stereo (two channels) by appropriate initialization >+ of the decoder. >+The 'coupled stream count' field indicates that the decoders for the first M >+ Opus streams are to be initialized for stereo (two-channel) output, and the >+ remaining (N - M) decoders are to be initialized for mono (a single >+ channel) only. >+The total number of decoded channels, (M + N), MUST be no larger than >+ 255, as there is no way to index more channels than that in the channel >+ mapping. >+<vspace blankLines="1"/> >+For channel mapping family 0, this value defaults to (C - 1) >+ (i.e., 0 for mono and 1 for stereo), and is not coded. >+<vspace blankLines="1"/> >+</t> >+<t>Channel Mapping (8*C bits): >+This contains one octet per output channel, indicating which decoded channel >+ is to be used for each one. >+Let 'index' be the value of this octet for a particular output channel. >+This value MUST either be smaller than (M + N), or be the special >+ value 255. >+If 'index' is less than 2*M, the output MUST be taken from decoding stream >+ ('index'/2) as stereo and selecting the left channel if 'index' is even, and >+ the right channel if 'index' is odd. >+If 'index' is 2*M or larger, but less than 255, the output MUST be taken from >+ decoding stream ('index' - M) as mono. >+If 'index' is 255, the corresponding output channel MUST contain pure silence. >+<vspace blankLines="1"/> >+The number of output channels, C, is not constrained to match the number of >+ decoded channels (M + N). >+A single index value MAY appear multiple times, i.e., the same decoded channel >+ might be mapped to multiple output channels. >+Some decoded channels might not be assigned to any output channel, as well. >+<vspace blankLines="1"/> >+For channel mapping family 0, the first index defaults to 0, and if >+ C == 2, the second index defaults to 1. >+Neither index is coded. >+</t> >+</list> >+</t> >+ >+<t> >+After producing the output channels, the channel mapping family determines the >+ semantic meaning of each one. >+There are three defined mapping families in this specification. >+</t> >+ >+<section anchor="channel_mapping_0" title="Channel Mapping Family 0"> >+<t> >+Allowed numbers of channels: 1 or 2. >+RTP mapping. >+This is the same channel interpretation as <xref target="RFC7587"/>. >+</t> >+<t> >+<list style="symbols"> >+<t>1 channel: monophonic (mono).</t> >+<t>2 channels: stereo (left, right).</t> >+</list> >+Special mapping: This channel mapping value also >+ indicates that the contents consists of a single Opus stream that is stereo if >+ and only if C == 2, with stream index 0 mapped to output >+ channel 0 (mono, or left channel) and stream index 1 mapped to >+ output channel 1 (right channel) if stereo. >+When the 'channel mapping family' octet has this value, the channel mapping >+ table MUST be omitted from the ID header packet. >+</t> >+</section> >+ >+<section anchor="channel_mapping_1" title="Channel Mapping Family 1"> >+<t> >+Allowed numbers of channels: 1...8. >+Vorbis channel order (see below). >+</t> >+<t> >+Each channel is assigned to a speaker location in a conventional surround >+ arrangement. >+Specific locations depend on the number of channels, and are given below >+ in order of the corresponding channel indices. >+<list style="symbols"> >+ <t>1 channel: monophonic (mono).</t> >+ <t>2 channels: stereo (left, right).</t> >+ <t>3 channels: linear surround (left, center, right)</t> >+ <t>4 channels: quadraphonic (front left, front right, rear left, rear right).</t> >+ <t>5 channels: 5.0 surround (front left, front center, front right, rear left, rear right).</t> >+ <t>6 channels: 5.1 surround (front left, front center, front right, rear left, rear right, LFE).</t> >+ <t>7 channels: 6.1 surround (front left, front center, front right, side left, side right, rear center, LFE).</t> >+ <t>8 channels: 7.1 surround (front left, front center, front right, side left, side right, rear left, rear right, LFE)</t> >+</list> >+</t> >+<t> >+This set of surround options and speaker location orderings is the same >+ as those used by the Vorbis codec <xref target="vorbis-mapping"/>. >+The ordering is different from the one used by the >+ WAVE <xref target="wave-multichannel"/> and >+ Free Lossless Audio Codec (FLAC) <xref target="flac"/> formats, >+ so correct ordering requires permutation of the output channels when decoding >+ to or encoding from those formats. >+'LFE' here refers to a Low Frequency Effects channel, often mapped to a >+ subwoofer with no particular spatial position. >+Implementations SHOULD identify 'side' or 'rear' speaker locations with >+ 'surround' and 'back' as appropriate when interfacing with audio formats >+ or systems which prefer that terminology. >+</t> >+</section> >+ >+<section anchor="channel_mapping_255" >+ title="Channel Mapping Family 255"> >+<t> >+Allowed numbers of channels: 1...255. >+No defined channel meaning. >+</t> >+<t> >+Channels are unidentified. >+General-purpose players SHOULD NOT attempt to play these streams. >+Offline implementations MAY deinterleave the output into separate PCM files, >+ one per channel. >+Implementations SHOULD NOT produce output for channels mapped to stream index >+ 255 (pure silence) unless they have no other way to indicate the index of >+ non-silent channels. >+</t> >+</section> >+ >+<section anchor="channel_mapping_undefined" >+ title="Undefined Channel Mappings"> >+<t> >+The remaining channel mapping families (2...254) are reserved. >+A demuxer implementation encountering a reserved channel mapping family value >+ SHOULD act as though the value is 255. >+</t> >+</section> >+ >+<section anchor="downmix" title="Downmixing"> >+<t> >+An Ogg Opus player MUST support any valid channel mapping with a channel >+ mapping family of 0 or 1, even if the number of channels does not match the >+ physically connected audio hardware. >+Players SHOULD perform channel mixing to increase or reduce the number of >+ channels as needed. >+</t> >+ >+<t> >+Implementations MAY use the matrices in >+ Figures <xref target="downmix-matrix-3" format="counter"/> >+ through <xref target="downmix-matrix-8" format="counter"/> to implement >+ downmixing from multichannel files using >+ <xref target="channel_mapping_1">Channel Mapping Family 1</xref>, which are >+ known to give acceptable results for stereo. >+Matrices for 3 and 4 channels are normalized so each coefficient row sums >+ to 1 to avoid clipping. >+For 5 or more channels they are normalized to 2 as a compromise between >+ clipping and dynamic range reduction. >+</t> >+<t> >+In these matrices the front left and front right channels are generally >+passed through directly. >+When a surround channel is split between both the left and right stereo >+ channels, coefficients are chosen so their squares sum to 1, which >+ helps preserve the perceived intensity. >+Rear channels are mixed more diffusely or attenuated to maintain focus >+ on the front channels. >+</t> >+ >+<figure anchor="downmix-matrix-3" >+ title="Stereo downmix matrix for the linear surround channel mapping" >+ align="center"> >+<artwork align="center"><![CDATA[ >+L output = ( 0.585786 * left + 0.414214 * center ) >+R output = ( 0.414214 * center + 0.585786 * right ) >+]]></artwork> >+<postamble> >+Exact coefficient values are 1 and 1/sqrt(2), multiplied by >+ 1/(1 + 1/sqrt(2)) for normalization. >+</postamble> >+</figure> >+ >+<figure anchor="downmix-matrix-4" >+ title="Stereo downmix matrix for the quadraphonic channel mapping" >+ align="center"> >+<artwork align="center"><![CDATA[ >+/ \ / \ / FL \ >+| L output | | 0.422650 0.000000 0.366025 0.211325 | | FR | >+| R output | = | 0.000000 0.422650 0.211325 0.366025 | | RL | >+\ / \ / \ RR / >+]]></artwork> >+<postamble> >+Exact coefficient values are 1, sqrt(3)/2 and 1/2, multiplied by >+ 1/(1 + sqrt(3)/2 + 1/2) for normalization. >+</postamble> >+</figure> >+ >+<figure anchor="downmix-matrix-5" >+ title="Stereo downmix matrix for the 5.0 surround mapping" >+ align="center"> >+<artwork align="center"><![CDATA[ >+ / FL \ >+/ \ / \ | FC | >+| L | | 0.650802 0.460186 0.000000 0.563611 0.325401 | | FR | >+| R | = | 0.000000 0.460186 0.650802 0.325401 0.563611 | | RL | >+\ / \ / | RR | >+ \ / >+]]></artwork> >+<postamble> >+Exact coefficient values are 1, 1/sqrt(2), sqrt(3)/2 and 1/2, multiplied by >+ 2/(1 + 1/sqrt(2) + sqrt(3)/2 + 1/2) >+ for normalization. >+</postamble> >+</figure> >+ >+<figure anchor="downmix-matrix-6" >+ title="Stereo downmix matrix for the 5.1 surround mapping" >+ align="center"> >+<artwork align="center"><![CDATA[ >+ /FL \ >+/ \ / \ |FC | >+|L| | 0.529067 0.374107 0.000000 0.458186 0.264534 0.374107 | |FR | >+|R| = | 0.000000 0.374107 0.529067 0.264534 0.458186 0.374107 | |RL | >+\ / \ / |RR | >+ \LFE/ >+]]></artwork> >+<postamble> >+Exact coefficient values are 1, 1/sqrt(2), sqrt(3)/2 and 1/2, multiplied by >+2/(1 + 1/sqrt(2) + sqrt(3)/2 + 1/2 + 1/sqrt(2)) >+ for normalization. >+</postamble> >+</figure> >+ >+<figure anchor="downmix-matrix-7" >+ title="Stereo downmix matrix for the 6.1 surround mapping" >+ align="center"> >+<artwork align="center"><![CDATA[ >+ / \ >+ | 0.455310 0.321953 0.000000 0.394310 0.227655 0.278819 0.321953 | >+ | 0.000000 0.321953 0.455310 0.227655 0.394310 0.278819 0.321953 | >+ \ / >+]]></artwork> >+<postamble> >+Exact coefficient values are 1, 1/sqrt(2), sqrt(3)/2, 1/2 and >+ sqrt(3)/2/sqrt(2), multiplied by >+ 2/(1 + 1/sqrt(2) + sqrt(3)/2 + 1/2 + >+ sqrt(3)/2/sqrt(2) + 1/sqrt(2)) for normalization. >+The coefficients are in the same order as in <xref target="channel_mapping_1" />, >+ and the matrices above. >+</postamble> >+</figure> >+ >+<figure anchor="downmix-matrix-8" >+ title="Stereo downmix matrix for the 7.1 surround mapping" >+ align="center"> >+<artwork align="center"><![CDATA[ >+/ \ >+| .388631 .274804 .000000 .336565 .194316 .336565 .194316 .274804 | >+| .000000 .274804 .388631 .194316 .336565 .194316 .336565 .274804 | >+\ / >+]]></artwork> >+<postamble> >+Exact coefficient values are 1, 1/sqrt(2), sqrt(3)/2 and 1/2, multiplied by >+ 2/(2 + 2/sqrt(2) + sqrt(3)) for normalization. >+The coefficients are in the same order as in <xref target="channel_mapping_1" />, >+ and the matrices above. >+</postamble> >+</figure> >+ >+</section> >+ >+</section> <!-- end channel_mapping_table --> >+ >+</section> <!-- end id_header --> >+ >+<section anchor="comment_header" title="Comment Header"> >+ >+<figure anchor="comment_header_packet" title="Comment Header Packet" >+ align="center"> >+<artwork align="center"><![CDATA[ >+ 0 1 2 3 >+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| 'O' | 'p' | 'u' | 's' | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| 'T' | 'a' | 'g' | 's' | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| Vendor String Length | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| | >+: Vendor String... : >+| | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| User Comment List Length | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| User Comment #0 String Length | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| | >+: User Comment #0 String... : >+| | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| User Comment #1 String Length | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+: : >+]]></artwork> >+</figure> >+ >+<t> >+The comment header consists of a 64-bit magic signature, followed by data in >+ the same format as the <xref target="vorbis-comment"/> header used in Ogg >+ Vorbis, except (like Ogg Theora and Speex) the final "framing bit" specified >+ in the Vorbis spec is not present. >+<list style="numbers"> >+<t>Magic Signature: >+<vspace blankLines="1"/> >+This is an 8-octet (64-bit) field that allows codec identification and is >+ human-readable. >+It contains, in order, the magic numbers: >+<list style="empty"> >+<t>0x4F 'O'</t> >+<t>0x70 'p'</t> >+<t>0x75 'u'</t> >+<t>0x73 's'</t> >+<t>0x54 'T'</t> >+<t>0x61 'a'</t> >+<t>0x67 'g'</t> >+<t>0x73 's'</t> >+</list> >+Starting with "Op" helps distinguish it from audio data packets, as this is an >+ invalid TOC sequence. >+<vspace blankLines="1"/> >+</t> >+<t>Vendor String Length (32 bits, unsigned, little endian): >+<vspace blankLines="1"/> >+This field gives the length of the following vendor string, in octets. >+It MUST NOT indicate that the vendor string is longer than the rest of the >+ packet. >+<vspace blankLines="1"/> >+</t> >+<t>Vendor String (variable length, UTF-8 vector): >+<vspace blankLines="1"/> >+This is a simple human-readable tag for vendor information, encoded as a UTF-8 >+ string <xref target="RFC3629"/>. >+No terminating null octet is necessary. >+<vspace blankLines="1"/> >+This tag is intended to identify the codec encoder and encapsulation >+ implementations, for tracing differences in technical behavior. >+User-facing applications can use the 'ENCODER' user comment tag to identify >+ themselves. >+<vspace blankLines="1"/> >+</t> >+<t>User Comment List Length (32 bits, unsigned, little endian): >+<vspace blankLines="1"/> >+This field indicates the number of user-supplied comments. >+It MAY indicate there are zero user-supplied comments, in which case there are >+ no additional fields in the packet. >+It MUST NOT indicate that there are so many comments that the comment string >+ lengths would require more data than is available in the rest of the packet. >+<vspace blankLines="1"/> >+</t> >+<t>User Comment #i String Length (32 bits, unsigned, little endian): >+<vspace blankLines="1"/> >+This field gives the length of the following user comment string, in octets. >+There is one for each user comment indicated by the 'user comment list length' >+ field. >+It MUST NOT indicate that the string is longer than the rest of the packet. >+<vspace blankLines="1"/> >+</t> >+<t>User Comment #i String (variable length, UTF-8 vector): >+<vspace blankLines="1"/> >+This field contains a single user comment encoded as a UTF-8 >+ string <xref target="RFC3629"/>. >+There is one for each user comment indicated by the 'user comment list length' >+ field. >+</t> >+</list> >+</t> >+ >+<t> >+The vendor string length and user comment list length are REQUIRED, and >+ implementations SHOULD treat a stream as invalid if it contains a comment >+ header that does not have enough data for these fields, or that does not >+ contain enough data for the corresponding vendor string or user comments they >+ describe. >+Making this check before allocating the associated memory to contain the data >+ helps prevent a possible Denial-of-Service (DoS) attack from small comment >+ headers that claim to contain strings longer than the entire packet or more >+ user comments than than could possibly fit in the packet. >+</t> >+ >+<t> >+Immediately following the user comment list, the comment header MAY >+ contain zero-padding or other binary data which is not specified here. >+If the least-significant bit of the first byte of this data is 1, then editors >+ SHOULD preserve the contents of this data when updating the tags, but if this >+ bit is 0, all such data MAY be treated as padding, and truncated or discarded >+ as desired. >+This allows informal experimentation with the format of this binary data until >+ it can be specified later. >+</t> >+ >+<t> >+The comment header can be arbitrarily large and might be spread over a large >+ number of Ogg pages. >+Implementations MUST avoid attempting to allocate excessive amounts of memory >+ when presented with a very large comment header. >+To accomplish this, implementations MAY treat a stream as invalid if it has a >+ comment header larger than 125,829,120 octets (120 MB), and MAY >+ ignore individual comments that are not fully contained within the first >+ 61,440 octets of the comment header. >+</t> >+ >+<section anchor="comment_format" title="Tag Definitions"> >+<t> >+The user comment strings follow the NAME=value format described by >+ <xref target="vorbis-comment"/> with the same recommended tag names: >+ ARTIST, TITLE, DATE, ALBUM, and so on. >+</t> >+<t> >+Two new comment tags are introduced here: >+</t> >+ >+<t>First, an optional gain for track normalization:</t> >+<figure align="center"> >+<artwork align="left"><![CDATA[ >+R128_TRACK_GAIN=-573 >+]]></artwork> >+</figure> >+<t> >+ representing the volume shift needed to normalize the track's volume >+ during isolated playback, in random shuffle, and so on. >+The gain is a Q7.8 fixed point number in dB, as in the ID header's 'output >+ gain' field. >+This tag is similar to the REPLAYGAIN_TRACK_GAIN tag in >+ Vorbis <xref target="replay-gain"/>, except that the normal volume >+ reference is the <xref target="EBU-R128"/> standard. >+</t> >+<t>Second, an optional gain for album normalization:</t> >+<figure align="center"> >+<artwork align="left"><![CDATA[ >+R128_ALBUM_GAIN=111 >+]]></artwork> >+</figure> >+<t> >+ representing the volume shift needed to normalize the overall volume when >+ played as part of a particular collection of tracks. >+The gain is also a Q7.8 fixed point number in dB, as in the ID header's >+ 'output gain' field. >+The values '-573' and '111' given here are just examples. >+</t> >+<t> >+An Ogg Opus stream MUST NOT have more than one of each of these tags, and if >+ present their values MUST be an integer from -32768 to 32767, inclusive, >+ represented in ASCII as a base 10 number with no whitespace. >+A leading '+' or '-' character is valid. >+Leading zeros are also permitted, but the value MUST be represented by >+ no more than 6 characters. >+Other non-digit characters MUST NOT be present. >+</t> >+<t> >+If present, R128_TRACK_GAIN and R128_ALBUM_GAIN MUST correctly represent >+ the R128 normalization gain relative to the 'output gain' field specified >+ in the ID header. >+If a player chooses to make use of the R128_TRACK_GAIN tag or the >+ R128_ALBUM_GAIN tag, it MUST apply those gains >+ <spanx style="emph">in addition</spanx> to the 'output gain' value. >+If a tool modifies the ID header's 'output gain' field, it MUST also update or >+ remove the R128_TRACK_GAIN and R128_ALBUM_GAIN comment tags if present. >+A muxer SHOULD place the gain it wants other tools to use by default into the >+ 'output gain' field, and not the comment tag. >+</t> >+<t> >+To avoid confusion with multiple normalization schemes, an Opus comment header >+ SHOULD NOT contain any of the REPLAYGAIN_TRACK_GAIN, REPLAYGAIN_TRACK_PEAK, >+ REPLAYGAIN_ALBUM_GAIN, or REPLAYGAIN_ALBUM_PEAK tags, unless they are only >+ to be used in some context where there is guaranteed to be no such confusion. >+<xref target="EBU-R128"/> normalization is preferred to the earlier >+ REPLAYGAIN schemes because of its clear definition and adoption by industry. >+Peak normalizations are difficult to calculate reliably for lossy codecs >+ because of variation in excursion heights due to decoder differences. >+In the authors' investigations they were not applied consistently or broadly >+ enough to merit inclusion here. >+</t> >+</section> <!-- end comment_format --> >+</section> <!-- end comment_header --> >+ >+</section> <!-- end headers --> >+ >+<section anchor="packet_size_limits" title="Packet Size Limits"> >+<t> >+Technically, valid Opus packets can be arbitrarily large due to the padding >+ format, although the amount of non-padding data they can contain is bounded. >+These packets might be spread over a similarly enormous number of Ogg pages. >+When encoding, implementations SHOULD limit the use of padding in audio data >+ packets to no more than is necessary to make a variable bitrate (VBR) stream >+ constant bitrate (CBR), unless they have no reasonable way to determine what >+ is necessary. >+Demuxers SHOULD treat audio data packets as invalid (treat them as if they were >+ malformed Opus packets with an invalid TOC sequence) if they are larger than >+ 61,440 octets per Opus stream, unless they have a specific reason for >+ allowing extra padding. >+Such packets necessarily contain more padding than needed to make a stream CBR. >+Demuxers MUST avoid attempting to allocate excessive amounts of memory when >+ presented with a very large packet. >+Demuxers MAY treat audio data packets as invalid or partially process them if >+ they are larger than 61,440 octets in an Ogg Opus stream with channel >+ mapping families 0 or 1. >+Demuxers MAY treat audio data packets as invalid or partially process them in >+ any Ogg Opus stream if the packet is larger than 61,440 octets and also >+ larger than 7,680 octets per Opus stream. >+The presence of an extremely large packet in the stream could indicate a >+ memory exhaustion attack or stream corruption. >+</t> >+<t> >+In an Ogg Opus stream, the largest possible valid packet that does not use >+ padding has a size of (61,298*N - 2) octets. >+With 255 streams, this is 15,630,988 octets and can >+ span up to 61,298 Ogg pages, all but one of which will have a granule >+ position of -1. >+This is of course a very extreme packet, consisting of 255 streams, each >+ containing 120 ms of audio encoded as 2.5 ms frames, each frame >+ using the maximum possible number of octets (1275) and stored in the least >+ efficient manner allowed (a VBR code 3 Opus packet). >+Even in such a packet, most of the data will be zeros as 2.5 ms frames >+ cannot actually use all 1275 octets. >+</t> >+<t> >+The largest packet consisting of entirely useful data is >+ (15,326*N - 2) octets. >+This corresponds to 120 ms of audio encoded as 10 ms frames in either >+ SILK or Hybrid mode, but at a data rate of over 1 Mbps, which makes little >+ sense for the quality achieved. >+</t> >+<t> >+A more reasonable limit is (7,664*N - 2) octets. >+This corresponds to 120 ms of audio encoded as 20 ms stereo CELT mode >+ frames, with a total bitrate just under 511 kbps (not counting the Ogg >+ encapsulation overhead). >+For channel mapping family 1, N=8 provides a reasonable upper bound, as it >+ allows for each of the 8 possible output channels to be decoded from a >+ separate stereo Opus stream. >+This gives a size of 61,310 octets, which is rounded up to a multiple of >+ 1,024 octets to yield the audio data packet size of 61,440 octets >+ that any implementation is expected to be able to process successfully. >+</t> >+</section> >+ >+<section anchor="encoder" title="Encoder Guidelines"> >+<t> >+When encoding Opus streams, Ogg muxers SHOULD take into account the >+ algorithmic delay of the Opus encoder. >+</t> >+<t> >+In encoders derived from the reference >+ implementation <xref target="RFC6716"/>, the number of samples can be >+ queried with: >+</t> >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+ opus_encoder_ctl(encoder_state, OPUS_GET_LOOKAHEAD(&delay_samples)); >+]]></artwork> >+</figure> >+<t> >+To achieve good quality in the very first samples of a stream, implementations >+ MAY use linear predictive coding (LPC) extrapolation to generate at least 120 >+ extra samples at the beginning to avoid the Opus encoder having to encode a >+ discontinuous signal. >+For more information on linear prediction, see >+ <xref target="linear-prediction"/>. >+For an input file containing 'length' samples, the implementation SHOULD set >+ the pre-skip header value to (delay_samples + extra_samples), encode >+ at least (length + delay_samples + extra_samples) >+ samples, and set the granule position of the last page to >+ (length + delay_samples + extra_samples). >+This ensures that the encoded file has the same duration as the original, with >+ no time offset. The best way to pad the end of the stream is to also use LPC >+ extrapolation, but zero-padding is also acceptable. >+</t> >+ >+<section anchor="lpc" title="LPC Extrapolation"> >+<t> >+The first step in LPC extrapolation is to compute linear prediction >+ coefficients. <xref target="lpc-sample"/> >+When extending the end of the signal, order-N (typically with N ranging from 8 >+ to 40) LPC analysis is performed on a window near the end of the signal. >+The last N samples are used as memory to an infinite impulse response (IIR) >+ filter. >+</t> >+<t> >+The filter is then applied on a zero input to extrapolate the end of the signal. >+Let a(k) be the kth LPC coefficient and x(n) be the nth sample of the signal, >+ each new sample past the end of the signal is computed as: >+</t> >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+ N >+ --- >+x(n) = \ a(k)*x(n-k) >+ / >+ --- >+ k=1 >+]]></artwork> >+</figure> >+<t> >+The process is repeated independently for each channel. >+It is possible to extend the beginning of the signal by applying the same >+ process backward in time. >+When extending the beginning of the signal, it is best to apply a "fade in" to >+ the extrapolated signal, e.g. by multiplying it by a half-Hanning window >+ <xref target="hanning"/>. >+</t> >+ >+</section> >+ >+<section anchor="continuous_chaining" title="Continuous Chaining"> >+<t> >+In some applications, such as Internet radio, it is desirable to cut a long >+ stream into smaller chains, e.g. so the comment header can be updated. >+This can be done simply by separating the input streams into segments and >+ encoding each segment independently. >+The drawback of this approach is that it creates a small discontinuity >+ at the boundary due to the lossy nature of Opus. >+A muxer MAY avoid this discontinuity by using the following procedure: >+<list style="numbers"> >+<t>Encode the last frame of the first segment as an independent frame by >+ turning off all forms of inter-frame prediction. >+De-emphasis is allowed.</t> >+<t>Set the granule position of the last page to a point near the end of the >+ last frame.</t> >+<t>Begin the second segment with a copy of the last frame of the first >+ segment.</t> >+<t>Set the pre-skip value of the second stream in such a way as to properly >+ join the two streams.</t> >+<t>Continue the encoding process normally from there, without any reset to >+ the encoder.</t> >+</list> >+</t> >+<t> >+In encoders derived from the reference implementation, inter-frame prediction >+ can be turned off by calling: >+</t> >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+ opus_encoder_ctl(encoder_state, OPUS_SET_PREDICTION_DISABLED(1)); >+]]></artwork> >+</figure> >+<t> >+For best results, this implementation requires that prediction be explicitly >+ enabled again before resuming normal encoding, even after a reset. >+</t> >+ >+</section> >+ >+</section> >+ >+<section anchor="implementation" title="Implementation Status"> >+<t> >+A brief summary of major implementations of this draft is available >+ at <eref target="https://wiki.xiph.org/OggOpusImplementation"/>, >+ along with their status. >+</t> >+<t> >+[Note to RFC Editor: please remove this entire section before >+ final publication per <xref target="RFC6982"/>, along with >+ its references.] >+</t> >+</section> >+ >+<section anchor="security" title="Security Considerations"> >+<t> >+Implementations of the Opus codec need to take appropriate security >+ considerations into account, as outlined in <xref target="RFC4732"/>. >+This is just as much a problem for the container as it is for the codec itself. >+Malicious payloads and/or input streams can be used to attack codec >+ implementations. >+Implementations MUST NOT overrun their allocated memory nor consume excessive >+ resources when decoding payloads or processing input streams. >+Although problems in encoding applications are typically rarer, this still >+ applies to a muxer, as vulnerabilities would allow an attacker to attack >+ transcoding gateways. >+</t> >+ >+<t> >+Header parsing code contains the most likely area for potential overruns. >+It is important for implementations to ensure their buffers contain enough >+ data for all of the required fields before attempting to read it (for example, >+ for all of the channel map data in the ID header). >+Implementations would do well to validate the indices of the channel map, also, >+ to ensure they meet all of the restrictions outlined in >+ <xref target="channel_mapping"/>, in order to avoid attempting to read data >+ from channels that do not exist. >+</t> >+ >+<t> >+To avoid excessive resource usage, we advise implementations to be especially >+ wary of streams that might cause them to process far more data than was >+ actually transmitted. >+For example, a relatively small comment header may contain values for the >+ string lengths or user comment list length that imply that it is many >+ gigabytes in size. >+Even computing the size of the required buffer could overflow a 32-bit integer, >+ and actually attempting to allocate such a buffer before verifying it would be >+ a reasonable size is a bad idea. >+After reading the user comment list length, implementations might wish to >+ verify that the header contains at least the minimum amount of data for that >+ many comments (4 additional octets per comment, to indicate each has a >+ length of zero) before proceeding any further, again taking care to avoid >+ overflow in these calculations. >+If allocating an array of pointers to point at these strings, the size of the >+ pointers may be larger than 4 octets, potentially requiring a separate >+ overflow check. >+</t> >+ >+<t> >+Another bug in this class we have observed more than once involves the handling >+ of invalid data at the end of a stream. >+Often, implementations will seek to the end of a stream to locate the last >+ timestamp in order to compute its total duration. >+If they do not find a valid capture pattern and Ogg page from the desired >+ logical stream, they will back up and try again. >+If care is not taken to avoid re-scanning data that was already scanned, this >+ search can quickly devolve into something with a complexity that is quadratic >+ in the amount of invalid data. >+</t> >+ >+<t> >+In general when seeking, implementations will wish to be cautious about the >+ effects of invalid granule position values, and ensure all algorithms will >+ continue to make progress and eventually terminate, even if these are missing >+ or out-of-order. >+</t> >+ >+<t> >+Like most other container formats, Ogg Opus streams SHOULD NOT be used with >+ insecure ciphers or cipher modes that are vulnerable to known-plaintext >+ attacks. >+Elements such as the Ogg page capture pattern and the magic signatures in the >+ ID header and the comment header all have easily predictable values, in >+ addition to various elements of the codec data itself. >+</t> >+</section> >+ >+<section anchor="content_type" title="Content Type"> >+<t> >+An "Ogg Opus file" consists of one or more sequentially multiplexed segments, >+ each containing exactly one Ogg Opus stream. >+The RECOMMENDED mime-type for Ogg Opus files is "audio/ogg". >+</t> >+ >+<t> >+If more specificity is desired, one MAY indicate the presence of Opus streams >+ using the codecs parameter defined in <xref target="RFC6381"/> and >+ <xref target="RFC5334"/>, e.g., >+</t> >+<figure> >+<artwork align="center"><![CDATA[ >+ audio/ogg; codecs=opus >+]]></artwork> >+</figure> >+<t> >+ for an Ogg Opus file. >+</t> >+ >+<t> >+The RECOMMENDED filename extension for Ogg Opus files is '.opus'. >+</t> >+ >+<t> >+When Opus is concurrently multiplexed with other streams in an Ogg container, >+ one SHOULD use one of the "audio/ogg", "video/ogg", or "application/ogg" >+ mime-types, as defined in <xref target="RFC5334"/>. >+Such streams are not strictly "Ogg Opus files" as described above, >+ since they contain more than a single Opus stream per sequentially >+ multiplexed segment, e.g. video or multiple audio tracks. >+In such cases the the '.opus' filename extension is NOT RECOMMENDED. >+</t> >+ >+<t> >+In either case, this document updates <xref target="RFC5334"/> >+ to add 'opus' as a codecs parameter value with char[8]: 'OpusHead' >+ as Codec Identifier. >+</t> >+</section> >+ >+<section anchor="iana" title="IANA Considerations"> >+<t> >+This document updates the IANA Media Types registry to add .opus >+ as a file extension for "audio/ogg", and to add itself as a reference >+ alongside <xref target="RFC5334"/> for "audio/ogg", "video/ogg", and >+ "application/ogg" Media Types. >+</t> >+<t> >+This document defines a new registry "Opus Channel Mapping Families" to >+ indicate how the semantic meanings of the channels in a multi-channel Opus >+ stream are described. >+IANA is requested to create a new name space of "Opus Channel Mapping >+ Families". >+This will be a new registry on the IANA Matrix, and not a subregistry of an >+ existing registry. >+Modifications to this registry follow the "Specification Required" registration >+ policy as defined in <xref target="RFC5226"/>. >+Each registry entry consists of a Channel Mapping Family Number, which is >+ specified in decimal in the range 0 to 255, inclusive, and a Reference (or >+ list of references) >+Each Reference must point to sufficient documentation to describe what >+ information is coded in the Opus identification header for this channel >+ mapping family, how a demuxer determines the Stream Count ('N') and Coupled >+ Stream Count ('M') from this information, and how it determines the proper >+ interpretation of each of the decoded channels. >+</t> >+<t> >+This document defines three initial assignments for this registry. >+</t> >+<texttable> >+<ttcol>Value</ttcol><ttcol>Reference</ttcol> >+<c>0</c><c>[RFCXXXX] <xref target="channel_mapping_0"/></c> >+<c>1</c><c>[RFCXXXX] <xref target="channel_mapping_1"/></c> >+<c>255</c><c>[RFCXXXX] <xref target="channel_mapping_255"/></c> >+</texttable> >+<t> >+The designated expert will determine if the Reference points to a specification >+ that meets the requirements for permanence and ready availability laid out >+ in <xref target="RFC5226"/> and that it specifies the information >+ described above with sufficient clarity to allow interoperable >+ implementations. >+</t> >+</section> >+ >+<section anchor="Acknowledgments" title="Acknowledgments"> >+<t> >+Thanks to Ben Campbell, Joel M. Halpern, Mark Harris, Greg Maxwell, >+ Christopher "Monty" Montgomery, Jean-Marc Valin, Stephan Wenger, and Mo Zanaty >+ for their valuable contributions to this document. >+Additional thanks to Andrew D'Addesio, Greg Maxwell, and Vincent Penquerc'h for >+ their feedback based on early implementations. >+</t> >+</section> >+ >+<section title="RFC Editor Notes"> >+<t> >+In <xref target="iana"/>, "RFCXXXX" is to be replaced with the RFC number >+ assigned to this draft. >+</t> >+</section> >+ >+</middle> >+<back> >+<references title="Normative References"> >+ &rfc2119; >+ &rfc3533; >+ &rfc3629; >+ &rfc5226; >+ &rfc5334; >+ &rfc6381; >+ &rfc6716; >+ >+<reference anchor="EBU-R128" target="https://tech.ebu.ch/loudness"> >+<front> >+ <title>Loudness Recommendation EBU R128</title> >+ <author> >+ <organization>EBU Technical Committee</organization> >+ </author> >+ <date month="August" year="2011"/> >+</front> >+</reference> >+ >+<reference anchor="vorbis-comment" >+ target="https://www.xiph.org/vorbis/doc/v-comment.html"> >+<front> >+<title>Ogg Vorbis I Format Specification: Comment Field and Header >+ Specification</title> >+<author initials="C." surname="Montgomery" >+ fullname="Christopher "Monty" Montgomery"/> >+<date month="July" year="2002"/> >+</front> >+</reference> >+ >+</references> >+ >+<references title="Informative References"> >+ >+<!--?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.3550.xml"?--> >+ &rfc4732; >+ &rfc6982; >+ &rfc7587; >+ >+<reference anchor="flac" >+ target="https://xiph.org/flac/format.html"> >+ <front> >+ <title>FLAC - Free Lossless Audio Codec Format Description</title> >+ <author initials="J." surname="Coalson" fullname="Josh Coalson"/> >+ <date month="January" year="2008"/> >+ </front> >+</reference> >+ >+<reference anchor="hanning" >+ target="https://en.wikipedia.org/w/index.php?title=Window_function&oldid=703074467#Hann_.28Hanning.29_window"> >+ <front> >+ <title>Hann window</title> >+ <author> >+ <organization>Wikipedia</organization> >+ </author> >+ <date month="February" year="2016"/> >+ </front> >+</reference> >+ >+<reference anchor="linear-prediction" >+ target="https://en.wikipedia.org/w/index.php?title=Linear_predictive_coding&oldid=687498962"> >+ <front> >+ <title>Linear Predictive Coding</title> >+ <author> >+ <organization>Wikipedia</organization> >+ </author> >+ <date month="October" year="2015"/> >+ </front> >+</reference> >+ >+<reference anchor="lpc-sample" >+ target="https://svn.xiph.org/trunk/vorbis/lib/lpc.c"> >+<front> >+ <title>Autocorrelation LPC coeff generation algorithm >+ (Vorbis source code)</title> >+<author initials="J." surname="Degener" fullname="Jutta Degener"/> >+<author initials="C." surname="Bormann" fullname="Carsten Bormann"/> >+<date month="November" year="1994"/> >+</front> >+</reference> >+ >+<reference anchor="q-notation" >+ target="https://en.wikipedia.org/w/index.php?title=Q_%28number_format%29&oldid=697252615"> >+<front> >+<title>Q (number format)</title> >+<author><organization>Wikipedia</organization></author> >+<date month="December" year="2015"/> >+</front> >+</reference> >+ >+<reference anchor="replay-gain" >+ target="https://wiki.xiph.org/VorbisComment#Replay_Gain"> >+<front> >+<title>VorbisComment: Replay Gain</title> >+<author initials="C." surname="Parker" fullname="Conrad Parker"/> >+<author initials="M." surname="Leese" fullname="Martin Leese"/> >+<date month="June" year="2009"/> >+</front> >+</reference> >+ >+<reference anchor="seeking" >+ target="https://wiki.xiph.org/Seeking"> >+<front> >+<title>Granulepos Encoding and How Seeking Really Works</title> >+<author initials="S." surname="Pfeiffer" fullname="Silvia Pfeiffer"/> >+<author initials="C." surname="Parker" fullname="Conrad Parker"/> >+<author initials="G." surname="Maxwell" fullname="Greg Maxwell"/> >+<date month="May" year="2012"/> >+</front> >+</reference> >+ >+<reference anchor="vorbis-mapping" >+ target="https://www.xiph.org/vorbis/doc/Vorbis_I_spec.html#x1-810004.3.9"> >+<front> >+<title>The Vorbis I Specification, Section 4.3.9 Output Channel Order</title> >+<author initials="C." surname="Montgomery" >+ fullname="Christopher "Monty" Montgomery"/> >+<date month="January" year="2010"/> >+</front> >+</reference> >+ >+<reference anchor="vorbis-trim" >+ target="https://xiph.org/vorbis/doc/Vorbis_I_spec.html#x1-132000A.2"> >+ <front> >+ <title>The Vorbis I Specification, Appendix A: Embedding Vorbis >+ into an Ogg stream</title> >+ <author initials="C." surname="Montgomery" >+ fullname="Christopher "Monty" Montgomery"/> >+ <date month="November" year="2008"/> >+ </front> >+</reference> >+ >+<reference anchor="wave-multichannel" >+ target="http://msdn.microsoft.com/en-us/windows/hardware/gg463006.aspx"> >+ <front> >+ <title>Multiple Channel Audio Data and WAVE Files</title> >+ <author> >+ <organization>Microsoft Corporation</organization> >+ </author> >+ <date month="March" year="2007"/> >+ </front> >+</reference> >+ >+</references> >+ >+</back> >+</rfc> >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/draft-ietf-codec-opus-update.xml b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/draft-ietf-codec-opus-update.xml >new file mode 100644 >index 0000000000000000000000000000000000000000..6e52a1668d90597815fca7a9dbef38b8896c5362 >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/draft-ietf-codec-opus-update.xml >@@ -0,0 +1,519 @@ >+<?xml version="1.0" encoding="US-ASCII"?> >+<!DOCTYPE rfc SYSTEM "rfc2629.dtd"> >+<?rfc toc="yes"?> >+<?rfc tocompact="yes"?> >+<?rfc tocdepth="3"?> >+<?rfc tocindent="yes"?> >+<?rfc symrefs="yes"?> >+<?rfc sortrefs="yes"?> >+<?rfc comments="yes"?> >+<?rfc inline="yes"?> >+<?rfc compact="yes"?> >+<?rfc subcompact="no"?> >+<rfc category="std" docName="draft-ietf-codec-opus-update-08" >+ ipr="trust200902" updates="6716"> >+ <front> >+ <title abbrev="Opus Update">Updates to the Opus Audio Codec</title> >+ >+<author initials="JM" surname="Valin" fullname="Jean-Marc Valin"> >+<organization>Mozilla Corporation</organization> >+<address> >+<postal> >+<street>331 E. Evelyn Avenue</street> >+<city>Mountain View</city> >+<region>CA</region> >+<code>94041</code> >+<country>USA</country> >+</postal> >+<phone>+1 650 903-0800</phone> >+<email>jmvalin@jmvalin.ca</email> >+</address> >+</author> >+ >+<author initials="K." surname="Vos" fullname="Koen Vos"> >+<organization>vocTone</organization> >+<address> >+<postal> >+<street></street> >+<city></city> >+<region></region> >+<code></code> >+<country></country> >+</postal> >+<phone></phone> >+<email>koenvos74@gmail.com</email> >+</address> >+</author> >+ >+ >+ >+ <date day="26" month="July" year="2017" /> >+ >+ <abstract> >+ <t>This document addresses minor issues that were found in the specification >+ of the Opus audio codec in RFC 6716.</t> >+ </abstract> >+ </front> >+ >+ <middle> >+ <section title="Introduction"> >+ <t>This document addresses minor issues that were discovered in the reference >+ implementation of the Opus codec. Unlike most IETF specifications, Opus is defined >+ in <xref target="RFC6716">RFC 6716</xref> in terms of a normative reference >+ decoder implementation rather than from the associated text description. >+ That RFC includes the reference decoder implementation as Appendix A. >+ That's why only issues affecting the decoder are >+ listed here. An up-to-date implementation of the Opus encoder can be found at >+ <eref target="https://opus-codec.org/"/>.</t> >+ <t> >+ Some of the changes in this document update normative behaviour in a way that requires >+ new test vectors. The English text of the specification is unaffected, only >+ the C implementation is. The updated specification remains fully compatible with >+ the original specification. >+ </t> >+ >+ <t> >+ Note: due to RFC formatting conventions, lines exceeding the column width >+ in the patch are split using a backslash character. The backslashes >+ at the end of a line and the white space at the beginning >+ of the following line are not part of the patch. A properly formatted patch >+ including all changes is available at >+ <eref target="https://www.ietf.org/proceedings/98/slides/materials-98-codec-opus-update-00.patch"/> >+ and has a SHA1 029e3aa88fc342c91e67a21e7bfbc9458661cd5f. >+ </t> >+ >+ </section> >+ >+ <section title="Terminology"> >+ <t>The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", >+ "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this >+ document are to be interpreted as described in <xref >+ target="RFC2119">RFC 2119</xref>.</t> >+ </section> >+ >+ <section title="Stereo State Reset in SILK"> >+ <t>The reference implementation does not reinitialize the stereo state >+ during a mode switch. The old stereo memory can produce a brief impulse >+ (i.e. single sample) in the decoded audio. This can be fixed by changing >+ silk/dec_API.c at line 72: >+ </t> >+<figure> >+<artwork><![CDATA[ >+<CODE BEGINS> >+ for( n = 0; n < DECODER_NUM_CHANNELS; n++ ) { >+ ret = silk_init_decoder( &channel_state[ n ] ); >+ } >++ silk_memset(&((silk_decoder *)decState)->sStereo, 0, >++ sizeof(((silk_decoder *)decState)->sStereo)); >++ /* Not strictly needed, but it's cleaner that way */ >++ ((silk_decoder *)decState)->prev_decode_only_middle = 0; >+ >+ return ret; >+ } >+<CODE ENDS> >+]]></artwork> >+</figure> >+ <t> >+ This change affects the normative output of the decoder, but the >+ amount of change is within the tolerance and too small to make the testvector check fail. >+ </t> >+ </section> >+ >+ <section anchor="padding" title="Parsing of the Opus Packet Padding"> >+ <t>It was discovered that some invalid packets of very large size could trigger >+ an out-of-bounds read in the Opus packet parsing code responsible for padding. >+ This is due to an integer overflow if the signaled padding exceeds 2^31-1 bytes >+ (the actual packet may be smaller). The code can be fixed by applying the following >+ changes at line 596 of src/opus_decoder.c: >+ </t> >+<figure> >+<artwork><![CDATA[ >+<CODE BEGINS> >+ /* Padding flag is bit 6 */ >+ if (ch&0x40) >+ { >+- int padding=0; >+ int p; >+ do { >+ if (len<=0) >+ return OPUS_INVALID_PACKET; >+ p = *data++; >+ len--; >+- padding += p==255 ? 254: p; >++ len -= p==255 ? 254: p; >+ } while (p==255); >+- len -= padding; >+ } >+<CODE ENDS> >+]]></artwork> >+</figure> >+ <t>This packet parsing issue is limited to reading memory up >+ to about 60 kB beyond the compressed buffer. This can only be triggered >+ by a compressed packet more than about 16 MB long, so it's not a problem >+ for RTP. In theory, it could crash a file >+ decoder (e.g. Opus in Ogg) if the memory just after the incoming packet >+ is out-of-range, but our attempts to trigger such a crash in a production >+ application built using an affected version of the Opus decoder failed.</t> >+ </section> >+ >+ <section anchor="resampler" title="Resampler buffer"> >+ <t>The SILK resampler had the following issues: >+ <list style="numbers"> >+ <t>The calls to memcpy() were using sizeof(opus_int32), but the type of the >+ local buffer was opus_int16.</t> >+ <t>Because the size was wrong, this potentially allowed the source >+ and destination regions of the memcpy() to overlap. >+ We believe that nSamplesIn (number of input samples) is at least fs_in_khZ (sampling rate in kHz), >+ which is at least 8. >+ Since RESAMPLER_ORDER_FIR_12 is only 8, that should not be a problem once >+ the type size is fixed.</t> >+ <t>The size of the buffer used RESAMPLER_MAX_BATCH_SIZE_IN, but the >+ data stored in it was actually twice the input batch size >+ (nSamplesIn<<1).</t> >+ </list></t> >+ <t> >+ The fact that the code never produced any error in testing (including when run under the >+ Valgrind memory debugger), suggests that in practice >+ the batch sizes are reasonable enough that none of the issues above >+ was ever a problem. However, the authors know of no obvious approach to proving that. >+ </t> >+ <t>The code can be fixed by applying the following changes to line 78 of silk/resampler_private_IIR_FIR.c: >+ </t> >+<figure> >+<artwork><![CDATA[ >+<CODE BEGINS> >+ ) >+ { >+ silk_resampler_state_struct *S = \ >+(silk_resampler_state_struct *)SS; >+ opus_int32 nSamplesIn; >+ opus_int32 max_index_Q16, index_increment_Q16; >+- opus_int16 buf[ RESAMPLER_MAX_BATCH_SIZE_IN + \ >+RESAMPLER_ORDER_FIR_12 ]; >++ opus_int16 buf[ 2*RESAMPLER_MAX_BATCH_SIZE_IN + \ >+RESAMPLER_ORDER_FIR_12 ]; >+ >+ /* Copy buffered samples to start of buffer */ >+- silk_memcpy( buf, S->sFIR, RESAMPLER_ORDER_FIR_12 \ >+* sizeof( opus_int32 ) ); >++ silk_memcpy( buf, S->sFIR, RESAMPLER_ORDER_FIR_12 \ >+* sizeof( opus_int16 ) ); >+ >+ /* Iterate over blocks of frameSizeIn input samples */ >+ index_increment_Q16 = S->invRatio_Q16; >+ while( 1 ) { >+ nSamplesIn = silk_min( inLen, S->batchSize ); >+ >+ /* Upsample 2x */ >+ silk_resampler_private_up2_HQ( S->sIIR, &buf[ \ >+RESAMPLER_ORDER_FIR_12 ], in, nSamplesIn ); >+ >+ max_index_Q16 = silk_LSHIFT32( nSamplesIn, 16 + 1 \ >+); /* + 1 because 2x upsampling */ >+ out = silk_resampler_private_IIR_FIR_INTERPOL( out, \ >+buf, max_index_Q16, index_increment_Q16 ); >+ in += nSamplesIn; >+ inLen -= nSamplesIn; >+ >+ if( inLen > 0 ) { >+ /* More iterations to do; copy last part of \ >+filtered signal to beginning of buffer */ >+- silk_memcpy( buf, &buf[ nSamplesIn << 1 ], \ >+RESAMPLER_ORDER_FIR_12 * sizeof( opus_int32 ) ); >++ silk_memmove( buf, &buf[ nSamplesIn << 1 ], \ >+RESAMPLER_ORDER_FIR_12 * sizeof( opus_int16 ) ); >+ } else { >+ break; >+ } >+ } >+ >+ /* Copy last part of filtered signal to the state for \ >+the next call */ >+- silk_memcpy( S->sFIR, &buf[ nSamplesIn << 1 ], \ >+RESAMPLER_ORDER_FIR_12 * sizeof( opus_int32 ) ); >++ silk_memcpy( S->sFIR, &buf[ nSamplesIn << 1 ], \ >+RESAMPLER_ORDER_FIR_12 * sizeof( opus_int16 ) ); >+ } >+<CODE ENDS> >+]]></artwork> >+</figure> >+ </section> >+ >+ <section title="Integer wrap-around in inverse gain computation"> >+ <t> >+ It was discovered through decoder fuzzing that some bitstreams could produce >+ integer values exceeding 32-bits in LPC_inverse_pred_gain_QA(), causing >+ a wrap-around. Although the error is harmless in practice, the C standard considers >+ the behavior as undefined, so the following patch to line 87 of silk/LPC_inv_pred_gain.c >+ detects values that do not fit in a 32-bit integer and considers the corresponding filters unstable: >+ </t> >+<figure> >+<artwork><![CDATA[ >+<CODE BEGINS> >+ /* Update AR coefficient */ >+ for( n = 0; n < k; n++ ) { >+- tmp_QA = Aold_QA[ n ] - MUL32_FRAC_Q( \ >+Aold_QA[ k - n - 1 ], rc_Q31, 31 ); >+- Anew_QA[ n ] = MUL32_FRAC_Q( tmp_QA, rc_mult2 , mult2Q ); >++ opus_int64 tmp64; >++ tmp_QA = silk_SUB_SAT32( Aold_QA[ n ], MUL32_FRAC_Q( \ >+Aold_QA[ k - n - 1 ], rc_Q31, 31 ) ); >++ tmp64 = silk_RSHIFT_ROUND64( silk_SMULL( tmp_QA, \ >+rc_mult2 ), mult2Q); >++ if( tmp64 > silk_int32_MAX || tmp64 < silk_int32_MIN ) { >++ return 0; >++ } >++ Anew_QA[ n ] = ( opus_int32 )tmp64; >+ } >+<CODE ENDS> >+]]></artwork> >+</figure> >+ </section> >+ >+ <section title="Integer wrap-around in LSF decoding" anchor="lsf_overflow"> >+ <t> >+ It was discovered -- also from decoder fuzzing -- that an integer wrap-around could >+ occur when decoding line spectral frequency coefficients from extreme bitstreams. >+ The end result of the wrap-around is an illegal read access on the stack, which >+ the authors do not believe is exploitable but should nonetheless be fixed. The following >+ patch to line 137 of silk/NLSF_stabilize.c prevents the problem: >+ </t> >+<figure> >+<artwork><![CDATA[ >+<CODE BEGINS> >+ /* Keep delta_min distance between the NLSFs */ >+ for( i = 1; i < L; i++ ) >+- NLSF_Q15[i] = silk_max_int( NLSF_Q15[i], \ >+NLSF_Q15[i-1] + NDeltaMin_Q15[i] ); >++ NLSF_Q15[i] = silk_max_int( NLSF_Q15[i], \ >+silk_ADD_SAT16( NLSF_Q15[i-1], NDeltaMin_Q15[i] ) ); >+ >+ /* Last NLSF should be no higher than 1 - NDeltaMin[L] */ >+<CODE ENDS> >+]]></artwork> >+</figure> >+ >+ </section> >+ >+ <section title="Cap on Band Energy"> >+ <t>On extreme bit-streams, it is possible for log-domain band energy levels >+ to exceed the maximum single-precision floating point value once converted >+ to a linear scale. This would later cause the decoded values to be NaN (not a number), >+ possibly causing problems in the software using the PCM values. This can be >+ avoided with the following patch to line 552 of celt/quant_bands.c: >+ </t> >+<figure> >+<artwork><![CDATA[ >+<CODE BEGINS> >+ { >+ opus_val16 lg = ADD16(oldEBands[i+c*m->nbEBands], >+ SHL16((opus_val16)eMeans[i],6)); >++ lg = MIN32(QCONST32(32.f, 16), lg); >+ eBands[i+c*m->nbEBands] = PSHR32(celt_exp2(lg),4); >+ } >+ for (;i<m->nbEBands;i++) >+<CODE ENDS> >+]]></artwork> >+</figure> >+ </section> >+ >+ <section title="Hybrid Folding" anchor="folding"> >+ <t>When encoding in hybrid mode at low bitrate, we sometimes only have >+ enough bits to code a single CELT band (8 - 9.6 kHz). When that happens, >+ the second band (CELT band 18, from 9.6 to 12 kHz) cannot use folding >+ because it is wider than the amount already coded, and falls back to >+ white noise. Because it can also happen on transients (e.g. stops), it >+ can cause audible pre-echo. >+ </t> >+ <t> >+ To address the issue, we change the folding behavior so that it is >+ never forced to fall back to LCG due to the first band not containing >+ enough coefficients to fold onto the second band. This >+ is achieved by simply repeating part of the first band in the folding >+ of the second band. This changes the code in celt/bands.c around line 1237: >+ </t> >+<figure> >+<artwork><![CDATA[ >+<CODE BEGINS> >+ b = 0; >+ } >+ >+- if (resynth && M*eBands[i]-N >= M*eBands[start] && \ >+(update_lowband || lowband_offset==0)) >++ if (resynth && (M*eBands[i]-N >= M*eBands[start] || \ >+i==start+1) && (update_lowband || lowband_offset==0)) >+ lowband_offset = i; >+ >++ if (i == start+1) >++ { >++ int n1, n2; >++ int offset; >++ n1 = M*(eBands[start+1]-eBands[start]); >++ n2 = M*(eBands[start+2]-eBands[start+1]); >++ offset = M*eBands[start]; >++ /* Duplicate enough of the first band folding data to \ >+be able to fold the second band. >++ Copies no data for CELT-only mode. */ >++ OPUS_COPY(&norm[offset+n1], &norm[offset+2*n1 - n2], n2-n1); >++ if (C==2) >++ OPUS_COPY(&norm2[offset+n1], &norm2[offset+2*n1 - n2], \ >+n2-n1); >++ } >++ >+ tf_change = tf_res[i]; >+ if (i>=m->effEBands) >+ { >+<CODE ENDS> >+]]></artwork> >+</figure> >+ >+ <t> >+ as well as line 1260: >+ </t> >+ >+<figure> >+<artwork><![CDATA[ >+<CODE BEGINS> >+ fold_start = lowband_offset; >+ while(M*eBands[--fold_start] > effective_lowband); >+ fold_end = lowband_offset-1; >+- while(M*eBands[++fold_end] < effective_lowband+N); >++ while(++fold_end < i && M*eBands[fold_end] < \ >+effective_lowband+N); >+ x_cm = y_cm = 0; >+ fold_i = fold_start; do { >+ x_cm |= collapse_masks[fold_i*C+0]; >+ >+<CODE ENDS> >+]]></artwork> >+</figure> >+ <t> >+ The fix does not impact compatibility, because the improvement does >+ not depend on the encoder doing anything special. There is also no >+ reasonable way for an encoder to use the original behavior to >+ improve quality over the proposed change. >+ </t> >+ </section> >+ >+ <section title="Downmix to Mono" anchor="stereo"> >+ <t>The last issue is not strictly a bug, but it is an issue that has been reported >+ when downmixing an Opus decoded stream to mono, whether this is done inside the decoder >+ or as a post-processing step on the stereo decoder output. Opus intensity stereo allows >+ optionally coding the two channels 180-degrees out of phase on a per-band basis. >+ This provides better stereo quality than forcing the two channels to be in phase, >+ but when the output is downmixed to mono, the energy in the affected bands is cancelled >+ sometimes resulting in audible artefacts. >+ </t> >+ <t>As a work-around for this issue, the decoder MAY choose not to apply the 180-degree >+ phase shift when the output is meant to be downmixed (inside or >+ outside of the decoder). >+ </t> >+ </section> >+ >+ >+ <section title="New Test Vectors"> >+ <t>Changes in <xref target="folding"/> and <xref target="stereo"/> have >+ sufficient impact on the testvectors to make them fail. For this reason, >+ this document also updates the Opus test vectors. The new test vectors now >+ include two decoded outputs for the same bitstream. The outputs with >+ suffix 'm' do not apply the CELT 180-degree phase shift as allowed in >+ <xref target="stereo"/>, while the outputs without the suffix do. An >+ implementation is compliant as long as it passes either set of vectors. >+ </t> >+ <t> >+ In addition, any Opus implementation >+ that passes the original test vectors from <xref target="RFC6716">RFC 6716</xref> >+ is still compliant with the Opus specification. However, newer implementations >+ SHOULD be based on the new test vectors rather than the old ones. >+ </t> >+ <t>The new test vectors are located at >+ <eref target="https://www.ietf.org/proceedings/98/slides/materials-98-codec-opus-newvectors-00.tar.gz"/>. >+ The SHA1 hash of the test vectors are: >+<figure> >+<artwork> >+<![CDATA[ >+e49b2862ceec7324790ed8019eb9744596d5be01 testvector01.bit >+b809795ae1bcd606049d76de4ad24236257135e0 testvector02.bit >+e0c4ecaeab44d35a2f5b6575cd996848e5ee2acc testvector03.bit >+a0f870cbe14ebb71fa9066ef3ee96e59c9a75187 testvector04.bit >+9b3d92b48b965dfe9edf7b8a85edd4309f8cf7c8 testvector05.bit >+28e66769ab17e17f72875283c14b19690cbc4e57 testvector06.bit >+bacf467be3215fc7ec288f29e2477de1192947a6 testvector07.bit >+ddbe08b688bbf934071f3893cd0030ce48dba12f testvector08.bit >+3932d9d61944dab1201645b8eeaad595d5705ecb testvector09.bit >+521eb2a1e0cc9c31b8b740673307c2d3b10c1900 testvector10.bit >+6bc8f3146fcb96450c901b16c3d464ccdf4d5d96 testvector11.bit >+338c3f1b4b97226bc60bc41038becbc6de06b28f testvector12.bit >+f5ef93884da6a814d311027918e9afc6f2e5c2c8 testvector01.dec >+48ac1ff1995250a756e1e17bd32acefa8cd2b820 testvector02.dec >+d15567e919db2d0e818727092c0af8dd9df23c95 testvector03.dec >+1249dd28f5bd1e39a66fd6d99449dca7a8316342 testvector04.dec >+b85675d81deef84a112c466cdff3b7aaa1d2fc76 testvector05.dec >+55f0b191e90bfa6f98b50d01a64b44255cb4813e testvector06.dec >+61e8b357ab090b1801eeb578a28a6ae935e25b7b testvector07.dec >+a58539ee5321453b2ddf4c0f2500e856b3966862 testvector08.dec >+bb96aad2cde188555862b7bbb3af6133851ef8f4 testvector09.dec >+1b6cdf0413ac9965b16184b1bea129b5c0b2a37a testvector10.dec >+b1fff72b74666e3027801b29dbc48b31f80dee0d testvector11.dec >+98e09bbafed329e341c3b4052e9c4ba5fc83f9b1 testvector12.dec >+1e7d984ea3fbb16ba998aea761f4893fbdb30157 testvector01m.dec >+48ac1ff1995250a756e1e17bd32acefa8cd2b820 testvector02m.dec >+d15567e919db2d0e818727092c0af8dd9df23c95 testvector03m.dec >+1249dd28f5bd1e39a66fd6d99449dca7a8316342 testvector04m.dec >+d70b0bad431e7d463bc3da49bd2d49f1c6d0a530 testvector05m.dec >+6ac1648c3174c95fada565161a6c78bdbe59c77d testvector06m.dec >+fc5e2f709693738324fb4c8bdc0dad6dda04e713 testvector07m.dec >+aad2ba397bf1b6a18e8e09b50e4b19627d479f00 testvector08m.dec >+6feb7a7b9d7cdc1383baf8d5739e2a514bd0ba08 testvector09m.dec >+1b6cdf0413ac9965b16184b1bea129b5c0b2a37a testvector10m.dec >+fd3d3a7b0dfbdab98d37ed9aa04b659b9fefbd18 testvector11m.dec >+98e09bbafed329e341c3b4052e9c4ba5fc83f9b1 testvector12m.dec >+]]> >+</artwork> >+</figure> >+ Note that the decoder input bitstream files (.bit) are unchanged. >+ </t> >+ </section> >+ >+ <section anchor="security" title="Security Considerations"> >+ <t>This document fixes two security issues reported on Opus and that affect the >+ reference implementation in <xref target="RFC6716">RFC 6716</xref>: CVE-2013-0899 >+ <eref target="https://nvd.nist.gov/vuln/detail/CVE-2013-0899"/> >+ and CVE-2017-0381 <eref target="https://nvd.nist.gov/vuln/detail/CVE-2017-0381"/>. >+ CVE-2013-0899 is fixed by <xref target="padding"/> and >+ could theoretically cause information leak, but the >+ leaked information would at the very least go through the decoder process before >+ being accessible to the attacker. Also, the bug can only be triggered by Opus packets >+ at least 24 MB in size. CVE-2017-0381 is fixed by <xref target="lsf_overflow"/> and, as far >+ as the authors are aware, could not be exploited in any way (despite the claims in >+ the CVE) unless the read-only table >+ was somehow placed very close to sensitive data, which is highly unlikely. >+ Beyond the two fixed CVEs, this document adds no new security considerations on top of >+ <xref target="RFC6716">RFC 6716</xref>. >+ </t> >+ </section> >+ >+ <section anchor="IANA" title="IANA Considerations"> >+ <t>This document makes no request of IANA.</t> >+ >+ <t>Note to RFC Editor: this section may be removed on publication as an >+ RFC.</t> >+ </section> >+ >+ <section anchor="Acknowledgements" title="Acknowledgements"> >+ <t>We would like to thank Juri Aedla for reporting the issue with the parsing of >+ the Opus padding. Thanks to Felicia Lim for reporting the LSF integer overflow issue. >+ Also, thanks to Tina le Grand, Jonathan Lennox, and Mark Harris for their >+ feedback on this document.</t> >+ </section> >+ </middle> >+ >+ <back> >+ <references title="Normative References"> >+ <?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml"?> >+ <?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.6716.xml"?> >+ >+ >+ </references> >+ </back> >+</rfc> >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/draft-ietf-codec-opus.xml b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/draft-ietf-codec-opus.xml >new file mode 100644 >index 0000000000000000000000000000000000000000..334cad97a27d7e7bf1cdd09f4914cb6a96ae4711 >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/draft-ietf-codec-opus.xml >@@ -0,0 +1,8276 @@ >+<?xml version="1.0" encoding="utf-8"?> >+<!DOCTYPE rfc SYSTEM 'rfc2629.dtd'> >+<?rfc toc="yes" symrefs="yes" ?> >+ >+<rfc ipr="trust200902" category="std" docName="draft-ietf-codec-opus-14"> >+ >+<front> >+<title abbrev="Interactive Audio Codec">Definition of the Opus Audio Codec</title> >+ >+ >+<author initials="JM" surname="Valin" fullname="Jean-Marc Valin"> >+<organization>Mozilla Corporation</organization> >+<address> >+<postal> >+<street>650 Castro Street</street> >+<city>Mountain View</city> >+<region>CA</region> >+<code>94041</code> >+<country>USA</country> >+</postal> >+<phone>+1 650 903-0800</phone> >+<email>jmvalin@jmvalin.ca</email> >+</address> >+</author> >+ >+<author initials="K." surname="Vos" fullname="Koen Vos"> >+<organization>Skype Technologies S.A.</organization> >+<address> >+<postal> >+<street>Soder Malarstrand 43</street> >+<city>Stockholm</city> >+<region></region> >+<code>11825</code> >+<country>SE</country> >+</postal> >+<phone>+46 73 085 7619</phone> >+<email>koen.vos@skype.net</email> >+</address> >+</author> >+ >+<author initials="T." surname="Terriberry" fullname="Timothy B. Terriberry"> >+<organization>Mozilla Corporation</organization> >+<address> >+<postal> >+<street>650 Castro Street</street> >+<city>Mountain View</city> >+<region>CA</region> >+<code>94041</code> >+<country>USA</country> >+</postal> >+<phone>+1 650 903-0800</phone> >+<email>tterriberry@mozilla.com</email> >+</address> >+</author> >+ >+<date day="17" month="May" year="2012" /> >+ >+<area>General</area> >+ >+<workgroup></workgroup> >+ >+<abstract> >+<t> >+This document defines the Opus interactive speech and audio codec. >+Opus is designed to handle a wide range of interactive audio applications, >+ including Voice over IP, videoconferencing, in-game chat, and even live, >+ distributed music performances. >+It scales from low bitrate narrowband speech at 6 kb/s to very high quality >+ stereo music at 510 kb/s. >+Opus uses both linear prediction (LP) and the Modified Discrete Cosine >+ Transform (MDCT) to achieve good compression of both speech and music. >+</t> >+</abstract> >+</front> >+ >+<middle> >+ >+<section anchor="introduction" title="Introduction"> >+<t> >+The Opus codec is a real-time interactive audio codec designed to meet the requirements >+described in <xref target="requirements"></xref>. >+It is composed of a linear >+ prediction (LP)-based <xref target="LPC"/> layer and a Modified Discrete Cosine Transform >+ (MDCT)-based <xref target="MDCT"/> layer. >+The main idea behind using two layers is that in speech, linear prediction >+ techniques (such as Code-Excited Linear Prediction, or CELP) code low frequencies more efficiently than transform >+ (e.g., MDCT) domain techniques, while the situation is reversed for music and >+ higher speech frequencies. >+Thus a codec with both layers available can operate over a wider range than >+ either one alone and, by combining them, achieve better quality than either >+ one individually. >+</t> >+ >+<t> >+The primary normative part of this specification is provided by the source code >+ in <xref target="ref-implementation"></xref>. >+Only the decoder portion of this software is normative, though a >+ significant amount of code is shared by both the encoder and decoder. >+<xref target="conformance"/> provides a decoder conformance test. >+The decoder contains a great deal of integer and fixed-point arithmetic which >+ needs to be performed exactly, including all rounding considerations, so any >+ useful specification requires domain-specific symbolic language to adequately >+ define these operations. >+Additionally, any >+conflict between the symbolic representation and the included reference >+implementation must be resolved. For the practical reasons of compatibility and >+testability it would be advantageous to give the reference implementation >+priority in any disagreement. The C language is also one of the most >+widely understood human-readable symbolic representations for machine >+behavior. >+For these reasons this RFC uses the reference implementation as the sole >+ symbolic representation of the codec. >+</t> >+ >+<t>While the symbolic representation is unambiguous and complete it is not >+always the easiest way to understand the codec's operation. For this reason >+this document also describes significant parts of the codec in English and >+takes the opportunity to explain the rationale behind many of the more >+surprising elements of the design. These descriptions are intended to be >+accurate and informative, but the limitations of common English sometimes >+result in ambiguity, so it is expected that the reader will always read >+them alongside the symbolic representation. Numerous references to the >+implementation are provided for this purpose. The descriptions sometimes >+differ from the reference in ordering or through mathematical simplification >+wherever such deviation makes an explanation easier to understand. >+For example, the right shift and left shift operations in the reference >+implementation are often described using division and multiplication in the text. >+In general, the text is focused on the "what" and "why" while the symbolic >+representation most clearly provides the "how". >+</t> >+ >+<section anchor="notation" title="Notation and Conventions"> >+<t> >+The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", >+ "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be >+ interpreted as described in RFC 2119 <xref target="rfc2119"></xref>. >+</t> >+<t> >+Various operations in the codec require bit-exact fixed-point behavior, even >+ when writing a floating point implementation. >+The notation "Q<n>", where n is an integer, denotes the number of binary >+ digits to the right of the decimal point in a fixed-point number. >+For example, a signed Q14 value in a 16-bit word can represent values from >+ -2.0 to 1.99993896484375, inclusive. >+This notation is for informational purposes only. >+Arithmetic, when described, always operates on the underlying integer. >+E.g., the text will explicitly indicate any shifts required after a >+ multiplication. >+</t> >+<t> >+Expressions, where included in the text, follow C operator rules and >+ precedence, with the exception that the syntax "x**y" indicates x raised to >+ the power y. >+The text also makes use of the following functions: >+</t> >+ >+<section anchor="min" toc="exclude" title="min(x,y)"> >+<t> >+The smallest of two values x and y. >+</t> >+</section> >+ >+<section anchor="max" toc="exclude" title="max(x,y)"> >+<t> >+The largest of two values x and y. >+</t> >+</section> >+ >+<section anchor="clamp" toc="exclude" title="clamp(lo,x,hi)"> >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+clamp(lo,x,hi) = max(lo,min(x,hi)) >+]]></artwork> >+</figure> >+<t> >+With this definition, if lo > hi, the lower bound is the one that >+ is enforced. >+</t> >+</section> >+ >+<section anchor="sign" toc="exclude" title="sign(x)"> >+<t> >+The sign of x, i.e., >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+ ( -1, x < 0 , >+sign(x) = < 0, x == 0 , >+ ( 1, x > 0 . >+]]></artwork> >+</figure> >+</t> >+</section> >+ >+<section anchor="abs" toc="exclude" title="abs(x)"> >+<t> >+The absolute value of x, i.e., >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+abs(x) = sign(x)*x . >+]]></artwork> >+</figure> >+</t> >+</section> >+ >+<section anchor="floor" toc="exclude" title="floor(f)"> >+<t> >+The largest integer z such that z <= f. >+</t> >+</section> >+ >+<section anchor="ceil" toc="exclude" title="ceil(f)"> >+<t> >+The smallest integer z such that z >= f. >+</t> >+</section> >+ >+<section anchor="round" toc="exclude" title="round(f)"> >+<t> >+The integer z nearest to f, with ties rounded towards negative infinity, >+ i.e., >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+ round(f) = ceil(f - 0.5) . >+]]></artwork> >+</figure> >+</t> >+</section> >+ >+<section anchor="log2" toc="exclude" title="log2(f)"> >+<t> >+The base-two logarithm of f. >+</t> >+</section> >+ >+<section anchor="ilog" toc="exclude" title="ilog(n)"> >+<t> >+The minimum number of bits required to store a positive integer n in two's >+ complement notation, or 0 for a non-positive integer n. >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+ ( 0, n <= 0, >+ilog(n) = < >+ ( floor(log2(n))+1, n > 0 >+]]></artwork> >+</figure> >+Examples: >+<list style="symbols"> >+<t>ilog(-1) = 0</t> >+<t>ilog(0) = 0</t> >+<t>ilog(1) = 1</t> >+<t>ilog(2) = 2</t> >+<t>ilog(3) = 2</t> >+<t>ilog(4) = 3</t> >+<t>ilog(7) = 3</t> >+</list> >+</t> >+</section> >+ >+</section> >+ >+</section> >+ >+<section anchor="overview" title="Opus Codec Overview"> >+ >+<t> >+The Opus codec scales from 6 kb/s narrowband mono speech to 510 kb/s >+ fullband stereo music, with algorithmic delays ranging from 5 ms to >+ 65.2 ms. >+At any given time, either the LP layer, the MDCT layer, or both, may be active. >+It can seamlessly switch between all of its various operating modes, giving it >+ a great deal of flexibility to adapt to varying content and network >+ conditions without renegotiating the current session. >+The codec allows input and output of various audio bandwidths, defined as >+ follows: >+</t> >+<texttable anchor="audio-bandwidth"> >+<ttcol>Abbreviation</ttcol> >+<ttcol align="right">Audio Bandwidth</ttcol> >+<ttcol align="right">Sample Rate (Effective)</ttcol> >+<c>NB (narrowband)</c> <c>4 kHz</c> <c>8 kHz</c> >+<c>MB (medium-band)</c> <c>6 kHz</c> <c>12 kHz</c> >+<c>WB (wideband)</c> <c>8 kHz</c> <c>16 kHz</c> >+<c>SWB (super-wideband)</c> <c>12 kHz</c> <c>24 kHz</c> >+<c>FB (fullband)</c> <c>20 kHz (*)</c> <c>48 kHz</c> >+</texttable> >+<t> >+(*) Although the sampling theorem allows a bandwidth as large as half the >+ sampling rate, Opus never codes audio above 20 kHz, as that is the >+ generally accepted upper limit of human hearing. >+</t> >+ >+<t> >+Opus defines super-wideband (SWB) with an effective sample rate of 24 kHz, >+ unlike some other audio coding standards that use 32 kHz. >+This was chosen for a number of reasons. >+The band layout in the MDCT layer naturally allows skipping coefficients for >+ frequencies over 12 kHz, but does not allow cleanly dropping just those >+ frequencies over 16 kHz. >+A sample rate of 24 kHz also makes resampling in the MDCT layer easier, >+ as 24 evenly divides 48, and when 24 kHz is sufficient, it can save >+ computation in other processing, such as Acoustic Echo Cancellation (AEC). >+Experimental changes to the band layout to allow a 16 kHz cutoff >+ (32 kHz effective sample rate) showed potential quality degradations at >+ other sample rates, and at typical bitrates the number of bits saved by using >+ such a cutoff instead of coding in fullband (FB) mode is very small. >+Therefore, if an application wishes to process a signal sampled at 32 kHz, >+ it should just use FB. >+</t> >+ >+<t> >+The LP layer is based on the SILK codec >+ <xref target="SILK"></xref>. >+It supports NB, MB, or WB audio and frame sizes from 10 ms to 60 ms, >+ and requires an additional 5 ms look-ahead for noise shaping estimation. >+A small additional delay (up to 1.5 ms) may be required for sampling rate >+ conversion. >+Like Vorbis <xref target='Vorbis-website'/> and many other modern codecs, SILK is inherently designed for >+ variable-bitrate (VBR) coding, though the encoder can also produce >+ constant-bitrate (CBR) streams. >+The version of SILK used in Opus is substantially modified from, and not >+ compatible with, the stand-alone SILK codec previously deployed by Skype. >+This document does not serve to define that format, but those interested in the >+ original SILK codec should see <xref target="SILK"/> instead. >+</t> >+ >+<t> >+The MDCT layer is based on the CELT codec <xref target="CELT"></xref>. >+It supports NB, WB, SWB, or FB audio and frame sizes from 2.5 ms to >+ 20 ms, and requires an additional 2.5 ms look-ahead due to the >+ overlapping MDCT windows. >+The CELT codec is inherently designed for CBR coding, but unlike many CBR >+ codecs it is not limited to a set of predetermined rates. >+It internally allocates bits to exactly fill any given target budget, and an >+ encoder can produce a VBR stream by varying the target on a per-frame basis. >+The MDCT layer is not used for speech when the audio bandwidth is WB or less, >+ as it is not useful there. >+On the other hand, non-speech signals are not always adequately coded using >+ linear prediction, so for music only the MDCT layer should be used. >+</t> >+ >+<t> >+A "Hybrid" mode allows the use of both layers simultaneously with a frame size >+ of 10 or 20 ms and a SWB or FB audio bandwidth. >+The LP layer codes the low frequencies by resampling the signal down to WB. >+The MDCT layer follows, coding the high frequency portion of the signal. >+The cutoff between the two lies at 8 kHz, the maximum WB audio bandwidth. >+In the MDCT layer, all bands below 8 kHz are discarded, so there is no >+ coding redundancy between the two layers. >+</t> >+ >+<t> >+The sample rate (in contrast to the actual audio bandwidth) can be chosen >+ independently on the encoder and decoder side, e.g., a fullband signal can be >+ decoded as wideband, or vice versa. >+This approach ensures a sender and receiver can always interoperate, regardless >+ of the capabilities of their actual audio hardware. >+Internally, the LP layer always operates at a sample rate of twice the audio >+ bandwidth, up to a maximum of 16 kHz, which it continues to use for SWB >+ and FB. >+The decoder simply resamples its output to support different sample rates. >+The MDCT layer always operates internally at a sample rate of 48 kHz. >+Since all the supported sample rates evenly divide this rate, and since the >+ the decoder may easily zero out the high frequency portion of the spectrum in >+ the frequency domain, it can simply decimate the MDCT layer output to achieve >+ the other supported sample rates very cheaply. >+</t> >+ >+<t> >+After conversion to the common, desired output sample rate, the decoder simply >+ adds the output from the two layers together. >+To compensate for the different look-ahead required by each layer, the CELT >+ encoder input is delayed by an additional 2.7 ms. >+This ensures that low frequencies and high frequencies arrive at the same time. >+This extra delay may be reduced by an encoder by using less look-ahead for noise >+ shaping or using a simpler resampler in the LP layer, but this will reduce >+ quality. >+However, the base 2.5 ms look-ahead in the CELT layer cannot be reduced in >+ the encoder because it is needed for the MDCT overlap, whose size is fixed by >+ the decoder. >+</t> >+ >+<t> >+Both layers use the same entropy coder, avoiding any waste from "padding bits" >+ between them. >+The hybrid approach makes it easy to support both CBR and VBR coding. >+Although the LP layer is VBR, the bit allocation of the MDCT layer can produce >+ a final stream that is CBR by using all the bits left unused by the LP layer. >+</t> >+ >+<section title="Control Parameters"> >+<t> >+The Opus codec includes a number of control parameters which can be changed dynamically during >+regular operation of the codec, without interrupting the audio stream from the encoder to the decoder. >+These parameters only affect the encoder since any impact they have on the bit-stream is signaled >+in-band such that a decoder can decode any Opus stream without any out-of-band signaling. Any Opus >+implementation can add or modify these control parameters without affecting interoperability. The most >+important encoder control parameters in the reference encoder are listed below. >+</t> >+ >+<section title="Bitrate" toc="exlcude"> >+<t> >+Opus supports all bitrates from 6 kb/s to 510 kb/s. All other parameters being >+equal, higher bitrate results in higher quality. For a frame size of 20 ms, these >+are the bitrate "sweet spots" for Opus in various configurations: >+<list style="symbols"> >+<t>8-12 kb/s for NB speech,</t> >+<t>16-20 kb/s for WB speech,</t> >+<t>28-40 kb/s for FB speech,</t> >+<t>48-64 kb/s for FB mono music, and</t> >+<t>64-128 kb/s for FB stereo music.</t> >+</list> >+</t> >+</section> >+ >+<section title="Number of Channels (Mono/Stereo)" toc="exlcude"> >+<t> >+Opus can transmit either mono or stereo frames within a single stream. >+When decoding a mono frame in a stereo decoder, the left and right channels are >+ identical, and when decoding a stereo frame in a mono decoder, the mono output >+ is the average of the left and right channels. >+In some cases, it is desirable to encode a stereo input stream in mono (e.g., >+ because the bitrate is too low to encode stereo with sufficient quality). >+The number of channels encoded can be selected in real-time, but by default the >+ reference encoder attempts to make the best decision possible given the >+ current bitrate. >+</t> >+</section> >+ >+<section title="Audio Bandwidth" toc="exlcude"> >+<t> >+The audio bandwidths supported by Opus are listed in >+ <xref target="audio-bandwidth"/>. >+Just like for the number of channels, any decoder can decode audio encoded at >+ any bandwidth. >+For example, any Opus decoder operating at 8 kHz can decode a FB Opus >+ frame, and any Opus decoder operating at 48 kHz can decode a NB frame. >+Similarly, the reference encoder can take a 48 kHz input signal and >+ encode it as NB. >+The higher the audio bandwidth, the higher the required bitrate to achieve >+ acceptable quality. >+The audio bandwidth can be explicitly specified in real-time, but by default >+ the reference encoder attempts to make the best bandwidth decision possible >+ given the current bitrate. >+</t> >+</section> >+ >+ >+<section title="Frame Duration" toc="exlcude"> >+<t> >+Opus can encode frames of 2.5, 5, 10, 20, 40 or 60 ms. >+It can also combine multiple frames into packets of up to 120 ms. >+For real-time applications, sending fewer packets per second reduces the >+ bitrate, since it reduces the overhead from IP, UDP, and RTP headers. >+However, it increases latency and sensitivity to packet losses, as losing one >+ packet constitutes a loss of a bigger chunk of audio. >+Increasing the frame duration also slightly improves coding efficiency, but the >+ gain becomes small for frame sizes above 20 ms. >+For this reason, 20 ms frames are a good choice for most applications. >+</t> >+</section> >+ >+<section title="Complexity" toc="exlcude"> >+<t> >+There are various aspects of the Opus encoding process where trade-offs >+can be made between CPU complexity and quality/bitrate. In the reference >+encoder, the complexity is selected using an integer from 0 to 10, where >+0 is the lowest complexity and 10 is the highest. Examples of >+computations for which such trade-offs may occur are: >+<list style="symbols"> >+<t>The order of the pitch analysis whitening filter <xref target="Whitening"/>,</t> >+<t>The order of the short-term noise shaping filter,</t> >+<t>The number of states in delayed decision quantization of the >+residual signal, and</t> >+<t>The use of certain bit-stream features such as variable time-frequency >+resolution and the pitch post-filter.</t> >+</list> >+</t> >+</section> >+ >+<section title="Packet Loss Resilience" toc="exlcude"> >+<t> >+Audio codecs often exploit inter-frame correlations to reduce the >+bitrate at a cost in error propagation: after losing one packet >+several packets need to be received before the decoder is able to >+accurately reconstruct the speech signal. The extent to which Opus >+exploits inter-frame dependencies can be adjusted on the fly to >+choose a trade-off between bitrate and amount of error propagation. >+</t> >+</section> >+ >+<section title="Forward Error Correction (FEC)" toc="exlcude"> >+<t> >+ Another mechanism providing robustness against packet loss is the in-band >+ Forward Error Correction (FEC). Packets that are determined to >+ contain perceptually important speech information, such as onsets or >+ transients, are encoded again at a lower bitrate and this re-encoded >+ information is added to a subsequent packet. >+</t> >+</section> >+ >+<section title="Constant/Variable Bitrate" toc="exlcude"> >+<t> >+Opus is more efficient when operating with variable bitrate (VBR), which is >+the default. However, in some (rare) applications, constant bitrate (CBR) >+is required. There are two main reasons to operate in CBR mode: >+<list style="symbols"> >+<t>When the transport only supports a fixed size for each compressed frame</t> >+<t>When encryption is used for an audio stream that is either highly constrained >+ (e.g. yes/no, recorded prompts) or highly sensitive <xref target="SRTP-VBR"></xref> </t> >+</list> >+ >+When low-latency transmission is required over a relatively slow connection, then >+constrained VBR can also be used. This uses VBR in a way that simulates a >+"bit reservoir" and is equivalent to what MP3 (MPEG 1, Layer 3) and >+AAC (Advanced Audio Coding) call CBR (i.e., not true >+CBR due to the bit reservoir). >+</t> >+</section> >+ >+<section title="Discontinuous Transmission (DTX)" toc="exlcude"> >+<t> >+ Discontinuous Transmission (DTX) reduces the bitrate during silence >+ or background noise. When DTX is enabled, only one frame is encoded >+ every 400 milliseconds. >+</t> >+</section> >+ >+</section> >+ >+</section> >+ >+<section anchor="modes" title="Internal Framing"> >+ >+<t> >+The Opus encoder produces "packets", which are each a contiguous set of bytes >+ meant to be transmitted as a single unit. >+The packets described here do not include such things as IP, UDP, or RTP >+ headers which are normally found in a transport-layer packet. >+A single packet may contain multiple audio frames, so long as they share a >+ common set of parameters, including the operating mode, audio bandwidth, frame >+ size, and channel count (mono vs. stereo). >+This section describes the possible combinations of these parameters and the >+ internal framing used to pack multiple frames into a single packet. >+This framing is not self-delimiting. >+Instead, it assumes that a higher layer (such as UDP or RTP <xref target='RFC3550'/> >+or Ogg <xref target='RFC3533'/> or Matroska <xref target='Matroska-website'/>) >+ will communicate the length, in bytes, of the packet, and it uses this >+ information to reduce the framing overhead in the packet itself. >+A decoder implementation MUST support the framing described in this section. >+An alternative, self-delimiting variant of the framing is described in >+ <xref target="self-delimiting-framing"/>. >+Support for that variant is OPTIONAL. >+</t> >+ >+<t> >+All bit diagrams in this document number the bits so that bit 0 is the most >+ significant bit of the first byte, and bit 7 is the least significant. >+Bit 8 is thus the most significant bit of the second byte, etc. >+Well-formed Opus packets obey certain requirements, marked [R1] through [R7] >+ below. >+These are summarized in <xref target="malformed-packets"/> along with >+ appropriate means of handling malformed packets. >+</t> >+ >+<section anchor="toc_byte" title="The TOC Byte"> >+<t anchor="R1"> >+A well-formed Opus packet MUST contain at least one byte [R1]. >+This byte forms a table-of-contents (TOC) header that signals which of the >+ various modes and configurations a given packet uses. >+It is composed of a configuration number, "config", a stereo flag, "s", and a >+ frame count code, "c", arranged as illustrated in >+ <xref target="toc_byte_fig"/>. >+A description of each of these fields follows. >+</t> >+ >+<figure anchor="toc_byte_fig" title="The TOC Byte"> >+<artwork align="center"><![CDATA[ >+ 0 >+ 0 1 2 3 4 5 6 7 >++-+-+-+-+-+-+-+-+ >+| config |s| c | >++-+-+-+-+-+-+-+-+ >+]]></artwork> >+</figure> >+ >+<t> >+The top five bits of the TOC byte, labeled "config", encode one of 32 possible >+ configurations of operating mode, audio bandwidth, and frame size. >+As described, the LP (SILK) layer and MDCT (CELT) layer can be combined in three possible >+ operating modes: >+<list style="numbers"> >+<t>A SILK-only mode for use in low bitrate connections with an audio bandwidth >+ of WB or less,</t> >+<t>A Hybrid (SILK+CELT) mode for SWB or FB speech at medium bitrates, and</t> >+<t>A CELT-only mode for very low delay speech transmission as well as music >+ transmission (NB to FB).</t> >+</list> >+The 32 possible configurations each identify which one of these operating modes >+ the packet uses, as well as the audio bandwidth and the frame size. >+<xref target="config_bits"/> lists the parameters for each configuration. >+</t> >+<texttable anchor="config_bits" title="TOC Byte Configuration Parameters"> >+<ttcol>Configuration Number(s)</ttcol> >+<ttcol>Mode</ttcol> >+<ttcol>Bandwidth</ttcol> >+<ttcol>Frame Sizes</ttcol> >+<c>0...3</c> <c>SILK-only</c> <c>NB</c> <c>10, 20, 40, 60 ms</c> >+<c>4...7</c> <c>SILK-only</c> <c>MB</c> <c>10, 20, 40, 60 ms</c> >+<c>8...11</c> <c>SILK-only</c> <c>WB</c> <c>10, 20, 40, 60 ms</c> >+<c>12...13</c> <c>Hybrid</c> <c>SWB</c> <c>10, 20 ms</c> >+<c>14...15</c> <c>Hybrid</c> <c>FB</c> <c>10, 20 ms</c> >+<c>16...19</c> <c>CELT-only</c> <c>NB</c> <c>2.5, 5, 10, 20 ms</c> >+<c>20...23</c> <c>CELT-only</c> <c>WB</c> <c>2.5, 5, 10, 20 ms</c> >+<c>24...27</c> <c>CELT-only</c> <c>SWB</c> <c>2.5, 5, 10, 20 ms</c> >+<c>28...31</c> <c>CELT-only</c> <c>FB</c> <c>2.5, 5, 10, 20 ms</c> >+</texttable> >+<t> >+The configuration numbers in each range (e.g., 0...3 for NB SILK-only) >+ correspond to the various choices of frame size, in the same order. >+For example, configuration 0 has a 10 ms frame size and configuration 3 >+ has a 60 ms frame size. >+</t> >+ >+<t> >+One additional bit, labeled "s", signals mono vs. stereo, with 0 indicating >+ mono and 1 indicating stereo. >+</t> >+ >+<t> >+The remaining two bits of the TOC byte, labeled "c", code the number of frames >+ per packet (codes 0 to 3) as follows: >+<list style="symbols"> >+<t>0: 1 frame in the packet</t> >+<t>1: 2 frames in the packet, each with equal compressed size</t> >+<t>2: 2 frames in the packet, with different compressed sizes</t> >+<t>3: an arbitrary number of frames in the packet</t> >+</list> >+This draft refers to a packet as a code 0 packet, code 1 packet, etc., based on >+ the value of "c". >+</t> >+ >+</section> >+ >+<section title="Frame Packing"> >+ >+<t> >+This section describes how frames are packed according to each possible value >+ of "c" in the TOC byte. >+</t> >+ >+<section anchor="frame-length-coding" title="Frame Length Coding"> >+<t> >+When a packet contains multiple VBR frames (i.e., code 2 or 3), the compressed >+ length of one or more of these frames is indicated with a one- or two-byte >+ sequence, with the meaning of the first byte as follows: >+<list style="symbols"> >+<t>0: No frame (discontinuous transmission (DTX) or lost packet)</t> >+<t>1...251: Length of the frame in bytes</t> >+<t>252...255: A second byte is needed. The total length is (second_byte*4)+first_byte</t> >+</list> >+</t> >+ >+<t> >+The special length 0 indicates that no frame is available, either because it >+ was dropped during transmission by some intermediary or because the encoder >+ chose not to transmit it. >+Any Opus frame in any mode MAY have a length of 0. >+</t> >+ >+<t> >+The maximum representable length is 255*4+255=1275 bytes. >+For 20 ms frames, this represents a bitrate of 510 kb/s, which is >+ approximately the highest useful rate for lossily compressed fullband stereo >+ music. >+Beyond this point, lossless codecs are more appropriate. >+It is also roughly the maximum useful rate of the MDCT layer, as shortly >+ thereafter quality no longer improves with additional bits due to limitations >+ on the codebook sizes. >+</t> >+ >+<t anchor="R2"> >+No length is transmitted for the last frame in a VBR packet, or for any of the >+ frames in a CBR packet, as it can be inferred from the total size of the >+ packet and the size of all other data in the packet. >+However, the length of any individual frame MUST NOT exceed >+ 1275 bytes [R2], to allow for repacketization by gateways, >+ conference bridges, or other software. >+</t> >+</section> >+ >+<section title="Code 0: One Frame in the Packet"> >+ >+<t> >+For code 0 packets, the TOC byte is immediately followed by N-1 bytes >+ of compressed data for a single frame (where N is the size of the packet), >+ as illustrated in <xref target="code0_packet"/>. >+</t> >+<figure anchor="code0_packet" title="A Code 0 Packet" align="center"> >+<artwork align="center"><![CDATA[ >+ 0 1 2 3 >+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| config |s|0|0| | >++-+-+-+-+-+-+-+-+ | >+| Compressed frame 1 (N-1 bytes)... : >+: | >+| | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+]]></artwork> >+</figure> >+</section> >+ >+<section title="Code 1: Two Frames in the Packet, Each with Equal Compressed Size"> >+<t anchor="R3"> >+For code 1 packets, the TOC byte is immediately followed by the >+ (N-1)/2 bytes of compressed data for the first frame, followed by >+ (N-1)/2 bytes of compressed data for the second frame, as illustrated in >+ <xref target="code1_packet"/>. >+The number of payload bytes available for compressed data, N-1, MUST be even >+ for all code 1 packets [R3]. >+</t> >+<figure anchor="code1_packet" title="A Code 1 Packet" align="center"> >+<artwork align="center"><![CDATA[ >+ 0 1 2 3 >+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| config |s|0|1| | >++-+-+-+-+-+-+-+-+ : >+| Compressed frame 1 ((N-1)/2 bytes)... | >+: +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| | | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ : >+| Compressed frame 2 ((N-1)/2 bytes)... | >+: +-+-+-+-+-+-+-+-+ >+| | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+]]></artwork> >+</figure> >+</section> >+ >+<section title="Code 2: Two Frames in the Packet, with Different Compressed Sizes"> >+<t anchor="R4"> >+For code 2 packets, the TOC byte is followed by a one- or two-byte sequence >+ indicating the length of the first frame (marked N1 in <xref target='code2_packet'/>), >+ followed by N1 bytes of compressed data for the first frame. >+The remaining N-N1-2 or N-N1-3 bytes are the compressed data for the >+ second frame. >+This is illustrated in <xref target="code2_packet"/>. >+A code 2 packet MUST contain enough bytes to represent a valid length. >+For example, a 1-byte code 2 packet is always invalid, and a 2-byte code 2 >+ packet whose second byte is in the range 252...255 is also invalid. >+The length of the first frame, N1, MUST also be no larger than the size of the >+ payload remaining after decoding that length for all code 2 packets [R4]. >+This makes, for example, a 2-byte code 2 packet with a second byte in the range >+ 1...251 invalid as well (the only valid 2-byte code 2 packet is one where the >+ length of both frames is zero). >+</t> >+<figure anchor="code2_packet" title="A Code 2 Packet" align="center"> >+<artwork align="center"><![CDATA[ >+ 0 1 2 3 >+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| config |s|1|0| N1 (1-2 bytes): | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ : >+| Compressed frame 1 (N1 bytes)... | >+: +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| | | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | >+| Compressed frame 2... : >+: | >+| | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+]]></artwork> >+</figure> >+</section> >+ >+<section title="Code 3: A Signaled Number of Frames in the Packet"> >+<t anchor="R5"> >+Code 3 packets signal the number of frames, as well as additional >+ padding, called "Opus padding" to indicate that this padding is added at the >+ Opus layer, rather than at the transport layer. >+Code 3 packets MUST have at least 2 bytes [R6,R7]. >+The TOC byte is followed by a byte encoding the number of frames in the packet >+ in bits 2 to 7 (marked "M" in <xref target='frame_count_byte'/>), with bit 1 indicating whether >+ or not Opus padding is inserted (marked "p" in <xref target='frame_count_byte'/>), and bit 0 >+ indicating VBR (marked "v" in <xref target='frame_count_byte'/>). >+M MUST NOT be zero, and the audio duration contained within a packet MUST NOT >+ exceed 120 ms [R5]. >+This limits the maximum frame count for any frame size to 48 (for 2.5 ms >+ frames), with lower limits for longer frame sizes. >+<xref target="frame_count_byte"/> illustrates the layout of the frame count >+ byte. >+</t> >+<figure anchor="frame_count_byte" title="The frame count byte"> >+<artwork align="center"><![CDATA[ >+ 0 >+ 0 1 2 3 4 5 6 7 >++-+-+-+-+-+-+-+-+ >+|v|p| M | >++-+-+-+-+-+-+-+-+ >+]]></artwork> >+</figure> >+<t> >+When Opus padding is used, the number of bytes of padding is encoded in the >+ bytes following the frame count byte. >+Values from 0...254 indicate that 0...254 bytes of padding are included, >+ in addition to the byte(s) used to indicate the size of the padding. >+If the value is 255, then the size of the additional padding is 254 bytes, >+ plus the padding value encoded in the next byte. >+There MUST be at least one more byte in the packet in this case [R6,R7]. >+The additional padding bytes appear at the end of the packet, and MUST be set >+ to zero by the encoder to avoid creating a covert channel. >+The decoder MUST accept any value for the padding bytes, however. >+</t> >+<t> >+Although this encoding provides multiple ways to indicate a given number of >+ padding bytes, each uses a different number of bytes to indicate the padding >+ size, and thus will increase the total packet size by a different amount. >+For example, to add 255 bytes to a packet, set the padding bit, p, to 1, insert >+ a single byte after the frame count byte with a value of 254, and append 254 >+ padding bytes with the value zero to the end of the packet. >+To add 256 bytes to a packet, set the padding bit to 1, insert two bytes after >+ the frame count byte with the values 255 and 0, respectively, and append 254 >+ padding bytes with the value zero to the end of the packet. >+By using the value 255 multiple times, it is possible to create a packet of any >+ specific, desired size. >+Let P be the number of header bytes used to indicate the padding size plus the >+ number of padding bytes themselves (i.e., P is the total number of bytes added >+ to the packet). >+Then P MUST be no more than N-2 [R6,R7]. >+</t> >+<t anchor="R6"> >+In the CBR case, let R=N-2-P be the number of bytes remaining in the packet >+ after subtracting the (optional) padding. >+Then the compressed length of each frame in bytes is equal to R/M. >+The value R MUST be a non-negative integer multiple of M [R6]. >+The compressed data for all M frames follows, each of size >+ R/M bytes, as illustrated in <xref target="code3cbr_packet"/>. >+</t> >+ >+<figure anchor="code3cbr_packet" title="A CBR Code 3 Packet" align="center"> >+<artwork align="center"><![CDATA[ >+ 0 1 2 3 >+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| config |s|1|1|0|p| M | Padding length (Optional) : >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| | >+: Compressed frame 1 (R/M bytes)... : >+| | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| | >+: Compressed frame 2 (R/M bytes)... : >+| | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| | >+: ... : >+| | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| | >+: Compressed frame M (R/M bytes)... : >+| | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+: Opus Padding (Optional)... | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+]]></artwork> >+</figure> >+ >+<t anchor="R7"> >+In the VBR case, the (optional) padding length is followed by M-1 frame >+ lengths (indicated by "N1" to "N[M-1]" in <xref target='code3vbr_packet'/>), each encoded in a >+ one- or two-byte sequence as described above. >+The packet MUST contain enough data for the M-1 lengths after removing the >+ (optional) padding, and the sum of these lengths MUST be no larger than the >+ number of bytes remaining in the packet after decoding them [R7]. >+The compressed data for all M frames follows, each frame consisting of the >+ indicated number of bytes, with the final frame consuming any remaining bytes >+ before the final padding, as illustrated in <xref target="code3cbr_packet"/>. >+The number of header bytes (TOC byte, frame count byte, padding length bytes, >+ and frame length bytes), plus the signaled length of the first M-1 frames themselves, >+ plus the signaled length of the padding MUST be no larger than N, the total size of the >+ packet. >+</t> >+ >+<figure anchor="code3vbr_packet" title="A VBR Code 3 Packet" align="center"> >+<artwork align="center"><![CDATA[ >+ 0 1 2 3 >+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| config |s|1|1|1|p| M | Padding length (Optional) : >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+: N1 (1-2 bytes): N2 (1-2 bytes): ... : N[M-1] | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| | >+: Compressed frame 1 (N1 bytes)... : >+| | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| | >+: Compressed frame 2 (N2 bytes)... : >+| | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| | >+: ... : >+| | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| | >+: Compressed frame M... : >+| | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+: Opus Padding (Optional)... | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+]]></artwork> >+</figure> >+</section> >+</section> >+ >+<section anchor="examples" title="Examples"> >+<t> >+Simplest case, one NB mono 20 ms SILK frame: >+</t> >+ >+<figure anchor='framing_example_1'> >+<artwork><![CDATA[ >+ 0 1 2 3 >+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| 1 |0|0|0| compressed data... : >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+]]></artwork> >+</figure> >+ >+<t> >+Two FB mono 5 ms CELT frames of the same compressed size: >+</t> >+ >+<figure anchor='framing_example_2'> >+<artwork><![CDATA[ >+ 0 1 2 3 >+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| 29 |0|0|1| compressed data... : >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+]]></artwork> >+</figure> >+ >+<t> >+Two FB mono 20 ms Hybrid frames of different compressed size: >+</t> >+ >+<figure anchor='framing_example_3'> >+<artwork><![CDATA[ >+ 0 1 2 3 >+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| 15 |0|1|1|1|0| 2 | N1 | | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | >+| compressed data... : >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+]]></artwork> >+</figure> >+ >+<t> >+Four FB stereo 20 ms CELT frames of the same compressed size: >+</t> >+ >+<figure anchor='framing_example_4'> >+<artwork><![CDATA[ >+ 0 1 2 3 >+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| 31 |1|1|1|0|0| 4 | compressed data... : >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+]]></artwork> >+</figure> >+</section> >+ >+<section anchor="malformed-packets" title="Receiving Malformed Packets"> >+<t> >+A receiver MUST NOT process packets which violate any of the rules above as >+ normal Opus packets. >+They are reserved for future applications, such as in-band headers (containing >+ metadata, etc.). >+Packets which violate these constraints may cause implementations of >+ <spanx style="emph">this</spanx> specification to treat them as malformed, and >+ discard them. >+</t> >+<t> >+These constraints are summarized here for reference: >+<list style="format [R%d]"> >+<t>Packets are at least one byte.</t> >+<t>No implicit frame length is larger than 1275 bytes.</t> >+<t>Code 1 packets have an odd total length, N, so that (N-1)/2 is an >+ integer.</t> >+<t>Code 2 packets have enough bytes after the TOC for a valid frame >+ length, and that length is no larger than the number of bytes remaining in the >+ packet.</t> >+<t>Code 3 packets contain at least one frame, but no more than 120 ms >+ of audio total.</t> >+<t>The length of a CBR code 3 packet, N, is at least two bytes, the number of >+ bytes added to indicate the padding size plus the trailing padding bytes >+ themselves, P, is no more than N-2, and the frame count, M, satisfies >+ the constraint that (N-2-P) is a non-negative integer multiple of M.</t> >+<t>VBR code 3 packets are large enough to contain all the header bytes (TOC >+ byte, frame count byte, any padding length bytes, and any frame length bytes), >+ plus the length of the first M-1 frames, plus any trailing padding bytes.</t> >+</list> >+</t> >+</section> >+ >+</section> >+ >+<section title="Opus Decoder"> >+<t> >+The Opus decoder consists of two main blocks: the SILK decoder and the CELT >+ decoder. >+At any given time, one or both of the SILK and CELT decoders may be active. >+The output of the Opus decode is the sum of the outputs from the SILK and CELT >+ decoders with proper sample rate conversion and delay compensation on the SILK >+ side, and optional decimation (when decoding to sample rates less than >+ 48 kHz) on the CELT side, as illustrated in the block diagram below. >+</t> >+<figure> >+<artwork> >+<![CDATA[ >+ +---------+ +------------+ >+ | SILK | | Sample | >+ +->| Decoder |--->| Rate |----+ >+Bit- +---------+ | | | | Conversion | v >+stream | Range |---+ +---------+ +------------+ /---\ Audio >+------->| Decoder | | + |------> >+ | |---+ +---------+ +------------+ \---/ >+ +---------+ | | CELT | | Decimation | ^ >+ +->| Decoder |--->| (Optional) |----+ >+ | | | | >+ +---------+ +------------+ >+]]> >+</artwork> >+</figure> >+ >+<section anchor="range-decoder" title="Range Decoder"> >+<t> >+Opus uses an entropy coder based on range coding <xref target="range-coding"></xref> >+<xref target="Martin79"></xref>, >+which is itself a rediscovery of the FIFO arithmetic code introduced by <xref target="coding-thesis"></xref>. >+It is very similar to arithmetic encoding, except that encoding is done with >+digits in any base instead of with bits, >+so it is faster when using larger bases (i.e., a byte). All of the >+calculations in the range coder must use bit-exact integer arithmetic. >+</t> >+<t> >+Symbols may also be coded as "raw bits" packed directly into the bitstream, >+ bypassing the range coder. >+These are packed backwards starting at the end of the frame, as illustrated in >+ <xref target="rawbits-example"/>. >+This reduces complexity and makes the stream more resilient to bit errors, as >+ corruption in the raw bits will not desynchronize the decoding process, unlike >+ corruption in the input to the range decoder. >+Raw bits are only used in the CELT layer. >+</t> >+ >+<figure anchor="rawbits-example" title="Illustrative example of packing range >+ coder and raw bits data"> >+<artwork align="center"><![CDATA[ >+ 0 1 2 3 >+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| Range coder data (packed MSB to LSB) -> : >++ + >+: : >++ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+: | <- Boundary occurs at an arbitrary bit position : >++-+-+-+ + >+: <- Raw bits data (packed LSB to MSB) | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+]]></artwork> >+</figure> >+ >+<t> >+Each symbol coded by the range coder is drawn from a finite alphabet and coded >+ in a separate "context", which describes the size of the alphabet and the >+ relative frequency of each symbol in that alphabet. >+</t> >+<t> >+Suppose there is a context with n symbols, identified with an index that ranges >+ from 0 to n-1. >+The parameters needed to encode or decode symbol k in this context are >+ represented by a three-tuple (fl[k], fh[k], ft), with >+ 0 <= fl[k] < fh[k] <= ft <= 65535. >+The values of this tuple are derived from the probability model for the >+ symbol, represented by traditional "frequency counts". >+Because Opus uses static contexts these are not updated as symbols are decoded. >+Let f[i] be the frequency of symbol i. >+Then the three-tuple corresponding to symbol k is given by >+</t> >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+ k-1 n-1 >+ __ __ >+fl[k] = \ f[i], fh[k] = fl[k] + f[k], ft = \ f[i] >+ /_ /_ >+ i=0 i=0 >+]]></artwork> >+</figure> >+<t> >+The range decoder extracts the symbols and integers encoded using the range >+ encoder in <xref target="range-encoder"/>. >+The range decoder maintains an internal state vector composed of the two-tuple >+ (val, rng), representing the difference between the high end of the >+ current range and the actual coded value, minus one, and the size of the >+ current range, respectively. >+Both val and rng are 32-bit unsigned integer values. >+</t> >+ >+<section anchor="range-decoder-init" title="Range Decoder Initialization"> >+<t> >+Let b0 be the first input byte (or zero if there are no bytes in this Opus >+ frame). >+The decoder initializes rng to 128 and initializes val to >+ (127 - (b0>>1)), where (b0>>1) is the top 7 bits of the >+ first input byte. >+It saves the remaining bit, (b0&1), for use in the renormalization >+ procedure described in <xref target="range-decoder-renorm"/>, which the >+ decoder invokes immediately after initialization to read additional bits and >+ establish the invariant that rng > 2**23. >+</t> >+</section> >+ >+<section anchor="decoding-symbols" title="Decoding Symbols"> >+<t> >+Decoding a symbol is a two-step process. >+The first step determines a 16-bit unsigned value fs, which lies within the >+ range of some symbol in the current context. >+The second step updates the range decoder state with the three-tuple >+ (fl[k], fh[k], ft) corresponding to that symbol. >+</t> >+<t> >+The first step is implemented by ec_decode() (entdec.c), which computes >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+ val >+fs = ft - min(------ + 1, ft) . >+ rng/ft >+]]></artwork> >+</figure> >+The divisions here are integer division. >+</t> >+<t> >+The decoder then identifies the symbol in the current context corresponding to >+ fs; i.e., the value of k whose three-tuple (fl[k], fh[k], ft) >+ satisfies fl[k] <= fs < fh[k]. >+It uses this tuple to update val according to >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+ rng >+val = val - --- * (ft - fh[k]) . >+ ft >+]]></artwork> >+</figure> >+If fl[k] is greater than zero, then the decoder updates rng using >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+ rng >+rng = --- * (fh[k] - fl[k]) . >+ ft >+]]></artwork> >+</figure> >+Otherwise, it updates rng using >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+ rng >+rng = rng - --- * (ft - fh[k]) . >+ ft >+]]></artwork> >+</figure> >+</t> >+<t> >+Using a special case for the first symbol (rather than the last symbol, as is >+ commonly done in other arithmetic coders) ensures that all the truncation >+ error from the finite precision arithmetic accumulates in symbol 0. >+This makes the cost of coding a 0 slightly smaller, on average, than its >+ estimated probability indicates and makes the cost of coding any other symbol >+ slightly larger. >+When contexts are designed so that 0 is the most probable symbol, which is >+ often the case, this strategy minimizes the inefficiency introduced by the >+ finite precision. >+It also makes some of the special-case decoding routines in >+ <xref target="decoding-alternate"/> particularly simple. >+</t> >+<t> >+After the updates, implemented by ec_dec_update() (entdec.c), the decoder >+ normalizes the range using the procedure in the next section, and returns the >+ index k. >+</t> >+ >+<section anchor="range-decoder-renorm" title="Renormalization"> >+<t> >+To normalize the range, the decoder repeats the following process, implemented >+ by ec_dec_normalize() (entdec.c), until rng > 2**23. >+If rng is already greater than 2**23, the entire process is skipped. >+First, it sets rng to (rng<<8). >+Then it reads the next byte of the Opus frame and forms an 8-bit value sym, >+ using the left-over bit buffered from the previous byte as the high bit >+ and the top 7 bits of the byte just read as the other 7 bits of sym. >+The remaining bit in the byte just read is buffered for use in the next >+ iteration. >+If no more input bytes remain, it uses zero bits instead. >+See <xref target="range-decoder-init"/> for the initialization used to process >+ the first byte. >+Then, it sets >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+val = ((val<<8) + (255-sym)) & 0x7FFFFFFF . >+]]></artwork> >+</figure> >+</t> >+<t> >+It is normal and expected that the range decoder will read several bytes >+ into the raw bits data (if any) at the end of the packet by the time the frame >+ is completely decoded, as illustrated in <xref target="finalize-example"/>. >+This same data MUST also be returned as raw bits when requested. >+The encoder is expected to terminate the stream in such a way that the decoder >+ will decode the intended values regardless of the data contained in the raw >+ bits. >+<xref target="encoder-finalizing"/> describes a procedure for doing this. >+If the range decoder consumes all of the bytes belonging to the current frame, >+ it MUST continue to use zero when any further input bytes are required, even >+ if there is additional data in the current packet from padding or other >+ frames. >+</t> >+ >+<figure anchor="finalize-example" title="Illustrative example of raw bits >+ overlapping range coder data"> >+<artwork align="center"><![CDATA[ >+ n n+1 n+2 n+3 >+ 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+: | <----------- Overlap region ------------> | : >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+ ^ ^ >+ | End of data buffered by the range coder | >+...-----------------------------------------------+ >+ | >+ | End of data consumed by raw bits >+ +-------------------------------------------------------... >+]]></artwork> >+</figure> >+</section> >+</section> >+ >+<section anchor="decoding-alternate" title="Alternate Decoding Methods"> >+<t> >+The reference implementation uses three additional decoding methods that are >+ exactly equivalent to the above, but make assumptions and simplifications that >+ allow for a more efficient implementation. >+</t> >+<section anchor="ec_decode_bin" title="ec_decode_bin()"> >+<t> >+The first is ec_decode_bin() (entdec.c), defined using the parameter ftb >+ instead of ft. >+It is mathematically equivalent to calling ec_decode() with >+ ft = (1<<ftb), but avoids one of the divisions. >+</t> >+</section> >+<section anchor="ec_dec_bit_logp" title="ec_dec_bit_logp()"> >+<t> >+The next is ec_dec_bit_logp() (entdec.c), which decodes a single binary symbol, >+ replacing both the ec_decode() and ec_dec_update() steps. >+The context is described by a single parameter, logp, which is the absolute >+ value of the base-2 logarithm of the probability of a "1". >+It is mathematically equivalent to calling ec_decode() with >+ ft = (1<<logp), followed by ec_dec_update() with >+ the 3-tuple (fl[k] = 0, >+ fh[k] = (1<<logp) - 1, >+ ft = (1<<logp)) if the returned value >+ of fs is less than (1<<logp) - 1 (a "0" was decoded), and with >+ (fl[k] = (1<<logp) - 1, >+ fh[k] = ft = (1<<logp)) otherwise (a "1" was >+ decoded). >+The implementation requires no multiplications or divisions. >+</t> >+</section> >+<section anchor="ec_dec_icdf" title="ec_dec_icdf()"> >+<t> >+The last is ec_dec_icdf() (entdec.c), which decodes a single symbol with a >+ table-based context of up to 8 bits, also replacing both the ec_decode() and >+ ec_dec_update() steps, as well as the search for the decoded symbol in between. >+The context is described by two parameters, an icdf >+ ("inverse" cumulative distribution function) table and ftb. >+As with ec_decode_bin(), (1<<ftb) is equivalent to ft. >+idcf[k], on the other hand, stores (1<<ftb)-fh[k], which is equal to >+ (1<<ftb) - fl[k+1]. >+fl[0] is assumed to be 0, and the table is terminated by a value of 0 (where >+ fh[k] == ft). >+</t> >+<t> >+The function is mathematically equivalent to calling ec_decode() with >+ ft = (1<<ftb), using the returned value fs to search the table >+ for the first entry where fs < (1<<ftb)-icdf[k], and >+ calling ec_dec_update() with >+ fl[k] = (1<<ftb) - icdf[k-1] (or 0 >+ if k == 0), fh[k] = (1<<ftb) - idcf[k], >+ and ft = (1<<ftb). >+Combining the search with the update allows the division to be replaced by a >+ series of multiplications (which are usually much cheaper), and using an >+ inverse CDF allows the use of an ftb as large as 8 in an 8-bit table without >+ any special cases. >+This is the primary interface with the range decoder in the SILK layer, though >+ it is used in a few places in the CELT layer as well. >+</t> >+<t> >+Although icdf[k] is more convenient for the code, the frequency counts, f[k], >+ are a more natural representation of the probability distribution function >+ (PDF) for a given symbol. >+Therefore this draft lists the latter, not the former, when describing the >+ context in which a symbol is coded as a list, e.g., {4, 4, 4, 4}/16 for a >+ uniform context with four possible values and ft = 16. >+The value of ft after the slash is always the sum of the entries in the PDF, >+ but is included for convenience. >+Contexts with identical probabilities, f[k]/ft, but different values of ft >+ (or equivalently, ftb) are not the same, and cannot, in general, be used in >+ place of one another. >+An icdf table is also not capable of representing a PDF where the first symbol >+ has 0 probability. >+In such contexts, ec_dec_icdf() can decode the symbol by using a table that >+ drops the entries for any initial zero-probability values and adding the >+ constant offset of the first value with a non-zero probability to its return >+ value. >+</t> >+</section> >+</section> >+ >+<section anchor="decoding-bits" title="Decoding Raw Bits"> >+<t> >+The raw bits used by the CELT layer are packed at the end of the packet, with >+ the least significant bit of the first value packed in the least significant >+ bit of the last byte, filling up to the most significant bit in the last byte, >+ continuing on to the least significant bit of the penultimate byte, and so on. >+The reference implementation reads them using ec_dec_bits() (entdec.c). >+Because the range decoder must read several bytes ahead in the stream, as >+ described in <xref target="range-decoder-renorm"/>, the input consumed by the >+ raw bits may overlap with the input consumed by the range coder, and a decoder >+ MUST allow this. >+The format should render it impossible to attempt to read more raw bits than >+ there are actual bits in the frame, though a decoder may wish to check for >+ this and report an error. >+</t> >+</section> >+ >+<section anchor="ec_dec_uint" title="Decoding Uniformly Distributed Integers"> >+<t> >+The function ec_dec_uint() (entdec.c) decodes one of ft equiprobable values in >+ the range 0 to (ft - 1), inclusive, each with a frequency of 1, >+ where ft may be as large as (2**32 - 1). >+Because ec_decode() is limited to a total frequency of (2**16 - 1), >+ it splits up the value into a range coded symbol representing up to 8 of the >+ high bits, and, if necessary, raw bits representing the remainder of the >+ value. >+The limit of 8 bits in the range coded symbol is a trade-off between >+ implementation complexity, modeling error (since the symbols no longer truly >+ have equal coding cost), and rounding error introduced by the range coder >+ itself (which gets larger as more bits are included). >+Using raw bits reduces the maximum number of divisions required in the worst >+ case, but means that it may be possible to decode a value outside the range >+ 0 to (ft - 1), inclusive. >+</t> >+ >+<t> >+ec_dec_uint() takes a single, positive parameter, ft, which is not necessarily >+ a power of two, and returns an integer, t, whose value lies between 0 and >+ (ft - 1), inclusive. >+Let ftb = ilog(ft - 1), i.e., the number of bits required >+ to store (ft - 1) in two's complement notation. >+If ftb is 8 or less, then t is decoded with t = ec_decode(ft), and >+ the range coder state is updated using the three-tuple (t, t + 1, >+ ft). >+</t> >+<t> >+If ftb is greater than 8, then the top 8 bits of t are decoded using >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+t = ec_decode(((ft - 1) >> (ftb - 8)) + 1) , >+]]></artwork> >+</figure> >+ the decoder state is updated using the three-tuple >+ (t, t + 1, >+ ((ft - 1) >> (ftb - 8)) + 1), >+ and the remaining bits are decoded as raw bits, setting >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+t = (t << (ftb - 8)) | ec_dec_bits(ftb - 8) . >+]]></artwork> >+</figure> >+If, at this point, t >= ft, then the current frame is corrupt. >+In that case, the decoder should assume there has been an error in the coding, >+ decoding, or transmission and SHOULD take measures to conceal the >+ error and/or report to the application that the error has occurred. >+</t> >+ >+</section> >+ >+<section anchor="decoder-tell" title="Current Bit Usage"> >+<t> >+The bit allocation routines in the CELT decoder need a conservative upper bound >+ on the number of bits that have been used from the current frame thus far, >+ including both range coder bits and raw bits. >+This drives allocation decisions that must match those made in the encoder. >+The upper bound is computed in the reference implementation to whole-bit >+ precision by the function ec_tell() (entcode.h) and to fractional 1/8th bit >+ precision by the function ec_tell_frac() (entcode.c). >+Like all operations in the range coder, it must be implemented in a bit-exact >+ manner, and must produce exactly the same value returned by the same functions >+ in the encoder after encoding the same symbols. >+</t> >+<t> >+ec_tell() is guaranteed to return ceil(ec_tell_frac()/8.0). >+In various places the codec will check to ensure there is enough room to >+ contain a symbol before attempting to decode it. >+In practice, although the number of bits used so far is an upper bound, >+ decoding a symbol whose probability model suggests it has a worst-case cost of >+ p 1/8th bits may actually advance the return value of ec_tell_frac() by >+ p-1, p, or p+1 1/8th bits, due to approximation error in that upper bound, >+ truncation error in the range coder, and for large values of ft, modeling >+ error in ec_dec_uint(). >+</t> >+<t> >+However, this error is bounded, and periodic calls to ec_tell() or >+ ec_tell_frac() at precisely defined points in the decoding process prevent it >+ from accumulating. >+For a range coder symbol that requires a whole number of bits (i.e., >+ for which ft/(fh[k] - fl[k]) is a power of two), where there are at >+ least p 1/8th bits available, decoding the symbol will never cause ec_tell() or >+ ec_tell_frac() to exceed the size of the frame ("bust the budget"). >+In this case the return value of ec_tell_frac() will only advance by more than >+ p 1/8th bits if there was an additional, fractional number of bits remaining, >+ and it will never advance beyond the next whole-bit boundary, which is safe, >+ since frames always contain a whole number of bits. >+However, when p is not a whole number of bits, an extra 1/8th bit is required >+ to ensure that decoding the symbol will not bust the budget. >+</t> >+<t> >+The reference implementation keeps track of the total number of whole bits that >+ have been processed by the decoder so far in the variable nbits_total, >+ including the (possibly fractional) number of bits that are currently >+ buffered, but not consumed, inside the range coder. >+nbits_total is initialized to 9 just before the initial range renormalization >+ process completes (or equivalently, it can be initialized to 33 after the >+ first renormalization). >+The extra two bits over the actual amount buffered by the range coder >+ guarantees that it is an upper bound and that there is enough room for the >+ encoder to terminate the stream. >+Each iteration through the range coder's renormalization loop increases >+ nbits_total by 8. >+Reading raw bits increases nbits_total by the number of raw bits read. >+</t> >+ >+<section anchor="ec_tell" title="ec_tell()"> >+<t> >+The whole number of bits buffered in rng may be estimated via lg = ilog(rng). >+ec_tell() then becomes a simple matter of removing these bits from the total. >+It returns (nbits_total - lg). >+</t> >+<t> >+In a newly initialized decoder, before any symbols have been read, this reports >+ that 1 bit has been used. >+This is the bit reserved for termination of the encoder. >+</t> >+</section> >+ >+<section anchor="ec_tell_frac" title="ec_tell_frac()"> >+<t> >+ec_tell_frac() estimates the number of bits buffered in rng to fractional >+ precision. >+Since rng must be greater than 2**23 after renormalization, lg must be at least >+ 24. >+Let >+<figure align="center"> >+<artwork align="center"> >+<![CDATA[ >+r_Q15 = rng >> (lg-16) , >+]]></artwork> >+</figure> >+ so that 32768 <= r_Q15 < 65536, an unsigned Q15 value representing the >+ fractional part of rng. >+Then the following procedure can be used to add one bit of precision to lg. >+First, update >+<figure align="center"> >+<artwork align="center"> >+<![CDATA[ >+r_Q15 = (r_Q15*r_Q15) >> 15 . >+]]></artwork> >+</figure> >+Then add the 16th bit of r_Q15 to lg via >+<figure align="center"> >+<artwork align="center"> >+<![CDATA[ >+lg = 2*lg + (r_Q15 >> 16) . >+]]></artwork> >+</figure> >+Finally, if this bit was a 1, reduce r_Q15 by a factor of two via >+<figure align="center"> >+<artwork align="center"> >+<![CDATA[ >+r_Q15 = r_Q15 >> 1 , >+]]></artwork> >+</figure> >+ so that it once again lies in the range 32768 <= r_Q15 < 65536. >+</t> >+<t> >+This procedure is repeated three times to extend lg to 1/8th bit precision. >+ec_tell_frac() then returns (nbits_total*8 - lg). >+</t> >+</section> >+ >+</section> >+ >+</section> >+ >+<section anchor="silk_decoder_outline" title="SILK Decoder"> >+<t> >+The decoder's LP layer uses a modified version of the SILK codec (herein simply >+ called "SILK"), which runs a decoded excitation signal through adaptive >+ long-term and short-term prediction synthesis filters. >+It runs at NB, MB, and WB sample rates internally. >+When used in a SWB or FB Hybrid frame, the LP layer itself still only runs in >+ WB. >+</t> >+ >+<section title="SILK Decoder Modules"> >+<t> >+An overview of the decoder is given in <xref target="silk_decoder_figure"/>. >+</t> >+<figure align="center" anchor="silk_decoder_figure" title="SILK Decoder"> >+<artwork align="center"> >+<![CDATA[ >+ +---------+ +------------+ >+-->| Range |--->| Decode |---------------------------+ >+ 1 | Decoder | 2 | Parameters |----------+ 5 | >+ +---------+ +------------+ 4 | | >+ 3 | | | >+ \/ \/ \/ >+ +------------+ +------------+ +------------+ >+ | Generate |-->| LTP |-->| LPC | >+ | Excitation | | Synthesis | | Synthesis | >+ +------------+ +------------+ +------------+ >+ ^ | >+ | | >+ +-------------------+----------------+ >+ | 6 >+ | +------------+ +-------------+ >+ +-->| Stereo |-->| Sample Rate |--> >+ | Unmixing | 7 | Conversion | 8 >+ +------------+ +-------------+ >+ >+1: Range encoded bitstream >+2: Coded parameters >+3: Pulses, LSBs, and signs >+4: Pitch lags, Long-Term Prediction (LTP) coefficients >+5: Linear Predictive Coding (LPC) coefficients and gains >+6: Decoded signal (mono or mid-side stereo) >+7: Unmixed signal (mono or left-right stereo) >+8: Resampled signal >+]]> >+</artwork> >+</figure> >+ >+<t> >+The decoder feeds the bitstream (1) to the range decoder from >+ <xref target="range-decoder"/>, and then decodes the parameters in it (2) >+ using the procedures detailed in >+ Sections <xref format="counter" target="silk_header_bits"/> >+ through <xref format="counter" target="silk_signs"/>. >+These parameters (3, 4, 5) are used to generate an excitation signal (see >+ <xref target="silk_excitation_reconstruction"/>), which is fed to an optional >+ long-term prediction (LTP) filter (voiced frames only, see >+ <xref target="silk_ltp_synthesis"/>) and then a short-term prediction filter >+ (see <xref target="silk_lpc_synthesis"/>), producing the decoded signal (6). >+For stereo streams, the mid-side representation is converted to separate left >+ and right channels (7). >+The result is finally resampled to the desired output sample rate (e.g., >+ 48 kHz) so that the resampled signal (8) can be mixed with the CELT >+ layer. >+</t> >+ >+</section> >+ >+<section anchor="silk_layer_organization" title="LP Layer Organization"> >+ >+<t> >+Internally, the LP layer of a single Opus frame is composed of either a single >+ 10 ms regular SILK frame or between one and three 20 ms regular SILK >+ frames. >+A stereo Opus frame may double the number of regular SILK frames (up to a total >+ of six), since it includes separate frames for a mid channel and, optionally, >+ a side channel. >+Optional Low Bit-Rate Redundancy (LBRR) frames, which are reduced-bitrate >+ encodings of previous SILK frames, may be included to aid in recovery from >+ packet loss. >+If present, these appear before the regular SILK frames. >+They are in most respects identical to regular, active SILK frames, except that >+ they are usually encoded with a lower bitrate. >+This draft uses "SILK frame" to refer to either one and "regular SILK frame" if >+ it needs to draw a distinction between the two. >+</t> >+<t> >+Logically, each SILK frame is in turn composed of either two or four 5 ms >+ subframes. >+Various parameters, such as the quantization gain of the excitation and the >+ pitch lag and filter coefficients can vary on a subframe-by-subframe basis. >+Physically, the parameters for each subframe are interleaved in the bitstream, >+ as described in the relevant sections for each parameter. >+</t> >+<t> >+All of these frames and subframes are decoded from the same range coder, with >+ no padding between them. >+Thus packing multiple SILK frames in a single Opus frame saves, on average, >+ half a byte per SILK frame. >+It also allows some parameters to be predicted from prior SILK frames in the >+ same Opus frame, since this does not degrade packet loss robustness (beyond >+ any penalty for merely using fewer, larger packets to store multiple frames). >+</t> >+ >+<t> >+Stereo support in SILK uses a variant of mid-side coding, allowing a mono >+ decoder to simply decode the mid channel. >+However, the data for the two channels is interleaved, so a mono decoder must >+ still unpack the data for the side channel. >+It would be required to do so anyway for Hybrid Opus frames, or to support >+ decoding individual 20 ms frames. >+</t> >+ >+<t> >+<xref target="silk_symbols"/> summarizes the overall grouping of the contents of >+ the LP layer. >+Figures <xref format="counter" target="silk_mono_60ms_frame"/> >+ and <xref format="counter" target="silk_stereo_60ms_frame"/> illustrate >+ the ordering of the various SILK frames for a 60 ms Opus frame, for both >+ mono and stereo, respectively. >+</t> >+ >+<texttable anchor="silk_symbols" >+ title="Organization of the SILK layer of an Opus frame"> >+<ttcol align="center">Symbol(s)</ttcol> >+<ttcol align="center">PDF(s)</ttcol> >+<ttcol align="center">Condition</ttcol> >+ >+<c>Voice Activity Detection (VAD) flags</c> >+<c>{1, 1}/2</c> >+<c/> >+ >+<c>LBRR flag</c> >+<c>{1, 1}/2</c> >+<c/> >+ >+<c>Per-frame LBRR flags</c> >+<c><xref target="silk_lbrr_flag_pdfs"/></c> >+<c><xref target="silk_lbrr_flags"/></c> >+ >+<c>LBRR Frame(s)</c> >+<c><xref target="silk_frame"/></c> >+<c><xref target="silk_lbrr_flags"/></c> >+ >+<c>Regular SILK Frame(s)</c> >+<c><xref target="silk_frame"/></c> >+<c/> >+ >+</texttable> >+ >+<figure align="center" anchor="silk_mono_60ms_frame" >+ title="A 60 ms Mono Frame"> >+<artwork align="center"><![CDATA[ >++---------------------------------+ >+| VAD Flags | >++---------------------------------+ >+| LBRR Flag | >++---------------------------------+ >+| Per-Frame LBRR Flags (Optional) | >++---------------------------------+ >+| LBRR Frame 1 (Optional) | >++---------------------------------+ >+| LBRR Frame 2 (Optional) | >++---------------------------------+ >+| LBRR Frame 3 (Optional) | >++---------------------------------+ >+| Regular SILK Frame 1 | >++---------------------------------+ >+| Regular SILK Frame 2 | >++---------------------------------+ >+| Regular SILK Frame 3 | >++---------------------------------+ >+]]></artwork> >+</figure> >+ >+<figure align="center" anchor="silk_stereo_60ms_frame" >+ title="A 60 ms Stereo Frame"> >+<artwork align="center"><![CDATA[ >++---------------------------------------+ >+| Mid VAD Flags | >++---------------------------------------+ >+| Mid LBRR Flag | >++---------------------------------------+ >+| Side VAD Flags | >++---------------------------------------+ >+| Side LBRR Flag | >++---------------------------------------+ >+| Mid Per-Frame LBRR Flags (Optional) | >++---------------------------------------+ >+| Side Per-Frame LBRR Flags (Optional) | >++---------------------------------------+ >+| Mid LBRR Frame 1 (Optional) | >++---------------------------------------+ >+| Side LBRR Frame 1 (Optional) | >++---------------------------------------+ >+| Mid LBRR Frame 2 (Optional) | >++---------------------------------------+ >+| Side LBRR Frame 2 (Optional) | >++---------------------------------------+ >+| Mid LBRR Frame 3 (Optional) | >++---------------------------------------+ >+| Side LBRR Frame 3 (Optional) | >++---------------------------------------+ >+| Mid Regular SILK Frame 1 | >++---------------------------------------+ >+| Side Regular SILK Frame 1 (Optional) | >++---------------------------------------+ >+| Mid Regular SILK Frame 2 | >++---------------------------------------+ >+| Side Regular SILK Frame 2 (Optional) | >++---------------------------------------+ >+| Mid Regular SILK Frame 3 | >++---------------------------------------+ >+| Side Regular SILK Frame 3 (Optional) | >++---------------------------------------+ >+]]></artwork> >+</figure> >+ >+</section> >+ >+<section anchor="silk_header_bits" title="Header Bits"> >+<t> >+The LP layer begins with two to eight header bits, decoded in silk_Decode() >+ (dec_API.c). >+These consist of one Voice Activity Detection (VAD) bit per frame (up to 3), >+ followed by a single flag indicating the presence of LBRR frames. >+For a stereo packet, these first flags correspond to the mid channel, and a >+ second set of flags is included for the side channel. >+</t> >+<t> >+Because these are the first symbols decoded by the range coder and because they >+ are coded as binary values with uniform probability, they can be extracted >+ directly from the most significant bits of the first byte of compressed data. >+Thus, a receiver can determine if an Opus frame contains any active SILK frames >+ without the overhead of using the range decoder. >+</t> >+</section> >+ >+<section anchor="silk_lbrr_flags" title="Per-Frame LBRR Flags"> >+<t> >+For Opus frames longer than 20 ms, a set of LBRR flags is >+ decoded for each channel that has its LBRR flag set. >+Each set contains one flag per 20 ms SILK frame. >+40 ms Opus frames use the 2-frame LBRR flag PDF from >+ <xref target="silk_lbrr_flag_pdfs"/>, and 60 ms Opus frames use the >+ 3-frame LBRR flag PDF. >+For each channel, the resulting 2- or 3-bit integer contains the corresponding >+ LBRR flag for each frame, packed in order from the LSB to the MSB. >+</t> >+ >+<texttable anchor="silk_lbrr_flag_pdfs" title="LBRR Flag PDFs"> >+<ttcol>Frame Size</ttcol> >+<ttcol>PDF</ttcol> >+<c>40 ms</c> <c>{0, 53, 53, 150}/256</c> >+<c>60 ms</c> <c>{0, 41, 20, 29, 41, 15, 28, 82}/256</c> >+</texttable> >+ >+<t> >+A 10 or 20 ms Opus frame does not contain any per-frame LBRR flags, >+ as there may be at most one LBRR frame per channel. >+The global LBRR flag in the header bits (see <xref target="silk_header_bits"/>) >+ is already sufficient to indicate the presence of that single LBRR frame. >+</t> >+ >+</section> >+ >+<section anchor="silk_lbrr_frames" title="LBRR Frames"> >+<t> >+The LBRR frames, if present, contain an encoded representation of the signal >+ immediately prior to the current Opus frame as if it were encoded with the >+ current mode, frame size, audio bandwidth, and channel count, even if those >+ differ from the prior Opus frame. >+When one of these parameters changes from one Opus frame to the next, this >+ implies that the LBRR frames of the current Opus frame may not be simple >+ drop-in replacements for the contents of the previous Opus frame. >+</t> >+ >+<t> >+For example, when switching from 20 ms to 60 ms, the 60 ms Opus >+ frame may contain LBRR frames covering up to three prior 20 ms Opus >+ frames, even if those frames already contained LBRR frames covering some of >+ the same time periods. >+When switching from 20 ms to 10 ms, the 10 ms Opus frame can >+ contain an LBRR frame covering at most half the prior 20 ms Opus frame, >+ potentially leaving a hole that needs to be concealed from even a single >+ packet loss (see <xref target="Packet Loss Concealment"/>). >+When switching from mono to stereo, the LBRR frames in the first stereo Opus >+ frame MAY contain a non-trivial side channel. >+</t> >+ >+<t> >+In order to properly produce LBRR frames under all conditions, an encoder might >+ need to buffer up to 60 ms of audio and re-encode it during these >+ transitions. >+However, the reference implementation opts to disable LBRR frames at the >+ transition point for simplicity. >+Since transitions are relatively infrequent in normal usage, this does not have >+ a significant impact on packet loss robustness. >+</t> >+ >+<t> >+The LBRR frames immediately follow the LBRR flags, prior to any regular SILK >+ frames. >+<xref target="silk_frame"/> describes their exact contents. >+LBRR frames do not include their own separate VAD flags. >+LBRR frames are only meant to be transmitted for active speech, thus all LBRR >+ frames are treated as active. >+</t> >+ >+<t> >+In a stereo Opus frame longer than 20 ms, although the per-frame LBRR >+ flags for the mid channel are coded as a unit before the per-frame LBRR flags >+ for the side channel, the LBRR frames themselves are interleaved. >+The decoder parses an LBRR frame for the mid channel of a given 20 ms >+ interval (if present) and then immediately parses the corresponding LBRR >+ frame for the side channel (if present), before proceeding to the next >+ 20 ms interval. >+</t> >+</section> >+ >+<section anchor="silk_regular_frames" title="Regular SILK Frames"> >+<t> >+The regular SILK frame(s) follow the LBRR frames (if any). >+<xref target="silk_frame"/> describes their contents, as well. >+Unlike the LBRR frames, a regular SILK frame is coded for each time interval in >+ an Opus frame, even if the corresponding VAD flags are unset. >+For stereo Opus frames longer than 20 ms, the regular mid and side SILK >+ frames for each 20 ms interval are interleaved, just as with the LBRR >+ frames. >+The side frame may be skipped by coding an appropriate flag, as detailed in >+ <xref target="silk_mid_only_flag"/>. >+</t> >+</section> >+ >+<section anchor="silk_frame" title="SILK Frame Contents"> >+<t> >+Each SILK frame includes a set of side information that encodes >+<list style="symbols"> >+<t>The frame type and quantization type (<xref target="silk_frame_type"/>),</t> >+<t>Quantization gains (<xref target="silk_gains"/>),</t> >+<t>Short-term prediction filter coefficients (<xref target="silk_nlsfs"/>),</t> >+<t>A Line Spectral Frequencies (LSF) interpolation weight (<xref target="silk_nlsf_interpolation"/>),</t> >+<t> >+Long-term prediction filter lags and gains (<xref target="silk_ltp_params"/>), >+ and >+</t> >+<t>A linear congruential generator (LCG) seed (<xref target="silk_seed"/>).</t> >+</list> >+The quantized excitation signal (see <xref target="silk_excitation"/>) follows >+ these at the end of the frame. >+<xref target="silk_frame_symbols"/> details the overall organization of a >+ SILK frame. >+</t> >+ >+<texttable anchor="silk_frame_symbols" >+ title="Order of the symbols in an individual SILK frame"> >+<ttcol align="center">Symbol(s)</ttcol> >+<ttcol align="center">PDF(s)</ttcol> >+<ttcol align="center">Condition</ttcol> >+ >+<c>Stereo Prediction Weights</c> >+<c><xref target="silk_stereo_pred_pdfs"/></c> >+<c><xref target="silk_stereo_pred"/></c> >+ >+<c>Mid-only Flag</c> >+<c><xref target="silk_mid_only_pdf"/></c> >+<c><xref target="silk_mid_only_flag"/></c> >+ >+<c>Frame Type</c> >+<c><xref target="silk_frame_type"/></c> >+<c/> >+ >+<c>Subframe Gains</c> >+<c><xref target="silk_gains"/></c> >+<c/> >+ >+<c>Normalized LSF Stage-1 Index</c> >+<c><xref target="silk_nlsf_stage1_pdfs"/></c> >+<c/> >+ >+<c>Normalized LSF Stage-2 Residual</c> >+<c><xref target="silk_nlsf_stage2"/></c> >+<c/> >+ >+<c>Normalized LSF Interpolation Weight</c> >+<c><xref target="silk_nlsf_interp_pdf"/></c> >+<c>20 ms frame</c> >+ >+<c>Primary Pitch Lag</c> >+<c><xref target="silk_ltp_lags"/></c> >+<c>Voiced frame</c> >+ >+<c>Subframe Pitch Contour</c> >+<c><xref target="silk_pitch_contour_pdfs"/></c> >+<c>Voiced frame</c> >+ >+<c>Periodicity Index</c> >+<c><xref target="silk_perindex_pdf"/></c> >+<c>Voiced frame</c> >+ >+<c>LTP Filter</c> >+<c><xref target="silk_ltp_filter_pdfs"/></c> >+<c>Voiced frame</c> >+ >+<c>LTP Scaling</c> >+<c><xref target="silk_ltp_scaling_pdf"/></c> >+<c><xref target="silk_ltp_scaling"/></c> >+ >+<c>LCG Seed</c> >+<c><xref target="silk_seed_pdf"/></c> >+<c/> >+ >+<c>Excitation Rate Level</c> >+<c><xref target="silk_rate_level_pdfs"/></c> >+<c/> >+ >+<c>Excitation Pulse Counts</c> >+<c><xref target="silk_pulse_count_pdfs"/></c> >+<c/> >+ >+<c>Excitation Pulse Locations</c> >+<c><xref target="silk_pulse_locations"/></c> >+<c>Non-zero pulse count</c> >+ >+<c>Excitation LSBs</c> >+<c><xref target="silk_shell_lsb_pdf"/></c> >+<c><xref target="silk_pulse_counts"/></c> >+ >+<c>Excitation Signs</c> >+<c><xref target="silk_sign_pdfs"/></c> >+<c/> >+ >+</texttable> >+ >+<section anchor="silk_stereo_pred" toc="include" >+ title="Stereo Prediction Weights"> >+<t> >+A SILK frame corresponding to the mid channel of a stereo Opus frame begins >+ with a pair of side channel prediction weights, designed such that zeros >+ indicate normal mid-side coupling. >+Since these weights can change on every frame, the first portion of each frame >+ linearly interpolates between the previous weights and the current ones, using >+ zeros for the previous weights if none are available. >+These prediction weights are never included in a mono Opus frame, and the >+ previous weights are reset to zeros on any transition from mono to stereo. >+They are also not included in an LBRR frame for the side channel, even if the >+ LBRR flags indicate the corresponding mid channel was not coded. >+In that case, the previous weights are used, again substituting in zeros if no >+ previous weights are available since the last decoder reset >+ (see <xref target="decoder-reset"/>). >+</t> >+ >+<t> >+To summarize, these weights are coded if and only if >+<list style="symbols"> >+<t>This is a stereo Opus frame (<xref target="toc_byte"/>), and</t> >+<t>The current SILK frame corresponds to the mid channel.</t> >+</list> >+</t> >+ >+<t> >+The prediction weights are coded in three separate pieces, which are decoded >+ by silk_stereo_decode_pred() (decode_stereo_pred.c). >+The first piece jointly codes the high-order part of a table index for both >+ weights. >+The second piece codes the low-order part of each table index. >+The third piece codes an offset used to linearly interpolate between table >+ indices. >+The details are as follows. >+</t> >+ >+<t> >+Let n be an index decoded with the 25-element stage-1 PDF in >+ <xref target="silk_stereo_pred_pdfs"/>. >+Then let i0 and i1 be indices decoded with the stage-2 and stage-3 PDFs in >+ <xref target="silk_stereo_pred_pdfs"/>, respectively, and let i2 and i3 >+ be two more indices decoded with the stage-2 and stage-3 PDFs, all in that >+ order. >+</t> >+ >+<texttable anchor="silk_stereo_pred_pdfs" title="Stereo Weight PDFs"> >+<ttcol align="left">Stage</ttcol> >+<ttcol align="left">PDF</ttcol> >+<c>Stage 1</c> >+<c>{7, 2, 1, 1, 1, >+ 10, 24, 8, 1, 1, >+ 3, 23, 92, 23, 3, >+ 1, 1, 8, 24, 10, >+ 1, 1, 1, 2, 7}/256</c> >+ >+<c>Stage 2</c> >+<c>{85, 86, 85}/256</c> >+ >+<c>Stage 3</c> >+<c>{51, 51, 52, 51, 51}/256</c> >+</texttable> >+ >+<t> >+Then use n, i0, and i2 to form two table indices, wi0 and wi1, according to >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+wi0 = i0 + 3*(n/5) >+wi1 = i2 + 3*(n%5) >+]]></artwork> >+</figure> >+ where the division is integer division. >+The range of these indices is 0 to 14, inclusive. >+Let w[i] be the i'th weight from <xref target="silk_stereo_weights_table"/>. >+Then the two prediction weights, w0_Q13 and w1_Q13, are >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+w1_Q13 = w_Q13[wi1] >+ + ((w_Q13[wi1+1] - w_Q13[wi1])*6554) >> 16)*(2*i3 + 1) >+ >+w0_Q13 = w_Q13[wi0] >+ + ((w_Q13[wi0+1] - w_Q13[wi0])*6554) >> 16)*(2*i1 + 1) >+ - w1_Q13 >+]]></artwork> >+</figure> >+N.b., w1_Q13 is computed first here, because w0_Q13 depends on it. >+The constant 6554 is approximately 0.1 in Q16. >+Although wi0 and wi1 only have 15 possible values, >+ <xref target="silk_stereo_weights_table"/> contains 16 entries to allow >+ interpolation between entry wi0 and (wi0 + 1) (and likewise for wi1). >+</t> >+ >+<texttable anchor="silk_stereo_weights_table" >+ title="Stereo Weight Table"> >+<ttcol align="left">Index</ttcol> >+<ttcol align="right">Weight (Q13)</ttcol> >+ <c>0</c> <c>-13732</c> >+ <c>1</c> <c>-10050</c> >+ <c>2</c> <c>-8266</c> >+ <c>3</c> <c>-7526</c> >+ <c>4</c> <c>-6500</c> >+ <c>5</c> <c>-5000</c> >+ <c>6</c> <c>-2950</c> >+ <c>7</c> <c>-820</c> >+ <c>8</c> <c>820</c> >+ <c>9</c> <c>2950</c> >+<c>10</c> <c>5000</c> >+<c>11</c> <c>6500</c> >+<c>12</c> <c>7526</c> >+<c>13</c> <c>8266</c> >+<c>14</c> <c>10050</c> >+<c>15</c> <c>13732</c> >+</texttable> >+ >+</section> >+ >+<section anchor="silk_mid_only_flag" toc="include" title="Mid-only Flag"> >+<t> >+A flag appears after the stereo prediction weights that indicates if only the >+ mid channel is coded for this time interval. >+It appears only when >+<list style="symbols"> >+<t>This is a stereo Opus frame (see <xref target="toc_byte"/>),</t> >+<t>The current SILK frame corresponds to the mid channel, and</t> >+<t>Either >+<list style="symbols"> >+<t>This is a regular SILK frame where the VAD flags >+ (see <xref target="silk_header_bits"/>) indicate that the corresponding side >+ channel is not active.</t> >+<t> >+This is an LBRR frame where the LBRR flags >+ (see <xref target="silk_header_bits"/> and <xref target="silk_lbrr_flags"/>) >+ indicate that the corresponding side channel is not coded. >+</t> >+</list> >+</t> >+</list> >+It is omitted when there are no stereo weights, for all of the same reasons. >+It is also omitted for a regular SILK frame when the VAD flag of the >+ corresponding side channel frame is set (indicating it is active). >+The side channel must be coded in this case, making the mid-only flag >+ redundant. >+It is also omitted for an LBRR frame when the corresponding LBRR flags >+ indicate the side channel is coded. >+</t> >+ >+<t> >+When the flag is present, the decoder reads a single value using the PDF in >+ <xref target="silk_mid_only_pdf"/>, as implemented in >+ silk_stereo_decode_mid_only() (decode_stereo_pred.c). >+If the flag is set, then there is no corresponding SILK frame for the side >+ channel, the entire decoding process for the side channel is skipped, and >+ zeros are fed to the stereo unmixing process (see >+ <xref target="silk_stereo_unmixing"/>) instead. >+As stated above, LBRR frames still include this flag when the LBRR flag >+ indicates that the side channel is not coded. >+In that case, if this flag is zero (indicating that there should be a side >+ channel), then Packet Loss Concealment (PLC, see >+ <xref target="Packet Loss Concealment"/>) SHOULD be invoked to recover a >+ side channel signal. >+Otherwise, the stereo image will collapse. >+</t> >+ >+<texttable anchor="silk_mid_only_pdf" title="Mid-only Flag PDF"> >+<ttcol align="left">PDF</ttcol> >+<c>{192, 64}/256</c> >+</texttable> >+ >+</section> >+ >+<section anchor="silk_frame_type" toc="include" title="Frame Type"> >+<t> >+Each SILK frame contains a single "frame type" symbol that jointly codes the >+ signal type and quantization offset type of the corresponding frame. >+If the current frame is a regular SILK frame whose VAD bit was not set (an >+ "inactive" frame), then the frame type symbol takes on a value of either 0 or >+ 1 and is decoded using the first PDF in <xref target="silk_frame_type_pdfs"/>. >+If the frame is an LBRR frame or a regular SILK frame whose VAD flag was set >+ (an "active" frame), then the value of the symbol may range from 2 to 5, >+ inclusive, and is decoded using the second PDF in >+ <xref target="silk_frame_type_pdfs"/>. >+<xref target="silk_frame_type_table"/> translates between the value of the >+ frame type symbol and the corresponding signal type and quantization offset >+ type. >+</t> >+ >+<texttable anchor="silk_frame_type_pdfs" title="Frame Type PDFs"> >+<ttcol>VAD Flag</ttcol> >+<ttcol>PDF</ttcol> >+<c>Inactive</c> <c>{26, 230, 0, 0, 0, 0}/256</c> >+<c>Active</c> <c>{0, 0, 24, 74, 148, 10}/256</c> >+</texttable> >+ >+<texttable anchor="silk_frame_type_table" >+ title="Signal Type and Quantization Offset Type from Frame Type"> >+<ttcol>Frame Type</ttcol> >+<ttcol>Signal Type</ttcol> >+<ttcol align="right">Quantization Offset Type</ttcol> >+<c>0</c> <c>Inactive</c> <c>Low</c> >+<c>1</c> <c>Inactive</c> <c>High</c> >+<c>2</c> <c>Unvoiced</c> <c>Low</c> >+<c>3</c> <c>Unvoiced</c> <c>High</c> >+<c>4</c> <c>Voiced</c> <c>Low</c> >+<c>5</c> <c>Voiced</c> <c>High</c> >+</texttable> >+ >+</section> >+ >+<section anchor="silk_gains" toc="include" title="Subframe Gains"> >+<t> >+A separate quantization gain is coded for each 5 ms subframe. >+These gains control the step size between quantization levels of the excitation >+ signal and, therefore, the quality of the reconstruction. >+They are independent of and unrelated to the pitch contours coded for voiced >+ frames. >+The quantization gains are themselves uniformly quantized to 6 bits on a >+ log scale, giving them a resolution of approximately 1.369 dB and a range >+ of approximately 1.94 dB to 88.21 dB. >+</t> >+<t> >+The subframe gains are either coded independently, or relative to the gain from >+ the most recent coded subframe in the same channel. >+Independent coding is used if and only if >+<list style="symbols"> >+<t> >+This is the first subframe in the current SILK frame, and >+</t> >+<t>Either >+<list style="symbols"> >+<t> >+This is the first SILK frame of its type (LBRR or regular) for this channel in >+ the current Opus frame, or >+ </t> >+<t> >+The previous SILK frame of the same type (LBRR or regular) for this channel in >+ the same Opus frame was not coded. >+</t> >+</list> >+</t> >+</list> >+</t> >+ >+<t> >+In an independently coded subframe gain, the 3 most significant bits of the >+ quantization gain are decoded using a PDF selected from >+ <xref target="silk_independent_gain_msb_pdfs"/> based on the decoded signal >+ type (see <xref target="silk_frame_type"/>). >+</t> >+ >+<texttable anchor="silk_independent_gain_msb_pdfs" >+ title="PDFs for Independent Quantization Gain MSB Coding"> >+<ttcol align="left">Signal Type</ttcol> >+<ttcol align="left">PDF</ttcol> >+<c>Inactive</c> <c>{32, 112, 68, 29, 12, 1, 1, 1}/256</c> >+<c>Unvoiced</c> <c>{2, 17, 45, 60, 62, 47, 19, 4}/256</c> >+<c>Voiced</c> <c>{1, 3, 26, 71, 94, 50, 9, 2}/256</c> >+</texttable> >+ >+<t> >+The 3 least significant bits are decoded using a uniform PDF: >+</t> >+<texttable anchor="silk_independent_gain_lsb_pdf" >+ title="PDF for Independent Quantization Gain LSB Coding"> >+<ttcol align="left">PDF</ttcol> >+<c>{32, 32, 32, 32, 32, 32, 32, 32}/256</c> >+</texttable> >+ >+<t> >+These 6 bits are combined to form a value, gain_index, between 0 and 63. >+When the gain for the previous subframe is available, then the current gain is >+ limited as follows: >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+log_gain = max(gain_index, previous_log_gain - 16) . >+]]></artwork> >+</figure> >+This may help some implementations limit the change in precision of their >+ internal LTP history. >+The indices which this clamp applies to cannot simply be removed from the >+ codebook, because previous_log_gain will not be available after packet loss. >+The clamping is skipped after a decoder reset, and in the side channel if the >+ previous frame in the side channel was not coded, since there is no value for >+ previous_log_gain available. >+It MAY also be skipped after packet loss. >+</t> >+ >+<t> >+For subframes which do not have an independent gain (including the first >+ subframe of frames not listed as using independent coding above), the >+ quantization gain is coded relative to the gain from the previous subframe (in >+ the same channel). >+The PDF in <xref target="silk_delta_gain_pdf"/> yields a delta_gain_index value >+ between 0 and 40, inclusive. >+</t> >+<texttable anchor="silk_delta_gain_pdf" >+ title="PDF for Delta Quantization Gain Coding"> >+<ttcol align="left">PDF</ttcol> >+<c>{6, 5, 11, 31, 132, 21, 8, 4, >+ 3, 2, 2, 2, 1, 1, 1, 1, >+ 1, 1, 1, 1, 1, 1, 1, 1, >+ 1, 1, 1, 1, 1, 1, 1, 1, >+ 1, 1, 1, 1, 1, 1, 1, 1, 1}/256</c> >+</texttable> >+<t> >+The following formula translates this index into a quantization gain for the >+ current subframe using the gain from the previous subframe: >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+log_gain = clamp(0, max(2*delta_gain_index - 16, >+ previous_log_gain + delta_gain_index - 4), 63) . >+]]></artwork> >+</figure> >+</t> >+<t> >+silk_gains_dequant() (gain_quant.c) dequantizes log_gain for the k'th subframe >+ and converts it into a linear Q16 scale factor via >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+gain_Q16[k] = silk_log2lin((0x1D1C71*log_gain>>16) + 2090) >+]]></artwork> >+</figure> >+</t> >+<t> >+The function silk_log2lin() (log2lin.c) computes an approximation of >+ 2**(inLog_Q7/128.0), where inLog_Q7 is its Q7 input. >+Let i = inLog_Q7>>7 be the integer part of inLogQ7 and >+ f = inLog_Q7&127 be the fractional part. >+Then >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+(1<<i) + ((-174*f*(128-f)>>16)+f)*((1<<i)>>7) >+]]></artwork> >+</figure> >+ yields the approximate exponential. >+The final Q16 gain values lies between 81920 and 1686110208, inclusive >+ (representing scale factors of 1.25 to 25728, respectively). >+</t> >+</section> >+ >+<section anchor="silk_nlsfs" toc="include" title="Normalized Line Spectral >+ Frequency (LSF) and Linear Predictive Coding (LPC) Coefficients"> >+<t> >+A set of normalized Line Spectral Frequency (LSF) coefficients follow the >+ quantization gains in the bitstream, and represent the Linear Predictive >+ Coding (LPC) coefficients for the current SILK frame. >+Once decoded, the normalized LSFs form an increasing list of Q15 values between >+ 0 and 1. >+These represent the interleaved zeros on the upper half of the unit circle >+ (between 0 and pi, hence "normalized") in the standard decomposition >+ <xref target="line-spectral-pairs"/> of the LPC filter into a symmetric part >+ and an anti-symmetric part (P and Q in <xref target="silk_nlsf2lpc"/>). >+Because of non-linear effects in the decoding process, an implementation SHOULD >+ match the fixed-point arithmetic described in this section exactly. >+An encoder SHOULD also use the same process. >+</t> >+<t> >+The normalized LSFs are coded using a two-stage vector quantizer (VQ) >+ (<xref target="silk_nlsf_stage1"/> and <xref target="silk_nlsf_stage2"/>). >+NB and MB frames use an order-10 predictor, while WB frames use an order-16 >+ predictor, and thus have different sets of tables. >+After reconstructing the normalized LSFs >+ (<xref target="silk_nlsf_reconstruction"/>), the decoder runs them through a >+ stabilization process (<xref target="silk_nlsf_stabilization"/>), interpolates >+ them between frames (<xref target="silk_nlsf_interpolation"/>), converts them >+ back into LPC coefficients (<xref target="silk_nlsf2lpc"/>), and then runs >+ them through further processes to limit the range of the coefficients >+ (<xref target="silk_lpc_range_limit"/>) and the gain of the filter >+ (<xref target="silk_lpc_gain_limit"/>). >+All of this is necessary to ensure the reconstruction process is stable. >+</t> >+ >+<section anchor="silk_nlsf_stage1" title="Normalized LSF Stage 1 Decoding"> >+<t> >+The first VQ stage uses a 32-element codebook, coded with one of the PDFs in >+ <xref target="silk_nlsf_stage1_pdfs"/>, depending on the audio bandwidth and >+ the signal type of the current SILK frame. >+This yields a single index, I1, for the entire frame, which >+<list style="numbers"> >+<t>Indexes an element in a coarse codebook,</t> >+<t>Selects the PDFs for the second stage of the VQ, and</t> >+<t>Selects the prediction weights used to remove intra-frame redundancy from >+ the second stage.</t> >+</list> >+The actual codebook elements are listed in >+ <xref target="silk_nlsf_nbmb_codebook"/> and >+ <xref target="silk_nlsf_wb_codebook"/>, but they are not needed until the last >+ stages of reconstructing the LSF coefficients. >+</t> >+ >+<texttable anchor="silk_nlsf_stage1_pdfs" >+ title="PDFs for Normalized LSF Stage-1 Index Decoding"> >+<ttcol align="left">Audio Bandwidth</ttcol> >+<ttcol align="left">Signal Type</ttcol> >+<ttcol align="left">PDF</ttcol> >+<c>NB or MB</c> <c>Inactive or unvoiced</c> >+<c> >+{44, 34, 30, 19, 21, 12, 11, 3, >+ 3, 2, 16, 2, 2, 1, 5, 2, >+ 1, 3, 3, 1, 1, 2, 2, 2, >+ 3, 1, 9, 9, 2, 7, 2, 1}/256 >+</c> >+<c>NB or MB</c> <c>Voiced</c> >+<c> >+{1, 10, 1, 8, 3, 8, 8, 14, >+13, 14, 1, 14, 12, 13, 11, 11, >+12, 11, 10, 10, 11, 8, 9, 8, >+ 7, 8, 1, 1, 6, 1, 6, 5}/256 >+</c> >+<c>WB</c> <c>Inactive or unvoiced</c> >+<c> >+{31, 21, 3, 17, 1, 8, 17, 4, >+ 1, 18, 16, 4, 2, 3, 1, 10, >+ 1, 3, 16, 11, 16, 2, 2, 3, >+ 2, 11, 1, 4, 9, 8, 7, 3}/256 >+</c> >+<c>WB</c> <c>Voiced</c> >+<c> >+{1, 4, 16, 5, 18, 11, 5, 14, >+15, 1, 3, 12, 13, 14, 14, 6, >+14, 12, 2, 6, 1, 12, 12, 11, >+10, 3, 10, 5, 1, 1, 1, 3}/256 >+</c> >+</texttable> >+ >+</section> >+ >+<section anchor="silk_nlsf_stage2" title="Normalized LSF Stage 2 Decoding"> >+<t> >+A total of 16 PDFs are available for the LSF residual in the second stage: the >+ 8 (a...h) for NB and MB frames given in >+ <xref target="silk_nlsf_stage2_nbmb_pdfs"/>, and the 8 (i...p) for WB frames >+ given in <xref target="silk_nlsf_stage2_wb_pdfs"/>. >+Which PDF is used for which coefficient is driven by the index, I1, >+ decoded in the first stage. >+<xref target="silk_nlsf_nbmb_stage2_cb_sel"/> lists the letter of the >+ corresponding PDF for each normalized LSF coefficient for NB and MB, and >+ <xref target="silk_nlsf_wb_stage2_cb_sel"/> lists the same information for WB. >+</t> >+ >+<texttable anchor="silk_nlsf_stage2_nbmb_pdfs" >+ title="PDFs for NB/MB Normalized LSF Stage-2 Index Decoding"> >+<ttcol align="left">Codebook</ttcol> >+<ttcol align="left">PDF</ttcol> >+<c>a</c> <c>{1, 1, 1, 15, 224, 11, 1, 1, 1}/256</c> >+<c>b</c> <c>{1, 1, 2, 34, 183, 32, 1, 1, 1}/256</c> >+<c>c</c> <c>{1, 1, 4, 42, 149, 55, 2, 1, 1}/256</c> >+<c>d</c> <c>{1, 1, 8, 52, 123, 61, 8, 1, 1}/256</c> >+<c>e</c> <c>{1, 3, 16, 53, 101, 74, 6, 1, 1}/256</c> >+<c>f</c> <c>{1, 3, 17, 55, 90, 73, 15, 1, 1}/256</c> >+<c>g</c> <c>{1, 7, 24, 53, 74, 67, 26, 3, 1}/256</c> >+<c>h</c> <c>{1, 1, 18, 63, 78, 58, 30, 6, 1}/256</c> >+</texttable> >+ >+<texttable anchor="silk_nlsf_stage2_wb_pdfs" >+ title="PDFs for WB Normalized LSF Stage-2 Index Decoding"> >+<ttcol align="left">Codebook</ttcol> >+<ttcol align="left">PDF</ttcol> >+<c>i</c> <c>{1, 1, 1, 9, 232, 9, 1, 1, 1}/256</c> >+<c>j</c> <c>{1, 1, 2, 28, 186, 35, 1, 1, 1}/256</c> >+<c>k</c> <c>{1, 1, 3, 42, 152, 53, 2, 1, 1}/256</c> >+<c>l</c> <c>{1, 1, 10, 49, 126, 65, 2, 1, 1}/256</c> >+<c>m</c> <c>{1, 4, 19, 48, 100, 77, 5, 1, 1}/256</c> >+<c>n</c> <c>{1, 1, 14, 54, 100, 72, 12, 1, 1}/256</c> >+<c>o</c> <c>{1, 1, 15, 61, 87, 61, 25, 4, 1}/256</c> >+<c>p</c> <c>{1, 7, 21, 50, 77, 81, 17, 1, 1}/256</c> >+</texttable> >+ >+<texttable anchor="silk_nlsf_nbmb_stage2_cb_sel" >+ title="Codebook Selection for NB/MB Normalized LSF Stage-2 Index Decoding"> >+<ttcol>I1</ttcol> >+<ttcol>Coefficient</ttcol> >+<c/> >+<c><spanx style="vbare">0 1 2 3 4 5 6 7 8 9</spanx></c> >+<c> 0</c> >+<c><spanx style="vbare">a a a a a a a a a a</spanx></c> >+<c> 1</c> >+<c><spanx style="vbare">b d b c c b c b b b</spanx></c> >+<c> 2</c> >+<c><spanx style="vbare">c b b b b b b b b b</spanx></c> >+<c> 3</c> >+<c><spanx style="vbare">b c c c c b c b b b</spanx></c> >+<c> 4</c> >+<c><spanx style="vbare">c d d d d c c c c c</spanx></c> >+<c> 5</c> >+<c><spanx style="vbare">a f d d c c c c b b</spanx></c> >+<c> g</c> >+<c><spanx style="vbare">a c c c c c c c c b</spanx></c> >+<c> 7</c> >+<c><spanx style="vbare">c d g e e e f e f f</spanx></c> >+<c> 8</c> >+<c><spanx style="vbare">c e f f e f e g e e</spanx></c> >+<c> 9</c> >+<c><spanx style="vbare">c e e h e f e f f e</spanx></c> >+<c>10</c> >+<c><spanx style="vbare">e d d d c d c c c c</spanx></c> >+<c>11</c> >+<c><spanx style="vbare">b f f g e f e f f f</spanx></c> >+<c>12</c> >+<c><spanx style="vbare">c h e g f f f f f f</spanx></c> >+<c>13</c> >+<c><spanx style="vbare">c h f f f f f g f e</spanx></c> >+<c>14</c> >+<c><spanx style="vbare">d d f e e f e f e e</spanx></c> >+<c>15</c> >+<c><spanx style="vbare">c d d f f e e e e e</spanx></c> >+<c>16</c> >+<c><spanx style="vbare">c e e g e f e f f f</spanx></c> >+<c>17</c> >+<c><spanx style="vbare">c f e g f f f e f e</spanx></c> >+<c>18</c> >+<c><spanx style="vbare">c h e f e f e f f f</spanx></c> >+<c>19</c> >+<c><spanx style="vbare">c f e g h g f g f e</spanx></c> >+<c>20</c> >+<c><spanx style="vbare">d g h e g f f g e f</spanx></c> >+<c>21</c> >+<c><spanx style="vbare">c h g e e e f e f f</spanx></c> >+<c>22</c> >+<c><spanx style="vbare">e f f e g g f g f e</spanx></c> >+<c>23</c> >+<c><spanx style="vbare">c f f g f g e g e e</spanx></c> >+<c>24</c> >+<c><spanx style="vbare">e f f f d h e f f e</spanx></c> >+<c>25</c> >+<c><spanx style="vbare">c d e f f g e f f e</spanx></c> >+<c>26</c> >+<c><spanx style="vbare">c d c d d e c d d d</spanx></c> >+<c>27</c> >+<c><spanx style="vbare">b b c c c c c d c c</spanx></c> >+<c>28</c> >+<c><spanx style="vbare">e f f g g g f g e f</spanx></c> >+<c>29</c> >+<c><spanx style="vbare">d f f e e e e d d c</spanx></c> >+<c>30</c> >+<c><spanx style="vbare">c f d h f f e e f e</spanx></c> >+<c>31</c> >+<c><spanx style="vbare">e e f e f g f g f e</spanx></c> >+</texttable> >+ >+<texttable anchor="silk_nlsf_wb_stage2_cb_sel" >+ title="Codebook Selection for WB Normalized LSF Stage-2 Index Decoding"> >+<ttcol>I1</ttcol> >+<ttcol>Coefficient</ttcol> >+<c/> >+<c><spanx style="vbare">0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15</spanx></c> >+<c> 0</c> >+<c><spanx style="vbare">i i i i i i i i i i i i i i i i</spanx></c> >+<c> 1</c> >+<c><spanx style="vbare">k l l l l l k k k k k j j j i l</spanx></c> >+<c> 2</c> >+<c><spanx style="vbare">k n n l p m m n k n m n n m l l</spanx></c> >+<c> 3</c> >+<c><spanx style="vbare">i k j k k j j j j j i i i i i j</spanx></c> >+<c> 4</c> >+<c><spanx style="vbare">i o n m o m p n m m m n n m m l</spanx></c> >+<c> 5</c> >+<c><spanx style="vbare">i l n n m l l n l l l l l l k m</spanx></c> >+<c> 6</c> >+<c><spanx style="vbare">i i i i i i i i i i i i i i i i</spanx></c> >+<c> 7</c> >+<c><spanx style="vbare">i k o l p k n l m n n m l l k l</spanx></c> >+<c> 8</c> >+<c><spanx style="vbare">i o k o o m n m o n m m n l l l</spanx></c> >+<c> 9</c> >+<c><spanx style="vbare">k j i i i i i i i i i i i i i i</spanx></c> >+<c>10</c> >+<c><spanx style="vbare">i j i i i i i i i i i i i i i j</spanx></c> >+<c>11</c> >+<c><spanx style="vbare">k k l m n l l l l l l l k k j l</spanx></c> >+<c>12</c> >+<c><spanx style="vbare">k k l l m l l l l l l l l k j l</spanx></c> >+<c>13</c> >+<c><spanx style="vbare">l m m m o m m n l n m m n m l m</spanx></c> >+<c>14</c> >+<c><spanx style="vbare">i o m n m p n k o n p m m l n l</spanx></c> >+<c>15</c> >+<c><spanx style="vbare">i j i j j j j j j j i i i i j i</spanx></c> >+<c>16</c> >+<c><spanx style="vbare">j o n p n m n l m n m m m l l m</spanx></c> >+<c>17</c> >+<c><spanx style="vbare">j l l m m l l n k l l n n n l m</spanx></c> >+<c>18</c> >+<c><spanx style="vbare">k l l k k k l k j k j k j j j m</spanx></c> >+<c>19</c> >+<c><spanx style="vbare">i k l n l l k k k j j i i i i i</spanx></c> >+<c>20</c> >+<c><spanx style="vbare">l m l n l l k k j j j j j k k m</spanx></c> >+<c>21</c> >+<c><spanx style="vbare">k o l p p m n m n l n l l k l l</spanx></c> >+<c>22</c> >+<c><spanx style="vbare">k l n o o l n l m m l l l l k m</spanx></c> >+<c>23</c> >+<c><spanx style="vbare">j l l m m m m l n n n l j j j j</spanx></c> >+<c>24</c> >+<c><spanx style="vbare">k n l o o m p m m n l m m l l l</spanx></c> >+<c>25</c> >+<c><spanx style="vbare">i o j j i i i i i i i i i i i i</spanx></c> >+<c>26</c> >+<c><spanx style="vbare">i o o l n k n n l m m p p m m m</spanx></c> >+<c>27</c> >+<c><spanx style="vbare">l l p l n m l l l k k l l l k l</spanx></c> >+<c>28</c> >+<c><spanx style="vbare">i i j i i i k j k j j k k k j j</spanx></c> >+<c>29</c> >+<c><spanx style="vbare">i l k n l l k l k j i i j i i j</spanx></c> >+<c>30</c> >+<c><spanx style="vbare">l n n m p n l l k l k k j i j i</spanx></c> >+<c>31</c> >+<c><spanx style="vbare">k l n l m l l l k j k o m i i i</spanx></c> >+</texttable> >+ >+<t> >+Decoding the second stage residual proceeds as follows. >+For each coefficient, the decoder reads a symbol using the PDF corresponding to >+ I1 from either <xref target="silk_nlsf_nbmb_stage2_cb_sel"/> or >+ <xref target="silk_nlsf_wb_stage2_cb_sel"/>, and subtracts 4 from the result >+ to give an index in the range -4 to 4, inclusive. >+If the index is either -4 or 4, it reads a second symbol using the PDF in >+ <xref target="silk_nlsf_ext_pdf"/>, and adds the value of this second symbol >+ to the index, using the same sign. >+This gives the index, I2[k], a total range of -10 to 10, inclusive. >+</t> >+ >+<texttable anchor="silk_nlsf_ext_pdf" >+ title="PDF for Normalized LSF Index Extension Decoding"> >+<ttcol align="left">PDF</ttcol> >+<c>{156, 60, 24, 9, 4, 2, 1}/256</c> >+</texttable> >+ >+<t> >+The decoded indices from both stages are translated back into normalized LSF >+ coefficients in silk_NLSF_decode() (NLSF_decode.c). >+The stage-2 indices represent residuals after both the first stage of the VQ >+ and a separate backwards-prediction step. >+The backwards prediction process in the encoder subtracts a prediction from >+ each residual formed by a multiple of the coefficient that follows it. >+The decoder must undo this process. >+<xref target="silk_nlsf_pred_weights"/> contains lists of prediction weights >+ for each coefficient. >+There are two lists for NB and MB, and another two lists for WB, giving two >+ possible prediction weights for each coefficient. >+</t> >+ >+<texttable anchor="silk_nlsf_pred_weights" >+ title="Prediction Weights for Normalized LSF Decoding"> >+<ttcol align="left">Coefficient</ttcol> >+<ttcol align="right">A</ttcol> >+<ttcol align="right">B</ttcol> >+<ttcol align="right">C</ttcol> >+<ttcol align="right">D</ttcol> >+ <c>0</c> <c>179</c> <c>116</c> <c>175</c> <c>68</c> >+ <c>1</c> <c>138</c> <c>67</c> <c>148</c> <c>62</c> >+ <c>2</c> <c>140</c> <c>82</c> <c>160</c> <c>66</c> >+ <c>3</c> <c>148</c> <c>59</c> <c>176</c> <c>60</c> >+ <c>4</c> <c>151</c> <c>92</c> <c>178</c> <c>72</c> >+ <c>5</c> <c>149</c> <c>72</c> <c>173</c> <c>117</c> >+ <c>6</c> <c>153</c> <c>100</c> <c>174</c> <c>85</c> >+ <c>7</c> <c>151</c> <c>89</c> <c>164</c> <c>90</c> >+ <c>8</c> <c>163</c> <c>92</c> <c>177</c> <c>118</c> >+ <c>9</c> <c/> <c/> <c>174</c> <c>136</c> >+<c>10</c> <c/> <c/> <c>196</c> <c>151</c> >+<c>11</c> <c/> <c/> <c>182</c> <c>142</c> >+<c>12</c> <c/> <c/> <c>198</c> <c>160</c> >+<c>13</c> <c/> <c/> <c>192</c> <c>142</c> >+<c>14</c> <c/> <c/> <c>182</c> <c>155</c> >+</texttable> >+ >+<t> >+The prediction is undone using the procedure implemented in >+ silk_NLSF_residual_dequant() (NLSF_decode.c), which is as follows. >+Each coefficient selects its prediction weight from one of the two lists based >+ on the stage-1 index, I1. >+<xref target="silk_nlsf_nbmb_weight_sel"/> gives the selections for each >+ coefficient for NB and MB, and <xref target="silk_nlsf_wb_weight_sel"/> gives >+ the selections for WB. >+Let d_LPC be the order of the codebook, i.e., 10 for NB and MB, and 16 for WB, >+ and let pred_Q8[k] be the weight for the k'th coefficient selected by this >+ process for 0 <= k < d_LPC-1. >+Then, the stage-2 residual for each coefficient is computed via >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+res_Q10[k] = (k+1 < d_LPC ? (res_Q10[k+1]*pred_Q8[k])>>8 : 0) >+ + ((((I2[k]<<10) - sign(I2[k])*102)*qstep)>>16) , >+]]></artwork> >+</figure> >+ where qstep is the Q16 quantization step size, which is 11796 for NB and MB >+ and 9830 for WB (representing step sizes of approximately 0.18 and 0.15, >+ respectively). >+</t> >+ >+<texttable anchor="silk_nlsf_nbmb_weight_sel" >+ title="Prediction Weight Selection for NB/MB Normalized LSF Decoding"> >+<ttcol>I1</ttcol> >+<ttcol>Coefficient</ttcol> >+<c/> >+<c><spanx style="vbare">0 1 2 3 4 5 6 7 8</spanx></c> >+<c> 0</c> >+<c><spanx style="vbare">A B A A A A A A A</spanx></c> >+<c> 1</c> >+<c><spanx style="vbare">B A A A A A A A A</spanx></c> >+<c> 2</c> >+<c><spanx style="vbare">A A A A A A A A A</spanx></c> >+<c> 3</c> >+<c><spanx style="vbare">B B B A A A A B A</spanx></c> >+<c> 4</c> >+<c><spanx style="vbare">A B A A A A A A A</spanx></c> >+<c> 5</c> >+<c><spanx style="vbare">A B A A A A A A A</spanx></c> >+<c> 6</c> >+<c><spanx style="vbare">B A B B A A A B A</spanx></c> >+<c> 7</c> >+<c><spanx style="vbare">A B B A A B B A A</spanx></c> >+<c> 8</c> >+<c><spanx style="vbare">A A B B A B A B B</spanx></c> >+<c> 9</c> >+<c><spanx style="vbare">A A B B A A B B B</spanx></c> >+<c>10</c> >+<c><spanx style="vbare">A A A A A A A A A</spanx></c> >+<c>11</c> >+<c><spanx style="vbare">A B A B B B B B A</spanx></c> >+<c>12</c> >+<c><spanx style="vbare">A B A B B B B B A</spanx></c> >+<c>13</c> >+<c><spanx style="vbare">A B B B B B B B A</spanx></c> >+<c>14</c> >+<c><spanx style="vbare">B A B B A B B B B</spanx></c> >+<c>15</c> >+<c><spanx style="vbare">A B B B B B A B A</spanx></c> >+<c>16</c> >+<c><spanx style="vbare">A A B B A B A B A</spanx></c> >+<c>17</c> >+<c><spanx style="vbare">A A B B B A B B B</spanx></c> >+<c>18</c> >+<c><spanx style="vbare">A B B A A B B B A</spanx></c> >+<c>19</c> >+<c><spanx style="vbare">A A A B B B A B A</spanx></c> >+<c>20</c> >+<c><spanx style="vbare">A B B A A B A B A</spanx></c> >+<c>21</c> >+<c><spanx style="vbare">A B B A A A B B A</spanx></c> >+<c>22</c> >+<c><spanx style="vbare">A A A A A B B B B</spanx></c> >+<c>23</c> >+<c><spanx style="vbare">A A B B A A A B B</spanx></c> >+<c>24</c> >+<c><spanx style="vbare">A A A B A B B B B</spanx></c> >+<c>25</c> >+<c><spanx style="vbare">A B B B B B B B A</spanx></c> >+<c>26</c> >+<c><spanx style="vbare">A A A A A A A A A</spanx></c> >+<c>27</c> >+<c><spanx style="vbare">A A A A A A A A A</spanx></c> >+<c>28</c> >+<c><spanx style="vbare">A A B A B B A B A</spanx></c> >+<c>29</c> >+<c><spanx style="vbare">B A A B A A A A A</spanx></c> >+<c>30</c> >+<c><spanx style="vbare">A A A B B A B A B</spanx></c> >+<c>31</c> >+<c><spanx style="vbare">B A B B A B B B B</spanx></c> >+</texttable> >+ >+<texttable anchor="silk_nlsf_wb_weight_sel" >+ title="Prediction Weight Selection for WB Normalized LSF Decoding"> >+<ttcol>I1</ttcol> >+<ttcol>Coefficient</ttcol> >+<c/> >+<c><spanx style="vbare">0 1 2 3 4 5 6 7 8 9 10 11 12 13 14</spanx></c> >+<c> 0</c> >+<c><spanx style="vbare">C C C C C C C C C C C C C C D</spanx></c> >+<c> 1</c> >+<c><spanx style="vbare">C C C C C C C C C C C C C C C</spanx></c> >+<c> 2</c> >+<c><spanx style="vbare">C C D C C D D D C D D D D C C</spanx></c> >+<c> 3</c> >+<c><spanx style="vbare">C C C C C C C C C C C C D C C</spanx></c> >+<c> 4</c> >+<c><spanx style="vbare">C D D C D C D D C D D D D D C</spanx></c> >+<c> 5</c> >+<c><spanx style="vbare">C C D C C C C C C C C C C C C</spanx></c> >+<c> 6</c> >+<c><spanx style="vbare">D C C C C C C C C C C D C D C</spanx></c> >+<c> 7</c> >+<c><spanx style="vbare">C D D C C C D C D D D C D C D</spanx></c> >+<c> 8</c> >+<c><spanx style="vbare">C D C D D C D C D C D D D D D</spanx></c> >+<c> 9</c> >+<c><spanx style="vbare">C C C C C C C C C C C C C C D</spanx></c> >+<c>10</c> >+<c><spanx style="vbare">C D C C C C C C C C C C C C C</spanx></c> >+<c>11</c> >+<c><spanx style="vbare">C C D C D D D D D D D C D C C</spanx></c> >+<c>12</c> >+<c><spanx style="vbare">C C D C C D C D C D C C D C C</spanx></c> >+<c>13</c> >+<c><spanx style="vbare">C C C C D D C D C D D D D C C</spanx></c> >+<c>14</c> >+<c><spanx style="vbare">C D C C C D D C D D D C D D D</spanx></c> >+<c>15</c> >+<c><spanx style="vbare">C C D D C C C C C C C C D D C</spanx></c> >+<c>16</c> >+<c><spanx style="vbare">C D D C D C D D D D D C D C C</spanx></c> >+<c>17</c> >+<c><spanx style="vbare">C C D C C C C D C C D D D C C</spanx></c> >+<c>18</c> >+<c><spanx style="vbare">C C C C C C C C C C C C C C D</spanx></c> >+<c>19</c> >+<c><spanx style="vbare">C C C C C C C C C C C C D C C</spanx></c> >+<c>20</c> >+<c><spanx style="vbare">C C C C C C C C C C C C C C C</spanx></c> >+<c>21</c> >+<c><spanx style="vbare">C D C D C D D C D C D C D D C</spanx></c> >+<c>22</c> >+<c><spanx style="vbare">C C D D D D C D D C C D D C C</spanx></c> >+<c>23</c> >+<c><spanx style="vbare">C D D C D C D C D C C C C D C</spanx></c> >+<c>24</c> >+<c><spanx style="vbare">C C C D D C D C D D D D D D D</spanx></c> >+<c>25</c> >+<c><spanx style="vbare">C C C C C C C C C C C C C C D</spanx></c> >+<c>26</c> >+<c><spanx style="vbare">C D D C C C D D C C D D D D D</spanx></c> >+<c>27</c> >+<c><spanx style="vbare">C C C C C D C D D D D C D D D</spanx></c> >+<c>28</c> >+<c><spanx style="vbare">C C C C C C C C C C C C C C D</spanx></c> >+<c>29</c> >+<c><spanx style="vbare">C C C C C C C C C C C C C C D</spanx></c> >+<c>30</c> >+<c><spanx style="vbare">D C C C C C C C C C C D C C C</spanx></c> >+<c>31</c> >+<c><spanx style="vbare">C C D C C D D D C C D C C D C</spanx></c> >+</texttable> >+ >+</section> >+ >+<section anchor="silk_nlsf_reconstruction" >+ title="Reconstructing the Normalized LSF Coefficients"> >+<t> >+Once the stage-1 index I1 and the stage-2 residual res_Q10[] have been decoded, >+ the final normalized LSF coefficients can be reconstructed. >+</t> >+<t> >+The spectral distortion introduced by the quantization of each LSF coefficient >+ varies, so the stage-2 residual is weighted accordingly, using the >+ low-complexity Inverse Harmonic Mean Weighting (IHMW) function proposed in >+ <xref target="laroia-icassp"/>. >+The weights are derived directly from the stage-1 codebook vector. >+Let cb1_Q8[k] be the k'th entry of the stage-1 codebook vector from >+ <xref target="silk_nlsf_nbmb_codebook"/> or >+ <xref target="silk_nlsf_wb_codebook"/>. >+Then for 0 <= k < d_LPC the following expression >+ computes the square of the weight as a Q18 value: >+<figure align="center"> >+<artwork align="center"> >+<![CDATA[ >+w2_Q18[k] = (1024/(cb1_Q8[k] - cb1_Q8[k-1]) >+ + 1024/(cb1_Q8[k+1] - cb1_Q8[k])) << 16 , >+]]> >+</artwork> >+</figure> >+ where cb1_Q8[-1] = 0 and cb1_Q8[d_LPC] = 256, and the >+ division is integer division. >+This is reduced to an unsquared, Q9 value using the following square-root >+ approximation: >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+i = ilog(w2_Q18[k]) >+f = (w2_Q18[k]>>(i-8)) & 127 >+y = ((i&1) ? 32768 : 46214) >> ((32-i)>>1) >+w_Q9[k] = y + ((213*f*y)>>16) >+]]></artwork> >+</figure> >+The constant 46214 here is approximately the square root of 2 in Q15. >+The cb1_Q8[] vector completely determines these weights, and they may be >+ tabulated and stored as 13-bit unsigned values (with a range of 1819 to 5227, >+ inclusive) to avoid computing them when decoding. >+The reference implementation already requires code to compute these weights on >+ unquantized coefficients in the encoder, in silk_NLSF_VQ_weights_laroia() >+ (NLSF_VQ_weights_laroia.c) and its callers, so it reuses that code in the >+ decoder instead of using a pre-computed table to reduce the amount of ROM >+ required. >+</t> >+ >+<texttable anchor="silk_nlsf_nbmb_codebook" >+ title="NB/MB Normalized LSF Stage-1 Codebook Vectors"> >+<ttcol>I1</ttcol> >+<ttcol>Codebook (Q8)</ttcol> >+<c/> >+<c><spanx style="vbare"> 0 1 2 3 4 5 6 7 8 9</spanx></c> >+<c>0</c> >+<c><spanx style="vbare">12 35 60 83 108 132 157 180 206 228</spanx></c> >+<c>1</c> >+<c><spanx style="vbare">15 32 55 77 101 125 151 175 201 225</spanx></c> >+<c>2</c> >+<c><spanx style="vbare">19 42 66 89 114 137 162 184 209 230</spanx></c> >+<c>3</c> >+<c><spanx style="vbare">12 25 50 72 97 120 147 172 200 223</spanx></c> >+<c>4</c> >+<c><spanx style="vbare">26 44 69 90 114 135 159 180 205 225</spanx></c> >+<c>5</c> >+<c><spanx style="vbare">13 22 53 80 106 130 156 180 205 228</spanx></c> >+<c>6</c> >+<c><spanx style="vbare">15 25 44 64 90 115 142 168 196 222</spanx></c> >+<c>7</c> >+<c><spanx style="vbare">19 24 62 82 100 120 145 168 190 214</spanx></c> >+<c>8</c> >+<c><spanx style="vbare">22 31 50 79 103 120 151 170 203 227</spanx></c> >+<c>9</c> >+<c><spanx style="vbare">21 29 45 65 106 124 150 171 196 224</spanx></c> >+<c>10</c> >+<c><spanx style="vbare">30 49 75 97 121 142 165 186 209 229</spanx></c> >+<c>11</c> >+<c><spanx style="vbare">19 25 52 70 93 116 143 166 192 219</spanx></c> >+<c>12</c> >+<c><spanx style="vbare">26 34 62 75 97 118 145 167 194 217</spanx></c> >+<c>13</c> >+<c><spanx style="vbare">25 33 56 70 91 113 143 165 196 223</spanx></c> >+<c>14</c> >+<c><spanx style="vbare">21 34 51 72 97 117 145 171 196 222</spanx></c> >+<c>15</c> >+<c><spanx style="vbare">20 29 50 67 90 117 144 168 197 221</spanx></c> >+<c>16</c> >+<c><spanx style="vbare">22 31 48 66 95 117 146 168 196 222</spanx></c> >+<c>17</c> >+<c><spanx style="vbare">24 33 51 77 116 134 158 180 200 224</spanx></c> >+<c>18</c> >+<c><spanx style="vbare">21 28 70 87 106 124 149 170 194 217</spanx></c> >+<c>19</c> >+<c><spanx style="vbare">26 33 53 64 83 117 152 173 204 225</spanx></c> >+<c>20</c> >+<c><spanx style="vbare">27 34 65 95 108 129 155 174 210 225</spanx></c> >+<c>21</c> >+<c><spanx style="vbare">20 26 72 99 113 131 154 176 200 219</spanx></c> >+<c>22</c> >+<c><spanx style="vbare">34 43 61 78 93 114 155 177 205 229</spanx></c> >+<c>23</c> >+<c><spanx style="vbare">23 29 54 97 124 138 163 179 209 229</spanx></c> >+<c>24</c> >+<c><spanx style="vbare">30 38 56 89 118 129 158 178 200 231</spanx></c> >+<c>25</c> >+<c><spanx style="vbare">21 29 49 63 85 111 142 163 193 222</spanx></c> >+<c>26</c> >+<c><spanx style="vbare">27 48 77 103 133 158 179 196 215 232</spanx></c> >+<c>27</c> >+<c><spanx style="vbare">29 47 74 99 124 151 176 198 220 237</spanx></c> >+<c>28</c> >+<c><spanx style="vbare">33 42 61 76 93 121 155 174 207 225</spanx></c> >+<c>29</c> >+<c><spanx style="vbare">29 53 87 112 136 154 170 188 208 227</spanx></c> >+<c>30</c> >+<c><spanx style="vbare">24 30 52 84 131 150 166 186 203 229</spanx></c> >+<c>31</c> >+<c><spanx style="vbare">37 48 64 84 104 118 156 177 201 230</spanx></c> >+</texttable> >+ >+<texttable anchor="silk_nlsf_wb_codebook" >+ title="WB Normalized LSF Stage-1 Codebook Vectors"> >+<ttcol>I1</ttcol> >+<ttcol>Codebook (Q8)</ttcol> >+<c/> >+<c><spanx style="vbare"> 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15</spanx></c> >+<c>0</c> >+<c><spanx style="vbare"> 7 23 38 54 69 85 100 116 131 147 162 178 193 208 223 239</spanx></c> >+<c>1</c> >+<c><spanx style="vbare">13 25 41 55 69 83 98 112 127 142 157 171 187 203 220 236</spanx></c> >+<c>2</c> >+<c><spanx style="vbare">15 21 34 51 61 78 92 106 126 136 152 167 185 205 225 240</spanx></c> >+<c>3</c> >+<c><spanx style="vbare">10 21 36 50 63 79 95 110 126 141 157 173 189 205 221 237</spanx></c> >+<c>4</c> >+<c><spanx style="vbare">17 20 37 51 59 78 89 107 123 134 150 164 184 205 224 240</spanx></c> >+<c>5</c> >+<c><spanx style="vbare">10 15 32 51 67 81 96 112 129 142 158 173 189 204 220 236</spanx></c> >+<c>6</c> >+<c><spanx style="vbare"> 8 21 37 51 65 79 98 113 126 138 155 168 179 192 209 218</spanx></c> >+<c>7</c> >+<c><spanx style="vbare">12 15 34 55 63 78 87 108 118 131 148 167 185 203 219 236</spanx></c> >+<c>8</c> >+<c><spanx style="vbare">16 19 32 36 56 79 91 108 118 136 154 171 186 204 220 237</spanx></c> >+<c>9</c> >+<c><spanx style="vbare">11 28 43 58 74 89 105 120 135 150 165 180 196 211 226 241</spanx></c> >+<c>10</c> >+<c><spanx style="vbare"> 6 16 33 46 60 75 92 107 123 137 156 169 185 199 214 225</spanx></c> >+<c>11</c> >+<c><spanx style="vbare">11 19 30 44 57 74 89 105 121 135 152 169 186 202 218 234</spanx></c> >+<c>12</c> >+<c><spanx style="vbare">12 19 29 46 57 71 88 100 120 132 148 165 182 199 216 233</spanx></c> >+<c>13</c> >+<c><spanx style="vbare">17 23 35 46 56 77 92 106 123 134 152 167 185 204 222 237</spanx></c> >+<c>14</c> >+<c><spanx style="vbare">14 17 45 53 63 75 89 107 115 132 151 171 188 206 221 240</spanx></c> >+<c>15</c> >+<c><spanx style="vbare"> 9 16 29 40 56 71 88 103 119 137 154 171 189 205 222 237</spanx></c> >+<c>16</c> >+<c><spanx style="vbare">16 19 36 48 57 76 87 105 118 132 150 167 185 202 218 236</spanx></c> >+<c>17</c> >+<c><spanx style="vbare">12 17 29 54 71 81 94 104 126 136 149 164 182 201 221 237</spanx></c> >+<c>18</c> >+<c><spanx style="vbare">15 28 47 62 79 97 115 129 142 155 168 180 194 208 223 238</spanx></c> >+<c>19</c> >+<c><spanx style="vbare"> 8 14 30 45 62 78 94 111 127 143 159 175 192 207 223 239</spanx></c> >+<c>20</c> >+<c><spanx style="vbare">17 30 49 62 79 92 107 119 132 145 160 174 190 204 220 235</spanx></c> >+<c>21</c> >+<c><spanx style="vbare">14 19 36 45 61 76 91 108 121 138 154 172 189 205 222 238</spanx></c> >+<c>22</c> >+<c><spanx style="vbare">12 18 31 45 60 76 91 107 123 138 154 171 187 204 221 236</spanx></c> >+<c>23</c> >+<c><spanx style="vbare">13 17 31 43 53 70 83 103 114 131 149 167 185 203 220 237</spanx></c> >+<c>24</c> >+<c><spanx style="vbare">17 22 35 42 58 78 93 110 125 139 155 170 188 206 224 240</spanx></c> >+<c>25</c> >+<c><spanx style="vbare"> 8 15 34 50 67 83 99 115 131 146 162 178 193 209 224 239</spanx></c> >+<c>26</c> >+<c><spanx style="vbare">13 16 41 66 73 86 95 111 128 137 150 163 183 206 225 241</spanx></c> >+<c>27</c> >+<c><spanx style="vbare">17 25 37 52 63 75 92 102 119 132 144 160 175 191 212 231</spanx></c> >+<c>28</c> >+<c><spanx style="vbare">19 31 49 65 83 100 117 133 147 161 174 187 200 213 227 242</spanx></c> >+<c>29</c> >+<c><spanx style="vbare">18 31 52 68 88 103 117 126 138 149 163 177 192 207 223 239</spanx></c> >+<c>30</c> >+<c><spanx style="vbare">16 29 47 61 76 90 106 119 133 147 161 176 193 209 224 240</spanx></c> >+<c>31</c> >+<c><spanx style="vbare">15 21 35 50 61 73 86 97 110 119 129 141 175 198 218 237</spanx></c> >+</texttable> >+ >+<t> >+Given the stage-1 codebook entry cb1_Q8[], the stage-2 residual res_Q10[], and >+ their corresponding weights, w_Q9[], the reconstructed normalized LSF >+ coefficients are >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+NLSF_Q15[k] = clamp(0, >+ (cb1_Q8[k]<<7) + (res_Q10[k]<<14)/w_Q9[k], 32767) , >+]]></artwork> >+</figure> >+ where the division is integer division. >+However, nothing in either the reconstruction process or the >+ quantization process in the encoder thus far guarantees that the coefficients >+ are monotonically increasing and separated well enough to ensure a stable >+ filter <xref target="Kabal86"/>. >+When using the reference encoder, roughly 2% of frames violate this constraint. >+The next section describes a stabilization procedure used to make these >+ guarantees. >+</t> >+ >+</section> >+ >+<section anchor="silk_nlsf_stabilization" title="Normalized LSF Stabilization"> >+<t> >+The normalized LSF stabilization procedure is implemented in >+ silk_NLSF_stabilize() (NLSF_stabilize.c). >+This process ensures that consecutive values of the normalized LSF >+ coefficients, NLSF_Q15[], are spaced some minimum distance apart >+ (predetermined to be the 0.01 percentile of a large training set). >+<xref target="silk_nlsf_min_spacing"/> gives the minimum spacings for NB and MB >+ and those for WB, where row k is the minimum allowed value of >+ NLSF_Q[k]-NLSF_Q[k-1]. >+For the purposes of computing this spacing for the first and last coefficient, >+ NLSF_Q15[-1] is taken to be 0, and NLSF_Q15[d_LPC] is taken to be 32768. >+</t> >+ >+<texttable anchor="silk_nlsf_min_spacing" >+ title="Minimum Spacing for Normalized LSF Coefficients"> >+<ttcol>Coefficient</ttcol> >+<ttcol align="right">NB and MB</ttcol> >+<ttcol align="right">WB</ttcol> >+ <c>0</c> <c>250</c> <c>100</c> >+ <c>1</c> <c>3</c> <c>3</c> >+ <c>2</c> <c>6</c> <c>40</c> >+ <c>3</c> <c>3</c> <c>3</c> >+ <c>4</c> <c>3</c> <c>3</c> >+ <c>5</c> <c>3</c> <c>3</c> >+ <c>6</c> <c>4</c> <c>5</c> >+ <c>7</c> <c>3</c> <c>14</c> >+ <c>8</c> <c>3</c> <c>14</c> >+ <c>9</c> <c>3</c> <c>10</c> >+<c>10</c> <c>461</c> <c>11</c> >+<c>11</c> <c/> <c>3</c> >+<c>12</c> <c/> <c>8</c> >+<c>13</c> <c/> <c>9</c> >+<c>14</c> <c/> <c>7</c> >+<c>15</c> <c/> <c>3</c> >+<c>16</c> <c/> <c>347</c> >+</texttable> >+ >+<t> >+The procedure starts off by trying to make small adjustments which attempt to >+ minimize the amount of distortion introduced. >+After 20 such adjustments, it falls back to a more direct method which >+ guarantees the constraints are enforced but may require large adjustments. >+</t> >+<t> >+Let NDeltaMin_Q15[k] be the minimum required spacing for the current audio >+ bandwidth from <xref target="silk_nlsf_min_spacing"/>. >+First, the procedure finds the index i where >+ NLSF_Q15[i] - NLSF_Q15[i-1] - NDeltaMin_Q15[i] is the >+ smallest, breaking ties by using the lower value of i. >+If this value is non-negative, then the stabilization stops; the coefficients >+ satisfy all the constraints. >+Otherwise, if i == 0, it sets NLSF_Q15[0] to NDeltaMin_Q15[0], and if >+ i == d_LPC, it sets NLSF_Q15[d_LPC-1] to >+ (32768 - NDeltaMin_Q15[d_LPC]). >+For all other values of i, both NLSF_Q15[i-1] and NLSF_Q15[i] are updated as >+ follows: >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+ i-1 >+ __ >+ min_center_Q15 = (NDeltaMin_Q15[i]>>1) + \ NDeltaMin_Q15[k] >+ /_ >+ k=0 >+ d_LPC >+ __ >+ max_center_Q15 = 32768 - (NDeltaMin_Q15[i]>>1) - \ NDeltaMin_Q15[k] >+ /_ >+ k=i+1 >+center_freq_Q15 = clamp(min_center_Q15[i], >+ (NLSF_Q15[i-1] + NLSF_Q15[i] + 1)>>1, >+ max_center_Q15[i]) >+ >+ NLSF_Q15[i-1] = center_freq_Q15 - (NDeltaMin_Q15[i]>>1) >+ >+ NLSF_Q15[i] = NLSF_Q15[i-1] + NDeltaMin_Q15[i] . >+]]></artwork> >+</figure> >+Then the procedure repeats again, until it has either executed 20 times or >+ has stopped because the coefficients satisfy all the constraints. >+</t> >+<t> >+After the 20th repetition of the above procedure, the following fallback >+ procedure executes once. >+First, the values of NLSF_Q15[k] for 0 <= k < d_LPC >+ are sorted in ascending order. >+Then for each value of k from 0 to d_LPC-1, NLSF_Q15[k] is set to >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+max(NLSF_Q15[k], NLSF_Q15[k-1] + NDeltaMin_Q15[k]) . >+]]></artwork> >+</figure> >+Next, for each value of k from d_LPC-1 down to 0, NLSF_Q15[k] is set to >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+min(NLSF_Q15[k], NLSF_Q15[k+1] - NDeltaMin_Q15[k+1]) . >+]]></artwork> >+</figure> >+</t> >+ >+</section> >+ >+<section anchor="silk_nlsf_interpolation" title="Normalized LSF Interpolation"> >+<t> >+For 20 ms SILK frames, the first half of the frame (i.e., the first two >+ subframes) may use normalized LSF coefficients that are interpolated between >+ the decoded LSFs for the most recent coded frame (in the same channel) and the >+ current frame. >+A Q2 interpolation factor follows the LSF coefficient indices in the bitstream, >+ which is decoded using the PDF in <xref target="silk_nlsf_interp_pdf"/>. >+This happens in silk_decode_indices() (decode_indices.c). >+After either >+<list style="symbols"> >+<t>An uncoded regular SILK frame in the side channel, or</t> >+<t>A decoder reset (see <xref target="decoder-reset"/>),</t> >+</list> >+ the decoder still decodes this factor, but ignores its value and always uses >+ 4 instead. >+For 10 ms SILK frames, this factor is not stored at all. >+</t> >+ >+<texttable anchor="silk_nlsf_interp_pdf" >+ title="PDF for Normalized LSF Interpolation Index"> >+<ttcol>PDF</ttcol> >+<c>{13, 22, 29, 11, 181}/256</c> >+</texttable> >+ >+<t> >+Let n2_Q15[k] be the normalized LSF coefficients decoded by the procedure in >+ <xref target="silk_nlsfs"/>, n0_Q15[k] be the LSF coefficients >+ decoded for the prior frame, and w_Q2 be the interpolation factor. >+Then the normalized LSF coefficients used for the first half of a 20 ms >+ frame, n1_Q15[k], are >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+n1_Q15[k] = n0_Q15[k] + (w_Q2*(n2_Q15[k] - n0_Q15[k]) >> 2) . >+]]></artwork> >+</figure> >+This interpolation is performed in silk_decode_parameters() >+ (decode_parameters.c). >+</t> >+</section> >+ >+<section anchor="silk_nlsf2lpc" >+ title="Converting Normalized LSFs to LPC Coefficients"> >+<t> >+Any LPC filter A(z) can be split into a symmetric part P(z) and an >+ anti-symmetric part Q(z) such that >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+ d_LPC >+ __ -k 1 >+A(z) = 1 - \ a[k] * z = - * (P(z) + Q(z)) >+ /_ 2 >+ k=1 >+]]></artwork> >+</figure> >+with >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+ -d_LPC-1 -1 >+P(z) = A(z) + z * A(z ) >+ >+ -d_LPC-1 -1 >+Q(z) = A(z) - z * A(z ) . >+]]></artwork> >+</figure> >+The even normalized LSF coefficients correspond to a pair of conjugate roots of >+ P(z), while the odd coefficients correspond to a pair of conjugate roots of >+ Q(z), all of which lie on the unit circle. >+In addition, P(z) has a root at pi and Q(z) has a root at 0. >+Thus, they may be reconstructed mathematically from a set of normalized LSF >+ coefficients, n[k], as >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+ d_LPC/2-1 >+ -1 ___ -1 -2 >+P(z) = (1 + z ) * | | (1 - 2*cos(pi*n[2*k])*z + z ) >+ k=0 >+ >+ d_LPC/2-1 >+ -1 ___ -1 -2 >+Q(z) = (1 - z ) * | | (1 - 2*cos(pi*n[2*k+1])*z + z ) >+ k=0 >+]]></artwork> >+</figure> >+</t> >+<t> >+However, SILK performs this reconstruction using a fixed-point approximation so >+ that all decoders can reproduce it in a bit-exact manner to avoid prediction >+ drift. >+The function silk_NLSF2A() (NLSF2A.c) implements this procedure. >+</t> >+<t> >+To start, it approximates cos(pi*n[k]) using a table lookup with linear >+ interpolation. >+The encoder SHOULD use the inverse of this piecewise linear approximation, >+ rather than the true inverse of the cosine function, when deriving the >+ normalized LSF coefficients. >+These values are also re-ordered to improve numerical accuracy when >+ constructing the LPC polynomials. >+</t> >+ >+<texttable anchor="silk_nlsf_orderings" >+ title="LSF Ordering for Polynomial Evaluation"> >+<ttcol>Coefficient</ttcol> >+<ttcol align="right">NB and MB</ttcol> >+<ttcol align="right">WB</ttcol> >+ <c>0</c> <c>0</c> <c>0</c> >+ <c>1</c> <c>9</c> <c>15</c> >+ <c>2</c> <c>6</c> <c>8</c> >+ <c>3</c> <c>3</c> <c>7</c> >+ <c>4</c> <c>4</c> <c>4</c> >+ <c>5</c> <c>5</c> <c>11</c> >+ <c>6</c> <c>8</c> <c>12</c> >+ <c>7</c> <c>1</c> <c>3</c> >+ <c>8</c> <c>2</c> <c>2</c> >+ <c>9</c> <c>7</c> <c>13</c> >+<c>10</c> <c/> <c>10</c> >+<c>11</c> <c/> <c>5</c> >+<c>12</c> <c/> <c>6</c> >+<c>13</c> <c/> <c>9</c> >+<c>14</c> <c/> <c>14</c> >+<c>15</c> <c/> <c>1</c> >+</texttable> >+ >+<t> >+The top 7 bits of each normalized LSF coefficient index a value in the table, >+ and the next 8 bits interpolate between it and the next value. >+Let i = (n[k] >> 8) be the integer index and >+ f = (n[k] & 255) be the fractional part of a given >+ coefficient. >+Then the re-ordered, approximated cosine, c_Q17[ordering[k]], is >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+c_Q17[ordering[k]] = (cos_Q12[i]*256 >+ + (cos_Q12[i+1]-cos_Q12[i])*f + 4) >> 3 , >+]]></artwork> >+</figure> >+ where ordering[k] is the k'th entry of the column of >+ <xref target="silk_nlsf_orderings"/> corresponding to the current audio >+ bandwidth and cos_Q12[i] is the i'th entry of <xref target="silk_cos_table"/>. >+</t> >+ >+<texttable anchor="silk_cos_table" >+ title="Q12 Cosine Table for LSF Conversion"> >+<ttcol align="right">i</ttcol> >+<ttcol align="right">+0</ttcol> >+<ttcol align="right">+1</ttcol> >+<ttcol align="right">+2</ttcol> >+<ttcol align="right">+3</ttcol> >+<c>0</c> >+ <c>4096</c> <c>4095</c> <c>4091</c> <c>4085</c> >+<c>4</c> >+ <c>4076</c> <c>4065</c> <c>4052</c> <c>4036</c> >+<c>8</c> >+ <c>4017</c> <c>3997</c> <c>3973</c> <c>3948</c> >+<c>12</c> >+ <c>3920</c> <c>3889</c> <c>3857</c> <c>3822</c> >+<c>16</c> >+ <c>3784</c> <c>3745</c> <c>3703</c> <c>3659</c> >+<c>20</c> >+ <c>3613</c> <c>3564</c> <c>3513</c> <c>3461</c> >+<c>24</c> >+ <c>3406</c> <c>3349</c> <c>3290</c> <c>3229</c> >+<c>28</c> >+ <c>3166</c> <c>3102</c> <c>3035</c> <c>2967</c> >+<c>32</c> >+ <c>2896</c> <c>2824</c> <c>2751</c> <c>2676</c> >+<c>36</c> >+ <c>2599</c> <c>2520</c> <c>2440</c> <c>2359</c> >+<c>40</c> >+ <c>2276</c> <c>2191</c> <c>2106</c> <c>2019</c> >+<c>44</c> >+ <c>1931</c> <c>1842</c> <c>1751</c> <c>1660</c> >+<c>48</c> >+ <c>1568</c> <c>1474</c> <c>1380</c> <c>1285</c> >+<c>52</c> >+ <c>1189</c> <c>1093</c> <c>995</c> <c>897</c> >+<c>56</c> >+ <c>799</c> <c>700</c> <c>601</c> <c>501</c> >+<c>60</c> >+ <c>401</c> <c>301</c> <c>201</c> <c>101</c> >+<c>64</c> >+ <c>0</c> <c>-101</c> <c>-201</c> <c>-301</c> >+<c>68</c> >+ <c>-401</c> <c>-501</c> <c>-601</c> <c>-700</c> >+<c>72</c> >+ <c>-799</c> <c>-897</c> <c>-995</c> <c>-1093</c> >+<c>76</c> >+<c>-1189</c><c>-1285</c><c>-1380</c><c>-1474</c> >+<c>80</c> >+<c>-1568</c><c>-1660</c><c>-1751</c><c>-1842</c> >+<c>84</c> >+<c>-1931</c><c>-2019</c><c>-2106</c><c>-2191</c> >+<c>88</c> >+<c>-2276</c><c>-2359</c><c>-2440</c><c>-2520</c> >+<c>92</c> >+<c>-2599</c><c>-2676</c><c>-2751</c><c>-2824</c> >+<c>96</c> >+<c>-2896</c><c>-2967</c><c>-3035</c><c>-3102</c> >+<c>100</c> >+<c>-3166</c><c>-3229</c><c>-3290</c><c>-3349</c> >+<c>104</c> >+<c>-3406</c><c>-3461</c><c>-3513</c><c>-3564</c> >+<c>108</c> >+<c>-3613</c><c>-3659</c><c>-3703</c><c>-3745</c> >+<c>112</c> >+<c>-3784</c><c>-3822</c><c>-3857</c><c>-3889</c> >+<c>116</c> >+<c>-3920</c><c>-3948</c><c>-3973</c><c>-3997</c> >+<c>120</c> >+<c>-4017</c><c>-4036</c><c>-4052</c><c>-4065</c> >+<c>124</c> >+<c>-4076</c><c>-4085</c><c>-4091</c><c>-4095</c> >+<c>128</c> >+<c>-4096</c> <c/> <c/> <c/> >+</texttable> >+ >+<t> >+Given the list of cosine values, silk_NLSF2A_find_poly() (NLSF2A.c) >+ computes the coefficients of P and Q, described here via a simple recurrence. >+Let p_Q16[k][j] and q_Q16[k][j] be the coefficients of the products of the >+ first (k+1) root pairs for P and Q, with j indexing the coefficient number. >+Only the first (k+2) coefficients are needed, as the products are symmetric. >+Let p_Q16[0][0] = q_Q16[0][0] = 1<<16, >+ p_Q16[0][1] = -c_Q17[0], q_Q16[0][1] = -c_Q17[1], and >+ d2 = d_LPC/2. >+As boundary conditions, assume >+ p_Q16[k][j] = q_Q16[k][j] = 0 for all >+ j < 0. >+Also, assume p_Q16[k][k+2] = p_Q16[k][k] and >+ q_Q16[k][k+2] = q_Q16[k][k] (because of the symmetry). >+Then, for 0 < k < d2 and 0 <= j <= k+1, >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+p_Q16[k][j] = p_Q16[k-1][j] + p_Q16[k-1][j-2] >+ - ((c_Q17[2*k]*p_Q16[k-1][j-1] + 32768)>>16) , >+ >+q_Q16[k][j] = q_Q16[k-1][j] + q_Q16[k-1][j-2] >+ - ((c_Q17[2*k+1]*q_Q16[k-1][j-1] + 32768)>>16) . >+]]></artwork> >+</figure> >+The use of Q17 values for the cosine terms in an otherwise Q16 expression >+ implicitly scales them by a factor of 2. >+The multiplications in this recurrence may require up to 48 bits of precision >+ in the result to avoid overflow. >+In practice, each row of the recurrence only depends on the previous row, so an >+ implementation does not need to store all of them. >+</t> >+<t> >+silk_NLSF2A() uses the values from the last row of this recurrence to >+ reconstruct a 32-bit version of the LPC filter (without the leading 1.0 >+ coefficient), a32_Q17[k], 0 <= k < d2: >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+a32_Q17[k] = -(q_Q16[d2-1][k+1] - q_Q16[d2-1][k]) >+ - (p_Q16[d2-1][k+1] + p_Q16[d2-1][k])) , >+ >+a32_Q17[d_LPC-k-1] = (q_Q16[d2-1][k+1] - q_Q16[d2-1][k]) >+ - (p_Q16[d2-1][k+1] + p_Q16[d2-1][k])) . >+]]></artwork> >+</figure> >+The sum and difference of two terms from each of the p_Q16 and q_Q16 >+ coefficient lists reflect the (1 + z**-1) and >+ (1 - z**-1) factors of P and Q, respectively. >+The promotion of the expression from Q16 to Q17 implicitly scales the result >+ by 1/2. >+</t> >+</section> >+ >+<section anchor="silk_lpc_range_limit" >+ title="Limiting the Range of the LPC Coefficients"> >+<t> >+The a32_Q17[] coefficients are too large to fit in a 16-bit value, which >+ significantly increases the cost of applying this filter in fixed-point >+ decoders. >+Reducing them to Q12 precision doesn't incur any significant quality loss, >+ but still does not guarantee they will fit. >+silk_NLSF2A() applies up to 10 rounds of bandwidth expansion to limit >+ the dynamic range of these coefficients. >+Even floating-point decoders SHOULD perform these steps, to avoid mismatch. >+</t> >+<t> >+For each round, the process first finds the index k such that abs(a32_Q17[k]) >+ is largest, breaking ties by choosing the lowest value of k. >+Then, it computes the corresponding Q12 precision value, maxabs_Q12, subject to >+ an upper bound to avoid overflow in subsequent computations: >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+maxabs_Q12 = min((maxabs_Q17 + 16) >> 5, 163838) . >+]]></artwork> >+</figure> >+If this is larger than 32767, the procedure derives the chirp factor, >+ sc_Q16[0], to use in the bandwidth expansion as >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+ (maxabs_Q12 - 32767) << 14 >+sc_Q16[0] = 65470 - -------------------------- , >+ (maxabs_Q12 * (k+1)) >> 2 >+]]></artwork> >+</figure> >+ where the division here is integer division. >+This is an approximation of the chirp factor needed to reduce the target >+ coefficient to 32767, though it is both less than 0.999 and, for >+ k > 0 when maxabs_Q12 is much greater than 32767, still slightly >+ too large. >+The upper bound on maxabs_Q12, 163838, was chosen because it is equal to >+ ((2**31 - 1) >> 14) + 32767, i.e., the >+ largest value of maxabs_Q12 that would not overflow the numerator in the >+ equation above when stored in a signed 32-bit integer. >+</t> >+<t> >+silk_bwexpander_32() (bwexpander_32.c) performs the bandwidth expansion (again, >+ only when maxabs_Q12 is greater than 32767) using the following recurrence: >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+ a32_Q17[k] = (a32_Q17[k]*sc_Q16[k]) >> 16 >+ >+sc_Q16[k+1] = (sc_Q16[0]*sc_Q16[k] + 32768) >> 16 >+]]></artwork> >+</figure> >+The first multiply may require up to 48 bits of precision in the result to >+ avoid overflow. >+The second multiply must be unsigned to avoid overflow with only 32 bits of >+ precision. >+The reference implementation uses a slightly more complex formulation that >+ avoids the 32-bit overflow using signed multiplication, but is otherwise >+ equivalent. >+</t> >+<t> >+After 10 rounds of bandwidth expansion are performed, they are simply saturated >+ to 16 bits: >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+a32_Q17[k] = clamp(-32768, (a32_Q17[k] + 16) >> 5, 32767) << 5 . >+]]></artwork> >+</figure> >+Because this performs the actual saturation in the Q12 domain, but converts the >+ coefficients back to the Q17 domain for the purposes of prediction gain >+ limiting, this step must be performed after the 10th round of bandwidth >+ expansion, regardless of whether or not the Q12 version of any coefficient >+ still overflows a 16-bit integer. >+This saturation is not performed if maxabs_Q12 drops to 32767 or less prior to >+ the 10th round. >+</t> >+</section> >+ >+<section anchor="silk_lpc_gain_limit" >+ title="Limiting the Prediction Gain of the LPC Filter"> >+<t> >+The prediction gain of an LPC synthesis filter is the square-root of the output >+ energy when the filter is excited by a unit-energy impulse. >+Even if the Q12 coefficients would fit, the resulting filter may still have a >+ significant gain (especially for voiced sounds), making the filter unstable. >+silk_NLSF2A() applies up to 18 additional rounds of bandwidth expansion to >+ limit the prediction gain. >+Instead of controlling the amount of bandwidth expansion using the prediction >+ gain itself (which may diverge to infinity for an unstable filter), >+ silk_NLSF2A() uses silk_LPC_inverse_pred_gain_QA() (LPC_inv_pred_gain.c) to >+ compute the reflection coefficients associated with the filter. >+The filter is stable if and only if the magnitude of these coefficients is >+ sufficiently less than one. >+The reflection coefficients, rc[k], can be computed using a simple Levinson >+ recurrence, initialized with the LPC coefficients >+ a[d_LPC-1][n] = a[n], and then updated via >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+ rc[k] = -a[k][k] , >+ >+ a[k][n] - a[k][k-n-1]*rc[k] >+a[k-1][n] = --------------------------- . >+ 2 >+ 1 - rc[k] >+]]></artwork> >+</figure> >+</t> >+<t> >+However, silk_LPC_inverse_pred_gain_QA() approximates this using fixed-point >+ arithmetic to guarantee reproducible results across platforms and >+ implementations. >+Since small changes in the coefficients can make a stable filter unstable, it >+ takes the real Q12 coefficients that will be used during reconstruction as >+ input. >+Thus, let >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+a32_Q12[n] = (a32_Q17[n] + 16) >> 5 >+]]></artwork> >+</figure> >+ be the Q12 version of the LPC coefficients that will eventually be used. >+As a simple initial check, the decoder computes the DC response as >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+ d_PLC-1 >+ __ >+DC_resp = \ a32_Q12[n] >+ /_ >+ n=0 >+]]></artwork> >+</figure> >+ and if DC_resp > 4096, the filter is unstable. >+</t> >+<t> >+Increasing the precision of these Q12 coefficients to Q24 for intermediate >+ computations allows more accurate computation of the reflection coefficients, >+ so the decoder initializes the recurrence via >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+a32_Q24[d_LPC-1][n] = a32_Q12[n] << 12 . >+]]></artwork> >+</figure> >+Then for each k from d_LPC-1 down to 0, if >+ abs(a32_Q24[k][k]) > 16773022, the filter is unstable and the >+ recurrence stops. >+The constant 16773022 here is approximately 0.99975 in Q24. >+Otherwise, row k-1 of a32_Q24 is computed from row k as >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+ rc_Q31[k] = -a32_Q24[k][k] << 7 , >+ >+ div_Q30[k] = (1<<30) - (rc_Q31[k]*rc_Q31[k] >> 32) , >+ >+ b1[k] = ilog(div_Q30[k]) , >+ >+ b2[k] = b1[k] - 16 , >+ >+ (1<<29) - 1 >+ inv_Qb2[k] = ----------------------- , >+ div_Q30[k] >> (b2[k]+1) >+ >+ err_Q29[k] = (1<<29) >+ - ((div_Q30[k]<<(15-b2[k]))*inv_Qb2[k] >> 16) , >+ >+ gain_Qb1[k] = ((inv_Qb2[k] << 16) >+ + (err_Q29[k]*inv_Qb2[k] >> 13)) , >+ >+num_Q24[k-1][n] = a32_Q24[k][n] >+ - ((a32_Q24[k][k-n-1]*rc_Q31[k] + (1<<30)) >> 31) , >+ >+a32_Q24[k-1][n] = (num_Q24[k-1][n]*gain_Qb1[k] >+ + (1<<(b1[k]-1))) >> b1[k] , >+]]></artwork> >+</figure> >+ where 0 <= n < k. >+Here, rc_Q30[k] are the reflection coefficients. >+div_Q30[k] is the denominator for each iteration, and gain_Qb1[k] is its >+ multiplicative inverse (with b1[k] fractional bits, where b1[k] ranges from >+ 20 to 31). >+inv_Qb2[k], which ranges from 16384 to 32767, is a low-precision version of >+ that inverse (with b2[k] fractional bits). >+err_Q29[k] is the residual error, ranging from -32763 to 32392, which is used >+ to improve the accuracy. >+The values t_Q24[k-1][n] for each n are the numerators for the next row of >+ coefficients in the recursion, and a32_Q24[k-1][n] is the final version of >+ that row. >+Every multiply in this procedure except the one used to compute gain_Qb1[k] >+ requires more than 32 bits of precision, but otherwise all intermediate >+ results fit in 32 bits or less. >+In practice, because each row only depends on the next one, an implementation >+ does not need to store them all. >+</t> >+<t> >+If abs(a32_Q24[k][k]) <= 16773022 for >+ 0 <= k < d_LPC, then the filter is considered stable. >+However, the problem of determining stability is ill-conditioned when the >+ filter contains several reflection coefficients whose magnitude is very close >+ to one. >+This fixed-point algorithm is not mathematically guaranteed to correctly >+ classify filters as stable or unstable in this case, though it does very well >+ in practice. >+</t> >+<t> >+On round i, 1 <= i <= 18, if the filter passes these >+ stability checks, then this procedure stops, and the final LPC coefficients to >+ use for reconstruction in <xref target="silk_lpc_synthesis"/> are >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+a_Q12[k] = (a32_Q17[k] + 16) >> 5 . >+]]></artwork> >+</figure> >+Otherwise, a round of bandwidth expansion is applied using the same procedure >+ as in <xref target="silk_lpc_range_limit"/>, with >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+sc_Q16[0] = 65536 - (2<<i) . >+]]></artwork> >+</figure> >+During the 15th round, sc_Q16[0] becomes 0 in the above equation, so a_Q12[k] >+ is set to 0 for all k, guaranteeing a stable filter. >+</t> >+</section> >+ >+</section> >+ >+<section anchor="silk_ltp_params" toc="include" >+ title="Long-Term Prediction (LTP) Parameters"> >+<t> >+After the normalized LSF indices and, for 20 ms frames, the LSF >+ interpolation index, voiced frames (see <xref target="silk_frame_type"/>) >+ include additional LTP parameters. >+There is one primary lag index for each SILK frame, but this is refined to >+ produce a separate lag index per subframe using a vector quantizer. >+Each subframe also gets its own prediction gain coefficient. >+</t> >+ >+<section anchor="silk_ltp_lags" title="Pitch Lags"> >+<t> >+The primary lag index is coded either relative to the primary lag of the prior >+ frame in the same channel, or as an absolute index. >+Absolute coding is used if and only if >+<list style="symbols"> >+<t> >+This is the first SILK frame of its type (LBRR or regular) for this channel in >+ the current Opus frame, >+</t> >+<t> >+The previous SILK frame of the same type (LBRR or regular) for this channel in >+ the same Opus frame was not coded, or >+</t> >+<t> >+That previous SILK frame was coded, but was not voiced (see >+ <xref target="silk_frame_type"/>). >+</t> >+</list> >+</t> >+ >+<t> >+With absolute coding, the primary pitch lag may range from 2 ms >+ (inclusive) up to 18 ms (exclusive), corresponding to pitches from >+ 500 Hz down to 55.6 Hz, respectively. >+It is comprised of a high part and a low part, where the decoder reads the high >+ part using the 32-entry codebook in <xref target="silk_abs_pitch_high_pdf"/> >+ and the low part using the codebook corresponding to the current audio >+ bandwidth from <xref target="silk_abs_pitch_low_pdf"/>. >+The final primary pitch lag is then >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+lag = lag_high*lag_scale + lag_low + lag_min >+]]></artwork> >+</figure> >+ where lag_high is the high part, lag_low is the low part, and lag_scale >+ and lag_min are the values from the "Scale" and "Minimum Lag" columns of >+ <xref target="silk_abs_pitch_low_pdf"/>, respectively. >+</t> >+ >+<texttable anchor="silk_abs_pitch_high_pdf" >+ title="PDF for High Part of Primary Pitch Lag"> >+<ttcol align="left">PDF</ttcol> >+<c>{3, 3, 6, 11, 21, 30, 32, 19, >+ 11, 10, 12, 13, 13, 12, 11, 9, >+ 8, 7, 6, 4, 2, 2, 2, 1, >+ 1, 1, 1, 1, 1, 1, 1, 1}/256</c> >+</texttable> >+ >+<texttable anchor="silk_abs_pitch_low_pdf" >+ title="PDF for Low Part of Primary Pitch Lag"> >+<ttcol>Audio Bandwidth</ttcol> >+<ttcol>PDF</ttcol> >+<ttcol>Scale</ttcol> >+<ttcol>Minimum Lag</ttcol> >+<ttcol>Maximum Lag</ttcol> >+<c>NB</c> <c>{64, 64, 64, 64}/256</c> <c>4</c> <c>16</c> <c>144</c> >+<c>MB</c> <c>{43, 42, 43, 43, 42, 43}/256</c> <c>6</c> <c>24</c> <c>216</c> >+<c>WB</c> <c>{32, 32, 32, 32, 32, 32, 32, 32}/256</c> <c>8</c> <c>32</c> <c>288</c> >+</texttable> >+ >+<t> >+All frames that do not use absolute coding for the primary lag index use >+ relative coding instead. >+The decoder reads a single delta value using the 21-entry PDF in >+ <xref target="silk_rel_pitch_pdf"/>. >+If the resulting value is zero, it falls back to the absolute coding procedure >+ from the prior paragraph. >+Otherwise, the final primary pitch lag is then >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+lag = previous_lag + (delta_lag_index - 9) >+]]></artwork> >+</figure> >+ where previous_lag is the primary pitch lag from the most recent frame in the >+ same channel and delta_lag_index is the value just decoded. >+This allows a per-frame change in the pitch lag of -8 to +11 samples. >+The decoder does no clamping at this point, so this value can fall outside the >+ range of 2 ms to 18 ms, and the decoder must use this unclamped >+ value when using relative coding in the next SILK frame (if any). >+However, because an Opus frame can use relative coding for at most two >+ consecutive SILK frames, integer overflow should not be an issue. >+</t> >+ >+<texttable anchor="silk_rel_pitch_pdf" >+ title="PDF for Primary Pitch Lag Change"> >+<ttcol align="left">PDF</ttcol> >+<c>{46, 2, 2, 3, 4, 6, 10, 15, >+ 26, 38, 30, 22, 15, 10, 7, 6, >+ 4, 4, 2, 2, 2}/256</c> >+</texttable> >+ >+<t> >+After the primary pitch lag, a "pitch contour", stored as a single entry from >+ one of four small VQ codebooks, gives lag offsets for each subframe in the >+ current SILK frame. >+The codebook index is decoded using one of the PDFs in >+ <xref target="silk_pitch_contour_pdfs"/> depending on the current frame size >+ and audio bandwidth. >+Tables <xref format="counter" target="silk_pitch_contour_cb_nb10ms"/> >+ through <xref format="counter" target="silk_pitch_contour_cb_mbwb20ms"/> >+ give the corresponding offsets to apply to the primary pitch lag for each >+ subframe given the decoded codebook index. >+</t> >+ >+<texttable anchor="silk_pitch_contour_pdfs" >+ title="PDFs for Subframe Pitch Contour"> >+<ttcol>Audio Bandwidth</ttcol> >+<ttcol>SILK Frame Size</ttcol> >+<ttcol align="right">Codebook Size</ttcol> >+<ttcol>PDF</ttcol> >+<c>NB</c> <c>10 ms</c> <c>3</c> >+<c>{143, 50, 63}/256</c> >+<c>NB</c> <c>20 ms</c> <c>11</c> >+<c>{68, 12, 21, 17, 19, 22, 30, 24, >+ 17, 16, 10}/256</c> >+<c>MB or WB</c> <c>10 ms</c> <c>12</c> >+<c>{91, 46, 39, 19, 14, 12, 8, 7, >+ 6, 5, 5, 4}/256</c> >+<c>MB or WB</c> <c>20 ms</c> <c>34</c> >+<c>{33, 22, 18, 16, 15, 14, 14, 13, >+ 13, 10, 9, 9, 8, 6, 6, 6, >+ 5, 4, 4, 4, 3, 3, 3, 2, >+ 2, 2, 2, 2, 2, 2, 1, 1, >+ 1, 1}/256</c> >+</texttable> >+ >+<texttable anchor="silk_pitch_contour_cb_nb10ms" >+ title="Codebook Vectors for Subframe Pitch Contour: NB, 10 ms Frames"> >+<ttcol>Index</ttcol> >+<ttcol align="right">Subframe Offsets</ttcol> >+<c>0</c> <c><spanx style="vbare"> 0 0</spanx></c> >+<c>1</c> <c><spanx style="vbare"> 1 0</spanx></c> >+<c>2</c> <c><spanx style="vbare"> 0 1</spanx></c> >+</texttable> >+ >+<texttable anchor="silk_pitch_contour_cb_nb20ms" >+ title="Codebook Vectors for Subframe Pitch Contour: NB, 20 ms Frames"> >+<ttcol>Index</ttcol> >+<ttcol align="right">Subframe Offsets</ttcol> >+ <c>0</c> <c><spanx style="vbare"> 0 0 0 0</spanx></c> >+ <c>1</c> <c><spanx style="vbare"> 2 1 0 -1</spanx></c> >+ <c>2</c> <c><spanx style="vbare">-1 0 1 2</spanx></c> >+ <c>3</c> <c><spanx style="vbare">-1 0 0 1</spanx></c> >+ <c>4</c> <c><spanx style="vbare">-1 0 0 0</spanx></c> >+ <c>5</c> <c><spanx style="vbare"> 0 0 0 1</spanx></c> >+ <c>6</c> <c><spanx style="vbare"> 0 0 1 1</spanx></c> >+ <c>7</c> <c><spanx style="vbare"> 1 1 0 0</spanx></c> >+ <c>8</c> <c><spanx style="vbare"> 1 0 0 0</spanx></c> >+ <c>9</c> <c><spanx style="vbare"> 0 0 0 -1</spanx></c> >+<c>10</c> <c><spanx style="vbare"> 1 0 0 -1</spanx></c> >+</texttable> >+ >+<texttable anchor="silk_pitch_contour_cb_mbwb10ms" >+ title="Codebook Vectors for Subframe Pitch Contour: MB or WB, 10 ms Frames"> >+<ttcol>Index</ttcol> >+<ttcol align="right">Subframe Offsets</ttcol> >+ <c>0</c> <c><spanx style="vbare"> 0 0</spanx></c> >+ <c>1</c> <c><spanx style="vbare"> 0 1</spanx></c> >+ <c>2</c> <c><spanx style="vbare"> 1 0</spanx></c> >+ <c>3</c> <c><spanx style="vbare">-1 1</spanx></c> >+ <c>4</c> <c><spanx style="vbare"> 1 -1</spanx></c> >+ <c>5</c> <c><spanx style="vbare">-1 2</spanx></c> >+ <c>6</c> <c><spanx style="vbare"> 2 -1</spanx></c> >+ <c>7</c> <c><spanx style="vbare">-2 2</spanx></c> >+ <c>8</c> <c><spanx style="vbare"> 2 -2</spanx></c> >+ <c>9</c> <c><spanx style="vbare">-2 3</spanx></c> >+<c>10</c> <c><spanx style="vbare"> 3 -2</spanx></c> >+<c>11</c> <c><spanx style="vbare">-3 3</spanx></c> >+</texttable> >+ >+<texttable anchor="silk_pitch_contour_cb_mbwb20ms" >+ title="Codebook Vectors for Subframe Pitch Contour: MB or WB, 20 ms Frames"> >+<ttcol>Index</ttcol> >+<ttcol align="right">Subframe Offsets</ttcol> >+ <c>0</c> <c><spanx style="vbare"> 0 0 0 0</spanx></c> >+ <c>1</c> <c><spanx style="vbare"> 0 0 1 1</spanx></c> >+ <c>2</c> <c><spanx style="vbare"> 1 1 0 0</spanx></c> >+ <c>3</c> <c><spanx style="vbare">-1 0 0 0</spanx></c> >+ <c>4</c> <c><spanx style="vbare"> 0 0 0 1</spanx></c> >+ <c>5</c> <c><spanx style="vbare"> 1 0 0 0</spanx></c> >+ <c>6</c> <c><spanx style="vbare">-1 0 0 1</spanx></c> >+ <c>7</c> <c><spanx style="vbare"> 0 0 0 -1</spanx></c> >+ <c>8</c> <c><spanx style="vbare">-1 0 1 2</spanx></c> >+ <c>9</c> <c><spanx style="vbare"> 1 0 0 -1</spanx></c> >+<c>10</c> <c><spanx style="vbare">-2 -1 1 2</spanx></c> >+<c>11</c> <c><spanx style="vbare"> 2 1 0 -1</spanx></c> >+<c>12</c> <c><spanx style="vbare">-2 0 0 2</spanx></c> >+<c>13</c> <c><spanx style="vbare">-2 0 1 3</spanx></c> >+<c>14</c> <c><spanx style="vbare"> 2 1 -1 -2</spanx></c> >+<c>15</c> <c><spanx style="vbare">-3 -1 1 3</spanx></c> >+<c>16</c> <c><spanx style="vbare"> 2 0 0 -2</spanx></c> >+<c>17</c> <c><spanx style="vbare"> 3 1 0 -2</spanx></c> >+<c>18</c> <c><spanx style="vbare">-3 -1 2 4</spanx></c> >+<c>19</c> <c><spanx style="vbare">-4 -1 1 4</spanx></c> >+<c>20</c> <c><spanx style="vbare"> 3 1 -1 -3</spanx></c> >+<c>21</c> <c><spanx style="vbare">-4 -1 2 5</spanx></c> >+<c>22</c> <c><spanx style="vbare"> 4 2 -1 -3</spanx></c> >+<c>23</c> <c><spanx style="vbare"> 4 1 -1 -4</spanx></c> >+<c>24</c> <c><spanx style="vbare">-5 -1 2 6</spanx></c> >+<c>25</c> <c><spanx style="vbare"> 5 2 -1 -4</spanx></c> >+<c>26</c> <c><spanx style="vbare">-6 -2 2 6</spanx></c> >+<c>27</c> <c><spanx style="vbare">-5 -2 2 5</spanx></c> >+<c>28</c> <c><spanx style="vbare"> 6 2 -1 -5</spanx></c> >+<c>29</c> <c><spanx style="vbare">-7 -2 3 8</spanx></c> >+<c>30</c> <c><spanx style="vbare"> 6 2 -2 -6</spanx></c> >+<c>31</c> <c><spanx style="vbare"> 5 2 -2 -5</spanx></c> >+<c>32</c> <c><spanx style="vbare"> 8 3 -2 -7</spanx></c> >+<c>33</c> <c><spanx style="vbare">-9 -3 3 9</spanx></c> >+</texttable> >+ >+<t> >+The final pitch lag for each subframe is assembled in silk_decode_pitch() >+ (decode_pitch.c). >+Let lag be the primary pitch lag for the current SILK frame, contour_index be >+ index of the VQ codebook, and lag_cb[contour_index][k] be the corresponding >+ entry of the codebook from the appropriate table given above for the k'th >+ subframe. >+Then the final pitch lag for that subframe is >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+pitch_lags[k] = clamp(lag_min, lag + lag_cb[contour_index][k], >+ lag_max) >+]]></artwork> >+</figure> >+ where lag_min and lag_max are the values from the "Minimum Lag" and >+ "Maximum Lag" columns of <xref target="silk_abs_pitch_low_pdf"/>, >+ respectively. >+</t> >+ >+</section> >+ >+<section anchor="silk_ltp_filter" title="LTP Filter Coefficients"> >+<t> >+SILK uses a separate 5-tap pitch filter for each subframe, selected from one >+ of three codebooks. >+The three codebooks each represent different rate-distortion trade-offs, with >+ average rates of 1.61 bits/subframe, 3.68 bits/subframe, and >+ 4.85 bits/subframe, respectively. >+</t> >+ >+<t> >+The importance of the filter coefficients generally depends on two factors: the >+ periodicity of the signal and relative energy between the current subframe and >+ the signal from one period earlier. >+Greater periodicity and decaying energy both lead to more important filter >+ coefficients, and thus should be coded with lower distortion and higher rate. >+These properties are relatively stable over the duration of a single SILK >+ frame, hence all of the subframes in a SILK frame choose their filter from the >+ same codebook. >+This is signaled with an explicitly-coded "periodicity index". >+This immediately follows the subframe pitch lags, and is coded using the >+ 3-entry PDF from <xref target="silk_perindex_pdf"/>. >+</t> >+ >+<texttable anchor="silk_perindex_pdf" title="Periodicity Index PDF"> >+<ttcol>PDF</ttcol> >+<c>{77, 80, 99}/256</c> >+</texttable> >+ >+<t> >+The indices of the filters for each subframe follow. >+They are all coded using the PDF from <xref target="silk_ltp_filter_pdfs"/> >+ corresponding to the periodicity index. >+Tables <xref format="counter" target="silk_ltp_filter_coeffs0"/> >+ through <xref format="counter" target="silk_ltp_filter_coeffs2"/> >+ contain the corresponding filter taps as signed Q7 integers. >+</t> >+ >+<texttable anchor="silk_ltp_filter_pdfs" title="LTP Filter PDFs"> >+<ttcol>Periodicity Index</ttcol> >+<ttcol align="right">Codebook Size</ttcol> >+<ttcol>PDF</ttcol> >+<c>0</c> <c>8</c> <c>{185, 15, 13, 13, 9, 9, 6, 6}/256</c> >+<c>1</c> <c>16</c> <c>{57, 34, 21, 20, 15, 13, 12, 13, >+ 10, 10, 9, 10, 9, 8, 7, 8}/256</c> >+<c>2</c> <c>32</c> <c>{15, 16, 14, 12, 12, 12, 11, 11, >+ 11, 10, 9, 9, 9, 9, 8, 8, >+ 8, 8, 7, 7, 6, 6, 5, 4, >+ 5, 4, 4, 4, 3, 4, 3, 2}/256</c> >+</texttable> >+ >+<texttable anchor="silk_ltp_filter_coeffs0" >+ title="Codebook Vectors for LTP Filter, Periodicity Index 0"> >+<ttcol>Index</ttcol> >+<ttcol align="right">Filter Taps (Q7)</ttcol> >+ <c>0</c> >+<c><spanx style="vbare"> 4 6 24 7 5</spanx></c> >+ <c>1</c> >+<c><spanx style="vbare"> 0 0 2 0 0</spanx></c> >+ <c>2</c> >+<c><spanx style="vbare"> 12 28 41 13 -4</spanx></c> >+ <c>3</c> >+<c><spanx style="vbare"> -9 15 42 25 14</spanx></c> >+ <c>4</c> >+<c><spanx style="vbare"> 1 -2 62 41 -9</spanx></c> >+ <c>5</c> >+<c><spanx style="vbare">-10 37 65 -4 3</spanx></c> >+ <c>6</c> >+<c><spanx style="vbare"> -6 4 66 7 -8</spanx></c> >+ <c>7</c> >+<c><spanx style="vbare"> 16 14 38 -3 33</spanx></c> >+</texttable> >+ >+<texttable anchor="silk_ltp_filter_coeffs1" >+ title="Codebook Vectors for LTP Filter, Periodicity Index 1"> >+<ttcol>Index</ttcol> >+<ttcol align="right">Filter Taps (Q7)</ttcol> >+ >+ <c>0</c> >+<c><spanx style="vbare"> 13 22 39 23 12</spanx></c> >+ <c>1</c> >+<c><spanx style="vbare"> -1 36 64 27 -6</spanx></c> >+ <c>2</c> >+<c><spanx style="vbare"> -7 10 55 43 17</spanx></c> >+ <c>3</c> >+<c><spanx style="vbare"> 1 1 8 1 1</spanx></c> >+ <c>4</c> >+<c><spanx style="vbare"> 6 -11 74 53 -9</spanx></c> >+ <c>5</c> >+<c><spanx style="vbare">-12 55 76 -12 8</spanx></c> >+ <c>6</c> >+<c><spanx style="vbare"> -3 3 93 27 -4</spanx></c> >+ <c>7</c> >+<c><spanx style="vbare"> 26 39 59 3 -8</spanx></c> >+ <c>8</c> >+<c><spanx style="vbare"> 2 0 77 11 9</spanx></c> >+ <c>9</c> >+<c><spanx style="vbare"> -8 22 44 -6 7</spanx></c> >+<c>10</c> >+<c><spanx style="vbare"> 40 9 26 3 9</spanx></c> >+<c>11</c> >+<c><spanx style="vbare"> -7 20 101 -7 4</spanx></c> >+<c>12</c> >+<c><spanx style="vbare"> 3 -8 42 26 0</spanx></c> >+<c>13</c> >+<c><spanx style="vbare">-15 33 68 2 23</spanx></c> >+<c>14</c> >+<c><spanx style="vbare"> -2 55 46 -2 15</spanx></c> >+<c>15</c> >+<c><spanx style="vbare"> 3 -1 21 16 41</spanx></c> >+</texttable> >+ >+<texttable anchor="silk_ltp_filter_coeffs2" >+ title="Codebook Vectors for LTP Filter, Periodicity Index 2"> >+<ttcol>Index</ttcol> >+<ttcol align="right">Filter Taps (Q7)</ttcol> >+ <c>0</c> >+<c><spanx style="vbare"> -6 27 61 39 5</spanx></c> >+ <c>1</c> >+<c><spanx style="vbare">-11 42 88 4 1</spanx></c> >+ <c>2</c> >+<c><spanx style="vbare"> -2 60 65 6 -4</spanx></c> >+ <c>3</c> >+<c><spanx style="vbare"> -1 -5 73 56 1</spanx></c> >+ <c>4</c> >+<c><spanx style="vbare"> -9 19 94 29 -9</spanx></c> >+ <c>5</c> >+<c><spanx style="vbare"> 0 12 99 6 4</spanx></c> >+ <c>6</c> >+<c><spanx style="vbare"> 8 -19 102 46 -13</spanx></c> >+ <c>7</c> >+<c><spanx style="vbare"> 3 2 13 3 2</spanx></c> >+ <c>8</c> >+<c><spanx style="vbare"> 9 -21 84 72 -18</spanx></c> >+ <c>9</c> >+<c><spanx style="vbare">-11 46 104 -22 8</spanx></c> >+<c>10</c> >+<c><spanx style="vbare"> 18 38 48 23 0</spanx></c> >+<c>11</c> >+<c><spanx style="vbare">-16 70 83 -21 11</spanx></c> >+<c>12</c> >+<c><spanx style="vbare"> 5 -11 117 22 -8</spanx></c> >+<c>13</c> >+<c><spanx style="vbare"> -6 23 117 -12 3</spanx></c> >+<c>14</c> >+<c><spanx style="vbare"> 3 -8 95 28 4</spanx></c> >+<c>15</c> >+<c><spanx style="vbare">-10 15 77 60 -15</spanx></c> >+<c>16</c> >+<c><spanx style="vbare"> -1 4 124 2 -4</spanx></c> >+<c>17</c> >+<c><spanx style="vbare"> 3 38 84 24 -25</spanx></c> >+<c>18</c> >+<c><spanx style="vbare"> 2 13 42 13 31</spanx></c> >+<c>19</c> >+<c><spanx style="vbare"> 21 -4 56 46 -1</spanx></c> >+<c>20</c> >+<c><spanx style="vbare"> -1 35 79 -13 19</spanx></c> >+<c>21</c> >+<c><spanx style="vbare"> -7 65 88 -9 -14</spanx></c> >+<c>22</c> >+<c><spanx style="vbare"> 20 4 81 49 -29</spanx></c> >+<c>23</c> >+<c><spanx style="vbare"> 20 0 75 3 -17</spanx></c> >+<c>24</c> >+<c><spanx style="vbare"> 5 -9 44 92 -8</spanx></c> >+<c>25</c> >+<c><spanx style="vbare"> 1 -3 22 69 31</spanx></c> >+<c>26</c> >+<c><spanx style="vbare"> -6 95 41 -12 5</spanx></c> >+<c>27</c> >+<c><spanx style="vbare"> 39 67 16 -4 1</spanx></c> >+<c>28</c> >+<c><spanx style="vbare"> 0 -6 120 55 -36</spanx></c> >+<c>29</c> >+<c><spanx style="vbare">-13 44 122 4 -24</spanx></c> >+<c>30</c> >+<c><spanx style="vbare"> 81 5 11 3 7</spanx></c> >+<c>31</c> >+<c><spanx style="vbare"> 2 0 9 10 88</spanx></c> >+</texttable> >+ >+</section> >+ >+<section anchor="silk_ltp_scaling" title="LTP Scaling Parameter"> >+<t> >+An LTP scaling parameter appears after the LTP filter coefficients if and only >+ if >+<list style="symbols"> >+<t>This is a voiced frame (see <xref target="silk_frame_type"/>), and</t> >+<t>Either >+<list style="symbols"> >+<t> >+This SILK frame corresponds to the first time interval of the >+ current Opus frame for its type (LBRR or regular), or >+</t> >+<t> >+This is an LBRR frame where the LBRR flags (see >+ <xref target="silk_lbrr_flags"/>) indicate the previous LBRR frame in the same >+ channel is not coded. >+</t> >+</list> >+</t> >+</list> >+This allows the encoder to trade off the prediction gain between >+ packets against the recovery time after packet loss. >+Unlike absolute-coding for pitch lags, regular SILK frames that are not at the >+ start of an Opus frame (i.e., that do not correspond to the first 20 ms >+ time interval in Opus frames of 40 or 60 ms) do not include this >+ field, even if the prior frame was not voiced, or (in the case of the side >+ channel) not even coded. >+After an uncoded frame in the side channel, the LTP buffer (see >+ <xref target="silk_ltp_synthesis"/>) is cleared to zero, and is thus in a >+ known state. >+In contrast, LBRR frames do include this field when the prior frame was not >+ coded, since the LTP buffer contains the output of the PLC, which is >+ non-normative. >+</t> >+<t> >+If present, the decoder reads a value using the 3-entry PDF in >+ <xref target="silk_ltp_scaling_pdf"/>. >+The three possible values represent Q14 scale factors of 15565, 12288, and >+ 8192, respectively (corresponding to approximately 0.95, 0.75, and 0.5). >+Frames that do not code the scaling parameter use the default factor of 15565 >+ (approximately 0.95). >+</t> >+ >+<texttable anchor="silk_ltp_scaling_pdf" >+ title="PDF for LTP Scaling Parameter"> >+<ttcol align="left">PDF</ttcol> >+<c>{128, 64, 64}/256</c> >+</texttable> >+ >+</section> >+ >+</section> >+ >+<section anchor="silk_seed" toc="include" >+ title="Linear Congruential Generator (LCG) Seed"> >+<t> >+As described in <xref target="silk_excitation_reconstruction"/>, SILK uses a >+ linear congruential generator (LCG) to inject pseudorandom noise into the >+ quantized excitation. >+To ensure synchronization of this process between the encoder and decoder, each >+ SILK frame stores a 2-bit seed after the LTP parameters (if any). >+The encoder may consider the choice of seed during quantization, and the >+ flexibility of this choice lets it reduce distortion, helping to pay for the >+ bit cost required to signal it. >+The decoder reads the seed using the uniform 4-entry PDF in >+ <xref target="silk_seed_pdf"/>, yielding a value between 0 and 3, inclusive. >+</t> >+ >+<texttable anchor="silk_seed_pdf" >+ title="PDF for LCG Seed"> >+<ttcol align="left">PDF</ttcol> >+<c>{64, 64, 64, 64}/256</c> >+</texttable> >+ >+</section> >+ >+<section anchor="silk_excitation" toc="include" title="Excitation"> >+<t> >+SILK codes the excitation using a modified version of the Pyramid Vector >+ Quantization (PVQ) codebook <xref target="PVQ"/>. >+The PVQ codebook is designed for Laplace-distributed values and consists of all >+ sums of K signed, unit pulses in a vector of dimension N, where two pulses at >+ the same position are required to have the same sign. >+Thus the codebook includes all integer codevectors y of dimension N that >+ satisfy >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+N-1 >+__ >+\ abs(y[j]) = K . >+/_ >+j=0 >+]]></artwork> >+</figure> >+Unlike regular PVQ, SILK uses a variable-length, rather than fixed-length, >+ encoding. >+This encoding is better suited to the more Gaussian-like distribution of the >+ coefficient magnitudes and the non-uniform distribution of their signs (caused >+ by the quantization offset described below). >+SILK also handles large codebooks by coding the least significant bits (LSBs) >+ of each coefficient directly. >+This adds a small coding efficiency loss, but greatly reduces the computation >+ time and ROM size required for decoding, as implemented in >+ silk_decode_pulses() (decode_pulses.c). >+</t> >+ >+<t> >+SILK fixes the dimension of the codebook to N = 16. >+The excitation is made up of a number of "shell blocks", each 16 samples in >+ size. >+<xref target="silk_shell_block_table"/> lists the number of shell blocks >+ required for a SILK frame for each possible audio bandwidth and frame size. >+10 ms MB frames nominally contain 120 samples (10 ms at >+ 12 kHz), which is not a multiple of 16. >+This is handled by coding 8 shell blocks (128 samples) and discarding the final >+ 8 samples of the last block. >+The decoder contains no special case that prevents an encoder from placing >+ pulses in these samples, and they must be correctly parsed from the bitstream >+ if present, but they are otherwise ignored. >+</t> >+ >+<texttable anchor="silk_shell_block_table" >+ title="Number of Shell Blocks Per SILK Frame"> >+<ttcol>Audio Bandwidth</ttcol> >+<ttcol>Frame Size</ttcol> >+<ttcol align="right">Number of Shell Blocks</ttcol> >+<c>NB</c> <c>10 ms</c> <c>5</c> >+<c>MB</c> <c>10 ms</c> <c>8</c> >+<c>WB</c> <c>10 ms</c> <c>10</c> >+<c>NB</c> <c>20 ms</c> <c>10</c> >+<c>MB</c> <c>20 ms</c> <c>15</c> >+<c>WB</c> <c>20 ms</c> <c>20</c> >+</texttable> >+ >+<section anchor="silk_rate_level" title="Rate Level"> >+<t> >+The first symbol in the excitation is a "rate level", which is an index from 0 >+ to 8, inclusive, coded using the PDF in <xref target="silk_rate_level_pdfs"/> >+ corresponding to the signal type of the current frame (from >+ <xref target="silk_frame_type"/>). >+The rate level selects the PDF used to decode the number of pulses in >+ the individual shell blocks. >+It does not directly convey any information about the bitrate or the number of >+ pulses itself, but merely changes the probability of the symbols in >+ <xref target="silk_pulse_counts"/>. >+Level 0 provides a more efficient encoding at low rates generally, and >+ level 8 provides a more efficient encoding at high rates generally, >+ though the most efficient level for a particular SILK frame may depend on the >+ exact distribution of the coded symbols. >+An encoder should, but is not required to, use the most efficient rate level. >+</t> >+ >+<texttable anchor="silk_rate_level_pdfs" >+ title="PDFs for the Rate Level"> >+<ttcol>Signal Type</ttcol> >+<ttcol>PDF</ttcol> >+<c>Inactive or Unvoiced</c> >+<c>{15, 51, 12, 46, 45, 13, 33, 27, 14}/256</c> >+<c>Voiced</c> >+<c>{33, 30, 36, 17, 34, 49, 18, 21, 18}/256</c> >+</texttable> >+ >+</section> >+ >+<section anchor="silk_pulse_counts" title="Pulses Per Shell Block"> >+<t> >+The total number of pulses in each of the shell blocks follows the rate level. >+The pulse counts for all of the shell blocks are coded consecutively, before >+ the content of any of the blocks. >+Each block may have anywhere from 0 to 16 pulses, inclusive, coded using the >+ 18-entry PDF in <xref target="silk_pulse_count_pdfs"/> corresponding to the >+ rate level from <xref target="silk_rate_level"/>. >+The special value 17 indicates that this block has one or more additional >+ LSBs to decode for each coefficient. >+If the decoder encounters this value, it decodes another value for the actual >+ pulse count of the block, but uses the PDF corresponding to the special rate >+ level 9 instead of the normal rate level. >+This process repeats until the decoder reads a value less than 17, and it then >+ sets the number of extra LSBs used to the number of 17's decoded for that >+ block. >+If it reads the value 17 ten times, then the next iteration uses the special >+ rate level 10 instead of 9. >+The probability of decoding a 17 when using the PDF for rate level 10 is >+ zero, ensuring that the number of LSBs for a block will not exceed 10. >+The cumulative distribution for rate level 10 is just a shifted version of >+ that for 9 and thus does not require any additional storage. >+</t> >+ >+<texttable anchor="silk_pulse_count_pdfs" >+ title="PDFs for the Pulse Count"> >+<ttcol>Rate Level</ttcol> >+<ttcol>PDF</ttcol> >+<c>0</c> >+<c>{131, 74, 25, 8, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}/256</c> >+<c>1</c> >+<c>{58, 93, 60, 23, 7, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}/256</c> >+<c>2</c> >+<c>{43, 51, 46, 33, 24, 16, 11, 8, 6, 3, 3, 3, 2, 1, 1, 2, 1, 2}/256</c> >+<c>3</c> >+<c>{17, 52, 71, 57, 31, 12, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}/256</c> >+<c>4</c> >+<c>{6, 21, 41, 53, 49, 35, 21, 11, 6, 3, 2, 2, 1, 1, 1, 1, 1, 1}/256</c> >+<c>5</c> >+<c>{7, 14, 22, 28, 29, 28, 25, 20, 17, 13, 11, 9, 7, 5, 4, 4, 3, 10}/256</c> >+<c>6</c> >+<c>{2, 5, 14, 29, 42, 46, 41, 31, 19, 11, 6, 3, 2, 1, 1, 1, 1, 1}/256</c> >+<c>7</c> >+<c>{1, 2, 4, 10, 19, 29, 35, 37, 34, 28, 20, 14, 8, 5, 4, 2, 2, 2}/256</c> >+<c>8</c> >+<c>{1, 2, 2, 5, 9, 14, 20, 24, 27, 28, 26, 23, 20, 15, 11, 8, 6, 15}/256</c> >+<c>9</c> >+<c>{1, 1, 1, 6, 27, 58, 56, 39, 25, 14, 10, 6, 3, 3, 2, 1, 1, 2}/256</c> >+<c>10</c> >+<c>{2, 1, 6, 27, 58, 56, 39, 25, 14, 10, 6, 3, 3, 2, 1, 1, 2, 0}/256</c> >+</texttable> >+ >+</section> >+ >+<section anchor="silk_pulse_locations" title="Pulse Location Decoding"> >+<t> >+The locations of the pulses in each shell block follow the pulse counts, >+ as decoded by silk_shell_decoder() (shell_coder.c). >+As with the pulse counts, these locations are coded for all the shell blocks >+ before any of the remaining information for each block. >+Unlike many other codecs, SILK places no restriction on the distribution of >+ pulses within a shell block. >+All of the pulses may be placed in a single location, or each one in a unique >+ location, or anything in between. >+</t> >+ >+<t> >+The location of pulses is coded by recursively partitioning each block into >+ halves, and coding how many pulses fall on the left side of the split. >+All remaining pulses must fall on the right side of the split. >+The process then recurses into the left half, and after that returns, the >+ right half (preorder traversal). >+The PDF to use is chosen by the size of the current partition (16, 8, 4, or 2) >+ and the number of pulses in the partition (1 to 16, inclusive). >+Tables <xref format="counter" target="silk_shell_code3_pdfs"/> >+ through <xref format="counter" target="silk_shell_code0_pdfs"/> list the >+ PDFs used for each partition size and pulse count. >+This process skips partitions without any pulses, i.e., where the initial pulse >+ count from <xref target="silk_pulse_counts"/> was zero, or where the split in >+ the prior level indicated that all of the pulses fell on the other side. >+These partitions have nothing to code, so they require no PDF. >+</t> >+ >+<texttable anchor="silk_shell_code3_pdfs" >+ title="PDFs for Pulse Count Split, 16 Sample Partitions"> >+<ttcol>Pulse Count</ttcol> >+<ttcol>PDF</ttcol> >+ <c>1</c> <c>{126, 130}/256</c> >+ <c>2</c> <c>{56, 142, 58}/256</c> >+ <c>3</c> <c>{25, 101, 104, 26}/256</c> >+ <c>4</c> <c>{12, 60, 108, 64, 12}/256</c> >+ <c>5</c> <c>{7, 35, 84, 87, 37, 6}/256</c> >+ <c>6</c> <c>{4, 20, 59, 86, 63, 21, 3}/256</c> >+ <c>7</c> <c>{3, 12, 38, 72, 75, 42, 12, 2}/256</c> >+ <c>8</c> <c>{2, 8, 25, 54, 73, 59, 27, 7, 1}/256</c> >+ <c>9</c> <c>{2, 5, 17, 39, 63, 65, 42, 18, 4, 1}/256</c> >+<c>10</c> <c>{1, 4, 12, 28, 49, 63, 54, 30, 11, 3, 1}/256</c> >+<c>11</c> <c>{1, 4, 8, 20, 37, 55, 57, 41, 22, 8, 2, 1}/256</c> >+<c>12</c> <c>{1, 3, 7, 15, 28, 44, 53, 48, 33, 16, 6, 1, 1}/256</c> >+<c>13</c> <c>{1, 2, 6, 12, 21, 35, 47, 48, 40, 25, 12, 5, 1, 1}/256</c> >+<c>14</c> <c>{1, 1, 4, 10, 17, 27, 37, 47, 43, 33, 21, 9, 4, 1, 1}/256</c> >+<c>15</c> <c>{1, 1, 1, 8, 14, 22, 33, 40, 43, 38, 28, 16, 8, 1, 1, 1}/256</c> >+<c>16</c> <c>{1, 1, 1, 1, 13, 18, 27, 36, 41, 41, 34, 24, 14, 1, 1, 1, 1}/256</c> >+</texttable> >+ >+<texttable anchor="silk_shell_code2_pdfs" >+ title="PDFs for Pulse Count Split, 8 Sample Partitions"> >+<ttcol>Pulse Count</ttcol> >+<ttcol>PDF</ttcol> >+ <c>1</c> <c>{127, 129}/256</c> >+ <c>2</c> <c>{53, 149, 54}/256</c> >+ <c>3</c> <c>{22, 105, 106, 23}/256</c> >+ <c>4</c> <c>{11, 61, 111, 63, 10}/256</c> >+ <c>5</c> <c>{6, 35, 86, 88, 36, 5}/256</c> >+ <c>6</c> <c>{4, 20, 59, 87, 62, 21, 3}/256</c> >+ <c>7</c> <c>{3, 13, 40, 71, 73, 41, 13, 2}/256</c> >+ <c>8</c> <c>{3, 9, 27, 53, 70, 56, 28, 9, 1}/256</c> >+ <c>9</c> <c>{3, 8, 19, 37, 57, 61, 44, 20, 6, 1}/256</c> >+<c>10</c> <c>{3, 7, 15, 28, 44, 54, 49, 33, 17, 5, 1}/256</c> >+<c>11</c> <c>{1, 7, 13, 22, 34, 46, 48, 38, 28, 14, 4, 1}/256</c> >+<c>12</c> <c>{1, 1, 11, 22, 27, 35, 42, 47, 33, 25, 10, 1, 1}/256</c> >+<c>13</c> <c>{1, 1, 6, 14, 26, 37, 43, 43, 37, 26, 14, 6, 1, 1}/256</c> >+<c>14</c> <c>{1, 1, 4, 10, 20, 31, 40, 42, 40, 31, 20, 10, 4, 1, 1}/256</c> >+<c>15</c> <c>{1, 1, 3, 8, 16, 26, 35, 38, 38, 35, 26, 16, 8, 3, 1, 1}/256</c> >+<c>16</c> <c>{1, 1, 2, 6, 12, 21, 30, 36, 38, 36, 30, 21, 12, 6, 2, 1, 1}/256</c> >+</texttable> >+ >+<texttable anchor="silk_shell_code1_pdfs" >+ title="PDFs for Pulse Count Split, 4 Sample Partitions"> >+<ttcol>Pulse Count</ttcol> >+<ttcol>PDF</ttcol> >+ <c>1</c> <c>{127, 129}/256</c> >+ <c>2</c> <c>{49, 157, 50}/256</c> >+ <c>3</c> <c>{20, 107, 109, 20}/256</c> >+ <c>4</c> <c>{11, 60, 113, 62, 10}/256</c> >+ <c>5</c> <c>{7, 36, 84, 87, 36, 6}/256</c> >+ <c>6</c> <c>{6, 24, 57, 82, 60, 23, 4}/256</c> >+ <c>7</c> <c>{5, 18, 39, 64, 68, 42, 16, 4}/256</c> >+ <c>8</c> <c>{6, 14, 29, 47, 61, 52, 30, 14, 3}/256</c> >+ <c>9</c> <c>{1, 15, 23, 35, 51, 50, 40, 30, 10, 1}/256</c> >+<c>10</c> <c>{1, 1, 21, 32, 42, 52, 46, 41, 18, 1, 1}/256</c> >+<c>11</c> <c>{1, 6, 16, 27, 36, 42, 42, 36, 27, 16, 6, 1}/256</c> >+<c>12</c> <c>{1, 5, 12, 21, 31, 38, 40, 38, 31, 21, 12, 5, 1}/256</c> >+<c>13</c> <c>{1, 3, 9, 17, 26, 34, 38, 38, 34, 26, 17, 9, 3, 1}/256</c> >+<c>14</c> <c>{1, 3, 7, 14, 22, 29, 34, 36, 34, 29, 22, 14, 7, 3, 1}/256</c> >+<c>15</c> <c>{1, 2, 5, 11, 18, 25, 31, 35, 35, 31, 25, 18, 11, 5, 2, 1}/256</c> >+<c>16</c> <c>{1, 1, 4, 9, 15, 21, 28, 32, 34, 32, 28, 21, 15, 9, 4, 1, 1}/256</c> >+</texttable> >+ >+<texttable anchor="silk_shell_code0_pdfs" >+ title="PDFs for Pulse Count Split, 2 Sample Partitions"> >+<ttcol>Pulse Count</ttcol> >+<ttcol>PDF</ttcol> >+ <c>1</c> <c>{128, 128}/256</c> >+ <c>2</c> <c>{42, 172, 42}/256</c> >+ <c>3</c> <c>{21, 107, 107, 21}/256</c> >+ <c>4</c> <c>{12, 60, 112, 61, 11}/256</c> >+ <c>5</c> <c>{8, 34, 86, 86, 35, 7}/256</c> >+ <c>6</c> <c>{8, 23, 55, 90, 55, 20, 5}/256</c> >+ <c>7</c> <c>{5, 15, 38, 72, 72, 36, 15, 3}/256</c> >+ <c>8</c> <c>{6, 12, 27, 52, 77, 47, 20, 10, 5}/256</c> >+ <c>9</c> <c>{6, 19, 28, 35, 40, 40, 35, 28, 19, 6}/256</c> >+<c>10</c> <c>{4, 14, 22, 31, 37, 40, 37, 31, 22, 14, 4}/256</c> >+<c>11</c> <c>{3, 10, 18, 26, 33, 38, 38, 33, 26, 18, 10, 3}/256</c> >+<c>12</c> <c>{2, 8, 13, 21, 29, 36, 38, 36, 29, 21, 13, 8, 2}/256</c> >+<c>13</c> <c>{1, 5, 10, 17, 25, 32, 38, 38, 32, 25, 17, 10, 5, 1}/256</c> >+<c>14</c> <c>{1, 4, 7, 13, 21, 29, 35, 36, 35, 29, 21, 13, 7, 4, 1}/256</c> >+<c>15</c> <c>{1, 2, 5, 10, 17, 25, 32, 36, 36, 32, 25, 17, 10, 5, 2, 1}/256</c> >+<c>16</c> <c>{1, 2, 4, 7, 13, 21, 28, 34, 36, 34, 28, 21, 13, 7, 4, 2, 1}/256</c> >+</texttable> >+ >+</section> >+ >+<section anchor="silk_shell_lsb" title="LSB Decoding"> >+<t> >+After the decoder reads the pulse locations for all blocks, it reads the LSBs >+ (if any) for each block in turn. >+Inside each block, it reads all the LSBs for each coefficient in turn, even >+ those where no pulses were allocated, before proceeding to the next one. >+For 10 ms MB frames, it reads LSBs even for the extra 8 samples in >+ the last block. >+The LSBs are coded from most significant to least significant, and they all use >+ the PDF in <xref target="silk_shell_lsb_pdf"/>. >+</t> >+ >+<texttable anchor="silk_shell_lsb_pdf" title="PDF for Excitation LSBs"> >+<ttcol>PDF</ttcol> >+<c>{136, 120}/256</c> >+</texttable> >+ >+<t> >+The number of LSBs read for each coefficient in a block is determined in >+ <xref target="silk_pulse_counts"/>. >+The magnitude of the coefficient is initially equal to the number of pulses >+ placed at that location in <xref target="silk_pulse_locations"/>. >+As each LSB is decoded, the magnitude is doubled, and then the value of the LSB >+ added to it, to obtain an updated magnitude. >+</t> >+</section> >+ >+<section anchor="silk_signs" title="Sign Decoding"> >+<t> >+After decoding the pulse locations and the LSBs, the decoder knows the >+ magnitude of each coefficient in the excitation. >+It then decodes a sign for all coefficients with a non-zero magnitude, using >+ one of the PDFs from <xref target="silk_sign_pdfs"/>. >+If the value decoded is 0, then the coefficient magnitude is negated. >+Otherwise, it remains positive. >+</t> >+ >+<t> >+The decoder chooses the PDF for the sign based on the signal type and >+ quantization offset type (from <xref target="silk_frame_type"/>) and the >+ number of pulses in the block (from <xref target="silk_pulse_counts"/>). >+The number of pulses in the block does not take into account any LSBs. >+Most PDFs are skewed towards negative signs because of the quantization offset, >+ but the PDFs for zero pulses are highly skewed towards positive signs. >+If a block contains many positive coefficients, it is sometimes beneficial to >+ code it solely using LSBs (i.e., with zero pulses), since the encoder may be >+ able to save enough bits on the signs to justify the less efficient >+ coefficient magnitude encoding. >+</t> >+ >+<texttable anchor="silk_sign_pdfs" >+ title="PDFs for Excitation Signs"> >+<ttcol>Signal Type</ttcol> >+<ttcol>Quantization Offset Type</ttcol> >+<ttcol>Pulse Count</ttcol> >+<ttcol>PDF</ttcol> >+<c>Inactive</c> <c>Low</c> <c>0</c> <c>{2, 254}/256</c> >+<c>Inactive</c> <c>Low</c> <c>1</c> <c>{207, 49}/256</c> >+<c>Inactive</c> <c>Low</c> <c>2</c> <c>{189, 67}/256</c> >+<c>Inactive</c> <c>Low</c> <c>3</c> <c>{179, 77}/256</c> >+<c>Inactive</c> <c>Low</c> <c>4</c> <c>{174, 82}/256</c> >+<c>Inactive</c> <c>Low</c> <c>5</c> <c>{163, 93}/256</c> >+<c>Inactive</c> <c>Low</c> <c>6 or more</c> <c>{157, 99}/256</c> >+<c>Inactive</c> <c>High</c> <c>0</c> <c>{58, 198}/256</c> >+<c>Inactive</c> <c>High</c> <c>1</c> <c>{245, 11}/256</c> >+<c>Inactive</c> <c>High</c> <c>2</c> <c>{238, 18}/256</c> >+<c>Inactive</c> <c>High</c> <c>3</c> <c>{232, 24}/256</c> >+<c>Inactive</c> <c>High</c> <c>4</c> <c>{225, 31}/256</c> >+<c>Inactive</c> <c>High</c> <c>5</c> <c>{220, 36}/256</c> >+<c>Inactive</c> <c>High</c> <c>6 or more</c> <c>{211, 45}/256</c> >+<c>Unvoiced</c> <c>Low</c> <c>0</c> <c>{1, 255}/256</c> >+<c>Unvoiced</c> <c>Low</c> <c>1</c> <c>{210, 46}/256</c> >+<c>Unvoiced</c> <c>Low</c> <c>2</c> <c>{190, 66}/256</c> >+<c>Unvoiced</c> <c>Low</c> <c>3</c> <c>{178, 78}/256</c> >+<c>Unvoiced</c> <c>Low</c> <c>4</c> <c>{169, 87}/256</c> >+<c>Unvoiced</c> <c>Low</c> <c>5</c> <c>{162, 94}/256</c> >+<c>Unvoiced</c> <c>Low</c> <c>6 or more</c> <c>{152, 104}/256</c> >+<c>Unvoiced</c> <c>High</c> <c>0</c> <c>{48, 208}/256</c> >+<c>Unvoiced</c> <c>High</c> <c>1</c> <c>{242, 14}/256</c> >+<c>Unvoiced</c> <c>High</c> <c>2</c> <c>{235, 21}/256</c> >+<c>Unvoiced</c> <c>High</c> <c>3</c> <c>{224, 32}/256</c> >+<c>Unvoiced</c> <c>High</c> <c>4</c> <c>{214, 42}/256</c> >+<c>Unvoiced</c> <c>High</c> <c>5</c> <c>{205, 51}/256</c> >+<c>Unvoiced</c> <c>High</c> <c>6 or more</c> <c>{190, 66}/256</c> >+<c>Voiced</c> <c>Low</c> <c>0</c> <c>{1, 255}/256</c> >+<c>Voiced</c> <c>Low</c> <c>1</c> <c>{162, 94}/256</c> >+<c>Voiced</c> <c>Low</c> <c>2</c> <c>{152, 104}/256</c> >+<c>Voiced</c> <c>Low</c> <c>3</c> <c>{147, 109}/256</c> >+<c>Voiced</c> <c>Low</c> <c>4</c> <c>{144, 112}/256</c> >+<c>Voiced</c> <c>Low</c> <c>5</c> <c>{141, 115}/256</c> >+<c>Voiced</c> <c>Low</c> <c>6 or more</c> <c>{138, 118}/256</c> >+<c>Voiced</c> <c>High</c> <c>0</c> <c>{8, 248}/256</c> >+<c>Voiced</c> <c>High</c> <c>1</c> <c>{203, 53}/256</c> >+<c>Voiced</c> <c>High</c> <c>2</c> <c>{187, 69}/256</c> >+<c>Voiced</c> <c>High</c> <c>3</c> <c>{176, 80}/256</c> >+<c>Voiced</c> <c>High</c> <c>4</c> <c>{168, 88}/256</c> >+<c>Voiced</c> <c>High</c> <c>5</c> <c>{161, 95}/256</c> >+<c>Voiced</c> <c>High</c> <c>6 or more</c> <c>{154, 102}/256</c> >+</texttable> >+ >+</section> >+ >+<section anchor="silk_excitation_reconstruction" >+ title="Reconstructing the Excitation"> >+ >+<t> >+After the signs have been read, there is enough information to reconstruct the >+ complete excitation signal. >+This requires adding a constant quantization offset to each non-zero sample, >+ and then pseudorandomly inverting and offsetting every sample. >+The constant quantization offset varies depending on the signal type and >+ quantization offset type (see <xref target="silk_frame_type"/>). >+</t> >+ >+<texttable anchor="silk_quantization_offsets" >+ title="Excitation Quantization Offsets"> >+<ttcol align="left">Signal Type</ttcol> >+<ttcol align="left">Quantization Offset Type</ttcol> >+<ttcol align="right">Quantization Offset (Q23)</ttcol> >+<c>Inactive</c> <c>Low</c> <c>25</c> >+<c>Inactive</c> <c>High</c> <c>60</c> >+<c>Unvoiced</c> <c>Low</c> <c>25</c> >+<c>Unvoiced</c> <c>High</c> <c>60</c> >+<c>Voiced</c> <c>Low</c> <c>8</c> >+<c>Voiced</c> <c>High</c> <c>25</c> >+</texttable> >+ >+<t> >+Let e_raw[i] be the raw excitation value at position i, with a magnitude >+ composed of the pulses at that location (see >+ <xref target="silk_pulse_locations"/>) combined with any additional LSBs (see >+ <xref target="silk_shell_lsb"/>), and with the corresponding sign decoded in >+ <xref target="silk_signs"/>. >+Additionally, let seed be the current pseudorandom seed, which is initialized >+ to the value decoded from <xref target="silk_seed"/> for the first sample in >+ the current SILK frame, and updated for each subsequent sample according to >+ the procedure below. >+Finally, let offset_Q23 be the quantization offset from >+ <xref target="silk_quantization_offsets"/>. >+Then the following procedure produces the final reconstructed excitation value, >+ e_Q23[i]: >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+e_Q23[i] = (e_raw[i] << 8) - sign(e_raw[i])*20 + offset_Q23; >+ seed = (196314165*seed + 907633515) & 0xFFFFFFFF; >+e_Q23[i] = (seed & 0x80000000) ? -e_Q23[i] : e_Q23[i]; >+ seed = (seed + e_raw[i]) & 0xFFFFFFFF; >+]]></artwork> >+</figure> >+When e_raw[i] is zero, sign() returns 0 by the definition in >+ <xref target="sign"/>, so the factor of 20 does not get added. >+The final e_Q23[i] value may require more than 16 bits per sample, but will not >+ require more than 23, including the sign. >+</t> >+ >+</section> >+ >+</section> >+ >+<section anchor="silk_frame_reconstruction" toc="include" >+ title="SILK Frame Reconstruction"> >+ >+<t> >+The remainder of the reconstruction process for the frame does not need to be >+ bit-exact, as small errors should only introduce proportionally small >+ distortions. >+Although the reference implementation only includes a fixed-point version of >+ the remaining steps, this section describes them in terms of a floating-point >+ version for simplicity. >+This produces a signal with a nominal range of -1.0 to 1.0. >+</t> >+ >+<t> >+silk_decode_core() (decode_core.c) contains the code for the main >+ reconstruction process. >+It proceeds subframe-by-subframe, since quantization gains, LTP parameters, and >+ (in 20 ms SILK frames) LPC coefficients can vary from one to the >+ next. >+</t> >+ >+<t> >+Let a_Q12[k] be the LPC coefficients for the current subframe. >+If this is the first or second subframe of a 20 ms SILK frame and the LSF >+ interpolation factor, w_Q2 (see <xref target="silk_nlsf_interpolation"/>), is >+ less than 4, then these correspond to the final LPC coefficients produced by >+ <xref target="silk_lpc_gain_limit"/> from the interpolated LSF coefficients, >+ n1_Q15[k] (computed in <xref target="silk_nlsf_interpolation"/>). >+Otherwise, they correspond to the final LPC coefficients produced from the >+ uninterpolated LSF coefficients for the current frame, n2_Q15[k]. >+</t> >+ >+<t> >+Also, let n be the number of samples in a subframe (40 for NB, 60 for MB, and >+ 80 for WB), s be the index of the current subframe in this SILK frame (0 or 1 >+ for 10 ms frames, or 0 to 3 for 20 ms frames), and j be the index of >+ the first sample in the residual corresponding to the current subframe. >+</t> >+ >+<section anchor="silk_ltp_synthesis" title="LTP Synthesis"> >+<t> >+Voiced SILK frames (see <xref target="silk_frame_type"/>) pass the excitation >+ through an LTP filter using the parameters decoded in >+ <xref target="silk_ltp_params"/> to produce an LPC residual. >+The LTP filter requires LPC residual values from before the current subframe as >+ input. >+However, since the LPC coefficients may have changed, it obtains this residual >+ by "rewhitening" the corresponding output signal using the LPC coefficients >+ from the current subframe. >+Let out[i] for >+ (j - pitch_lags[s] - d_LPC - 2) <= i < j >+ be the fully reconstructed output signal from the last >+ (pitch_lags[s] + d_LPC + 2) samples of previous subframes >+ (see <xref target="silk_lpc_synthesis"/>), where pitch_lags[s] is the pitch >+ lag for the current subframe from <xref target="silk_ltp_lags"/>. >+During reconstruction of the first subframe for this channel after either >+<list style="symbols"> >+<t>An uncoded regular SILK frame (if this is the side channel), or</t> >+<t>A decoder reset (see <xref target="decoder-reset"/>),</t> >+</list> >+ out[] is rewhitened into an LPC residual, >+ res[i], via >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+ 4.0*LTP_scale_Q14 >+res[i] = ----------------- * clamp(-1.0, >+ gain_Q16[s] >+ >+ d_LPC-1 >+ __ a_Q12[k] >+ out[i] - \ out[i-k-1] * --------, 1.0) . >+ /_ 4096.0 >+ k=0 >+]]></artwork> >+</figure> >+This requires storage to buffer up to 306 values of out[i] from previous >+ subframes. >+This corresponds to WB with a maximum pitch lag of >+ 18 ms * 16 kHz samples, plus 16 samples for d_LPC, plus 2 >+ samples for the width of the LTP filter. >+</t> >+ >+<t> >+Let e_Q23[i] for j <= i < (j + n) be the >+ excitation for the current subframe, and b_Q7[k] for >+ 0 <= k < 5 be the coefficients of the LTP filter >+ taken from the codebook entry in one of >+ Tables <xref format="counter" target="silk_ltp_filter_coeffs0"/> >+ through <xref format="counter" target="silk_ltp_filter_coeffs2"/> >+ corresponding to the index decoded for the current subframe in >+ <xref target="silk_ltp_filter"/>. >+Then for i such that j <= i < (j + n), >+ the LPC residual is >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+ 4 >+ e_Q23[i] __ b_Q7[k] >+res[i] = --------- + \ res[i - pitch_lags[s] + 2 - k] * ------- . >+ 2.0**23 /_ 128.0 >+ k=0 >+]]></artwork> >+</figure> >+</t> >+ >+<t> >+For unvoiced frames, the LPC residual for >+ j <= i < (j + n) is simply a normalized >+ copy of the excitation signal, i.e., >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+ e_Q23[i] >+res[i] = --------- >+ 2.0**23 >+]]></artwork> >+</figure> >+</t> >+</section> >+ >+<section anchor="silk_lpc_synthesis" title="LPC Synthesis"> >+<t> >+LPC synthesis uses the short-term LPC filter to predict the next output >+ coefficient. >+For i such that (j - d_LPC) <= i < j, let >+ lpc[i] be the result of LPC synthesis from the last d_LPC samples of the >+ previous subframe, or zeros in the first subframe for this channel after >+ either >+<list style="symbols"> >+<t>An uncoded regular SILK frame (if this is the side channel), or</t> >+<t>A decoder reset (see <xref target="decoder-reset"/>).</t> >+</list> >+Then for i such that j <= i < (j + n), the >+ result of LPC synthesis for the current subframe is >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+ d_LPC-1 >+ gain_Q16[i] __ a_Q12[k] >+lpc[i] = ----------- * res[i] + \ lpc[i-k-1] * -------- . >+ 65536.0 /_ 4096.0 >+ k=0 >+]]></artwork> >+</figure> >+The decoder saves the final d_LPC values, i.e., lpc[i] such that >+ (j + n - d_LPC) <= i < (j + n), >+ to feed into the LPC synthesis of the next subframe. >+This requires storage for up to 16 values of lpc[i] (for WB frames). >+</t> >+ >+<t> >+Then, the signal is clamped into the final nominal range: >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+out[i] = clamp(-1.0, lpc[i], 1.0) . >+]]></artwork> >+</figure> >+This clamping occurs entirely after the LPC synthesis filter has run. >+The decoder saves the unclamped values, lpc[i], to feed into the LPC filter for >+ the next subframe, but saves the clamped values, out[i], for rewhitening in >+ voiced frames. >+</t> >+</section> >+ >+</section> >+ >+</section> >+ >+<section anchor="silk_stereo_unmixing" title="Stereo Unmixing"> >+<t> >+For stereo streams, after decoding a frame from each channel, the decoder must >+ convert the mid-side (MS) representation into a left-right (LR) >+ representation. >+The function silk_stereo_MS_to_LR (stereo_MS_to_LR.c) implements this process. >+In it, the decoder predicts the side channel using a) a simple low-passed >+ version of the mid channel, and b) the unfiltered mid channel, using the >+ prediction weights decoded in <xref target="silk_stereo_pred"/>. >+This simple low-pass filter imposes a one-sample delay, and the unfiltered >+mid channel is also delayed by one sample. >+In order to allow seamless switching between stereo and mono, mono streams must >+ also impose the same one-sample delay. >+The encoder requires an additional one-sample delay for both mono and stereo >+ streams, though an encoder may omit the delay for mono if it knows it will >+ never switch to stereo. >+</t> >+ >+<t> >+The unmixing process operates in two phases. >+The first phase lasts for 8 ms, during which it interpolates the >+ prediction weights from the previous frame, prev_w0_Q13 and prev_w1_Q13, to >+ the values for the current frame, w0_Q13 and w1_Q13. >+The second phase simply uses these weights for the remainder of the frame. >+</t> >+ >+<t> >+Let mid[i] and side[i] be the contents of out[i] (from >+ <xref target="silk_lpc_synthesis"/>) for the current mid and side channels, >+ respectively, and let left[i] and right[i] be the corresponding stereo output >+ channels. >+If the side channel is not coded (see <xref target="silk_mid_only_flag"/>), >+ then side[i] is set to zero. >+Also let j be defined as in <xref target="silk_frame_reconstruction"/>, n1 be >+ the number of samples in phase 1 (64 for NB, 96 for MB, and 128 for WB), >+ and n2 be the total number of samples in the frame. >+Then for i such that j <= i < (j + n2), >+ the left and right channel output is >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+ prev_w0_Q13 (w0_Q13 - prev_w0_Q13) >+ w0 = ----------- + min(i - j, n1)*---------------------- , >+ 8192.0 8192.0*n1 >+ >+ prev_w1_Q13 (w1_Q13 - prev_w1_Q13) >+ w1 = ----------- + min(i - j, n1)*---------------------- , >+ 8192.0 8192.0*n1 >+ >+ mid[i-2] + 2*mid[i-1] + mid[i] >+ p0 = ------------------------------ , >+ 4.0 >+ >+ left[i] = clamp(-1.0, (1 + w1)*mid[i-1] + side[i-1] + w0*p0, 1.0) , >+ >+right[i] = clamp(-1.0, (1 - w1)*mid[i-1] - side[i-1] - w0*p0, 1.0) . >+]]></artwork> >+</figure> >+These formulas require two samples prior to index j, the start of the >+ frame, for the mid channel, and one prior sample for the side channel. >+For the first frame after a decoder reset, zeros are used instead. >+</t> >+ >+</section> >+ >+<section title="Resampling"> >+<t> >+After stereo unmixing (if any), the decoder applies resampling to convert the >+ decoded SILK output to the sample rate desired by the application. >+This is necessary when decoding a Hybrid frame at SWB or FB sample rates, or >+ whenever the decoder wants the output at a different sample rate than the >+ internal SILK sampling rate (e.g., to allow a constant sample rate when the >+ audio bandwidth changes, or to allow mixing with audio from other >+ applications). >+The resampler itself is non-normative, and a decoder can use any method it >+ wants to perform the resampling. >+</t> >+ >+<t> >+However, a minimum amount of delay is imposed to allow the resampler to >+ operate, and this delay is normative, so that the corresponding delay can be >+ applied to the MDCT layer in the encoder. >+A decoder is always free to use a resampler which requires more delay than >+ allowed for here (e.g., to improve quality), but it must then delay the output >+ of the MDCT layer by this extra amount. >+Keeping as much delay as possible on the encoder side allows an encoder which >+ knows it will never use any of the SILK or Hybrid modes to skip this delay. >+By contrast, if it were all applied by the decoder, then a decoder which >+ processes audio in fixed-size blocks would be forced to delay the output of >+ CELT frames just in case of a later switch to a SILK or Hybrid mode. >+</t> >+ >+<t> >+<xref target="silk_resampler_delay_alloc"/> gives the maximum resampler delay >+ in samples at 48 kHz for each SILK audio bandwidth. >+Because the actual output rate may not be 48 kHz, it may not be possible >+ to achieve exactly these delays while using a whole number of input or output >+ samples. >+The reference implementation is able to resample to any of the supported >+ output sampling rates (8, 12, 16, 24, or 48 kHz) within or near this >+ delay constraint. >+Some resampling filters (including those used by the reference implementation) >+ may add a delay that is not an exact integer, or is not linear-phase, and so >+ cannot be represented by a single delay at all frequencies. >+However, such deviations are unlikely to be perceptible, and the comparison >+ tool described in <xref target="conformance"/> is designed to be relatively >+ insensitive to them. >+The delays listed here are the ones that should be targeted by the encoder. >+</t> >+ >+<texttable anchor="silk_resampler_delay_alloc" >+ title="SILK Resampler Delay Allocations"> >+<ttcol>Audio Bandwidth</ttcol> >+<ttcol>Delay in millisecond</ttcol> >+<c>NB</c> <c>0.538</c> >+<c>MB</c> <c>0.692</c> >+<c>WB</c> <c>0.706</c> >+</texttable> >+ >+<t> >+NB is given a smaller decoder delay allocation than MB and WB to allow a >+ higher-order filter when resampling to 8 kHz in both the encoder and >+ decoder. >+This implies that the audio content of two SILK frames operating at different >+ bandwidths are not perfectly aligned in time. >+This is not an issue for any transitions described in >+ <xref target="switching"/>, because they all involve a SILK decoder reset. >+When the decoder is reset, any samples remaining in the resampling buffer >+ are discarded, and the resampler is re-initialized with silence. >+</t> >+ >+</section> >+ >+</section> >+ >+ >+<section title="CELT Decoder"> >+ >+<t> >+The CELT layer of Opus is based on the Modified Discrete Cosine Transform >+<xref target='MDCT'/> with partially overlapping windows of 5 to 22.5 ms. >+The main principle behind CELT is that the MDCT spectrum is divided into >+bands that (roughly) follow the Bark scale, i.e., the scale of the ear's >+critical bands <xref target="Zwicker61"/>. The normal CELT layer uses 21 of those bands, though Opus >+ Custom (see <xref target="opus-custom"/>) may use a different number of bands. >+In Hybrid mode, the first 17 bands (up to 8 kHz) are not coded. >+A band can contain as little as one MDCT bin per channel, and as many as 176 >+bins per channel, as detailed in <xref target="celt_band_sizes"/>. >+In each band, the gain (energy) is coded separately from >+the shape of the spectrum. Coding the gain explicitly makes it easy to >+preserve the spectral envelope of the signal. The remaining unit-norm shape >+vector is encoded using a Pyramid Vector Quantizer (PVQ) <xref target='PVQ-decoder'/>. >+</t> >+ >+<texttable anchor="celt_band_sizes" >+ title="MDCT Bins Per Channel Per Band for Each Frame Size"> >+<ttcol>Frame Size:</ttcol> >+<ttcol align="right">2.5 ms</ttcol> >+<ttcol align="right">5 ms</ttcol> >+<ttcol align="right">10 ms</ttcol> >+<ttcol align="right">20 ms</ttcol> >+<ttcol align="right">Start Frequency</ttcol> >+<ttcol align="right">Stop Frequency</ttcol> >+<c>Band</c> <c>Bins:</c> <c/> <c/> <c/> <c/> <c/> >+ <c>0</c> <c>1</c> <c>2</c> <c>4</c> <c>8</c> <c>0 Hz</c> <c>200 Hz</c> >+ <c>1</c> <c>1</c> <c>2</c> <c>4</c> <c>8</c> <c>200 Hz</c> <c>400 Hz</c> >+ <c>2</c> <c>1</c> <c>2</c> <c>4</c> <c>8</c> <c>400 Hz</c> <c>600 Hz</c> >+ <c>3</c> <c>1</c> <c>2</c> <c>4</c> <c>8</c> <c>600 Hz</c> <c>800 Hz</c> >+ <c>4</c> <c>1</c> <c>2</c> <c>4</c> <c>8</c> <c>800 Hz</c> <c>1000 Hz</c> >+ <c>5</c> <c>1</c> <c>2</c> <c>4</c> <c>8</c> <c>1000 Hz</c> <c>1200 Hz</c> >+ <c>6</c> <c>1</c> <c>2</c> <c>4</c> <c>8</c> <c>1200 Hz</c> <c>1400 Hz</c> >+ <c>7</c> <c>1</c> <c>2</c> <c>4</c> <c>8</c> <c>1400 Hz</c> <c>1600 Hz</c> >+ <c>8</c> <c>2</c> <c>4</c> <c>8</c> <c>16</c> <c>1600 Hz</c> <c>2000 Hz</c> >+ <c>9</c> <c>2</c> <c>4</c> <c>8</c> <c>16</c> <c>2000 Hz</c> <c>2400 Hz</c> >+<c>10</c> <c>2</c> <c>4</c> <c>8</c> <c>16</c> <c>2400 Hz</c> <c>2800 Hz</c> >+<c>11</c> <c>2</c> <c>4</c> <c>8</c> <c>16</c> <c>2800 Hz</c> <c>3200 Hz</c> >+<c>12</c> <c>4</c> <c>8</c> <c>16</c> <c>32</c> <c>3200 Hz</c> <c>4000 Hz</c> >+<c>13</c> <c>4</c> <c>8</c> <c>16</c> <c>32</c> <c>4000 Hz</c> <c>4800 Hz</c> >+<c>14</c> <c>4</c> <c>8</c> <c>16</c> <c>32</c> <c>4800 Hz</c> <c>5600 Hz</c> >+<c>15</c> <c>6</c> <c>12</c> <c>24</c> <c>48</c> <c>5600 Hz</c> <c>6800 Hz</c> >+<c>16</c> <c>6</c> <c>12</c> <c>24</c> <c>48</c> <c>6800 Hz</c> <c>8000 Hz</c> >+<c>17</c> <c>8</c> <c>16</c> <c>32</c> <c>64</c> <c>8000 Hz</c> <c>9600 Hz</c> >+<c>18</c> <c>12</c> <c>24</c> <c>48</c> <c>96</c> <c>9600 Hz</c> <c>12000 Hz</c> >+<c>19</c> <c>18</c> <c>36</c> <c>72</c> <c>144</c> <c>12000 Hz</c> <c>15600 Hz</c> >+<c>20</c> <c>22</c> <c>44</c> <c>88</c> <c>176</c> <c>15600 Hz</c> <c>20000 Hz</c> >+</texttable> >+ >+<t> >+Transients are notoriously difficult for transform codecs to code. >+CELT uses two different strategies for them: >+<list style="numbers"> >+<t>Using multiple smaller MDCTs instead of a single large MDCT, and</t> >+<t>Dynamic time-frequency resolution changes (See <xref target='tf-change'/>).</t> >+</list> >+To improve quality on highly tonal and periodic signals, CELT includes >+a prefilter/postfilter combination. The prefilter on the encoder side >+attenuates the signal's harmonics. The postfilter on the decoder side >+restores the original gain of the harmonics, while shaping the coding noise >+to roughly follow the harmonics. Such noise shaping reduces the perception >+of the noise. >+</t> >+ >+<t> >+When coding a stereo signal, three coding methods are available: >+<list style="symbols"> >+<t>mid-side stereo: encodes the mean and the difference of the left and right channels,</t> >+<t>intensity stereo: only encodes the mean of the left and right channels (discards the difference),</t> >+<t>dual stereo: encodes the left and right channels separately.</t> >+</list> >+</t> >+ >+<t> >+An overview of the decoder is given in <xref target="celt-decoder-overview"/>. >+</t> >+ >+<figure anchor="celt-decoder-overview" title="Structure of the CELT decoder"> >+<artwork align="center"><![CDATA[ >+ +---------+ >+ | Coarse | >+ +->| decoder |----+ >+ | +---------+ | >+ | | >+ | +---------+ v >+ | | Fine | +---+ >+ +->| decoder |->| + | >+ | +---------+ +---+ >+ | ^ | >++---------+ | | | >+| Range | | +----------+ v >+| Decoder |-+ | Bit | +------+ >++---------+ | |Allocation| | 2**x | >+ | +----------+ +------+ >+ | | | >+ | v v +--------+ >+ | +---------+ +---+ +-------+ | pitch | >+ +->| PVQ |->| * |->| IMDCT |->| post- |---> >+ | | decoder | +---+ +-------+ | filter | >+ | +---------+ +--------+ >+ | ^ >+ +--------------------------------------+ >+]]></artwork> >+</figure> >+ >+<t> >+The decoder is based on the following symbols and sets of symbols: >+</t> >+ >+<texttable anchor="celt_symbols" >+ title="Order of the Symbols in the CELT Section of the Bitstream"> >+<ttcol align="center">Symbol(s)</ttcol> >+<ttcol align="center">PDF</ttcol> >+<ttcol align="center">Condition</ttcol> >+<c>silence</c> <c>{32767, 1}/32768</c> <c></c> >+<c>post-filter</c> <c>{1, 1}/2</c> <c></c> >+<c>octave</c> <c>uniform (6)</c><c>post-filter</c> >+<c>period</c> <c>raw bits (4+octave)</c><c>post-filter</c> >+<c>gain</c> <c>raw bits (3)</c><c>post-filter</c> >+<c>tapset</c> <c>{2, 1, 1}/4</c><c>post-filter</c> >+<c>transient</c> <c>{7, 1}/8</c><c></c> >+<c>intra</c> <c>{7, 1}/8</c><c></c> >+<c>coarse energy</c><c><xref target="energy-decoding"/></c><c></c> >+<c>tf_change</c> <c><xref target="transient-decoding"/></c><c></c> >+<c>tf_select</c> <c>{1, 1}/2</c><c><xref target="transient-decoding"/></c> >+<c>spread</c> <c>{7, 2, 21, 2}/32</c><c></c> >+<c>dyn. alloc.</c> <c><xref target="allocation"/></c><c></c> >+<c>alloc. trim</c> <c>{2, 2, 5, 10, 22, 46, 22, 10, 5, 2, 2}/128</c><c></c> >+<c>skip</c> <c>{1, 1}/2</c><c><xref target="allocation"/></c> >+<c>intensity</c> <c>uniform</c><c><xref target="allocation"/></c> >+<c>dual</c> <c>{1, 1}/2</c><c></c> >+<c>fine energy</c> <c><xref target="energy-decoding"/></c><c></c> >+<c>residual</c> <c><xref target="PVQ-decoder"/></c><c></c> >+<c>anti-collapse</c><c>{1, 1}/2</c><c><xref target="anti-collapse"/></c> >+<c>finalize</c> <c><xref target="energy-decoding"/></c><c></c> >+</texttable> >+ >+<t> >+The decoder extracts information from the range-coded bitstream in the order >+described in <xref target='celt_symbols'/>. In some circumstances, it is >+possible for a decoded value to be out of range due to a very small amount of redundancy >+in the encoding of large integers by the range coder. >+In that case, the decoder should assume there has been an error in the coding, >+decoding, or transmission and SHOULD take measures to conceal the error and/or report >+to the application that a problem has occurred. Such out of range errors cannot occur >+in the SILK layer. >+</t> >+ >+<section anchor="transient-decoding" title="Transient Decoding"> >+<t> >+The "transient" flag indicates whether the frame uses a single long MDCT or several short MDCTs. >+When it is set, then the MDCT coefficients represent multiple >+short MDCTs in the frame. When not set, the coefficients represent a single >+long MDCT for the frame. The flag is encoded in the bitstream with a probability of 1/8. >+In addition to the global transient flag is a per-band >+binary flag to change the time-frequency (tf) resolution independently in each band. The >+change in tf resolution is defined in tf_select_table[][] in celt.c and depends >+on the frame size, whether the transient flag is set, and the value of tf_select. >+The tf_select flag uses a 1/2 probability, but is only decoded >+if it can have an impact on the result knowing the value of all per-band >+tf_change flags. >+</t> >+</section> >+ >+<section anchor="energy-decoding" title="Energy Envelope Decoding"> >+ >+<t> >+It is important to quantize the energy with sufficient resolution because >+any energy quantization error cannot be compensated for at a later >+stage. Regardless of the resolution used for encoding the spectral shape of a band, >+it is perceptually important to preserve the energy in each band. CELT uses a >+three-step coarse-fine-fine strategy for encoding the energy in the base-2 log >+domain, as implemented in quant_bands.c</t> >+ >+<section anchor="coarse-energy-decoding" title="Coarse energy decoding"> >+<t> >+Coarse quantization of the energy uses a fixed resolution of 6 dB >+(integer part of base-2 log). To minimize the bitrate, prediction is applied >+both in time (using the previous frame) and in frequency (using the previous >+bands). The part of the prediction that is based on the >+previous frame can be disabled, creating an "intra" frame where the energy >+is coded without reference to prior frames. The decoder first reads the intra flag >+to determine what prediction is used. >+The 2-D z-transform <xref target='z-transform'/> of >+the prediction filter is: >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+ -1 -1 >+ (1 - alpha*z_l )*(1 - z_b ) >+A(z_l, z_b) = ----------------------------- >+ -1 >+ 1 - beta*z_b >+]]></artwork> >+</figure> >+where b is the band index and l is the frame index. The prediction coefficients >+applied depend on the frame size in use when not using intra energy and are alpha=0, beta=4915/32768 >+when using intra energy. >+The time-domain prediction is based on the final fine quantization of the previous >+frame, while the frequency domain (within the current frame) prediction is based >+on coarse quantization only (because the fine quantization has not been computed >+yet). The prediction is clamped internally so that fixed point implementations with >+limited dynamic range always remain in the same state as floating point implementations. >+We approximate the ideal >+probability distribution of the prediction error using a Laplace distribution >+with separate parameters for each frame size in intra- and inter-frame modes. These >+parameters are held in the e_prob_model table in quant_bands.c. >+The >+coarse energy quantization is performed by unquant_coarse_energy() and >+unquant_coarse_energy_impl() (quant_bands.c). The encoding of the Laplace-distributed values is >+implemented in ec_laplace_decode() (laplace.c). >+</t> >+ >+</section> >+ >+<section anchor="fine-energy-decoding" title="Fine energy quantization"> >+<t> >+The number of bits assigned to fine energy quantization in each band is determined >+by the bit allocation computation described in <xref target="allocation"></xref>. >+Let B_i be the number of fine energy bits >+for band i; the refinement is an integer f in the range [0,2**B_i-1]. The mapping between f >+and the correction applied to the coarse energy is equal to (f+1/2)/2**B_i - 1/2. Fine >+energy quantization is implemented in quant_fine_energy() (quant_bands.c). >+</t> >+<t> >+When some bits are left "unused" after all other flags have been decoded, these bits >+are assigned to a "final" step of fine allocation. In effect, these bits are used >+to add one extra fine energy bit per band per channel. The allocation process >+determines two "priorities" for the final fine bits. >+Any remaining bits are first assigned only to bands of priority 0, starting >+from band 0 and going up. If all bands of priority 0 have received one bit per >+channel, then bands of priority 1 are assigned an extra bit per channel, >+starting from band 0. If any bits are left after this, they are left unused. >+This is implemented in unquant_energy_finalise() (quant_bands.c). >+</t> >+ >+</section> <!-- fine energy --> >+ >+</section> <!-- Energy decode --> >+ >+<section anchor="allocation" title="Bit Allocation"> >+ >+<t>Because the bit allocation drives the decoding of the range-coder >+stream, it MUST be recovered exactly so that identical coding decisions are >+made in the encoder and decoder. Any deviation from the reference's resulting >+bit allocation will result in corrupted output, though implementers are >+free to implement the procedure in any way which produces identical results.</t> >+ >+<t>The per-band gain-shape structure of the CELT layer ensures that using >+ the same number of bits for the spectral shape of a band in every frame will >+ result in a roughly constant signal-to-noise ratio in that band. >+This results in coding noise that has the same spectral envelope as the signal. >+The masking curve produced by a standard psychoacoustic model also closely >+ follows the spectral envelope of the signal. >+This structure means that the ideal allocation is more consistent from frame to >+ frame than it is for other codecs without an equivalent structure, and that a >+ fixed allocation provides fairly consistent perceptual >+ performance <xref target='Valin2010'/>.</t> >+ >+<t>Many codecs transmit significant amounts of side information to control the >+ bit allocation within a frame. >+Often this control is only indirect, and must be exercised carefully to >+ achieve the desired rate constraints. >+The CELT layer, however, can adapt over a very wide range of rates, and thus >+ has a large number of codebook sizes to choose from for each band. >+Explicitly signaling the size of each of these codebooks would impose >+ considerable overhead, even though the allocation is relatively static from >+ frame to frame. >+This is because all of the information required to compute these codebook sizes >+ must be derived from a single frame by itself, in order to retain robustness >+ to packet loss, so the signaling cannot take advantage of knowledge of the >+ allocation in neighboring frames. >+This problem is exacerbated in low-latency (small frame size) applications, >+ which would include this overhead in every frame.</t> >+ >+<t>For this reason, in the MDCT mode Opus uses a primarily implicit bit >+allocation. The available bitstream capacity is known in advance to both >+the encoder and decoder without additional signaling, ultimately from the >+packet sizes expressed by a higher-level protocol. Using this information, >+the codec interpolates an allocation from a hard-coded table.</t> >+ >+<t>While the band-energy structure effectively models intra-band masking, >+it ignores the weaker inter-band masking, band-temporal masking, and >+other less significant perceptual effects. While these effects can >+often be ignored, they can become significant for particular samples. One >+mechanism available to encoders would be to simply increase the overall >+rate for these frames, but this is not possible in a constant rate mode >+and can be fairly inefficient. As a result three explicitly signaled >+mechanisms are provided to alter the implicit allocation:</t> >+ >+<t> >+<list style="symbols"> >+<t>Band boost</t> >+<t>Allocation trim</t> >+<t>Band skipping</t> >+</list> >+</t> >+ >+<t>The first of these mechanisms, band boost, allows an encoder to boost >+the allocation in specific bands. The second, allocation trim, works by >+biasing the overall allocation towards higher or lower frequency bands. The third, band >+skipping, selects which low-precision high frequency bands >+will be allocated no shape bits at all.</t> >+ >+<t>In stereo mode there are two additional parameters >+potentially coded as part of the allocation procedure: a parameter to allow the >+selective elimination of allocation for the 'side' (i.e., intensity stereo) in jointly coded bands, >+and a flag to deactivate joint coding (i.e., dual stereo). These values are not signaled if >+they would be meaningless in the overall context of the allocation.</t> >+ >+<t>Because every signaled adjustment increases overhead and implementation >+complexity, none were included speculatively: the reference encoder makes use >+of all of these mechanisms. While the decision logic in the reference was >+found to be effective enough to justify the overhead and complexity, further >+analysis techniques may be discovered which increase the effectiveness of these >+parameters. As with other signaled parameters, an encoder is free to choose the >+values in any manner, but unless a technique is known to deliver superior >+perceptual results the methods used by the reference implementation should be >+used.</t> >+ >+<t>The allocation process consists of the following steps: determining the per-band >+maximum allocation vector, decoding the boosts, decoding the tilt, determining >+the remaining capacity of the frame, searching the mode table for the >+entry nearest but not exceeding the available space (subject to the tilt, boosts, band >+maximums, and band minimums), linear interpolation, reallocation of >+unused bits with concurrent skip decoding, determination of the >+fine-energy vs. shape split, and final reallocation. This process results >+in a per-band shape allocation (in 1/8th bit units), a per-band fine-energy >+allocation (in 1 bit per channel units), a set of band priorities for >+controlling the use of remaining bits at the end of the frame, and a >+remaining balance of unallocated space, which is usually zero except >+at very high rates.</t> >+ >+<t> >+The "static" bit allocation (in 1/8 bits) for a quality q, excluding the minimums, maximums, >+tilt and boosts, is equal to channels*N*alloc[band][q]<<LM>>2, where >+alloc[][] is given in <xref target="static_alloc"/> and LM=log2(frame_size/120). The allocation >+is obtained by linearly interpolating between two values of q (in steps of 1/64) to find the >+highest allocation that does not exceed the number of bits remaining. >+</t> >+ >+<texttable anchor="static_alloc" >+ title="CELT Static Allocation Table"> >+ <preamble>Rows indicate the MDCT bands, columns are the different quality (q) parameters. The units are 1/32 bit per MDCT bin.</preamble> >+<ttcol align="right">0</ttcol> >+<ttcol align="right">1</ttcol> >+<ttcol align="right">2</ttcol> >+<ttcol align="right">3</ttcol> >+<ttcol align="right">4</ttcol> >+<ttcol align="right">5</ttcol> >+<ttcol align="right">6</ttcol> >+<ttcol align="right">7</ttcol> >+<ttcol align="right">8</ttcol> >+<ttcol align="right">9</ttcol> >+<ttcol align="right">10</ttcol> >+<c>0</c><c>90</c><c>110</c><c>118</c><c>126</c><c>134</c><c>144</c><c>152</c><c>162</c><c>172</c><c>200</c> >+<c>0</c><c>80</c><c>100</c><c>110</c><c>119</c><c>127</c><c>137</c><c>145</c><c>155</c><c>165</c><c>200</c> >+<c>0</c><c>75</c><c>90</c><c>103</c><c>112</c><c>120</c><c>130</c><c>138</c><c>148</c><c>158</c><c>200</c> >+<c>0</c><c>69</c><c>84</c><c>93</c><c>104</c><c>114</c><c>124</c><c>132</c><c>142</c><c>152</c><c>200</c> >+<c>0</c><c>63</c><c>78</c><c>86</c><c>95</c><c>103</c><c>113</c><c>123</c><c>133</c><c>143</c><c>200</c> >+<c>0</c><c>56</c><c>71</c><c>80</c><c>89</c><c>97</c><c>107</c><c>117</c><c>127</c><c>137</c><c>200</c> >+<c>0</c><c>49</c><c>65</c><c>75</c><c>83</c><c>91</c><c>101</c><c>111</c><c>121</c><c>131</c><c>200</c> >+<c>0</c><c>40</c><c>58</c><c>70</c><c>78</c><c>85</c><c>95</c><c>105</c><c>115</c><c>125</c><c>200</c> >+<c>0</c><c>34</c><c>51</c><c>65</c><c>72</c><c>78</c><c>88</c><c>98</c><c>108</c><c>118</c><c>198</c> >+<c>0</c><c>29</c><c>45</c><c>59</c><c>66</c><c>72</c><c>82</c><c>92</c><c>102</c><c>112</c><c>193</c> >+<c>0</c><c>20</c><c>39</c><c>53</c><c>60</c><c>66</c><c>76</c><c>86</c><c>96</c><c>106</c><c>188</c> >+<c>0</c><c>18</c><c>32</c><c>47</c><c>54</c><c>60</c><c>70</c><c>80</c><c>90</c><c>100</c><c>183</c> >+<c>0</c><c>10</c><c>26</c><c>40</c><c>47</c><c>54</c><c>64</c><c>74</c><c>84</c><c>94</c><c>178</c> >+<c>0</c><c>0</c><c>20</c><c>31</c><c>39</c><c>47</c><c>57</c><c>67</c><c>77</c><c>87</c><c>173</c> >+<c>0</c><c>0</c><c>12</c><c>23</c><c>32</c><c>41</c><c>51</c><c>61</c><c>71</c><c>81</c><c>168</c> >+<c>0</c><c>0</c><c>0</c><c>15</c><c>25</c><c>35</c><c>45</c><c>55</c><c>65</c><c>75</c><c>163</c> >+<c>0</c><c>0</c><c>0</c><c>4</c><c>17</c><c>29</c><c>39</c><c>49</c><c>59</c><c>69</c><c>158</c> >+<c>0</c><c>0</c><c>0</c><c>0</c><c>12</c><c>23</c><c>33</c><c>43</c><c>53</c><c>63</c><c>153</c> >+<c>0</c><c>0</c><c>0</c><c>0</c><c>1</c><c>16</c><c>26</c><c>36</c><c>46</c><c>56</c><c>148</c> >+<c>0</c><c>0</c><c>0</c><c>0</c><c>0</c><c>10</c><c>15</c><c>20</c><c>30</c><c>45</c><c>129</c> >+<c>0</c><c>0</c><c>0</c><c>0</c><c>0</c><c>1</c><c>1</c><c>1</c><c>1</c><c>20</c><c>104</c> >+</texttable> >+ >+<t>The maximum allocation vector is an approximation of the maximum space >+that can be used by each band for a given mode. The value is >+approximate because the shape encoding is variable rate (due >+to entropy coding of splitting parameters). Setting the maximum too low reduces the >+maximum achievable quality in a band while setting it too high >+may result in waste: bitstream capacity available at the end >+of the frame which can not be put to any use. The maximums >+specified by the codec reflect the average maximum. In the reference >+implementation, the maximums in bits/sample are precomputed in a static table >+(see cache_caps50[] in static_modes_float.h) for each band, >+for each value of LM, and for both mono and stereo. >+ >+Implementations are expected >+to simply use the same table data, but the procedure for generating >+this table is included in rate.c as part of compute_pulse_cache().</t> >+ >+<t>To convert the values in cache.caps into the actual maximums: first >+set nbBands to the maximum number of bands for this mode, and stereo to >+zero if stereo is not in use and one otherwise. For each band set N >+to the number of MDCT bins covered by the band (for one channel), set LM >+to the shift value for the frame size, >+then set i to nbBands*(2*LM+stereo). Then set the maximum for the band to >+the i-th index of cache.caps + 64 and multiply by the number of channels >+in the current frame (one or two) and by N, then divide the result by 4 >+using integer division. The resulting vector will be called >+cap[]. The elements fit in signed 16-bit integers but do not fit in 8 bits. >+This procedure is implemented in the reference in the function init_caps() in celt.c. >+</t> >+ >+<t>The band boosts are represented by a series of binary symbols which >+are entropy coded with very low probability. Each band can potentially be boosted >+multiple times, subject to the frame actually having enough room to obey >+the boost and having enough room to code the boost symbol. The default >+coding cost for a boost starts out at six bits (probability p=1/64), but subsequent boosts >+in a band cost only a single bit and every time a band is boosted the >+initial cost is reduced (down to a minimum of two bits, or p=1/4). Since the initial >+cost of coding a boost is 6 bits, the coding cost of the boost symbols when >+completely unused is 0.48 bits/frame for a 21 band mode (21*-log2(1-1/2**6)).</t> >+ >+<t>To decode the band boosts: First set 'dynalloc_logp' to 6, the initial >+amount of storage required to signal a boost in bits, 'total_bits' to the >+size of the frame in 8th bits, 'total_boost' to zero, and 'tell' to the total number >+of 8th bits decoded >+so far. For each band from the coding start (0 normally, but 17 in Hybrid mode) >+to the coding end (which changes depending on the signaled bandwidth), the boost quanta >+in units of 1/8 bit is calculated as quanta = min(8*N, max(48, N)). >+This represents a boost step size of six bits, subject to a lower limit of >+1/8th bit/sample and an upper limit of 1 bit/sample. >+Set 'boost' to zero and 'dynalloc_loop_logp' >+to dynalloc_logp. While dynalloc_loop_log (the current worst case symbol cost) in >+8th bits plus tell is less than total_bits plus total_boost and boost is less than cap[] for this >+band: Decode a bit from the bitstream with a with dynalloc_loop_logp as the cost >+of a one, update tell to reflect the current used capacity, if the decoded value >+is zero break the loop otherwise add quanta to boost and total_boost, subtract quanta from >+total_bits, and set dynalloc_loop_log to 1. When the while loop finishes >+boost contains the boost for this band. If boost is non-zero and dynalloc_logp >+is greater than 2, decrease dynalloc_logp. Once this process has been >+executed on all bands, the band boosts have been decoded. This procedure >+is implemented around line 2474 of celt.c.</t> >+ >+<t>At very low rates it is possible that there won't be enough available >+space to execute the inner loop even once. In these cases band boost >+is not possible but its overhead is completely eliminated. Because of the >+high cost of band boost when activated, a reasonable encoder should not be >+using it at very low rates. The reference implements its dynalloc decision >+logic around line 1304 of celt.c.</t> >+ >+<t>The allocation trim is a integer value from 0-10. The default value of >+5 indicates no trim. The trim parameter is entropy coded in order to >+lower the coding cost of less extreme adjustments. Values lower than >+5 bias the allocation towards lower frequencies and values above 5 >+bias it towards higher frequencies. Like other signaled parameters, signaling >+of the trim is gated so that it is not included if there is insufficient space >+available in the bitstream. To decode the trim, first set >+the trim value to 5, then if and only if the count of decoded 8th bits so far (ec_tell_frac) >+plus 48 (6 bits) is less than or equal to the total frame size in 8th >+bits minus total_boost (a product of the above band boost procedure), >+decode the trim value using the PDF in <xref target="celt_trim_pdf"/>.</t> >+ >+<texttable anchor="celt_trim_pdf" title="PDF for the Trim"> >+<ttcol>PDF</ttcol> >+<c>{1, 1, 2, 5, 10, 22, 46, 22, 10, 5, 2, 2}/128</c> >+</texttable> >+ >+<t>For 10 ms and 20 ms frames using short blocks and that have at least LM+2 bits left prior to >+the allocation process, then one anti-collapse bit is reserved in the allocation process so it can >+be decoded later. Following the the anti-collapse reservation, one bit is reserved for skip if available.</t> >+ >+<t>For stereo frames, bits are reserved for intensity stereo and for dual stereo. Intensity stereo >+requires ilog2(end-start) bits. Those bits are reserved if there is enough bits left. Following this, one >+bit is reserved for dual stereo if available.</t> >+ >+ >+<t>The allocation computation begins by setting up some initial conditions. >+'total' is set to the remaining available 8th bits, computed by taking the >+size of the coded frame times 8 and subtracting ec_tell_frac(). From this value, one (8th bit) >+is subtracted to ensure that the resulting allocation will be conservative. 'anti_collapse_rsv' >+is set to 8 (8th bits) if and only if the frame is a transient, LM is greater than 1, and total is >+greater than or equal to (LM+2) * 8. Total is then decremented by anti_collapse_rsv and clamped >+to be equal to or greater than zero. 'skip_rsv' is set to 8 (8th bits) if total is greater than >+8, otherwise it is zero. Total is then decremented by skip_rsv. This reserves space for the >+final skipping flag.</t> >+ >+<t>If the current frame is stereo, intensity_rsv is set to the conservative log2 in 8th bits >+of the number of coded bands for this frame (given by the table LOG2_FRAC_TABLE in rate.c). If >+intensity_rsv is greater than total then intensity_rsv is set to zero. Otherwise total is >+decremented by intensity_rsv, and if total is still greater than 8, dual_stereo_rsv is >+set to 8 and total is decremented by dual_stereo_rsv.</t> >+ >+<t>The allocation process then computes a vector representing the hard minimum amounts allocation >+any band will receive for shape. This minimum is higher than the technical limit of the PVQ >+process, but very low rate allocations produce an excessively sparse spectrum and these bands >+are better served by having no allocation at all. For each coded band, set thresh[band] to >+twenty-four times the number of MDCT bins in the band and divide by 16. If 8 times the number >+of channels is greater, use that instead. This sets the minimum allocation to one bit per channel >+or 48 128th bits per MDCT bin, whichever is greater. The band-size dependent part of this >+value is not scaled by the channel count, because at the very low rates where this limit is >+applicable there will usually be no bits allocated to the side.</t> >+ >+<t>The previously decoded allocation trim is used to derive a vector of per-band adjustments, >+'trim_offsets[]'. For each coded band take the alloc_trim and subtract 5 and LM. Then multiply >+the result by the number of channels, the number of MDCT bins in the shortest frame size for this mode, >+the number of remaining bands, 2**LM, and 8. Then divide this value by 64. Finally, if the >+number of MDCT bins in the band per channel is only one, 8 times the number of channels is subtracted >+in order to diminish the allocation by one bit, because width 1 bands receive greater benefit >+from the coarse energy coding.</t> >+ >+ >+</section> >+ >+<section anchor="PVQ-decoder" title="Shape Decoding"> >+<t> >+In each band, the normalized "shape" is encoded >+using a vector quantization scheme called a "pyramid vector quantizer". >+</t> >+ >+<t>In >+the simplest case, the number of bits allocated in >+<xref target="allocation"></xref> is converted to a number of pulses as described >+by <xref target="bits-pulses"></xref>. Knowing the number of pulses and the >+number of samples in the band, the decoder calculates the size of the codebook >+as detailed in <xref target="cwrs-decoder"></xref>. The size is used to decode >+an unsigned integer (uniform probability model), which is the codeword index. >+This index is converted into the corresponding vector as explained in >+<xref target="cwrs-decoder"></xref>. This vector is then scaled to unit norm. >+</t> >+ >+<section anchor="bits-pulses" title="Bits to Pulses"> >+<t> >+Although the allocation is performed in 1/8th bit units, the quantization requires >+an integer number of pulses K. To do this, the encoder searches for the value >+of K that produces the number of bits nearest to the allocated value >+(rounding down if exactly halfway between two values), not to exceed >+the total number of bits available. For efficiency reasons, the search is performed against a >+precomputed allocation table which only permits some K values for each N. The number of >+codebook entries can be computed as explained in <xref target="cwrs-decoder"></xref>. The difference >+between the number of bits allocated and the number of bits used is accumulated to a >+"balance" (initialized to zero) that helps adjust the >+allocation for the next bands. One third of the balance is applied to the >+bit allocation of each band to help achieve the target allocation. The only >+exceptions are the band before the last and the last band, for which half the balance >+and the whole balance are applied, respectively. >+</t> >+</section> >+ >+<section anchor="cwrs-decoder" title="PVQ Decoding"> >+ >+<t> >+Decoding of PVQ vectors is implemented in decode_pulses() (cwrs.c). >+The unique codeword index is decoded as a uniformly-distributed integer value between 0 and >+V(N,K)-1, where V(N,K) is the number of possible combinations of K pulses in >+N samples. The index is then converted to a vector in the same way specified in >+<xref target="PVQ"></xref>. The indexing is based on the calculation of V(N,K) >+(denoted N(L,K) in <xref target="PVQ"></xref>). >+</t> >+ >+<t> >+ The number of combinations can be computed recursively as >+V(N,K) = V(N-1,K) + V(N,K-1) + V(N-1,K-1), with V(N,0) = 1 and V(0,K) = 0, K != 0. >+There are many different ways to compute V(N,K), including precomputed tables and direct >+use of the recursive formulation. The reference implementation applies the recursive >+formulation one line (or column) at a time to save on memory use, >+along with an alternate, >+univariate recurrence to initialize an arbitrary line, and direct >+polynomial solutions for small N. All of these methods are >+equivalent, and have different trade-offs in speed, memory usage, and >+code size. Implementations MAY use any methods they like, as long as >+they are equivalent to the mathematical definition. >+</t> >+ >+<t> >+The decoded vector X is recovered as follows. >+Let i be the index decoded with the procedure in <xref target="ec_dec_uint"/> >+ with ft = V(N,K), so that 0 <= i < V(N,K). >+Let k = K. >+Then for j = 0 to (N - 1), inclusive, do: >+<list style="numbers"> >+<t>Let p = (V(N-j-1,k) + V(N-j,k))/2.</t> >+<t> >+If i < p, then let sgn = 1, else let sgn = -1 >+ and set i = i - p. >+</t> >+<t>Let k0 = k and set p = p - V(N-j-1,k).</t> >+<t> >+While p > i, set k = k - 1 and >+ p = p - V(N-j-1,k). >+</t> >+<t> >+Set X[j] = sgn*(k0 - k) and i = i - p. >+</t> >+</list> >+</t> >+ >+<t> >+The decoded vector X is then normalized such that its >+L2-norm equals one. >+</t> >+</section> >+ >+<section anchor="spreading" title="Spreading"> >+<t> >+The normalized vector decoded in <xref target="cwrs-decoder"/> is then rotated >+for the purpose of avoiding tonal artifacts. The rotation gain is equal to >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+g_r = N / (N + f_r*K) >+]]></artwork> >+</figure> >+ >+where N is the number of dimensions, K is the number of pulses, and f_r depends on >+the value of the "spread" parameter in the bit-stream. >+</t> >+ >+<texttable anchor="spread values" title="Spreading Values"> >+<ttcol>Spread value</ttcol> >+<ttcol>f_r</ttcol> >+ <c>0</c> <c>infinite (no rotation)</c> >+ <c>1</c> <c>15</c> >+ <c>2</c> <c>10</c> >+ <c>3</c> <c>5</c> >+</texttable> >+ >+<t> >+The rotation angle is then calculated as >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+ 2 >+ pi * g_r >+theta = ---------- >+ 4 >+]]></artwork> >+</figure> >+A 2-D rotation R(i,j) between points x_i and x_j is defined as: >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+x_i' = cos(theta)*x_i + sin(theta)*x_j >+x_j' = -sin(theta)*x_i + cos(theta)*x_j >+]]></artwork> >+</figure> >+ >+An N-D rotation is then achieved by applying a series of 2-D rotations back and forth, in the >+following order: R(x_1, x_2), R(x_2, x_3), ..., R(x_N-2, X_N-1), R(x_N-1, X_N), >+R(x_N-2, X_N-1), ..., R(x_1, x_2). >+</t> >+ >+<t> >+If the decoded vector represents more >+than one time block, then this spreading process is applied separately on each time block. >+Also, if each block represents 8 samples or more, then another N-D rotation, by >+(pi/2-theta), is applied <spanx style="emph">before</spanx> the rotation described above. This >+extra rotation is applied in an interleaved manner with a stride equal to round(sqrt(N/nb_blocks)), >+i.e., it is applied independently for each set of sample S_k = {stride*n + k}, n=0..N/stride-1. >+</t> >+</section> >+ >+<section anchor="split" title="Split decoding"> >+<t> >+To avoid the need for multi-precision calculations when decoding PVQ codevectors, >+the maximum size allowed for codebooks is 32 bits. When larger codebooks are >+needed, the vector is instead split in two sub-vectors of size N/2. >+A quantized gain parameter with precision >+derived from the current allocation is entropy coded to represent the relative >+gains of each side of the split, and the entire decoding process is recursively >+applied. Multiple levels of splitting may be applied up to a limit of LM+1 splits. >+The same recursive mechanism is applied for the joint coding >+of stereo audio. >+</t> >+ >+</section> >+ >+<section anchor="tf-change" title="Time-Frequency change"> >+<t> >+The time-frequency (TF) parameters are used to control the time-frequency resolution tradeoff >+in each coded band. For each band, there are two possible TF choices. For the first >+band coded, the PDF is {3, 1}/4 for frames marked as transient and {15, 1}/16 for >+the other frames. For subsequent bands, the TF choice is coded relative to the >+previous TF choice with probability {15, 1}/15 for transient frames and {31, 1}/32 >+otherwise. The mapping between the decoded TF choices and the adjustment in TF >+resolution is shown in the tables below. >+</t> >+ >+<texttable anchor='tf_00' >+ title="TF Adjustments for Non-transient Frames and tf_select=0"> >+<ttcol align='center'>Frame size (ms)</ttcol> >+<ttcol align='center'>0</ttcol> >+<ttcol align='center'>1</ttcol> >+<c>2.5</c> <c>0</c> <c>-1</c> >+<c>5</c> <c>0</c> <c>-1</c> >+<c>10</c> <c>0</c> <c>-2</c> >+<c>20</c> <c>0</c> <c>-2</c> >+</texttable> >+ >+<texttable anchor='tf_01' >+ title="TF Adjustments for Non-transient Frames and tf_select=1"> >+<ttcol align='center'>Frame size (ms)</ttcol> >+<ttcol align='center'>0</ttcol> >+<ttcol align='center'>1</ttcol> >+<c>2.5</c> <c>0</c> <c>-1</c> >+<c>5</c> <c>0</c> <c>-2</c> >+<c>10</c> <c>0</c> <c>-3</c> >+<c>20</c> <c>0</c> <c>-3</c> >+</texttable> >+ >+ >+<texttable anchor='tf_10' >+ title="TF Adjustments for Transient Frames and tf_select=0"> >+<ttcol align='center'>Frame size (ms)</ttcol> >+<ttcol align='center'>0</ttcol> >+<ttcol align='center'>1</ttcol> >+<c>2.5</c> <c>0</c> <c>-1</c> >+<c>5</c> <c>1</c> <c>0</c> >+<c>10</c> <c>2</c> <c>0</c> >+<c>20</c> <c>3</c> <c>0</c> >+</texttable> >+ >+<texttable anchor='tf_11' >+ title="TF Adjustments for Transient Frames and tf_select=1"> >+<ttcol align='center'>Frame size (ms)</ttcol> >+<ttcol align='center'>0</ttcol> >+<ttcol align='center'>1</ttcol> >+<c>2.5</c> <c>0</c> <c>-1</c> >+<c>5</c> <c>1</c> <c>-1</c> >+<c>10</c> <c>1</c> <c>-1</c> >+<c>20</c> <c>1</c> <c>-1</c> >+</texttable> >+ >+<t> >+A negative TF adjustment means that the temporal resolution is increased, >+while a positive TF adjustment means that the frequency resolution is increased. >+Changes in TF resolution are implemented using the Hadamard transform <xref target="Hadamard"/>. To increase >+the time resolution by N, N "levels" of the Hadamard transform are applied to the >+decoded vector for each interleaved MDCT vector. To increase the frequency resolution >+(assumes a transient frame), then N levels of the Hadamard transform are applied >+<spanx style="emph">across</spanx> the interleaved MDCT vector. In the case of increased >+time resolution the decoder uses the "sequency order" because the input vector >+is sorted in time. >+</t> >+</section> >+ >+ >+</section> >+ >+<section anchor="anti-collapse" title="Anti-Collapse Processing"> >+<t> >+The anti-collapse feature is designed to avoid the situation where the use of multiple >+short MDCTs causes the energy in one or more of the MDCTs to be zero for >+some bands, causing unpleasant artifacts. >+When the frame has the transient bit set, an anti-collapse bit is decoded. >+When anti-collapse is set, the energy in each small MDCT is prevented >+from collapsing to zero. For each band of each MDCT where a collapse is >+detected, a pseudo-random signal is inserted with an energy corresponding >+to the minimum energy over the two previous frames. A renormalization step is >+then required to ensure that the anti-collapse step did not alter the >+energy preservation property. >+</t> >+</section> >+ >+<section anchor="denormalization" title="Denormalization"> >+<t> >+Just as each band was normalized in the encoder, the last step of the decoder before >+the inverse MDCT is to denormalize the bands. Each decoded normalized band is >+multiplied by the square root of the decoded energy. This is done by denormalise_bands() >+(bands.c). >+</t> >+</section> >+ >+<section anchor="inverse-mdct" title="Inverse MDCT"> >+ >+ >+<t>The inverse MDCT implementation has no special characteristics. The >+input is N frequency-domain samples and the output is 2*N time-domain >+samples, while scaling by 1/2. A "low-overlap" window reduces the algorithmic delay. >+It is derived from a basic (full overlap) 240-sample version of the window used by the Vorbis codec: >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+ 2 >+ / /pi /pi n + 1/2\ \ \ >+W(n) = |sin|-- * sin|-- * -------| | | . >+ \ \2 \2 L / / / >+]]></artwork> >+</figure> >+The low-overlap window is created by zero-padding the basic window and inserting ones in the >+middle, such that the resulting window still satisfies power complementarity <xref target='Princen86'/>. >+The IMDCT and >+windowing are performed by mdct_backward (mdct.c). >+</t> >+ >+<section anchor="post-filter" title="Post-filter"> >+<t> >+The output of the inverse MDCT (after weighted overlap-add) is sent to the >+post-filter. Although the post-filter is applied at the end, the post-filter >+parameters are encoded at the beginning, just after the silence flag. >+The post-filter can be switched on or off using one bit (logp=1). >+If the post-filter is enabled, then the octave is decoded as an integer value >+between 0 and 6 of uniform probability. Once the octave is known, the fine pitch >+within the octave is decoded using 4+octave raw bits. The final pitch period >+is equal to (16<<octave)+fine_pitch-1 so it is bounded between 15 and 1022, >+inclusively. Next, the gain is decoded as three raw bits and is equal to >+G=3*(int_gain+1)/32. The set of post-filter taps is decoded last, using >+a pdf equal to {2, 1, 1}/4. Tapset zero corresponds to the filter coefficients >+g0 = 0.3066406250, g1 = 0.2170410156, g2 = 0.1296386719. Tapset one >+corresponds to the filter coefficients g0 = 0.4638671875, g1 = 0.2680664062, >+g2 = 0, and tapset two uses filter coefficients g0 = 0.7998046875, >+g1 = 0.1000976562, g2 = 0. >+</t> >+ >+<t> >+The post-filter response is thus computed as: >+ <figure align="center"> >+ <artwork align="center"> >+ <![CDATA[ >+ y(n) = x(n) + G*(g0*y(n-T) + g1*(y(n-T+1)+y(n-T+1)) >+ + g2*(y(n-T+2)+y(n-T+2))) >+]]> >+ </artwork> >+ </figure> >+ >+During a transition between different gains, a smooth transition is calculated >+using the square of the MDCT window. It is important that values of y(n) be >+interpolated one at a time such that the past value of y(n) used is interpolated. >+</t> >+</section> >+ >+<section anchor="deemphasis" title="De-emphasis"> >+<t> >+After the post-filter, >+the signal is de-emphasized using the inverse of the pre-emphasis filter >+used in the encoder: >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+ 1 1 >+---- = --------------- , >+A(z) -1 >+ 1 - alpha_p*z >+]]></artwork> >+</figure> >+where alpha_p=0.8500061035. >+</t> >+</section> >+ >+</section> >+ >+</section> >+ >+<section anchor="Packet Loss Concealment" title="Packet Loss Concealment (PLC)"> >+<t> >+Packet loss concealment (PLC) is an optional decoder-side feature that >+SHOULD be included when receiving from an unreliable channel. Because >+PLC is not part of the bitstream, there are many acceptable ways to >+implement PLC with different complexity/quality trade-offs. >+</t> >+ >+<t> >+The PLC in >+the reference implementation depends on the mode of last packet received. >+In CELT mode, the PLC finds a periodicity in the decoded >+signal and repeats the windowed waveform using the pitch offset. The windowed >+waveform is overlapped in such a way as to preserve the time-domain aliasing >+cancellation with the previous frame and the next frame. This is implemented >+in celt_decode_lost() (mdct.c). In SILK mode, the PLC uses LPC extrapolation >+from the previous frame, implemented in silk_PLC() (PLC.c). >+</t> >+ >+<section anchor="clock-drift" title="Clock Drift Compensation"> >+<t> >+Clock drift refers to the gradual desynchronization of two endpoints >+whose sample clocks run at different frequencies while they are streaming >+live audio. Differences in clock frequencies are generally attributable to >+manufacturing variation in the endpoints' clock hardware. For long-lived >+streams, the time difference between sender and receiver can grow without >+bound. >+</t> >+ >+<t> >+When the sender's clock runs slower than the receiver's, the effect is similar >+to packet loss: too few packets are received. The receiver can distinguish >+between drift and loss if the transport provides packet timestamps. A receiver >+for live streams SHOULD conceal the effects of drift, and MAY do so by invoking >+the PLC. >+</t> >+ >+<t> >+When the sender's clock runs faster than the receiver's, too many packets will >+be received. The receiver MAY respond by skipping any packet (i.e., not >+submitting the packet for decoding). This is likely to produce a less severe >+artifact than if the frame were dropped after decoding. >+</t> >+ >+<t> >+A decoder MAY employ a more sophisticated drift compensation method. For >+example, the >+<xref target='Google-NetEQ'>NetEQ component</xref> >+of the >+<xref target='Google-WebRTC'>Google WebRTC codebase</xref> >+compensates for drift by adding or removing >+one period when the signal is highly periodic. The reference implementation of >+Opus allows a caller to learn whether the current frame's signal is highly >+periodic, and if so what the period is, using the OPUS_GET_PITCH() request. >+</t> >+</section> >+ >+</section> >+ >+<section anchor="switching" title="Configuration Switching"> >+ >+<t> >+Switching between the Opus coding modes, audio bandwidths, and channel counts >+ requires careful consideration to avoid audible glitches. >+Switching between any two configurations of the CELT-only mode, any two >+ configurations of the Hybrid mode, or from WB SILK to Hybrid mode does not >+ require any special treatment in the decoder, as the MDCT overlap will smooth >+ the transition. >+Switching from Hybrid mode to WB SILK requires adding in the final contents >+ of the CELT overlap buffer to the first SILK-only packet. >+This can be done by decoding a 2.5 ms silence frame with the CELT decoder >+ using the channel count of the SILK-only packet (and any choice of audio >+ bandwidth), which will correctly handle the cases when the channel count >+ changes as well. >+</t> >+ >+<t> >+When changing the channel count for SILK-only or Hybrid packets, the encoder >+ can avoid glitches by smoothly varying the stereo width of the input signal >+ before or after the transition, and SHOULD do so. >+However, other transitions between SILK-only packets or between NB or MB SILK >+ and Hybrid packets may cause glitches, because neither the LSF coefficients >+ nor the LTP, LPC, stereo unmixing, and resampler buffers are available at the >+ new sample rate. >+These switches SHOULD be delayed by the encoder until quiet periods or >+ transients, where the inevitable glitches will be less audible. Additionally, >+ the bit-stream MAY include redundant side information ("redundancy"), in the >+ form of additional CELT frames embedded in each of the Opus frames around the >+ transition. >+</t> >+ >+<t> >+The other transitions that cannot be easily handled are those where the lower >+ frequencies switch between the SILK LP-based model and the CELT MDCT model. >+However, an encoder may not have an opportunity to delay such a switch to a >+ convenient point. >+For example, if the content switches from speech to music, and the encoder does >+ not have enough latency in its analysis to detect this in advance, there may >+ be no convenient silence period during which to make the transition for quite >+ some time. >+To avoid or reduce glitches during these problematic mode transitions, and >+ also between audio bandwidth changes in the SILK-only modes, transitions MAY >+ include redundant side information ("redundancy"), in the form of an >+ additional CELT frame embedded in the Opus frame. >+</t> >+ >+<t> >+A transition between coding the lower frequencies with the LP model and the >+ MDCT model or a transition that involves changing the SILK bandwidth >+ is only normatively specified when it includes redundancy. >+For those without redundancy, it is RECOMMENDED that the decoder use a >+ concealment technique (e.g., make use of a PLC algorithm) to "fill in" the >+ gap or discontinuity caused by the mode transition. >+Therefore, PLC MUST NOT be applied during any normative transition, i.e., when >+<list style="symbols"> >+<t>A packet includes redundancy for this transition (as described below),</t> >+<t>The transition is between any WB SILK packet and any Hybrid packet, or vice >+ versa,</t> >+<t>The transition is between any two Hybrid mode packets, or</t> >+<t>The transition is between any two CELT mode packets,</t> >+</list> >+ unless there is actual packet loss. >+</t> >+ >+<section anchor="side-info" title="Transition Side Information (Redundancy)"> >+<t> >+Transitions with side information include an extra 5 ms "redundant" CELT >+ frame within the Opus frame. >+This frame is designed to fill in the gap or discontinuity in the different >+ layers without requiring the decoder to conceal it. >+For transitions from CELT-only to SILK-only or Hybrid, the redundant frame is >+ inserted in the first Opus frame after the transition (i.e., the first >+ SILK-only or Hybrid frame). >+For transitions from SILK-only or Hybrid to CELT-only, the redundant frame is >+ inserted in the last Opus frame before the transition (i.e., the last >+ SILK-only or Hybrid frame). >+</t> >+ >+<section anchor="opus_redundancy_flag" title="Redundancy Flag"> >+<t> >+The presence of redundancy is signaled in all SILK-only and Hybrid frames, not >+ just those involved in a mode transition. >+This allows the frames to be decoded correctly even if an adjacent frame is >+ lost. >+For SILK-only frames, this signaling is implicit, based on the size of the >+ of the Opus frame and the number of bits consumed decoding the SILK portion of >+ it. >+After decoding the SILK portion of the Opus frame, the decoder uses ec_tell() >+ (see <xref target="ec_tell"/>) to check if there are at least 17 bits >+ remaining. >+If so, then the frame contains redundancy. >+</t> >+ >+<t> >+For Hybrid frames, this signaling is explicit. >+After decoding the SILK portion of the Opus frame, the decoder uses ec_tell() >+ (see <xref target="ec_tell"/>) to ensure there are at least 37 bits remaining. >+If so, it reads a symbol with the PDF in >+ <xref target="opus_redundancy_flag_pdf"/>, and if the value is 1, then the >+ frame contains redundancy. >+Otherwise (if there were fewer than 37 bits left or the value was 0), the frame >+ does not contain redundancy. >+</t> >+ >+<texttable anchor="opus_redundancy_flag_pdf" title="Redundancy Flag PDF"> >+<ttcol>PDF</ttcol> >+<c>{4095, 1}/4096</c> >+</texttable> >+</section> >+ >+<section anchor="opus_redundancy_pos" title="Redundancy Position Flag"> >+<t> >+Since the current frame is a SILK-only or a Hybrid frame, it must be at least >+ 10 ms. >+Therefore, it needs an additional flag to indicate whether the redundant >+ 5 ms CELT frame should be mixed into the beginning of the current frame, >+ or the end. >+After determining that a frame contains redundancy, the decoder reads a >+ 1 bit symbol with a uniform PDF >+ (<xref target="opus_redundancy_pos_pdf"/>). >+</t> >+ >+<texttable anchor="opus_redundancy_pos_pdf" title="Redundancy Position PDF"> >+<ttcol>PDF</ttcol> >+<c>{1, 1}/2</c> >+</texttable> >+ >+<t> >+If the value is zero, this is the first frame in the transition, and the >+ redundancy belongs at the end. >+If the value is one, this is the second frame in the transition, and the >+ redundancy belongs at the beginning. >+There is no way to specify that an Opus frame contains separate redundant CELT >+ frames at both the beginning and the end. >+</t> >+</section> >+ >+<section anchor="opus_redundancy_size" title="Redundancy Size"> >+<t> >+Unlike the CELT portion of a Hybrid frame, the redundant CELT frame does not >+ use the same entropy coder state as the rest of the Opus frame, because this >+ would break the CELT bit allocation mechanism in Hybrid frames. >+Thus, a redundant CELT frame always starts and ends on a byte boundary, even in >+ SILK-only frames, where this is not strictly necessary. >+</t> >+ >+<t> >+For SILK-only frames, the number of bytes in the redundant CELT frame is simply >+ the number of whole bytes remaining, which must be at least 2, due to the >+ space check in <xref target="opus_redundancy_flag"/>. >+For Hybrid frames, the number of bytes is equal to 2, plus a decoded unsigned >+ integer less than 256 (see <xref target="ec_dec_uint"/>). >+This may be more than the number of whole bytes remaining in the Opus frame, >+ in which case the frame is invalid. >+However, a decoder is not required to ignore the entire frame, as this may be >+ the result of a bit error that desynchronized the range coder. >+There may still be useful data before the error, and a decoder MAY keep any >+ audio decoded so far instead of invoking the PLC, but it is RECOMMENDED that >+ the decoder stop decoding and discard the rest of the current Opus frame. >+</t> >+ >+<t> >+It would have been possible to avoid these invalid states in the design of Opus >+ by limiting the range of the explicit length decoded from Hybrid frames by the >+ actual number of whole bytes remaining. >+However, this would require an encoder to determine the rate allocation for the >+ MDCT layer up front, before it began encoding that layer. >+By allowing some invalid sizes, the encoder is able to defer that decision >+ until much later. >+When encoding Hybrid frames which do not include redundancy, the encoder must >+ still decide up-front if it wishes to use the minimum 37 bits required to >+ trigger encoding of the redundancy flag, but this is a much looser >+ restriction. >+</t> >+ >+<t> >+After determining the size of the redundant CELT frame, the decoder reduces >+ the size of the buffer currently in use by the range coder by that amount. >+The CELT layer read any raw bits from the end of this reduced buffer, and all >+ calculations of the number of bits remaining in the buffer must be done using >+ this new, reduced size, rather than the original size of the Opus frame. >+</t> >+</section> >+ >+<section anchor="opus_redundancy_decoding" title="Decoding the Redundancy"> >+<t> >+The redundant frame is decoded like any other CELT-only frame, with the >+ exception that it does not contain a TOC byte. >+The frame size is fixed at 5 ms, the channel count is set to that of the >+ current frame, and the audio bandwidth is also set to that of the current >+ frame, with the exception that for MB SILK frames, it is set to WB. >+</t> >+ >+<t> >+If the redundancy belongs at the beginning (in a CELT-only to SILK-only or >+ Hybrid transition), the final reconstructed output uses the first 2.5 ms >+ of audio output by the decoder for the redundant frame as-is, discarding >+ the corresponding output from the SILK-only or Hybrid portion of the frame. >+The remaining 2.5 ms is cross-lapped with the decoded SILK/Hybrid signal >+ using the CELT's power-complementary MDCT window to ensure a smooth >+ transition. >+</t> >+ >+<t> >+If the redundancy belongs at the end (in a SILK-only or Hybrid to CELT-only >+ transition), only the second half (2.5 ms) of the audio output by the >+ decoder for the redundant frame is used. >+In that case, the second half of the redundant frame is cross-lapped with the >+ end of the SILK/Hybrid signal, again using CELT's power-complementary MDCT >+ window to ensure a smooth transition. >+</t> >+</section> >+ >+</section> >+ >+<section anchor="decoder-reset" title="State Reset"> >+<t> >+When a transition occurs, the state of the SILK or the CELT decoder (or both) >+ may need to be reset before decoding a frame in the new mode. >+This avoids reusing "out of date" memory, which may not have been updated in >+ some time or may not be in a well-defined state due to, e.g., PLC. >+The SILK state is reset before every SILK-only or Hybrid frame where the >+ previous frame was CELT-only. >+The CELT state is reset every time the operating mode changes and the new mode >+ is either Hybrid or CELT-only, except when the transition uses redundancy as >+ described above. >+When switching from SILK-only or Hybrid to CELT-only with redundancy, the CELT >+ state is reset before decoding the redundant CELT frame embedded in the >+ SILK-only or Hybrid frame, but it is not reset before decoding the following >+ CELT-only frame. >+When switching from CELT-only mode to SILK-only or Hybrid mode with redundancy, >+ the CELT decoder is not reset for decoding the redundant CELT frame. >+</t> >+</section> >+ >+<section title="Summary of Transitions"> >+ >+<t> >+<xref target="normative_transitions"/> illustrates all of the normative >+ transitions involving a mode change, an audio bandwidth change, or both. >+Each one uses an S, H, or C to represent an Opus frame in the corresponding >+ mode. >+In addition, an R indicates the presence of redundancy in the Opus frame it is >+ cross-lapped with. >+Its location in the first or last 5 ms is assumed to correspond to whether >+ it is the frame before or after the transition. >+Other uses of redundancy are non-normative. >+Finally, a c indicates the contents of the CELT overlap buffer after the >+ previously decoded frame (i.e., as extracted by decoding a silence frame). >+<figure align="center" anchor="normative_transitions" >+ title="Normative Transitions"> >+<artwork align="center"><![CDATA[ >+SILK to SILK with Redundancy: S -> S -> S >+ & >+ !R -> R >+ & >+ ;S -> S -> S >+ >+NB or MB SILK to Hybrid with Redundancy: S -> S -> S >+ & >+ !R ->;H -> H -> H >+ >+WB SILK to Hybrid: S -> S -> S ->!H -> H -> H >+ >+SILK to CELT with Redundancy: S -> S -> S >+ & >+ !R -> C -> C -> C >+ >+Hybrid to NB or MB SILK with Redundancy: H -> H -> H >+ & >+ !R -> R >+ & >+ ;S -> S -> S >+ >+Hybrid to WB SILK: H -> H -> H -> c >+ \ + >+ > S -> S -> S >+ >+Hybrid to CELT with Redundancy: H -> H -> H >+ & >+ !R -> C -> C -> C >+ >+CELT to SILK with Redundancy: C -> C -> C -> R >+ & >+ ;S -> S -> S >+ >+CELT to Hybrid with Redundancy: C -> C -> C -> R >+ & >+ |H -> H -> H >+ >+Key: >+S SILK-only frame ; SILK decoder reset >+H Hybrid frame | CELT and SILK decoder resets >+C CELT-only frame ! CELT decoder reset >+c CELT overlap + Direct mixing >+R Redundant CELT frame & Windowed cross-lap >+]]></artwork> >+</figure> >+The first two and the last two Opus frames in each example are illustrative, >+ i.e., there is no requirement that a stream remain in the same configuration >+ for three consecutive frames before or after a switch. >+</t> >+ >+<t> >+The behavior of transitions without redundancy where PLC is allowed is non-normative. >+An encoder might still wish to use these transitions if, for example, it >+ doesn't want to add the extra bitrate required for redundancy or if it makes >+ a decision to switch after it has already transmitted the frame that would >+ have had to contain the redundancy. >+<xref target="nonnormative_transitions"/> illustrates the recommended >+ cross-lapping and decoder resets for these transitions. >+<figure align="center" anchor="nonnormative_transitions" >+ title="Recommended Non-Normative Transitions"> >+<artwork align="center"><![CDATA[ >+SILK to SILK (audio bandwidth change): S -> S -> S ;S -> S -> S >+ >+NB or MB SILK to Hybrid: S -> S -> S |H -> H -> H >+ >+SILK to CELT without Redundancy: S -> S -> S -> P >+ & >+ !C -> C -> C >+ >+Hybrid to NB or MB SILK: H -> H -> H -> c >+ + >+ ;S -> S -> S >+ >+Hybrid to CELT without Redundancy: H -> H -> H -> P >+ & >+ !C -> C -> C >+ >+CELT to SILK without Redundancy: C -> C -> C -> P >+ & >+ ;S -> S -> S >+ >+CELT to Hybrid without Redundancy: C -> C -> C -> P >+ & >+ |H -> H -> H >+ >+Key: >+S SILK-only frame ; SILK decoder reset >+H Hybrid frame | CELT and SILK decoder resets >+C CELT-only frame ! CELT decoder reset >+c CELT overlap + Direct mixing >+P Packet Loss Concealment & Windowed cross-lap >+]]></artwork> >+</figure> >+Encoders SHOULD NOT use other transitions, e.g., those that involve redundancy >+ in ways not illustrated in <xref target="normative_transitions"/>. >+</t> >+ >+</section> >+ >+</section> >+ >+</section> >+ >+ >+<!-- ******************************************************************* --> >+<!-- ************************** OPUS ENCODER *********************** --> >+<!-- ******************************************************************* --> >+ >+<section title="Opus Encoder"> >+<t> >+Just like the decoder, the Opus encoder also normally consists of two main blocks: the >+SILK encoder and the CELT encoder. However, unlike the case of the decoder, a valid >+(though potentially suboptimal) Opus encoder is not required to support all modes and >+may thus only include a SILK encoder module or a CELT encoder module. >+The output bit-stream of the Opus encoding contains bits from the SILK and CELT >+ encoders, though these are not separable due to the use of a range coder. >+A block diagram of the encoder is illustrated below. >+ >+<figure align="center" anchor="opus-encoder-figure" title="Opus Encoder"> >+<artwork> >+<![CDATA[ >+ +------------+ +---------+ >+ | Sample | | SILK |------+ >+ +->| Rate |--->| Encoder | V >+ +-----------+ | | Conversion | | | +---------+ >+ | Optional | | +------------+ +---------+ | Range | >+->| High-pass |--+ | Encoder |----> >+ | Filter | | +--------------+ +---------+ | | Bit- >+ +-----------+ | | Delay | | CELT | +---------+ stream >+ +->| Compensation |->| Encoder | ^ >+ | | | |------+ >+ +--------------+ +---------+ >+]]> >+</artwork> >+</figure> >+</t> >+ >+<t> >+For a normal encoder where both the SILK and the CELT modules are included, an optimal >+encoder should select which coding mode to use at run-time depending on the conditions. >+In the reference implementation, the frame size is selected by the application, but the >+other configuration parameters (number of channels, bandwidth, mode) are automatically >+selected (unless explicitly overridden by the application) depend on the following: >+<list style="symbols"> >+<t>Requested bitrate</t> >+<t>Input sampling rate</t> >+<t>Type of signal (speech vs music)</t> >+<t>Frame size in use</t> >+</list> >+ >+The type of signal currently needs to be provided by the application (though it can be >+changed in real-time). An Opus encoder implementation could also do automatic detection, >+but since Opus is an interactive codec, such an implementation would likely have to either >+delay the signal (for non-interactive applications) or delay the mode switching decisions (for >+interactive applications). >+</t> >+ >+<t> >+When the encoder is configured for voice over IP applications, the input signal is >+filtered by a high-pass filter to remove the lowest part of the spectrum >+that contains little speech energy and may contain background noise. This is a second order >+Auto Regressive Moving Average (i.e., with poles and zeros) filter with a cut-off frequency around 50 Hz. >+In the future, a music detector may also be used to lower the cut-off frequency when the >+input signal is detected to be music rather than speech. >+</t> >+ >+<section anchor="range-encoder" title="Range Encoder"> >+<t> >+The range coder acts as the bit-packer for Opus. >+It is used in three different ways: to encode >+<list style="symbols"> >+<t> >+Entropy-coded symbols with a fixed probability model using ec_encode() >+ (entenc.c), >+</t> >+<t> >+Integers from 0 to (2**M - 1) using ec_enc_uint() or ec_enc_bits() >+ (entenc.c),</t> >+<t> >+Integers from 0 to (ft - 1) (where ft is not a power of two) using >+ ec_enc_uint() (entenc.c). >+</t> >+</list> >+</t> >+ >+<t> >+The range encoder maintains an internal state vector composed of the four-tuple >+ (val, rng, rem, ext) representing the low end of the current >+ range, the size of the current range, a single buffered output byte, and a >+ count of additional carry-propagating output bytes. >+Both val and rng are 32-bit unsigned integer values, rem is a byte value or >+ less than 255 or the special value -1, and ext is an unsigned integer with at >+ least 11 bits. >+This state vector is initialized at the start of each each frame to the value >+ (0, 2**31, -1, 0). >+After encoding a sequence of symbols, the value of rng in the encoder should >+ exactly match the value of rng in the decoder after decoding the same sequence >+ of symbols. >+This is a powerful tool for detecting errors in either an encoder or decoder >+ implementation. >+The value of val, on the other hand, represents different things in the encoder >+ and decoder, and is not expected to match. >+</t> >+ >+<t> >+The decoder has no analog for rem and ext. >+These are used to perform carry propagation in the renormalization loop below. >+Each iteration of this loop produces 9 bits of output, consisting of 8 data >+ bits and a carry flag. >+The encoder cannot determine the final value of the output bytes until it >+ propagates these carry flags. >+Therefore the reference implementation buffers a single non-propagating output >+ byte (i.e., one less than 255) in rem and keeps a count of additional >+ propagating (i.e., 255) output bytes in ext. >+An implementation may choose to use any mathematically equivalent scheme to >+ perform carry propagation. >+</t> >+ >+<section anchor="encoding-symbols" title="Encoding Symbols"> >+<t> >+The main encoding function is ec_encode() (entenc.c), which encodes symbol k in >+ the current context using the same three-tuple (fl[k], fh[k], ft) >+ as the decoder to describe the range of the symbol (see >+ <xref target="range-decoder"/>). >+</t> >+<t> >+ec_encode() updates the state of the encoder as follows. >+If fl[k] is greater than zero, then >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+ rng >+val = val + rng - --- * (ft - fl) , >+ ft >+ >+ rng >+rng = --- * (fh - fl) . >+ ft >+]]></artwork> >+</figure> >+Otherwise, val is unchanged and >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+ rng >+rng = rng - --- * (fh - fl) . >+ ft >+]]></artwork> >+</figure> >+The divisions here are integer division. >+</t> >+ >+<section anchor="range-encoder-renorm" title="Renormalization"> >+<t> >+After this update, the range is normalized using a procedure very similar to >+ that of <xref target="range-decoder-renorm"/>, implemented by >+ ec_enc_normalize() (entenc.c). >+The following process is repeated until rng > 2**23. >+First, the top 9 bits of val, (val>>23), are sent to the carry buffer, >+ described in <xref target="ec_enc_carry_out"/>. >+Then, the encoder sets >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+val = (val<<8) & 0x7FFFFFFF , >+ >+rng = rng<<8 . >+]]></artwork> >+</figure> >+</t> >+</section> >+ >+<section anchor="ec_enc_carry_out" >+ title="Carry Propagation and Output Buffering"> >+<t> >+The function ec_enc_carry_out() (entenc.c) implements carry propagation and >+ output buffering. >+It takes as input a 9-bit value, c, consisting of 8 data bits and an additional >+ carry bit. >+If c is equal to the value 255, then ext is simply incremented, and no other >+ state updates are performed. >+Otherwise, let b = (c>>8) be the carry bit. >+Then, >+<list style="symbols"> >+<t> >+If the buffered byte rem contains a value other than -1, the encoder outputs >+ the byte (rem + b). >+Otherwise, if rem is -1, no byte is output. >+</t> >+<t> >+If ext is non-zero, then the encoder outputs ext bytes---all with a value of 0 >+ if b is set, or 255 if b is unset---and sets ext to 0. >+</t> >+<t> >+rem is set to the 8 data bits: >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+rem = c & 255 . >+]]></artwork> >+</figure> >+</t> >+</list> >+</t> >+</section> >+ >+</section> >+ >+<section anchor="encoding-alternate" title="Alternate Encoding Methods"> >+<t> >+The reference implementation uses three additional encoding methods that are >+ exactly equivalent to the above, but make assumptions and simplifications that >+ allow for a more efficient implementation. >+</t> >+ >+<section anchor="ec_encode_bin" title="ec_encode_bin()"> >+<t> >+The first is ec_encode_bin() (entenc.c), defined using the parameter ftb >+ instead of ft. >+It is mathematically equivalent to calling ec_encode() with >+ ft = (1<<ftb), but avoids using division. >+</t> >+</section> >+ >+<section anchor="ec_enc_bit_logp" title="ec_enc_bit_logp()"> >+<t> >+The next is ec_enc_bit_logp() (entenc.c), which encodes a single binary symbol. >+The context is described by a single parameter, logp, which is the absolute >+ value of the base-2 logarithm of the probability of a "1". >+It is mathematically equivalent to calling ec_encode() with the 3-tuple >+ (fl[k] = 0, fh[k] = (1<<logp) - 1, >+ ft = (1<<logp)) if k is 0 and with >+ (fl[k] = (1<<logp) - 1, >+ fh[k] = ft = (1<<logp)) if k is 1. >+The implementation requires no multiplications or divisions. >+</t> >+</section> >+ >+<section anchor="ec_enc_icdf" title="ec_enc_icdf()"> >+<t> >+The last is ec_enc_icdf() (entenc.c), which encodes a single binary symbol with >+ a table-based context of up to 8 bits. >+This uses the same icdf table as ec_dec_icdf() from >+ <xref target="ec_dec_icdf"/>. >+The function is mathematically equivalent to calling ec_encode() with >+ fl[k] = (1<<ftb) - icdf[k-1] (or 0 if >+ k == 0), fh[k] = (1<<ftb) - icdf[k], and >+ ft = (1<<ftb). >+This only saves a few arithmetic operations over ec_encode_bin(), but allows >+ the encoder to use the same icdf tables as the decoder. >+</t> >+</section> >+ >+</section> >+ >+<section anchor="encoding-bits" title="Encoding Raw Bits"> >+<t> >+The raw bits used by the CELT layer are packed at the end of the buffer using >+ ec_enc_bits() (entenc.c). >+Because the raw bits may continue into the last byte output by the range coder >+ if there is room in the low-order bits, the encoder must be prepared to merge >+ these values into a single byte. >+The procedure in <xref target="encoder-finalizing"/> does this in a way that >+ ensures both the range coded data and the raw bits can be decoded >+ successfully. >+</t> >+</section> >+ >+<section anchor="encoding-ints" title="Encoding Uniformly Distributed Integers"> >+<t> >+The function ec_enc_uint() (entenc.c) encodes one of ft equiprobable symbols in >+ the range 0 to (ft - 1), inclusive, each with a frequency of 1, >+ where ft may be as large as (2**32 - 1). >+Like the decoder (see <xref target="ec_dec_uint"/>), it splits up the >+ value into a range coded symbol representing up to 8 of the high bits, and, if >+ necessary, raw bits representing the remainder of the value. >+</t> >+<t> >+ec_enc_uint() takes a two-tuple (t, ft), where t is the value to be >+ encoded, 0 <= t < ft, and ft is not necessarily a >+ power of two. >+Let ftb = ilog(ft - 1), i.e., the number of bits required >+ to store (ft - 1) in two's complement notation. >+If ftb is 8 or less, then t is encoded directly using ec_encode() with the >+ three-tuple (t, t + 1, ft). >+</t> >+<t> >+If ftb is greater than 8, then the top 8 bits of t are encoded using the >+ three-tuple (t>>(ftb - 8), >+ (t>>(ftb - 8)) + 1, >+ ((ft - 1)>>(ftb - 8)) + 1), and the >+ remaining bits, >+ (t & ((1<<(ftb - 8)) - 1), >+ are encoded as raw bits with ec_enc_bits(). >+</t> >+</section> >+ >+<section anchor="encoder-finalizing" title="Finalizing the Stream"> >+<t> >+After all symbols are encoded, the stream must be finalized by outputting a >+ value inside the current range. >+Let end be the integer in the interval [val, val + rng) with the >+ largest number of trailing zero bits, b, such that >+ (end + (1<<b) - 1) is also in the interval >+ [val, val + rng). >+This choice of end allows the maximum number of trailing bits to be set to >+ arbitrary values while still ensuring the range coded part of the buffer can >+ be decoded correctly. >+Then, while end is not zero, the top 9 bits of end, i.e., (end>>23), are >+ passed to the carry buffer in accordance with the procedure in >+ <xref target="ec_enc_carry_out"/>, and end is updated via >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+end = (end<<8) & 0x7FFFFFFF . >+]]></artwork> >+</figure> >+Finally, if the buffered output byte, rem, is neither zero nor the special >+ value -1, or the carry count, ext, is greater than zero, then 9 zero bits are >+ sent to the carry buffer to flush it to the output buffer. >+When outputting the final byte from the range coder, if it would overlap any >+ raw bits already packed into the end of the output buffer, they should be ORed >+ into the same byte. >+The bit allocation routines in the CELT layer should ensure that this can be >+ done without corrupting the range coder data so long as end is chosen as >+ described above. >+If there is any space between the end of the range coder data and the end of >+ the raw bits, it is padded with zero bits. >+This entire process is implemented by ec_enc_done() (entenc.c). >+</t> >+</section> >+ >+<section anchor="encoder-tell" title="Current Bit Usage"> >+<t> >+ The bit allocation routines in Opus need to be able to determine a >+ conservative upper bound on the number of bits that have been used >+ to encode the current frame thus far. This drives allocation >+ decisions and ensures that the range coder and raw bits will not >+ overflow the output buffer. This is computed in the >+ reference implementation to whole-bit precision by >+ the function ec_tell() (entcode.h) and to fractional 1/8th bit >+ precision by the function ec_tell_frac() (entcode.c). >+ Like all operations in the range coder, it must be implemented in a >+ bit-exact manner, and must produce exactly the same value returned by >+ the same functions in the decoder after decoding the same symbols. >+</t> >+</section> >+ >+</section> >+ >+<section title='SILK Encoder'> >+ <t> >+ In many respects the SILK encoder mirrors the SILK decoder described >+ in <xref target='silk_decoder_outline'/>. >+ Details such as the quantization and range coder tables can be found >+ there, while this section describes the high-level design choices that >+ were made. >+ The diagram below shows the basic modules of the SILK encoder. >+<figure align="center" anchor="silk_encoder_figure" title="SILK Encoder"> >+<artwork> >+<![CDATA[ >+ +----------+ +--------+ +---------+ >+ | Sample | | Stereo | | SILK | >+------>| Rate |--->| Mixing |--->| Core |----------> >+Input |Conversion| | | | Encoder | Bitstream >+ +----------+ +--------+ +---------+ >+]]> >+</artwork> >+</figure> >+</t> >+ >+<section title='Sample Rate Conversion'> >+<t> >+The input signal's sampling rate is adjusted by a sample rate conversion >+module so that it matches the SILK internal sampling rate. >+The input to the sample rate converter is delayed by a number of samples >+depending on the sample rate ratio, such that the overall delay is constant >+for all input and output sample rates. >+</t> >+</section> >+ >+<section title='Stereo Mixing'> >+<t> >+The stereo mixer is only used for stereo input signals. >+It converts a stereo left/right signal into an adaptive >+mid/side representation. >+The first step is to compute non-adaptive mid/side signals >+as half the sum and difference between left and right signals. >+The side signal is then minimized in energy by subtracting a >+prediction of it based on the mid signal. >+This prediction works well when the left and right signals >+exhibit linear dependency, for instance for an amplitude-panned >+input signal. >+Like in the decoder, the prediction coefficients are linearly >+interpolated during the first 8 ms of the frame. >+ The mid signal is always encoded, whereas the residual >+ side signal is only encoded if it has sufficient >+ energy compared to the mid signal's energy. >+ If it has not, >+ the "mid_only_flag" is set without encoding the side signal. >+</t> >+<t> >+The predictor coefficients are coded regardless of whether >+the side signal is encoded. >+For each frame, two predictor coefficients are computed, one >+that predicts between low-passed mid and side channels, and >+one that predicts between high-passed mid and side channels. >+The low-pass filter is a simple three-tap filter >+and creates a delay of one sample. >+The high-pass filtered signal is the difference between >+the mid signal delayed by one sample and the low-passed >+signal. Instead of explicitly computing the high-passed >+signal, it is computationally more efficient to transform >+the prediction coefficients before applying them to the >+filtered mid signal, as follows >+<figure align="center"> >+<artwork align="center"> >+<![CDATA[ >+pred(n) = LP(n) * w0 + HP(n) * w1 >+ = LP(n) * w0 + (mid(n-1) - LP(n)) * w1 >+ = LP(n) * (w0 - w1) + mid(n-1) * w1 >+]]> >+</artwork> >+</figure> >+where w0 and w1 are the low-pass and high-pass prediction >+coefficients, mid(n-1) is the mid signal delayed by one sample, >+LP(n) and HP(n) are the low-passed and high-passed >+signals and pred(n) is the prediction signal that is subtracted >+from the side signal. >+</t> >+</section> >+ >+<section title='SILK Core Encoder'> >+<t> >+What follows is a description of the core encoder and its components. >+For simplicity, the core encoder is referred to simply as the encoder in >+the remainder of this section. An overview of the encoder is given in >+<xref target="encoder_figure" />. >+</t> >+<figure align="center" anchor="encoder_figure" title="SILK Core Encoder"> >+<artwork align="center"> >+<![CDATA[ >+ +---+ >+ +--------------------------------->| | >+ +---------+ | +---------+ | | >+ |Voice | | |LTP |12 | | >+ +-->|Activity |--+ +----->|Scaling |-----------+---->| | >+ | |Detector |3 | | |Control |<--+ | | | >+ | +---------+ | | +---------+ | | | | >+ | | | +---------+ | | | | >+ | | | |Gains | | | | | >+ | | | +-->|Processor|---|---+---|---->| R | >+ | | | | | |11 | | | | a | >+ | \/ | | +---------+ | | | | n | >+ | +---------+ | | +---------+ | | | | g | >+ | |Pitch | | | |LSF | | | | | e | >+ | +->|Analysis |---+ | |Quantizer|---|---|---|---->| | >+ | | | |4 | | | |8 | | | | E |--> >+ | | +---------+ | | +---------+ | | | | n | 2 >+ | | | | 9/\ 10| | | | | c | >+ | | | | | \/ | | | | o | >+ | | +---------+ | | +----------+ | | | | d | >+ | | |Noise | +--|-->|Prediction|--+---|---|---->| e | >+ | +->|Shaping |---|--+ |Analysis |7 | | | | r | >+ | | |Analysis |5 | | | | | | | | | >+ | | +---------+ | | +----------+ | | | | | >+ | | | | /\ | | | | | >+ | | +----------|--|--------+ | | | | | >+ | | | \/ \/ \/ \/ \/ | | >+ | | | +---------+ +------------+ | | >+ | | | | | |Noise | | | >+-+-------+-----+------>|Prefilter|--------->|Shaping |-->| | >+1 | | 6 |Quantization|13 | | >+ +---------+ +------------+ +---+ >+ >+1: Input speech signal >+2: Range encoded bitstream >+3: Voice activity estimate >+4: Pitch lags (per 5 ms) and voicing decision (per 20 ms) >+5: Noise shaping quantization coefficients >+ - Short term synthesis and analysis >+ noise shaping coefficients (per 5 ms) >+ - Long term synthesis and analysis noise >+ shaping coefficients (per 5 ms and for voiced speech only) >+ - Noise shaping tilt (per 5 ms) >+ - Quantizer gain/step size (per 5 ms) >+6: Input signal filtered with analysis noise shaping filters >+7: Short and long term prediction coefficients >+ LTP (per 5 ms) and LPC (per 20 ms) >+8: LSF quantization indices >+9: LSF coefficients >+10: Quantized LSF coefficients >+11: Processed gains, and synthesis noise shape coefficients >+12: LTP state scaling coefficient. Controlling error propagation >+ / prediction gain trade-off >+13: Quantized signal >+]]> >+</artwork> >+</figure> >+ >+<section title='Voice Activity Detection'> >+<t> >+The input signal is processed by a Voice Activity Detector (VAD) to produce >+a measure of voice activity, spectral tilt, and signal-to-noise estimates for >+each frame. The VAD uses a sequence of half-band filterbanks to split the >+signal into four subbands: 0...Fs/16, Fs/16...Fs/8, Fs/8...Fs/4, and >+Fs/4...Fs/2, where Fs is the sampling frequency (8, 12, 16, or 24 kHz). >+The lowest subband, from 0 - Fs/16, is high-pass filtered with a first-order >+moving average (MA) filter (with transfer function H(z) = 1-z**(-1)) to >+reduce the energy at the lowest frequencies. For each frame, the signal >+energy per subband is computed. >+In each subband, a noise level estimator tracks the background noise level >+and a Signal-to-Noise Ratio (SNR) value is computed as the logarithm of the >+ratio of energy to noise level. >+Using these intermediate variables, the following parameters are calculated >+for use in other SILK modules: >+<list style="symbols"> >+<t> >+Average SNR. The average of the subband SNR values. >+</t> >+ >+<t> >+Smoothed subband SNRs. Temporally smoothed subband SNR values. >+</t> >+ >+<t> >+Speech activity level. Based on the average SNR and a weighted average of the >+subband energies. >+</t> >+ >+<t> >+Spectral tilt. A weighted average of the subband SNRs, with positive weights >+for the low subbands and negative weights for the high subbands. >+</t> >+</list> >+</t> >+</section> >+ >+<section title='Pitch Analysis' anchor='pitch_estimator_overview_section'> >+<t> >+The input signal is processed by the open loop pitch estimator shown in >+<xref target='pitch_estimator_figure' />. >+<figure align="center" anchor="pitch_estimator_figure" >+ title="Block diagram of the pitch estimator"> >+<artwork align="center"> >+<![CDATA[ >+ +--------+ +----------+ >+ |2 x Down| |Time- | >+ +->|sampling|->|Correlator| | >+ | | | | | |4 >+ | +--------+ +----------+ \/ >+ | | 2 +-------+ >+ | | +-->|Speech |5 >+ +---------+ +--------+ | \/ | |Type |-> >+ |LPC | |Down | | +----------+ | | >+ +->|Analysis | +->|sample |-+------------->|Time- | +-------+ >+ | | | | |to 8 kHz| |Correlator|-----------> >+ | +---------+ | +--------+ |__________| 6 >+ | | | |3 >+ | \/ | \/ >+ | +---------+ | +----------+ >+ | |Whitening| | |Time- | >+-+->|Filter |-+--------------------------->|Correlator|-----------> >+1 | | | | 7 >+ +---------+ +----------+ >+ >+1: Input signal >+2: Lag candidates from stage 1 >+3: Lag candidates from stage 2 >+4: Correlation threshold >+5: Voiced/unvoiced flag >+6: Pitch correlation >+7: Pitch lags >+]]> >+</artwork> >+</figure> >+The pitch analysis finds a binary voiced/unvoiced classification, and, for >+frames classified as voiced, four pitch lags per frame - one for each >+5 ms subframe - and a pitch correlation indicating the periodicity of >+the signal. >+The input is first whitened using a Linear Prediction (LP) whitening filter, >+where the coefficients are computed through standard Linear Prediction Coding >+(LPC) analysis. The order of the whitening filter is 16 for best results, but >+is reduced to 12 for medium complexity and 8 for low complexity modes. >+The whitened signal is analyzed to find pitch lags for which the time >+correlation is high. >+The analysis consists of three stages for reducing the complexity: >+<list style="symbols"> >+<t>In the first stage, the whitened signal is downsampled to 4 kHz >+(from 8 kHz) and the current frame is correlated to a signal delayed >+by a range of lags, starting from a shortest lag corresponding to >+500 Hz, to a longest lag corresponding to 56 Hz.</t> >+ >+<t> >+The second stage operates on an 8 kHz signal (downsampled from 12, 16, >+or 24 kHz) and measures time correlations only near the lags >+corresponding to those that had sufficiently high correlations in the first >+stage. The resulting correlations are adjusted for a small bias towards >+short lags to avoid ending up with a multiple of the true pitch lag. >+The highest adjusted correlation is compared to a threshold depending on: >+<list style="symbols"> >+<t> >+Whether the previous frame was classified as voiced >+</t> >+<t> >+The speech activity level >+</t> >+<t> >+The spectral tilt. >+</t> >+</list> >+If the threshold is exceeded, the current frame is classified as voiced and >+the lag with the highest adjusted correlation is stored for a final pitch >+analysis of the highest precision in the third stage. >+</t> >+<t> >+The last stage operates directly on the whitened input signal to compute time >+correlations for each of the four subframes independently in a narrow range >+around the lag with highest correlation from the second stage. >+</t> >+</list> >+</t> >+</section> >+ >+<section title='Noise Shaping Analysis' anchor='noise_shaping_analysis_overview_section'> >+<t> >+The noise shaping analysis finds gains and filter coefficients used in the >+prefilter and noise shaping quantizer. These parameters are chosen such that >+they will fulfill several requirements: >+<list style="symbols"> >+<t> >+Balancing quantization noise and bitrate. >+The quantization gains determine the step size between reconstruction levels >+of the excitation signal. Therefore, increasing the quantization gain >+amplifies quantization noise, but also reduces the bitrate by lowering >+the entropy of the quantization indices. >+</t> >+<t> >+Spectral shaping of the quantization noise; the noise shaping quantizer is >+capable of reducing quantization noise in some parts of the spectrum at the >+cost of increased noise in other parts without substantially changing the >+bitrate. >+By shaping the noise such that it follows the signal spectrum, it becomes >+less audible. In practice, best results are obtained by making the shape >+of the noise spectrum slightly flatter than the signal spectrum. >+</t> >+<t> >+De-emphasizing spectral valleys; by using different coefficients in the >+analysis and synthesis part of the prefilter and noise shaping quantizer, >+the levels of the spectral valleys can be decreased relative to the levels >+of the spectral peaks such as speech formants and harmonics. >+This reduces the entropy of the signal, which is the difference between the >+coded signal and the quantization noise, thus lowering the bitrate. >+</t> >+<t> >+Matching the levels of the decoded speech formants to the levels of the >+original speech formants; an adjustment gain and a first order tilt >+coefficient are computed to compensate for the effect of the noise >+shaping quantization on the level and spectral tilt. >+</t> >+</list> >+</t> >+<t> >+<figure align="center" anchor="noise_shape_analysis_spectra_figure" >+ title="Noise shaping and spectral de-emphasis illustration"> >+<artwork align="center"> >+<![CDATA[ >+ / \ ___ >+ | // \\ >+ | // \\ ____ >+ |_// \\___// \\ ____ >+ | / ___ \ / \\ // \\ >+ P |/ / \ \_/ \\_____// \\ >+ o | / \ ____ \ / \\ >+ w | / \___/ \ \___/ ____ \\___ 1 >+ e |/ \ / \ \ >+ r | \_____/ \ \__ 2 >+ | \ >+ | \___ 3 >+ | >+ +----------------------------------------> >+ Frequency >+ >+1: Input signal spectrum >+2: De-emphasized and level matched spectrum >+3: Quantization noise spectrum >+]]> >+</artwork> >+</figure> >+<xref target='noise_shape_analysis_spectra_figure' /> shows an example of an >+input signal spectrum (1). >+After de-emphasis and level matching, the spectrum has deeper valleys (2). >+The quantization noise spectrum (3) more or less follows the input signal >+spectrum, while having slightly less pronounced peaks. >+The entropy, which provides a lower bound on the bitrate for encoding the >+excitation signal, is proportional to the area between the de-emphasized >+spectrum (2) and the quantization noise spectrum (3). Without de-emphasis, >+the entropy is proportional to the area between input spectrum (1) and >+quantization noise (3) - clearly higher. >+</t> >+ >+<t> >+The transformation from input signal to de-emphasized signal can be >+described as a filtering operation with a filter >+<figure align="center"> >+<artwork align="center"> >+<![CDATA[ >+ -1 Wana(z) >+H(z) = G * ( 1 - c_tilt * z ) * ------- >+ Wsyn(z), >+]]> >+</artwork> >+</figure> >+having an adjustment gain G, a first order tilt adjustment filter with >+tilt coefficient c_tilt, and where >+<figure align="center"> >+<artwork align="center"> >+<![CDATA[ >+ 16 d >+ __ -k -L __ -k >+Wana(z) = (1 - \ (a_ana(k) * z )*(1 - z * \ b_ana(k) * z ), >+ /_ /_ >+ k=1 k=-d >+]]> >+</artwork> >+</figure> >+is the analysis part of the de-emphasis filter, consisting of the short-term >+shaping filter with coefficients a_ana(k), and the long-term shaping filter >+with coefficients b_ana(k) and pitch lag L. >+The parameter d determines the number of long-term shaping filter taps. >+</t> >+ >+<t> >+Similarly, but without the tilt adjustment, the synthesis part can be written as >+<figure align="center"> >+<artwork align="center"> >+<![CDATA[ >+ 16 d >+ __ -k -L __ -k >+Wsyn(z) = (1 - \ (a_syn(k) * z )*(1 - z * \ b_syn(k) * z ). >+ /_ /_ >+ k=1 k=-d >+ ]]> >+</artwork> >+</figure> >+</t> >+<t> >+All noise shaping parameters are computed and applied per subframe of 5 ms. >+First, an LPC analysis is performed on a windowed signal block of 15 ms. >+The signal block has a look-ahead of 5 ms relative to the current subframe, >+and the window is an asymmetric sine window. The LPC analysis is done with the >+autocorrelation method, with an order of between 8, in lowest-complexity mode, >+and 16, for best quality. >+</t> >+<t> >+Optionally the LPC analysis and noise shaping filters are warped by replacing >+the delay elements by first-order allpass filters. >+This increases the frequency resolution at low frequencies and reduces it at >+high ones, which better matches the human auditory system and improves >+quality. >+The warped analysis and filtering comes at a cost in complexity >+and is therefore only done in higher complexity modes. >+</t> >+<t> >+The quantization gain is found by taking the square root of the residual energy >+from the LPC analysis and multiplying it by a value inversely proportional >+to the coding quality control parameter and the pitch correlation. >+</t> >+<t> >+Next the two sets of short-term noise shaping coefficients a_ana(k) and >+a_syn(k) are obtained by applying different amounts of bandwidth expansion to the >+coefficients found in the LPC analysis. >+This bandwidth expansion moves the roots of the LPC polynomial towards the >+origin, using the formulas >+<figure align="center"> >+<artwork align="center"> >+<![CDATA[ >+ k >+ a_ana(k) = a(k)*g_ana , and >+ >+ k >+ a_syn(k) = a(k)*g_syn , >+]]> >+</artwork> >+</figure> >+where a(k) is the k'th LPC coefficient, and the bandwidth expansion factors >+g_ana and g_syn are calculated as >+<figure align="center"> >+<artwork align="center"> >+<![CDATA[ >+g_ana = 0.95 - 0.01*C, and >+ >+g_syn = 0.95 + 0.01*C, >+]]> >+</artwork> >+</figure> >+where C is the coding quality control parameter between 0 and 1. >+Applying more bandwidth expansion to the analysis part than to the synthesis >+part gives the desired de-emphasis of spectral valleys in between formants. >+</t> >+ >+<t> >+The long-term shaping is applied only during voiced frames. >+It uses three filter taps, described by >+<figure align="center"> >+<artwork align="center"> >+ <![CDATA[ >+b_ana = F_ana * [0.25, 0.5, 0.25], and >+ >+b_syn = F_syn * [0.25, 0.5, 0.25]. >+]]> >+</artwork> >+</figure> >+For unvoiced frames these coefficients are set to 0. The multiplication factors >+F_ana and F_syn are chosen between 0 and 1, depending on the coding quality >+control parameter, as well as the calculated pitch correlation and smoothed >+subband SNR of the lowest subband. By having F_ana less than F_syn, >+the pitch harmonics are emphasized relative to the valleys in between the >+harmonics. >+</t> >+ >+<t> >+The tilt coefficient c_tilt is for unvoiced frames chosen as >+<figure align="center"> >+<artwork align="center"> >+<![CDATA[ >+c_tilt = 0.25, >+]]> >+</artwork> >+</figure> >+and as >+<figure align="center"> >+<artwork align="center"> >+<![CDATA[ >+c_tilt = 0.25 + 0.2625 * V >+]]> >+</artwork> >+</figure> >+for voiced frames, where V is the voice activity level between 0 and 1. >+</t> >+<t> >+The adjustment gain G serves to correct any level mismatch between the original >+and decoded signals that might arise from the noise shaping and de-emphasis. >+This gain is computed as the ratio of the prediction gain of the short-term >+analysis and synthesis filter coefficients. The prediction gain of an LPC >+synthesis filter is the square root of the output energy when the filter is >+excited by a unit-energy impulse on the input. >+An efficient way to compute the prediction gain is by first computing the >+reflection coefficients from the LPC coefficients through the step-down >+algorithm, and extracting the prediction gain from the reflection coefficients >+as >+<figure align="center"> >+<artwork align="center"> >+<![CDATA[ >+ K >+ ___ 2 -0.5 >+ predGain = ( | | 1 - (r_k) ) , >+ k=1 >+]]> >+</artwork> >+</figure> >+where r_k is the k'th reflection coefficient. >+</t> >+ >+<t> >+Initial values for the quantization gains are computed as the square-root of >+the residual energy of the LPC analysis, adjusted by the coding quality control >+parameter. >+These quantization gains are later adjusted based on the results of the >+prediction analysis. >+</t> >+</section> >+ >+<section title='Prediction Analysis' anchor='pred_ana_overview_section'> >+<t> >+The prediction analysis is performed in one of two ways depending on how >+the pitch estimator classified the frame. >+The processing for voiced and unvoiced speech is described in >+<xref target='pred_ana_voiced_overview_section' /> and >+ <xref target='pred_ana_unvoiced_overview_section' />, respectively. >+ Inputs to this function include the pre-whitened signal from the >+ pitch estimator (see <xref target='pitch_estimator_overview_section'/>). >+</t> >+ >+<section title='Voiced Speech' anchor='pred_ana_voiced_overview_section'> >+<t> >+ For a frame of voiced speech the pitch pulses will remain dominant in the >+ pre-whitened input signal. >+ Further whitening is desirable as it leads to higher quality at the same >+ available bitrate. >+ To achieve this, a Long-Term Prediction (LTP) analysis is carried out to >+ estimate the coefficients of a fifth-order LTP filter for each of four >+ subframes. >+ The LTP coefficients are quantized using the method described in >+ <xref target='ltp_quantizer_overview_section'/>, and the quantized LTP >+ coefficients are used to compute the LTP residual signal. >+ This LTP residual signal is the input to an LPC analysis where the LPC coefficients are >+ estimated using Burg's method <xref target="Burg"/>, such that the residual energy is minimized. >+ The estimated LPC coefficients are converted to a Line Spectral Frequency (LSF) vector >+ and quantized as described in <xref target='lsf_quantizer_overview_section'/>. >+After quantization, the quantized LSF vector is converted back to LPC >+coefficients using the full procedure in <xref target="silk_nlsfs"/>. >+By using quantized LTP coefficients and LPC coefficients derived from the >+quantized LSF coefficients, the encoder remains fully synchronized with the >+decoder. >+The quantized LPC and LTP coefficients are also used to filter the input >+signal and measure residual energy for each of the four subframes. >+</t> >+</section> >+<section title='Unvoiced Speech' anchor='pred_ana_unvoiced_overview_section'> >+<t> >+For a speech signal that has been classified as unvoiced, there is no need >+for LTP filtering, as it has already been determined that the pre-whitened >+input signal is not periodic enough within the allowed pitch period range >+for LTP analysis to be worth the cost in terms of complexity and bitrate. >+The pre-whitened input signal is therefore discarded, and instead the input >+signal is used for LPC analysis using Burg's method. >+The resulting LPC coefficients are converted to an LSF vector and quantized >+as described in the following section. >+They are then transformed back to obtain quantized LPC coefficients, which >+are then used to filter the input signal and measure residual energy for >+each of the four subframes. >+</t> >+<section title="Burg's Method"> >+<t> >+The main purpose of linear prediction in SILK is to reduce the bitrate by >+minimizing the residual energy. >+At least at high bitrates, perceptual aspects are handled >+independently by the noise shaping filter. >+Burg's method is used because it provides higher prediction gain >+than the autocorrelation method and, unlike the covariance method, >+produces stable filters (assuming numerical errors don't spoil >+that). SILK's implementation of Burg's method is also computationally >+faster than the autocovariance method. >+The implementation of Burg's method differs from traditional >+implementations in two aspects. >+The first difference is that it >+operates on autocorrelations, similar to the Schur algorithm <xref target="Schur"/>, but >+with a simple update to the autocorrelations after finding each >+reflection coefficient to make the result identical to Burg's method. >+This brings down the complexity of Burg's method to near that of >+the autocorrelation method. >+The second difference is that the signal in each subframe is scaled >+by the inverse of the residual quantization step size. Subframes with >+a small quantization step size will on average spend more bits for a >+given amount of residual energy than subframes with a large step size. >+Without scaling, Burg's method minimizes the total residual energy in >+all subframes, which doesn't necessarily minimize the total number of >+bits needed for coding the quantized residual. The residual energy >+of the scaled subframes is a better measure for that number of >+bits. >+</t> >+</section> >+</section> >+</section> >+ >+<section title='LSF Quantization' anchor='lsf_quantizer_overview_section'> >+<t> >+Unlike many other speech codecs, SILK uses variable bitrate coding >+for the LSFs. >+This improves the average rate-distortion (R-D) tradeoff and reduces outliers. >+The variable bitrate coding minimizes a linear combination of the weighted >+quantization errors and the bitrate. >+The weights for the quantization errors are the Inverse >+Harmonic Mean Weighting (IHMW) function proposed by Laroia et al. >+(see <xref target="laroia-icassp" />). >+These weights are referred to here as Laroia weights. >+</t> >+<t> >+The LSF quantizer consists of two stages. >+The first stage is an (unweighted) vector quantizer (VQ), with a >+codebook size of 32 vectors. >+The quantization errors for the codebook vector are sorted, and >+for the N best vectors a second stage quantizer is run. >+By varying the number N a tradeoff is made between R-D performance >+and computational efficiency. >+For each of the N codebook vectors the Laroia weights corresponding >+to that vector (and not to the input vector) are calculated. >+Then the residual between the input LSF vector and the codebook >+vector is scaled by the square roots of these Laroia weights. >+This scaling partially normalizes error sensitivity for the >+residual vector, so that a uniform quantizer with fixed >+step sizes can be used in the second stage without too much >+performance loss. >+And by scaling with Laroia weights determined from the first-stage >+codebook vector, the process can be reversed in the decoder. >+</t> >+<t> >+The second stage uses predictive delayed decision scalar >+quantization. >+The quantization error is weighted by Laroia weights determined >+from the LSF input vector. >+The predictor multiplies the previous quantized residual value >+by a prediction coefficient that depends on the vector index from the >+first stage VQ and on the location in the LSF vector. >+The prediction is subtracted from the LSF residual value before >+quantizing the result, and added back afterwards. >+This subtraction can be interpreted as shifting the quantization levels >+of the scalar quantizer, and as a result the quantization error of >+each value depends on the quantization decision of the previous value. >+This dependency is exploited by the delayed decision mechanism to >+search for a quantization sequency with best R-D performance >+with a Viterbi-like algorithm <xref target="Viterbi"/>. >+The quantizer processes the residual LSF vector in reverse order >+(i.e., it starts with the highest residual LSF value). >+This is done because the prediction works slightly >+better in the reverse direction. >+</t> >+<t> >+The quantization index of the first stage is entropy coded. >+The quantization sequence from the second stage is also entropy >+coded, where for each element the probability table is chosen >+depending on the vector index from the first stage and the location >+of that element in the LSF vector. >+</t> >+ >+<section title='LSF Stabilization' anchor='lsf_stabilizer_overview_section'> >+<t> >+If the input is stable, finding the best candidate usually results in a >+quantized vector that is also stable. Because of the two-stage approach, >+however, it is possible that the best quantization candidate is unstable. >+The encoder applies the same stabilization procedure applied by the decoder >+ (see <xref target="silk_nlsf_stabilization"/> to ensure the LSF parameters >+ are within their valid range, increasingly sorted, and have minimum >+ distances between each other and the border values. >+</t> >+</section> >+</section> >+ >+<section title='LTP Quantization' anchor='ltp_quantizer_overview_section'> >+<t> >+For voiced frames, the prediction analysis described in >+<xref target='pred_ana_voiced_overview_section' /> resulted in four sets >+(one set per subframe) of five LTP coefficients, plus four weighting matrices. >+The LTP coefficients for each subframe are quantized using entropy constrained >+vector quantization. >+A total of three vector codebooks are available for quantization, with >+different rate-distortion trade-offs. The three codebooks have 10, 20, and >+40 vectors and average rates of about 3, 4, and 5 bits per vector, respectively. >+Consequently, the first codebook has larger average quantization distortion at >+a lower rate, whereas the last codebook has smaller average quantization >+distortion at a higher rate. >+Given the weighting matrix W_ltp and LTP vector b, the weighted rate-distortion >+measure for a codebook vector cb_i with rate r_i is give by >+<figure align="center"> >+<artwork align="center"> >+<![CDATA[ >+ RD = u * (b - cb_i)' * W_ltp * (b - cb_i) + r_i, >+]]> >+</artwork> >+</figure> >+where u is a fixed, heuristically-determined parameter balancing the distortion >+and rate. >+Which codebook gives the best performance for a given LTP vector depends on the >+weighting matrix for that LTP vector. >+For example, for a low valued W_ltp, it is advantageous to use the codebook >+with 10 vectors as it has a lower average rate. >+For a large W_ltp, on the other hand, it is often better to use the codebook >+with 40 vectors, as it is more likely to contain the best codebook vector. >+The weighting matrix W_ltp depends mostly on two aspects of the input signal. >+The first is the periodicity of the signal; the more periodic, the larger W_ltp. >+The second is the change in signal energy in the current subframe, relative to >+the signal one pitch lag earlier. >+A decaying energy leads to a larger W_ltp than an increasing energy. >+Both aspects fluctuate relatively slowly, which causes the W_ltp matrices for >+different subframes of one frame often to be similar. >+Because of this, one of the three codebooks typically gives good performance >+for all subframes, and therefore the codebook search for the subframe LTP >+vectors is constrained to only allow codebook vectors to be chosen from the >+same codebook, resulting in a rate reduction. >+</t> >+ >+<t> >+To find the best codebook, each of the three vector codebooks is >+used to quantize all subframe LTP vectors and produce a combined >+weighted rate-distortion measure for each vector codebook. >+The vector codebook with the lowest combined rate-distortion >+over all subframes is chosen. The quantized LTP vectors are used >+in the noise shaping quantizer, and the index of the codebook >+plus the four indices for the four subframe codebook vectors >+are passed on to the range encoder. >+</t> >+</section> >+ >+<section title='Prefilter'> >+<t> >+In the prefilter the input signal is filtered using the spectral valley >+de-emphasis filter coefficients from the noise shaping analysis >+(see <xref target='noise_shaping_analysis_overview_section'/>). >+By applying only the noise shaping analysis filter to the input signal, >+it provides the input to the noise shaping quantizer. >+</t> >+</section> >+ >+<section title='Noise Shaping Quantizer'> >+<t> >+The noise shaping quantizer independently shapes the signal and coding noise >+spectra to obtain a perceptually higher quality at the same bitrate. >+</t> >+<t> >+The prefilter output signal is multiplied with a compensation gain G computed >+in the noise shaping analysis. Then the output of a synthesis shaping filter >+is added, and the output of a prediction filter is subtracted to create a >+residual signal. >+The residual signal is multiplied by the inverse quantized quantization gain >+from the noise shaping analysis, and input to a scalar quantizer. >+The quantization indices of the scalar quantizer represent a signal of pulses >+that is input to the pyramid range encoder. >+The scalar quantizer also outputs a quantization signal, which is multiplied >+by the quantized quantization gain from the noise shaping analysis to create >+an excitation signal. >+The output of the prediction filter is added to the excitation signal to form >+the quantized output signal y(n). >+The quantized output signal y(n) is input to the synthesis shaping and >+prediction filters. >+</t> >+<t> >+Optionally the noise shaping quantizer operates in a delayed decision >+mode. >+In this mode it uses a Viterbi algorithm to keep track of >+multiple rounding choices in the quantizer and select the best >+one after a delay of 32 samples. This improves the rate/distortion >+performance of the quantizer. >+</t> >+</section> >+ >+<section title='Constant Bitrate Mode'> >+<t> >+ SILK was designed to run in Variable Bitrate (VBR) mode. However >+ the reference implementation also has a Constant Bitrate (CBR) mode >+ for SILK. In CBR mode SILK will attempt to encode each packet with >+ no more than the allowed number of bits. The Opus wrapper code >+ then pads the bitstream if any unused bits are left in SILK mode, or >+ encodes the high band with the remaining number of bits in Hybrid mode. >+ The number of payload bits is adjusted by changing >+ the quantization gains and the rate/distortion tradeoff in the noise >+ shaping quantizer, in an iterative loop >+ around the noise shaping quantizer and entropy coding. >+ Compared to the SILK VBR mode, the CBR mode has lower >+ audio quality at a given average bitrate, and also has higher >+ computational complexity. >+</t> >+</section> >+ >+</section> >+ >+</section> >+ >+ >+<section title="CELT Encoder"> >+<t> >+Most of the aspects of the CELT encoder can be directly derived from the description >+of the decoder. For example, the filters and rotations in the encoder are simply the >+inverse of the operation performed by the decoder. Similarly, the quantizers generally >+optimize for the mean square error (because noise shaping is part of the bit-stream itself), >+so no special search is required. For this reason, only the less straightforward aspects of the >+encoder are described here. >+</t> >+ >+<section anchor="pitch-prefilter" title="Pitch Prefilter"> >+<t>The pitch prefilter is applied after the pre-emphasis. It is applied >+in such a way as to be the inverse of the decoder's post-filter. The main non-obvious aspect of the >+prefilter is the selection of the pitch period. The pitch search should be optimized for the >+following criteria: >+<list style="symbols"> >+<t>continuity: it is important that the pitch period >+does not change abruptly between frames; and</t> >+<t>avoidance of pitch multiples: when the period used is a multiple of the real period >+(lower frequency fundamental), the post-filter loses most of its ability to reduce noise</t> >+</list> >+</t> >+</section> >+ >+<section anchor="normalization" title="Bands and Normalization"> >+<t> >+The MDCT output is divided into bands that are designed to match the ear's critical >+bands for the smallest (2.5 ms) frame size. The larger frame sizes use integer >+multiples of the 2.5 ms layout. For each band, the encoder >+computes the energy that will later be encoded. Each band is then normalized by the >+square root of the <spanx style="strong">unquantized</spanx> energy, such that each band now forms a unit vector X. >+The energy and the normalization are computed by compute_band_energies() >+and normalise_bands() (bands.c), respectively. >+</t> >+</section> >+ >+<section anchor="energy-quantization" title="Energy Envelope Quantization"> >+ >+<t> >+Energy quantization (both coarse and fine) can be easily understood from the decoding process. >+For all useful bitrates, the coarse quantizer always chooses the quantized log energy value that >+minimizes the error for each band. Only at very low rate does the encoder allow larger errors to >+minimize the rate and avoid using more bits than are available. When the >+available CPU requirements allow it, it is best to try encoding the coarse energy both with and without >+inter-frame prediction such that the best prediction mode can be selected. The optimal mode depends on >+the coding rate, the available bitrate, and the current rate of packet loss. >+</t> >+ >+<t>The fine energy quantizer always chooses the quantized log energy value that >+minimizes the error for each band because the rate of the fine quantization depends only >+on the bit allocation and not on the values that are coded. >+</t> >+</section> <!-- Energy quant --> >+ >+<section title="Bit Allocation"> >+<t>The encoder must use exactly the same bit allocation process as used by the decoder >+and described in <xref target="allocation"/>. The three mechanisms that can be used by the >+encoder to adjust the bitrate on a frame-by-frame basis are band boost, allocation trim, >+and band skipping. >+</t> >+ >+<section title="Band Boost"> >+<t>The reference encoder makes a decision to boost a band when the energy of that band is significantly >+higher than that of the neighboring bands. Let E_j be the log-energy of band j, we define >+<list> >+<t>D_j = 2*E_j - E_j-1 - E_j+1 </t> >+</list> >+ >+The allocation of band j is boosted once if D_j > t1 and twice if D_j > t2. For LM>=1, t1=2 and t2=4, >+while for LM<1, t1=3 and t2=5. >+</t> >+ >+</section> >+ >+<section title="Allocation Trim"> >+<t>The allocation trim is a value between 0 and 10 (inclusively) that controls the allocation >+balance between the low and high frequencies. The encoder starts with a safe "default" of 5 >+and deviates from that default in two different ways. First the trim can deviate by +/- 2 >+depending on the spectral tilt of the input signal. For signals with more low frequencies, the >+trim is increased by up to 2, while for signals with more high frequencies, the trim is >+decreased by up to 2. >+For stereo inputs, the trim value can >+be decreased by up to 4 when the inter-channel correlation at low frequency (first 8 bands) >+is high. </t> >+</section> >+ >+<section title="Band Skipping"> >+<t>The encoder uses band skipping to ensure that the shape of the bands is only coded >+if there is at least 1/2 bit per sample available for the PVQ. If not, then no bit is allocated >+and folding is used instead. To ensure continuity in the allocation, some amount of hysteresis is >+added to the process, such that a band that received PVQ bits in the previous frame only needs 7/16 >+bit/sample to be coded for the current frame, while a band that did not receive PVQ bits in the >+previous frames needs at least 9/16 bit/sample to be coded.</t> >+</section> >+ >+</section> >+ >+<section title="Stereo Decisions"> >+<t>Because CELT applies mid-side stereo coupling in the normalized domain, it does not suffer from >+important stereo image problems even when the two channels are completely uncorrelated. For this reason >+it is always safe to use stereo coupling on any audio frame. That being said, there are some frames >+for which dual (independent) stereo is still more efficient. This decision is made by comparing the estimated >+entropy with and without coupling over the first 13 bands, taking into account the fact that all bands with >+more than two MDCT bins require one extra degree of freedom when coded in mid-side. Let L1_ms and L1_lr >+be the L1-norm of the mid-side vector and the L1-norm of the left-right vector, respectively. The decision >+to use mid-side is made if and only if >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+ L1_ms L1_lr >+-------- < ----- >+bins + E bins >+]]></artwork> >+</figure> >+where bins is the number of MDCT bins in the first 13 bands and E is the number of extra degrees of >+freedom for mid-side coding. For LM>1, E=13, otherwise E=5. >+</t> >+ >+<t>The reference encoder decides on the intensity stereo threshold based on the bitrate alone. After >+taking into account the frame size by subtracting 80 bits per frame for coarse energy, the first >+band using intensity coding is as follows: >+</t> >+ >+<texttable anchor="intensity-thresholds" >+ title="Thresholds for Intensity Stereo"> >+<ttcol align='center'>bitrate (kb/s)</ttcol> >+<ttcol align='center'>start band</ttcol> >+<c><35</c> <c>8</c> >+<c>35-50</c> <c>12</c> >+<c>50-68</c> <c>16</c> >+<c>84-84</c> <c>18</c> >+<c>84-102</c> <c>19</c> >+<c>102-130</c> <c>20</c> >+<c>>130</c> <c>disabled</c> >+</texttable> >+ >+ >+</section> >+ >+<section title="Time-Frequency Decision"> >+<t> >+The choice of time-frequency resolution used in <xref target="tf-change"></xref> is based on >+R-D optimization. The distortion is the L1-norm (sum of absolute values) of each band >+after each TF resolution under consideration. The L1 norm is used because it represents the entropy >+for a Laplacian source. The number of bits required to code a change in TF resolution between >+two bands is higher than the cost of having those two bands use the same resolution, which is >+what requires the R-D optimization. The optimal decision is computed using the Viterbi algorithm. >+See tf_analysis() in celt/celt.c. >+</t> >+</section> >+ >+<section title="Spreading Values Decision"> >+<t> >+The choice of the spreading value in <xref target="spread values"></xref> has an >+impact on the nature of the coding noise introduced by CELT. The larger the f_r value, the >+lower the impact of the rotation, and the more tonal the coding noise. The >+more tonal the signal, the more tonal the noise should be, so the CELT encoder determines >+the optimal value for f_r by estimating how tonal the signal is. The tonality estimate >+is based on discrete pdf (4-bin histogram) of each band. Bands that have a large number of small >+values are considered more tonal and a decision is made by combining all bands with more than >+8 samples. See spreading_decision() in celt/bands.c. >+</t> >+</section> >+ >+<section anchor="pvq" title="Spherical Vector Quantization"> >+<t>CELT uses a Pyramid Vector Quantization (PVQ) <xref target="PVQ"></xref> >+codebook for quantizing the details of the spectrum in each band that have not >+been predicted by the pitch predictor. The PVQ codebook consists of all sums >+of K signed pulses in a vector of N samples, where two pulses at the same position >+are required to have the same sign. Thus the codebook includes >+all integer codevectors y of N dimensions that satisfy sum(abs(y(j))) = K. >+</t> >+ >+<t> >+In bands where there are sufficient bits allocated PVQ is used to encode >+the unit vector that results from the normalization in >+<xref target="normalization"></xref> directly. Given a PVQ codevector y, >+the unit vector X is obtained as X = y/||y||, where ||.|| denotes the >+L2 norm. >+</t> >+ >+ >+<section anchor="pvq-search" title="PVQ Search"> >+ >+<t> >+The search for the best codevector y is performed by alg_quant() >+(vq.c). There are several possible approaches to the >+search, with a trade-off between quality and complexity. The method used in the reference >+implementation computes an initial codeword y1 by projecting the normalized spectrum >+X onto the codebook pyramid of K-1 pulses: >+</t> >+<t> >+y0 = truncate_towards_zero( (K-1) * X / sum(abs(X))) >+</t> >+ >+<t> >+Depending on N, K and the input data, the initial codeword y0 may contain from >+0 to K-1 non-zero values. All the remaining pulses, with the exception of the last one, >+are found iteratively with a greedy search that minimizes the normalized correlation >+between y and X: >+<figure align="center"> >+<artwork align="center"><![CDATA[ >+ T >+J = -X * y / ||y|| >+]]></artwork> >+</figure> >+</t> >+ >+<t> >+The search described above is considered to be a good trade-off between quality >+and computational cost. However, there are other possible ways to search the PVQ >+codebook and the implementers MAY use any other search methods. See alg_quant() in celt/vq.c. >+</t> >+</section> >+ >+<section anchor="cwrs-encoder" title="PVQ Encoding"> >+ >+<t> >+The vector to encode, X, is converted into an index i such that >+ 0 <= i < V(N,K) as follows. >+Let i = 0 and k = 0. >+Then for j = (N - 1) down to 0, inclusive, do: >+<list style="numbers"> >+<t> >+If k > 0, set >+ i = i + (V(N-j-1,k-1) + V(N-j,k-1))/2. >+</t> >+<t>Set k = k + abs(X[j]).</t> >+<t> >+If X[j] < 0, set >+ i = i + (V(N-j-1,k) + V(N-j,k))/2. >+</t> >+</list> >+</t> >+ >+<t> >+The index i is then encoded using the procedure in >+ <xref target="encoding-ints"/> with ft = V(N,K). >+</t> >+ >+</section> >+ >+</section> >+ >+ >+ >+ >+ >+</section> >+ >+</section> >+ >+ >+<section anchor="conformance" title="Conformance"> >+ >+<t> >+It is our intention to allow the greatest possible choice of freedom in >+implementing the specification. For this reason, outside of the exceptions >+noted in this section, conformance is defined through the reference >+implementation of the decoder provided in <xref target="ref-implementation"/>. >+Although this document includes an English description of the codec, should >+the description contradict the source code of the reference implementation, >+the latter shall take precedence. >+</t> >+ >+<t> >+Compliance with this specification means that in addition to following the normative keywords in this document, >+ a decoder's output MUST also be >+ within the thresholds specified by the opus_compare.c tool (included >+ with the code) when compared to the reference implementation for each of the >+ test vectors provided (see <xref target="test-vectors"></xref>) and for each output >+ sampling rate and channel count supported. In addition, a compliant >+ decoder implementation MUST have the same final range decoder state as that of the >+ reference decoder. It is therefore RECOMMENDED that the >+ decoder implement the same functional behavior as the reference. >+ >+ A decoder implementation is not required to support all output sampling >+ rates or all output channel counts. >+</t> >+ >+<section title="Testing"> >+<t> >+Using the reference code provided in <xref target="ref-implementation"></xref>, >+a test vector can be decoded with >+<list> >+<t>opus_demo -d <rate> <channels> testvectorX.bit testX.out</t> >+</list> >+where <rate> is the sampling rate and can be 8000, 12000, 16000, 24000, or 48000, and >+<channels> is 1 for mono or 2 for stereo. >+</t> >+ >+<t> >+If the range decoder state is incorrect for one of the frames, the decoder will exit with >+"Error: Range coder state mismatch between encoder and decoder". If the decoder succeeds, then >+the output can be compared with the "reference" output with >+<list> >+<t>opus_compare -s -r <rate> testvectorX.dec testX.out</t> >+</list> >+for stereo or >+<list> >+<t>opus_compare -r <rate> testvectorX.dec testX.out</t> >+</list> >+for mono. >+</t> >+ >+<t>In addition to indicating whether the test vector comparison passes, the opus_compare tool >+outputs an "Opus quality metric" that indicates how well the tested decoder matches the >+reference implementation. A quality of 0 corresponds to the passing threshold, while >+a quality of 100 is the highest possible value and means that the output of the tested decoder is identical to the reference >+implementation. The passing threshold (quality 0) was calibrated in such a way that it corresponds to >+additive white noise with a 48 dB SNR (similar to what can be obtained on a cassette deck). >+It is still possible for an implementation to sound very good with such a low quality measure >+(e.g. if the deviation is due to inaudible phase distortion), but unless this is verified by >+listening tests, it is RECOMMENDED that implementations achieve a quality above 90 for 48 kHz >+decoding. For other sampling rates, it is normal for the quality metric to be lower >+(typically as low as 50 even for a good implementation) because of harmless mismatch with >+the delay and phase of the internal sampling rate conversion. >+</t> >+ >+<t> >+On POSIX environments, the run_vectors.sh script can be used to verify all test >+vectors. This can be done with >+<list> >+<t>run_vectors.sh <exec path> <vector path> <rate></t> >+</list> >+where <exec path> is the directory where the opus_demo and opus_compare executables >+are built and <vector path> is the directory containing the test vectors. >+</t> >+</section> >+ >+<section anchor="opus-custom" title="Opus Custom"> >+<t> >+Opus Custom is an OPTIONAL part of the specification that is defined to >+handle special sample rates and frame rates that are not supported by the >+main Opus specification. Use of Opus Custom is discouraged for all but very >+special applications for which a frame size different from 2.5, 5, 10, or 20 ms is >+needed (for either complexity or latency reasons). Because Opus Custom is >+optional, streams encoded using Opus Custom cannot be expected to be decodable by all Opus >+implementations. Also, because no in-band mechanism exists for specifying the sampling >+rate and frame size of Opus Custom streams, out-of-band signaling is required. >+In Opus Custom operation, only the CELT layer is available, using the opus_custom_* function >+calls in opus_custom.h. >+</t> >+</section> >+ >+</section> >+ >+<section anchor="security" title="Security Considerations"> >+ >+<t> >+Implementations of the Opus codec need to take appropriate security considerations >+into account, as outlined in <xref target="DOS"/>. >+It is extremely important for the decoder to be robust against malicious >+payloads. >+Malicious payloads must not cause the decoder to overrun its allocated memory >+ or to take an excessive amount of resources to decode. >+Although problems >+in encoders are typically rarer, the same applies to the encoder. Malicious >+audio streams must not cause the encoder to misbehave because this would >+allow an attacker to attack transcoding gateways. >+</t> >+<t> >+The reference implementation contains no known buffer overflow or cases where >+ a specially crafted packet or audio segment could cause a significant increase >+ in CPU load. >+However, on certain CPU architectures where denormalized floating-point >+ operations are much slower than normal floating-point operations, it is >+ possible for some audio content (e.g., silence or near-silence) to cause an >+ increase in CPU load. >+Denormals can be introduced by reordering operations in the compiler and depend >+ on the target architecture, so it is difficult to guarantee that an implementation >+ avoids them. >+For architectures on which denormals are problematic, adding very small >+ floating-point offsets to the affected signals to prevent significant numbers >+ of denormalized operations is RECOMMENDED. >+Alternatively, it is often possible to configure the hardware to treat >+ denormals as zero (DAZ). >+No such issue exists for the fixed-point reference implementation. >+</t> >+<t>The reference implementation was validated in the following conditions: >+<list style="numbers"> >+<t> >+Sending the decoder valid packets generated by the reference encoder and >+ verifying that the decoder's final range coder state matches that of the >+ encoder. >+</t> >+<t> >+Sending the decoder packets generated by the reference encoder and then >+ subjected to random corruption. >+</t> >+<t>Sending the decoder random packets.</t> >+<t> >+Sending the decoder packets generated by a version of the reference encoder >+ modified to make random coding decisions (internal fuzzing), including mode >+ switching, and verifying that the range coder final states match. >+</t> >+</list> >+In all of the conditions above, both the encoder and the decoder were run >+ inside the <xref target="Valgrind">Valgrind</xref> memory >+ debugger, which tracks reads and writes to invalid memory regions as well as >+ the use of uninitialized memory. >+There were no errors reported on any of the tested conditions. >+</t> >+</section> >+ >+ >+<section title="IANA Considerations"> >+<t> >+This document has no actions for IANA. >+</t> >+</section> >+ >+<section anchor="Acknowledgements" title="Acknowledgements"> >+<t> >+Thanks to all other developers, including Raymond Chen, Soeren Skak Jensen, Gregory Maxwell, >+Christopher Montgomery, and Karsten Vandborg Soerensen. We would also >+like to thank Igor Dyakonov, Jan Skoglund, and Christian Hoene for their help with subjective testing of the >+Opus codec. Thanks to Ralph Giles, John Ridges, Ben Schwartz, Keith Yan, Christian Hoene, Kat Walsh, and many others on the Opus and CELT mailing lists >+for their bug reports and feedback. >+</t> >+</section> >+ >+<section title="Copying Conditions"> >+<t>The authors agree to grant third parties the irrevocable right to copy, use and distribute >+the work (excluding Code Components available under the simplified BSD license), with or >+without modification, in any medium, without royalty, provided that, unless separate >+permission is granted, redistributed modified works do not contain misleading author, version, >+name of work, or endorsement information.</t> >+</section> >+ >+</middle> >+ >+<back> >+ >+<references title="Normative References"> >+ >+<reference anchor="rfc2119"> >+<front> >+<title>Key words for use in RFCs to Indicate Requirement Levels </title> >+<author initials="S." surname="Bradner" fullname="Scott Bradner"></author> >+</front> >+<seriesInfo name="RFC" value="2119" /> >+</reference> >+ >+</references> >+ >+<references title="Informative References"> >+ >+<reference anchor='requirements'> >+<front> >+<title>Requirements for an Internet Audio Codec</title> >+<author initials='J.-M.' surname='Valin' fullname='J.-M. Valin'> >+<organization /></author> >+<author initials='K.' surname='Vos' fullname='K. Vos'> >+<organization /></author> >+<author> >+<organization>IETF</organization></author> >+<date year='2011' month='August' /> >+<abstract> >+<t>This document provides specific requirements for an Internet audio >+ codec. These requirements address quality, sample rate, bitrate, >+ and packet-loss robustness, as well as other desirable properties. >+</t></abstract></front> >+<seriesInfo name='RFC' value='6366' /> >+<format type='TXT' target='http://tools.ietf.org/rfc/rfc6366.txt' /> >+</reference> >+ >+<?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.3550.xml"?> >+<?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.3533.xml"?> >+ >+<reference anchor='SILK' target='http://developer.skype.com/silk'> >+<front> >+<title>SILK Speech Codec</title> >+<author initials='K.' surname='Vos' fullname='K. Vos'> >+<organization /></author> >+<author initials='S.' surname='Jensen' fullname='S. Jensen'> >+<organization /></author> >+<author initials='K.' surname='Soerensen' fullname='K. Soerensen'> >+<organization /></author> >+<date year='2010' month='March' /> >+<abstract> >+<t></t> >+</abstract></front> >+<seriesInfo name='Internet-Draft' value='draft-vos-silk-01' /> >+<format type='TXT' target='http://tools.ietf.org/html/draft-vos-silk-01' /> >+</reference> >+ >+<reference anchor="laroia-icassp"> >+<front> >+<title abbrev="Robust and Efficient Quantization of Speech LSP"> >+Robust and Efficient Quantization of Speech LSP Parameters Using Structured Vector Quantization >+</title> >+<author initials="R.L." surname="Laroia" fullname="R."> >+<organization/> >+</author> >+<author initials="N.P." surname="Phamdo" fullname="N."> >+<organization/> >+</author> >+<author initials="N.F." surname="Farvardin" fullname="N."> >+<organization/> >+</author> >+</front> >+<seriesInfo name="ICASSP-1991, Proc. IEEE Int. Conf. Acoust., Speech, Signal Processing, pp. 641-644, October" value="1991"/> >+</reference> >+ >+<reference anchor='CELT' target='http://celt-codec.org/'> >+<front> >+<title>Constrained-Energy Lapped Transform (CELT) Codec</title> >+<author initials='J-M.' surname='Valin' fullname='J-M. Valin'> >+<organization /></author> >+<author initials='T.B.' surname='Terriberry' fullname='Timothy B. Terriberry'> >+<organization /></author> >+<author initials='G.' surname='Maxwell' fullname='G. Maxwell'> >+<organization /></author> >+<author initials='C.' surname='Montgomery' fullname='C. Montgomery'> >+<organization /></author> >+<date year='2010' month='July' /> >+<abstract> >+<t></t> >+</abstract></front> >+<seriesInfo name='Internet-Draft' value='draft-valin-celt-codec-02' /> >+<format type='TXT' target='http://tools.ietf.org/html/draft-valin-celt-codec-02' /> >+</reference> >+ >+<reference anchor='SRTP-VBR'> >+<front> >+<title>Guidelines for the use of Variable Bit Rate Audio with Secure RTP</title> >+<author initials='C.' surname='Perkins' fullname='K. Vos'> >+<organization /></author> >+<author initials='J.M.' surname='Valin' fullname='J.M. Valin'> >+<organization /></author> >+<date year='2011' month='July' /> >+<abstract> >+<t></t> >+</abstract></front> >+<seriesInfo name='RFC' value='6562' /> >+<format type='TXT' target='http://tools.ietf.org/html/rfc6562' /> >+</reference> >+ >+<reference anchor='DOS'> >+<front> >+<title>Internet Denial-of-Service Considerations</title> >+<author initials='M.' surname='Handley' fullname='M. Handley'> >+<organization /></author> >+<author initials='E.' surname='Rescorla' fullname='E. Rescorla'> >+<organization /></author> >+<author> >+<organization>IAB</organization></author> >+<date year='2006' month='December' /> >+<abstract> >+<t>This document provides an overview of possible avenues for denial-of-service (DoS) attack on Internet systems. The aim is to encourage protocol designers and network engineers towards designs that are more robust. We discuss partial solutions that reduce the effectiveness of attacks, and how some solutions might inadvertently open up alternative vulnerabilities. This memo provides information for the Internet community.</t></abstract></front> >+<seriesInfo name='RFC' value='4732' /> >+<format type='TXT' octets='91844' target='ftp://ftp.isi.edu/in-notes/rfc4732.txt' /> >+</reference> >+ >+<reference anchor="Martin79"> >+<front> >+<title>Range encoding: An algorithm for removing redundancy from a digitised message</title> >+<author initials="G.N.N." surname="Martin" fullname="G. Nigel N. Martin"><organization/></author> >+<date year="1979" /> >+</front> >+<seriesInfo name="Proc. Institution of Electronic and Radio Engineers International Conference on Video and Data Recording" value="" /> >+</reference> >+ >+<reference anchor="coding-thesis"> >+<front> >+<title>Source coding algorithms for fast data compression</title> >+<author initials="R." surname="Pasco" fullname=""><organization/></author> >+<date month="May" year="1976" /> >+</front> >+<seriesInfo name="Ph.D. thesis" value="Dept. of Electrical Engineering, Stanford University" /> >+</reference> >+ >+<reference anchor="PVQ"> >+<front> >+<title>A Pyramid Vector Quantizer</title> >+<author initials="T." surname="Fischer" fullname=""><organization/></author> >+<date month="July" year="1986" /> >+</front> >+<seriesInfo name="IEEE Trans. on Information Theory, Vol. 32" value="pp. 568-583" /> >+</reference> >+ >+<reference anchor="Kabal86"> >+<front> >+<title>The Computation of Line Spectral Frequencies Using Chebyshev Polynomials</title> >+<author initials="P." surname="Kabal" fullname="P. Kabal"><organization/></author> >+<author initials="R." surname="Ramachandran" fullname="R. P. Ramachandran"><organization/></author> >+<date month="December" year="1986" /> >+</front> >+<seriesInfo name="IEEE Trans. Acoustics, Speech, Signal Processing, vol. 34, no. 6" value="pp. 1419-1426" /> >+</reference> >+ >+ >+<reference anchor="Valgrind" target="http://valgrind.org/"> >+<front> >+<title>Valgrind website</title> >+<author></author> >+</front> >+</reference> >+ >+<reference anchor="Google-NetEQ" target="http://code.google.com/p/webrtc/source/browse/trunk/src/modules/audio_coding/NetEQ/main/source/?r=583"> >+<front> >+<title>Google NetEQ code</title> >+<author></author> >+</front> >+</reference> >+ >+<reference anchor="Google-WebRTC" target="http://code.google.com/p/webrtc/"> >+<front> >+<title>Google WebRTC code</title> >+<author></author> >+</front> >+</reference> >+ >+ >+<reference anchor="Opus-git" target="git://git.xiph.org/opus.git"> >+<front> >+<title>Opus Git Repository</title> >+<author></author> >+</front> >+</reference> >+ >+<reference anchor="Opus-website" target="http://opus-codec.org/"> >+<front> >+<title>Opus website</title> >+<author></author> >+</front> >+</reference> >+ >+<reference anchor="Vorbis-website" target="http://xiph.org/vorbis/"> >+<front> >+<title>Vorbis website</title> >+<author></author> >+</front> >+</reference> >+ >+<reference anchor="Matroska-website" target="http://matroska.org/"> >+<front> >+<title>Matroska website</title> >+<author></author> >+</front> >+</reference> >+ >+<reference anchor="Vectors-website" target="http://opus-codec.org/testvectors/"> >+<front> >+<title>Opus Testvectors (webside)</title> >+<author></author> >+</front> >+</reference> >+ >+<reference anchor="Vectors-proc" target="http://www.ietf.org/proceedings/83/slides/slides-83-codec-0.gz"> >+<front> >+<title>Opus Testvectors (proceedings)</title> >+<author></author> >+</front> >+</reference> >+ >+<reference anchor="line-spectral-pairs" target="http://en.wikipedia.org/wiki/Line_spectral_pairs"> >+<front> >+<title>Line Spectral Pairs</title> >+<author><organization>Wikipedia</organization></author> >+</front> >+</reference> >+ >+<reference anchor="range-coding" target="http://en.wikipedia.org/wiki/Range_coding"> >+<front> >+<title>Range Coding</title> >+<author><organization>Wikipedia</organization></author> >+</front> >+</reference> >+ >+<reference anchor="Hadamard" target="http://en.wikipedia.org/wiki/Hadamard_transform"> >+<front> >+<title>Hadamard Transform</title> >+<author><organization>Wikipedia</organization></author> >+</front> >+</reference> >+ >+<reference anchor="Viterbi" target="http://en.wikipedia.org/wiki/Viterbi_algorithm"> >+<front> >+<title>Viterbi Algorithm</title> >+<author><organization>Wikipedia</organization></author> >+</front> >+</reference> >+ >+<reference anchor="Whitening" target="http://en.wikipedia.org/wiki/White_noise"> >+<front> >+<title>White Noise</title> >+<author><organization>Wikipedia</organization></author> >+</front> >+</reference> >+ >+<reference anchor="LPC" target="http://en.wikipedia.org/wiki/Linear_prediction"> >+<front> >+<title>Linear Prediction</title> >+<author><organization>Wikipedia</organization></author> >+</front> >+</reference> >+ >+<reference anchor="MDCT" target="http://en.wikipedia.org/wiki/Modified_discrete_cosine_transform"> >+<front> >+<title>Modified Discrete Cosine Transform</title> >+<author><organization>Wikipedia</organization></author> >+</front> >+</reference> >+ >+<reference anchor="FFT" target="http://en.wikipedia.org/wiki/Fast_Fourier_transform"> >+<front> >+<title>Fast Fourier Transform</title> >+<author><organization>Wikipedia</organization></author> >+</front> >+</reference> >+ >+<reference anchor="z-transform" target="http://en.wikipedia.org/wiki/Z-transform"> >+<front> >+<title>Z-transform</title> >+<author><organization>Wikipedia</organization></author> >+</front> >+</reference> >+ >+ >+<reference anchor="Burg"> >+<front> >+<title>Maximum Entropy Spectral Analysis</title> >+<author initials="JP." surname="Burg" fullname="J.P. Burg"><organization/></author> >+</front> >+</reference> >+ >+<reference anchor="Schur"> >+<front> >+<title>A fixed point computation of partial correlation coefficients</title> >+<author initials="J." surname="Le Roux" fullname="J. Le Roux"><organization/></author> >+<author initials="C." surname="Gueguen" fullname="C. Gueguen"><organization/></author> >+</front> >+<seriesInfo name="ICASSP-1977, Proc. IEEE Int. Conf. Acoust., Speech, Signal Processing, pp. 257-259, October" value="1977"/> >+</reference> >+ >+<reference anchor="Princen86"> >+<front> >+<title>Analysis/synthesis filter bank design based on time domain aliasing cancellation</title> >+<author initials="J." surname="Princen" fullname="John P. Princen"><organization/></author> >+<author initials="A." surname="Bradley" fullname="Alan B. Bradley"><organization/></author> >+</front> >+<seriesInfo name="IEEE Trans. Acoust. Speech Sig. Proc. ASSP-34 (5), 1153-1161" value="1986"/> >+</reference> >+ >+<reference anchor="Valin2010"> >+<front> >+<title>A High-Quality Speech and Audio Codec With Less Than 10 ms delay</title> >+<author initials="JM" surname="Valin" fullname="Jean-Marc Valin"><organization/> >+</author> >+<author initials="T. B." surname="Terriberry" fullname="Timothy Terriberry"><organization/></author> >+<author initials="C." surname="Montgomery" fullname="Christopher Montgomery"><organization/></author> >+<author initials="G." surname="Maxwell" fullname="Gregory Maxwell"><organization/></author> >+</front> >+<seriesInfo name="IEEE Trans. on Audio, Speech and Language Processing, Vol. 18, No. 1, pp. 58-67" value="2010" /> >+</reference> >+ >+ >+<reference anchor="Zwicker61"> >+<front> >+<title>Subdivision of the audible frequency range into critical bands</title> >+<author initials="E." surname="Zwicker" fullname="E. Zwicker"><organization/></author> >+<date month="February" year="1961" /> >+</front> >+<seriesInfo name="The Journal of the Acoustical Society of America, Vol. 33, No 2" value="p. 248" /> >+</reference> >+ >+ >+</references> >+ >+<section anchor="ref-implementation" title="Reference Implementation"> >+ >+<t>This appendix contains the complete source code for the >+reference implementation of the Opus codec written in C. By default, >+this implementation relies on floating-point arithmetic, but it can be >+compiled to use only fixed-point arithmetic by defining the FIXED_POINT >+macro. Information on building and using the reference implementation is >+available in the README file. >+</t> >+ >+<t>The implementation can be compiled with either a C89 or a C99 >+compiler. It is reasonably optimized for most platforms such that >+only architecture-specific optimizations are likely to be useful. >+The FFT <xref target="FFT"/> used is a slightly modified version of the KISS-FFT library, >+but it is easy to substitute any other FFT library. >+</t> >+ >+<t> >+While the reference implementation does not rely on any >+<spanx style="emph">undefined behavior</spanx> as defined by C89 or C99, >+it relies on common <spanx style="emph">implementation-defined behavior</spanx> >+for two's complement architectures: >+<list style="symbols"> >+<t>Right shifts of negative values are consistent with two's complement arithmetic, so that a>>b is equivalent to floor(a/(2**b)),</t> >+<t>For conversion to a signed integer of N bits, the value is reduced modulo 2**N to be within range of the type,</t> >+<t>The result of integer division of a negative value is truncated towards zero, and</t> >+<t>The compiler provides a 64-bit integer type (a C99 requirement which is supported by most C89 compilers).</t> >+</list> >+</t> >+ >+<t> >+In its current form, the reference implementation also requires the following >+architectural characteristics to obtain acceptable performance: >+<list style="symbols"> >+<t>Two's complement arithmetic,</t> >+<t>At least a 16 bit by 16 bit integer multiplier (32-bit result), and</t> >+<t>At least a 32-bit adder/accumulator.</t> >+</list> >+</t> >+ >+ >+<section title="Extracting the source"> >+<t> >+The complete source code can be extracted from this draft, by running the >+following command line: >+ >+<list style="symbols"> >+<t><![CDATA[ >+cat draft-ietf-codec-opus.txt | grep '^\ \ \ ###' | sed -e 's/...###//' | base64 -d > opus_source.tar.gz >+]]></t> >+<t> >+tar xzvf opus_source.tar.gz >+</t> >+<t>cd opus_source</t> >+<t>make</t> >+</list> >+On systems where the provided Makefile does not work, the following command line may be used to compile >+the source code: >+<list style="symbols"> >+<t><![CDATA[ >+cc -O2 -g -o opus_demo src/opus_demo.c `cat *.mk | grep -v fixed | sed -e 's/.*=//' -e 's/\\\\//'` -DOPUS_BUILD -Iinclude -Icelt -Isilk -Isilk/float -DUSE_ALLOCA -Drestrict= -lm >+]]></t></list> >+</t> >+ >+<t> >+On systems where the base64 utility is not present, the following commands can be used instead: >+<list style="symbols"> >+<t><![CDATA[ >+cat draft-ietf-codec-opus.txt | grep '^\ \ \ ###' | sed -e 's/...###//' > opus.b64 >+]]></t> >+<t>openssl base64 -d -in opus.b64 > opus_source.tar.gz</t> >+</list> >+ >+</t> >+</section> >+ >+<section title="Up-to-date Implementation"> >+<t> >+As of the time of publication of this memo, an up-to-date implementation conforming to >+this standard is available in a >+ <xref target='Opus-git'>Git repository</xref>. >+Releases and other resources are available at >+ <xref target='Opus-website'/>. However, although that implementation is expected to >+ remain conformant with the standard, it is the code in this document that shall >+ remain normative. >+</t> >+</section> >+ >+<section title="Base64-encoded Source Code"> >+<t> >+<?rfc include="opus_source.base64"?> >+</t> >+</section> >+ >+<section anchor="test-vectors" title="Test Vectors"> >+<t> >+Because of size constraints, the Opus test vectors are not distributed in this >+draft. They are available in the proceedings of the 83th IETF meeting (Paris) <xref target="Vectors-proc"/> and from the Opus codec website at >+<xref target="Vectors-website"/>. These test vectors were created specifically to exercise >+all aspects of the decoder and therefore the audio quality of the decoded output is >+significantly lower than what Opus can achieve in normal operation. >+</t> >+ >+<t> >+The SHA1 hash of the files in the test vector package are >+<?rfc include="testvectors_sha1"?> >+</t> >+ >+</section> >+ >+</section> >+ >+<section anchor="self-delimiting-framing" title="Self-Delimiting Framing"> >+<t> >+To use the internal framing described in <xref target="modes"/>, the decoder >+ must know the total length of the Opus packet, in bytes. >+This section describes a simple variation of that framing which can be used >+ when the total length of the packet is not known. >+Nothing in the encoding of the packet itself allows a decoder to distinguish >+ between the regular, undelimited framing and the self-delimiting framing >+ described in this appendix. >+Which one is used and where must be established by context at the transport >+ layer. >+It is RECOMMENDED that a transport layer choose exactly one framing scheme, >+ rather than allowing an encoder to signal which one it wants to use. >+</t> >+ >+<t> >+For example, although a regular Opus stream does not support more than two >+ channels, a multi-channel Opus stream may be formed from several one- and >+ two-channel streams. >+To pack an Opus packet from each of these streams together in a single packet >+ at the transport layer, one could use the self-delimiting framing for all but >+ the last stream, and then the regular, undelimited framing for the last one. >+Reverting to the undelimited framing for the last stream saves overhead >+ (because the total size of the transport-layer packet will still be known), >+ and ensures that a "multi-channel" stream which only has a single Opus stream >+ uses the same framing as a regular Opus stream does. >+This avoids the need for signaling to distinguish these two cases. >+</t> >+ >+<t> >+The self-delimiting framing is identical to the regular, undelimited framing >+ from <xref target="modes"/>, except that each Opus packet contains one extra >+ length field, encoded using the same one- or two-byte scheme from >+ <xref target="frame-length-coding"/>. >+This extra length immediately precedes the compressed data of the first Opus >+ frame in the packet, and is interpreted in the various modes as follows: >+<list style="symbols"> >+<t> >+Code 0 packets: It is the length of the single Opus frame (see >+ <xref target="sd_code0_packet"/>). >+</t> >+<t> >+Code 1 packets: It is the length used for both of the Opus frames (see >+ <xref target="sd_code1_packet"/>). >+</t> >+<t> >+Code 2 packets: It is the length of the second Opus frame (see >+ <xref target="sd_code2_packet"/>).</t> >+<t> >+CBR Code 3 packets: It is the length used for all of the Opus frames (see >+ <xref target="sd_code3cbr_packet"/>). >+</t> >+<t>VBR Code 3 packets: It is the length of the last Opus frame (see >+ <xref target="sd_code3vbr_packet"/>). >+</t> >+</list> >+</t> >+ >+<figure anchor="sd_code0_packet" title="A Self-Delimited Code 0 Packet" >+ align="center"> >+<artwork align="center"><![CDATA[ >+ 0 1 2 3 >+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| config |s|0|0| N1 (1-2 bytes): | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | >+| Compressed frame 1 (N1 bytes)... : >+: | >+| | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+]]></artwork> >+</figure> >+ >+<figure anchor="sd_code1_packet" title="A Self-Delimited Code 1 Packet" >+ align="center"> >+<artwork align="center"><![CDATA[ >+ 0 1 2 3 >+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| config |s|0|1| N1 (1-2 bytes): | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ : >+| Compressed frame 1 (N1 bytes)... | >+: +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| | | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ : >+| Compressed frame 2 (N1 bytes)... | >+: +-+-+-+-+-+-+-+-+ >+| | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+]]></artwork> >+</figure> >+ >+<figure anchor="sd_code2_packet" title="A Self-Delimited Code 2 Packet" >+ align="center"> >+<artwork align="center"><![CDATA[ >+ 0 1 2 3 >+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| config |s|1|0| N1 (1-2 bytes): N2 (1-2 bytes : | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ : >+| Compressed frame 1 (N1 bytes)... | >+: +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| | | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | >+| Compressed frame 2 (N2 bytes)... : >+: | >+| | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+]]></artwork> >+</figure> >+ >+<figure anchor="sd_code3cbr_packet" title="A Self-Delimited CBR Code 3 Packet" >+ align="center"> >+<artwork align="center"><![CDATA[ >+ 0 1 2 3 >+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| config |s|1|1|0|p| M | Pad len (Opt) : N1 (1-2 bytes): >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| | >+: Compressed frame 1 (N1 bytes)... : >+| | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| | >+: Compressed frame 2 (N1 bytes)... : >+| | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| | >+: ... : >+| | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| | >+: Compressed frame M (N1 bytes)... : >+| | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+: Opus Padding (Optional)... | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+]]></artwork> >+</figure> >+ >+<figure anchor="sd_code3vbr_packet" title="A Self-Delimited VBR Code 3 Packet" >+ align="center"> >+<artwork align="center"><![CDATA[ >+ 0 1 2 3 >+ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| config |s|1|1|1|p| M | Padding length (Optional) : >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+: N1 (1-2 bytes): ... : N[M-1] | N[M] : >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| | >+: Compressed frame 1 (N1 bytes)... : >+| | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| | >+: Compressed frame 2 (N2 bytes)... : >+| | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| | >+: ... : >+| | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+| | >+: Compressed frame M (N[M] bytes)... : >+| | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+: Opus Padding (Optional)... | >++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ >+]]></artwork> >+</figure> >+ >+</section> >+ >+</back> >+ >+</rfc> >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/draft-ietf-payload-rtp-opus.xml b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/draft-ietf-payload-rtp-opus.xml >new file mode 100644 >index 0000000000000000000000000000000000000000..c4eb21077b7224ef1443f6d4565832604f47dd38 >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/draft-ietf-payload-rtp-opus.xml >@@ -0,0 +1,960 @@ >+<?xml version="1.0" encoding="UTF-8"?> >+<!DOCTYPE rfc SYSTEM "rfc2629.dtd" [ >+<!ENTITY rfc2119 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml'> >+<!ENTITY rfc3389 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.3389.xml'> >+<!ENTITY rfc3550 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.3550.xml'> >+<!ENTITY rfc3711 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.3711.xml'> >+<!ENTITY rfc3551 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.3551.xml'> >+<!ENTITY rfc6838 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.6838.xml'> >+<!ENTITY rfc4855 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.4855.xml'> >+<!ENTITY rfc4566 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.4566.xml'> >+<!ENTITY rfc4585 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.4585.xml'> >+<!ENTITY rfc3264 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.3264.xml'> >+<!ENTITY rfc2974 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.2974.xml'> >+<!ENTITY rfc2326 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.2326.xml'> >+<!ENTITY rfc3555 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.3555.xml'> >+<!ENTITY rfc5124 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.5124.xml'> >+<!ENTITY rfc5405 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.5405.xml'> >+<!ENTITY rfc5576 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.5576.xml'> >+<!ENTITY rfc6562 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.6562.xml'> >+<!ENTITY rfc6716 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.6716.xml'> >+<!ENTITY rfc7202 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.7202.xml'> >+<!ENTITY nbsp " "> >+ ]> >+ >+ <rfc category="std" ipr="trust200902" docName="draft-ietf-payload-rtp-opus-11"> >+<?xml-stylesheet type='text/xsl' href='rfc2629.xslt' ?> >+ >+<?rfc strict="yes" ?> >+<?rfc toc="yes" ?> >+<?rfc tocdepth="3" ?> >+<?rfc tocappendix='no' ?> >+<?rfc tocindent='yes' ?> >+<?rfc symrefs="yes" ?> >+<?rfc sortrefs="yes" ?> >+<?rfc compact="no" ?> >+<?rfc subcompact="yes" ?> >+<?rfc iprnotified="yes" ?> >+ >+ <front> >+ <title abbrev="RTP Payload Format for Opus"> >+ RTP Payload Format for the Opus Speech and Audio Codec >+ </title> >+ >+ <author fullname="Julian Spittka" initials="J." surname="Spittka"> >+ <address> >+ <email>jspittka@gmail.com</email> >+ </address> >+ </author> >+ >+ <author initials='K.' surname='Vos' fullname='Koen Vos'> >+ <organization>vocTone</organization> >+ <address> >+ <postal> >+ <street></street> >+ <code></code> >+ <city></city> >+ <region></region> >+ <country></country> >+ </postal> >+ <email>koenvos74@gmail.com</email> >+ </address> >+ </author> >+ >+ <author initials="JM" surname="Valin" fullname="Jean-Marc Valin"> >+ <organization>Mozilla</organization> >+ <address> >+ <postal> >+ <street>331 E. Evelyn Avenue</street> >+ <city>Mountain View</city> >+ <region>CA</region> >+ <code>94041</code> >+ <country>USA</country> >+ </postal> >+ <email>jmvalin@jmvalin.ca</email> >+ </address> >+ </author> >+ >+ <date day='14' month='April' year='2015' /> >+ >+ <abstract> >+ <t> >+ This document defines the Real-time Transport Protocol (RTP) payload >+ format for packetization of Opus encoded >+ speech and audio data necessary to integrate the codec in the >+ most compatible way. It also provides an applicability statement >+ for the use of Opus over RTP. Further, it describes media type registrations >+ for the RTP payload format. >+ </t> >+ </abstract> >+ </front> >+ >+ <middle> >+ <section title='Introduction'> >+ <t> >+ Opus <xref target="RFC6716"/> is a speech and audio codec developed within the >+ IETF Internet Wideband Audio Codec working group. The codec >+ has a very low algorithmic delay and it >+ is highly scalable in terms of audio bandwidth, bitrate, and >+ complexity. Further, it provides different modes to efficiently encode speech signals >+ as well as music signals, thus making it the codec of choice for >+ various applications using the Internet or similar networks. >+ </t> >+ <t> >+ This document defines the Real-time Transport Protocol (RTP) >+ <xref target="RFC3550"/> payload format for packetization >+ of Opus encoded speech and audio data necessary to >+ integrate Opus in the >+ most compatible way. It also provides an applicability statement >+ for the use of Opus over RTP. >+ Further, it describes media type registrations for >+ the RTP payload format. >+ </t> >+ </section> >+ >+ <section title='Conventions, Definitions and Acronyms used in this document'> >+ <t>The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", >+ "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this >+ document are to be interpreted as described in <xref target="RFC2119"/>.</t> >+ <t> >+ <list style='hanging'> >+ <t hangText="audio bandwidth:"> The range of audio frequecies being coded</t> >+ <t hangText="CBR:"> Constant bitrate</t> >+ <t hangText="CPU:"> Central Processing Unit</t> >+ <t hangText="DTX:"> Discontinuous transmission</t> >+ <t hangText="FEC:"> Forward error correction</t> >+ <t hangText="IP:"> Internet Protocol</t> >+ <t hangText="samples:"> Speech or audio samples (per channel)</t> >+ <t hangText="SDP:"> Session Description Protocol</t> >+ <t hangText="VBR:"> Variable bitrate</t> >+ </list> >+ </t> >+ <t> >+ Throughout this document, we refer to the following definitions: >+ </t> >+ <texttable anchor='bandwidth_definitions'> >+ <ttcol align='center'>Abbreviation</ttcol> >+ <ttcol align='center'>Name</ttcol> >+ <ttcol align='center'>Audio Bandwidth (Hz)</ttcol> >+ <ttcol align='center'>Sampling Rate (Hz)</ttcol> >+ <c>NB</c> >+ <c>Narrowband</c> >+ <c>0 - 4000</c> >+ <c>8000</c> >+ >+ <c>MB</c> >+ <c>Mediumband</c> >+ <c>0 - 6000</c> >+ <c>12000</c> >+ >+ <c>WB</c> >+ <c>Wideband</c> >+ <c>0 - 8000</c> >+ <c>16000</c> >+ >+ <c>SWB</c> >+ <c>Super-wideband</c> >+ <c>0 - 12000</c> >+ <c>24000</c> >+ >+ <c>FB</c> >+ <c>Fullband</c> >+ <c>0 - 20000</c> >+ <c>48000</c> >+ >+ <postamble> >+ Audio bandwidth naming >+ </postamble> >+ </texttable> >+ </section> >+ >+ <section title='Opus Codec'> >+ <t> >+ Opus encodes speech >+ signals as well as general audio signals. Two different modes can be >+ chosen, a voice mode or an audio mode, to allow the most efficient coding >+ depending on the type of the input signal, the sampling frequency of the >+ input signal, and the intended application. >+ </t> >+ >+ <t> >+ The voice mode allows efficient encoding of voice signals at lower bit >+ rates while the audio mode is optimized for general audio signals at medium and >+ higher bitrates. >+ </t> >+ >+ <t> >+ Opus is highly scalable in terms of audio >+ bandwidth, bitrate, and complexity. Further, Opus allows >+ transmitting stereo signals with in-band signaling in the bit-stream. >+ </t> >+ >+ <section title='Network Bandwidth'> >+ <t> >+ Opus supports bitrates from 6 kb/s to 510 kb/s. >+ The bitrate can be changed dynamically within that range. >+ All >+ other parameters being >+ equal, higher bitrates result in higher audio quality. >+ </t> >+ <section title='Recommended Bitrate' anchor='bitrate_by_bandwidth'> >+ <t> >+ For a frame size of >+ 20 ms, these >+ are the bitrate "sweet spots" for Opus in various configurations: >+ >+ <list style="symbols"> >+ <t>8-12 kb/s for NB speech,</t> >+ <t>16-20 kb/s for WB speech,</t> >+ <t>28-40 kb/s for FB speech,</t> >+ <t>48-64 kb/s for FB mono music, and</t> >+ <t>64-128 kb/s for FB stereo music.</t> >+ </list> >+ </t> >+ </section> >+ <section title='Variable versus Constant Bitrate' anchor='variable-vs-constant-bitrate'> >+ <t> >+ For the same average bitrate, variable bitrate (VBR) can achieve higher audio quality >+ than constant bitrate (CBR). For the majority of voice transmission applications, VBR >+ is the best choice. One reason for choosing CBR is the potential >+ information leak that <spanx style='emph'>might</spanx> occur when encrypting the >+ compressed stream. See <xref target="RFC6562"/> for guidelines on when VBR is >+ appropriate for encrypted audio communications. In the case where an existing >+ VBR stream needs to be converted to CBR for security reasons, then the Opus padding >+ mechanism described in <xref target="RFC6716"/> is the RECOMMENDED way to achieve padding >+ because the RTP padding bit is unencrypted.</t> >+ >+ <t> >+ The bitrate can be adjusted at any point in time. To avoid congestion, >+ the average bitrate SHOULD NOT exceed the available >+ network bandwidth. If no target bitrate is specified, the bitrates specified in >+ <xref target='bitrate_by_bandwidth'/> are RECOMMENDED. >+ </t> >+ >+ </section> >+ >+ <section title='Discontinuous Transmission (DTX)'> >+ >+ <t> >+ Opus can, as described in <xref target='variable-vs-constant-bitrate'/>, >+ be operated with a variable bitrate. In that case, the encoder will >+ automatically reduce the bitrate for certain input signals, like periods >+ of silence. When using continuous transmission, it will reduce the >+ bitrate when the characteristics of the input signal permit, but >+ will never interrupt the transmission to the receiver. Therefore, the >+ received signal will maintain the same high level of audio quality over the >+ full duration of a transmission while minimizing the average bit >+ rate over time. >+ </t> >+ >+ <t> >+ In cases where the bitrate of Opus needs to be reduced even >+ further or in cases where only constant bitrate is available, >+ the Opus encoder can use discontinuous >+ transmission (DTX), where parts of the encoded signal that >+ correspond to periods of silence in the input speech or audio signal >+ are not transmitted to the receiver. A receiver can distinguish >+ between DTX and packet loss by looking for gaps in the sequence >+ number, as described by Section 4.1 >+ of <xref target="RFC3551"/>. >+ </t> >+ >+ <t> >+ On the receiving side, the non-transmitted parts will be handled by a >+ frame loss concealment unit in the Opus decoder which generates a >+ comfort noise signal to replace the non transmitted parts of the >+ speech or audio signal. Use of <xref target="RFC3389"/> Comfort >+ Noise (CN) with Opus is discouraged. >+ The transmitter MUST drop whole frames only, >+ based on the size of the last transmitted frame, >+ to ensure successive RTP timestamps differ by a multiple of 120 and >+ to allow the receiver to use whole frames for concealment. >+ </t> >+ >+ <t> >+ DTX can be used with both variable and constant bitrate. >+ It will have a slightly lower speech or audio >+ quality than continuous transmission. Therefore, using continuous >+ transmission is RECOMMENDED unless constraints on available network bandwidth >+ are severe. >+ </t> >+ >+ </section> >+ >+ </section> >+ >+ <section title='Complexity'> >+ >+ <t> >+ Complexity of the encoder can be scaled to optimize for CPU resources in real-time, mostly as >+ a trade-off between audio quality and bitrate. Also, different modes of Opus have different complexity. >+ </t> >+ >+ </section> >+ >+ <section title="Forward Error Correction (FEC)"> >+ >+ <t> >+ The voice mode of Opus allows for embedding "in-band" forward error correction (FEC) >+ data into the Opus bit stream. This FEC scheme adds >+ redundant information about the previous packet (N-1) to the current >+ output packet N. For >+ each frame, the encoder decides whether to use FEC based on (1) an >+ externally-provided estimate of the channel's packet loss rate; (2) an >+ externally-provided estimate of the channel's capacity; (3) the >+ sensitivity of the audio or speech signal to packet loss; (4) whether >+ the receiving decoder has indicated it can take advantage of "in-band" >+ FEC information. The decision to send "in-band" FEC information is >+ entirely controlled by the encoder and therefore no special precautions >+ for the payload have to be taken. >+ </t> >+ >+ <t> >+ On the receiving side, the decoder can take advantage of this >+ additional information when it loses a packet and the next packet >+ is available. In order to use the FEC data, the jitter buffer needs >+ to provide access to payloads with the FEC data. >+ Instead of performing loss concealment for a missing packet, the >+ receiver can then configure its decoder to decode the FEC data from the next packet. >+ </t> >+ >+ <t> >+ Any compliant Opus decoder is capable of ignoring >+ FEC information when it is not needed, so encoding with FEC cannot cause >+ interoperability problems. >+ However, if FEC cannot be used on the receiving side, then FEC >+ SHOULD NOT be used, as it leads to an inefficient usage of network >+ resources. Decoder support for FEC SHOULD be indicated at the time a >+ session is set up. >+ </t> >+ >+ </section> >+ >+ <section title='Stereo Operation'> >+ >+ <t> >+ Opus allows for transmission of stereo audio signals. This operation >+ is signaled in-band in the Opus bit-stream and no special arrangement >+ is needed in the payload format. An >+ Opus decoder is capable of handling a stereo encoding, but an >+ application might only be capable of consuming a single audio >+ channel. >+ </t> >+ <t> >+ If a decoder cannot take advantage of the benefits of a stereo signal >+ this SHOULD be indicated at the time a session is set up. In that case >+ the sending side SHOULD NOT send stereo signals as it leads to an >+ inefficient usage of network resources. >+ </t> >+ >+ </section> >+ >+ </section> >+ >+ <section title='Opus RTP Payload Format' anchor='opus-rtp-payload-format'> >+ <t>The payload format for Opus consists of the RTP header and Opus payload >+ data.</t> >+ <section title='RTP Header Usage'> >+ <t>The format of the RTP header is specified in <xref target="RFC3550"/>. >+ The use of the fields of the RTP header by the Opus payload format is >+ consistent with that specification.</t> >+ >+ <t>The payload length of Opus is an integer number of octets and >+ therefore no padding is necessary. The payload MAY be padded by an >+ integer number of octets according to <xref target="RFC3550"/>, >+ although the Opus internal padding is preferred.</t> >+ >+ <t>The timestamp, sequence number, and marker bit (M) of the RTP header >+ are used in accordance with Section 4.1 >+ of <xref target="RFC3551"/>.</t> >+ >+ <t>The RTP payload type for Opus is to be assigned dynamically.</t> >+ >+ <t>The receiving side MUST be prepared to receive duplicate RTP >+ packets. The receiver MUST provide at most one of those payloads to the >+ Opus decoder for decoding, and MUST discard the others.</t> >+ >+ <t>Opus supports 5 different audio bandwidths, which can be adjusted during >+ a stream. >+ The RTP timestamp is incremented with a 48000 Hz clock rate >+ for all modes of Opus and all sampling rates. >+ The unit >+ for the timestamp is samples per single (mono) channel. The RTP timestamp corresponds to the >+ sample time of the first encoded sample in the encoded frame. >+ For data encoded with sampling rates other than 48000 Hz, >+ the sampling rate has to be adjusted to 48000 Hz.</t> >+ >+ </section> >+ >+ <section title='Payload Structure'> >+ <t> >+ The Opus encoder can output encoded frames representing 2.5, 5, 10, 20, >+ 40, or 60 ms of speech or audio data. Further, an arbitrary number of frames can be >+ combined into a packet, up to a maximum packet duration representing >+ 120 ms of speech or audio data. The grouping of one or more Opus >+ frames into a single Opus packet is defined in Section 3 of >+ <xref target="RFC6716"/>. An RTP payload MUST contain exactly one >+ Opus packet as defined by that document. >+ </t> >+ >+ <t><xref target='payload-structure'/> shows the structure combined with the RTP header.</t> >+ >+ <figure anchor="payload-structure" >+ title="Packet structure with RTP header"> >+ <artwork align="center"> >+ <![CDATA[ >++----------+--------------+ >+|RTP Header| Opus Payload | >++----------+--------------+ >+ ]]> >+ </artwork> >+ </figure> >+ >+ <t> >+ <xref target='opus-packetization'/> shows supported frame sizes in >+ milliseconds of encoded speech or audio data for the speech and audio modes >+ (Mode) and sampling rates (fs) of Opus and shows how the timestamp is >+ incremented for packetization (ts incr). If the Opus encoder >+ outputs multiple encoded frames into a single packet, the timestamp >+ increment is the sum of the increments for the individual frames. >+ </t> >+ >+ <texttable anchor='opus-packetization' title="Supported Opus frame >+ sizes and timestamp increments marked with an o. Unsupported marked with an x."> >+ <ttcol align='center'>Mode</ttcol> >+ <ttcol align='center'>fs</ttcol> >+ <ttcol align='center'>2.5</ttcol> >+ <ttcol align='center'>5</ttcol> >+ <ttcol align='center'>10</ttcol> >+ <ttcol align='center'>20</ttcol> >+ <ttcol align='center'>40</ttcol> >+ <ttcol align='center'>60</ttcol> >+ <c>ts incr</c> >+ <c>all</c> >+ <c>120</c> >+ <c>240</c> >+ <c>480</c> >+ <c>960</c> >+ <c>1920</c> >+ <c>2880</c> >+ <c>voice</c> >+ <c>NB/MB/WB/SWB/FB</c> >+ <c>x</c> >+ <c>x</c> >+ <c>o</c> >+ <c>o</c> >+ <c>o</c> >+ <c>o</c> >+ <c>audio</c> >+ <c>NB/WB/SWB/FB</c> >+ <c>o</c> >+ <c>o</c> >+ <c>o</c> >+ <c>o</c> >+ <c>x</c> >+ <c>x</c> >+ </texttable> >+ >+ </section> >+ >+ </section> >+ >+ <section title='Congestion Control'> >+ >+ <t>The target bitrate of Opus can be adjusted at any point in time, thus >+ allowing efficient congestion control. Furthermore, the amount >+ of encoded speech or audio data encoded in a >+ single packet can be used for congestion control, since the transmission >+ rate is inversely proportional to the packet duration. A lower packet >+ transmission rate reduces the amount of header overhead, but at the same >+ time increases latency and loss sensitivity, so it ought to be used with >+ care.</t> >+ >+ <t>Since UDP does not provide congestion control, applications that use >+ RTP over UDP SHOULD implement their own congestion control above the >+ UDP layer <xref target="RFC5405"/>. Work in the rmcat working group >+ <xref target="rmcat"/> describes the >+ interactions and conceptual interfaces necessary between the application >+ components that relate to congestion control, including the RTP layer, >+ the higher-level media codec control layer, and the lower-level >+ transport interface, as well as components dedicated to congestion >+ control functions.</t> >+ </section> >+ >+ <section title='IANA Considerations'> >+ <t>One media subtype (audio/opus) has been defined and registered as >+ described in the following section.</t> >+ >+ <section title='Opus Media Type Registration'> >+ <t>Media type registration is done according to <xref >+ target="RFC6838"/> and <xref target="RFC4855"/>.<vspace >+ blankLines='1'/></t> >+ >+ <t>Type name: audio<vspace blankLines='1'/></t> >+ <t>Subtype name: opus<vspace blankLines='1'/></t> >+ >+ <t>Required parameters:</t> >+ <t><list style="hanging"> >+ <t hangText="rate:"> the RTP timestamp is incremented with a >+ 48000 Hz clock rate for all modes of Opus and all sampling >+ rates. For data encoded with sampling rates other than 48000 Hz, >+ the sampling rate has to be adjusted to 48000 Hz. >+ </t> >+ </list></t> >+ >+ <t>Optional parameters:</t> >+ >+ <t><list style="hanging"> >+ <t hangText="maxplaybackrate:"> >+ a hint about the maximum output sampling rate that the receiver is >+ capable of rendering in Hz. >+ The decoder MUST be capable of decoding >+ any audio bandwidth but due to hardware limitations only signals >+ up to the specified sampling rate can be played back. Sending signals >+ with higher audio bandwidth results in higher than necessary network >+ usage and encoding complexity, so an encoder SHOULD NOT encode >+ frequencies above the audio bandwidth specified by maxplaybackrate. >+ This parameter can take any value between 8000 and 48000, although >+ commonly the value will match one of the Opus bandwidths >+ (<xref target="bandwidth_definitions"/>). >+ By default, the receiver is assumed to have no limitations, i.e. 48000. >+ <vspace blankLines='1'/> >+ </t> >+ >+ <t hangText="sprop-maxcapturerate:"> >+ a hint about the maximum input sampling rate that the sender is likely to produce. >+ This is not a guarantee that the sender will never send any higher bandwidth >+ (e.g. it could send a pre-recorded prompt that uses a higher bandwidth), but it >+ indicates to the receiver that frequencies above this maximum can safely be discarded. >+ This parameter is useful to avoid wasting receiver resources by operating the audio >+ processing pipeline (e.g. echo cancellation) at a higher rate than necessary. >+ This parameter can take any value between 8000 and 48000, although >+ commonly the value will match one of the Opus bandwidths >+ (<xref target="bandwidth_definitions"/>). >+ By default, the sender is assumed to have no limitations, i.e. 48000. >+ <vspace blankLines='1'/> >+ </t> >+ >+ <t hangText="maxptime:"> the maximum duration of media represented >+ by a packet (according to Section 6 of >+ <xref target="RFC4566"/>) that a decoder wants to receive, in >+ milliseconds rounded up to the next full integer value. >+ Possible values are 3, 5, 10, 20, 40, 60, or an arbitrary >+ multiple of an Opus frame size rounded up to the next full integer >+ value, up to a maximum value of 120, as >+ defined in <xref target='opus-rtp-payload-format'/>. If no value is >+ specified, the default is 120. >+ <vspace blankLines='1'/></t> >+ >+ <t hangText="ptime:"> the preferred duration of media represented >+ by a packet (according to Section 6 of >+ <xref target="RFC4566"/>) that a decoder wants to receive, in >+ milliseconds rounded up to the next full integer value. >+ Possible values are 3, 5, 10, 20, 40, 60, or an arbitrary >+ multiple of an Opus frame size rounded up to the next full integer >+ value, up to a maximum value of 120, as defined in <xref >+ target='opus-rtp-payload-format'/>. If no value is >+ specified, the default is 20. >+ <vspace blankLines='1'/></t> >+ >+ <t hangText="maxaveragebitrate:"> specifies the maximum average >+ receive bitrate of a session in bits per second (b/s). The actual >+ value of the bitrate can vary, as it is dependent on the >+ characteristics of the media in a packet. Note that the maximum >+ average bitrate MAY be modified dynamically during a session. Any >+ positive integer is allowed, but values outside the range >+ 6000 to 510000 SHOULD be ignored. If no value is specified, the >+ maximum value specified in <xref target='bitrate_by_bandwidth'/> >+ for the corresponding mode of Opus and corresponding maxplaybackrate >+ is the default.<vspace blankLines='1'/></t> >+ >+ <t hangText="stereo:"> >+ specifies whether the decoder prefers receiving stereo or mono signals. >+ Possible values are 1 and 0 where 1 specifies that stereo signals are preferred, >+ and 0 specifies that only mono signals are preferred. >+ Independent of the stereo parameter every receiver MUST be able to receive and >+ decode stereo signals but sending stereo signals to a receiver that signaled a >+ preference for mono signals may result in higher than necessary network >+ utilization and encoding complexity. If no value is specified, >+ the default is 0 (mono).<vspace blankLines='1'/> >+ </t> >+ >+ <t hangText="sprop-stereo:"> >+ specifies whether the sender is likely to produce stereo audio. >+ Possible values are 1 and 0, where 1 specifies that stereo signals are likely to >+ be sent, and 0 specifies that the sender will likely only send mono. >+ This is not a guarantee that the sender will never send stereo audio >+ (e.g. it could send a pre-recorded prompt that uses stereo), but it >+ indicates to the receiver that the received signal can be safely downmixed to mono. >+ This parameter is useful to avoid wasting receiver resources by operating the audio >+ processing pipeline (e.g. echo cancellation) in stereo when not necessary. >+ If no value is specified, the default is 0 >+ (mono).<vspace blankLines='1'/> >+ </t> >+ >+ <t hangText="cbr:"> >+ specifies if the decoder prefers the use of a constant bitrate versus >+ variable bitrate. Possible values are 1 and 0, where 1 specifies constant >+ bitrate and 0 specifies variable bitrate. If no value is specified, >+ the default is 0 (vbr). When cbr is 1, the maximum average bitrate can still >+ change, e.g. to adapt to changing network conditions.<vspace blankLines='1'/> >+ </t> >+ >+ <t hangText="useinbandfec:"> specifies that the decoder has the capability to >+ take advantage of the Opus in-band FEC. Possible values are 1 and 0. >+ Providing 0 when FEC cannot be used on the receiving side is >+ RECOMMENDED. If no >+ value is specified, useinbandfec is assumed to be 0. >+ This parameter is only a preference and the receiver MUST be able to process >+ packets that include FEC information, even if it means the FEC part is discarded. >+ <vspace blankLines='1'/></t> >+ >+ <t hangText="usedtx:"> specifies if the decoder prefers the use of >+ DTX. Possible values are 1 and 0. If no value is specified, the >+ default is 0.<vspace blankLines='1'/></t> >+ </list></t> >+ >+ <t>Encoding considerations:<vspace blankLines='1'/></t> >+ <t><list style="hanging"> >+ <t>The Opus media type is framed and consists of binary data according >+ to Section 4.8 in <xref target="RFC6838"/>.</t> >+ </list></t> >+ >+ <t>Security considerations: </t> >+ <t><list style="hanging"> >+ <t>See <xref target='security-considerations'/> of this document.</t> >+ </list></t> >+ >+ <t>Interoperability considerations: none<vspace blankLines='1'/></t> >+ <t>Published specification: RFC [XXXX]</t> >+ <t>Note to the RFC Editor: Replace [XXXX] with the number of the published >+ RFC.<vspace blankLines='1'/></t> >+ >+ <t>Applications that use this media type: </t> >+ <t><list style="hanging"> >+ <t>Any application that requires the transport of >+ speech or audio data can use this media type. Some examples are, >+ but not limited to, audio and video conferencing, Voice over IP, >+ media streaming.</t> >+ </list></t> >+ >+ <t>Fragment identifier considerations: N/A<vspace blankLines='1'/></t> >+ >+ <t>Person & email address to contact for further information:</t> >+ <t><list style="hanging"> >+ <t>SILK Support silksupport@skype.net</t> >+ <t>Jean-Marc Valin jmvalin@jmvalin.ca</t> >+ </list></t> >+ >+ <t>Intended usage: COMMON<vspace blankLines='1'/></t> >+ >+ <t>Restrictions on usage:<vspace blankLines='1'/></t> >+ >+ <t><list style="hanging"> >+ <t>For transfer over RTP, the RTP payload format (<xref >+ target='opus-rtp-payload-format'/> of this document) SHALL be >+ used.</t> >+ </list></t> >+ >+ <t>Author:</t> >+ <t><list style="hanging"> >+ <t>Julian Spittka jspittka@gmail.com<vspace blankLines='1'/></t> >+ <t>Koen Vos koenvos74@gmail.com<vspace blankLines='1'/></t> >+ <t>Jean-Marc Valin jmvalin@jmvalin.ca<vspace blankLines='1'/></t> >+ </list></t> >+ >+ <t> Change controller: IETF Payload Working Group delegated from the IESG</t> >+ </section> >+ </section> >+ >+ <section title='SDP Considerations'> >+ <t>The information described in the media type specification has a >+ specific mapping to fields in the Session Description Protocol (SDP) >+ <xref target="RFC4566"/>, which is commonly used to describe RTP >+ sessions. When SDP is used to specify sessions employing Opus, >+ the mapping is as follows:</t> >+ >+ <t> >+ <list style="symbols"> >+ <t>The media type ("audio") goes in SDP "m=" as the media name.</t> >+ >+ <t>The media subtype ("opus") goes in SDP "a=rtpmap" as the encoding >+ name. The RTP clock rate in "a=rtpmap" MUST be 48000 and the number of >+ channels MUST be 2.</t> >+ >+ <t>The OPTIONAL media type parameters "ptime" and "maxptime" are >+ mapped to "a=ptime" and "a=maxptime" attributes, respectively, in the >+ SDP.</t> >+ >+ <t>The OPTIONAL media type parameters "maxaveragebitrate", >+ "maxplaybackrate", "stereo", "cbr", "useinbandfec", and >+ "usedtx", when present, MUST be included in the "a=fmtp" attribute >+ in the SDP, expressed as a media type string in the form of a >+ semicolon-separated list of parameter=value pairs (e.g., >+ maxplaybackrate=48000). They MUST NOT be specified in an >+ SSRC-specific "fmtp" source-level attribute (as defined in >+ Section 6.3 of <xref target="RFC5576"/>).</t> >+ >+ <t>The OPTIONAL media type parameters "sprop-maxcapturerate", >+ and "sprop-stereo" MAY be mapped to the "a=fmtp" SDP attribute by >+ copying them directly from the media type parameter string as part >+ of the semicolon-separated list of parameter=value pairs (e.g., >+ sprop-stereo=1). These same OPTIONAL media type parameters MAY also >+ be specified using an SSRC-specific "fmtp" source-level attribute >+ as described in Section 6.3 of <xref target="RFC5576"/>. >+ They MAY be specified in both places, in which case the parameter >+ in the source-level attribute overrides the one found on the >+ "a=fmtp" line. The value of any parameter which is not specified in >+ a source-level source attribute MUST be taken from the "a=fmtp" >+ line, if it is present there.</t> >+ >+ </list> >+ </t> >+ >+ <t>Below are some examples of SDP session descriptions for Opus:</t> >+ >+ <t>Example 1: Standard mono session with 48000 Hz clock rate</t> >+ <figure> >+ <artwork> >+ <![CDATA[ >+ m=audio 54312 RTP/AVP 101 >+ a=rtpmap:101 opus/48000/2 >+ ]]> >+ </artwork> >+ </figure> >+ >+ >+ <t>Example 2: 16000 Hz clock rate, maximum packet size of 40 ms, >+ recommended packet size of 40 ms, maximum average bitrate of 20000 bps, >+ prefers to receive stereo but only plans to send mono, FEC is desired, >+ DTX is not desired</t> >+ >+ <figure> >+ <artwork> >+ <![CDATA[ >+ m=audio 54312 RTP/AVP 101 >+ a=rtpmap:101 opus/48000/2 >+ a=fmtp:101 maxplaybackrate=16000; sprop-maxcapturerate=16000; >+ maxaveragebitrate=20000; stereo=1; useinbandfec=1; usedtx=0 >+ a=ptime:40 >+ a=maxptime:40 >+ ]]> >+ </artwork> >+ </figure> >+ >+ <t>Example 3: Two-way full-band stereo preferred</t> >+ >+ <figure> >+ <artwork> >+ <![CDATA[ >+ m=audio 54312 RTP/AVP 101 >+ a=rtpmap:101 opus/48000/2 >+ a=fmtp:101 stereo=1; sprop-stereo=1 >+ ]]> >+ </artwork> >+ </figure> >+ >+ >+ <section title='SDP Offer/Answer Considerations'> >+ >+ <t>When using the offer-answer procedure described in <xref >+ target="RFC3264"/> to negotiate the use of Opus, the following >+ considerations apply:</t> >+ >+ <t><list style="symbols"> >+ >+ <t>Opus supports several clock rates. For signaling purposes only >+ the highest, i.e. 48000, is used. The actual clock rate of the >+ corresponding media is signaled inside the payload and is not >+ restricted by this payload format description. The decoder MUST be >+ capable of decoding every received clock rate. An example >+ is shown below: >+ >+ <figure> >+ <artwork> >+ <![CDATA[ >+ m=audio 54312 RTP/AVP 100 >+ a=rtpmap:100 opus/48000/2 >+ ]]> >+ </artwork> >+ </figure> >+ </t> >+ >+ <t>The "ptime" and "maxptime" parameters are unidirectional >+ receive-only parameters and typically will not compromise >+ interoperability; however, some values might cause application >+ performance to suffer. <xref >+ target="RFC3264"/> defines the SDP offer-answer handling of the >+ "ptime" parameter. The "maxptime" parameter MUST be handled in the >+ same way.</t> >+ >+ <t> >+ The "maxplaybackrate" parameter is a unidirectional receive-only >+ parameter that reflects limitations of the local receiver. When >+ sending to a single destination, a sender MUST NOT use an audio >+ bandwidth higher than necessary to make full use of audio sampled at >+ a sampling rate of "maxplaybackrate". Gateways or senders that >+ are sending the same encoded audio to multiple destinations >+ SHOULD NOT use an audio bandwidth higher than necessary to >+ represent audio sampled at "maxplaybackrate", as this would lead >+ to inefficient use of network resources. >+ The "maxplaybackrate" parameter does not >+ affect interoperability. Also, this parameter SHOULD NOT be used >+ to adjust the audio bandwidth as a function of the bitrate, as this >+ is the responsibility of the Opus encoder implementation. >+ </t> >+ >+ <t>The "maxaveragebitrate" parameter is a unidirectional receive-only >+ parameter that reflects limitations of the local receiver. The sender >+ of the other side MUST NOT send with an average bitrate higher than >+ "maxaveragebitrate" as it might overload the network and/or >+ receiver. The "maxaveragebitrate" parameter typically will not >+ compromise interoperability; however, some values might cause >+ application performance to suffer, and ought to be set with >+ care.</t> >+ >+ <t>The "sprop-maxcapturerate" and "sprop-stereo" parameters are >+ unidirectional sender-only parameters that reflect limitations of >+ the sender side. >+ They allow the receiver to set up a reduced-complexity audio >+ processing pipeline if the sender is not planning to use the full >+ range of Opus's capabilities. >+ Neither "sprop-maxcapturerate" nor "sprop-stereo" affect >+ interoperability and the receiver MUST be capable of receiving any signal. >+ </t> >+ >+ <t> >+ The "stereo" parameter is a unidirectional receive-only >+ parameter. When sending to a single destination, a sender MUST >+ NOT use stereo when "stereo" is 0. Gateways or senders that are >+ sending the same encoded audio to multiple destinations SHOULD >+ NOT use stereo when "stereo" is 0, as this would lead to >+ inefficient use of network resources. The "stereo" parameter does >+ not affect interoperability. >+ </t> >+ >+ <t> >+ The "cbr" parameter is a unidirectional receive-only >+ parameter. >+ </t> >+ >+ <t>The "useinbandfec" parameter is a unidirectional receive-only >+ parameter.</t> >+ >+ <t>The "usedtx" parameter is a unidirectional receive-only >+ parameter.</t> >+ >+ <t>Any unknown parameter in an offer MUST be ignored by the receiver >+ and MUST be removed from the answer.</t> >+ >+ </list></t> >+ >+ <t> >+ The Opus parameters in an SDP Offer/Answer exchange are completely >+ orthogonal, and there is no relationship between the SDP Offer and >+ the Answer. >+ </t> >+ </section> >+ >+ <section title='Declarative SDP Considerations for Opus'> >+ >+ <t>For declarative use of SDP such as in Session Announcement Protocol >+ (SAP), <xref target="RFC2974"/>, and RTSP, <xref target="RFC2326"/>, for >+ Opus, the following needs to be considered:</t> >+ >+ <t><list style="symbols"> >+ >+ <t>The values for "maxptime", "ptime", "maxplaybackrate", and >+ "maxaveragebitrate" ought to be selected carefully to ensure that a >+ reasonable performance can be achieved for the participants of a session.</t> >+ >+ <t> >+ The values for "maxptime", "ptime", and of the payload >+ format configuration are recommendations by the decoding side to ensure >+ the best performance for the decoder. >+ </t> >+ >+ <t>All other parameters of the payload format configuration are declarative >+ and a participant MUST use the configurations that are provided for >+ the session. More than one configuration can be provided if necessary >+ by declaring multiple RTP payload types; however, the number of types >+ ought to be kept small.</t> >+ </list></t> >+ </section> >+ </section> >+ >+ <section title='Security Considerations' anchor='security-considerations'> >+ >+ <t>Use of variable bitrate (VBR) is subject to the security considerations in >+ <xref target="RFC6562"/>.</t> >+ >+ <t>RTP packets using the payload format defined in this specification >+ are subject to the security considerations discussed in the RTP >+ specification <xref target="RFC3550"/>, and in any applicable RTP profile such as >+ RTP/AVP <xref target="RFC3551"/>, RTP/AVPF <xref target="RFC4585"/>, >+ RTP/SAVP <xref target="RFC3711"/> or RTP/SAVPF <xref target="RFC5124"/>. >+ However, as "Securing the RTP Protocol Framework: >+ Why RTP Does Not Mandate a Single Media Security Solution" >+ <xref target="RFC7202"/> discusses, it is not an RTP payload >+ format's responsibility to discuss or mandate what solutions are used >+ to meet the basic security goals like confidentiality, integrity and >+ source authenticity for RTP in general. This responsibility lays on >+ anyone using RTP in an application. They can find guidance on >+ available security mechanisms and important considerations in Options >+ for Securing RTP Sessions [I-D.ietf-avtcore-rtp-security-options]. >+ Applications SHOULD use one or more appropriate strong security >+ mechanisms.</t> >+ >+ <t>This payload format and the Opus encoding do not exhibit any >+ significant non-uniformity in the receiver-end computational load and thus >+ are unlikely to pose a denial-of-service threat due to the receipt of >+ pathological datagrams.</t> >+ </section> >+ >+ <section title='Acknowledgements'> >+ <t>Many people have made useful comments and suggestions contributing to this document. >+ In particular, we would like to thank >+ Tina le Grand, Cullen Jennings, Jonathan Lennox, Gregory Maxwell, Colin Perkins, Jan Skoglund, >+ Timothy B. Terriberry, Martin Thompson, Justin Uberti, Magnus Westerlund, and Mo Zanaty.</t> >+ </section> >+ </middle> >+ >+ <back> >+ <references title="Normative References"> >+ &rfc2119; >+ &rfc3389; >+ &rfc3550; >+ &rfc3711; >+ &rfc3551; >+ &rfc6838; >+ &rfc4855; >+ &rfc4566; >+ &rfc3264; >+ &rfc2326; >+ &rfc5576; >+ &rfc6562; >+ &rfc6716; >+ </references> >+ >+ <references title="Informative References"> >+ &rfc2974; >+ &rfc4585; >+ &rfc5124; >+ &rfc5405; >+ &rfc7202; >+ >+ <reference anchor='rmcat' target='https://datatracker.ietf.org/wg/rmcat/documents/'> >+ <front> >+ <title>rmcat documents</title> >+ <author/> >+ <date/> >+ <abstract> >+ <t></t> >+ </abstract></front> >+ </reference> >+ >+ >+ </references> >+ >+ </back> >+</rfc> >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/opus_in_isobmff.css b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/opus_in_isobmff.css >new file mode 100644 >index 0000000000000000000000000000000000000000..bffe8f45ae9959bbd9c84f96ec832a9a0ae5e0dc >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/opus_in_isobmff.css >@@ -0,0 +1,60 @@ >+/* Normal links */ >+.normal_link a:link >+{ >+ color : yellow; >+} >+.normal_link a:visited >+{ >+ color : green; >+} >+ >+/* Boxes */ >+.pre >+{ >+ white-space: pre; /* CSS 2.0 */ >+ white-space: pre-wrap; /* CSS 2.1 */ >+ white-space: -pre-wrap; /* Opera 4-6 */ >+ white-space: -o-pre-wrap; /* Opera 7 */ >+ white-space: -moz-pre-wrap; /* Mozilla */ >+ white-space: -hp-pre-wrap; /* HP Printers */ >+ word-wrap : break-word; /* IE 5+ */ >+} >+ >+.title_box >+{ >+ width : 470px; >+ height : 70px; >+ margin : 2px 50px 2px 2px; >+ padding : 10px; >+ border : 1px solid black; >+ background-color : #666666; >+ white-space : pre; >+ float : left; >+ text-align : center; >+ color : #C0C0C0; >+ font-size : 50pt; >+ font-style : italic; >+} >+ >+.subindex_box >+{ >+ margin : 5px; >+ padding : 14px 22px; >+ border : 1px solid black; >+ background-color : #778877; >+ float : left; >+ text-align : center; >+ color : #115555; >+ font-size : 32pt; >+} >+ >+.frame_box >+{ >+ margin : 10px; >+ padding : 10px; >+ border : 0px; >+ background-color : #084040; >+ text-align : left; >+ color : #C0C0C0; >+ font-family : monospace; >+} >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/opus_in_isobmff.html b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/opus_in_isobmff.html >new file mode 100644 >index 0000000000000000000000000000000000000000..a1175dbfdde25e8372ed6fc4d0401fca922c599e >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/opus_in_isobmff.html >@@ -0,0 +1,684 @@ >+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> >+<html> >+ <head> >+ <link rel="stylesheet" type="text/css" href="opus_in_isobmff.css"/> >+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> >+ <title>Encapsulation of Opus in ISO Base Media File Format</title> >+ </head> >+ <body bgcolor="0x333333" text="#60B0C0"> >+ <b><u>Encapsulation of Opus in ISO Base Media File Format</u></b><br> >+ <font size="2">last updated: April 28, 2016</font><br> >+ <br> >+ <div class="normal_link pre frame_box"> >+ >+ Encapsulation of Opus in ISO Base Media File Format >+ Version 0.6.8 (incomplete) >+ >+ >+Table of Contents >+<a href="#1">1</a> Scope >+<a href="#2">2</a> Normative References >+<a href="#3">3</a> Terms and Definitions >+<a href="#4">4</a> Design Rules of Encapsulation >+ <a href="#4.1">4.1</a> File Type Indentification >+ <a href="#4.2">4.2</a> Overview of Track Structure >+ <a href="#4.3">4.3</a> Definitions of Opus sample >+ <a href="#4.3.1">4.3.1</a> Sample entry format >+ <a href="#4.3.2">4.3.2</a> Opus Specific Box >+ <a href="#4.3.3">4.3.3</a> Sample format >+ <a href="#4.3.4">4.3.4</a> Duration of Opus sample >+ <a href="#4.3.5">4.3.5</a> Sub-sample >+ <a href="#4.3.6">4.3.6</a> Random Access >+ <a href="#4.3.6.1">4.3.6.1</a> Random Access Point >+ <a href="#4.3.6.2">4.3.6.2</a> Pre-roll >+ <a href="#4.4">4.4</a> Trimming of Actual Duration >+ <a href="#4.5">4.5</a> Channel Layout (informative) >+ <a href="#4.6">4.6</a> Basic Structure (informative) >+ <a href="#4.6.1">4.6.2</a> Initial Movie >+ <a href="#4.6.2">4.6.3</a> Movie Fragments >+ <a href="#4.7">4.7</a> Example of Encapsulation (informative) >+<a href="#5">5</a> Author's Address >+ >+<a name="1"></a> >+1 Scope >+ This specification specifies the fundamental way of the encapsulation of Opus coded bitstreams in ISO Base Media >+ file format and its derivatives. The encapsulation of Opus coded bitstreams in QuickTime file format is outside >+ the scope of this specification. >+ >+<a name="2"></a> >+2 Normative References >+ [1] ISO/IEC 14496-12:2015 Corrected version >+ Information technology — Coding of audio-visual objects — Part 12: ISO base media file format >+ >+ [2] RFC 6716 >+ Definition of the Opus Audio Codec >+ >+ [3] draft-ietf-codec-oggopus-06 >+ Ogg Encapsulation for the Opus Audio Codec >+ >+<a name="3"></a> >+3 Terms and Definitions >+ 3.1 active track >+ enabled track from the non-alternate group or selected track from alternate group >+ >+ 3.2 actual duration >+ duration constructed from valid samples >+ >+ 3.3 edit >+ entry in the Edit List Box >+ >+ 3.4 padded samples >+ PCM samples after decoding Opus sample(s) which are not valid samples >+ An Opus bitstream always contains them partially at the beginning and may contain them in part at the end, as >+ long as not physically removed yet at the beginning and/or the end. >+ >+ 3.5 priming samples >+ padded samples at the beginning of the Opus bitstream >+ >+ 3.6 sample-accurate >+ for any PCM sample, a timestamp exactly matching its sampling timestamp is present in the media timeline. >+ >+ 3.7 valid samples >+ PCM samples after decoding Opus sample(s) corresponding to input PCM samples >+ >+<a name="4"></a> >+4 Design Rules of Encapsulation >+ 4.1 File Type Indentification<a name="4.1"></a> >+ This specification does not define any brand to declare files are conformant to this specification. However, >+ files conformant to this specification shall contain at least one brand, which supports the requirements and the >+ requirements described in this clause without contradiction, in the compatible brands list of the File Type Box. >+ As an example, the minimal support of the encapsulation of Opus bitstreams in ISO Base Media file format requires >+ the 'iso2' brand in the compatible brands list since support of roll groups is required. >+<a name="4.2"></a> >+ 4.2 Overview of Track Structure >+ This clause summarizes requirements of the encapsulation of Opus coded bitstream as media data in audio tracks >+ in file formats compliant with the ISO Base Media File Format. The details are described in clauses after this >+ clause. >+ + The handler_type field in the Handler Reference Box shall be set to 'soun'. >+ + The Media Information Box shall contain the Sound Media Header Box. >+ + The codingname of the sample entry is 'Opus'. >+ This specification does not define any encapsulation using MP4AudioSampleEntry with objectTypeIndication >+ specified by the MPEG-4 Registration Authority (http://www.mp4ra.org/). >+ See 4.3.1 Sample entry format to get the details about the sample entry. >+ + The 'dOps' box is added to the sample entry to convey initializing information for the decoder. >+ See 4.3.2 Opus Specific Box to get the details. >+ + An Opus sample is exactly one Opus packet for each of different Opus bitstreams. >+ See 4.3.3 Sample format to get the details. >+ + Every Opus sample is a sync sample but requires pre-roll for every random access to get correct output. >+ See 4.3.6 Random Access to get the details. >+<a name="4.3"></a> >+ 4.3 Definitions of Opus sample >+ 4.3.1 Sample entry format<a name="4.3.1"></a> >+ For any track containing Opus bitstreams, at least one sample entry describing corresponding Opus bitstream >+ shall be present inside the Sample Table Box. This version of the specification defines only one sample >+ entry format named OpusSampleEntry whose codingname is 'Opus'. This sample entry includes exactly one Opus >+ Specific Box defined in 4.3.2 as a mandatory box and indicates that Opus samples described by this sample >+ entry are stored by the sample format described in 4.3.3. >+ >+ The syntax and semantics of the OpusSampleEntry is shown as follows. >+ >+ class OpusSampleEntry() extends AudioSampleEntry ('Opus'){ >+ OpusSpecificBox(); >+ } >+ >+ + channelcount: >+ The channelcount field shall be set to the sum of the total number of Opus bitstreams and the number >+ of Opus bitstreams producing two channels. This value is indentical with (M+N), where M is the value of >+ the *Coupled Stream Count* field and N is the value of the *Stream Count* field in the *Channel Mapping >+ Table* in the identification header defined in Ogg Opus [3]. >+ + samplesize: >+ The samplesize field shall be set to 16. >+ + samplerate: >+ The samplerate field shall be set to 48000<<16. >+ + OpusSpecificBox >+ This box contains initializing information for the decoder as defined in 4.3.2. >+ >+ 4.3.2 Opus Specific Box<a name="4.3.2"></a> >+ Exactly one Opus Specific Box shall be present in each OpusSampleEntry. >+ The Opus Specific Box contains the Version field and this specification defines version 0 of this box. >+ If incompatible changes occured in the fields after the Version field within the OpusSpecificBox in the >+ future versions of this specification, another version will be defined. >+ This box refers to Ogg Opus [3] at many parts but all the data are stored as big-endian format. >+ >+ The syntax and semantics of the Opus Specific Box is shown as follows. >+ >+ class ChannelMappingTable (unsigned int(8) OutputChannelCount){ >+ unsigned int(8) StreamCount; >+ unsigned int(8) CoupledCount; >+ unsigned int(8 * OutputChannelCount) ChannelMapping; >+ } >+ >+ aligned(8) class OpusSpecificBox extends Box('dOps'){ >+ unsigned int(8) Version; >+ unsigned int(8) OutputChannelCount; >+ unsigned int(16) PreSkip; >+ unsigned int(32) InputSampleRate; >+ signed int(16) OutputGain; >+ unsigned int(8) ChannelMappingFamily; >+ if (ChannelMappingFamily != 0) { >+ ChannelMappingTable(OutputChannelCount); >+ } >+ } >+ >+ + Version: >+ The Version field shall be set to 0. >+ In the future versions of this specification, this field may be set to other values. And without support >+ of those values, the reader shall not read the fields after this within the OpusSpecificBox. >+ + OutputChannelCount: >+ The OutputChannelCount field shall be set to the same value as the *Output Channel Count* field in the >+ identification header defined in Ogg Opus [3]. >+ + PreSkip: >+ The PreSkip field indicates the number of the priming samples, that is, the number of samples at 48000 Hz >+ to discard from the decoder output when starting playback. The value of the PreSkip field shall be at least >+ 80 milliseconds' worth of PCM samples even when removing any number of Opus samples which may or may not >+ contain the priming samples. The PreSkip field is not used for discarding the priming samples at the whole >+ playback at all since it is informative only, and that task falls on the Edit List Box. >+ + InputSampleRate: >+ The InputSampleRate field shall be set to the same value as the *Input Sample Rate* field in the >+ identification header defined in Ogg Opus [3]. >+ + OutputGain: >+ The OutputGain field shall be set to the same value as the *Output Gain* field in the identification >+ header define in Ogg Opus [3]. Note that the value is stored as 8.8 fixed-point. >+ + ChannelMappingFamily: >+ The ChannelMappingFamily field shall be set to the same value as the *Channel Mapping Family* field in >+ the identification header defined in Ogg Opus [3]. >+ + StreamCount: >+ The StreamCount field shall be set to the same value as the *Stream Count* field in the identification >+ header defined in Ogg Opus [3]. >+ + CoupledCount: >+ The CoupledCount field shall be set to the same value as the *Coupled Count* field in the identification >+ header defined in Ogg Opus [3]. >+ + ChannelMapping: >+ The ChannelMapping field shall be set to the same octet string as *Channel Mapping* field in the identi- >+ fication header defined in Ogg Opus [3]. >+ >+ 4.3.3 Sample format<a name="4.3.3"></a> >+ An Opus sample is exactly one Opus packet for each of different Opus bitstreams. Due to support more than >+ two channels, an Opus sample can contain frames from multiple Opus bitstreams but all Opus packets shall >+ share with the total of frame sizes in a single Opus sample. The way of how to pack an Opus packet from >+ each of Opus bitstreams into a single Opus sample follows Appendix B. in RFC 6716 [2]. >+ The endianness has nothing to do with any Opus sample since every Opus packet is processed byte-by-byte. >+ In this specification, 'sample' means 'Opus sample' except for 'padded samples', 'priming samples', 'valid >+ sample' and 'sample-accurate', i.e. 'sample' is 'sample' in the term defined in ISO/IEC 14496-12 [1]. >+ >+ +-----------------------------------------+-------------------------------------+ >+ | Opus packet 0 (self-delimiting framing) | Opus packet 1 (undelimited framing) | >+ +-----------------------------------------+-------------------------------------+ >+ |<---------------------------- the size of Opus sample ------------------------>| >+ >+ Figure 1 - Example structure of an Opus sample containing two Opus bitstreams >+ >+ 4.3.4 Duration of Opus sample<a name="4.3.4"></a> >+ The duration of Opus sample is given by multiplying the total of frame sizes for a single Opus bitstream >+ expressed in seconds by the value of the timescale field in the Media Header Box. >+ Let's say an Opus sample consists of two Opus bitstreams, where the frame size of one bitstream is 40 milli- >+ seconds and the frame size of another is 60 milliseconds, and the timescale field in the Media Header Box >+ is set to 48000, then the duration of that Opus sample shall be 120 milliseconds since three 40 millisecond >+ frame and two 60 millisecond frames shall be contained because of the maximum duration of Opus packet, 120 >+ milliseconds, and 5760 in the timescale indicated in the Media Header Box. >+ >+ To indicate the valid samples excluding the padded samples at the end of Opus bitstream, the duration of >+ the last Opus sample of an Opus bitstream is given by multiplying the number of the valid samples by the >+ value produced by dividing the value of the timescale field in the Media Header Box by 48000. >+ >+ 4.3.5 Sub-sample<a name="4.3.5"></a> >+ The structure of the last Opus packet in an Opus sample is different from the others in the same Opus sample, >+ and the others are invalid Opus packets as an Opus sample because of self-delimiting framing. To avoid >+ complexities, sub-sample is not defined for Opus sample in this specification. >+ >+ 4.3.6 Random Access<a name="4.3.6"></a> >+ This subclause describes the nature of the random access of Opus sample. >+ >+ 4.3.6.1 Random Access Point<a name="4.3.6.1"></a> >+ All Opus samples can be independently decoded i.e. every Opus sample is a sync sample. Therefore, the >+ Sync Sample Box shall not be present as long as there are no samples other than Opus samples in the same >+ track. And the sample_is_non_sync_sample field for Opus samples shall be set to 0. >+ >+ 4.3.6.2 Pre-roll<a name="4.3.6.2"></a> >+ Opus bitstream requires at least 80 millisecond pre-roll after each random access to get correct output. >+ Pre-roll is indicated by the roll_distance field in AudioRollRecoveryEntry. AudioPreRollEntry shall not >+ be used since every Opus sample is a sync sample in Opus bitstream. Note that roll_distance is expressed >+ in sample units in a term of ISO Base Media File Format, and always takes negative values. >+ >+ For any track containing Opus bitstreams, at least one Sample Group Description Box and at least one >+ Sample to Group Box within the Sample Table Box shall be present and these have the grouping_type field >+ set to 'roll'. If any Opus sample is contained in a track fragment, the Sample to Group Box with the >+ grouping_type field set to 'roll' shall be present for that track fragment. >+ >+ For the requirement of AudioRollRecoveryEntry, the compatible_brands field in the File Type Box shall >+ contain at least one brand which requires support for roll groups. >+<a name="4.4"></a> >+ 4.4 Trimming of Actual Duration >+ Due to the priming samples (or the padding at the beginning) derived from the pre-roll for the startup and the >+ padded samples at the end, we need trim from media to get the actual duration. An edit in the Edit List Box can >+ achieve this demand, and the Edit Box and the Edit List Box shall be present. >+ >+ For sample-accurate trimming, proper timescale should be set to the timescale field in the Movie Header Box >+ and the Media Header Box inside Track Box(es) for Opus bitstream. The timescale field in the Media Header Box is >+ typically set to 48000. It is recommended that the timescale field in the Movie Header Box be set to the same >+ value of the timescale field in the Media Header Box in order to avoid the rounding problem when specifying >+ duration of edit if the timescales in all of the Media Header Boxes are set to the same value. >+ >+ For example, to indicate the actual duration of an Opus bitstream in a track with the timescale fields of both >+ the Movie Header Box and the Media Header Box set to 48000, we would use the following edit: >+ segment_duration = the number of the valid samples >+ media_time = the number of the priming samples >+ media_rate = 1 << 16 >+ >+ The Edit List Box is applied to whole movie including all movie fragments. Therefore, it is impossible to tell >+ the actual duration in the case producing movie fragments on the fly such as live-streaming. In such cases, >+ the duration of the last Opus sample may be helpful by setting zero to the segment_duration field since the >+ value 0 represents implicit duration equal to the sum of the duration of all samples. >+<a name="4.5"></a> >+ 4.5 Channel Layout (informative) >+ By the application of alternate_group in the Track Header Box, whole audio channels in all active tracks from >+ non-alternate group and/or different alternate group from each other are composited into the presentation. If >+ an Opus sample consists of multiple Opus bitstreams, it can be splitted into individual Opus bitstreams and >+ reconstructed into new Opus samples as long as every Opus bitstream has the same total duration in each Opus >+ sample. This nature can be utilized to encapsulate a single Opus bitstream in each track without breaking the >+ original channel layout. >+ >+ As an example, let's say there is a following track: >+ OutputChannelCount = 6; >+ StreamCount = 4; >+ CoupledCount = 2; >+ ChannelMapping = {0, 4, 1, 2, 3, 5}; // front left, front center, front right, rear left, rear right, LFE >+ Here, to couple front left to front right channels into the first stream, and couple rear left to rear right >+ channels into the second stream, reordering is needed since coupled streams must precede any non-coupled stream. >+ You extract the four Opus bitstreams from this track and you encapsulate two of the four into a track and the >+ others into another track. The former track is as follows. >+ OutputChannelCount = 6; >+ StreamCount = 2; >+ CoupledCount = 2; >+ ChannelMapping = {0, 255, 1, 2, 3, 255}; // front left, front center, front right, rear left, rear right, LFE >+ And the latter track is as follows. >+ OutputChannelCount = 6; >+ StreamCount = 2; >+ CoupledCount = 0; >+ ChannelMapping = {255, 0, 255, 255, 255, 1}; // front left, front center, front right, rear left, rear right, LFE >+ In addition, the value of the alternate_group field in the both tracks is set to 0. As the result, the player >+ may play as if channels with 255 are not present, and play the presentation constructed from the both tracks >+ in the same channel layout as the one of the original track. Keep in mind that the way of the composition, i.e. >+ the mixing for playback, is not defined here, and maybe different results could occur except for the channel >+ layout of the original, depending on an implementation or the definition of a derived file format. >+ >+ Note that some derived file formats may specify the restriction to ignore alternate grouping. In the context of >+ such file formats, this application is not available. This unavailability does not mean incompatibilities among >+ file formats unless the restriction to the value of the alternate_group field is specified and brings about >+ any conflict among their definitions. >+<a name="4.6"></a> >+ 4.6 Basic Structure (informative) >+ 4.6.1 Initial Movie<a name="4.6.1"></a> >+ This subclause shows a basic structure of the Movie Box as follows: >+ >+ +----+----+----+----+----+----+----+----+------------------------------+ >+ |moov| | | | | | | | Movie Box | >+ +----+----+----+----+----+----+----+----+------------------------------+ >+ | |mvhd| | | | | | | Movie Header Box | >+ +----+----+----+----+----+----+----+----+------------------------------+ >+ | |trak| | | | | | | Track Box | >+ +----+----+----+----+----+----+----+----+------------------------------+ >+ | | |tkhd| | | | | | Track Header Box | >+ +----+----+----+----+----+----+----+----+------------------------------+ >+ | | |edts| | | | | | Edit Box | >+ +----+----+----+----+----+----+----+----+------------------------------+ >+ | | | |elst| | | | | Edit List Box | >+ +----+----+----+----+----+----+----+----+------------------------------+ >+ | | |mdia| | | | | | Media Box | >+ +----+----+----+----+----+----+----+----+------------------------------+ >+ | | | |mdhd| | | | | Media Header Box | >+ +----+----+----+----+----+----+----+----+------------------------------+ >+ | | | |hdlr| | | | | Handler Reference Box | >+ +----+----+----+----+----+----+----+----+------------------------------+ >+ | | | |minf| | | | | Media Information Box | >+ +----+----+----+----+----+----+----+----+------------------------------+ >+ | | | | |smhd| | | | Sound Media Header Box | >+ +----+----+----+----+----+----+----+----+------------------------------+ >+ | | | | |dinf| | | | Data Information Box | >+ +----+----+----+----+----+----+----+----+------------------------------+ >+ | | | | | |dref| | | Data Reference Box | >+ +----+----+----+----+----+----+----+----+------------------------------+ >+ | | | | | | |url | | DataEntryUrlBox | >+ +----+----+----+----+----+----+ or +----+------------------------------+ >+ | | | | | | |urn | | DataEntryUrnBox | >+ +----+----+----+----+----+----+----+----+------------------------------+ >+ | | | | |stbl| | | | Sample Table | >+ +----+----+----+----+----+----+----+----+------------------------------+ >+ | | | | | |stsd| | | Sample Description Box | >+ +----+----+----+----+----+----+----+----+------------------------------+ >+ | | | | | | |Opus| | OpusSampleEntry | >+ +----+----+----+----+----+----+----+----+------------------------------+ >+ | | | | | | | |dOps| Opus Specific Box | >+ +----+----+----+----+----+----+----+----+------------------------------+ >+ | | | | | |stts| | | Decoding Time to Sample Box | >+ +----+----+----+----+----+----+----+----+------------------------------+ >+ | | | | | |stsc| | | Sample To Chunk Box | >+ +----+----+----+----+----+----+----+----+------------------------------+ >+ | | | | | |stsz| | | Sample Size Box | >+ +----+----+----+----+----+ or +----+----+------------------------------+ >+ | | | | | |stz2| | | Compact Sample Size Box | >+ +----+----+----+----+----+----+----+----+------------------------------+ >+ | | | | | |stco| | | Chunk Offset Box | >+ +----+----+----+----+----+ or +----+----+------------------------------+ >+ | | | | | |co64| | | Chunk Large Offset Box | >+ +----+----+----+----+----+----+----+----+------------------------------+ >+ | | | | | |sgpd| | | Sample Group Description Box | >+ +----+----+----+----+----+----+----+----+------------------------------+ >+ | | | | | |sbgp| | | Sample to Group Box | >+ +----+----+----+----+----+----+----+----+------------------------------+ >+ | |mvex|* | | | | | | Movie Extends Box | >+ +----+----+----+----+----+----+----+----+------------------------------+ >+ | | |trex|* | | | | | Track Extends Box | >+ +----+----+----+----+----+----+----+----+------------------------------+ >+ >+ Figure 2 - Basic structure of Movie Box >+ >+ It is strongly recommended that the order of boxes should follow the above structure. >+ Boxes marked with an asterisk (*) may be present. >+ For most boxes listed above, the definition is as is defined in ISO/IEC 14496-12 [1]. The additional boxes >+ and the additional requirements, restrictions and recommendations to the other boxes are described in this >+ specification. >+ >+ 4.6.2 Movie Fragments<a name="4.6.2"></a> >+ This subclause shows a basic structure of the Movie Fragment Box as follows: >+ >+ +----+----+----+----+----+----+----+----+------------------------------+ >+ |moof| | | | | | | | Movie Fragment Box | >+ +----+----+----+----+----+----+----+----+------------------------------+ >+ | |mfhd| | | | | | | Movie Fragment Header Box | >+ +----+----+----+----+----+----+----+----+------------------------------+ >+ | |traf| | | | | | | Track Fragment Box | >+ +----+----+----+----+----+----+----+----+------------------------------+ >+ | | |tfhd| | | | | | Track Fragment Header Box | >+ +----+----+----+----+----+----+----+----+------------------------------+ >+ | | |trun| | | | | | Track Fragment Run Box | >+ +----+----+----+----+----+----+----+----+------------------------------+ >+ | | |sgpd|* | | | | | Sample Group Description Box | >+ +----+----+----+----+----+----+----+----+------------------------------+ >+ | | |sbgp|* | | | | | Sample to Group Box | >+ +----+----+----+----+----+----+----+----+------------------------------+ >+ >+ Figure 3 - Basic structure of Movie Fragment Box >+ >+ It is strongly recommended that the Movie Fragment Header Box and the Track Fragment Header Box be >+ placed first in their container. >+ Boxes marked with an asterisk (*) may be present. >+ For the boxes listed above, the definition is as is defined in ISO/IEC 14496-12 [1]. >+<a name="4.7"></a> >+ 4.7 Example of Encapsulation (informative) >+ [File] >+ size = 17790 >+ [ftyp: File Type Box] >+ position = 0 >+ size = 24 >+ major_brand = mp42 : MP4 version 2 >+ minor_version = 0 >+ compatible_brands >+ brand[0] = mp42 : MP4 version 2 >+ brand[1] = iso2 : ISO Base Media file format version 2 >+ [moov: Movie Box] >+ position = 24 >+ size = 757 >+ [mvhd: Movie Header Box] >+ position = 32 >+ size = 108 >+ version = 0 >+ flags = 0x000000 >+ creation_time = UTC 2014/12/12, 18:41:19 >+ modification_time = UTC 2014/12/12, 18:41:19 >+ timescale = 48000 >+ duration = 33600 (00:00:00.700) >+ rate = 1.000000 >+ volume = 1.000000 >+ reserved = 0x0000 >+ reserved = 0x00000000 >+ reserved = 0x00000000 >+ transformation matrix >+ | a, b, u | | 1.000000, 0.000000, 0.000000 | >+ | c, d, v | = | 0.000000, 1.000000, 0.000000 | >+ | x, y, w | | 0.000000, 0.000000, 1.000000 | >+ pre_defined = 0x00000000 >+ pre_defined = 0x00000000 >+ pre_defined = 0x00000000 >+ pre_defined = 0x00000000 >+ pre_defined = 0x00000000 >+ pre_defined = 0x00000000 >+ next_track_ID = 2 >+ [iods: Object Descriptor Box] >+ position = 140 >+ size = 33 >+ version = 0 >+ flags = 0x000000 >+ [tag = 0x10: MP4_IOD] >+ expandableClassSize = 16 >+ ObjectDescriptorID = 1 >+ URL_Flag = 0 >+ includeInlineProfileLevelFlag = 0 >+ reserved = 0xf >+ ODProfileLevelIndication = 0xff >+ sceneProfileLevelIndication = 0xff >+ audioProfileLevelIndication = 0xfe >+ visualProfileLevelIndication = 0xff >+ graphicsProfileLevelIndication = 0xff >+ [tag = 0x0e: ES_ID_Inc] >+ expandableClassSize = 4 >+ Track_ID = 1 >+ [trak: Track Box] >+ position = 173 >+ size = 608 >+ [tkhd: Track Header Box] >+ position = 181 >+ size = 92 >+ version = 0 >+ flags = 0x000007 >+ Track enabled >+ Track in movie >+ Track in preview >+ creation_time = UTC 2014/12/12, 18:41:19 >+ modification_time = UTC 2014/12/12, 18:41:19 >+ track_ID = 1 >+ reserved = 0x00000000 >+ duration = 33600 (00:00:00.700) >+ reserved = 0x00000000 >+ reserved = 0x00000000 >+ layer = 0 >+ alternate_group = 0 >+ volume = 1.000000 >+ reserved = 0x0000 >+ transformation matrix >+ | a, b, u | | 1.000000, 0.000000, 0.000000 | >+ | c, d, v | = | 0.000000, 1.000000, 0.000000 | >+ | x, y, w | | 0.000000, 0.000000, 1.000000 | >+ width = 0.000000 >+ height = 0.000000 >+ [edts: Edit Box] >+ position = 273 >+ size = 36 >+ [elst: Edit List Box] >+ position = 281 >+ size = 28 >+ version = 0 >+ flags = 0x000000 >+ entry_count = 1 >+ entry[0] >+ segment_duration = 33600 >+ media_time = 312 >+ media_rate = 1.000000 >+ [mdia: Media Box] >+ position = 309 >+ size = 472 >+ [mdhd: Media Header Box] >+ position = 317 >+ size = 32 >+ version = 0 >+ flags = 0x000000 >+ creation_time = UTC 2014/12/12, 18:41:19 >+ modification_time = UTC 2014/12/12, 18:41:19 >+ timescale = 48000 >+ duration = 34560 (00:00:00.720) >+ language = und >+ pre_defined = 0x0000 >+ [hdlr: Handler Reference Box] >+ position = 349 >+ size = 51 >+ version = 0 >+ flags = 0x000000 >+ pre_defined = 0x00000000 >+ handler_type = soun >+ reserved = 0x00000000 >+ reserved = 0x00000000 >+ reserved = 0x00000000 >+ name = Xiph Audio Handler >+ [minf: Media Information Box] >+ position = 400 >+ size = 381 >+ [smhd: Sound Media Header Box] >+ position = 408 >+ size = 16 >+ version = 0 >+ flags = 0x000000 >+ balance = 0.000000 >+ reserved = 0x0000 >+ [dinf: Data Information Box] >+ position = 424 >+ size = 36 >+ [dref: Data Reference Box] >+ position = 432 >+ size = 28 >+ version = 0 >+ flags = 0x000000 >+ entry_count = 1 >+ [url : Data Entry Url Box] >+ position = 448 >+ size = 12 >+ version = 0 >+ flags = 0x000001 >+ location = in the same file >+ [stbl: Sample Table Box] >+ position = 460 >+ size = 321 >+ [stsd: Sample Description Box] >+ position = 468 >+ size = 79 >+ version = 0 >+ flags = 0x000000 >+ entry_count = 1 >+ [Opus: Audio Description] >+ position = 484 >+ size = 63 >+ reserved = 0x000000000000 >+ data_reference_index = 1 >+ reserved = 0x0000 >+ reserved = 0x0000 >+ reserved = 0x00000000 >+ channelcount = 6 >+ samplesize = 16 >+ pre_defined = 0 >+ reserved = 0 >+ samplerate = 48000.000000 >+ [dOps: Opus Specific Box] >+ position = 520 >+ size = 27 >+ Version = 0 >+ OutputChannelCount = 6 >+ PreSkip = 312 >+ InputSampleRate = 48000 >+ OutputGain = 0 >+ ChannelMappingFamily = 1 >+ StreamCount = 4 >+ CoupledCount = 2 >+ ChannelMapping >+ 0 -> 0: front left >+ 1 -> 4: fron center >+ 2 -> 1: front right >+ 3 -> 2: side left >+ 4 -> 3: side right >+ 5 -> 5: rear center >+ [stts: Decoding Time to Sample Box] >+ position = 547 >+ size = 24 >+ version = 0 >+ flags = 0x000000 >+ entry_count = 1 >+ entry[0] >+ sample_count = 18 >+ sample_delta = 1920 >+ [stsc: Sample To Chunk Box] >+ position = 571 >+ size = 40 >+ version = 0 >+ flags = 0x000000 >+ entry_count = 2 >+ entry[0] >+ first_chunk = 1 >+ samples_per_chunk = 13 >+ sample_description_index = 1 >+ entry[1] >+ first_chunk = 2 >+ samples_per_chunk = 5 >+ sample_description_index = 1 >+ [stsz: Sample Size Box] >+ position = 611 >+ size = 92 >+ version = 0 >+ flags = 0x000000 >+ sample_size = 0 (variable) >+ sample_count = 18 >+ entry_size[0] = 977 >+ entry_size[1] = 938 >+ entry_size[2] = 939 >+ entry_size[3] = 938 >+ entry_size[4] = 934 >+ entry_size[5] = 945 >+ entry_size[6] = 948 >+ entry_size[7] = 956 >+ entry_size[8] = 955 >+ entry_size[9] = 930 >+ entry_size[10] = 933 >+ entry_size[11] = 934 >+ entry_size[12] = 972 >+ entry_size[13] = 977 >+ entry_size[14] = 958 >+ entry_size[15] = 949 >+ entry_size[16] = 962 >+ entry_size[17] = 848 >+ [stco: Chunk Offset Box] >+ position = 703 >+ size = 24 >+ version = 0 >+ flags = 0x000000 >+ entry_count = 2 >+ chunk_offset[0] = 797 >+ chunk_offset[1] = 13096 >+ [sgpd: Sample Group Description Box] >+ position = 727 >+ size = 26 >+ version = 1 >+ flags = 0x000000 >+ grouping_type = roll >+ default_length = 2 (constant) >+ entry_count = 1 >+ roll_distance[0] = -2 >+ [sbgp: Sample to Group Box] >+ position = 753 >+ size = 28 >+ version = 0 >+ flags = 0x000000 >+ grouping_type = roll >+ entry_count = 1 >+ entry[0] >+ sample_count = 18 >+ group_description_index = 1 >+ [free: Free Space Box] >+ position = 781 >+ size = 8 >+ [mdat: Media Data Box] >+ position = 789 >+ size = 17001 >+<a name="5"></a> >+5 Authors' Address >+ Yusuke Nakamura >+ Email: muken.the.vfrmaniac |at| gmail.com >+ </div> >+ </body> >+</html> >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/opus_update.patch b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/opus_update.patch >new file mode 100644 >index 0000000000000000000000000000000000000000..11f066c7022ff6f896e31c8600a3d6f06f0f4182 >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/opus_update.patch >@@ -0,0 +1,244 @@ >+diff --git a/celt/bands.c b/celt/bands.c >+index 6962587..32e1de6 100644 >+--- a/celt/bands.c >++++ b/celt/bands.c >+@@ -1234,9 +1234,23 @@ void quant_all_bands(int encode, const CELTMode *m, int start, int end, >+ b = 0; >+ } >+ >+- if (resynth && M*eBands[i]-N >= M*eBands[start] && (update_lowband || lowband_offset==0)) >++ if (resynth && (M*eBands[i]-N >= M*eBands[start] || i==start+1) && (update_lowband || lowband_offset==0)) >+ lowband_offset = i; >+ >++ if (i == start+1) >++ { >++ int n1, n2; >++ int offset; >++ n1 = M*(eBands[start+1]-eBands[start]); >++ n2 = M*(eBands[start+2]-eBands[start+1]); >++ offset = M*eBands[start]; >++ /* Duplicate enough of the first band folding data to be able to fold the second band. >++ Copies no data for CELT-only mode. */ >++ OPUS_COPY(&norm[offset+n1], &norm[offset+2*n1 - n2], n2-n1); >++ if (C==2) >++ OPUS_COPY(&norm2[offset+n1], &norm2[offset+2*n1 - n2], n2-n1); >++ } >++ >+ tf_change = tf_res[i]; >+ if (i>=m->effEBands) >+ { >+@@ -1257,7 +1271,7 @@ void quant_all_bands(int encode, const CELTMode *m, int start, int end, >+ fold_start = lowband_offset; >+ while(M*eBands[--fold_start] > effective_lowband); >+ fold_end = lowband_offset-1; >+- while(M*eBands[++fold_end] < effective_lowband+N); >++ while(++fold_end < i && M*eBands[fold_end] < effective_lowband+N); >+ x_cm = y_cm = 0; >+ fold_i = fold_start; do { >+ x_cm |= collapse_masks[fold_i*C+0]; >+diff --git a/celt/quant_bands.c b/celt/quant_bands.c >+index e5ed9ef..82fb823 100644 >+--- a/celt/quant_bands.c >++++ b/celt/quant_bands.c >+@@ -552,6 +552,7 @@ void log2Amp(const CELTMode *m, int start, int end, >+ { >+ opus_val16 lg = ADD16(oldEBands[i+c*m->nbEBands], >+ SHL16((opus_val16)eMeans[i],6)); >++ lg = MIN32(QCONST32(32.f, 16), lg); >+ eBands[i+c*m->nbEBands] = PSHR32(celt_exp2(lg),4); >+ } >+ for (;i<m->nbEBands;i++) >+diff --git a/silk/LPC_inv_pred_gain.c b/silk/LPC_inv_pred_gain.c >+index 60c439b..6c301da 100644 >+--- a/silk/LPC_inv_pred_gain.c >++++ b/silk/LPC_inv_pred_gain.c >+@@ -84,8 +84,13 @@ static opus_int32 LPC_inverse_pred_gain_QA( /* O Returns inver >+ >+ /* Update AR coefficient */ >+ for( n = 0; n < k; n++ ) { >+- tmp_QA = Aold_QA[ n ] - MUL32_FRAC_Q( Aold_QA[ k - n - 1 ], rc_Q31, 31 ); >+- Anew_QA[ n ] = MUL32_FRAC_Q( tmp_QA, rc_mult2 , mult2Q ); >++ opus_int64 tmp64; >++ tmp_QA = silk_SUB_SAT32( Aold_QA[ n ], MUL32_FRAC_Q( Aold_QA[ k - n - 1 ], rc_Q31, 31 ) ); >++ tmp64 = silk_RSHIFT_ROUND64( silk_SMULL( tmp_QA, rc_mult2 ), mult2Q); >++ if( tmp64 > silk_int32_MAX || tmp64 < silk_int32_MIN ) { >++ return 0; >++ } >++ Anew_QA[ n ] = ( opus_int32 )tmp64; >+ } >+ } >+ >+diff --git a/silk/NLSF_stabilize.c b/silk/NLSF_stabilize.c >+index 979aaba..2ef2398 100644 >+--- a/silk/NLSF_stabilize.c >++++ b/silk/NLSF_stabilize.c >+@@ -134,7 +134,7 @@ void silk_NLSF_stabilize( >+ >+ /* Keep delta_min distance between the NLSFs */ >+ for( i = 1; i < L; i++ ) >+- NLSF_Q15[i] = silk_max_int( NLSF_Q15[i], NLSF_Q15[i-1] + NDeltaMin_Q15[i] ); >++ NLSF_Q15[i] = silk_max_int( NLSF_Q15[i], silk_ADD_SAT16( NLSF_Q15[i-1], NDeltaMin_Q15[i] ) ); >+ >+ /* Last NLSF should be no higher than 1 - NDeltaMin[L] */ >+ NLSF_Q15[L-1] = silk_min_int( NLSF_Q15[L-1], (1<<15) - NDeltaMin_Q15[L] ); >+diff --git a/silk/dec_API.c b/silk/dec_API.c >+index efd7918..21bb7e0 100644 >+--- a/silk/dec_API.c >++++ b/silk/dec_API.c >+@@ -72,6 +72,9 @@ opus_int silk_InitDecoder( /* O Returns error co >+ for( n = 0; n < DECODER_NUM_CHANNELS; n++ ) { >+ ret = silk_init_decoder( &channel_state[ n ] ); >+ } >++ silk_memset(&((silk_decoder *)decState)->sStereo, 0, sizeof(((silk_decoder *)decState)->sStereo)); >++ /* Not strictly needed, but it's cleaner that way */ >++ ((silk_decoder *)decState)->prev_decode_only_middle = 0; >+ >+ return ret; >+ } >+diff --git a/silk/resampler_private_IIR_FIR.c b/silk/resampler_private_IIR_FIR.c >+index dbd6d9a..91a43aa 100644 >+--- a/silk/resampler_private_IIR_FIR.c >++++ b/silk/resampler_private_IIR_FIR.c >+@@ -75,10 +75,10 @@ void silk_resampler_private_IIR_FIR( >+ silk_resampler_state_struct *S = (silk_resampler_state_struct *)SS; >+ opus_int32 nSamplesIn; >+ opus_int32 max_index_Q16, index_increment_Q16; >+- opus_int16 buf[ RESAMPLER_MAX_BATCH_SIZE_IN + RESAMPLER_ORDER_FIR_12 ]; >++ opus_int16 buf[ 2*RESAMPLER_MAX_BATCH_SIZE_IN + RESAMPLER_ORDER_FIR_12 ]; >+ >+ /* Copy buffered samples to start of buffer */ >+- silk_memcpy( buf, S->sFIR, RESAMPLER_ORDER_FIR_12 * sizeof( opus_int32 ) ); >++ silk_memcpy( buf, S->sFIR, RESAMPLER_ORDER_FIR_12 * sizeof( opus_int16 ) ); >+ >+ /* Iterate over blocks of frameSizeIn input samples */ >+ index_increment_Q16 = S->invRatio_Q16; >+@@ -95,13 +95,13 @@ void silk_resampler_private_IIR_FIR( >+ >+ if( inLen > 0 ) { >+ /* More iterations to do; copy last part of filtered signal to beginning of buffer */ >+- silk_memcpy( buf, &buf[ nSamplesIn << 1 ], RESAMPLER_ORDER_FIR_12 * sizeof( opus_int32 ) ); >++ silk_memmove( buf, &buf[ nSamplesIn << 1 ], RESAMPLER_ORDER_FIR_12 * sizeof( opus_int16 ) ); >+ } else { >+ break; >+ } >+ } >+ >+ /* Copy last part of filtered signal to the state for the next call */ >+- silk_memcpy( S->sFIR, &buf[ nSamplesIn << 1 ], RESAMPLER_ORDER_FIR_12 * sizeof( opus_int32 ) ); >++ silk_memcpy( S->sFIR, &buf[ nSamplesIn << 1 ], RESAMPLER_ORDER_FIR_12 * sizeof( opus_int16 ) ); >+ } >+ >+diff --git a/src/opus_decoder.c b/src/opus_decoder.c >+index 0cc56f8..8a30fbc 100644 >+--- a/src/opus_decoder.c >++++ b/src/opus_decoder.c >+@@ -595,16 +595,14 @@ static int opus_packet_parse_impl(const unsigned char *data, int len, >+ /* Padding flag is bit 6 */ >+ if (ch&0x40) >+ { >+- int padding=0; >+ int p; >+ do { >+ if (len<=0) >+ return OPUS_INVALID_PACKET; >+ p = *data++; >+ len--; >+- padding += p==255 ? 254: p; >++ len -= p==255 ? 254: p; >+ } while (p==255); >+- len -= padding; >+ } >+ if (len<0) >+ return OPUS_INVALID_PACKET; >+diff --git a/run_vectors.sh b/run_vectors.sh >+index 7cd23ed..4841b0a 100755 >+--- a/run_vectors.sh >++++ b/run_vectors.sh >+@@ -1,3 +1,5 @@ >++#!/bin/sh >++# >+ # Copyright (c) 2011-2012 IETF Trust, Jean-Marc Valin. All rights reserved. >+ # >+ # This file is extracted from RFC6716. Please see that RFC for additional >+@@ -31,10 +33,8 @@ >+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS >+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+ >+-#!/bin/sh >+- >+-rm logs_mono.txt >+-rm logs_stereo.txt >++rm -f logs_mono.txt logs_mono2.txt >++rm -f logs_stereo.txt logs_stereo2.txt >+ >+ if [ "$#" -ne "3" ]; then >+ echo "usage: run_vectors.sh <exec path> <vector path> <rate>" >+@@ -45,18 +45,23 @@ CMD_PATH=$1 >+ VECTOR_PATH=$2 >+ RATE=$3 >+ >+-OPUS_DEMO=$CMD_PATH/opus_demo >+-OPUS_COMPARE=$CMD_PATH/opus_compare >++: ${OPUS_DEMO:=$CMD_PATH/opus_demo} >++: ${OPUS_COMPARE:=$CMD_PATH/opus_compare} >+ >+ if [ -d $VECTOR_PATH ]; then >+ echo Test vectors found in $VECTOR_PATH >+ else >+ echo No test vectors found >+- #Don't make the test fail here because the test vectors will be >+- #distributed separately >++ #Don't make the test fail here because the test vectors >++ #will be distributed separately >+ exit 0 >+ fi >+ >++if [ ! -x $OPUS_COMPARE ]; then >++ echo ERROR: Compare program not found: $OPUS_COMPARE >++ exit 1 >++fi >++ >+ if [ -x $OPUS_DEMO ]; then >+ echo Decoding with $OPUS_DEMO >+ else >+@@ -82,9 +87,11 @@ do >+ echo ERROR: decoding failed >+ exit 1 >+ fi >+- $OPUS_COMPARE -r $RATE $VECTOR_PATH/testvector$file.dec tmp.out >> logs_mono.txt 2>&1 >++ $OPUS_COMPARE -r $RATE $VECTOR_PATH/testvector${file}.dec tmp.out >> logs_mono.txt 2>&1 >+ float_ret=$? >+- if [ "$float_ret" -eq "0" ]; then >++ $OPUS_COMPARE -r $RATE $VECTOR_PATH/testvector${file}m.dec tmp.out >> logs_mono2.txt 2>&1 >++ float_ret2=$? >++ if [ "$float_ret" -eq "0" ] || [ "$float_ret2" -eq "0" ]; then >+ echo output matches reference >+ else >+ echo ERROR: output does not match reference >+@@ -111,9 +118,11 @@ do >+ echo ERROR: decoding failed >+ exit 1 >+ fi >+- $OPUS_COMPARE -s -r $RATE $VECTOR_PATH/testvector$file.dec tmp.out >> logs_stereo.txt 2>&1 >++ $OPUS_COMPARE -s -r $RATE $VECTOR_PATH/testvector${file}.dec tmp.out >> logs_stereo.txt 2>&1 >+ float_ret=$? >+- if [ "$float_ret" -eq "0" ]; then >++ $OPUS_COMPARE -s -r $RATE $VECTOR_PATH/testvector${file}m.dec tmp.out >> logs_stereo2.txt 2>&1 >++ float_ret2=$? >++ if [ "$float_ret" -eq "0" ] || [ "$float_ret2" -eq "0" ]; then >+ echo output matches reference >+ else >+ echo ERROR: output does not match reference >+@@ -125,5 +134,10 @@ done >+ >+ >+ echo All tests have passed successfully >+-grep quality logs_mono.txt | awk '{sum+=$4}END{print "Average mono quality is", sum/NR, "%"}' >+-grep quality logs_stereo.txt | awk '{sum+=$4}END{print "Average stereo quality is", sum/NR, "%"}' >++mono1=`grep quality logs_mono.txt | awk '{sum+=$4}END{if (NR == 12) sum /= 12; else sum = 0; print sum}'` >++mono2=`grep quality logs_mono2.txt | awk '{sum+=$4}END{if (NR == 12) sum /= 12; else sum = 0; print sum}'` >++echo $mono1 $mono2 | awk '{if ($2 > $1) $1 = $2; print "Average mono quality is", $1, "%"}' >++ >++stereo1=`grep quality logs_stereo.txt | awk '{sum+=$4}END{if (NR == 12) sum /= 12; else sum = 0; print sum}'` >++stereo2=`grep quality logs_stereo2.txt | awk '{sum+=$4}END{if (NR == 12) sum /= 12; else sum = 0; print sum}'` >++echo $stereo1 $stereo2 | awk '{if ($2 > $1) $1 = $2; print "Average stereo quality is", $1, "%"}' >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/release.txt b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/release.txt >new file mode 100644 >index 0000000000000000000000000000000000000000..6d3ffa23901c04d2fb9886f52d4cb74ca427b6d1 >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/release.txt >@@ -0,0 +1,43 @@ >+= Release checklist = >+ >+== Source release == >+ >+- Check for uncommitted changes to master. >+- Update OPUS_LT_* API versioning in configure.ac. >+- Tag the release commit with 'git tag -s vN.M'. >+ - Include release notes in the tag annotation. >+- Verify 'make distcheck' produces a tarball with >+ the desired name. >+- Push tag to public repo. >+- Upload source package 'opus-${version}.tar.gz' >+ - Add to https://svn.xiph.org/releases/opus/ >+ - Update checksum files >+ - svn commit >+ - Copy to archive.mozilla.org/pub/opus/ >+ - Update checksum files there as well. >+- Add release notes to https://git.xiph.org/opus-website.git >+- Update links and checksums on the downloads page. >+- Add a copy of the documentation to <https://www.opus-codec.org/docs/> >+ and update the links. >+- Update /topic in #opus IRC channel. >+ >+Releases are commited to https://svn.xiph.org/releases/opus/ >+which propagates to downloads.xiph.org, and copied manually >+to https://archive.mozilla.org/pub/opus/ >+ >+Website updates are committed to https://git.xiph.org/opus-website.git >+which propagates to https://opus-codec.org/ >+ >+== Binary release == >+ >+We usually build opus-tools binaries for MacOS and Windows. >+ >+Binary releases are copied manually to >+https://archive.mozilla.org/pub/opus/win32/ >+ >+For Mac, submit a pull request to homebrew. >+ >+== Website updates == >+ >+For major releases, recreate the files on https://opus-codec.org/examples/ >+with the next encoder. >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/include/opus_defines.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/include/opus_defines.h >index 315412dd1d2383cf9009690d3aa102aaa30aa813..33c5acdb3393501c9dd628978c78fd226459dc55 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/include/opus_defines.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/include/opus_defines.h >@@ -165,8 +165,9 @@ extern "C" { > #define OPUS_GET_EXPERT_FRAME_DURATION_REQUEST 4041 > #define OPUS_SET_PREDICTION_DISABLED_REQUEST 4042 > #define OPUS_GET_PREDICTION_DISABLED_REQUEST 4043 >- > /* Don't use 4045, it's already taken by OPUS_GET_GAIN_REQUEST */ >+#define OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST 4046 >+#define OPUS_GET_PHASE_INVERSION_DISABLED_REQUEST 4047 > > /* Macros to trigger compilation errors when the wrong types are provided to a CTL */ > #define __opus_check_int(x) (((void)((x) == (opus_int32)0)), (opus_int32)(x)) >@@ -208,6 +209,9 @@ extern "C" { > #define OPUS_FRAMESIZE_20_MS 5004 /**< Use 20 ms frames */ > #define OPUS_FRAMESIZE_40_MS 5005 /**< Use 40 ms frames */ > #define OPUS_FRAMESIZE_60_MS 5006 /**< Use 60 ms frames */ >+#define OPUS_FRAMESIZE_80_MS 5007 /**< Use 80 ms frames */ >+#define OPUS_FRAMESIZE_100_MS 5008 /**< Use 100 ms frames */ >+#define OPUS_FRAMESIZE_120_MS 5009 /**< Use 120 ms frames */ > > /**@}*/ > >@@ -566,7 +570,9 @@ extern "C" { > * <dt>OPUS_FRAMESIZE_20_MS</dt><dd>Use 20 ms frames.</dd> > * <dt>OPUS_FRAMESIZE_40_MS</dt><dd>Use 40 ms frames.</dd> > * <dt>OPUS_FRAMESIZE_60_MS</dt><dd>Use 60 ms frames.</dd> >- * <dt>OPUS_FRAMESIZE_VARIABLE</dt><dd>Optimize the frame size dynamically.</dd> >+ * <dt>OPUS_FRAMESIZE_80_MS</dt><dd>Use 80 ms frames.</dd> >+ * <dt>OPUS_FRAMESIZE_100_MS</dt><dd>Use 100 ms frames.</dd> >+ * <dt>OPUS_FRAMESIZE_120_MS</dt><dd>Use 120 ms frames.</dd> > * </dl> > * @hideinitializer */ > #define OPUS_SET_EXPERT_FRAME_DURATION(x) OPUS_SET_EXPERT_FRAME_DURATION_REQUEST, __opus_check_int(x) >@@ -581,7 +587,9 @@ extern "C" { > * <dt>OPUS_FRAMESIZE_20_MS</dt><dd>Use 20 ms frames.</dd> > * <dt>OPUS_FRAMESIZE_40_MS</dt><dd>Use 40 ms frames.</dd> > * <dt>OPUS_FRAMESIZE_60_MS</dt><dd>Use 60 ms frames.</dd> >- * <dt>OPUS_FRAMESIZE_VARIABLE</dt><dd>Optimize the frame size dynamically.</dd> >+ * <dt>OPUS_FRAMESIZE_80_MS</dt><dd>Use 80 ms frames.</dd> >+ * <dt>OPUS_FRAMESIZE_100_MS</dt><dd>Use 100 ms frames.</dd> >+ * <dt>OPUS_FRAMESIZE_120_MS</dt><dd>Use 120 ms frames.</dd> > * </dl> > * @hideinitializer */ > #define OPUS_GET_EXPERT_FRAME_DURATION(x) OPUS_GET_EXPERT_FRAME_DURATION_REQUEST, __opus_check_int_ptr(x) >@@ -681,6 +689,30 @@ extern "C" { > */ > #define OPUS_GET_SAMPLE_RATE(x) OPUS_GET_SAMPLE_RATE_REQUEST, __opus_check_int_ptr(x) > >+/** If set to 1, disables the use of phase inversion for intensity stereo, >+ * improving the quality of mono downmixes, but slightly reducing normal >+ * stereo quality. Disabling phase inversion in the decoder does not comply >+ * with RFC 6716, although it does not cause any interoperability issue and >+ * is expected to become part of the Opus standard once RFC 6716 is updated >+ * by draft-ietf-codec-opus-update. >+ * @see OPUS_GET_PHASE_INVERSION_DISABLED >+ * @param[in] x <tt>opus_int32</tt>: Allowed values: >+ * <dl> >+ * <dt>0</dt><dd>Enable phase inversion (default).</dd> >+ * <dt>1</dt><dd>Disable phase inversion.</dd> >+ * </dl> >+ * @hideinitializer */ >+#define OPUS_SET_PHASE_INVERSION_DISABLED(x) OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST, __opus_check_int(x) >+/** Gets the encoder's configured phase inversion status. >+ * @see OPUS_SET_PHASE_INVERSION_DISABLED >+ * @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values: >+ * <dl> >+ * <dt>0</dt><dd>Stereo phase inversion enabled (default).</dd> >+ * <dt>1</dt><dd>Stereo phase inversion disabled.</dd> >+ * </dl> >+ * @hideinitializer */ >+#define OPUS_GET_PHASE_INVERSION_DISABLED(x) OPUS_GET_PHASE_INVERSION_DISABLED_REQUEST, __opus_check_int_ptr(x) >+ > /**@}*/ > > /** @defgroup opus_decoderctls Decoder related CTLs >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/include/opus_multistream.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/include/opus_multistream.h >index 3622e009fb53052ddb1375cf370eb85eb02970e7..babcee6905bf9f70d922eb903d28a9151f053505 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/include/opus_multistream.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/include/opus_multistream.h >@@ -273,7 +273,7 @@ OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusMSEncoder *opus_multistream_surround_enc > unsigned char *mapping, > int application, > int *error >-) OPUS_ARG_NONNULL(5); >+) OPUS_ARG_NONNULL(4) OPUS_ARG_NONNULL(5) OPUS_ARG_NONNULL(6); > > /** Initialize a previously allocated multistream encoder state. > * The memory pointed to by \a st must be at least the size returned by >@@ -342,7 +342,7 @@ OPUS_EXPORT int opus_multistream_surround_encoder_init( > int *coupled_streams, > unsigned char *mapping, > int application >-) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(6); >+) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(5) OPUS_ARG_NONNULL(6) OPUS_ARG_NONNULL(7); > > /** Encodes a multistream Opus frame. > * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state. >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/include/opus_types.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/include/opus_types.h >index b28e03aea202d97fe71cf58afc90dac2084144a9..7cf675580ffb0ad9ba7b040a5c03eb2828910486 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/include/opus_types.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/include/opus_types.h >@@ -33,14 +33,29 @@ > #ifndef OPUS_TYPES_H > #define OPUS_TYPES_H > >+#define opus_int int /* used for counters etc; at least 16 bits */ >+#define opus_int64 long long >+#define opus_int8 signed char >+ >+#define opus_uint unsigned int /* used for counters etc; at least 16 bits */ >+#define opus_uint64 unsigned long long >+#define opus_uint8 unsigned char >+ > /* Use the real stdint.h if it's there (taken from Paul Hsieh's pstdint.h) */ >-#if (defined(__STDC__) && __STDC__ && __STDC_VERSION__ >= 199901L) || (defined(__GNUC__) && (defined(_STDINT_H) || defined(_STDINT_H_)) || defined (HAVE_STDINT_H)) >+#if (defined(__STDC__) && __STDC__ && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || (defined(__GNUC__) && (defined(_STDINT_H) || defined(_STDINT_H_)) || defined (HAVE_STDINT_H)) > #include <stdint.h> >- >+# undef opus_int64 >+# undef opus_int8 >+# undef opus_uint64 >+# undef opus_uint8 >+ typedef int8_t opus_int8; >+ typedef uint8_t opus_uint8; > typedef int16_t opus_int16; > typedef uint16_t opus_uint16; > typedef int32_t opus_int32; > typedef uint32_t opus_uint32; >+ typedef int64_t opus_int64; >+ typedef uint64_t opus_uint64; > #elif defined(_WIN32) > > # if defined(__CYGWIN__) >@@ -148,12 +163,4 @@ > > #endif > >-#define opus_int int /* used for counters etc; at least 16 bits */ >-#define opus_int64 long long >-#define opus_int8 signed char >- >-#define opus_uint unsigned int /* used for counters etc; at least 16 bits */ >-#define opus_uint64 unsigned long long >-#define opus_uint8 unsigned char >- > #endif /* OPUS_TYPES_H */ >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/releases.sha2 b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/releases.sha2 >new file mode 100644 >index 0000000000000000000000000000000000000000..b1b32c005518ffd44ad50597225f78d39b556eb9 >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/releases.sha2 >@@ -0,0 +1,63 @@ >+b2f75c4ac5ab837845eb028413fae2a28754bfb0a6d76416e2af1441ef447649 opus-0.9.0.tar.gz >+4e379a98ba95bbbfe9087ef10fdd05c8ac9060b6d695f587ea82a7b43a0df4fe opus-0.9.10.tar.gz >+b1cad6846a8f819a141009fe3f8f10c946e8eff7e9c2339cd517bb136cc59eae opus-0.9.14.tar.gz >+206221afc47b87496588013bd4523e1e9f556336c0813f4372773fc536dd4293 opus-0.9.1.tar.gz >+6e85c1b57e1d7b7dfe2928bf92586b96b73a9067e054ede45bd8e6d24bd30582 opus-0.9.2.tar.gz >+d916e34c18a396eb7dffc47af754f441af52a290b761e20db9aedb65928c699e opus-0.9.3.tar.gz >+53801066fa97329768e7b871fd1495740269ec46802e1c9051aa7e78c6edee5b opus-0.9.5.tar.gz >+3bfaeb25f4b4a625a0bc994d6fc6f6776a05193f60099e0a99f7530c6b256309 opus-0.9.6.tar.gz >+1b69772c31c5cbaa43d1dfa5b1c495fc29712e8e0ff69d6f8ad46459e5c6715f opus-0.9.7.tar.gz >+4aa30d2e0652ffb4a7a22cc8a29c4ce78267626f560a2d9213b1d2d4e618cf36 opus-0.9.8.tar.gz >+2f62359f09151fa3b242040dc9b4c5b6bda15557c5daea59c8420f1a2ff328b7 opus-0.9.9.tar.gz >+43bcea51afa531f32a6a5fdd9cba4bd496993e26a141217db3cccce6caa7cd74 opus-1.0.0-rc.tar.gz >+9250fcc74472d45c1e14745542ec9c8d09982538aefed56962495614be3e0d2d opus-1.0.0.tar.gz >+76bc0a31502a51dae9ab737b4db043b9ecfcd0b5861f0bfda41b662bd5b92227 opus-1.0.1-rc2.tar.gz >+3de8d6809dac38971ebb305532d4ea532519d3bed08985f25d6c557f9ce5e8ff opus-1.0.1-rc3.tar.gz >+8044397a6365a07117b08cbe8f9818bf7c93746908806ba74a2917187bbdda5f opus-1.0.1-rc.tar.gz >+80fa5c3caf2ac0fd68f8a22cce1564fc46b368c773a17554887d0066fe1841ef opus-1.0.1.tar.gz >+da615edbee5d019c1833071d69a4782c19f178cf9ca1401375036ecef25cd78a opus-1.0.2.tar.gz >+191a089c92dbc403de6980463dd3604b65beb12d283c607e246c8076363cb49c opus-1.0.3.tar.gz >+a8d40efe87f6c3e76725391457d46277878c7a816ae1642843261463133fa5c8 opus-1.1-alpha.tar.gz >+ec1784287f385aef994b64734aaecae04860e61aa50fc6eef6643fa7e40dd193 opus-1.1-beta.tar.gz >+8aa16360f59a94d3e38f38f28d24039f7663179682cbae82aa42f1dd9e52e6ed opus-1.1-rc.tar.gz >+ebc87a086d4fe677c5e42d56888b1fd25af858e4179eae4f8656270410dffac3 opus-1.1-rc2.tar.gz >+cbfd09c58cc10a4d3fcb727ad5d46d7bb549f8185ac922ee28b4581b52a7bee9 opus-1.1-rc3.tar.gz >+b9727015a58affcf3db527322bf8c4d2fcf39f5f6b8f15dbceca20206cbe1d95 opus-1.1.tar.gz >+0c668639dcd16b14709fc9dc49e6686606f5a256f2eaa1ebaa2f39a66f8626cd opus-1.1.1-beta.tar.gz >+66f2a5877c8803dc9a5a44b4f3d0bdc8f06bd066324222d144eb255612b68152 opus-1.1.1-rc.tar.gz >+9b84ff56bd7720d5554103c557664efac2b8b18acc4bbcc234cb881ab9a3371e opus-1.1.1.tar.gz >+0e290078e31211baa7b5886bcc8ab6bc048b9fc83882532da4a1a45e58e907fd opus-1.1.2.tar.gz >+58b6fe802e7e30182e95d0cde890c0ace40b6f125cffc50635f0ad2eef69b633 opus-1.1.3.tar.gz >+9122b6b380081dd2665189f97bfd777f04f92dc3ab6698eea1dbb27ad59d8692 opus-1.1.4.tar.gz >+eb84981ca0f40a3e5d5e58d2e8582cb2fee05a022825a6dfe14d14b04eb563e4 opus-1.1.5.tar.gz >+654a9bebb73266271a28edcfff431e4cfd9bfcde71f42849a0cdd73bece803a7 opus-1.2-alpha.tar.gz >+c0e90507259cf21ce7b2c82fb9ac55367d8543dae91cc3d4d2c59afd37f44023 opus-1.2-alpha2.tar.gz >+291e979a8a2fb679ed35a5dff5d761a9d9a5e22586fd07934ed94461e2636c7a opus-1.2-beta.tar.gz >+85343fdaed96529d94c1e1f3a210fa51240d04ca62fa01e97ef02f88020c2ce9 opus-1.2-rc1.tar.gz >+77db45a87b51578fbc49555ef1b10926179861d854eb2613207dc79d9ec0a9a9 opus-1.2.tar.gz >+cfafd339ccd9c5ef8d6ab15d7e1a412c054bf4cb4ecbbbcc78c12ef2def70732 opus-1.2.1.tar.gz >+94ac78ca4f74c4e43bc9fe4ec1ad0aa36f38ab90f45b0727c40dd1e96096e767 opus_testvectors-draft11.tar.gz >+94ac78ca4f74c4e43bc9fe4ec1ad0aa36f38ab90f45b0727c40dd1e96096e767 opus_testvectors.tar.gz >+5d2b99757bcb628bab2611f3ed27af6f35276ce3abc96c0ed4399d6c6463dda5 opus-tools-0.1.2.tar.gz >+008317297d6ce84f84992abf8cc948a048a4fa135e1d1caf429fafde8965a792 opus-tools-0.1.3.tar.gz >+de80485c5afa1fd83c0e16a0dd4860470c872997a7dd0a58e99b2ee8a93e5168 opus-tools-0.1.4.tar.gz >+76678d0eb7a9b3d793bd0243f9ced9ab0ecdab263f5232ed940c8f5795fb0405 opus-tools-0.1.5.tar.gz >+cc86dbc2a4d76da7e1ed9afee85448c8f798c465a5412233f178783220f3a2c1 opus-tools-0.1.6.tar.gz >+e0f08d301555dffc417604269b5a85d2bd197f259c7d6c957f370ffd33d6d9cd opus-tools-0.1.7.tar.gz >+e4e188579ea1c4e4d5066460d4a7214a7eafe3539e9a4466fdc98af41ba4a2f6 opus-tools-0.1.8.tar.gz >+b1873dd78c7fbc98cf65d6e10cfddb5c2c03b3af93f922139a2104baedb4643a opus-tools-0.1.9.tar.gz >+a2357532d19471b70666e0e0ec17d514246d8b3cb2eb168f68bb0f6fd372b28c opus-tools-0.1.10.tar.gz >+bd6d14e8897a2f80065ef34a516c70e74f8e00060abdbc238e79e5f99bca3e96 libopusenc-0.1.tar.gz >+8071b968475c1a17f54b6840d6de9d9ee20f930e827b0401abe3c4cf4f3bf30a opusfile-0.1.tar.gz >+b4a678b3b6c4adfb6aff1f67ef658becfe146ea7c7ff228e99543762171557f9 opusfile-0.2.tar.gz >+4248927f2c4e316ea5b84fb02bd100bfec8fa4624a6910d77f0af7f0c6cb8baa opusfile-0.3.tar.gz >+9836ea11706c44f36de92c4c9b1248e03a4c521e7fb2cff18a0cb4f8b0e79140 opusfile-0.4.tar.gz >+f187906b1b35f7f0d7de6a759b4aab512a9279d23adb35d8009e7e33bd6a922a opusfile-0.4.zip >+2ce52d006aeeec9f10260dbe3073c4636954a1ab19c82b8baafefe0180aa4a39 opusfile-0.5.tar.gz >+b940d62beb15b5974764574b9f265481fe5b6ee16902fb705727546caf956261 opusfile-0.5.zip >+2428717b356e139f18ed2fdb5ad990b5654a238907a0058200b39c46a7d03ea6 opusfile-0.6.tar.gz >+753339225193df605372944889023b9b3c5378d672e8784d69fa241cd465278c opusfile-0.6.zip >+9e2bed13bc729058591a0f1cab2505e8cfd8e7ac460bf10a78bcc3b125e7c301 opusfile-0.7.tar.gz >+346967d7989bb83b05949483b76bd0f69a12c59bd8b4457e864902b52bb0ac34 opusfile-0.7.zip >+2c231ed3cfaa1b3173f52d740e5bbd77d51b9dfecb87014b404917fba4b855a4 opusfile-0.8.tar.gz >+89dff4342c3b789574cbea5c57f11b96d4ebe4d28ab90248c1783ea569b1e9e3 opusfile-0.8.zip >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/A2NLSF.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/A2NLSF.c >index b6e9e5ffccaa05995dfdbfe600166865d899013e..b487686ff9c6d129c0656fb1095de8a289fc4dba 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/A2NLSF.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/A2NLSF.c >@@ -40,7 +40,7 @@ POSSIBILITY OF SUCH DAMAGE. > > /* Number of binary divisions, when not in low complexity mode */ > #define BIN_DIV_STEPS_A2NLSF_FIX 3 /* must be no higher than 16 - log2( LSF_COS_TAB_SZ_FIX ) */ >-#define MAX_ITERATIONS_A2NLSF_FIX 30 >+#define MAX_ITERATIONS_A2NLSF_FIX 16 > > /* Helper function for A2NLSF(..) */ > /* Transforms polynomials from cos(n*f) to cos(f)^n */ >@@ -130,7 +130,7 @@ void silk_A2NLSF( > const opus_int d /* I Filter order (must be even) */ > ) > { >- opus_int i, k, m, dd, root_ix, ffrac; >+ opus_int i, k, m, dd, root_ix, ffrac; > opus_int32 xlo, xhi, xmid; > opus_int32 ylo, yhi, ymid, thr; > opus_int32 nom, den; >@@ -239,13 +239,13 @@ void silk_A2NLSF( > /* Set NLSFs to white spectrum and exit */ > NLSF[ 0 ] = (opus_int16)silk_DIV32_16( 1 << 15, d + 1 ); > for( k = 1; k < d; k++ ) { >- NLSF[ k ] = (opus_int16)silk_SMULBB( k + 1, NLSF[ 0 ] ); >+ NLSF[ k ] = (opus_int16)silk_ADD16( NLSF[ k-1 ], NLSF[ 0 ] ); > } > return; > } > > /* Error: Apply progressively more bandwidth expansion and run again */ >- silk_bwexpander_32( a_Q16, d, 65536 - silk_SMULBB( 10 + i, i ) ); /* 10_Q16 = 0.00015*/ >+ silk_bwexpander_32( a_Q16, d, 65536 - silk_LSHIFT( 1, i ) ); > > silk_A2NLSF_init( a_Q16, P, Q, dd ); > p = P; /* Pointer to polynomial */ >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/API.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/API.h >index 0131acbb08fb07a8dd0d15502758ded5a1bc7fa6..4d90ff9aa3ecd2b16df4020b510c88a725b13649 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/API.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/API.h >@@ -80,7 +80,8 @@ opus_int silk_Encode( /* O Returns error co > opus_int nSamplesIn, /* I Number of samples in input vector */ > ec_enc *psRangeEnc, /* I/O Compressor data structure */ > opus_int32 *nBytesOut, /* I/O Number of bytes in payload (input: Max bytes) */ >- const opus_int prefillFlag /* I Flag to indicate prefilling buffers no coding */ >+ const opus_int prefillFlag, /* I Flag to indicate prefilling buffers no coding */ >+ int activity /* I Decision of Opus voice activity detector */ > ); > > /****************************************/ >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/CNG.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/CNG.c >index 701b36a38a3105dfa48dcbc54e881e49be199ff6..e6d9b861e95e743f1d0857ce48aedf3cebfbf1e4 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/CNG.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/CNG.c >@@ -138,11 +138,11 @@ void silk_CNG( > gain_Q16 = silk_LSHIFT32( silk_SQRT_APPROX( gain_Q16 ), 8 ); > } > gain_Q10 = silk_RSHIFT( gain_Q16, 6 ); >- >+ > silk_CNG_exc( CNG_sig_Q14 + MAX_LPC_ORDER, psCNG->CNG_exc_buf_Q14, length, &psCNG->rand_seed ); > > /* Convert CNG NLSF to filter representation */ >- silk_NLSF2A( A_Q12, psCNG->CNG_smth_NLSF_Q15, psDec->LPC_order ); >+ silk_NLSF2A( A_Q12, psCNG->CNG_smth_NLSF_Q15, psDec->LPC_order, psDec->arch ); > > /* Generate CNG signal, by synthesis filtering */ > silk_memcpy( CNG_sig_Q14, psCNG->CNG_synth_state, MAX_LPC_ORDER * sizeof( opus_int32 ) ); >@@ -171,10 +171,10 @@ void silk_CNG( > > /* Update states */ > CNG_sig_Q14[ MAX_LPC_ORDER + i ] = silk_ADD_SAT32( CNG_sig_Q14[ MAX_LPC_ORDER + i ], silk_LSHIFT_SAT32( LPC_pred_Q10, 4 ) ); >- >+ > /* Scale with Gain and add to input signal */ > frame[ i ] = (opus_int16)silk_ADD_SAT16( frame[ i ], silk_SAT16( silk_RSHIFT_ROUND( silk_SMULWW( CNG_sig_Q14[ MAX_LPC_ORDER + i ], gain_Q10 ), 8 ) ) ); >- >+ > } > silk_memcpy( psCNG->CNG_synth_state, &CNG_sig_Q14[ length ], MAX_LPC_ORDER * sizeof( opus_int32 ) ); > } else { >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/LPC_analysis_filter.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/LPC_analysis_filter.c >index 20906673ff124610df2071cb765cbf9b09b33f08..7715f70f8d6763757b0ef194be4cd014ffd0c223 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/LPC_analysis_filter.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/LPC_analysis_filter.c >@@ -39,6 +39,13 @@ POSSIBILITY OF SUCH DAMAGE. > /* first d output samples are set to zero */ > /*******************************************/ > >+/* OPT: Using celt_fir() for this function should be faster, but it may cause >+ integer overflows in intermediate values (not final results), which the >+ current implementation silences by casting to unsigned. Enabling >+ this should be safe in pretty much all cases, even though it is not technically >+ C89-compliant. */ >+#define USE_CELT_FIR 0 >+ > void silk_LPC_analysis_filter( > opus_int16 *out, /* O Output signal */ > const opus_int16 *in, /* I Input signal */ >@@ -49,8 +56,7 @@ void silk_LPC_analysis_filter( > ) > { > opus_int j; >-#ifdef FIXED_POINT >- opus_int16 mem[SILK_MAX_ORDER_LPC]; >+#if defined(FIXED_POINT) && USE_CELT_FIR > opus_int16 num[SILK_MAX_ORDER_LPC]; > #else > int ix; >@@ -62,15 +68,12 @@ void silk_LPC_analysis_filter( > silk_assert( (d & 1) == 0 ); > silk_assert( d <= len ); > >-#ifdef FIXED_POINT >+#if defined(FIXED_POINT) && USE_CELT_FIR > silk_assert( d <= SILK_MAX_ORDER_LPC ); > for ( j = 0; j < d; j++ ) { > num[ j ] = -B[ j ]; > } >- for (j=0;j<d;j++) { >- mem[ j ] = in[ d - j - 1 ]; >- } >- celt_fir( in + d, num, out + d, len - d, d, mem, arch ); >+ celt_fir( in + d, num, out + d, len - d, d, arch ); > for ( j = 0; j < d; j++ ) { > out[ j ] = 0; > } >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/LPC_fit.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/LPC_fit.c >new file mode 100644 >index 0000000000000000000000000000000000000000..cdea4f3abcaf7fcd141a4b86e2f924b679effd94 >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/LPC_fit.c >@@ -0,0 +1,81 @@ >+/*********************************************************************** >+Copyright (c) 2013, Koen Vos. All rights reserved. >+Redistribution and use in source and binary forms, with or without >+modification, are permitted provided that the following conditions >+are met: >+- Redistributions of source code must retain the above copyright notice, >+this list of conditions and the following disclaimer. >+- Redistributions in binary form must reproduce the above copyright >+notice, this list of conditions and the following disclaimer in the >+documentation and/or other materials provided with the distribution. >+- Neither the name of Internet Society, IETF or IETF Trust, nor the >+names of specific contributors, may be used to endorse or promote >+products derived from this software without specific prior written >+permission. >+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" >+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE >+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE >+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE >+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE >+POSSIBILITY OF SUCH DAMAGE. >+***********************************************************************/ >+ >+#ifdef HAVE_CONFIG_H >+#include "config.h" >+#endif >+ >+#include "SigProc_FIX.h" >+ >+/* Convert int32 coefficients to int16 coefs and make sure there's no wrap-around */ >+void silk_LPC_fit( >+ opus_int16 *a_QOUT, /* O Output signal */ >+ opus_int32 *a_QIN, /* I/O Input signal */ >+ const opus_int QOUT, /* I Input Q domain */ >+ const opus_int QIN, /* I Input Q domain */ >+ const opus_int d /* I Filter order */ >+) >+{ >+ opus_int i, k, idx = 0; >+ opus_int32 maxabs, absval, chirp_Q16; >+ >+ /* Limit the maximum absolute value of the prediction coefficients, so that they'll fit in int16 */ >+ for( i = 0; i < 10; i++ ) { >+ /* Find maximum absolute value and its index */ >+ maxabs = 0; >+ for( k = 0; k < d; k++ ) { >+ absval = silk_abs( a_QIN[k] ); >+ if( absval > maxabs ) { >+ maxabs = absval; >+ idx = k; >+ } >+ } >+ maxabs = silk_RSHIFT_ROUND( maxabs, QIN - QOUT ); >+ >+ if( maxabs > silk_int16_MAX ) { >+ /* Reduce magnitude of prediction coefficients */ >+ maxabs = silk_min( maxabs, 163838 ); /* ( silk_int32_MAX >> 14 ) + silk_int16_MAX = 163838 */ >+ chirp_Q16 = SILK_FIX_CONST( 0.999, 16 ) - silk_DIV32( silk_LSHIFT( maxabs - silk_int16_MAX, 14 ), >+ silk_RSHIFT32( silk_MUL( maxabs, idx + 1), 2 ) ); >+ silk_bwexpander_32( a_QIN, d, chirp_Q16 ); >+ } else { >+ break; >+ } >+ } >+ >+ if( i == 10 ) { >+ /* Reached the last iteration, clip the coefficients */ >+ for( k = 0; k < d; k++ ) { >+ a_QOUT[ k ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( a_QIN[ k ], QIN - QOUT ) ); >+ a_QIN[ k ] = silk_LSHIFT( (opus_int32)a_QOUT[ k ], QIN - QOUT ); >+ } >+ } else { >+ for( k = 0; k < d; k++ ) { >+ a_QOUT[ k ] = (opus_int16)silk_RSHIFT_ROUND( a_QIN[ k ], QIN - QOUT ); >+ } >+ } >+} >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/LPC_inv_pred_gain.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/LPC_inv_pred_gain.c >index 4af89aa5fad324799620e64c3fa22e3ea6bd9400..a3746a6ef9f3187468ccd6944837d8c02bbadd18 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/LPC_inv_pred_gain.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/LPC_inv_pred_gain.c >@@ -30,6 +30,7 @@ POSSIBILITY OF SUCH DAMAGE. > #endif > > #include "SigProc_FIX.h" >+#include "define.h" > > #define QA 24 > #define A_LIMIT SILK_FIX_CONST( 0.99975, QA ) >@@ -38,117 +39,103 @@ POSSIBILITY OF SUCH DAMAGE. > > /* Compute inverse of LPC prediction gain, and */ > /* test if LPC coefficients are stable (all poles within unit circle) */ >-static opus_int32 LPC_inverse_pred_gain_QA( /* O Returns inverse prediction gain in energy domain, Q30 */ >- opus_int32 A_QA[ 2 ][ SILK_MAX_ORDER_LPC ], /* I Prediction coefficients */ >+static opus_int32 LPC_inverse_pred_gain_QA_c( /* O Returns inverse prediction gain in energy domain, Q30 */ >+ opus_int32 A_QA[ SILK_MAX_ORDER_LPC ], /* I Prediction coefficients */ > const opus_int order /* I Prediction order */ > ) > { > opus_int k, n, mult2Q; >- opus_int32 invGain_Q30, rc_Q31, rc_mult1_Q30, rc_mult2, tmp_QA; >- opus_int32 *Aold_QA, *Anew_QA; >+ opus_int32 invGain_Q30, rc_Q31, rc_mult1_Q30, rc_mult2, tmp1, tmp2; > >- Anew_QA = A_QA[ order & 1 ]; >- >- invGain_Q30 = (opus_int32)1 << 30; >+ invGain_Q30 = SILK_FIX_CONST( 1, 30 ); > for( k = order - 1; k > 0; k-- ) { > /* Check for stability */ >- if( ( Anew_QA[ k ] > A_LIMIT ) || ( Anew_QA[ k ] < -A_LIMIT ) ) { >+ if( ( A_QA[ k ] > A_LIMIT ) || ( A_QA[ k ] < -A_LIMIT ) ) { > return 0; > } > > /* Set RC equal to negated AR coef */ >- rc_Q31 = -silk_LSHIFT( Anew_QA[ k ], 31 - QA ); >+ rc_Q31 = -silk_LSHIFT( A_QA[ k ], 31 - QA ); > > /* rc_mult1_Q30 range: [ 1 : 2^30 ] */ >- rc_mult1_Q30 = ( (opus_int32)1 << 30 ) - silk_SMMUL( rc_Q31, rc_Q31 ); >+ rc_mult1_Q30 = silk_SUB32( SILK_FIX_CONST( 1, 30 ), silk_SMMUL( rc_Q31, rc_Q31 ) ); > silk_assert( rc_mult1_Q30 > ( 1 << 15 ) ); /* reduce A_LIMIT if fails */ > silk_assert( rc_mult1_Q30 <= ( 1 << 30 ) ); > >- /* rc_mult2 range: [ 2^30 : silk_int32_MAX ] */ >- mult2Q = 32 - silk_CLZ32( silk_abs( rc_mult1_Q30 ) ); >- rc_mult2 = silk_INVERSE32_varQ( rc_mult1_Q30, mult2Q + 30 ); >- > /* Update inverse gain */ > /* invGain_Q30 range: [ 0 : 2^30 ] */ > invGain_Q30 = silk_LSHIFT( silk_SMMUL( invGain_Q30, rc_mult1_Q30 ), 2 ); > silk_assert( invGain_Q30 >= 0 ); > silk_assert( invGain_Q30 <= ( 1 << 30 ) ); >+ if( invGain_Q30 < SILK_FIX_CONST( 1.0f / MAX_PREDICTION_POWER_GAIN, 30 ) ) { >+ return 0; >+ } > >- /* Swap pointers */ >- Aold_QA = Anew_QA; >- Anew_QA = A_QA[ k & 1 ]; >+ /* rc_mult2 range: [ 2^30 : silk_int32_MAX ] */ >+ mult2Q = 32 - silk_CLZ32( silk_abs( rc_mult1_Q30 ) ); >+ rc_mult2 = silk_INVERSE32_varQ( rc_mult1_Q30, mult2Q + 30 ); > > /* Update AR coefficient */ >- for( n = 0; n < k; n++ ) { >- tmp_QA = Aold_QA[ n ] - MUL32_FRAC_Q( Aold_QA[ k - n - 1 ], rc_Q31, 31 ); >- Anew_QA[ n ] = MUL32_FRAC_Q( tmp_QA, rc_mult2 , mult2Q ); >+ for( n = 0; n < (k + 1) >> 1; n++ ) { >+ opus_int64 tmp64; >+ tmp1 = A_QA[ n ]; >+ tmp2 = A_QA[ k - n - 1 ]; >+ tmp64 = silk_RSHIFT_ROUND64( silk_SMULL( silk_SUB_SAT32(tmp1, >+ MUL32_FRAC_Q( tmp2, rc_Q31, 31 ) ), rc_mult2 ), mult2Q); >+ if( tmp64 > silk_int32_MAX || tmp64 < silk_int32_MIN ) { >+ return 0; >+ } >+ A_QA[ n ] = ( opus_int32 )tmp64; >+ tmp64 = silk_RSHIFT_ROUND64( silk_SMULL( silk_SUB_SAT32(tmp2, >+ MUL32_FRAC_Q( tmp1, rc_Q31, 31 ) ), rc_mult2), mult2Q); >+ if( tmp64 > silk_int32_MAX || tmp64 < silk_int32_MIN ) { >+ return 0; >+ } >+ A_QA[ k - n - 1 ] = ( opus_int32 )tmp64; > } > } > > /* Check for stability */ >- if( ( Anew_QA[ 0 ] > A_LIMIT ) || ( Anew_QA[ 0 ] < -A_LIMIT ) ) { >+ if( ( A_QA[ k ] > A_LIMIT ) || ( A_QA[ k ] < -A_LIMIT ) ) { > return 0; > } > > /* Set RC equal to negated AR coef */ >- rc_Q31 = -silk_LSHIFT( Anew_QA[ 0 ], 31 - QA ); >+ rc_Q31 = -silk_LSHIFT( A_QA[ 0 ], 31 - QA ); > > /* Range: [ 1 : 2^30 ] */ >- rc_mult1_Q30 = ( (opus_int32)1 << 30 ) - silk_SMMUL( rc_Q31, rc_Q31 ); >+ rc_mult1_Q30 = silk_SUB32( SILK_FIX_CONST( 1, 30 ), silk_SMMUL( rc_Q31, rc_Q31 ) ); > > /* Update inverse gain */ > /* Range: [ 0 : 2^30 ] */ > invGain_Q30 = silk_LSHIFT( silk_SMMUL( invGain_Q30, rc_mult1_Q30 ), 2 ); >- silk_assert( invGain_Q30 >= 0 ); >- silk_assert( invGain_Q30 <= 1<<30 ); >+ silk_assert( invGain_Q30 >= 0 ); >+ silk_assert( invGain_Q30 <= ( 1 << 30 ) ); >+ if( invGain_Q30 < SILK_FIX_CONST( 1.0f / MAX_PREDICTION_POWER_GAIN, 30 ) ) { >+ return 0; >+ } > > return invGain_Q30; > } > > /* For input in Q12 domain */ >-opus_int32 silk_LPC_inverse_pred_gain( /* O Returns inverse prediction gain in energy domain, Q30 */ >+opus_int32 silk_LPC_inverse_pred_gain_c( /* O Returns inverse prediction gain in energy domain, Q30 */ > const opus_int16 *A_Q12, /* I Prediction coefficients, Q12 [order] */ > const opus_int order /* I Prediction order */ > ) > { > opus_int k; >- opus_int32 Atmp_QA[ 2 ][ SILK_MAX_ORDER_LPC ]; >- opus_int32 *Anew_QA; >+ opus_int32 Atmp_QA[ SILK_MAX_ORDER_LPC ]; > opus_int32 DC_resp = 0; > >- Anew_QA = Atmp_QA[ order & 1 ]; >- > /* Increase Q domain of the AR coefficients */ > for( k = 0; k < order; k++ ) { > DC_resp += (opus_int32)A_Q12[ k ]; >- Anew_QA[ k ] = silk_LSHIFT32( (opus_int32)A_Q12[ k ], QA - 12 ); >+ Atmp_QA[ k ] = silk_LSHIFT32( (opus_int32)A_Q12[ k ], QA - 12 ); > } > /* If the DC is unstable, we don't even need to do the full calculations */ > if( DC_resp >= 4096 ) { > return 0; > } >- return LPC_inverse_pred_gain_QA( Atmp_QA, order ); >+ return LPC_inverse_pred_gain_QA_c( Atmp_QA, order ); > } >- >-#ifdef FIXED_POINT >- >-/* For input in Q24 domain */ >-opus_int32 silk_LPC_inverse_pred_gain_Q24( /* O Returns inverse prediction gain in energy domain, Q30 */ >- const opus_int32 *A_Q24, /* I Prediction coefficients [order] */ >- const opus_int order /* I Prediction order */ >-) >-{ >- opus_int k; >- opus_int32 Atmp_QA[ 2 ][ SILK_MAX_ORDER_LPC ]; >- opus_int32 *Anew_QA; >- >- Anew_QA = Atmp_QA[ order & 1 ]; >- >- /* Increase Q domain of the AR coefficients */ >- for( k = 0; k < order; k++ ) { >- Anew_QA[ k ] = silk_RSHIFT32( A_Q24[ k ], 24 - QA ); >- } >- >- return LPC_inverse_pred_gain_QA( Atmp_QA, order ); >-} >-#endif >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/LP_variable_cutoff.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/LP_variable_cutoff.c >index f639e1f899a9c23e7e542055287c93e99f3b8774..79112ad354a157ae68beda4d355f0f116f2b6f8a 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/LP_variable_cutoff.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/LP_variable_cutoff.c >@@ -130,6 +130,6 @@ void silk_LP_variable_cutoff( > > /* ARMA low-pass filtering */ > silk_assert( TRANSITION_NB == 3 && TRANSITION_NA == 2 ); >- silk_biquad_alt( frame, B_Q28, A_Q28, psLP->In_LP_State, frame, frame_length, 1); >+ silk_biquad_alt_stride1( frame, B_Q28, A_Q28, psLP->In_LP_State, frame, frame_length); > } > } >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/MacroCount.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/MacroCount.h >index 834817d058b9e9e4b8e7c244a9ce735278cf3544..78100ffedeb29061809327309599863a4dc4af48 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/MacroCount.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/MacroCount.h >@@ -319,14 +319,6 @@ static OPUS_INLINE opus_int32 silk_ADD_POS_SAT32(opus_int64 a, opus_int64 b){ > return(tmp); > } > >-#undef silk_ADD_POS_SAT64 >-static OPUS_INLINE opus_int64 silk_ADD_POS_SAT64(opus_int64 a, opus_int64 b){ >- opus_int64 tmp; >- ops_count += 1; >- tmp = ((((a)+(b)) & 0x8000000000000000LL) ? silk_int64_MAX : ((a)+(b))); >- return(tmp); >-} >- > #undef silk_LSHIFT8 > static OPUS_INLINE opus_int8 silk_LSHIFT8(opus_int8 a, opus_int32 shift){ > opus_int8 ret; >@@ -699,7 +691,7 @@ return(ret); > > > #undef silk_LIMIT_32 >-static OPUS_INLINE opus_int silk_LIMIT_32(opus_int32 a, opus_int32 limit1, opus_int32 limit2) >+static OPUS_INLINE opus_int32 silk_LIMIT_32(opus_int32 a, opus_int32 limit1, opus_int32 limit2) > { > opus_int32 ret; > ops_count += 6; >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/MacroDebug.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/MacroDebug.h >index 35aedc5c5fa646722e6879ee51c78f324491ed84..8dd4ce2ee275a6a64f4b1ede526fa8b428f6122b 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/MacroDebug.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/MacroDebug.h >@@ -539,8 +539,7 @@ static OPUS_INLINE opus_int32 silk_DIV32_16_(opus_int32 a32, opus_int32 b32, cha > no checking needed for silk_POS_SAT32 > no checking needed for silk_ADD_POS_SAT8 > no checking needed for silk_ADD_POS_SAT16 >- no checking needed for silk_ADD_POS_SAT32 >- no checking needed for silk_ADD_POS_SAT64 */ >+ no checking needed for silk_ADD_POS_SAT32 */ > > #undef silk_LSHIFT8 > #define silk_LSHIFT8(a,b) silk_LSHIFT8_((a), (b), __FILE__, __LINE__) >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/NLSF2A.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/NLSF2A.c >index b1c559ea68213e06d39de79c977e86f573bd51c8..116b465b1db8c678177adedbc6d25ff9ed387510 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/NLSF2A.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/NLSF2A.c >@@ -66,7 +66,8 @@ static OPUS_INLINE void silk_NLSF2A_find_poly( > void silk_NLSF2A( > opus_int16 *a_Q12, /* O monic whitening filter coefficients in Q12, [ d ] */ > const opus_int16 *NLSF, /* I normalized line spectral frequencies in Q15, [ d ] */ >- const opus_int d /* I filter order (should be even) */ >+ const opus_int d, /* I filter order (should be even) */ >+ int arch /* I Run-time architecture */ > ) > { > /* This ordering was found to maximize quality. It improves numerical accuracy of >@@ -83,15 +84,14 @@ void silk_NLSF2A( > opus_int32 P[ SILK_MAX_ORDER_LPC / 2 + 1 ], Q[ SILK_MAX_ORDER_LPC / 2 + 1 ]; > opus_int32 Ptmp, Qtmp, f_int, f_frac, cos_val, delta; > opus_int32 a32_QA1[ SILK_MAX_ORDER_LPC ]; >- opus_int32 maxabs, absval, idx=0, sc_Q16; > > silk_assert( LSF_COS_TAB_SZ_FIX == 128 ); >- silk_assert( d==10||d==16 ); >+ silk_assert( d==10 || d==16 ); > > /* convert LSFs to 2*cos(LSF), using piecewise linear curve from table */ > ordering = d == 16 ? ordering16 : ordering10; > for( k = 0; k < d; k++ ) { >- silk_assert(NLSF[k] >= 0 ); >+ silk_assert( NLSF[k] >= 0 ); > > /* f_int on a scale 0-127 (rounded down) */ > f_int = silk_RSHIFT( NLSF[k], 15 - 7 ); >@@ -126,52 +126,15 @@ void silk_NLSF2A( > a32_QA1[ d-k-1 ] = Qtmp - Ptmp; /* QA+1 */ > } > >- /* Limit the maximum absolute value of the prediction coefficients, so that they'll fit in int16 */ >- for( i = 0; i < 10; i++ ) { >- /* Find maximum absolute value and its index */ >- maxabs = 0; >- for( k = 0; k < d; k++ ) { >- absval = silk_abs( a32_QA1[k] ); >- if( absval > maxabs ) { >- maxabs = absval; >- idx = k; >- } >- } >- maxabs = silk_RSHIFT_ROUND( maxabs, QA + 1 - 12 ); /* QA+1 -> Q12 */ >- >- if( maxabs > silk_int16_MAX ) { >- /* Reduce magnitude of prediction coefficients */ >- maxabs = silk_min( maxabs, 163838 ); /* ( silk_int32_MAX >> 14 ) + silk_int16_MAX = 163838 */ >- sc_Q16 = SILK_FIX_CONST( 0.999, 16 ) - silk_DIV32( silk_LSHIFT( maxabs - silk_int16_MAX, 14 ), >- silk_RSHIFT32( silk_MUL( maxabs, idx + 1), 2 ) ); >- silk_bwexpander_32( a32_QA1, d, sc_Q16 ); >- } else { >- break; >- } >- } >+ /* Convert int32 coefficients to Q12 int16 coefs */ >+ silk_LPC_fit( a_Q12, a32_QA1, 12, QA + 1, d ); > >- if( i == 10 ) { >- /* Reached the last iteration, clip the coefficients */ >+ for( i = 0; silk_LPC_inverse_pred_gain( a_Q12, d, arch ) == 0 && i < MAX_LPC_STABILIZE_ITERATIONS; i++ ) { >+ /* Prediction coefficients are (too close to) unstable; apply bandwidth expansion */ >+ /* on the unscaled coefficients, convert to Q12 and measure again */ >+ silk_bwexpander_32( a32_QA1, d, 65536 - silk_LSHIFT( 2, i ) ); > for( k = 0; k < d; k++ ) { >- a_Q12[ k ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( a32_QA1[ k ], QA + 1 - 12 ) ); /* QA+1 -> Q12 */ >- a32_QA1[ k ] = silk_LSHIFT( (opus_int32)a_Q12[ k ], QA + 1 - 12 ); >- } >- } else { >- for( k = 0; k < d; k++ ) { >- a_Q12[ k ] = (opus_int16)silk_RSHIFT_ROUND( a32_QA1[ k ], QA + 1 - 12 ); /* QA+1 -> Q12 */ >- } >- } >- >- for( i = 0; i < MAX_LPC_STABILIZE_ITERATIONS; i++ ) { >- if( silk_LPC_inverse_pred_gain( a_Q12, d ) < SILK_FIX_CONST( 1.0 / MAX_PREDICTION_POWER_GAIN, 30 ) ) { >- /* Prediction coefficients are (too close to) unstable; apply bandwidth expansion */ >- /* on the unscaled coefficients, convert to Q12 and measure again */ >- silk_bwexpander_32( a32_QA1, d, 65536 - silk_LSHIFT( 2, i ) ); >- for( k = 0; k < d; k++ ) { >- a_Q12[ k ] = (opus_int16)silk_RSHIFT_ROUND( a32_QA1[ k ], QA + 1 - 12 ); /* QA+1 -> Q12 */ >- } >- } else { >- break; >+ a_Q12[ k ] = (opus_int16)silk_RSHIFT_ROUND( a32_QA1[ k ], QA + 1 - 12 ); /* QA+1 -> Q12 */ > } > } > } >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/NLSF_VQ.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/NLSF_VQ.c >index 69b6e22e18965a9804b54aec1b9ff7cb82453652..452f3dcb7ddd8a788a00f3c27c139e95ea20bbfa 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/NLSF_VQ.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/NLSF_VQ.c >@@ -33,36 +33,44 @@ POSSIBILITY OF SUCH DAMAGE. > > /* Compute quantization errors for an LPC_order element input vector for a VQ codebook */ > void silk_NLSF_VQ( >- opus_int32 err_Q26[], /* O Quantization errors [K] */ >+ opus_int32 err_Q24[], /* O Quantization errors [K] */ > const opus_int16 in_Q15[], /* I Input vectors to be quantized [LPC_order] */ > const opus_uint8 pCB_Q8[], /* I Codebook vectors [K*LPC_order] */ >+ const opus_int16 pWght_Q9[], /* I Codebook weights [K*LPC_order] */ > const opus_int K, /* I Number of codebook vectors */ > const opus_int LPC_order /* I Number of LPCs */ > ) > { >- opus_int i, m; >- opus_int32 diff_Q15, sum_error_Q30, sum_error_Q26; >+ opus_int i, m; >+ opus_int32 diff_Q15, diffw_Q24, sum_error_Q24, pred_Q24; >+ const opus_int16 *w_Q9_ptr; >+ const opus_uint8 *cb_Q8_ptr; > >- silk_assert( LPC_order <= 16 ); > silk_assert( ( LPC_order & 1 ) == 0 ); > > /* Loop over codebook */ >+ cb_Q8_ptr = pCB_Q8; >+ w_Q9_ptr = pWght_Q9; > for( i = 0; i < K; i++ ) { >- sum_error_Q26 = 0; >- for( m = 0; m < LPC_order; m += 2 ) { >- /* Compute weighted squared quantization error for index m */ >- diff_Q15 = silk_SUB_LSHIFT32( in_Q15[ m ], (opus_int32)*pCB_Q8++, 7 ); /* range: [ -32767 : 32767 ]*/ >- sum_error_Q30 = silk_SMULBB( diff_Q15, diff_Q15 ); >+ sum_error_Q24 = 0; >+ pred_Q24 = 0; >+ for( m = LPC_order-2; m >= 0; m -= 2 ) { >+ /* Compute weighted absolute predictive quantization error for index m + 1 */ >+ diff_Q15 = silk_SUB_LSHIFT32( in_Q15[ m + 1 ], (opus_int32)cb_Q8_ptr[ m + 1 ], 7 ); /* range: [ -32767 : 32767 ]*/ >+ diffw_Q24 = silk_SMULBB( diff_Q15, w_Q9_ptr[ m + 1 ] ); >+ sum_error_Q24 = silk_ADD32( sum_error_Q24, silk_abs( silk_SUB_RSHIFT32( diffw_Q24, pred_Q24, 1 ) ) ); >+ pred_Q24 = diffw_Q24; > >- /* Compute weighted squared quantization error for index m + 1 */ >- diff_Q15 = silk_SUB_LSHIFT32( in_Q15[m + 1], (opus_int32)*pCB_Q8++, 7 ); /* range: [ -32767 : 32767 ]*/ >- sum_error_Q30 = silk_SMLABB( sum_error_Q30, diff_Q15, diff_Q15 ); >+ /* Compute weighted absolute predictive quantization error for index m */ >+ diff_Q15 = silk_SUB_LSHIFT32( in_Q15[ m ], (opus_int32)cb_Q8_ptr[ m ], 7 ); /* range: [ -32767 : 32767 ]*/ >+ diffw_Q24 = silk_SMULBB( diff_Q15, w_Q9_ptr[ m ] ); >+ sum_error_Q24 = silk_ADD32( sum_error_Q24, silk_abs( silk_SUB_RSHIFT32( diffw_Q24, pred_Q24, 1 ) ) ); >+ pred_Q24 = diffw_Q24; > >- sum_error_Q26 = silk_ADD_RSHIFT32( sum_error_Q26, sum_error_Q30, 4 ); >- >- silk_assert( sum_error_Q26 >= 0 ); >- silk_assert( sum_error_Q30 >= 0 ); >+ silk_assert( sum_error_Q24 >= 0 ); > } >- err_Q26[ i ] = sum_error_Q26; >+ err_Q24[ i ] = sum_error_Q24; >+ cb_Q8_ptr += LPC_order; >+ w_Q9_ptr += LPC_order; > } > } >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/NLSF_decode.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/NLSF_decode.c >index 9f715060b8efb2c3c6d84c10edc68036f0253f46..eeb0ba8c92c8b60f7dc61953fd8054e874ba07d2 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/NLSF_decode.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/NLSF_decode.c >@@ -32,7 +32,7 @@ POSSIBILITY OF SUCH DAMAGE. > #include "main.h" > > /* Predictive dequantizer for NLSF residuals */ >-static OPUS_INLINE void silk_NLSF_residual_dequant( /* O Returns RD value in Q30 */ >+static OPUS_INLINE void silk_NLSF_residual_dequant( /* O Returns RD value in Q30 */ > opus_int16 x_Q10[], /* O Output [ order ] */ > const opus_int8 indices[], /* I Quantization indices [ order ] */ > const opus_uint8 pred_coef_Q8[], /* I Backward predictor coefs [ order ] */ >@@ -70,15 +70,9 @@ void silk_NLSF_decode( > opus_uint8 pred_Q8[ MAX_LPC_ORDER ]; > opus_int16 ec_ix[ MAX_LPC_ORDER ]; > opus_int16 res_Q10[ MAX_LPC_ORDER ]; >- opus_int16 W_tmp_QW[ MAX_LPC_ORDER ]; >- opus_int32 W_tmp_Q9, NLSF_Q15_tmp; >+ opus_int32 NLSF_Q15_tmp; > const opus_uint8 *pCB_element; >- >- /* Decode first stage */ >- pCB_element = &psNLSF_CB->CB1_NLSF_Q8[ NLSFIndices[ 0 ] * psNLSF_CB->order ]; >- for( i = 0; i < psNLSF_CB->order; i++ ) { >- pNLSF_Q15[ i ] = silk_LSHIFT( (opus_int16)pCB_element[ i ], 7 ); >- } >+ const opus_int16 *pCB_Wght_Q9; > > /* Unpack entropy table indices and predictor for current CB1 index */ > silk_NLSF_unpack( ec_ix, pred_Q8, psNLSF_CB, NLSFIndices[ 0 ] ); >@@ -86,13 +80,11 @@ void silk_NLSF_decode( > /* Predictive residual dequantizer */ > silk_NLSF_residual_dequant( res_Q10, &NLSFIndices[ 1 ], pred_Q8, psNLSF_CB->quantStepSize_Q16, psNLSF_CB->order ); > >- /* Weights from codebook vector */ >- silk_NLSF_VQ_weights_laroia( W_tmp_QW, pNLSF_Q15, psNLSF_CB->order ); >- >- /* Apply inverse square-rooted weights and add to output */ >+ /* Apply inverse square-rooted weights to first stage and add to output */ >+ pCB_element = &psNLSF_CB->CB1_NLSF_Q8[ NLSFIndices[ 0 ] * psNLSF_CB->order ]; >+ pCB_Wght_Q9 = &psNLSF_CB->CB1_Wght_Q9[ NLSFIndices[ 0 ] * psNLSF_CB->order ]; > for( i = 0; i < psNLSF_CB->order; i++ ) { >- W_tmp_Q9 = silk_SQRT_APPROX( silk_LSHIFT( (opus_int32)W_tmp_QW[ i ], 18 - NLSF_W_Q ) ); >- NLSF_Q15_tmp = silk_ADD32( pNLSF_Q15[ i ], silk_DIV32_16( silk_LSHIFT( (opus_int32)res_Q10[ i ], 14 ), W_tmp_Q9 ) ); >+ NLSF_Q15_tmp = silk_ADD_LSHIFT32( silk_DIV32_16( silk_LSHIFT( (opus_int32)res_Q10[ i ], 14 ), pCB_Wght_Q9[ i ] ), (opus_int16)pCB_element[ i ], 7 ); > pNLSF_Q15[ i ] = (opus_int16)silk_LIMIT( NLSF_Q15_tmp, 0, 32767 ); > } > >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/NLSF_del_dec_quant.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/NLSF_del_dec_quant.c >index de88fee060e3772eb43c4d0df6812aa101590dbf..44a16acd0bc11ab733bbb0bbe42c378b21d4af1f 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/NLSF_del_dec_quant.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/NLSF_del_dec_quant.c >@@ -84,7 +84,7 @@ opus_int32 silk_NLSF_del_dec_quant( /* O Returns > nStates = 1; > RD_Q25[ 0 ] = 0; > prev_out_Q10[ 0 ] = 0; >- for( i = order - 1; ; i-- ) { >+ for( i = order - 1; i >= 0; i-- ) { > rates_Q5 = &ec_rates_Q5[ ec_ix[ i ] ]; > in_Q10 = x_Q10[ i ]; > for( j = 0; j < nStates; j++ ) { >@@ -131,7 +131,7 @@ opus_int32 silk_NLSF_del_dec_quant( /* O Returns > RD_Q25[ j + nStates ] = silk_SMLABB( silk_MLA( RD_tmp_Q25, silk_SMULBB( diff_Q10, diff_Q10 ), w_Q5[ i ] ), mu_Q20, rate1_Q5 ); > } > >- if( nStates <= ( NLSF_QUANT_DEL_DEC_STATES >> 1 ) ) { >+ if( nStates <= NLSF_QUANT_DEL_DEC_STATES/2 ) { > /* double number of states and copy */ > for( j = 0; j < nStates; j++ ) { > ind[ j + nStates ][ i ] = ind[ j ][ i ] + 1; >@@ -140,7 +140,7 @@ opus_int32 silk_NLSF_del_dec_quant( /* O Returns > for( j = nStates; j < NLSF_QUANT_DEL_DEC_STATES; j++ ) { > ind[ j ][ i ] = ind[ j - nStates ][ i ]; > } >- } else if( i > 0 ) { >+ } else { > /* sort lower and upper half of RD_Q25, pairwise */ > for( j = 0; j < NLSF_QUANT_DEL_DEC_STATES; j++ ) { > if( RD_Q25[ j ] > RD_Q25[ j + NLSF_QUANT_DEL_DEC_STATES ] ) { >@@ -191,8 +191,6 @@ opus_int32 silk_NLSF_del_dec_quant( /* O Returns > for( j = 0; j < NLSF_QUANT_DEL_DEC_STATES; j++ ) { > ind[ j ][ i ] += silk_RSHIFT( ind_sort[ j ], NLSF_QUANT_DEL_DEC_STATES_LOG2 ); > } >- } else { /* i == 0 */ >- break; > } > } > >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/NLSF_encode.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/NLSF_encode.c >index f03c3f1c3549d9dccf4f511537b4001c409f7e6b..268b9a195b508565367812ba2747a7ba6a1f4aa0 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/NLSF_encode.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/NLSF_encode.c >@@ -37,9 +37,9 @@ POSSIBILITY OF SUCH DAMAGE. > /***********************/ > opus_int32 silk_NLSF_encode( /* O Returns RD value in Q25 */ > opus_int8 *NLSFIndices, /* I Codebook path vector [ LPC_ORDER + 1 ] */ >- opus_int16 *pNLSF_Q15, /* I/O Quantized NLSF vector [ LPC_ORDER ] */ >+ opus_int16 *pNLSF_Q15, /* I/O (Un)quantized NLSF vector [ LPC_ORDER ] */ > const silk_NLSF_CB_struct *psNLSF_CB, /* I Codebook object */ >- const opus_int16 *pW_QW, /* I NLSF weight vector [ LPC_ORDER ] */ >+ const opus_int16 *pW_Q2, /* I NLSF weight vector [ LPC_ORDER ] */ > const opus_int NLSF_mu_Q20, /* I Rate weight for the RD optimization */ > const opus_int nSurvivors, /* I Max survivors after first stage */ > const opus_int signalType /* I Signal type: 0/1/2 */ >@@ -47,21 +47,19 @@ opus_int32 silk_NLSF_encode( /* O Returns > { > opus_int i, s, ind1, bestIndex, prob_Q8, bits_q7; > opus_int32 W_tmp_Q9, ret; >- VARDECL( opus_int32, err_Q26 ); >+ VARDECL( opus_int32, err_Q24 ); > VARDECL( opus_int32, RD_Q25 ); > VARDECL( opus_int, tempIndices1 ); > VARDECL( opus_int8, tempIndices2 ); >- opus_int16 res_Q15[ MAX_LPC_ORDER ]; > opus_int16 res_Q10[ MAX_LPC_ORDER ]; > opus_int16 NLSF_tmp_Q15[ MAX_LPC_ORDER ]; >- opus_int16 W_tmp_QW[ MAX_LPC_ORDER ]; > opus_int16 W_adj_Q5[ MAX_LPC_ORDER ]; > opus_uint8 pred_Q8[ MAX_LPC_ORDER ]; > opus_int16 ec_ix[ MAX_LPC_ORDER ]; > const opus_uint8 *pCB_element, *iCDF_ptr; >+ const opus_int16 *pCB_Wght_Q9; > SAVE_STACK; > >- silk_assert( nSurvivors <= NLSF_VQ_MAX_SURVIVORS ); > silk_assert( signalType >= 0 && signalType <= 2 ); > silk_assert( NLSF_mu_Q20 <= 32767 && NLSF_mu_Q20 >= 0 ); > >@@ -69,12 +67,12 @@ opus_int32 silk_NLSF_encode( /* O Returns > silk_NLSF_stabilize( pNLSF_Q15, psNLSF_CB->deltaMin_Q15, psNLSF_CB->order ); > > /* First stage: VQ */ >- ALLOC( err_Q26, psNLSF_CB->nVectors, opus_int32 ); >- silk_NLSF_VQ( err_Q26, pNLSF_Q15, psNLSF_CB->CB1_NLSF_Q8, psNLSF_CB->nVectors, psNLSF_CB->order ); >+ ALLOC( err_Q24, psNLSF_CB->nVectors, opus_int32 ); >+ silk_NLSF_VQ( err_Q24, pNLSF_Q15, psNLSF_CB->CB1_NLSF_Q8, psNLSF_CB->CB1_Wght_Q9, psNLSF_CB->nVectors, psNLSF_CB->order ); > > /* Sort the quantization errors */ > ALLOC( tempIndices1, nSurvivors, opus_int ); >- silk_insertion_sort_increasing( err_Q26, tempIndices1, psNLSF_CB->nVectors, nSurvivors ); >+ silk_insertion_sort_increasing( err_Q24, tempIndices1, psNLSF_CB->nVectors, nSurvivors ); > > ALLOC( RD_Q25, nSurvivors, opus_int32 ); > ALLOC( tempIndices2, nSurvivors * MAX_LPC_ORDER, opus_int8 ); >@@ -85,23 +83,12 @@ opus_int32 silk_NLSF_encode( /* O Returns > > /* Residual after first stage */ > pCB_element = &psNLSF_CB->CB1_NLSF_Q8[ ind1 * psNLSF_CB->order ]; >+ pCB_Wght_Q9 = &psNLSF_CB->CB1_Wght_Q9[ ind1 * psNLSF_CB->order ]; > for( i = 0; i < psNLSF_CB->order; i++ ) { > NLSF_tmp_Q15[ i ] = silk_LSHIFT16( (opus_int16)pCB_element[ i ], 7 ); >- res_Q15[ i ] = pNLSF_Q15[ i ] - NLSF_tmp_Q15[ i ]; >- } >- >- /* Weights from codebook vector */ >- silk_NLSF_VQ_weights_laroia( W_tmp_QW, NLSF_tmp_Q15, psNLSF_CB->order ); >- >- /* Apply square-rooted weights */ >- for( i = 0; i < psNLSF_CB->order; i++ ) { >- W_tmp_Q9 = silk_SQRT_APPROX( silk_LSHIFT( (opus_int32)W_tmp_QW[ i ], 18 - NLSF_W_Q ) ); >- res_Q10[ i ] = (opus_int16)silk_RSHIFT( silk_SMULBB( res_Q15[ i ], W_tmp_Q9 ), 14 ); >- } >- >- /* Modify input weights accordingly */ >- for( i = 0; i < psNLSF_CB->order; i++ ) { >- W_adj_Q5[ i ] = silk_DIV32_16( silk_LSHIFT( (opus_int32)pW_QW[ i ], 5 ), W_tmp_QW[ i ] ); >+ W_tmp_Q9 = pCB_Wght_Q9[ i ]; >+ res_Q10[ i ] = (opus_int16)silk_RSHIFT( silk_SMULBB( pNLSF_Q15[ i ] - NLSF_tmp_Q15[ i ], W_tmp_Q9 ), 14 ); >+ W_adj_Q5[ i ] = silk_DIV32_varQ( (opus_int32)pW_Q2[ i ], silk_SMULBB( W_tmp_Q9, W_tmp_Q9 ), 21 ); > } > > /* Unpack entropy table indices and predictor for current CB1 index */ >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/NSQ.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/NSQ.c >index 43e3fee7e0ad929394ef7cbcf814bade28719bec..617a19feadef8d557b086c34558d31750276a1c5 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/NSQ.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/NSQ.c >@@ -37,7 +37,7 @@ POSSIBILITY OF SUCH DAMAGE. > static OPUS_INLINE void silk_nsq_scale_states( > const silk_encoder_state *psEncC, /* I Encoder State */ > silk_nsq_state *NSQ, /* I/O NSQ state */ >- const opus_int32 x_Q3[], /* I input in Q3 */ >+ const opus_int16 x16[], /* I input */ > opus_int32 x_sc_Q10[], /* O input scaled with 1/Gain */ > const opus_int16 sLTP[], /* I re-whitened LTP state in Q0 */ > opus_int32 sLTP_Q15[], /* O LTP state matching scaled input */ >@@ -75,14 +75,14 @@ static OPUS_INLINE void silk_noise_shape_quantizer( > > void silk_NSQ_c > ( >- const silk_encoder_state *psEncC, /* I/O Encoder State */ >+ const silk_encoder_state *psEncC, /* I Encoder State */ > silk_nsq_state *NSQ, /* I/O NSQ state */ > SideInfoIndices *psIndices, /* I/O Quantization Indices */ >- const opus_int32 x_Q3[], /* I Prefiltered input signal */ >+ const opus_int16 x16[], /* I Input */ > opus_int8 pulses[], /* O Quantized pulse signal */ > const opus_int16 PredCoef_Q12[ 2 * MAX_LPC_ORDER ], /* I Short term prediction coefs */ > const opus_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ], /* I Long term prediction coefs */ >- const opus_int16 AR2_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I Noise shaping coefs */ >+ const opus_int16 AR_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I Noise shaping coefs */ > const opus_int HarmShapeGain_Q14[ MAX_NB_SUBFR ], /* I Long term shaping coefs */ > const opus_int Tilt_Q14[ MAX_NB_SUBFR ], /* I Spectral tilt */ > const opus_int32 LF_shp_Q14[ MAX_NB_SUBFR ], /* I Low frequency shaping coefs */ >@@ -117,8 +117,7 @@ void silk_NSQ_c > LSF_interpolation_flag = 1; > } > >- ALLOC( sLTP_Q15, >- psEncC->ltp_mem_length + psEncC->frame_length, opus_int32 ); >+ ALLOC( sLTP_Q15, psEncC->ltp_mem_length + psEncC->frame_length, opus_int32 ); > ALLOC( sLTP, psEncC->ltp_mem_length + psEncC->frame_length, opus_int16 ); > ALLOC( x_sc_Q10, psEncC->subfr_length, opus_int32 ); > /* Set up pointers to start of sub frame */ >@@ -128,7 +127,7 @@ void silk_NSQ_c > for( k = 0; k < psEncC->nb_subfr; k++ ) { > A_Q12 = &PredCoef_Q12[ (( k >> 1 ) | ( 1 - LSF_interpolation_flag )) * MAX_LPC_ORDER ]; > B_Q14 = <PCoef_Q14[ k * LTP_ORDER ]; >- AR_shp_Q13 = &AR2_Q13[ k * MAX_SHAPE_LPC_ORDER ]; >+ AR_shp_Q13 = &AR_Q13[ k * MAX_SHAPE_LPC_ORDER ]; > > /* Noise shape parameters */ > silk_assert( HarmShapeGain_Q14[ k ] >= 0 ); >@@ -154,13 +153,13 @@ void silk_NSQ_c > } > } > >- silk_nsq_scale_states( psEncC, NSQ, x_Q3, x_sc_Q10, sLTP, sLTP_Q15, k, LTP_scale_Q14, Gains_Q16, pitchL, psIndices->signalType ); >+ silk_nsq_scale_states( psEncC, NSQ, x16, x_sc_Q10, sLTP, sLTP_Q15, k, LTP_scale_Q14, Gains_Q16, pitchL, psIndices->signalType ); > > silk_noise_shape_quantizer( NSQ, psIndices->signalType, x_sc_Q10, pulses, pxq, sLTP_Q15, A_Q12, B_Q14, > AR_shp_Q13, lag, HarmShapeFIRPacked_Q14, Tilt_Q14[ k ], LF_shp_Q14[ k ], Gains_Q16[ k ], Lambda_Q10, > offset_Q10, psEncC->subfr_length, psEncC->shapingLPCOrder, psEncC->predictLPCOrder, psEncC->arch ); > >- x_Q3 += psEncC->subfr_length; >+ x16 += psEncC->subfr_length; > pulses += psEncC->subfr_length; > pxq += psEncC->subfr_length; > } >@@ -169,7 +168,6 @@ void silk_NSQ_c > NSQ->lagPrev = pitchL[ psEncC->nb_subfr - 1 ]; > > /* Save quantized speech and noise shaping signals */ >- /* DEBUG_STORE_DATA( enc.pcm, &NSQ->xq[ psEncC->ltp_mem_length ], psEncC->frame_length * sizeof( opus_int16 ) ) */ > silk_memmove( NSQ->xq, &NSQ->xq[ psEncC->frame_length ], psEncC->ltp_mem_length * sizeof( opus_int16 ) ); > silk_memmove( NSQ->sLTP_shp_Q14, &NSQ->sLTP_shp_Q14[ psEncC->frame_length ], psEncC->ltp_mem_length * sizeof( opus_int32 ) ); > RESTORE_STACK; >@@ -250,7 +248,7 @@ void silk_noise_shape_quantizer( > > /* Noise shape feedback */ > silk_assert( ( shapingLPCOrder & 1 ) == 0 ); /* check that order is even */ >- n_AR_Q12 = silk_NSQ_noise_shape_feedback_loop(psLPC_Q14, NSQ->sAR2_Q14, AR_shp_Q13, shapingLPCOrder, arch); >+ n_AR_Q12 = silk_NSQ_noise_shape_feedback_loop(&NSQ->sDiff_shp_Q14, NSQ->sAR2_Q14, AR_shp_Q13, shapingLPCOrder, arch); > > n_AR_Q12 = silk_SMLAWB( n_AR_Q12, NSQ->sLF_AR_shp_Q14, Tilt_Q14 ); > >@@ -279,14 +277,27 @@ void silk_noise_shape_quantizer( > r_Q10 = silk_SUB32( x_sc_Q10[ i ], tmp1 ); /* residual error Q10 */ > > /* Flip sign depending on dither */ >- if ( NSQ->rand_seed < 0 ) { >- r_Q10 = -r_Q10; >+ if( NSQ->rand_seed < 0 ) { >+ r_Q10 = -r_Q10; > } > r_Q10 = silk_LIMIT_32( r_Q10, -(31 << 10), 30 << 10 ); > > /* Find two quantization level candidates and measure their rate-distortion */ > q1_Q10 = silk_SUB32( r_Q10, offset_Q10 ); > q1_Q0 = silk_RSHIFT( q1_Q10, 10 ); >+ if (Lambda_Q10 > 2048) { >+ /* For aggressive RDO, the bias becomes more than one pulse. */ >+ int rdo_offset = Lambda_Q10/2 - 512; >+ if (q1_Q10 > rdo_offset) { >+ q1_Q0 = silk_RSHIFT( q1_Q10 - rdo_offset, 10 ); >+ } else if (q1_Q10 < -rdo_offset) { >+ q1_Q0 = silk_RSHIFT( q1_Q10 + rdo_offset, 10 ); >+ } else if (q1_Q10 < 0) { >+ q1_Q0 = -1; >+ } else { >+ q1_Q0 = 0; >+ } >+ } > if( q1_Q0 > 0 ) { > q1_Q10 = silk_SUB32( silk_LSHIFT( q1_Q0, 10 ), QUANT_LEVEL_ADJUST_Q10 ); > q1_Q10 = silk_ADD32( q1_Q10, offset_Q10 ); >@@ -337,7 +348,8 @@ void silk_noise_shape_quantizer( > /* Update states */ > psLPC_Q14++; > *psLPC_Q14 = xq_Q14; >- sLF_AR_shp_Q14 = silk_SUB_LSHIFT32( xq_Q14, n_AR_Q12, 2 ); >+ NSQ->sDiff_shp_Q14 = silk_SUB_LSHIFT32( xq_Q14, x_sc_Q10[ i ], 4 ); >+ sLF_AR_shp_Q14 = silk_SUB_LSHIFT32( NSQ->sDiff_shp_Q14, n_AR_Q12, 2 ); > NSQ->sLF_AR_shp_Q14 = sLF_AR_shp_Q14; > > NSQ->sLTP_shp_Q14[ NSQ->sLTP_shp_buf_idx ] = silk_SUB_LSHIFT32( sLF_AR_shp_Q14, n_LF_Q12, 2 ); >@@ -356,7 +368,7 @@ void silk_noise_shape_quantizer( > static OPUS_INLINE void silk_nsq_scale_states( > const silk_encoder_state *psEncC, /* I Encoder State */ > silk_nsq_state *NSQ, /* I/O NSQ state */ >- const opus_int32 x_Q3[], /* I input in Q3 */ >+ const opus_int16 x16[], /* I input */ > opus_int32 x_sc_Q10[], /* O input scaled with 1/Gain */ > const opus_int16 sLTP[], /* I re-whitened LTP state in Q0 */ > opus_int32 sLTP_Q15[], /* O LTP state matching scaled input */ >@@ -368,28 +380,18 @@ static OPUS_INLINE void silk_nsq_scale_states( > ) > { > opus_int i, lag; >- opus_int32 gain_adj_Q16, inv_gain_Q31, inv_gain_Q23; >+ opus_int32 gain_adj_Q16, inv_gain_Q31, inv_gain_Q26; > > lag = pitchL[ subfr ]; > inv_gain_Q31 = silk_INVERSE32_varQ( silk_max( Gains_Q16[ subfr ], 1 ), 47 ); > silk_assert( inv_gain_Q31 != 0 ); > >- /* Calculate gain adjustment factor */ >- if( Gains_Q16[ subfr ] != NSQ->prev_gain_Q16 ) { >- gain_adj_Q16 = silk_DIV32_varQ( NSQ->prev_gain_Q16, Gains_Q16[ subfr ], 16 ); >- } else { >- gain_adj_Q16 = (opus_int32)1 << 16; >- } >- > /* Scale input */ >- inv_gain_Q23 = silk_RSHIFT_ROUND( inv_gain_Q31, 8 ); >+ inv_gain_Q26 = silk_RSHIFT_ROUND( inv_gain_Q31, 5 ); > for( i = 0; i < psEncC->subfr_length; i++ ) { >- x_sc_Q10[ i ] = silk_SMULWW( x_Q3[ i ], inv_gain_Q23 ); >+ x_sc_Q10[ i ] = silk_SMULWW( x16[ i ], inv_gain_Q26 ); > } > >- /* Save inverse gain */ >- NSQ->prev_gain_Q16 = Gains_Q16[ subfr ]; >- > /* After rewhitening the LTP state is un-scaled, so scale with inv_gain_Q16 */ > if( NSQ->rewhite_flag ) { > if( subfr == 0 ) { >@@ -403,7 +405,9 @@ static OPUS_INLINE void silk_nsq_scale_states( > } > > /* Adjust for changing gain */ >- if( gain_adj_Q16 != (opus_int32)1 << 16 ) { >+ if( Gains_Q16[ subfr ] != NSQ->prev_gain_Q16 ) { >+ gain_adj_Q16 = silk_DIV32_varQ( NSQ->prev_gain_Q16, Gains_Q16[ subfr ], 16 ); >+ > /* Scale long-term shaping state */ > for( i = NSQ->sLTP_shp_buf_idx - psEncC->ltp_mem_length; i < NSQ->sLTP_shp_buf_idx; i++ ) { > NSQ->sLTP_shp_Q14[ i ] = silk_SMULWW( gain_adj_Q16, NSQ->sLTP_shp_Q14[ i ] ); >@@ -417,6 +421,7 @@ static OPUS_INLINE void silk_nsq_scale_states( > } > > NSQ->sLF_AR_shp_Q14 = silk_SMULWW( gain_adj_Q16, NSQ->sLF_AR_shp_Q14 ); >+ NSQ->sDiff_shp_Q14 = silk_SMULWW( gain_adj_Q16, NSQ->sDiff_shp_Q14 ); > > /* Scale short-term prediction and shaping states */ > for( i = 0; i < NSQ_LPC_BUF_LENGTH; i++ ) { >@@ -425,5 +430,8 @@ static OPUS_INLINE void silk_nsq_scale_states( > for( i = 0; i < MAX_SHAPE_LPC_ORDER; i++ ) { > NSQ->sAR2_Q14[ i ] = silk_SMULWW( gain_adj_Q16, NSQ->sAR2_Q14[ i ] ); > } >+ >+ /* Save inverse gain */ >+ NSQ->prev_gain_Q16 = Gains_Q16[ subfr ]; > } > } >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/NSQ_del_dec.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/NSQ_del_dec.c >index ab6feeac98702abaa56e12043a55e9a25f96dffc..599e25f1c8bbf3cba988f660a61064a8665e6b67 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/NSQ_del_dec.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/NSQ_del_dec.c >@@ -43,6 +43,7 @@ typedef struct { > opus_int32 Shape_Q14[ DECISION_DELAY ]; > opus_int32 sAR2_Q14[ MAX_SHAPE_LPC_ORDER ]; > opus_int32 LF_AR_Q14; >+ opus_int32 Diff_Q14; > opus_int32 Seed; > opus_int32 SeedInit; > opus_int32 RD_Q10; >@@ -53,6 +54,7 @@ typedef struct { > opus_int32 RD_Q10; > opus_int32 xq_Q14; > opus_int32 LF_AR_Q14; >+ opus_int32 Diff_Q14; > opus_int32 sLTP_shp_Q14; > opus_int32 LPC_exc_Q14; > } NSQ_sample_struct; >@@ -66,7 +68,7 @@ static OPUS_INLINE void silk_nsq_del_dec_scale_states( > const silk_encoder_state *psEncC, /* I Encoder State */ > silk_nsq_state *NSQ, /* I/O NSQ state */ > NSQ_del_dec_struct psDelDec[], /* I/O Delayed decision states */ >- const opus_int32 x_Q3[], /* I Input in Q3 */ >+ const opus_int16 x16[], /* I Input */ > opus_int32 x_sc_Q10[], /* O Input scaled with 1/Gain in Q10 */ > const opus_int16 sLTP[], /* I Re-whitened LTP state in Q0 */ > opus_int32 sLTP_Q15[], /* O LTP state matching scaled input */ >@@ -107,20 +109,20 @@ static OPUS_INLINE void silk_noise_shape_quantizer_del_dec( > opus_int predictLPCOrder, /* I Prediction filter order */ > opus_int warping_Q16, /* I */ > opus_int nStatesDelayedDecision, /* I Number of states in decision tree */ >- opus_int *smpl_buf_idx, /* I Index to newest samples in buffers */ >+ opus_int *smpl_buf_idx, /* I/O Index to newest samples in buffers */ > opus_int decisionDelay, /* I */ > int arch /* I */ > ); > > void silk_NSQ_del_dec_c( >- const silk_encoder_state *psEncC, /* I/O Encoder State */ >+ const silk_encoder_state *psEncC, /* I Encoder State */ > silk_nsq_state *NSQ, /* I/O NSQ state */ > SideInfoIndices *psIndices, /* I/O Quantization Indices */ >- const opus_int32 x_Q3[], /* I Prefiltered input signal */ >+ const opus_int16 x16[], /* I Input */ > opus_int8 pulses[], /* O Quantized pulse signal */ > const opus_int16 PredCoef_Q12[ 2 * MAX_LPC_ORDER ], /* I Short term prediction coefs */ > const opus_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ], /* I Long term prediction coefs */ >- const opus_int16 AR2_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I Noise shaping coefs */ >+ const opus_int16 AR_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I Noise shaping coefs */ > const opus_int HarmShapeGain_Q14[ MAX_NB_SUBFR ], /* I Long term shaping coefs */ > const opus_int Tilt_Q14[ MAX_NB_SUBFR ], /* I Spectral tilt */ > const opus_int32 LF_shp_Q14[ MAX_NB_SUBFR ], /* I Low frequency shaping coefs */ >@@ -159,6 +161,7 @@ void silk_NSQ_del_dec_c( > psDD->SeedInit = psDD->Seed; > psDD->RD_Q10 = 0; > psDD->LF_AR_Q14 = NSQ->sLF_AR_shp_Q14; >+ psDD->Diff_Q14 = NSQ->sDiff_shp_Q14; > psDD->Shape_Q14[ 0 ] = NSQ->sLTP_shp_Q14[ psEncC->ltp_mem_length - 1 ]; > silk_memcpy( psDD->sLPC_Q14, NSQ->sLPC_Q14, NSQ_LPC_BUF_LENGTH * sizeof( opus_int32 ) ); > silk_memcpy( psDD->sAR2_Q14, NSQ->sAR2_Q14, sizeof( NSQ->sAR2_Q14 ) ); >@@ -186,8 +189,7 @@ void silk_NSQ_del_dec_c( > LSF_interpolation_flag = 1; > } > >- ALLOC( sLTP_Q15, >- psEncC->ltp_mem_length + psEncC->frame_length, opus_int32 ); >+ ALLOC( sLTP_Q15, psEncC->ltp_mem_length + psEncC->frame_length, opus_int32 ); > ALLOC( sLTP, psEncC->ltp_mem_length + psEncC->frame_length, opus_int16 ); > ALLOC( x_sc_Q10, psEncC->subfr_length, opus_int32 ); > ALLOC( delayedGain_Q10, DECISION_DELAY, opus_int32 ); >@@ -199,7 +201,7 @@ void silk_NSQ_del_dec_c( > for( k = 0; k < psEncC->nb_subfr; k++ ) { > A_Q12 = &PredCoef_Q12[ ( ( k >> 1 ) | ( 1 - LSF_interpolation_flag ) ) * MAX_LPC_ORDER ]; > B_Q14 = <PCoef_Q14[ k * LTP_ORDER ]; >- AR_shp_Q13 = &AR2_Q13[ k * MAX_SHAPE_LPC_ORDER ]; >+ AR_shp_Q13 = &AR_Q13[ k * MAX_SHAPE_LPC_ORDER ]; > > /* Noise shape parameters */ > silk_assert( HarmShapeGain_Q14[ k ] >= 0 ); >@@ -235,7 +237,8 @@ void silk_NSQ_del_dec_c( > psDD = &psDelDec[ Winner_ind ]; > last_smple_idx = smpl_buf_idx + decisionDelay; > for( i = 0; i < decisionDelay; i++ ) { >- last_smple_idx = ( last_smple_idx - 1 ) & DECISION_DELAY_MASK; >+ last_smple_idx = ( last_smple_idx - 1 ) % DECISION_DELAY; >+ if( last_smple_idx < 0 ) last_smple_idx += DECISION_DELAY; > pulses[ i - decisionDelay ] = (opus_int8)silk_RSHIFT_ROUND( psDD->Q_Q10[ last_smple_idx ], 10 ); > pxq[ i - decisionDelay ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( > silk_SMULWW( psDD->Xq_Q14[ last_smple_idx ], Gains_Q16[ 1 ] ), 14 ) ); >@@ -257,7 +260,7 @@ void silk_NSQ_del_dec_c( > } > } > >- silk_nsq_del_dec_scale_states( psEncC, NSQ, psDelDec, x_Q3, x_sc_Q10, sLTP, sLTP_Q15, k, >+ silk_nsq_del_dec_scale_states( psEncC, NSQ, psDelDec, x16, x_sc_Q10, sLTP, sLTP_Q15, k, > psEncC->nStatesDelayedDecision, LTP_scale_Q14, Gains_Q16, pitchL, psIndices->signalType, decisionDelay ); > > silk_noise_shape_quantizer_del_dec( NSQ, psDelDec, psIndices->signalType, x_sc_Q10, pulses, pxq, sLTP_Q15, >@@ -265,7 +268,7 @@ void silk_NSQ_del_dec_c( > Gains_Q16[ k ], Lambda_Q10, offset_Q10, psEncC->subfr_length, subfr++, psEncC->shapingLPCOrder, > psEncC->predictLPCOrder, psEncC->warping_Q16, psEncC->nStatesDelayedDecision, &smpl_buf_idx, decisionDelay, psEncC->arch ); > >- x_Q3 += psEncC->subfr_length; >+ x16 += psEncC->subfr_length; > pulses += psEncC->subfr_length; > pxq += psEncC->subfr_length; > } >@@ -286,7 +289,9 @@ void silk_NSQ_del_dec_c( > last_smple_idx = smpl_buf_idx + decisionDelay; > Gain_Q10 = silk_RSHIFT32( Gains_Q16[ psEncC->nb_subfr - 1 ], 6 ); > for( i = 0; i < decisionDelay; i++ ) { >- last_smple_idx = ( last_smple_idx - 1 ) & DECISION_DELAY_MASK; >+ last_smple_idx = ( last_smple_idx - 1 ) % DECISION_DELAY; >+ if( last_smple_idx < 0 ) last_smple_idx += DECISION_DELAY; >+ > pulses[ i - decisionDelay ] = (opus_int8)silk_RSHIFT_ROUND( psDD->Q_Q10[ last_smple_idx ], 10 ); > pxq[ i - decisionDelay ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( > silk_SMULWW( psDD->Xq_Q14[ last_smple_idx ], Gain_Q10 ), 8 ) ); >@@ -297,10 +302,10 @@ void silk_NSQ_del_dec_c( > > /* Update states */ > NSQ->sLF_AR_shp_Q14 = psDD->LF_AR_Q14; >+ NSQ->sDiff_shp_Q14 = psDD->Diff_Q14; > NSQ->lagPrev = pitchL[ psEncC->nb_subfr - 1 ]; > > /* Save quantized speech signal */ >- /* DEBUG_STORE_DATA( enc.pcm, &NSQ->xq[psEncC->ltp_mem_length], psEncC->frame_length * sizeof( opus_int16 ) ) */ > silk_memmove( NSQ->xq, &NSQ->xq[ psEncC->frame_length ], psEncC->ltp_mem_length * sizeof( opus_int16 ) ); > silk_memmove( NSQ->sLTP_shp_Q14, &NSQ->sLTP_shp_Q14[ psEncC->frame_length ], psEncC->ltp_mem_length * sizeof( opus_int32 ) ); > RESTORE_STACK; >@@ -335,7 +340,7 @@ static OPUS_INLINE void silk_noise_shape_quantizer_del_dec( > opus_int predictLPCOrder, /* I Prediction filter order */ > opus_int warping_Q16, /* I */ > opus_int nStatesDelayedDecision, /* I Number of states in decision tree */ >- opus_int *smpl_buf_idx, /* I Index to newest samples in buffers */ >+ opus_int *smpl_buf_idx, /* I/O Index to newest samples in buffers */ > opus_int decisionDelay, /* I */ > int arch /* I */ > ) >@@ -389,7 +394,7 @@ static OPUS_INLINE void silk_noise_shape_quantizer_del_dec( > /* Long-term shaping */ > if( lag > 0 ) { > /* Symmetric, packed FIR coefficients */ >- n_LTP_Q14 = silk_SMULWB( silk_ADD32( shp_lag_ptr[ 0 ], shp_lag_ptr[ -2 ] ), HarmShapeFIRPacked_Q14 ); >+ n_LTP_Q14 = silk_SMULWB( silk_ADD_SAT32( shp_lag_ptr[ 0 ], shp_lag_ptr[ -2 ] ), HarmShapeFIRPacked_Q14 ); > n_LTP_Q14 = silk_SMLAWT( n_LTP_Q14, shp_lag_ptr[ -1 ], HarmShapeFIRPacked_Q14 ); > n_LTP_Q14 = silk_SUB_LSHIFT32( LTP_pred_Q14, n_LTP_Q14, 2 ); /* Q12 -> Q14 */ > shp_lag_ptr++; >@@ -416,7 +421,7 @@ static OPUS_INLINE void silk_noise_shape_quantizer_del_dec( > /* Noise shape feedback */ > silk_assert( ( shapingLPCOrder & 1 ) == 0 ); /* check that order is even */ > /* Output of lowpass section */ >- tmp2 = silk_SMLAWB( psLPC_Q14[ 0 ], psDD->sAR2_Q14[ 0 ], warping_Q16 ); >+ tmp2 = silk_SMLAWB( psDD->Diff_Q14, psDD->sAR2_Q14[ 0 ], warping_Q16 ); > /* Output of allpass section */ > tmp1 = silk_SMLAWB( psDD->sAR2_Q14[ 0 ], psDD->sAR2_Q14[ 1 ] - tmp2, warping_Q16 ); > psDD->sAR2_Q14[ 0 ] = tmp2; >@@ -462,6 +467,19 @@ static OPUS_INLINE void silk_noise_shape_quantizer_del_dec( > /* Find two quantization level candidates and measure their rate-distortion */ > q1_Q10 = silk_SUB32( r_Q10, offset_Q10 ); > q1_Q0 = silk_RSHIFT( q1_Q10, 10 ); >+ if (Lambda_Q10 > 2048) { >+ /* For aggressive RDO, the bias becomes more than one pulse. */ >+ int rdo_offset = Lambda_Q10/2 - 512; >+ if (q1_Q10 > rdo_offset) { >+ q1_Q0 = silk_RSHIFT( q1_Q10 - rdo_offset, 10 ); >+ } else if (q1_Q10 < -rdo_offset) { >+ q1_Q0 = silk_RSHIFT( q1_Q10 + rdo_offset, 10 ); >+ } else if (q1_Q10 < 0) { >+ q1_Q0 = -1; >+ } else { >+ q1_Q0 = 0; >+ } >+ } > if( q1_Q0 > 0 ) { > q1_Q10 = silk_SUB32( silk_LSHIFT( q1_Q0, 10 ), QUANT_LEVEL_ADJUST_Q10 ); > q1_Q10 = silk_ADD32( q1_Q10, offset_Q10 ); >@@ -515,7 +533,8 @@ static OPUS_INLINE void silk_noise_shape_quantizer_del_dec( > xq_Q14 = silk_ADD32( LPC_exc_Q14, LPC_pred_Q14 ); > > /* Update states */ >- sLF_AR_shp_Q14 = silk_SUB32( xq_Q14, n_AR_Q14 ); >+ psSS[ 0 ].Diff_Q14 = silk_SUB_LSHIFT32( xq_Q14, x_Q10[ i ], 4 ); >+ sLF_AR_shp_Q14 = silk_SUB32( psSS[ 0 ].Diff_Q14, n_AR_Q14 ); > psSS[ 0 ].sLTP_shp_Q14 = silk_SUB32( sLF_AR_shp_Q14, n_LF_Q14 ); > psSS[ 0 ].LF_AR_Q14 = sLF_AR_shp_Q14; > psSS[ 0 ].LPC_exc_Q14 = LPC_exc_Q14; >@@ -529,21 +548,22 @@ static OPUS_INLINE void silk_noise_shape_quantizer_del_dec( > exc_Q14 = -exc_Q14; > } > >- > /* Add predictions */ > LPC_exc_Q14 = silk_ADD32( exc_Q14, LTP_pred_Q14 ); > xq_Q14 = silk_ADD32( LPC_exc_Q14, LPC_pred_Q14 ); > > /* Update states */ >- sLF_AR_shp_Q14 = silk_SUB32( xq_Q14, n_AR_Q14 ); >+ psSS[ 1 ].Diff_Q14 = silk_SUB_LSHIFT32( xq_Q14, x_Q10[ i ], 4 ); >+ sLF_AR_shp_Q14 = silk_SUB32( psSS[ 1 ].Diff_Q14, n_AR_Q14 ); > psSS[ 1 ].sLTP_shp_Q14 = silk_SUB32( sLF_AR_shp_Q14, n_LF_Q14 ); > psSS[ 1 ].LF_AR_Q14 = sLF_AR_shp_Q14; > psSS[ 1 ].LPC_exc_Q14 = LPC_exc_Q14; > psSS[ 1 ].xq_Q14 = xq_Q14; > } > >- *smpl_buf_idx = ( *smpl_buf_idx - 1 ) & DECISION_DELAY_MASK; /* Index to newest samples */ >- last_smple_idx = ( *smpl_buf_idx + decisionDelay ) & DECISION_DELAY_MASK; /* Index to decisionDelay old samples */ >+ *smpl_buf_idx = ( *smpl_buf_idx - 1 ) % DECISION_DELAY; >+ if( *smpl_buf_idx < 0 ) *smpl_buf_idx += DECISION_DELAY; >+ last_smple_idx = ( *smpl_buf_idx + decisionDelay ) % DECISION_DELAY; > > /* Find winner */ > RDmin_Q10 = psSampleState[ 0 ][ 0 ].RD_Q10; >@@ -607,6 +627,7 @@ static OPUS_INLINE void silk_noise_shape_quantizer_del_dec( > psDD = &psDelDec[ k ]; > psSS = &psSampleState[ k ][ 0 ]; > psDD->LF_AR_Q14 = psSS->LF_AR_Q14; >+ psDD->Diff_Q14 = psSS->Diff_Q14; > psDD->sLPC_Q14[ NSQ_LPC_BUF_LENGTH + i ] = psSS->xq_Q14; > psDD->Xq_Q14[ *smpl_buf_idx ] = psSS->xq_Q14; > psDD->Q_Q10[ *smpl_buf_idx ] = psSS->Q_Q10; >@@ -631,7 +652,7 @@ static OPUS_INLINE void silk_nsq_del_dec_scale_states( > const silk_encoder_state *psEncC, /* I Encoder State */ > silk_nsq_state *NSQ, /* I/O NSQ state */ > NSQ_del_dec_struct psDelDec[], /* I/O Delayed decision states */ >- const opus_int32 x_Q3[], /* I Input in Q3 */ >+ const opus_int16 x16[], /* I Input */ > opus_int32 x_sc_Q10[], /* O Input scaled with 1/Gain in Q10 */ > const opus_int16 sLTP[], /* I Re-whitened LTP state in Q0 */ > opus_int32 sLTP_Q15[], /* O LTP state matching scaled input */ >@@ -645,29 +666,19 @@ static OPUS_INLINE void silk_nsq_del_dec_scale_states( > ) > { > opus_int i, k, lag; >- opus_int32 gain_adj_Q16, inv_gain_Q31, inv_gain_Q23; >+ opus_int32 gain_adj_Q16, inv_gain_Q31, inv_gain_Q26; > NSQ_del_dec_struct *psDD; > > lag = pitchL[ subfr ]; > inv_gain_Q31 = silk_INVERSE32_varQ( silk_max( Gains_Q16[ subfr ], 1 ), 47 ); > silk_assert( inv_gain_Q31 != 0 ); > >- /* Calculate gain adjustment factor */ >- if( Gains_Q16[ subfr ] != NSQ->prev_gain_Q16 ) { >- gain_adj_Q16 = silk_DIV32_varQ( NSQ->prev_gain_Q16, Gains_Q16[ subfr ], 16 ); >- } else { >- gain_adj_Q16 = (opus_int32)1 << 16; >- } >- > /* Scale input */ >- inv_gain_Q23 = silk_RSHIFT_ROUND( inv_gain_Q31, 8 ); >+ inv_gain_Q26 = silk_RSHIFT_ROUND( inv_gain_Q31, 5 ); > for( i = 0; i < psEncC->subfr_length; i++ ) { >- x_sc_Q10[ i ] = silk_SMULWW( x_Q3[ i ], inv_gain_Q23 ); >+ x_sc_Q10[ i ] = silk_SMULWW( x16[ i ], inv_gain_Q26 ); > } > >- /* Save inverse gain */ >- NSQ->prev_gain_Q16 = Gains_Q16[ subfr ]; >- > /* After rewhitening the LTP state is un-scaled, so scale with inv_gain_Q16 */ > if( NSQ->rewhite_flag ) { > if( subfr == 0 ) { >@@ -681,7 +692,9 @@ static OPUS_INLINE void silk_nsq_del_dec_scale_states( > } > > /* Adjust for changing gain */ >- if( gain_adj_Q16 != (opus_int32)1 << 16 ) { >+ if( Gains_Q16[ subfr ] != NSQ->prev_gain_Q16 ) { >+ gain_adj_Q16 = silk_DIV32_varQ( NSQ->prev_gain_Q16, Gains_Q16[ subfr ], 16 ); >+ > /* Scale long-term shaping state */ > for( i = NSQ->sLTP_shp_buf_idx - psEncC->ltp_mem_length; i < NSQ->sLTP_shp_buf_idx; i++ ) { > NSQ->sLTP_shp_Q14[ i ] = silk_SMULWW( gain_adj_Q16, NSQ->sLTP_shp_Q14[ i ] ); >@@ -699,6 +712,7 @@ static OPUS_INLINE void silk_nsq_del_dec_scale_states( > > /* Scale scalar states */ > psDD->LF_AR_Q14 = silk_SMULWW( gain_adj_Q16, psDD->LF_AR_Q14 ); >+ psDD->Diff_Q14 = silk_SMULWW( gain_adj_Q16, psDD->Diff_Q14 ); > > /* Scale short-term prediction and shaping states */ > for( i = 0; i < NSQ_LPC_BUF_LENGTH; i++ ) { >@@ -712,5 +726,8 @@ static OPUS_INLINE void silk_nsq_del_dec_scale_states( > psDD->Shape_Q14[ i ] = silk_SMULWW( gain_adj_Q16, psDD->Shape_Q14[ i ] ); > } > } >+ >+ /* Save inverse gain */ >+ NSQ->prev_gain_Q16 = Gains_Q16[ subfr ]; > } > } >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/PLC.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/PLC.c >index fb6ea887b7ee254b1b858a6a52bc5845e0d5738d..a3e55ea765ef4f4b071901555d33d03c0633eae2 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/PLC.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/PLC.c >@@ -275,7 +275,7 @@ static OPUS_INLINE void silk_PLC_conceal( > /* Reduce random noise for unvoiced frames with high LPC gain */ > opus_int32 invGain_Q30, down_scale_Q30; > >- invGain_Q30 = silk_LPC_inverse_pred_gain( psPLC->prevLPC_Q12, psDec->LPC_order ); >+ invGain_Q30 = silk_LPC_inverse_pred_gain( psPLC->prevLPC_Q12, psDec->LPC_order, arch ); > > down_scale_Q30 = silk_min_32( silk_RSHIFT( (opus_int32)1 << 30, LOG2_INV_LPC_GAIN_HIGH_THRES ), invGain_Q30 ); > down_scale_Q30 = silk_max_32( silk_RSHIFT( (opus_int32)1 << 30, LOG2_INV_LPC_GAIN_LOW_THRES ), down_scale_Q30 ); >@@ -328,8 +328,10 @@ static OPUS_INLINE void silk_PLC_conceal( > for( j = 0; j < LTP_ORDER; j++ ) { > B_Q14[ j ] = silk_RSHIFT( silk_SMULBB( harm_Gain_Q15, B_Q14[ j ] ), 15 ); > } >- /* Gradually reduce excitation gain */ >- rand_scale_Q14 = silk_RSHIFT( silk_SMULBB( rand_scale_Q14, rand_Gain_Q15 ), 15 ); >+ if ( psDec->indices.signalType != TYPE_NO_VOICE_ACTIVITY ) { >+ /* Gradually reduce excitation gain */ >+ rand_scale_Q14 = silk_RSHIFT( silk_SMULBB( rand_scale_Q14, rand_Gain_Q15 ), 15 ); >+ } > > /* Slowly increase pitch lag */ > psPLC->pitchL_Q8 = silk_SMLAWB( psPLC->pitchL_Q8, psPLC->pitchL_Q8, PITCH_DRIFT_FAC_Q16 ); >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/SigProc_FIX.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/SigProc_FIX.h >index b63299441e930a385e97ef9c13d5755cc0f9c413..f9ae326326d31a81cdf9c4ff2bb5aa827a4ebac1 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/SigProc_FIX.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/SigProc_FIX.h >@@ -35,7 +35,7 @@ extern "C" > > /*#define silk_MACRO_COUNT */ /* Used to enable WMOPS counting */ > >-#define SILK_MAX_ORDER_LPC 16 /* max order of the LPC analysis in schur() and k2a() */ >+#define SILK_MAX_ORDER_LPC 24 /* max order of the LPC analysis in schur() and k2a() */ > > #include <string.h> /* for memset(), memcpy(), memmove() */ > #include "typedef.h" >@@ -47,6 +47,11 @@ extern "C" > #include "x86/SigProc_FIX_sse.h" > #endif > >+#if (defined(OPUS_ARM_ASM) || defined(OPUS_ARM_MAY_HAVE_NEON_INTR)) >+#include "arm/biquad_alt_arm.h" >+#include "arm/LPC_inv_pred_gain_arm.h" >+#endif >+ > /********************************************************************/ > /* SIGNAL PROCESSING FUNCTIONS */ > /********************************************************************/ >@@ -96,14 +101,22 @@ void silk_resampler_down2_3( > * slower than biquad() but uses more precise coefficients > * can handle (slowly) varying coefficients > */ >-void silk_biquad_alt( >+void silk_biquad_alt_stride1( > const opus_int16 *in, /* I input signal */ > const opus_int32 *B_Q28, /* I MA coefficients [3] */ > const opus_int32 *A_Q28, /* I AR coefficients [2] */ > opus_int32 *S, /* I/O State vector [2] */ > opus_int16 *out, /* O output signal */ >- const opus_int32 len, /* I signal length (must be even) */ >- opus_int stride /* I Operate on interleaved signal if > 1 */ >+ const opus_int32 len /* I signal length (must be even) */ >+); >+ >+void silk_biquad_alt_stride2_c( >+ const opus_int16 *in, /* I input signal */ >+ const opus_int32 *B_Q28, /* I MA coefficients [3] */ >+ const opus_int32 *A_Q28, /* I AR coefficients [2] */ >+ opus_int32 *S, /* I/O State vector [4] */ >+ opus_int16 *out, /* O output signal */ >+ const opus_int32 len /* I signal length (must be even) */ > ); > > /* Variable order MA prediction error filter. */ >@@ -132,17 +145,11 @@ void silk_bwexpander_32( > > /* Compute inverse of LPC prediction gain, and */ > /* test if LPC coefficients are stable (all poles within unit circle) */ >-opus_int32 silk_LPC_inverse_pred_gain( /* O Returns inverse prediction gain in energy domain, Q30 */ >+opus_int32 silk_LPC_inverse_pred_gain_c( /* O Returns inverse prediction gain in energy domain, Q30 */ > const opus_int16 *A_Q12, /* I Prediction coefficients, Q12 [order] */ > const opus_int order /* I Prediction order */ > ); > >-/* For input in Q24 domain */ >-opus_int32 silk_LPC_inverse_pred_gain_Q24( /* O Returns inverse prediction gain in energy domain, Q30 */ >- const opus_int32 *A_Q24, /* I Prediction coefficients [order] */ >- const opus_int order /* I Prediction order */ >-); >- > /* Split signal in two decimated bands using first-order allpass filters */ > void silk_ana_filt_bank_1( > const opus_int16 *in, /* I Input signal [N] */ >@@ -152,6 +159,14 @@ void silk_ana_filt_bank_1( > const opus_int32 N /* I Number of input samples */ > ); > >+#if !defined(OVERRIDE_silk_biquad_alt_stride2) >+#define silk_biquad_alt_stride2(in, B_Q28, A_Q28, S, out, len, arch) ((void)(arch), silk_biquad_alt_stride2_c(in, B_Q28, A_Q28, S, out, len)) >+#endif >+ >+#if !defined(OVERRIDE_silk_LPC_inverse_pred_gain) >+#define silk_LPC_inverse_pred_gain(A_Q12, order, arch) ((void)(arch), silk_LPC_inverse_pred_gain_c(A_Q12, order)) >+#endif >+ > /********************************************************************/ > /* SCALAR FUNCTIONS */ > /********************************************************************/ >@@ -271,7 +286,17 @@ void silk_A2NLSF( > void silk_NLSF2A( > opus_int16 *a_Q12, /* O monic whitening filter coefficients in Q12, [ d ] */ > const opus_int16 *NLSF, /* I normalized line spectral frequencies in Q15, [ d ] */ >- const opus_int d /* I filter order (should be even) */ >+ const opus_int d, /* I filter order (should be even) */ >+ int arch /* I Run-time architecture */ >+); >+ >+/* Convert int32 coefficients to int16 coefs and make sure there's no wrap-around */ >+void silk_LPC_fit( >+ opus_int16 *a_QOUT, /* O Output signal */ >+ opus_int32 *a_QIN, /* I/O Input signal */ >+ const opus_int QOUT, /* I Input Q domain */ >+ const opus_int QIN, /* I Input Q domain */ >+ const opus_int d /* I Filter order */ > ); > > void silk_insertion_sort_increasing( >@@ -471,8 +496,7 @@ static OPUS_INLINE opus_int32 silk_ROR32( opus_int32 a32, opus_int rot ) > /* Add with saturation for positive input values */ > #define silk_ADD_POS_SAT8(a, b) ((((a)+(b)) & 0x80) ? silk_int8_MAX : ((a)+(b))) > #define silk_ADD_POS_SAT16(a, b) ((((a)+(b)) & 0x8000) ? silk_int16_MAX : ((a)+(b))) >-#define silk_ADD_POS_SAT32(a, b) ((((a)+(b)) & 0x80000000) ? silk_int32_MAX : ((a)+(b))) >-#define silk_ADD_POS_SAT64(a, b) ((((a)+(b)) & 0x8000000000000000LL) ? silk_int64_MAX : ((a)+(b))) >+#define silk_ADD_POS_SAT32(a, b) ((((opus_uint32)(a)+(opus_uint32)(b)) & 0x80000000) ? silk_int32_MAX : ((a)+(b))) > > #define silk_LSHIFT8(a, shift) ((opus_int8)((opus_uint8)(a)<<(shift))) /* shift >= 0, shift < 8 */ > #define silk_LSHIFT16(a, shift) ((opus_int16)((opus_uint16)(a)<<(shift))) /* shift >= 0, shift < 16 */ >@@ -572,7 +596,9 @@ static OPUS_INLINE opus_int64 silk_max_64(opus_int64 a, opus_int64 b) > /* Make sure to store the result as the seed for the next call (also in between */ > /* frames), otherwise result won't be random at all. When only using some of the */ > /* bits, take the most significant bits by right-shifting. */ >-#define silk_RAND(seed) (silk_MLA_ovflw(907633515, (seed), 196314165)) >+#define RAND_MULTIPLIER 196314165 >+#define RAND_INCREMENT 907633515 >+#define silk_RAND(seed) (silk_MLA_ovflw((RAND_INCREMENT), (seed), (RAND_MULTIPLIER))) > > /* Add some multiplication functions that can be easily mapped to ARM. */ > >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/VQ_WMat_EC.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/VQ_WMat_EC.c >index 7983f1db80ccceca58bd7a762ea9054cfa54b6b9..0f3d545c4ef8c133ee515336e19c16fa6272dbe3 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/VQ_WMat_EC.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/VQ_WMat_EC.c >@@ -34,84 +34,95 @@ POSSIBILITY OF SUCH DAMAGE. > /* Entropy constrained matrix-weighted VQ, hard-coded to 5-element vectors, for a single input data vector */ > void silk_VQ_WMat_EC_c( > opus_int8 *ind, /* O index of best codebook vector */ >- opus_int32 *rate_dist_Q14, /* O best weighted quant error + mu * rate */ >+ opus_int32 *res_nrg_Q15, /* O best residual energy */ >+ opus_int32 *rate_dist_Q8, /* O best total bitrate */ > opus_int *gain_Q7, /* O sum of absolute LTP coefficients */ >- const opus_int16 *in_Q14, /* I input vector to be quantized */ >- const opus_int32 *W_Q18, /* I weighting matrix */ >+ const opus_int32 *XX_Q17, /* I correlation matrix */ >+ const opus_int32 *xX_Q17, /* I correlation vector */ > const opus_int8 *cb_Q7, /* I codebook */ > const opus_uint8 *cb_gain_Q7, /* I codebook effective gain */ > const opus_uint8 *cl_Q5, /* I code length for each codebook vector */ >- const opus_int mu_Q9, /* I tradeoff betw. weighted error and rate */ >+ const opus_int subfr_len, /* I number of samples per subframe */ > const opus_int32 max_gain_Q7, /* I maximum sum of absolute LTP coefficients */ >- opus_int L /* I number of vectors in codebook */ >+ const opus_int L /* I number of vectors in codebook */ > ) > { > opus_int k, gain_tmp_Q7; > const opus_int8 *cb_row_Q7; >- opus_int16 diff_Q14[ 5 ]; >- opus_int32 sum1_Q14, sum2_Q16; >+ opus_int32 neg_xX_Q24[ 5 ]; >+ opus_int32 sum1_Q15, sum2_Q24; >+ opus_int32 bits_res_Q8, bits_tot_Q8; >+ >+ /* Negate and convert to new Q domain */ >+ neg_xX_Q24[ 0 ] = -silk_LSHIFT32( xX_Q17[ 0 ], 7 ); >+ neg_xX_Q24[ 1 ] = -silk_LSHIFT32( xX_Q17[ 1 ], 7 ); >+ neg_xX_Q24[ 2 ] = -silk_LSHIFT32( xX_Q17[ 2 ], 7 ); >+ neg_xX_Q24[ 3 ] = -silk_LSHIFT32( xX_Q17[ 3 ], 7 ); >+ neg_xX_Q24[ 4 ] = -silk_LSHIFT32( xX_Q17[ 4 ], 7 ); > > /* Loop over codebook */ >- *rate_dist_Q14 = silk_int32_MAX; >+ *rate_dist_Q8 = silk_int32_MAX; >+ *res_nrg_Q15 = silk_int32_MAX; > cb_row_Q7 = cb_Q7; >+ /* In things go really bad, at least *ind is set to something safe. */ >+ *ind = 0; > for( k = 0; k < L; k++ ) { >+ opus_int32 penalty; > gain_tmp_Q7 = cb_gain_Q7[k]; >- >- diff_Q14[ 0 ] = in_Q14[ 0 ] - silk_LSHIFT( cb_row_Q7[ 0 ], 7 ); >- diff_Q14[ 1 ] = in_Q14[ 1 ] - silk_LSHIFT( cb_row_Q7[ 1 ], 7 ); >- diff_Q14[ 2 ] = in_Q14[ 2 ] - silk_LSHIFT( cb_row_Q7[ 2 ], 7 ); >- diff_Q14[ 3 ] = in_Q14[ 3 ] - silk_LSHIFT( cb_row_Q7[ 3 ], 7 ); >- diff_Q14[ 4 ] = in_Q14[ 4 ] - silk_LSHIFT( cb_row_Q7[ 4 ], 7 ); >- > /* Weighted rate */ >- sum1_Q14 = silk_SMULBB( mu_Q9, cl_Q5[ k ] ); >+ /* Quantization error: 1 - 2 * xX * cb + cb' * XX * cb */ >+ sum1_Q15 = SILK_FIX_CONST( 1.001, 15 ); > > /* Penalty for too large gain */ >- sum1_Q14 = silk_ADD_LSHIFT32( sum1_Q14, silk_max( silk_SUB32( gain_tmp_Q7, max_gain_Q7 ), 0 ), 10 ); >- >- silk_assert( sum1_Q14 >= 0 ); >- >- /* first row of W_Q18 */ >- sum2_Q16 = silk_SMULWB( W_Q18[ 1 ], diff_Q14[ 1 ] ); >- sum2_Q16 = silk_SMLAWB( sum2_Q16, W_Q18[ 2 ], diff_Q14[ 2 ] ); >- sum2_Q16 = silk_SMLAWB( sum2_Q16, W_Q18[ 3 ], diff_Q14[ 3 ] ); >- sum2_Q16 = silk_SMLAWB( sum2_Q16, W_Q18[ 4 ], diff_Q14[ 4 ] ); >- sum2_Q16 = silk_LSHIFT( sum2_Q16, 1 ); >- sum2_Q16 = silk_SMLAWB( sum2_Q16, W_Q18[ 0 ], diff_Q14[ 0 ] ); >- sum1_Q14 = silk_SMLAWB( sum1_Q14, sum2_Q16, diff_Q14[ 0 ] ); >- >- /* second row of W_Q18 */ >- sum2_Q16 = silk_SMULWB( W_Q18[ 7 ], diff_Q14[ 2 ] ); >- sum2_Q16 = silk_SMLAWB( sum2_Q16, W_Q18[ 8 ], diff_Q14[ 3 ] ); >- sum2_Q16 = silk_SMLAWB( sum2_Q16, W_Q18[ 9 ], diff_Q14[ 4 ] ); >- sum2_Q16 = silk_LSHIFT( sum2_Q16, 1 ); >- sum2_Q16 = silk_SMLAWB( sum2_Q16, W_Q18[ 6 ], diff_Q14[ 1 ] ); >- sum1_Q14 = silk_SMLAWB( sum1_Q14, sum2_Q16, diff_Q14[ 1 ] ); >- >- /* third row of W_Q18 */ >- sum2_Q16 = silk_SMULWB( W_Q18[ 13 ], diff_Q14[ 3 ] ); >- sum2_Q16 = silk_SMLAWB( sum2_Q16, W_Q18[ 14 ], diff_Q14[ 4 ] ); >- sum2_Q16 = silk_LSHIFT( sum2_Q16, 1 ); >- sum2_Q16 = silk_SMLAWB( sum2_Q16, W_Q18[ 12 ], diff_Q14[ 2 ] ); >- sum1_Q14 = silk_SMLAWB( sum1_Q14, sum2_Q16, diff_Q14[ 2 ] ); >- >- /* fourth row of W_Q18 */ >- sum2_Q16 = silk_SMULWB( W_Q18[ 19 ], diff_Q14[ 4 ] ); >- sum2_Q16 = silk_LSHIFT( sum2_Q16, 1 ); >- sum2_Q16 = silk_SMLAWB( sum2_Q16, W_Q18[ 18 ], diff_Q14[ 3 ] ); >- sum1_Q14 = silk_SMLAWB( sum1_Q14, sum2_Q16, diff_Q14[ 3 ] ); >- >- /* last row of W_Q18 */ >- sum2_Q16 = silk_SMULWB( W_Q18[ 24 ], diff_Q14[ 4 ] ); >- sum1_Q14 = silk_SMLAWB( sum1_Q14, sum2_Q16, diff_Q14[ 4 ] ); >- >- silk_assert( sum1_Q14 >= 0 ); >+ penalty = silk_LSHIFT32( silk_max( silk_SUB32( gain_tmp_Q7, max_gain_Q7 ), 0 ), 11 ); >+ >+ /* first row of XX_Q17 */ >+ sum2_Q24 = silk_MLA( neg_xX_Q24[ 0 ], XX_Q17[ 1 ], cb_row_Q7[ 1 ] ); >+ sum2_Q24 = silk_MLA( sum2_Q24, XX_Q17[ 2 ], cb_row_Q7[ 2 ] ); >+ sum2_Q24 = silk_MLA( sum2_Q24, XX_Q17[ 3 ], cb_row_Q7[ 3 ] ); >+ sum2_Q24 = silk_MLA( sum2_Q24, XX_Q17[ 4 ], cb_row_Q7[ 4 ] ); >+ sum2_Q24 = silk_LSHIFT32( sum2_Q24, 1 ); >+ sum2_Q24 = silk_MLA( sum2_Q24, XX_Q17[ 0 ], cb_row_Q7[ 0 ] ); >+ sum1_Q15 = silk_SMLAWB( sum1_Q15, sum2_Q24, cb_row_Q7[ 0 ] ); >+ >+ /* second row of XX_Q17 */ >+ sum2_Q24 = silk_MLA( neg_xX_Q24[ 1 ], XX_Q17[ 7 ], cb_row_Q7[ 2 ] ); >+ sum2_Q24 = silk_MLA( sum2_Q24, XX_Q17[ 8 ], cb_row_Q7[ 3 ] ); >+ sum2_Q24 = silk_MLA( sum2_Q24, XX_Q17[ 9 ], cb_row_Q7[ 4 ] ); >+ sum2_Q24 = silk_LSHIFT32( sum2_Q24, 1 ); >+ sum2_Q24 = silk_MLA( sum2_Q24, XX_Q17[ 6 ], cb_row_Q7[ 1 ] ); >+ sum1_Q15 = silk_SMLAWB( sum1_Q15, sum2_Q24, cb_row_Q7[ 1 ] ); >+ >+ /* third row of XX_Q17 */ >+ sum2_Q24 = silk_MLA( neg_xX_Q24[ 2 ], XX_Q17[ 13 ], cb_row_Q7[ 3 ] ); >+ sum2_Q24 = silk_MLA( sum2_Q24, XX_Q17[ 14 ], cb_row_Q7[ 4 ] ); >+ sum2_Q24 = silk_LSHIFT32( sum2_Q24, 1 ); >+ sum2_Q24 = silk_MLA( sum2_Q24, XX_Q17[ 12 ], cb_row_Q7[ 2 ] ); >+ sum1_Q15 = silk_SMLAWB( sum1_Q15, sum2_Q24, cb_row_Q7[ 2 ] ); >+ >+ /* fourth row of XX_Q17 */ >+ sum2_Q24 = silk_MLA( neg_xX_Q24[ 3 ], XX_Q17[ 19 ], cb_row_Q7[ 4 ] ); >+ sum2_Q24 = silk_LSHIFT32( sum2_Q24, 1 ); >+ sum2_Q24 = silk_MLA( sum2_Q24, XX_Q17[ 18 ], cb_row_Q7[ 3 ] ); >+ sum1_Q15 = silk_SMLAWB( sum1_Q15, sum2_Q24, cb_row_Q7[ 3 ] ); >+ >+ /* last row of XX_Q17 */ >+ sum2_Q24 = silk_LSHIFT32( neg_xX_Q24[ 4 ], 1 ); >+ sum2_Q24 = silk_MLA( sum2_Q24, XX_Q17[ 24 ], cb_row_Q7[ 4 ] ); >+ sum1_Q15 = silk_SMLAWB( sum1_Q15, sum2_Q24, cb_row_Q7[ 4 ] ); > > /* find best */ >- if( sum1_Q14 < *rate_dist_Q14 ) { >- *rate_dist_Q14 = sum1_Q14; >- *ind = (opus_int8)k; >- *gain_Q7 = gain_tmp_Q7; >+ if( sum1_Q15 >= 0 ) { >+ /* Translate residual energy to bits using high-rate assumption (6 dB ==> 1 bit/sample) */ >+ bits_res_Q8 = silk_SMULBB( subfr_len, silk_lin2log( sum1_Q15 + penalty) - (15 << 7) ); >+ /* In the following line we reduce the codelength component by half ("-1"); seems to slghtly improve quality */ >+ bits_tot_Q8 = silk_ADD_LSHIFT32( bits_res_Q8, cl_Q5[ k ], 3-1 ); >+ if( bits_tot_Q8 <= *rate_dist_Q8 ) { >+ *rate_dist_Q8 = bits_tot_Q8; >+ *res_nrg_Q15 = sum1_Q15 + penalty; >+ *ind = (opus_int8)k; >+ *gain_Q7 = gain_tmp_Q7; >+ } > } > > /* Go to next cbk vector */ >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/arm/LPC_inv_pred_gain_arm.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/arm/LPC_inv_pred_gain_arm.h >new file mode 100644 >index 0000000000000000000000000000000000000000..9895b555c8870520d02906faadb52dcfbbfbc964 >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/arm/LPC_inv_pred_gain_arm.h >@@ -0,0 +1,57 @@ >+/*********************************************************************** >+Copyright (c) 2017 Google Inc. >+Redistribution and use in source and binary forms, with or without >+modification, are permitted provided that the following conditions >+are met: >+- Redistributions of source code must retain the above copyright notice, >+this list of conditions and the following disclaimer. >+- Redistributions in binary form must reproduce the above copyright >+notice, this list of conditions and the following disclaimer in the >+documentation and/or other materials provided with the distribution. >+- Neither the name of Internet Society, IETF or IETF Trust, nor the >+names of specific contributors, may be used to endorse or promote >+products derived from this software without specific prior written >+permission. >+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" >+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE >+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE >+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE >+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE >+POSSIBILITY OF SUCH DAMAGE. >+***********************************************************************/ >+ >+#ifndef SILK_LPC_INV_PRED_GAIN_ARM_H >+# define SILK_LPC_INV_PRED_GAIN_ARM_H >+ >+# include "celt/arm/armcpu.h" >+ >+# if defined(OPUS_ARM_MAY_HAVE_NEON_INTR) >+opus_int32 silk_LPC_inverse_pred_gain_neon( /* O Returns inverse prediction gain in energy domain, Q30 */ >+ const opus_int16 *A_Q12, /* I Prediction coefficients, Q12 [order] */ >+ const opus_int order /* I Prediction order */ >+); >+ >+# if !defined(OPUS_HAVE_RTCD) && defined(OPUS_ARM_PRESUME_NEON) >+# define OVERRIDE_silk_LPC_inverse_pred_gain (1) >+# define silk_LPC_inverse_pred_gain(A_Q12, order, arch) ((void)(arch), PRESUME_NEON(silk_LPC_inverse_pred_gain)(A_Q12, order)) >+# endif >+# endif >+ >+# if !defined(OVERRIDE_silk_LPC_inverse_pred_gain) >+/*Is run-time CPU detection enabled on this platform?*/ >+# if defined(OPUS_HAVE_RTCD) && (defined(OPUS_ARM_MAY_HAVE_NEON_INTR) && !defined(OPUS_ARM_PRESUME_NEON_INTR)) >+extern opus_int32 (*const SILK_LPC_INVERSE_PRED_GAIN_IMPL[OPUS_ARCHMASK+1])(const opus_int16 *A_Q12, const opus_int order); >+# define OVERRIDE_silk_LPC_inverse_pred_gain (1) >+# define silk_LPC_inverse_pred_gain(A_Q12, order, arch) ((*SILK_LPC_INVERSE_PRED_GAIN_IMPL[(arch)&OPUS_ARCHMASK])(A_Q12, order)) >+# elif defined(OPUS_ARM_PRESUME_NEON_INTR) >+# define OVERRIDE_silk_LPC_inverse_pred_gain (1) >+# define silk_LPC_inverse_pred_gain(A_Q12, order, arch) ((void)(arch), silk_LPC_inverse_pred_gain_neon(A_Q12, order)) >+# endif >+# endif >+ >+#endif /* end SILK_LPC_INV_PRED_GAIN_ARM_H */ >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/arm/LPC_inv_pred_gain_neon_intr.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/arm/LPC_inv_pred_gain_neon_intr.c >new file mode 100644 >index 0000000000000000000000000000000000000000..27142f34cebe6946506c98c7c80ed706e60738be >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/arm/LPC_inv_pred_gain_neon_intr.c >@@ -0,0 +1,280 @@ >+/*********************************************************************** >+Copyright (c) 2017 Google Inc. >+Redistribution and use in source and binary forms, with or without >+modification, are permitted provided that the following conditions >+are met: >+- Redistributions of source code must retain the above copyright notice, >+this list of conditions and the following disclaimer. >+- Redistributions in binary form must reproduce the above copyright >+notice, this list of conditions and the following disclaimer in the >+documentation and/or other materials provided with the distribution. >+- Neither the name of Internet Society, IETF or IETF Trust, nor the >+names of specific contributors, may be used to endorse or promote >+products derived from this software without specific prior written >+permission. >+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" >+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE >+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE >+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE >+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE >+POSSIBILITY OF SUCH DAMAGE. >+***********************************************************************/ >+ >+#ifdef HAVE_CONFIG_H >+#include "config.h" >+#endif >+ >+#include <arm_neon.h> >+#include "SigProc_FIX.h" >+#include "define.h" >+ >+#define QA 24 >+#define A_LIMIT SILK_FIX_CONST( 0.99975, QA ) >+ >+#define MUL32_FRAC_Q(a32, b32, Q) ((opus_int32)(silk_RSHIFT_ROUND64(silk_SMULL(a32, b32), Q))) >+ >+/* The difficulty is how to judge a 64-bit signed integer tmp64 is 32-bit overflowed, >+ * since NEON has no 64-bit min, max or comparison instructions. >+ * A failed idea is to compare the results of vmovn(tmp64) and vqmovn(tmp64) whether they are equal or not. >+ * However, this idea fails when the tmp64 is something like 0xFFFFFFF980000000. >+ * Here we know that mult2Q >= 1, so the highest bit (bit 63, sign bit) of tmp64 must equal to bit 62. >+ * tmp64 was shifted left by 1 and we got tmp64'. If high_half(tmp64') != 0 and high_half(tmp64') != -1, >+ * then we know that bit 31 to bit 63 of tmp64 can not all be the sign bit, and therefore tmp64 is 32-bit overflowed. >+ * That is, we judge if tmp64' > 0x00000000FFFFFFFF, or tmp64' <= 0xFFFFFFFF00000000. >+ * We use narrowing shift right 31 bits to tmp32' to save data bandwidth and instructions. >+ * That is, we judge if tmp32' > 0x00000000, or tmp32' <= 0xFFFFFFFF. >+ */ >+ >+/* Compute inverse of LPC prediction gain, and */ >+/* test if LPC coefficients are stable (all poles within unit circle) */ >+static OPUS_INLINE opus_int32 LPC_inverse_pred_gain_QA_neon( /* O Returns inverse prediction gain in energy domain, Q30 */ >+ opus_int32 A_QA[ SILK_MAX_ORDER_LPC ], /* I Prediction coefficients */ >+ const opus_int order /* I Prediction order */ >+) >+{ >+ opus_int k, n, mult2Q; >+ opus_int32 invGain_Q30, rc_Q31, rc_mult1_Q30, rc_mult2, tmp1, tmp2; >+ opus_int32 max, min; >+ int32x4_t max_s32x4, min_s32x4; >+ int32x2_t max_s32x2, min_s32x2; >+ >+ max_s32x4 = vdupq_n_s32( silk_int32_MIN ); >+ min_s32x4 = vdupq_n_s32( silk_int32_MAX ); >+ invGain_Q30 = SILK_FIX_CONST( 1, 30 ); >+ for( k = order - 1; k > 0; k-- ) { >+ int32x2_t rc_Q31_s32x2, rc_mult2_s32x2; >+ int64x2_t mult2Q_s64x2; >+ >+ /* Check for stability */ >+ if( ( A_QA[ k ] > A_LIMIT ) || ( A_QA[ k ] < -A_LIMIT ) ) { >+ return 0; >+ } >+ >+ /* Set RC equal to negated AR coef */ >+ rc_Q31 = -silk_LSHIFT( A_QA[ k ], 31 - QA ); >+ >+ /* rc_mult1_Q30 range: [ 1 : 2^30 ] */ >+ rc_mult1_Q30 = silk_SUB32( SILK_FIX_CONST( 1, 30 ), silk_SMMUL( rc_Q31, rc_Q31 ) ); >+ silk_assert( rc_mult1_Q30 > ( 1 << 15 ) ); /* reduce A_LIMIT if fails */ >+ silk_assert( rc_mult1_Q30 <= ( 1 << 30 ) ); >+ >+ /* Update inverse gain */ >+ /* invGain_Q30 range: [ 0 : 2^30 ] */ >+ invGain_Q30 = silk_LSHIFT( silk_SMMUL( invGain_Q30, rc_mult1_Q30 ), 2 ); >+ silk_assert( invGain_Q30 >= 0 ); >+ silk_assert( invGain_Q30 <= ( 1 << 30 ) ); >+ if( invGain_Q30 < SILK_FIX_CONST( 1.0f / MAX_PREDICTION_POWER_GAIN, 30 ) ) { >+ return 0; >+ } >+ >+ /* rc_mult2 range: [ 2^30 : silk_int32_MAX ] */ >+ mult2Q = 32 - silk_CLZ32( silk_abs( rc_mult1_Q30 ) ); >+ rc_mult2 = silk_INVERSE32_varQ( rc_mult1_Q30, mult2Q + 30 ); >+ >+ /* Update AR coefficient */ >+ rc_Q31_s32x2 = vdup_n_s32( rc_Q31 ); >+ mult2Q_s64x2 = vdupq_n_s64( -mult2Q ); >+ rc_mult2_s32x2 = vdup_n_s32( rc_mult2 ); >+ >+ for( n = 0; n < ( ( k + 1 ) >> 1 ) - 3; n += 4 ) { >+ /* We always calculate extra elements of A_QA buffer when ( k % 4 ) != 0, to take the advantage of SIMD parallelization. */ >+ int32x4_t tmp1_s32x4, tmp2_s32x4, t0_s32x4, t1_s32x4, s0_s32x4, s1_s32x4, t_QA0_s32x4, t_QA1_s32x4; >+ int64x2_t t0_s64x2, t1_s64x2, t2_s64x2, t3_s64x2; >+ tmp1_s32x4 = vld1q_s32( A_QA + n ); >+ tmp2_s32x4 = vld1q_s32( A_QA + k - n - 4 ); >+ tmp2_s32x4 = vrev64q_s32( tmp2_s32x4 ); >+ tmp2_s32x4 = vcombine_s32( vget_high_s32( tmp2_s32x4 ), vget_low_s32( tmp2_s32x4 ) ); >+ t0_s32x4 = vqrdmulhq_lane_s32( tmp2_s32x4, rc_Q31_s32x2, 0 ); >+ t1_s32x4 = vqrdmulhq_lane_s32( tmp1_s32x4, rc_Q31_s32x2, 0 ); >+ t_QA0_s32x4 = vqsubq_s32( tmp1_s32x4, t0_s32x4 ); >+ t_QA1_s32x4 = vqsubq_s32( tmp2_s32x4, t1_s32x4 ); >+ t0_s64x2 = vmull_s32( vget_low_s32 ( t_QA0_s32x4 ), rc_mult2_s32x2 ); >+ t1_s64x2 = vmull_s32( vget_high_s32( t_QA0_s32x4 ), rc_mult2_s32x2 ); >+ t2_s64x2 = vmull_s32( vget_low_s32 ( t_QA1_s32x4 ), rc_mult2_s32x2 ); >+ t3_s64x2 = vmull_s32( vget_high_s32( t_QA1_s32x4 ), rc_mult2_s32x2 ); >+ t0_s64x2 = vrshlq_s64( t0_s64x2, mult2Q_s64x2 ); >+ t1_s64x2 = vrshlq_s64( t1_s64x2, mult2Q_s64x2 ); >+ t2_s64x2 = vrshlq_s64( t2_s64x2, mult2Q_s64x2 ); >+ t3_s64x2 = vrshlq_s64( t3_s64x2, mult2Q_s64x2 ); >+ t0_s32x4 = vcombine_s32( vmovn_s64( t0_s64x2 ), vmovn_s64( t1_s64x2 ) ); >+ t1_s32x4 = vcombine_s32( vmovn_s64( t2_s64x2 ), vmovn_s64( t3_s64x2 ) ); >+ s0_s32x4 = vcombine_s32( vshrn_n_s64( t0_s64x2, 31 ), vshrn_n_s64( t1_s64x2, 31 ) ); >+ s1_s32x4 = vcombine_s32( vshrn_n_s64( t2_s64x2, 31 ), vshrn_n_s64( t3_s64x2, 31 ) ); >+ max_s32x4 = vmaxq_s32( max_s32x4, s0_s32x4 ); >+ min_s32x4 = vminq_s32( min_s32x4, s0_s32x4 ); >+ max_s32x4 = vmaxq_s32( max_s32x4, s1_s32x4 ); >+ min_s32x4 = vminq_s32( min_s32x4, s1_s32x4 ); >+ t1_s32x4 = vrev64q_s32( t1_s32x4 ); >+ t1_s32x4 = vcombine_s32( vget_high_s32( t1_s32x4 ), vget_low_s32( t1_s32x4 ) ); >+ vst1q_s32( A_QA + n, t0_s32x4 ); >+ vst1q_s32( A_QA + k - n - 4, t1_s32x4 ); >+ } >+ for( ; n < (k + 1) >> 1; n++ ) { >+ opus_int64 tmp64; >+ tmp1 = A_QA[ n ]; >+ tmp2 = A_QA[ k - n - 1 ]; >+ tmp64 = silk_RSHIFT_ROUND64( silk_SMULL( silk_SUB_SAT32(tmp1, >+ MUL32_FRAC_Q( tmp2, rc_Q31, 31 ) ), rc_mult2 ), mult2Q); >+ if( tmp64 > silk_int32_MAX || tmp64 < silk_int32_MIN ) { >+ return 0; >+ } >+ A_QA[ n ] = ( opus_int32 )tmp64; >+ tmp64 = silk_RSHIFT_ROUND64( silk_SMULL( silk_SUB_SAT32(tmp2, >+ MUL32_FRAC_Q( tmp1, rc_Q31, 31 ) ), rc_mult2), mult2Q); >+ if( tmp64 > silk_int32_MAX || tmp64 < silk_int32_MIN ) { >+ return 0; >+ } >+ A_QA[ k - n - 1 ] = ( opus_int32 )tmp64; >+ } >+ } >+ >+ /* Check for stability */ >+ if( ( A_QA[ k ] > A_LIMIT ) || ( A_QA[ k ] < -A_LIMIT ) ) { >+ return 0; >+ } >+ >+ max_s32x2 = vmax_s32( vget_low_s32( max_s32x4 ), vget_high_s32( max_s32x4 ) ); >+ min_s32x2 = vmin_s32( vget_low_s32( min_s32x4 ), vget_high_s32( min_s32x4 ) ); >+ max_s32x2 = vmax_s32( max_s32x2, vreinterpret_s32_s64( vshr_n_s64( vreinterpret_s64_s32( max_s32x2 ), 32 ) ) ); >+ min_s32x2 = vmin_s32( min_s32x2, vreinterpret_s32_s64( vshr_n_s64( vreinterpret_s64_s32( min_s32x2 ), 32 ) ) ); >+ max = vget_lane_s32( max_s32x2, 0 ); >+ min = vget_lane_s32( min_s32x2, 0 ); >+ if( ( max > 0 ) || ( min < -1 ) ) { >+ return 0; >+ } >+ >+ /* Set RC equal to negated AR coef */ >+ rc_Q31 = -silk_LSHIFT( A_QA[ 0 ], 31 - QA ); >+ >+ /* Range: [ 1 : 2^30 ] */ >+ rc_mult1_Q30 = silk_SUB32( SILK_FIX_CONST( 1, 30 ), silk_SMMUL( rc_Q31, rc_Q31 ) ); >+ >+ /* Update inverse gain */ >+ /* Range: [ 0 : 2^30 ] */ >+ invGain_Q30 = silk_LSHIFT( silk_SMMUL( invGain_Q30, rc_mult1_Q30 ), 2 ); >+ silk_assert( invGain_Q30 >= 0 ); >+ silk_assert( invGain_Q30 <= ( 1 << 30 ) ); >+ if( invGain_Q30 < SILK_FIX_CONST( 1.0f / MAX_PREDICTION_POWER_GAIN, 30 ) ) { >+ return 0; >+ } >+ >+ return invGain_Q30; >+} >+ >+/* For input in Q12 domain */ >+opus_int32 silk_LPC_inverse_pred_gain_neon( /* O Returns inverse prediction gain in energy domain, Q30 */ >+ const opus_int16 *A_Q12, /* I Prediction coefficients, Q12 [order] */ >+ const opus_int order /* I Prediction order */ >+) >+{ >+#ifdef OPUS_CHECK_ASM >+ const opus_int32 invGain_Q30_c = silk_LPC_inverse_pred_gain_c( A_Q12, order ); >+#endif >+ >+ opus_int32 invGain_Q30; >+ if( ( SILK_MAX_ORDER_LPC != 24 ) || ( order & 1 )) { >+ invGain_Q30 = silk_LPC_inverse_pred_gain_c( A_Q12, order ); >+ } >+ else { >+ opus_int32 Atmp_QA[ SILK_MAX_ORDER_LPC ]; >+ opus_int32 DC_resp; >+ int16x8_t t0_s16x8, t1_s16x8, t2_s16x8; >+ int32x4_t t0_s32x4; >+ const opus_int leftover = order & 7; >+ >+ /* Increase Q domain of the AR coefficients */ >+ t0_s16x8 = vld1q_s16( A_Q12 + 0 ); >+ t1_s16x8 = vld1q_s16( A_Q12 + 8 ); >+ t2_s16x8 = vld1q_s16( A_Q12 + 16 ); >+ t0_s32x4 = vpaddlq_s16( t0_s16x8 ); >+ >+ switch( order - leftover ) >+ { >+ case 24: >+ t0_s32x4 = vpadalq_s16( t0_s32x4, t2_s16x8 ); >+ /* Intend to fall through */ >+ >+ case 16: >+ t0_s32x4 = vpadalq_s16( t0_s32x4, t1_s16x8 ); >+ vst1q_s32( Atmp_QA + 16, vshll_n_s16( vget_low_s16 ( t2_s16x8 ), QA - 12 ) ); >+ vst1q_s32( Atmp_QA + 20, vshll_n_s16( vget_high_s16( t2_s16x8 ), QA - 12 ) ); >+ /* Intend to fall through */ >+ >+ case 8: >+ { >+ const int32x2_t t_s32x2 = vpadd_s32( vget_low_s32( t0_s32x4 ), vget_high_s32( t0_s32x4 ) ); >+ const int64x1_t t_s64x1 = vpaddl_s32( t_s32x2 ); >+ DC_resp = vget_lane_s32( vreinterpret_s32_s64( t_s64x1 ), 0 ); >+ vst1q_s32( Atmp_QA + 8, vshll_n_s16( vget_low_s16 ( t1_s16x8 ), QA - 12 ) ); >+ vst1q_s32( Atmp_QA + 12, vshll_n_s16( vget_high_s16( t1_s16x8 ), QA - 12 ) ); >+ } >+ break; >+ >+ default: >+ DC_resp = 0; >+ break; >+ } >+ A_Q12 += order - leftover; >+ >+ switch( leftover ) >+ { >+ case 6: >+ DC_resp += (opus_int32)A_Q12[ 5 ]; >+ DC_resp += (opus_int32)A_Q12[ 4 ]; >+ /* Intend to fall through */ >+ >+ case 4: >+ DC_resp += (opus_int32)A_Q12[ 3 ]; >+ DC_resp += (opus_int32)A_Q12[ 2 ]; >+ /* Intend to fall through */ >+ >+ case 2: >+ DC_resp += (opus_int32)A_Q12[ 1 ]; >+ DC_resp += (opus_int32)A_Q12[ 0 ]; >+ /* Intend to fall through */ >+ >+ default: >+ break; >+ } >+ >+ /* If the DC is unstable, we don't even need to do the full calculations */ >+ if( DC_resp >= 4096 ) { >+ invGain_Q30 = 0; >+ } else { >+ vst1q_s32( Atmp_QA + 0, vshll_n_s16( vget_low_s16 ( t0_s16x8 ), QA - 12 ) ); >+ vst1q_s32( Atmp_QA + 4, vshll_n_s16( vget_high_s16( t0_s16x8 ), QA - 12 ) ); >+ invGain_Q30 = LPC_inverse_pred_gain_QA_neon( Atmp_QA, order ); >+ } >+ } >+ >+#ifdef OPUS_CHECK_ASM >+ silk_assert( invGain_Q30_c == invGain_Q30 ); >+#endif >+ >+ return invGain_Q30; >+} >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/arm/NSQ_del_dec_arm.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/arm/NSQ_del_dec_arm.h >new file mode 100644 >index 0000000000000000000000000000000000000000..9e76e1692799b42f3eb443abb47ad3722a51f2c4 >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/arm/NSQ_del_dec_arm.h >@@ -0,0 +1,100 @@ >+/*********************************************************************** >+Copyright (c) 2017 Google Inc. >+Redistribution and use in source and binary forms, with or without >+modification, are permitted provided that the following conditions >+are met: >+- Redistributions of source code must retain the above copyright notice, >+this list of conditions and the following disclaimer. >+- Redistributions in binary form must reproduce the above copyright >+notice, this list of conditions and the following disclaimer in the >+documentation and/or other materials provided with the distribution. >+- Neither the name of Internet Society, IETF or IETF Trust, nor the >+names of specific contributors, may be used to endorse or promote >+products derived from this software without specific prior written >+permission. >+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" >+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE >+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE >+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE >+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE >+POSSIBILITY OF SUCH DAMAGE. >+***********************************************************************/ >+ >+#ifndef SILK_NSQ_DEL_DEC_ARM_H >+#define SILK_NSQ_DEL_DEC_ARM_H >+ >+#include "celt/arm/armcpu.h" >+ >+#if defined(OPUS_ARM_MAY_HAVE_NEON_INTR) >+void silk_NSQ_del_dec_neon( >+ const silk_encoder_state *psEncC, silk_nsq_state *NSQ, >+ SideInfoIndices *psIndices, const opus_int16 x16[], opus_int8 pulses[], >+ const opus_int16 PredCoef_Q12[2 * MAX_LPC_ORDER], >+ const opus_int16 LTPCoef_Q14[LTP_ORDER * MAX_NB_SUBFR], >+ const opus_int16 AR_Q13[MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER], >+ const opus_int HarmShapeGain_Q14[MAX_NB_SUBFR], >+ const opus_int Tilt_Q14[MAX_NB_SUBFR], >+ const opus_int32 LF_shp_Q14[MAX_NB_SUBFR], >+ const opus_int32 Gains_Q16[MAX_NB_SUBFR], >+ const opus_int pitchL[MAX_NB_SUBFR], const opus_int Lambda_Q10, >+ const opus_int LTP_scale_Q14); >+ >+#if !defined(OPUS_HAVE_RTCD) >+#define OVERRIDE_silk_NSQ_del_dec (1) >+#define silk_NSQ_del_dec(psEncC, NSQ, psIndices, x16, pulses, PredCoef_Q12, \ >+ LTPCoef_Q14, AR_Q13, HarmShapeGain_Q14, Tilt_Q14, \ >+ LF_shp_Q14, Gains_Q16, pitchL, Lambda_Q10, \ >+ LTP_scale_Q14, arch) \ >+ ((void)(arch), \ >+ PRESUME_NEON(silk_NSQ_del_dec)( \ >+ psEncC, NSQ, psIndices, x16, pulses, PredCoef_Q12, LTPCoef_Q14, \ >+ AR_Q13, HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, pitchL, \ >+ Lambda_Q10, LTP_scale_Q14)) >+#endif >+#endif >+ >+#if !defined(OVERRIDE_silk_NSQ_del_dec) >+/*Is run-time CPU detection enabled on this platform?*/ >+#if defined(OPUS_HAVE_RTCD) && (defined(OPUS_ARM_MAY_HAVE_NEON_INTR) && \ >+ !defined(OPUS_ARM_PRESUME_NEON_INTR)) >+extern void (*const SILK_NSQ_DEL_DEC_IMPL[OPUS_ARCHMASK + 1])( >+ const silk_encoder_state *psEncC, silk_nsq_state *NSQ, >+ SideInfoIndices *psIndices, const opus_int16 x16[], opus_int8 pulses[], >+ const opus_int16 PredCoef_Q12[2 * MAX_LPC_ORDER], >+ const opus_int16 LTPCoef_Q14[LTP_ORDER * MAX_NB_SUBFR], >+ const opus_int16 AR_Q13[MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER], >+ const opus_int HarmShapeGain_Q14[MAX_NB_SUBFR], >+ const opus_int Tilt_Q14[MAX_NB_SUBFR], >+ const opus_int32 LF_shp_Q14[MAX_NB_SUBFR], >+ const opus_int32 Gains_Q16[MAX_NB_SUBFR], >+ const opus_int pitchL[MAX_NB_SUBFR], const opus_int Lambda_Q10, >+ const opus_int LTP_scale_Q14); >+#define OVERRIDE_silk_NSQ_del_dec (1) >+#define silk_NSQ_del_dec(psEncC, NSQ, psIndices, x16, pulses, PredCoef_Q12, \ >+ LTPCoef_Q14, AR_Q13, HarmShapeGain_Q14, Tilt_Q14, \ >+ LF_shp_Q14, Gains_Q16, pitchL, Lambda_Q10, \ >+ LTP_scale_Q14, arch) \ >+ ((*SILK_NSQ_DEL_DEC_IMPL[(arch)&OPUS_ARCHMASK])( \ >+ psEncC, NSQ, psIndices, x16, pulses, PredCoef_Q12, LTPCoef_Q14, \ >+ AR_Q13, HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, pitchL, \ >+ Lambda_Q10, LTP_scale_Q14)) >+#elif defined(OPUS_ARM_PRESUME_NEON_INTR) >+#define OVERRIDE_silk_NSQ_del_dec (1) >+#define silk_NSQ_del_dec(psEncC, NSQ, psIndices, x16, pulses, PredCoef_Q12, \ >+ LTPCoef_Q14, AR_Q13, HarmShapeGain_Q14, Tilt_Q14, \ >+ LF_shp_Q14, Gains_Q16, pitchL, Lambda_Q10, \ >+ LTP_scale_Q14, arch) \ >+ ((void)(arch), \ >+ silk_NSQ_del_dec_neon(psEncC, NSQ, psIndices, x16, pulses, PredCoef_Q12, \ >+ LTPCoef_Q14, AR_Q13, HarmShapeGain_Q14, Tilt_Q14, \ >+ LF_shp_Q14, Gains_Q16, pitchL, Lambda_Q10, \ >+ LTP_scale_Q14)) >+#endif >+#endif >+ >+#endif /* end SILK_NSQ_DEL_DEC_ARM_H */ >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/arm/NSQ_del_dec_neon_intr.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/arm/NSQ_del_dec_neon_intr.c >new file mode 100644 >index 0000000000000000000000000000000000000000..212410f36292631d22de5eac272da068cfb8c159 >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/arm/NSQ_del_dec_neon_intr.c >@@ -0,0 +1,1124 @@ >+/*********************************************************************** >+Copyright (c) 2017 Google Inc. >+Redistribution and use in source and binary forms, with or without >+modification, are permitted provided that the following conditions >+are met: >+- Redistributions of source code must retain the above copyright notice, >+this list of conditions and the following disclaimer. >+- Redistributions in binary form must reproduce the above copyright >+notice, this list of conditions and the following disclaimer in the >+documentation and/or other materials provided with the distribution. >+- Neither the name of Internet Society, IETF or IETF Trust, nor the >+names of specific contributors, may be used to endorse or promote >+products derived from this software without specific prior written >+permission. >+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" >+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE >+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE >+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE >+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE >+POSSIBILITY OF SUCH DAMAGE. >+***********************************************************************/ >+ >+#ifdef HAVE_CONFIG_H >+#include "config.h" >+#endif >+ >+#include <arm_neon.h> >+#ifdef OPUS_CHECK_ASM >+# include <string.h> >+#endif >+#include "main.h" >+#include "stack_alloc.h" >+ >+/* NEON intrinsics optimization now can only parallelize up to 4 delay decision states. */ >+/* If there are more states, C function is called, and this optimization must be expanded. */ >+#define NEON_MAX_DEL_DEC_STATES 4 >+ >+typedef struct { >+ opus_int32 sLPC_Q14[ MAX_SUB_FRAME_LENGTH + NSQ_LPC_BUF_LENGTH ][ NEON_MAX_DEL_DEC_STATES ]; >+ opus_int32 RandState[ DECISION_DELAY ][ NEON_MAX_DEL_DEC_STATES ]; >+ opus_int32 Q_Q10[ DECISION_DELAY ][ NEON_MAX_DEL_DEC_STATES ]; >+ opus_int32 Xq_Q14[ DECISION_DELAY ][ NEON_MAX_DEL_DEC_STATES ]; >+ opus_int32 Pred_Q15[ DECISION_DELAY ][ NEON_MAX_DEL_DEC_STATES ]; >+ opus_int32 Shape_Q14[ DECISION_DELAY ][ NEON_MAX_DEL_DEC_STATES ]; >+ opus_int32 sAR2_Q14[ MAX_SHAPE_LPC_ORDER ][ NEON_MAX_DEL_DEC_STATES ]; >+ opus_int32 LF_AR_Q14[ NEON_MAX_DEL_DEC_STATES ]; >+ opus_int32 Diff_Q14[ NEON_MAX_DEL_DEC_STATES ]; >+ opus_int32 Seed[ NEON_MAX_DEL_DEC_STATES ]; >+ opus_int32 SeedInit[ NEON_MAX_DEL_DEC_STATES ]; >+ opus_int32 RD_Q10[ NEON_MAX_DEL_DEC_STATES ]; >+} NSQ_del_decs_struct; >+ >+typedef struct { >+ opus_int32 Q_Q10[ NEON_MAX_DEL_DEC_STATES ]; >+ opus_int32 RD_Q10[ NEON_MAX_DEL_DEC_STATES ]; >+ opus_int32 xq_Q14[ NEON_MAX_DEL_DEC_STATES ]; >+ opus_int32 LF_AR_Q14[ NEON_MAX_DEL_DEC_STATES ]; >+ opus_int32 Diff_Q14[ NEON_MAX_DEL_DEC_STATES ]; >+ opus_int32 sLTP_shp_Q14[ NEON_MAX_DEL_DEC_STATES ]; >+ opus_int32 LPC_exc_Q14[ NEON_MAX_DEL_DEC_STATES ]; >+} NSQ_samples_struct; >+ >+static OPUS_INLINE void silk_nsq_del_dec_scale_states_neon( >+ const silk_encoder_state *psEncC, /* I Encoder State */ >+ silk_nsq_state *NSQ, /* I/O NSQ state */ >+ NSQ_del_decs_struct psDelDec[], /* I/O Delayed decision states */ >+ const opus_int16 x16[], /* I Input */ >+ opus_int32 x_sc_Q10[], /* O Input scaled with 1/Gain in Q10 */ >+ const opus_int16 sLTP[], /* I Re-whitened LTP state in Q0 */ >+ opus_int32 sLTP_Q15[], /* O LTP state matching scaled input */ >+ opus_int subfr, /* I Subframe number */ >+ const opus_int LTP_scale_Q14, /* I LTP state scaling */ >+ const opus_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I */ >+ const opus_int pitchL[ MAX_NB_SUBFR ], /* I Pitch lag */ >+ const opus_int signal_type, /* I Signal type */ >+ const opus_int decisionDelay /* I Decision delay */ >+); >+ >+/******************************************/ >+/* Noise shape quantizer for one subframe */ >+/******************************************/ >+static OPUS_INLINE void silk_noise_shape_quantizer_del_dec_neon( >+ silk_nsq_state *NSQ, /* I/O NSQ state */ >+ NSQ_del_decs_struct psDelDec[], /* I/O Delayed decision states */ >+ opus_int signalType, /* I Signal type */ >+ const opus_int32 x_Q10[], /* I */ >+ opus_int8 pulses[], /* O */ >+ opus_int16 xq[], /* O */ >+ opus_int32 sLTP_Q15[], /* I/O LTP filter state */ >+ opus_int32 delayedGain_Q10[], /* I/O Gain delay buffer */ >+ const opus_int16 a_Q12[], /* I Short term prediction coefs */ >+ const opus_int16 b_Q14[], /* I Long term prediction coefs */ >+ const opus_int16 AR_shp_Q13[], /* I Noise shaping coefs */ >+ opus_int lag, /* I Pitch lag */ >+ opus_int32 HarmShapeFIRPacked_Q14, /* I */ >+ opus_int Tilt_Q14, /* I Spectral tilt */ >+ opus_int32 LF_shp_Q14, /* I */ >+ opus_int32 Gain_Q16, /* I */ >+ opus_int Lambda_Q10, /* I */ >+ opus_int offset_Q10, /* I */ >+ opus_int length, /* I Input length */ >+ opus_int subfr, /* I Subframe number */ >+ opus_int shapingLPCOrder, /* I Shaping LPC filter order */ >+ opus_int predictLPCOrder, /* I Prediction filter order */ >+ opus_int warping_Q16, /* I */ >+ opus_int nStatesDelayedDecision, /* I Number of states in decision tree */ >+ opus_int *smpl_buf_idx, /* I/O Index to newest samples in buffers */ >+ opus_int decisionDelay /* I */ >+); >+ >+static OPUS_INLINE void copy_winner_state_kernel( >+ const NSQ_del_decs_struct *psDelDec, >+ const opus_int offset, >+ const opus_int last_smple_idx, >+ const opus_int Winner_ind, >+ const int32x2_t gain_lo_s32x2, >+ const int32x2_t gain_hi_s32x2, >+ const int32x4_t shift_s32x4, >+ int32x4_t t0_s32x4, >+ int32x4_t t1_s32x4, >+ opus_int8 *const pulses, >+ opus_int16 *pxq, >+ silk_nsq_state *NSQ >+) >+{ >+ int16x8_t t_s16x8; >+ int32x4_t o0_s32x4, o1_s32x4; >+ >+ t0_s32x4 = vld1q_lane_s32( &psDelDec->Q_Q10[ last_smple_idx - 0 ][ Winner_ind ], t0_s32x4, 0 ); >+ t0_s32x4 = vld1q_lane_s32( &psDelDec->Q_Q10[ last_smple_idx - 1 ][ Winner_ind ], t0_s32x4, 1 ); >+ t0_s32x4 = vld1q_lane_s32( &psDelDec->Q_Q10[ last_smple_idx - 2 ][ Winner_ind ], t0_s32x4, 2 ); >+ t0_s32x4 = vld1q_lane_s32( &psDelDec->Q_Q10[ last_smple_idx - 3 ][ Winner_ind ], t0_s32x4, 3 ); >+ t1_s32x4 = vld1q_lane_s32( &psDelDec->Q_Q10[ last_smple_idx - 4 ][ Winner_ind ], t1_s32x4, 0 ); >+ t1_s32x4 = vld1q_lane_s32( &psDelDec->Q_Q10[ last_smple_idx - 5 ][ Winner_ind ], t1_s32x4, 1 ); >+ t1_s32x4 = vld1q_lane_s32( &psDelDec->Q_Q10[ last_smple_idx - 6 ][ Winner_ind ], t1_s32x4, 2 ); >+ t1_s32x4 = vld1q_lane_s32( &psDelDec->Q_Q10[ last_smple_idx - 7 ][ Winner_ind ], t1_s32x4, 3 ); >+ t_s16x8 = vcombine_s16( vrshrn_n_s32( t0_s32x4, 10 ), vrshrn_n_s32( t1_s32x4, 10 ) ); >+ vst1_s8( &pulses[ offset ], vmovn_s16( t_s16x8 ) ); >+ >+ t0_s32x4 = vld1q_lane_s32( &psDelDec->Xq_Q14[ last_smple_idx - 0 ][ Winner_ind ], t0_s32x4, 0 ); >+ t0_s32x4 = vld1q_lane_s32( &psDelDec->Xq_Q14[ last_smple_idx - 1 ][ Winner_ind ], t0_s32x4, 1 ); >+ t0_s32x4 = vld1q_lane_s32( &psDelDec->Xq_Q14[ last_smple_idx - 2 ][ Winner_ind ], t0_s32x4, 2 ); >+ t0_s32x4 = vld1q_lane_s32( &psDelDec->Xq_Q14[ last_smple_idx - 3 ][ Winner_ind ], t0_s32x4, 3 ); >+ t1_s32x4 = vld1q_lane_s32( &psDelDec->Xq_Q14[ last_smple_idx - 4 ][ Winner_ind ], t1_s32x4, 0 ); >+ t1_s32x4 = vld1q_lane_s32( &psDelDec->Xq_Q14[ last_smple_idx - 5 ][ Winner_ind ], t1_s32x4, 1 ); >+ t1_s32x4 = vld1q_lane_s32( &psDelDec->Xq_Q14[ last_smple_idx - 6 ][ Winner_ind ], t1_s32x4, 2 ); >+ t1_s32x4 = vld1q_lane_s32( &psDelDec->Xq_Q14[ last_smple_idx - 7 ][ Winner_ind ], t1_s32x4, 3 ); >+ o0_s32x4 = vqdmulhq_lane_s32( t0_s32x4, gain_lo_s32x2, 0 ); >+ o1_s32x4 = vqdmulhq_lane_s32( t1_s32x4, gain_lo_s32x2, 0 ); >+ o0_s32x4 = vmlaq_lane_s32( o0_s32x4, t0_s32x4, gain_hi_s32x2, 0 ); >+ o1_s32x4 = vmlaq_lane_s32( o1_s32x4, t1_s32x4, gain_hi_s32x2, 0 ); >+ o0_s32x4 = vrshlq_s32( o0_s32x4, shift_s32x4 ); >+ o1_s32x4 = vrshlq_s32( o1_s32x4, shift_s32x4 ); >+ vst1_s16( &pxq[ offset + 0 ], vqmovn_s32( o0_s32x4 ) ); >+ vst1_s16( &pxq[ offset + 4 ], vqmovn_s32( o1_s32x4 ) ); >+ >+ t0_s32x4 = vld1q_lane_s32( &psDelDec->Shape_Q14[ last_smple_idx - 0 ][ Winner_ind ], t0_s32x4, 0 ); >+ t0_s32x4 = vld1q_lane_s32( &psDelDec->Shape_Q14[ last_smple_idx - 1 ][ Winner_ind ], t0_s32x4, 1 ); >+ t0_s32x4 = vld1q_lane_s32( &psDelDec->Shape_Q14[ last_smple_idx - 2 ][ Winner_ind ], t0_s32x4, 2 ); >+ t0_s32x4 = vld1q_lane_s32( &psDelDec->Shape_Q14[ last_smple_idx - 3 ][ Winner_ind ], t0_s32x4, 3 ); >+ t1_s32x4 = vld1q_lane_s32( &psDelDec->Shape_Q14[ last_smple_idx - 4 ][ Winner_ind ], t1_s32x4, 0 ); >+ t1_s32x4 = vld1q_lane_s32( &psDelDec->Shape_Q14[ last_smple_idx - 5 ][ Winner_ind ], t1_s32x4, 1 ); >+ t1_s32x4 = vld1q_lane_s32( &psDelDec->Shape_Q14[ last_smple_idx - 6 ][ Winner_ind ], t1_s32x4, 2 ); >+ t1_s32x4 = vld1q_lane_s32( &psDelDec->Shape_Q14[ last_smple_idx - 7 ][ Winner_ind ], t1_s32x4, 3 ); >+ vst1q_s32( &NSQ->sLTP_shp_Q14[ NSQ->sLTP_shp_buf_idx + offset + 0 ], t0_s32x4 ); >+ vst1q_s32( &NSQ->sLTP_shp_Q14[ NSQ->sLTP_shp_buf_idx + offset + 4 ], t1_s32x4 ); >+} >+ >+static OPUS_INLINE void copy_winner_state( >+ const NSQ_del_decs_struct *psDelDec, >+ const opus_int decisionDelay, >+ const opus_int smpl_buf_idx, >+ const opus_int Winner_ind, >+ const opus_int32 gain, >+ const opus_int32 shift, >+ opus_int8 *const pulses, >+ opus_int16 *pxq, >+ silk_nsq_state *NSQ >+) >+{ >+ opus_int i, last_smple_idx; >+ const int32x2_t gain_lo_s32x2 = vdup_n_s32( silk_LSHIFT32( gain & 0x0000FFFF, 15 ) ); >+ const int32x2_t gain_hi_s32x2 = vdup_n_s32( gain >> 16 ); >+ const int32x4_t shift_s32x4 = vdupq_n_s32( -shift ); >+ int32x4_t t0_s32x4, t1_s32x4; >+ >+ t0_s32x4 = t1_s32x4 = vdupq_n_s32( 0 ); /* initialization */ >+ last_smple_idx = smpl_buf_idx + decisionDelay - 1 + DECISION_DELAY; >+ if( last_smple_idx >= DECISION_DELAY ) last_smple_idx -= DECISION_DELAY; >+ if( last_smple_idx >= DECISION_DELAY ) last_smple_idx -= DECISION_DELAY; >+ >+ for( i = 0; ( i < ( decisionDelay - 7 ) ) && ( last_smple_idx >= 7 ); i += 8, last_smple_idx -= 8 ) { >+ copy_winner_state_kernel( psDelDec, i - decisionDelay, last_smple_idx, Winner_ind, gain_lo_s32x2, gain_hi_s32x2, shift_s32x4, t0_s32x4, t1_s32x4, pulses, pxq, NSQ ); >+ } >+ for( ; ( i < decisionDelay ) && ( last_smple_idx >= 0 ); i++, last_smple_idx-- ) { >+ pulses[ i - decisionDelay ] = (opus_int8)silk_RSHIFT_ROUND( psDelDec->Q_Q10[ last_smple_idx ][ Winner_ind ], 10 ); >+ pxq[ i - decisionDelay ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( silk_SMULWW( psDelDec->Xq_Q14[ last_smple_idx ][ Winner_ind ], gain ), shift ) ); >+ NSQ->sLTP_shp_Q14[ NSQ->sLTP_shp_buf_idx - decisionDelay + i ] = psDelDec->Shape_Q14[ last_smple_idx ][ Winner_ind ]; >+ } >+ >+ last_smple_idx += DECISION_DELAY; >+ for( ; i < ( decisionDelay - 7 ); i++, last_smple_idx-- ) { >+ copy_winner_state_kernel( psDelDec, i - decisionDelay, last_smple_idx, Winner_ind, gain_lo_s32x2, gain_hi_s32x2, shift_s32x4, t0_s32x4, t1_s32x4, pulses, pxq, NSQ ); >+ } >+ for( ; i < decisionDelay; i++, last_smple_idx-- ) { >+ pulses[ i - decisionDelay ] = (opus_int8)silk_RSHIFT_ROUND( psDelDec->Q_Q10[ last_smple_idx ][ Winner_ind ], 10 ); >+ pxq[ i - decisionDelay ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( silk_SMULWW( psDelDec->Xq_Q14[ last_smple_idx ][ Winner_ind ], gain ), shift ) ); >+ NSQ->sLTP_shp_Q14[ NSQ->sLTP_shp_buf_idx - decisionDelay + i ] = psDelDec->Shape_Q14[ last_smple_idx ][ Winner_ind ]; >+ } >+} >+ >+void silk_NSQ_del_dec_neon( >+ const silk_encoder_state *psEncC, /* I Encoder State */ >+ silk_nsq_state *NSQ, /* I/O NSQ state */ >+ SideInfoIndices *psIndices, /* I/O Quantization Indices */ >+ const opus_int16 x16[], /* I Input */ >+ opus_int8 pulses[], /* O Quantized pulse signal */ >+ const opus_int16 PredCoef_Q12[ 2 * MAX_LPC_ORDER ], /* I Short term prediction coefs */ >+ const opus_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ], /* I Long term prediction coefs */ >+ const opus_int16 AR_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I Noise shaping coefs */ >+ const opus_int HarmShapeGain_Q14[ MAX_NB_SUBFR ], /* I Long term shaping coefs */ >+ const opus_int Tilt_Q14[ MAX_NB_SUBFR ], /* I Spectral tilt */ >+ const opus_int32 LF_shp_Q14[ MAX_NB_SUBFR ], /* I Low frequency shaping coefs */ >+ const opus_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I Quantization step sizes */ >+ const opus_int pitchL[ MAX_NB_SUBFR ], /* I Pitch lags */ >+ const opus_int Lambda_Q10, /* I Rate/distortion tradeoff */ >+ const opus_int LTP_scale_Q14 /* I LTP state scaling */ >+) >+{ >+#ifdef OPUS_CHECK_ASM >+ silk_nsq_state NSQ_c; >+ SideInfoIndices psIndices_c; >+ opus_int8 pulses_c[ MAX_FRAME_LENGTH ]; >+ const opus_int8 *const pulses_a = pulses; >+ >+ ( void )pulses_a; >+ silk_memcpy( &NSQ_c, NSQ, sizeof( NSQ_c ) ); >+ silk_memcpy( &psIndices_c, psIndices, sizeof( psIndices_c ) ); >+ silk_memcpy( pulses_c, pulses, sizeof( pulses_c ) ); >+ silk_NSQ_del_dec_c( psEncC, &NSQ_c, &psIndices_c, x16, pulses_c, PredCoef_Q12, LTPCoef_Q14, AR_Q13, HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, >+ pitchL, Lambda_Q10, LTP_scale_Q14 ); >+#endif >+ >+ /* The optimization parallelizes the different delay decision states. */ >+ if(( psEncC->nStatesDelayedDecision > NEON_MAX_DEL_DEC_STATES ) || ( psEncC->nStatesDelayedDecision <= 2 )) { >+ /* NEON intrinsics optimization now can only parallelize up to 4 delay decision states. */ >+ /* If there are more states, C function is called, and this optimization must be expanded. */ >+ /* When the number of delay decision states is less than 3, there are penalties using this */ >+ /* optimization, and C function is called. */ >+ /* When the number of delay decision states is 2, it's better to specialize another */ >+ /* structure NSQ_del_dec2_struct and optimize with shorter NEON registers. (Low priority) */ >+ silk_NSQ_del_dec_c( psEncC, NSQ, psIndices, x16, pulses, PredCoef_Q12, LTPCoef_Q14, AR_Q13, HarmShapeGain_Q14, >+ Tilt_Q14, LF_shp_Q14, Gains_Q16, pitchL, Lambda_Q10, LTP_scale_Q14 ); >+ } else { >+ opus_int i, k, lag, start_idx, LSF_interpolation_flag, Winner_ind, subfr; >+ opus_int smpl_buf_idx, decisionDelay; >+ const opus_int16 *A_Q12, *B_Q14, *AR_shp_Q13; >+ opus_int16 *pxq; >+ VARDECL( opus_int32, sLTP_Q15 ); >+ VARDECL( opus_int16, sLTP ); >+ opus_int32 HarmShapeFIRPacked_Q14; >+ opus_int offset_Q10; >+ opus_int32 RDmin_Q10, Gain_Q10; >+ VARDECL( opus_int32, x_sc_Q10 ); >+ VARDECL( opus_int32, delayedGain_Q10 ); >+ VARDECL( NSQ_del_decs_struct, psDelDec ); >+ int32x4_t t_s32x4; >+ SAVE_STACK; >+ >+ /* Set unvoiced lag to the previous one, overwrite later for voiced */ >+ lag = NSQ->lagPrev; >+ >+ silk_assert( NSQ->prev_gain_Q16 != 0 ); >+ >+ /* Initialize delayed decision states */ >+ ALLOC( psDelDec, 1, NSQ_del_decs_struct ); >+ /* Only RandState and RD_Q10 need to be initialized to 0. */ >+ silk_memset( psDelDec->RandState, 0, sizeof( psDelDec->RandState ) ); >+ vst1q_s32( psDelDec->RD_Q10, vdupq_n_s32( 0 ) ); >+ >+ for( k = 0; k < psEncC->nStatesDelayedDecision; k++ ) { >+ psDelDec->SeedInit[ k ] = psDelDec->Seed[ k ] = ( k + psIndices->Seed ) & 3; >+ } >+ vst1q_s32( psDelDec->LF_AR_Q14, vld1q_dup_s32( &NSQ->sLF_AR_shp_Q14 ) ); >+ vst1q_s32( psDelDec->Diff_Q14, vld1q_dup_s32( &NSQ->sDiff_shp_Q14 ) ); >+ vst1q_s32( psDelDec->Shape_Q14[ 0 ], vld1q_dup_s32( &NSQ->sLTP_shp_Q14[ psEncC->ltp_mem_length - 1 ] ) ); >+ for( i = 0; i < NSQ_LPC_BUF_LENGTH; i++ ) { >+ vst1q_s32( psDelDec->sLPC_Q14[ i ], vld1q_dup_s32( &NSQ->sLPC_Q14[ i ] ) ); >+ } >+ for( i = 0; i < (opus_int)( sizeof( NSQ->sAR2_Q14 ) / sizeof( NSQ->sAR2_Q14[ 0 ] ) ); i++ ) { >+ vst1q_s32( psDelDec->sAR2_Q14[ i ], vld1q_dup_s32( &NSQ->sAR2_Q14[ i ] ) ); >+ } >+ >+ offset_Q10 = silk_Quantization_Offsets_Q10[ psIndices->signalType >> 1 ][ psIndices->quantOffsetType ]; >+ smpl_buf_idx = 0; /* index of oldest samples */ >+ >+ decisionDelay = silk_min_int( DECISION_DELAY, psEncC->subfr_length ); >+ >+ /* For voiced frames limit the decision delay to lower than the pitch lag */ >+ if( psIndices->signalType == TYPE_VOICED ) { >+ opus_int pitch_min = pitchL[ 0 ]; >+ for( k = 1; k < psEncC->nb_subfr; k++ ) { >+ pitch_min = silk_min_int( pitch_min, pitchL[ k ] ); >+ } >+ decisionDelay = silk_min_int( decisionDelay, pitch_min - LTP_ORDER / 2 - 1 ); >+ } else { >+ if( lag > 0 ) { >+ decisionDelay = silk_min_int( decisionDelay, lag - LTP_ORDER / 2 - 1 ); >+ } >+ } >+ >+ if( psIndices->NLSFInterpCoef_Q2 == 4 ) { >+ LSF_interpolation_flag = 0; >+ } else { >+ LSF_interpolation_flag = 1; >+ } >+ >+ ALLOC( sLTP_Q15, psEncC->ltp_mem_length + psEncC->frame_length, opus_int32 ); >+ ALLOC( sLTP, psEncC->ltp_mem_length + psEncC->frame_length, opus_int16 ); >+ ALLOC( x_sc_Q10, psEncC->subfr_length, opus_int32 ); >+ ALLOC( delayedGain_Q10, DECISION_DELAY, opus_int32 ); >+ /* Set up pointers to start of sub frame */ >+ pxq = &NSQ->xq[ psEncC->ltp_mem_length ]; >+ NSQ->sLTP_shp_buf_idx = psEncC->ltp_mem_length; >+ NSQ->sLTP_buf_idx = psEncC->ltp_mem_length; >+ subfr = 0; >+ for( k = 0; k < psEncC->nb_subfr; k++ ) { >+ A_Q12 = &PredCoef_Q12[ ( ( k >> 1 ) | ( 1 - LSF_interpolation_flag ) ) * MAX_LPC_ORDER ]; >+ B_Q14 = <PCoef_Q14[ k * LTP_ORDER ]; >+ AR_shp_Q13 = &AR_Q13[ k * MAX_SHAPE_LPC_ORDER ]; >+ >+ /* Noise shape parameters */ >+ silk_assert( HarmShapeGain_Q14[ k ] >= 0 ); >+ HarmShapeFIRPacked_Q14 = silk_RSHIFT( HarmShapeGain_Q14[ k ], 2 ); >+ HarmShapeFIRPacked_Q14 |= silk_LSHIFT( (opus_int32)silk_RSHIFT( HarmShapeGain_Q14[ k ], 1 ), 16 ); >+ >+ NSQ->rewhite_flag = 0; >+ if( psIndices->signalType == TYPE_VOICED ) { >+ /* Voiced */ >+ lag = pitchL[ k ]; >+ >+ /* Re-whitening */ >+ if( ( k & ( 3 - silk_LSHIFT( LSF_interpolation_flag, 1 ) ) ) == 0 ) { >+ if( k == 2 ) { >+ /* RESET DELAYED DECISIONS */ >+ /* Find winner */ >+ int32x4_t RD_Q10_s32x4; >+ RDmin_Q10 = psDelDec->RD_Q10[ 0 ]; >+ Winner_ind = 0; >+ for( i = 1; i < psEncC->nStatesDelayedDecision; i++ ) { >+ if( psDelDec->RD_Q10[ i ] < RDmin_Q10 ) { >+ RDmin_Q10 = psDelDec->RD_Q10[ i ]; >+ Winner_ind = i; >+ } >+ } >+ psDelDec->RD_Q10[ Winner_ind ] -= ( silk_int32_MAX >> 4 ); >+ RD_Q10_s32x4 = vld1q_s32( psDelDec->RD_Q10 ); >+ RD_Q10_s32x4 = vaddq_s32( RD_Q10_s32x4, vdupq_n_s32( silk_int32_MAX >> 4 ) ); >+ vst1q_s32( psDelDec->RD_Q10, RD_Q10_s32x4 ); >+ >+ /* Copy final part of signals from winner state to output and long-term filter states */ >+ copy_winner_state( psDelDec, decisionDelay, smpl_buf_idx, Winner_ind, Gains_Q16[ 1 ], 14, pulses, pxq, NSQ ); >+ >+ subfr = 0; >+ } >+ >+ /* Rewhiten with new A coefs */ >+ start_idx = psEncC->ltp_mem_length - lag - psEncC->predictLPCOrder - LTP_ORDER / 2; >+ silk_assert( start_idx > 0 ); >+ >+ silk_LPC_analysis_filter( &sLTP[ start_idx ], &NSQ->xq[ start_idx + k * psEncC->subfr_length ], >+ A_Q12, psEncC->ltp_mem_length - start_idx, psEncC->predictLPCOrder, psEncC->arch ); >+ >+ NSQ->sLTP_buf_idx = psEncC->ltp_mem_length; >+ NSQ->rewhite_flag = 1; >+ } >+ } >+ >+ silk_nsq_del_dec_scale_states_neon( psEncC, NSQ, psDelDec, x16, x_sc_Q10, sLTP, sLTP_Q15, k, >+ LTP_scale_Q14, Gains_Q16, pitchL, psIndices->signalType, decisionDelay ); >+ >+ silk_noise_shape_quantizer_del_dec_neon( NSQ, psDelDec, psIndices->signalType, x_sc_Q10, pulses, pxq, sLTP_Q15, >+ delayedGain_Q10, A_Q12, B_Q14, AR_shp_Q13, lag, HarmShapeFIRPacked_Q14, Tilt_Q14[ k ], LF_shp_Q14[ k ], >+ Gains_Q16[ k ], Lambda_Q10, offset_Q10, psEncC->subfr_length, subfr++, psEncC->shapingLPCOrder, >+ psEncC->predictLPCOrder, psEncC->warping_Q16, psEncC->nStatesDelayedDecision, &smpl_buf_idx, decisionDelay ); >+ >+ x16 += psEncC->subfr_length; >+ pulses += psEncC->subfr_length; >+ pxq += psEncC->subfr_length; >+ } >+ >+ /* Find winner */ >+ RDmin_Q10 = psDelDec->RD_Q10[ 0 ]; >+ Winner_ind = 0; >+ for( k = 1; k < psEncC->nStatesDelayedDecision; k++ ) { >+ if( psDelDec->RD_Q10[ k ] < RDmin_Q10 ) { >+ RDmin_Q10 = psDelDec->RD_Q10[ k ]; >+ Winner_ind = k; >+ } >+ } >+ >+ /* Copy final part of signals from winner state to output and long-term filter states */ >+ psIndices->Seed = psDelDec->SeedInit[ Winner_ind ]; >+ Gain_Q10 = silk_RSHIFT32( Gains_Q16[ psEncC->nb_subfr - 1 ], 6 ); >+ copy_winner_state( psDelDec, decisionDelay, smpl_buf_idx, Winner_ind, Gain_Q10, 8, pulses, pxq, NSQ ); >+ >+ t_s32x4 = vdupq_n_s32( 0 ); /* initialization */ >+ for( i = 0; i < ( NSQ_LPC_BUF_LENGTH - 3 ); i += 4 ) { >+ t_s32x4 = vld1q_lane_s32( &psDelDec->sLPC_Q14[ i + 0 ][ Winner_ind ], t_s32x4, 0 ); >+ t_s32x4 = vld1q_lane_s32( &psDelDec->sLPC_Q14[ i + 1 ][ Winner_ind ], t_s32x4, 1 ); >+ t_s32x4 = vld1q_lane_s32( &psDelDec->sLPC_Q14[ i + 2 ][ Winner_ind ], t_s32x4, 2 ); >+ t_s32x4 = vld1q_lane_s32( &psDelDec->sLPC_Q14[ i + 3 ][ Winner_ind ], t_s32x4, 3 ); >+ vst1q_s32( &NSQ->sLPC_Q14[ i ], t_s32x4 ); >+ } >+ >+ for( ; i < NSQ_LPC_BUF_LENGTH; i++ ) { >+ NSQ->sLPC_Q14[ i ] = psDelDec->sLPC_Q14[ i ][ Winner_ind ]; >+ } >+ >+ for( i = 0; i < (opus_int)( sizeof( NSQ->sAR2_Q14 ) / sizeof( NSQ->sAR2_Q14[ 0 ] ) - 3 ); i += 4 ) { >+ t_s32x4 = vld1q_lane_s32( &psDelDec->sAR2_Q14[ i + 0 ][ Winner_ind ], t_s32x4, 0 ); >+ t_s32x4 = vld1q_lane_s32( &psDelDec->sAR2_Q14[ i + 1 ][ Winner_ind ], t_s32x4, 1 ); >+ t_s32x4 = vld1q_lane_s32( &psDelDec->sAR2_Q14[ i + 2 ][ Winner_ind ], t_s32x4, 2 ); >+ t_s32x4 = vld1q_lane_s32( &psDelDec->sAR2_Q14[ i + 3 ][ Winner_ind ], t_s32x4, 3 ); >+ vst1q_s32( &NSQ->sAR2_Q14[ i ], t_s32x4 ); >+ } >+ >+ for( ; i < (opus_int)( sizeof( NSQ->sAR2_Q14 ) / sizeof( NSQ->sAR2_Q14[ 0 ] ) ); i++ ) { >+ NSQ->sAR2_Q14[ i ] = psDelDec->sAR2_Q14[ i ][ Winner_ind ]; >+ } >+ >+ /* Update states */ >+ NSQ->sLF_AR_shp_Q14 = psDelDec->LF_AR_Q14[ Winner_ind ]; >+ NSQ->sDiff_shp_Q14 = psDelDec->Diff_Q14[ Winner_ind ]; >+ NSQ->lagPrev = pitchL[ psEncC->nb_subfr - 1 ]; >+ >+ /* Save quantized speech signal */ >+ silk_memmove( NSQ->xq, &NSQ->xq[ psEncC->frame_length ], psEncC->ltp_mem_length * sizeof( opus_int16 ) ); >+ silk_memmove( NSQ->sLTP_shp_Q14, &NSQ->sLTP_shp_Q14[ psEncC->frame_length ], psEncC->ltp_mem_length * sizeof( opus_int32 ) ); >+ RESTORE_STACK; >+ } >+ >+#ifdef OPUS_CHECK_ASM >+ silk_assert( !memcmp( &NSQ_c, NSQ, sizeof( NSQ_c ) ) ); >+ silk_assert( !memcmp( &psIndices_c, psIndices, sizeof( psIndices_c ) ) ); >+ silk_assert( !memcmp( pulses_c, pulses_a, sizeof( pulses_c ) ) ); >+#endif >+} >+ >+/******************************************/ >+/* Noise shape quantizer for one subframe */ >+/******************************************/ >+/* Note: Function silk_short_prediction_create_arch_coef_neon() defined in NSQ_neon.h is actually a hacking C function. */ >+/* Therefore here we append "_local" to the NEON function name to avoid confusion. */ >+static OPUS_INLINE void silk_short_prediction_create_arch_coef_neon_local(opus_int32 *out, const opus_int16 *in, opus_int order) >+{ >+ int16x8_t t_s16x8; >+ int32x4_t t0_s32x4, t1_s32x4, t2_s32x4, t3_s32x4; >+ silk_assert( order == 10 || order == 16 ); >+ >+ t_s16x8 = vld1q_s16( in + 0 ); /* 7 6 5 4 3 2 1 0 */ >+ t_s16x8 = vrev64q_s16( t_s16x8 ); /* 4 5 6 7 0 1 2 3 */ >+ t2_s32x4 = vshll_n_s16( vget_high_s16( t_s16x8 ), 15 ); /* 4 5 6 7 */ >+ t3_s32x4 = vshll_n_s16( vget_low_s16( t_s16x8 ), 15 ); /* 0 1 2 3 */ >+ >+ if( order == 16 ) { >+ t_s16x8 = vld1q_s16( in + 8 ); /* F E D C B A 9 8 */ >+ t_s16x8 = vrev64q_s16( t_s16x8 ); /* C D E F 8 9 A B */ >+ t0_s32x4 = vshll_n_s16( vget_high_s16( t_s16x8 ), 15 ); /* C D E F */ >+ t1_s32x4 = vshll_n_s16( vget_low_s16( t_s16x8 ), 15 ); /* 8 9 A B */ >+ } else { >+ int16x4_t t_s16x4; >+ >+ t0_s32x4 = vdupq_n_s32( 0 ); /* zero zero zero zero */ >+ t_s16x4 = vld1_s16( in + 6 ); /* 9 8 7 6 */ >+ t_s16x4 = vrev64_s16( t_s16x4 ); /* 6 7 8 9 */ >+ t1_s32x4 = vshll_n_s16( t_s16x4, 15 ); >+ t1_s32x4 = vcombine_s32( vget_low_s32(t0_s32x4), vget_low_s32( t1_s32x4 ) ); /* 8 9 zero zero */ >+ } >+ vst1q_s32( out + 0, t0_s32x4 ); >+ vst1q_s32( out + 4, t1_s32x4 ); >+ vst1q_s32( out + 8, t2_s32x4 ); >+ vst1q_s32( out + 12, t3_s32x4 ); >+} >+ >+static OPUS_INLINE int32x4_t silk_SMLAWB_lane0_neon( >+ const int32x4_t out_s32x4, >+ const int32x4_t in_s32x4, >+ const int32x2_t coef_s32x2 >+) >+{ >+ return vaddq_s32( out_s32x4, vqdmulhq_lane_s32( in_s32x4, coef_s32x2, 0 ) ); >+} >+ >+static OPUS_INLINE int32x4_t silk_SMLAWB_lane1_neon( >+ const int32x4_t out_s32x4, >+ const int32x4_t in_s32x4, >+ const int32x2_t coef_s32x2 >+) >+{ >+ return vaddq_s32( out_s32x4, vqdmulhq_lane_s32( in_s32x4, coef_s32x2, 1 ) ); >+} >+ >+/* Note: This function has different return value than silk_noise_shape_quantizer_short_prediction_neon(). */ >+/* Therefore here we append "_local" to the function name to avoid confusion. */ >+static OPUS_INLINE int32x4_t silk_noise_shape_quantizer_short_prediction_neon_local(const opus_int32 *buf32, const opus_int32 *a_Q12_arch, opus_int order) >+{ >+ const int32x4_t a_Q12_arch0_s32x4 = vld1q_s32( a_Q12_arch + 0 ); >+ const int32x4_t a_Q12_arch1_s32x4 = vld1q_s32( a_Q12_arch + 4 ); >+ const int32x4_t a_Q12_arch2_s32x4 = vld1q_s32( a_Q12_arch + 8 ); >+ const int32x4_t a_Q12_arch3_s32x4 = vld1q_s32( a_Q12_arch + 12 ); >+ int32x4_t LPC_pred_Q14_s32x4; >+ >+ silk_assert( order == 10 || order == 16 ); >+ /* Avoids introducing a bias because silk_SMLAWB() always rounds to -inf */ >+ LPC_pred_Q14_s32x4 = vdupq_n_s32( silk_RSHIFT( order, 1 ) ); >+ LPC_pred_Q14_s32x4 = silk_SMLAWB_lane0_neon( LPC_pred_Q14_s32x4, vld1q_s32( buf32 + 0 * NEON_MAX_DEL_DEC_STATES ), vget_low_s32( a_Q12_arch0_s32x4 ) ); >+ LPC_pred_Q14_s32x4 = silk_SMLAWB_lane1_neon( LPC_pred_Q14_s32x4, vld1q_s32( buf32 + 1 * NEON_MAX_DEL_DEC_STATES ), vget_low_s32( a_Q12_arch0_s32x4 ) ); >+ LPC_pred_Q14_s32x4 = silk_SMLAWB_lane0_neon( LPC_pred_Q14_s32x4, vld1q_s32( buf32 + 2 * NEON_MAX_DEL_DEC_STATES ), vget_high_s32( a_Q12_arch0_s32x4 ) ); >+ LPC_pred_Q14_s32x4 = silk_SMLAWB_lane1_neon( LPC_pred_Q14_s32x4, vld1q_s32( buf32 + 3 * NEON_MAX_DEL_DEC_STATES ), vget_high_s32( a_Q12_arch0_s32x4 ) ); >+ LPC_pred_Q14_s32x4 = silk_SMLAWB_lane0_neon( LPC_pred_Q14_s32x4, vld1q_s32( buf32 + 4 * NEON_MAX_DEL_DEC_STATES ), vget_low_s32( a_Q12_arch1_s32x4 ) ); >+ LPC_pred_Q14_s32x4 = silk_SMLAWB_lane1_neon( LPC_pred_Q14_s32x4, vld1q_s32( buf32 + 5 * NEON_MAX_DEL_DEC_STATES ), vget_low_s32( a_Q12_arch1_s32x4 ) ); >+ LPC_pred_Q14_s32x4 = silk_SMLAWB_lane0_neon( LPC_pred_Q14_s32x4, vld1q_s32( buf32 + 6 * NEON_MAX_DEL_DEC_STATES ), vget_high_s32( a_Q12_arch1_s32x4 ) ); >+ LPC_pred_Q14_s32x4 = silk_SMLAWB_lane1_neon( LPC_pred_Q14_s32x4, vld1q_s32( buf32 + 7 * NEON_MAX_DEL_DEC_STATES ), vget_high_s32( a_Q12_arch1_s32x4 ) ); >+ LPC_pred_Q14_s32x4 = silk_SMLAWB_lane0_neon( LPC_pred_Q14_s32x4, vld1q_s32( buf32 + 8 * NEON_MAX_DEL_DEC_STATES ), vget_low_s32( a_Q12_arch2_s32x4 ) ); >+ LPC_pred_Q14_s32x4 = silk_SMLAWB_lane1_neon( LPC_pred_Q14_s32x4, vld1q_s32( buf32 + 9 * NEON_MAX_DEL_DEC_STATES ), vget_low_s32( a_Q12_arch2_s32x4 ) ); >+ LPC_pred_Q14_s32x4 = silk_SMLAWB_lane0_neon( LPC_pred_Q14_s32x4, vld1q_s32( buf32 + 10 * NEON_MAX_DEL_DEC_STATES ), vget_high_s32( a_Q12_arch2_s32x4 ) ); >+ LPC_pred_Q14_s32x4 = silk_SMLAWB_lane1_neon( LPC_pred_Q14_s32x4, vld1q_s32( buf32 + 11 * NEON_MAX_DEL_DEC_STATES ), vget_high_s32( a_Q12_arch2_s32x4 ) ); >+ LPC_pred_Q14_s32x4 = silk_SMLAWB_lane0_neon( LPC_pred_Q14_s32x4, vld1q_s32( buf32 + 12 * NEON_MAX_DEL_DEC_STATES ), vget_low_s32( a_Q12_arch3_s32x4 ) ); >+ LPC_pred_Q14_s32x4 = silk_SMLAWB_lane1_neon( LPC_pred_Q14_s32x4, vld1q_s32( buf32 + 13 * NEON_MAX_DEL_DEC_STATES ), vget_low_s32( a_Q12_arch3_s32x4 ) ); >+ LPC_pred_Q14_s32x4 = silk_SMLAWB_lane0_neon( LPC_pred_Q14_s32x4, vld1q_s32( buf32 + 14 * NEON_MAX_DEL_DEC_STATES ), vget_high_s32( a_Q12_arch3_s32x4 ) ); >+ LPC_pred_Q14_s32x4 = silk_SMLAWB_lane1_neon( LPC_pred_Q14_s32x4, vld1q_s32( buf32 + 15 * NEON_MAX_DEL_DEC_STATES ), vget_high_s32( a_Q12_arch3_s32x4 ) ); >+ >+ return LPC_pred_Q14_s32x4; >+} >+ >+static OPUS_INLINE void silk_noise_shape_quantizer_del_dec_neon( >+ silk_nsq_state *NSQ, /* I/O NSQ state */ >+ NSQ_del_decs_struct psDelDec[], /* I/O Delayed decision states */ >+ opus_int signalType, /* I Signal type */ >+ const opus_int32 x_Q10[], /* I */ >+ opus_int8 pulses[], /* O */ >+ opus_int16 xq[], /* O */ >+ opus_int32 sLTP_Q15[], /* I/O LTP filter state */ >+ opus_int32 delayedGain_Q10[], /* I/O Gain delay buffer */ >+ const opus_int16 a_Q12[], /* I Short term prediction coefs */ >+ const opus_int16 b_Q14[], /* I Long term prediction coefs */ >+ const opus_int16 AR_shp_Q13[], /* I Noise shaping coefs */ >+ opus_int lag, /* I Pitch lag */ >+ opus_int32 HarmShapeFIRPacked_Q14, /* I */ >+ opus_int Tilt_Q14, /* I Spectral tilt */ >+ opus_int32 LF_shp_Q14, /* I */ >+ opus_int32 Gain_Q16, /* I */ >+ opus_int Lambda_Q10, /* I */ >+ opus_int offset_Q10, /* I */ >+ opus_int length, /* I Input length */ >+ opus_int subfr, /* I Subframe number */ >+ opus_int shapingLPCOrder, /* I Shaping LPC filter order */ >+ opus_int predictLPCOrder, /* I Prediction filter order */ >+ opus_int warping_Q16, /* I */ >+ opus_int nStatesDelayedDecision, /* I Number of states in decision tree */ >+ opus_int *smpl_buf_idx, /* I/O Index to newest samples in buffers */ >+ opus_int decisionDelay /* I */ >+) >+{ >+ opus_int i, j, k, Winner_ind, RDmin_ind, RDmax_ind, last_smple_idx; >+ opus_int32 Winner_rand_state; >+ opus_int32 LTP_pred_Q14, n_LTP_Q14; >+ opus_int32 RDmin_Q10, RDmax_Q10; >+ opus_int32 Gain_Q10; >+ opus_int32 *pred_lag_ptr, *shp_lag_ptr; >+ opus_int32 a_Q12_arch[MAX_LPC_ORDER]; >+ const int32x2_t warping_Q16_s32x2 = vdup_n_s32( silk_LSHIFT32( warping_Q16, 16 ) >> 1 ); >+ const opus_int32 LF_shp_Q29 = silk_LSHIFT32( LF_shp_Q14, 16 ) >> 1; >+ opus_int32 AR_shp_Q28[ MAX_SHAPE_LPC_ORDER ]; >+ const uint32x4_t rand_multiplier_u32x4 = vdupq_n_u32( RAND_MULTIPLIER ); >+ const uint32x4_t rand_increment_u32x4 = vdupq_n_u32( RAND_INCREMENT ); >+ >+ VARDECL( NSQ_samples_struct, psSampleState ); >+ SAVE_STACK; >+ >+ silk_assert( nStatesDelayedDecision > 0 ); >+ silk_assert( ( shapingLPCOrder & 1 ) == 0 ); /* check that order is even */ >+ ALLOC( psSampleState, 2, NSQ_samples_struct ); >+ >+ shp_lag_ptr = &NSQ->sLTP_shp_Q14[ NSQ->sLTP_shp_buf_idx - lag + HARM_SHAPE_FIR_TAPS / 2 ]; >+ pred_lag_ptr = &sLTP_Q15[ NSQ->sLTP_buf_idx - lag + LTP_ORDER / 2 ]; >+ Gain_Q10 = silk_RSHIFT( Gain_Q16, 6 ); >+ >+ for( i = 0; i < ( MAX_SHAPE_LPC_ORDER - 7 ); i += 8 ) { >+ const int16x8_t t_s16x8 = vld1q_s16( AR_shp_Q13 + i ); >+ vst1q_s32( AR_shp_Q28 + i + 0, vshll_n_s16( vget_low_s16( t_s16x8 ), 15 ) ); >+ vst1q_s32( AR_shp_Q28 + i + 4, vshll_n_s16( vget_high_s16( t_s16x8 ), 15 ) ); >+ } >+ >+ for( ; i < MAX_SHAPE_LPC_ORDER; i++ ) { >+ AR_shp_Q28[i] = silk_LSHIFT32( AR_shp_Q13[i], 15 ); >+ } >+ >+ silk_short_prediction_create_arch_coef_neon_local( a_Q12_arch, a_Q12, predictLPCOrder ); >+ >+ for( i = 0; i < length; i++ ) { >+ int32x4_t Seed_s32x4, LPC_pred_Q14_s32x4; >+ int32x4_t sign_s32x4, tmp1_s32x4, tmp2_s32x4; >+ int32x4_t n_AR_Q14_s32x4, n_LF_Q14_s32x4; >+ int32x2_t AR_shp_Q28_s32x2; >+ int16x4_t r_Q10_s16x4, rr_Q10_s16x4; >+ >+ /* Perform common calculations used in all states */ >+ >+ /* Long-term prediction */ >+ if( signalType == TYPE_VOICED ) { >+ /* Unrolled loop */ >+ /* Avoids introducing a bias because silk_SMLAWB() always rounds to -inf */ >+ LTP_pred_Q14 = 2; >+ LTP_pred_Q14 = silk_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ 0 ], b_Q14[ 0 ] ); >+ LTP_pred_Q14 = silk_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -1 ], b_Q14[ 1 ] ); >+ LTP_pred_Q14 = silk_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -2 ], b_Q14[ 2 ] ); >+ LTP_pred_Q14 = silk_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -3 ], b_Q14[ 3 ] ); >+ LTP_pred_Q14 = silk_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -4 ], b_Q14[ 4 ] ); >+ LTP_pred_Q14 = silk_LSHIFT( LTP_pred_Q14, 1 ); /* Q13 -> Q14 */ >+ pred_lag_ptr++; >+ } else { >+ LTP_pred_Q14 = 0; >+ } >+ >+ /* Long-term shaping */ >+ if( lag > 0 ) { >+ /* Symmetric, packed FIR coefficients */ >+ n_LTP_Q14 = silk_SMULWB( silk_ADD32( shp_lag_ptr[ 0 ], shp_lag_ptr[ -2 ] ), HarmShapeFIRPacked_Q14 ); >+ n_LTP_Q14 = silk_SMLAWT( n_LTP_Q14, shp_lag_ptr[ -1 ], HarmShapeFIRPacked_Q14 ); >+ n_LTP_Q14 = silk_SUB_LSHIFT32( LTP_pred_Q14, n_LTP_Q14, 2 ); /* Q12 -> Q14 */ >+ shp_lag_ptr++; >+ } else { >+ n_LTP_Q14 = 0; >+ } >+ >+ /* Generate dither */ >+ Seed_s32x4 = vld1q_s32( psDelDec->Seed ); >+ Seed_s32x4 = vreinterpretq_s32_u32( vmlaq_u32( rand_increment_u32x4, vreinterpretq_u32_s32( Seed_s32x4 ), rand_multiplier_u32x4 ) ); >+ vst1q_s32( psDelDec->Seed, Seed_s32x4 ); >+ >+ /* Short-term prediction */ >+ LPC_pred_Q14_s32x4 = silk_noise_shape_quantizer_short_prediction_neon_local(psDelDec->sLPC_Q14[ NSQ_LPC_BUF_LENGTH - 16 + i ], a_Q12_arch, predictLPCOrder); >+ LPC_pred_Q14_s32x4 = vshlq_n_s32( LPC_pred_Q14_s32x4, 4 ); /* Q10 -> Q14 */ >+ >+ /* Noise shape feedback */ >+ /* Output of lowpass section */ >+ tmp2_s32x4 = silk_SMLAWB_lane0_neon( vld1q_s32( psDelDec->Diff_Q14 ), vld1q_s32( psDelDec->sAR2_Q14[ 0 ] ), warping_Q16_s32x2 ); >+ /* Output of allpass section */ >+ tmp1_s32x4 = vsubq_s32( vld1q_s32( psDelDec->sAR2_Q14[ 1 ] ), tmp2_s32x4 ); >+ tmp1_s32x4 = silk_SMLAWB_lane0_neon( vld1q_s32( psDelDec->sAR2_Q14[ 0 ] ), tmp1_s32x4, warping_Q16_s32x2 ); >+ vst1q_s32( psDelDec->sAR2_Q14[ 0 ], tmp2_s32x4 ); >+ AR_shp_Q28_s32x2 = vld1_s32( AR_shp_Q28 ); >+ n_AR_Q14_s32x4 = vaddq_s32( vdupq_n_s32( silk_RSHIFT( shapingLPCOrder, 1 ) ), vqdmulhq_lane_s32( tmp2_s32x4, AR_shp_Q28_s32x2, 0 ) ); >+ >+ /* Loop over allpass sections */ >+ for( j = 2; j < shapingLPCOrder; j += 2 ) { >+ /* Output of allpass section */ >+ tmp2_s32x4 = vsubq_s32( vld1q_s32( psDelDec->sAR2_Q14[ j + 0 ] ), tmp1_s32x4 ); >+ tmp2_s32x4 = silk_SMLAWB_lane0_neon( vld1q_s32( psDelDec->sAR2_Q14[ j - 1 ] ), tmp2_s32x4, warping_Q16_s32x2 ); >+ vst1q_s32( psDelDec->sAR2_Q14[ j - 1 ], tmp1_s32x4 ); >+ n_AR_Q14_s32x4 = vaddq_s32( n_AR_Q14_s32x4, vqdmulhq_lane_s32( tmp1_s32x4, AR_shp_Q28_s32x2, 1 ) ); >+ /* Output of allpass section */ >+ tmp1_s32x4 = vsubq_s32( vld1q_s32( psDelDec->sAR2_Q14[ j + 1 ] ), tmp2_s32x4 ); >+ tmp1_s32x4 = silk_SMLAWB_lane0_neon( vld1q_s32( psDelDec->sAR2_Q14[ j + 0 ] ), tmp1_s32x4, warping_Q16_s32x2 ); >+ vst1q_s32( psDelDec->sAR2_Q14[ j + 0 ], tmp2_s32x4 ); >+ AR_shp_Q28_s32x2 = vld1_s32( &AR_shp_Q28[ j ] ); >+ n_AR_Q14_s32x4 = vaddq_s32( n_AR_Q14_s32x4, vqdmulhq_lane_s32( tmp2_s32x4, AR_shp_Q28_s32x2, 0 ) ); >+ } >+ vst1q_s32( psDelDec->sAR2_Q14[ shapingLPCOrder - 1 ], tmp1_s32x4 ); >+ n_AR_Q14_s32x4 = vaddq_s32( n_AR_Q14_s32x4, vqdmulhq_lane_s32( tmp1_s32x4, AR_shp_Q28_s32x2, 1 ) ); >+ n_AR_Q14_s32x4 = vshlq_n_s32( n_AR_Q14_s32x4, 1 ); /* Q11 -> Q12 */ >+ n_AR_Q14_s32x4 = vaddq_s32( n_AR_Q14_s32x4, vqdmulhq_n_s32( vld1q_s32( psDelDec->LF_AR_Q14 ), silk_LSHIFT32( Tilt_Q14, 16 ) >> 1 ) ); /* Q12 */ >+ n_AR_Q14_s32x4 = vshlq_n_s32( n_AR_Q14_s32x4, 2 ); /* Q12 -> Q14 */ >+ n_LF_Q14_s32x4 = vqdmulhq_n_s32( vld1q_s32( psDelDec->Shape_Q14[ *smpl_buf_idx ] ), LF_shp_Q29 ); /* Q12 */ >+ n_LF_Q14_s32x4 = vaddq_s32( n_LF_Q14_s32x4, vqdmulhq_n_s32( vld1q_s32( psDelDec->LF_AR_Q14 ), silk_LSHIFT32( LF_shp_Q14 >> 16 , 15 ) ) ); /* Q12 */ >+ n_LF_Q14_s32x4 = vshlq_n_s32( n_LF_Q14_s32x4, 2 ); /* Q12 -> Q14 */ >+ >+ /* Input minus prediction plus noise feedback */ >+ /* r = x[ i ] - LTP_pred - LPC_pred + n_AR + n_Tilt + n_LF + n_LTP */ >+ tmp1_s32x4 = vaddq_s32( n_AR_Q14_s32x4, n_LF_Q14_s32x4 ); /* Q14 */ >+ tmp2_s32x4 = vaddq_s32( vdupq_n_s32( n_LTP_Q14 ), LPC_pred_Q14_s32x4 ); /* Q13 */ >+ tmp1_s32x4 = vsubq_s32( tmp2_s32x4, tmp1_s32x4 ); /* Q13 */ >+ tmp1_s32x4 = vrshrq_n_s32( tmp1_s32x4, 4 ); /* Q10 */ >+ tmp1_s32x4 = vsubq_s32( vdupq_n_s32( x_Q10[ i ] ), tmp1_s32x4 ); /* residual error Q10 */ >+ >+ /* Flip sign depending on dither */ >+ sign_s32x4 = vreinterpretq_s32_u32( vcltq_s32( Seed_s32x4, vdupq_n_s32( 0 ) ) ); >+ tmp1_s32x4 = veorq_s32( tmp1_s32x4, sign_s32x4 ); >+ tmp1_s32x4 = vsubq_s32( tmp1_s32x4, sign_s32x4 ); >+ tmp1_s32x4 = vmaxq_s32( tmp1_s32x4, vdupq_n_s32( -( 31 << 10 ) ) ); >+ tmp1_s32x4 = vminq_s32( tmp1_s32x4, vdupq_n_s32( 30 << 10 ) ); >+ r_Q10_s16x4 = vmovn_s32( tmp1_s32x4 ); >+ >+ /* Find two quantization level candidates and measure their rate-distortion */ >+ { >+ int16x4_t q1_Q10_s16x4 = vsub_s16( r_Q10_s16x4, vdup_n_s16( offset_Q10 ) ); >+ int16x4_t q1_Q0_s16x4 = vshr_n_s16( q1_Q10_s16x4, 10 ); >+ int16x4_t q2_Q10_s16x4; >+ int32x4_t rd1_Q10_s32x4, rd2_Q10_s32x4; >+ uint32x4_t t_u32x4; >+ >+ if( Lambda_Q10 > 2048 ) { >+ /* For aggressive RDO, the bias becomes more than one pulse. */ >+ const int rdo_offset = Lambda_Q10/2 - 512; >+ const uint16x4_t greaterThanRdo = vcgt_s16( q1_Q10_s16x4, vdup_n_s16( rdo_offset ) ); >+ const uint16x4_t lessThanMinusRdo = vclt_s16( q1_Q10_s16x4, vdup_n_s16( -rdo_offset ) ); >+ /* If Lambda_Q10 > 32767, then q1_Q0, q1_Q10 and q2_Q10 must change to 32-bit. */ >+ silk_assert( Lambda_Q10 <= 32767 ); >+ >+ q1_Q0_s16x4 = vreinterpret_s16_u16( vclt_s16( q1_Q10_s16x4, vdup_n_s16( 0 ) ) ); >+ q1_Q0_s16x4 = vbsl_s16( greaterThanRdo, vsub_s16( q1_Q10_s16x4, vdup_n_s16( rdo_offset ) ), q1_Q0_s16x4 ); >+ q1_Q0_s16x4 = vbsl_s16( lessThanMinusRdo, vadd_s16( q1_Q10_s16x4, vdup_n_s16( rdo_offset ) ), q1_Q0_s16x4 ); >+ q1_Q0_s16x4 = vshr_n_s16( q1_Q0_s16x4, 10 ); >+ } >+ { >+ const uint16x4_t equal0_u16x4 = vceq_s16( q1_Q0_s16x4, vdup_n_s16( 0 ) ); >+ const uint16x4_t equalMinus1_u16x4 = vceq_s16( q1_Q0_s16x4, vdup_n_s16( -1 ) ); >+ const uint16x4_t lessThanMinus1_u16x4 = vclt_s16( q1_Q0_s16x4, vdup_n_s16( -1 ) ); >+ int16x4_t tmp1_s16x4, tmp2_s16x4; >+ >+ q1_Q10_s16x4 = vshl_n_s16( q1_Q0_s16x4, 10 ); >+ tmp1_s16x4 = vadd_s16( q1_Q10_s16x4, vdup_n_s16( offset_Q10 - QUANT_LEVEL_ADJUST_Q10 ) ); >+ q1_Q10_s16x4 = vadd_s16( q1_Q10_s16x4, vdup_n_s16( offset_Q10 + QUANT_LEVEL_ADJUST_Q10 ) ); >+ q1_Q10_s16x4 = vbsl_s16( lessThanMinus1_u16x4, q1_Q10_s16x4, tmp1_s16x4 ); >+ q1_Q10_s16x4 = vbsl_s16( equal0_u16x4, vdup_n_s16( offset_Q10 ), q1_Q10_s16x4 ); >+ q1_Q10_s16x4 = vbsl_s16( equalMinus1_u16x4, vdup_n_s16( offset_Q10 - ( 1024 - QUANT_LEVEL_ADJUST_Q10 ) ), q1_Q10_s16x4 ); >+ q2_Q10_s16x4 = vadd_s16( q1_Q10_s16x4, vdup_n_s16( 1024 ) ); >+ q2_Q10_s16x4 = vbsl_s16( equal0_u16x4, vdup_n_s16( offset_Q10 + 1024 - QUANT_LEVEL_ADJUST_Q10 ), q2_Q10_s16x4 ); >+ q2_Q10_s16x4 = vbsl_s16( equalMinus1_u16x4, vdup_n_s16( offset_Q10 ), q2_Q10_s16x4 ); >+ tmp1_s16x4 = q1_Q10_s16x4; >+ tmp2_s16x4 = q2_Q10_s16x4; >+ tmp1_s16x4 = vbsl_s16( vorr_u16( equalMinus1_u16x4, lessThanMinus1_u16x4 ), vneg_s16( tmp1_s16x4 ), tmp1_s16x4 ); >+ tmp2_s16x4 = vbsl_s16( lessThanMinus1_u16x4, vneg_s16( tmp2_s16x4 ), tmp2_s16x4 ); >+ rd1_Q10_s32x4 = vmull_s16( tmp1_s16x4, vdup_n_s16( Lambda_Q10 ) ); >+ rd2_Q10_s32x4 = vmull_s16( tmp2_s16x4, vdup_n_s16( Lambda_Q10 ) ); >+ } >+ >+ rr_Q10_s16x4 = vsub_s16( r_Q10_s16x4, q1_Q10_s16x4 ); >+ rd1_Q10_s32x4 = vmlal_s16( rd1_Q10_s32x4, rr_Q10_s16x4, rr_Q10_s16x4 ); >+ rd1_Q10_s32x4 = vshrq_n_s32( rd1_Q10_s32x4, 10 ); >+ >+ rr_Q10_s16x4 = vsub_s16( r_Q10_s16x4, q2_Q10_s16x4 ); >+ rd2_Q10_s32x4 = vmlal_s16( rd2_Q10_s32x4, rr_Q10_s16x4, rr_Q10_s16x4 ); >+ rd2_Q10_s32x4 = vshrq_n_s32( rd2_Q10_s32x4, 10 ); >+ >+ tmp2_s32x4 = vld1q_s32( psDelDec->RD_Q10 ); >+ tmp1_s32x4 = vaddq_s32( tmp2_s32x4, vminq_s32( rd1_Q10_s32x4, rd2_Q10_s32x4 ) ); >+ tmp2_s32x4 = vaddq_s32( tmp2_s32x4, vmaxq_s32( rd1_Q10_s32x4, rd2_Q10_s32x4 ) ); >+ vst1q_s32( psSampleState[ 0 ].RD_Q10, tmp1_s32x4 ); >+ vst1q_s32( psSampleState[ 1 ].RD_Q10, tmp2_s32x4 ); >+ t_u32x4 = vcltq_s32( rd1_Q10_s32x4, rd2_Q10_s32x4 ); >+ tmp1_s32x4 = vbslq_s32( t_u32x4, vmovl_s16( q1_Q10_s16x4 ), vmovl_s16( q2_Q10_s16x4 ) ); >+ tmp2_s32x4 = vbslq_s32( t_u32x4, vmovl_s16( q2_Q10_s16x4 ), vmovl_s16( q1_Q10_s16x4 ) ); >+ vst1q_s32( psSampleState[ 0 ].Q_Q10, tmp1_s32x4 ); >+ vst1q_s32( psSampleState[ 1 ].Q_Q10, tmp2_s32x4 ); >+ } >+ >+ { >+ /* Update states for best quantization */ >+ int32x4_t exc_Q14_s32x4, LPC_exc_Q14_s32x4, xq_Q14_s32x4, sLF_AR_shp_Q14_s32x4; >+ >+ /* Quantized excitation */ >+ exc_Q14_s32x4 = vshlq_n_s32( tmp1_s32x4, 4 ); >+ exc_Q14_s32x4 = veorq_s32( exc_Q14_s32x4, sign_s32x4 ); >+ exc_Q14_s32x4 = vsubq_s32( exc_Q14_s32x4, sign_s32x4 ); >+ >+ /* Add predictions */ >+ LPC_exc_Q14_s32x4 = vaddq_s32( exc_Q14_s32x4, vdupq_n_s32( LTP_pred_Q14 ) ); >+ xq_Q14_s32x4 = vaddq_s32( LPC_exc_Q14_s32x4, LPC_pred_Q14_s32x4 ); >+ >+ /* Update states */ >+ tmp1_s32x4 = vsubq_s32( xq_Q14_s32x4, vshlq_n_s32( vdupq_n_s32( x_Q10[ i ] ), 4 ) ); >+ vst1q_s32( psSampleState[ 0 ].Diff_Q14, tmp1_s32x4 ); >+ sLF_AR_shp_Q14_s32x4 = vsubq_s32( tmp1_s32x4, n_AR_Q14_s32x4 ); >+ vst1q_s32( psSampleState[ 0 ].sLTP_shp_Q14, vsubq_s32( sLF_AR_shp_Q14_s32x4, n_LF_Q14_s32x4 ) ); >+ vst1q_s32( psSampleState[ 0 ].LF_AR_Q14, sLF_AR_shp_Q14_s32x4 ); >+ vst1q_s32( psSampleState[ 0 ].LPC_exc_Q14, LPC_exc_Q14_s32x4 ); >+ vst1q_s32( psSampleState[ 0 ].xq_Q14, xq_Q14_s32x4 ); >+ >+ /* Quantized excitation */ >+ exc_Q14_s32x4 = vshlq_n_s32( tmp2_s32x4, 4 ); >+ exc_Q14_s32x4 = veorq_s32( exc_Q14_s32x4, sign_s32x4 ); >+ exc_Q14_s32x4 = vsubq_s32( exc_Q14_s32x4, sign_s32x4 ); >+ >+ /* Add predictions */ >+ LPC_exc_Q14_s32x4 = vaddq_s32( exc_Q14_s32x4, vdupq_n_s32( LTP_pred_Q14 ) ); >+ xq_Q14_s32x4 = vaddq_s32( LPC_exc_Q14_s32x4, LPC_pred_Q14_s32x4 ); >+ >+ /* Update states */ >+ tmp1_s32x4 = vsubq_s32( xq_Q14_s32x4, vshlq_n_s32( vdupq_n_s32( x_Q10[ i ] ), 4 ) ); >+ vst1q_s32( psSampleState[ 1 ].Diff_Q14, tmp1_s32x4 ); >+ sLF_AR_shp_Q14_s32x4 = vsubq_s32( tmp1_s32x4, n_AR_Q14_s32x4 ); >+ vst1q_s32( psSampleState[ 1 ].sLTP_shp_Q14, vsubq_s32( sLF_AR_shp_Q14_s32x4, n_LF_Q14_s32x4 ) ); >+ vst1q_s32( psSampleState[ 1 ].LF_AR_Q14, sLF_AR_shp_Q14_s32x4 ); >+ vst1q_s32( psSampleState[ 1 ].LPC_exc_Q14, LPC_exc_Q14_s32x4 ); >+ vst1q_s32( psSampleState[ 1 ].xq_Q14, xq_Q14_s32x4 ); >+ } >+ >+ *smpl_buf_idx = *smpl_buf_idx ? ( *smpl_buf_idx - 1 ) : ( DECISION_DELAY - 1); >+ last_smple_idx = *smpl_buf_idx + decisionDelay + DECISION_DELAY; >+ if( last_smple_idx >= DECISION_DELAY ) last_smple_idx -= DECISION_DELAY; >+ if( last_smple_idx >= DECISION_DELAY ) last_smple_idx -= DECISION_DELAY; >+ >+ /* Find winner */ >+ RDmin_Q10 = psSampleState[ 0 ].RD_Q10[ 0 ]; >+ Winner_ind = 0; >+ for( k = 1; k < nStatesDelayedDecision; k++ ) { >+ if( psSampleState[ 0 ].RD_Q10[ k ] < RDmin_Q10 ) { >+ RDmin_Q10 = psSampleState[ 0 ].RD_Q10[ k ]; >+ Winner_ind = k; >+ } >+ } >+ >+ /* Increase RD values of expired states */ >+ { >+ uint32x4_t t_u32x4; >+ Winner_rand_state = psDelDec->RandState[ last_smple_idx ][ Winner_ind ]; >+ t_u32x4 = vceqq_s32( vld1q_s32( psDelDec->RandState[ last_smple_idx ] ), vdupq_n_s32( Winner_rand_state ) ); >+ t_u32x4 = vmvnq_u32( t_u32x4 ); >+ t_u32x4 = vshrq_n_u32( t_u32x4, 5 ); >+ tmp1_s32x4 = vld1q_s32( psSampleState[ 0 ].RD_Q10 ); >+ tmp2_s32x4 = vld1q_s32( psSampleState[ 1 ].RD_Q10 ); >+ tmp1_s32x4 = vaddq_s32( tmp1_s32x4, vreinterpretq_s32_u32( t_u32x4 ) ); >+ tmp2_s32x4 = vaddq_s32( tmp2_s32x4, vreinterpretq_s32_u32( t_u32x4 ) ); >+ vst1q_s32( psSampleState[ 0 ].RD_Q10, tmp1_s32x4 ); >+ vst1q_s32( psSampleState[ 1 ].RD_Q10, tmp2_s32x4 ); >+ >+ /* Find worst in first set and best in second set */ >+ RDmax_Q10 = psSampleState[ 0 ].RD_Q10[ 0 ]; >+ RDmin_Q10 = psSampleState[ 1 ].RD_Q10[ 0 ]; >+ RDmax_ind = 0; >+ RDmin_ind = 0; >+ for( k = 1; k < nStatesDelayedDecision; k++ ) { >+ /* find worst in first set */ >+ if( psSampleState[ 0 ].RD_Q10[ k ] > RDmax_Q10 ) { >+ RDmax_Q10 = psSampleState[ 0 ].RD_Q10[ k ]; >+ RDmax_ind = k; >+ } >+ /* find best in second set */ >+ if( psSampleState[ 1 ].RD_Q10[ k ] < RDmin_Q10 ) { >+ RDmin_Q10 = psSampleState[ 1 ].RD_Q10[ k ]; >+ RDmin_ind = k; >+ } >+ } >+ } >+ >+ /* Replace a state if best from second set outperforms worst in first set */ >+ if( RDmin_Q10 < RDmax_Q10 ) { >+ opus_int32 (*ptr)[NEON_MAX_DEL_DEC_STATES] = psDelDec->RandState; >+ const int numOthers = (int)( ( sizeof( NSQ_del_decs_struct ) - sizeof( ( (NSQ_del_decs_struct *)0 )->sLPC_Q14 ) ) >+ / ( NEON_MAX_DEL_DEC_STATES * sizeof( opus_int32 ) ) ); >+ /* Only ( predictLPCOrder - 1 ) of sLPC_Q14 buffer need to be updated, though the first several */ >+ /* useless sLPC_Q14[] will be different comparing with C when predictLPCOrder < NSQ_LPC_BUF_LENGTH. */ >+ /* Here just update constant ( NSQ_LPC_BUF_LENGTH - 1 ) for simplicity. */ >+ for( j = i + 1; j < i + NSQ_LPC_BUF_LENGTH; j++ ) { >+ psDelDec->sLPC_Q14[ j ][ RDmax_ind ] = psDelDec->sLPC_Q14[ j ][ RDmin_ind ]; >+ } >+ for( j = 0; j < numOthers; j++ ) { >+ ptr[ j ][ RDmax_ind ] = ptr[ j ][ RDmin_ind ]; >+ } >+ >+ psSampleState[ 0 ].Q_Q10[ RDmax_ind ] = psSampleState[ 1 ].Q_Q10[ RDmin_ind ]; >+ psSampleState[ 0 ].RD_Q10[ RDmax_ind ] = psSampleState[ 1 ].RD_Q10[ RDmin_ind ]; >+ psSampleState[ 0 ].xq_Q14[ RDmax_ind ] = psSampleState[ 1 ].xq_Q14[ RDmin_ind ]; >+ psSampleState[ 0 ].LF_AR_Q14[ RDmax_ind ] = psSampleState[ 1 ].LF_AR_Q14[ RDmin_ind ]; >+ psSampleState[ 0 ].Diff_Q14[ RDmax_ind ] = psSampleState[ 1 ].Diff_Q14[ RDmin_ind ]; >+ psSampleState[ 0 ].sLTP_shp_Q14[ RDmax_ind ] = psSampleState[ 1 ].sLTP_shp_Q14[ RDmin_ind ]; >+ psSampleState[ 0 ].LPC_exc_Q14[ RDmax_ind ] = psSampleState[ 1 ].LPC_exc_Q14[ RDmin_ind ]; >+ } >+ >+ /* Write samples from winner to output and long-term filter states */ >+ if( subfr > 0 || i >= decisionDelay ) { >+ pulses[ i - decisionDelay ] = (opus_int8)silk_RSHIFT_ROUND( psDelDec->Q_Q10[ last_smple_idx ][ Winner_ind ], 10 ); >+ xq[ i - decisionDelay ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( >+ silk_SMULWW( psDelDec->Xq_Q14[ last_smple_idx ][ Winner_ind ], delayedGain_Q10[ last_smple_idx ] ), 8 ) ); >+ NSQ->sLTP_shp_Q14[ NSQ->sLTP_shp_buf_idx - decisionDelay ] = psDelDec->Shape_Q14[ last_smple_idx ][ Winner_ind ]; >+ sLTP_Q15[ NSQ->sLTP_buf_idx - decisionDelay ] = psDelDec->Pred_Q15[ last_smple_idx ][ Winner_ind ]; >+ } >+ NSQ->sLTP_shp_buf_idx++; >+ NSQ->sLTP_buf_idx++; >+ >+ /* Update states */ >+ vst1q_s32( psDelDec->LF_AR_Q14, vld1q_s32( psSampleState[ 0 ].LF_AR_Q14 ) ); >+ vst1q_s32( psDelDec->Diff_Q14, vld1q_s32( psSampleState[ 0 ].Diff_Q14 ) ); >+ vst1q_s32( psDelDec->sLPC_Q14[ NSQ_LPC_BUF_LENGTH + i ], vld1q_s32( psSampleState[ 0 ].xq_Q14 ) ); >+ vst1q_s32( psDelDec->Xq_Q14[ *smpl_buf_idx ], vld1q_s32( psSampleState[ 0 ].xq_Q14 ) ); >+ tmp1_s32x4 = vld1q_s32( psSampleState[ 0 ].Q_Q10 ); >+ vst1q_s32( psDelDec->Q_Q10[ *smpl_buf_idx ], tmp1_s32x4 ); >+ vst1q_s32( psDelDec->Pred_Q15[ *smpl_buf_idx ], vshlq_n_s32( vld1q_s32( psSampleState[ 0 ].LPC_exc_Q14 ), 1 ) ); >+ vst1q_s32( psDelDec->Shape_Q14[ *smpl_buf_idx ], vld1q_s32( psSampleState[ 0 ].sLTP_shp_Q14 ) ); >+ tmp1_s32x4 = vrshrq_n_s32( tmp1_s32x4, 10 ); >+ tmp1_s32x4 = vaddq_s32( vld1q_s32( psDelDec->Seed ), tmp1_s32x4 ); >+ vst1q_s32( psDelDec->Seed, tmp1_s32x4 ); >+ vst1q_s32( psDelDec->RandState[ *smpl_buf_idx ], tmp1_s32x4 ); >+ vst1q_s32( psDelDec->RD_Q10, vld1q_s32( psSampleState[ 0 ].RD_Q10 ) ); >+ delayedGain_Q10[ *smpl_buf_idx ] = Gain_Q10; >+ } >+ /* Update LPC states */ >+ silk_memcpy( psDelDec->sLPC_Q14[ 0 ], psDelDec->sLPC_Q14[ length ], NEON_MAX_DEL_DEC_STATES * NSQ_LPC_BUF_LENGTH * sizeof( opus_int32 ) ); >+ >+ RESTORE_STACK; >+} >+ >+static OPUS_INLINE void silk_SMULWB_8_neon( >+ const opus_int16 *a, >+ const int32x2_t b, >+ opus_int32 *o >+) >+{ >+ const int16x8_t a_s16x8 = vld1q_s16( a ); >+ int32x4_t o0_s32x4, o1_s32x4; >+ >+ o0_s32x4 = vshll_n_s16( vget_low_s16( a_s16x8 ), 15 ); >+ o1_s32x4 = vshll_n_s16( vget_high_s16( a_s16x8 ), 15 ); >+ o0_s32x4 = vqdmulhq_lane_s32( o0_s32x4, b, 0 ); >+ o1_s32x4 = vqdmulhq_lane_s32( o1_s32x4, b, 0 ); >+ vst1q_s32( o, o0_s32x4 ); >+ vst1q_s32( o + 4, o1_s32x4 ); >+} >+ >+/* Only works when ( b >= -65536 ) && ( b < 65536 ). */ >+static OPUS_INLINE void silk_SMULWW_small_b_4_neon( >+ opus_int32 *a, >+ const int32x2_t b_s32x2) >+{ >+ int32x4_t o_s32x4; >+ >+ o_s32x4 = vld1q_s32( a ); >+ o_s32x4 = vqdmulhq_lane_s32( o_s32x4, b_s32x2, 0 ); >+ vst1q_s32( a, o_s32x4 ); >+} >+ >+/* Only works when ( b >= -65536 ) && ( b < 65536 ). */ >+static OPUS_INLINE void silk_SMULWW_small_b_8_neon( >+ opus_int32 *a, >+ const int32x2_t b_s32x2 >+) >+{ >+ int32x4_t o0_s32x4, o1_s32x4; >+ >+ o0_s32x4 = vld1q_s32( a ); >+ o1_s32x4 = vld1q_s32( a + 4 ); >+ o0_s32x4 = vqdmulhq_lane_s32( o0_s32x4, b_s32x2, 0 ); >+ o1_s32x4 = vqdmulhq_lane_s32( o1_s32x4, b_s32x2, 0 ); >+ vst1q_s32( a, o0_s32x4 ); >+ vst1q_s32( a + 4, o1_s32x4 ); >+} >+ >+static OPUS_INLINE void silk_SMULWW_4_neon( >+ opus_int32 *a, >+ const int32x2_t b_s32x2) >+{ >+ int32x4_t a_s32x4, o_s32x4; >+ >+ a_s32x4 = vld1q_s32( a ); >+ o_s32x4 = vqdmulhq_lane_s32( a_s32x4, b_s32x2, 0 ); >+ o_s32x4 = vmlaq_lane_s32( o_s32x4, a_s32x4, b_s32x2, 1 ); >+ vst1q_s32( a, o_s32x4 ); >+} >+ >+static OPUS_INLINE void silk_SMULWW_8_neon( >+ opus_int32 *a, >+ const int32x2_t b_s32x2 >+) >+{ >+ int32x4_t a0_s32x4, a1_s32x4, o0_s32x4, o1_s32x4; >+ >+ a0_s32x4 = vld1q_s32( a ); >+ a1_s32x4 = vld1q_s32( a + 4 ); >+ o0_s32x4 = vqdmulhq_lane_s32( a0_s32x4, b_s32x2, 0 ); >+ o1_s32x4 = vqdmulhq_lane_s32( a1_s32x4, b_s32x2, 0 ); >+ o0_s32x4 = vmlaq_lane_s32( o0_s32x4, a0_s32x4, b_s32x2, 1 ); >+ o1_s32x4 = vmlaq_lane_s32( o1_s32x4, a1_s32x4, b_s32x2, 1 ); >+ vst1q_s32( a, o0_s32x4 ); >+ vst1q_s32( a + 4, o1_s32x4 ); >+} >+ >+static OPUS_INLINE void silk_SMULWW_loop_neon( >+ const opus_int16 *a, >+ const opus_int32 b, >+ opus_int32 *o, >+ const opus_int loop_num >+) >+{ >+ opus_int i; >+ int32x2_t b_s32x2; >+ >+ b_s32x2 = vdup_n_s32( b ); >+ for( i = 0; i < loop_num - 7; i += 8 ) { >+ silk_SMULWB_8_neon( a + i, b_s32x2, o + i ); >+ } >+ for( ; i < loop_num; i++ ) { >+ o[ i ] = silk_SMULWW( a[ i ], b ); >+ } >+} >+ >+static OPUS_INLINE void silk_nsq_del_dec_scale_states_neon( >+ const silk_encoder_state *psEncC, /* I Encoder State */ >+ silk_nsq_state *NSQ, /* I/O NSQ state */ >+ NSQ_del_decs_struct psDelDec[], /* I/O Delayed decision states */ >+ const opus_int16 x16[], /* I Input */ >+ opus_int32 x_sc_Q10[], /* O Input scaled with 1/Gain in Q10 */ >+ const opus_int16 sLTP[], /* I Re-whitened LTP state in Q0 */ >+ opus_int32 sLTP_Q15[], /* O LTP state matching scaled input */ >+ opus_int subfr, /* I Subframe number */ >+ const opus_int LTP_scale_Q14, /* I LTP state scaling */ >+ const opus_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I */ >+ const opus_int pitchL[ MAX_NB_SUBFR ], /* I Pitch lag */ >+ const opus_int signal_type, /* I Signal type */ >+ const opus_int decisionDelay /* I Decision delay */ >+) >+{ >+ opus_int i, lag; >+ opus_int32 gain_adj_Q16, inv_gain_Q31, inv_gain_Q26; >+ >+ lag = pitchL[ subfr ]; >+ inv_gain_Q31 = silk_INVERSE32_varQ( silk_max( Gains_Q16[ subfr ], 1 ), 47 ); >+ silk_assert( inv_gain_Q31 != 0 ); >+ >+ /* Scale input */ >+ inv_gain_Q26 = silk_RSHIFT_ROUND( inv_gain_Q31, 5 ); >+ silk_SMULWW_loop_neon( x16, inv_gain_Q26, x_sc_Q10, psEncC->subfr_length ); >+ >+ /* After rewhitening the LTP state is un-scaled, so scale with inv_gain_Q16 */ >+ if( NSQ->rewhite_flag ) { >+ if( subfr == 0 ) { >+ /* Do LTP downscaling */ >+ inv_gain_Q31 = silk_LSHIFT( silk_SMULWB( inv_gain_Q31, LTP_scale_Q14 ), 2 ); >+ } >+ silk_SMULWW_loop_neon( sLTP + NSQ->sLTP_buf_idx - lag - LTP_ORDER / 2, inv_gain_Q31, sLTP_Q15 + NSQ->sLTP_buf_idx - lag - LTP_ORDER / 2, lag + LTP_ORDER / 2 ); >+ } >+ >+ /* Adjust for changing gain */ >+ if( Gains_Q16[ subfr ] != NSQ->prev_gain_Q16 ) { >+ int32x2_t gain_adj_Q16_s32x2; >+ gain_adj_Q16 = silk_DIV32_varQ( NSQ->prev_gain_Q16, Gains_Q16[ subfr ], 16 ); >+ >+ /* Scale long-term shaping state */ >+ if( ( gain_adj_Q16 >= -65536 ) && ( gain_adj_Q16 < 65536 ) ) { >+ gain_adj_Q16_s32x2 = vdup_n_s32( silk_LSHIFT32( gain_adj_Q16, 15 ) ); >+ for( i = NSQ->sLTP_shp_buf_idx - psEncC->ltp_mem_length; i < NSQ->sLTP_shp_buf_idx - 7; i += 8 ) { >+ silk_SMULWW_small_b_8_neon( NSQ->sLTP_shp_Q14 + i, gain_adj_Q16_s32x2 ); >+ } >+ for( ; i < NSQ->sLTP_shp_buf_idx; i++ ) { >+ NSQ->sLTP_shp_Q14[ i ] = silk_SMULWW( gain_adj_Q16, NSQ->sLTP_shp_Q14[ i ] ); >+ } >+ >+ /* Scale long-term prediction state */ >+ if( signal_type == TYPE_VOICED && NSQ->rewhite_flag == 0 ) { >+ for( i = NSQ->sLTP_buf_idx - lag - LTP_ORDER / 2; i < NSQ->sLTP_buf_idx - decisionDelay - 7; i += 8 ) { >+ silk_SMULWW_small_b_8_neon( sLTP_Q15 + i, gain_adj_Q16_s32x2 ); >+ } >+ for( ; i < NSQ->sLTP_buf_idx - decisionDelay; i++ ) { >+ sLTP_Q15[ i ] = silk_SMULWW( gain_adj_Q16, sLTP_Q15[ i ] ); >+ } >+ } >+ >+ /* Scale scalar states */ >+ silk_SMULWW_small_b_4_neon( psDelDec->LF_AR_Q14, gain_adj_Q16_s32x2 ); >+ silk_SMULWW_small_b_4_neon( psDelDec->Diff_Q14, gain_adj_Q16_s32x2 ); >+ >+ /* Scale short-term prediction and shaping states */ >+ for( i = 0; i < NSQ_LPC_BUF_LENGTH; i++ ) { >+ silk_SMULWW_small_b_4_neon( psDelDec->sLPC_Q14[ i ], gain_adj_Q16_s32x2 ); >+ } >+ >+ for( i = 0; i < MAX_SHAPE_LPC_ORDER; i++ ) { >+ silk_SMULWW_small_b_4_neon( psDelDec->sAR2_Q14[ i ], gain_adj_Q16_s32x2 ); >+ } >+ >+ for( i = 0; i < DECISION_DELAY; i++ ) { >+ silk_SMULWW_small_b_4_neon( psDelDec->Pred_Q15[ i ], gain_adj_Q16_s32x2 ); >+ silk_SMULWW_small_b_4_neon( psDelDec->Shape_Q14[ i ], gain_adj_Q16_s32x2 ); >+ } >+ } else { >+ gain_adj_Q16_s32x2 = vdup_n_s32( silk_LSHIFT32( gain_adj_Q16 & 0x0000FFFF, 15 ) ); >+ gain_adj_Q16_s32x2 = vset_lane_s32( gain_adj_Q16 >> 16, gain_adj_Q16_s32x2, 1 ); >+ for( i = NSQ->sLTP_shp_buf_idx - psEncC->ltp_mem_length; i < NSQ->sLTP_shp_buf_idx - 7; i += 8 ) { >+ silk_SMULWW_8_neon( NSQ->sLTP_shp_Q14 + i, gain_adj_Q16_s32x2 ); >+ } >+ for( ; i < NSQ->sLTP_shp_buf_idx; i++ ) { >+ NSQ->sLTP_shp_Q14[ i ] = silk_SMULWW( gain_adj_Q16, NSQ->sLTP_shp_Q14[ i ] ); >+ } >+ >+ /* Scale long-term prediction state */ >+ if( signal_type == TYPE_VOICED && NSQ->rewhite_flag == 0 ) { >+ for( i = NSQ->sLTP_buf_idx - lag - LTP_ORDER / 2; i < NSQ->sLTP_buf_idx - decisionDelay - 7; i += 8 ) { >+ silk_SMULWW_8_neon( sLTP_Q15 + i, gain_adj_Q16_s32x2 ); >+ } >+ for( ; i < NSQ->sLTP_buf_idx - decisionDelay; i++ ) { >+ sLTP_Q15[ i ] = silk_SMULWW( gain_adj_Q16, sLTP_Q15[ i ] ); >+ } >+ } >+ >+ /* Scale scalar states */ >+ silk_SMULWW_4_neon( psDelDec->LF_AR_Q14, gain_adj_Q16_s32x2 ); >+ silk_SMULWW_4_neon( psDelDec->Diff_Q14, gain_adj_Q16_s32x2 ); >+ >+ /* Scale short-term prediction and shaping states */ >+ for( i = 0; i < NSQ_LPC_BUF_LENGTH; i++ ) { >+ silk_SMULWW_4_neon( psDelDec->sLPC_Q14[ i ], gain_adj_Q16_s32x2 ); >+ } >+ >+ for( i = 0; i < MAX_SHAPE_LPC_ORDER; i++ ) { >+ silk_SMULWW_4_neon( psDelDec->sAR2_Q14[ i ], gain_adj_Q16_s32x2 ); >+ } >+ >+ for( i = 0; i < DECISION_DELAY; i++ ) { >+ silk_SMULWW_4_neon( psDelDec->Pred_Q15[ i ], gain_adj_Q16_s32x2 ); >+ silk_SMULWW_4_neon( psDelDec->Shape_Q14[ i ], gain_adj_Q16_s32x2 ); >+ } >+ } >+ >+ /* Save inverse gain */ >+ NSQ->prev_gain_Q16 = Gains_Q16[ subfr ]; >+ } >+} >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/arm/NSQ_neon.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/arm/NSQ_neon.h >index 77c946af8544786e31134571a8e5574f9e098c8c..b31d9442d6991c49ad5202f29d9d02b8d1139506 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/arm/NSQ_neon.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/arm/NSQ_neon.h >@@ -28,30 +28,31 @@ POSSIBILITY OF SUCH DAMAGE. > #define SILK_NSQ_NEON_H > > #include "cpu_support.h" >+#include "SigProc_FIX.h" > > #undef silk_short_prediction_create_arch_coef > /* For vectorized calc, reverse a_Q12 coefs, convert to 32-bit, and shift for vqdmulhq_s32. */ > static OPUS_INLINE void silk_short_prediction_create_arch_coef_neon(opus_int32 *out, const opus_int16 *in, opus_int order) > { >- out[15] = in[0] << 15; >- out[14] = in[1] << 15; >- out[13] = in[2] << 15; >- out[12] = in[3] << 15; >- out[11] = in[4] << 15; >- out[10] = in[5] << 15; >- out[9] = in[6] << 15; >- out[8] = in[7] << 15; >- out[7] = in[8] << 15; >- out[6] = in[9] << 15; >+ out[15] = silk_LSHIFT32(in[0], 15); >+ out[14] = silk_LSHIFT32(in[1], 15); >+ out[13] = silk_LSHIFT32(in[2], 15); >+ out[12] = silk_LSHIFT32(in[3], 15); >+ out[11] = silk_LSHIFT32(in[4], 15); >+ out[10] = silk_LSHIFT32(in[5], 15); >+ out[9] = silk_LSHIFT32(in[6], 15); >+ out[8] = silk_LSHIFT32(in[7], 15); >+ out[7] = silk_LSHIFT32(in[8], 15); >+ out[6] = silk_LSHIFT32(in[9], 15); > > if (order == 16) > { >- out[5] = in[10] << 15; >- out[4] = in[11] << 15; >- out[3] = in[12] << 15; >- out[2] = in[13] << 15; >- out[1] = in[14] << 15; >- out[0] = in[15] << 15; >+ out[5] = silk_LSHIFT32(in[10], 15); >+ out[4] = silk_LSHIFT32(in[11], 15); >+ out[3] = silk_LSHIFT32(in[12], 15); >+ out[2] = silk_LSHIFT32(in[13], 15); >+ out[1] = silk_LSHIFT32(in[14], 15); >+ out[0] = silk_LSHIFT32(in[15], 15); > } > else > { >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/arm/arm_silk_map.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/arm/arm_silk_map.c >index 9bd86a7b2152249fa850e9eec0cd6a6ca26ce715..0b9bfec2ca974768c59e09f448aca81ceb1d8f60 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/arm/arm_silk_map.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/arm/arm_silk_map.c >@@ -28,13 +28,62 @@ POSSIBILITY OF SUCH DAMAGE. > # include "config.h" > #endif > >+#include "main_FIX.h" > #include "NSQ.h" >+#include "SigProc_FIX.h" > > #if defined(OPUS_HAVE_RTCD) > > # if (defined(OPUS_ARM_MAY_HAVE_NEON_INTR) && \ > !defined(OPUS_ARM_PRESUME_NEON_INTR)) > >+void (*const SILK_BIQUAD_ALT_STRIDE2_IMPL[OPUS_ARCHMASK + 1])( >+ const opus_int16 *in, /* I input signal */ >+ const opus_int32 *B_Q28, /* I MA coefficients [3] */ >+ const opus_int32 *A_Q28, /* I AR coefficients [2] */ >+ opus_int32 *S, /* I/O State vector [4] */ >+ opus_int16 *out, /* O output signal */ >+ const opus_int32 len /* I signal length (must be even) */ >+) = { >+ silk_biquad_alt_stride2_c, /* ARMv4 */ >+ silk_biquad_alt_stride2_c, /* EDSP */ >+ silk_biquad_alt_stride2_c, /* Media */ >+ silk_biquad_alt_stride2_neon, /* Neon */ >+}; >+ >+opus_int32 (*const SILK_LPC_INVERSE_PRED_GAIN_IMPL[OPUS_ARCHMASK + 1])( /* O Returns inverse prediction gain in energy domain, Q30 */ >+ const opus_int16 *A_Q12, /* I Prediction coefficients, Q12 [order] */ >+ const opus_int order /* I Prediction order */ >+) = { >+ silk_LPC_inverse_pred_gain_c, /* ARMv4 */ >+ silk_LPC_inverse_pred_gain_c, /* EDSP */ >+ silk_LPC_inverse_pred_gain_c, /* Media */ >+ silk_LPC_inverse_pred_gain_neon, /* Neon */ >+}; >+ >+void (*const SILK_NSQ_DEL_DEC_IMPL[OPUS_ARCHMASK + 1])( >+ const silk_encoder_state *psEncC, /* I Encoder State */ >+ silk_nsq_state *NSQ, /* I/O NSQ state */ >+ SideInfoIndices *psIndices, /* I/O Quantization Indices */ >+ const opus_int16 x16[], /* I Input */ >+ opus_int8 pulses[], /* O Quantized pulse signal */ >+ const opus_int16 PredCoef_Q12[ 2 * MAX_LPC_ORDER ], /* I Short term prediction coefs */ >+ const opus_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ], /* I Long term prediction coefs */ >+ const opus_int16 AR_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I Noise shaping coefs */ >+ const opus_int HarmShapeGain_Q14[ MAX_NB_SUBFR ], /* I Long term shaping coefs */ >+ const opus_int Tilt_Q14[ MAX_NB_SUBFR ], /* I Spectral tilt */ >+ const opus_int32 LF_shp_Q14[ MAX_NB_SUBFR ], /* I Low frequency shaping coefs */ >+ const opus_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I Quantization step sizes */ >+ const opus_int pitchL[ MAX_NB_SUBFR ], /* I Pitch lags */ >+ const opus_int Lambda_Q10, /* I Rate/distortion tradeoff */ >+ const opus_int LTP_scale_Q14 /* I LTP state scaling */ >+) = { >+ silk_NSQ_del_dec_c, /* ARMv4 */ >+ silk_NSQ_del_dec_c, /* EDSP */ >+ silk_NSQ_del_dec_c, /* Media */ >+ silk_NSQ_del_dec_neon, /* Neon */ >+}; >+ > /*There is no table for silk_noise_shape_quantizer_short_prediction because the > NEON version takes different parameters than the C version. > Instead RTCD is done via if statements at the call sites. >@@ -52,4 +101,23 @@ opus_int32 > > # endif > >+# if defined(FIXED_POINT) && \ >+ defined(OPUS_ARM_MAY_HAVE_NEON_INTR) && !defined(OPUS_ARM_PRESUME_NEON_INTR) >+ >+void (*const SILK_WARPED_AUTOCORRELATION_FIX_IMPL[OPUS_ARCHMASK + 1])( >+ opus_int32 *corr, /* O Result [order + 1] */ >+ opus_int *scale, /* O Scaling of the correlation vector */ >+ const opus_int16 *input, /* I Input data to correlate */ >+ const opus_int warping_Q16, /* I Warping coefficient */ >+ const opus_int length, /* I Length of input */ >+ const opus_int order /* I Correlation order (even) */ >+) = { >+ silk_warped_autocorrelation_FIX_c, /* ARMv4 */ >+ silk_warped_autocorrelation_FIX_c, /* EDSP */ >+ silk_warped_autocorrelation_FIX_c, /* Media */ >+ silk_warped_autocorrelation_FIX_neon, /* Neon */ >+}; >+ >+# endif >+ > #endif /* OPUS_HAVE_RTCD */ >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/arm/biquad_alt_arm.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/arm/biquad_alt_arm.h >new file mode 100644 >index 0000000000000000000000000000000000000000..66ea9f43dd0b37b2d633087f1a25e9986fce2d6e >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/arm/biquad_alt_arm.h >@@ -0,0 +1,68 @@ >+/*********************************************************************** >+Copyright (c) 2017 Google Inc. >+Redistribution and use in source and binary forms, with or without >+modification, are permitted provided that the following conditions >+are met: >+- Redistributions of source code must retain the above copyright notice, >+this list of conditions and the following disclaimer. >+- Redistributions in binary form must reproduce the above copyright >+notice, this list of conditions and the following disclaimer in the >+documentation and/or other materials provided with the distribution. >+- Neither the name of Internet Society, IETF or IETF Trust, nor the >+names of specific contributors, may be used to endorse or promote >+products derived from this software without specific prior written >+permission. >+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" >+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE >+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE >+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE >+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE >+POSSIBILITY OF SUCH DAMAGE. >+***********************************************************************/ >+ >+#ifndef SILK_BIQUAD_ALT_ARM_H >+# define SILK_BIQUAD_ALT_ARM_H >+ >+# include "celt/arm/armcpu.h" >+ >+# if defined(OPUS_ARM_MAY_HAVE_NEON_INTR) >+void silk_biquad_alt_stride2_neon( >+ const opus_int16 *in, /* I input signal */ >+ const opus_int32 *B_Q28, /* I MA coefficients [3] */ >+ const opus_int32 *A_Q28, /* I AR coefficients [2] */ >+ opus_int32 *S, /* I/O State vector [4] */ >+ opus_int16 *out, /* O output signal */ >+ const opus_int32 len /* I signal length (must be even) */ >+); >+ >+# if !defined(OPUS_HAVE_RTCD) && defined(OPUS_ARM_PRESUME_NEON) >+# define OVERRIDE_silk_biquad_alt_stride2 (1) >+# define silk_biquad_alt_stride2(in, B_Q28, A_Q28, S, out, len, arch) ((void)(arch), PRESUME_NEON(silk_biquad_alt_stride2)(in, B_Q28, A_Q28, S, out, len)) >+# endif >+# endif >+ >+# if !defined(OVERRIDE_silk_biquad_alt_stride2) >+/*Is run-time CPU detection enabled on this platform?*/ >+# if defined(OPUS_HAVE_RTCD) && (defined(OPUS_ARM_MAY_HAVE_NEON_INTR) && !defined(OPUS_ARM_PRESUME_NEON_INTR)) >+extern void (*const SILK_BIQUAD_ALT_STRIDE2_IMPL[OPUS_ARCHMASK+1])( >+ const opus_int16 *in, /* I input signal */ >+ const opus_int32 *B_Q28, /* I MA coefficients [3] */ >+ const opus_int32 *A_Q28, /* I AR coefficients [2] */ >+ opus_int32 *S, /* I/O State vector [4] */ >+ opus_int16 *out, /* O output signal */ >+ const opus_int32 len /* I signal length (must be even) */ >+ ); >+# define OVERRIDE_silk_biquad_alt_stride2 (1) >+# define silk_biquad_alt_stride2(in, B_Q28, A_Q28, S, out, len, arch) ((*SILK_BIQUAD_ALT_STRIDE2_IMPL[(arch)&OPUS_ARCHMASK])(in, B_Q28, A_Q28, S, out, len)) >+# elif defined(OPUS_ARM_PRESUME_NEON_INTR) >+# define OVERRIDE_silk_biquad_alt_stride2 (1) >+# define silk_biquad_alt_stride2(in, B_Q28, A_Q28, S, out, len, arch) ((void)(arch), silk_biquad_alt_stride2_neon(in, B_Q28, A_Q28, S, out, len)) >+# endif >+# endif >+ >+#endif /* end SILK_BIQUAD_ALT_ARM_H */ >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/arm/biquad_alt_neon_intr.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/arm/biquad_alt_neon_intr.c >new file mode 100644 >index 0000000000000000000000000000000000000000..97157331858ca8bf69ac5293cb68e23cd6d4f33b >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/arm/biquad_alt_neon_intr.c >@@ -0,0 +1,156 @@ >+/*********************************************************************** >+Copyright (c) 2017 Google Inc. >+Redistribution and use in source and binary forms, with or without >+modification, are permitted provided that the following conditions >+are met: >+- Redistributions of source code must retain the above copyright notice, >+this list of conditions and the following disclaimer. >+- Redistributions in binary form must reproduce the above copyright >+notice, this list of conditions and the following disclaimer in the >+documentation and/or other materials provided with the distribution. >+- Neither the name of Internet Society, IETF or IETF Trust, nor the >+names of specific contributors, may be used to endorse or promote >+products derived from this software without specific prior written >+permission. >+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" >+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE >+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE >+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE >+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE >+POSSIBILITY OF SUCH DAMAGE. >+***********************************************************************/ >+ >+#ifdef HAVE_CONFIG_H >+#include "config.h" >+#endif >+ >+#include <arm_neon.h> >+#ifdef OPUS_CHECK_ASM >+# include <string.h> >+# include "stack_alloc.h" >+#endif >+#include "SigProc_FIX.h" >+ >+static inline void silk_biquad_alt_stride2_kernel( const int32x4_t A_L_s32x4, const int32x4_t A_U_s32x4, const int32x4_t B_Q28_s32x4, const int32x2_t t_s32x2, const int32x4_t in_s32x4, int32x4_t *S_s32x4, int32x2_t *out32_Q14_s32x2 ) >+{ >+ int32x4_t t_s32x4, out32_Q14_s32x4; >+ >+ *out32_Q14_s32x2 = vadd_s32( vget_low_s32( *S_s32x4 ), t_s32x2 ); /* silk_SMLAWB( S{0,1}, B_Q28[ 0 ], in{0,1} ) */ >+ *S_s32x4 = vcombine_s32( vget_high_s32( *S_s32x4 ), vdup_n_s32( 0 ) ); /* S{0,1} = S{2,3}; S{2,3} = 0; */ >+ *out32_Q14_s32x2 = vshl_n_s32( *out32_Q14_s32x2, 2 ); /* out32_Q14_{0,1} = silk_LSHIFT( silk_SMLAWB( S{0,1}, B_Q28[ 0 ], in{0,1} ), 2 ); */ >+ out32_Q14_s32x4 = vcombine_s32( *out32_Q14_s32x2, *out32_Q14_s32x2 ); /* out32_Q14_{0,1,0,1} */ >+ t_s32x4 = vqdmulhq_s32( out32_Q14_s32x4, A_L_s32x4 ); /* silk_SMULWB( out32_Q14_{0,1,0,1}, A{0,0,1,1}_L_Q28 ) */ >+ *S_s32x4 = vrsraq_n_s32( *S_s32x4, t_s32x4, 14 ); /* S{0,1} = S{2,3} + silk_RSHIFT_ROUND(); S{2,3} = silk_RSHIFT_ROUND(); */ >+ t_s32x4 = vqdmulhq_s32( out32_Q14_s32x4, A_U_s32x4 ); /* silk_SMULWB( out32_Q14_{0,1,0,1}, A{0,0,1,1}_U_Q28 ) */ >+ *S_s32x4 = vaddq_s32( *S_s32x4, t_s32x4 ); /* S0 = silk_SMLAWB( S{0,1,2,3}, out32_Q14_{0,1,0,1}, A{0,0,1,1}_U_Q28 ); */ >+ t_s32x4 = vqdmulhq_s32( in_s32x4, B_Q28_s32x4 ); /* silk_SMULWB( B_Q28[ {1,1,2,2} ], in{0,1,0,1} ) */ >+ *S_s32x4 = vaddq_s32( *S_s32x4, t_s32x4 ); /* S0 = silk_SMLAWB( S0, B_Q28[ {1,1,2,2} ], in{0,1,0,1} ); */ >+} >+ >+void silk_biquad_alt_stride2_neon( >+ const opus_int16 *in, /* I input signal */ >+ const opus_int32 *B_Q28, /* I MA coefficients [3] */ >+ const opus_int32 *A_Q28, /* I AR coefficients [2] */ >+ opus_int32 *S, /* I/O State vector [4] */ >+ opus_int16 *out, /* O output signal */ >+ const opus_int32 len /* I signal length (must be even) */ >+) >+{ >+ /* DIRECT FORM II TRANSPOSED (uses 2 element state vector) */ >+ opus_int k = 0; >+ const int32x2_t offset_s32x2 = vdup_n_s32( (1<<14) - 1 ); >+ const int32x4_t offset_s32x4 = vcombine_s32( offset_s32x2, offset_s32x2 ); >+ int16x4_t in_s16x4 = vdup_n_s16( 0 ); >+ int16x4_t out_s16x4; >+ int32x2_t A_Q28_s32x2, A_L_s32x2, A_U_s32x2, B_Q28_s32x2, t_s32x2; >+ int32x4_t A_L_s32x4, A_U_s32x4, B_Q28_s32x4, S_s32x4, out32_Q14_s32x4; >+ int32x2x2_t t0_s32x2x2, t1_s32x2x2, t2_s32x2x2, S_s32x2x2; >+ >+#ifdef OPUS_CHECK_ASM >+ opus_int32 S_c[ 4 ]; >+ VARDECL( opus_int16, out_c ); >+ SAVE_STACK; >+ ALLOC( out_c, 2 * len, opus_int16 ); >+ >+ silk_memcpy( &S_c, S, sizeof( S_c ) ); >+ silk_biquad_alt_stride2_c( in, B_Q28, A_Q28, S_c, out_c, len ); >+#endif >+ >+ /* Negate A_Q28 values and split in two parts */ >+ A_Q28_s32x2 = vld1_s32( A_Q28 ); >+ A_Q28_s32x2 = vneg_s32( A_Q28_s32x2 ); >+ A_L_s32x2 = vshl_n_s32( A_Q28_s32x2, 18 ); /* ( -A_Q28[] & 0x00003FFF ) << 18 */ >+ A_L_s32x2 = vreinterpret_s32_u32( vshr_n_u32( vreinterpret_u32_s32( A_L_s32x2 ), 3 ) ); /* ( -A_Q28[] & 0x00003FFF ) << 15 */ >+ A_U_s32x2 = vshr_n_s32( A_Q28_s32x2, 14 ); /* silk_RSHIFT( -A_Q28[], 14 ) */ >+ A_U_s32x2 = vshl_n_s32( A_U_s32x2, 16 ); /* silk_RSHIFT( -A_Q28[], 14 ) << 16 (Clip two leading bits to conform to C function.) */ >+ A_U_s32x2 = vshr_n_s32( A_U_s32x2, 1 ); /* silk_RSHIFT( -A_Q28[], 14 ) << 15 */ >+ >+ B_Q28_s32x2 = vld1_s32( B_Q28 ); >+ t_s32x2 = vld1_s32( B_Q28 + 1 ); >+ t0_s32x2x2 = vzip_s32( A_L_s32x2, A_L_s32x2 ); >+ t1_s32x2x2 = vzip_s32( A_U_s32x2, A_U_s32x2 ); >+ t2_s32x2x2 = vzip_s32( t_s32x2, t_s32x2 ); >+ A_L_s32x4 = vcombine_s32( t0_s32x2x2.val[ 0 ], t0_s32x2x2.val[ 1 ] ); /* A{0,0,1,1}_L_Q28 */ >+ A_U_s32x4 = vcombine_s32( t1_s32x2x2.val[ 0 ], t1_s32x2x2.val[ 1 ] ); /* A{0,0,1,1}_U_Q28 */ >+ B_Q28_s32x4 = vcombine_s32( t2_s32x2x2.val[ 0 ], t2_s32x2x2.val[ 1 ] ); /* B_Q28[ {1,1,2,2} ] */ >+ S_s32x4 = vld1q_s32( S ); /* S0 = S[ 0 ]; S3 = S[ 3 ]; */ >+ S_s32x2x2 = vtrn_s32( vget_low_s32( S_s32x4 ), vget_high_s32( S_s32x4 ) ); /* S2 = S[ 1 ]; S1 = S[ 2 ]; */ >+ S_s32x4 = vcombine_s32( S_s32x2x2.val[ 0 ], S_s32x2x2.val[ 1 ] ); >+ >+ for( ; k < len - 1; k += 2 ) { >+ int32x4_t in_s32x4[ 2 ], t_s32x4; >+ int32x2_t out32_Q14_s32x2[ 2 ]; >+ >+ /* S[ 2 * i + 0 ], S[ 2 * i + 1 ], S[ 2 * i + 2 ], S[ 2 * i + 3 ]: Q12 */ >+ in_s16x4 = vld1_s16( &in[ 2 * k ] ); /* in{0,1,2,3} = in[ 2 * k + {0,1,2,3} ]; */ >+ in_s32x4[ 0 ] = vshll_n_s16( in_s16x4, 15 ); /* in{0,1,2,3} << 15 */ >+ t_s32x4 = vqdmulhq_lane_s32( in_s32x4[ 0 ], B_Q28_s32x2, 0 ); /* silk_SMULWB( B_Q28[ 0 ], in{0,1,2,3} ) */ >+ in_s32x4[ 1 ] = vcombine_s32( vget_high_s32( in_s32x4[ 0 ] ), vget_high_s32( in_s32x4[ 0 ] ) ); /* in{2,3,2,3} << 15 */ >+ in_s32x4[ 0 ] = vcombine_s32( vget_low_s32 ( in_s32x4[ 0 ] ), vget_low_s32 ( in_s32x4[ 0 ] ) ); /* in{0,1,0,1} << 15 */ >+ silk_biquad_alt_stride2_kernel( A_L_s32x4, A_U_s32x4, B_Q28_s32x4, vget_low_s32 ( t_s32x4 ), in_s32x4[ 0 ], &S_s32x4, &out32_Q14_s32x2[ 0 ] ); >+ silk_biquad_alt_stride2_kernel( A_L_s32x4, A_U_s32x4, B_Q28_s32x4, vget_high_s32( t_s32x4 ), in_s32x4[ 1 ], &S_s32x4, &out32_Q14_s32x2[ 1 ] ); >+ >+ /* Scale back to Q0 and saturate */ >+ out32_Q14_s32x4 = vcombine_s32( out32_Q14_s32x2[ 0 ], out32_Q14_s32x2[ 1 ] ); /* out32_Q14_{0,1,2,3} */ >+ out32_Q14_s32x4 = vaddq_s32( out32_Q14_s32x4, offset_s32x4 ); /* out32_Q14_{0,1,2,3} + (1<<14) - 1 */ >+ out_s16x4 = vqshrn_n_s32( out32_Q14_s32x4, 14 ); /* (opus_int16)silk_SAT16( silk_RSHIFT( out32_Q14_{0,1,2,3} + (1<<14) - 1, 14 ) ) */ >+ vst1_s16( &out[ 2 * k ], out_s16x4 ); /* out[ 2 * k + {0,1,2,3} ] = (opus_int16)silk_SAT16( silk_RSHIFT( out32_Q14_{0,1,2,3} + (1<<14) - 1, 14 ) ); */ >+ } >+ >+ /* Process leftover. */ >+ if( k < len ) { >+ int32x4_t in_s32x4; >+ int32x2_t out32_Q14_s32x2; >+ >+ /* S[ 2 * i + 0 ], S[ 2 * i + 1 ]: Q12 */ >+ in_s16x4 = vld1_lane_s16( &in[ 2 * k + 0 ], in_s16x4, 0 ); /* in{0,1} = in[ 2 * k + {0,1} ]; */ >+ in_s16x4 = vld1_lane_s16( &in[ 2 * k + 1 ], in_s16x4, 1 ); /* in{0,1} = in[ 2 * k + {0,1} ]; */ >+ in_s32x4 = vshll_n_s16( in_s16x4, 15 ); /* in{0,1} << 15 */ >+ t_s32x2 = vqdmulh_lane_s32( vget_low_s32( in_s32x4 ), B_Q28_s32x2, 0 ); /* silk_SMULWB( B_Q28[ 0 ], in{0,1} ) */ >+ in_s32x4 = vcombine_s32( vget_low_s32( in_s32x4 ), vget_low_s32( in_s32x4 ) ); /* in{0,1,0,1} << 15 */ >+ silk_biquad_alt_stride2_kernel( A_L_s32x4, A_U_s32x4, B_Q28_s32x4, t_s32x2, in_s32x4, &S_s32x4, &out32_Q14_s32x2 ); >+ >+ /* Scale back to Q0 and saturate */ >+ out32_Q14_s32x2 = vadd_s32( out32_Q14_s32x2, offset_s32x2 ); /* out32_Q14_{0,1} + (1<<14) - 1 */ >+ out32_Q14_s32x4 = vcombine_s32( out32_Q14_s32x2, out32_Q14_s32x2 ); /* out32_Q14_{0,1,0,1} + (1<<14) - 1 */ >+ out_s16x4 = vqshrn_n_s32( out32_Q14_s32x4, 14 ); /* (opus_int16)silk_SAT16( silk_RSHIFT( out32_Q14_{0,1,0,1} + (1<<14) - 1, 14 ) ) */ >+ vst1_lane_s16( &out[ 2 * k + 0 ], out_s16x4, 0 ); /* out[ 2 * k + 0 ] = (opus_int16)silk_SAT16( silk_RSHIFT( out32_Q14_0 + (1<<14) - 1, 14 ) ); */ >+ vst1_lane_s16( &out[ 2 * k + 1 ], out_s16x4, 1 ); /* out[ 2 * k + 1 ] = (opus_int16)silk_SAT16( silk_RSHIFT( out32_Q14_1 + (1<<14) - 1, 14 ) ); */ >+ } >+ >+ vst1q_lane_s32( &S[ 0 ], S_s32x4, 0 ); /* S[ 0 ] = S0; */ >+ vst1q_lane_s32( &S[ 1 ], S_s32x4, 2 ); /* S[ 1 ] = S2; */ >+ vst1q_lane_s32( &S[ 2 ], S_s32x4, 1 ); /* S[ 2 ] = S1; */ >+ vst1q_lane_s32( &S[ 3 ], S_s32x4, 3 ); /* S[ 3 ] = S3; */ >+ >+#ifdef OPUS_CHECK_ASM >+ silk_assert( !memcmp( S_c, S, sizeof( S_c ) ) ); >+ silk_assert( !memcmp( out_c, out, 2 * len * sizeof( opus_int16 ) ) ); >+ RESTORE_STACK; >+#endif >+} >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/arm/macros_armv4.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/arm/macros_armv4.h >index 3f30e97288fd77b3a2298df668a419777164c622..877eb18dd58129cc159152dd4b09d6759a84a277 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/arm/macros_armv4.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/arm/macros_armv4.h >@@ -28,6 +28,11 @@ POSSIBILITY OF SUCH DAMAGE. > #ifndef SILK_MACROS_ARMv4_H > #define SILK_MACROS_ARMv4_H > >+/* This macro only avoids the undefined behaviour from a left shift of >+ a negative value. It should only be used in macros that can't include >+ SigProc_FIX.h. In other cases, use silk_LSHIFT32(). */ >+#define SAFE_SHL(a,b) ((opus_int32)((opus_uint32)(a) << (b))) >+ > /* (a32 * (opus_int32)((opus_int16)(b32))) >> 16 output have to be 32bit int */ > #undef silk_SMULWB > static OPUS_INLINE opus_int32 silk_SMULWB_armv4(opus_int32 a, opus_int16 b) >@@ -38,7 +43,7 @@ static OPUS_INLINE opus_int32 silk_SMULWB_armv4(opus_int32 a, opus_int16 b) > "#silk_SMULWB\n\t" > "smull %0, %1, %2, %3\n\t" > : "=&r"(rd_lo), "=&r"(rd_hi) >- : "%r"(a), "r"(b<<16) >+ : "%r"(a), "r"(SAFE_SHL(b,16)) > ); > return rd_hi; > } >@@ -80,7 +85,7 @@ static OPUS_INLINE opus_int32 silk_SMULWW_armv4(opus_int32 a, opus_int32 b) > : "=&r"(rd_lo), "=&r"(rd_hi) > : "%r"(a), "r"(b) > ); >- return (rd_hi<<16)+(rd_lo>>16); >+ return SAFE_SHL(rd_hi,16)+(rd_lo>>16); > } > #define silk_SMULWW(a, b) (silk_SMULWW_armv4(a, b)) > >@@ -96,8 +101,10 @@ static OPUS_INLINE opus_int32 silk_SMLAWW_armv4(opus_int32 a, opus_int32 b, > : "=&r"(rd_lo), "=&r"(rd_hi) > : "%r"(b), "r"(c) > ); >- return a+(rd_hi<<16)+(rd_lo>>16); >+ return a+SAFE_SHL(rd_hi,16)+(rd_lo>>16); > } > #define silk_SMLAWW(a, b, c) (silk_SMLAWW_armv4(a, b, c)) > >+#undef SAFE_SHL >+ > #endif /* SILK_MACROS_ARMv4_H */ >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/arm/macros_armv5e.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/arm/macros_armv5e.h >index aad4117e46a5fafaaea3b0e5dcc0be85b11c6cf9..b14ec65ddb29a22b093460c38aeb68ba5ed5407d 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/arm/macros_armv5e.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/arm/macros_armv5e.h >@@ -29,6 +29,11 @@ POSSIBILITY OF SUCH DAMAGE. > #ifndef SILK_MACROS_ARMv5E_H > #define SILK_MACROS_ARMv5E_H > >+/* This macro only avoids the undefined behaviour from a left shift of >+ a negative value. It should only be used in macros that can't include >+ SigProc_FIX.h. In other cases, use silk_LSHIFT32(). */ >+#define SAFE_SHL(a,b) ((opus_int32)((opus_uint32)(a) << (b))) >+ > /* (a32 * (opus_int32)((opus_int16)(b32))) >> 16 output have to be 32bit int */ > #undef silk_SMULWB > static OPUS_INLINE opus_int32 silk_SMULWB_armv5e(opus_int32 a, opus_int16 b) >@@ -190,7 +195,7 @@ static OPUS_INLINE opus_int32 silk_CLZ16_armv5(opus_int16 in16) > "#silk_CLZ16\n\t" > "clz %0, %1;\n" > : "=r"(res) >- : "r"(in16<<16|0x8000) >+ : "r"(SAFE_SHL(in16,16)|0x8000) > ); > return res; > } >@@ -210,4 +215,6 @@ static OPUS_INLINE opus_int32 silk_CLZ32_armv5(opus_int32 in32) > } > #define silk_CLZ32(in32) (silk_CLZ32_armv5(in32)) > >+#undef SAFE_SHL >+ > #endif /* SILK_MACROS_ARMv5E_H */ >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/biquad_alt.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/biquad_alt.c >index d55f5ee92ec2d9b4217810377a1c4a390f8104f9..54566a43c0013c7b7ed378069a44867cca93231f 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/biquad_alt.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/biquad_alt.c >@@ -39,14 +39,13 @@ POSSIBILITY OF SUCH DAMAGE. > #include "SigProc_FIX.h" > > /* Second order ARMA filter, alternative implementation */ >-void silk_biquad_alt( >+void silk_biquad_alt_stride1( > const opus_int16 *in, /* I input signal */ > const opus_int32 *B_Q28, /* I MA coefficients [3] */ > const opus_int32 *A_Q28, /* I AR coefficients [2] */ > opus_int32 *S, /* I/O State vector [2] */ > opus_int16 *out, /* O output signal */ >- const opus_int32 len, /* I signal length (must be even) */ >- opus_int stride /* I Operate on interleaved signal if > 1 */ >+ const opus_int32 len /* I signal length (must be even) */ > ) > { > /* DIRECT FORM II TRANSPOSED (uses 2 element state vector) */ >@@ -61,7 +60,7 @@ void silk_biquad_alt( > > for( k = 0; k < len; k++ ) { > /* S[ 0 ], S[ 1 ]: Q12 */ >- inval = in[ k * stride ]; >+ inval = in[ k ]; > out32_Q14 = silk_LSHIFT( silk_SMLAWB( S[ 0 ], B_Q28[ 0 ], inval ), 2 ); > > S[ 0 ] = S[1] + silk_RSHIFT_ROUND( silk_SMULWB( out32_Q14, A0_L_Q28 ), 14 ); >@@ -73,6 +72,50 @@ void silk_biquad_alt( > S[ 1 ] = silk_SMLAWB( S[ 1 ], B_Q28[ 2 ], inval ); > > /* Scale back to Q0 and saturate */ >- out[ k * stride ] = (opus_int16)silk_SAT16( silk_RSHIFT( out32_Q14 + (1<<14) - 1, 14 ) ); >+ out[ k ] = (opus_int16)silk_SAT16( silk_RSHIFT( out32_Q14 + (1<<14) - 1, 14 ) ); >+ } >+} >+ >+void silk_biquad_alt_stride2_c( >+ const opus_int16 *in, /* I input signal */ >+ const opus_int32 *B_Q28, /* I MA coefficients [3] */ >+ const opus_int32 *A_Q28, /* I AR coefficients [2] */ >+ opus_int32 *S, /* I/O State vector [4] */ >+ opus_int16 *out, /* O output signal */ >+ const opus_int32 len /* I signal length (must be even) */ >+) >+{ >+ /* DIRECT FORM II TRANSPOSED (uses 2 element state vector) */ >+ opus_int k; >+ opus_int32 A0_U_Q28, A0_L_Q28, A1_U_Q28, A1_L_Q28, out32_Q14[ 2 ]; >+ >+ /* Negate A_Q28 values and split in two parts */ >+ A0_L_Q28 = ( -A_Q28[ 0 ] ) & 0x00003FFF; /* lower part */ >+ A0_U_Q28 = silk_RSHIFT( -A_Q28[ 0 ], 14 ); /* upper part */ >+ A1_L_Q28 = ( -A_Q28[ 1 ] ) & 0x00003FFF; /* lower part */ >+ A1_U_Q28 = silk_RSHIFT( -A_Q28[ 1 ], 14 ); /* upper part */ >+ >+ for( k = 0; k < len; k++ ) { >+ /* S[ 0 ], S[ 1 ], S[ 2 ], S[ 3 ]: Q12 */ >+ out32_Q14[ 0 ] = silk_LSHIFT( silk_SMLAWB( S[ 0 ], B_Q28[ 0 ], in[ 2 * k + 0 ] ), 2 ); >+ out32_Q14[ 1 ] = silk_LSHIFT( silk_SMLAWB( S[ 2 ], B_Q28[ 0 ], in[ 2 * k + 1 ] ), 2 ); >+ >+ S[ 0 ] = S[ 1 ] + silk_RSHIFT_ROUND( silk_SMULWB( out32_Q14[ 0 ], A0_L_Q28 ), 14 ); >+ S[ 2 ] = S[ 3 ] + silk_RSHIFT_ROUND( silk_SMULWB( out32_Q14[ 1 ], A0_L_Q28 ), 14 ); >+ S[ 0 ] = silk_SMLAWB( S[ 0 ], out32_Q14[ 0 ], A0_U_Q28 ); >+ S[ 2 ] = silk_SMLAWB( S[ 2 ], out32_Q14[ 1 ], A0_U_Q28 ); >+ S[ 0 ] = silk_SMLAWB( S[ 0 ], B_Q28[ 1 ], in[ 2 * k + 0 ] ); >+ S[ 2 ] = silk_SMLAWB( S[ 2 ], B_Q28[ 1 ], in[ 2 * k + 1 ] ); >+ >+ S[ 1 ] = silk_RSHIFT_ROUND( silk_SMULWB( out32_Q14[ 0 ], A1_L_Q28 ), 14 ); >+ S[ 3 ] = silk_RSHIFT_ROUND( silk_SMULWB( out32_Q14[ 1 ], A1_L_Q28 ), 14 ); >+ S[ 1 ] = silk_SMLAWB( S[ 1 ], out32_Q14[ 0 ], A1_U_Q28 ); >+ S[ 3 ] = silk_SMLAWB( S[ 3 ], out32_Q14[ 1 ], A1_U_Q28 ); >+ S[ 1 ] = silk_SMLAWB( S[ 1 ], B_Q28[ 2 ], in[ 2 * k + 0 ] ); >+ S[ 3 ] = silk_SMLAWB( S[ 3 ], B_Q28[ 2 ], in[ 2 * k + 1 ] ); >+ >+ /* Scale back to Q0 and saturate */ >+ out[ 2 * k + 0 ] = (opus_int16)silk_SAT16( silk_RSHIFT( out32_Q14[ 0 ] + (1<<14) - 1, 14 ) ); >+ out[ 2 * k + 1 ] = (opus_int16)silk_SAT16( silk_RSHIFT( out32_Q14[ 1 ] + (1<<14) - 1, 14 ) ); > } > } >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/bwexpander.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/bwexpander.c >index 2eb4456695e7919203757b8ff8f60673913ef116..afa97907ec802c63c65d5267c1458c07c8257208 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/bwexpander.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/bwexpander.c >@@ -45,7 +45,7 @@ void silk_bwexpander( > /* Bias in silk_SMULWB can lead to unstable filters */ > for( i = 0; i < d - 1; i++ ) { > ar[ i ] = (opus_int16)silk_RSHIFT_ROUND( silk_MUL( chirp_Q16, ar[ i ] ), 16 ); >- chirp_Q16 += silk_RSHIFT_ROUND( silk_MUL( chirp_Q16, chirp_minus_one_Q16 ), 16 ); >+ chirp_Q16 += silk_RSHIFT_ROUND( silk_MUL( chirp_Q16, chirp_minus_one_Q16 ), 16 ); > } > ar[ d - 1 ] = (opus_int16)silk_RSHIFT_ROUND( silk_MUL( chirp_Q16, ar[ d - 1 ] ), 16 ); > } >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/control.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/control.h >index 747e5426a0c3fc7cb9b5bdb7834ddd98a23e9791..b76ec33cd6ddb6386f564e1d99d3ff57d7e693ad 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/control.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/control.h >@@ -77,6 +77,9 @@ typedef struct { > /* I: Flag to enable in-band Forward Error Correction (FEC); 0/1 */ > opus_int useInBandFEC; > >+ /* I: Flag to actually code in-band Forward Error Correction (FEC) in the current packet; 0/1 */ >+ opus_int LBRR_coded; >+ > /* I: Flag to enable discontinuous transmission (DTX); 0/1 */ > opus_int useDTX; > >@@ -110,6 +113,11 @@ typedef struct { > /* O: Tells the Opus encoder we're ready to switch */ > opus_int switchReady; > >+ /* O: SILK Signal type */ >+ opus_int signalType; >+ >+ /* O: SILK offset (dithering) */ >+ opus_int offset; > } silk_EncControlStruct; > > /**************************************************************************/ >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/control_SNR.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/control_SNR.c >index cee87eb0d8b37c54e05706fb68a8cdc18c9aab4c..464c1acfe88451abf6a3ed45db26b25cd0c653f0 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/control_SNR.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/control_SNR.c >@@ -64,8 +64,7 @@ opus_int silk_control_SNR( > /* Find bitrate interval in table and interpolate */ > for( k = 1; k < TARGET_RATE_TAB_SZ; k++ ) { > if( TargetRate_bps <= rateTable[ k ] ) { >- frac_Q6 = silk_DIV32( silk_LSHIFT( TargetRate_bps - rateTable[ k - 1 ], 6 ), >- rateTable[ k ] - rateTable[ k - 1 ] ); >+ frac_Q6 = silk_DIV32( silk_LSHIFT( TargetRate_bps - rateTable[ k - 1 ], 6 ), rateTable[ k ] - rateTable[ k - 1 ] ); > psEncC->SNR_dB_Q7 = silk_LSHIFT( silk_SNR_table_Q1[ k - 1 ], 6 ) + silk_MUL( frac_Q6, silk_SNR_table_Q1[ k ] - silk_SNR_table_Q1[ k - 1 ] ); > break; > } >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/control_codec.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/control_codec.c >index 044eea3f2a84e0aa443f05cfc5af2f5c5e454cad..9350fd4b2b4cc9b58891d83b7b7b774f274b181f 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/control_codec.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/control_codec.c >@@ -57,7 +57,7 @@ static opus_int silk_setup_complexity( > > static OPUS_INLINE opus_int silk_setup_LBRR( > silk_encoder_state *psEncC, /* I/O */ >- const opus_int32 TargetRate_bps /* I */ >+ const silk_EncControlStruct *encControl /* I */ > ); > > >@@ -65,7 +65,6 @@ static OPUS_INLINE opus_int silk_setup_LBRR( > opus_int silk_control_encoder( > silk_encoder_state_Fxx *psEnc, /* I/O Pointer to Silk encoder state */ > silk_EncControlStruct *encControl, /* I Control structure */ >- const opus_int32 TargetRate_bps, /* I Target max bitrate (bps) */ > const opus_int allow_bw_switch, /* I Flag to allow switching audio bandwidth */ > const opus_int channelNb, /* I Channel number */ > const opus_int force_fs_kHz >@@ -125,7 +124,7 @@ opus_int silk_control_encoder( > /********************************************/ > /* Set LBRR usage */ > /********************************************/ >- ret += silk_setup_LBRR( &psEnc->sCmn, TargetRate_bps ); >+ ret += silk_setup_LBRR( &psEnc->sCmn, encControl ); > > psEnc->sCmn.controlled_since_last_payload = 1; > >@@ -244,7 +243,6 @@ static opus_int silk_setup_fs( > if( psEnc->sCmn.fs_kHz != fs_kHz ) { > /* reset part of the state */ > silk_memset( &psEnc->sShape, 0, sizeof( psEnc->sShape ) ); >- silk_memset( &psEnc->sPrefilt, 0, sizeof( psEnc->sPrefilt ) ); > silk_memset( &psEnc->sCmn.sNSQ, 0, sizeof( psEnc->sCmn.sNSQ ) ); > silk_memset( psEnc->sCmn.prev_NLSFq_Q15, 0, sizeof( psEnc->sCmn.prev_NLSFq_Q15 ) ); > silk_memset( &psEnc->sCmn.sLP.In_LP_State, 0, sizeof( psEnc->sCmn.sLP.In_LP_State ) ); >@@ -255,7 +253,6 @@ static opus_int silk_setup_fs( > /* Initialize non-zero parameters */ > psEnc->sCmn.prevLag = 100; > psEnc->sCmn.first_frame_after_reset = 1; >- psEnc->sPrefilt.lagPrev = 100; > psEnc->sShape.LastGainIndex = 10; > psEnc->sCmn.sNSQ.lagPrev = 100; > psEnc->sCmn.sNSQ.prev_gain_Q16 = 65536; >@@ -293,13 +290,10 @@ static opus_int silk_setup_fs( > psEnc->sCmn.pitch_LPC_win_length = silk_SMULBB( FIND_PITCH_LPC_WIN_MS_2_SF, fs_kHz ); > } > if( psEnc->sCmn.fs_kHz == 16 ) { >- psEnc->sCmn.mu_LTP_Q9 = SILK_FIX_CONST( MU_LTP_QUANT_WB, 9 ); > psEnc->sCmn.pitch_lag_low_bits_iCDF = silk_uniform8_iCDF; > } else if( psEnc->sCmn.fs_kHz == 12 ) { >- psEnc->sCmn.mu_LTP_Q9 = SILK_FIX_CONST( MU_LTP_QUANT_MB, 9 ); > psEnc->sCmn.pitch_lag_low_bits_iCDF = silk_uniform6_iCDF; > } else { >- psEnc->sCmn.mu_LTP_Q9 = SILK_FIX_CONST( MU_LTP_QUANT_NB, 9 ); > psEnc->sCmn.pitch_lag_low_bits_iCDF = silk_uniform4_iCDF; > } > } >@@ -319,60 +313,75 @@ static opus_int silk_setup_complexity( > > /* Set encoding complexity */ > silk_assert( Complexity >= 0 && Complexity <= 10 ); >- if( Complexity < 2 ) { >+ if( Complexity < 1 ) { > psEncC->pitchEstimationComplexity = SILK_PE_MIN_COMPLEX; > psEncC->pitchEstimationThreshold_Q16 = SILK_FIX_CONST( 0.8, 16 ); > psEncC->pitchEstimationLPCOrder = 6; >- psEncC->shapingLPCOrder = 8; >+ psEncC->shapingLPCOrder = 12; > psEncC->la_shape = 3 * psEncC->fs_kHz; > psEncC->nStatesDelayedDecision = 1; > psEncC->useInterpolatedNLSFs = 0; >- psEncC->LTPQuantLowComplexity = 1; > psEncC->NLSF_MSVQ_Survivors = 2; > psEncC->warping_Q16 = 0; >- } else if( Complexity < 4 ) { >+ } else if( Complexity < 2 ) { > psEncC->pitchEstimationComplexity = SILK_PE_MID_COMPLEX; > psEncC->pitchEstimationThreshold_Q16 = SILK_FIX_CONST( 0.76, 16 ); > psEncC->pitchEstimationLPCOrder = 8; >- psEncC->shapingLPCOrder = 10; >+ psEncC->shapingLPCOrder = 14; > psEncC->la_shape = 5 * psEncC->fs_kHz; > psEncC->nStatesDelayedDecision = 1; > psEncC->useInterpolatedNLSFs = 0; >- psEncC->LTPQuantLowComplexity = 0; >+ psEncC->NLSF_MSVQ_Survivors = 3; >+ psEncC->warping_Q16 = 0; >+ } else if( Complexity < 3 ) { >+ psEncC->pitchEstimationComplexity = SILK_PE_MIN_COMPLEX; >+ psEncC->pitchEstimationThreshold_Q16 = SILK_FIX_CONST( 0.8, 16 ); >+ psEncC->pitchEstimationLPCOrder = 6; >+ psEncC->shapingLPCOrder = 12; >+ psEncC->la_shape = 3 * psEncC->fs_kHz; >+ psEncC->nStatesDelayedDecision = 2; >+ psEncC->useInterpolatedNLSFs = 0; >+ psEncC->NLSF_MSVQ_Survivors = 2; >+ psEncC->warping_Q16 = 0; >+ } else if( Complexity < 4 ) { >+ psEncC->pitchEstimationComplexity = SILK_PE_MID_COMPLEX; >+ psEncC->pitchEstimationThreshold_Q16 = SILK_FIX_CONST( 0.76, 16 ); >+ psEncC->pitchEstimationLPCOrder = 8; >+ psEncC->shapingLPCOrder = 14; >+ psEncC->la_shape = 5 * psEncC->fs_kHz; >+ psEncC->nStatesDelayedDecision = 2; >+ psEncC->useInterpolatedNLSFs = 0; > psEncC->NLSF_MSVQ_Survivors = 4; > psEncC->warping_Q16 = 0; > } else if( Complexity < 6 ) { > psEncC->pitchEstimationComplexity = SILK_PE_MID_COMPLEX; > psEncC->pitchEstimationThreshold_Q16 = SILK_FIX_CONST( 0.74, 16 ); > psEncC->pitchEstimationLPCOrder = 10; >- psEncC->shapingLPCOrder = 12; >+ psEncC->shapingLPCOrder = 16; > psEncC->la_shape = 5 * psEncC->fs_kHz; > psEncC->nStatesDelayedDecision = 2; > psEncC->useInterpolatedNLSFs = 1; >- psEncC->LTPQuantLowComplexity = 0; >- psEncC->NLSF_MSVQ_Survivors = 8; >+ psEncC->NLSF_MSVQ_Survivors = 6; > psEncC->warping_Q16 = psEncC->fs_kHz * SILK_FIX_CONST( WARPING_MULTIPLIER, 16 ); > } else if( Complexity < 8 ) { > psEncC->pitchEstimationComplexity = SILK_PE_MID_COMPLEX; > psEncC->pitchEstimationThreshold_Q16 = SILK_FIX_CONST( 0.72, 16 ); > psEncC->pitchEstimationLPCOrder = 12; >- psEncC->shapingLPCOrder = 14; >+ psEncC->shapingLPCOrder = 20; > psEncC->la_shape = 5 * psEncC->fs_kHz; > psEncC->nStatesDelayedDecision = 3; > psEncC->useInterpolatedNLSFs = 1; >- psEncC->LTPQuantLowComplexity = 0; >- psEncC->NLSF_MSVQ_Survivors = 16; >+ psEncC->NLSF_MSVQ_Survivors = 8; > psEncC->warping_Q16 = psEncC->fs_kHz * SILK_FIX_CONST( WARPING_MULTIPLIER, 16 ); > } else { > psEncC->pitchEstimationComplexity = SILK_PE_MAX_COMPLEX; > psEncC->pitchEstimationThreshold_Q16 = SILK_FIX_CONST( 0.7, 16 ); > psEncC->pitchEstimationLPCOrder = 16; >- psEncC->shapingLPCOrder = 16; >+ psEncC->shapingLPCOrder = 24; > psEncC->la_shape = 5 * psEncC->fs_kHz; > psEncC->nStatesDelayedDecision = MAX_DEL_DEC_STATES; > psEncC->useInterpolatedNLSFs = 1; >- psEncC->LTPQuantLowComplexity = 0; >- psEncC->NLSF_MSVQ_Survivors = 32; >+ psEncC->NLSF_MSVQ_Survivors = 16; > psEncC->warping_Q16 = psEncC->fs_kHz * SILK_FIX_CONST( WARPING_MULTIPLIER, 16 ); > } > >@@ -387,40 +396,26 @@ static opus_int silk_setup_complexity( > silk_assert( psEncC->warping_Q16 <= 32767 ); > silk_assert( psEncC->la_shape <= LA_SHAPE_MAX ); > silk_assert( psEncC->shapeWinLength <= SHAPE_LPC_WIN_MAX ); >- silk_assert( psEncC->NLSF_MSVQ_Survivors <= NLSF_VQ_MAX_SURVIVORS ); > > return ret; > } > > static OPUS_INLINE opus_int silk_setup_LBRR( > silk_encoder_state *psEncC, /* I/O */ >- const opus_int32 TargetRate_bps /* I */ >+ const silk_EncControlStruct *encControl /* I */ > ) > { > opus_int LBRR_in_previous_packet, ret = SILK_NO_ERROR; >- opus_int32 LBRR_rate_thres_bps; > > LBRR_in_previous_packet = psEncC->LBRR_enabled; >- psEncC->LBRR_enabled = 0; >- if( psEncC->useInBandFEC && psEncC->PacketLoss_perc > 0 ) { >- if( psEncC->fs_kHz == 8 ) { >- LBRR_rate_thres_bps = LBRR_NB_MIN_RATE_BPS; >- } else if( psEncC->fs_kHz == 12 ) { >- LBRR_rate_thres_bps = LBRR_MB_MIN_RATE_BPS; >+ psEncC->LBRR_enabled = encControl->LBRR_coded; >+ if( psEncC->LBRR_enabled ) { >+ /* Set gain increase for coding LBRR excitation */ >+ if( LBRR_in_previous_packet == 0 ) { >+ /* Previous packet did not have LBRR, and was therefore coded at a higher bitrate */ >+ psEncC->LBRR_GainIncreases = 7; > } else { >- LBRR_rate_thres_bps = LBRR_WB_MIN_RATE_BPS; >- } >- LBRR_rate_thres_bps = silk_SMULWB( silk_MUL( LBRR_rate_thres_bps, 125 - silk_min( psEncC->PacketLoss_perc, 25 ) ), SILK_FIX_CONST( 0.01, 16 ) ); >- >- if( TargetRate_bps > LBRR_rate_thres_bps ) { >- /* Set gain increase for coding LBRR excitation */ >- if( LBRR_in_previous_packet == 0 ) { >- /* Previous packet did not have LBRR, and was therefore coded at a higher bitrate */ >- psEncC->LBRR_GainIncreases = 7; >- } else { >- psEncC->LBRR_GainIncreases = silk_max_int( 7 - silk_SMULWB( (opus_int32)psEncC->PacketLoss_perc, SILK_FIX_CONST( 0.4, 16 ) ), 2 ); >- } >- psEncC->LBRR_enabled = 1; >+ psEncC->LBRR_GainIncreases = silk_max_int( 7 - silk_SMULWB( (opus_int32)psEncC->PacketLoss_perc, SILK_FIX_CONST( 0.4, 16 ) ), 2 ); > } > } > >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/debug.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/debug.h >index efb6d3e99e7f83175fe0342de004c867c08af8db..6f68c1ca0f02257733038e0f91c418c319a986b2 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/debug.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/debug.h >@@ -39,23 +39,10 @@ extern "C" > > unsigned long GetHighResolutionTime(void); /* O time in usec*/ > >-/* make SILK_DEBUG dependent on compiler's _DEBUG */ >-#if defined _WIN32 >- #ifdef _DEBUG >- #define SILK_DEBUG 1 >- #else >- #define SILK_DEBUG 0 >- #endif >- >- /* overrule the above */ >- #if 0 >- /* #define NO_ASSERTS*/ >- #undef SILK_DEBUG >- #define SILK_DEBUG 1 >- #endif >-#else >- #define SILK_DEBUG 0 >-#endif >+/* Set to 1 to enable DEBUG_STORE_DATA() macros for dumping >+ * intermediate signals from the codec. >+ */ >+#define SILK_DEBUG 0 > > /* Flag for using timers */ > #define SILK_TIC_TOC 0 >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/decode_core.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/decode_core.c >index e569c0e72b3e171826d730a4be64836fb0ec0d9a..fd4e857afa8accc6d7fad203bb9601889ad01d95 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/decode_core.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/decode_core.c >@@ -225,8 +225,6 @@ void silk_decode_core( > pxq[ i ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( silk_SMULWW( sLPC_Q14[ MAX_LPC_ORDER + i ], Gain_Q10 ), 8 ) ); > } > >- /* DEBUG_STORE_DATA( dec.pcm, pxq, psDec->subfr_length * sizeof( opus_int16 ) ) */ >- > /* Update LPC filter state */ > silk_memcpy( sLPC_Q14, &sLPC_Q14[ psDec->subfr_length ], MAX_LPC_ORDER * sizeof( opus_int32 ) ); > pexc_Q14 += psDec->subfr_length; >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/decode_frame.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/decode_frame.c >index a605d95ac6ab10a7acef7a5fa57e33e040bb0f86..dfa73c4a29670634aeb70061252ada7136ec2dc2 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/decode_frame.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/decode_frame.c >@@ -97,6 +97,7 @@ opus_int silk_decode_frame( > psDec->first_frame_after_reset = 0; > } else { > /* Handle packet loss by extrapolation */ >+ psDec->indices.signalType = psDec->prevSignalType; > silk_PLC( psDec, psDecCtrl, pOut, 1, arch ); > } > >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/decode_parameters.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/decode_parameters.c >index e345b1dcefb94606b89ca6a1ba07000b4efb442f..a56a40985874f579b3d40921f56d0ce401cd481e 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/decode_parameters.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/decode_parameters.c >@@ -52,7 +52,7 @@ void silk_decode_parameters( > silk_NLSF_decode( pNLSF_Q15, psDec->indices.NLSFIndices, psDec->psNLSF_CB ); > > /* Convert NLSF parameters to AR prediction filter coefficients */ >- silk_NLSF2A( psDecCtrl->PredCoef_Q12[ 1 ], pNLSF_Q15, psDec->LPC_order ); >+ silk_NLSF2A( psDecCtrl->PredCoef_Q12[ 1 ], pNLSF_Q15, psDec->LPC_order, psDec->arch ); > > /* If just reset, e.g., because internal Fs changed, do not allow interpolation */ > /* improves the case of packet loss in the first frame after a switch */ >@@ -69,7 +69,7 @@ void silk_decode_parameters( > } > > /* Convert NLSF parameters to AR prediction filter coefficients */ >- silk_NLSF2A( psDecCtrl->PredCoef_Q12[ 0 ], pNLSF0_Q15, psDec->LPC_order ); >+ silk_NLSF2A( psDecCtrl->PredCoef_Q12[ 0 ], pNLSF0_Q15, psDec->LPC_order, psDec->arch ); > } else { > /* Copy LPC coefficients for first half from second half */ > silk_memcpy( psDecCtrl->PredCoef_Q12[ 0 ], psDecCtrl->PredCoef_Q12[ 1 ], psDec->LPC_order * sizeof( opus_int16 ) ); >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/define.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/define.h >index 19c9b00e259e7716bcb02354e3914b139602f353..22fd720b976af233ec2dafc83d6d95be2793ed6b 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/define.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/define.h >@@ -56,6 +56,12 @@ extern "C" > /* DTX settings */ > #define NB_SPEECH_FRAMES_BEFORE_DTX 10 /* eq 200 ms */ > #define MAX_CONSECUTIVE_DTX 20 /* eq 400 ms */ >+#define DTX_ACTIVITY_THRESHOLD 0.1f >+ >+/* VAD decision */ >+#define VAD_NO_DECISION -1 >+#define VAD_NO_ACTIVITY 0 >+#define VAD_ACTIVITY 1 > > /* Maximum sampling frequency */ > #define MAX_FS_KHZ 16 >@@ -147,7 +153,7 @@ extern "C" > #define USE_HARM_SHAPING 1 > > /* Max LPC order of noise shaping filters */ >-#define MAX_SHAPE_LPC_ORDER 16 >+#define MAX_SHAPE_LPC_ORDER 24 > > #define HARM_SHAPE_FIR_TAPS 3 > >@@ -157,8 +163,7 @@ extern "C" > #define LTP_BUF_LENGTH 512 > #define LTP_MASK ( LTP_BUF_LENGTH - 1 ) > >-#define DECISION_DELAY 32 >-#define DECISION_DELAY_MASK ( DECISION_DELAY - 1 ) >+#define DECISION_DELAY 40 > > /* Number of subframes for excitation entropy coding */ > #define SHELL_CODEC_FRAME_LENGTH 16 >@@ -173,11 +178,7 @@ extern "C" > > #define MAX_MATRIX_SIZE MAX_LPC_ORDER /* Max of LPC Order and LTP order */ > >-#if( MAX_LPC_ORDER > DECISION_DELAY ) > # define NSQ_LPC_BUF_LENGTH MAX_LPC_ORDER >-#else >-# define NSQ_LPC_BUF_LENGTH DECISION_DELAY >-#endif > > /***************************/ > /* Voice activity detector */ >@@ -205,7 +206,6 @@ extern "C" > /******************/ > #define NLSF_W_Q 2 > #define NLSF_VQ_MAX_VECTORS 32 >-#define NLSF_VQ_MAX_SURVIVORS 32 > #define NLSF_QUANT_MAX_AMPLITUDE 4 > #define NLSF_QUANT_MAX_AMPLITUDE_EXT 10 > #define NLSF_QUANT_LEVEL_ADJ 0.1 >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/enc_API.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/enc_API.c >index f8060286dbafa9a1fa780f4eb7446adddf2ed08e..0a62a3c1d72afd0a62128e42dcaa803ad0f44318 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/enc_API.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/enc_API.c >@@ -144,7 +144,8 @@ opus_int silk_Encode( /* O Returns error co > opus_int nSamplesIn, /* I Number of samples in input vector */ > ec_enc *psRangeEnc, /* I/O Compressor data structure */ > opus_int32 *nBytesOut, /* I/O Number of bytes in payload (input: Max bytes) */ >- const opus_int prefillFlag /* I Flag to indicate prefilling buffers no coding */ >+ const opus_int prefillFlag, /* I Flag to indicate prefilling buffers no coding */ >+ opus_int activity /* I Decision of Opus voice activity detector */ > ) > { > opus_int n, i, nBits, flags, tmp_payloadSize_ms = 0, tmp_complexity = 0, ret = 0; >@@ -233,11 +234,10 @@ opus_int silk_Encode( /* O Returns error co > } > } > >- TargetRate_bps = silk_RSHIFT32( encControl->bitRate, encControl->nChannelsInternal - 1 ); > for( n = 0; n < encControl->nChannelsInternal; n++ ) { > /* Force the side channel to the same rate as the mid */ > opus_int force_fs_kHz = (n==1) ? psEnc->state_Fxx[0].sCmn.fs_kHz : 0; >- if( ( ret = silk_control_encoder( &psEnc->state_Fxx[ n ], encControl, TargetRate_bps, psEnc->allowBandwidthSwitch, n, force_fs_kHz ) ) != 0 ) { >+ if( ( ret = silk_control_encoder( &psEnc->state_Fxx[ n ], encControl, psEnc->allowBandwidthSwitch, n, force_fs_kHz ) ) != 0 ) { > silk_assert( 0 ); > RESTORE_STACK; > return ret; >@@ -416,7 +416,6 @@ opus_int silk_Encode( /* O Returns error co > /* Reset side channel encoder memory for first frame with side coding */ > if( psEnc->prev_decode_only_middle == 1 ) { > silk_memset( &psEnc->state_Fxx[ 1 ].sShape, 0, sizeof( psEnc->state_Fxx[ 1 ].sShape ) ); >- silk_memset( &psEnc->state_Fxx[ 1 ].sPrefilt, 0, sizeof( psEnc->state_Fxx[ 1 ].sPrefilt ) ); > silk_memset( &psEnc->state_Fxx[ 1 ].sCmn.sNSQ, 0, sizeof( psEnc->state_Fxx[ 1 ].sCmn.sNSQ ) ); > silk_memset( psEnc->state_Fxx[ 1 ].sCmn.prev_NLSFq_Q15, 0, sizeof( psEnc->state_Fxx[ 1 ].sCmn.prev_NLSFq_Q15 ) ); > silk_memset( &psEnc->state_Fxx[ 1 ].sCmn.sLP.In_LP_State, 0, sizeof( psEnc->state_Fxx[ 1 ].sCmn.sLP.In_LP_State ) ); >@@ -427,7 +426,7 @@ opus_int silk_Encode( /* O Returns error co > psEnc->state_Fxx[ 1 ].sCmn.sNSQ.prev_gain_Q16 = 65536; > psEnc->state_Fxx[ 1 ].sCmn.first_frame_after_reset = 1; > } >- silk_encode_do_VAD_Fxx( &psEnc->state_Fxx[ 1 ] ); >+ silk_encode_do_VAD_Fxx( &psEnc->state_Fxx[ 1 ], activity ); > } else { > psEnc->state_Fxx[ 1 ].sCmn.VAD_flags[ psEnc->state_Fxx[ 0 ].sCmn.nFramesEncoded ] = 0; > } >@@ -442,7 +441,7 @@ opus_int silk_Encode( /* O Returns error co > silk_memcpy( psEnc->state_Fxx[ 0 ].sCmn.inputBuf, psEnc->sStereo.sMid, 2 * sizeof( opus_int16 ) ); > silk_memcpy( psEnc->sStereo.sMid, &psEnc->state_Fxx[ 0 ].sCmn.inputBuf[ psEnc->state_Fxx[ 0 ].sCmn.frame_length ], 2 * sizeof( opus_int16 ) ); > } >- silk_encode_do_VAD_Fxx( &psEnc->state_Fxx[ 0 ] ); >+ silk_encode_do_VAD_Fxx( &psEnc->state_Fxx[ 0 ], activity ); > > /* Encode */ > for( n = 0; n < encControl->nChannelsInternal; n++ ) { >@@ -557,6 +556,10 @@ opus_int silk_Encode( /* O Returns error co > } > } > >+ encControl->signalType = psEnc->state_Fxx[0].sCmn.indices.signalType; >+ encControl->offset = silk_Quantization_Offsets_Q10 >+ [ psEnc->state_Fxx[0].sCmn.indices.signalType >> 1 ] >+ [ psEnc->state_Fxx[0].sCmn.indices.quantOffsetType ]; > RESTORE_STACK; > return ret; > } >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/arm/warped_autocorrelation_FIX_arm.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/arm/warped_autocorrelation_FIX_arm.h >new file mode 100644 >index 0000000000000000000000000000000000000000..1992e43288519f8adb5ff4d3c3824804cdfa44c5 >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/arm/warped_autocorrelation_FIX_arm.h >@@ -0,0 +1,68 @@ >+/*********************************************************************** >+Copyright (c) 2017 Google Inc. >+Redistribution and use in source and binary forms, with or without >+modification, are permitted provided that the following conditions >+are met: >+- Redistributions of source code must retain the above copyright notice, >+this list of conditions and the following disclaimer. >+- Redistributions in binary form must reproduce the above copyright >+notice, this list of conditions and the following disclaimer in the >+documentation and/or other materials provided with the distribution. >+- Neither the name of Internet Society, IETF or IETF Trust, nor the >+names of specific contributors, may be used to endorse or promote >+products derived from this software without specific prior written >+permission. >+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" >+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE >+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE >+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE >+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE >+POSSIBILITY OF SUCH DAMAGE. >+***********************************************************************/ >+ >+#ifndef SILK_WARPED_AUTOCORRELATION_FIX_ARM_H >+# define SILK_WARPED_AUTOCORRELATION_FIX_ARM_H >+ >+# include "celt/arm/armcpu.h" >+ >+# if defined(FIXED_POINT) >+ >+# if defined(OPUS_ARM_MAY_HAVE_NEON_INTR) >+void silk_warped_autocorrelation_FIX_neon( >+ opus_int32 *corr, /* O Result [order + 1] */ >+ opus_int *scale, /* O Scaling of the correlation vector */ >+ const opus_int16 *input, /* I Input data to correlate */ >+ const opus_int warping_Q16, /* I Warping coefficient */ >+ const opus_int length, /* I Length of input */ >+ const opus_int order /* I Correlation order (even) */ >+); >+ >+# if !defined(OPUS_HAVE_RTCD) && defined(OPUS_ARM_PRESUME_NEON) >+# define OVERRIDE_silk_warped_autocorrelation_FIX (1) >+# define silk_warped_autocorrelation_FIX(corr, scale, input, warping_Q16, length, order, arch) \ >+ ((void)(arch), PRESUME_NEON(silk_warped_autocorrelation_FIX)(corr, scale, input, warping_Q16, length, order)) >+# endif >+# endif >+ >+# if !defined(OVERRIDE_silk_warped_autocorrelation_FIX) >+/*Is run-time CPU detection enabled on this platform?*/ >+# if defined(OPUS_HAVE_RTCD) && (defined(OPUS_ARM_MAY_HAVE_NEON_INTR) && !defined(OPUS_ARM_PRESUME_NEON_INTR)) >+extern void (*const SILK_WARPED_AUTOCORRELATION_FIX_IMPL[OPUS_ARCHMASK+1])(opus_int32*, opus_int*, const opus_int16*, const opus_int, const opus_int, const opus_int); >+# define OVERRIDE_silk_warped_autocorrelation_FIX (1) >+# define silk_warped_autocorrelation_FIX(corr, scale, input, warping_Q16, length, order, arch) \ >+ ((*SILK_WARPED_AUTOCORRELATION_FIX_IMPL[(arch)&OPUS_ARCHMASK])(corr, scale, input, warping_Q16, length, order)) >+# elif defined(OPUS_ARM_PRESUME_NEON_INTR) >+# define OVERRIDE_silk_warped_autocorrelation_FIX (1) >+# define silk_warped_autocorrelation_FIX(corr, scale, input, warping_Q16, length, order, arch) \ >+ ((void)(arch), silk_warped_autocorrelation_FIX_neon(corr, scale, input, warping_Q16, length, order)) >+# endif >+# endif >+ >+# endif /* end FIXED_POINT */ >+ >+#endif /* end SILK_WARPED_AUTOCORRELATION_FIX_ARM_H */ >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/arm/warped_autocorrelation_FIX_neon_intr.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/arm/warped_autocorrelation_FIX_neon_intr.c >new file mode 100644 >index 0000000000000000000000000000000000000000..00a70cb51ffbf39c37ea041ba66ed064f0d3084f >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/arm/warped_autocorrelation_FIX_neon_intr.c >@@ -0,0 +1,260 @@ >+/*********************************************************************** >+Copyright (c) 2017 Google Inc., Jean-Marc Valin >+Redistribution and use in source and binary forms, with or without >+modification, are permitted provided that the following conditions >+are met: >+- Redistributions of source code must retain the above copyright notice, >+this list of conditions and the following disclaimer. >+- Redistributions in binary form must reproduce the above copyright >+notice, this list of conditions and the following disclaimer in the >+documentation and/or other materials provided with the distribution. >+- Neither the name of Internet Society, IETF or IETF Trust, nor the >+names of specific contributors, may be used to endorse or promote >+products derived from this software without specific prior written >+permission. >+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" >+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE >+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE >+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE >+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE >+POSSIBILITY OF SUCH DAMAGE. >+***********************************************************************/ >+ >+#ifdef HAVE_CONFIG_H >+#include "config.h" >+#endif >+ >+#include <arm_neon.h> >+#ifdef OPUS_CHECK_ASM >+# include <string.h> >+#endif >+#include "stack_alloc.h" >+#include "main_FIX.h" >+ >+static OPUS_INLINE void calc_corr( const opus_int32 *const input_QS, opus_int64 *const corr_QC, const opus_int offset, const int32x4_t state_QS_s32x4 ) >+{ >+ int64x2_t corr_QC_s64x2[ 2 ], t_s64x2[ 2 ]; >+ const int32x4_t input_QS_s32x4 = vld1q_s32( input_QS + offset ); >+ corr_QC_s64x2[ 0 ] = vld1q_s64( corr_QC + offset + 0 ); >+ corr_QC_s64x2[ 1 ] = vld1q_s64( corr_QC + offset + 2 ); >+ t_s64x2[ 0 ] = vmull_s32( vget_low_s32( state_QS_s32x4 ), vget_low_s32( input_QS_s32x4 ) ); >+ t_s64x2[ 1 ] = vmull_s32( vget_high_s32( state_QS_s32x4 ), vget_high_s32( input_QS_s32x4 ) ); >+ corr_QC_s64x2[ 0 ] = vsraq_n_s64( corr_QC_s64x2[ 0 ], t_s64x2[ 0 ], 2 * QS - QC ); >+ corr_QC_s64x2[ 1 ] = vsraq_n_s64( corr_QC_s64x2[ 1 ], t_s64x2[ 1 ], 2 * QS - QC ); >+ vst1q_s64( corr_QC + offset + 0, corr_QC_s64x2[ 0 ] ); >+ vst1q_s64( corr_QC + offset + 2, corr_QC_s64x2[ 1 ] ); >+} >+ >+static OPUS_INLINE int32x4_t calc_state( const int32x4_t state_QS0_s32x4, const int32x4_t state_QS0_1_s32x4, const int32x4_t state_QS1_1_s32x4, const int32x4_t warping_Q16_s32x4 ) >+{ >+ int32x4_t t_s32x4 = vsubq_s32( state_QS0_s32x4, state_QS0_1_s32x4 ); >+ t_s32x4 = vqdmulhq_s32( t_s32x4, warping_Q16_s32x4 ); >+ return vaddq_s32( state_QS1_1_s32x4, t_s32x4 ); >+} >+ >+void silk_warped_autocorrelation_FIX_neon( >+ opus_int32 *corr, /* O Result [order + 1] */ >+ opus_int *scale, /* O Scaling of the correlation vector */ >+ const opus_int16 *input, /* I Input data to correlate */ >+ const opus_int warping_Q16, /* I Warping coefficient */ >+ const opus_int length, /* I Length of input */ >+ const opus_int order /* I Correlation order (even) */ >+) >+{ >+ if( ( MAX_SHAPE_LPC_ORDER > 24 ) || ( order < 6 ) ) { >+ silk_warped_autocorrelation_FIX_c( corr, scale, input, warping_Q16, length, order ); >+ } else { >+ opus_int n, i, lsh; >+ opus_int64 corr_QC[ MAX_SHAPE_LPC_ORDER + 1 ] = { 0 }; /* In reverse order */ >+ opus_int64 corr_QC_orderT; >+ int64x2_t lsh_s64x2; >+ const opus_int orderT = ( order + 3 ) & ~3; >+ opus_int64 *corr_QCT; >+ opus_int32 *input_QS; >+ VARDECL( opus_int32, input_QST ); >+ VARDECL( opus_int32, state ); >+ SAVE_STACK; >+ >+ /* Order must be even */ >+ silk_assert( ( order & 1 ) == 0 ); >+ silk_assert( 2 * QS - QC >= 0 ); >+ >+ ALLOC( input_QST, length + 2 * MAX_SHAPE_LPC_ORDER, opus_int32 ); >+ >+ input_QS = input_QST; >+ /* input_QS has zero paddings in the beginning and end. */ >+ vst1q_s32( input_QS, vdupq_n_s32( 0 ) ); >+ input_QS += 4; >+ vst1q_s32( input_QS, vdupq_n_s32( 0 ) ); >+ input_QS += 4; >+ vst1q_s32( input_QS, vdupq_n_s32( 0 ) ); >+ input_QS += 4; >+ vst1q_s32( input_QS, vdupq_n_s32( 0 ) ); >+ input_QS += 4; >+ vst1q_s32( input_QS, vdupq_n_s32( 0 ) ); >+ input_QS += 4; >+ vst1q_s32( input_QS, vdupq_n_s32( 0 ) ); >+ input_QS += 4; >+ >+ /* Loop over samples */ >+ for( n = 0; n < length - 7; n += 8, input_QS += 8 ) { >+ const int16x8_t t0_s16x4 = vld1q_s16( input + n ); >+ vst1q_s32( input_QS + 0, vshll_n_s16( vget_low_s16( t0_s16x4 ), QS ) ); >+ vst1q_s32( input_QS + 4, vshll_n_s16( vget_high_s16( t0_s16x4 ), QS ) ); >+ } >+ for( ; n < length; n++, input_QS++ ) { >+ input_QS[ 0 ] = silk_LSHIFT32( (opus_int32)input[ n ], QS ); >+ } >+ vst1q_s32( input_QS, vdupq_n_s32( 0 ) ); >+ input_QS += 4; >+ vst1q_s32( input_QS, vdupq_n_s32( 0 ) ); >+ input_QS += 4; >+ vst1q_s32( input_QS, vdupq_n_s32( 0 ) ); >+ input_QS += 4; >+ vst1q_s32( input_QS, vdupq_n_s32( 0 ) ); >+ input_QS += 4; >+ vst1q_s32( input_QS, vdupq_n_s32( 0 ) ); >+ input_QS += 4; >+ vst1q_s32( input_QS, vdupq_n_s32( 0 ) ); >+ input_QS = input_QST + MAX_SHAPE_LPC_ORDER - orderT; >+ >+ /* The following loop runs ( length + order ) times, with ( order ) extra epilogues. */ >+ /* The zero paddings in input_QS guarantee corr_QC's correctness even with the extra epilogues. */ >+ /* The values of state_QS will be polluted by the extra epilogues, however they are temporary values. */ >+ >+ /* Keep the C code here to help understand the intrinsics optimization. */ >+ /* >+ { >+ opus_int32 state_QS[ 2 ][ MAX_SHAPE_LPC_ORDER + 1 ] = { 0 }; >+ opus_int32 *state_QST[ 3 ]; >+ state_QST[ 0 ] = state_QS[ 0 ]; >+ state_QST[ 1 ] = state_QS[ 1 ]; >+ for( n = 0; n < length + order; n++, input_QS++ ) { >+ state_QST[ 0 ][ orderT ] = input_QS[ orderT ]; >+ for( i = 0; i < orderT; i++ ) { >+ corr_QC[ i ] += silk_RSHIFT64( silk_SMULL( state_QST[ 0 ][ i ], input_QS[ i ] ), 2 * QS - QC ); >+ state_QST[ 1 ][ i ] = silk_SMLAWB( state_QST[ 1 ][ i + 1 ], state_QST[ 0 ][ i ] - state_QST[ 0 ][ i + 1 ], warping_Q16 ); >+ } >+ state_QST[ 2 ] = state_QST[ 0 ]; >+ state_QST[ 0 ] = state_QST[ 1 ]; >+ state_QST[ 1 ] = state_QST[ 2 ]; >+ } >+ } >+ */ >+ >+ { >+ const int32x4_t warping_Q16_s32x4 = vdupq_n_s32( warping_Q16 << 15 ); >+ const opus_int32 *in = input_QS + orderT; >+ opus_int o = orderT; >+ int32x4_t state_QS_s32x4[ 3 ][ 2 ]; >+ >+ ALLOC( state, length + orderT, opus_int32 ); >+ state_QS_s32x4[ 2 ][ 1 ] = vdupq_n_s32( 0 ); >+ >+ /* Calculate 8 taps of all inputs in each loop. */ >+ do { >+ state_QS_s32x4[ 0 ][ 0 ] = state_QS_s32x4[ 0 ][ 1 ] = >+ state_QS_s32x4[ 1 ][ 0 ] = state_QS_s32x4[ 1 ][ 1 ] = vdupq_n_s32( 0 ); >+ n = 0; >+ do { >+ calc_corr( input_QS + n, corr_QC, o - 8, state_QS_s32x4[ 0 ][ 0 ] ); >+ calc_corr( input_QS + n, corr_QC, o - 4, state_QS_s32x4[ 0 ][ 1 ] ); >+ state_QS_s32x4[ 2 ][ 1 ] = vld1q_s32( in + n ); >+ vst1q_lane_s32( state + n, state_QS_s32x4[ 0 ][ 0 ], 0 ); >+ state_QS_s32x4[ 2 ][ 0 ] = vextq_s32( state_QS_s32x4[ 0 ][ 0 ], state_QS_s32x4[ 0 ][ 1 ], 1 ); >+ state_QS_s32x4[ 2 ][ 1 ] = vextq_s32( state_QS_s32x4[ 0 ][ 1 ], state_QS_s32x4[ 2 ][ 1 ], 1 ); >+ state_QS_s32x4[ 0 ][ 0 ] = calc_state( state_QS_s32x4[ 0 ][ 0 ], state_QS_s32x4[ 2 ][ 0 ], state_QS_s32x4[ 1 ][ 0 ], warping_Q16_s32x4 ); >+ state_QS_s32x4[ 0 ][ 1 ] = calc_state( state_QS_s32x4[ 0 ][ 1 ], state_QS_s32x4[ 2 ][ 1 ], state_QS_s32x4[ 1 ][ 1 ], warping_Q16_s32x4 ); >+ state_QS_s32x4[ 1 ][ 0 ] = state_QS_s32x4[ 2 ][ 0 ]; >+ state_QS_s32x4[ 1 ][ 1 ] = state_QS_s32x4[ 2 ][ 1 ]; >+ } while( ++n < ( length + order ) ); >+ in = state; >+ o -= 8; >+ } while( o > 4 ); >+ >+ if( o ) { >+ /* Calculate the last 4 taps of all inputs. */ >+ opus_int32 *stateT = state; >+ silk_assert( o == 4 ); >+ state_QS_s32x4[ 0 ][ 0 ] = state_QS_s32x4[ 1 ][ 0 ] = vdupq_n_s32( 0 ); >+ n = length + order; >+ do { >+ calc_corr( input_QS, corr_QC, 0, state_QS_s32x4[ 0 ][ 0 ] ); >+ state_QS_s32x4[ 2 ][ 0 ] = vld1q_s32( stateT ); >+ vst1q_lane_s32( stateT, state_QS_s32x4[ 0 ][ 0 ], 0 ); >+ state_QS_s32x4[ 2 ][ 0 ] = vextq_s32( state_QS_s32x4[ 0 ][ 0 ], state_QS_s32x4[ 2 ][ 0 ], 1 ); >+ state_QS_s32x4[ 0 ][ 0 ] = calc_state( state_QS_s32x4[ 0 ][ 0 ], state_QS_s32x4[ 2 ][ 0 ], state_QS_s32x4[ 1 ][ 0 ], warping_Q16_s32x4 ); >+ state_QS_s32x4[ 1 ][ 0 ] = state_QS_s32x4[ 2 ][ 0 ]; >+ input_QS++; >+ stateT++; >+ } while( --n ); >+ } >+ } >+ >+ { >+ const opus_int16 *inputT = input; >+ int32x4_t t_s32x4; >+ int64x1_t t_s64x1; >+ int64x2_t t_s64x2 = vdupq_n_s64( 0 ); >+ for( n = 0; n <= length - 8; n += 8 ) { >+ int16x8_t input_s16x8 = vld1q_s16( inputT ); >+ t_s32x4 = vmull_s16( vget_low_s16( input_s16x8 ), vget_low_s16( input_s16x8 ) ); >+ t_s32x4 = vmlal_s16( t_s32x4, vget_high_s16( input_s16x8 ), vget_high_s16( input_s16x8 ) ); >+ t_s64x2 = vaddw_s32( t_s64x2, vget_low_s32( t_s32x4 ) ); >+ t_s64x2 = vaddw_s32( t_s64x2, vget_high_s32( t_s32x4 ) ); >+ inputT += 8; >+ } >+ t_s64x1 = vadd_s64( vget_low_s64( t_s64x2 ), vget_high_s64( t_s64x2 ) ); >+ corr_QC_orderT = vget_lane_s64( t_s64x1, 0 ); >+ for( ; n < length; n++ ) { >+ corr_QC_orderT += silk_SMULL( input[ n ], input[ n ] ); >+ } >+ corr_QC_orderT = silk_LSHIFT64( corr_QC_orderT, QC ); >+ corr_QC[ orderT ] = corr_QC_orderT; >+ } >+ >+ corr_QCT = corr_QC + orderT - order; >+ lsh = silk_CLZ64( corr_QC_orderT ) - 35; >+ lsh = silk_LIMIT( lsh, -12 - QC, 30 - QC ); >+ *scale = -( QC + lsh ); >+ silk_assert( *scale >= -30 && *scale <= 12 ); >+ lsh_s64x2 = vdupq_n_s64( lsh ); >+ for( i = 0; i <= order - 3; i += 4 ) { >+ int32x4_t corr_s32x4; >+ int64x2_t corr_QC0_s64x2, corr_QC1_s64x2; >+ corr_QC0_s64x2 = vld1q_s64( corr_QCT + i ); >+ corr_QC1_s64x2 = vld1q_s64( corr_QCT + i + 2 ); >+ corr_QC0_s64x2 = vshlq_s64( corr_QC0_s64x2, lsh_s64x2 ); >+ corr_QC1_s64x2 = vshlq_s64( corr_QC1_s64x2, lsh_s64x2 ); >+ corr_s32x4 = vcombine_s32( vmovn_s64( corr_QC1_s64x2 ), vmovn_s64( corr_QC0_s64x2 ) ); >+ corr_s32x4 = vrev64q_s32( corr_s32x4 ); >+ vst1q_s32( corr + order - i - 3, corr_s32x4 ); >+ } >+ if( lsh >= 0 ) { >+ for( ; i < order + 1; i++ ) { >+ corr[ order - i ] = (opus_int32)silk_CHECK_FIT32( silk_LSHIFT64( corr_QCT[ i ], lsh ) ); >+ } >+ } else { >+ for( ; i < order + 1; i++ ) { >+ corr[ order - i ] = (opus_int32)silk_CHECK_FIT32( silk_RSHIFT64( corr_QCT[ i ], -lsh ) ); >+ } >+ } >+ silk_assert( corr_QCT[ order ] >= 0 ); /* If breaking, decrease QC*/ >+ RESTORE_STACK; >+ } >+ >+#ifdef OPUS_CHECK_ASM >+ { >+ opus_int32 corr_c[ MAX_SHAPE_LPC_ORDER + 1 ]; >+ opus_int scale_c; >+ silk_warped_autocorrelation_FIX_c( corr_c, &scale_c, input, warping_Q16, length, order ); >+ silk_assert( !memcmp( corr_c, corr, sizeof( corr_c[ 0 ] ) * ( order + 1 ) ) ); >+ silk_assert( scale_c == *scale ); >+ } >+#endif >+} >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/burg_modified_FIX.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/burg_modified_FIX.c >index 17d0e0993cf5ba188db1829c12ded74cbe071915..80edbdfa8a65140848c2e8903190bcd85a5f90b7 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/burg_modified_FIX.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/burg_modified_FIX.c >@@ -37,7 +37,7 @@ POSSIBILITY OF SUCH DAMAGE. > #define MAX_FRAME_SIZE 384 /* subfr_length * nb_subfr = ( 0.005 * 16000 + 16 ) * 4 = 384 */ > > #define QA 25 >-#define N_BITS_HEAD_ROOM 2 >+#define N_BITS_HEAD_ROOM 3 > #define MIN_RSHIFTS -16 > #define MAX_RSHIFTS (32 - QA) > >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/corrMatrix_FIX.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/corrMatrix_FIX.c >index c1d437c7859e3a22c3ae0fbe0d6376b70812a437..1b4a29c232bfeeaf8b6b7b532577e234c982f42f 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/corrMatrix_FIX.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/corrMatrix_FIX.c >@@ -58,7 +58,7 @@ void silk_corrVector_FIX( > for( lag = 0; lag < order; lag++ ) { > inner_prod = 0; > for( i = 0; i < L; i++ ) { >- inner_prod += silk_RSHIFT32( silk_SMULBB( ptr1[ i ], ptr2[i] ), rshifts ); >+ inner_prod = silk_ADD_RSHIFT32( inner_prod, silk_SMULBB( ptr1[ i ], ptr2[i] ), rshifts ); > } > Xt[ lag ] = inner_prod; /* X[:,lag]'*t */ > ptr1--; /* Go to next column of X */ >@@ -77,61 +77,54 @@ void silk_corrMatrix_FIX( > const opus_int16 *x, /* I x vector [L + order - 1] used to form data matrix X */ > const opus_int L, /* I Length of vectors */ > const opus_int order, /* I Max lag for correlation */ >- const opus_int head_room, /* I Desired headroom */ > opus_int32 *XX, /* O Pointer to X'*X correlation matrix [ order x order ] */ >- opus_int *rshifts, /* I/O Right shifts of correlations */ >+ opus_int32 *nrg, /* O Energy of x vector */ >+ opus_int *rshifts, /* O Right shifts of correlations and energy */ > int arch /* I Run-time architecture */ > ) > { >- opus_int i, j, lag, rshifts_local, head_room_rshifts; >+ opus_int i, j, lag; > opus_int32 energy; > const opus_int16 *ptr1, *ptr2; > > /* Calculate energy to find shift used to fit in 32 bits */ >- silk_sum_sqr_shift( &energy, &rshifts_local, x, L + order - 1 ); >- /* Add shifts to get the desired head room */ >- head_room_rshifts = silk_max( head_room - silk_CLZ32( energy ), 0 ); >- >- energy = silk_RSHIFT32( energy, head_room_rshifts ); >- rshifts_local += head_room_rshifts; >+ silk_sum_sqr_shift( nrg, rshifts, x, L + order - 1 ); >+ energy = *nrg; > > /* Calculate energy of first column (0) of X: X[:,0]'*X[:,0] */ > /* Remove contribution of first order - 1 samples */ > for( i = 0; i < order - 1; i++ ) { >- energy -= silk_RSHIFT32( silk_SMULBB( x[ i ], x[ i ] ), rshifts_local ); >- } >- if( rshifts_local < *rshifts ) { >- /* Adjust energy */ >- energy = silk_RSHIFT32( energy, *rshifts - rshifts_local ); >- rshifts_local = *rshifts; >+ energy -= silk_RSHIFT32( silk_SMULBB( x[ i ], x[ i ] ), *rshifts ); > } > > /* Calculate energy of remaining columns of X: X[:,j]'*X[:,j] */ > /* Fill out the diagonal of the correlation matrix */ > matrix_ptr( XX, 0, 0, order ) = energy; >+ silk_assert( energy >= 0 ); > ptr1 = &x[ order - 1 ]; /* First sample of column 0 of X */ > for( j = 1; j < order; j++ ) { >- energy = silk_SUB32( energy, silk_RSHIFT32( silk_SMULBB( ptr1[ L - j ], ptr1[ L - j ] ), rshifts_local ) ); >- energy = silk_ADD32( energy, silk_RSHIFT32( silk_SMULBB( ptr1[ -j ], ptr1[ -j ] ), rshifts_local ) ); >+ energy = silk_SUB32( energy, silk_RSHIFT32( silk_SMULBB( ptr1[ L - j ], ptr1[ L - j ] ), *rshifts ) ); >+ energy = silk_ADD32( energy, silk_RSHIFT32( silk_SMULBB( ptr1[ -j ], ptr1[ -j ] ), *rshifts ) ); > matrix_ptr( XX, j, j, order ) = energy; >+ silk_assert( energy >= 0 ); > } > > ptr2 = &x[ order - 2 ]; /* First sample of column 1 of X */ > /* Calculate the remaining elements of the correlation matrix */ >- if( rshifts_local > 0 ) { >+ if( *rshifts > 0 ) { > /* Right shifting used */ > for( lag = 1; lag < order; lag++ ) { > /* Inner product of column 0 and column lag: X[:,0]'*X[:,lag] */ > energy = 0; > for( i = 0; i < L; i++ ) { >- energy += silk_RSHIFT32( silk_SMULBB( ptr1[ i ], ptr2[i] ), rshifts_local ); >+ energy += silk_RSHIFT32( silk_SMULBB( ptr1[ i ], ptr2[i] ), *rshifts ); > } > /* Calculate remaining off diagonal: X[:,j]'*X[:,j + lag] */ > matrix_ptr( XX, lag, 0, order ) = energy; > matrix_ptr( XX, 0, lag, order ) = energy; > for( j = 1; j < ( order - lag ); j++ ) { >- energy = silk_SUB32( energy, silk_RSHIFT32( silk_SMULBB( ptr1[ L - j ], ptr2[ L - j ] ), rshifts_local ) ); >- energy = silk_ADD32( energy, silk_RSHIFT32( silk_SMULBB( ptr1[ -j ], ptr2[ -j ] ), rshifts_local ) ); >+ energy = silk_SUB32( energy, silk_RSHIFT32( silk_SMULBB( ptr1[ L - j ], ptr2[ L - j ] ), *rshifts ) ); >+ energy = silk_ADD32( energy, silk_RSHIFT32( silk_SMULBB( ptr1[ -j ], ptr2[ -j ] ), *rshifts ) ); > matrix_ptr( XX, lag + j, j, order ) = energy; > matrix_ptr( XX, j, lag + j, order ) = energy; > } >@@ -153,6 +146,5 @@ void silk_corrMatrix_FIX( > ptr2--;/* Update pointer to first sample of next column (lag) in X */ > } > } >- *rshifts = rshifts_local; > } > >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/encode_frame_FIX.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/encode_frame_FIX.c >index 5ef44b03fc4c585999bcec28235e0ed4a55486b1..f6ee813b97fa564d33f9648e080f984159c944c3 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/encode_frame_FIX.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/encode_frame_FIX.c >@@ -29,6 +29,7 @@ POSSIBILITY OF SUCH DAMAGE. > #include "config.h" > #endif > >+#include <stdlib.h> > #include "main_FIX.h" > #include "stack_alloc.h" > #include "tuning_parameters.h" >@@ -37,26 +38,33 @@ POSSIBILITY OF SUCH DAMAGE. > static OPUS_INLINE void silk_LBRR_encode_FIX( > silk_encoder_state_FIX *psEnc, /* I/O Pointer to Silk FIX encoder state */ > silk_encoder_control_FIX *psEncCtrl, /* I/O Pointer to Silk FIX encoder control struct */ >- const opus_int32 xfw_Q3[], /* I Input signal */ >+ const opus_int16 x16[], /* I Input signal */ > opus_int condCoding /* I The type of conditional coding used so far for this frame */ > ); > > void silk_encode_do_VAD_FIX( >- silk_encoder_state_FIX *psEnc /* I/O Pointer to Silk FIX encoder state */ >+ silk_encoder_state_FIX *psEnc, /* I/O Pointer to Silk FIX encoder state */ >+ opus_int activity /* I Decision of Opus voice activity detector */ > ) > { >+ const opus_int activity_threshold = SILK_FIX_CONST( SPEECH_ACTIVITY_DTX_THRES, 8 ); >+ > /****************************/ > /* Voice Activity Detection */ > /****************************/ > silk_VAD_GetSA_Q8( &psEnc->sCmn, psEnc->sCmn.inputBuf + 1, psEnc->sCmn.arch ); >+ /* If Opus VAD is inactive and Silk VAD is active: lower Silk VAD to just under the threshold */ >+ if( activity == VAD_NO_ACTIVITY && psEnc->sCmn.speech_activity_Q8 >= activity_threshold ) { >+ psEnc->sCmn.speech_activity_Q8 = activity_threshold - 1; >+ } > > /**************************************************/ > /* Convert speech activity into VAD and DTX flags */ > /**************************************************/ >- if( psEnc->sCmn.speech_activity_Q8 < SILK_FIX_CONST( SPEECH_ACTIVITY_DTX_THRES, 8 ) ) { >+ if( psEnc->sCmn.speech_activity_Q8 < activity_threshold ) { > psEnc->sCmn.indices.signalType = TYPE_NO_VOICE_ACTIVITY; > psEnc->sCmn.noSpeechCounter++; >- if( psEnc->sCmn.noSpeechCounter < NB_SPEECH_FRAMES_BEFORE_DTX ) { >+ if( psEnc->sCmn.noSpeechCounter <= NB_SPEECH_FRAMES_BEFORE_DTX ) { > psEnc->sCmn.inDTX = 0; > } else if( psEnc->sCmn.noSpeechCounter > MAX_CONSECUTIVE_DTX + NB_SPEECH_FRAMES_BEFORE_DTX ) { > psEnc->sCmn.noSpeechCounter = NB_SPEECH_FRAMES_BEFORE_DTX; >@@ -94,6 +102,9 @@ opus_int silk_encode_frame_FIX( > opus_int16 ec_prevLagIndex_copy; > opus_int ec_prevSignalType_copy; > opus_int8 LastGainIndex_copy2; >+ opus_int gain_lock[ MAX_NB_SUBFR ] = {0}; >+ opus_int16 best_gain_mult[ MAX_NB_SUBFR ]; >+ opus_int best_sum[ MAX_NB_SUBFR ]; > SAVE_STACK; > > /* This is totally unnecessary but many compilers (including gcc) are too dumb to realise it */ >@@ -118,7 +129,6 @@ opus_int silk_encode_frame_FIX( > silk_memcpy( x_frame + LA_SHAPE_MS * psEnc->sCmn.fs_kHz, psEnc->sCmn.inputBuf + 1, psEnc->sCmn.frame_length * sizeof( opus_int16 ) ); > > if( !psEnc->sCmn.prefillFlag ) { >- VARDECL( opus_int32, xfw_Q3 ); > VARDECL( opus_int16, res_pitch ); > VARDECL( opus_uint8, ec_buf_copy ); > opus_int16 *res_pitch_frame; >@@ -132,7 +142,7 @@ opus_int silk_encode_frame_FIX( > /*****************************************/ > /* Find pitch lags, initial LPC analysis */ > /*****************************************/ >- silk_find_pitch_lags_FIX( psEnc, &sEncCtrl, res_pitch, x_frame, psEnc->sCmn.arch ); >+ silk_find_pitch_lags_FIX( psEnc, &sEncCtrl, res_pitch, x_frame - psEnc->sCmn.ltp_mem_length, psEnc->sCmn.arch ); > > /************************/ > /* Noise shape analysis */ >@@ -142,23 +152,17 @@ opus_int silk_encode_frame_FIX( > /***************************************************/ > /* Find linear prediction coefficients (LPC + LTP) */ > /***************************************************/ >- silk_find_pred_coefs_FIX( psEnc, &sEncCtrl, res_pitch, x_frame, condCoding ); >+ silk_find_pred_coefs_FIX( psEnc, &sEncCtrl, res_pitch_frame, x_frame, condCoding ); > > /****************************************/ > /* Process gains */ > /****************************************/ > silk_process_gains_FIX( psEnc, &sEncCtrl, condCoding ); > >- /*****************************************/ >- /* Prefiltering for noise shaper */ >- /*****************************************/ >- ALLOC( xfw_Q3, psEnc->sCmn.frame_length, opus_int32 ); >- silk_prefilter_FIX( psEnc, &sEncCtrl, xfw_Q3, x_frame ); >- > /****************************************/ > /* Low Bitrate Redundant Encoding */ > /****************************************/ >- silk_LBRR_encode_FIX( psEnc, &sEncCtrl, xfw_Q3, condCoding ); >+ silk_LBRR_encode_FIX( psEnc, &sEncCtrl, x_frame, condCoding ); > > /* Loop over quantizer and entropy coding to control bitrate */ > maxIter = 6; >@@ -194,17 +198,21 @@ opus_int silk_encode_frame_FIX( > /* Noise shaping quantization */ > /*****************************************/ > if( psEnc->sCmn.nStatesDelayedDecision > 1 || psEnc->sCmn.warping_Q16 > 0 ) { >- silk_NSQ_del_dec( &psEnc->sCmn, &psEnc->sCmn.sNSQ, &psEnc->sCmn.indices, xfw_Q3, psEnc->sCmn.pulses, >- sEncCtrl.PredCoef_Q12[ 0 ], sEncCtrl.LTPCoef_Q14, sEncCtrl.AR2_Q13, sEncCtrl.HarmShapeGain_Q14, >+ silk_NSQ_del_dec( &psEnc->sCmn, &psEnc->sCmn.sNSQ, &psEnc->sCmn.indices, x_frame, psEnc->sCmn.pulses, >+ sEncCtrl.PredCoef_Q12[ 0 ], sEncCtrl.LTPCoef_Q14, sEncCtrl.AR_Q13, sEncCtrl.HarmShapeGain_Q14, > sEncCtrl.Tilt_Q14, sEncCtrl.LF_shp_Q14, sEncCtrl.Gains_Q16, sEncCtrl.pitchL, sEncCtrl.Lambda_Q10, sEncCtrl.LTP_scale_Q14, > psEnc->sCmn.arch ); > } else { >- silk_NSQ( &psEnc->sCmn, &psEnc->sCmn.sNSQ, &psEnc->sCmn.indices, xfw_Q3, psEnc->sCmn.pulses, >- sEncCtrl.PredCoef_Q12[ 0 ], sEncCtrl.LTPCoef_Q14, sEncCtrl.AR2_Q13, sEncCtrl.HarmShapeGain_Q14, >+ silk_NSQ( &psEnc->sCmn, &psEnc->sCmn.sNSQ, &psEnc->sCmn.indices, x_frame, psEnc->sCmn.pulses, >+ sEncCtrl.PredCoef_Q12[ 0 ], sEncCtrl.LTPCoef_Q14, sEncCtrl.AR_Q13, sEncCtrl.HarmShapeGain_Q14, > sEncCtrl.Tilt_Q14, sEncCtrl.LF_shp_Q14, sEncCtrl.Gains_Q16, sEncCtrl.pitchL, sEncCtrl.Lambda_Q10, sEncCtrl.LTP_scale_Q14, > psEnc->sCmn.arch); > } > >+ if ( iter == maxIter && !found_lower ) { >+ silk_memcpy( &sRangeEnc_copy2, psRangeEnc, sizeof( ec_enc ) ); >+ } >+ > /****************************************/ > /* Encode Parameters */ > /****************************************/ >@@ -218,6 +226,33 @@ opus_int silk_encode_frame_FIX( > > nBits = ec_tell( psRangeEnc ); > >+ /* If we still bust after the last iteration, do some damage control. */ >+ if ( iter == maxIter && !found_lower && nBits > maxBits ) { >+ silk_memcpy( psRangeEnc, &sRangeEnc_copy2, sizeof( ec_enc ) ); >+ >+ /* Keep gains the same as the last frame. */ >+ psEnc->sShape.LastGainIndex = sEncCtrl.lastGainIndexPrev; >+ for ( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) { >+ psEnc->sCmn.indices.GainsIndices[ i ] = 4; >+ } >+ if (condCoding != CODE_CONDITIONALLY) { >+ psEnc->sCmn.indices.GainsIndices[ 0 ] = sEncCtrl.lastGainIndexPrev; >+ } >+ psEnc->sCmn.ec_prevLagIndex = ec_prevLagIndex_copy; >+ psEnc->sCmn.ec_prevSignalType = ec_prevSignalType_copy; >+ /* Clear all pulses. */ >+ for ( i = 0; i < psEnc->sCmn.frame_length; i++ ) { >+ psEnc->sCmn.pulses[ i ] = 0; >+ } >+ >+ silk_encode_indices( &psEnc->sCmn, psRangeEnc, psEnc->sCmn.nFramesEncoded, 0, condCoding ); >+ >+ silk_encode_pulses( psRangeEnc, psEnc->sCmn.indices.signalType, psEnc->sCmn.indices.quantOffsetType, >+ psEnc->sCmn.pulses, psEnc->sCmn.frame_length ); >+ >+ nBits = ec_tell( psRangeEnc ); >+ } >+ > if( useCBR == 0 && iter == 0 && nBits <= maxBits ) { > break; > } >@@ -265,15 +300,35 @@ opus_int silk_encode_frame_FIX( > break; > } > >+ if ( !found_lower && nBits > maxBits ) { >+ int j; >+ for ( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) { >+ int sum=0; >+ for ( j = i*psEnc->sCmn.subfr_length; j < (i+1)*psEnc->sCmn.subfr_length; j++ ) { >+ sum += abs( psEnc->sCmn.pulses[j] ); >+ } >+ if ( iter == 0 || (sum < best_sum[i] && !gain_lock[i]) ) { >+ best_sum[i] = sum; >+ best_gain_mult[i] = gainMult_Q8; >+ } else { >+ gain_lock[i] = 1; >+ } >+ } >+ } > if( ( found_lower & found_upper ) == 0 ) { > /* Adjust gain according to high-rate rate/distortion curve */ >- opus_int32 gain_factor_Q16; >- gain_factor_Q16 = silk_log2lin( silk_LSHIFT( nBits - maxBits, 7 ) / psEnc->sCmn.frame_length + SILK_FIX_CONST( 16, 7 ) ); >- gain_factor_Q16 = silk_min_32( gain_factor_Q16, SILK_FIX_CONST( 2, 16 ) ); > if( nBits > maxBits ) { >- gain_factor_Q16 = silk_max_32( gain_factor_Q16, SILK_FIX_CONST( 1.3, 16 ) ); >+ if (gainMult_Q8 < 16384) { >+ gainMult_Q8 *= 2; >+ } else { >+ gainMult_Q8 = 32767; >+ } >+ } else { >+ opus_int32 gain_factor_Q16; >+ gain_factor_Q16 = silk_log2lin( silk_LSHIFT( nBits - maxBits, 7 ) / psEnc->sCmn.frame_length + SILK_FIX_CONST( 16, 7 ) ); >+ gainMult_Q8 = silk_SMULWB( gain_factor_Q16, gainMult_Q8 ); > } >- gainMult_Q8 = silk_SMULWB( gain_factor_Q16, gainMult_Q8 ); >+ > } else { > /* Adjust gain by interpolating */ > gainMult_Q8 = gainMult_lower + silk_DIV32_16( silk_MUL( gainMult_upper - gainMult_lower, maxBits - nBits_lower ), nBits_upper - nBits_lower ); >@@ -287,7 +342,13 @@ opus_int silk_encode_frame_FIX( > } > > for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) { >- sEncCtrl.Gains_Q16[ i ] = silk_LSHIFT_SAT32( silk_SMULWB( sEncCtrl.GainsUnq_Q16[ i ], gainMult_Q8 ), 8 ); >+ opus_int16 tmp; >+ if ( gain_lock[i] ) { >+ tmp = best_gain_mult[i]; >+ } else { >+ tmp = gainMult_Q8; >+ } >+ sEncCtrl.Gains_Q16[ i ] = silk_LSHIFT_SAT32( silk_SMULWB( sEncCtrl.GainsUnq_Q16[ i ], tmp ), 8 ); > } > > /* Quantize gains */ >@@ -331,7 +392,7 @@ opus_int silk_encode_frame_FIX( > static OPUS_INLINE void silk_LBRR_encode_FIX( > silk_encoder_state_FIX *psEnc, /* I/O Pointer to Silk FIX encoder state */ > silk_encoder_control_FIX *psEncCtrl, /* I/O Pointer to Silk FIX encoder control struct */ >- const opus_int32 xfw_Q3[], /* I Input signal */ >+ const opus_int16 x16[], /* I Input signal */ > opus_int condCoding /* I The type of conditional coding used so far for this frame */ > ) > { >@@ -370,14 +431,14 @@ static OPUS_INLINE void silk_LBRR_encode_FIX( > /* Noise shaping quantization */ > /*****************************************/ > if( psEnc->sCmn.nStatesDelayedDecision > 1 || psEnc->sCmn.warping_Q16 > 0 ) { >- silk_NSQ_del_dec( &psEnc->sCmn, &sNSQ_LBRR, psIndices_LBRR, xfw_Q3, >+ silk_NSQ_del_dec( &psEnc->sCmn, &sNSQ_LBRR, psIndices_LBRR, x16, > psEnc->sCmn.pulses_LBRR[ psEnc->sCmn.nFramesEncoded ], psEncCtrl->PredCoef_Q12[ 0 ], psEncCtrl->LTPCoef_Q14, >- psEncCtrl->AR2_Q13, psEncCtrl->HarmShapeGain_Q14, psEncCtrl->Tilt_Q14, psEncCtrl->LF_shp_Q14, >+ psEncCtrl->AR_Q13, psEncCtrl->HarmShapeGain_Q14, psEncCtrl->Tilt_Q14, psEncCtrl->LF_shp_Q14, > psEncCtrl->Gains_Q16, psEncCtrl->pitchL, psEncCtrl->Lambda_Q10, psEncCtrl->LTP_scale_Q14, psEnc->sCmn.arch ); > } else { >- silk_NSQ( &psEnc->sCmn, &sNSQ_LBRR, psIndices_LBRR, xfw_Q3, >+ silk_NSQ( &psEnc->sCmn, &sNSQ_LBRR, psIndices_LBRR, x16, > psEnc->sCmn.pulses_LBRR[ psEnc->sCmn.nFramesEncoded ], psEncCtrl->PredCoef_Q12[ 0 ], psEncCtrl->LTPCoef_Q14, >- psEncCtrl->AR2_Q13, psEncCtrl->HarmShapeGain_Q14, psEncCtrl->Tilt_Q14, psEncCtrl->LF_shp_Q14, >+ psEncCtrl->AR_Q13, psEncCtrl->HarmShapeGain_Q14, psEncCtrl->Tilt_Q14, psEncCtrl->LF_shp_Q14, > psEncCtrl->Gains_Q16, psEncCtrl->pitchL, psEncCtrl->Lambda_Q10, psEncCtrl->LTP_scale_Q14, psEnc->sCmn.arch ); > } > >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/find_LPC_FIX.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/find_LPC_FIX.c >index e11cdc86e67d0f836c75e4033b9ee2b2915394a8..e55b63ac329a214dc5ac9ff40893943e33ad083d 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/find_LPC_FIX.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/find_LPC_FIX.c >@@ -92,7 +92,7 @@ void silk_find_LPC_FIX( > silk_interpolate( NLSF0_Q15, psEncC->prev_NLSFq_Q15, NLSF_Q15, k, psEncC->predictLPCOrder ); > > /* Convert to LPC for residual energy evaluation */ >- silk_NLSF2A( a_tmp_Q12, NLSF0_Q15, psEncC->predictLPCOrder ); >+ silk_NLSF2A( a_tmp_Q12, NLSF0_Q15, psEncC->predictLPCOrder, psEncC->arch ); > > /* Calculate residual energy with NLSF interpolation */ > silk_LPC_analysis_filter( LPC_res, x, a_tmp_Q12, 2 * subfr_length, psEncC->predictLPCOrder, psEncC->arch ); >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/find_LTP_FIX.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/find_LTP_FIX.c >index 1314a281375bd69c7270ca25fdd91e88e38c0c76..62d4afb2507407267112ec43946aceeeedb25c23 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/find_LTP_FIX.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/find_LTP_FIX.c >@@ -32,214 +32,68 @@ POSSIBILITY OF SUCH DAMAGE. > #include "main_FIX.h" > #include "tuning_parameters.h" > >-/* Head room for correlations */ >-#define LTP_CORRS_HEAD_ROOM 2 >- >-void silk_fit_LTP( >- opus_int32 LTP_coefs_Q16[ LTP_ORDER ], >- opus_int16 LTP_coefs_Q14[ LTP_ORDER ] >-); >- > void silk_find_LTP_FIX( >- opus_int16 b_Q14[ MAX_NB_SUBFR * LTP_ORDER ], /* O LTP coefs */ >- opus_int32 WLTP[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* O Weight for LTP quantization */ >- opus_int *LTPredCodGain_Q7, /* O LTP coding gain */ >- const opus_int16 r_lpc[], /* I residual signal after LPC signal + state for first 10 ms */ >+ opus_int32 XXLTP_Q17[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* O Correlation matrix */ >+ opus_int32 xXLTP_Q17[ MAX_NB_SUBFR * LTP_ORDER ], /* O Correlation vector */ >+ const opus_int16 r_ptr[], /* I Residual signal after LPC */ > const opus_int lag[ MAX_NB_SUBFR ], /* I LTP lags */ >- const opus_int32 Wght_Q15[ MAX_NB_SUBFR ], /* I weights */ >- const opus_int subfr_length, /* I subframe length */ >- const opus_int nb_subfr, /* I number of subframes */ >- const opus_int mem_offset, /* I number of samples in LTP memory */ >- opus_int corr_rshifts[ MAX_NB_SUBFR ], /* O right shifts applied to correlations */ >+ const opus_int subfr_length, /* I Subframe length */ >+ const opus_int nb_subfr, /* I Number of subframes */ > int arch /* I Run-time architecture */ > ) > { >- opus_int i, k, lshift; >- const opus_int16 *r_ptr, *lag_ptr; >- opus_int16 *b_Q14_ptr; >- >- opus_int32 regu; >- opus_int32 *WLTP_ptr; >- opus_int32 b_Q16[ LTP_ORDER ], delta_b_Q14[ LTP_ORDER ], d_Q14[ MAX_NB_SUBFR ], nrg[ MAX_NB_SUBFR ], g_Q26; >- opus_int32 w[ MAX_NB_SUBFR ], WLTP_max, max_abs_d_Q14, max_w_bits; >- >- opus_int32 temp32, denom32; >- opus_int extra_shifts; >- opus_int rr_shifts, maxRshifts, maxRshifts_wxtra, LZs; >- opus_int32 LPC_res_nrg, LPC_LTP_res_nrg, div_Q16; >- opus_int32 Rr[ LTP_ORDER ], rr[ MAX_NB_SUBFR ]; >- opus_int32 wd, m_Q12; >- >- b_Q14_ptr = b_Q14; >- WLTP_ptr = WLTP; >- r_ptr = &r_lpc[ mem_offset ]; >+ opus_int i, k, extra_shifts; >+ opus_int xx_shifts, xX_shifts, XX_shifts; >+ const opus_int16 *lag_ptr; >+ opus_int32 *XXLTP_Q17_ptr, *xXLTP_Q17_ptr; >+ opus_int32 xx, nrg, temp; >+ >+ xXLTP_Q17_ptr = xXLTP_Q17; >+ XXLTP_Q17_ptr = XXLTP_Q17; > for( k = 0; k < nb_subfr; k++ ) { > lag_ptr = r_ptr - ( lag[ k ] + LTP_ORDER / 2 ); > >- silk_sum_sqr_shift( &rr[ k ], &rr_shifts, r_ptr, subfr_length ); /* rr[ k ] in Q( -rr_shifts ) */ >- >- /* Assure headroom */ >- LZs = silk_CLZ32( rr[k] ); >- if( LZs < LTP_CORRS_HEAD_ROOM ) { >- rr[ k ] = silk_RSHIFT_ROUND( rr[ k ], LTP_CORRS_HEAD_ROOM - LZs ); >- rr_shifts += ( LTP_CORRS_HEAD_ROOM - LZs ); >- } >- corr_rshifts[ k ] = rr_shifts; >- silk_corrMatrix_FIX( lag_ptr, subfr_length, LTP_ORDER, LTP_CORRS_HEAD_ROOM, WLTP_ptr, &corr_rshifts[ k ], arch ); /* WLTP_fix_ptr in Q( -corr_rshifts[ k ] ) */ >- >- /* The correlation vector always has lower max abs value than rr and/or RR so head room is assured */ >- silk_corrVector_FIX( lag_ptr, r_ptr, subfr_length, LTP_ORDER, Rr, corr_rshifts[ k ], arch ); /* Rr_fix_ptr in Q( -corr_rshifts[ k ] ) */ >- if( corr_rshifts[ k ] > rr_shifts ) { >- rr[ k ] = silk_RSHIFT( rr[ k ], corr_rshifts[ k ] - rr_shifts ); /* rr[ k ] in Q( -corr_rshifts[ k ] ) */ >+ silk_sum_sqr_shift( &xx, &xx_shifts, r_ptr, subfr_length + LTP_ORDER ); /* xx in Q( -xx_shifts ) */ >+ silk_corrMatrix_FIX( lag_ptr, subfr_length, LTP_ORDER, XXLTP_Q17_ptr, &nrg, &XX_shifts, arch ); /* XXLTP_Q17_ptr and nrg in Q( -XX_shifts ) */ >+ extra_shifts = xx_shifts - XX_shifts; >+ if( extra_shifts > 0 ) { >+ /* Shift XX */ >+ xX_shifts = xx_shifts; >+ for( i = 0; i < LTP_ORDER * LTP_ORDER; i++ ) { >+ XXLTP_Q17_ptr[ i ] = silk_RSHIFT32( XXLTP_Q17_ptr[ i ], extra_shifts ); /* Q( -xX_shifts ) */ >+ } >+ nrg = silk_RSHIFT32( nrg, extra_shifts ); /* Q( -xX_shifts ) */ >+ } else if( extra_shifts < 0 ) { >+ /* Shift xx */ >+ xX_shifts = XX_shifts; >+ xx = silk_RSHIFT32( xx, -extra_shifts ); /* Q( -xX_shifts ) */ >+ } else { >+ xX_shifts = xx_shifts; > } >- silk_assert( rr[ k ] >= 0 ); >- >- regu = 1; >- regu = silk_SMLAWB( regu, rr[ k ], SILK_FIX_CONST( LTP_DAMPING/3, 16 ) ); >- regu = silk_SMLAWB( regu, matrix_ptr( WLTP_ptr, 0, 0, LTP_ORDER ), SILK_FIX_CONST( LTP_DAMPING/3, 16 ) ); >- regu = silk_SMLAWB( regu, matrix_ptr( WLTP_ptr, LTP_ORDER-1, LTP_ORDER-1, LTP_ORDER ), SILK_FIX_CONST( LTP_DAMPING/3, 16 ) ); >- silk_regularize_correlations_FIX( WLTP_ptr, &rr[k], regu, LTP_ORDER ); >- >- silk_solve_LDL_FIX( WLTP_ptr, LTP_ORDER, Rr, b_Q16 ); /* WLTP_fix_ptr and Rr_fix_ptr both in Q(-corr_rshifts[k]) */ >- >- /* Limit and store in Q14 */ >- silk_fit_LTP( b_Q16, b_Q14_ptr ); >- >- /* Calculate residual energy */ >- nrg[ k ] = silk_residual_energy16_covar_FIX( b_Q14_ptr, WLTP_ptr, Rr, rr[ k ], LTP_ORDER, 14 ); /* nrg_fix in Q( -corr_rshifts[ k ] ) */ >- >- /* temp = Wght[ k ] / ( nrg[ k ] * Wght[ k ] + 0.01f * subfr_length ); */ >- extra_shifts = silk_min_int( corr_rshifts[ k ], LTP_CORRS_HEAD_ROOM ); >- denom32 = silk_LSHIFT_SAT32( silk_SMULWB( nrg[ k ], Wght_Q15[ k ] ), 1 + extra_shifts ) + /* Q( -corr_rshifts[ k ] + extra_shifts ) */ >- silk_RSHIFT( silk_SMULWB( (opus_int32)subfr_length, 655 ), corr_rshifts[ k ] - extra_shifts ); /* Q( -corr_rshifts[ k ] + extra_shifts ) */ >- denom32 = silk_max( denom32, 1 ); >- silk_assert( ((opus_int64)Wght_Q15[ k ] << 16 ) < silk_int32_MAX ); /* Wght always < 0.5 in Q0 */ >- temp32 = silk_DIV32( silk_LSHIFT( (opus_int32)Wght_Q15[ k ], 16 ), denom32 ); /* Q( 15 + 16 + corr_rshifts[k] - extra_shifts ) */ >- temp32 = silk_RSHIFT( temp32, 31 + corr_rshifts[ k ] - extra_shifts - 26 ); /* Q26 */ >+ silk_corrVector_FIX( lag_ptr, r_ptr, subfr_length, LTP_ORDER, xXLTP_Q17_ptr, xX_shifts, arch ); /* xXLTP_Q17_ptr in Q( -xX_shifts ) */ > >- /* Limit temp such that the below scaling never wraps around */ >- WLTP_max = 0; >+ /* At this point all correlations are in Q(-xX_shifts) */ >+ temp = silk_SMLAWB( 1, nrg, SILK_FIX_CONST( LTP_CORR_INV_MAX, 16 ) ); >+ temp = silk_max( temp, xx ); >+TIC(div) >+#if 0 > for( i = 0; i < LTP_ORDER * LTP_ORDER; i++ ) { >- WLTP_max = silk_max( WLTP_ptr[ i ], WLTP_max ); >+ XXLTP_Q17_ptr[ i ] = silk_DIV32_varQ( XXLTP_Q17_ptr[ i ], temp, 17 ); > } >- lshift = silk_CLZ32( WLTP_max ) - 1 - 3; /* keep 3 bits free for vq_nearest_neighbor_fix */ >- silk_assert( 26 - 18 + lshift >= 0 ); >- if( 26 - 18 + lshift < 31 ) { >- temp32 = silk_min_32( temp32, silk_LSHIFT( (opus_int32)1, 26 - 18 + lshift ) ); >- } >- >- silk_scale_vector32_Q26_lshift_18( WLTP_ptr, temp32, LTP_ORDER * LTP_ORDER ); /* WLTP_ptr in Q( 18 - corr_rshifts[ k ] ) */ >- >- w[ k ] = matrix_ptr( WLTP_ptr, LTP_ORDER/2, LTP_ORDER/2, LTP_ORDER ); /* w in Q( 18 - corr_rshifts[ k ] ) */ >- silk_assert( w[k] >= 0 ); >- >- r_ptr += subfr_length; >- b_Q14_ptr += LTP_ORDER; >- WLTP_ptr += LTP_ORDER * LTP_ORDER; >- } >- >- maxRshifts = 0; >- for( k = 0; k < nb_subfr; k++ ) { >- maxRshifts = silk_max_int( corr_rshifts[ k ], maxRshifts ); >- } >- >- /* Compute LTP coding gain */ >- if( LTPredCodGain_Q7 != NULL ) { >- LPC_LTP_res_nrg = 0; >- LPC_res_nrg = 0; >- silk_assert( LTP_CORRS_HEAD_ROOM >= 2 ); /* Check that no overflow will happen when adding */ >- for( k = 0; k < nb_subfr; k++ ) { >- LPC_res_nrg = silk_ADD32( LPC_res_nrg, silk_RSHIFT( silk_ADD32( silk_SMULWB( rr[ k ], Wght_Q15[ k ] ), 1 ), 1 + ( maxRshifts - corr_rshifts[ k ] ) ) ); /* Q( -maxRshifts ) */ >- LPC_LTP_res_nrg = silk_ADD32( LPC_LTP_res_nrg, silk_RSHIFT( silk_ADD32( silk_SMULWB( nrg[ k ], Wght_Q15[ k ] ), 1 ), 1 + ( maxRshifts - corr_rshifts[ k ] ) ) ); /* Q( -maxRshifts ) */ >- } >- LPC_LTP_res_nrg = silk_max( LPC_LTP_res_nrg, 1 ); /* avoid division by zero */ >- >- div_Q16 = silk_DIV32_varQ( LPC_res_nrg, LPC_LTP_res_nrg, 16 ); >- *LTPredCodGain_Q7 = ( opus_int )silk_SMULBB( 3, silk_lin2log( div_Q16 ) - ( 16 << 7 ) ); >- >- silk_assert( *LTPredCodGain_Q7 == ( opus_int )silk_SAT16( silk_MUL( 3, silk_lin2log( div_Q16 ) - ( 16 << 7 ) ) ) ); >- } >- >- /* smoothing */ >- /* d = sum( B, 1 ); */ >- b_Q14_ptr = b_Q14; >- for( k = 0; k < nb_subfr; k++ ) { >- d_Q14[ k ] = 0; > for( i = 0; i < LTP_ORDER; i++ ) { >- d_Q14[ k ] += b_Q14_ptr[ i ]; >- } >- b_Q14_ptr += LTP_ORDER; >- } >- >- /* m = ( w * d' ) / ( sum( w ) + 1e-3 ); */ >- >- /* Find maximum absolute value of d_Q14 and the bits used by w in Q0 */ >- max_abs_d_Q14 = 0; >- max_w_bits = 0; >- for( k = 0; k < nb_subfr; k++ ) { >- max_abs_d_Q14 = silk_max_32( max_abs_d_Q14, silk_abs( d_Q14[ k ] ) ); >- /* w[ k ] is in Q( 18 - corr_rshifts[ k ] ) */ >- /* Find bits needed in Q( 18 - maxRshifts ) */ >- max_w_bits = silk_max_32( max_w_bits, 32 - silk_CLZ32( w[ k ] ) + corr_rshifts[ k ] - maxRshifts ); >- } >- >- /* max_abs_d_Q14 = (5 << 15); worst case, i.e. LTP_ORDER * -silk_int16_MIN */ >- silk_assert( max_abs_d_Q14 <= ( 5 << 15 ) ); >- >- /* How many bits is needed for w*d' in Q( 18 - maxRshifts ) in the worst case, of all d_Q14's being equal to max_abs_d_Q14 */ >- extra_shifts = max_w_bits + 32 - silk_CLZ32( max_abs_d_Q14 ) - 14; >- >- /* Subtract what we got available; bits in output var plus maxRshifts */ >- extra_shifts -= ( 32 - 1 - 2 + maxRshifts ); /* Keep sign bit free as well as 2 bits for accumulation */ >- extra_shifts = silk_max_int( extra_shifts, 0 ); >- >- maxRshifts_wxtra = maxRshifts + extra_shifts; >- >- temp32 = silk_RSHIFT( 262, maxRshifts + extra_shifts ) + 1; /* 1e-3f in Q( 18 - (maxRshifts + extra_shifts) ) */ >- wd = 0; >- for( k = 0; k < nb_subfr; k++ ) { >- /* w has at least 2 bits of headroom so no overflow should happen */ >- temp32 = silk_ADD32( temp32, silk_RSHIFT( w[ k ], maxRshifts_wxtra - corr_rshifts[ k ] ) ); /* Q( 18 - maxRshifts_wxtra ) */ >- wd = silk_ADD32( wd, silk_LSHIFT( silk_SMULWW( silk_RSHIFT( w[ k ], maxRshifts_wxtra - corr_rshifts[ k ] ), d_Q14[ k ] ), 2 ) ); /* Q( 18 - maxRshifts_wxtra ) */ >- } >- m_Q12 = silk_DIV32_varQ( wd, temp32, 12 ); >- >- b_Q14_ptr = b_Q14; >- for( k = 0; k < nb_subfr; k++ ) { >- /* w_fix[ k ] from Q( 18 - corr_rshifts[ k ] ) to Q( 16 ) */ >- if( 2 - corr_rshifts[k] > 0 ) { >- temp32 = silk_RSHIFT( w[ k ], 2 - corr_rshifts[ k ] ); >- } else { >- temp32 = silk_LSHIFT_SAT32( w[ k ], corr_rshifts[ k ] - 2 ); >+ xXLTP_Q17_ptr[ i ] = silk_DIV32_varQ( xXLTP_Q17_ptr[ i ], temp, 17 ); > } >- >- g_Q26 = silk_MUL( >- silk_DIV32( >- SILK_FIX_CONST( LTP_SMOOTHING, 26 ), >- silk_RSHIFT( SILK_FIX_CONST( LTP_SMOOTHING, 26 ), 10 ) + temp32 ), /* Q10 */ >- silk_LSHIFT_SAT32( silk_SUB_SAT32( (opus_int32)m_Q12, silk_RSHIFT( d_Q14[ k ], 2 ) ), 4 ) ); /* Q16 */ >- >- temp32 = 0; >- for( i = 0; i < LTP_ORDER; i++ ) { >- delta_b_Q14[ i ] = silk_max_16( b_Q14_ptr[ i ], 1638 ); /* 1638_Q14 = 0.1_Q0 */ >- temp32 += delta_b_Q14[ i ]; /* Q14 */ >+#else >+ for( i = 0; i < LTP_ORDER * LTP_ORDER; i++ ) { >+ XXLTP_Q17_ptr[ i ] = (opus_int32)( silk_LSHIFT64( (opus_int64)XXLTP_Q17_ptr[ i ], 17 ) / temp ); > } >- temp32 = silk_DIV32( g_Q26, temp32 ); /* Q14 -> Q12 */ > for( i = 0; i < LTP_ORDER; i++ ) { >- b_Q14_ptr[ i ] = silk_LIMIT_32( (opus_int32)b_Q14_ptr[ i ] + silk_SMULWB( silk_LSHIFT_SAT32( temp32, 4 ), delta_b_Q14[ i ] ), -16000, 28000 ); >+ xXLTP_Q17_ptr[ i ] = (opus_int32)( silk_LSHIFT64( (opus_int64)xXLTP_Q17_ptr[ i ], 17 ) / temp ); > } >- b_Q14_ptr += LTP_ORDER; >- } >-} >- >-void silk_fit_LTP( >- opus_int32 LTP_coefs_Q16[ LTP_ORDER ], >- opus_int16 LTP_coefs_Q14[ LTP_ORDER ] >-) >-{ >- opus_int i; >- >- for( i = 0; i < LTP_ORDER; i++ ) { >- LTP_coefs_Q14[ i ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( LTP_coefs_Q16[ i ], 2 ) ); >+#endif >+TOC(div) >+ r_ptr += subfr_length; >+ XXLTP_Q17_ptr += LTP_ORDER * LTP_ORDER; >+ xXLTP_Q17_ptr += LTP_ORDER; > } > } >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/find_pitch_lags_FIX.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/find_pitch_lags_FIX.c >index b8440a8247a31ce4cf768f6f148dd4a9e75f3533..9303e9db1f338ccc1771e90cb6b53c05e60547db 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/find_pitch_lags_FIX.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/find_pitch_lags_FIX.c >@@ -44,7 +44,7 @@ void silk_find_pitch_lags_FIX( > { > opus_int buf_len, i, scale; > opus_int32 thrhld_Q13, res_nrg; >- const opus_int16 *x_buf, *x_buf_ptr; >+ const opus_int16 *x_ptr; > VARDECL( opus_int16, Wsig ); > opus_int16 *Wsig_ptr; > opus_int32 auto_corr[ MAX_FIND_PITCH_LPC_ORDER + 1 ]; >@@ -61,8 +61,6 @@ void silk_find_pitch_lags_FIX( > /* Safety check */ > silk_assert( buf_len >= psEnc->sCmn.pitch_LPC_win_length ); > >- x_buf = x - psEnc->sCmn.ltp_mem_length; >- > /*************************************/ > /* Estimate LPC AR coefficients */ > /*************************************/ >@@ -72,19 +70,19 @@ void silk_find_pitch_lags_FIX( > ALLOC( Wsig, psEnc->sCmn.pitch_LPC_win_length, opus_int16 ); > > /* First LA_LTP samples */ >- x_buf_ptr = x_buf + buf_len - psEnc->sCmn.pitch_LPC_win_length; >+ x_ptr = x + buf_len - psEnc->sCmn.pitch_LPC_win_length; > Wsig_ptr = Wsig; >- silk_apply_sine_window( Wsig_ptr, x_buf_ptr, 1, psEnc->sCmn.la_pitch ); >+ silk_apply_sine_window( Wsig_ptr, x_ptr, 1, psEnc->sCmn.la_pitch ); > > /* Middle un - windowed samples */ > Wsig_ptr += psEnc->sCmn.la_pitch; >- x_buf_ptr += psEnc->sCmn.la_pitch; >- silk_memcpy( Wsig_ptr, x_buf_ptr, ( psEnc->sCmn.pitch_LPC_win_length - silk_LSHIFT( psEnc->sCmn.la_pitch, 1 ) ) * sizeof( opus_int16 ) ); >+ x_ptr += psEnc->sCmn.la_pitch; >+ silk_memcpy( Wsig_ptr, x_ptr, ( psEnc->sCmn.pitch_LPC_win_length - silk_LSHIFT( psEnc->sCmn.la_pitch, 1 ) ) * sizeof( opus_int16 ) ); > > /* Last LA_LTP samples */ > Wsig_ptr += psEnc->sCmn.pitch_LPC_win_length - silk_LSHIFT( psEnc->sCmn.la_pitch, 1 ); >- x_buf_ptr += psEnc->sCmn.pitch_LPC_win_length - silk_LSHIFT( psEnc->sCmn.la_pitch, 1 ); >- silk_apply_sine_window( Wsig_ptr, x_buf_ptr, 2, psEnc->sCmn.la_pitch ); >+ x_ptr += psEnc->sCmn.pitch_LPC_win_length - silk_LSHIFT( psEnc->sCmn.la_pitch, 1 ); >+ silk_apply_sine_window( Wsig_ptr, x_ptr, 2, psEnc->sCmn.la_pitch ); > > /* Calculate autocorrelation sequence */ > silk_autocorr( auto_corr, &scale, Wsig, psEnc->sCmn.pitch_LPC_win_length, psEnc->sCmn.pitchEstimationLPCOrder + 1, arch ); >@@ -112,7 +110,7 @@ void silk_find_pitch_lags_FIX( > /*****************************************/ > /* LPC analysis filtering */ > /*****************************************/ >- silk_LPC_analysis_filter( res, x_buf, A_Q12, buf_len, psEnc->sCmn.pitchEstimationLPCOrder, psEnc->sCmn.arch ); >+ silk_LPC_analysis_filter( res, x, A_Q12, buf_len, psEnc->sCmn.pitchEstimationLPCOrder, psEnc->sCmn.arch ); > > if( psEnc->sCmn.indices.signalType != TYPE_NO_VOICE_ACTIVITY && psEnc->sCmn.first_frame_after_reset == 0 ) { > /* Threshold for pitch estimator */ >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/find_pred_coefs_FIX.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/find_pred_coefs_FIX.c >index d308e9cf5fe609e17b06b4d1339193134cccf3f8..24c6aab3a77c95e1c90466e3cfb131e52b81e104 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/find_pred_coefs_FIX.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/find_pred_coefs_FIX.c >@@ -41,13 +41,12 @@ void silk_find_pred_coefs_FIX( > ) > { > opus_int i; >- opus_int32 invGains_Q16[ MAX_NB_SUBFR ], local_gains[ MAX_NB_SUBFR ], Wght_Q15[ MAX_NB_SUBFR ]; >+ opus_int32 invGains_Q16[ MAX_NB_SUBFR ], local_gains[ MAX_NB_SUBFR ]; > opus_int16 NLSF_Q15[ MAX_LPC_ORDER ]; > const opus_int16 *x_ptr; > opus_int16 *x_pre_ptr; > VARDECL( opus_int16, LPC_in_pre ); >- opus_int32 tmp, min_gain_Q16, minInvGain_Q30; >- opus_int LTP_corrs_rshift[ MAX_NB_SUBFR ]; >+ opus_int32 min_gain_Q16, minInvGain_Q30; > SAVE_STACK; > > /* weighting for weighted least squares */ >@@ -61,13 +60,11 @@ void silk_find_pred_coefs_FIX( > /* Invert and normalize gains, and ensure that maximum invGains_Q16 is within range of a 16 bit int */ > invGains_Q16[ i ] = silk_DIV32_varQ( min_gain_Q16, psEncCtrl->Gains_Q16[ i ], 16 - 2 ); > >- /* Ensure Wght_Q15 a minimum value 1 */ >- invGains_Q16[ i ] = silk_max( invGains_Q16[ i ], 363 ); >+ /* Limit inverse */ >+ invGains_Q16[ i ] = silk_max( invGains_Q16[ i ], 100 ); > > /* Square the inverted gains */ > silk_assert( invGains_Q16[ i ] == silk_SAT16( invGains_Q16[ i ] ) ); >- tmp = silk_SMULWB( invGains_Q16[ i ], invGains_Q16[ i ] ); >- Wght_Q15[ i ] = silk_RSHIFT( tmp, 1 ); > > /* Invert the inverted and normalized gains */ > local_gains[ i ] = silk_DIV32( ( (opus_int32)1 << 16 ), invGains_Q16[ i ] ); >@@ -77,24 +74,24 @@ void silk_find_pred_coefs_FIX( > psEnc->sCmn.nb_subfr * psEnc->sCmn.predictLPCOrder > + psEnc->sCmn.frame_length, opus_int16 ); > if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { >- VARDECL( opus_int32, WLTP ); >+ VARDECL( opus_int32, xXLTP_Q17 ); >+ VARDECL( opus_int32, XXLTP_Q17 ); > > /**********/ > /* VOICED */ > /**********/ > silk_assert( psEnc->sCmn.ltp_mem_length - psEnc->sCmn.predictLPCOrder >= psEncCtrl->pitchL[ 0 ] + LTP_ORDER / 2 ); > >- ALLOC( WLTP, psEnc->sCmn.nb_subfr * LTP_ORDER * LTP_ORDER, opus_int32 ); >+ ALLOC( xXLTP_Q17, psEnc->sCmn.nb_subfr * LTP_ORDER, opus_int32 ); >+ ALLOC( XXLTP_Q17, psEnc->sCmn.nb_subfr * LTP_ORDER * LTP_ORDER, opus_int32 ); > > /* LTP analysis */ >- silk_find_LTP_FIX( psEncCtrl->LTPCoef_Q14, WLTP, &psEncCtrl->LTPredCodGain_Q7, >- res_pitch, psEncCtrl->pitchL, Wght_Q15, psEnc->sCmn.subfr_length, >- psEnc->sCmn.nb_subfr, psEnc->sCmn.ltp_mem_length, LTP_corrs_rshift, psEnc->sCmn.arch ); >+ silk_find_LTP_FIX( XXLTP_Q17, xXLTP_Q17, res_pitch, >+ psEncCtrl->pitchL, psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr, psEnc->sCmn.arch ); > > /* Quantize LTP gain parameters */ > silk_quant_LTP_gains( psEncCtrl->LTPCoef_Q14, psEnc->sCmn.indices.LTPIndex, &psEnc->sCmn.indices.PERIndex, >- &psEnc->sCmn.sum_log_gain_Q7, WLTP, psEnc->sCmn.mu_LTP_Q9, psEnc->sCmn.LTPQuantLowComplexity, psEnc->sCmn.nb_subfr, >- psEnc->sCmn.arch); >+ &psEnc->sCmn.sum_log_gain_Q7, &psEncCtrl->LTPredCodGain_Q7, XXLTP_Q17, xXLTP_Q17, psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr, psEnc->sCmn.arch ); > > /* Control LTP scaling */ > silk_LTP_scale_ctrl_FIX( psEnc, psEncCtrl, condCoding ); >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/k2a_FIX.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/k2a_FIX.c >index 5fee599bcb74305a1d45c41e8795a0ee3f9cb5d9..549f6eadaa29de85bfd4c267c79259c6c114a9d9 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/k2a_FIX.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/k2a_FIX.c >@@ -39,14 +39,15 @@ void silk_k2a( > ) > { > opus_int k, n; >- opus_int32 Atmp[ SILK_MAX_ORDER_LPC ]; >+ opus_int32 rc, tmp1, tmp2; > > for( k = 0; k < order; k++ ) { >- for( n = 0; n < k; n++ ) { >- Atmp[ n ] = A_Q24[ n ]; >- } >- for( n = 0; n < k; n++ ) { >- A_Q24[ n ] = silk_SMLAWB( A_Q24[ n ], silk_LSHIFT( Atmp[ k - n - 1 ], 1 ), rc_Q15[ k ] ); >+ rc = rc_Q15[ k ]; >+ for( n = 0; n < (k + 1) >> 1; n++ ) { >+ tmp1 = A_Q24[ n ]; >+ tmp2 = A_Q24[ k - n - 1 ]; >+ A_Q24[ n ] = silk_SMLAWB( tmp1, silk_LSHIFT( tmp2, 1 ), rc ); >+ A_Q24[ k - n - 1 ] = silk_SMLAWB( tmp2, silk_LSHIFT( tmp1, 1 ), rc ); > } > A_Q24[ k ] = -silk_LSHIFT( (opus_int32)rc_Q15[ k ], 9 ); > } >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/k2a_Q16_FIX.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/k2a_Q16_FIX.c >index 3b039875446a13886a9b22ea1e2b0f54c2062a05..1595aa62126625750705b5d47b42bdc586f05942 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/k2a_Q16_FIX.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/k2a_Q16_FIX.c >@@ -39,15 +39,16 @@ void silk_k2a_Q16( > ) > { > opus_int k, n; >- opus_int32 Atmp[ SILK_MAX_ORDER_LPC ]; >+ opus_int32 rc, tmp1, tmp2; > > for( k = 0; k < order; k++ ) { >- for( n = 0; n < k; n++ ) { >- Atmp[ n ] = A_Q24[ n ]; >+ rc = rc_Q16[ k ]; >+ for( n = 0; n < (k + 1) >> 1; n++ ) { >+ tmp1 = A_Q24[ n ]; >+ tmp2 = A_Q24[ k - n - 1 ]; >+ A_Q24[ n ] = silk_SMLAWW( tmp1, tmp2, rc ); >+ A_Q24[ k - n - 1 ] = silk_SMLAWW( tmp2, tmp1, rc ); > } >- for( n = 0; n < k; n++ ) { >- A_Q24[ n ] = silk_SMLAWW( A_Q24[ n ], Atmp[ k - n - 1 ], rc_Q16[ k ] ); >- } >- A_Q24[ k ] = -silk_LSHIFT( rc_Q16[ k ], 8 ); >+ A_Q24[ k ] = -silk_LSHIFT( rc, 8 ); > } > } >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/main_FIX.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/main_FIX.h >index 375b5eb32ee6c6aec6247bf680b4e9332c82d34b..6d2112e511d0aef44582d52d6502dcb5c94ed068 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/main_FIX.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/main_FIX.h >@@ -36,6 +36,11 @@ POSSIBILITY OF SUCH DAMAGE. > #include "debug.h" > #include "entenc.h" > >+#if ((defined(OPUS_ARM_ASM) && defined(FIXED_POINT)) \ >+ || defined(OPUS_ARM_MAY_HAVE_NEON_INTR)) >+#include "fixed/arm/warped_autocorrelation_FIX_arm.h" >+#endif >+ > #ifndef FORCE_CPP_BUILD > #ifdef __cplusplus > extern "C" >@@ -47,6 +52,9 @@ extern "C" > #define silk_encode_do_VAD_Fxx silk_encode_do_VAD_FIX > #define silk_encode_frame_Fxx silk_encode_frame_FIX > >+#define QC 10 >+#define QS 13 >+ > /*********************/ > /* Encoder Functions */ > /*********************/ >@@ -58,7 +66,8 @@ void silk_HP_variable_cutoff( > > /* Encoder main function */ > void silk_encode_do_VAD_FIX( >- silk_encoder_state_FIX *psEnc /* I/O Pointer to Silk FIX encoder state */ >+ silk_encoder_state_FIX *psEnc, /* I/O Pointer to Silk FIX encoder state */ >+ opus_int activity /* I Decision of Opus voice activity detector */ > ); > > /* Encoder main function */ >@@ -81,33 +90,11 @@ opus_int silk_init_encoder( > opus_int silk_control_encoder( > silk_encoder_state_Fxx *psEnc, /* I/O Pointer to Silk encoder state */ > silk_EncControlStruct *encControl, /* I Control structure */ >- const opus_int32 TargetRate_bps, /* I Target max bitrate (bps) */ > const opus_int allow_bw_switch, /* I Flag to allow switching audio bandwidth */ > const opus_int channelNb, /* I Channel number */ > const opus_int force_fs_kHz > ); > >-/****************/ >-/* Prefiltering */ >-/****************/ >-void silk_prefilter_FIX( >- silk_encoder_state_FIX *psEnc, /* I/O Encoder state */ >- const silk_encoder_control_FIX *psEncCtrl, /* I Encoder control */ >- opus_int32 xw_Q10[], /* O Weighted signal */ >- const opus_int16 x[] /* I Speech signal */ >-); >- >-void silk_warped_LPC_analysis_filter_FIX_c( >- opus_int32 state[], /* I/O State [order + 1] */ >- opus_int32 res_Q2[], /* O Residual signal [length] */ >- const opus_int16 coef_Q13[], /* I Coefficients [order] */ >- const opus_int16 input[], /* I Input signal [length] */ >- const opus_int16 lambda_Q16, /* I Warping factor */ >- const opus_int length, /* I Length of input signal */ >- const opus_int order /* I Filter order (even) */ >-); >- >- > /**************************/ > /* Noise shaping analysis */ > /**************************/ >@@ -121,7 +108,7 @@ void silk_noise_shape_analysis_FIX( > ); > > /* Autocorrelations for a warped frequency axis */ >-void silk_warped_autocorrelation_FIX( >+void silk_warped_autocorrelation_FIX_c( > opus_int32 *corr, /* O Result [order + 1] */ > opus_int *scale, /* O Scaling of the correlation vector */ > const opus_int16 *input, /* I Input data to correlate */ >@@ -130,6 +117,11 @@ void silk_warped_autocorrelation_FIX( > const opus_int order /* I Correlation order (even) */ > ); > >+#if !defined(OVERRIDE_silk_warped_autocorrelation_FIX) >+#define silk_warped_autocorrelation_FIX(corr, scale, input, warping_Q16, length, order, arch) \ >+ ((void)(arch), silk_warped_autocorrelation_FIX_c(corr, scale, input, warping_Q16, length, order)) >+#endif >+ > /* Calculation of LTP state scaling */ > void silk_LTP_scale_ctrl_FIX( > silk_encoder_state_FIX *psEnc, /* I/O encoder state */ >@@ -168,16 +160,12 @@ void silk_find_LPC_FIX( > > /* LTP analysis */ > void silk_find_LTP_FIX( >- opus_int16 b_Q14[ MAX_NB_SUBFR * LTP_ORDER ], /* O LTP coefs */ >- opus_int32 WLTP[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* O Weight for LTP quantization */ >- opus_int *LTPredCodGain_Q7, /* O LTP coding gain */ >- const opus_int16 r_lpc[], /* I residual signal after LPC signal + state for first 10 ms */ >+ opus_int32 XXLTP_Q17[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* O Correlation matrix */ >+ opus_int32 xXLTP_Q17[ MAX_NB_SUBFR * LTP_ORDER ], /* O Correlation vector */ >+ const opus_int16 r_lpc[], /* I Residual signal after LPC */ > const opus_int lag[ MAX_NB_SUBFR ], /* I LTP lags */ >- const opus_int32 Wght_Q15[ MAX_NB_SUBFR ], /* I weights */ >- const opus_int subfr_length, /* I subframe length */ >- const opus_int nb_subfr, /* I number of subframes */ >- const opus_int mem_offset, /* I number of samples in LTP memory */ >- opus_int corr_rshifts[ MAX_NB_SUBFR ], /* O right shifts applied to correlations */ >+ const opus_int subfr_length, /* I Subframe length */ >+ const opus_int nb_subfr, /* I Number of subframes */ > int arch /* I Run-time architecture */ > ); > >@@ -231,9 +219,9 @@ void silk_corrMatrix_FIX( > const opus_int16 *x, /* I x vector [L + order - 1] used to form data matrix X */ > const opus_int L, /* I Length of vectors */ > const opus_int order, /* I Max lag for correlation */ >- const opus_int head_room, /* I Desired headroom */ > opus_int32 *XX, /* O Pointer to X'*X correlation matrix [ order x order ] */ >- opus_int *rshifts, /* I/O Right shifts of correlations */ >+ opus_int32 *nrg, /* O Energy of x vector */ >+ opus_int *rshifts, /* O Right shifts of correlations */ > int arch /* I Run-time architecture */ > ); > >@@ -248,22 +236,6 @@ void silk_corrVector_FIX( > int arch /* I Run-time architecture */ > ); > >-/* Add noise to matrix diagonal */ >-void silk_regularize_correlations_FIX( >- opus_int32 *XX, /* I/O Correlation matrices */ >- opus_int32 *xx, /* I/O Correlation values */ >- opus_int32 noise, /* I Noise to add */ >- opus_int D /* I Dimension of XX */ >-); >- >-/* Solves Ax = b, assuming A is symmetric */ >-void silk_solve_LDL_FIX( >- opus_int32 *A, /* I Pointer to symetric square matrix A */ >- opus_int M, /* I Size of matrix */ >- const opus_int32 *b, /* I Pointer to b vector */ >- opus_int32 *x_Q16 /* O Pointer to x solution vector */ >-); >- > #ifndef FORCE_CPP_BUILD > #ifdef __cplusplus > } >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/mips/noise_shape_analysis_FIX_mipsr1.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/mips/noise_shape_analysis_FIX_mipsr1.h >index c30481e43751dc00fea02593cf34302ed639779f..3999b5bd09dd8a9464ed22780d54578f3dbcdef8 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/mips/noise_shape_analysis_FIX_mipsr1.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/mips/noise_shape_analysis_FIX_mipsr1.h >@@ -169,7 +169,7 @@ void silk_noise_shape_analysis_FIX( > > if( psEnc->sCmn.warping_Q16 > 0 ) { > /* Calculate warped auto correlation */ >- silk_warped_autocorrelation_FIX( auto_corr, &scale, x_windowed, warping_Q16, psEnc->sCmn.shapeWinLength, psEnc->sCmn.shapingLPCOrder ); >+ silk_warped_autocorrelation_FIX( auto_corr, &scale, x_windowed, warping_Q16, psEnc->sCmn.shapeWinLength, psEnc->sCmn.shapingLPCOrder, arch ); > } else { > /* Calculate regular auto correlation */ > silk_autocorr( auto_corr, &scale, x_windowed, psEnc->sCmn.shapeWinLength, psEnc->sCmn.shapingLPCOrder + 1, arch ); >@@ -224,8 +224,8 @@ void silk_noise_shape_analysis_FIX( > silk_bwexpander_32( AR1_Q24, psEnc->sCmn.shapingLPCOrder, BWExp1_Q16 ); > > /* Ratio of prediction gains, in energy domain */ >- pre_nrg_Q30 = silk_LPC_inverse_pred_gain_Q24( AR2_Q24, psEnc->sCmn.shapingLPCOrder ); >- nrg = silk_LPC_inverse_pred_gain_Q24( AR1_Q24, psEnc->sCmn.shapingLPCOrder ); >+ pre_nrg_Q30 = silk_LPC_inverse_pred_gain_Q24( AR2_Q24, psEnc->sCmn.shapingLPCOrder, arch ); >+ nrg = silk_LPC_inverse_pred_gain_Q24( AR1_Q24, psEnc->sCmn.shapingLPCOrder, arch ); > > /*psEncCtrl->GainsPre[ k ] = 1.0f - 0.7f * ( 1.0f - pre_nrg / nrg ) = 0.3f + 0.7f * pre_nrg / nrg;*/ > pre_nrg_Q30 = silk_LSHIFT32( silk_SMULWB( pre_nrg_Q30, SILK_FIX_CONST( 0.7, 15 ) ), 1 ); >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/mips/warped_autocorrelation_FIX_mipsr1.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/mips/warped_autocorrelation_FIX_mipsr1.h >index e803ef0fceb04b3ca15264cb3a5edd8e971887b9..fcbd96c88d98aaa05b3e4a5c956e2eab09b6bc45 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/mips/warped_autocorrelation_FIX_mipsr1.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/mips/warped_autocorrelation_FIX_mipsr1.h >@@ -48,7 +48,8 @@ void silk_warped_autocorrelation_FIX( > const opus_int16 *input, /* I Input data to correlate */ > const opus_int warping_Q16, /* I Warping coefficient */ > const opus_int length, /* I Length of input */ >- const opus_int order /* I Correlation order (even) */ >+ const opus_int order, /* I Correlation order (even) */ >+ int arch /* I Run-time architecture */ > ) > { > opus_int n, i, lsh; >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/noise_shape_analysis_FIX.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/noise_shape_analysis_FIX.c >index 22a89f75aec0fc8d624409df861cbb6c2ca38595..85fea0bf09600594628001d7410712c4ee8c2612 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/noise_shape_analysis_FIX.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/noise_shape_analysis_FIX.c >@@ -57,88 +57,79 @@ static OPUS_INLINE opus_int32 warped_gain( /* gain in Q16*/ > /* Convert warped filter coefficients to monic pseudo-warped coefficients and limit maximum */ > /* amplitude of monic warped coefficients by using bandwidth expansion on the true coefficients */ > static OPUS_INLINE void limit_warped_coefs( >- opus_int32 *coefs_syn_Q24, >- opus_int32 *coefs_ana_Q24, >+ opus_int32 *coefs_Q24, > opus_int lambda_Q16, > opus_int32 limit_Q24, > opus_int order > ) { > opus_int i, iter, ind = 0; >- opus_int32 tmp, maxabs_Q24, chirp_Q16, gain_syn_Q16, gain_ana_Q16; >+ opus_int32 tmp, maxabs_Q24, chirp_Q16, gain_Q16; > opus_int32 nom_Q16, den_Q24; >+ opus_int32 limit_Q20, maxabs_Q20; > > /* Convert to monic coefficients */ > lambda_Q16 = -lambda_Q16; > for( i = order - 1; i > 0; i-- ) { >- coefs_syn_Q24[ i - 1 ] = silk_SMLAWB( coefs_syn_Q24[ i - 1 ], coefs_syn_Q24[ i ], lambda_Q16 ); >- coefs_ana_Q24[ i - 1 ] = silk_SMLAWB( coefs_ana_Q24[ i - 1 ], coefs_ana_Q24[ i ], lambda_Q16 ); >+ coefs_Q24[ i - 1 ] = silk_SMLAWB( coefs_Q24[ i - 1 ], coefs_Q24[ i ], lambda_Q16 ); > } > lambda_Q16 = -lambda_Q16; >- nom_Q16 = silk_SMLAWB( SILK_FIX_CONST( 1.0, 16 ), -(opus_int32)lambda_Q16, lambda_Q16 ); >- den_Q24 = silk_SMLAWB( SILK_FIX_CONST( 1.0, 24 ), coefs_syn_Q24[ 0 ], lambda_Q16 ); >- gain_syn_Q16 = silk_DIV32_varQ( nom_Q16, den_Q24, 24 ); >- den_Q24 = silk_SMLAWB( SILK_FIX_CONST( 1.0, 24 ), coefs_ana_Q24[ 0 ], lambda_Q16 ); >- gain_ana_Q16 = silk_DIV32_varQ( nom_Q16, den_Q24, 24 ); >+ nom_Q16 = silk_SMLAWB( SILK_FIX_CONST( 1.0, 16 ), -(opus_int32)lambda_Q16, lambda_Q16 ); >+ den_Q24 = silk_SMLAWB( SILK_FIX_CONST( 1.0, 24 ), coefs_Q24[ 0 ], lambda_Q16 ); >+ gain_Q16 = silk_DIV32_varQ( nom_Q16, den_Q24, 24 ); > for( i = 0; i < order; i++ ) { >- coefs_syn_Q24[ i ] = silk_SMULWW( gain_syn_Q16, coefs_syn_Q24[ i ] ); >- coefs_ana_Q24[ i ] = silk_SMULWW( gain_ana_Q16, coefs_ana_Q24[ i ] ); >+ coefs_Q24[ i ] = silk_SMULWW( gain_Q16, coefs_Q24[ i ] ); > } >- >+ limit_Q20 = silk_RSHIFT(limit_Q24, 4); > for( iter = 0; iter < 10; iter++ ) { > /* Find maximum absolute value */ > maxabs_Q24 = -1; > for( i = 0; i < order; i++ ) { >- tmp = silk_max( silk_abs_int32( coefs_syn_Q24[ i ] ), silk_abs_int32( coefs_ana_Q24[ i ] ) ); >+ tmp = silk_abs_int32( coefs_Q24[ i ] ); > if( tmp > maxabs_Q24 ) { > maxabs_Q24 = tmp; > ind = i; > } > } >- if( maxabs_Q24 <= limit_Q24 ) { >+ /* Use Q20 to avoid any overflow when multiplying by (ind + 1) later. */ >+ maxabs_Q20 = silk_RSHIFT(maxabs_Q24, 4); >+ if( maxabs_Q20 <= limit_Q20 ) { > /* Coefficients are within range - done */ > return; > } > > /* Convert back to true warped coefficients */ > for( i = 1; i < order; i++ ) { >- coefs_syn_Q24[ i - 1 ] = silk_SMLAWB( coefs_syn_Q24[ i - 1 ], coefs_syn_Q24[ i ], lambda_Q16 ); >- coefs_ana_Q24[ i - 1 ] = silk_SMLAWB( coefs_ana_Q24[ i - 1 ], coefs_ana_Q24[ i ], lambda_Q16 ); >+ coefs_Q24[ i - 1 ] = silk_SMLAWB( coefs_Q24[ i - 1 ], coefs_Q24[ i ], lambda_Q16 ); > } >- gain_syn_Q16 = silk_INVERSE32_varQ( gain_syn_Q16, 32 ); >- gain_ana_Q16 = silk_INVERSE32_varQ( gain_ana_Q16, 32 ); >+ gain_Q16 = silk_INVERSE32_varQ( gain_Q16, 32 ); > for( i = 0; i < order; i++ ) { >- coefs_syn_Q24[ i ] = silk_SMULWW( gain_syn_Q16, coefs_syn_Q24[ i ] ); >- coefs_ana_Q24[ i ] = silk_SMULWW( gain_ana_Q16, coefs_ana_Q24[ i ] ); >+ coefs_Q24[ i ] = silk_SMULWW( gain_Q16, coefs_Q24[ i ] ); > } > > /* Apply bandwidth expansion */ > chirp_Q16 = SILK_FIX_CONST( 0.99, 16 ) - silk_DIV32_varQ( >- silk_SMULWB( maxabs_Q24 - limit_Q24, silk_SMLABB( SILK_FIX_CONST( 0.8, 10 ), SILK_FIX_CONST( 0.1, 10 ), iter ) ), >- silk_MUL( maxabs_Q24, ind + 1 ), 22 ); >- silk_bwexpander_32( coefs_syn_Q24, order, chirp_Q16 ); >- silk_bwexpander_32( coefs_ana_Q24, order, chirp_Q16 ); >+ silk_SMULWB( maxabs_Q20 - limit_Q20, silk_SMLABB( SILK_FIX_CONST( 0.8, 10 ), SILK_FIX_CONST( 0.1, 10 ), iter ) ), >+ silk_MUL( maxabs_Q20, ind + 1 ), 22 ); >+ silk_bwexpander_32( coefs_Q24, order, chirp_Q16 ); > > /* Convert to monic warped coefficients */ > lambda_Q16 = -lambda_Q16; > for( i = order - 1; i > 0; i-- ) { >- coefs_syn_Q24[ i - 1 ] = silk_SMLAWB( coefs_syn_Q24[ i - 1 ], coefs_syn_Q24[ i ], lambda_Q16 ); >- coefs_ana_Q24[ i - 1 ] = silk_SMLAWB( coefs_ana_Q24[ i - 1 ], coefs_ana_Q24[ i ], lambda_Q16 ); >+ coefs_Q24[ i - 1 ] = silk_SMLAWB( coefs_Q24[ i - 1 ], coefs_Q24[ i ], lambda_Q16 ); > } > lambda_Q16 = -lambda_Q16; > nom_Q16 = silk_SMLAWB( SILK_FIX_CONST( 1.0, 16 ), -(opus_int32)lambda_Q16, lambda_Q16 ); >- den_Q24 = silk_SMLAWB( SILK_FIX_CONST( 1.0, 24 ), coefs_syn_Q24[ 0 ], lambda_Q16 ); >- gain_syn_Q16 = silk_DIV32_varQ( nom_Q16, den_Q24, 24 ); >- den_Q24 = silk_SMLAWB( SILK_FIX_CONST( 1.0, 24 ), coefs_ana_Q24[ 0 ], lambda_Q16 ); >- gain_ana_Q16 = silk_DIV32_varQ( nom_Q16, den_Q24, 24 ); >+ den_Q24 = silk_SMLAWB( SILK_FIX_CONST( 1.0, 24 ), coefs_Q24[ 0 ], lambda_Q16 ); >+ gain_Q16 = silk_DIV32_varQ( nom_Q16, den_Q24, 24 ); > for( i = 0; i < order; i++ ) { >- coefs_syn_Q24[ i ] = silk_SMULWW( gain_syn_Q16, coefs_syn_Q24[ i ] ); >- coefs_ana_Q24[ i ] = silk_SMULWW( gain_ana_Q16, coefs_ana_Q24[ i ] ); >+ coefs_Q24[ i ] = silk_SMULWW( gain_Q16, coefs_Q24[ i ] ); > } > } > silk_assert( 0 ); > } > >-#if defined(MIPSr1_ASM) >+/* Disable MIPS version until it's updated. */ >+#if 0 && defined(MIPSr1_ASM) > #include "mips/noise_shape_analysis_FIX_mipsr1.h" > #endif > >@@ -155,14 +146,13 @@ void silk_noise_shape_analysis_FIX( > ) > { > silk_shape_state_FIX *psShapeSt = &psEnc->sShape; >- opus_int k, i, nSamples, Qnrg, b_Q14, warping_Q16, scale = 0; >- opus_int32 SNR_adj_dB_Q7, HarmBoost_Q16, HarmShapeGain_Q16, Tilt_Q16, tmp32; >- opus_int32 nrg, pre_nrg_Q30, log_energy_Q7, log_energy_prev_Q7, energy_variation_Q7; >- opus_int32 delta_Q16, BWExp1_Q16, BWExp2_Q16, gain_mult_Q16, gain_add_Q16, strength_Q16, b_Q8; >+ opus_int k, i, nSamples, nSegs, Qnrg, b_Q14, warping_Q16, scale = 0; >+ opus_int32 SNR_adj_dB_Q7, HarmShapeGain_Q16, Tilt_Q16, tmp32; >+ opus_int32 nrg, log_energy_Q7, log_energy_prev_Q7, energy_variation_Q7; >+ opus_int32 BWExp_Q16, gain_mult_Q16, gain_add_Q16, strength_Q16, b_Q8; > opus_int32 auto_corr[ MAX_SHAPE_LPC_ORDER + 1 ]; > opus_int32 refl_coef_Q16[ MAX_SHAPE_LPC_ORDER ]; >- opus_int32 AR1_Q24[ MAX_SHAPE_LPC_ORDER ]; >- opus_int32 AR2_Q24[ MAX_SHAPE_LPC_ORDER ]; >+ opus_int32 AR_Q24[ MAX_SHAPE_LPC_ORDER ]; > VARDECL( opus_int16, x_windowed ); > const opus_int16 *x_ptr, *pitch_res_ptr; > SAVE_STACK; >@@ -209,14 +199,14 @@ void silk_noise_shape_analysis_FIX( > if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { > /* Initially set to 0; may be overruled in process_gains(..) */ > psEnc->sCmn.indices.quantOffsetType = 0; >- psEncCtrl->sparseness_Q8 = 0; > } else { > /* Sparseness measure, based on relative fluctuations of energy per 2 milliseconds */ > nSamples = silk_LSHIFT( psEnc->sCmn.fs_kHz, 1 ); > energy_variation_Q7 = 0; > log_energy_prev_Q7 = 0; > pitch_res_ptr = pitch_res; >- for( k = 0; k < silk_SMULBB( SUB_FRAME_LENGTH_MS, psEnc->sCmn.nb_subfr ) / 2; k++ ) { >+ nSegs = silk_SMULBB( SUB_FRAME_LENGTH_MS, psEnc->sCmn.nb_subfr ) / 2; >+ for( k = 0; k < nSegs; k++ ) { > silk_sum_sqr_shift( &nrg, &scale, pitch_res_ptr, nSamples ); > nrg += silk_RSHIFT( nSamples, scale ); /* Q(-scale)*/ > >@@ -228,18 +218,12 @@ void silk_noise_shape_analysis_FIX( > pitch_res_ptr += nSamples; > } > >- psEncCtrl->sparseness_Q8 = silk_RSHIFT( silk_sigm_Q15( silk_SMULWB( energy_variation_Q7 - >- SILK_FIX_CONST( 5.0, 7 ), SILK_FIX_CONST( 0.1, 16 ) ) ), 7 ); >- > /* Set quantization offset depending on sparseness measure */ >- if( psEncCtrl->sparseness_Q8 > SILK_FIX_CONST( SPARSENESS_THRESHOLD_QNT_OFFSET, 8 ) ) { >+ if( energy_variation_Q7 > SILK_FIX_CONST( ENERGY_VARIATION_THRESHOLD_QNT_OFFSET, 7 ) * (nSegs-1) ) { > psEnc->sCmn.indices.quantOffsetType = 0; > } else { > psEnc->sCmn.indices.quantOffsetType = 1; > } >- >- /* Increase coding SNR for sparse signals */ >- SNR_adj_dB_Q7 = silk_SMLAWB( SNR_adj_dB_Q7, SILK_FIX_CONST( SPARSE_SNR_INCR_dB, 15 ), psEncCtrl->sparseness_Q8 - SILK_FIX_CONST( 0.5, 8 ) ); > } > > /*******************************/ >@@ -247,14 +231,8 @@ void silk_noise_shape_analysis_FIX( > /*******************************/ > /* More BWE for signals with high prediction gain */ > strength_Q16 = silk_SMULWB( psEncCtrl->predGain_Q16, SILK_FIX_CONST( FIND_PITCH_WHITE_NOISE_FRACTION, 16 ) ); >- BWExp1_Q16 = BWExp2_Q16 = silk_DIV32_varQ( SILK_FIX_CONST( BANDWIDTH_EXPANSION, 16 ), >+ BWExp_Q16 = silk_DIV32_varQ( SILK_FIX_CONST( BANDWIDTH_EXPANSION, 16 ), > silk_SMLAWW( SILK_FIX_CONST( 1.0, 16 ), strength_Q16, strength_Q16 ), 16 ); >- delta_Q16 = silk_SMULWB( SILK_FIX_CONST( 1.0, 16 ) - silk_SMULBB( 3, psEncCtrl->coding_quality_Q14 ), >- SILK_FIX_CONST( LOW_RATE_BANDWIDTH_EXPANSION_DELTA, 16 ) ); >- BWExp1_Q16 = silk_SUB32( BWExp1_Q16, delta_Q16 ); >- BWExp2_Q16 = silk_ADD32( BWExp2_Q16, delta_Q16 ); >- /* BWExp1 will be applied after BWExp2, so make it relative */ >- BWExp1_Q16 = silk_DIV32_16( silk_LSHIFT( BWExp1_Q16, 14 ), silk_RSHIFT( BWExp2_Q16, 2 ) ); > > if( psEnc->sCmn.warping_Q16 > 0 ) { > /* Slightly more warping in analysis will move quantization noise up in frequency, where it's better masked */ >@@ -284,7 +262,7 @@ void silk_noise_shape_analysis_FIX( > > if( psEnc->sCmn.warping_Q16 > 0 ) { > /* Calculate warped auto correlation */ >- silk_warped_autocorrelation_FIX( auto_corr, &scale, x_windowed, warping_Q16, psEnc->sCmn.shapeWinLength, psEnc->sCmn.shapingLPCOrder ); >+ silk_warped_autocorrelation_FIX( auto_corr, &scale, x_windowed, warping_Q16, psEnc->sCmn.shapeWinLength, psEnc->sCmn.shapingLPCOrder, arch ); > } else { > /* Calculate regular auto correlation */ > silk_autocorr( auto_corr, &scale, x_windowed, psEnc->sCmn.shapeWinLength, psEnc->sCmn.shapingLPCOrder + 1, arch ); >@@ -299,7 +277,7 @@ void silk_noise_shape_analysis_FIX( > silk_assert( nrg >= 0 ); > > /* Convert reflection coefficients to prediction coefficients */ >- silk_k2a_Q16( AR2_Q24, refl_coef_Q16, psEnc->sCmn.shapingLPCOrder ); >+ silk_k2a_Q16( AR_Q24, refl_coef_Q16, psEnc->sCmn.shapingLPCOrder ); > > Qnrg = -scale; /* range: -12...30*/ > silk_assert( Qnrg >= -12 ); >@@ -318,40 +296,34 @@ void silk_noise_shape_analysis_FIX( > > if( psEnc->sCmn.warping_Q16 > 0 ) { > /* Adjust gain for warping */ >- gain_mult_Q16 = warped_gain( AR2_Q24, warping_Q16, psEnc->sCmn.shapingLPCOrder ); >- silk_assert( psEncCtrl->Gains_Q16[ k ] >= 0 ); >- if ( silk_SMULWW( silk_RSHIFT_ROUND( psEncCtrl->Gains_Q16[ k ], 1 ), gain_mult_Q16 ) >= ( silk_int32_MAX >> 1 ) ) { >- psEncCtrl->Gains_Q16[ k ] = silk_int32_MAX; >+ gain_mult_Q16 = warped_gain( AR_Q24, warping_Q16, psEnc->sCmn.shapingLPCOrder ); >+ silk_assert( psEncCtrl->Gains_Q16[ k ] > 0 ); >+ if( psEncCtrl->Gains_Q16[ k ] < SILK_FIX_CONST( 0.25, 16 ) ) { >+ psEncCtrl->Gains_Q16[ k ] = silk_SMULWW( psEncCtrl->Gains_Q16[ k ], gain_mult_Q16 ); > } else { >- psEncCtrl->Gains_Q16[ k ] = silk_SMULWW( psEncCtrl->Gains_Q16[ k ], gain_mult_Q16 ); >+ psEncCtrl->Gains_Q16[ k ] = silk_SMULWW( silk_RSHIFT_ROUND( psEncCtrl->Gains_Q16[ k ], 1 ), gain_mult_Q16 ); >+ if ( psEncCtrl->Gains_Q16[ k ] >= ( silk_int32_MAX >> 1 ) ) { >+ psEncCtrl->Gains_Q16[ k ] = silk_int32_MAX; >+ } else { >+ psEncCtrl->Gains_Q16[ k ] = silk_LSHIFT32( psEncCtrl->Gains_Q16[ k ], 1 ); >+ } > } >+ silk_assert( psEncCtrl->Gains_Q16[ k ] > 0 ); > } > >- /* Bandwidth expansion for synthesis filter shaping */ >- silk_bwexpander_32( AR2_Q24, psEnc->sCmn.shapingLPCOrder, BWExp2_Q16 ); >- >- /* Compute noise shaping filter coefficients */ >- silk_memcpy( AR1_Q24, AR2_Q24, psEnc->sCmn.shapingLPCOrder * sizeof( opus_int32 ) ); >- >- /* Bandwidth expansion for analysis filter shaping */ >- silk_assert( BWExp1_Q16 <= SILK_FIX_CONST( 1.0, 16 ) ); >- silk_bwexpander_32( AR1_Q24, psEnc->sCmn.shapingLPCOrder, BWExp1_Q16 ); >- >- /* Ratio of prediction gains, in energy domain */ >- pre_nrg_Q30 = silk_LPC_inverse_pred_gain_Q24( AR2_Q24, psEnc->sCmn.shapingLPCOrder ); >- nrg = silk_LPC_inverse_pred_gain_Q24( AR1_Q24, psEnc->sCmn.shapingLPCOrder ); >- >- /*psEncCtrl->GainsPre[ k ] = 1.0f - 0.7f * ( 1.0f - pre_nrg / nrg ) = 0.3f + 0.7f * pre_nrg / nrg;*/ >- pre_nrg_Q30 = silk_LSHIFT32( silk_SMULWB( pre_nrg_Q30, SILK_FIX_CONST( 0.7, 15 ) ), 1 ); >- psEncCtrl->GainsPre_Q14[ k ] = ( opus_int ) SILK_FIX_CONST( 0.3, 14 ) + silk_DIV32_varQ( pre_nrg_Q30, nrg, 14 ); >+ /* Bandwidth expansion */ >+ silk_bwexpander_32( AR_Q24, psEnc->sCmn.shapingLPCOrder, BWExp_Q16 ); > >- /* Convert to monic warped prediction coefficients and limit absolute values */ >- limit_warped_coefs( AR2_Q24, AR1_Q24, warping_Q16, SILK_FIX_CONST( 3.999, 24 ), psEnc->sCmn.shapingLPCOrder ); >+ if( psEnc->sCmn.warping_Q16 > 0 ) { >+ /* Convert to monic warped prediction coefficients and limit absolute values */ >+ limit_warped_coefs( AR_Q24, warping_Q16, SILK_FIX_CONST( 3.999, 24 ), psEnc->sCmn.shapingLPCOrder ); > >- /* Convert from Q24 to Q13 and store in int16 */ >- for( i = 0; i < psEnc->sCmn.shapingLPCOrder; i++ ) { >- psEncCtrl->AR1_Q13[ k * MAX_SHAPE_LPC_ORDER + i ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( AR1_Q24[ i ], 11 ) ); >- psEncCtrl->AR2_Q13[ k * MAX_SHAPE_LPC_ORDER + i ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( AR2_Q24[ i ], 11 ) ); >+ /* Convert from Q24 to Q13 and store in int16 */ >+ for( i = 0; i < psEnc->sCmn.shapingLPCOrder; i++ ) { >+ psEncCtrl->AR_Q13[ k * MAX_SHAPE_LPC_ORDER + i ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( AR_Q24[ i ], 11 ) ); >+ } >+ } else { >+ silk_LPC_fit( &psEncCtrl->AR_Q13[ k * MAX_SHAPE_LPC_ORDER ], AR_Q24, 13, 24, psEnc->sCmn.shapingLPCOrder ); > } > } > >@@ -368,11 +340,6 @@ void silk_noise_shape_analysis_FIX( > psEncCtrl->Gains_Q16[ k ] = silk_ADD_POS_SAT32( psEncCtrl->Gains_Q16[ k ], gain_add_Q16 ); > } > >- gain_mult_Q16 = SILK_FIX_CONST( 1.0, 16 ) + silk_RSHIFT_ROUND( silk_MLA( SILK_FIX_CONST( INPUT_TILT, 26 ), >- psEncCtrl->coding_quality_Q14, SILK_FIX_CONST( HIGH_RATE_INPUT_TILT, 12 ) ), 10 ); >- for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { >- psEncCtrl->GainsPre_Q14[ k ] = silk_SMULWB( gain_mult_Q16, psEncCtrl->GainsPre_Q14[ k ] ); >- } > > /************************************************/ > /* Control low-frequency shaping and noise tilt */ >@@ -410,14 +377,6 @@ void silk_noise_shape_analysis_FIX( > /****************************/ > /* HARMONIC SHAPING CONTROL */ > /****************************/ >- /* Control boosting of harmonic frequencies */ >- HarmBoost_Q16 = silk_SMULWB( silk_SMULWB( SILK_FIX_CONST( 1.0, 17 ) - silk_LSHIFT( psEncCtrl->coding_quality_Q14, 3 ), >- psEnc->LTPCorr_Q15 ), SILK_FIX_CONST( LOW_RATE_HARMONIC_BOOST, 16 ) ); >- >- /* More harmonic boost for noisy input signals */ >- HarmBoost_Q16 = silk_SMLAWB( HarmBoost_Q16, >- SILK_FIX_CONST( 1.0, 16 ) - silk_LSHIFT( psEncCtrl->input_quality_Q14, 2 ), SILK_FIX_CONST( LOW_INPUT_QUALITY_HARMONIC_BOOST, 16 ) ); >- > if( USE_HARM_SHAPING && psEnc->sCmn.indices.signalType == TYPE_VOICED ) { > /* More harmonic noise shaping for high bitrates or noisy input */ > HarmShapeGain_Q16 = silk_SMLAWB( SILK_FIX_CONST( HARMONIC_SHAPING, 16 ), >@@ -435,14 +394,11 @@ void silk_noise_shape_analysis_FIX( > /* Smooth over subframes */ > /*************************/ > for( k = 0; k < MAX_NB_SUBFR; k++ ) { >- psShapeSt->HarmBoost_smth_Q16 = >- silk_SMLAWB( psShapeSt->HarmBoost_smth_Q16, HarmBoost_Q16 - psShapeSt->HarmBoost_smth_Q16, SILK_FIX_CONST( SUBFR_SMTH_COEF, 16 ) ); > psShapeSt->HarmShapeGain_smth_Q16 = > silk_SMLAWB( psShapeSt->HarmShapeGain_smth_Q16, HarmShapeGain_Q16 - psShapeSt->HarmShapeGain_smth_Q16, SILK_FIX_CONST( SUBFR_SMTH_COEF, 16 ) ); > psShapeSt->Tilt_smth_Q16 = > silk_SMLAWB( psShapeSt->Tilt_smth_Q16, Tilt_Q16 - psShapeSt->Tilt_smth_Q16, SILK_FIX_CONST( SUBFR_SMTH_COEF, 16 ) ); > >- psEncCtrl->HarmBoost_Q14[ k ] = ( opus_int )silk_RSHIFT_ROUND( psShapeSt->HarmBoost_smth_Q16, 2 ); > psEncCtrl->HarmShapeGain_Q14[ k ] = ( opus_int )silk_RSHIFT_ROUND( psShapeSt->HarmShapeGain_smth_Q16, 2 ); > psEncCtrl->Tilt_Q14[ k ] = ( opus_int )silk_RSHIFT_ROUND( psShapeSt->Tilt_smth_Q16, 2 ); > } >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/pitch_analysis_core_FIX.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/pitch_analysis_core_FIX.c >index 01bb9fc0a837b6c34933fcb066a791873540dea3..8df109e6cf51107e4776c703e2a562d89b826fef 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/pitch_analysis_core_FIX.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/pitch_analysis_core_FIX.c >@@ -80,7 +80,7 @@ static void silk_P_Ana_calc_energy_st3( > /* FIXED POINT CORE PITCH ANALYSIS FUNCTION */ > /*************************************************************/ > opus_int silk_pitch_analysis_core( /* O Voicing estimate: 0 voiced, 1 unvoiced */ >- const opus_int16 *frame, /* I Signal of length PE_FRAME_LENGTH_MS*Fs_kHz */ >+ const opus_int16 *frame_unscaled, /* I Signal of length PE_FRAME_LENGTH_MS*Fs_kHz */ > opus_int *pitch_out, /* O 4 pitch lag values */ > opus_int16 *lagIndex, /* O Lag Index */ > opus_int8 *contourIndex, /* O Pitch contour Index */ >@@ -94,16 +94,17 @@ opus_int silk_pitch_analysis_core( /* O Voicing estimate: 0 > int arch /* I Run-time architecture */ > ) > { >- VARDECL( opus_int16, frame_8kHz ); >+ VARDECL( opus_int16, frame_8kHz_buf ); > VARDECL( opus_int16, frame_4kHz ); >+ VARDECL( opus_int16, frame_scaled ); > opus_int32 filt_state[ 6 ]; >- const opus_int16 *input_frame_ptr; >+ const opus_int16 *frame, *frame_8kHz; > opus_int i, k, d, j; > VARDECL( opus_int16, C ); > VARDECL( opus_int32, xcorr32 ); > const opus_int16 *target_ptr, *basis_ptr; >- opus_int32 cross_corr, normalizer, energy, shift, energy_basis, energy_target; >- opus_int d_srch[ PE_D_SRCH_LENGTH ], Cmax, length_d_srch, length_d_comp; >+ opus_int32 cross_corr, normalizer, energy, energy_basis, energy_target; >+ opus_int d_srch[ PE_D_SRCH_LENGTH ], Cmax, length_d_srch, length_d_comp, shift; > VARDECL( opus_int16, d_comp ); > opus_int32 sum, threshold, lag_counter; > opus_int CBimax, CBimax_new, CBimax_old, lag, start_lag, end_lag, lag_new; >@@ -119,6 +120,7 @@ opus_int silk_pitch_analysis_core( /* O Voicing estimate: 0 > opus_int32 delta_lag_log2_sqr_Q7, lag_log2_Q7, prevLag_log2_Q7, prev_lag_bias_Q13; > const opus_int8 *Lag_CB_ptr; > SAVE_STACK; >+ > /* Check for valid sampling frequency */ > silk_assert( Fs_kHz == 8 || Fs_kHz == 12 || Fs_kHz == 16 ); > >@@ -137,17 +139,33 @@ opus_int silk_pitch_analysis_core( /* O Voicing estimate: 0 > min_lag = PE_MIN_LAG_MS * Fs_kHz; > max_lag = PE_MAX_LAG_MS * Fs_kHz - 1; > >+ /* Downscale input if necessary */ >+ silk_sum_sqr_shift( &energy, &shift, frame_unscaled, frame_length ); >+ shift += 3 - silk_CLZ32( energy ); /* at least two bits headroom */ >+ ALLOC( frame_scaled, frame_length, opus_int16 ); >+ if( shift > 0 ) { >+ shift = silk_RSHIFT( shift + 1, 1 ); >+ for( i = 0; i < frame_length; i++ ) { >+ frame_scaled[ i ] = silk_RSHIFT( frame_unscaled[ i ], shift ); >+ } >+ frame = frame_scaled; >+ } else { >+ frame = frame_unscaled; >+ } >+ >+ ALLOC( frame_8kHz_buf, ( Fs_kHz == 8 ) ? 1 : frame_length_8kHz, opus_int16 ); > /* Resample from input sampled at Fs_kHz to 8 kHz */ >- ALLOC( frame_8kHz, frame_length_8kHz, opus_int16 ); > if( Fs_kHz == 16 ) { > silk_memset( filt_state, 0, 2 * sizeof( opus_int32 ) ); >- silk_resampler_down2( filt_state, frame_8kHz, frame, frame_length ); >+ silk_resampler_down2( filt_state, frame_8kHz_buf, frame, frame_length ); >+ frame_8kHz = frame_8kHz_buf; > } else if( Fs_kHz == 12 ) { > silk_memset( filt_state, 0, 6 * sizeof( opus_int32 ) ); >- silk_resampler_down2_3( filt_state, frame_8kHz, frame, frame_length ); >+ silk_resampler_down2_3( filt_state, frame_8kHz_buf, frame, frame_length ); >+ frame_8kHz = frame_8kHz_buf; > } else { > silk_assert( Fs_kHz == 8 ); >- silk_memcpy( frame_8kHz, frame, frame_length_8kHz * sizeof(opus_int16) ); >+ frame_8kHz = frame; > } > > /* Decimate again to 4 kHz */ >@@ -160,19 +178,6 @@ opus_int silk_pitch_analysis_core( /* O Voicing estimate: 0 > frame_4kHz[ i ] = silk_ADD_SAT16( frame_4kHz[ i ], frame_4kHz[ i - 1 ] ); > } > >- /******************************************************************************* >- ** Scale 4 kHz signal down to prevent correlations measures from overflowing >- ** find scaling as max scaling for each 8kHz(?) subframe >- *******************************************************************************/ >- >- /* Inner product is calculated with different lengths, so scale for the worst case */ >- silk_sum_sqr_shift( &energy, &shift, frame_4kHz, frame_length_4kHz ); >- if( shift > 0 ) { >- shift = silk_RSHIFT( shift, 1 ); >- for( i = 0; i < frame_length_4kHz; i++ ) { >- frame_4kHz[ i ] = silk_RSHIFT( frame_4kHz[ i ], shift ); >- } >- } > > /****************************************************************************** > * FIRST STAGE, operating in 4 khz >@@ -311,18 +316,6 @@ opus_int silk_pitch_analysis_core( /* O Voicing estimate: 0 > ** SECOND STAGE, operating at 8 kHz, on lag sections with high correlation > *************************************************************************************/ > >- /****************************************************************************** >- ** Scale signal down to avoid correlations measures from overflowing >- *******************************************************************************/ >- /* find scaling as max scaling for each subframe */ >- silk_sum_sqr_shift( &energy, &shift, frame_8kHz, frame_length_8kHz ); >- if( shift > 0 ) { >- shift = silk_RSHIFT( shift, 1 ); >- for( i = 0; i < frame_length_8kHz; i++ ) { >- frame_8kHz[ i ] = silk_RSHIFT( frame_8kHz[ i ], shift ); >- } >- } >- > /********************************************************************************* > * Find energy of each subframe projected onto its history, for a range of delays > *********************************************************************************/ >@@ -462,24 +455,6 @@ opus_int silk_pitch_analysis_core( /* O Voicing estimate: 0 > silk_assert( *LTPCorr_Q15 >= 0 ); > > if( Fs_kHz > 8 ) { >- VARDECL( opus_int16, scratch_mem ); >- /***************************************************************************/ >- /* Scale input signal down to avoid correlations measures from overflowing */ >- /***************************************************************************/ >- /* find scaling as max scaling for each subframe */ >- silk_sum_sqr_shift( &energy, &shift, frame, frame_length ); >- ALLOC( scratch_mem, shift > 0 ? frame_length : ALLOC_NONE, opus_int16 ); >- if( shift > 0 ) { >- /* Move signal to scratch mem because the input signal should be unchanged */ >- shift = silk_RSHIFT( shift, 1 ); >- for( i = 0; i < frame_length; i++ ) { >- scratch_mem[ i ] = silk_RSHIFT( frame[ i ], shift ); >- } >- input_frame_ptr = scratch_mem; >- } else { >- input_frame_ptr = frame; >- } >- > /* Search in original signal */ > > CBimax_old = CBimax; >@@ -519,14 +494,14 @@ opus_int silk_pitch_analysis_core( /* O Voicing estimate: 0 > /* Calculate the correlations and energies needed in stage 3 */ > ALLOC( energies_st3, nb_subfr * nb_cbk_search, silk_pe_stage3_vals ); > ALLOC( cross_corr_st3, nb_subfr * nb_cbk_search, silk_pe_stage3_vals ); >- silk_P_Ana_calc_corr_st3( cross_corr_st3, input_frame_ptr, start_lag, sf_length, nb_subfr, complexity, arch ); >- silk_P_Ana_calc_energy_st3( energies_st3, input_frame_ptr, start_lag, sf_length, nb_subfr, complexity, arch ); >+ silk_P_Ana_calc_corr_st3( cross_corr_st3, frame, start_lag, sf_length, nb_subfr, complexity, arch ); >+ silk_P_Ana_calc_energy_st3( energies_st3, frame, start_lag, sf_length, nb_subfr, complexity, arch ); > > lag_counter = 0; > silk_assert( lag == silk_SAT16( lag ) ); > contour_bias_Q15 = silk_DIV32_16( SILK_FIX_CONST( PE_FLATCONTOUR_BIAS, 15 ), lag ); > >- target_ptr = &input_frame_ptr[ PE_LTP_MEM_LENGTH_MS * Fs_kHz ]; >+ target_ptr = &frame[ PE_LTP_MEM_LENGTH_MS * Fs_kHz ]; > energy_target = silk_ADD32( silk_inner_prod_aligned( target_ptr, target_ptr, nb_subfr * sf_length, arch ), 1 ); > for( d = start_lag; d <= end_lag; d++ ) { > for( j = 0; j < nb_cbk_search; j++ ) { >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/prefilter_FIX.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/prefilter_FIX.c >deleted file mode 100644 >index 6a8e35152efbd6d0b17227aa7525a3a23dee9254..0000000000000000000000000000000000000000 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/prefilter_FIX.c >+++ /dev/null >@@ -1,221 +0,0 @@ >-/*********************************************************************** >-Copyright (c) 2006-2011, Skype Limited. All rights reserved. >-Redistribution and use in source and binary forms, with or without >-modification, are permitted provided that the following conditions >-are met: >-- Redistributions of source code must retain the above copyright notice, >-this list of conditions and the following disclaimer. >-- Redistributions in binary form must reproduce the above copyright >-notice, this list of conditions and the following disclaimer in the >-documentation and/or other materials provided with the distribution. >-- Neither the name of Internet Society, IETF or IETF Trust, nor the >-names of specific contributors, may be used to endorse or promote >-products derived from this software without specific prior written >-permission. >-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" >-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE >-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE >-ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE >-LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >-INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >-CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE >-POSSIBILITY OF SUCH DAMAGE. >-***********************************************************************/ >- >-#ifdef HAVE_CONFIG_H >-#include "config.h" >-#endif >- >-#include "main_FIX.h" >-#include "stack_alloc.h" >-#include "tuning_parameters.h" >- >-#if defined(MIPSr1_ASM) >-#include "mips/prefilter_FIX_mipsr1.h" >-#endif >- >- >-#if !defined(OVERRIDE_silk_warped_LPC_analysis_filter_FIX) >-#define silk_warped_LPC_analysis_filter_FIX(state, res_Q2, coef_Q13, input, lambda_Q16, length, order, arch) \ >- ((void)(arch),silk_warped_LPC_analysis_filter_FIX_c(state, res_Q2, coef_Q13, input, lambda_Q16, length, order)) >-#endif >- >-/* Prefilter for finding Quantizer input signal */ >-static OPUS_INLINE void silk_prefilt_FIX( >- silk_prefilter_state_FIX *P, /* I/O state */ >- opus_int32 st_res_Q12[], /* I short term residual signal */ >- opus_int32 xw_Q3[], /* O prefiltered signal */ >- opus_int32 HarmShapeFIRPacked_Q12, /* I Harmonic shaping coeficients */ >- opus_int Tilt_Q14, /* I Tilt shaping coeficient */ >- opus_int32 LF_shp_Q14, /* I Low-frequancy shaping coeficients */ >- opus_int lag, /* I Lag for harmonic shaping */ >- opus_int length /* I Length of signals */ >-); >- >-void silk_warped_LPC_analysis_filter_FIX_c( >- opus_int32 state[], /* I/O State [order + 1] */ >- opus_int32 res_Q2[], /* O Residual signal [length] */ >- const opus_int16 coef_Q13[], /* I Coefficients [order] */ >- const opus_int16 input[], /* I Input signal [length] */ >- const opus_int16 lambda_Q16, /* I Warping factor */ >- const opus_int length, /* I Length of input signal */ >- const opus_int order /* I Filter order (even) */ >-) >-{ >- opus_int n, i; >- opus_int32 acc_Q11, tmp1, tmp2; >- >- /* Order must be even */ >- silk_assert( ( order & 1 ) == 0 ); >- >- for( n = 0; n < length; n++ ) { >- /* Output of lowpass section */ >- tmp2 = silk_SMLAWB( state[ 0 ], state[ 1 ], lambda_Q16 ); >- state[ 0 ] = silk_LSHIFT( input[ n ], 14 ); >- /* Output of allpass section */ >- tmp1 = silk_SMLAWB( state[ 1 ], state[ 2 ] - tmp2, lambda_Q16 ); >- state[ 1 ] = tmp2; >- acc_Q11 = silk_RSHIFT( order, 1 ); >- acc_Q11 = silk_SMLAWB( acc_Q11, tmp2, coef_Q13[ 0 ] ); >- /* Loop over allpass sections */ >- for( i = 2; i < order; i += 2 ) { >- /* Output of allpass section */ >- tmp2 = silk_SMLAWB( state[ i ], state[ i + 1 ] - tmp1, lambda_Q16 ); >- state[ i ] = tmp1; >- acc_Q11 = silk_SMLAWB( acc_Q11, tmp1, coef_Q13[ i - 1 ] ); >- /* Output of allpass section */ >- tmp1 = silk_SMLAWB( state[ i + 1 ], state[ i + 2 ] - tmp2, lambda_Q16 ); >- state[ i + 1 ] = tmp2; >- acc_Q11 = silk_SMLAWB( acc_Q11, tmp2, coef_Q13[ i ] ); >- } >- state[ order ] = tmp1; >- acc_Q11 = silk_SMLAWB( acc_Q11, tmp1, coef_Q13[ order - 1 ] ); >- res_Q2[ n ] = silk_LSHIFT( (opus_int32)input[ n ], 2 ) - silk_RSHIFT_ROUND( acc_Q11, 9 ); >- } >-} >- >-void silk_prefilter_FIX( >- silk_encoder_state_FIX *psEnc, /* I/O Encoder state */ >- const silk_encoder_control_FIX *psEncCtrl, /* I Encoder control */ >- opus_int32 xw_Q3[], /* O Weighted signal */ >- const opus_int16 x[] /* I Speech signal */ >-) >-{ >- silk_prefilter_state_FIX *P = &psEnc->sPrefilt; >- opus_int j, k, lag; >- opus_int32 tmp_32; >- const opus_int16 *AR1_shp_Q13; >- const opus_int16 *px; >- opus_int32 *pxw_Q3; >- opus_int HarmShapeGain_Q12, Tilt_Q14; >- opus_int32 HarmShapeFIRPacked_Q12, LF_shp_Q14; >- VARDECL( opus_int32, x_filt_Q12 ); >- VARDECL( opus_int32, st_res_Q2 ); >- opus_int16 B_Q10[ 2 ]; >- SAVE_STACK; >- >- /* Set up pointers */ >- px = x; >- pxw_Q3 = xw_Q3; >- lag = P->lagPrev; >- ALLOC( x_filt_Q12, psEnc->sCmn.subfr_length, opus_int32 ); >- ALLOC( st_res_Q2, psEnc->sCmn.subfr_length, opus_int32 ); >- for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { >- /* Update Variables that change per sub frame */ >- if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { >- lag = psEncCtrl->pitchL[ k ]; >- } >- >- /* Noise shape parameters */ >- HarmShapeGain_Q12 = silk_SMULWB( (opus_int32)psEncCtrl->HarmShapeGain_Q14[ k ], 16384 - psEncCtrl->HarmBoost_Q14[ k ] ); >- silk_assert( HarmShapeGain_Q12 >= 0 ); >- HarmShapeFIRPacked_Q12 = silk_RSHIFT( HarmShapeGain_Q12, 2 ); >- HarmShapeFIRPacked_Q12 |= silk_LSHIFT( (opus_int32)silk_RSHIFT( HarmShapeGain_Q12, 1 ), 16 ); >- Tilt_Q14 = psEncCtrl->Tilt_Q14[ k ]; >- LF_shp_Q14 = psEncCtrl->LF_shp_Q14[ k ]; >- AR1_shp_Q13 = &psEncCtrl->AR1_Q13[ k * MAX_SHAPE_LPC_ORDER ]; >- >- /* Short term FIR filtering*/ >- silk_warped_LPC_analysis_filter_FIX( P->sAR_shp, st_res_Q2, AR1_shp_Q13, px, >- psEnc->sCmn.warping_Q16, psEnc->sCmn.subfr_length, psEnc->sCmn.shapingLPCOrder, psEnc->sCmn.arch ); >- >- /* Reduce (mainly) low frequencies during harmonic emphasis */ >- B_Q10[ 0 ] = silk_RSHIFT_ROUND( psEncCtrl->GainsPre_Q14[ k ], 4 ); >- tmp_32 = silk_SMLABB( SILK_FIX_CONST( INPUT_TILT, 26 ), psEncCtrl->HarmBoost_Q14[ k ], HarmShapeGain_Q12 ); /* Q26 */ >- tmp_32 = silk_SMLABB( tmp_32, psEncCtrl->coding_quality_Q14, SILK_FIX_CONST( HIGH_RATE_INPUT_TILT, 12 ) ); /* Q26 */ >- tmp_32 = silk_SMULWB( tmp_32, -psEncCtrl->GainsPre_Q14[ k ] ); /* Q24 */ >- tmp_32 = silk_RSHIFT_ROUND( tmp_32, 14 ); /* Q10 */ >- B_Q10[ 1 ]= silk_SAT16( tmp_32 ); >- x_filt_Q12[ 0 ] = silk_MLA( silk_MUL( st_res_Q2[ 0 ], B_Q10[ 0 ] ), P->sHarmHP_Q2, B_Q10[ 1 ] ); >- for( j = 1; j < psEnc->sCmn.subfr_length; j++ ) { >- x_filt_Q12[ j ] = silk_MLA( silk_MUL( st_res_Q2[ j ], B_Q10[ 0 ] ), st_res_Q2[ j - 1 ], B_Q10[ 1 ] ); >- } >- P->sHarmHP_Q2 = st_res_Q2[ psEnc->sCmn.subfr_length - 1 ]; >- >- silk_prefilt_FIX( P, x_filt_Q12, pxw_Q3, HarmShapeFIRPacked_Q12, Tilt_Q14, LF_shp_Q14, lag, psEnc->sCmn.subfr_length ); >- >- px += psEnc->sCmn.subfr_length; >- pxw_Q3 += psEnc->sCmn.subfr_length; >- } >- >- P->lagPrev = psEncCtrl->pitchL[ psEnc->sCmn.nb_subfr - 1 ]; >- RESTORE_STACK; >-} >- >-#ifndef OVERRIDE_silk_prefilt_FIX >-/* Prefilter for finding Quantizer input signal */ >-static OPUS_INLINE void silk_prefilt_FIX( >- silk_prefilter_state_FIX *P, /* I/O state */ >- opus_int32 st_res_Q12[], /* I short term residual signal */ >- opus_int32 xw_Q3[], /* O prefiltered signal */ >- opus_int32 HarmShapeFIRPacked_Q12, /* I Harmonic shaping coeficients */ >- opus_int Tilt_Q14, /* I Tilt shaping coeficient */ >- opus_int32 LF_shp_Q14, /* I Low-frequancy shaping coeficients */ >- opus_int lag, /* I Lag for harmonic shaping */ >- opus_int length /* I Length of signals */ >-) >-{ >- opus_int i, idx, LTP_shp_buf_idx; >- opus_int32 n_LTP_Q12, n_Tilt_Q10, n_LF_Q10; >- opus_int32 sLF_MA_shp_Q12, sLF_AR_shp_Q12; >- opus_int16 *LTP_shp_buf; >- >- /* To speed up use temp variables instead of using the struct */ >- LTP_shp_buf = P->sLTP_shp; >- LTP_shp_buf_idx = P->sLTP_shp_buf_idx; >- sLF_AR_shp_Q12 = P->sLF_AR_shp_Q12; >- sLF_MA_shp_Q12 = P->sLF_MA_shp_Q12; >- >- for( i = 0; i < length; i++ ) { >- if( lag > 0 ) { >- /* unrolled loop */ >- silk_assert( HARM_SHAPE_FIR_TAPS == 3 ); >- idx = lag + LTP_shp_buf_idx; >- n_LTP_Q12 = silk_SMULBB( LTP_shp_buf[ ( idx - HARM_SHAPE_FIR_TAPS / 2 - 1) & LTP_MASK ], HarmShapeFIRPacked_Q12 ); >- n_LTP_Q12 = silk_SMLABT( n_LTP_Q12, LTP_shp_buf[ ( idx - HARM_SHAPE_FIR_TAPS / 2 ) & LTP_MASK ], HarmShapeFIRPacked_Q12 ); >- n_LTP_Q12 = silk_SMLABB( n_LTP_Q12, LTP_shp_buf[ ( idx - HARM_SHAPE_FIR_TAPS / 2 + 1) & LTP_MASK ], HarmShapeFIRPacked_Q12 ); >- } else { >- n_LTP_Q12 = 0; >- } >- >- n_Tilt_Q10 = silk_SMULWB( sLF_AR_shp_Q12, Tilt_Q14 ); >- n_LF_Q10 = silk_SMLAWB( silk_SMULWT( sLF_AR_shp_Q12, LF_shp_Q14 ), sLF_MA_shp_Q12, LF_shp_Q14 ); >- >- sLF_AR_shp_Q12 = silk_SUB32( st_res_Q12[ i ], silk_LSHIFT( n_Tilt_Q10, 2 ) ); >- sLF_MA_shp_Q12 = silk_SUB32( sLF_AR_shp_Q12, silk_LSHIFT( n_LF_Q10, 2 ) ); >- >- LTP_shp_buf_idx = ( LTP_shp_buf_idx - 1 ) & LTP_MASK; >- LTP_shp_buf[ LTP_shp_buf_idx ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( sLF_MA_shp_Q12, 12 ) ); >- >- xw_Q3[i] = silk_RSHIFT_ROUND( silk_SUB32( sLF_MA_shp_Q12, n_LTP_Q12 ), 9 ); >- } >- >- /* Copy temp variable back to state */ >- P->sLF_AR_shp_Q12 = sLF_AR_shp_Q12; >- P->sLF_MA_shp_Q12 = sLF_MA_shp_Q12; >- P->sLTP_shp_buf_idx = LTP_shp_buf_idx; >-} >-#endif /* OVERRIDE_silk_prefilt_FIX */ >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/schur64_FIX.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/schur64_FIX.c >index 764a10ef3ea5d2a2f6854f3ae534151a51a018bc..b2cb12d9b160a0715f88e72439e5a036b8628ac5 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/schur64_FIX.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/schur64_FIX.c >@@ -43,7 +43,7 @@ opus_int32 silk_schur64( /* O returns residual ene > opus_int32 C[ SILK_MAX_ORDER_LPC + 1 ][ 2 ]; > opus_int32 Ctmp1_Q30, Ctmp2_Q30, rc_tmp_Q31; > >- silk_assert( order==6||order==8||order==10||order==12||order==14||order==16 ); >+ silk_assert( order >= 0 && order <= SILK_MAX_ORDER_LPC ); > > /* Check for invalid input */ > if( c[ 0 ] <= 0 ) { >@@ -51,9 +51,10 @@ opus_int32 silk_schur64( /* O returns residual ene > return 0; > } > >- for( k = 0; k < order + 1; k++ ) { >+ k = 0; >+ do { > C[ k ][ 0 ] = C[ k ][ 1 ] = c[ k ]; >- } >+ } while( ++k <= order ); > > for( k = 0; k < order; k++ ) { > /* Check that we won't be getting an unstable rc, otherwise stop here. */ >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/schur_FIX.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/schur_FIX.c >index c4c0ef23b47804e5f56c7c5d58c66556eef5a01e..59d44a6f7fe858c21eebca31b6be4430acd48319 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/schur_FIX.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/schur_FIX.c >@@ -43,28 +43,29 @@ opus_int32 silk_schur( /* O Returns residual ene > opus_int32 C[ SILK_MAX_ORDER_LPC + 1 ][ 2 ]; > opus_int32 Ctmp1, Ctmp2, rc_tmp_Q15; > >- silk_assert( order==6||order==8||order==10||order==12||order==14||order==16 ); >+ silk_assert( order >= 0 && order <= SILK_MAX_ORDER_LPC ); > > /* Get number of leading zeros */ > lz = silk_CLZ32( c[ 0 ] ); > > /* Copy correlations and adjust level to Q30 */ >+ k = 0; > if( lz < 2 ) { > /* lz must be 1, so shift one to the right */ >- for( k = 0; k < order + 1; k++ ) { >+ do { > C[ k ][ 0 ] = C[ k ][ 1 ] = silk_RSHIFT( c[ k ], 1 ); >- } >+ } while( ++k <= order ); > } else if( lz > 2 ) { > /* Shift to the left */ > lz -= 2; >- for( k = 0; k < order + 1; k++ ) { >+ do { > C[ k ][ 0 ] = C[ k ][ 1 ] = silk_LSHIFT( c[ k ], lz ); >- } >+ } while( ++k <= order ); > } else { > /* No need to shift */ >- for( k = 0; k < order + 1; k++ ) { >+ do { > C[ k ][ 0 ] = C[ k ][ 1 ] = c[ k ]; >- } >+ } while( ++k <= order ); > } > > for( k = 0; k < order; k++ ) { >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/solve_LS_FIX.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/solve_LS_FIX.c >deleted file mode 100644 >index 51d7d49d02a5e7cba9245295eba6aa26bc2bee7e..0000000000000000000000000000000000000000 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/solve_LS_FIX.c >+++ /dev/null >@@ -1,249 +0,0 @@ >-/*********************************************************************** >-Copyright (c) 2006-2011, Skype Limited. All rights reserved. >-Redistribution and use in source and binary forms, with or without >-modification, are permitted provided that the following conditions >-are met: >-- Redistributions of source code must retain the above copyright notice, >-this list of conditions and the following disclaimer. >-- Redistributions in binary form must reproduce the above copyright >-notice, this list of conditions and the following disclaimer in the >-documentation and/or other materials provided with the distribution. >-- Neither the name of Internet Society, IETF or IETF Trust, nor the >-names of specific contributors, may be used to endorse or promote >-products derived from this software without specific prior written >-permission. >-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" >-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE >-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE >-ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE >-LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >-INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >-CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE >-POSSIBILITY OF SUCH DAMAGE. >-***********************************************************************/ >- >-#ifdef HAVE_CONFIG_H >-#include "config.h" >-#endif >- >-#include "main_FIX.h" >-#include "stack_alloc.h" >-#include "tuning_parameters.h" >- >-/*****************************/ >-/* Internal function headers */ >-/*****************************/ >- >-typedef struct { >- opus_int32 Q36_part; >- opus_int32 Q48_part; >-} inv_D_t; >- >-/* Factorize square matrix A into LDL form */ >-static OPUS_INLINE void silk_LDL_factorize_FIX( >- opus_int32 *A, /* I/O Pointer to Symetric Square Matrix */ >- opus_int M, /* I Size of Matrix */ >- opus_int32 *L_Q16, /* I/O Pointer to Square Upper triangular Matrix */ >- inv_D_t *inv_D /* I/O Pointer to vector holding inverted diagonal elements of D */ >-); >- >-/* Solve Lx = b, when L is lower triangular and has ones on the diagonal */ >-static OPUS_INLINE void silk_LS_SolveFirst_FIX( >- const opus_int32 *L_Q16, /* I Pointer to Lower Triangular Matrix */ >- opus_int M, /* I Dim of Matrix equation */ >- const opus_int32 *b, /* I b Vector */ >- opus_int32 *x_Q16 /* O x Vector */ >-); >- >-/* Solve L^t*x = b, where L is lower triangular with ones on the diagonal */ >-static OPUS_INLINE void silk_LS_SolveLast_FIX( >- const opus_int32 *L_Q16, /* I Pointer to Lower Triangular Matrix */ >- const opus_int M, /* I Dim of Matrix equation */ >- const opus_int32 *b, /* I b Vector */ >- opus_int32 *x_Q16 /* O x Vector */ >-); >- >-static OPUS_INLINE void silk_LS_divide_Q16_FIX( >- opus_int32 T[], /* I/O Numenator vector */ >- inv_D_t *inv_D, /* I 1 / D vector */ >- opus_int M /* I dimension */ >-); >- >-/* Solves Ax = b, assuming A is symmetric */ >-void silk_solve_LDL_FIX( >- opus_int32 *A, /* I Pointer to symetric square matrix A */ >- opus_int M, /* I Size of matrix */ >- const opus_int32 *b, /* I Pointer to b vector */ >- opus_int32 *x_Q16 /* O Pointer to x solution vector */ >-) >-{ >- VARDECL( opus_int32, L_Q16 ); >- opus_int32 Y[ MAX_MATRIX_SIZE ]; >- inv_D_t inv_D[ MAX_MATRIX_SIZE ]; >- SAVE_STACK; >- >- silk_assert( M <= MAX_MATRIX_SIZE ); >- ALLOC( L_Q16, M * M, opus_int32 ); >- >- /*************************************************** >- Factorize A by LDL such that A = L*D*L', >- where L is lower triangular with ones on diagonal >- ****************************************************/ >- silk_LDL_factorize_FIX( A, M, L_Q16, inv_D ); >- >- /**************************************************** >- * substitute D*L'*x = Y. ie: >- L*D*L'*x = b => L*Y = b <=> Y = inv(L)*b >- ******************************************************/ >- silk_LS_SolveFirst_FIX( L_Q16, M, b, Y ); >- >- /**************************************************** >- D*L'*x = Y <=> L'*x = inv(D)*Y, because D is >- diagonal just multiply with 1/d_i >- ****************************************************/ >- silk_LS_divide_Q16_FIX( Y, inv_D, M ); >- >- /**************************************************** >- x = inv(L') * inv(D) * Y >- *****************************************************/ >- silk_LS_SolveLast_FIX( L_Q16, M, Y, x_Q16 ); >- RESTORE_STACK; >-} >- >-static OPUS_INLINE void silk_LDL_factorize_FIX( >- opus_int32 *A, /* I/O Pointer to Symetric Square Matrix */ >- opus_int M, /* I Size of Matrix */ >- opus_int32 *L_Q16, /* I/O Pointer to Square Upper triangular Matrix */ >- inv_D_t *inv_D /* I/O Pointer to vector holding inverted diagonal elements of D */ >-) >-{ >- opus_int i, j, k, status, loop_count; >- const opus_int32 *ptr1, *ptr2; >- opus_int32 diag_min_value, tmp_32, err; >- opus_int32 v_Q0[ MAX_MATRIX_SIZE ], D_Q0[ MAX_MATRIX_SIZE ]; >- opus_int32 one_div_diag_Q36, one_div_diag_Q40, one_div_diag_Q48; >- >- silk_assert( M <= MAX_MATRIX_SIZE ); >- >- status = 1; >- diag_min_value = silk_max_32( silk_SMMUL( silk_ADD_SAT32( A[ 0 ], A[ silk_SMULBB( M, M ) - 1 ] ), SILK_FIX_CONST( FIND_LTP_COND_FAC, 31 ) ), 1 << 9 ); >- for( loop_count = 0; loop_count < M && status == 1; loop_count++ ) { >- status = 0; >- for( j = 0; j < M; j++ ) { >- ptr1 = matrix_adr( L_Q16, j, 0, M ); >- tmp_32 = 0; >- for( i = 0; i < j; i++ ) { >- v_Q0[ i ] = silk_SMULWW( D_Q0[ i ], ptr1[ i ] ); /* Q0 */ >- tmp_32 = silk_SMLAWW( tmp_32, v_Q0[ i ], ptr1[ i ] ); /* Q0 */ >- } >- tmp_32 = silk_SUB32( matrix_ptr( A, j, j, M ), tmp_32 ); >- >- if( tmp_32 < diag_min_value ) { >- tmp_32 = silk_SUB32( silk_SMULBB( loop_count + 1, diag_min_value ), tmp_32 ); >- /* Matrix not positive semi-definite, or ill conditioned */ >- for( i = 0; i < M; i++ ) { >- matrix_ptr( A, i, i, M ) = silk_ADD32( matrix_ptr( A, i, i, M ), tmp_32 ); >- } >- status = 1; >- break; >- } >- D_Q0[ j ] = tmp_32; /* always < max(Correlation) */ >- >- /* two-step division */ >- one_div_diag_Q36 = silk_INVERSE32_varQ( tmp_32, 36 ); /* Q36 */ >- one_div_diag_Q40 = silk_LSHIFT( one_div_diag_Q36, 4 ); /* Q40 */ >- err = silk_SUB32( (opus_int32)1 << 24, silk_SMULWW( tmp_32, one_div_diag_Q40 ) ); /* Q24 */ >- one_div_diag_Q48 = silk_SMULWW( err, one_div_diag_Q40 ); /* Q48 */ >- >- /* Save 1/Ds */ >- inv_D[ j ].Q36_part = one_div_diag_Q36; >- inv_D[ j ].Q48_part = one_div_diag_Q48; >- >- matrix_ptr( L_Q16, j, j, M ) = 65536; /* 1.0 in Q16 */ >- ptr1 = matrix_adr( A, j, 0, M ); >- ptr2 = matrix_adr( L_Q16, j + 1, 0, M ); >- for( i = j + 1; i < M; i++ ) { >- tmp_32 = 0; >- for( k = 0; k < j; k++ ) { >- tmp_32 = silk_SMLAWW( tmp_32, v_Q0[ k ], ptr2[ k ] ); /* Q0 */ >- } >- tmp_32 = silk_SUB32( ptr1[ i ], tmp_32 ); /* always < max(Correlation) */ >- >- /* tmp_32 / D_Q0[j] : Divide to Q16 */ >- matrix_ptr( L_Q16, i, j, M ) = silk_ADD32( silk_SMMUL( tmp_32, one_div_diag_Q48 ), >- silk_RSHIFT( silk_SMULWW( tmp_32, one_div_diag_Q36 ), 4 ) ); >- >- /* go to next column */ >- ptr2 += M; >- } >- } >- } >- >- silk_assert( status == 0 ); >-} >- >-static OPUS_INLINE void silk_LS_divide_Q16_FIX( >- opus_int32 T[], /* I/O Numenator vector */ >- inv_D_t *inv_D, /* I 1 / D vector */ >- opus_int M /* I dimension */ >-) >-{ >- opus_int i; >- opus_int32 tmp_32; >- opus_int32 one_div_diag_Q36, one_div_diag_Q48; >- >- for( i = 0; i < M; i++ ) { >- one_div_diag_Q36 = inv_D[ i ].Q36_part; >- one_div_diag_Q48 = inv_D[ i ].Q48_part; >- >- tmp_32 = T[ i ]; >- T[ i ] = silk_ADD32( silk_SMMUL( tmp_32, one_div_diag_Q48 ), silk_RSHIFT( silk_SMULWW( tmp_32, one_div_diag_Q36 ), 4 ) ); >- } >-} >- >-/* Solve Lx = b, when L is lower triangular and has ones on the diagonal */ >-static OPUS_INLINE void silk_LS_SolveFirst_FIX( >- const opus_int32 *L_Q16, /* I Pointer to Lower Triangular Matrix */ >- opus_int M, /* I Dim of Matrix equation */ >- const opus_int32 *b, /* I b Vector */ >- opus_int32 *x_Q16 /* O x Vector */ >-) >-{ >- opus_int i, j; >- const opus_int32 *ptr32; >- opus_int32 tmp_32; >- >- for( i = 0; i < M; i++ ) { >- ptr32 = matrix_adr( L_Q16, i, 0, M ); >- tmp_32 = 0; >- for( j = 0; j < i; j++ ) { >- tmp_32 = silk_SMLAWW( tmp_32, ptr32[ j ], x_Q16[ j ] ); >- } >- x_Q16[ i ] = silk_SUB32( b[ i ], tmp_32 ); >- } >-} >- >-/* Solve L^t*x = b, where L is lower triangular with ones on the diagonal */ >-static OPUS_INLINE void silk_LS_SolveLast_FIX( >- const opus_int32 *L_Q16, /* I Pointer to Lower Triangular Matrix */ >- const opus_int M, /* I Dim of Matrix equation */ >- const opus_int32 *b, /* I b Vector */ >- opus_int32 *x_Q16 /* O x Vector */ >-) >-{ >- opus_int i, j; >- const opus_int32 *ptr32; >- opus_int32 tmp_32; >- >- for( i = M - 1; i >= 0; i-- ) { >- ptr32 = matrix_adr( L_Q16, 0, i, M ); >- tmp_32 = 0; >- for( j = M - 1; j > i; j-- ) { >- tmp_32 = silk_SMLAWW( tmp_32, ptr32[ silk_SMULBB( j, M ) ], x_Q16[ j ] ); >- } >- x_Q16[ i ] = silk_SUB32( b[ i ], tmp_32 ); >- } >-} >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/structs_FIX.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/structs_FIX.h >index 3294b251281ed8265d423c54e0d02273f7f99452..2774a97b24fe677b7d182a9a12028a7c1d87fa89 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/structs_FIX.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/structs_FIX.h >@@ -47,31 +47,17 @@ typedef struct { > opus_int32 Tilt_smth_Q16; > } silk_shape_state_FIX; > >-/********************************/ >-/* Prefilter state */ >-/********************************/ >-typedef struct { >- opus_int16 sLTP_shp[ LTP_BUF_LENGTH ]; >- opus_int32 sAR_shp[ MAX_SHAPE_LPC_ORDER + 1 ]; >- opus_int sLTP_shp_buf_idx; >- opus_int32 sLF_AR_shp_Q12; >- opus_int32 sLF_MA_shp_Q12; >- opus_int32 sHarmHP_Q2; >- opus_int32 rand_seed; >- opus_int lagPrev; >-} silk_prefilter_state_FIX; >- > /********************************/ > /* Encoder state FIX */ > /********************************/ > typedef struct { > silk_encoder_state sCmn; /* Common struct, shared with floating-point code */ > silk_shape_state_FIX sShape; /* Shape state */ >- silk_prefilter_state_FIX sPrefilt; /* Prefilter State */ > > /* Buffer for find pitch and noise shape analysis */ > silk_DWORD_ALIGN opus_int16 x_buf[ 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ];/* Buffer for find pitch and noise shape analysis */ > opus_int LTPCorr_Q15; /* Normalized correlation from pitch lag estimator */ >+ opus_int32 resNrgSmth; > } silk_encoder_state_FIX; > > /************************/ >@@ -87,11 +73,8 @@ typedef struct { > > /* Noise shaping parameters */ > /* Testing */ >- silk_DWORD_ALIGN opus_int16 AR1_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ]; >- silk_DWORD_ALIGN opus_int16 AR2_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ]; >+ silk_DWORD_ALIGN opus_int16 AR_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ]; > opus_int32 LF_shp_Q14[ MAX_NB_SUBFR ]; /* Packs two int16 coefficients per int32 value */ >- opus_int GainsPre_Q14[ MAX_NB_SUBFR ]; >- opus_int HarmBoost_Q14[ MAX_NB_SUBFR ]; > opus_int Tilt_Q14[ MAX_NB_SUBFR ]; > opus_int HarmShapeGain_Q14[ MAX_NB_SUBFR ]; > opus_int Lambda_Q10; >@@ -99,7 +82,6 @@ typedef struct { > opus_int coding_quality_Q14; > > /* measures */ >- opus_int sparseness_Q8; > opus_int32 predGain_Q16; > opus_int LTPredCodGain_Q7; > opus_int32 ResNrg[ MAX_NB_SUBFR ]; /* Residual energy per subframe */ >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/warped_autocorrelation_FIX.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/warped_autocorrelation_FIX.c >index 6ca6c1184d865f7fbbc15bcc6cbb329b26b86a02..994c299abd1240cdb37597e3a8aca8207e89a976 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/warped_autocorrelation_FIX.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/warped_autocorrelation_FIX.c >@@ -31,17 +31,13 @@ POSSIBILITY OF SUCH DAMAGE. > > #include "main_FIX.h" > >-#define QC 10 >-#define QS 14 >- > #if defined(MIPSr1_ASM) > #include "mips/warped_autocorrelation_FIX_mipsr1.h" > #endif > > >-#ifndef OVERRIDE_silk_warped_autocorrelation_FIX > /* Autocorrelations for a warped frequency axis */ >-void silk_warped_autocorrelation_FIX( >+void silk_warped_autocorrelation_FIX_c( > opus_int32 *corr, /* O Result [order + 1] */ > opus_int *scale, /* O Scaling of the correlation vector */ > const opus_int16 *input, /* I Input data to correlate */ >@@ -92,4 +88,3 @@ void silk_warped_autocorrelation_FIX( > } > silk_assert( corr_QC[ 0 ] >= 0 ); /* If breaking, decrease QC*/ > } >-#endif /* OVERRIDE_silk_warped_autocorrelation_FIX */ >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/x86/prefilter_FIX_sse.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/x86/prefilter_FIX_sse.c >index 488a603f5dd0199b712fe41601edf3a38b00ae10..d8c9c2f55f066450829309802b81593bf558a4ed 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/x86/prefilter_FIX_sse.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/x86/prefilter_FIX_sse.c >@@ -107,8 +107,8 @@ void silk_warped_LPC_analysis_filter_FIX_sse4_1( > xmm_tempb = _mm_add_epi32( xmm_tempb, xmm_product2 ); > xmm_tempa = _mm_add_epi32( xmm_tempa, xmm_tempb ); > >- sum = (coef_Q13_8 * state_8) >> 16; >- sum += (coef_Q13_9 * state_9) >> 16; >+ sum = (opus_int32)((coef_Q13_8 * state_8) >> 16); >+ sum += (opus_int32)((coef_Q13_9 * state_9) >> 16); > > xmm_tempa = _mm_add_epi32( xmm_tempa, _mm_shuffle_epi32( xmm_tempa, _MM_SHUFFLE( 0, 0, 0, 2 ) ) ); > sum += _mm_cvtsi128_si32( xmm_tempa); >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/LPC_inv_pred_gain_FLP.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/LPC_inv_pred_gain_FLP.c >index 25178bacdde4610be09a31b59fff79b35f71e033..2be2122d61408afffb1dbfd8cd06723fb28229b9 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/LPC_inv_pred_gain_FLP.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/LPC_inv_pred_gain_FLP.c >@@ -31,8 +31,7 @@ POSSIBILITY OF SUCH DAMAGE. > > #include "SigProc_FIX.h" > #include "SigProc_FLP.h" >- >-#define RC_THRESHOLD 0.9999f >+#include "define.h" > > /* compute inverse of LPC prediction gain, and */ > /* test if LPC coefficients are stable (all poles within unit circle) */ >@@ -43,34 +42,32 @@ silk_float silk_LPC_inverse_pred_gain_FLP( /* O return inverse prediction ga > ) > { > opus_int k, n; >- double invGain, rc, rc_mult1, rc_mult2; >- silk_float Atmp[ 2 ][ SILK_MAX_ORDER_LPC ]; >- silk_float *Aold, *Anew; >+ double invGain, rc, rc_mult1, rc_mult2, tmp1, tmp2; >+ silk_float Atmp[ SILK_MAX_ORDER_LPC ]; > >- Anew = Atmp[ order & 1 ]; >- silk_memcpy( Anew, A, order * sizeof(silk_float) ); >+ silk_memcpy( Atmp, A, order * sizeof(silk_float) ); > > invGain = 1.0; > for( k = order - 1; k > 0; k-- ) { >- rc = -Anew[ k ]; >- if( rc > RC_THRESHOLD || rc < -RC_THRESHOLD ) { >+ rc = -Atmp[ k ]; >+ rc_mult1 = 1.0f - rc * rc; >+ invGain *= rc_mult1; >+ if( invGain * MAX_PREDICTION_POWER_GAIN < 1.0f ) { > return 0.0f; > } >- rc_mult1 = 1.0f - rc * rc; > rc_mult2 = 1.0f / rc_mult1; >- invGain *= rc_mult1; >- /* swap pointers */ >- Aold = Anew; >- Anew = Atmp[ k & 1 ]; >- for( n = 0; n < k; n++ ) { >- Anew[ n ] = (silk_float)( ( Aold[ n ] - Aold[ k - n - 1 ] * rc ) * rc_mult2 ); >+ for( n = 0; n < (k + 1) >> 1; n++ ) { >+ tmp1 = Atmp[ n ]; >+ tmp2 = Atmp[ k - n - 1 ]; >+ Atmp[ n ] = (silk_float)( ( tmp1 - tmp2 * rc ) * rc_mult2 ); >+ Atmp[ k - n - 1 ] = (silk_float)( ( tmp2 - tmp1 * rc ) * rc_mult2 ); > } > } >- rc = -Anew[ 0 ]; >- if( rc > RC_THRESHOLD || rc < -RC_THRESHOLD ) { >- return 0.0f; >- } >+ rc = -Atmp[ 0 ]; > rc_mult1 = 1.0f - rc * rc; > invGain *= rc_mult1; >+ if( invGain * MAX_PREDICTION_POWER_GAIN < 1.0f ) { >+ return 0.0f; >+ } > return (silk_float)invGain; > } >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/SigProc_FLP.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/SigProc_FLP.h >index f0cb3733be6c7865a8831b6527b1b016fd0b5672..953de8b09e37bd6924d36554102e5b9aa65a66dd 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/SigProc_FLP.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/SigProc_FLP.h >@@ -68,13 +68,6 @@ void silk_k2a_FLP( > opus_int32 order /* I prediction order */ > ); > >-/* Solve the normal equations using the Levinson-Durbin recursion */ >-silk_float silk_levinsondurbin_FLP( /* O prediction error energy */ >- silk_float A[], /* O prediction coefficients [order] */ >- const silk_float corr[], /* I input auto-correlations [order + 1] */ >- const opus_int order /* I prediction order */ >-); >- > /* compute autocorrelation */ > void silk_autocorrelation_FLP( > silk_float *results, /* O result (length correlationCount) */ >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/encode_frame_FLP.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/encode_frame_FLP.c >index 2092a4d9e24829963e479bc03ecf7afa8fd13ad9..49956a2d752c6938b30331792bb52d724a89ece2 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/encode_frame_FLP.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/encode_frame_FLP.c >@@ -29,6 +29,7 @@ POSSIBILITY OF SUCH DAMAGE. > #include "config.h" > #endif > >+#include <stdlib.h> > #include "main_FLP.h" > #include "tuning_parameters.h" > >@@ -41,21 +42,28 @@ static OPUS_INLINE void silk_LBRR_encode_FLP( > ); > > void silk_encode_do_VAD_FLP( >- silk_encoder_state_FLP *psEnc /* I/O Encoder state FLP */ >+ silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ >+ opus_int activity /* I Decision of Opus voice activity detector */ > ) > { >+ const opus_int activity_threshold = SILK_FIX_CONST( SPEECH_ACTIVITY_DTX_THRES, 8 ); >+ > /****************************/ > /* Voice Activity Detection */ > /****************************/ > silk_VAD_GetSA_Q8( &psEnc->sCmn, psEnc->sCmn.inputBuf + 1, psEnc->sCmn.arch ); >+ /* If Opus VAD is inactive and Silk VAD is active: lower Silk VAD to just under the threshold */ >+ if( activity == VAD_NO_ACTIVITY && psEnc->sCmn.speech_activity_Q8 >= activity_threshold ) { >+ psEnc->sCmn.speech_activity_Q8 = activity_threshold - 1; >+ } > > /**************************************************/ > /* Convert speech activity into VAD and DTX flags */ > /**************************************************/ >- if( psEnc->sCmn.speech_activity_Q8 < SILK_FIX_CONST( SPEECH_ACTIVITY_DTX_THRES, 8 ) ) { >+ if( psEnc->sCmn.speech_activity_Q8 < activity_threshold ) { > psEnc->sCmn.indices.signalType = TYPE_NO_VOICE_ACTIVITY; > psEnc->sCmn.noSpeechCounter++; >- if( psEnc->sCmn.noSpeechCounter < NB_SPEECH_FRAMES_BEFORE_DTX ) { >+ if( psEnc->sCmn.noSpeechCounter <= NB_SPEECH_FRAMES_BEFORE_DTX ) { > psEnc->sCmn.inDTX = 0; > } else if( psEnc->sCmn.noSpeechCounter > MAX_CONSECUTIVE_DTX + NB_SPEECH_FRAMES_BEFORE_DTX ) { > psEnc->sCmn.noSpeechCounter = NB_SPEECH_FRAMES_BEFORE_DTX; >@@ -85,7 +93,6 @@ opus_int silk_encode_frame_FLP( > silk_encoder_control_FLP sEncCtrl; > opus_int i, iter, maxIter, found_upper, found_lower, ret = 0; > silk_float *x_frame, *res_pitch_frame; >- silk_float xfw[ MAX_FRAME_LENGTH ]; > silk_float res_pitch[ 2 * MAX_FRAME_LENGTH + LA_PITCH_MAX ]; > ec_enc sRangeEnc_copy, sRangeEnc_copy2; > silk_nsq_state sNSQ_copy, sNSQ_copy2; >@@ -97,6 +104,9 @@ opus_int silk_encode_frame_FLP( > opus_int8 LastGainIndex_copy2; > opus_int32 pGains_Q16[ MAX_NB_SUBFR ]; > opus_uint8 ec_buf_copy[ 1275 ]; >+ opus_int gain_lock[ MAX_NB_SUBFR ] = {0}; >+ opus_int16 best_gain_mult[ MAX_NB_SUBFR ]; >+ opus_int best_sum[ MAX_NB_SUBFR ]; > > /* This is totally unnecessary but many compilers (including gcc) are too dumb to realise it */ > LastGainIndex_copy2 = nBits_lower = nBits_upper = gainMult_lower = gainMult_upper = 0; >@@ -139,22 +149,17 @@ opus_int silk_encode_frame_FLP( > /***************************************************/ > /* Find linear prediction coefficients (LPC + LTP) */ > /***************************************************/ >- silk_find_pred_coefs_FLP( psEnc, &sEncCtrl, res_pitch, x_frame, condCoding ); >+ silk_find_pred_coefs_FLP( psEnc, &sEncCtrl, res_pitch_frame, x_frame, condCoding ); > > /****************************************/ > /* Process gains */ > /****************************************/ > silk_process_gains_FLP( psEnc, &sEncCtrl, condCoding ); > >- /*****************************************/ >- /* Prefiltering for noise shaper */ >- /*****************************************/ >- silk_prefilter_FLP( psEnc, &sEncCtrl, xfw, x_frame ); >- > /****************************************/ > /* Low Bitrate Redundant Encoding */ > /****************************************/ >- silk_LBRR_encode_FLP( psEnc, &sEncCtrl, xfw, condCoding ); >+ silk_LBRR_encode_FLP( psEnc, &sEncCtrl, x_frame, condCoding ); > > /* Loop over quantizer and entroy coding to control bitrate */ > maxIter = 6; >@@ -188,7 +193,11 @@ opus_int silk_encode_frame_FLP( > /*****************************************/ > /* Noise shaping quantization */ > /*****************************************/ >- silk_NSQ_wrapper_FLP( psEnc, &sEncCtrl, &psEnc->sCmn.indices, &psEnc->sCmn.sNSQ, psEnc->sCmn.pulses, xfw ); >+ silk_NSQ_wrapper_FLP( psEnc, &sEncCtrl, &psEnc->sCmn.indices, &psEnc->sCmn.sNSQ, psEnc->sCmn.pulses, x_frame ); >+ >+ if ( iter == maxIter && !found_lower ) { >+ silk_memcpy( &sRangeEnc_copy2, psRangeEnc, sizeof( ec_enc ) ); >+ } > > /****************************************/ > /* Encode Parameters */ >@@ -203,6 +212,33 @@ opus_int silk_encode_frame_FLP( > > nBits = ec_tell( psRangeEnc ); > >+ /* If we still bust after the last iteration, do some damage control. */ >+ if ( iter == maxIter && !found_lower && nBits > maxBits ) { >+ silk_memcpy( psRangeEnc, &sRangeEnc_copy2, sizeof( ec_enc ) ); >+ >+ /* Keep gains the same as the last frame. */ >+ psEnc->sShape.LastGainIndex = sEncCtrl.lastGainIndexPrev; >+ for ( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) { >+ psEnc->sCmn.indices.GainsIndices[ i ] = 4; >+ } >+ if (condCoding != CODE_CONDITIONALLY) { >+ psEnc->sCmn.indices.GainsIndices[ 0 ] = sEncCtrl.lastGainIndexPrev; >+ } >+ psEnc->sCmn.ec_prevLagIndex = ec_prevLagIndex_copy; >+ psEnc->sCmn.ec_prevSignalType = ec_prevSignalType_copy; >+ /* Clear all pulses. */ >+ for ( i = 0; i < psEnc->sCmn.frame_length; i++ ) { >+ psEnc->sCmn.pulses[ i ] = 0; >+ } >+ >+ silk_encode_indices( &psEnc->sCmn, psRangeEnc, psEnc->sCmn.nFramesEncoded, 0, condCoding ); >+ >+ silk_encode_pulses( psRangeEnc, psEnc->sCmn.indices.signalType, psEnc->sCmn.indices.quantOffsetType, >+ psEnc->sCmn.pulses, psEnc->sCmn.frame_length ); >+ >+ nBits = ec_tell( psRangeEnc ); >+ } >+ > if( useCBR == 0 && iter == 0 && nBits <= maxBits ) { > break; > } >@@ -223,7 +259,9 @@ opus_int silk_encode_frame_FLP( > if( nBits > maxBits ) { > if( found_lower == 0 && iter >= 2 ) { > /* Adjust the quantizer's rate/distortion tradeoff and discard previous "upper" results */ >- sEncCtrl.Lambda *= 1.5f; >+ sEncCtrl.Lambda = silk_max_float(sEncCtrl.Lambda*1.5f, 1.5f); >+ /* Reducing dithering can help us hit the target. */ >+ psEnc->sCmn.indices.quantOffsetType = 0; > found_upper = 0; > gainsID_upper = -1; > } else { >@@ -250,15 +288,34 @@ opus_int silk_encode_frame_FLP( > break; > } > >+ if ( !found_lower && nBits > maxBits ) { >+ int j; >+ for ( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) { >+ int sum=0; >+ for ( j = i*psEnc->sCmn.subfr_length; j < (i+1)*psEnc->sCmn.subfr_length; j++ ) { >+ sum += abs( psEnc->sCmn.pulses[j] ); >+ } >+ if ( iter == 0 || (sum < best_sum[i] && !gain_lock[i]) ) { >+ best_sum[i] = sum; >+ best_gain_mult[i] = gainMult_Q8; >+ } else { >+ gain_lock[i] = 1; >+ } >+ } >+ } > if( ( found_lower & found_upper ) == 0 ) { > /* Adjust gain according to high-rate rate/distortion curve */ >- opus_int32 gain_factor_Q16; >- gain_factor_Q16 = silk_log2lin( silk_LSHIFT( nBits - maxBits, 7 ) / psEnc->sCmn.frame_length + SILK_FIX_CONST( 16, 7 ) ); >- gain_factor_Q16 = silk_min_32( gain_factor_Q16, SILK_FIX_CONST( 2, 16 ) ); > if( nBits > maxBits ) { >- gain_factor_Q16 = silk_max_32( gain_factor_Q16, SILK_FIX_CONST( 1.3, 16 ) ); >+ if (gainMult_Q8 < 16384) { >+ gainMult_Q8 *= 2; >+ } else { >+ gainMult_Q8 = 32767; >+ } >+ } else { >+ opus_int32 gain_factor_Q16; >+ gain_factor_Q16 = silk_log2lin( silk_LSHIFT( nBits - maxBits, 7 ) / psEnc->sCmn.frame_length + SILK_FIX_CONST( 16, 7 ) ); >+ gainMult_Q8 = silk_SMULWB( gain_factor_Q16, gainMult_Q8 ); > } >- gainMult_Q8 = silk_SMULWB( gain_factor_Q16, gainMult_Q8 ); > } else { > /* Adjust gain by interpolating */ > gainMult_Q8 = gainMult_lower + ( ( gainMult_upper - gainMult_lower ) * ( maxBits - nBits_lower ) ) / ( nBits_upper - nBits_lower ); >@@ -272,7 +329,13 @@ opus_int silk_encode_frame_FLP( > } > > for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) { >- pGains_Q16[ i ] = silk_LSHIFT_SAT32( silk_SMULWB( sEncCtrl.GainsUnq_Q16[ i ], gainMult_Q8 ), 8 ); >+ opus_int16 tmp; >+ if ( gain_lock[i] ) { >+ tmp = best_gain_mult[i]; >+ } else { >+ tmp = gainMult_Q8; >+ } >+ pGains_Q16[ i ] = silk_LSHIFT_SAT32( silk_SMULWB( sEncCtrl.GainsUnq_Q16[ i ], tmp ), 8 ); > } > > /* Quantize gains */ >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/energy_FLP.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/energy_FLP.c >index 24b8179f9e3b4f3c88e992cf9fd81a4d90294c76..7bc7173c9cf3f46699e89cd13db3b277ade6606a 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/energy_FLP.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/energy_FLP.c >@@ -37,13 +37,12 @@ double silk_energy_FLP( > opus_int dataSize > ) > { >- opus_int i, dataSize4; >+ opus_int i; > double result; > > /* 4x unrolled loop */ > result = 0.0; >- dataSize4 = dataSize & 0xFFFC; >- for( i = 0; i < dataSize4; i += 4 ) { >+ for( i = 0; i < dataSize - 3; i += 4 ) { > result += data[ i + 0 ] * (double)data[ i + 0 ] + > data[ i + 1 ] * (double)data[ i + 1 ] + > data[ i + 2 ] * (double)data[ i + 2 ] + >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/find_LPC_FLP.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/find_LPC_FLP.c >index fcfe1c3681eb61f4273638cc42e1e17000491ede..4d63964febb8b2932ef9cf98ffe96b396a37b826 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/find_LPC_FLP.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/find_LPC_FLP.c >@@ -73,7 +73,7 @@ void silk_find_LPC_FLP( > silk_interpolate( NLSF0_Q15, psEncC->prev_NLSFq_Q15, NLSF_Q15, k, psEncC->predictLPCOrder ); > > /* Convert to LPC for residual energy evaluation */ >- silk_NLSF2A_FLP( a_tmp, NLSF0_Q15, psEncC->predictLPCOrder ); >+ silk_NLSF2A_FLP( a_tmp, NLSF0_Q15, psEncC->predictLPCOrder, psEncC->arch ); > > /* Calculate residual energy with LSF interpolation */ > silk_LPC_analysis_filter_FLP( LPC_res, a_tmp, x, 2 * subfr_length, psEncC->predictLPCOrder ); >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/find_LTP_FLP.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/find_LTP_FLP.c >index 722999601409d3d94639226c0a1f23f19a7e4d75..f97064930e8416cfdfe952eadbb8ba74b09c8f43 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/find_LTP_FLP.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/find_LTP_FLP.c >@@ -33,100 +33,32 @@ POSSIBILITY OF SUCH DAMAGE. > #include "tuning_parameters.h" > > void silk_find_LTP_FLP( >- silk_float b[ MAX_NB_SUBFR * LTP_ORDER ], /* O LTP coefs */ >- silk_float WLTP[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* O Weight for LTP quantization */ >- silk_float *LTPredCodGain, /* O LTP coding gain */ >- const silk_float r_lpc[], /* I LPC residual */ >- const opus_int lag[ MAX_NB_SUBFR ], /* I LTP lags */ >- const silk_float Wght[ MAX_NB_SUBFR ], /* I Weights */ >+ silk_float XX[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* O Weight for LTP quantization */ >+ silk_float xX[ MAX_NB_SUBFR * LTP_ORDER ], /* O Weight for LTP quantization */ >+ const silk_float r_ptr[], /* I LPC residual */ >+ const opus_int lag[ MAX_NB_SUBFR ], /* I LTP lags */ > const opus_int subfr_length, /* I Subframe length */ >- const opus_int nb_subfr, /* I number of subframes */ >- const opus_int mem_offset /* I Number of samples in LTP memory */ >+ const opus_int nb_subfr /* I number of subframes */ > ) > { >- opus_int i, k; >- silk_float *b_ptr, temp, *WLTP_ptr; >- silk_float LPC_res_nrg, LPC_LTP_res_nrg; >- silk_float d[ MAX_NB_SUBFR ], m, g, delta_b[ LTP_ORDER ]; >- silk_float w[ MAX_NB_SUBFR ], nrg[ MAX_NB_SUBFR ], regu; >- silk_float Rr[ LTP_ORDER ], rr[ MAX_NB_SUBFR ]; >- const silk_float *r_ptr, *lag_ptr; >+ opus_int k; >+ silk_float *xX_ptr, *XX_ptr; >+ const silk_float *lag_ptr; >+ silk_float xx, temp; > >- b_ptr = b; >- WLTP_ptr = WLTP; >- r_ptr = &r_lpc[ mem_offset ]; >+ xX_ptr = xX; >+ XX_ptr = XX; > for( k = 0; k < nb_subfr; k++ ) { > lag_ptr = r_ptr - ( lag[ k ] + LTP_ORDER / 2 ); >+ silk_corrMatrix_FLP( lag_ptr, subfr_length, LTP_ORDER, XX_ptr ); >+ silk_corrVector_FLP( lag_ptr, r_ptr, subfr_length, LTP_ORDER, xX_ptr ); >+ xx = ( silk_float )silk_energy_FLP( r_ptr, subfr_length + LTP_ORDER ); >+ temp = 1.0f / silk_max( xx, LTP_CORR_INV_MAX * 0.5f * ( XX_ptr[ 0 ] + XX_ptr[ 24 ] ) + 1.0f ); >+ silk_scale_vector_FLP( XX_ptr, temp, LTP_ORDER * LTP_ORDER ); >+ silk_scale_vector_FLP( xX_ptr, temp, LTP_ORDER ); > >- silk_corrMatrix_FLP( lag_ptr, subfr_length, LTP_ORDER, WLTP_ptr ); >- silk_corrVector_FLP( lag_ptr, r_ptr, subfr_length, LTP_ORDER, Rr ); >- >- rr[ k ] = ( silk_float )silk_energy_FLP( r_ptr, subfr_length ); >- regu = 1.0f + rr[ k ] + >- matrix_ptr( WLTP_ptr, 0, 0, LTP_ORDER ) + >- matrix_ptr( WLTP_ptr, LTP_ORDER-1, LTP_ORDER-1, LTP_ORDER ); >- regu *= LTP_DAMPING / 3; >- silk_regularize_correlations_FLP( WLTP_ptr, &rr[ k ], regu, LTP_ORDER ); >- silk_solve_LDL_FLP( WLTP_ptr, LTP_ORDER, Rr, b_ptr ); >- >- /* Calculate residual energy */ >- nrg[ k ] = silk_residual_energy_covar_FLP( b_ptr, WLTP_ptr, Rr, rr[ k ], LTP_ORDER ); >- >- temp = Wght[ k ] / ( nrg[ k ] * Wght[ k ] + 0.01f * subfr_length ); >- silk_scale_vector_FLP( WLTP_ptr, temp, LTP_ORDER * LTP_ORDER ); >- w[ k ] = matrix_ptr( WLTP_ptr, LTP_ORDER / 2, LTP_ORDER / 2, LTP_ORDER ); >- >- r_ptr += subfr_length; >- b_ptr += LTP_ORDER; >- WLTP_ptr += LTP_ORDER * LTP_ORDER; >- } >- >- /* Compute LTP coding gain */ >- if( LTPredCodGain != NULL ) { >- LPC_LTP_res_nrg = 1e-6f; >- LPC_res_nrg = 0.0f; >- for( k = 0; k < nb_subfr; k++ ) { >- LPC_res_nrg += rr[ k ] * Wght[ k ]; >- LPC_LTP_res_nrg += nrg[ k ] * Wght[ k ]; >- } >- >- silk_assert( LPC_LTP_res_nrg > 0 ); >- *LTPredCodGain = 3.0f * silk_log2( LPC_res_nrg / LPC_LTP_res_nrg ); >- } >- >- /* Smoothing */ >- /* d = sum( B, 1 ); */ >- b_ptr = b; >- for( k = 0; k < nb_subfr; k++ ) { >- d[ k ] = 0; >- for( i = 0; i < LTP_ORDER; i++ ) { >- d[ k ] += b_ptr[ i ]; >- } >- b_ptr += LTP_ORDER; >- } >- /* m = ( w * d' ) / ( sum( w ) + 1e-3 ); */ >- temp = 1e-3f; >- for( k = 0; k < nb_subfr; k++ ) { >- temp += w[ k ]; >- } >- m = 0; >- for( k = 0; k < nb_subfr; k++ ) { >- m += d[ k ] * w[ k ]; >- } >- m = m / temp; >- >- b_ptr = b; >- for( k = 0; k < nb_subfr; k++ ) { >- g = LTP_SMOOTHING / ( LTP_SMOOTHING + w[ k ] ) * ( m - d[ k ] ); >- temp = 0; >- for( i = 0; i < LTP_ORDER; i++ ) { >- delta_b[ i ] = silk_max_float( b_ptr[ i ], 0.1f ); >- temp += delta_b[ i ]; >- } >- temp = g / temp; >- for( i = 0; i < LTP_ORDER; i++ ) { >- b_ptr[ i ] = b_ptr[ i ] + delta_b[ i ] * temp; >- } >- b_ptr += LTP_ORDER; >+ r_ptr += subfr_length; >+ XX_ptr += LTP_ORDER * LTP_ORDER; >+ xX_ptr += LTP_ORDER; > } > } >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/find_pred_coefs_FLP.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/find_pred_coefs_FLP.c >index 1af4fe5f1b2d1676ca2682c026d98c2e781ae50c..cb2e763b1db02bb3fd0c166f6a900d57fc23b824 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/find_pred_coefs_FLP.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/find_pred_coefs_FLP.c >@@ -41,8 +41,9 @@ void silk_find_pred_coefs_FLP( > ) > { > opus_int i; >- silk_float WLTP[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ]; >- silk_float invGains[ MAX_NB_SUBFR ], Wght[ MAX_NB_SUBFR ]; >+ silk_float XXLTP[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ]; >+ silk_float xXLTP[ MAX_NB_SUBFR * LTP_ORDER ]; >+ silk_float invGains[ MAX_NB_SUBFR ]; > opus_int16 NLSF_Q15[ MAX_LPC_ORDER ]; > const silk_float *x_ptr; > silk_float *x_pre_ptr, LPC_in_pre[ MAX_NB_SUBFR * MAX_LPC_ORDER + MAX_FRAME_LENGTH ]; >@@ -52,7 +53,6 @@ void silk_find_pred_coefs_FLP( > for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) { > silk_assert( psEncCtrl->Gains[ i ] > 0.0f ); > invGains[ i ] = 1.0f / psEncCtrl->Gains[ i ]; >- Wght[ i ] = invGains[ i ] * invGains[ i ]; > } > > if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { >@@ -62,13 +62,11 @@ void silk_find_pred_coefs_FLP( > silk_assert( psEnc->sCmn.ltp_mem_length - psEnc->sCmn.predictLPCOrder >= psEncCtrl->pitchL[ 0 ] + LTP_ORDER / 2 ); > > /* LTP analysis */ >- silk_find_LTP_FLP( psEncCtrl->LTPCoef, WLTP, &psEncCtrl->LTPredCodGain, res_pitch, >- psEncCtrl->pitchL, Wght, psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr, psEnc->sCmn.ltp_mem_length ); >+ silk_find_LTP_FLP( XXLTP, xXLTP, res_pitch, psEncCtrl->pitchL, psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr ); > > /* Quantize LTP gain parameters */ > silk_quant_LTP_gains_FLP( psEncCtrl->LTPCoef, psEnc->sCmn.indices.LTPIndex, &psEnc->sCmn.indices.PERIndex, >- &psEnc->sCmn.sum_log_gain_Q7, WLTP, psEnc->sCmn.mu_LTP_Q9, psEnc->sCmn.LTPQuantLowComplexity, psEnc->sCmn.nb_subfr, >- psEnc->sCmn.arch ); >+ &psEnc->sCmn.sum_log_gain_Q7, &psEncCtrl->LTPredCodGain, XXLTP, xXLTP, psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr, psEnc->sCmn.arch ); > > /* Control LTP scaling */ > silk_LTP_scale_ctrl_FLP( psEnc, psEncCtrl, condCoding ); >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/inner_product_FLP.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/inner_product_FLP.c >index 029c012911dadd6732ff1373fba04b296e3ac69e..cdd39d24ce9418916db346ba93ad58cf0d9fc146 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/inner_product_FLP.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/inner_product_FLP.c >@@ -38,13 +38,12 @@ double silk_inner_product_FLP( > opus_int dataSize > ) > { >- opus_int i, dataSize4; >+ opus_int i; > double result; > > /* 4x unrolled loop */ > result = 0.0; >- dataSize4 = dataSize & 0xFFFC; >- for( i = 0; i < dataSize4; i += 4 ) { >+ for( i = 0; i < dataSize - 3; i += 4 ) { > result += data1[ i + 0 ] * (double)data2[ i + 0 ] + > data1[ i + 1 ] * (double)data2[ i + 1 ] + > data1[ i + 2 ] * (double)data2[ i + 2 ] + >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/k2a_FLP.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/k2a_FLP.c >index 12af4e76697a869831b73de533e316a8859b8163..1448008dbbed139791089132b0e391b2e7e07f6b 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/k2a_FLP.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/k2a_FLP.c >@@ -39,15 +39,16 @@ void silk_k2a_FLP( > ) > { > opus_int k, n; >- silk_float Atmp[ SILK_MAX_ORDER_LPC ]; >+ silk_float rck, tmp1, tmp2; > > for( k = 0; k < order; k++ ) { >- for( n = 0; n < k; n++ ) { >- Atmp[ n ] = A[ n ]; >+ rck = rc[ k ]; >+ for( n = 0; n < (k + 1) >> 1; n++ ) { >+ tmp1 = A[ n ]; >+ tmp2 = A[ k - n - 1 ]; >+ A[ n ] = tmp1 + tmp2 * rck; >+ A[ k - n - 1 ] = tmp2 + tmp1 * rck; > } >- for( n = 0; n < k; n++ ) { >- A[ n ] += Atmp[ k - n - 1 ] * rc[ k ]; >- } >- A[ k ] = -rc[ k ]; >+ A[ k ] = -rck; > } > } >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/levinsondurbin_FLP.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/levinsondurbin_FLP.c >deleted file mode 100644 >index f0ba6069812fd32b92cbea649d9bb7e0b55a4f02..0000000000000000000000000000000000000000 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/levinsondurbin_FLP.c >+++ /dev/null >@@ -1,81 +0,0 @@ >-/*********************************************************************** >-Copyright (c) 2006-2011, Skype Limited. All rights reserved. >-Redistribution and use in source and binary forms, with or without >-modification, are permitted provided that the following conditions >-are met: >-- Redistributions of source code must retain the above copyright notice, >-this list of conditions and the following disclaimer. >-- Redistributions in binary form must reproduce the above copyright >-notice, this list of conditions and the following disclaimer in the >-documentation and/or other materials provided with the distribution. >-- Neither the name of Internet Society, IETF or IETF Trust, nor the >-names of specific contributors, may be used to endorse or promote >-products derived from this software without specific prior written >-permission. >-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" >-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE >-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE >-ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE >-LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >-INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >-CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE >-POSSIBILITY OF SUCH DAMAGE. >-***********************************************************************/ >- >-#ifdef HAVE_CONFIG_H >-#include "config.h" >-#endif >- >-#include "SigProc_FLP.h" >- >-/* Solve the normal equations using the Levinson-Durbin recursion */ >-silk_float silk_levinsondurbin_FLP( /* O prediction error energy */ >- silk_float A[], /* O prediction coefficients [order] */ >- const silk_float corr[], /* I input auto-correlations [order + 1] */ >- const opus_int order /* I prediction order */ >-) >-{ >- opus_int i, mHalf, m; >- silk_float min_nrg, nrg, t, km, Atmp1, Atmp2; >- >- min_nrg = 1e-12f * corr[ 0 ] + 1e-9f; >- nrg = corr[ 0 ]; >- nrg = silk_max_float(min_nrg, nrg); >- A[ 0 ] = corr[ 1 ] / nrg; >- nrg -= A[ 0 ] * corr[ 1 ]; >- nrg = silk_max_float(min_nrg, nrg); >- >- for( m = 1; m < order; m++ ) >- { >- t = corr[ m + 1 ]; >- for( i = 0; i < m; i++ ) { >- t -= A[ i ] * corr[ m - i ]; >- } >- >- /* reflection coefficient */ >- km = t / nrg; >- >- /* residual energy */ >- nrg -= km * t; >- nrg = silk_max_float(min_nrg, nrg); >- >- mHalf = m >> 1; >- for( i = 0; i < mHalf; i++ ) { >- Atmp1 = A[ i ]; >- Atmp2 = A[ m - i - 1 ]; >- A[ m - i - 1 ] -= km * Atmp1; >- A[ i ] -= km * Atmp2; >- } >- if( m & 1 ) { >- A[ mHalf ] -= km * A[ mHalf ]; >- } >- A[ m ] = km; >- } >- >- /* return the residual energy */ >- return nrg; >-} >- >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/main_FLP.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/main_FLP.h >index e5a75972e5f8c030a1076c65d336a7d028763c54..5dc0ccf4a413b3a2d3ec79114faa334c42b7653b 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/main_FLP.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/main_FLP.h >@@ -56,7 +56,8 @@ void silk_HP_variable_cutoff( > > /* Encoder main function */ > void silk_encode_do_VAD_FLP( >- silk_encoder_state_FLP *psEnc /* I/O Encoder state FLP */ >+ silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ >+ opus_int activity /* I Decision of Opus voice activity detector */ > ); > > /* Encoder main function */ >@@ -79,22 +80,11 @@ opus_int silk_init_encoder( > opus_int silk_control_encoder( > silk_encoder_state_FLP *psEnc, /* I/O Pointer to Silk encoder state FLP */ > silk_EncControlStruct *encControl, /* I Control structure */ >- const opus_int32 TargetRate_bps, /* I Target max bitrate (bps) */ > const opus_int allow_bw_switch, /* I Flag to allow switching audio bandwidth */ > const opus_int channelNb, /* I Channel number */ > const opus_int force_fs_kHz > ); > >-/****************/ >-/* Prefiltering */ >-/****************/ >-void silk_prefilter_FLP( >- silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ >- const silk_encoder_control_FLP *psEncCtrl, /* I Encoder control FLP */ >- silk_float xw[], /* O Weighted signal */ >- const silk_float x[] /* I Speech signal */ >-); >- > /**************************/ > /* Noise shaping analysis */ > /**************************/ >@@ -153,15 +143,12 @@ void silk_find_LPC_FLP( > > /* LTP analysis */ > void silk_find_LTP_FLP( >- silk_float b[ MAX_NB_SUBFR * LTP_ORDER ], /* O LTP coefs */ >- silk_float WLTP[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* O Weight for LTP quantization */ >- silk_float *LTPredCodGain, /* O LTP coding gain */ >- const silk_float r_lpc[], /* I LPC residual */ >+ silk_float XX[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* O Weight for LTP quantization */ >+ silk_float xX[ MAX_NB_SUBFR * LTP_ORDER ], /* O Weight for LTP quantization */ >+ const silk_float r_ptr[], /* I LPC residual */ > const opus_int lag[ MAX_NB_SUBFR ], /* I LTP lags */ >- const silk_float Wght[ MAX_NB_SUBFR ], /* I Weights */ > const opus_int subfr_length, /* I Subframe length */ >- const opus_int nb_subfr, /* I number of subframes */ >- const opus_int mem_offset /* I Number of samples in LTP memory */ >+ const opus_int nb_subfr /* I number of subframes */ > ); > > void silk_LTP_analysis_filter_FLP( >@@ -198,14 +185,15 @@ void silk_LPC_analysis_filter_FLP( > > /* LTP tap quantizer */ > void silk_quant_LTP_gains_FLP( >- silk_float B[ MAX_NB_SUBFR * LTP_ORDER ], /* I/O (Un-)quantized LTP gains */ >+ silk_float B[ MAX_NB_SUBFR * LTP_ORDER ], /* O Quantized LTP gains */ > opus_int8 cbk_index[ MAX_NB_SUBFR ], /* O Codebook index */ > opus_int8 *periodicity_index, /* O Periodicity index */ > opus_int32 *sum_log_gain_Q7, /* I/O Cumulative max prediction gain */ >- const silk_float W[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* I Error weights */ >- const opus_int mu_Q10, /* I Mu value (R/D tradeoff) */ >- const opus_int lowComplexity, /* I Flag for low complexity */ >- const opus_int nb_subfr, /* I number of subframes */ >+ silk_float *pred_gain_dB, /* O LTP prediction gain */ >+ const silk_float XX[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* I Correlation matrix */ >+ const silk_float xX[ MAX_NB_SUBFR * LTP_ORDER ], /* I Correlation vector */ >+ const opus_int subfr_len, /* I Number of samples per subframe */ >+ const opus_int nb_subfr, /* I Number of subframes */ > int arch /* I Run-time architecture */ > ); > >@@ -245,22 +233,6 @@ void silk_corrVector_FLP( > silk_float *Xt /* O X'*t correlation vector [order] */ > ); > >-/* Add noise to matrix diagonal */ >-void silk_regularize_correlations_FLP( >- silk_float *XX, /* I/O Correlation matrices */ >- silk_float *xx, /* I/O Correlation values */ >- const silk_float noise, /* I Noise energy to add */ >- const opus_int D /* I Dimension of XX */ >-); >- >-/* Function to solve linear equation Ax = b, where A is an MxM symmetric matrix */ >-void silk_solve_LDL_FLP( >- silk_float *A, /* I/O Symmetric square matrix, out: reg. */ >- const opus_int M, /* I Size of matrix */ >- const silk_float *b, /* I Pointer to b vector */ >- silk_float *x /* O Pointer to x solution vector */ >-); >- > /* Apply sine window to signal vector. */ > /* Window types: */ > /* 1 -> sine window from 0 to pi/2 */ >@@ -285,7 +257,8 @@ void silk_A2NLSF_FLP( > void silk_NLSF2A_FLP( > silk_float *pAR, /* O LPC coefficients [ LPC_order ] */ > const opus_int16 *NLSF_Q15, /* I NLSF vector [ LPC_order ] */ >- const opus_int LPC_order /* I LPC order */ >+ const opus_int LPC_order, /* I LPC order */ >+ int arch /* I Run-time architecture */ > ); > > /* Limit, stabilize, and quantize NLSFs */ >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/noise_shape_analysis_FLP.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/noise_shape_analysis_FLP.c >index 65f6ea587053819cdb141c04eb7dcf90e8ded754..cb3d8a50b7cb77095bfc2bf87359a5b71cfd3dc5 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/noise_shape_analysis_FLP.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/noise_shape_analysis_FLP.c >@@ -55,25 +55,21 @@ static OPUS_INLINE silk_float warped_gain( > /* Convert warped filter coefficients to monic pseudo-warped coefficients and limit maximum */ > /* amplitude of monic warped coefficients by using bandwidth expansion on the true coefficients */ > static OPUS_INLINE void warped_true2monic_coefs( >- silk_float *coefs_syn, >- silk_float *coefs_ana, >+ silk_float *coefs, > silk_float lambda, > silk_float limit, > opus_int order > ) { > opus_int i, iter, ind = 0; >- silk_float tmp, maxabs, chirp, gain_syn, gain_ana; >+ silk_float tmp, maxabs, chirp, gain; > > /* Convert to monic coefficients */ > for( i = order - 1; i > 0; i-- ) { >- coefs_syn[ i - 1 ] -= lambda * coefs_syn[ i ]; >- coefs_ana[ i - 1 ] -= lambda * coefs_ana[ i ]; >+ coefs[ i - 1 ] -= lambda * coefs[ i ]; > } >- gain_syn = ( 1.0f - lambda * lambda ) / ( 1.0f + lambda * coefs_syn[ 0 ] ); >- gain_ana = ( 1.0f - lambda * lambda ) / ( 1.0f + lambda * coefs_ana[ 0 ] ); >+ gain = ( 1.0f - lambda * lambda ) / ( 1.0f + lambda * coefs[ 0 ] ); > for( i = 0; i < order; i++ ) { >- coefs_syn[ i ] *= gain_syn; >- coefs_ana[ i ] *= gain_ana; >+ coefs[ i ] *= gain; > } > > /* Limit */ >@@ -81,7 +77,7 @@ static OPUS_INLINE void warped_true2monic_coefs( > /* Find maximum absolute value */ > maxabs = -1.0f; > for( i = 0; i < order; i++ ) { >- tmp = silk_max( silk_abs_float( coefs_syn[ i ] ), silk_abs_float( coefs_ana[ i ] ) ); >+ tmp = silk_abs_float( coefs[ i ] ); > if( tmp > maxabs ) { > maxabs = tmp; > ind = i; >@@ -94,36 +90,59 @@ static OPUS_INLINE void warped_true2monic_coefs( > > /* Convert back to true warped coefficients */ > for( i = 1; i < order; i++ ) { >- coefs_syn[ i - 1 ] += lambda * coefs_syn[ i ]; >- coefs_ana[ i - 1 ] += lambda * coefs_ana[ i ]; >+ coefs[ i - 1 ] += lambda * coefs[ i ]; > } >- gain_syn = 1.0f / gain_syn; >- gain_ana = 1.0f / gain_ana; >+ gain = 1.0f / gain; > for( i = 0; i < order; i++ ) { >- coefs_syn[ i ] *= gain_syn; >- coefs_ana[ i ] *= gain_ana; >+ coefs[ i ] *= gain; > } > > /* Apply bandwidth expansion */ > chirp = 0.99f - ( 0.8f + 0.1f * iter ) * ( maxabs - limit ) / ( maxabs * ( ind + 1 ) ); >- silk_bwexpander_FLP( coefs_syn, order, chirp ); >- silk_bwexpander_FLP( coefs_ana, order, chirp ); >+ silk_bwexpander_FLP( coefs, order, chirp ); > > /* Convert to monic warped coefficients */ > for( i = order - 1; i > 0; i-- ) { >- coefs_syn[ i - 1 ] -= lambda * coefs_syn[ i ]; >- coefs_ana[ i - 1 ] -= lambda * coefs_ana[ i ]; >+ coefs[ i - 1 ] -= lambda * coefs[ i ]; > } >- gain_syn = ( 1.0f - lambda * lambda ) / ( 1.0f + lambda * coefs_syn[ 0 ] ); >- gain_ana = ( 1.0f - lambda * lambda ) / ( 1.0f + lambda * coefs_ana[ 0 ] ); >+ gain = ( 1.0f - lambda * lambda ) / ( 1.0f + lambda * coefs[ 0 ] ); > for( i = 0; i < order; i++ ) { >- coefs_syn[ i ] *= gain_syn; >- coefs_ana[ i ] *= gain_ana; >+ coefs[ i ] *= gain; > } > } > silk_assert( 0 ); > } > >+static OPUS_INLINE void limit_coefs( >+ silk_float *coefs, >+ silk_float limit, >+ opus_int order >+) { >+ opus_int i, iter, ind = 0; >+ silk_float tmp, maxabs, chirp; >+ >+ for( iter = 0; iter < 10; iter++ ) { >+ /* Find maximum absolute value */ >+ maxabs = -1.0f; >+ for( i = 0; i < order; i++ ) { >+ tmp = silk_abs_float( coefs[ i ] ); >+ if( tmp > maxabs ) { >+ maxabs = tmp; >+ ind = i; >+ } >+ } >+ if( maxabs <= limit ) { >+ /* Coefficients are within range - done */ >+ return; >+ } >+ >+ /* Apply bandwidth expansion */ >+ chirp = 0.99f - ( 0.8f + 0.1f * iter ) * ( maxabs - limit ) / ( maxabs * ( ind + 1 ) ); >+ silk_bwexpander_FLP( coefs, order, chirp ); >+ } >+ silk_assert( 0 ); >+} >+ > /* Compute noise shaping coefficients and initial gain values */ > void silk_noise_shape_analysis_FLP( > silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ >@@ -133,12 +152,13 @@ void silk_noise_shape_analysis_FLP( > ) > { > silk_shape_state_FLP *psShapeSt = &psEnc->sShape; >- opus_int k, nSamples; >- silk_float SNR_adj_dB, HarmBoost, HarmShapeGain, Tilt; >- silk_float nrg, pre_nrg, log_energy, log_energy_prev, energy_variation; >- silk_float delta, BWExp1, BWExp2, gain_mult, gain_add, strength, b, warping; >+ opus_int k, nSamples, nSegs; >+ silk_float SNR_adj_dB, HarmShapeGain, Tilt; >+ silk_float nrg, log_energy, log_energy_prev, energy_variation; >+ silk_float BWExp, gain_mult, gain_add, strength, b, warping; > silk_float x_windowed[ SHAPE_LPC_WIN_MAX ]; > silk_float auto_corr[ MAX_SHAPE_LPC_ORDER + 1 ]; >+ silk_float rc[ MAX_SHAPE_LPC_ORDER + 1 ]; > const silk_float *x_ptr, *pitch_res_ptr; > > /* Point to start of first LPC analysis block */ >@@ -176,14 +196,14 @@ void silk_noise_shape_analysis_FLP( > if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { > /* Initially set to 0; may be overruled in process_gains(..) */ > psEnc->sCmn.indices.quantOffsetType = 0; >- psEncCtrl->sparseness = 0.0f; > } else { > /* Sparseness measure, based on relative fluctuations of energy per 2 milliseconds */ > nSamples = 2 * psEnc->sCmn.fs_kHz; > energy_variation = 0.0f; > log_energy_prev = 0.0f; > pitch_res_ptr = pitch_res; >- for( k = 0; k < silk_SMULBB( SUB_FRAME_LENGTH_MS, psEnc->sCmn.nb_subfr ) / 2; k++ ) { >+ nSegs = silk_SMULBB( SUB_FRAME_LENGTH_MS, psEnc->sCmn.nb_subfr ) / 2; >+ for( k = 0; k < nSegs; k++ ) { > nrg = ( silk_float )nSamples + ( silk_float )silk_energy_FLP( pitch_res_ptr, nSamples ); > log_energy = silk_log2( nrg ); > if( k > 0 ) { >@@ -192,17 +212,13 @@ void silk_noise_shape_analysis_FLP( > log_energy_prev = log_energy; > pitch_res_ptr += nSamples; > } >- psEncCtrl->sparseness = silk_sigmoid( 0.4f * ( energy_variation - 5.0f ) ); > > /* Set quantization offset depending on sparseness measure */ >- if( psEncCtrl->sparseness > SPARSENESS_THRESHOLD_QNT_OFFSET ) { >+ if( energy_variation > ENERGY_VARIATION_THRESHOLD_QNT_OFFSET * (nSegs-1) ) { > psEnc->sCmn.indices.quantOffsetType = 0; > } else { > psEnc->sCmn.indices.quantOffsetType = 1; > } >- >- /* Increase coding SNR for sparse signals */ >- SNR_adj_dB += SPARSE_SNR_INCR_dB * ( psEncCtrl->sparseness - 0.5f ); > } > > /*******************************/ >@@ -210,19 +226,10 @@ void silk_noise_shape_analysis_FLP( > /*******************************/ > /* More BWE for signals with high prediction gain */ > strength = FIND_PITCH_WHITE_NOISE_FRACTION * psEncCtrl->predGain; /* between 0.0 and 1.0 */ >- BWExp1 = BWExp2 = BANDWIDTH_EXPANSION / ( 1.0f + strength * strength ); >- delta = LOW_RATE_BANDWIDTH_EXPANSION_DELTA * ( 1.0f - 0.75f * psEncCtrl->coding_quality ); >- BWExp1 -= delta; >- BWExp2 += delta; >- /* BWExp1 will be applied after BWExp2, so make it relative */ >- BWExp1 /= BWExp2; >- >- if( psEnc->sCmn.warping_Q16 > 0 ) { >- /* Slightly more warping in analysis will move quantization noise up in frequency, where it's better masked */ >- warping = (silk_float)psEnc->sCmn.warping_Q16 / 65536.0f + 0.01f * psEncCtrl->coding_quality; >- } else { >- warping = 0.0f; >- } >+ BWExp = BANDWIDTH_EXPANSION / ( 1.0f + strength * strength ); >+ >+ /* Slightly more warping in analysis will move quantization noise up in frequency, where it's better masked */ >+ warping = (silk_float)psEnc->sCmn.warping_Q16 / 65536.0f + 0.01f * psEncCtrl->coding_quality; > > /********************************************/ > /* Compute noise shaping AR coefs and gains */ >@@ -252,37 +259,28 @@ void silk_noise_shape_analysis_FLP( > } > > /* Add white noise, as a fraction of energy */ >- auto_corr[ 0 ] += auto_corr[ 0 ] * SHAPE_WHITE_NOISE_FRACTION; >+ auto_corr[ 0 ] += auto_corr[ 0 ] * SHAPE_WHITE_NOISE_FRACTION + 1.0f; > > /* Convert correlations to prediction coefficients, and compute residual energy */ >- nrg = silk_levinsondurbin_FLP( &psEncCtrl->AR2[ k * MAX_SHAPE_LPC_ORDER ], auto_corr, psEnc->sCmn.shapingLPCOrder ); >+ nrg = silk_schur_FLP( rc, auto_corr, psEnc->sCmn.shapingLPCOrder ); >+ silk_k2a_FLP( &psEncCtrl->AR[ k * MAX_SHAPE_LPC_ORDER ], rc, psEnc->sCmn.shapingLPCOrder ); > psEncCtrl->Gains[ k ] = ( silk_float )sqrt( nrg ); > > if( psEnc->sCmn.warping_Q16 > 0 ) { > /* Adjust gain for warping */ >- psEncCtrl->Gains[ k ] *= warped_gain( &psEncCtrl->AR2[ k * MAX_SHAPE_LPC_ORDER ], warping, psEnc->sCmn.shapingLPCOrder ); >+ psEncCtrl->Gains[ k ] *= warped_gain( &psEncCtrl->AR[ k * MAX_SHAPE_LPC_ORDER ], warping, psEnc->sCmn.shapingLPCOrder ); > } > > /* Bandwidth expansion for synthesis filter shaping */ >- silk_bwexpander_FLP( &psEncCtrl->AR2[ k * MAX_SHAPE_LPC_ORDER ], psEnc->sCmn.shapingLPCOrder, BWExp2 ); >- >- /* Compute noise shaping filter coefficients */ >- silk_memcpy( >- &psEncCtrl->AR1[ k * MAX_SHAPE_LPC_ORDER ], >- &psEncCtrl->AR2[ k * MAX_SHAPE_LPC_ORDER ], >- psEnc->sCmn.shapingLPCOrder * sizeof( silk_float ) ); >+ silk_bwexpander_FLP( &psEncCtrl->AR[ k * MAX_SHAPE_LPC_ORDER ], psEnc->sCmn.shapingLPCOrder, BWExp ); > >- /* Bandwidth expansion for analysis filter shaping */ >- silk_bwexpander_FLP( &psEncCtrl->AR1[ k * MAX_SHAPE_LPC_ORDER ], psEnc->sCmn.shapingLPCOrder, BWExp1 ); >- >- /* Ratio of prediction gains, in energy domain */ >- pre_nrg = silk_LPC_inverse_pred_gain_FLP( &psEncCtrl->AR2[ k * MAX_SHAPE_LPC_ORDER ], psEnc->sCmn.shapingLPCOrder ); >- nrg = silk_LPC_inverse_pred_gain_FLP( &psEncCtrl->AR1[ k * MAX_SHAPE_LPC_ORDER ], psEnc->sCmn.shapingLPCOrder ); >- psEncCtrl->GainsPre[ k ] = 1.0f - 0.7f * ( 1.0f - pre_nrg / nrg ); >- >- /* Convert to monic warped prediction coefficients and limit absolute values */ >- warped_true2monic_coefs( &psEncCtrl->AR2[ k * MAX_SHAPE_LPC_ORDER ], &psEncCtrl->AR1[ k * MAX_SHAPE_LPC_ORDER ], >- warping, 3.999f, psEnc->sCmn.shapingLPCOrder ); >+ if( psEnc->sCmn.warping_Q16 > 0 ) { >+ /* Convert to monic warped prediction coefficients and limit absolute values */ >+ warped_true2monic_coefs( &psEncCtrl->AR[ k * MAX_SHAPE_LPC_ORDER ], warping, 3.999f, psEnc->sCmn.shapingLPCOrder ); >+ } else { >+ /* Limit absolute values */ >+ limit_coefs( &psEncCtrl->AR[ k * MAX_SHAPE_LPC_ORDER ], 3.999f, psEnc->sCmn.shapingLPCOrder ); >+ } > } > > /*****************/ >@@ -296,11 +294,6 @@ void silk_noise_shape_analysis_FLP( > psEncCtrl->Gains[ k ] += gain_add; > } > >- gain_mult = 1.0f + INPUT_TILT + psEncCtrl->coding_quality * HIGH_RATE_INPUT_TILT; >- for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { >- psEncCtrl->GainsPre[ k ] *= gain_mult; >- } >- > /************************************************/ > /* Control low-frequency shaping and noise tilt */ > /************************************************/ >@@ -331,12 +324,6 @@ void silk_noise_shape_analysis_FLP( > /****************************/ > /* HARMONIC SHAPING CONTROL */ > /****************************/ >- /* Control boosting of harmonic frequencies */ >- HarmBoost = LOW_RATE_HARMONIC_BOOST * ( 1.0f - psEncCtrl->coding_quality ) * psEnc->LTPCorr; >- >- /* More harmonic boost for noisy input signals */ >- HarmBoost += LOW_INPUT_QUALITY_HARMONIC_BOOST * ( 1.0f - psEncCtrl->input_quality ); >- > if( USE_HARM_SHAPING && psEnc->sCmn.indices.signalType == TYPE_VOICED ) { > /* Harmonic noise shaping */ > HarmShapeGain = HARMONIC_SHAPING; >@@ -355,8 +342,6 @@ void silk_noise_shape_analysis_FLP( > /* Smooth over subframes */ > /*************************/ > for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { >- psShapeSt->HarmBoost_smth += SUBFR_SMTH_COEF * ( HarmBoost - psShapeSt->HarmBoost_smth ); >- psEncCtrl->HarmBoost[ k ] = psShapeSt->HarmBoost_smth; > psShapeSt->HarmShapeGain_smth += SUBFR_SMTH_COEF * ( HarmShapeGain - psShapeSt->HarmShapeGain_smth ); > psEncCtrl->HarmShapeGain[ k ] = psShapeSt->HarmShapeGain_smth; > psShapeSt->Tilt_smth += SUBFR_SMTH_COEF * ( Tilt - psShapeSt->Tilt_smth ); >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/pitch_analysis_core_FLP.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/pitch_analysis_core_FLP.c >index d0e637a29dc95d5e63ade14d98f9e3f4ce7e0bd8..b37169378b1f525660fccef65f8a2fb431ecc809 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/pitch_analysis_core_FLP.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/pitch_analysis_core_FLP.c >@@ -159,7 +159,7 @@ opus_int silk_pitch_analysis_core_FLP( /* O Voicing estimate: 0 voiced, > > /* Low-pass filter */ > for( i = frame_length_4kHz - 1; i > 0; i-- ) { >- frame_4kHz[ i ] += frame_4kHz[ i - 1 ]; >+ frame_4kHz[ i ] = silk_ADD_SAT16( frame_4kHz[ i ], frame_4kHz[ i - 1 ] ); > } > > /****************************************************************************** >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/prefilter_FLP.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/prefilter_FLP.c >deleted file mode 100644 >index 8bc32fb41040ef7b4f0f1224689bb0b0448ec050..0000000000000000000000000000000000000000 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/prefilter_FLP.c >+++ /dev/null >@@ -1,206 +0,0 @@ >-/*********************************************************************** >-Copyright (c) 2006-2011, Skype Limited. All rights reserved. >-Redistribution and use in source and binary forms, with or without >-modification, are permitted provided that the following conditions >-are met: >-- Redistributions of source code must retain the above copyright notice, >-this list of conditions and the following disclaimer. >-- Redistributions in binary form must reproduce the above copyright >-notice, this list of conditions and the following disclaimer in the >-documentation and/or other materials provided with the distribution. >-- Neither the name of Internet Society, IETF or IETF Trust, nor the >-names of specific contributors, may be used to endorse or promote >-products derived from this software without specific prior written >-permission. >-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" >-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE >-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE >-ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE >-LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >-INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >-CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE >-POSSIBILITY OF SUCH DAMAGE. >-***********************************************************************/ >- >-#ifdef HAVE_CONFIG_H >-#include "config.h" >-#endif >- >-#include "main_FLP.h" >-#include "tuning_parameters.h" >- >-/* >-* Prefilter for finding Quantizer input signal >-*/ >-static OPUS_INLINE void silk_prefilt_FLP( >- silk_prefilter_state_FLP *P, /* I/O state */ >- silk_float st_res[], /* I */ >- silk_float xw[], /* O */ >- silk_float *HarmShapeFIR, /* I */ >- silk_float Tilt, /* I */ >- silk_float LF_MA_shp, /* I */ >- silk_float LF_AR_shp, /* I */ >- opus_int lag, /* I */ >- opus_int length /* I */ >-); >- >-static void silk_warped_LPC_analysis_filter_FLP( >- silk_float state[], /* I/O State [order + 1] */ >- silk_float res[], /* O Residual signal [length] */ >- const silk_float coef[], /* I Coefficients [order] */ >- const silk_float input[], /* I Input signal [length] */ >- const silk_float lambda, /* I Warping factor */ >- const opus_int length, /* I Length of input signal */ >- const opus_int order /* I Filter order (even) */ >-) >-{ >- opus_int n, i; >- silk_float acc, tmp1, tmp2; >- >- /* Order must be even */ >- silk_assert( ( order & 1 ) == 0 ); >- >- for( n = 0; n < length; n++ ) { >- /* Output of lowpass section */ >- tmp2 = state[ 0 ] + lambda * state[ 1 ]; >- state[ 0 ] = input[ n ]; >- /* Output of allpass section */ >- tmp1 = state[ 1 ] + lambda * ( state[ 2 ] - tmp2 ); >- state[ 1 ] = tmp2; >- acc = coef[ 0 ] * tmp2; >- /* Loop over allpass sections */ >- for( i = 2; i < order; i += 2 ) { >- /* Output of allpass section */ >- tmp2 = state[ i ] + lambda * ( state[ i + 1 ] - tmp1 ); >- state[ i ] = tmp1; >- acc += coef[ i - 1 ] * tmp1; >- /* Output of allpass section */ >- tmp1 = state[ i + 1 ] + lambda * ( state[ i + 2 ] - tmp2 ); >- state[ i + 1 ] = tmp2; >- acc += coef[ i ] * tmp2; >- } >- state[ order ] = tmp1; >- acc += coef[ order - 1 ] * tmp1; >- res[ n ] = input[ n ] - acc; >- } >-} >- >-/* >-* silk_prefilter. Main prefilter function >-*/ >-void silk_prefilter_FLP( >- silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */ >- const silk_encoder_control_FLP *psEncCtrl, /* I Encoder control FLP */ >- silk_float xw[], /* O Weighted signal */ >- const silk_float x[] /* I Speech signal */ >-) >-{ >- silk_prefilter_state_FLP *P = &psEnc->sPrefilt; >- opus_int j, k, lag; >- silk_float HarmShapeGain, Tilt, LF_MA_shp, LF_AR_shp; >- silk_float B[ 2 ]; >- const silk_float *AR1_shp; >- const silk_float *px; >- silk_float *pxw; >- silk_float HarmShapeFIR[ 3 ]; >- silk_float st_res[ MAX_SUB_FRAME_LENGTH + MAX_LPC_ORDER ]; >- >- /* Set up pointers */ >- px = x; >- pxw = xw; >- lag = P->lagPrev; >- for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { >- /* Update Variables that change per sub frame */ >- if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { >- lag = psEncCtrl->pitchL[ k ]; >- } >- >- /* Noise shape parameters */ >- HarmShapeGain = psEncCtrl->HarmShapeGain[ k ] * ( 1.0f - psEncCtrl->HarmBoost[ k ] ); >- HarmShapeFIR[ 0 ] = 0.25f * HarmShapeGain; >- HarmShapeFIR[ 1 ] = 32767.0f / 65536.0f * HarmShapeGain; >- HarmShapeFIR[ 2 ] = 0.25f * HarmShapeGain; >- Tilt = psEncCtrl->Tilt[ k ]; >- LF_MA_shp = psEncCtrl->LF_MA_shp[ k ]; >- LF_AR_shp = psEncCtrl->LF_AR_shp[ k ]; >- AR1_shp = &psEncCtrl->AR1[ k * MAX_SHAPE_LPC_ORDER ]; >- >- /* Short term FIR filtering */ >- silk_warped_LPC_analysis_filter_FLP( P->sAR_shp, st_res, AR1_shp, px, >- (silk_float)psEnc->sCmn.warping_Q16 / 65536.0f, psEnc->sCmn.subfr_length, psEnc->sCmn.shapingLPCOrder ); >- >- /* Reduce (mainly) low frequencies during harmonic emphasis */ >- B[ 0 ] = psEncCtrl->GainsPre[ k ]; >- B[ 1 ] = -psEncCtrl->GainsPre[ k ] * >- ( psEncCtrl->HarmBoost[ k ] * HarmShapeGain + INPUT_TILT + psEncCtrl->coding_quality * HIGH_RATE_INPUT_TILT ); >- pxw[ 0 ] = B[ 0 ] * st_res[ 0 ] + B[ 1 ] * P->sHarmHP; >- for( j = 1; j < psEnc->sCmn.subfr_length; j++ ) { >- pxw[ j ] = B[ 0 ] * st_res[ j ] + B[ 1 ] * st_res[ j - 1 ]; >- } >- P->sHarmHP = st_res[ psEnc->sCmn.subfr_length - 1 ]; >- >- silk_prefilt_FLP( P, pxw, pxw, HarmShapeFIR, Tilt, LF_MA_shp, LF_AR_shp, lag, psEnc->sCmn.subfr_length ); >- >- px += psEnc->sCmn.subfr_length; >- pxw += psEnc->sCmn.subfr_length; >- } >- P->lagPrev = psEncCtrl->pitchL[ psEnc->sCmn.nb_subfr - 1 ]; >-} >- >-/* >-* Prefilter for finding Quantizer input signal >-*/ >-static OPUS_INLINE void silk_prefilt_FLP( >- silk_prefilter_state_FLP *P, /* I/O state */ >- silk_float st_res[], /* I */ >- silk_float xw[], /* O */ >- silk_float *HarmShapeFIR, /* I */ >- silk_float Tilt, /* I */ >- silk_float LF_MA_shp, /* I */ >- silk_float LF_AR_shp, /* I */ >- opus_int lag, /* I */ >- opus_int length /* I */ >-) >-{ >- opus_int i; >- opus_int idx, LTP_shp_buf_idx; >- silk_float n_Tilt, n_LF, n_LTP; >- silk_float sLF_AR_shp, sLF_MA_shp; >- silk_float *LTP_shp_buf; >- >- /* To speed up use temp variables instead of using the struct */ >- LTP_shp_buf = P->sLTP_shp; >- LTP_shp_buf_idx = P->sLTP_shp_buf_idx; >- sLF_AR_shp = P->sLF_AR_shp; >- sLF_MA_shp = P->sLF_MA_shp; >- >- for( i = 0; i < length; i++ ) { >- if( lag > 0 ) { >- silk_assert( HARM_SHAPE_FIR_TAPS == 3 ); >- idx = lag + LTP_shp_buf_idx; >- n_LTP = LTP_shp_buf[ ( idx - HARM_SHAPE_FIR_TAPS / 2 - 1) & LTP_MASK ] * HarmShapeFIR[ 0 ]; >- n_LTP += LTP_shp_buf[ ( idx - HARM_SHAPE_FIR_TAPS / 2 ) & LTP_MASK ] * HarmShapeFIR[ 1 ]; >- n_LTP += LTP_shp_buf[ ( idx - HARM_SHAPE_FIR_TAPS / 2 + 1) & LTP_MASK ] * HarmShapeFIR[ 2 ]; >- } else { >- n_LTP = 0; >- } >- >- n_Tilt = sLF_AR_shp * Tilt; >- n_LF = sLF_AR_shp * LF_AR_shp + sLF_MA_shp * LF_MA_shp; >- >- sLF_AR_shp = st_res[ i ] - n_Tilt; >- sLF_MA_shp = sLF_AR_shp - n_LF; >- >- LTP_shp_buf_idx = ( LTP_shp_buf_idx - 1 ) & LTP_MASK; >- LTP_shp_buf[ LTP_shp_buf_idx ] = sLF_MA_shp; >- >- xw[ i ] = sLF_MA_shp - n_LTP; >- } >- /* Copy temp variable back to state */ >- P->sLF_AR_shp = sLF_AR_shp; >- P->sLF_MA_shp = sLF_MA_shp; >- P->sLTP_shp_buf_idx = LTP_shp_buf_idx; >-} >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/schur_FLP.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/schur_FLP.c >index ee436f8351c8adf1ee36fa5052612ccf462a55ae..c1e0bbb5411c9959ca3f7f6c29577136170481dd 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/schur_FLP.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/schur_FLP.c >@@ -38,22 +38,23 @@ silk_float silk_schur_FLP( /* O returns residual energy > ) > { > opus_int k, n; >- silk_float C[ SILK_MAX_ORDER_LPC + 1 ][ 2 ]; >- silk_float Ctmp1, Ctmp2, rc_tmp; >+ double C[ SILK_MAX_ORDER_LPC + 1 ][ 2 ]; >+ double Ctmp1, Ctmp2, rc_tmp; > >- silk_assert( order==6||order==8||order==10||order==12||order==14||order==16 ); >+ silk_assert( order >= 0 && order <= SILK_MAX_ORDER_LPC ); > > /* Copy correlations */ >- for( k = 0; k < order+1; k++ ) { >+ k = 0; >+ do { > C[ k ][ 0 ] = C[ k ][ 1 ] = auto_corr[ k ]; >- } >+ } while( ++k <= order ); > > for( k = 0; k < order; k++ ) { > /* Get reflection coefficient */ > rc_tmp = -C[ k + 1 ][ 0 ] / silk_max_float( C[ 0 ][ 1 ], 1e-9f ); > > /* Save the output */ >- refl_coef[ k ] = rc_tmp; >+ refl_coef[ k ] = (silk_float)rc_tmp; > > /* Update correlations */ > for( n = 0; n < order - k; n++ ) { >@@ -65,6 +66,5 @@ silk_float silk_schur_FLP( /* O returns residual energy > } > > /* Return residual energy */ >- return C[ 0 ][ 1 ]; >+ return (silk_float)C[ 0 ][ 1 ]; > } >- >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/solve_LS_FLP.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/solve_LS_FLP.c >deleted file mode 100644 >index 7c90d665a0f0d18b573b632a9328560511bf2a81..0000000000000000000000000000000000000000 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/solve_LS_FLP.c >+++ /dev/null >@@ -1,207 +0,0 @@ >-/*********************************************************************** >-Copyright (c) 2006-2011, Skype Limited. All rights reserved. >-Redistribution and use in source and binary forms, with or without >-modification, are permitted provided that the following conditions >-are met: >-- Redistributions of source code must retain the above copyright notice, >-this list of conditions and the following disclaimer. >-- Redistributions in binary form must reproduce the above copyright >-notice, this list of conditions and the following disclaimer in the >-documentation and/or other materials provided with the distribution. >-- Neither the name of Internet Society, IETF or IETF Trust, nor the >-names of specific contributors, may be used to endorse or promote >-products derived from this software without specific prior written >-permission. >-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" >-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE >-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE >-ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE >-LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >-INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >-CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE >-POSSIBILITY OF SUCH DAMAGE. >-***********************************************************************/ >- >-#ifdef HAVE_CONFIG_H >-#include "config.h" >-#endif >- >-#include "main_FLP.h" >-#include "tuning_parameters.h" >- >-/********************************************************************** >- * LDL Factorisation. Finds the upper triangular matrix L and the diagonal >- * Matrix D (only the diagonal elements returned in a vector)such that >- * the symmetric matric A is given by A = L*D*L'. >- **********************************************************************/ >-static OPUS_INLINE void silk_LDL_FLP( >- silk_float *A, /* I/O Pointer to Symetric Square Matrix */ >- opus_int M, /* I Size of Matrix */ >- silk_float *L, /* I/O Pointer to Square Upper triangular Matrix */ >- silk_float *Dinv /* I/O Pointer to vector holding the inverse diagonal elements of D */ >-); >- >-/********************************************************************** >- * Function to solve linear equation Ax = b, when A is a MxM lower >- * triangular matrix, with ones on the diagonal. >- **********************************************************************/ >-static OPUS_INLINE void silk_SolveWithLowerTriangularWdiagOnes_FLP( >- const silk_float *L, /* I Pointer to Lower Triangular Matrix */ >- opus_int M, /* I Dim of Matrix equation */ >- const silk_float *b, /* I b Vector */ >- silk_float *x /* O x Vector */ >-); >- >-/********************************************************************** >- * Function to solve linear equation (A^T)x = b, when A is a MxM lower >- * triangular, with ones on the diagonal. (ie then A^T is upper triangular) >- **********************************************************************/ >-static OPUS_INLINE void silk_SolveWithUpperTriangularFromLowerWdiagOnes_FLP( >- const silk_float *L, /* I Pointer to Lower Triangular Matrix */ >- opus_int M, /* I Dim of Matrix equation */ >- const silk_float *b, /* I b Vector */ >- silk_float *x /* O x Vector */ >-); >- >-/********************************************************************** >- * Function to solve linear equation Ax = b, when A is a MxM >- * symmetric square matrix - using LDL factorisation >- **********************************************************************/ >-void silk_solve_LDL_FLP( >- silk_float *A, /* I/O Symmetric square matrix, out: reg. */ >- const opus_int M, /* I Size of matrix */ >- const silk_float *b, /* I Pointer to b vector */ >- silk_float *x /* O Pointer to x solution vector */ >-) >-{ >- opus_int i; >- silk_float L[ MAX_MATRIX_SIZE ][ MAX_MATRIX_SIZE ]; >- silk_float T[ MAX_MATRIX_SIZE ]; >- silk_float Dinv[ MAX_MATRIX_SIZE ]; /* inverse diagonal elements of D*/ >- >- silk_assert( M <= MAX_MATRIX_SIZE ); >- >- /*************************************************** >- Factorize A by LDL such that A = L*D*(L^T), >- where L is lower triangular with ones on diagonal >- ****************************************************/ >- silk_LDL_FLP( A, M, &L[ 0 ][ 0 ], Dinv ); >- >- /**************************************************** >- * substitute D*(L^T) = T. ie: >- L*D*(L^T)*x = b => L*T = b <=> T = inv(L)*b >- ******************************************************/ >- silk_SolveWithLowerTriangularWdiagOnes_FLP( &L[ 0 ][ 0 ], M, b, T ); >- >- /**************************************************** >- D*(L^T)*x = T <=> (L^T)*x = inv(D)*T, because D is >- diagonal just multiply with 1/d_i >- ****************************************************/ >- for( i = 0; i < M; i++ ) { >- T[ i ] = T[ i ] * Dinv[ i ]; >- } >- /**************************************************** >- x = inv(L') * inv(D) * T >- *****************************************************/ >- silk_SolveWithUpperTriangularFromLowerWdiagOnes_FLP( &L[ 0 ][ 0 ], M, T, x ); >-} >- >-static OPUS_INLINE void silk_SolveWithUpperTriangularFromLowerWdiagOnes_FLP( >- const silk_float *L, /* I Pointer to Lower Triangular Matrix */ >- opus_int M, /* I Dim of Matrix equation */ >- const silk_float *b, /* I b Vector */ >- silk_float *x /* O x Vector */ >-) >-{ >- opus_int i, j; >- silk_float temp; >- const silk_float *ptr1; >- >- for( i = M - 1; i >= 0; i-- ) { >- ptr1 = matrix_adr( L, 0, i, M ); >- temp = 0; >- for( j = M - 1; j > i ; j-- ) { >- temp += ptr1[ j * M ] * x[ j ]; >- } >- temp = b[ i ] - temp; >- x[ i ] = temp; >- } >-} >- >-static OPUS_INLINE void silk_SolveWithLowerTriangularWdiagOnes_FLP( >- const silk_float *L, /* I Pointer to Lower Triangular Matrix */ >- opus_int M, /* I Dim of Matrix equation */ >- const silk_float *b, /* I b Vector */ >- silk_float *x /* O x Vector */ >-) >-{ >- opus_int i, j; >- silk_float temp; >- const silk_float *ptr1; >- >- for( i = 0; i < M; i++ ) { >- ptr1 = matrix_adr( L, i, 0, M ); >- temp = 0; >- for( j = 0; j < i; j++ ) { >- temp += ptr1[ j ] * x[ j ]; >- } >- temp = b[ i ] - temp; >- x[ i ] = temp; >- } >-} >- >-static OPUS_INLINE void silk_LDL_FLP( >- silk_float *A, /* I/O Pointer to Symetric Square Matrix */ >- opus_int M, /* I Size of Matrix */ >- silk_float *L, /* I/O Pointer to Square Upper triangular Matrix */ >- silk_float *Dinv /* I/O Pointer to vector holding the inverse diagonal elements of D */ >-) >-{ >- opus_int i, j, k, loop_count, err = 1; >- silk_float *ptr1, *ptr2; >- double temp, diag_min_value; >- silk_float v[ MAX_MATRIX_SIZE ], D[ MAX_MATRIX_SIZE ]; /* temp arrays*/ >- >- silk_assert( M <= MAX_MATRIX_SIZE ); >- >- diag_min_value = FIND_LTP_COND_FAC * 0.5f * ( A[ 0 ] + A[ M * M - 1 ] ); >- for( loop_count = 0; loop_count < M && err == 1; loop_count++ ) { >- err = 0; >- for( j = 0; j < M; j++ ) { >- ptr1 = matrix_adr( L, j, 0, M ); >- temp = matrix_ptr( A, j, j, M ); /* element in row j column j*/ >- for( i = 0; i < j; i++ ) { >- v[ i ] = ptr1[ i ] * D[ i ]; >- temp -= ptr1[ i ] * v[ i ]; >- } >- if( temp < diag_min_value ) { >- /* Badly conditioned matrix: add white noise and run again */ >- temp = ( loop_count + 1 ) * diag_min_value - temp; >- for( i = 0; i < M; i++ ) { >- matrix_ptr( A, i, i, M ) += ( silk_float )temp; >- } >- err = 1; >- break; >- } >- D[ j ] = ( silk_float )temp; >- Dinv[ j ] = ( silk_float )( 1.0f / temp ); >- matrix_ptr( L, j, j, M ) = 1.0f; >- >- ptr1 = matrix_adr( A, j, 0, M ); >- ptr2 = matrix_adr( L, j + 1, 0, M); >- for( i = j + 1; i < M; i++ ) { >- temp = 0.0; >- for( k = 0; k < j; k++ ) { >- temp += ptr2[ k ] * v[ k ]; >- } >- matrix_ptr( L, i, j, M ) = ( silk_float )( ( ptr1[ i ] - temp ) * Dinv[ j ] ); >- ptr2 += M; /* go to next column*/ >- } >- } >- } >- silk_assert( err == 0 ); >-} >- >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/structs_FLP.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/structs_FLP.h >index 14d647ced27e6b6a6de567fad39822d67a3cd4c8..3150b386e478506dc8884ae69197129ef1c41633 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/structs_FLP.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/structs_FLP.h >@@ -42,32 +42,16 @@ extern "C" > /********************************/ > typedef struct { > opus_int8 LastGainIndex; >- silk_float HarmBoost_smth; > silk_float HarmShapeGain_smth; > silk_float Tilt_smth; > } silk_shape_state_FLP; > >-/********************************/ >-/* Prefilter state */ >-/********************************/ >-typedef struct { >- silk_float sLTP_shp[ LTP_BUF_LENGTH ]; >- silk_float sAR_shp[ MAX_SHAPE_LPC_ORDER + 1 ]; >- opus_int sLTP_shp_buf_idx; >- silk_float sLF_AR_shp; >- silk_float sLF_MA_shp; >- silk_float sHarmHP; >- opus_int32 rand_seed; >- opus_int lagPrev; >-} silk_prefilter_state_FLP; >- > /********************************/ > /* Encoder state FLP */ > /********************************/ > typedef struct { > silk_encoder_state sCmn; /* Common struct, shared with fixed-point code */ > silk_shape_state_FLP sShape; /* Noise shaping state */ >- silk_prefilter_state_FLP sPrefilt; /* Prefilter State */ > > /* Buffer for find pitch and noise shape analysis */ > silk_float x_buf[ 2 * MAX_FRAME_LENGTH + LA_SHAPE_MAX ];/* Buffer for find pitch and noise shape analysis */ >@@ -86,12 +70,9 @@ typedef struct { > opus_int pitchL[ MAX_NB_SUBFR ]; > > /* Noise shaping parameters */ >- silk_float AR1[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ]; >- silk_float AR2[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ]; >+ silk_float AR[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ]; > silk_float LF_MA_shp[ MAX_NB_SUBFR ]; > silk_float LF_AR_shp[ MAX_NB_SUBFR ]; >- silk_float GainsPre[ MAX_NB_SUBFR ]; >- silk_float HarmBoost[ MAX_NB_SUBFR ]; > silk_float Tilt[ MAX_NB_SUBFR ]; > silk_float HarmShapeGain[ MAX_NB_SUBFR ]; > silk_float Lambda; >@@ -99,7 +80,6 @@ typedef struct { > silk_float coding_quality; > > /* Measures */ >- silk_float sparseness; > silk_float predGain; > silk_float LTPredCodGain; > silk_float ResNrg[ MAX_NB_SUBFR ]; /* Residual energy per subframe */ >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/wrappers_FLP.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/wrappers_FLP.c >index 6666b8efaade2f0ce9eef37181c07683d5433ec2..ad90b874a4d814a615c914174205fdfb10df0974 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/wrappers_FLP.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/float/wrappers_FLP.c >@@ -54,13 +54,14 @@ void silk_A2NLSF_FLP( > void silk_NLSF2A_FLP( > silk_float *pAR, /* O LPC coefficients [ LPC_order ] */ > const opus_int16 *NLSF_Q15, /* I NLSF vector [ LPC_order ] */ >- const opus_int LPC_order /* I LPC order */ >+ const opus_int LPC_order, /* I LPC order */ >+ int arch /* I Run-time architecture */ > ) > { > opus_int i; > opus_int16 a_fix_Q12[ MAX_LPC_ORDER ]; > >- silk_NLSF2A( a_fix_Q12, NLSF_Q15, LPC_order ); >+ silk_NLSF2A( a_fix_Q12, NLSF_Q15, LPC_order, arch ); > > for( i = 0; i < LPC_order; i++ ) { > pAR[ i ] = ( silk_float )a_fix_Q12[ i ] * ( 1.0f / 4096.0f ); >@@ -102,14 +103,14 @@ void silk_NSQ_wrapper_FLP( > ) > { > opus_int i, j; >- opus_int32 x_Q3[ MAX_FRAME_LENGTH ]; >+ opus_int16 x16[ MAX_FRAME_LENGTH ]; > opus_int32 Gains_Q16[ MAX_NB_SUBFR ]; > silk_DWORD_ALIGN opus_int16 PredCoef_Q12[ 2 ][ MAX_LPC_ORDER ]; > opus_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ]; > opus_int LTP_scale_Q14; > > /* Noise shaping parameters */ >- opus_int16 AR2_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ]; >+ opus_int16 AR_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ]; > opus_int32 LF_shp_Q14[ MAX_NB_SUBFR ]; /* Packs two int16 coefficients per int32 value */ > opus_int Lambda_Q10; > opus_int Tilt_Q14[ MAX_NB_SUBFR ]; >@@ -119,7 +120,7 @@ void silk_NSQ_wrapper_FLP( > /* Noise shape parameters */ > for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) { > for( j = 0; j < psEnc->sCmn.shapingLPCOrder; j++ ) { >- AR2_Q13[ i * MAX_SHAPE_LPC_ORDER + j ] = silk_float2int( psEncCtrl->AR2[ i * MAX_SHAPE_LPC_ORDER + j ] * 8192.0f ); >+ AR_Q13[ i * MAX_SHAPE_LPC_ORDER + j ] = silk_float2int( psEncCtrl->AR[ i * MAX_SHAPE_LPC_ORDER + j ] * 8192.0f ); > } > } > >@@ -155,16 +156,16 @@ void silk_NSQ_wrapper_FLP( > > /* Convert input to fix */ > for( i = 0; i < psEnc->sCmn.frame_length; i++ ) { >- x_Q3[ i ] = silk_float2int( 8.0f * x[ i ] ); >+ x16[ i ] = silk_float2int( x[ i ] ); > } > > /* Call NSQ */ > if( psEnc->sCmn.nStatesDelayedDecision > 1 || psEnc->sCmn.warping_Q16 > 0 ) { >- silk_NSQ_del_dec( &psEnc->sCmn, psNSQ, psIndices, x_Q3, pulses, PredCoef_Q12[ 0 ], LTPCoef_Q14, >- AR2_Q13, HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, psEncCtrl->pitchL, Lambda_Q10, LTP_scale_Q14, psEnc->sCmn.arch ); >+ silk_NSQ_del_dec( &psEnc->sCmn, psNSQ, psIndices, x16, pulses, PredCoef_Q12[ 0 ], LTPCoef_Q14, >+ AR_Q13, HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, psEncCtrl->pitchL, Lambda_Q10, LTP_scale_Q14, psEnc->sCmn.arch ); > } else { >- silk_NSQ( &psEnc->sCmn, psNSQ, psIndices, x_Q3, pulses, PredCoef_Q12[ 0 ], LTPCoef_Q14, >- AR2_Q13, HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, psEncCtrl->pitchL, Lambda_Q10, LTP_scale_Q14, psEnc->sCmn.arch ); >+ silk_NSQ( &psEnc->sCmn, psNSQ, psIndices, x16, pulses, PredCoef_Q12[ 0 ], LTPCoef_Q14, >+ AR_Q13, HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, psEncCtrl->pitchL, Lambda_Q10, LTP_scale_Q14, psEnc->sCmn.arch ); > } > } > >@@ -172,31 +173,35 @@ void silk_NSQ_wrapper_FLP( > /* Floating-point Silk LTP quantiation wrapper */ > /***********************************************/ > void silk_quant_LTP_gains_FLP( >- silk_float B[ MAX_NB_SUBFR * LTP_ORDER ], /* I/O (Un-)quantized LTP gains */ >+ silk_float B[ MAX_NB_SUBFR * LTP_ORDER ], /* O Quantized LTP gains */ > opus_int8 cbk_index[ MAX_NB_SUBFR ], /* O Codebook index */ > opus_int8 *periodicity_index, /* O Periodicity index */ > opus_int32 *sum_log_gain_Q7, /* I/O Cumulative max prediction gain */ >- const silk_float W[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* I Error weights */ >- const opus_int mu_Q10, /* I Mu value (R/D tradeoff) */ >- const opus_int lowComplexity, /* I Flag for low complexity */ >- const opus_int nb_subfr, /* I number of subframes */ >+ silk_float *pred_gain_dB, /* O LTP prediction gain */ >+ const silk_float XX[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* I Correlation matrix */ >+ const silk_float xX[ MAX_NB_SUBFR * LTP_ORDER ], /* I Correlation vector */ >+ const opus_int subfr_len, /* I Number of samples per subframe */ >+ const opus_int nb_subfr, /* I Number of subframes */ > int arch /* I Run-time architecture */ > ) > { >- opus_int i; >+ opus_int i, pred_gain_dB_Q7; > opus_int16 B_Q14[ MAX_NB_SUBFR * LTP_ORDER ]; >- opus_int32 W_Q18[ MAX_NB_SUBFR*LTP_ORDER*LTP_ORDER ]; >+ opus_int32 XX_Q17[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ]; >+ opus_int32 xX_Q17[ MAX_NB_SUBFR * LTP_ORDER ]; > >- for( i = 0; i < nb_subfr * LTP_ORDER; i++ ) { >- B_Q14[ i ] = (opus_int16)silk_float2int( B[ i ] * 16384.0f ); >- } > for( i = 0; i < nb_subfr * LTP_ORDER * LTP_ORDER; i++ ) { >- W_Q18[ i ] = (opus_int32)silk_float2int( W[ i ] * 262144.0f ); >+ XX_Q17[ i ] = (opus_int32)silk_float2int( XX[ i ] * 131072.0f ); >+ } >+ for( i = 0; i < nb_subfr * LTP_ORDER; i++ ) { >+ xX_Q17[ i ] = (opus_int32)silk_float2int( xX[ i ] * 131072.0f ); > } > >- silk_quant_LTP_gains( B_Q14, cbk_index, periodicity_index, sum_log_gain_Q7, W_Q18, mu_Q10, lowComplexity, nb_subfr, arch ); >+ silk_quant_LTP_gains( B_Q14, cbk_index, periodicity_index, sum_log_gain_Q7, &pred_gain_dB_Q7, XX_Q17, xX_Q17, subfr_len, nb_subfr, arch ); > > for( i = 0; i < nb_subfr * LTP_ORDER; i++ ) { > B[ i ] = (silk_float)B_Q14[ i ] * ( 1.0f / 16384.0f ); > } >+ >+ *pred_gain_dB = (silk_float)pred_gain_dB_Q7 * ( 1.0f / 128.0f ); > } >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/gain_quant.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/gain_quant.c >index 64ccd0611bff368cf79f950df5a167baa8d410bd..ee65245aa367105ee1e0dfa8b5f2619d8c223820 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/gain_quant.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/gain_quant.c >@@ -76,6 +76,7 @@ void silk_gains_quant( > /* Accumulate deltas */ > if( ind[ k ] > double_step_size_threshold ) { > *prev_ind += silk_LSHIFT( ind[ k ], 1 ) - double_step_size_threshold; >+ *prev_ind = silk_min_int( *prev_ind, N_LEVELS_QGAIN - 1 ); > } else { > *prev_ind += ind[ k ]; > } >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/init_decoder.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/init_decoder.c >index f887c67886fb57acd54b03a3dc5210c3b09bb4b2..16c03dcd1ca1b33b4840999d8db6c7f5b2b15ebe 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/init_decoder.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/init_decoder.c >@@ -44,6 +44,7 @@ opus_int silk_init_decoder( > /* Used to deactivate LSF interpolation */ > psDec->first_frame_after_reset = 1; > psDec->prev_gain_Q16 = 65536; >+ psDec->arch = opus_select_arch(); > > /* Reset CNG state */ > silk_CNG_Reset( psDec ); >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/lin2log.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/lin2log.c >index d4fe515321f0d5b76d6d314ccff4d16f93f91838..0d5155aa86e4d67630c541d68fa7a5e1bf400bce 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/lin2log.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/lin2log.c >@@ -41,6 +41,6 @@ opus_int32 silk_lin2log( > silk_CLZ_FRAC( inLin, &lz, &frac_Q7 ); > > /* Piece-wise parabolic approximation */ >- return silk_LSHIFT( 31 - lz, 7 ) + silk_SMLAWB( frac_Q7, silk_MUL( frac_Q7, 128 - frac_Q7 ), 179 ); >+ return silk_ADD_LSHIFT32( silk_SMLAWB( frac_Q7, silk_MUL( frac_Q7, 128 - frac_Q7 ), 179 ), 31 - lz, 7 ); > } > >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/macros.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/macros.h >index d3ca34752004506b6fd6ae4bdd88b7864af68072..3c67b6e5d97c366f9841e2ba9bdeefbfbfeb20ec 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/macros.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/macros.h >@@ -36,14 +36,6 @@ POSSIBILITY OF SUCH DAMAGE. > #include "opus_defines.h" > #include "arch.h" > >-#if OPUS_GNUC_PREREQ(3, 0) >-#define opus_likely(x) (__builtin_expect(!!(x), 1)) >-#define opus_unlikely(x) (__builtin_expect(!!(x), 0)) >-#else >-#define opus_likely(x) (!!(x)) >-#define opus_unlikely(x) (!!(x)) >-#endif >- > /* This is an OPUS_INLINE header file for general platform. */ > > /* (a32 * (opus_int32)((opus_int16)(b32))) >> 16 output have to be 32bit int */ >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/main.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/main.h >index 2f90d68f7da0c7d4b09b706af701a64e272af507..1a33eed549b6a2085d6120d5210ae1c2bd4b28b6 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/main.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/main.h >@@ -42,6 +42,10 @@ POSSIBILITY OF SUCH DAMAGE. > #include "x86/main_sse.h" > #endif > >+#if (defined(OPUS_ARM_ASM) || defined(OPUS_ARM_MAY_HAVE_NEON_INTR)) >+#include "arm/NSQ_del_dec_arm.h" >+#endif >+ > /* Convert Left/Right stereo signal to adaptive Mid/Side representation */ > void silk_stereo_LR_to_MS( > stereo_enc_state *state, /* I/O State */ >@@ -109,22 +113,22 @@ void silk_stereo_decode_mid_only( > > /* Encodes signs of excitation */ > void silk_encode_signs( >- ec_enc *psRangeEnc, /* I/O Compressor data structure */ >- const opus_int8 pulses[], /* I pulse signal */ >- opus_int length, /* I length of input */ >- const opus_int signalType, /* I Signal type */ >- const opus_int quantOffsetType, /* I Quantization offset type */ >- const opus_int sum_pulses[ MAX_NB_SHELL_BLOCKS ] /* I Sum of absolute pulses per block */ >+ ec_enc *psRangeEnc, /* I/O Compressor data structure */ >+ const opus_int8 pulses[], /* I pulse signal */ >+ opus_int length, /* I length of input */ >+ const opus_int signalType, /* I Signal type */ >+ const opus_int quantOffsetType, /* I Quantization offset type */ >+ const opus_int sum_pulses[ MAX_NB_SHELL_BLOCKS ] /* I Sum of absolute pulses per block */ > ); > > /* Decodes signs of excitation */ > void silk_decode_signs( >- ec_dec *psRangeDec, /* I/O Compressor data structure */ >- opus_int16 pulses[], /* I/O pulse signal */ >- opus_int length, /* I length of input */ >- const opus_int signalType, /* I Signal type */ >- const opus_int quantOffsetType, /* I Quantization offset type */ >- const opus_int sum_pulses[ MAX_NB_SHELL_BLOCKS ] /* I Sum of absolute pulses per block */ >+ ec_dec *psRangeDec, /* I/O Compressor data structure */ >+ opus_int16 pulses[], /* I/O pulse signal */ >+ opus_int length, /* I length of input */ >+ const opus_int signalType, /* I Signal type */ >+ const opus_int quantOffsetType, /* I Quantization offset type */ >+ const opus_int sum_pulses[ MAX_NB_SHELL_BLOCKS ] /* I Sum of absolute pulses per block */ > ); > > /* Check encoder control struct */ >@@ -205,37 +209,37 @@ void silk_interpolate( > > /* LTP tap quantizer */ > void silk_quant_LTP_gains( >- opus_int16 B_Q14[ MAX_NB_SUBFR * LTP_ORDER ], /* I/O (un)quantized LTP gains */ >+ opus_int16 B_Q14[ MAX_NB_SUBFR * LTP_ORDER ], /* O Quantized LTP gains */ > opus_int8 cbk_index[ MAX_NB_SUBFR ], /* O Codebook Index */ > opus_int8 *periodicity_index, /* O Periodicity Index */ > opus_int32 *sum_gain_dB_Q7, /* I/O Cumulative max prediction gain */ >- const opus_int32 W_Q18[ MAX_NB_SUBFR*LTP_ORDER*LTP_ORDER ], /* I Error Weights in Q18 */ >- opus_int mu_Q9, /* I Mu value (R/D tradeoff) */ >- opus_int lowComplexity, /* I Flag for low complexity */ >- const opus_int nb_subfr, /* I number of subframes */ >+ opus_int *pred_gain_dB_Q7, /* O LTP prediction gain */ >+ const opus_int32 XX_Q17[ MAX_NB_SUBFR*LTP_ORDER*LTP_ORDER ], /* I Correlation matrix in Q18 */ >+ const opus_int32 xX_Q17[ MAX_NB_SUBFR*LTP_ORDER ], /* I Correlation vector in Q18 */ >+ const opus_int subfr_len, /* I Number of samples per subframe */ >+ const opus_int nb_subfr, /* I Number of subframes */ > int arch /* I Run-time architecture */ > ); > > /* Entropy constrained matrix-weighted VQ, for a single input data vector */ > void silk_VQ_WMat_EC_c( > opus_int8 *ind, /* O index of best codebook vector */ >- opus_int32 *rate_dist_Q14, /* O best weighted quant error + mu * rate */ >+ opus_int32 *res_nrg_Q15, /* O best residual energy */ >+ opus_int32 *rate_dist_Q8, /* O best total bitrate */ > opus_int *gain_Q7, /* O sum of absolute LTP coefficients */ >- const opus_int16 *in_Q14, /* I input vector to be quantized */ >- const opus_int32 *W_Q18, /* I weighting matrix */ >+ const opus_int32 *XX_Q17, /* I correlation matrix */ >+ const opus_int32 *xX_Q17, /* I correlation vector */ > const opus_int8 *cb_Q7, /* I codebook */ > const opus_uint8 *cb_gain_Q7, /* I codebook effective gain */ > const opus_uint8 *cl_Q5, /* I code length for each codebook vector */ >- const opus_int mu_Q9, /* I tradeoff betw. weighted error and rate */ >+ const opus_int subfr_len, /* I number of samples per subframe */ > const opus_int32 max_gain_Q7, /* I maximum sum of absolute LTP coefficients */ >- opus_int L /* I number of vectors in codebook */ >+ const opus_int L /* I number of vectors in codebook */ > ); > > #if !defined(OVERRIDE_silk_VQ_WMat_EC) >-#define silk_VQ_WMat_EC(ind, rate_dist_Q14, gain_Q7, in_Q14, W_Q18, cb_Q7, cb_gain_Q7, cl_Q5, \ >- mu_Q9, max_gain_Q7, L, arch) \ >- ((void)(arch),silk_VQ_WMat_EC_c(ind, rate_dist_Q14, gain_Q7, in_Q14, W_Q18, cb_Q7, cb_gain_Q7, cl_Q5, \ >- mu_Q9, max_gain_Q7, L)) >+#define silk_VQ_WMat_EC(ind, res_nrg_Q15, rate_dist_Q8, gain_Q7, XX_Q17, xX_Q17, cb_Q7, cb_gain_Q7, cl_Q5, subfr_len, max_gain_Q7, L, arch) \ >+ ((void)(arch),silk_VQ_WMat_EC_c(ind, res_nrg_Q15, rate_dist_Q8, gain_Q7, XX_Q17, xX_Q17, cb_Q7, cb_gain_Q7, cl_Q5, subfr_len, max_gain_Q7, L)) > #endif > > /************************************/ >@@ -243,14 +247,14 @@ void silk_VQ_WMat_EC_c( > /************************************/ > > void silk_NSQ_c( >- const silk_encoder_state *psEncC, /* I/O Encoder State */ >+ const silk_encoder_state *psEncC, /* I Encoder State */ > silk_nsq_state *NSQ, /* I/O NSQ state */ > SideInfoIndices *psIndices, /* I/O Quantization Indices */ >- const opus_int32 x_Q3[], /* I Prefiltered input signal */ >+ const opus_int16 x16[], /* I Input */ > opus_int8 pulses[], /* O Quantized pulse signal */ > const opus_int16 PredCoef_Q12[ 2 * MAX_LPC_ORDER ], /* I Short term prediction coefs */ > const opus_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ], /* I Long term prediction coefs */ >- const opus_int16 AR2_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I Noise shaping coefs */ >+ const opus_int16 AR_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I Noise shaping coefs */ > const opus_int HarmShapeGain_Q14[ MAX_NB_SUBFR ], /* I Long term shaping coefs */ > const opus_int Tilt_Q14[ MAX_NB_SUBFR ], /* I Spectral tilt */ > const opus_int32 LF_shp_Q14[ MAX_NB_SUBFR ], /* I Low frequency shaping coefs */ >@@ -261,22 +265,22 @@ void silk_NSQ_c( > ); > > #if !defined(OVERRIDE_silk_NSQ) >-#define silk_NSQ(psEncC, NSQ, psIndices, x_Q3, pulses, PredCoef_Q12, LTPCoef_Q14, AR2_Q13, \ >+#define silk_NSQ(psEncC, NSQ, psIndices, x16, pulses, PredCoef_Q12, LTPCoef_Q14, AR_Q13, \ > HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, pitchL, Lambda_Q10, LTP_scale_Q14, arch) \ >- ((void)(arch),silk_NSQ_c(psEncC, NSQ, psIndices, x_Q3, pulses, PredCoef_Q12, LTPCoef_Q14, AR2_Q13, \ >+ ((void)(arch),silk_NSQ_c(psEncC, NSQ, psIndices, x16, pulses, PredCoef_Q12, LTPCoef_Q14, AR_Q13, \ > HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, pitchL, Lambda_Q10, LTP_scale_Q14)) > #endif > > /* Noise shaping using delayed decision */ > void silk_NSQ_del_dec_c( >- const silk_encoder_state *psEncC, /* I/O Encoder State */ >+ const silk_encoder_state *psEncC, /* I Encoder State */ > silk_nsq_state *NSQ, /* I/O NSQ state */ > SideInfoIndices *psIndices, /* I/O Quantization Indices */ >- const opus_int32 x_Q3[], /* I Prefiltered input signal */ >+ const opus_int16 x16[], /* I Input */ > opus_int8 pulses[], /* O Quantized pulse signal */ > const opus_int16 PredCoef_Q12[ 2 * MAX_LPC_ORDER ], /* I Short term prediction coefs */ > const opus_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ], /* I Long term prediction coefs */ >- const opus_int16 AR2_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I Noise shaping coefs */ >+ const opus_int16 AR_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I Noise shaping coefs */ > const opus_int HarmShapeGain_Q14[ MAX_NB_SUBFR ], /* I Long term shaping coefs */ > const opus_int Tilt_Q14[ MAX_NB_SUBFR ], /* I Spectral tilt */ > const opus_int32 LF_shp_Q14[ MAX_NB_SUBFR ], /* I Low frequency shaping coefs */ >@@ -287,9 +291,9 @@ void silk_NSQ_del_dec_c( > ); > > #if !defined(OVERRIDE_silk_NSQ_del_dec) >-#define silk_NSQ_del_dec(psEncC, NSQ, psIndices, x_Q3, pulses, PredCoef_Q12, LTPCoef_Q14, AR2_Q13, \ >+#define silk_NSQ_del_dec(psEncC, NSQ, psIndices, x16, pulses, PredCoef_Q12, LTPCoef_Q14, AR_Q13, \ > HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, pitchL, Lambda_Q10, LTP_scale_Q14, arch) \ >- ((void)(arch),silk_NSQ_del_dec_c(psEncC, NSQ, psIndices, x_Q3, pulses, PredCoef_Q12, LTPCoef_Q14, AR2_Q13, \ >+ ((void)(arch),silk_NSQ_del_dec_c(psEncC, NSQ, psIndices, x16, pulses, PredCoef_Q12, LTPCoef_Q14, AR_Q13, \ > HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, pitchL, Lambda_Q10, LTP_scale_Q14)) > #endif > >@@ -346,6 +350,7 @@ void silk_NLSF_VQ( > opus_int32 err_Q26[], /* O Quantization errors [K] */ > const opus_int16 in_Q15[], /* I Input vectors to be quantized [LPC_order] */ > const opus_uint8 pCB_Q8[], /* I Codebook vectors [K*LPC_order] */ >+ const opus_int16 pWght_Q9[], /* I Codebook weights [K*LPC_order] */ > const opus_int K, /* I Number of codebook vectors */ > const opus_int LPC_order /* I Number of LPCs */ > ); >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/mips/NSQ_del_dec_mipsr1.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/mips/NSQ_del_dec_mipsr1.h >index ad1cfe2a9b0841012701b1fe77d7da2f044d0b26..cd70713a8f5d9453ec62d7786bc30a90abddc409 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/mips/NSQ_del_dec_mipsr1.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/mips/NSQ_del_dec_mipsr1.h >@@ -61,7 +61,7 @@ static inline void silk_noise_shape_quantizer_del_dec( > opus_int predictLPCOrder, /* I Prediction filter order */ > opus_int warping_Q16, /* I */ > opus_int nStatesDelayedDecision, /* I Number of states in decision tree */ >- opus_int *smpl_buf_idx, /* I Index to newest samples in buffers */ >+ opus_int *smpl_buf_idx, /* I/O Index to newest samples in buffers */ > opus_int decisionDelay, /* I */ > int arch /* I */ > ) >@@ -323,8 +323,9 @@ static inline void silk_noise_shape_quantizer_del_dec( > psSS[ 1 ].xq_Q14 = xq_Q14; > } > >- *smpl_buf_idx = ( *smpl_buf_idx - 1 ) & DECISION_DELAY_MASK; /* Index to newest samples */ >- last_smple_idx = ( *smpl_buf_idx + decisionDelay ) & DECISION_DELAY_MASK; /* Index to decisionDelay old samples */ >+ *smpl_buf_idx = ( *smpl_buf_idx - 1 ) % DECISION_DELAY; >+ if( *smpl_buf_idx < 0 ) *smpl_buf_idx += DECISION_DELAY; >+ last_smple_idx = ( *smpl_buf_idx + decisionDelay ) % DECISION_DELAY; > > /* Find winner */ > RDmin_Q10 = psSampleState[ 0 ][ 0 ].RD_Q10; >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/mips/sigproc_fix_mipsr1.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/mips/sigproc_fix_mipsr1.h >index 3b0a6953656d97318f3aa83ebba9f208be1bd88b..51520c0a6fd550cb872906244e6afc1c0cc138aa 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/mips/sigproc_fix_mipsr1.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/mips/sigproc_fix_mipsr1.h >@@ -28,11 +28,6 @@ POSSIBILITY OF SUCH DAMAGE. > #ifndef SILK_SIGPROC_FIX_MIPSR1_H > #define SILK_SIGPROC_FIX_MIPSR1_H > >-#ifdef __cplusplus >-extern "C" >-{ >-#endif >- > #undef silk_SAT16 > static inline short int silk_SAT16(int a) > { >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/process_NLSFs.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/process_NLSFs.c >index 0ab71f0163407f854bc42f06a5900e6b1abe2937..2f10f8df5b3d70e5823fe2db55b5b1174b26afbb 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/process_NLSFs.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/process_NLSFs.c >@@ -89,7 +89,7 @@ void silk_process_NLSFs( > NLSF_mu_Q20, psEncC->NLSF_MSVQ_Survivors, psEncC->indices.signalType ); > > /* Convert quantized NLSFs back to LPC coefficients */ >- silk_NLSF2A( PredCoef_Q12[ 1 ], pNLSF_Q15, psEncC->predictLPCOrder ); >+ silk_NLSF2A( PredCoef_Q12[ 1 ], pNLSF_Q15, psEncC->predictLPCOrder, psEncC->arch ); > > if( doInterpolate ) { > /* Calculate the interpolated, quantized LSF vector for the first half */ >@@ -97,7 +97,7 @@ void silk_process_NLSFs( > psEncC->indices.NLSFInterpCoef_Q2, psEncC->predictLPCOrder ); > > /* Convert back to LPC coefficients */ >- silk_NLSF2A( PredCoef_Q12[ 0 ], pNLSF0_temp_Q15, psEncC->predictLPCOrder ); >+ silk_NLSF2A( PredCoef_Q12[ 0 ], pNLSF0_temp_Q15, psEncC->predictLPCOrder, psEncC->arch ); > > } else { > /* Copy LPC coefficients for first half from second half */ >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/quant_LTP_gains.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/quant_LTP_gains.c >index 513a8c4468ffc4c87a741460065f63ebe67752a6..d6b8eff8d1864ccfa21a26a6bc597ebc2dbcedb3 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/quant_LTP_gains.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/quant_LTP_gains.c >@@ -33,14 +33,15 @@ POSSIBILITY OF SUCH DAMAGE. > #include "tuning_parameters.h" > > void silk_quant_LTP_gains( >- opus_int16 B_Q14[ MAX_NB_SUBFR * LTP_ORDER ], /* I/O (un)quantized LTP gains */ >+ opus_int16 B_Q14[ MAX_NB_SUBFR * LTP_ORDER ], /* O Quantized LTP gains */ > opus_int8 cbk_index[ MAX_NB_SUBFR ], /* O Codebook Index */ > opus_int8 *periodicity_index, /* O Periodicity Index */ > opus_int32 *sum_log_gain_Q7, /* I/O Cumulative max prediction gain */ >- const opus_int32 W_Q18[ MAX_NB_SUBFR*LTP_ORDER*LTP_ORDER ], /* I Error Weights in Q18 */ >- opus_int mu_Q9, /* I Mu value (R/D tradeoff) */ >- opus_int lowComplexity, /* I Flag for low complexity */ >- const opus_int nb_subfr, /* I number of subframes */ >+ opus_int *pred_gain_dB_Q7, /* O LTP prediction gain */ >+ const opus_int32 XX_Q17[ MAX_NB_SUBFR*LTP_ORDER*LTP_ORDER ], /* I Correlation matrix in Q18 */ >+ const opus_int32 xX_Q17[ MAX_NB_SUBFR*LTP_ORDER ], /* I Correlation vector in Q18 */ >+ const opus_int subfr_len, /* I Number of samples per subframe */ >+ const opus_int nb_subfr, /* I Number of subframes */ > int arch /* I Run-time architecture */ > ) > { >@@ -49,16 +50,16 @@ void silk_quant_LTP_gains( > const opus_uint8 *cl_ptr_Q5; > const opus_int8 *cbk_ptr_Q7; > const opus_uint8 *cbk_gain_ptr_Q7; >- const opus_int16 *b_Q14_ptr; >- const opus_int32 *W_Q18_ptr; >- opus_int32 rate_dist_Q14_subfr, rate_dist_Q14, min_rate_dist_Q14; >- opus_int32 sum_log_gain_tmp_Q7, best_sum_log_gain_Q7, max_gain_Q7, gain_Q7; >+ const opus_int32 *XX_Q17_ptr, *xX_Q17_ptr; >+ opus_int32 res_nrg_Q15_subfr, res_nrg_Q15, rate_dist_Q7_subfr, rate_dist_Q7, min_rate_dist_Q7; >+ opus_int32 sum_log_gain_tmp_Q7, best_sum_log_gain_Q7, max_gain_Q7; >+ opus_int gain_Q7; > > /***************************************************/ > /* iterate over different codebooks with different */ > /* rates/distortions, and choose best */ > /***************************************************/ >- min_rate_dist_Q14 = silk_int32_MAX; >+ min_rate_dist_Q7 = silk_int32_MAX; > best_sum_log_gain_Q7 = 0; > for( k = 0; k < 3; k++ ) { > /* Safety margin for pitch gain control, to take into account factors >@@ -70,53 +71,47 @@ void silk_quant_LTP_gains( > cbk_gain_ptr_Q7 = silk_LTP_vq_gain_ptrs_Q7[ k ]; > cbk_size = silk_LTP_vq_sizes[ k ]; > >- /* Set up pointer to first subframe */ >- W_Q18_ptr = W_Q18; >- b_Q14_ptr = B_Q14; >+ /* Set up pointers to first subframe */ >+ XX_Q17_ptr = XX_Q17; >+ xX_Q17_ptr = xX_Q17; > >- rate_dist_Q14 = 0; >+ res_nrg_Q15 = 0; >+ rate_dist_Q7 = 0; > sum_log_gain_tmp_Q7 = *sum_log_gain_Q7; > for( j = 0; j < nb_subfr; j++ ) { > max_gain_Q7 = silk_log2lin( ( SILK_FIX_CONST( MAX_SUM_LOG_GAIN_DB / 6.0, 7 ) - sum_log_gain_tmp_Q7 ) > + SILK_FIX_CONST( 7, 7 ) ) - gain_safety; >- > silk_VQ_WMat_EC( > &temp_idx[ j ], /* O index of best codebook vector */ >- &rate_dist_Q14_subfr, /* O best weighted quantization error + mu * rate */ >+ &res_nrg_Q15_subfr, /* O residual energy */ >+ &rate_dist_Q7_subfr, /* O best weighted quantization error + mu * rate */ > &gain_Q7, /* O sum of absolute LTP coefficients */ >- b_Q14_ptr, /* I input vector to be quantized */ >- W_Q18_ptr, /* I weighting matrix */ >+ XX_Q17_ptr, /* I correlation matrix */ >+ xX_Q17_ptr, /* I correlation vector */ > cbk_ptr_Q7, /* I codebook */ > cbk_gain_ptr_Q7, /* I codebook effective gains */ > cl_ptr_Q5, /* I code length for each codebook vector */ >- mu_Q9, /* I tradeoff between weighted error and rate */ >+ subfr_len, /* I number of samples per subframe */ > max_gain_Q7, /* I maximum sum of absolute LTP coefficients */ > cbk_size, /* I number of vectors in codebook */ > arch /* I Run-time architecture */ > ); > >- rate_dist_Q14 = silk_ADD_POS_SAT32( rate_dist_Q14, rate_dist_Q14_subfr ); >+ res_nrg_Q15 = silk_ADD_POS_SAT32( res_nrg_Q15, res_nrg_Q15_subfr ); >+ rate_dist_Q7 = silk_ADD_POS_SAT32( rate_dist_Q7, rate_dist_Q7_subfr ); > sum_log_gain_tmp_Q7 = silk_max(0, sum_log_gain_tmp_Q7 > + silk_lin2log( gain_safety + gain_Q7 ) - SILK_FIX_CONST( 7, 7 )); > >- b_Q14_ptr += LTP_ORDER; >- W_Q18_ptr += LTP_ORDER * LTP_ORDER; >+ XX_Q17_ptr += LTP_ORDER * LTP_ORDER; >+ xX_Q17_ptr += LTP_ORDER; > } > >- /* Avoid never finding a codebook */ >- rate_dist_Q14 = silk_min( silk_int32_MAX - 1, rate_dist_Q14 ); >- >- if( rate_dist_Q14 < min_rate_dist_Q14 ) { >- min_rate_dist_Q14 = rate_dist_Q14; >+ if( rate_dist_Q7 <= min_rate_dist_Q7 ) { >+ min_rate_dist_Q7 = rate_dist_Q7; > *periodicity_index = (opus_int8)k; > silk_memcpy( cbk_index, temp_idx, nb_subfr * sizeof( opus_int8 ) ); > best_sum_log_gain_Q7 = sum_log_gain_tmp_Q7; > } >- >- /* Break early in low-complexity mode if rate distortion is below threshold */ >- if( lowComplexity && ( rate_dist_Q14 < silk_LTP_gain_middle_avg_RD_Q14 ) ) { >- break; >- } > } > > cbk_ptr_Q7 = silk_LTP_vq_ptrs_Q7[ *periodicity_index ]; >@@ -125,5 +120,13 @@ void silk_quant_LTP_gains( > B_Q14[ j * LTP_ORDER + k ] = silk_LSHIFT( cbk_ptr_Q7[ cbk_index[ j ] * LTP_ORDER + k ], 7 ); > } > } >+ >+ if( nb_subfr == 2 ) { >+ res_nrg_Q15 = silk_RSHIFT32( res_nrg_Q15, 1 ); >+ } else { >+ res_nrg_Q15 = silk_RSHIFT32( res_nrg_Q15, 2 ); >+ } >+ > *sum_log_gain_Q7 = best_sum_log_gain_Q7; >+ *pred_gain_dB_Q7 = (opus_int)silk_SMULBB( -3, silk_lin2log( res_nrg_Q15 ) - ( 15 << 7 ) ); > } >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/structs.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/structs.h >index 827829dc6f32ce13485be17a71efc3963d7c4224..4ff590b04caba50835fcd18009437bc790aaaaae 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/structs.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/structs.h >@@ -48,6 +48,7 @@ typedef struct { > opus_int32 sLPC_Q14[ MAX_SUB_FRAME_LENGTH + NSQ_LPC_BUF_LENGTH ]; > opus_int32 sAR2_Q14[ MAX_SHAPE_LPC_ORDER ]; > opus_int32 sLF_AR_shp_Q14; >+ opus_int32 sDiff_shp_Q14; > opus_int lagPrev; > opus_int sLTP_buf_idx; > opus_int sLTP_shp_buf_idx; >@@ -86,6 +87,7 @@ typedef struct { > const opus_int16 quantStepSize_Q16; > const opus_int16 invQuantStepSize_Q6; > const opus_uint8 *CB1_NLSF_Q8; >+ const opus_int16 *CB1_Wght_Q9; > const opus_uint8 *CB1_iCDF; > const opus_uint8 *pred_Q8; > const opus_uint8 *ec_sel; >@@ -169,8 +171,6 @@ typedef struct { > opus_int pitchEstimationComplexity; /* Complexity level for pitch estimator */ > opus_int pitchEstimationLPCOrder; /* Whitening filter order for pitch estimator */ > opus_int32 pitchEstimationThreshold_Q16; /* Threshold for pitch estimator */ >- opus_int LTPQuantLowComplexity; /* Flag for low complexity LTP quantization */ >- opus_int mu_LTP_Q9; /* Rate-distortion tradeoff in LTP quantization */ > opus_int32 sum_log_gain_Q7; /* Cumulative max prediction gain */ > opus_int NLSF_MSVQ_Survivors; /* Number of survivors in NLSF MSVQ */ > opus_int first_frame_after_reset; /* Flag for deactivating NLSF interpolation, pitch prediction */ >@@ -301,6 +301,7 @@ typedef struct { > /* Stuff used for PLC */ > opus_int lossCnt; > opus_int prevSignalType; >+ int arch; > > silk_PLC_struct sPLC; > >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/sum_sqr_shift.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/sum_sqr_shift.c >index 129df191d8ded4d84e003aea36d98a59a349dd47..4fd0c3d7d536c3b5e3ba549d19048833d00b4e69 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/sum_sqr_shift.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/sum_sqr_shift.c >@@ -41,43 +41,40 @@ void silk_sum_sqr_shift( > ) > { > opus_int i, shft; >- opus_int32 nrg_tmp, nrg; >+ opus_uint32 nrg_tmp; >+ opus_int32 nrg; > >- nrg = 0; >- shft = 0; >- len--; >- for( i = 0; i < len; i += 2 ) { >- nrg = silk_SMLABB_ovflw( nrg, x[ i ], x[ i ] ); >- nrg = silk_SMLABB_ovflw( nrg, x[ i + 1 ], x[ i + 1 ] ); >- if( nrg < 0 ) { >- /* Scale down */ >- nrg = (opus_int32)silk_RSHIFT_uint( (opus_uint32)nrg, 2 ); >- shft = 2; >- i+=2; >- break; >- } >+ /* Do a first run with the maximum shift we could have. */ >+ shft = 31-silk_CLZ32(len); >+ /* Let's be conservative with rounding and start with nrg=len. */ >+ nrg = len; >+ for( i = 0; i < len - 1; i += 2 ) { >+ nrg_tmp = silk_SMULBB( x[ i ], x[ i ] ); >+ nrg_tmp = silk_SMLABB_ovflw( nrg_tmp, x[ i + 1 ], x[ i + 1 ] ); >+ nrg = (opus_int32)silk_ADD_RSHIFT_uint( nrg, nrg_tmp, shft ); > } >- for( ; i < len; i += 2 ) { >+ if( i < len ) { >+ /* One sample left to process */ >+ nrg_tmp = silk_SMULBB( x[ i ], x[ i ] ); >+ nrg = (opus_int32)silk_ADD_RSHIFT_uint( nrg, nrg_tmp, shft ); >+ } >+ silk_assert( nrg >= 0 ); >+ /* Make sure the result will fit in a 32-bit signed integer with two bits >+ of headroom. */ >+ shft = silk_max_32(0, shft+3 - silk_CLZ32(nrg)); >+ nrg = 0; >+ for( i = 0 ; i < len - 1; i += 2 ) { > nrg_tmp = silk_SMULBB( x[ i ], x[ i ] ); > nrg_tmp = silk_SMLABB_ovflw( nrg_tmp, x[ i + 1 ], x[ i + 1 ] ); >- nrg = (opus_int32)silk_ADD_RSHIFT_uint( nrg, (opus_uint32)nrg_tmp, shft ); >- if( nrg < 0 ) { >- /* Scale down */ >- nrg = (opus_int32)silk_RSHIFT_uint( (opus_uint32)nrg, 2 ); >- shft += 2; >- } >+ nrg = (opus_int32)silk_ADD_RSHIFT_uint( nrg, nrg_tmp, shft ); > } >- if( i == len ) { >+ if( i < len ) { > /* One sample left to process */ > nrg_tmp = silk_SMULBB( x[ i ], x[ i ] ); > nrg = (opus_int32)silk_ADD_RSHIFT_uint( nrg, nrg_tmp, shft ); > } > >- /* Make sure to have at least one extra leading zero (two leading zeros in total) */ >- if( nrg & 0xC0000000 ) { >- nrg = silk_RSHIFT_uint( (opus_uint32)nrg, 2 ); >- shft += 2; >- } >+ silk_assert( nrg >= 0 ); > > /* Output arguments */ > *shift = shft; >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/tables.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/tables.h >index 7fea6fda39da463384c315d5b652c3352f696182..8b0380eeb0984c17b382567297851c2d5a270aae 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/tables.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/tables.h >@@ -76,10 +76,8 @@ extern const opus_uint8 silk_NLSF_EXT_iCDF[ 7 ]; > extern const opus_uint8 silk_LTP_per_index_iCDF[ 3 ]; /* 3 */ > extern const opus_uint8 * const silk_LTP_gain_iCDF_ptrs[ NB_LTP_CBKS ]; /* 3 */ > extern const opus_uint8 * const silk_LTP_gain_BITS_Q5_ptrs[ NB_LTP_CBKS ]; /* 3 */ >-extern const opus_int16 silk_LTP_gain_middle_avg_RD_Q14; > extern const opus_int8 * const silk_LTP_vq_ptrs_Q7[ NB_LTP_CBKS ]; /* 168 */ > extern const opus_uint8 * const silk_LTP_vq_gain_ptrs_Q7[NB_LTP_CBKS]; >- > extern const opus_int8 silk_LTP_vq_sizes[ NB_LTP_CBKS ]; /* 3 */ > > extern const opus_uint8 silk_LTPscale_iCDF[ 3 ]; /* 4 */ >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/tables_LTP.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/tables_LTP.c >index 0e6a0254d5db55262cece02698d53eb4b1327d6b..5e12c8643e5b0f15c1c9486a8845c833f1ddf341 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/tables_LTP.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/tables_LTP.c >@@ -51,8 +51,6 @@ static const opus_uint8 silk_LTP_gain_iCDF_2[32] = { > 24, 20, 16, 12, 9, 5, 2, 0 > }; > >-const opus_int16 silk_LTP_gain_middle_avg_RD_Q14 = 12304; >- > static const opus_uint8 silk_LTP_gain_BITS_Q5_0[8] = { > 15, 131, 138, 138, 155, 155, 173, 173 > }; >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/tables_NLSF_CB_NB_MB.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/tables_NLSF_CB_NB_MB.c >index 8c59d207aa00808657c662b6588d1fcfc3ac795b..195d5b95bd154cc4a94f2ee63b7688a5ec0671f7 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/tables_NLSF_CB_NB_MB.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/tables_NLSF_CB_NB_MB.c >@@ -74,6 +74,41 @@ static const opus_uint8 silk_NLSF_CB1_NB_MB_Q8[ 320 ] = { > 64, 84, 104, 118, 156, 177, 201, 230 > }; > >+static const opus_int16 silk_NLSF_CB1_Wght_Q9[ 320 ] = { >+ 2897, 2314, 2314, 2314, 2287, 2287, 2314, 2300, 2327, 2287, >+ 2888, 2580, 2394, 2367, 2314, 2274, 2274, 2274, 2274, 2194, >+ 2487, 2340, 2340, 2314, 2314, 2314, 2340, 2340, 2367, 2354, >+ 3216, 2766, 2340, 2340, 2314, 2274, 2221, 2207, 2261, 2194, >+ 2460, 2474, 2367, 2394, 2394, 2394, 2394, 2367, 2407, 2314, >+ 3479, 3056, 2127, 2207, 2274, 2274, 2274, 2287, 2314, 2261, >+ 3282, 3141, 2580, 2394, 2247, 2221, 2207, 2194, 2194, 2114, >+ 4096, 3845, 2221, 2620, 2620, 2407, 2314, 2394, 2367, 2074, >+ 3178, 3244, 2367, 2221, 2553, 2434, 2340, 2314, 2167, 2221, >+ 3338, 3488, 2726, 2194, 2261, 2460, 2354, 2367, 2207, 2101, >+ 2354, 2420, 2327, 2367, 2394, 2420, 2420, 2420, 2460, 2367, >+ 3779, 3629, 2434, 2527, 2367, 2274, 2274, 2300, 2207, 2048, >+ 3254, 3225, 2713, 2846, 2447, 2327, 2300, 2300, 2274, 2127, >+ 3263, 3300, 2753, 2806, 2447, 2261, 2261, 2247, 2127, 2101, >+ 2873, 2981, 2633, 2367, 2407, 2354, 2194, 2247, 2247, 2114, >+ 3225, 3197, 2633, 2580, 2274, 2181, 2247, 2221, 2221, 2141, >+ 3178, 3310, 2740, 2407, 2274, 2274, 2274, 2287, 2194, 2114, >+ 3141, 3272, 2460, 2061, 2287, 2500, 2367, 2487, 2434, 2181, >+ 3507, 3282, 2314, 2700, 2647, 2474, 2367, 2394, 2340, 2127, >+ 3423, 3535, 3038, 3056, 2300, 1950, 2221, 2274, 2274, 2274, >+ 3404, 3366, 2087, 2687, 2873, 2354, 2420, 2274, 2474, 2540, >+ 3760, 3488, 1950, 2660, 2897, 2527, 2394, 2367, 2460, 2261, >+ 3028, 3272, 2740, 2888, 2740, 2154, 2127, 2287, 2234, 2247, >+ 3695, 3657, 2025, 1969, 2660, 2700, 2580, 2500, 2327, 2367, >+ 3207, 3413, 2354, 2074, 2888, 2888, 2340, 2487, 2247, 2167, >+ 3338, 3366, 2846, 2780, 2327, 2154, 2274, 2287, 2114, 2061, >+ 2327, 2300, 2181, 2167, 2181, 2367, 2633, 2700, 2700, 2553, >+ 2407, 2434, 2221, 2261, 2221, 2221, 2340, 2420, 2607, 2700, >+ 3038, 3244, 2806, 2888, 2474, 2074, 2300, 2314, 2354, 2380, >+ 2221, 2154, 2127, 2287, 2500, 2793, 2793, 2620, 2580, 2367, >+ 3676, 3713, 2234, 1838, 2181, 2753, 2726, 2673, 2513, 2207, >+ 2793, 3160, 2726, 2553, 2846, 2513, 2181, 2394, 2221, 2181 >+}; >+ > static const opus_uint8 silk_NLSF_CB1_iCDF_NB_MB[ 64 ] = { > 212, 178, 148, 129, 108, 96, 85, 82, > 79, 77, 61, 59, 57, 56, 51, 49, >@@ -150,6 +185,7 @@ const silk_NLSF_CB_struct silk_NLSF_CB_NB_MB = > SILK_FIX_CONST( 0.18, 16 ), > SILK_FIX_CONST( 1.0 / 0.18, 6 ), > silk_NLSF_CB1_NB_MB_Q8, >+ silk_NLSF_CB1_Wght_Q9, > silk_NLSF_CB1_iCDF_NB_MB, > silk_NLSF_PRED_NB_MB_Q8, > silk_NLSF_CB2_SELECT_NB_MB, >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/tables_NLSF_CB_WB.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/tables_NLSF_CB_WB.c >index 50af87eb2e1c1d74286269074b5d8a09262027c3..5cc9f57bffca77886de8764d32d62213da5dafd2 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/tables_NLSF_CB_WB.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/tables_NLSF_CB_WB.c >@@ -98,6 +98,41 @@ static const opus_uint8 silk_NLSF_CB1_WB_Q8[ 512 ] = { > 110, 119, 129, 141, 175, 198, 218, 237 > }; > >+static const opus_int16 silk_NLSF_CB1_WB_Wght_Q9[ 512 ] = { >+ 3657, 2925, 2925, 2925, 2925, 2925, 2925, 2925, 2925, 2925, 2925, 2925, 2963, 2963, 2925, 2846, >+ 3216, 3085, 2972, 3056, 3056, 3010, 3010, 3010, 2963, 2963, 3010, 2972, 2888, 2846, 2846, 2726, >+ 3920, 4014, 2981, 3207, 3207, 2934, 3056, 2846, 3122, 3244, 2925, 2846, 2620, 2553, 2780, 2925, >+ 3516, 3197, 3010, 3103, 3019, 2888, 2925, 2925, 2925, 2925, 2888, 2888, 2888, 2888, 2888, 2753, >+ 5054, 5054, 2934, 3573, 3385, 3056, 3085, 2793, 3160, 3160, 2972, 2846, 2513, 2540, 2753, 2888, >+ 4428, 4149, 2700, 2753, 2972, 3010, 2925, 2846, 2981, 3019, 2925, 2925, 2925, 2925, 2888, 2726, >+ 3620, 3019, 2972, 3056, 3056, 2873, 2806, 3056, 3216, 3047, 2981, 3291, 3291, 2981, 3310, 2991, >+ 5227, 5014, 2540, 3338, 3526, 3385, 3197, 3094, 3376, 2981, 2700, 2647, 2687, 2793, 2846, 2673, >+ 5081, 5174, 4615, 4428, 2460, 2897, 3047, 3207, 3169, 2687, 2740, 2888, 2846, 2793, 2846, 2700, >+ 3122, 2888, 2963, 2925, 2925, 2925, 2925, 2963, 2963, 2963, 2963, 2925, 2925, 2963, 2963, 2963, >+ 4202, 3207, 2981, 3103, 3010, 2888, 2888, 2925, 2972, 2873, 2916, 3019, 2972, 3010, 3197, 2873, >+ 3760, 3760, 3244, 3103, 2981, 2888, 2925, 2888, 2972, 2934, 2793, 2793, 2846, 2888, 2888, 2660, >+ 3854, 4014, 3207, 3122, 3244, 2934, 3047, 2963, 2963, 3085, 2846, 2793, 2793, 2793, 2793, 2580, >+ 3845, 4080, 3357, 3516, 3094, 2740, 3010, 2934, 3122, 3085, 2846, 2846, 2647, 2647, 2846, 2806, >+ 5147, 4894, 3225, 3845, 3441, 3169, 2897, 3413, 3451, 2700, 2580, 2673, 2740, 2846, 2806, 2753, >+ 4109, 3789, 3291, 3160, 2925, 2888, 2888, 2925, 2793, 2740, 2793, 2740, 2793, 2846, 2888, 2806, >+ 5081, 5054, 3047, 3545, 3244, 3056, 3085, 2944, 3103, 2897, 2740, 2740, 2740, 2846, 2793, 2620, >+ 4309, 4309, 2860, 2527, 3207, 3376, 3376, 3075, 3075, 3376, 3056, 2846, 2647, 2580, 2726, 2753, >+ 3056, 2916, 2806, 2888, 2740, 2687, 2897, 3103, 3150, 3150, 3216, 3169, 3056, 3010, 2963, 2846, >+ 4375, 3882, 2925, 2888, 2846, 2888, 2846, 2846, 2888, 2888, 2888, 2846, 2888, 2925, 2888, 2846, >+ 2981, 2916, 2916, 2981, 2981, 3056, 3122, 3216, 3150, 3056, 3010, 2972, 2972, 2972, 2925, 2740, >+ 4229, 4149, 3310, 3347, 2925, 2963, 2888, 2981, 2981, 2846, 2793, 2740, 2846, 2846, 2846, 2793, >+ 4080, 4014, 3103, 3010, 2925, 2925, 2925, 2888, 2925, 2925, 2846, 2846, 2846, 2793, 2888, 2780, >+ 4615, 4575, 3169, 3441, 3207, 2981, 2897, 3038, 3122, 2740, 2687, 2687, 2687, 2740, 2793, 2700, >+ 4149, 4269, 3789, 3657, 2726, 2780, 2888, 2888, 3010, 2972, 2925, 2846, 2687, 2687, 2793, 2888, >+ 4215, 3554, 2753, 2846, 2846, 2888, 2888, 2888, 2925, 2925, 2888, 2925, 2925, 2925, 2963, 2888, >+ 5174, 4921, 2261, 3432, 3789, 3479, 3347, 2846, 3310, 3479, 3150, 2897, 2460, 2487, 2753, 2925, >+ 3451, 3685, 3122, 3197, 3357, 3047, 3207, 3207, 2981, 3216, 3085, 2925, 2925, 2687, 2540, 2434, >+ 2981, 3010, 2793, 2793, 2740, 2793, 2846, 2972, 3056, 3103, 3150, 3150, 3150, 3103, 3010, 3010, >+ 2944, 2873, 2687, 2726, 2780, 3010, 3432, 3545, 3357, 3244, 3056, 3010, 2963, 2925, 2888, 2846, >+ 3019, 2944, 2897, 3010, 3010, 2972, 3019, 3103, 3056, 3056, 3010, 2888, 2846, 2925, 2925, 2888, >+ 3920, 3967, 3010, 3197, 3357, 3216, 3291, 3291, 3479, 3704, 3441, 2726, 2181, 2460, 2580, 2607 >+}; >+ > static const opus_uint8 silk_NLSF_CB1_iCDF_WB[ 64 ] = { > 225, 204, 201, 184, 183, 175, 158, 154, > 153, 135, 119, 115, 113, 110, 109, 99, >@@ -188,6 +223,7 @@ const silk_NLSF_CB_struct silk_NLSF_CB_WB = > SILK_FIX_CONST( 0.15, 16 ), > SILK_FIX_CONST( 1.0 / 0.15, 6 ), > silk_NLSF_CB1_WB_Q8, >+ silk_NLSF_CB1_WB_Wght_Q9, > silk_NLSF_CB1_iCDF_WB, > silk_NLSF_PRED_WB_Q8, > silk_NLSF_CB2_SELECT_WB, >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/tests/test_unit_LPC_inv_pred_gain.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/tests/test_unit_LPC_inv_pred_gain.c >new file mode 100644 >index 0000000000000000000000000000000000000000..67067cead70297fe77361ae555aa9bc304b87ff6 >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/tests/test_unit_LPC_inv_pred_gain.c >@@ -0,0 +1,129 @@ >+/*********************************************************************** >+Copyright (c) 2017 Google Inc., Jean-Marc Valin >+Redistribution and use in source and binary forms, with or without >+modification, are permitted provided that the following conditions >+are met: >+- Redistributions of source code must retain the above copyright notice, >+this list of conditions and the following disclaimer. >+- Redistributions in binary form must reproduce the above copyright >+notice, this list of conditions and the following disclaimer in the >+documentation and/or other materials provided with the distribution. >+- Neither the name of Internet Society, IETF or IETF Trust, nor the >+names of specific contributors, may be used to endorse or promote >+products derived from this software without specific prior written >+permission. >+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" >+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE >+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE >+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE >+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE >+POSSIBILITY OF SUCH DAMAGE. >+***********************************************************************/ >+ >+#ifdef HAVE_CONFIG_H >+#include "config.h" >+#endif >+ >+#include <stdio.h> >+#include <stdlib.h> >+#include "celt/stack_alloc.h" >+#include "cpu_support.h" >+#include "SigProc_FIX.h" >+ >+/* Computes the impulse response of the filter so we >+ can catch filters that are definitely unstable. Some >+ unstable filters may be classified as stable, but not >+ the other way around. */ >+int check_stability(opus_int16 *A_Q12, int order) { >+ int i; >+ int j; >+ int sum_a, sum_abs_a; >+ sum_a = sum_abs_a = 0; >+ for( j = 0; j < order; j++ ) { >+ sum_a += A_Q12[ j ]; >+ sum_abs_a += silk_abs( A_Q12[ j ] ); >+ } >+ /* Check DC stability. */ >+ if( sum_a >= 4096 ) { >+ return 0; >+ } >+ /* If the sum of absolute values is less than 1, the filter >+ has to be stable. */ >+ if( sum_abs_a < 4096 ) { >+ return 1; >+ } >+ double y[SILK_MAX_ORDER_LPC] = {0}; >+ y[0] = 1; >+ for( i = 0; i < 10000; i++ ) { >+ double sum = 0; >+ for( j = 0; j < order; j++ ) { >+ sum += y[ j ]*A_Q12[ j ]; >+ } >+ for( j = order - 1; j > 0; j-- ) { >+ y[ j ] = y[ j - 1 ]; >+ } >+ y[ 0 ] = sum*(1./4096); >+ /* If impulse response reaches +/- 10000, the filter >+ is definitely unstable. */ >+ if( !(y[ 0 ] < 10000 && y[ 0 ] > -10000) ) { >+ return 0; >+ } >+ /* Test every 8 sample for low amplitude. */ >+ if( ( i & 0x7 ) == 0 ) { >+ double amp = 0; >+ for( j = 0; j < order; j++ ) { >+ amp += fabs(y[j]); >+ } >+ if( amp < 0.00001 ) { >+ return 1; >+ } >+ } >+ } >+ return 1; >+} >+ >+int main(void) { >+ const int arch = opus_select_arch(); >+ /* Set to 10000 so all branches in C function are triggered */ >+ const int loop_num = 10000; >+ int count = 0; >+ ALLOC_STACK; >+ >+ /* FIXME: Make the seed random (with option to set it explicitly) >+ so we get wider coverage. */ >+ srand(0); >+ >+ printf("Testing silk_LPC_inverse_pred_gain() optimization ...\n"); >+ for( count = 0; count < loop_num; count++ ) { >+ unsigned int i; >+ opus_int order; >+ unsigned int shift; >+ opus_int16 A_Q12[ SILK_MAX_ORDER_LPC ]; >+ opus_int32 gain; >+ >+ for( order = 2; order <= SILK_MAX_ORDER_LPC; order += 2 ) { /* order must be even. */ >+ for( shift = 0; shift < 16; shift++ ) { /* Different dynamic range. */ >+ for( i = 0; i < SILK_MAX_ORDER_LPC; i++ ) { >+ A_Q12[i] = ((opus_int16)rand()) >> shift; >+ } >+ gain = silk_LPC_inverse_pred_gain(A_Q12, order, arch); >+ /* Look for filters that silk_LPC_inverse_pred_gain() thinks are >+ stable but definitely aren't. */ >+ if( gain != 0 && !check_stability(A_Q12, order) ) { >+ fprintf(stderr, "**Loop %4d failed!**\n", count); >+ return 1; >+ } >+ } >+ } >+ if( !(count % 500) ) { >+ printf("Loop %4d passed\n", count); >+ } >+ } >+ printf("silk_LPC_inverse_pred_gain() optimization passed\n"); >+ return 0; >+} >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/tuning_parameters.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/tuning_parameters.h >index 5b8f404235f491d9b4bedaa48f3942307e7d12a1..d70275fd8f5dd15e3c68bd28d3215b40c49bbe54 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/tuning_parameters.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/tuning_parameters.h >@@ -53,19 +53,12 @@ extern "C" > /* LPC analysis regularization */ > #define FIND_LPC_COND_FAC 1e-5f > >-/* LTP analysis defines */ >-#define FIND_LTP_COND_FAC 1e-5f >-#define LTP_DAMPING 0.05f >-#define LTP_SMOOTHING 0.1f >- >-/* LTP quantization settings */ >-#define MU_LTP_QUANT_NB 0.03f >-#define MU_LTP_QUANT_MB 0.025f >-#define MU_LTP_QUANT_WB 0.02f >- > /* Max cumulative LTP gain */ > #define MAX_SUM_LOG_GAIN_DB 250.0f > >+/* LTP analysis defines */ >+#define LTP_CORR_INV_MAX 0.03f >+ > /***********************/ > /* High pass filtering */ > /***********************/ >@@ -103,25 +96,16 @@ extern "C" > #define SPARSE_SNR_INCR_dB 2.0f > > /* threshold for sparseness measure above which to use lower quantization offset during unvoiced */ >-#define SPARSENESS_THRESHOLD_QNT_OFFSET 0.75f >+#define ENERGY_VARIATION_THRESHOLD_QNT_OFFSET 0.6f > > /* warping control */ > #define WARPING_MULTIPLIER 0.015f > > /* fraction added to first autocorrelation value */ >-#define SHAPE_WHITE_NOISE_FRACTION 5e-5f >+#define SHAPE_WHITE_NOISE_FRACTION 3e-5f > > /* noise shaping filter chirp factor */ >-#define BANDWIDTH_EXPANSION 0.95f >- >-/* difference between chirp factors for analysis and synthesis noise shaping filters at low bitrates */ >-#define LOW_RATE_BANDWIDTH_EXPANSION_DELTA 0.01f >- >-/* extra harmonic boosting (signal shaping) at low bitrates */ >-#define LOW_RATE_HARMONIC_BOOST 0.1f >- >-/* extra harmonic boosting (signal shaping) for noisy input signals */ >-#define LOW_INPUT_QUALITY_HARMONIC_BOOST 0.1f >+#define BANDWIDTH_EXPANSION 0.94f > > /* harmonic noise shaping */ > #define HARMONIC_SHAPING 0.3f >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/x86/NSQ_del_dec_sse.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/x86/NSQ_del_dec_sse.c >index 21d4a8bc1e960af9a95ab202cc951d14c04601b3..c5212bee8d3a1b1c2162ce832681145bb747c76b 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/x86/NSQ_del_dec_sse.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/x86/NSQ_del_dec_sse.c >@@ -107,12 +107,12 @@ static OPUS_INLINE void silk_noise_shape_quantizer_del_dec_sse4_1( > opus_int predictLPCOrder, /* I Prediction filter order */ > opus_int warping_Q16, /* I */ > opus_int nStatesDelayedDecision, /* I Number of states in decision tree */ >- opus_int *smpl_buf_idx, /* I Index to newest samples in buffers */ >+ opus_int *smpl_buf_idx, /* I/O Index to newest samples in buffers */ > opus_int decisionDelay /* I */ > ); > > void silk_NSQ_del_dec_sse4_1( >- const silk_encoder_state *psEncC, /* I/O Encoder State */ >+ const silk_encoder_state *psEncC, /* I Encoder State */ > silk_nsq_state *NSQ, /* I/O NSQ state */ > SideInfoIndices *psIndices, /* I/O Quantization Indices */ > const opus_int32 x_Q3[], /* I Prefiltered input signal */ >@@ -234,7 +234,8 @@ void silk_NSQ_del_dec_sse4_1( > psDD = &psDelDec[ Winner_ind ]; > last_smple_idx = smpl_buf_idx + decisionDelay; > for( i = 0; i < decisionDelay; i++ ) { >- last_smple_idx = ( last_smple_idx - 1 ) & DECISION_DELAY_MASK; >+ last_smple_idx = ( last_smple_idx - 1 ) % DECISION_DELAY; >+ if( last_smple_idx < 0 ) last_smple_idx += DECISION_DELAY; > pulses[ i - decisionDelay ] = (opus_int8)silk_RSHIFT_ROUND( psDD->Q_Q10[ last_smple_idx ], 10 ); > pxq[ i - decisionDelay ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( > silk_SMULWW( psDD->Xq_Q14[ last_smple_idx ], Gains_Q16[ 1 ] ), 14 ) ); >@@ -285,7 +286,8 @@ void silk_NSQ_del_dec_sse4_1( > last_smple_idx = smpl_buf_idx + decisionDelay; > Gain_Q10 = silk_RSHIFT32( Gains_Q16[ psEncC->nb_subfr - 1 ], 6 ); > for( i = 0; i < decisionDelay; i++ ) { >- last_smple_idx = ( last_smple_idx - 1 ) & DECISION_DELAY_MASK; >+ last_smple_idx = ( last_smple_idx - 1 ) % DECISION_DELAY; >+ if( last_smple_idx < 0 ) last_smple_idx += DECISION_DELAY; > pulses[ i - decisionDelay ] = (opus_int8)silk_RSHIFT_ROUND( psDD->Q_Q10[ last_smple_idx ], 10 ); > pxq[ i - decisionDelay ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( > silk_SMULWW( psDD->Xq_Q14[ last_smple_idx ], Gain_Q10 ), 8 ) ); >@@ -299,7 +301,6 @@ void silk_NSQ_del_dec_sse4_1( > NSQ->lagPrev = pitchL[ psEncC->nb_subfr - 1 ]; > > /* Save quantized speech signal */ >- /* DEBUG_STORE_DATA( enc.pcm, &NSQ->xq[psEncC->ltp_mem_length], psEncC->frame_length * sizeof( opus_int16 ) ) */ > silk_memmove( NSQ->xq, &NSQ->xq[ psEncC->frame_length ], psEncC->ltp_mem_length * sizeof( opus_int16 ) ); > silk_memmove( NSQ->sLTP_shp_Q14, &NSQ->sLTP_shp_Q14[ psEncC->frame_length ], psEncC->ltp_mem_length * sizeof( opus_int32 ) ); > RESTORE_STACK; >@@ -333,7 +334,7 @@ static OPUS_INLINE void silk_noise_shape_quantizer_del_dec_sse4_1( > opus_int predictLPCOrder, /* I Prediction filter order */ > opus_int warping_Q16, /* I */ > opus_int nStatesDelayedDecision, /* I Number of states in decision tree */ >- opus_int *smpl_buf_idx, /* I Index to newest samples in buffers */ >+ opus_int *smpl_buf_idx, /* I/O Index to newest samples in buffers */ > opus_int decisionDelay /* I */ > ) > { >@@ -638,8 +639,9 @@ static OPUS_INLINE void silk_noise_shape_quantizer_del_dec_sse4_1( > psSS[ 1 ].xq_Q14 = xq_Q14; > } > } >- *smpl_buf_idx = ( *smpl_buf_idx - 1 ) & DECISION_DELAY_MASK; /* Index to newest samples */ >- last_smple_idx = ( *smpl_buf_idx + decisionDelay ) & DECISION_DELAY_MASK; /* Index to decisionDelay old samples */ >+ *smpl_buf_idx = ( *smpl_buf_idx - 1 ) % DECISION_DELAY; >+ if( *smpl_buf_idx < 0 ) *smpl_buf_idx += DECISION_DELAY; >+ last_smple_idx = ( *smpl_buf_idx + decisionDelay ) % DECISION_DELAY; > > /* Find winner */ > RDmin_Q10 = psSampleState[ 0 ][ 0 ].RD_Q10; >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/x86/NSQ_sse.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/x86/NSQ_sse.c >index bb3c5f195570ebcd87ddc6b0f6f400bcce3b2127..6a9e6e96cfab85c47aedd52adca5ec4b462ab815 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/x86/NSQ_sse.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/x86/NSQ_sse.c >@@ -71,7 +71,7 @@ static OPUS_INLINE void silk_noise_shape_quantizer_10_16_sse4_1( > ); > > void silk_NSQ_sse4_1( >- const silk_encoder_state *psEncC, /* I/O Encoder State */ >+ const silk_encoder_state *psEncC, /* I Encoder State */ > silk_nsq_state *NSQ, /* I/O NSQ state */ > SideInfoIndices *psIndices, /* I/O Quantization Indices */ > const opus_int32 x_Q3[], /* I Prefiltered input signal */ >@@ -233,7 +233,6 @@ void silk_NSQ_sse4_1( > NSQ->lagPrev = pitchL[ psEncC->nb_subfr - 1 ]; > > /* Save quantized speech and noise shaping signals */ >- /* DEBUG_STORE_DATA( enc.pcm, &NSQ->xq[ psEncC->ltp_mem_length ], psEncC->frame_length * sizeof( opus_int16 ) ) */ > silk_memmove( NSQ->xq, &NSQ->xq[ psEncC->frame_length ], psEncC->ltp_mem_length * sizeof( opus_int16 ) ); > silk_memmove( NSQ->sLTP_shp_Q14, &NSQ->sLTP_shp_Q14[ psEncC->frame_length ], psEncC->ltp_mem_length * sizeof( opus_int32 ) ); > RESTORE_STACK; >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/x86/main_sse.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/x86/main_sse.h >index d8d61310edcf96e01eaed42468e327b9de2d4a38..2f15d44869781c435014dd1ddb2c02423b16e3c1 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/x86/main_sse.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/x86/main_sse.h >@@ -34,6 +34,7 @@ > > # if defined(OPUS_X86_MAY_HAVE_SSE4_1) > >+#if 0 /* FIXME: SSE disabled until silk_VQ_WMat_EC_sse4_1() gets updated. */ > # define OVERRIDE_silk_VQ_WMat_EC > > void silk_VQ_WMat_EC_sse4_1( >@@ -79,11 +80,13 @@ extern void (*const SILK_VQ_WMAT_EC_IMPL[OPUS_ARCHMASK + 1])( > mu_Q9, max_gain_Q7, L)) > > #endif >+#endif > >+#if 0 /* FIXME: SSE disabled until the NSQ code gets updated. */ > # define OVERRIDE_silk_NSQ > > void silk_NSQ_sse4_1( >- const silk_encoder_state *psEncC, /* I/O Encoder State */ >+ const silk_encoder_state *psEncC, /* I Encoder State */ > silk_nsq_state *NSQ, /* I/O NSQ state */ > SideInfoIndices *psIndices, /* I/O Quantization Indices */ > const opus_int32 x_Q3[], /* I Prefiltered input signal */ >@@ -110,7 +113,7 @@ void silk_NSQ_sse4_1( > #else > > extern void (*const SILK_NSQ_IMPL[OPUS_ARCHMASK + 1])( >- const silk_encoder_state *psEncC, /* I/O Encoder State */ >+ const silk_encoder_state *psEncC, /* I Encoder State */ > silk_nsq_state *NSQ, /* I/O NSQ state */ > SideInfoIndices *psIndices, /* I/O Quantization Indices */ > const opus_int32 x_Q3[], /* I Prefiltered input signal */ >@@ -137,7 +140,7 @@ extern void (*const SILK_NSQ_IMPL[OPUS_ARCHMASK + 1])( > # define OVERRIDE_silk_NSQ_del_dec > > void silk_NSQ_del_dec_sse4_1( >- const silk_encoder_state *psEncC, /* I/O Encoder State */ >+ const silk_encoder_state *psEncC, /* I Encoder State */ > silk_nsq_state *NSQ, /* I/O NSQ state */ > SideInfoIndices *psIndices, /* I/O Quantization Indices */ > const opus_int32 x_Q3[], /* I Prefiltered input signal */ >@@ -164,7 +167,7 @@ void silk_NSQ_del_dec_sse4_1( > #else > > extern void (*const SILK_NSQ_DEL_DEC_IMPL[OPUS_ARCHMASK + 1])( >- const silk_encoder_state *psEncC, /* I/O Encoder State */ >+ const silk_encoder_state *psEncC, /* I Encoder State */ > silk_nsq_state *NSQ, /* I/O NSQ state */ > SideInfoIndices *psIndices, /* I/O Quantization Indices */ > const opus_int32 x_Q3[], /* I Prefiltered input signal */ >@@ -187,6 +190,7 @@ extern void (*const SILK_NSQ_DEL_DEC_IMPL[OPUS_ARCHMASK + 1])( > HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, pitchL, Lambda_Q10, LTP_scale_Q14)) > > #endif >+#endif > > void silk_noise_shape_quantizer( > silk_nsq_state *NSQ, /* I/O NSQ state */ >@@ -238,39 +242,6 @@ extern opus_int (*const SILK_VAD_GETSA_Q8_IMPL[OPUS_ARCHMASK + 1])( > silk_encoder_state *psEnC, > const opus_int16 pIn[]); > >-# define OVERRIDE_silk_warped_LPC_analysis_filter_FIX >- >-#endif >- >-void silk_warped_LPC_analysis_filter_FIX_sse4_1( >- opus_int32 state[], /* I/O State [order + 1] */ >- opus_int32 res_Q2[], /* O Residual signal [length] */ >- const opus_int16 coef_Q13[], /* I Coefficients [order] */ >- const opus_int16 input[], /* I Input signal [length] */ >- const opus_int16 lambda_Q16, /* I Warping factor */ >- const opus_int length, /* I Length of input signal */ >- const opus_int order /* I Filter order (even) */ >-); >- >-#if defined(OPUS_X86_PRESUME_SSE4_1) >-#define silk_warped_LPC_analysis_filter_FIX(state, res_Q2, coef_Q13, input, lambda_Q16, length, order, arch) \ >- ((void)(arch),silk_warped_LPC_analysis_filter_FIX_c(state, res_Q2, coef_Q13, input, lambda_Q16, length, order)) >- >-#else >- >-extern void (*const SILK_WARPED_LPC_ANALYSIS_FILTER_FIX_IMPL[OPUS_ARCHMASK + 1])( >- opus_int32 state[], /* I/O State [order + 1] */ >- opus_int32 res_Q2[], /* O Residual signal [length] */ >- const opus_int16 coef_Q13[], /* I Coefficients [order] */ >- const opus_int16 input[], /* I Input signal [length] */ >- const opus_int16 lambda_Q16, /* I Warping factor */ >- const opus_int length, /* I Length of input signal */ >- const opus_int order /* I Filter order (even) */ >-); >- >-# define silk_warped_LPC_analysis_filter_FIX(state, res_Q2, coef_Q13, input, lambda_Q16, length, order, arch) \ >- ((*SILK_WARPED_LPC_ANALYSIS_FILTER_FIX_IMPL[(arch) & OPUS_ARCHMASK])(state, res_Q2, coef_Q13, input, lambda_Q16, length, order)) >- > #endif > > # endif >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/x86/x86_silk_map.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/x86/x86_silk_map.c >index 818841f2c190799f33a3fad89edef61ace1ac716..32dcc3cab7a93bd6c3509a89d4b80771aad2ddf5 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/x86/x86_silk_map.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/x86/x86_silk_map.c >@@ -66,8 +66,9 @@ opus_int (*const SILK_VAD_GETSA_Q8_IMPL[ OPUS_ARCHMASK + 1 ] )( > MAY_HAVE_SSE4_1( silk_VAD_GetSA_Q8 ) /* avx */ > }; > >+#if 0 /* FIXME: SSE disabled until the NSQ code gets updated. */ > void (*const SILK_NSQ_IMPL[ OPUS_ARCHMASK + 1 ] )( >- const silk_encoder_state *psEncC, /* I/O Encoder State */ >+ const silk_encoder_state *psEncC, /* I Encoder State */ > silk_nsq_state *NSQ, /* I/O NSQ state */ > SideInfoIndices *psIndices, /* I/O Quantization Indices */ > const opus_int32 x_Q3[], /* I Prefiltered input signal */ >@@ -89,7 +90,9 @@ void (*const SILK_NSQ_IMPL[ OPUS_ARCHMASK + 1 ] )( > MAY_HAVE_SSE4_1( silk_NSQ ), /* sse4.1 */ > MAY_HAVE_SSE4_1( silk_NSQ ) /* avx */ > }; >+#endif > >+#if 0 /* FIXME: SSE disabled until silk_VQ_WMat_EC_sse4_1() gets updated. */ > void (*const SILK_VQ_WMAT_EC_IMPL[ OPUS_ARCHMASK + 1 ] )( > opus_int8 *ind, /* O index of best codebook vector */ > opus_int32 *rate_dist_Q14, /* O best weighted quant error + mu * rate */ >@@ -109,9 +112,11 @@ void (*const SILK_VQ_WMAT_EC_IMPL[ OPUS_ARCHMASK + 1 ] )( > MAY_HAVE_SSE4_1( silk_VQ_WMat_EC ), /* sse4.1 */ > MAY_HAVE_SSE4_1( silk_VQ_WMat_EC ) /* avx */ > }; >+#endif > >+#if 0 /* FIXME: SSE disabled until the NSQ code gets updated. */ > void (*const SILK_NSQ_DEL_DEC_IMPL[ OPUS_ARCHMASK + 1 ] )( >- const silk_encoder_state *psEncC, /* I/O Encoder State */ >+ const silk_encoder_state *psEncC, /* I Encoder State */ > silk_nsq_state *NSQ, /* I/O NSQ state */ > SideInfoIndices *psIndices, /* I/O Quantization Indices */ > const opus_int32 x_Q3[], /* I Prefiltered input signal */ >@@ -133,25 +138,10 @@ void (*const SILK_NSQ_DEL_DEC_IMPL[ OPUS_ARCHMASK + 1 ] )( > MAY_HAVE_SSE4_1( silk_NSQ_del_dec ), /* sse4.1 */ > MAY_HAVE_SSE4_1( silk_NSQ_del_dec ) /* avx */ > }; >+#endif > > #if defined(FIXED_POINT) > >-void (*const SILK_WARPED_LPC_ANALYSIS_FILTER_FIX_IMPL[ OPUS_ARCHMASK + 1 ] )( >- opus_int32 state[], /* I/O State [order + 1] */ >- opus_int32 res_Q2[], /* O Residual signal [length] */ >- const opus_int16 coef_Q13[], /* I Coefficients [order] */ >- const opus_int16 input[], /* I Input signal [length] */ >- const opus_int16 lambda_Q16, /* I Warping factor */ >- const opus_int length, /* I Length of input signal */ >- const opus_int order /* I Filter order (even) */ >-) = { >- silk_warped_LPC_analysis_filter_FIX_c, /* non-sse */ >- silk_warped_LPC_analysis_filter_FIX_c, >- silk_warped_LPC_analysis_filter_FIX_c, >- MAY_HAVE_SSE4_1( silk_warped_LPC_analysis_filter_FIX ), /* sse4.1 */ >- MAY_HAVE_SSE4_1( silk_warped_LPC_analysis_filter_FIX ) /* avx */ >-}; >- > void (*const SILK_BURG_MODIFIED_IMPL[ OPUS_ARCHMASK + 1 ] )( > opus_int32 *res_nrg, /* O Residual energy */ > opus_int *res_nrg_Q, /* O Residual energy Q value */ >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/analysis.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/analysis.c >index 663431a436a1c81a9ba73ff2a6f2d7fffaebb158..f4160e4b4ed5c114cf7d610dbd97a1569060a077 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/analysis.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/analysis.c >@@ -29,20 +29,27 @@ > #include "config.h" > #endif > >+#define ANALYSIS_C >+ >+#include <stdio.h> >+ >+#include "mathops.h" > #include "kiss_fft.h" > #include "celt.h" > #include "modes.h" > #include "arch.h" > #include "quant_bands.h" >-#include <stdio.h> > #include "analysis.h" > #include "mlp.h" > #include "stack_alloc.h" >+#include "float_cast.h" > > #ifndef M_PI > #define M_PI 3.141592653 > #endif > >+#ifndef DISABLE_FLOAT_API >+ > static const float dct_table[128] = { > 0.250000f, 0.250000f, 0.250000f, 0.250000f, 0.250000f, 0.250000f, 0.250000f, 0.250000f, > 0.250000f, 0.250000f, 0.250000f, 0.250000f, 0.250000f, 0.250000f, 0.250000f, 0.250000f, >@@ -96,52 +103,118 @@ static const float analysis_window[240] = { > }; > > static const int tbands[NB_TBANDS+1] = { >- 2, 4, 6, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56, 68, 80, 96, 120 >+ 4, 8, 12, 16, 20, 24, 28, 32, 40, 48, 56, 64, 80, 96, 112, 136, 160, 192, 240 > }; > >-static const int extra_bands[NB_TOT_BANDS+1] = { >- 1, 2, 4, 6, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56, 68, 80, 96, 120, 160, 200 >-}; >- >-/*static const float tweight[NB_TBANDS+1] = { >- .3, .4, .5, .6, .7, .8, .9, 1., 1., 1., 1., 1., 1., 1., .8, .7, .6, .5 >-};*/ >- > #define NB_TONAL_SKIP_BANDS 9 > >-#define cA 0.43157974f >-#define cB 0.67848403f >-#define cC 0.08595542f >-#define cE ((float)M_PI/2) >-static OPUS_INLINE float fast_atan2f(float y, float x) { >- float x2, y2; >- /* Should avoid underflow on the values we'll get */ >- if (ABS16(x)+ABS16(y)<1e-9f) >+static opus_val32 silk_resampler_down2_hp( >+ opus_val32 *S, /* I/O State vector [ 2 ] */ >+ opus_val32 *out, /* O Output signal [ floor(len/2) ] */ >+ const opus_val32 *in, /* I Input signal [ len ] */ >+ int inLen /* I Number of input samples */ >+) >+{ >+ int k, len2 = inLen/2; >+ opus_val32 in32, out32, out32_hp, Y, X; >+ opus_val64 hp_ener = 0; >+ /* Internal variables and state are in Q10 format */ >+ for( k = 0; k < len2; k++ ) { >+ /* Convert to Q10 */ >+ in32 = in[ 2 * k ]; >+ >+ /* All-pass section for even input sample */ >+ Y = SUB32( in32, S[ 0 ] ); >+ X = MULT16_32_Q15(QCONST16(0.6074371f, 15), Y); >+ out32 = ADD32( S[ 0 ], X ); >+ S[ 0 ] = ADD32( in32, X ); >+ out32_hp = out32; >+ /* Convert to Q10 */ >+ in32 = in[ 2 * k + 1 ]; >+ >+ /* All-pass section for odd input sample, and add to output of previous section */ >+ Y = SUB32( in32, S[ 1 ] ); >+ X = MULT16_32_Q15(QCONST16(0.15063f, 15), Y); >+ out32 = ADD32( out32, S[ 1 ] ); >+ out32 = ADD32( out32, X ); >+ S[ 1 ] = ADD32( in32, X ); >+ >+ Y = SUB32( -in32, S[ 2 ] ); >+ X = MULT16_32_Q15(QCONST16(0.15063f, 15), Y); >+ out32_hp = ADD32( out32_hp, S[ 2 ] ); >+ out32_hp = ADD32( out32_hp, X ); >+ S[ 2 ] = ADD32( -in32, X ); >+ >+ hp_ener += out32_hp*(opus_val64)out32_hp; >+ /* Add, convert back to int16 and store to output */ >+ out[ k ] = HALF32(out32); >+ } >+#ifdef FIXED_POINT >+ /* len2 can be up to 480, so we shift by 8 more to make it fit. */ >+ hp_ener = hp_ener >> (2*SIG_SHIFT + 8); >+#endif >+ return (opus_val32)hp_ener; >+} >+ >+static opus_val32 downmix_and_resample(downmix_func downmix, const void *_x, opus_val32 *y, opus_val32 S[3], int subframe, int offset, int c1, int c2, int C, int Fs) >+{ >+ VARDECL(opus_val32, tmp); >+ opus_val32 scale; >+ int j; >+ opus_val32 ret = 0; >+ SAVE_STACK; >+ >+ if (subframe==0) return 0; >+ if (Fs == 48000) > { >- x*=1e12f; >- y*=1e12f; >+ subframe *= 2; >+ offset *= 2; >+ } else if (Fs == 16000) { >+ subframe = subframe*2/3; >+ offset = offset*2/3; > } >- x2 = x*x; >- y2 = y*y; >- if(x2<y2){ >- float den = (y2 + cB*x2) * (y2 + cC*x2); >- if (den!=0) >- return -x*y*(y2 + cA*x2) / den + (y<0 ? -cE : cE); >- else >- return (y<0 ? -cE : cE); >- }else{ >- float den = (x2 + cB*y2) * (x2 + cC*y2); >- if (den!=0) >- return x*y*(x2 + cA*y2) / den + (y<0 ? -cE : cE) - (x*y<0 ? -cE : cE); >- else >- return (y<0 ? -cE : cE) - (x*y<0 ? -cE : cE); >+ ALLOC(tmp, subframe, opus_val32); >+ >+ downmix(_x, tmp, subframe, offset, c1, c2, C); >+#ifdef FIXED_POINT >+ scale = (1<<SIG_SHIFT); >+#else >+ scale = 1.f/32768; >+#endif >+ if (c2==-2) >+ scale /= C; >+ else if (c2>-1) >+ scale /= 2; >+ for (j=0;j<subframe;j++) >+ tmp[j] *= scale; >+ if (Fs == 48000) >+ { >+ ret = silk_resampler_down2_hp(S, y, tmp, subframe); >+ } else if (Fs == 24000) { >+ OPUS_COPY(y, tmp, subframe); >+ } else if (Fs == 16000) { >+ VARDECL(opus_val32, tmp3x); >+ ALLOC(tmp3x, 3*subframe, opus_val32); >+ /* Don't do this at home! This resampler is horrible and it's only (barely) >+ usable for the purpose of the analysis because we don't care about all >+ the aliasing between 8 kHz and 12 kHz. */ >+ for (j=0;j<subframe;j++) >+ { >+ tmp3x[3*j] = tmp[j]; >+ tmp3x[3*j+1] = tmp[j]; >+ tmp3x[3*j+2] = tmp[j]; >+ } >+ silk_resampler_down2_hp(S, y, tmp3x, 3*subframe); > } >+ RESTORE_STACK; >+ return ret; > } > >-void tonality_analysis_init(TonalityAnalysisState *tonal) >+void tonality_analysis_init(TonalityAnalysisState *tonal, opus_int32 Fs) > { > /* Initialize reusable fields. */ > tonal->arch = opus_select_arch(); >+ tonal->Fs = Fs; > /* Clear remaining fields. */ > tonality_analysis_reset(tonal); > } >@@ -151,6 +224,8 @@ void tonality_analysis_reset(TonalityAnalysisState *tonal) > /* Clear non-reusable fields. */ > char *start = (char*)&tonal->TONALITY_ANALYSIS_RESET_START; > OPUS_CLEAR(start, sizeof(TonalityAnalysisState) - (start - (char*)tonal)); >+ tonal->music_confidence = .9f; >+ tonal->speech_confidence = .1f; > } > > void tonality_get_info(TonalityAnalysisState *tonal, AnalysisInfo *info_out, int len) >@@ -158,6 +233,9 @@ void tonality_get_info(TonalityAnalysisState *tonal, AnalysisInfo *info_out, int > int pos; > int curr_lookahead; > float psum; >+ float tonality_max; >+ float tonality_avg; >+ int tonality_count; > int i; > > pos = tonal->read_pos; >@@ -165,7 +243,8 @@ void tonality_get_info(TonalityAnalysisState *tonal, AnalysisInfo *info_out, int > if (curr_lookahead<0) > curr_lookahead += DETECT_SIZE; > >- if (len > 480 && pos != tonal->write_pos) >+ /* On long frames, look at the second analysis window rather than the first. */ >+ if (len > tonal->Fs/50 && pos != tonal->write_pos) > { > pos++; > if (pos==DETECT_SIZE) >@@ -176,18 +255,32 @@ void tonality_get_info(TonalityAnalysisState *tonal, AnalysisInfo *info_out, int > if (pos<0) > pos = DETECT_SIZE-1; > OPUS_COPY(info_out, &tonal->info[pos], 1); >- tonal->read_subframe += len/120; >- while (tonal->read_subframe>=4) >+ tonality_max = tonality_avg = info_out->tonality; >+ tonality_count = 1; >+ /* If possible, look ahead for a tone to compensate for the delay in the tone detector. */ >+ for (i=0;i<3;i++) > { >- tonal->read_subframe -= 4; >+ pos++; >+ if (pos==DETECT_SIZE) >+ pos = 0; >+ if (pos == tonal->write_pos) >+ break; >+ tonality_max = MAX32(tonality_max, tonal->info[pos].tonality); >+ tonality_avg += tonal->info[pos].tonality; >+ tonality_count++; >+ } >+ info_out->tonality = MAX32(tonality_avg/tonality_count, tonality_max-.2f); >+ tonal->read_subframe += len/(tonal->Fs/400); >+ while (tonal->read_subframe>=8) >+ { >+ tonal->read_subframe -= 8; > tonal->read_pos++; > } > if (tonal->read_pos>=DETECT_SIZE) > tonal->read_pos-=DETECT_SIZE; > >- /* Compensate for the delay in the features themselves. >- FIXME: Need a better estimate the 10 I just made up */ >- curr_lookahead = IMAX(curr_lookahead-10, 0); >+ /* The -1 is to compensate for the delay in the features themselves. */ >+ curr_lookahead = IMAX(curr_lookahead-1, 0); > > psum=0; > /* Summing the probability of transition patterns that involve music at >@@ -197,11 +290,28 @@ void tonality_get_info(TonalityAnalysisState *tonal, AnalysisInfo *info_out, int > for (;i<DETECT_SIZE;i++) > psum += tonal->pspeech[i]; > psum = psum*tonal->music_confidence + (1-psum)*tonal->speech_confidence; >- /*printf("%f %f %f\n", psum, info_out->music_prob, info_out->tonality);*/ >+ /*printf("%f %f %f %f %f\n", psum, info_out->music_prob, info_out->vad_prob, info_out->activity_probability, info_out->tonality);*/ > > info_out->music_prob = psum; > } > >+static const float std_feature_bias[9] = { >+ 5.684947f, 3.475288f, 1.770634f, 1.599784f, 3.773215f, >+ 2.163313f, 1.260756f, 1.116868f, 1.918795f >+}; >+ >+#define LEAKAGE_OFFSET 2.5f >+#define LEAKAGE_SLOPE 2.f >+ >+#ifdef FIXED_POINT >+/* For fixed-point, the input is +/-2^15 shifted up by SIG_SHIFT, so we need to >+ compensate for that in the energy. */ >+#define SCALE_COMPENS (1.f/((opus_int32)1<<(15+SIG_SHIFT))) >+#define SCALE_ENER(e) ((SCALE_COMPENS*SCALE_COMPENS)*(e)) >+#else >+#define SCALE_ENER(e) (e) >+#endif >+ > static void tonality_analysis(TonalityAnalysisState *tonal, const CELTMode *celt_mode, const void *x, int len, int offset, int c1, int c2, int C, int lsb_depth, downmix_func downmix) > { > int i, b; >@@ -235,19 +345,41 @@ static void tonality_analysis(TonalityAnalysisState *tonal, const CELTMode *celt > float noise_floor; > int remaining; > AnalysisInfo *info; >+ float hp_ener; >+ float tonality2[240]; >+ float midE[8]; >+ float spec_variability=0; >+ float band_log2[NB_TBANDS+1]; >+ float leakage_from[NB_TBANDS+1]; >+ float leakage_to[NB_TBANDS+1]; > SAVE_STACK; > >- tonal->last_transition++; >- alpha = 1.f/IMIN(20, 1+tonal->count); >- alphaE = 1.f/IMIN(50, 1+tonal->count); >- alphaE2 = 1.f/IMIN(1000, 1+tonal->count); >+ alpha = 1.f/IMIN(10, 1+tonal->count); >+ alphaE = 1.f/IMIN(25, 1+tonal->count); >+ alphaE2 = 1.f/IMIN(500, 1+tonal->count); >+ >+ if (tonal->Fs == 48000) >+ { >+ /* len and offset are now at 24 kHz. */ >+ len/= 2; >+ offset /= 2; >+ } else if (tonal->Fs == 16000) { >+ len = 3*len/2; >+ offset = 3*offset/2; >+ } > >- if (tonal->count<4) >- tonal->music_prob = .5; >+ if (tonal->count<4) { >+ if (tonal->application == OPUS_APPLICATION_VOIP) >+ tonal->music_prob = .1f; >+ else >+ tonal->music_prob = .625f; >+ } > kfft = celt_mode->mdct.kfft[0]; > if (tonal->count==0) > tonal->mem_fill = 240; >- downmix(x, &tonal->inmem[tonal->mem_fill], IMIN(len, ANALYSIS_BUF_SIZE-tonal->mem_fill), offset, c1, c2, C); >+ tonal->hp_ener_accum += (float)downmix_and_resample(downmix, x, >+ &tonal->inmem[tonal->mem_fill], tonal->downmix_state, >+ IMIN(len, ANALYSIS_BUF_SIZE-tonal->mem_fill), offset, c1, c2, C, tonal->Fs); > if (tonal->mem_fill+len < ANALYSIS_BUF_SIZE) > { > tonal->mem_fill += len; >@@ -255,6 +387,7 @@ static void tonality_analysis(TonalityAnalysisState *tonal, const CELTMode *celt > RESTORE_STACK; > return; > } >+ hp_ener = tonal->hp_ener_accum; > info = &tonal->info[tonal->write_pos++]; > if (tonal->write_pos>=DETECT_SIZE) > tonal->write_pos-=DETECT_SIZE; >@@ -273,7 +406,9 @@ static void tonality_analysis(TonalityAnalysisState *tonal, const CELTMode *celt > } > OPUS_MOVE(tonal->inmem, tonal->inmem+ANALYSIS_BUF_SIZE-240, 240); > remaining = len - (ANALYSIS_BUF_SIZE-tonal->mem_fill); >- downmix(x, &tonal->inmem[240], remaining, offset+ANALYSIS_BUF_SIZE-tonal->mem_fill, c1, c2, C); >+ tonal->hp_ener_accum = (float)downmix_and_resample(downmix, x, >+ &tonal->inmem[240], tonal->downmix_state, remaining, >+ offset+ANALYSIS_BUF_SIZE-tonal->mem_fill, c1, c2, C, tonal->Fs); > tonal->mem_fill = 240 + remaining; > opus_fft(kfft, in, out, tonal->arch); > #ifndef FIXED_POINT >@@ -305,24 +440,31 @@ static void tonality_analysis(TonalityAnalysisState *tonal, const CELTMode *celt > d_angle2 = angle2 - angle; > d2_angle2 = d_angle2 - d_angle; > >- mod1 = d2_angle - (float)floor(.5+d2_angle); >+ mod1 = d2_angle - (float)float2int(d2_angle); > noisiness[i] = ABS16(mod1); > mod1 *= mod1; > mod1 *= mod1; > >- mod2 = d2_angle2 - (float)floor(.5+d2_angle2); >+ mod2 = d2_angle2 - (float)float2int(d2_angle2); > noisiness[i] += ABS16(mod2); > mod2 *= mod2; > mod2 *= mod2; > >- avg_mod = .25f*(d2A[i]+2.f*mod1+mod2); >+ avg_mod = .25f*(d2A[i]+mod1+2*mod2); >+ /* This introduces an extra delay of 2 frames in the detection. */ > tonality[i] = 1.f/(1.f+40.f*16.f*pi4*avg_mod)-.015f; >+ /* No delay on this detection, but it's less reliable. */ >+ tonality2[i] = 1.f/(1.f+40.f*16.f*pi4*mod2)-.015f; > > A[i] = angle2; > dA[i] = d_angle2; > d2A[i] = mod2; > } >- >+ for (i=2;i<N2-1;i++) >+ { >+ float tt = MIN32(tonality2[i], MAX32(tonality2[i-1], tonality2[i+1])); >+ tonality[i] = .9f*MAX32(tonality[i], tt-.1f); >+ } > frame_tonality = 0; > max_frame_tonality = 0; > /*tw_sum = 0;*/ >@@ -339,6 +481,22 @@ static void tonality_analysis(TonalityAnalysisState *tonal, const CELTMode *celt > } > relativeE = 0; > frame_loudness = 0; >+ /* The energy of the very first band is special because of DC. */ >+ { >+ float E = 0; >+ float X1r, X2r; >+ X1r = 2*(float)out[0].r; >+ X2r = 2*(float)out[0].i; >+ E = X1r*X1r + X2r*X2r; >+ for (i=1;i<4;i++) >+ { >+ float binE = out[i].r*(float)out[i].r + out[N-i].r*(float)out[N-i].r >+ + out[i].i*(float)out[i].i + out[N-i].i*(float)out[N-i].i; >+ E += binE; >+ } >+ E = SCALE_ENER(E); >+ band_log2[0] = .5f*1.442695f*(float)log(E+1e-10f); >+ } > for (b=0;b<NB_TBANDS;b++) > { > float E=0, tE=0, nE=0; >@@ -348,12 +506,9 @@ static void tonality_analysis(TonalityAnalysisState *tonal, const CELTMode *celt > { > float binE = out[i].r*(float)out[i].r + out[N-i].r*(float)out[N-i].r > + out[i].i*(float)out[i].i + out[N-i].i*(float)out[N-i].i; >-#ifdef FIXED_POINT >- /* FIXME: It's probably best to change the BFCC filter initial state instead */ >- binE *= 5.55e-17f; >-#endif >+ binE = SCALE_ENER(binE); > E += binE; >- tE += binE*tonality[i]; >+ tE += binE*MAX32(0, tonality[i]); > nE += binE*2.f*(.5f-noisiness[i]); > } > #ifndef FIXED_POINT >@@ -371,14 +526,27 @@ static void tonality_analysis(TonalityAnalysisState *tonal, const CELTMode *celt > > frame_loudness += (float)sqrt(E+1e-10f); > logE[b] = (float)log(E+1e-10f); >- tonal->lowE[b] = MIN32(logE[b], tonal->lowE[b]+.01f); >- tonal->highE[b] = MAX32(logE[b], tonal->highE[b]-.1f); >- if (tonal->highE[b] < tonal->lowE[b]+1.f) >+ band_log2[b+1] = .5f*1.442695f*(float)log(E+1e-10f); >+ tonal->logE[tonal->E_count][b] = logE[b]; >+ if (tonal->count==0) >+ tonal->highE[b] = tonal->lowE[b] = logE[b]; >+ if (tonal->highE[b] > tonal->lowE[b] + 7.5) >+ { >+ if (tonal->highE[b] - logE[b] > logE[b] - tonal->lowE[b]) >+ tonal->highE[b] -= .01f; >+ else >+ tonal->lowE[b] += .01f; >+ } >+ if (logE[b] > tonal->highE[b]) > { >- tonal->highE[b]+=.5f; >- tonal->lowE[b]-=.5f; >+ tonal->highE[b] = logE[b]; >+ tonal->lowE[b] = MAX32(tonal->highE[b]-15, tonal->lowE[b]); >+ } else if (logE[b] < tonal->lowE[b]) >+ { >+ tonal->lowE[b] = logE[b]; >+ tonal->highE[b] = MIN32(tonal->lowE[b]+15, tonal->highE[b]); > } >- relativeE += (logE[b]-tonal->lowE[b])/(1e-15f+tonal->highE[b]-tonal->lowE[b]); >+ relativeE += (logE[b]-tonal->lowE[b])/(1e-15f + (tonal->highE[b]-tonal->lowE[b])); > > L1=L2=0; > for (i=0;i<NB_FRAMES;i++) >@@ -410,27 +578,74 @@ static void tonality_analysis(TonalityAnalysisState *tonal, const CELTMode *celt > tonal->prev_band_tonality[b] = band_tonality[b]; > } > >+ leakage_from[0] = band_log2[0]; >+ leakage_to[0] = band_log2[0] - LEAKAGE_OFFSET; >+ for (b=1;b<NB_TBANDS+1;b++) >+ { >+ float leak_slope = LEAKAGE_SLOPE*(tbands[b]-tbands[b-1])/4; >+ leakage_from[b] = MIN16(leakage_from[b-1]+leak_slope, band_log2[b]); >+ leakage_to[b] = MAX16(leakage_to[b-1]-leak_slope, band_log2[b]-LEAKAGE_OFFSET); >+ } >+ for (b=NB_TBANDS-2;b>=0;b--) >+ { >+ float leak_slope = LEAKAGE_SLOPE*(tbands[b+1]-tbands[b])/4; >+ leakage_from[b] = MIN16(leakage_from[b+1]+leak_slope, leakage_from[b]); >+ leakage_to[b] = MAX16(leakage_to[b+1]-leak_slope, leakage_to[b]); >+ } >+ celt_assert(NB_TBANDS+1 <= LEAK_BANDS); >+ for (b=0;b<NB_TBANDS+1;b++) >+ { >+ /* leak_boost[] is made up of two terms. The first, based on leakage_to[], >+ represents the boost needed to overcome the amount of analysis leakage >+ cause in a weaker band b by louder neighbouring bands. >+ The second, based on leakage_from[], applies to a loud band b for >+ which the quantization noise causes synthesis leakage to the weaker >+ neighbouring bands. */ >+ float boost = MAX16(0, leakage_to[b] - band_log2[b]) + >+ MAX16(0, band_log2[b] - (leakage_from[b]+LEAKAGE_OFFSET)); >+ info->leak_boost[b] = IMIN(255, (int)floor(.5 + 64.f*boost)); >+ } >+ for (;b<LEAK_BANDS;b++) info->leak_boost[b] = 0; >+ >+ for (i=0;i<NB_FRAMES;i++) >+ { >+ int j; >+ float mindist = 1e15f; >+ for (j=0;j<NB_FRAMES;j++) >+ { >+ int k; >+ float dist=0; >+ for (k=0;k<NB_TBANDS;k++) >+ { >+ float tmp; >+ tmp = tonal->logE[i][k] - tonal->logE[j][k]; >+ dist += tmp*tmp; >+ } >+ if (j!=i) >+ mindist = MIN32(mindist, dist); >+ } >+ spec_variability += mindist; >+ } >+ spec_variability = (float)sqrt(spec_variability/NB_FRAMES/NB_TBANDS); > bandwidth_mask = 0; > bandwidth = 0; > maxE = 0; > noise_floor = 5.7e-4f/(1<<(IMAX(0,lsb_depth-8))); >-#ifdef FIXED_POINT >- noise_floor *= 1<<(15+SIG_SHIFT); >-#endif > noise_floor *= noise_floor; >- for (b=0;b<NB_TOT_BANDS;b++) >+ for (b=0;b<NB_TBANDS;b++) > { > float E=0; > int band_start, band_end; > /* Keep a margin of 300 Hz for aliasing */ >- band_start = extra_bands[b]; >- band_end = extra_bands[b+1]; >+ band_start = tbands[b]; >+ band_end = tbands[b+1]; > for (i=band_start;i<band_end;i++) > { > float binE = out[i].r*(float)out[i].r + out[N-i].r*(float)out[N-i].r > + out[i].i*(float)out[i].i + out[N-i].i*(float)out[N-i].i; > E += binE; > } >+ E = SCALE_ENER(E); > maxE = MAX32(maxE, E); > tonal->meanE[b] = MAX32((1-alphaE2)*tonal->meanE[b], E); > E = MAX32(E, tonal->meanE[b]); >@@ -441,14 +656,36 @@ static void tonality_analysis(TonalityAnalysisState *tonal, const CELTMode *celt > 2) less than 90 dB below the peak band (maximal masking possible considering > both the ATH and the loudness-dependent slope of the spreading function) > 3) above the PCM quantization noise floor >+ We use b+1 because the first CELT band isn't included in tbands[] > */ > if (E>.1*bandwidth_mask && E*1e9f > maxE && E > noise_floor*(band_end-band_start)) >- bandwidth = b; >+ bandwidth = b+1; >+ } >+ /* Special case for the last two bands, for which we don't have spectrum but only >+ the energy above 12 kHz. */ >+ if (tonal->Fs == 48000) { >+ float ratio; >+ float E = hp_ener*(1.f/(240*240)); >+ ratio = tonal->prev_bandwidth==20 ? 0.03f : 0.07f; >+#ifdef FIXED_POINT >+ /* silk_resampler_down2_hp() shifted right by an extra 8 bits. */ >+ E *= 256.f*(1.f/Q15ONE)*(1.f/Q15ONE); >+#endif >+ maxE = MAX32(maxE, E); >+ tonal->meanE[b] = MAX32((1-alphaE2)*tonal->meanE[b], E); >+ E = MAX32(E, tonal->meanE[b]); >+ /* Use a simple follower with 13 dB/Bark slope for spreading function */ >+ bandwidth_mask = MAX32(.05f*bandwidth_mask, E); >+ if (E>ratio*bandwidth_mask && E*1e9f > maxE && E > noise_floor*160) >+ bandwidth = 20; >+ /* This detector is unreliable, so if the bandwidth is close to SWB, assume it's FB. */ >+ if (bandwidth >= 17) >+ bandwidth = 20; > } > if (tonal->count<=2) > bandwidth = 20; > frame_loudness = 20*(float)log10(frame_loudness); >- tonal->Etracker = MAX32(tonal->Etracker-.03f, frame_loudness); >+ tonal->Etracker = MAX32(tonal->Etracker-.003f, frame_loudness); > tonal->lowECount *= (1-alphaE); > if (frame_loudness < tonal->Etracker-30) > tonal->lowECount += alphaE; >@@ -460,11 +697,18 @@ static void tonality_analysis(TonalityAnalysisState *tonal, const CELTMode *celt > sum += dct_table[i*16+b]*logE[b]; > BFCC[i] = sum; > } >+ for (i=0;i<8;i++) >+ { >+ float sum=0; >+ for (b=0;b<16;b++) >+ sum += dct_table[i*16+b]*.5f*(tonal->highE[b]+tonal->lowE[b]); >+ midE[i] = sum; >+ } > > frame_stationarity /= NB_TBANDS; > relativeE /= NB_TBANDS; > if (tonal->count<10) >- relativeE = .5; >+ relativeE = .5f; > frame_noisiness /= NB_TBANDS; > #if 1 > info->activity = frame_noisiness + (1-frame_noisiness)*relativeE; >@@ -479,7 +723,7 @@ static void tonality_analysis(TonalityAnalysisState *tonal, const CELTMode *celt > info->tonality_slope = slope; > > tonal->E_count = (tonal->E_count+1)%NB_FRAMES; >- tonal->count++; >+ tonal->count = IMIN(tonal->count+1, ANALYSIS_COUNT_MAX); > info->tonality = frame_tonality; > > for (i=0;i<4;i++) >@@ -498,6 +742,8 @@ static void tonality_analysis(TonalityAnalysisState *tonal, const CELTMode *celt > for (i=0;i<9;i++) > tonal->std[i] = (1-alpha)*tonal->std[i] + alpha*features[i]*features[i]; > } >+ for (i=0;i<4;i++) >+ features[i] = BFCC[i]-midE[i]; > > for (i=0;i<8;i++) > { >@@ -507,24 +753,26 @@ static void tonality_analysis(TonalityAnalysisState *tonal, const CELTMode *celt > tonal->mem[i] = BFCC[i]; > } > for (i=0;i<9;i++) >- features[11+i] = (float)sqrt(tonal->std[i]); >- features[20] = info->tonality; >- features[21] = info->activity; >- features[22] = frame_stationarity; >- features[23] = info->tonality_slope; >- features[24] = tonal->lowECount; >+ features[11+i] = (float)sqrt(tonal->std[i]) - std_feature_bias[i]; >+ features[18] = spec_variability - 0.78f; >+ features[20] = info->tonality - 0.154723f; >+ features[21] = info->activity - 0.724643f; >+ features[22] = frame_stationarity - 0.743717f; >+ features[23] = info->tonality_slope + 0.069216f; >+ features[24] = tonal->lowECount - 0.067930f; > >-#ifndef DISABLE_FLOAT_API > mlp_process(&net, features, frame_probs); > frame_probs[0] = .5f*(frame_probs[0]+1); > /* Curve fitting between the MLP probability and the actual probability */ >- frame_probs[0] = .01f + 1.21f*frame_probs[0]*frame_probs[0] - .23f*(float)pow(frame_probs[0], 10); >+ /*frame_probs[0] = .01f + 1.21f*frame_probs[0]*frame_probs[0] - .23f*(float)pow(frame_probs[0], 10);*/ > /* Probability of active audio (as opposed to silence) */ > frame_probs[1] = .5f*frame_probs[1]+.5f; >- /* Consider that silence has a 50-50 probability. */ >- frame_probs[0] = frame_probs[1]*frame_probs[0] + (1-frame_probs[1])*.5f; >+ frame_probs[1] *= frame_probs[1]; >+ >+ /* Probability of speech or music vs noise */ >+ info->activity_probability = frame_probs[1]; > >- /*printf("%f %f ", frame_probs[0], frame_probs[1]);*/ >+ /*printf("%f %f\n", frame_probs[0], frame_probs[1]);*/ > { > /* Probability of state transition */ > float tau; >@@ -542,12 +790,32 @@ static void tonality_analysis(TonalityAnalysisState *tonal, const CELTMode *celt > float music0; > float p, q; > >+ /* More silence transitions for speech than for music. */ >+ tau = .001f*tonal->music_prob + .01f*(1-tonal->music_prob); >+ p = MAX16(.05f,MIN16(.95f,frame_probs[1])); >+ q = MAX16(.05f,MIN16(.95f,tonal->vad_prob)); >+ beta = .02f+.05f*ABS16(p-q)/(p*(1-q)+q*(1-p)); >+ /* p0 and p1 are the probabilities of speech and music at this frame >+ using only information from previous frame and applying the >+ state transition model */ >+ p0 = (1-tonal->vad_prob)*(1-tau) + tonal->vad_prob *tau; >+ p1 = tonal->vad_prob *(1-tau) + (1-tonal->vad_prob)*tau; >+ /* We apply the current probability with exponent beta to work around >+ the fact that the probability estimates aren't independent. */ >+ p0 *= (float)pow(1-frame_probs[1], beta); >+ p1 *= (float)pow(frame_probs[1], beta); >+ /* Normalise the probabilities to get the Marokv probability of music. */ >+ tonal->vad_prob = p1/(p0+p1); >+ info->vad_prob = tonal->vad_prob; >+ /* Consider that silence has a 50-50 probability of being speech or music. */ >+ frame_probs[0] = tonal->vad_prob*frame_probs[0] + (1-tonal->vad_prob)*.5f; >+ > /* One transition every 3 minutes of active audio */ >- tau = .00005f*frame_probs[1]; >+ tau = .0001f; > /* Adapt beta based on how "unexpected" the new prob is */ > p = MAX16(.05f,MIN16(.95f,frame_probs[0])); > q = MAX16(.05f,MIN16(.95f,tonal->music_prob)); >- beta = .01f+.05f*ABS16(p-q)/(p*(1-q)+q*(1-p)); >+ beta = .02f+.05f*ABS16(p-q)/(p*(1-q)+q*(1-p)); > /* p0 and p1 are the probabilities of speech and music at this frame > using only information from previous frame and applying the > state transition model */ >@@ -561,6 +829,7 @@ static void tonality_analysis(TonalityAnalysisState *tonal, const CELTMode *celt > tonal->music_prob = p1/(p0+p1); > info->music_prob = tonal->music_prob; > >+ /*printf("%f %f %f %f\n", frame_probs[0], frame_probs[1], tonal->music_prob, tonal->vad_prob);*/ > /* This chunk of code deals with delayed decision. */ > psum=1e-20f; > /* Instantaneous probability of speech and music, with beta pre-applied. */ >@@ -568,8 +837,11 @@ static void tonality_analysis(TonalityAnalysisState *tonal, const CELTMode *celt > music0 = (float)pow(frame_probs[0], beta); > if (tonal->count==1) > { >- tonal->pspeech[0]=.5; >- tonal->pmusic [0]=.5; >+ if (tonal->application == OPUS_APPLICATION_VOIP) >+ tonal->pmusic[0] = .1f; >+ else >+ tonal->pmusic[0] = .625f; >+ tonal->pspeech[0] = 1-tonal->pmusic[0]; > } > /* Updated probability of having only speech (s0) or only music (m0), > before considering the new observation. */ >@@ -619,24 +891,17 @@ static void tonality_analysis(TonalityAnalysisState *tonal, const CELTMode *celt > tonal->speech_confidence_count = IMIN(tonal->speech_confidence_count, 500); > tonal->speech_confidence += adapt*MIN16(.2f,frame_probs[0]-tonal->speech_confidence); > } >- } else { >- if (tonal->music_confidence_count==0) >- tonal->music_confidence = .9f; >- if (tonal->speech_confidence_count==0) >- tonal->speech_confidence = .1f; > } > } >- if (tonal->last_music != (tonal->music_prob>.5f)) >- tonal->last_transition=0; > tonal->last_music = tonal->music_prob>.5f; >-#else >- info->music_prob = 0; >-#endif >- /*for (i=0;i<25;i++) >+#ifdef MLP_TRAINING >+ for (i=0;i<25;i++) > printf("%f ", features[i]); >- printf("\n");*/ >+ printf("\n"); >+#endif > > info->bandwidth = bandwidth; >+ tonal->prev_bandwidth = bandwidth; > /*printf("%d %d\n", info->bandwidth, info->opus_bandwidth);*/ > info->noisiness = frame_noisiness; > info->valid = 1; >@@ -650,18 +915,19 @@ void run_analysis(TonalityAnalysisState *analysis, const CELTMode *celt_mode, co > int offset; > int pcm_len; > >+ analysis_frame_size -= analysis_frame_size&1; > if (analysis_pcm != NULL) > { > /* Avoid overflow/wrap-around of the analysis buffer */ >- analysis_frame_size = IMIN((DETECT_SIZE-5)*Fs/100, analysis_frame_size); >+ analysis_frame_size = IMIN((DETECT_SIZE-5)*Fs/50, analysis_frame_size); > > pcm_len = analysis_frame_size - analysis->analysis_offset; > offset = analysis->analysis_offset; >- do { >- tonality_analysis(analysis, celt_mode, analysis_pcm, IMIN(480, pcm_len), offset, c1, c2, C, lsb_depth, downmix); >- offset += 480; >- pcm_len -= 480; >- } while (pcm_len>0); >+ while (pcm_len>0) { >+ tonality_analysis(analysis, celt_mode, analysis_pcm, IMIN(Fs/50, pcm_len), offset, c1, c2, C, lsb_depth, downmix); >+ offset += Fs/50; >+ pcm_len -= Fs/50; >+ } > analysis->analysis_offset = analysis_frame_size; > > analysis->analysis_offset -= frame_size; >@@ -670,3 +936,5 @@ void run_analysis(TonalityAnalysisState *analysis, const CELTMode *celt_mode, co > analysis_info->valid = 0; > tonality_get_info(analysis, analysis_info, frame_size); > } >+ >+#endif /* DISABLE_FLOAT_API */ >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/analysis.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/analysis.h >index 9eae56a525378a3602444ce960957d44bf91fa61..cac51dfa4eb55d8d1abbb0dee9f070463542df1d 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/analysis.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/analysis.h >@@ -33,13 +33,20 @@ > > #define NB_FRAMES 8 > #define NB_TBANDS 18 >-#define NB_TOT_BANDS 21 >-#define ANALYSIS_BUF_SIZE 720 /* 15 ms at 48 kHz */ >+#define ANALYSIS_BUF_SIZE 720 /* 30 ms at 24 kHz */ > >-#define DETECT_SIZE 200 >+/* At that point we can stop counting frames because it no longer matters. */ >+#define ANALYSIS_COUNT_MAX 10000 >+ >+#define DETECT_SIZE 100 >+ >+/* Uncomment this to print the MLP features on stdout. */ >+/*#define MLP_TRAINING*/ > > typedef struct { > int arch; >+ int application; >+ opus_int32 Fs; > #define TONALITY_ANALYSIS_RESET_START angle > float angle[240]; > float d_angle[240]; >@@ -48,21 +55,22 @@ typedef struct { > int mem_fill; /* number of usable samples in the buffer */ > float prev_band_tonality[NB_TBANDS]; > float prev_tonality; >+ int prev_bandwidth; > float E[NB_FRAMES][NB_TBANDS]; >+ float logE[NB_FRAMES][NB_TBANDS]; > float lowE[NB_TBANDS]; > float highE[NB_TBANDS]; >- float meanE[NB_TOT_BANDS]; >+ float meanE[NB_TBANDS+1]; > float mem[32]; > float cmean[8]; > float std[9]; > float music_prob; >+ float vad_prob; > float Etracker; > float lowECount; > int E_count; > int last_music; >- int last_transition; > int count; >- float subframe_mem[3]; > int analysis_offset; > /** Probability of having speech for time i to DETECT_SIZE-1 (and music before). > pspeech[0] is the probability that all frames in the window are speech. */ >@@ -77,6 +85,8 @@ typedef struct { > int write_pos; > int read_pos; > int read_subframe; >+ float hp_ener_accum; >+ opus_val32 downmix_state[3]; > AnalysisInfo info[DETECT_SIZE]; > } TonalityAnalysisState; > >@@ -86,7 +96,7 @@ typedef struct { > * not be repeated every analysis step. No allocated memory is retained > * by the state struct, so no cleanup call is required. > */ >-void tonality_analysis_init(TonalityAnalysisState *analysis); >+void tonality_analysis_init(TonalityAnalysisState *analysis, opus_int32 Fs); > > /** Reset a TonalityAnalysisState stuct. > * >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/mlp_data.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/mlp_data.c >index c2fda4e2e593fd372863d43375947862b277e488..a819880bff5a8995d211b7bb343a7033c9c71692 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/mlp_data.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/mlp_data.c >@@ -1,106 +1,109 @@ >-/* The contents of this file was automatically generated by mlp_train.c >- It contains multi-layer perceptron (MLP) weights. */ >- > #ifdef HAVE_CONFIG_H > #include "config.h" > #endif > > #include "mlp.h" > >-/* RMS error was 0.138320, seed was 1361535663 */ >+/* RMS error was 0.280492, seed was 1480478173 */ >+/* 0.005976 0.031821 (0.280494 0.280492) done */ > >-static const float weights[422] = { >+static const float weights[450] = { > > /* hidden layer */ >--0.0941125f, -0.302976f, -0.603555f, -0.19393f, -0.185983f, >--0.601617f, -0.0465317f, -0.114563f, -0.103599f, -0.618938f, >--0.317859f, -0.169949f, -0.0702885f, 0.148065f, 0.409524f, >-0.548432f, 0.367649f, -0.494393f, 0.764306f, -1.83957f, >-0.170849f, 12.786f, -1.08848f, -1.27284f, -16.2606f, >-24.1773f, -5.57454f, -0.17276f, -0.163388f, -0.224421f, >--0.0948944f, -0.0728695f, -0.26557f, -0.100283f, -0.0515459f, >--0.146142f, -0.120674f, -0.180655f, 0.12857f, 0.442138f, >--0.493735f, 0.167767f, 0.206699f, -0.197567f, 0.417999f, >-1.50364f, -0.773341f, -10.0401f, 0.401872f, 2.97966f, >-15.2165f, -1.88905f, -1.19254f, 0.0285397f, -0.00405139f, >-0.0707565f, 0.00825699f, -0.0927269f, -0.010393f, -0.00428882f, >--0.00489743f, -0.0709731f, -0.00255992f, 0.0395619f, 0.226424f, >-0.0325231f, 0.162175f, -0.100118f, 0.485789f, 0.12697f, >-0.285937f, 0.0155637f, 0.10546f, 3.05558f, 1.15059f, >--1.00904f, -1.83088f, 3.31766f, -3.42516f, -0.119135f, >--0.0405654f, 0.00690068f, 0.0179877f, -0.0382487f, 0.00597941f, >--0.0183611f, 0.00190395f, -0.144322f, -0.0435671f, 0.000990594f, >-0.221087f, 0.142405f, 0.484066f, 0.404395f, 0.511955f, >--0.237255f, 0.241742f, 0.35045f, -0.699428f, 10.3993f, >-2.6507f, -2.43459f, -4.18838f, 1.05928f, 1.71067f, >-0.00667811f, -0.0721335f, -0.0397346f, 0.0362704f, -0.11496f, >--0.0235776f, 0.0082161f, -0.0141741f, -0.0329699f, -0.0354253f, >-0.00277404f, -0.290654f, -1.14767f, -0.319157f, -0.686544f, >-0.36897f, 0.478899f, 0.182579f, -0.411069f, 0.881104f, >--4.60683f, 1.4697f, 0.335845f, -1.81905f, -30.1699f, >-5.55225f, 0.0019508f, -0.123576f, -0.0727332f, -0.0641597f, >--0.0534458f, -0.108166f, -0.0937368f, -0.0697883f, -0.0275475f, >--0.192309f, -0.110074f, 0.285375f, -0.405597f, 0.0926724f, >--0.287881f, -0.851193f, -0.099493f, -0.233764f, -1.2852f, >-1.13611f, 3.12168f, -0.0699f, -1.86216f, 2.65292f, >--7.31036f, 2.44776f, -0.00111802f, -0.0632786f, -0.0376296f, >--0.149851f, 0.142963f, 0.184368f, 0.123433f, 0.0756158f, >-0.117312f, 0.0933395f, 0.0692163f, 0.0842592f, 0.0704683f, >-0.0589963f, 0.0942205f, -0.448862f, 0.0262677f, 0.270352f, >--0.262317f, 0.172586f, 2.00227f, -0.159216f, 0.038422f, >-10.2073f, 4.15536f, -2.3407f, -0.0550265f, 0.00964792f, >--0.141336f, 0.0274501f, 0.0343921f, -0.0487428f, 0.0950172f, >--0.00775017f, -0.0372492f, -0.00548121f, -0.0663695f, 0.0960506f, >--0.200008f, -0.0412827f, 0.58728f, 0.0515787f, 0.337254f, >-0.855024f, 0.668371f, -0.114904f, -3.62962f, -0.467477f, >--0.215472f, 2.61537f, 0.406117f, -1.36373f, 0.0425394f, >-0.12208f, 0.0934502f, 0.123055f, 0.0340935f, -0.142466f, >-0.035037f, -0.0490666f, 0.0733208f, 0.0576672f, 0.123984f, >--0.0517194f, -0.253018f, 0.590565f, 0.145849f, 0.315185f, >-0.221534f, -0.149081f, 0.216161f, -0.349575f, 24.5664f, >--0.994196f, 0.614289f, -18.7905f, -2.83277f, -0.716801f, >--0.347201f, 0.479515f, -0.246027f, 0.0758683f, 0.137293f, >--0.17781f, 0.118751f, -0.00108329f, -0.237334f, 0.355732f, >--0.12991f, -0.0547627f, -0.318576f, -0.325524f, 0.180494f, >--0.0625604f, 0.141219f, 0.344064f, 0.37658f, -0.591772f, >-5.8427f, -0.38075f, 0.221894f, -1.41934f, -1.87943e+06f, >-1.34114f, 0.0283355f, -0.0447856f, -0.0211466f, -0.0256927f, >-0.0139618f, 0.0207934f, -0.0107666f, 0.0110969f, 0.0586069f, >--0.0253545f, -0.0328433f, 0.11872f, -0.216943f, 0.145748f, >-0.119808f, -0.0915211f, -0.120647f, -0.0787719f, -0.143644f, >--0.595116f, -1.152f, -1.25335f, -1.17092f, 4.34023f, >--975268.f, -1.37033f, -0.0401123f, 0.210602f, -0.136656f, >-0.135962f, -0.0523293f, 0.0444604f, 0.0143928f, 0.00412666f, >--0.0193003f, 0.218452f, -0.110204f, -2.02563f, 0.918238f, >--2.45362f, 1.19542f, -0.061362f, -1.92243f, 0.308111f, >-0.49764f, 0.912356f, 0.209272f, -2.34525f, 2.19326f, >--6.47121f, 1.69771f, -0.725123f, 0.0118929f, 0.0377944f, >-0.0554003f, 0.0226452f, -0.0704421f, -0.0300309f, 0.0122978f, >--0.0041782f, -0.0686612f, 0.0313115f, 0.039111f, 0.364111f, >--0.0945548f, 0.0229876f, -0.17414f, 0.329795f, 0.114714f, >-0.30022f, 0.106997f, 0.132355f, 5.79932f, 0.908058f, >--0.905324f, -3.3561f, 0.190647f, 0.184211f, -0.673648f, >-0.231807f, -0.0586222f, 0.230752f, -0.438277f, 0.245857f, >--0.17215f, 0.0876383f, -0.720512f, 0.162515f, 0.0170571f, >-0.101781f, 0.388477f, 1.32931f, 1.08548f, -0.936301f, >--2.36958f, -6.71988f, -3.44376f, 2.13818f, 14.2318f, >-4.91459f, -3.09052f, -9.69191f, -0.768234f, 1.79604f, >-0.0549653f, 0.163399f, 0.0797025f, 0.0343933f, -0.0555876f, >--0.00505673f, 0.0187258f, 0.0326628f, 0.0231486f, 0.15573f, >-0.0476223f, -0.254824f, 1.60155f, -0.801221f, 2.55496f, >-0.737629f, -1.36249f, -0.695463f, -2.44301f, -1.73188f, >-3.95279f, 1.89068f, 0.486087f, -11.3343f, 3.9416e+06f, >- >+-0.514624f, 0.0234227f, -0.14329f, -0.0878216f, -0.00187827f, >+-0.0257443f, 0.108524f, 0.00333881f, 0.00585017f, -0.0246132f, >+0.142723f, -0.00436494f, 0.0101354f, -0.11124f, -0.0809367f, >+-0.0750772f, 0.0295524f, 0.00823944f, 0.150392f, 0.0320876f, >+-0.0710564f, -1.43818f, 0.652076f, 0.0650744f, -1.54821f, >+0.168949f, -1.92724f, 0.0517976f, -0.0670737f, -0.0690121f, >+0.00247528f, -0.0522024f, 0.0631368f, 0.0532776f, 0.047751f, >+-0.011715f, 0.142374f, -0.0290885f, -0.279263f, -0.433499f, >+-0.0795174f, -0.380458f, -0.051263f, 0.218537f, -0.322478f, >+1.06667f, -0.104607f, -4.70108f, 0.312037f, 0.277397f, >+-2.71859f, 1.70037f, -0.141845f, 0.0115618f, 0.0629883f, >+0.0403871f, 0.0139428f, -0.00430733f, -0.0429038f, -0.0590318f, >+-0.0501526f, -0.0284802f, -0.0415686f, -0.0438999f, 0.0822666f, >+0.197194f, 0.0363275f, -0.0584307f, 0.0752364f, -0.0799796f, >+-0.146275f, 0.161661f, -0.184585f, 0.145568f, 0.442823f, >+1.61221f, 1.11162f, 2.62177f, -2.482f, -0.112599f, >+-0.110366f, -0.140794f, -0.181694f, 0.0648674f, 0.0842248f, >+0.0933993f, 0.150122f, 0.129171f, 0.176848f, 0.141758f, >+-0.271822f, 0.235113f, 0.0668579f, -0.433957f, 0.113633f, >+-0.169348f, -1.40091f, 0.62861f, -0.134236f, 0.402173f, >+1.86373f, 1.53998f, -4.32084f, 0.735343f, 0.800214f, >+-0.00968415f, 0.0425904f, 0.0196811f, -0.018426f, -0.000343953f, >+-0.00416389f, 0.00111558f, 0.0173069f, -0.00998596f, -0.025898f, >+0.00123764f, -0.00520373f, -0.0565033f, 0.0637394f, 0.0051213f, >+0.0221361f, 0.00819962f, -0.0467061f, -0.0548258f, -0.00314063f, >+-1.18332f, 1.88091f, -0.41148f, -2.95727f, -0.521449f, >+-0.271641f, 0.124946f, -0.0532936f, 0.101515f, 0.000208564f, >+-0.0488748f, 0.0642388f, -0.0383848f, 0.0135046f, -0.0413592f, >+-0.0326402f, -0.0137421f, -0.0225219f, -0.0917294f, -0.277759f, >+-0.185418f, 0.0471128f, -0.125879f, 0.262467f, -0.212794f, >+-0.112931f, -1.99885f, -0.404787f, 0.224402f, 0.637962f, >+-0.27808f, -0.0723953f, -0.0537655f, -0.0336359f, -0.0906601f, >+-0.0641309f, -0.0713542f, 0.0524317f, 0.00608819f, 0.0754101f, >+-0.0488401f, -0.00671865f, 0.0418239f, 0.0536284f, -0.132639f, >+0.0267648f, -0.248432f, -0.0104153f, 0.035544f, -0.212753f, >+-0.302895f, -0.0357854f, 0.376838f, 0.597025f, -0.664647f, >+0.268422f, -0.376772f, -1.05472f, 0.0144178f, 0.179122f, >+0.0360155f, 0.220262f, -0.0056381f, 0.0317197f, 0.0621066f, >+-0.00779298f, 0.00789378f, 0.00350605f, 0.0104809f, 0.0362871f, >+-0.157708f, -0.0659779f, -0.0926278f, 0.00770791f, 0.0631621f, >+0.0817343f, -0.424295f, -0.0437727f, -0.24251f, 0.711217f, >+-0.736455f, -2.194f, -0.107612f, -0.175156f, -0.0366573f, >+-0.0123156f, -0.0628516f, -0.0218977f, -0.00693699f, 0.00695185f, >+0.00507362f, 0.00359334f, 0.0052661f, 0.035561f, 0.0382701f, >+0.0342179f, -0.00790271f, -0.0170925f, 0.047029f, 0.0197362f, >+-0.0153435f, 0.0644152f, -0.36862f, -0.0674876f, -2.82672f, >+1.34122f, -0.0788029f, -3.47792f, 0.507246f, -0.816378f, >+-0.0142383f, -0.127349f, -0.106926f, -0.0359524f, 0.105045f, >+0.291554f, 0.195413f, 0.0866214f, -0.066577f, -0.102188f, >+0.0979466f, -0.12982f, 0.400181f, -0.409336f, -0.0593326f, >+-0.0656203f, -0.204474f, 0.179802f, 0.000509084f, 0.0995954f, >+-2.377f, -0.686359f, 0.934861f, 1.10261f, 1.3901f, >+-4.33616f, -0.00264017f, 0.00713045f, 0.106264f, 0.143726f, >+-0.0685305f, -0.054656f, -0.0176725f, -0.0772669f, -0.0264526f, >+-0.0103824f, -0.0269872f, -0.00687f, 0.225804f, 0.407751f, >+-0.0612611f, -0.0576863f, -0.180131f, -0.222772f, -0.461742f, >+0.335236f, 1.03399f, 4.24112f, -0.345796f, -0.594549f, >+-76.1407f, -0.265276f, 0.0507719f, 0.0643044f, 0.0384832f, >+0.0424459f, -0.0387817f, -0.0235996f, -0.0740556f, -0.0270029f, >+0.00882177f, -0.0552371f, -0.00485851f, 0.314295f, 0.360431f, >+-0.0787085f, 0.110355f, -0.415958f, -0.385088f, -0.272224f, >+-1.55108f, -0.141848f, 0.448877f, -0.563447f, -2.31403f, >+-0.120077f, -1.49918f, -0.817726f, -0.0495854f, -0.0230782f, >+-0.0224014f, 0.117076f, 0.0393216f, 0.051997f, 0.0330763f, >+-0.110796f, 0.0211117f, -0.0197258f, 0.0187461f, 0.0125183f, >+0.14876f, 0.0920565f, -0.342475f, 0.135272f, -0.168155f, >+-0.033423f, -0.0604611f, -0.128835f, 0.664947f, -0.144997f, >+2.27649f, 1.28663f, 0.841217f, -2.42807f, 0.0230471f, >+0.226709f, -0.0374803f, 0.155436f, 0.0400342f, -0.184686f, >+0.128488f, -0.0939518f, -0.0578559f, 0.0265967f, -0.0999322f, >+-0.0322768f, -0.322994f, -0.189371f, -0.738069f, -0.0754914f, >+0.214717f, -0.093728f, -0.695741f, 0.0899298f, -2.06188f, >+-0.273719f, -0.896977f, 0.130553f, 0.134638f, 1.29355f, >+0.00520749f, -0.0324224f, 0.00530451f, 0.0192385f, 0.00328708f, >+0.0250838f, 0.0053365f, -0.0177321f, 0.00618789f, 0.00525364f, >+0.00104596f, -0.0360459f, 0.0402403f, -0.0406351f, 0.0136883f, >+0.0880722f, -0.0197449f, 0.089938f, 0.0100456f, -0.0475638f, >+-0.73267f, 0.037433f, -0.146551f, -0.230221f, -3.06489f, >+-1.40194f, 0.0198483f, 0.0397953f, -0.0190239f, 0.0470715f, >+-0.131363f, -0.191721f, -0.0176224f, -0.0480352f, -0.221799f, >+-0.26794f, -0.0292615f, 0.0612127f, -0.129877f, 0.00628332f, >+-0.085918f, 0.0175379f, 0.0541011f, -0.0810874f, -0.380809f, >+-0.222056f, -0.508859f, -0.473369f, 0.484958f, -2.28411f, >+0.0139516f, > /* output layer */ >--0.381439f, 0.12115f, -0.906927f, 2.93878f, 1.6388f, >-0.882811f, 0.874344f, 1.21726f, -0.874545f, 0.321706f, >-0.785055f, 0.946558f, -0.575066f, -3.46553f, 0.884905f, >-0.0924047f, -9.90712f, 0.391338f, 0.160103f, -2.04954f, >-4.1455f, 0.0684029f, -0.144761f, -0.285282f, 0.379244f, >--1.1584f, -0.0277241f, -9.85f, -4.82386f, 3.71333f, >-3.87308f, 3.52558f}; >+3.90017f, 1.71789f, -1.43372f, -2.70839f, 1.77107f, >+5.48006f, 1.44661f, 2.01134f, -1.88383f, -3.64958f, >+-1.26351f, 0.779421f, 2.11357f, 3.10409f, 1.68846f, >+-4.46197f, -1.61455f, 3.59832f, 2.43531f, -1.26458f, >+0.417941f, 1.47437f, 2.16635f, -1.909f, -0.828869f, >+1.38805f, -2.67975f, -0.110044f, 1.95596f, 0.697931f, >+-0.313226f, -0.889315f, 0.283236f, 0.946102f, }; > >-static const int topo[3] = {25, 15, 2}; >+static const int topo[3] = {25, 16, 2}; > > const MLP net = { > 3, >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/mlp_train.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/mlp_train.c >new file mode 100644 >index 0000000000000000000000000000000000000000..8d9d127a6dbbb4e596e9fd28b5c1ab1ac5307f19 >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/mlp_train.c >@@ -0,0 +1,501 @@ >+/* Copyright (c) 2008-2011 Octasic Inc. >+ Written by Jean-Marc Valin */ >+/* >+ Redistribution and use in source and binary forms, with or without >+ modification, are permitted provided that the following conditions >+ are met: >+ >+ - Redistributions of source code must retain the above copyright >+ notice, this list of conditions and the following disclaimer. >+ >+ - Redistributions in binary form must reproduce the above copyright >+ notice, this list of conditions and the following disclaimer in the >+ documentation and/or other materials provided with the distribution. >+ >+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS >+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT >+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR >+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR >+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, >+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, >+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR >+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF >+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING >+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS >+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+*/ >+ >+ >+#include "mlp_train.h" >+#include <stdlib.h> >+#include <stdio.h> >+#include <string.h> >+#include <semaphore.h> >+#include <pthread.h> >+#include <time.h> >+#include <signal.h> >+ >+int stopped = 0; >+ >+void handler(int sig) >+{ >+ stopped = 1; >+ signal(sig, handler); >+} >+ >+MLPTrain * mlp_init(int *topo, int nbLayers, float *inputs, float *outputs, int nbSamples) >+{ >+ int i, j, k; >+ MLPTrain *net; >+ int inDim, outDim; >+ net = malloc(sizeof(*net)); >+ net->topo = malloc(nbLayers*sizeof(net->topo[0])); >+ for (i=0;i<nbLayers;i++) >+ net->topo[i] = topo[i]; >+ inDim = topo[0]; >+ outDim = topo[nbLayers-1]; >+ net->in_rate = malloc((inDim+1)*sizeof(net->in_rate[0])); >+ net->weights = malloc((nbLayers-1)*sizeof(net->weights)); >+ net->best_weights = malloc((nbLayers-1)*sizeof(net->weights)); >+ for (i=0;i<nbLayers-1;i++) >+ { >+ net->weights[i] = malloc((topo[i]+1)*topo[i+1]*sizeof(net->weights[0][0])); >+ net->best_weights[i] = malloc((topo[i]+1)*topo[i+1]*sizeof(net->weights[0][0])); >+ } >+ double inMean[inDim]; >+ for (j=0;j<inDim;j++) >+ { >+ double std=0; >+ inMean[j] = 0; >+ for (i=0;i<nbSamples;i++) >+ { >+ inMean[j] += inputs[i*inDim+j]; >+ std += inputs[i*inDim+j]*inputs[i*inDim+j]; >+ } >+ inMean[j] /= nbSamples; >+ std /= nbSamples; >+ net->in_rate[1+j] = .5/(.0001+std); >+ std = std-inMean[j]*inMean[j]; >+ if (std<.001) >+ std = .001; >+ std = 1/sqrt(inDim*std); >+ for (k=0;k<topo[1];k++) >+ net->weights[0][k*(topo[0]+1)+j+1] = randn(std); >+ } >+ net->in_rate[0] = 1; >+ for (j=0;j<topo[1];j++) >+ { >+ double sum = 0; >+ for (k=0;k<inDim;k++) >+ sum += inMean[k]*net->weights[0][j*(topo[0]+1)+k+1]; >+ net->weights[0][j*(topo[0]+1)] = -sum; >+ } >+ for (j=0;j<outDim;j++) >+ { >+ double mean = 0; >+ double std; >+ for (i=0;i<nbSamples;i++) >+ mean += outputs[i*outDim+j]; >+ mean /= nbSamples; >+ std = 1/sqrt(topo[nbLayers-2]); >+ net->weights[nbLayers-2][j*(topo[nbLayers-2]+1)] = mean; >+ for (k=0;k<topo[nbLayers-2];k++) >+ net->weights[nbLayers-2][j*(topo[nbLayers-2]+1)+k+1] = randn(std); >+ } >+ return net; >+} >+ >+#define MAX_NEURONS 100 >+#define MAX_OUT 10 >+ >+double compute_gradient(MLPTrain *net, float *inputs, float *outputs, int nbSamples, double *W0_grad, double *W1_grad, double *error_rate) >+{ >+ int i,j; >+ int s; >+ int inDim, outDim, hiddenDim; >+ int *topo; >+ double *W0, *W1; >+ double rms=0; >+ int W0_size, W1_size; >+ double hidden[MAX_NEURONS]; >+ double netOut[MAX_NEURONS]; >+ double error[MAX_NEURONS]; >+ >+ topo = net->topo; >+ inDim = net->topo[0]; >+ hiddenDim = net->topo[1]; >+ outDim = net->topo[2]; >+ W0_size = (topo[0]+1)*topo[1]; >+ W1_size = (topo[1]+1)*topo[2]; >+ W0 = net->weights[0]; >+ W1 = net->weights[1]; >+ memset(W0_grad, 0, W0_size*sizeof(double)); >+ memset(W1_grad, 0, W1_size*sizeof(double)); >+ for (i=0;i<outDim;i++) >+ netOut[i] = outputs[i]; >+ for (i=0;i<outDim;i++) >+ error_rate[i] = 0; >+ for (s=0;s<nbSamples;s++) >+ { >+ float *in, *out; >+ float inp[inDim]; >+ in = inputs+s*inDim; >+ out = outputs + s*outDim; >+ for (j=0;j<inDim;j++) >+ inp[j] = in[j]; >+ for (i=0;i<hiddenDim;i++) >+ { >+ double sum = W0[i*(inDim+1)]; >+ for (j=0;j<inDim;j++) >+ sum += W0[i*(inDim+1)+j+1]*inp[j]; >+ hidden[i] = tansig_approx(sum); >+ } >+ for (i=0;i<outDim;i++) >+ { >+ double sum = W1[i*(hiddenDim+1)]; >+ for (j=0;j<hiddenDim;j++) >+ sum += W1[i*(hiddenDim+1)+j+1]*hidden[j]; >+ netOut[i] = tansig_approx(sum); >+ error[i] = out[i] - netOut[i]; >+ if (out[i] == 0) error[i] *= .0; >+ error_rate[i] += fabs(error[i])>1; >+ if (i==0) error[i] *= 5; >+ rms += error[i]*error[i]; >+ /*error[i] = error[i]/(1+fabs(error[i]));*/ >+ } >+ /* Back-propagate error */ >+ for (i=0;i<outDim;i++) >+ { >+ double grad = 1-netOut[i]*netOut[i]; >+ W1_grad[i*(hiddenDim+1)] += error[i]*grad; >+ for (j=0;j<hiddenDim;j++) >+ W1_grad[i*(hiddenDim+1)+j+1] += grad*error[i]*hidden[j]; >+ } >+ for (i=0;i<hiddenDim;i++) >+ { >+ double grad; >+ grad = 0; >+ for (j=0;j<outDim;j++) >+ grad += error[j]*W1[j*(hiddenDim+1)+i+1]; >+ grad *= 1-hidden[i]*hidden[i]; >+ W0_grad[i*(inDim+1)] += grad; >+ for (j=0;j<inDim;j++) >+ W0_grad[i*(inDim+1)+j+1] += grad*inp[j]; >+ } >+ } >+ return rms; >+} >+ >+#define NB_THREADS 8 >+ >+sem_t sem_begin[NB_THREADS]; >+sem_t sem_end[NB_THREADS]; >+ >+struct GradientArg { >+ int id; >+ int done; >+ MLPTrain *net; >+ float *inputs; >+ float *outputs; >+ int nbSamples; >+ double *W0_grad; >+ double *W1_grad; >+ double rms; >+ double error_rate[MAX_OUT]; >+}; >+ >+void *gradient_thread_process(void *_arg) >+{ >+ int W0_size, W1_size; >+ struct GradientArg *arg = _arg; >+ int *topo = arg->net->topo; >+ W0_size = (topo[0]+1)*topo[1]; >+ W1_size = (topo[1]+1)*topo[2]; >+ double W0_grad[W0_size]; >+ double W1_grad[W1_size]; >+ arg->W0_grad = W0_grad; >+ arg->W1_grad = W1_grad; >+ while (1) >+ { >+ sem_wait(&sem_begin[arg->id]); >+ if (arg->done) >+ break; >+ arg->rms = compute_gradient(arg->net, arg->inputs, arg->outputs, arg->nbSamples, arg->W0_grad, arg->W1_grad, arg->error_rate); >+ sem_post(&sem_end[arg->id]); >+ } >+ fprintf(stderr, "done\n"); >+ return NULL; >+} >+ >+float mlp_train_backprop(MLPTrain *net, float *inputs, float *outputs, int nbSamples, int nbEpoch, float rate) >+{ >+ int i, j; >+ int e; >+ float best_rms = 1e10; >+ int inDim, outDim, hiddenDim; >+ int *topo; >+ double *W0, *W1, *best_W0, *best_W1; >+ double *W0_grad, *W1_grad; >+ double *W0_oldgrad, *W1_oldgrad; >+ double *W0_rate, *W1_rate; >+ double *best_W0_rate, *best_W1_rate; >+ int W0_size, W1_size; >+ topo = net->topo; >+ W0_size = (topo[0]+1)*topo[1]; >+ W1_size = (topo[1]+1)*topo[2]; >+ struct GradientArg args[NB_THREADS]; >+ pthread_t thread[NB_THREADS]; >+ int samplePerPart = nbSamples/NB_THREADS; >+ int count_worse=0; >+ int count_retries=0; >+ >+ topo = net->topo; >+ inDim = net->topo[0]; >+ hiddenDim = net->topo[1]; >+ outDim = net->topo[2]; >+ W0 = net->weights[0]; >+ W1 = net->weights[1]; >+ best_W0 = net->best_weights[0]; >+ best_W1 = net->best_weights[1]; >+ W0_grad = malloc(W0_size*sizeof(double)); >+ W1_grad = malloc(W1_size*sizeof(double)); >+ W0_oldgrad = malloc(W0_size*sizeof(double)); >+ W1_oldgrad = malloc(W1_size*sizeof(double)); >+ W0_rate = malloc(W0_size*sizeof(double)); >+ W1_rate = malloc(W1_size*sizeof(double)); >+ best_W0_rate = malloc(W0_size*sizeof(double)); >+ best_W1_rate = malloc(W1_size*sizeof(double)); >+ memset(W0_grad, 0, W0_size*sizeof(double)); >+ memset(W0_oldgrad, 0, W0_size*sizeof(double)); >+ memset(W1_grad, 0, W1_size*sizeof(double)); >+ memset(W1_oldgrad, 0, W1_size*sizeof(double)); >+ >+ rate /= nbSamples; >+ for (i=0;i<hiddenDim;i++) >+ for (j=0;j<inDim+1;j++) >+ W0_rate[i*(inDim+1)+j] = rate*net->in_rate[j]; >+ for (i=0;i<W1_size;i++) >+ W1_rate[i] = rate; >+ >+ for (i=0;i<NB_THREADS;i++) >+ { >+ args[i].net = net; >+ args[i].inputs = inputs+i*samplePerPart*inDim; >+ args[i].outputs = outputs+i*samplePerPart*outDim; >+ args[i].nbSamples = samplePerPart; >+ args[i].id = i; >+ args[i].done = 0; >+ sem_init(&sem_begin[i], 0, 0); >+ sem_init(&sem_end[i], 0, 0); >+ pthread_create(&thread[i], NULL, gradient_thread_process, &args[i]); >+ } >+ for (e=0;e<nbEpoch;e++) >+ { >+ double rms=0; >+ double error_rate[2] = {0,0}; >+ for (i=0;i<NB_THREADS;i++) >+ { >+ sem_post(&sem_begin[i]); >+ } >+ memset(W0_grad, 0, W0_size*sizeof(double)); >+ memset(W1_grad, 0, W1_size*sizeof(double)); >+ for (i=0;i<NB_THREADS;i++) >+ { >+ sem_wait(&sem_end[i]); >+ rms += args[i].rms; >+ error_rate[0] += args[i].error_rate[0]; >+ error_rate[1] += args[i].error_rate[1]; >+ for (j=0;j<W0_size;j++) >+ W0_grad[j] += args[i].W0_grad[j]; >+ for (j=0;j<W1_size;j++) >+ W1_grad[j] += args[i].W1_grad[j]; >+ } >+ >+ float mean_rate = 0, min_rate = 1e10; >+ rms = (rms/(outDim*nbSamples)); >+ error_rate[0] = (error_rate[0]/(nbSamples)); >+ error_rate[1] = (error_rate[1]/(nbSamples)); >+ fprintf (stderr, "%f %f (%f %f) ", error_rate[0], error_rate[1], rms, best_rms); >+ if (rms < best_rms) >+ { >+ best_rms = rms; >+ for (i=0;i<W0_size;i++) >+ { >+ best_W0[i] = W0[i]; >+ best_W0_rate[i] = W0_rate[i]; >+ } >+ for (i=0;i<W1_size;i++) >+ { >+ best_W1[i] = W1[i]; >+ best_W1_rate[i] = W1_rate[i]; >+ } >+ count_worse=0; >+ count_retries=0; >+ } else { >+ count_worse++; >+ if (count_worse>30) >+ { >+ count_retries++; >+ count_worse=0; >+ for (i=0;i<W0_size;i++) >+ { >+ W0[i] = best_W0[i]; >+ best_W0_rate[i] *= .7; >+ if (best_W0_rate[i]<1e-15) best_W0_rate[i]=1e-15; >+ W0_rate[i] = best_W0_rate[i]; >+ W0_grad[i] = 0; >+ } >+ for (i=0;i<W1_size;i++) >+ { >+ W1[i] = best_W1[i]; >+ best_W1_rate[i] *= .8; >+ if (best_W1_rate[i]<1e-15) best_W1_rate[i]=1e-15; >+ W1_rate[i] = best_W1_rate[i]; >+ W1_grad[i] = 0; >+ } >+ } >+ } >+ if (count_retries>10) >+ break; >+ for (i=0;i<W0_size;i++) >+ { >+ if (W0_oldgrad[i]*W0_grad[i] > 0) >+ W0_rate[i] *= 1.01; >+ else if (W0_oldgrad[i]*W0_grad[i] < 0) >+ W0_rate[i] *= .9; >+ mean_rate += W0_rate[i]; >+ if (W0_rate[i] < min_rate) >+ min_rate = W0_rate[i]; >+ if (W0_rate[i] < 1e-15) >+ W0_rate[i] = 1e-15; >+ /*if (W0_rate[i] > .01) >+ W0_rate[i] = .01;*/ >+ W0_oldgrad[i] = W0_grad[i]; >+ W0[i] += W0_grad[i]*W0_rate[i]; >+ } >+ for (i=0;i<W1_size;i++) >+ { >+ if (W1_oldgrad[i]*W1_grad[i] > 0) >+ W1_rate[i] *= 1.01; >+ else if (W1_oldgrad[i]*W1_grad[i] < 0) >+ W1_rate[i] *= .9; >+ mean_rate += W1_rate[i]; >+ if (W1_rate[i] < min_rate) >+ min_rate = W1_rate[i]; >+ if (W1_rate[i] < 1e-15) >+ W1_rate[i] = 1e-15; >+ W1_oldgrad[i] = W1_grad[i]; >+ W1[i] += W1_grad[i]*W1_rate[i]; >+ } >+ mean_rate /= (topo[0]+1)*topo[1] + (topo[1]+1)*topo[2]; >+ fprintf (stderr, "%g %d", mean_rate, e); >+ if (count_retries) >+ fprintf(stderr, " %d", count_retries); >+ fprintf(stderr, "\n"); >+ if (stopped) >+ break; >+ } >+ for (i=0;i<NB_THREADS;i++) >+ { >+ args[i].done = 1; >+ sem_post(&sem_begin[i]); >+ pthread_join(thread[i], NULL); >+ fprintf (stderr, "joined %d\n", i); >+ } >+ free(W0_grad); >+ free(W0_oldgrad); >+ free(W1_grad); >+ free(W1_oldgrad); >+ free(W0_rate); >+ free(best_W0_rate); >+ free(W1_rate); >+ free(best_W1_rate); >+ return best_rms; >+} >+ >+int main(int argc, char **argv) >+{ >+ int i, j; >+ int nbInputs; >+ int nbOutputs; >+ int nbHidden; >+ int nbSamples; >+ int nbEpoch; >+ int nbRealInputs; >+ unsigned int seed; >+ int ret; >+ float rms; >+ float *inputs; >+ float *outputs; >+ if (argc!=6) >+ { >+ fprintf (stderr, "usage: mlp_train <inputs> <hidden> <outputs> <nb samples> <nb epoch>\n"); >+ return 1; >+ } >+ nbInputs = atoi(argv[1]); >+ nbHidden = atoi(argv[2]); >+ nbOutputs = atoi(argv[3]); >+ nbSamples = atoi(argv[4]); >+ nbEpoch = atoi(argv[5]); >+ nbRealInputs = nbInputs; >+ inputs = malloc(nbInputs*nbSamples*sizeof(*inputs)); >+ outputs = malloc(nbOutputs*nbSamples*sizeof(*outputs)); >+ >+ seed = time(NULL); >+ /*seed = 1452209040;*/ >+ fprintf (stderr, "Seed is %u\n", seed); >+ srand(seed); >+ build_tansig_table(); >+ signal(SIGTERM, handler); >+ signal(SIGINT, handler); >+ signal(SIGHUP, handler); >+ for (i=0;i<nbSamples;i++) >+ { >+ for (j=0;j<nbRealInputs;j++) >+ ret = scanf(" %f", &inputs[i*nbInputs+j]); >+ for (j=0;j<nbOutputs;j++) >+ ret = scanf(" %f", &outputs[i*nbOutputs+j]); >+ if (feof(stdin)) >+ { >+ nbSamples = i; >+ break; >+ } >+ } >+ int topo[3] = {nbInputs, nbHidden, nbOutputs}; >+ MLPTrain *net; >+ >+ fprintf (stderr, "Got %d samples\n", nbSamples); >+ net = mlp_init(topo, 3, inputs, outputs, nbSamples); >+ rms = mlp_train_backprop(net, inputs, outputs, nbSamples, nbEpoch, 1); >+ printf ("#ifdef HAVE_CONFIG_H\n"); >+ printf ("#include \"config.h\"\n"); >+ printf ("#endif\n\n"); >+ printf ("#include \"mlp.h\"\n\n"); >+ printf ("/* RMS error was %f, seed was %u */\n\n", rms, seed); >+ printf ("static const float weights[%d] = {\n", (topo[0]+1)*topo[1] + (topo[1]+1)*topo[2]); >+ printf ("\n/* hidden layer */\n"); >+ for (i=0;i<(topo[0]+1)*topo[1];i++) >+ { >+ printf ("%gf,", net->weights[0][i]); >+ if (i%5==4) >+ printf("\n"); >+ else >+ printf(" "); >+ } >+ printf ("\n/* output layer */\n"); >+ for (i=0;i<(topo[1]+1)*topo[2];i++) >+ { >+ printf ("%gf,", net->weights[1][i]); >+ if (i%5==4) >+ printf("\n"); >+ else >+ printf(" "); >+ } >+ printf ("};\n\n"); >+ printf ("static const int topo[3] = {%d, %d, %d};\n\n", topo[0], topo[1], topo[2]); >+ printf ("const MLP net = {\n"); >+ printf (" 3,\n"); >+ printf (" topo,\n"); >+ printf (" weights\n};\n"); >+ return 0; >+} >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/mlp_train.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/mlp_train.h >new file mode 100644 >index 0000000000000000000000000000000000000000..494041585a3f9cb643348a992145abce06fe7ebd >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/mlp_train.h >@@ -0,0 +1,86 @@ >+/* Copyright (c) 2008-2011 Octasic Inc. >+ Written by Jean-Marc Valin */ >+/* >+ Redistribution and use in source and binary forms, with or without >+ modification, are permitted provided that the following conditions >+ are met: >+ >+ - Redistributions of source code must retain the above copyright >+ notice, this list of conditions and the following disclaimer. >+ >+ - Redistributions in binary form must reproduce the above copyright >+ notice, this list of conditions and the following disclaimer in the >+ documentation and/or other materials provided with the distribution. >+ >+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS >+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT >+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR >+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR >+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, >+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, >+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR >+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF >+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING >+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS >+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+*/ >+ >+#ifndef _MLP_TRAIN_H_ >+#define _MLP_TRAIN_H_ >+ >+#include <math.h> >+#include <stdlib.h> >+ >+double tansig_table[501]; >+static inline double tansig_double(double x) >+{ >+ return 2./(1.+exp(-2.*x)) - 1.; >+} >+static inline void build_tansig_table(void) >+{ >+ int i; >+ for (i=0;i<501;i++) >+ tansig_table[i] = tansig_double(.04*(i-250)); >+} >+ >+static inline double tansig_approx(double x) >+{ >+ int i; >+ double y, dy; >+ if (x>=10) >+ return 1; >+ if (x<=-10) >+ return -1; >+ i = lrint(25*x); >+ x -= .04*i; >+ y = tansig_table[250+i]; >+ dy = 1-y*y; >+ y = y + x*dy*(1 - y*x); >+ return y; >+} >+ >+static inline float randn(float sd) >+{ >+ float U1, U2, S, x; >+ do { >+ U1 = ((float)rand())/RAND_MAX; >+ U2 = ((float)rand())/RAND_MAX; >+ U1 = 2*U1-1; >+ U2 = 2*U2-1; >+ S = U1*U1 + U2*U2; >+ } while (S >= 1 || S == 0.0f); >+ x = sd*sqrt(-2 * log(S) / S) * U1; >+ return x; >+} >+ >+ >+typedef struct { >+ int layers; >+ int *topo; >+ double **weights; >+ double **best_weights; >+ double *in_rate; >+} MLPTrain; >+ >+ >+#endif /* _MLP_TRAIN_H_ */ >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/opus.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/opus.c >index f76f125cfa300426798ec2c2a1a8c4a934204d58..cdbd13a11cd78d470a98154fc1ea1e8a6c3dcef3 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/opus.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/opus.c >@@ -107,7 +107,7 @@ OPUS_EXPORT void opus_pcm_soft_clip(float *_x, int N, int C, float *declip_mem) > /* Slightly boost "a" by 2^-22. This is just enough to ensure -ffast-math > does not cause output values larger than +/-1, but small enough not > to matter even for 24-bit output. */ >- a += a*2.4e-7; >+ a += a*2.4e-7f; > if (x[i*C]>0) > a = -a; > /* Apply soft clipping */ >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/opus_compare.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/opus_compare.c >index 66828fd8caef6c8f7cc90f87e379e2cfb07d0ce8..1956e08fa5cee0e9b87e5f2ab5217e24eac98d53 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/opus_compare.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/opus_compare.c >@@ -238,15 +238,11 @@ int main(int _argc,const char **_argv){ > if(xlength!=ylength*downsample){ > fprintf(stderr,"Sample counts do not match (%lu!=%lu).\n", > (unsigned long)xlength,(unsigned long)ylength*downsample); >- free(x); >- free(y); > return EXIT_FAILURE; > } > if(xlength<TEST_WIN_SIZE){ > fprintf(stderr,"Insufficient sample data (%lu<%i).\n", > (unsigned long)xlength,TEST_WIN_SIZE); >- free(x); >- free(y); > return EXIT_FAILURE; > } > nframes=(xlength-TEST_WIN_SIZE+TEST_WIN_STEP)/TEST_WIN_STEP; >@@ -367,6 +363,9 @@ int main(int _argc,const char **_argv){ > Ef*=Ef; > err+=Ef*Ef; > } >+ free(xb); >+ free(X); >+ free(Y); > err=pow(err/nframes,1.0/16); > Q=100*(1-0.5*log(1+err)/log(1.13)); > if(Q<0){ >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/opus_decoder.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/opus_decoder.c >index 9a0896b550d34651814e4bde2fd347921a58c16f..149ae7f21d8bb4167fcc9262d32d4393b319f460 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/opus_decoder.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/opus_decoder.c >@@ -33,7 +33,7 @@ > # error "OPUS_BUILD _MUST_ be defined to build Opus. This probably means you need other defines as well, as in a config.h. See the included build files for details." > #endif > >-#if defined(__GNUC__) && (__GNUC__ >= 2) && !defined(__OPTIMIZE__) && !defined(OPUS_WILL_BE_SLOW) && defined(NDEBUG) >+#if defined(__GNUC__) && (__GNUC__ >= 2) && !defined(__OPTIMIZE__) && !defined(OPUS_WILL_BE_SLOW) > # pragma message "You appear to be compiling without optimization, if so opus will be very slow." > #endif > >@@ -891,7 +891,7 @@ int opus_decoder_ctl(OpusDecoder *st, int request, ...) > break; > case OPUS_GET_LAST_PACKET_DURATION_REQUEST: > { >- opus_uint32 *value = va_arg(ap, opus_uint32*); >+ opus_int32 *value = va_arg(ap, opus_int32*); > if (!value) > { > goto bad_arg; >@@ -899,6 +899,26 @@ int opus_decoder_ctl(OpusDecoder *st, int request, ...) > *value = st->last_packet_duration; > } > break; >+ case OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST: >+ { >+ opus_int32 value = va_arg(ap, opus_int32); >+ if(value<0 || value>1) >+ { >+ goto bad_arg; >+ } >+ celt_decoder_ctl(celt_dec, OPUS_SET_PHASE_INVERSION_DISABLED(value)); >+ } >+ break; >+ case OPUS_GET_PHASE_INVERSION_DISABLED_REQUEST: >+ { >+ opus_int32 *value = va_arg(ap, opus_int32*); >+ if (!value) >+ { >+ goto bad_arg; >+ } >+ celt_decoder_ctl(celt_dec, OPUS_GET_PHASE_INVERSION_DISABLED(value)); >+ } >+ break; > default: > /*fprintf(stderr, "unknown opus_decoder_ctl() request: %d", request);*/ > ret = OPUS_UNIMPLEMENTED; >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/opus_demo.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/opus_demo.c >index 6988a8cb15d6e608f5865277178e1c04c6961d4b..50987c96f265f6060762f9c04e6287cb9b5aab6b 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/opus_demo.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/opus_demo.c >@@ -54,9 +54,9 @@ void print_usage( char* argv[] ) > fprintf(stderr, "-d : only runs the decoder (reads the bit-stream as input)\n" ); > fprintf(stderr, "-cbr : enable constant bitrate; default: variable bitrate\n" ); > fprintf(stderr, "-cvbr : enable constrained variable bitrate; default: unconstrained\n" ); >- fprintf(stderr, "-variable-duration : enable frames of variable duration (experts only); default: disabled\n" ); >+ fprintf(stderr, "-delayed-decision : use look-ahead for speech/music detection (experts only); default: disabled\n" ); > fprintf(stderr, "-bandwidth <NB|MB|WB|SWB|FB> : audio bandwidth (from narrowband to fullband); default: sampling rate\n" ); >- fprintf(stderr, "-framesize <2.5|5|10|20|40|60> : frame size in ms; default: 20 \n" ); >+ fprintf(stderr, "-framesize <2.5|5|10|20|40|60|80|100|120> : frame size in ms; default: 20 \n" ); > fprintf(stderr, "-max_payload <bytes> : maximum payload size in bytes, default: 1024\n" ); > fprintf(stderr, "-complexity <comp> : complexity, 0 (lowest) ... 10 (highest); default: 10\n" ); > fprintf(stderr, "-inbandfec : enable SILK inband FEC\n" ); >@@ -253,6 +253,7 @@ int main(int argc, char *argv[]) > opus_uint32 dec_final_range; > int encode_only=0, decode_only=0; > int max_frame_size = 48000*2; >+ size_t num_read; > int curr_read=0; > int sweep_bps = 0; > int random_framesize=0, newsize=0, delayed_celt=0; >@@ -382,9 +383,15 @@ int main(int argc, char *argv[]) > frame_size = sampling_rate/25; > else if (strcmp(argv[ args + 1 ], "60")==0) > frame_size = 3*sampling_rate/50; >+ else if (strcmp(argv[ args + 1 ], "80")==0) >+ frame_size = 4*sampling_rate/50; >+ else if (strcmp(argv[ args + 1 ], "100")==0) >+ frame_size = 5*sampling_rate/50; >+ else if (strcmp(argv[ args + 1 ], "120")==0) >+ frame_size = 6*sampling_rate/50; > else { > fprintf(stderr, "Unsupported frame size: %s ms. " >- "Supported are 2.5, 5, 10, 20, 40, 60.\n", >+ "Supported are 2.5, 5, 10, 20, 40, 60, 80, 100, 120.\n", > argv[ args + 1 ]); > return EXIT_FAILURE; > } >@@ -408,10 +415,6 @@ int main(int argc, char *argv[]) > check_encoder_option(decode_only, "-cvbr"); > cvbr = 1; > args++; >- } else if( strcmp( argv[ args ], "-variable-duration" ) == 0 ) { >- check_encoder_option(decode_only, "-variable-duration"); >- variable_duration = OPUS_FRAMESIZE_VARIABLE; >- args++; > } else if( strcmp( argv[ args ], "-delayed-decision" ) == 0 ) { > check_encoder_option(decode_only, "-delayed-decision"); > delayed_decision = 1; >@@ -599,22 +602,25 @@ int main(int argc, char *argv[]) > } > if(delayed_decision) > { >- if (variable_duration!=OPUS_FRAMESIZE_VARIABLE) >- { >- if (frame_size==sampling_rate/400) >- variable_duration = OPUS_FRAMESIZE_2_5_MS; >- else if (frame_size==sampling_rate/200) >- variable_duration = OPUS_FRAMESIZE_5_MS; >- else if (frame_size==sampling_rate/100) >- variable_duration = OPUS_FRAMESIZE_10_MS; >- else if (frame_size==sampling_rate/50) >- variable_duration = OPUS_FRAMESIZE_20_MS; >- else if (frame_size==sampling_rate/25) >- variable_duration = OPUS_FRAMESIZE_40_MS; >- else >- variable_duration = OPUS_FRAMESIZE_60_MS; >- opus_encoder_ctl(enc, OPUS_SET_EXPERT_FRAME_DURATION(variable_duration)); >- } >+ if (frame_size==sampling_rate/400) >+ variable_duration = OPUS_FRAMESIZE_2_5_MS; >+ else if (frame_size==sampling_rate/200) >+ variable_duration = OPUS_FRAMESIZE_5_MS; >+ else if (frame_size==sampling_rate/100) >+ variable_duration = OPUS_FRAMESIZE_10_MS; >+ else if (frame_size==sampling_rate/50) >+ variable_duration = OPUS_FRAMESIZE_20_MS; >+ else if (frame_size==sampling_rate/25) >+ variable_duration = OPUS_FRAMESIZE_40_MS; >+ else if (frame_size==3*sampling_rate/50) >+ variable_duration = OPUS_FRAMESIZE_60_MS; >+ else if (frame_size==4*sampling_rate/50) >+ variable_duration = OPUS_FRAMESIZE_80_MS; >+ else if (frame_size==5*sampling_rate/50) >+ variable_duration = OPUS_FRAMESIZE_100_MS; >+ else >+ variable_duration = OPUS_FRAMESIZE_120_MS; >+ opus_encoder_ctl(enc, OPUS_SET_EXPERT_FRAME_DURATION(variable_duration)); > frame_size = 2*48000; > } > while (!stop) >@@ -652,8 +658,8 @@ int main(int argc, char *argv[]) > if (decode_only) > { > unsigned char ch[4]; >- err = fread(ch, 1, 4, fin); >- if (feof(fin)) >+ num_read = fread(ch, 1, 4, fin); >+ if (num_read!=4) > break; > len[toggle] = char_to_int(ch); > if (len[toggle]>max_payload_bytes || len[toggle]<0) >@@ -661,14 +667,16 @@ int main(int argc, char *argv[]) > fprintf(stderr, "Invalid payload length: %d\n",len[toggle]); > break; > } >- err = fread(ch, 1, 4, fin); >+ num_read = fread(ch, 1, 4, fin); >+ if (num_read!=4) >+ break; > enc_final_range[toggle] = char_to_int(ch); >- err = fread(data[toggle], 1, len[toggle], fin); >- if (err<len[toggle]) >+ num_read = fread(data[toggle], 1, len[toggle], fin); >+ if (num_read!=(size_t)len[toggle]) > { > fprintf(stderr, "Ran out of input, " > "expecting %d bytes got %d\n", >- len[toggle],err); >+ len[toggle],(int)num_read); > break; > } > } else { >@@ -680,8 +688,8 @@ int main(int argc, char *argv[]) > opus_encoder_ctl(enc, OPUS_SET_FORCE_CHANNELS(mode_list[curr_mode][3])); > frame_size = mode_list[curr_mode][2]; > } >- err = fread(fbytes, sizeof(short)*channels, frame_size-remaining, fin); >- curr_read = err; >+ num_read = fread(fbytes, sizeof(short)*channels, frame_size-remaining, fin); >+ curr_read = (int)num_read; > tot_in += curr_read; > for(i=0;i<curr_read*channels;i++) > { >@@ -721,14 +729,8 @@ int main(int argc, char *argv[]) > if (len[toggle] < 0) > { > fprintf (stderr, "opus_encode() returned %d\n", len[toggle]); >- free(data[0]); >- if (use_inbandfec) >- free(data[1]); > fclose(fin); > fclose(fout); >- free(in); >- free(out); >- free(fbytes); > return EXIT_FAILURE; > } > curr_mode_count += frame_size; >@@ -746,14 +748,6 @@ int main(int argc, char *argv[]) > if ((err = opus_packet_pad(data[toggle], len[toggle], new_len)) != OPUS_OK) > { > fprintf(stderr, "padding failed: %s\n", opus_strerror(err)); >- free(data[0]); >- if (use_inbandfec) >- free(data[1]); >- fclose(fin); >- fclose(fout); >- free(in); >- free(out); >- free(fbytes); > return EXIT_FAILURE; > } > len[toggle] = new_len; >@@ -765,44 +759,20 @@ int main(int argc, char *argv[]) > int_to_char(len[toggle], int_field); > if (fwrite(int_field, 1, 4, fout) != 4) { > fprintf(stderr, "Error writing.\n"); >- free(data[0]); >- if (use_inbandfec) >- free(data[1]); >- fclose(fin); >- fclose(fout); >- free(in); >- free(out); >- free(fbytes); > return EXIT_FAILURE; > } > int_to_char(enc_final_range[toggle], int_field); > if (fwrite(int_field, 1, 4, fout) != 4) { > fprintf(stderr, "Error writing.\n"); >- free(data[0]); >- if (use_inbandfec) >- free(data[1]); >- fclose(fin); >- fclose(fout); >- free(in); >- free(out); >- free(fbytes); > return EXIT_FAILURE; > } > if (fwrite(data[toggle], 1, len[toggle], fout) != (unsigned)len[toggle]) { > fprintf(stderr, "Error writing.\n"); >- free(data[0]); >- if (use_inbandfec) >- free(data[1]); >- fclose(fin); >- fclose(fout); >- free(in); >- free(out); >- free(fbytes); > return EXIT_FAILURE; > } > tot_samples += nb_encoded; > } else { >- int output_samples; >+ opus_int32 output_samples; > lost = len[toggle]==0 || (packet_loss_perc>0 && rand()%100 < packet_loss_perc); > if (lost) > opus_decoder_ctl(dec, OPUS_GET_LAST_PACKET_DURATION(&output_samples)); >@@ -828,7 +798,7 @@ int main(int argc, char *argv[]) > if (!decode_only && tot_out + output_samples > tot_in) > { > stop=1; >- output_samples = tot_in-tot_out; >+ output_samples = (opus_int32)(tot_in - tot_out); > } > if (output_samples>skip) { > int i; >@@ -841,14 +811,6 @@ int main(int argc, char *argv[]) > } > if (fwrite(fbytes, sizeof(short)*channels, output_samples-skip, fout) != (unsigned)(output_samples-skip)){ > fprintf(stderr, "Error writing.\n"); >- free(data[0]); >- if (use_inbandfec) >- free(data[1]); >- fclose(fin); >- fclose(fout); >- free(in); >- free(out); >- free(fbytes); > return EXIT_FAILURE; > } > tot_out += output_samples-skip; >@@ -875,14 +837,8 @@ int main(int argc, char *argv[]) > (long)count, > (unsigned long)enc_final_range[toggle^use_inbandfec], > (unsigned long)dec_final_range); >- free(data[0]); >- if (use_inbandfec) >- free(data[1]); > fclose(fin); > fclose(fout); >- free(in); >- free(out); >- free(fbytes); > return EXIT_FAILURE; > } > >@@ -922,8 +878,6 @@ int main(int argc, char *argv[]) > 1e-3*bits_act*sampling_rate/(1e-15+frame_size*(double)count_act)); > fprintf (stderr, "bitrate standard deviation: %7.3f kb/s\n", > 1e-3*sqrt(bits2/count - bits*bits/(count*(double)count))*sampling_rate/frame_size); >- /* Close any files to which intermediate results were stored */ >- SILK_DEBUG_STORE_CLOSE_FILES > silk_TimerSave("opus_timing.txt"); > opus_encoder_destroy(enc); > opus_decoder_destroy(dec); >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/opus_encoder.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/opus_encoder.c >index 9a516a884aa7778e8577a5598191530bc69067b2..2149c20b4190a047cb44ff63e2daac1c793956f1 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/opus_encoder.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/opus_encoder.c >@@ -53,6 +53,10 @@ > > #define MAX_ENCODER_BUFFER 480 > >+#ifndef DISABLE_FLOAT_API >+#define PSEUDO_SNR_THRESHOLD 316.23f /* 10^(25/10) */ >+#endif >+ > typedef struct { > opus_val32 XX, XY, YY; > opus_val16 smoothed_width; >@@ -82,6 +86,7 @@ struct OpusEncoder { > int encoder_buffer; > int lfe; > int arch; >+ int use_dtx; /* general DTX for both SILK and CELT */ > #ifndef DISABLE_FLOAT_API > TonalityAnalysisState analysis; > #endif >@@ -97,6 +102,8 @@ struct OpusEncoder { > int prev_channels; > int prev_framesize; > int bandwidth; >+ /* Bandwidth determined automatically from the rate (before any other adjustment) */ >+ int auto_bandwidth; > int silk_bw_switch; > /* Sampling rate (at the API level) */ > int first; >@@ -105,7 +112,10 @@ struct OpusEncoder { > opus_val16 delay_buffer[MAX_ENCODER_BUFFER*2]; > #ifndef DISABLE_FLOAT_API > int detected_bandwidth; >+ int nb_no_activity_frames; >+ opus_val32 peak_signal_energy; > #endif >+ int nonfinal_frame; /* current frame is not the final in a packet */ > opus_uint32 rangeFinal; > }; > >@@ -113,32 +123,32 @@ struct OpusEncoder { > middle (memoriless) threshold. The second column is the hysteresis > (difference with the middle) */ > static const opus_int32 mono_voice_bandwidth_thresholds[8] = { >- 11000, 1000, /* NB<->MB */ >- 14000, 1000, /* MB<->WB */ >- 17000, 1000, /* WB<->SWB */ >- 21000, 2000, /* SWB<->FB */ >+ 10000, 1000, /* NB<->MB */ >+ 11000, 1000, /* MB<->WB */ >+ 13500, 1000, /* WB<->SWB */ >+ 14000, 2000, /* SWB<->FB */ > }; > static const opus_int32 mono_music_bandwidth_thresholds[8] = { >- 12000, 1000, /* NB<->MB */ >- 15000, 1000, /* MB<->WB */ >- 18000, 2000, /* WB<->SWB */ >- 22000, 2000, /* SWB<->FB */ >+ 10000, 1000, /* NB<->MB */ >+ 11000, 1000, /* MB<->WB */ >+ 13500, 1000, /* WB<->SWB */ >+ 14000, 2000, /* SWB<->FB */ > }; > static const opus_int32 stereo_voice_bandwidth_thresholds[8] = { >- 11000, 1000, /* NB<->MB */ >- 14000, 1000, /* MB<->WB */ >- 21000, 2000, /* WB<->SWB */ >- 28000, 2000, /* SWB<->FB */ >+ 10000, 1000, /* NB<->MB */ >+ 11000, 1000, /* MB<->WB */ >+ 13500, 1000, /* WB<->SWB */ >+ 14000, 2000, /* SWB<->FB */ > }; > static const opus_int32 stereo_music_bandwidth_thresholds[8] = { >- 12000, 1000, /* NB<->MB */ >- 18000, 2000, /* MB<->WB */ >- 21000, 2000, /* WB<->SWB */ >- 30000, 2000, /* SWB<->FB */ >+ 10000, 1000, /* NB<->MB */ >+ 11000, 1000, /* MB<->WB */ >+ 13500, 1000, /* WB<->SWB */ >+ 14000, 2000, /* SWB<->FB */ > }; > /* Threshold bit-rates for switching between mono and stereo */ >-static const opus_int32 stereo_voice_threshold = 30000; >-static const opus_int32 stereo_music_threshold = 30000; >+static const opus_int32 stereo_voice_threshold = 24000; >+static const opus_int32 stereo_music_threshold = 24000; > > /* Threshold bit-rate for switching between SILK/hybrid and CELT-only */ > static const opus_int32 mode_thresholds[2][2] = { >@@ -147,6 +157,14 @@ static const opus_int32 mode_thresholds[2][2] = { > { 36000, 16000}, /* stereo */ > }; > >+static const opus_int32 fec_thresholds[] = { >+ 12000, 1000, /* NB */ >+ 14000, 1000, /* MB */ >+ 16000, 1000, /* WB */ >+ 20000, 1000, /* SWB */ >+ 22000, 1000, /* FB */ >+}; >+ > int opus_encoder_get_size(int channels) > { > int silkEncSizeBytes, celtEncSizeBytes; >@@ -245,7 +263,8 @@ int opus_encoder_init(OpusEncoder* st, opus_int32 Fs, int channels, int applicat > st->bandwidth = OPUS_BANDWIDTH_FULLBAND; > > #ifndef DISABLE_FLOAT_API >- tonality_analysis_init(&st->analysis); >+ tonality_analysis_init(&st->analysis, st->Fs); >+ st->analysis.application = st->application; > #endif > > return OPUS_OK; >@@ -323,10 +342,11 @@ static void silk_biquad_float( > } > #endif > >-static void hp_cutoff(const opus_val16 *in, opus_int32 cutoff_Hz, opus_val16 *out, opus_val32 *hp_mem, int len, int channels, opus_int32 Fs) >+static void hp_cutoff(const opus_val16 *in, opus_int32 cutoff_Hz, opus_val16 *out, opus_val32 *hp_mem, int len, int channels, opus_int32 Fs, int arch) > { > opus_int32 B_Q28[ 3 ], A_Q28[ 2 ]; > opus_int32 Fc_Q19, r_Q28, r_Q22; >+ (void)arch; > > silk_assert( cutoff_Hz <= silk_int32_MAX / SILK_FIX_CONST( 1.5 * 3.14159 / 1000, 19 ) ); > Fc_Q19 = silk_DIV32_16( silk_SMULBB( SILK_FIX_CONST( 1.5 * 3.14159 / 1000, 19 ), cutoff_Hz ), Fs/1000 ); >@@ -346,9 +366,10 @@ static void hp_cutoff(const opus_val16 *in, opus_int32 cutoff_Hz, opus_val16 *ou > A_Q28[ 1 ] = silk_SMULWW( r_Q22, r_Q22 ); > > #ifdef FIXED_POINT >- silk_biquad_alt( in, B_Q28, A_Q28, hp_mem, out, len, channels ); >- if( channels == 2 ) { >- silk_biquad_alt( in+1, B_Q28, A_Q28, hp_mem+2, out+1, len, channels ); >+ if( channels == 1 ) { >+ silk_biquad_alt_stride1( in, B_Q28, A_Q28, hp_mem, out, len ); >+ } else { >+ silk_biquad_alt_stride2( in, B_Q28, A_Q28, hp_mem, out, len, arch ); > } > #else > silk_biquad_float( in, B_Q28, A_Q28, hp_mem, out, len, channels ); >@@ -371,14 +392,14 @@ static void dc_reject(const opus_val16 *in, opus_int32 cutoff_Hz, opus_val16 *ou > for (i=0;i<len;i++) > { > opus_val32 x, tmp, y; >- x = SHL32(EXTEND32(in[channels*i+c]), 15); >+ x = SHL32(EXTEND32(in[channels*i+c]), 14); > /* First stage */ > tmp = x-hp_mem[2*c]; > hp_mem[2*c] = hp_mem[2*c] + PSHR32(x - hp_mem[2*c], shift); > /* Second stage */ > y = tmp - hp_mem[2*c+1]; > hp_mem[2*c+1] = hp_mem[2*c+1] + PSHR32(tmp - hp_mem[2*c+1], shift); >- out[channels*i+c] = EXTRACT16(SATURATE(PSHR32(y, 15), 32767)); >+ out[channels*i+c] = EXTRACT16(SATURATE(PSHR32(y, 14), 32767)); > } > } > } >@@ -386,24 +407,57 @@ static void dc_reject(const opus_val16 *in, opus_int32 cutoff_Hz, opus_val16 *ou > #else > static void dc_reject(const opus_val16 *in, opus_int32 cutoff_Hz, opus_val16 *out, opus_val32 *hp_mem, int len, int channels, opus_int32 Fs) > { >- int c, i; >- float coef; >- >+ int i; >+ float coef, coef2; > coef = 4.0f*cutoff_Hz/Fs; >- for (c=0;c<channels;c++) >+ coef2 = 1-coef; >+ if (channels==2) > { >+ float m0, m1, m2, m3; >+ m0 = hp_mem[0]; >+ m1 = hp_mem[1]; >+ m2 = hp_mem[2]; >+ m3 = hp_mem[3]; >+ for (i=0;i<len;i++) >+ { >+ opus_val32 x0, x1, tmp0, tmp1, out0, out1; >+ x0 = in[2*i+0]; >+ x1 = in[2*i+1]; >+ /* First stage */ >+ tmp0 = x0-m0; >+ tmp1 = x1-m2; >+ m0 = coef*x0 + VERY_SMALL + coef2*m0; >+ m2 = coef*x1 + VERY_SMALL + coef2*m2; >+ /* Second stage */ >+ out0 = tmp0 - m1; >+ out1 = tmp1 - m3; >+ m1 = coef*tmp0 + VERY_SMALL + coef2*m1; >+ m3 = coef*tmp1 + VERY_SMALL + coef2*m3; >+ out[2*i+0] = out0; >+ out[2*i+1] = out1; >+ } >+ hp_mem[0] = m0; >+ hp_mem[1] = m1; >+ hp_mem[2] = m2; >+ hp_mem[3] = m3; >+ } else { >+ float m0, m1; >+ m0 = hp_mem[0]; >+ m1 = hp_mem[1]; > for (i=0;i<len;i++) > { > opus_val32 x, tmp, y; >- x = in[channels*i+c]; >+ x = in[i]; > /* First stage */ >- tmp = x-hp_mem[2*c]; >- hp_mem[2*c] = hp_mem[2*c] + coef*(x - hp_mem[2*c]) + VERY_SMALL; >+ tmp = x-m0; >+ m0 = coef*x + VERY_SMALL + coef2*m0; > /* Second stage */ >- y = tmp - hp_mem[2*c+1]; >- hp_mem[2*c+1] = hp_mem[2*c+1] + coef*(tmp - hp_mem[2*c+1]) + VERY_SMALL; >- out[channels*i+c] = y; >+ y = tmp - m1; >+ m1 = coef*tmp + VERY_SMALL + coef2*m1; >+ out[i] = y; > } >+ hp_mem[0] = m0; >+ hp_mem[1] = m1; > } > } > #endif >@@ -520,288 +574,58 @@ static opus_int32 user_bitrate_to_bitrate(OpusEncoder *st, int frame_size, int m > return st->user_bitrate_bps; > } > >-#ifndef DISABLE_FLOAT_API >-/* Don't use more than 60 ms for the frame size analysis */ >-#define MAX_DYNAMIC_FRAMESIZE 24 >-/* Estimates how much the bitrate will be boosted based on the sub-frame energy */ >-static float transient_boost(const float *E, const float *E_1, int LM, int maxM) >-{ >- int i; >- int M; >- float sumE=0, sumE_1=0; >- float metric; >- >- M = IMIN(maxM, (1<<LM)+1); >- for (i=0;i<M;i++) >- { >- sumE += E[i]; >- sumE_1 += E_1[i]; >- } >- metric = sumE*sumE_1/(M*M); >- /*if (LM==3) >- printf("%f\n", metric);*/ >- /*return metric>10 ? 1 : 0;*/ >- /*return MAX16(0,1-exp(-.25*(metric-2.)));*/ >- return MIN16(1,(float)sqrt(MAX16(0,.05f*(metric-2)))); >-} >- >-/* Viterbi decoding trying to find the best frame size combination using look-ahead >- >- State numbering: >- 0: unused >- 1: 2.5 ms >- 2: 5 ms (#1) >- 3: 5 ms (#2) >- 4: 10 ms (#1) >- 5: 10 ms (#2) >- 6: 10 ms (#3) >- 7: 10 ms (#4) >- 8: 20 ms (#1) >- 9: 20 ms (#2) >- 10: 20 ms (#3) >- 11: 20 ms (#4) >- 12: 20 ms (#5) >- 13: 20 ms (#6) >- 14: 20 ms (#7) >- 15: 20 ms (#8) >-*/ >-static int transient_viterbi(const float *E, const float *E_1, int N, int frame_cost, int rate) >-{ >- int i; >- float cost[MAX_DYNAMIC_FRAMESIZE][16]; >- int states[MAX_DYNAMIC_FRAMESIZE][16]; >- float best_cost; >- int best_state; >- float factor; >- /* Take into account that we damp VBR in the 32 kb/s to 64 kb/s range. */ >- if (rate<80) >- factor=0; >- else if (rate>160) >- factor=1; >- else >- factor = (rate-80.f)/80.f; >- /* Makes variable framesize less aggressive at lower bitrates, but I can't >- find any valid theoretical justification for this (other than it seems >- to help) */ >- for (i=0;i<16;i++) >- { >- /* Impossible state */ >- states[0][i] = -1; >- cost[0][i] = 1e10; >- } >- for (i=0;i<4;i++) >- { >- cost[0][1<<i] = (frame_cost + rate*(1<<i))*(1+factor*transient_boost(E, E_1, i, N+1)); >- states[0][1<<i] = i; >- } >- for (i=1;i<N;i++) >- { >- int j; >- >- /* Follow continuations */ >- for (j=2;j<16;j++) >- { >- cost[i][j] = cost[i-1][j-1]; >- states[i][j] = j-1; >- } >- >- /* New frames */ >- for(j=0;j<4;j++) >- { >- int k; >- float min_cost; >- float curr_cost; >- states[i][1<<j] = 1; >- min_cost = cost[i-1][1]; >- for(k=1;k<4;k++) >- { >- float tmp = cost[i-1][(1<<(k+1))-1]; >- if (tmp < min_cost) >- { >- states[i][1<<j] = (1<<(k+1))-1; >- min_cost = tmp; >- } >- } >- curr_cost = (frame_cost + rate*(1<<j))*(1+factor*transient_boost(E+i, E_1+i, j, N-i+1)); >- cost[i][1<<j] = min_cost; >- /* If part of the frame is outside the analysis window, only count part of the cost */ >- if (N-i < (1<<j)) >- cost[i][1<<j] += curr_cost*(float)(N-i)/(1<<j); >- else >- cost[i][1<<j] += curr_cost; >- } >- } >- >- best_state=1; >- best_cost = cost[N-1][1]; >- /* Find best end state (doesn't force a frame to end at N-1) */ >- for (i=2;i<16;i++) >- { >- if (cost[N-1][i]<best_cost) >- { >- best_cost = cost[N-1][i]; >- best_state = i; >- } >- } >- >- /* Follow transitions back */ >- for (i=N-1;i>=0;i--) >- { >- /*printf("%d ", best_state);*/ >- best_state = states[i][best_state]; >- } >- /*printf("%d\n", best_state);*/ >- return best_state; >-} >- >-static int optimize_framesize(const void *x, int len, int C, opus_int32 Fs, >- int bitrate, opus_val16 tonality, float *mem, int buffering, >- downmix_func downmix) >-{ >- int N; >- int i; >- float e[MAX_DYNAMIC_FRAMESIZE+4]; >- float e_1[MAX_DYNAMIC_FRAMESIZE+3]; >- opus_val32 memx; >- int bestLM=0; >- int subframe; >- int pos; >- int offset; >- VARDECL(opus_val32, sub); >- >- subframe = Fs/400; >- ALLOC(sub, subframe, opus_val32); >- e[0]=mem[0]; >- e_1[0]=1.f/(EPSILON+mem[0]); >- if (buffering) >- { >- /* Consider the CELT delay when not in restricted-lowdelay */ >- /* We assume the buffering is between 2.5 and 5 ms */ >- offset = 2*subframe - buffering; >- celt_assert(offset>=0 && offset <= subframe); >- len -= offset; >- e[1]=mem[1]; >- e_1[1]=1.f/(EPSILON+mem[1]); >- e[2]=mem[2]; >- e_1[2]=1.f/(EPSILON+mem[2]); >- pos = 3; >- } else { >- pos=1; >- offset=0; >- } >- N=IMIN(len/subframe, MAX_DYNAMIC_FRAMESIZE); >- /* Just silencing a warning, it's really initialized later */ >- memx = 0; >- for (i=0;i<N;i++) >- { >- float tmp; >- opus_val32 tmpx; >- int j; >- tmp=EPSILON; >- >- downmix(x, sub, subframe, i*subframe+offset, 0, -2, C); >- if (i==0) >- memx = sub[0]; >- for (j=0;j<subframe;j++) >- { >- tmpx = sub[j]; >- tmp += (tmpx-memx)*(float)(tmpx-memx); >- memx = tmpx; >- } >- e[i+pos] = tmp; >- e_1[i+pos] = 1.f/tmp; >- } >- /* Hack to get 20 ms working with APPLICATION_AUDIO >- The real problem is that the corresponding memory needs to use 1.5 ms >- from this frame and 1 ms from the next frame */ >- e[i+pos] = e[i+pos-1]; >- if (buffering) >- N=IMIN(MAX_DYNAMIC_FRAMESIZE, N+2); >- bestLM = transient_viterbi(e, e_1, N, (int)((1.f+.5f*tonality)*(60*C+40)), bitrate/400); >- mem[0] = e[1<<bestLM]; >- if (buffering) >- { >- mem[1] = e[(1<<bestLM)+1]; >- mem[2] = e[(1<<bestLM)+2]; >- } >- return bestLM; >-} >- >-#endif >- > #ifndef DISABLE_FLOAT_API > #ifdef FIXED_POINT > #define PCM2VAL(x) FLOAT2INT16(x) > #else > #define PCM2VAL(x) SCALEIN(x) > #endif >-void downmix_float(const void *_x, opus_val32 *sub, int subframe, int offset, int c1, int c2, int C) >+ >+void downmix_float(const void *_x, opus_val32 *y, int subframe, int offset, int c1, int c2, int C) > { > const float *x; >- opus_val32 scale; > int j; >+ > x = (const float *)_x; > for (j=0;j<subframe;j++) >- sub[j] = PCM2VAL(x[(j+offset)*C+c1]); >+ y[j] = PCM2VAL(x[(j+offset)*C+c1]); > if (c2>-1) > { > for (j=0;j<subframe;j++) >- sub[j] += PCM2VAL(x[(j+offset)*C+c2]); >+ y[j] += PCM2VAL(x[(j+offset)*C+c2]); > } else if (c2==-2) > { > int c; > for (c=1;c<C;c++) > { > for (j=0;j<subframe;j++) >- sub[j] += PCM2VAL(x[(j+offset)*C+c]); >+ y[j] += PCM2VAL(x[(j+offset)*C+c]); > } > } >-#ifdef FIXED_POINT >- scale = (1<<SIG_SHIFT); >-#else >- scale = 1.f; >-#endif >- if (C==-2) >- scale /= C; >- else >- scale /= 2; >- for (j=0;j<subframe;j++) >- sub[j] *= scale; > } > #endif > >-void downmix_int(const void *_x, opus_val32 *sub, int subframe, int offset, int c1, int c2, int C) >+void downmix_int(const void *_x, opus_val32 *y, int subframe, int offset, int c1, int c2, int C) > { > const opus_int16 *x; >- opus_val32 scale; > int j; >+ > x = (const opus_int16 *)_x; > for (j=0;j<subframe;j++) >- sub[j] = x[(j+offset)*C+c1]; >+ y[j] = x[(j+offset)*C+c1]; > if (c2>-1) > { > for (j=0;j<subframe;j++) >- sub[j] += x[(j+offset)*C+c2]; >+ y[j] += x[(j+offset)*C+c2]; > } else if (c2==-2) > { > int c; > for (c=1;c<C;c++) > { > for (j=0;j<subframe;j++) >- sub[j] += x[(j+offset)*C+c]; >+ y[j] += x[(j+offset)*C+c]; > } > } >-#ifdef FIXED_POINT >- scale = (1<<SIG_SHIFT); >-#else >- scale = 1.f/32768; >-#endif >- if (C==-2) >- scale /= C; >- else >- scale /= 2; >- for (j=0;j<subframe;j++) >- sub[j] *= scale; > } > > opus_int32 frame_size_select(opus_int32 frame_size, int variable_duration, opus_int32 Fs) >@@ -811,53 +635,24 @@ opus_int32 frame_size_select(opus_int32 frame_size, int variable_duration, opus_ > return -1; > if (variable_duration == OPUS_FRAMESIZE_ARG) > new_size = frame_size; >- else if (variable_duration == OPUS_FRAMESIZE_VARIABLE) >- new_size = Fs/50; >- else if (variable_duration >= OPUS_FRAMESIZE_2_5_MS && variable_duration <= OPUS_FRAMESIZE_60_MS) >- new_size = IMIN(3*Fs/50, (Fs/400)<<(variable_duration-OPUS_FRAMESIZE_2_5_MS)); >+ else if (variable_duration >= OPUS_FRAMESIZE_2_5_MS && variable_duration <= OPUS_FRAMESIZE_120_MS) >+ { >+ if (variable_duration <= OPUS_FRAMESIZE_40_MS) >+ new_size = (Fs/400)<<(variable_duration-OPUS_FRAMESIZE_2_5_MS); >+ else >+ new_size = (variable_duration-OPUS_FRAMESIZE_2_5_MS-2)*Fs/50; >+ } > else > return -1; > if (new_size>frame_size) > return -1; >- if (400*new_size!=Fs && 200*new_size!=Fs && 100*new_size!=Fs && >- 50*new_size!=Fs && 25*new_size!=Fs && 50*new_size!=3*Fs) >+ if (400*new_size!=Fs && 200*new_size!=Fs && 100*new_size!=Fs && >+ 50*new_size!=Fs && 25*new_size!=Fs && 50*new_size!=3*Fs && >+ 50*new_size!=4*Fs && 50*new_size!=5*Fs && 50*new_size!=6*Fs) > return -1; > return new_size; > } > >-opus_int32 compute_frame_size(const void *analysis_pcm, int frame_size, >- int variable_duration, int C, opus_int32 Fs, int bitrate_bps, >- int delay_compensation, downmix_func downmix >-#ifndef DISABLE_FLOAT_API >- , float *subframe_mem >-#endif >- ) >-{ >-#ifndef DISABLE_FLOAT_API >- if (variable_duration == OPUS_FRAMESIZE_VARIABLE && frame_size >= Fs/200) >- { >- int LM = 3; >- LM = optimize_framesize(analysis_pcm, frame_size, C, Fs, bitrate_bps, >- 0, subframe_mem, delay_compensation, downmix); >- while ((Fs/400<<LM)>frame_size) >- LM--; >- frame_size = (Fs/400<<LM); >- } else >-#else >- (void)analysis_pcm; >- (void)C; >- (void)bitrate_bps; >- (void)delay_compensation; >- (void)downmix; >-#endif >- { >- frame_size = frame_size_select(frame_size, variable_duration, Fs); >- } >- if (frame_size<0) >- return -1; >- return frame_size; >-} >- > opus_val16 compute_stereo_width(const opus_val16 *pcm, int frame_size, opus_int32 Fs, StereoWidthState *mem) > { > opus_val32 xx, xy, yy; >@@ -934,6 +729,347 @@ opus_val16 compute_stereo_width(const opus_val16 *pcm, int frame_size, opus_int3 > return EXTRACT16(MIN32(Q15ONE, MULT16_16(20, mem->max_follower))); > } > >+static int decide_fec(int useInBandFEC, int PacketLoss_perc, int last_fec, int mode, int *bandwidth, opus_int32 rate) >+{ >+ int orig_bandwidth; >+ if (!useInBandFEC || PacketLoss_perc == 0 || mode == MODE_CELT_ONLY) >+ return 0; >+ orig_bandwidth = *bandwidth; >+ for (;;) >+ { >+ opus_int32 hysteresis; >+ opus_int32 LBRR_rate_thres_bps; >+ /* Compute threshold for using FEC at the current bandwidth setting */ >+ LBRR_rate_thres_bps = fec_thresholds[2*(*bandwidth - OPUS_BANDWIDTH_NARROWBAND)]; >+ hysteresis = fec_thresholds[2*(*bandwidth - OPUS_BANDWIDTH_NARROWBAND) + 1]; >+ if (last_fec == 1) LBRR_rate_thres_bps -= hysteresis; >+ if (last_fec == 0) LBRR_rate_thres_bps += hysteresis; >+ LBRR_rate_thres_bps = silk_SMULWB( silk_MUL( LBRR_rate_thres_bps, >+ 125 - silk_min( PacketLoss_perc, 25 ) ), SILK_FIX_CONST( 0.01, 16 ) ); >+ /* If loss <= 5%, we look at whether we have enough rate to enable FEC. >+ If loss > 5%, we decrease the bandwidth until we can enable FEC. */ >+ if (rate > LBRR_rate_thres_bps) >+ return 1; >+ else if (PacketLoss_perc <= 5) >+ return 0; >+ else if (*bandwidth > OPUS_BANDWIDTH_NARROWBAND) >+ (*bandwidth)--; >+ else >+ break; >+ } >+ /* Couldn't find any bandwidth to enable FEC, keep original bandwidth. */ >+ *bandwidth = orig_bandwidth; >+ return 0; >+} >+ >+static int compute_silk_rate_for_hybrid(int rate, int bandwidth, int frame20ms, int vbr, int fec) { >+ int entry; >+ int i; >+ int N; >+ int silk_rate; >+ static int rate_table[][5] = { >+ /* |total| |-------- SILK------------| >+ |-- No FEC -| |--- FEC ---| >+ 10ms 20ms 10ms 20ms */ >+ { 0, 0, 0, 0, 0}, >+ {12000, 10000, 10000, 11000, 11000}, >+ {16000, 13500, 13500, 15000, 15000}, >+ {20000, 16000, 16000, 18000, 18000}, >+ {24000, 18000, 18000, 21000, 21000}, >+ {32000, 22000, 22000, 28000, 28000}, >+ {64000, 38000, 38000, 50000, 50000} >+ }; >+ entry = 1 + frame20ms + 2*fec; >+ N = sizeof(rate_table)/sizeof(rate_table[0]); >+ for (i=1;i<N;i++) >+ { >+ if (rate_table[i][0] > rate) break; >+ } >+ if (i == N) >+ { >+ silk_rate = rate_table[i-1][entry]; >+ /* For now, just give 50% of the extra bits to SILK. */ >+ silk_rate += (rate-rate_table[i-1][0])/2; >+ } else { >+ opus_int32 lo, hi, x0, x1; >+ lo = rate_table[i-1][entry]; >+ hi = rate_table[i][entry]; >+ x0 = rate_table[i-1][0]; >+ x1 = rate_table[i][0]; >+ silk_rate = (lo*(x1-rate) + hi*(rate-x0))/(x1-x0); >+ } >+ if (!vbr) >+ { >+ /* Tiny boost to SILK for CBR. We should probably tune this better. */ >+ silk_rate += 100; >+ } >+ if (bandwidth==OPUS_BANDWIDTH_SUPERWIDEBAND) >+ silk_rate += 300; >+ return silk_rate; >+} >+ >+/* Returns the equivalent bitrate corresponding to 20 ms frames, >+ complexity 10 VBR operation. */ >+static opus_int32 compute_equiv_rate(opus_int32 bitrate, int channels, >+ int frame_rate, int vbr, int mode, int complexity, int loss) >+{ >+ opus_int32 equiv; >+ equiv = bitrate; >+ /* Take into account overhead from smaller frames. */ >+ equiv -= (40*channels+20)*(frame_rate - 50); >+ /* CBR is about a 8% penalty for both SILK and CELT. */ >+ if (!vbr) >+ equiv -= equiv/12; >+ /* Complexity makes about 10% difference (from 0 to 10) in general. */ >+ equiv = equiv * (90+complexity)/100; >+ if (mode == MODE_SILK_ONLY || mode == MODE_HYBRID) >+ { >+ /* SILK complexity 0-1 uses the non-delayed-decision NSQ, which >+ costs about 20%. */ >+ if (complexity<2) >+ equiv = equiv*4/5; >+ equiv -= equiv*loss/(6*loss + 10); >+ } else if (mode == MODE_CELT_ONLY) { >+ /* CELT complexity 0-4 doesn't have the pitch filter, which costs >+ about 10%. */ >+ if (complexity<5) >+ equiv = equiv*9/10; >+ } else { >+ /* Mode not known yet */ >+ /* Half the SILK loss*/ >+ equiv -= equiv*loss/(12*loss + 20); >+ } >+ return equiv; >+} >+ >+#ifndef DISABLE_FLOAT_API >+ >+static int is_digital_silence(const opus_val16* pcm, int frame_size, int channels, int lsb_depth) >+{ >+ int silence = 0; >+ opus_val32 sample_max = 0; >+#ifdef MLP_TRAINING >+ return 0; >+#endif >+ sample_max = celt_maxabs16(pcm, frame_size*channels); >+ >+#ifdef FIXED_POINT >+ silence = (sample_max == 0); >+ (void)lsb_depth; >+#else >+ silence = (sample_max <= (opus_val16) 1 / (1 << lsb_depth)); >+#endif >+ >+ return silence; >+} >+ >+#ifdef FIXED_POINT >+static opus_val32 compute_frame_energy(const opus_val16 *pcm, int frame_size, int channels, int arch) >+{ >+ int i; >+ opus_val32 sample_max; >+ int max_shift; >+ int shift; >+ opus_val32 energy = 0; >+ int len = frame_size*channels; >+ (void)arch; >+ /* Max amplitude in the signal */ >+ sample_max = celt_maxabs16(pcm, len); >+ >+ /* Compute the right shift required in the MAC to avoid an overflow */ >+ max_shift = celt_ilog2(len); >+ shift = IMAX(0, (celt_ilog2(sample_max) << 1) + max_shift - 28); >+ >+ /* Compute the energy */ >+ for (i=0; i<len; i++) >+ energy += SHR32(MULT16_16(pcm[i], pcm[i]), shift); >+ >+ /* Normalize energy by the frame size and left-shift back to the original position */ >+ energy /= len; >+ energy = SHL32(energy, shift); >+ >+ return energy; >+} >+#else >+static opus_val32 compute_frame_energy(const opus_val16 *pcm, int frame_size, int channels, int arch) >+{ >+ int len = frame_size*channels; >+ return celt_inner_prod(pcm, pcm, len, arch)/len; >+} >+#endif >+ >+/* Decides if DTX should be turned on (=1) or off (=0) */ >+static int decide_dtx_mode(float activity_probability, /* probability that current frame contains speech/music */ >+ int *nb_no_activity_frames, /* number of consecutive frames with no activity */ >+ opus_val32 peak_signal_energy, /* peak energy of desired signal detected so far */ >+ const opus_val16 *pcm, /* input pcm signal */ >+ int frame_size, /* frame size */ >+ int channels, >+ int is_silence, /* only digital silence detected in this frame */ >+ int arch >+ ) >+{ >+ opus_val32 noise_energy; >+ >+ if (!is_silence) >+ { >+ if (activity_probability < DTX_ACTIVITY_THRESHOLD) /* is noise */ >+ { >+ noise_energy = compute_frame_energy(pcm, frame_size, channels, arch); >+ >+ /* but is sufficiently quiet */ >+ is_silence = peak_signal_energy >= (PSEUDO_SNR_THRESHOLD * noise_energy); >+ } >+ } >+ >+ if (is_silence) >+ { >+ /* The number of consecutive DTX frames should be within the allowed bounds */ >+ (*nb_no_activity_frames)++; >+ >+ if (*nb_no_activity_frames > NB_SPEECH_FRAMES_BEFORE_DTX) >+ { >+ if (*nb_no_activity_frames <= (NB_SPEECH_FRAMES_BEFORE_DTX + MAX_CONSECUTIVE_DTX)) >+ /* Valid frame for DTX! */ >+ return 1; >+ else >+ (*nb_no_activity_frames) = NB_SPEECH_FRAMES_BEFORE_DTX; >+ } >+ } else >+ (*nb_no_activity_frames) = 0; >+ >+ return 0; >+} >+ >+#endif >+ >+static opus_int32 encode_multiframe_packet(OpusEncoder *st, >+ const opus_val16 *pcm, >+ int nb_frames, >+ int frame_size, >+ unsigned char *data, >+ opus_int32 out_data_bytes, >+ int to_celt, >+ int lsb_depth, >+ int float_api) >+{ >+ int i; >+ int ret = 0; >+ VARDECL(unsigned char, tmp_data); >+ int bak_mode, bak_bandwidth, bak_channels, bak_to_mono; >+ VARDECL(OpusRepacketizer, rp); >+ int max_header_bytes; >+ opus_int32 bytes_per_frame; >+ opus_int32 cbr_bytes; >+ opus_int32 repacketize_len; >+ int tmp_len; >+ ALLOC_STACK; >+ >+ /* Worst cases: >+ * 2 frames: Code 2 with different compressed sizes >+ * >2 frames: Code 3 VBR */ >+ max_header_bytes = nb_frames == 2 ? 3 : (2+(nb_frames-1)*2); >+ >+ if (st->use_vbr || st->user_bitrate_bps==OPUS_BITRATE_MAX) >+ repacketize_len = out_data_bytes; >+ else { >+ cbr_bytes = 3*st->bitrate_bps/(3*8*st->Fs/(frame_size*nb_frames)); >+ repacketize_len = IMIN(cbr_bytes, out_data_bytes); >+ } >+ bytes_per_frame = IMIN(1276, 1+(repacketize_len-max_header_bytes)/nb_frames); >+ >+ ALLOC(tmp_data, nb_frames*bytes_per_frame, unsigned char); >+ ALLOC(rp, 1, OpusRepacketizer); >+ opus_repacketizer_init(rp); >+ >+ bak_mode = st->user_forced_mode; >+ bak_bandwidth = st->user_bandwidth; >+ bak_channels = st->force_channels; >+ >+ st->user_forced_mode = st->mode; >+ st->user_bandwidth = st->bandwidth; >+ st->force_channels = st->stream_channels; >+ >+ bak_to_mono = st->silk_mode.toMono; >+ if (bak_to_mono) >+ st->force_channels = 1; >+ else >+ st->prev_channels = st->stream_channels; >+ >+ for (i=0;i<nb_frames;i++) >+ { >+ st->silk_mode.toMono = 0; >+ st->nonfinal_frame = i<(nb_frames-1); >+ >+ /* When switching from SILK/Hybrid to CELT, only ask for a switch at the last frame */ >+ if (to_celt && i==nb_frames-1) >+ st->user_forced_mode = MODE_CELT_ONLY; >+ >+ tmp_len = opus_encode_native(st, pcm+i*(st->channels*frame_size), frame_size, >+ tmp_data+i*bytes_per_frame, bytes_per_frame, lsb_depth, NULL, 0, 0, 0, 0, >+ NULL, float_api); >+ >+ if (tmp_len<0) >+ { >+ RESTORE_STACK; >+ return OPUS_INTERNAL_ERROR; >+ } >+ >+ ret = opus_repacketizer_cat(rp, tmp_data+i*bytes_per_frame, tmp_len); >+ >+ if (ret<0) >+ { >+ RESTORE_STACK; >+ return OPUS_INTERNAL_ERROR; >+ } >+ } >+ >+ ret = opus_repacketizer_out_range_impl(rp, 0, nb_frames, data, repacketize_len, 0, !st->use_vbr); >+ >+ if (ret<0) >+ { >+ RESTORE_STACK; >+ return OPUS_INTERNAL_ERROR; >+ } >+ >+ /* Discard configs that were forced locally for the purpose of repacketization */ >+ st->user_forced_mode = bak_mode; >+ st->user_bandwidth = bak_bandwidth; >+ st->force_channels = bak_channels; >+ st->silk_mode.toMono = bak_to_mono; >+ >+ RESTORE_STACK; >+ return ret; >+} >+ >+static int compute_redundancy_bytes(opus_int32 max_data_bytes, opus_int32 bitrate_bps, int frame_rate, int channels) >+{ >+ int redundancy_bytes_cap; >+ int redundancy_bytes; >+ opus_int32 redundancy_rate; >+ int base_bits; >+ opus_int32 available_bits; >+ base_bits = (40*channels+20); >+ >+ /* Equivalent rate for 5 ms frames. */ >+ redundancy_rate = bitrate_bps + base_bits*(200 - frame_rate); >+ /* For VBR, further increase the bitrate if we can afford it. It's pretty short >+ and we'll avoid artefacts. */ >+ redundancy_rate = 3*redundancy_rate/2; >+ redundancy_bytes = redundancy_rate/1600; >+ >+ /* Compute the max rate we can use given CBR or VBR with cap. */ >+ available_bits = max_data_bytes*8 - 2*base_bits; >+ redundancy_bytes_cap = (available_bits*240/(240+48000/frame_rate) + base_bits)/8; >+ redundancy_bytes = IMIN(redundancy_bytes, redundancy_bytes_cap); >+ /* It we can't get enough bits for redundancy to be worth it, rely on the decoder PLC. */ >+ if (redundancy_bytes > 4 + 8*channels) >+ redundancy_bytes = IMIN(257, redundancy_bytes); >+ else >+ redundancy_bytes = 0; >+ return redundancy_bytes; >+} >+ > opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_size, > unsigned char *data, opus_int32 out_data_bytes, int lsb_depth, > const void *analysis_pcm, opus_int32 analysis_size, int c1, int c2, >@@ -971,6 +1107,7 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ > AnalysisInfo analysis_info; > int analysis_read_pos_bak=-1; > int analysis_read_subframe_bak=-1; >+ int is_silence = 0; > #endif > VARDECL(opus_val16, tmp_prefill); > >@@ -979,15 +1116,19 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ > max_data_bytes = IMIN(1276, out_data_bytes); > > st->rangeFinal = 0; >- if ((!st->variable_duration && 400*frame_size != st->Fs && 200*frame_size != st->Fs && 100*frame_size != st->Fs && >- 50*frame_size != st->Fs && 25*frame_size != st->Fs && 50*frame_size != 3*st->Fs) >- || (400*frame_size < st->Fs) >- || max_data_bytes<=0 >- ) >+ if (frame_size <= 0 || max_data_bytes <= 0) > { > RESTORE_STACK; > return OPUS_BAD_ARG; > } >+ >+ /* Cannot encode 100 ms in 1 byte */ >+ if (max_data_bytes==1 && st->Fs==(frame_size*10)) >+ { >+ RESTORE_STACK; >+ return OPUS_BUFFER_TOO_SMALL; >+ } >+ > silk_enc = (char*)st+st->silk_enc_offset; > celt_enc = (CELTEncoder*)((char*)st+st->celt_enc_offset); > if (st->application == OPUS_APPLICATION_RESTRICTED_LOWDELAY) >@@ -1001,25 +1142,42 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ > #ifndef DISABLE_FLOAT_API > analysis_info.valid = 0; > #ifdef FIXED_POINT >- if (st->silk_mode.complexity >= 10 && st->Fs==48000) >+ if (st->silk_mode.complexity >= 10 && st->Fs>=16000) > #else >- if (st->silk_mode.complexity >= 7 && st->Fs==48000) >+ if (st->silk_mode.complexity >= 7 && st->Fs>=16000) > #endif > { >- analysis_read_pos_bak = st->analysis.read_pos; >- analysis_read_subframe_bak = st->analysis.read_subframe; >- run_analysis(&st->analysis, celt_mode, analysis_pcm, analysis_size, frame_size, >- c1, c2, analysis_channels, st->Fs, >- lsb_depth, downmix, &analysis_info); >+ if (is_digital_silence(pcm, frame_size, st->channels, lsb_depth)) >+ { >+ is_silence = 1; >+ } else { >+ analysis_read_pos_bak = st->analysis.read_pos; >+ analysis_read_subframe_bak = st->analysis.read_subframe; >+ run_analysis(&st->analysis, celt_mode, analysis_pcm, analysis_size, frame_size, >+ c1, c2, analysis_channels, st->Fs, >+ lsb_depth, downmix, &analysis_info); >+ } >+ >+ /* Track the peak signal energy */ >+ if (!is_silence && analysis_info.activity_probability > DTX_ACTIVITY_THRESHOLD) >+ st->peak_signal_energy = MAX32(MULT16_32_Q15(QCONST16(0.999f, 15), st->peak_signal_energy), >+ compute_frame_energy(pcm, frame_size, st->channels, st->arch)); > } > #else > (void)analysis_pcm; > (void)analysis_size; >+ (void)c1; >+ (void)c2; >+ (void)analysis_channels; >+ (void)downmix; > #endif > >- st->voice_ratio = -1; >- > #ifndef DISABLE_FLOAT_API >+ /* Reset voice_ratio if this frame is not silent or if analysis is disabled. >+ * Otherwise, preserve voice_ratio from the last non-silent frame */ >+ if (!is_silence) >+ st->voice_ratio = -1; >+ > st->detected_bandwidth = 0; > if (analysis_info.valid) > { >@@ -1039,6 +1197,8 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ > else > st->detected_bandwidth = OPUS_BANDWIDTH_FULLBAND; > } >+#else >+ st->voice_ratio = -1; > #endif > > if (st->channels==2 && st->force_channels!=1) >@@ -1052,12 +1212,13 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ > if (!st->use_vbr) > { > int cbrBytes; >- /* Multiply by 3 to make sure the division is exact. */ >- int frame_rate3 = 3*st->Fs/frame_size; >+ /* Multiply by 12 to make sure the division is exact. */ >+ int frame_rate12 = 12*st->Fs/frame_size; > /* We need to make sure that "int" values always fit in 16 bits. */ >- cbrBytes = IMIN( (3*st->bitrate_bps/8 + frame_rate3/2)/frame_rate3, max_data_bytes); >- st->bitrate_bps = cbrBytes*(opus_int32)frame_rate3*8/3; >- max_data_bytes = cbrBytes; >+ cbrBytes = IMIN( (12*st->bitrate_bps/8 + frame_rate12/2)/frame_rate12, max_data_bytes); >+ st->bitrate_bps = cbrBytes*(opus_int32)frame_rate12*8/12; >+ /* Make sure we provide at least one byte to avoid failing. */ >+ max_data_bytes = IMAX(1, cbrBytes); > } > if (max_data_bytes<3 || st->bitrate_bps < 3*frame_rate*8 > || (frame_rate<50 && (max_data_bytes*frame_rate<300 || st->bitrate_bps < 2400))) >@@ -1065,25 +1226,63 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ > /*If the space is too low to do something useful, emit 'PLC' frames.*/ > int tocmode = st->mode; > int bw = st->bandwidth == 0 ? OPUS_BANDWIDTH_NARROWBAND : st->bandwidth; >+ int packet_code = 0; >+ int num_multiframes = 0; >+ > if (tocmode==0) > tocmode = MODE_SILK_ONLY; > if (frame_rate>100) > tocmode = MODE_CELT_ONLY; >- if (frame_rate < 50) >- tocmode = MODE_SILK_ONLY; >+ /* 40 ms -> 2 x 20 ms if in CELT_ONLY or HYBRID mode */ >+ if (frame_rate==25 && tocmode!=MODE_SILK_ONLY) >+ { >+ frame_rate = 50; >+ packet_code = 1; >+ } >+ >+ /* >= 60 ms frames */ >+ if (frame_rate<=16) >+ { >+ /* 1 x 60 ms, 2 x 40 ms, 2 x 60 ms */ >+ if (out_data_bytes==1 || (tocmode==MODE_SILK_ONLY && frame_rate!=10)) >+ { >+ tocmode = MODE_SILK_ONLY; >+ >+ packet_code = frame_rate <= 12; >+ frame_rate = frame_rate == 12 ? 25 : 16; >+ } >+ else >+ { >+ num_multiframes = 50/frame_rate; >+ frame_rate = 50; >+ packet_code = 3; >+ } >+ } >+ > if(tocmode==MODE_SILK_ONLY&&bw>OPUS_BANDWIDTH_WIDEBAND) > bw=OPUS_BANDWIDTH_WIDEBAND; > else if (tocmode==MODE_CELT_ONLY&&bw==OPUS_BANDWIDTH_MEDIUMBAND) > bw=OPUS_BANDWIDTH_NARROWBAND; > else if (tocmode==MODE_HYBRID&&bw<=OPUS_BANDWIDTH_SUPERWIDEBAND) > bw=OPUS_BANDWIDTH_SUPERWIDEBAND; >+ > data[0] = gen_toc(tocmode, frame_rate, bw, st->stream_channels); >- ret = 1; >+ data[0] |= packet_code; >+ >+ ret = packet_code <= 1 ? 1 : 2; >+ >+ max_data_bytes = IMAX(max_data_bytes, ret); >+ >+ if (packet_code==3) >+ data[1] = num_multiframes; >+ > if (!st->use_vbr) > { > ret = opus_packet_pad(data, ret, max_data_bytes); > if (ret == OPUS_OK) > ret = max_data_bytes; >+ else >+ ret = OPUS_INTERNAL_ERROR; > } > RESTORE_STACK; > return ret; >@@ -1091,7 +1290,8 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ > max_rate = frame_rate*max_data_bytes*8; > > /* Equivalent 20-ms rate for mode/channel/bandwidth decisions */ >- equiv_rate = st->bitrate_bps - (40*st->channels+20)*(st->Fs/frame_size - 50); >+ equiv_rate = compute_equiv_rate(st->bitrate_bps, st->channels, st->Fs/frame_size, >+ st->use_vbr, 0, st->silk_mode.complexity, st->silk_mode.packetLossPercentage); > > if (st->signal_type == OPUS_SIGNAL_VOICE) > voice_est = 127; >@@ -1132,7 +1332,9 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ > } > #endif > } >- equiv_rate = st->bitrate_bps - (40*st->stream_channels+20)*(st->Fs/frame_size - 50); >+ /* Update equivalent rate for channels decision. */ >+ equiv_rate = compute_equiv_rate(st->bitrate_bps, st->stream_channels, st->Fs/frame_size, >+ st->use_vbr, 0, st->silk_mode.complexity, st->silk_mode.packetLossPercentage); > > /* Mode selection depending on application and signal type */ > if (st->application == OPUS_APPLICATION_RESTRICTED_LOWDELAY) >@@ -1181,10 +1383,21 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ > /* When FEC is enabled and there's enough packet loss, use SILK */ > if (st->silk_mode.useInBandFEC && st->silk_mode.packetLossPercentage > (128-voice_est)>>4) > st->mode = MODE_SILK_ONLY; >- /* When encoding voice and DTX is enabled, set the encoder to SILK mode (at least for now) */ >+ /* When encoding voice and DTX is enabled but the generalized DTX cannot be used, >+ because of complexity and sampling frequency settings, switch to SILK DTX and >+ set the encoder to SILK mode */ >+#ifndef DISABLE_FLOAT_API >+ st->silk_mode.useDTX = st->use_dtx && !(analysis_info.valid || is_silence); >+#else >+ st->silk_mode.useDTX = st->use_dtx; >+#endif > if (st->silk_mode.useDTX && voice_est > 100) > st->mode = MODE_SILK_ONLY; > #endif >+ >+ /* If max_data_bytes represents less than 6 kb/s, switch to CELT-only mode */ >+ if (max_data_bytes < (frame_rate > 50 ? 9000 : 6000)*frame_size / (st->Fs * 8)) >+ st->mode = MODE_CELT_ONLY; > } else { > st->mode = st->user_forced_mode; > } >@@ -1194,19 +1407,6 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ > st->mode = MODE_CELT_ONLY; > if (st->lfe) > st->mode = MODE_CELT_ONLY; >- /* If max_data_bytes represents less than 8 kb/s, switch to CELT-only mode */ >- if (max_data_bytes < (frame_rate > 50 ? 12000 : 8000)*frame_size / (st->Fs * 8)) >- st->mode = MODE_CELT_ONLY; >- >- if (st->stream_channels == 1 && st->prev_channels ==2 && st->silk_mode.toMono==0 >- && st->mode != MODE_CELT_ONLY && st->prev_mode != MODE_CELT_ONLY) >- { >- /* Delay stereo->mono transition by two frames so that SILK can do a smooth downmix */ >- st->silk_mode.toMono = 1; >- st->stream_channels = 2; >- } else { >- st->silk_mode.toMono = 0; >- } > > if (st->prev_mode > 0 && > ((st->mode != MODE_CELT_ONLY && st->prev_mode == MODE_CELT_ONLY) || >@@ -1226,24 +1426,23 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ > } > } > } >- /* For the first frame at a new SILK bandwidth */ >- if (st->silk_bw_switch) >- { >- redundancy = 1; >- celt_to_silk = 1; >- st->silk_bw_switch = 0; >- prefill=1; >- } > >- if (redundancy) >+ /* When encoding multiframes, we can ask for a switch to CELT only in the last frame. This switch >+ * is processed above as the requested mode shouldn't interrupt stereo->mono transition. */ >+ if (st->stream_channels == 1 && st->prev_channels ==2 && st->silk_mode.toMono==0 >+ && st->mode != MODE_CELT_ONLY && st->prev_mode != MODE_CELT_ONLY) > { >- /* Fair share of the max size allowed */ >- redundancy_bytes = IMIN(257, max_data_bytes*(opus_int32)(st->Fs/200)/(frame_size+st->Fs/200)); >- /* For VBR, target the actual bitrate (subject to the limit above) */ >- if (st->use_vbr) >- redundancy_bytes = IMIN(redundancy_bytes, st->bitrate_bps/1600); >+ /* Delay stereo->mono transition by two frames so that SILK can do a smooth downmix */ >+ st->silk_mode.toMono = 1; >+ st->stream_channels = 2; >+ } else { >+ st->silk_mode.toMono = 0; > } > >+ /* Update equivalent rate with mode decision. */ >+ equiv_rate = compute_equiv_rate(st->bitrate_bps, st->stream_channels, st->Fs/frame_size, >+ st->use_vbr, st->mode, st->silk_mode.complexity, st->silk_mode.packetLossPercentage); >+ > if (st->mode != MODE_CELT_ONLY && st->prev_mode == MODE_CELT_ONLY) > { > silk_EncControlStruct dummy; >@@ -1257,17 +1456,7 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ > const opus_int32 *voice_bandwidth_thresholds, *music_bandwidth_thresholds; > opus_int32 bandwidth_thresholds[8]; > int bandwidth = OPUS_BANDWIDTH_FULLBAND; >- opus_int32 equiv_rate2; > >- equiv_rate2 = equiv_rate; >- if (st->mode != MODE_CELT_ONLY) >- { >- /* Adjust the threshold +/- 10% depending on complexity */ >- equiv_rate2 = equiv_rate2 * (45+st->silk_mode.complexity)/50; >- /* CBR is less efficient by ~1 kb/s */ >- if (!st->use_vbr) >- equiv_rate2 -= 1000; >- } > if (st->channels==2 && st->force_channels!=1) > { > voice_bandwidth_thresholds = stereo_voice_bandwidth_thresholds; >@@ -1288,15 +1477,15 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ > hysteresis = bandwidth_thresholds[2*(bandwidth-OPUS_BANDWIDTH_MEDIUMBAND)+1]; > if (!st->first) > { >- if (st->bandwidth >= bandwidth) >+ if (st->auto_bandwidth >= bandwidth) > threshold -= hysteresis; > else > threshold += hysteresis; > } >- if (equiv_rate2 >= threshold) >+ if (equiv_rate >= threshold) > break; > } while (--bandwidth>OPUS_BANDWIDTH_NARROWBAND); >- st->bandwidth = bandwidth; >+ st->bandwidth = st->auto_bandwidth = bandwidth; > /* Prevents any transition to SWB/FB until the SILK layer has fully > switched to WB mode and turned the variable LP filter off */ > if (!st->first && st->mode != MODE_CELT_ONLY && !st->silk_mode.inWBmodeWithoutVariableLP && st->bandwidth > OPUS_BANDWIDTH_WIDEBAND) >@@ -1349,6 +1538,8 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ > st->bandwidth = IMIN(st->bandwidth, st->detected_bandwidth); > } > #endif >+ st->silk_mode.LBRR_coded = decide_fec(st->silk_mode.useInBandFEC, st->silk_mode.packetLossPercentage, >+ st->silk_mode.LBRR_coded, st->mode, &st->bandwidth, equiv_rate); > celt_encoder_ctl(celt_enc, OPUS_SET_LSB_DEPTH(lsb_depth)); > > /* CELT mode doesn't support mediumband, use wideband instead */ >@@ -1357,15 +1548,34 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ > if (st->lfe) > st->bandwidth = OPUS_BANDWIDTH_NARROWBAND; > >- /* Can't support higher than wideband for >20 ms frames */ >- if (frame_size > st->Fs/50 && (st->mode == MODE_CELT_ONLY || st->bandwidth > OPUS_BANDWIDTH_WIDEBAND)) >+ curr_bandwidth = st->bandwidth; >+ >+ /* Chooses the appropriate mode for speech >+ *NEVER* switch to/from CELT-only mode here as this will invalidate some assumptions */ >+ if (st->mode == MODE_SILK_ONLY && curr_bandwidth > OPUS_BANDWIDTH_WIDEBAND) >+ st->mode = MODE_HYBRID; >+ if (st->mode == MODE_HYBRID && curr_bandwidth <= OPUS_BANDWIDTH_WIDEBAND) >+ st->mode = MODE_SILK_ONLY; >+ >+ /* Can't support higher than >60 ms frames, and >20 ms when in Hybrid or CELT-only modes */ >+ if ((frame_size > st->Fs/50 && (st->mode != MODE_SILK_ONLY)) || frame_size > 3*st->Fs/50) > { >- VARDECL(unsigned char, tmp_data); >+ int enc_frame_size; > int nb_frames; >- int bak_mode, bak_bandwidth, bak_channels, bak_to_mono; >- VARDECL(OpusRepacketizer, rp); >- opus_int32 bytes_per_frame; >- opus_int32 repacketize_len; >+ >+ if (st->mode == MODE_SILK_ONLY) >+ { >+ if (frame_size == 2*st->Fs/25) /* 80 ms -> 2x 40 ms */ >+ enc_frame_size = st->Fs/25; >+ else if (frame_size == 3*st->Fs/25) /* 120 ms -> 2x 60 ms */ >+ enc_frame_size = 3*st->Fs/50; >+ else /* 100 ms -> 5x 20 ms */ >+ enc_frame_size = st->Fs/50; >+ } >+ else >+ enc_frame_size = st->Fs/50; >+ >+ nb_frames = frame_size/enc_frame_size; > > #ifndef DISABLE_FLOAT_API > if (analysis_read_pos_bak!= -1) >@@ -1375,74 +1585,33 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ > } > #endif > >- nb_frames = frame_size > st->Fs/25 ? 3 : 2; >- bytes_per_frame = IMIN(1276,(out_data_bytes-3)/nb_frames); >- >- ALLOC(tmp_data, nb_frames*bytes_per_frame, unsigned char); >- >- ALLOC(rp, 1, OpusRepacketizer); >- opus_repacketizer_init(rp); >- >- bak_mode = st->user_forced_mode; >- bak_bandwidth = st->user_bandwidth; >- bak_channels = st->force_channels; >+ ret = encode_multiframe_packet(st, pcm, nb_frames, enc_frame_size, data, >+ out_data_bytes, to_celt, lsb_depth, float_api); > >- st->user_forced_mode = st->mode; >- st->user_bandwidth = st->bandwidth; >- st->force_channels = st->stream_channels; >- bak_to_mono = st->silk_mode.toMono; >- >- if (bak_to_mono) >- st->force_channels = 1; >- else >- st->prev_channels = st->stream_channels; >- for (i=0;i<nb_frames;i++) >- { >- int tmp_len; >- st->silk_mode.toMono = 0; >- /* When switching from SILK/Hybrid to CELT, only ask for a switch at the last frame */ >- if (to_celt && i==nb_frames-1) >- st->user_forced_mode = MODE_CELT_ONLY; >- tmp_len = opus_encode_native(st, pcm+i*(st->channels*st->Fs/50), st->Fs/50, >- tmp_data+i*bytes_per_frame, bytes_per_frame, lsb_depth, >- NULL, 0, c1, c2, analysis_channels, downmix, float_api); >- if (tmp_len<0) >- { >- RESTORE_STACK; >- return OPUS_INTERNAL_ERROR; >- } >- ret = opus_repacketizer_cat(rp, tmp_data+i*bytes_per_frame, tmp_len); >- if (ret<0) >- { >- RESTORE_STACK; >- return OPUS_INTERNAL_ERROR; >- } >- } >- if (st->use_vbr) >- repacketize_len = out_data_bytes; >- else >- repacketize_len = IMIN(3*st->bitrate_bps/(3*8*50/nb_frames), out_data_bytes); >- ret = opus_repacketizer_out_range_impl(rp, 0, nb_frames, data, repacketize_len, 0, !st->use_vbr); >- if (ret<0) >- { >- RESTORE_STACK; >- return OPUS_INTERNAL_ERROR; >- } >- st->user_forced_mode = bak_mode; >- st->user_bandwidth = bak_bandwidth; >- st->force_channels = bak_channels; >- st->silk_mode.toMono = bak_to_mono; > RESTORE_STACK; > return ret; > } >- curr_bandwidth = st->bandwidth; > >- /* Chooses the appropriate mode for speech >- *NEVER* switch to/from CELT-only mode here as this will invalidate some assumptions */ >- if (st->mode == MODE_SILK_ONLY && curr_bandwidth > OPUS_BANDWIDTH_WIDEBAND) >- st->mode = MODE_HYBRID; >- if (st->mode == MODE_HYBRID && curr_bandwidth <= OPUS_BANDWIDTH_WIDEBAND) >- st->mode = MODE_SILK_ONLY; >+ /* For the first frame at a new SILK bandwidth */ >+ if (st->silk_bw_switch) >+ { >+ redundancy = 1; >+ celt_to_silk = 1; >+ st->silk_bw_switch = 0; >+ prefill=1; >+ } >+ >+ /* If we decided to go with CELT, make sure redundancy is off, no matter what >+ we decided earlier. */ >+ if (st->mode == MODE_CELT_ONLY) >+ redundancy = 0; >+ >+ if (redundancy) >+ { >+ redundancy_bytes = compute_redundancy_bytes(max_data_bytes, st->bitrate_bps, frame_rate, st->stream_channels); >+ if (redundancy_bytes == 0) >+ redundancy = 0; >+ } > > /* printf("%d %d %d %d\n", st->bitrate_bps, st->stream_channels, st->mode, curr_bandwidth); */ > bytes_target = IMIN(max_data_bytes-redundancy_bytes, st->bitrate_bps * frame_size / (st->Fs * 8)) - 1; >@@ -1467,7 +1636,7 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ > > if (st->application == OPUS_APPLICATION_VOIP) > { >- hp_cutoff(pcm, cutoff_Hz, &pcm_buf[total_buffer*st->channels], st->hp_mem, frame_size, st->channels, st->Fs); >+ hp_cutoff(pcm, cutoff_Hz, &pcm_buf[total_buffer*st->channels], st->hp_mem, frame_size, st->channels, st->Fs, st->arch); > } else { > dc_reject(pcm, 3, &pcm_buf[total_buffer*st->channels], st->hp_mem, frame_size, st->channels, st->Fs); > } >@@ -1492,6 +1661,7 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ > if (st->mode != MODE_CELT_ONLY) > { > opus_int32 total_bitRate, celt_rate; >+ opus_int activity; > #ifdef FIXED_POINT > const opus_int16 *pcm_silk; > #else >@@ -1499,30 +1669,31 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ > ALLOC(pcm_silk, st->channels*frame_size, opus_int16); > #endif > >+ activity = VAD_NO_DECISION; >+#ifndef DISABLE_FLOAT_API >+ if( analysis_info.valid ) { >+ /* Inform SILK about the Opus VAD decision */ >+ activity = ( analysis_info.activity_probability >= DTX_ACTIVITY_THRESHOLD ); >+ } >+#endif >+ > /* Distribute bits between SILK and CELT */ > total_bitRate = 8 * bytes_target * frame_rate; > if( st->mode == MODE_HYBRID ) { >- int HB_gain_ref; > /* Base rate for SILK */ >- st->silk_mode.bitRate = st->stream_channels * ( 5000 + 1000 * ( st->Fs == 100 * frame_size ) ); >- if( curr_bandwidth == OPUS_BANDWIDTH_SUPERWIDEBAND ) { >- /* SILK gets 2/3 of the remaining bits */ >- st->silk_mode.bitRate += ( total_bitRate - st->silk_mode.bitRate ) * 2 / 3; >- } else { /* FULLBAND */ >- /* SILK gets 3/5 of the remaining bits */ >- st->silk_mode.bitRate += ( total_bitRate - st->silk_mode.bitRate ) * 3 / 5; >- } >- /* Don't let SILK use more than 80% */ >- if( st->silk_mode.bitRate > total_bitRate * 4/5 ) { >- st->silk_mode.bitRate = total_bitRate * 4/5; >- } >+ st->silk_mode.bitRate = compute_silk_rate_for_hybrid(total_bitRate, >+ curr_bandwidth, st->Fs == 50 * frame_size, st->use_vbr, st->silk_mode.LBRR_coded); > if (!st->energy_masking) > { > /* Increasingly attenuate high band when it gets allocated fewer bits */ > celt_rate = total_bitRate - st->silk_mode.bitRate; >- HB_gain_ref = (curr_bandwidth == OPUS_BANDWIDTH_SUPERWIDEBAND) ? 3000 : 3600; >- HB_gain = SHL32((opus_val32)celt_rate, 9) / SHR32((opus_val32)celt_rate + st->stream_channels * HB_gain_ref, 6); >- HB_gain = HB_gain < (opus_val32)Q15ONE*6/7 ? HB_gain + Q15ONE/7 : Q15ONE; >+ HB_gain = Q15ONE - SHR32(celt_exp2(-celt_rate * QCONST16(1.f/1024, 10)), 1); >+#ifndef FIXED_POINT >+ /* Sanity check of high band gain */ >+ if (celt_isnan(HB_gain)) { >+ HB_gain = Q15ONE; >+ } >+#endif > } > } else { > /* SILK gets all bits */ >@@ -1569,7 +1740,6 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ > st->silk_mode.bitRate += 3*rate_offset/5; > else > st->silk_mode.bitRate += rate_offset; >- bytes_target += rate_offset * frame_size / (8 * st->Fs); > } > > st->silk_mode.payloadSize_ms = 1000 * frame_size / st->Fs; >@@ -1590,40 +1760,52 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ > st->silk_mode.minInternalSampleRate = 8000; > } > >+ st->silk_mode.maxInternalSampleRate = 16000; > if (st->mode == MODE_SILK_ONLY) > { > opus_int32 effective_max_rate = max_rate; >- st->silk_mode.maxInternalSampleRate = 16000; > if (frame_rate > 50) > effective_max_rate = effective_max_rate*2/3; >- if (effective_max_rate < 13000) >+ if (effective_max_rate < 8000) > { > st->silk_mode.maxInternalSampleRate = 12000; > st->silk_mode.desiredInternalSampleRate = IMIN(12000, st->silk_mode.desiredInternalSampleRate); > } >- if (effective_max_rate < 9600) >+ if (effective_max_rate < 7000) > { > st->silk_mode.maxInternalSampleRate = 8000; > st->silk_mode.desiredInternalSampleRate = IMIN(8000, st->silk_mode.desiredInternalSampleRate); > } >- } else { >- st->silk_mode.maxInternalSampleRate = 16000; > } > > st->silk_mode.useCBR = !st->use_vbr; > > /* Call SILK encoder for the low band */ >- nBytes = IMIN(1275, max_data_bytes-1-redundancy_bytes); > >- st->silk_mode.maxBits = nBytes*8; >- /* Only allow up to 90% of the bits for hybrid mode*/ >- if (st->mode == MODE_HYBRID) >- st->silk_mode.maxBits = (opus_int32)st->silk_mode.maxBits*9/10; >+ /* Max bits for SILK, counting ToC, redundancy bytes, and optionally redundancy. */ >+ st->silk_mode.maxBits = (max_data_bytes-1)*8; >+ if (redundancy && redundancy_bytes >= 2) >+ { >+ /* Counting 1 bit for redundancy position and 20 bits for flag+size (only for hybrid). */ >+ st->silk_mode.maxBits -= redundancy_bytes*8 + 1; >+ if (st->mode == MODE_HYBRID) >+ st->silk_mode.maxBits -= 20; >+ } > if (st->silk_mode.useCBR) > { >- st->silk_mode.maxBits = (st->silk_mode.bitRate * frame_size / (st->Fs * 8))*8; >- /* Reduce the initial target to make it easier to reach the CBR rate */ >- st->silk_mode.bitRate = IMAX(1, st->silk_mode.bitRate-2000); >+ if (st->mode == MODE_HYBRID) >+ { >+ st->silk_mode.maxBits = IMIN(st->silk_mode.maxBits, st->silk_mode.bitRate * frame_size / st->Fs); >+ } >+ } else { >+ /* Constrained VBR. */ >+ if (st->mode == MODE_HYBRID) >+ { >+ /* Compute SILK bitrate corresponding to the max total bits available */ >+ opus_int32 maxBitRate = compute_silk_rate_for_hybrid(st->silk_mode.maxBits*st->Fs / frame_size, >+ curr_bandwidth, st->Fs == 50 * frame_size, st->use_vbr, st->silk_mode.LBRR_coded); >+ st->silk_mode.maxBits = maxBitRate * frame_size / st->Fs; >+ } > } > > if (prefill) >@@ -1646,7 +1828,7 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ > for (i=0;i<st->encoder_buffer*st->channels;i++) > pcm_silk[i] = FLOAT2INT16(st->delay_buffer[i]); > #endif >- silk_Encode( silk_enc, &st->silk_mode, pcm_silk, st->encoder_buffer, NULL, &zero, 1 ); >+ silk_Encode( silk_enc, &st->silk_mode, pcm_silk, st->encoder_buffer, NULL, &zero, 1, activity ); > } > > #ifdef FIXED_POINT >@@ -1655,20 +1837,14 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ > for (i=0;i<frame_size*st->channels;i++) > pcm_silk[i] = FLOAT2INT16(pcm_buf[total_buffer*st->channels + i]); > #endif >- ret = silk_Encode( silk_enc, &st->silk_mode, pcm_silk, frame_size, &enc, &nBytes, 0 ); >+ ret = silk_Encode( silk_enc, &st->silk_mode, pcm_silk, frame_size, &enc, &nBytes, 0, activity ); > if( ret ) { > /*fprintf (stderr, "SILK encode error: %d\n", ret);*/ > /* Handle error */ > RESTORE_STACK; > return OPUS_INTERNAL_ERROR; > } >- if (nBytes==0) >- { >- st->rangeFinal = 0; >- data[-1] = gen_toc(st->mode, st->Fs/frame_size, curr_bandwidth, st->stream_channels); >- RESTORE_STACK; >- return 1; >- } >+ > /* Extract SILK internal bandwidth for signaling in first byte */ > if( st->mode == MODE_SILK_ONLY ) { > if( st->silk_mode.internalSampleRate == 8000 ) { >@@ -1682,11 +1858,21 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ > silk_assert( st->silk_mode.internalSampleRate == 16000 ); > } > >- st->silk_mode.opusCanSwitch = st->silk_mode.switchReady; >+ st->silk_mode.opusCanSwitch = st->silk_mode.switchReady && !st->nonfinal_frame; >+ >+ if (nBytes==0) >+ { >+ st->rangeFinal = 0; >+ data[-1] = gen_toc(st->mode, st->Fs/frame_size, curr_bandwidth, st->stream_channels); >+ RESTORE_STACK; >+ return 1; >+ } >+ > /* FIXME: How do we allocate the redundancy for CBR? */ > if (st->silk_mode.opusCanSwitch) > { >- redundancy = 1; >+ redundancy_bytes = compute_redundancy_bytes(max_data_bytes, st->bitrate_bps, frame_rate, st->stream_channels); >+ redundancy = (redundancy_bytes != 0); > celt_to_silk = 0; > st->silk_bw_switch = 1; > } >@@ -1727,40 +1913,18 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ > > if (st->mode == MODE_HYBRID) > { >- int len; >- >- len = (ec_tell(&enc)+7)>>3; >- if (redundancy) >- len += st->mode == MODE_HYBRID ? 3 : 1; > if( st->use_vbr ) { >- nb_compr_bytes = len + bytes_target - (st->silk_mode.bitRate * frame_size) / (8 * st->Fs); >- } else { >- /* check if SILK used up too much */ >- nb_compr_bytes = len > bytes_target ? len : bytes_target; >+ celt_encoder_ctl(celt_enc, OPUS_SET_BITRATE(st->bitrate_bps-st->silk_mode.bitRate)); >+ celt_encoder_ctl(celt_enc, OPUS_SET_VBR_CONSTRAINT(0)); > } > } else { > if (st->use_vbr) > { >- opus_int32 bonus=0; >-#ifndef DISABLE_FLOAT_API >- if (st->variable_duration==OPUS_FRAMESIZE_VARIABLE && frame_size != st->Fs/50) >- { >- bonus = (60*st->stream_channels+40)*(st->Fs/frame_size-50); >- if (analysis_info.valid) >- bonus = (opus_int32)(bonus*(1.f+.5f*analysis_info.tonality)); >- } >-#endif > celt_encoder_ctl(celt_enc, OPUS_SET_VBR(1)); > celt_encoder_ctl(celt_enc, OPUS_SET_VBR_CONSTRAINT(st->vbr_constraint)); >- celt_encoder_ctl(celt_enc, OPUS_SET_BITRATE(st->bitrate_bps+bonus)); >- nb_compr_bytes = max_data_bytes-1-redundancy_bytes; >- } else { >- nb_compr_bytes = bytes_target; >+ celt_encoder_ctl(celt_enc, OPUS_SET_BITRATE(st->bitrate_bps)); > } > } >- >- } else { >- nb_compr_bytes = 0; > } > > ALLOC(tmp_prefill, st->channels*st->Fs/400, opus_val16); >@@ -1786,7 +1950,7 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ > } > st->prev_HB_gain = HB_gain; > if (st->mode != MODE_HYBRID || st->stream_channels==1) >- st->silk_mode.stereoWidth_Q14 = IMIN((1<<14),2*IMAX(0,equiv_rate-30000)); >+ st->silk_mode.stereoWidth_Q14 = IMIN((1<<14),2*IMAX(0,equiv_rate-24000)); > if( !st->energy_masking && st->channels == 2 ) { > /* Apply stereo width reduction (at low bitrates) */ > if( st->hybrid_stereo_width_Q14 < (1 << 14) || st->silk_mode.stereoWidth_Q14 < (1 << 14) ) { >@@ -1809,19 +1973,23 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ > if ( st->mode != MODE_CELT_ONLY && ec_tell(&enc)+17+20*(st->mode == MODE_HYBRID) <= 8*(max_data_bytes-1)) > { > /* For SILK mode, the redundancy is inferred from the length */ >- if (st->mode == MODE_HYBRID && (redundancy || ec_tell(&enc)+37 <= 8*nb_compr_bytes)) >+ if (st->mode == MODE_HYBRID) > ec_enc_bit_logp(&enc, redundancy, 12); > if (redundancy) > { > int max_redundancy; > ec_enc_bit_logp(&enc, celt_to_silk, 1); > if (st->mode == MODE_HYBRID) >- max_redundancy = (max_data_bytes-1)-nb_compr_bytes; >+ { >+ /* Reserve the 8 bits needed for the redundancy length, >+ and at least a few bits for CELT if possible */ >+ max_redundancy = (max_data_bytes-1)-((ec_tell(&enc)+8+3+7)>>3); >+ } > else > max_redundancy = (max_data_bytes-1)-((ec_tell(&enc)+7)>>3); > /* Target the same bit-rate for redundancy as for the rest, > up to a max of 257 bytes */ >- redundancy_bytes = IMIN(max_redundancy, st->bitrate_bps/1600); >+ redundancy_bytes = IMIN(max_redundancy, redundancy_bytes); > redundancy_bytes = IMIN(257, IMAX(2, redundancy_bytes)); > if (st->mode == MODE_HYBRID) > ec_enc_uint(&enc, redundancy_bytes-2, 256); >@@ -1843,7 +2011,7 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ > ec_enc_done(&enc); > nb_compr_bytes = ret; > } else { >- nb_compr_bytes = IMIN((max_data_bytes-1)-redundancy_bytes, nb_compr_bytes); >+ nb_compr_bytes = (max_data_bytes-1)-redundancy_bytes; > ec_enc_shrink(&enc, nb_compr_bytes); > } > >@@ -1851,6 +2019,14 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ > if (redundancy || st->mode != MODE_SILK_ONLY) > celt_encoder_ctl(celt_enc, CELT_SET_ANALYSIS(&analysis_info)); > #endif >+ if (st->mode == MODE_HYBRID) { >+ SILKInfo info; >+ info.signalType = st->silk_mode.signalType; >+ info.offset = st->silk_mode.offset; >+ celt_encoder_ctl(celt_enc, CELT_SET_SILK_INFO(&info)); >+ } else { >+ celt_encoder_ctl(celt_enc, CELT_SET_SILK_INFO((SILKInfo*)NULL)); >+ } > > /* 5 ms redundant frame for CELT->SILK */ > if (redundancy && celt_to_silk) >@@ -1858,6 +2034,7 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ > int err; > celt_encoder_ctl(celt_enc, CELT_SET_START_BAND(0)); > celt_encoder_ctl(celt_enc, OPUS_SET_VBR(0)); >+ celt_encoder_ctl(celt_enc, OPUS_SET_BITRATE(OPUS_BITRATE_MAX)); > err = celt_encode_with_ec(celt_enc, pcm_buf, st->Fs/200, data+nb_compr_bytes, redundancy_bytes, NULL); > if (err < 0) > { >@@ -1881,15 +2058,25 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ > celt_encode_with_ec(celt_enc, tmp_prefill, st->Fs/400, dummy, 2, NULL); > celt_encoder_ctl(celt_enc, CELT_SET_PREDICTION(0)); > } >- /* If false, we already busted the budget and we'll end up with a "PLC packet" */ >+ /* If false, we already busted the budget and we'll end up with a "PLC frame" */ > if (ec_tell(&enc) <= 8*nb_compr_bytes) > { >+ /* Set the bitrate again if it was overridden in the redundancy code above*/ >+ if (redundancy && celt_to_silk && st->mode==MODE_HYBRID && st->use_vbr) >+ celt_encoder_ctl(celt_enc, OPUS_SET_BITRATE(st->bitrate_bps-st->silk_mode.bitRate)); >+ celt_encoder_ctl(celt_enc, OPUS_SET_VBR(st->use_vbr)); > ret = celt_encode_with_ec(celt_enc, pcm_buf, frame_size, NULL, nb_compr_bytes, &enc); > if (ret < 0) > { > RESTORE_STACK; > return OPUS_INTERNAL_ERROR; > } >+ /* Put CELT->SILK redundancy data in the right place. */ >+ if (redundancy && celt_to_silk && st->mode==MODE_HYBRID && st->use_vbr) >+ { >+ OPUS_MOVE(data+ret, data+nb_compr_bytes, redundancy_bytes); >+ nb_compr_bytes = nb_compr_bytes+redundancy_bytes; >+ } > } > } > >@@ -1905,7 +2092,15 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ > celt_encoder_ctl(celt_enc, OPUS_RESET_STATE); > celt_encoder_ctl(celt_enc, CELT_SET_START_BAND(0)); > celt_encoder_ctl(celt_enc, CELT_SET_PREDICTION(0)); >+ celt_encoder_ctl(celt_enc, OPUS_SET_VBR(0)); >+ celt_encoder_ctl(celt_enc, OPUS_SET_BITRATE(OPUS_BITRATE_MAX)); > >+ if (st->mode == MODE_HYBRID) >+ { >+ /* Shrink packet to what the encoder actually used. */ >+ nb_compr_bytes = ret; >+ ec_enc_shrink(&enc, nb_compr_bytes); >+ } > /* NOTE: We could speed this up slightly (at the expense of code size) by just adding a function that prefills the buffer */ > celt_encode_with_ec(celt_enc, pcm_buf+st->channels*(frame_size-N2-N4), N4, dummy, 2, NULL); > >@@ -1935,6 +2130,21 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ > > st->first = 0; > >+ /* DTX decision */ >+#ifndef DISABLE_FLOAT_API >+ if (st->use_dtx && (analysis_info.valid || is_silence)) >+ { >+ if (decide_dtx_mode(analysis_info.activity_probability, &st->nb_no_activity_frames, >+ st->peak_signal_energy, pcm, frame_size, st->channels, is_silence, st->arch)) >+ { >+ st->rangeFinal = 0; >+ data[0] = gen_toc(st->mode, st->Fs/frame_size, curr_bandwidth, st->stream_channels); >+ RESTORE_STACK; >+ return 1; >+ } >+ } >+#endif >+ > /* In the unlikely case that the SILK encoder busted its target, tell > the decoder to call the PLC */ > if (ec_tell(&enc) > (max_data_bytes-1)*8) >@@ -1962,7 +2172,6 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_ > if (!st->use_vbr) > { > if (opus_packet_pad(data, ret, max_data_bytes) != OPUS_OK) >- > { > RESTORE_STACK; > return OPUS_INTERNAL_ERROR; >@@ -1981,18 +2190,15 @@ opus_int32 opus_encode_float(OpusEncoder *st, const float *pcm, int analysis_fra > { > int i, ret; > int frame_size; >- int delay_compensation; > VARDECL(opus_int16, in); > ALLOC_STACK; > >- if (st->application == OPUS_APPLICATION_RESTRICTED_LOWDELAY) >- delay_compensation = 0; >- else >- delay_compensation = st->delay_compensation; >- frame_size = compute_frame_size(pcm, analysis_frame_size, >- st->variable_duration, st->channels, st->Fs, st->bitrate_bps, >- delay_compensation, downmix_float, st->analysis.subframe_mem); >- >+ frame_size = frame_size_select(analysis_frame_size, st->variable_duration, st->Fs); >+ if (frame_size <= 0) >+ { >+ RESTORE_STACK; >+ return OPUS_BAD_ARG; >+ } > ALLOC(in, frame_size*st->channels, opus_int16); > > for (i=0;i<frame_size*st->channels;i++) >@@ -2008,18 +2214,7 @@ opus_int32 opus_encode(OpusEncoder *st, const opus_int16 *pcm, int analysis_fram > unsigned char *data, opus_int32 out_data_bytes) > { > int frame_size; >- int delay_compensation; >- if (st->application == OPUS_APPLICATION_RESTRICTED_LOWDELAY) >- delay_compensation = 0; >- else >- delay_compensation = st->delay_compensation; >- frame_size = compute_frame_size(pcm, analysis_frame_size, >- st->variable_duration, st->channels, st->Fs, st->bitrate_bps, >- delay_compensation, downmix_int >-#ifndef DISABLE_FLOAT_API >- , st->analysis.subframe_mem >-#endif >- ); >+ frame_size = frame_size_select(analysis_frame_size, st->variable_duration, st->Fs); > return opus_encode_native(st, pcm, frame_size, data, out_data_bytes, 16, > pcm, analysis_frame_size, 0, -2, st->channels, downmix_int, 0); > } >@@ -2030,18 +2225,15 @@ opus_int32 opus_encode(OpusEncoder *st, const opus_int16 *pcm, int analysis_fram > { > int i, ret; > int frame_size; >- int delay_compensation; > VARDECL(float, in); > ALLOC_STACK; > >- if (st->application == OPUS_APPLICATION_RESTRICTED_LOWDELAY) >- delay_compensation = 0; >- else >- delay_compensation = st->delay_compensation; >- frame_size = compute_frame_size(pcm, analysis_frame_size, >- st->variable_duration, st->channels, st->Fs, st->bitrate_bps, >- delay_compensation, downmix_int, st->analysis.subframe_mem); >- >+ frame_size = frame_size_select(analysis_frame_size, st->variable_duration, st->Fs); >+ if (frame_size <= 0) >+ { >+ RESTORE_STACK; >+ return OPUS_BAD_ARG; >+ } > ALLOC(in, frame_size*st->channels, float); > > for (i=0;i<frame_size*st->channels;i++) >@@ -2055,14 +2247,7 @@ opus_int32 opus_encode_float(OpusEncoder *st, const float *pcm, int analysis_fra > unsigned char *data, opus_int32 out_data_bytes) > { > int frame_size; >- int delay_compensation; >- if (st->application == OPUS_APPLICATION_RESTRICTED_LOWDELAY) >- delay_compensation = 0; >- else >- delay_compensation = st->delay_compensation; >- frame_size = compute_frame_size(pcm, analysis_frame_size, >- st->variable_duration, st->channels, st->Fs, st->bitrate_bps, >- delay_compensation, downmix_float, st->analysis.subframe_mem); >+ frame_size = frame_size_select(analysis_frame_size, st->variable_duration, st->Fs); > return opus_encode_native(st, pcm, frame_size, data, out_data_bytes, 24, > pcm, analysis_frame_size, 0, -2, st->channels, downmix_float, 1); > } >@@ -2093,6 +2278,9 @@ int opus_encoder_ctl(OpusEncoder *st, int request, ...) > break; > } > st->application = value; >+#ifndef DISABLE_FLOAT_API >+ st->analysis.application = value; >+#endif > } > break; > case OPUS_GET_APPLICATION_REQUEST: >@@ -2211,7 +2399,7 @@ int opus_encoder_ctl(OpusEncoder *st, int request, ...) > { > goto bad_arg; > } >- st->silk_mode.useDTX = value; >+ st->use_dtx = value; > } > break; > case OPUS_GET_DTX_REQUEST: >@@ -2221,7 +2409,7 @@ int opus_encoder_ctl(OpusEncoder *st, int request, ...) > { > goto bad_arg; > } >- *value = st->silk_mode.useDTX; >+ *value = st->use_dtx; > } > break; > case OPUS_SET_COMPLEXITY_REQUEST: >@@ -2422,10 +2610,11 @@ int opus_encoder_ctl(OpusEncoder *st, int request, ...) > case OPUS_SET_EXPERT_FRAME_DURATION_REQUEST: > { > opus_int32 value = va_arg(ap, opus_int32); >- if (value != OPUS_FRAMESIZE_ARG && value != OPUS_FRAMESIZE_2_5_MS && >- value != OPUS_FRAMESIZE_5_MS && value != OPUS_FRAMESIZE_10_MS && >- value != OPUS_FRAMESIZE_20_MS && value != OPUS_FRAMESIZE_40_MS && >- value != OPUS_FRAMESIZE_60_MS && value != OPUS_FRAMESIZE_VARIABLE) >+ if (value != OPUS_FRAMESIZE_ARG && value != OPUS_FRAMESIZE_2_5_MS && >+ value != OPUS_FRAMESIZE_5_MS && value != OPUS_FRAMESIZE_10_MS && >+ value != OPUS_FRAMESIZE_20_MS && value != OPUS_FRAMESIZE_40_MS && >+ value != OPUS_FRAMESIZE_60_MS && value != OPUS_FRAMESIZE_80_MS && >+ value != OPUS_FRAMESIZE_100_MS && value != OPUS_FRAMESIZE_120_MS) > { > goto bad_arg; > } >@@ -2459,6 +2648,26 @@ int opus_encoder_ctl(OpusEncoder *st, int request, ...) > *value = st->silk_mode.reducedDependency; > } > break; >+ case OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST: >+ { >+ opus_int32 value = va_arg(ap, opus_int32); >+ if(value<0 || value>1) >+ { >+ goto bad_arg; >+ } >+ celt_encoder_ctl(celt_enc, OPUS_SET_PHASE_INVERSION_DISABLED(value)); >+ } >+ break; >+ case OPUS_GET_PHASE_INVERSION_DISABLED_REQUEST: >+ { >+ opus_int32 *value = va_arg(ap, opus_int32*); >+ if (!value) >+ { >+ goto bad_arg; >+ } >+ celt_encoder_ctl(celt_enc, OPUS_GET_PHASE_INVERSION_DISABLED(value)); >+ } >+ break; > case OPUS_RESET_STATE: > { > void *silk_enc; >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/opus_multistream_decoder.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/opus_multistream_decoder.c >index b95eaa6eac12f036ab9f0a4de65621bf57e5b8c0..e421726f2b427dd2ddd4d20f1dfb99c2afb7008b 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/opus_multistream_decoder.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/opus_multistream_decoder.c >@@ -237,7 +237,8 @@ static int opus_multistream_decode_native( > for (s=0;s<st->layout.nb_streams;s++) > { > OpusDecoder *dec; >- int packet_offset, ret; >+ opus_int32 packet_offset; >+ int ret; > > dec = (OpusDecoder*)ptr; > ptr += (s < st->layout.nb_coupled_streams) ? align(coupled_size) : align(mono_size); >@@ -425,6 +426,7 @@ int opus_multistream_decoder_ctl(OpusMSDecoder *st, int request, ...) > case OPUS_GET_SAMPLE_RATE_REQUEST: > case OPUS_GET_GAIN_REQUEST: > case OPUS_GET_LAST_PACKET_DURATION_REQUEST: >+ case OPUS_GET_PHASE_INVERSION_DISABLED_REQUEST: > { > OpusDecoder *dec; > /* For int32* GET params, just query the first stream */ >@@ -499,6 +501,7 @@ int opus_multistream_decoder_ctl(OpusMSDecoder *st, int request, ...) > } > break; > case OPUS_SET_GAIN_REQUEST: >+ case OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST: > { > int s; > /* This works for int32 params */ >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/opus_multistream_encoder.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/opus_multistream_encoder.c >index e722e31ab8ee9f10242944954ea6f5ac2018a13b..032fc0039b91312e756bf89c6bf0de052f68acf1 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/opus_multistream_encoder.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/opus_multistream_encoder.c >@@ -87,7 +87,6 @@ struct OpusMSEncoder { > int variable_duration; > MappingType mapping_type; > opus_int32 bitrate_bps; >- float subframe_mem[3]; > /* Encoder states go here */ > /* then opus_val32 window_mem[channels*120]; */ > /* then opus_val32 preemph_mem[channels]; */ >@@ -133,6 +132,29 @@ static opus_val32 *ms_get_window_mem(OpusMSEncoder *st) > return (opus_val32*)(void*)ptr; > } > >+#ifdef ENABLE_EXPERIMENTAL_AMBISONICS >+static int validate_ambisonics(int nb_channels, int *nb_streams, int *nb_coupled_streams) >+{ >+ int order_plus_one; >+ int acn_channels; >+ int nondiegetic_channels; >+ >+ order_plus_one = isqrt32(nb_channels); >+ acn_channels = order_plus_one * order_plus_one; >+ nondiegetic_channels = nb_channels - acn_channels; >+ >+ if (order_plus_one < 1 || order_plus_one > 15 || >+ (nondiegetic_channels != 0 && nondiegetic_channels != 2)) >+ return 0; >+ >+ if (nb_streams) >+ *nb_streams = acn_channels + (nondiegetic_channels != 0); >+ if (nb_coupled_streams) >+ *nb_coupled_streams = nondiegetic_channels != 0; >+ return 1; >+} >+#endif >+ > static int validate_encoder_layout(const ChannelLayout *layout) > { > int s; >@@ -240,6 +262,7 @@ void surround_analysis(const CELTMode *celt_mode, const void *pcm, opus_val16 *b > int pos[8] = {0}; > int upsample; > int frame_size; >+ int freq_size; > opus_val16 channel_offset; > opus_val32 bandE[21]; > opus_val16 maskLogE[3][21]; >@@ -250,6 +273,7 @@ void surround_analysis(const CELTMode *celt_mode, const void *pcm, opus_val16 *b > > upsample = resampling_factor(rate); > frame_size = len*upsample; >+ freq_size = IMIN(960, frame_size); > > /* LM = log2(frame_size / 120) */ > for (LM=0;LM<celt_mode->maxLM;LM++) >@@ -258,7 +282,7 @@ void surround_analysis(const CELTMode *celt_mode, const void *pcm, opus_val16 *b > > ALLOC(in, frame_size+overlap, opus_val32); > ALLOC(x, len, opus_val16); >- ALLOC(freq, frame_size, opus_val32); >+ ALLOC(freq, freq_size, opus_val32); > > channel_pos(channels, pos); > >@@ -268,6 +292,9 @@ void surround_analysis(const CELTMode *celt_mode, const void *pcm, opus_val16 *b > > for (c=0;c<channels;c++) > { >+ int frame; >+ int nb_frames = frame_size/freq_size; >+ celt_assert(nb_frames*freq_size == frame_size); > OPUS_COPY(in, mem+c*overlap, overlap); > (*copy_channel_in)(x, 1, pcm, channels, c, len); > celt_preemphasis(x, in+overlap, frame_size, 1, upsample, celt_mode->preemph, preemph_mem+c, 0); >@@ -277,25 +304,33 @@ void surround_analysis(const CELTMode *celt_mode, const void *pcm, opus_val16 *b > sum = celt_inner_prod(in, in, frame_size+overlap, 0); > /* This should filter out both NaNs and ridiculous signals that could > cause NaNs further down. */ >- if (!(sum < 1e9f) || celt_isnan(sum)) >+ if (!(sum < 1e18f) || celt_isnan(sum)) > { > OPUS_CLEAR(in, frame_size+overlap); > preemph_mem[c] = 0; > } > } > #endif >- clt_mdct_forward(&celt_mode->mdct, in, freq, celt_mode->window, >- overlap, celt_mode->maxLM-LM, 1, arch); >- if (upsample != 1) >+ OPUS_CLEAR(bandE, 21); >+ for (frame=0;frame<nb_frames;frame++) > { >- int bound = len; >- for (i=0;i<bound;i++) >- freq[i] *= upsample; >- for (;i<frame_size;i++) >- freq[i] = 0; >- } >+ opus_val32 tmpE[21]; >+ clt_mdct_forward(&celt_mode->mdct, in+960*frame, freq, celt_mode->window, >+ overlap, celt_mode->maxLM-LM, 1, arch); >+ if (upsample != 1) >+ { >+ int bound = freq_size/upsample; >+ for (i=0;i<bound;i++) >+ freq[i] *= upsample; >+ for (;i<freq_size;i++) >+ freq[i] = 0; >+ } > >- compute_band_energies(celt_mode, freq, bandE, 21, 1, LM); >+ compute_band_energies(celt_mode, freq, tmpE, 21, 1, LM, arch); >+ /* If we have multiple frames, take the max energy. */ >+ for (i=0;i<21;i++) >+ bandE[i] = MAX32(bandE[i], tmpE[i]); >+ } > amp2Log2(celt_mode, 21, 21, bandE, bandLogE+21*c, 1); > /* Apply spreading function with -6 dB/band going up and -12 dB/band going down. */ > for (i=1;i<21;i++) >@@ -411,8 +446,8 @@ opus_int32 opus_multistream_surround_encoder_get_size(int channels, int mapping_ > #ifdef ENABLE_EXPERIMENTAL_AMBISONICS > } else if (mapping_family==254) > { >- nb_streams=channels; >- nb_coupled_streams=0; >+ if (!validate_ambisonics(channels, &nb_streams, &nb_coupled_streams)) >+ return 0; > #endif > } else > return 0; >@@ -448,7 +483,6 @@ static int opus_multistream_encoder_init_impl( > st->layout.nb_channels = channels; > st->layout.nb_streams = streams; > st->layout.nb_coupled_streams = coupled_streams; >- st->subframe_mem[0]=st->subframe_mem[1]=st->subframe_mem[2]=0; > if (mapping_type != MAPPING_TYPE_SURROUND) > st->lfe_stream = -1; > st->bitrate_bps = OPUS_AUTO; >@@ -456,8 +490,16 @@ static int opus_multistream_encoder_init_impl( > st->variable_duration = OPUS_FRAMESIZE_ARG; > for (i=0;i<st->layout.nb_channels;i++) > st->layout.mapping[i] = mapping[i]; >- if (!validate_layout(&st->layout) || !validate_encoder_layout(&st->layout)) >+ if (!validate_layout(&st->layout)) > return OPUS_BAD_ARG; >+ if (mapping_type == MAPPING_TYPE_SURROUND && >+ !validate_encoder_layout(&st->layout)) >+ return OPUS_BAD_ARG; >+#ifdef ENABLE_EXPERIMENTAL_AMBISONICS >+ if (mapping_type == MAPPING_TYPE_AMBISONICS && >+ !validate_ambisonics(st->layout.nb_channels, NULL, NULL)) >+ return OPUS_BAD_ARG; >+#endif > ptr = (char*)st + align(sizeof(OpusMSEncoder)); > coupled_size = opus_encoder_get_size(2); > mono_size = opus_encoder_get_size(1); >@@ -553,10 +595,12 @@ int opus_multistream_surround_encoder_init( > } else if (mapping_family==254) > { > int i; >- *streams=channels; >- *coupled_streams=0; >- for(i=0;i<channels;i++) >- mapping[i] = i; >+ if (!validate_ambisonics(channels, streams, coupled_streams)) >+ return OPUS_BAD_ARG; >+ for(i = 0; i < (*streams - *coupled_streams); i++) >+ mapping[i] = i + (*coupled_streams * 2); >+ for(i = 0; i < *coupled_streams * 2; i++) >+ mapping[i + (*streams - *coupled_streams)] = i; > #endif > } else > return OPUS_UNIMPLEMENTED; >@@ -672,58 +716,59 @@ static void surround_rate_allocation( > int lfe_offset; > int coupled_ratio; /* Q8 */ > int lfe_ratio; /* Q8 */ >+ int nb_lfe; >+ int nb_uncoupled; >+ int nb_coupled; >+ int nb_normal; >+ opus_int32 channel_offset; >+ opus_int32 bitrate; >+ int total; >+ >+ nb_lfe = (st->lfe_stream!=-1); >+ nb_coupled = st->layout.nb_coupled_streams; >+ nb_uncoupled = st->layout.nb_streams-nb_coupled-nb_lfe; >+ nb_normal = 2*nb_coupled + nb_uncoupled; >+ >+ /* Give each non-LFE channel enough bits per channel for coding band energy. */ >+ channel_offset = 40*IMAX(50, Fs/frame_size); > >- if (st->bitrate_bps > st->layout.nb_channels*40000) >- stream_offset = 20000; >- else >- stream_offset = st->bitrate_bps/st->layout.nb_channels/2; >- stream_offset += 60*(Fs/frame_size-50); >- /* We start by giving each stream (coupled or uncoupled) the same bitrate. >- This models the main saving of coupled channels over uncoupled. */ >- /* The LFE stream is an exception to the above and gets fewer bits. */ >- lfe_offset = 3500 + 60*(Fs/frame_size-50); >- /* Coupled streams get twice the mono rate after the first 20 kb/s. */ >- coupled_ratio = 512; >- /* Should depend on the bitrate, for now we assume LFE gets 1/8 the bits of mono */ >- lfe_ratio = 32; >- >- /* Compute bitrate allocation between streams */ > if (st->bitrate_bps==OPUS_AUTO) > { >- channel_rate = Fs+60*Fs/frame_size; >+ bitrate = nb_normal*(channel_offset + Fs + 10000) + 8000*nb_lfe; > } else if (st->bitrate_bps==OPUS_BITRATE_MAX) > { >- channel_rate = 300000; >+ bitrate = nb_normal*300000 + nb_lfe*128000; > } else { >- int nb_lfe; >- int nb_uncoupled; >- int nb_coupled; >- int total; >- nb_lfe = (st->lfe_stream!=-1); >- nb_coupled = st->layout.nb_coupled_streams; >- nb_uncoupled = st->layout.nb_streams-nb_coupled-nb_lfe; >- total = (nb_uncoupled<<8) /* mono */ >- + coupled_ratio*nb_coupled /* stereo */ >- + nb_lfe*lfe_ratio; >- channel_rate = 256*(st->bitrate_bps-lfe_offset*nb_lfe-stream_offset*(nb_coupled+nb_uncoupled))/total; >+ bitrate = st->bitrate_bps; > } >-#ifndef FIXED_POINT >- if (st->variable_duration==OPUS_FRAMESIZE_VARIABLE && frame_size != Fs/50) >- { >- opus_int32 bonus; >- bonus = 60*(Fs/frame_size-50); >- channel_rate += bonus; >- } >-#endif >+ >+ /* Give LFE some basic stream_channel allocation but never exceed 1/20 of the >+ total rate for the non-energy part to avoid problems at really low rate. */ >+ lfe_offset = IMIN(bitrate/20, 3000) + 15*IMAX(50, Fs/frame_size); >+ >+ /* We give each stream (coupled or uncoupled) a starting bitrate. >+ This models the main saving of coupled channels over uncoupled. */ >+ stream_offset = (bitrate - channel_offset*nb_normal - lfe_offset*nb_lfe)/nb_normal/2; >+ stream_offset = IMAX(0, IMIN(20000, stream_offset)); >+ >+ /* Coupled streams get twice the mono rate after the offset is allocated. */ >+ coupled_ratio = 512; >+ /* Should depend on the bitrate, for now we assume LFE gets 1/8 the bits of mono */ >+ lfe_ratio = 32; >+ >+ total = (nb_uncoupled<<8) /* mono */ >+ + coupled_ratio*nb_coupled /* stereo */ >+ + nb_lfe*lfe_ratio; >+ channel_rate = 256*(opus_int64)(bitrate - lfe_offset*nb_lfe - stream_offset*(nb_coupled+nb_uncoupled) - channel_offset*nb_normal)/total; > > for (i=0;i<st->layout.nb_streams;i++) > { > if (i<st->layout.nb_coupled_streams) >- rate[i] = stream_offset+(channel_rate*coupled_ratio>>8); >+ rate[i] = 2*channel_offset + IMAX(0, stream_offset+(channel_rate*coupled_ratio>>8)); > else if (i!=st->lfe_stream) >- rate[i] = stream_offset+channel_rate; >+ rate[i] = channel_offset + IMAX(0, stream_offset + channel_rate); > else >- rate[i] = lfe_offset+(channel_rate*lfe_ratio>>8); >+ rate[i] = IMAX(0, lfe_offset+(channel_rate*lfe_ratio>>8)); > } > } > >@@ -736,47 +781,72 @@ static void ambisonics_rate_allocation( > ) > { > int i; >- int non_mono_rate; > int total_rate; >+ int directional_rate; >+ int nondirectional_rate; >+ int leftover_bits; > >- /* The mono channel gets (rate_ratio_num / rate_ratio_den) times as many bits >- * as all other channels */ >+ /* Each nondirectional channel gets (rate_ratio_num / rate_ratio_den) times >+ * as many bits as all other ambisonics channels. >+ */ > const int rate_ratio_num = 4; > const int rate_ratio_den = 3; >- const int num_channels = st->layout.nb_streams; >+ const int nb_channels = st->layout.nb_streams + st->layout.nb_coupled_streams; >+ const int nb_nondirectional_channels = st->layout.nb_coupled_streams * 2 + 1; >+ const int nb_directional_channels = st->layout.nb_streams - 1; > > if (st->bitrate_bps==OPUS_AUTO) > { >- total_rate = num_channels * (20000 + st->layout.nb_streams*(Fs+60*Fs/frame_size)); >+ total_rate = (st->layout.nb_coupled_streams + st->layout.nb_streams) * >+ (Fs+60*Fs/frame_size) + st->layout.nb_streams * 15000; > } else if (st->bitrate_bps==OPUS_BITRATE_MAX) > { >- total_rate = num_channels * 320000; >- } else { >+ total_rate = nb_channels * 320000; >+ } else >+ { > total_rate = st->bitrate_bps; > } > >- /* Let y be the non-mono rate and let p, q be integers such that the mono >- * channel rate is (p/q) * y. >+ /* Let y be the directional rate, m be the num of nondirectional channels >+ * m = (s + 1) >+ * and let p, q be integers such that the nondirectional rate is >+ * m_rate = (p / q) * y > * Also let T be the total bitrate to allocate. Then >- * (n - 1) y + (p/q) y = T >- * y = (T q) / (qn - q + p) >+ * T = (n - m) * y + m * m_rate >+ * Solving for y, >+ * y = (q * T) / (m * (p - q) + n * q) > */ >- non_mono_rate = >- total_rate * rate_ratio_den >- / (rate_ratio_den*num_channels + rate_ratio_num - rate_ratio_den); >+ directional_rate = >+ total_rate * rate_ratio_den >+ / (nb_nondirectional_channels * (rate_ratio_num - rate_ratio_den) >+ + nb_channels * rate_ratio_den); > >-#ifndef FIXED_POINT >- if (st->variable_duration==OPUS_FRAMESIZE_VARIABLE && frame_size != Fs/50) >- { >- opus_int32 bonus = 60*(Fs/frame_size-50); >- non_mono_rate += bonus; >- } >-#endif >+ /* Calculate the nondirectional rate. >+ * m_rate = y * (p / q) >+ */ >+ nondirectional_rate = directional_rate * rate_ratio_num / rate_ratio_den; > >- rate[0] = total_rate - (num_channels - 1) * non_mono_rate; >- for (i=1;i<st->layout.nb_streams;i++) >+ /* Calculate the leftover from truncation error. >+ * leftover = T - y * (n - m) - m_rate * m >+ * Place leftover bits in omnidirectional channel. >+ */ >+ leftover_bits = total_rate >+ - directional_rate * nb_directional_channels >+ - nondirectional_rate * nb_nondirectional_channels; >+ >+ /* Calculate rates for each channel */ >+ for (i = 0; i < st->layout.nb_streams; i++) > { >- rate[i] = non_mono_rate; >+ if (i < st->layout.nb_coupled_streams) >+ { >+ rate[i] = nondirectional_rate * 2; >+ } else if (i == st->layout.nb_coupled_streams) >+ { >+ rate[i] = nondirectional_rate + leftover_bits; >+ } else >+ { >+ rate[i] = directional_rate; >+ } > } > } > #endif /* ENABLE_EXPERIMENTAL_AMBISONICS */ >@@ -812,8 +882,8 @@ static opus_int32 rate_allocation( > return rate_sum; > } > >-/* Max size in case the encoder decides to return three frames */ >-#define MS_FRAME_TMP (3*1275+7) >+/* Max size in case the encoder decides to return six frames (6 x 20 ms = 120 ms) */ >+#define MS_FRAME_TMP (6*1275+12) > static int opus_multistream_encode_native > ( > OpusMSEncoder *st, >@@ -859,32 +929,8 @@ static int opus_multistream_encode_native > opus_encoder_ctl((OpusEncoder*)ptr, OPUS_GET_VBR(&vbr)); > opus_encoder_ctl((OpusEncoder*)ptr, CELT_GET_MODE(&celt_mode)); > >- { >- opus_int32 delay_compensation; >- int channels; >- >- channels = st->layout.nb_streams + st->layout.nb_coupled_streams; >- opus_encoder_ctl((OpusEncoder*)ptr, OPUS_GET_LOOKAHEAD(&delay_compensation)); >- delay_compensation -= Fs/400; >- frame_size = compute_frame_size(pcm, analysis_frame_size, >- st->variable_duration, channels, Fs, st->bitrate_bps, >- delay_compensation, downmix >-#ifndef DISABLE_FLOAT_API >- , st->subframe_mem >-#endif >- ); >- } >- >- if (400*frame_size < Fs) >- { >- RESTORE_STACK; >- return OPUS_BAD_ARG; >- } >- /* Validate frame_size before using it to allocate stack space. >- This mirrors the checks in opus_encode[_float](). */ >- if (400*frame_size != Fs && 200*frame_size != Fs && >- 100*frame_size != Fs && 50*frame_size != Fs && >- 25*frame_size != Fs && 50*frame_size != 3*Fs) >+ frame_size = frame_size_select(analysis_frame_size, st->variable_duration, Fs); >+ if (frame_size <= 0) > { > RESTORE_STACK; > return OPUS_BAD_ARG; >@@ -892,6 +938,9 @@ static int opus_multistream_encode_native > > /* Smallest packet the encoder can produce. */ > smallest_packet = st->layout.nb_streams*2-1; >+ /* 100 ms needs an extra byte per stream for the ToC. */ >+ if (Fs/frame_size == 10) >+ smallest_packet += st->layout.nb_streams; > if (max_data_bytes < smallest_packet) > { > RESTORE_STACK; >@@ -1013,6 +1062,9 @@ static int opus_multistream_encode_native > curr_max = max_data_bytes - tot_size; > /* Reserve one byte for the last stream and two for the others */ > curr_max -= IMAX(0,2*(st->layout.nb_streams-s-1)-1); >+ /* For 100 ms, reserve an extra byte per stream for the ToC */ >+ if (Fs/frame_size == 10) >+ curr_max -= st->layout.nb_streams-s-1; > curr_max = IMIN(curr_max,MS_FRAME_TMP); > /* Repacketizer will add one or two bytes for self-delimited frames */ > if (s != st->layout.nb_streams-1) curr_max -= curr_max>253 ? 2 : 1; >@@ -1161,9 +1213,11 @@ int opus_multistream_encoder_ctl(OpusMSEncoder *st, int request, ...) > case OPUS_SET_BITRATE_REQUEST: > { > opus_int32 value = va_arg(ap, opus_int32); >- if (value<0 && value!=OPUS_AUTO && value!=OPUS_BITRATE_MAX) >+ if (value != OPUS_AUTO && value != OPUS_BITRATE_MAX) > { >- goto bad_arg; >+ if (value <= 0) >+ goto bad_arg; >+ value = IMIN(300000*st->layout.nb_channels, IMAX(500*st->layout.nb_channels, value)); > } > st->bitrate_bps = value; > } >@@ -1206,6 +1260,7 @@ int opus_multistream_encoder_ctl(OpusMSEncoder *st, int request, ...) > case OPUS_GET_INBAND_FEC_REQUEST: > case OPUS_GET_FORCE_CHANNELS_REQUEST: > case OPUS_GET_PREDICTION_DISABLED_REQUEST: >+ case OPUS_GET_PHASE_INVERSION_DISABLED_REQUEST: > { > OpusEncoder *enc; > /* For int32* GET params, just query the first stream */ >@@ -1252,6 +1307,7 @@ int opus_multistream_encoder_ctl(OpusMSEncoder *st, int request, ...) > case OPUS_SET_FORCE_MODE_REQUEST: > case OPUS_SET_FORCE_CHANNELS_REQUEST: > case OPUS_SET_PREDICTION_DISABLED_REQUEST: >+ case OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST: > { > int s; > /* This works for int32 params */ >@@ -1313,7 +1369,6 @@ int opus_multistream_encoder_ctl(OpusMSEncoder *st, int request, ...) > case OPUS_RESET_STATE: > { > int s; >- st->subframe_mem[0] = st->subframe_mem[1] = st->subframe_mem[2] = 0; > if (st->mapping_type == MAPPING_TYPE_SURROUND) > { > OPUS_CLEAR(ms_get_preemph_mem(st), st->layout.nb_channels); >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/opus_private.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/opus_private.h >index 3b62eed0964f0535ef12017c389abb627e3c4d0a..a731cc550ea43724d52beb650c4970da9adbda01 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/opus_private.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/opus_private.h >@@ -92,14 +92,6 @@ int encode_size(int size, unsigned char *data); > > opus_int32 frame_size_select(opus_int32 frame_size, int variable_duration, opus_int32 Fs); > >-opus_int32 compute_frame_size(const void *analysis_pcm, int frame_size, >- int variable_duration, int C, opus_int32 Fs, int bitrate_bps, >- int delay_compensation, downmix_func downmix >-#ifndef DISABLE_FLOAT_API >- , float *subframe_mem >-#endif >- ); >- > opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_size, > unsigned char *data, opus_int32 out_data_bytes, int lsb_depth, > const void *analysis_pcm, opus_int32 analysis_size, int c1, int c2, >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/tests/opus_decode_fuzzer.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/tests/opus_decode_fuzzer.c >new file mode 100644 >index 0000000000000000000000000000000000000000..90026221ceaf299b3f04145fd49716fb5b146d22 >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/tests/opus_decode_fuzzer.c >@@ -0,0 +1,126 @@ >+/* Copyright (c) 2017 Google Inc. */ >+/* >+ Redistribution and use in source and binary forms, with or without >+ modification, are permitted provided that the following conditions >+ are met: >+ >+ - Redistributions of source code must retain the above copyright >+ notice, this list of conditions and the following disclaimer. >+ >+ - Redistributions in binary form must reproduce the above copyright >+ notice, this list of conditions and the following disclaimer in the >+ documentation and/or other materials provided with the distribution. >+ >+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS >+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT >+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR >+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER >+ OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, >+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, >+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR >+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF >+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING >+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS >+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+*/ >+ >+#ifdef HAVE_CONFIG_H >+#include "config.h" >+#endif >+ >+#include <stdint.h> >+#include <stdlib.h> >+#include <string.h> >+#include "opus.h" >+#include "opus_types.h" >+ >+#define MAX_FRAME_SAMP 5760 >+#define MAX_PACKET 1500 >+ >+/* 4 bytes: packet length, 4 bytes: encoder final range */ >+#define SETUP_BYTE_COUNT 8 >+ >+typedef struct { >+ int fs; >+ int channels; >+} TocInfo; >+ >+static void ParseToc(const uint8_t *toc, TocInfo *const info) { >+ const int samp_freqs[5] = {8000, 12000, 16000, 24000, 48000}; >+ const int bandwidth = opus_packet_get_bandwidth(toc); >+ >+ info->fs = samp_freqs[bandwidth - OPUS_BANDWIDTH_NARROWBAND]; >+ info->channels = opus_packet_get_nb_channels(toc); >+} >+ >+/* Treats the input data as concatenated packets encoded by opus_demo, >+ * structured as >+ * bytes 0..3: packet length >+ * bytes 4..7: encoder final range >+ * bytes 8+ : Opus packet, including ToC >+ */ >+int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { >+ OpusDecoder *dec; >+ opus_int16 *pcm; >+ uint8_t *packet; >+ TocInfo toc; >+ int i, err; >+ >+ /* Not enough data to setup the decoder (+1 for the ToC) */ >+ if (size < SETUP_BYTE_COUNT + 1) { >+ return 0; >+ } >+ >+ /* Create decoder based on info from the first ToC available */ >+ ParseToc(&data[SETUP_BYTE_COUNT], &toc); >+ >+ dec = opus_decoder_create(toc.fs, toc.channels, &err); >+ if (err != OPUS_OK | dec == NULL) { >+ return 0; >+ } >+ >+ pcm = (opus_int16*) malloc(sizeof(*pcm) * MAX_FRAME_SAMP * toc.channels); >+ packet = (uint8_t*) calloc(MAX_PACKET, sizeof(*packet)); >+ >+ i = 0; >+ while (1) { >+ int len, fec; >+ >+ if (i + SETUP_BYTE_COUNT >= size) { >+ break; >+ } >+ >+ len = (opus_uint32) data[i ] << 24 | >+ (opus_uint32) data[i + 1] << 16 | >+ (opus_uint32) data[i + 2] << 8 | >+ (opus_uint32) data[i + 3]; >+ if (len > MAX_PACKET || len < 0) { >+ break; >+ } >+ >+ /* Bytes 4..7 represent encoder final range, but are unused here. >+ * Instead, byte 4 is repurposed to determine if FEC is used. */ >+ fec = data[i + 4] & 1; >+ >+ /* Lost packet */ >+ if (len == 0) { >+ int frame_size; >+ opus_decoder_ctl(dec, OPUS_GET_LAST_PACKET_DURATION(&frame_size)); >+ (void) opus_decode(dec, NULL, size, pcm, frame_size, fec); >+ } else { >+ if (i + SETUP_BYTE_COUNT + len > size) { >+ break; >+ } >+ memcpy(pcm, &data[i + SETUP_BYTE_COUNT], len); >+ (void) opus_decode(dec, data, size, pcm, MAX_FRAME_SAMP, fec); >+ } >+ >+ i += SETUP_BYTE_COUNT + len; >+ } >+ >+ opus_decoder_destroy(dec); >+ free(pcm); >+ free(packet); >+ >+ return 0; >+} >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/tests/opus_decode_fuzzer.options b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/tests/opus_decode_fuzzer.options >new file mode 100644 >index 0000000000000000000000000000000000000000..e5ae71b937a4e3557f047545080f2e538736d70f >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/tests/opus_decode_fuzzer.options >@@ -0,0 +1,2 @@ >+[libfuzzer] >+max_len = 1000000 >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/tests/opus_encode_regressions.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/tests/opus_encode_regressions.c >new file mode 100644 >index 0000000000000000000000000000000000000000..29234730144399341b50a8b3282c6291223b6691 >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/tests/opus_encode_regressions.c >@@ -0,0 +1,1035 @@ >+/* Copyright (c) 2016 Mark Harris, Jean-Marc Valin */ >+/* >+ Redistribution and use in source and binary forms, with or without >+ modification, are permitted provided that the following conditions >+ are met: >+ >+ - Redistributions of source code must retain the above copyright >+ notice, this list of conditions and the following disclaimer. >+ >+ - Redistributions in binary form must reproduce the above copyright >+ notice, this list of conditions and the following disclaimer in the >+ documentation and/or other materials provided with the distribution. >+ >+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS >+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT >+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR >+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER >+ OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, >+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, >+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR >+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF >+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING >+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS >+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+*/ >+ >+ >+#ifdef HAVE_CONFIG_H >+#include "config.h" >+#endif >+ >+#include <stdio.h> >+#include <stdlib.h> >+#include <limits.h> >+#include <stdint.h> >+#include <math.h> >+#include <string.h> >+#include <assert.h> >+#include "opus_multistream.h" >+#include "opus.h" >+#include "test_opus_common.h" >+ >+ >+static int celt_ec_internal_error(void) >+{ >+ OpusMSEncoder *enc; >+ int err; >+ unsigned char data[2460]; >+ int streams; >+ int coupled_streams; >+ unsigned char mapping[1]; >+ >+ enc = opus_multistream_surround_encoder_create(16000, 1, 1, &streams, >+ &coupled_streams, mapping, OPUS_APPLICATION_VOIP, &err); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_SIGNAL(OPUS_SIGNAL_MUSIC)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_VBR(0)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_VBR_CONSTRAINT(0)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_PREDICTION_DISABLED(1)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_PHASE_INVERSION_DISABLED(0)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_DTX(0)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_COMPLEXITY(0)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_MAX_BANDWIDTH(OPUS_BANDWIDTH_NARROWBAND)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_BANDWIDTH(OPUS_AUTO)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_LSB_DEPTH(8)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_INBAND_FEC(0)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_PACKET_LOSS_PERC(0)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_BITRATE(OPUS_AUTO)); >+ { >+ static const short pcm[320] = >+ { >+ 0, 0, 0, 0, 0, 0, 0, 0, 0, >+ 0, 0, 0, 0, 0, 0, 1792, 1799, 1799, >+ 1799, 1799, 1799, 1799, 1799, 1799, 1799, 1799, 1799, >+ 1799, 1799, 1799, 1799, 1799, 0, 25600, 1799, 1799, >+ 1799, 1799, 1799, 1799, 1799, 1799, 1799, 1799, 1799, >+ 1799, 1799, 1799, 1799, 7, 0, 255, 0, 0, >+ 0, 0, 0, 0, 0, 0, 0, 32767, -1, >+ 0, 0, 0, 100, 0, 16384, 0, 0, 0, >+ 0, 0, 0, 4, 0, 0, -256, 255, 0, >+ 0, 0, 0, 0, 0, 0, 0, 0, 0, >+ 0, 0, 0, 0, 0, 0, 0, 0, 0, >+ 0, 0,-32768, 0, 0, 0, 0, 0, 0, >+ 0, 0, 0, 0, 0, 0, 0, 0, 0, >+ 0, 0, 0, 0, 0, 0, 0, 0, 0, >+ 0, 0, 0, 0, 128, 0, 0, 0, 0, >+ 0, 0, 0, 0, -256, 0, 0, 32, 0, >+ 0, 0, 0, 0, 0, 0, 4352, 4, 228, >+ 0, 0, 0, 0, 0, 0, 0, 0, 0, >+ 0, 0, 0, 0, 0, 0, 5632, 0, 0, >+ 0, 0,-32768, 0, 0, 0, 0, 0, 0, >+ 0, 0, 0, 0, 0, 0, 0, 0, 0, >+ 0, 0, 0, 0, 0, 0, 0, 0, 0, >+ 0, 0, 0, 256, 0, 0, 0, 0, 0, >+ 0, 0, 0, 0, 0, 0, 0, 0, 0, >+ -3944, 10500, 4285, 10459, -6474, 10204, -6539, 11601, -6824, >+ 13385, -7142, 13872,-11553, 13670, -7725, 13463, -6887, 7874, >+ -5580, 12600, -4964, 12480, 3254, 11741, -4210, 9741, -3155, >+ 7558, -5468, 5431, -1073, 3641, -1304, 0, -1, 343, >+ 26, 0, 0, 150, 0, 0, 0, 0, 0, >+ 0, 0, 0, 0, 0, 0, 0, 0, 0, >+ 0, 0, 0, 0, 0, 0, 0, 0, 0, >+ 0, 0, 0, 0, 0, 0, 0, 0, 0, >+ 0, 0, 0, 0, 0, 0, 0, 0, 0, >+ 0, 0, 0, 1799, 1799, 1799, 1799, 1799, -2553, >+ 7, 1792, 1799, 1799, 1799, 1799, 1799, 1799, 1799, >+ 1799, 1799, 1799, 1799, -9721 >+ }; >+ err = opus_multistream_encode(enc, pcm, 320, data, 2460); >+ assert(err > 0); >+ } >+ opus_multistream_encoder_ctl(enc, OPUS_SET_SIGNAL(OPUS_SIGNAL_MUSIC)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_VBR(0)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_VBR_CONSTRAINT(1)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_PREDICTION_DISABLED(1)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_PHASE_INVERSION_DISABLED(0)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_DTX(1)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_COMPLEXITY(10)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_MAX_BANDWIDTH(OPUS_BANDWIDTH_FULLBAND)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_BANDWIDTH(OPUS_BANDWIDTH_FULLBAND)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_LSB_DEPTH(18)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_INBAND_FEC(1)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_PACKET_LOSS_PERC(90)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_BITRATE(280130)); >+ { >+ static const short pcm[160] = >+ { >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9526, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, 25600, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510 >+ }; >+ err = opus_multistream_encode(enc, pcm, 160, data, 2460); >+ assert(err > 0); >+ } >+ opus_multistream_encoder_ctl(enc, OPUS_SET_SIGNAL(OPUS_SIGNAL_MUSIC)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_VBR(0)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_VBR_CONSTRAINT(1)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_PREDICTION_DISABLED(1)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_PHASE_INVERSION_DISABLED(0)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_DTX(1)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_COMPLEXITY(10)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_MAX_BANDWIDTH(OPUS_BANDWIDTH_FULLBAND)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_BANDWIDTH(OPUS_BANDWIDTH_FULLBAND)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_LSB_DEPTH(18)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_INBAND_FEC(1)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_PACKET_LOSS_PERC(90)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_BITRATE(280130)); >+ { >+ static const short pcm[160] = >+ { >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9494, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510 >+ }; >+ err = opus_multistream_encode(enc, pcm, 160, data, 2460); >+ assert(err > 0); >+ } >+ opus_multistream_encoder_ctl(enc, OPUS_SET_SIGNAL(OPUS_SIGNAL_MUSIC)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_VBR(0)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_VBR_CONSTRAINT(1)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_PREDICTION_DISABLED(1)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_PHASE_INVERSION_DISABLED(0)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_DTX(1)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_COMPLEXITY(10)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_MAX_BANDWIDTH(OPUS_BANDWIDTH_FULLBAND)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_BANDWIDTH(OPUS_BANDWIDTH_FULLBAND)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_LSB_DEPTH(18)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_INBAND_FEC(1)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_PACKET_LOSS_PERC(90)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_BITRATE(280130)); >+ { >+ static const short pcm[160] = >+ { >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9479, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, -9510, >+ -9510, -9510, -9510, -9510, -9510, -9510, -9510 >+ }; >+ err = opus_multistream_encode(enc, pcm, 160, data, 2460); >+ assert(err > 0); >+ } >+ opus_multistream_encoder_ctl(enc, OPUS_SET_SIGNAL(OPUS_SIGNAL_MUSIC)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_VBR(0)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_VBR_CONSTRAINT(1)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_PREDICTION_DISABLED(1)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_PHASE_INVERSION_DISABLED(0)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_DTX(1)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_COMPLEXITY(10)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_MAX_BANDWIDTH(OPUS_BANDWIDTH_FULLBAND)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_BANDWIDTH(OPUS_BANDWIDTH_FULLBAND)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_LSB_DEPTH(18)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_INBAND_FEC(1)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_PACKET_LOSS_PERC(90)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_BITRATE(280130)); >+ { >+ static const short pcm[160] = >+ { >+ -9510, -9510, 1799, 1799, 1799, 1799, 1799, 1799, 1799, >+ 1799, 1799, 1799, 1799, 1799, 1799, 1799, 1799, 0, >+ 0, 0, 0, 0, 0, 0, 0, 0, 0, >+ 0, 0, 0, 0, 0, 0, 0, 0, 0, >+ 0, 0, 0, 0, 0, 0, 0, 0, 0, >+ -256, 255, 0, 0, 0, 0, 0, 0, 0, >+ 0, 0, 0, 0, 0, 0, 0, 0, 0, >+ 0, 0, 0, 0, 0, 0, 0, 0, 0, >+ 0, 0, 0, 0, 0, 0, 0, 0, 0, >+ 0, 0, 0, 0, 0, 0, 0, 0, 0, >+ 0, 0, 0, 0, 0, 0, 0, 128, 0, >+ 0, 0, 0, 0, 0, 0, 0, 0, 0, >+ 0, 32, 0, 0, 0, 0, 0, 0, 0, >+ 4352, 4, 0, 0, 0, 0, 0, 0, 0, >+ 0, 0, 0, 0, 148, 0, 0, 0, 0, >+ 5632 >+ }; >+ err = opus_multistream_encode(enc, pcm, 160, data, 2460); >+ assert(err > 0); >+ } >+ opus_multistream_encoder_ctl(enc, OPUS_SET_SIGNAL(OPUS_SIGNAL_VOICE)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_VBR(0)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_VBR_CONSTRAINT(1)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_PREDICTION_DISABLED(1)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_PHASE_INVERSION_DISABLED(1)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_DTX(1)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_COMPLEXITY(0)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_MAX_BANDWIDTH(OPUS_BANDWIDTH_NARROWBAND)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_BANDWIDTH(OPUS_AUTO)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_LSB_DEPTH(12)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_INBAND_FEC(0)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_PACKET_LOSS_PERC(41)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_BITRATE(21425)); >+ { >+ static const short pcm[40] = >+ { >+ 10459, -6474, 10204, -6539, 11601, -6824, 13385, -7142, 13872, >+ -11553, 13670, -7725, 13463, -6887, 12482, -5580, 12600, -4964, >+ 12480, 3254, 11741, -4210, 9741, -3155, 7558, -5468, 5431, >+ -1073, 3641, -1304, 0, -1, 343, 26, 0, 0, >+ 0, 0, -256, 226 >+ }; >+ err = opus_multistream_encode(enc, pcm, 40, data, 2460); >+ assert(err > 0); >+ /* returns -3 */ >+ } >+ opus_multistream_encoder_destroy(enc); >+ return 0; >+} >+ >+static int mscbr_encode_fail10(void) >+{ >+ OpusMSEncoder *enc; >+ int err; >+ unsigned char data[627300]; >+ static const unsigned char mapping[255] = >+ { >+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, >+ 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, >+ 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, >+ 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, >+ 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, >+ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99,100,101, >+ 102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118, >+ 119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135, >+ 136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152, >+ 153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169, >+ 170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186, >+ 187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203, >+ 204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220, >+ 221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237, >+ 238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254 >+ }; >+ >+ enc = opus_multistream_encoder_create(8000, 255, 254, 1, mapping, >+ OPUS_APPLICATION_RESTRICTED_LOWDELAY, &err); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_SIGNAL(OPUS_SIGNAL_VOICE)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_VBR(0)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_VBR_CONSTRAINT(0)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_PREDICTION_DISABLED(0)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_FORCE_CHANNELS(2)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_PHASE_INVERSION_DISABLED(1)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_DTX(1)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_COMPLEXITY(2)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_MAX_BANDWIDTH(OPUS_BANDWIDTH_NARROWBAND)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_BANDWIDTH(OPUS_AUTO)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_LSB_DEPTH(14)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_INBAND_FEC(0)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_PACKET_LOSS_PERC(57)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_BITRATE(3642675)); >+ { >+ static const short pcm[20*255] = >+ { >+ 0 >+ }; >+ err = opus_multistream_encode(enc, pcm, 20, data, 627300); >+ assert(err > 0); >+ /* returns -1 */ >+ } >+ opus_multistream_encoder_destroy(enc); >+ return 0; >+} >+ >+static int mscbr_encode_fail(void) >+{ >+ OpusMSEncoder *enc; >+ int err; >+ unsigned char data[472320]; >+ static const unsigned char mapping[192] = >+ { >+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, >+ 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, >+ 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, >+ 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, >+ 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, >+ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99,100,101, >+ 102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118, >+ 119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135, >+ 136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152, >+ 153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169, >+ 170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186, >+ 187,188,189,190,191 >+ }; >+ >+ enc = opus_multistream_encoder_create(8000, 192, 189, 3, mapping, >+ OPUS_APPLICATION_RESTRICTED_LOWDELAY, &err); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_SIGNAL(OPUS_SIGNAL_MUSIC)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_VBR(0)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_VBR_CONSTRAINT(0)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_PREDICTION_DISABLED(0)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_FORCE_CHANNELS(OPUS_AUTO)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_PHASE_INVERSION_DISABLED(0)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_DTX(0)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_COMPLEXITY(0)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_MAX_BANDWIDTH(OPUS_BANDWIDTH_MEDIUMBAND)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_BANDWIDTH(OPUS_AUTO)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_LSB_DEPTH(8)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_INBAND_FEC(0)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_PACKET_LOSS_PERC(0)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_BITRATE(15360)); >+ { >+ static const short pcm[20*192] = >+ { >+ 0 >+ }; >+ err = opus_multistream_encode(enc, pcm, 20, data, 472320); >+ assert(err > 0); >+ /* returns -1 */ >+ } >+ opus_multistream_encoder_destroy(enc); >+ return 0; >+} >+ >+static int surround_analysis_uninit(void) >+{ >+ OpusMSEncoder *enc; >+ int err; >+ unsigned char data[7380]; >+ int streams; >+ int coupled_streams; >+ unsigned char mapping[3]; >+ >+ enc = opus_multistream_surround_encoder_create(24000, 3, 1, &streams, >+ &coupled_streams, mapping, OPUS_APPLICATION_AUDIO, &err); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_SIGNAL(OPUS_SIGNAL_VOICE)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_VBR(1)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_VBR_CONSTRAINT(1)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_PREDICTION_DISABLED(0)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_FORCE_CHANNELS(OPUS_AUTO)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_PHASE_INVERSION_DISABLED(0)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_DTX(0)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_COMPLEXITY(0)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_MAX_BANDWIDTH(OPUS_BANDWIDTH_NARROWBAND)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_BANDWIDTH(OPUS_BANDWIDTH_NARROWBAND)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_LSB_DEPTH(8)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_INBAND_FEC(1)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_BITRATE(84315)); >+ { >+ static const short pcm[960*3] = >+ { >+ -6896, 4901, -6158, 4120, -5164, 3631, -4442, 3153, -4070, >+ 3349, -4577, 4474, -5541, 5058, -6701, 3881, -7933, 1863, >+ -8041, 697, -6738,-31464, 14330,-12523, 4096, -6130, 29178, >+ -250,-21252, 10467, 16907, -3359, -6644, 31965, 14607,-21544, >+ -32497, 24020, 12557,-26926,-18421, -1842, 24587, 19659, 4878, >+ 10954, 23060, 8907,-10215,-16179, 31772,-11825,-15590,-23089, >+ 17173,-25903,-17387, 11733, 4884, 10204,-16476,-14367, 516, >+ 20453,-16898, 20967,-23813, -20, 22011,-17167, 9459, 32499, >+ -25855, -523, -3883, -390, -4206, 634, -3767, 2325, -2751, >+ 3115, -2392, 2746, -2173, 2317, -1147, 2326, 23142, 11314, >+ -15350,-24529, 3026, 6146, 2150, 2476, 1105, -830, 1775, >+ -3425, 3674,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ 4293,-14023, 3879,-15553, 3158,-16161, 2629, 18433,-12535, >+ -6645,-20735,-32763,-13824,-20992, 25859, 13052, -8731, 2292, >+ -3860, 24049, 10225,-19220, 10478,-22294, 22773, 28137, 13816, >+ 30953,-25863,-24598, 16888,-14612,-28942, 20974,-27397,-18944, >+ -18690, 20991,-16638, 5632,-14330, 28911,-25594, 17408, 29958, >+ -517,-20984, -1800, 11281, 9977,-21221,-14854, 23840, -9477, >+ 3362,-12805,-22493, 32507, 156, 16384, -1163, 2301, -1874, >+ 4600, -1748, 6950, 16557, 8192, -7372, -1033, -3278, 2806, >+ 20275, 3317, -717, 9792, -767, 9099, -613, 8362, 5027, >+ 7774, 2597, 8549, 5278, 8743, 9343, 6940, 13038, 4826, >+ 14086, 2964, 13215, 1355, 11596, 455, 9850, -519, 10680, >+ -2287, 12551, -3736, 13639, -4291, 13790, -2722, 14544, -866, >+ 15050, -304, 22833, -1196, 13520, -2063, 13051, -2317, 13066, >+ -2737, 13773, -2664, 14105, -3447, 13854, 24589, 24672, -5280, >+ 10388, -4933, 7543, -4149, 3654, -1552, 1726, 661, 57, >+ 2922, -751, 3917, 8419, 3840, -5218, 3435, 5540, -1073, >+ 4153, -6656, 1649, -769, -7276,-13072, 6380, -7948, 20717, >+ 18425, 17392, 14335,-18190, -1842, 24587, 19659, 11790, 10954, >+ 23060, 8907,-10215,-16179, 31772,-11825,-15590,-23101, 17173, >+ -25903,-17387, 11733, 4884, 10192,-16627,-14367, 516, 20453, >+ -16898, 20967,-23813, -20, 22011,-17167, 9468, 32499,-25607, >+ -523, -3883, -390, -4206, 634, -3767, 2325, -2751, 3115, >+ -2392, 2746, -2161, 2317, -1147, 2326, 23142, 11314,-15350, >+ -29137, 3026,-15056, -491,-15170, -386,-16015, -641,-16505, >+ -930,-16206, -717,-16175, -2839,-16374, -4558,-16237, -5207, >+ -15903, -6421, 6373, -1403, 5431, -1073, 3641, -1304, -4495, >+ -769, -7276, 2856, -7870, 3314, -8730, 3964,-10183, 4011, >+ -11135, 3421,-11727, 2966,-12360, 2818,-13472, 3660,-13805, >+ 5162,-13478, 6434,-12840, 7335,-12420, 6865,-12349, 5541, >+ -11965, 5530,-10820, 5132, -9197, 3367, -7745, 1223, -6910, >+ -433, -6211, -1711, -4958, -1025, -3755, -836, -3292, -1666, >+ -2661,-10755, 31472,-27906, 31471, 18690, 5617, 16649, 11253, >+ -22516,-17674,-31990, 3575,-31479, 5883, 26121, 12890, -6612, >+ 12228,-11634, 523, 26136,-21496, 20745,-15868, -4100,-24826, >+ 23282, 22798, 491, -1774, 15075,-27373,-13094, 6417,-29487, >+ 14608, 10185, 16143, 22211, -8436, 4288, -8694, 2375, 3023, >+ 486, 1455, 128, 202, 942, -923, 2068, -1233, -717, >+ -1042, -2167, 32255, -4632, 310, -4458, -3639, -5258, 2106, >+ -6857, 2681, -7497, 2765, -6601, 1945, -5219, 19154, -4877, >+ 619, -5719, -1928, -6208, -121, 593, 188, 1558, -4152, >+ 1648, 156, 1604, -3664, -6862, -2851, -5112, -3600, -3747, >+ -5081, -4428, -5592, 20974,-27397,-18944,-18690, 20991,-17406, >+ 5632,-14330, 28911, 15934, 15934, 15934, 15934, 15934, 15934, >+ 15934, 15934, 15934, 15934, 15934, 15934,-25594, 17408, 29958, >+ -7173,-16888, 9098, -613, 8362, 675, 7774, 2597, 8549, >+ 5278, 8743, 9375, 6940, 13038, 4826, 14598, 7721,-24308, >+ -29905,-19703,-17106,-16124, -3287,-26118,-19709,-10769, 24353, >+ 28648, 6946, -1363, 12485, -1187, 26074,-25055, 10004,-24798, >+ 7204, -4581, -9678, 1554, 10553, 3102, 12193, 2443, 11955, >+ 1213, 10689, -1293, 921, -4173, 10709, -6049, 8815, -7128, >+ 8147, -8308, 6847, -2977, 4920,-11447,-22426,-11794, 3514, >+ -10220, 3430, -7993, 1926, -7072, 327, -7569, -608, -7605, >+ 3695, -6271, -1579, -4877, -1419, -3103, -2197, 128, -3904, >+ 3760, -5401, 4906, -6051, 4250, -6272, 3492, -6343, 3197, >+ -6397, 4041, -6341, 6255, -6381, 7905, 16504, 0, -6144, >+ 8062, -5606, 8622, -5555, -9, -1, 7423, 0, 1, >+ 238, 5148, 1309, 4700, 2218, 4403, 2573, 3568, 28303, >+ 1758, 3454, -1247, 3434, -4912, 2862, -7844, 1718,-10095, >+ 369,-12631, 128, -3904, 3632, -5401, 4906, -6051, 4250, >+ -6272, 3492, -6343, 3197, -6397, 4041, -6341, 6255, -6381, >+ 7905, 16504, 0, -6144, 8062, -5606, 8622, -5555, 8439, >+ -3382, 7398, -1170, 6132, 238, 5148, 1309, 4700, 2218, >+ 4403, 2573, 3568, 2703, 1758, 3454, -1247, 3434, -4912, >+ 2862, -7844, 1718,-10095, 369,-12631, -259,-14632, 234, >+ -15056, -521,-15170, -386,-16015, -641,-16505, -930,-16206, >+ -1209,-16146, -2839,-16374, -4558,-16218, -5207,-15903, -6421, >+ -15615, -6925,-14871, -6149,-13759, -5233,-12844, 18313, -4357, >+ -5696, 2804, 12992,-22802, -6720, -9770, -7088, -8998, 14330, >+ -12523, 14843, -6130, 29178, -250,-27396, 10467, 16907, -3359, >+ -6644, 31965, 14607,-21544,-32497, 24020, 12557,-26926, -173, >+ -129, -6401, -130,-25089, -3841, -4916, -3048, 224, -237, >+ -3969, -189, -3529, -535, -3464,-14863,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14395,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907, 0, 32512,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907, 9925, -718, 9753, -767, >+ 9099, -613, 8362, 675, 7774, 2597, 8549, 5278, 8743, >+ 9375, 6940, 13038, 4826, 14598, 7721,-24308,-29905,-19703, >+ -17106,-16124, -3287,-26118,-19709, 0, 24353, 28648, 10274, >+ -11292,-29665,-16417, 24346, 14553, 18707, 26323, -4596,-17711, >+ 5133, 26328, 13,-31168, 24583, 18404,-28927,-24350, 19453, >+ 28642, 1019,-10777, -3079, 30188, -7686, 27635,-32521,-16384, >+ 12528, -6386, 10986, 23827,-25880,-32752,-23321, 14605, 32231, >+ 780,-13849, 15119, 28647, 4888, -7705, 30750, 64, 0, >+ 32488, 6687,-20758, 19745, -2070,-13792, -6414, 28188, -2821, >+ -4585, 7168, 7444, 23557,-21998, 13064, 3345, -4086,-28915, >+ -8694, 32262, 8461, 27387,-12275, 12012, 23563,-18719,-28410, >+ 29144,-22271, -562, -9986, -5434, 12288, 5573,-16642, 32448, >+ 29182, 32705,-30723, 24255,-19716, 18368, -4357, -5696, 2804, >+ 12992,-22802,-22080, -7701, -5183, 486, -3133, -5660, -1083, >+ 16871,-28726,-11029,-30259, -1209,-16146, -2839,-16374, -4558, >+ -16218,-10523, 20697, -9500, -1316, 5431, -1073, 3641, -1304, >+ 1649, -769, -7276, 2856, -7870, 3314, -8730, 3964,-10183, >+ 4011,-11135, 3421,-11727, 21398, 32767, -1, 32486, -1, >+ 6301,-13071, 6380, -7948, -1, 32767, 240, 14081, -5646, >+ 30973, -3598,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907, 32767,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907, 8901, 9375, 6940, 13038, 4826, 14598, 7721,-24308, >+ -29905,-19703,-17106,-16124, -3287,-26118,-19709,-10769, 24361, >+ 28648, 10274,-11292,-29665,-16417, 24346, 14580, 18707, 26323, >+ -4440,-17711, 5133, 26328,-14579,-31008, 24583, 18404, 28417, >+ -24350, 19453, 28642,-32513,-10777, -3079, 30188, -7686, 27635, >+ -32521,-16384,-20240, -6386, 10986, 23827,-25880,-32752,-23321, >+ 14605, 32231, 780,-13849, 15119, 28647, 4888, -7705,-15074, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907, 8192,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14897,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -15931,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907, 26121, 12890, 2604, >+ 12228,-11634, 12299, 5573,-16642, 32452, 29182, 32705,-30723, >+ 24255,-19716, 13248,-11779, -5696, 2804, 12992,-27666,-22080, >+ -7701, -5183, -6682,-31464, 14330,-12523, 14843, -6130, 29178, >+ -18,-27396, 10467, 16907, -3359, -6644, 31965, 14607,-21544, >+ -32497, 24020, 12557,-26926,-18421, 706, 24587, 19659, 4878, >+ 10954, 23060, 8907,-10215,-22579, 31772,-11825,-15590,-23089, >+ 17173,-25903,-17387, 3285, 4884, 10204,-16627,-14367, 516, >+ 20453,-16898, 20967,-23815, -20, 22011,-17167, 9468, 32499, >+ -25607, -523, -3883, -390, -4206, 634, -3767, 2325, -2751, >+ 3115, -2392, 2746, -2173, 2317, -1147, 2326, 23142, 11314, >+ -15130,-29137, 3026, 6146, 2150, 2476, 1105, -830, 1775, >+ -3425, 3674, -5287, 4609, -7175, 4922, -9579, 4556,-12007, >+ 4236,-14023, 3879,-15553, 3158,-16161, 2576, 18398,-12535, >+ -6645,-20735,-32763,-13824,-20992, 25859, 5372, 12040, 13307, >+ -4355,-30213, -9, -6019, 14061,-31487,-13842, 30449, 15083, >+ 14088, 31205,-18678,-12830, 14090,-26138,-25337,-11541, -3254, >+ 27628,-22270, 30953,-16136,-30745, 20991,-17406, 5632,-14330, >+ 28911,-25594, 17408,-20474, 13041, -8731, 2292, -3860, 24049, >+ 10225,-19220, 10478, -4374, -1199, 148, -330, -74, 593, >+ 188, 1558, -4152, 15984, 15934, 15934, 15934, 15934, 15934, >+ 15934, 15934, 15934, 15934, 15934, 15934, 1598, 156, 1604, >+ -1163, 2278,-30018,-25821,-21763,-23776, 24066, 9502, 25866, >+ -25055, 10004,-24798, 7204, -4581, -9678, 1554, 10553, 3102, >+ 12193, 2443, 11955, 1213, 10689, -1293, 921, -4173, 8661, >+ -6049, 8815,-21221,-14854, 23840, -9477, 8549, 5278, 8743, >+ 9375, 6940, 13038, 4826, 14598, 7721,-24308,-29905,-19703, >+ -17106,-16124, -3287,-26118,-19709,-10769, 24361, 28648, 10274, >+ -11292,-29665,-16417, 24346, 14580, 18707, 26323, -4410,-17711, >+ 5133, 26328,-14579,-31008, 24583, 18404, 28417,-24350, 19453, >+ 28642,-32513,-10777, -3079, 30188, -7686, 27635,-32521,-16384, >+ -20240, -6386, 10986, 23827,-25880,-32752,-23321, 14605, 32231, >+ 780,-13849, 15119, 28647, 4888, -7705, 30750, 64, 0, >+ 32488, 6687,-20758, 19745, -2070, -1, -1, 28, 256, >+ -4608, 7168, 7444, 23557,-21998, 13064, 3345, -4086,-28915, >+ -8594, 32262, 8461, 27387,-12275, 12012, 23563,-18719,-28410, >+ 29144,-22271,-32562,-16384, 12528, -6386, 10986, 23827,-25880, >+ -32752,-23321, 14605, 32231, 780,-13849, 15119, 28647, 4888, >+ -7705, 30750, 64, 0, 32488, 6687,-20758, 19745, -2070, >+ -13792, -6414, 28188, -2821, -4585, 7168, 7444, 23557,-21998, >+ 13064, 3345, -4086,-28915, -8694, 32262, 8461, 27387,-12275, >+ 12012, 23563,-18719,-28410, 29144,-22271, -562, -9986, -5434, >+ 12288, -2107,-16643, 32452, 29182, 32705,-30723, 24255,-19716, >+ 18368, -4357, -5696, 2804, 12992,-22802,-22080, -7701, -5183, >+ 486, -3133, -5660, -1083, 16871,-28726,-11029,-30259, -1209, >+ -16146, -2839,-16374, -4558,-16218,-10523, 20697, -9500, -1316, >+ 5431, -1073, 3641, -1304, 1649, -769, -7276, 2856, -7870, >+ 3314, -8730, 3964,-10183, 4011,-11135, 3421,-11727, 21398, >+ 32767, -1, 32486, -1, -99,-13072, 6380, -7948, 4864, >+ 32767, 17392, 14335, -5646, 30973, -3598,-10299,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14905,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-19771,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-16443,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-15931,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907, -1,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907, 7877, 7710, 7710, 7710, 7710, 7710, 7710, >+ 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, >+ 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, >+ 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, >+ 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, >+ 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, >+ 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, >+ 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, >+ 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, >+ 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, >+ 7710, 7710, 7710, 7710, 7710, -994, -7276, 2856, -7870, >+ 3314, -8730, 3964,-10183, 4011,-11135, 3421,-11727, 21398, >+ 32767, -1, 32486, -1, -99,-13072, 6380, -7948, 4864, >+ 32767, 17392, 14335, -5646, 30973, -3598,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14905,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907, 197, 0,-14977,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907, 12838, 6653, 294, >+ -29699,-25821,-21763,-23776, 24066, 9502, 25866,-25055, 10004, >+ -24798, 7204, -4581, -9678, 1554, 10553, 3102, 12193, 2443, >+ 11955, 1213, 10689, -1293, 921, 179, 8448, -6049, 8815, >+ -7128, 8147, -8308, 6847, -9889, 4920,-11447, 3174,-11794, >+ 3514,-10220, 3430, 16384, 1926, -7072, 327, -7537, -608, >+ -7605, -1169, -6397, -1579, -4877, -1419, -3103, -2197, 128, >+ -3904, 3632, -5401, 4906, -6051, 4250, -6272, 3492, -6343, >+ 3197, -6397, 4041, -6341, 6255, -6381, 7905, 16504, 0, >+ -6144, 8062, -5606, 8622, -5555, 8439, -3382, 7398, -1170, >+ 6132, 238, 5148, 1309, 4700, 2218, 4403, 2573, 3568, >+ 2703, 1758, 3454, -1247, 3434, -4912, 2862, -7844, 1718, >+ -10095, 369,-12631, -259,-14632, 234,-15056, -491,-16194, >+ -386,-16015, -641,-16505, -930,-16206, -1209,-16146, -2839, >+ -16374, -4558,-16218, -5207,-15903, -6421,-15615, -6925,-14871, >+ -6149,-13759, -5233,-12844, 18313, -4357, -5696, 2804, 12992, >+ -22802, -6720, -9770, -7088, -8998, 14330,-12523, 14843, -6130, >+ 29178, -250,-27396, 10467, 16907, -3359, -6644, 31965, 14607, >+ -21544,-32497, 24020, 12557,-26926, -173, -129, -6401, -130, >+ -25089, -3816, -4916, -3048, -32, -1, -3969, 256, -3529, >+ -535, -3464,-14863,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -1209,-16146, -2839,-16374, -4558,-16218,-10523, 20697, -9500, >+ -1316, 5431, -1073, 3641, -1304, 1649, -769, -7276, 2856, >+ -7870, 3314, -8730, 3964,-10183, 4011,-11135, 3421,-11727, >+ 21398, 32767, -1, 32486, -1, 6301,-13071, 6380, -7948, >+ -1, 32767, 240, 14081, -5646, 30973, -3598,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ 32767,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907, 8901, 9375, 6940, >+ 13038, 4826, 14598, 7721,-24308,-29905,-19703,-17106,-16124, >+ -3287,-26118,-19709,-10769, 24361, 28648, 10274,-11292,-29665, >+ -16417, 24346, 14580, 18707, 26323, -4440,-17711, 5133, 26328, >+ -14579,-31008, 24583, 18404, 28417,-24350, 19453, 28642,-32513, >+ -10777, -3079, 30188, -7686, 27635,-32521,-16384,-20240, -6386, >+ 10986, 23827,-25880,-32752,-23321, 14605, 32231, 780,-13849, >+ 15119, 28647, 4888, -7705,-15074,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, 8192, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14897, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-15931,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907, 26121, 12890, 2604, 12228,-11634, 12299, 5573, >+ -16642, 32452, 29182, 32705,-30723, 24255,-19716, 13248,-11779, >+ -5696, 2804, 12992,-27666,-22080, -7701, -5183, -6682,-31464, >+ 14330,-12523, 14843, -6130, 29178, -18,-27396, 10467, 16907, >+ -3359, -6644, 31965, 14607,-21544,-32497, 24020, 12557,-26926, >+ -18421, 706, 24587, 19659, 4878, 10954, 23060, 8907,-10215, >+ -22579, 31772,-11825,-15590,-23089, 17173,-25903,-17387, 3285, >+ 4884, 10204,-16627,-14367, 516, 20453,-16898, 20967,-23815, >+ -20, 22011,-17167, 9468, 32499,-25607, -523, -3883, -390, >+ -4206, 634, -3767, 2325, -2751, 3115, -2392, 2746, -2173, >+ 2317, -1147, 2326, 23142, 11314,-15130,-29137, 3026, 6146, >+ 2150, 2476, 1105, -830, 1775, -3425, 3674, -5287, 4609, >+ -7175, 4922, -9579, 4556,-12007, 4236,-14023, 3879,-15553, >+ 3158,-16161, 2576, 18398,-12535, -6645,-20735,-32763,-13824, >+ -20992, 25859, 5372, 12040, 13307, -4355,-30213, -9, -6019 >+ }; >+ err = opus_multistream_encode(enc, pcm, 960, data, 7380); >+ assert(err > 0); >+ } >+ opus_multistream_encoder_ctl(enc, OPUS_SET_SIGNAL(OPUS_SIGNAL_MUSIC)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_VBR(1)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_VBR_CONSTRAINT(0)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_PREDICTION_DISABLED(1)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_FORCE_CHANNELS(OPUS_AUTO)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_PHASE_INVERSION_DISABLED(1)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_DTX(1)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_COMPLEXITY(6)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_MAX_BANDWIDTH(OPUS_BANDWIDTH_NARROWBAND)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_BANDWIDTH(OPUS_AUTO)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_LSB_DEPTH(9)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_INBAND_FEC(1)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_PACKET_LOSS_PERC(5)); >+ opus_multistream_encoder_ctl(enc, OPUS_SET_BITRATE(775410)); >+ { >+ static const short pcm[1440*3] = >+ { >+ 30449, 15083, 14088, 31205,-18678,-12830, 14090,-26138,-25337, >+ -11541, -3254, 27628,-22270, 30953,-16136,-30745, 20991,-17406, >+ 5632,-14330, 28911,-25594, 17408,-20474, 13041, -8731, 2292, >+ -3860, 24049, 10225,-19220, 10478, -4374, -1199, 148, -330, >+ -74, 593, 188, 1558, -4152, 15984, 15934, 15934, 15934, >+ 15934, 15934, 15934, 15934, 15934, 15934, 15934, 15934, 1598, >+ 156, 1604, -1163, 2278,-30018,-25821,-21763,-23776, 24066, >+ 9502, 25866,-25055, 10004,-24798, 7204, -4581, -9678, 1554, >+ 10553, 3102, 12193, 2443, 11955, 1213, 10689, -1293, 921, >+ -4173, 8661, -6049, 8815,-21221,-14854, 23840, -9477, 8549, >+ 5278, 8743, 9375, 6940, 13038, 4826, 14598, 7721,-24308, >+ -29905,-19703,-17106,-16124, -3287,-26118,-19709,-10769, 24361, >+ 28648, 10274,-11292,-29665,-16417, 24346, 14580, 18707, 26323, >+ -4410,-17711, 5133, 26328,-14579,-31008, 24583, 18404, 28417, >+ -24350, 19453, 28642,-32513,-10777, -3079, 30188, -7686, 27635, >+ -32521,-16384,-20240, -6386, 10986, 23827,-25880,-32752,-23321, >+ 14605, 32231, 780,-13849, 15119, 28647, 4888, -7705, 30750, >+ 64, 0, 32488, 6687,-20758, 19745, -2070, -1, -1, >+ 28, 256, -4608, 7168, 7444, 23557,-21998, 13064, 3345, >+ -4086,-28915, -8594, 32262, 8461, 27387,-12275, 12012, 23563, >+ -18719,-28410, 29144,-22271,-32562,-16384, 12528, -6386, 10986, >+ 23827,-25880,-32752,-23321, 14605, 32231, 780,-13849, 15119, >+ 28647, 4888, -7705, 30750, 64, 0, 32488, 6687,-20758, >+ 19745, -2070,-13792, -6414, 28188, -2821, -4585, 7168, 7444, >+ 23557,-21998, 13064, 3345, -4086,-28915, -8694, 32262, 8461, >+ -14853,-14907,-14907,-14907,-14907, 32767,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14891,-14907,-14907,-14907, >+ -14907,-14907, 8901, 9375, 6940, 13038, 4826, 14598, 7721, >+ -24308,-29905,-19703,-17106,-16124, -3287,-26118,-19709,-10769, >+ 24361, 28648, 10274,-11292,-29665,-16417, 24346, 14580, 18707, >+ 26323, -4440,-17711, 5133, 26328,-14579,-31008, 24583, 18404, >+ 28417,-24350, 19453, 28642,-32513,-10777, -3079, 30188, -7686, >+ 27635,-32521,-16384,-20240, -6386, 10986, 23827,-25880,-32752, >+ -23321, 14605, 32231, 780,-13849, 15119, 28647, 4888, -7705, >+ -15074,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907, 8192,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14897,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-15931,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907, 26121, 12890, >+ 2604, 12228,-11634, 12299, 5573,-16642, 32452, 29182, 7710, >+ 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, >+ 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, >+ 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, >+ 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, >+ 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, >+ 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, >+ 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, >+ 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, >+ 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, >+ 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, >+ 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, >+ 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, >+ 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, >+ 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, >+ 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, >+ 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, >+ 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, >+ 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, >+ 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, >+ 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, >+ 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, >+ 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, >+ 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, >+ 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, 7710, >+ 7710,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-10811,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14917,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14938,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907,-14907, >+ -14907,-14907,-14907,-14907, -571, -9986, -58, 12542,-18491, >+ 32507, 12838, 6653, 294, -1, 0,-19968, 18368, -4357, >+ -5696, 2804, 12998,-22802,-22080, -7701, -5183, 486, -3133, >+ -5660, -1083, 13799,-28726,-11029, 205,-14848, 32464, -1, >+ -129,-13072, 6380, -7948, 20717, 18425, 17392, 14335, -5646, >+ 30973, -3598, 7188, -3867, 3055, -4247, 5597, -4011,-26427, >+ -11,-30418, 7922, 2614, 237, -5839,-27413,-17624,-29716, >+ -13539, 239, 20991, 18164, -4082,-16647,-27386, 19458, 20224, >+ 4619, 19728, -7409,-18186,-25073, 27627,-23539, -7945,-31464, >+ 14330,-12523,-22021, -7701, -5183, 486, -3133, -5660, -1083, >+ 13799,-28726,-11029, 205,-14848, 32464, -1, -129,-13072, >+ 6380, -7948, 20717, 18425, 17392, 14093, -5646, 30973, -3598, >+ 7188, -3867, 3055, 3689, -5401, 4906, -6051, 4250, -6272, >+ 3492, -6343, 3197, -6397, 4041, -6341, 6255, -6381, 239, >+ 20991, 18164, -4082,-16647,-27386, 19458, 20224, 4619, 19728, >+ -7409,-18186,-25073, 27627,-23539, -7945,-31464, 14330,-12523, >+ 14843, -6130, 30202, -250,-28420, 10467, 16907, -3359, -6644, >+ 31965, 3343,-11727, 2966,-12616, 3064,-13472, 6732,-12349, >+ 5541,-11965, 5530,-10820, -1912, -3637, 32285, -4607, 310, >+ -32768, 0, -5258, 2106, -6857, 2681, -5449, -3606, -6717, >+ -5482, -3606, -1853, 4082, -7631, -9808, -1742, -2851, -5112, >+ 64, -868,-13546,-13365,-13365,-13365,-13365,-13365,-13365, >+ -13365,-13365,-13365,-13365,-13365,-13365,-13365,-13365,-13365, >+ -13365,-13365,-13365,-13365,-13365,-13365,-13365,-13365,-13365, >+ -13365,-13365,-13365,-13365,-13365,-13365,-13365,-13365,-13365, >+ -13365,-13365,-13365,-13365,-13365,-13365,-13365, 7883, -2316, >+ 9086, -3944, 10500, 4285, 10459, -6474, 10204, -6539, 11601, >+ -6824, 13385, -7142, 13872, -7457, 13670, -7725, 13463, -6887, >+ 12482, -5580, 12600, -4964, 12480, 3254, 11741, -4210,-24819, >+ 23282, 22798, 491, -1774, -1073, 3641, -1304, 28928, -250, >+ -27396, 6657, -8961, 22524, 19987, 10231, 1791, 8947,-32763, >+ -26385,-31227, -792,-30461, 8926, 4866, 27863, 27756, 27756, >+ 27756, 27756, 27756, 27756, 27756, 27756, 5630,-11070,-16136, >+ 20671,-11530, 27328, 8179, 5059,-31503,-24379,-19472, 17863, >+ -29202, 22986, -23, 8909, 8422, 10450 >+ }; >+ err = opus_multistream_encode(enc, pcm, 1440, data, 7380); >+ /* reads uninitialized data at src/opus_multistream_encoder.c:293 */ >+ assert(err > 0); >+ } >+ opus_multistream_encoder_destroy(enc); >+ return 0; >+} >+ >+static int ec_enc_shrink_assert(void) >+{ >+ OpusEncoder *enc; >+ int err; >+ int data_len; >+ unsigned char data[2000]; >+ static const short pcm1[960] = { 5140 }; >+ static const short pcm2[2880] = >+ { >+ -256,-12033, 0, -2817, 6912, 0, -5359, 5200, 3061, >+ 0, -2903, 5652, -1281,-24656,-14433,-24678, 32,-29793, >+ 2870, 0, 4096, 5120, 5140, -234,-20230,-24673,-24633, >+ -24673,-24705, 0,-32768,-25444,-25444, 0,-25444,-25444, >+ 156,-20480, -7948, -5920, -7968, -7968, 224, 0, 20480, >+ 11, 20496, 13, 20496, 11,-20480, 2292,-20240, 244, >+ 20480, 11, 20496, 11,-20480, 244,-20240, 7156, 20456, >+ -246,-20243, 244, 128, 244, 20480, 11, 20496, 11, >+ -20480, 244,-20256, 244, 20480, 256, 0, -246, 16609, >+ -176, 0, 29872, -4096, -2888, 516, 2896, 4096, 2896, >+ -20480, -3852, -2896, -1025,-31056,-14433, 244, 1792, -256, >+ -12033, 0, -2817, 0, 0, -5359, 5200, 3061, 16, >+ -2903, 5652, -1281,-24656,-14433,-24678, 32,-29793, 2870, >+ 0, 4096, 5120, 5140, -234,-20230,-24673,-24633,-24673, >+ -24705, 0,-32768,-25444,-25444, 0,-25444,-25444, 156, >+ -20480, -7973, -5920, -7968, -7968, 224, 0, 20480, 11, >+ 20496, 11, 20496, 11,-20480, 2292,-20213, 244, 20480, >+ 11, 20496, 11,-24698, -2873, 0, 7, -1, 208, >+ -256, 244, 0, 4352, 20715, -2796, 11,-22272, 5364, >+ -234,-20230,-24673,-25913, 8351,-24832, 13963, 11, 0, >+ 16, 5140, 5652, -1281,-24656,-14433,-24673, 32671, 159, >+ 0,-25472,-25444, 156,-25600,-25444,-25444, 0, -2896, >+ -7968, -7960, -7968, -7968, 0, 0, 2896, 4096, 2896, >+ 4096, 2896, 0, -2896, -4088, -2896, 0, 2896, 0, >+ -2896, -4096, -2896, 11, 2640, -4609, -2896,-32768, -3072, >+ 0, 2896, 4096, 2896, 0, -2896, -4096, -2896, 0, >+ 80, 1, 2816, 0, 20656, 255,-20480, 116,-18192 >+ }; >+ static const short pcm3[2880] = { 0 }; >+ >+ enc = opus_encoder_create(48000, 1, OPUS_APPLICATION_AUDIO, &err); >+ opus_encoder_ctl(enc, OPUS_SET_COMPLEXITY(10)); >+ opus_encoder_ctl(enc, OPUS_SET_PACKET_LOSS_PERC(6)); >+ opus_encoder_ctl(enc, OPUS_SET_BITRATE(6000)); >+ data_len = opus_encode(enc, pcm1, 960, data, 2000); >+ assert(data_len > 0); >+ >+ opus_encoder_ctl(enc, OPUS_SET_SIGNAL(OPUS_SIGNAL_VOICE)); >+ opus_encoder_ctl(enc, OPUS_SET_PREDICTION_DISABLED(1)); >+ opus_encoder_ctl(enc, OPUS_SET_BANDWIDTH(OPUS_BANDWIDTH_SUPERWIDEBAND)); >+ opus_encoder_ctl(enc, OPUS_SET_INBAND_FEC(1)); >+ opus_encoder_ctl(enc, OPUS_SET_BITRATE(15600)); >+ data_len = opus_encode(enc, pcm2, 2880, data, 122); >+ assert(data_len > 0); >+ >+ opus_encoder_ctl(enc, OPUS_SET_SIGNAL(OPUS_SIGNAL_MUSIC)); >+ opus_encoder_ctl(enc, OPUS_SET_BITRATE(27000)); >+ data_len = opus_encode(enc, pcm3, 2880, data, 122); /* assertion failure */ >+ assert(data_len > 0); >+ >+ opus_encoder_destroy(enc); >+ return 0; >+} >+ >+static int ec_enc_shrink_assert2(void) >+{ >+ OpusEncoder *enc; >+ int err; >+ int data_len; >+ unsigned char data[2000]; >+ >+ enc = opus_encoder_create(48000, 1, OPUS_APPLICATION_AUDIO, &err); >+ opus_encoder_ctl(enc, OPUS_SET_COMPLEXITY(6)); >+ opus_encoder_ctl(enc, OPUS_SET_SIGNAL(OPUS_SIGNAL_VOICE)); >+ opus_encoder_ctl(enc, OPUS_SET_BANDWIDTH(OPUS_BANDWIDTH_FULLBAND)); >+ opus_encoder_ctl(enc, OPUS_SET_PACKET_LOSS_PERC(26)); >+ opus_encoder_ctl(enc, OPUS_SET_BITRATE(27000)); >+ { >+ static const short pcm[960] = { 0 }; >+ data_len = opus_encode(enc, pcm, 960, data, 2000); >+ assert(data_len > 0); >+ } >+ opus_encoder_ctl(enc, OPUS_SET_SIGNAL(OPUS_SIGNAL_MUSIC)); >+ { >+ static const short pcm[480] = >+ { >+ 32767, 32767, 0, 0, 32767, 32767, 0, 0, 32767, 32767, >+ -32768, -32768, 0, 0, -32768, -32768, 0, 0, -32768, -32768 >+ }; >+ data_len = opus_encode(enc, pcm, 480, data, 19); >+ assert(data_len > 0); >+ } >+ opus_encoder_destroy(enc); >+ return 0; >+} >+ >+static int silk_gain_assert(void) >+{ >+ OpusEncoder *enc; >+ int err; >+ int data_len; >+ unsigned char data[1000]; >+ static const short pcm1[160] = { 0 }; >+ static const short pcm2[960] = >+ { >+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, >+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, >+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, >+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, >+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, >+ 32767, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, >+ 0, 0, 0, 0, 32767 >+ }; >+ >+ enc = opus_encoder_create(8000, 1, OPUS_APPLICATION_AUDIO, &err); >+ opus_encoder_ctl(enc, OPUS_SET_COMPLEXITY(3)); >+ opus_encoder_ctl(enc, OPUS_SET_MAX_BANDWIDTH(OPUS_BANDWIDTH_NARROWBAND)); >+ opus_encoder_ctl(enc, OPUS_SET_BITRATE(6000)); >+ data_len = opus_encode(enc, pcm1, 160, data, 1000); >+ assert(data_len > 0); >+ >+ opus_encoder_ctl(enc, OPUS_SET_VBR(0)); >+ opus_encoder_ctl(enc, OPUS_SET_COMPLEXITY(0)); >+ opus_encoder_ctl(enc, OPUS_SET_MAX_BANDWIDTH(OPUS_BANDWIDTH_MEDIUMBAND)); >+ opus_encoder_ctl(enc, OPUS_SET_BITRATE(2867)); >+ data_len = opus_encode(enc, pcm2, 960, data, 1000); >+ assert(data_len > 0); >+ >+ opus_encoder_destroy(enc); >+ return 0; >+} >+ >+void regression_test(void) >+{ >+ fprintf(stderr, "Running simple tests for bugs that have been fixed previously\n"); >+ celt_ec_internal_error(); >+ mscbr_encode_fail10(); >+ mscbr_encode_fail(); >+ surround_analysis_uninit(); >+ ec_enc_shrink_assert(); >+ ec_enc_shrink_assert2(); >+ silk_gain_assert(); >+} >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/tests/run_vectors.sh b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/tests/run_vectors.sh >index 1d447c43f5967706bd309ebbf22038a1f3a11f25..dcb76cf1879ef0801d5a5c33fc676ed79bf41e87 100755 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/tests/run_vectors.sh >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/tests/run_vectors.sh >@@ -33,8 +33,8 @@ > # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS > # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > >-rm logs_mono.txt >-rm logs_stereo.txt >+rm -f logs_mono.txt logs_mono2.txt >+rm -f logs_stereo.txt logs_stereo2.txt > > if [ "$#" -ne "3" ]; then > echo "usage: run_vectors.sh <exec path> <vector path> <rate>" >@@ -48,51 +48,53 @@ RATE=$3 > : ${OPUS_DEMO:=$CMD_PATH/opus_demo} > : ${OPUS_COMPARE:=$CMD_PATH/opus_compare} > >-if [ -d $VECTOR_PATH ]; then >- echo Test vectors found in $VECTOR_PATH >+if [ -d "$VECTOR_PATH" ]; then >+ echo "Test vectors found in $VECTOR_PATH" > else >- echo No test vectors found >+ echo "No test vectors found" > #Don't make the test fail here because the test vectors > #will be distributed separately > exit 0 > fi > >-if [ ! -x $OPUS_COMPARE ]; then >- echo ERROR: Compare program not found: $OPUS_COMPARE >+if [ ! -x "$OPUS_COMPARE" ]; then >+ echo "ERROR: Compare program not found: $OPUS_COMPARE" > exit 1 > fi > >-if [ -x $OPUS_DEMO ]; then >- echo Decoding with $OPUS_DEMO >+if [ -x "$OPUS_DEMO" ]; then >+ echo "Decoding with $OPUS_DEMO" > else >- echo ERROR: Decoder not found: $OPUS_DEMO >+ echo "ERROR: Decoder not found: $OPUS_DEMO" > exit 1 > fi > > echo "==============" >-echo Testing mono >+echo "Testing mono" > echo "==============" > echo > > for file in 01 02 03 04 05 06 07 08 09 10 11 12 > do >- if [ -e $VECTOR_PATH/testvector$file.bit ]; then >- echo Testing testvector$file >+ if [ -e "$VECTOR_PATH/testvector$file.bit" ]; then >+ echo "Testing testvector$file" > else >- echo Bitstream file not found: testvector$file.bit >+ echo "Bitstream file not found: testvector$file.bit" > fi >- if $OPUS_DEMO -d $RATE 1 $VECTOR_PATH/testvector$file.bit tmp.out >> logs_mono.txt 2>&1; then >- echo successfully decoded >+ if "$OPUS_DEMO" -d "$RATE" 1 "$VECTOR_PATH/testvector$file.bit" tmp.out >> logs_mono.txt 2>&1; then >+ echo "successfully decoded" > else >- echo ERROR: decoding failed >+ echo "ERROR: decoding failed" > exit 1 > fi >- $OPUS_COMPARE -r $RATE $VECTOR_PATH/testvector$file.dec tmp.out >> logs_mono.txt 2>&1 >+ "$OPUS_COMPARE" -r "$RATE" "$VECTOR_PATH/testvector${file}.dec" tmp.out >> logs_mono.txt 2>&1 > float_ret=$? >- if [ "$float_ret" -eq "0" ]; then >- echo output matches reference >+ "$OPUS_COMPARE" -r "$RATE" "$VECTOR_PATH/testvector${file}m.dec" tmp.out >> logs_mono2.txt 2>&1 >+ float_ret2=$? >+ if [ "$float_ret" -eq "0" ] || [ "$float_ret2" -eq "0" ]; then >+ echo "output matches reference" > else >- echo ERROR: output does not match reference >+ echo "ERROR: output does not match reference" > exit 1 > fi > echo >@@ -105,23 +107,25 @@ echo > > for file in 01 02 03 04 05 06 07 08 09 10 11 12 > do >- if [ -e $VECTOR_PATH/testvector$file.bit ]; then >- echo Testing testvector$file >+ if [ -e "$VECTOR_PATH/testvector$file.bit" ]; then >+ echo "Testing testvector$file" > else >- echo Bitstream file not found: testvector$file >+ echo "Bitstream file not found: testvector$file" > fi >- if $OPUS_DEMO -d $RATE 2 $VECTOR_PATH/testvector$file.bit tmp.out >> logs_stereo.txt 2>&1; then >- echo successfully decoded >+ if "$OPUS_DEMO" -d "$RATE" 2 "$VECTOR_PATH/testvector$file.bit" tmp.out >> logs_stereo.txt 2>&1; then >+ echo "successfully decoded" > else >- echo ERROR: decoding failed >+ echo "ERROR: decoding failed" > exit 1 > fi >- $OPUS_COMPARE -s -r $RATE $VECTOR_PATH/testvector$file.dec tmp.out >> logs_stereo.txt 2>&1 >+ "$OPUS_COMPARE" -s -r "$RATE" "$VECTOR_PATH/testvector${file}.dec" tmp.out >> logs_stereo.txt 2>&1 > float_ret=$? >- if [ "$float_ret" -eq "0" ]; then >- echo output matches reference >+ "$OPUS_COMPARE" -s -r "$RATE" "$VECTOR_PATH/testvector${file}m.dec" tmp.out >> logs_stereo2.txt 2>&1 >+ float_ret2=$? >+ if [ "$float_ret" -eq "0" ] || [ "$float_ret2" -eq "0" ]; then >+ echo "output matches reference" > else >- echo ERROR: output does not match reference >+ echo "ERROR: output does not match reference" > exit 1 > fi > echo >@@ -129,6 +133,11 @@ done > > > >-echo All tests have passed successfully >-grep quality logs_mono.txt | awk '{sum+=$4}END{print "Average mono quality is", sum/NR, "%"}' >-grep quality logs_stereo.txt | awk '{sum+=$4}END{print "Average stereo quality is", sum/NR, "%"}' >+echo "All tests have passed successfully" >+mono1=`grep quality logs_mono.txt | awk '{sum+=$4}END{if (NR == 12) sum /= 12; else sum = 0; print sum}'` >+mono2=`grep quality logs_mono2.txt | awk '{sum+=$4}END{if (NR == 12) sum /= 12; else sum = 0; print sum}'` >+echo $mono1 $mono2 | awk '{if ($2 > $1) $1 = $2; print "Average mono quality is", $1, "%"}' >+ >+stereo1=`grep quality logs_stereo.txt | awk '{sum+=$4}END{if (NR == 12) sum /= 12; else sum = 0; print sum}'` >+stereo2=`grep quality logs_stereo2.txt | awk '{sum+=$4}END{if (NR == 12) sum /= 12; else sum = 0; print sum}'` >+echo $stereo1 $stereo2 | awk '{if ($2 > $1) $1 = $2; print "Average stereo quality is", $1, "%"}' >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/tests/test_opus_api.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/tests/test_opus_api.c >index 489052d21fb30bb8b0ff9c33cefff0f1a500feda..1d0095058f80a1213b015561984c3bcc7cf8e542 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/tests/test_opus_api.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/tests/test_opus_api.c >@@ -1383,6 +1383,15 @@ opus_int32 test_enc_api(void) > err=opus_encoder_ctl(enc,OPUS_SET_EXPERT_FRAME_DURATION(OPUS_FRAMESIZE_60_MS)); > if(err!=OPUS_OK)test_failed(); > cfgs++; >+ err=opus_encoder_ctl(enc,OPUS_SET_EXPERT_FRAME_DURATION(OPUS_FRAMESIZE_80_MS)); >+ if(err!=OPUS_OK)test_failed(); >+ cfgs++; >+ err=opus_encoder_ctl(enc,OPUS_SET_EXPERT_FRAME_DURATION(OPUS_FRAMESIZE_100_MS)); >+ if(err!=OPUS_OK)test_failed(); >+ cfgs++; >+ err=opus_encoder_ctl(enc,OPUS_SET_EXPERT_FRAME_DURATION(OPUS_FRAMESIZE_120_MS)); >+ if(err!=OPUS_OK)test_failed(); >+ cfgs++; > CHECK_SETGET(OPUS_SET_EXPERT_FRAME_DURATION(i),OPUS_GET_EXPERT_FRAME_DURATION(&i),0,-1, > OPUS_FRAMESIZE_60_MS,OPUS_FRAMESIZE_ARG, > " OPUS_SET_EXPERT_FRAME_DURATION ............... OK.\n", >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/tests/test_opus_common.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/tests/test_opus_common.h >index 66b969001893c988c8cede3a5e29b0f03cd0d62b..235cf1c101689110a00135bbce2c3a2b51fda0b4 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/tests/test_opus_common.h >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/tests/test_opus_common.h >@@ -64,6 +64,8 @@ static opus_uint32 iseed; > > #ifdef __GNUC__ > __attribute__((noreturn)) >+#elif defined(_MSC_VER) >+__declspec(noreturn) > #endif > static OPUS_INLINE void _test_failed(const char *file, int line) > { >@@ -76,3 +78,5 @@ static OPUS_INLINE void _test_failed(const char *file, int line) > abort(); > } > #define test_failed() _test_failed(__FILE__, __LINE__); >+ >+void regression_test(void); >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/tests/test_opus_decode.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/tests/test_opus_decode.c >index 9c0eb9c72858d5a8f4dc4da6b9f31eb2caebc41e..5197fa1dd2cf10b5e5037d2b2153d6ef664477b7 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/tests/test_opus_decode.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/tests/test_opus_decode.c >@@ -104,7 +104,7 @@ int test_decoder_code0(int no_fuzz) > int factor=48000/fsv[t>>1]; > for(fec=0;fec<2;fec++) > { >- int dur; >+ opus_int32 dur; > /*Test PLC on a fresh decoder*/ > out_samples = opus_decode(dec[t], 0, 0, outbuf, 120/factor, fec); > if(out_samples!=120/factor)test_failed(); >@@ -135,7 +135,14 @@ int test_decoder_code0(int no_fuzz) > outbuf[0]=32749; > out_samples = opus_decode(dec[t], packet, 0, outbuf, 0, fec); > if(out_samples>0)test_failed(); >+#if !defined(OPUS_BUILD) && (OPUS_GNUC_PREREQ(4, 6) || (defined(__clang_major__) && __clang_major__ >= 3)) >+#pragma GCC diagnostic push >+#pragma GCC diagnostic ignored "-Wnonnull" >+#endif > out_samples = opus_decode(dec[t], packet, 0, 0, 0, fec); >+#if !defined(OPUS_BUILD) && (OPUS_GNUC_PREREQ(4, 6) || (defined(__clang_major__) && __clang_major__ >= 3)) >+#pragma GCC diagnostic pop >+#endif > if(out_samples>0)test_failed(); > if(outbuf[0]!=32749)test_failed(); > >@@ -160,7 +167,7 @@ int test_decoder_code0(int no_fuzz) > /*Count code 0 tests*/ > for(i=0;i<64;i++) > { >- int dur; >+ opus_int32 dur; > int j,expected[5*2]; > packet[0]=i<<2; > packet[1]=255; >@@ -314,7 +321,7 @@ int test_decoder_code0(int no_fuzz) > if(opus_decode(decbak, 0, 0, outbuf, MAX_FRAME_SAMP, 0)<20)test_failed(); > for(t=0;t<5*2;t++) > { >- int dur; >+ opus_int32 dur; > out_samples = opus_decode(dec[t], packet, plen+1, outbuf, MAX_FRAME_SAMP, 0); > if(out_samples!=expected[t])test_failed(); > if(t==0)dec_final_range2=dec_final_range1; >@@ -384,26 +391,26 @@ void test_soft_clip(void) > { > for (j=0;j<1024;j++) > { >- x[j]=(i&255)*(1/32.f)-4.f; >+ x[j]=(j&255)*(1/32.f)-4.f; > } > opus_pcm_soft_clip(&x[i],1024-i,1,s); > for (j=i;j<1024;j++) > { >- if(x[i]>1.f)test_failed(); >- if(x[i]<-1.f)test_failed(); >+ if(x[j]>1.f)test_failed(); >+ if(x[j]<-1.f)test_failed(); > } > } > for(i=1;i<9;i++) > { > for (j=0;j<1024;j++) > { >- x[j]=(i&255)*(1/32.f)-4.f; >+ x[j]=(j&255)*(1/32.f)-4.f; > } > opus_pcm_soft_clip(x,1024/i,i,s); > for (j=0;j<(1024/i)*i;j++) > { >- if(x[i]>1.f)test_failed(); >- if(x[i]<-1.f)test_failed(); >+ if(x[j]>1.f)test_failed(); >+ if(x[j]<-1.f)test_failed(); > } > } > opus_pcm_soft_clip(x,0,1,s); >@@ -436,7 +443,7 @@ int main(int _argc, char **_argv) > iseed=atoi(env_seed); > env_used=1; > } >- else iseed=(opus_uint32)time(NULL)^((getpid()&65535)<<16); >+ else iseed=(opus_uint32)time(NULL)^(((opus_uint32)getpid()&65535)<<16); > Rw=Rz=iseed; > > oversion=opus_get_version_string(); >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/tests/test_opus_encode.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/tests/test_opus_encode.c >index 132d074d3025456f9d2297e7988e85ac51610b85..dae49c3d5351bd556c03d74ed8ae69c21952062a 100644 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/tests/test_opus_encode.c >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/tests/test_opus_encode.c >@@ -51,8 +51,8 @@ > #define SAMPLES (48000*30) > #define SSAMPLES (SAMPLES/3) > #define MAX_FRAME_SAMP (5760) >- > #define PI (3.141592653589793238462643f) >+#define RAND_SAMPLE(a) (a[fast_rand() % sizeof(a)/sizeof(a[0])]) > > void generate_music(short *buf, opus_int32 len) > { >@@ -112,14 +112,169 @@ static OPUS_INLINE void save_packet(unsigned char* p, int len, opus_uint32 rng) > } > #endif > >+int get_frame_size_enum(int frame_size, int sampling_rate) >+{ >+ int frame_size_enum; >+ >+ if(frame_size==sampling_rate/400) >+ frame_size_enum = OPUS_FRAMESIZE_2_5_MS; >+ else if(frame_size==sampling_rate/200) >+ frame_size_enum = OPUS_FRAMESIZE_5_MS; >+ else if(frame_size==sampling_rate/100) >+ frame_size_enum = OPUS_FRAMESIZE_10_MS; >+ else if(frame_size==sampling_rate/50) >+ frame_size_enum = OPUS_FRAMESIZE_20_MS; >+ else if(frame_size==sampling_rate/25) >+ frame_size_enum = OPUS_FRAMESIZE_40_MS; >+ else if(frame_size==3*sampling_rate/50) >+ frame_size_enum = OPUS_FRAMESIZE_60_MS; >+ else if(frame_size==4*sampling_rate/50) >+ frame_size_enum = OPUS_FRAMESIZE_80_MS; >+ else if(frame_size==5*sampling_rate/50) >+ frame_size_enum = OPUS_FRAMESIZE_100_MS; >+ else if(frame_size==6*sampling_rate/50) >+ frame_size_enum = OPUS_FRAMESIZE_120_MS; >+ else >+ test_failed(); >+ >+ return frame_size_enum; >+} >+ >+void test_encode(OpusEncoder *enc, int channels, int frame_size, OpusDecoder *dec, const char* debug_info) >+{ >+ int samp_count = 0; >+ opus_int16 *inbuf; >+ unsigned char packet[MAX_PACKET+257]; >+ int len; >+ opus_int16 *outbuf; >+ int out_samples; >+ >+ /* Generate input data */ >+ inbuf = (opus_int16*)malloc(sizeof(*inbuf)*SSAMPLES); >+ generate_music(inbuf, SSAMPLES/2); >+ >+ /* Allocate memory for output data */ >+ outbuf = (opus_int16*)malloc(sizeof(*outbuf)*MAX_FRAME_SAMP*3); >+ >+ /* Encode data, then decode for sanity check */ >+ do { >+ len = opus_encode(enc, &inbuf[samp_count*channels], frame_size, packet, MAX_PACKET); >+ if(len<0 || len>MAX_PACKET) { >+ fprintf(stderr,"%s\n",debug_info); >+ fprintf(stderr,"opus_encode() returned %d\n",len); >+ test_failed(); >+ } >+ >+ out_samples = opus_decode(dec, packet, len, outbuf, MAX_FRAME_SAMP, 0); >+ if(out_samples!=frame_size) { >+ fprintf(stderr,"%s\n",debug_info); >+ fprintf(stderr,"opus_decode() returned %d\n",out_samples); >+ test_failed(); >+ } >+ >+ samp_count += frame_size; >+ } while (samp_count < ((SSAMPLES/2)-MAX_FRAME_SAMP)); >+ >+ /* Clean up */ >+ free(inbuf); >+ free(outbuf); >+} >+ >+void fuzz_encoder_settings(const int num_encoders, const int num_setting_changes) >+{ >+ OpusEncoder *enc; >+ OpusDecoder *dec; >+ int i,j,err; >+ >+ /* Parameters to fuzz. Some values are duplicated to increase their probability of being tested. */ >+ int sampling_rates[5] = {8000, 12000, 16000, 24000, 48000}; >+ int channels[2] = {1, 2}; >+ int applications[3] = {OPUS_APPLICATION_AUDIO, OPUS_APPLICATION_VOIP, OPUS_APPLICATION_RESTRICTED_LOWDELAY}; >+ int bitrates[11] = {6000, 12000, 16000, 24000, 32000, 48000, 64000, 96000, 510000, OPUS_AUTO, OPUS_BITRATE_MAX}; >+ int force_channels[4] = {OPUS_AUTO, OPUS_AUTO, 1, 2}; >+ int use_vbr[3] = {0, 1, 1}; >+ int vbr_constraints[3] = {0, 1, 1}; >+ int complexities[11] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; >+ int max_bandwidths[6] = {OPUS_BANDWIDTH_NARROWBAND, OPUS_BANDWIDTH_MEDIUMBAND, >+ OPUS_BANDWIDTH_WIDEBAND, OPUS_BANDWIDTH_SUPERWIDEBAND, >+ OPUS_BANDWIDTH_FULLBAND, OPUS_BANDWIDTH_FULLBAND}; >+ int signals[4] = {OPUS_AUTO, OPUS_AUTO, OPUS_SIGNAL_VOICE, OPUS_SIGNAL_MUSIC}; >+ int inband_fecs[3] = {0, 0, 1}; >+ int packet_loss_perc[4] = {0, 1, 2, 5}; >+ int lsb_depths[2] = {8, 24}; >+ int prediction_disabled[3] = {0, 0, 1}; >+ int use_dtx[2] = {0, 1}; >+ int frame_sizes_ms_x2[9] = {5, 10, 20, 40, 80, 120, 160, 200, 240}; /* x2 to avoid 2.5 ms */ >+ char debug_info[512]; >+ >+ for (i=0; i<num_encoders; i++) { >+ int sampling_rate = RAND_SAMPLE(sampling_rates); >+ int num_channels = RAND_SAMPLE(channels); >+ int application = RAND_SAMPLE(applications); >+ >+ dec = opus_decoder_create(sampling_rate, num_channels, &err); >+ if(err!=OPUS_OK || dec==NULL)test_failed(); >+ >+ enc = opus_encoder_create(sampling_rate, num_channels, application, &err); >+ if(err!=OPUS_OK || enc==NULL)test_failed(); >+ >+ for (j=0; j<num_setting_changes; j++) { >+ int bitrate = RAND_SAMPLE(bitrates); >+ int force_channel = RAND_SAMPLE(force_channels); >+ int vbr = RAND_SAMPLE(use_vbr); >+ int vbr_constraint = RAND_SAMPLE(vbr_constraints); >+ int complexity = RAND_SAMPLE(complexities); >+ int max_bw = RAND_SAMPLE(max_bandwidths); >+ int sig = RAND_SAMPLE(signals); >+ int inband_fec = RAND_SAMPLE(inband_fecs); >+ int pkt_loss = RAND_SAMPLE(packet_loss_perc); >+ int lsb_depth = RAND_SAMPLE(lsb_depths); >+ int pred_disabled = RAND_SAMPLE(prediction_disabled); >+ int dtx = RAND_SAMPLE(use_dtx); >+ int frame_size_ms_x2 = RAND_SAMPLE(frame_sizes_ms_x2); >+ int frame_size = frame_size_ms_x2*sampling_rate/2000; >+ int frame_size_enum = get_frame_size_enum(frame_size, sampling_rate); >+ force_channel = IMIN(force_channel, num_channels); >+ >+ sprintf(debug_info, >+ "fuzz_encoder_settings: %d kHz, %d ch, application: %d, " >+ "%d bps, force ch: %d, vbr: %d, vbr constraint: %d, complexity: %d, " >+ "max bw: %d, signal: %d, inband fec: %d, pkt loss: %d%%, lsb depth: %d, " >+ "pred disabled: %d, dtx: %d, (%d/2) ms\n", >+ sampling_rate/1000, num_channels, application, bitrate, >+ force_channel, vbr, vbr_constraint, complexity, max_bw, sig, inband_fec, >+ pkt_loss, lsb_depth, pred_disabled, dtx, frame_size_ms_x2); >+ >+ if(opus_encoder_ctl(enc, OPUS_SET_BITRATE(bitrate)) != OPUS_OK) test_failed(); >+ if(opus_encoder_ctl(enc, OPUS_SET_FORCE_CHANNELS(force_channel)) != OPUS_OK) test_failed(); >+ if(opus_encoder_ctl(enc, OPUS_SET_VBR(vbr)) != OPUS_OK) test_failed(); >+ if(opus_encoder_ctl(enc, OPUS_SET_VBR_CONSTRAINT(vbr_constraint)) != OPUS_OK) test_failed(); >+ if(opus_encoder_ctl(enc, OPUS_SET_COMPLEXITY(complexity)) != OPUS_OK) test_failed(); >+ if(opus_encoder_ctl(enc, OPUS_SET_MAX_BANDWIDTH(max_bw)) != OPUS_OK) test_failed(); >+ if(opus_encoder_ctl(enc, OPUS_SET_SIGNAL(sig)) != OPUS_OK) test_failed(); >+ if(opus_encoder_ctl(enc, OPUS_SET_INBAND_FEC(inband_fec)) != OPUS_OK) test_failed(); >+ if(opus_encoder_ctl(enc, OPUS_SET_PACKET_LOSS_PERC(pkt_loss)) != OPUS_OK) test_failed(); >+ if(opus_encoder_ctl(enc, OPUS_SET_LSB_DEPTH(lsb_depth)) != OPUS_OK) test_failed(); >+ if(opus_encoder_ctl(enc, OPUS_SET_PREDICTION_DISABLED(pred_disabled)) != OPUS_OK) test_failed(); >+ if(opus_encoder_ctl(enc, OPUS_SET_DTX(dtx)) != OPUS_OK) test_failed(); >+ if(opus_encoder_ctl(enc, OPUS_SET_EXPERT_FRAME_DURATION(frame_size_enum)) != OPUS_OK) test_failed(); >+ >+ test_encode(enc, num_channels, frame_size, dec, debug_info); >+ } >+ >+ opus_encoder_destroy(enc); >+ opus_decoder_destroy(dec); >+ } >+} >+ > int run_test1(int no_fuzz) > { > static const int fsizes[6]={960*3,960*2,120,240,480,960}; > static const char *mstrings[3] = {" LP","Hybrid"," MDCT"}; > unsigned char mapping[256] = {0,1,255}; > unsigned char db62[36]; >- opus_int32 i; >- int rc,j,err; >+ opus_int32 i,j; >+ int rc,err; > OpusEncoder *enc; > OpusMSEncoder *MSenc; > OpusDecoder *dec; >@@ -229,6 +384,7 @@ int run_test1(int no_fuzz) > > if(opus_encoder_ctl(enc, OPUS_SET_BANDWIDTH(OPUS_AUTO))!=OPUS_OK)test_failed(); > if(opus_encoder_ctl(enc, OPUS_SET_FORCE_MODE(-2))!=OPUS_BAD_ARG)test_failed(); >+ if(opus_encode(enc, inbuf, 500, packet, MAX_PACKET)!=OPUS_BAD_ARG)test_failed(); > > for(rc=0;rc<3;rc++) > { >@@ -335,7 +491,8 @@ int run_test1(int no_fuzz) > if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_BITRATE(rate))!=OPUS_OK)test_failed(); > count=i=0; > do { >- int pred,len,out_samples,frame_size,loss; >+ int len,out_samples,frame_size,loss; >+ opus_int32 pred; > if(opus_multistream_encoder_ctl(MSenc, OPUS_GET_PREDICTION_DISABLED(&pred))!=OPUS_OK)test_failed(); > if(opus_multistream_encoder_ctl(MSenc, OPUS_SET_PREDICTION_DISABLED((int)(fast_rand()&15)<(pred?11:4)))!=OPUS_OK)test_failed(); > frame_size=frame[j]; >@@ -425,7 +582,7 @@ int run_test1(int no_fuzz) > the decoders in order to compare them. */ > if(opus_packet_parse(packet,len,&toc,frames,size,&payload_offset)<=0)test_failed(); > if((fast_rand()&1023)==0)len=0; >- for(j=(frames[0]-packet);j<len;j++)for(jj=0;jj<8;jj++)packet[j]^=((!no_fuzz)&&((fast_rand()&1023)==0))<<jj; >+ for(j=(opus_int32)(frames[0]-packet);j<len;j++)for(jj=0;jj<8;jj++)packet[j]^=((!no_fuzz)&&((fast_rand()&1023)==0))<<jj; > out_samples = opus_decode(dec_err[0], len>0?packet:NULL, len, out2buf, MAX_FRAME_SAMP, 0); > if(out_samples<0||out_samples>MAX_FRAME_SAMP)test_failed(); > if((len>0&&out_samples!=frame_size))test_failed(); /*FIXME use lastframe*/ >@@ -470,39 +627,74 @@ int run_test1(int no_fuzz) > return 0; > } > >+void print_usage(char* _argv[]) >+{ >+ fprintf(stderr,"Usage: %s [<seed>] [-fuzz <num_encoders> <num_settings_per_encoder>]\n",_argv[0]); >+} >+ > int main(int _argc, char **_argv) > { >+ int args=1; >+ char * strtol_str=NULL; > const char * oversion; > const char * env_seed; > int env_used; >- >- if(_argc>2) >- { >- fprintf(stderr,"Usage: %s [<seed>]\n",_argv[0]); >- return 1; >- } >+ int num_encoders_to_fuzz=5; >+ int num_setting_changes=40; > > env_used=0; > env_seed=getenv("SEED"); >- if(_argc>1)iseed=atoi(_argv[1]); >- else if(env_seed) >- { >+ if(_argc>1) >+ iseed=strtol(_argv[1], &strtol_str, 10); /* the first input argument might be the seed */ >+ if(strtol_str!=NULL && strtol_str[0]=='\0') /* iseed is a valid number */ >+ args++; >+ else if(env_seed) { > iseed=atoi(env_seed); > env_used=1; > } >- else iseed=(opus_uint32)time(NULL)^((getpid()&65535)<<16); >+ else iseed=(opus_uint32)time(NULL)^(((opus_uint32)getpid()&65535)<<16); > Rw=Rz=iseed; > >+ while(args<_argc) >+ { >+ if(strcmp(_argv[args], "-fuzz")==0 && _argc==(args+3)) { >+ num_encoders_to_fuzz=strtol(_argv[args+1], &strtol_str, 10); >+ if(strtol_str[0]!='\0' || num_encoders_to_fuzz<=0) { >+ print_usage(_argv); >+ return EXIT_FAILURE; >+ } >+ num_setting_changes=strtol(_argv[args+2], &strtol_str, 10); >+ if(strtol_str[0]!='\0' || num_setting_changes<=0) { >+ print_usage(_argv); >+ return EXIT_FAILURE; >+ } >+ args+=3; >+ } >+ else { >+ print_usage(_argv); >+ return EXIT_FAILURE; >+ } >+ } >+ > oversion=opus_get_version_string(); > if(!oversion)test_failed(); > fprintf(stderr,"Testing %s encoder. Random seed: %u (%.4X)\n", oversion, iseed, fast_rand() % 65535); > if(env_used)fprintf(stderr," Random seed set from the environment (SEED=%s).\n", env_seed); > >+ regression_test(); >+ > /*Setting TEST_OPUS_NOFUZZ tells the tool not to send garbage data > into the decoders. This is helpful because garbage data > may cause the decoders to clip, which angers CLANG IOC.*/ > run_test1(getenv("TEST_OPUS_NOFUZZ")!=NULL); > >+ /* Fuzz encoder settings online */ >+ if(getenv("TEST_OPUS_NOFUZZ")==NULL) { >+ fprintf(stderr,"Running fuzz_encoder_settings with %d encoder(s) and %d setting change(s) each.\n", >+ num_encoders_to_fuzz, num_setting_changes); >+ fuzz_encoder_settings(num_encoders_to_fuzz, num_setting_changes); >+ } >+ > fprintf(stderr,"Tests completed successfully.\n"); > > return 0; >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/update_version b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/update_version >new file mode 100644 >index 0000000000000000000000000000000000000000..a9999918d0f7e3cd52eb1c2cdbc70c1d85ccb226 >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/update_version >@@ -0,0 +1,65 @@ >+#!/bin/bash >+ >+# Creates and updates the package_version information used by configure.ac >+# (or other makefiles). When run inside a git repository it will use the >+# version information that can be queried from it unless AUTO_UPDATE is set >+# to 'no'. If no version is currently known it will be set to 'unknown'. >+# >+# If called with the argument 'release', the PACKAGE_VERSION will be updated >+# even if AUTO_UPDATE=no, but the value of AUTO_UPDATE shall be preserved. >+# This is used to force a version update whenever `make dist` is run. >+# >+# The exit status is 1 if package_version is not modified, else 0 is returned. >+# >+# This script should NOT be included in distributed tarballs, because if a >+# parent directory contains a git repository we do not want to accidentally >+# retrieve the version information from it instead. Tarballs should ship >+# with only the package_version file. >+# >+# Ron <ron@debian.org>, 2012. >+ >+SRCDIR=$(dirname $0) >+ >+if [ -e "$SRCDIR/package_version" ]; then >+ . "$SRCDIR/package_version" >+fi >+ >+if [ "$AUTO_UPDATE" = no ]; then >+ [ "$1" = release ] || exit 1 >+else >+ AUTO_UPDATE=yes >+fi >+ >+# We run `git status` before describe here to ensure that we don't get a false >+# -dirty from files that have been touched but are not actually altered in the >+# working dir. >+GIT_VERSION=$(cd "$SRCDIR" && git status > /dev/null 2>&1 \ >+ && git describe --tags --match 'v*' --dirty 2> /dev/null) >+GIT_VERSION=${GIT_VERSION#v} >+ >+if [ -n "$GIT_VERSION" ]; then >+ >+ [ "$GIT_VERSION" != "$PACKAGE_VERSION" ] || exit 1 >+ PACKAGE_VERSION="$GIT_VERSION" >+ >+elif [ -z "$PACKAGE_VERSION" ]; then >+ # No current package_version and no git ... >+ # We really shouldn't ever get here, because this script should only be >+ # included in the git repository, and should usually be export-ignored. >+ PACKAGE_VERSION="unknown" >+else >+ exit 1 >+fi >+ >+cat > "$SRCDIR/package_version" <<-EOF >+ # Automatically generated by update_version. >+ # This file may be sourced into a shell script or makefile. >+ >+ # Set this to 'no' if you do not wish the version information >+ # to be checked and updated for every build. Most people will >+ # never want to change this, it is an option for developers >+ # making frequent changes that they know will not be released. >+ AUTO_UPDATE=$AUTO_UPDATE >+ >+ PACKAGE_VERSION="$PACKAGE_VERSION" >+EOF >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/win32/.gitignore b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/win32/.gitignore >new file mode 100644 >index 0000000000000000000000000000000000000000..c17feab73d3492ce8662ee69546dec0d9eebbd7d >--- /dev/null >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/win32/.gitignore >@@ -0,0 +1,26 @@ >+# Visual Studio ignores >+[Dd]ebug/ >+[Dd]ebugDLL/ >+[Dd]ebugDLL_fixed/ >+[Dd]ebugPublic/ >+[Rr]elease/ >+[Rr]eleaseDLL/ >+[Rr]eleaseDLL_fixed/ >+[Rr]eleases/ >+*.manifest >+*.lastbuildstate >+*.lib >+*.log >+*.idb >+*.ipdb >+*.ilk >+*.iobj >+*.obj >+*.opensdf >+*.pdb >+*.sdf >+*.suo >+*.tlog >+*.vcxproj.user >+*.vc.db >+*.vc.opendb >diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/win32/genversion.bat b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/win32/genversion.bat >index cd1d4dce6ed8f5486ee31a3f5a14dab8bc038e0c..1def7460b5e02fa18998a57e0e0efc5ab3134ed5 100755 >--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/win32/genversion.bat >+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/win32/genversion.bat >@@ -2,13 +2,13 @@ > > setlocal enableextensions enabledelayedexpansion > >-for /f %%v in ('git --git-dir="%~dp0..\.git" describe --tags --match "v*"') do set version=%%v >+for /f %%v in ('cd "%~dp0.." ^&^& git status ^>NUL 2^>NUL ^&^& git describe --tags --match "v*" --dirty 2^>NUL') do set version=%%v > >-if not "%version%"=="" goto :gotversion >+if not "%version%"=="" set version=!version:~1! && goto :gotversion > >-if exist "%~dp0..\version.mk" goto :getversion >+if exist "%~dp0..\package_version" goto :getversion > >-echo Git cannot be found, nor can version.mk. Generating unknown version. >+echo Git cannot be found, nor can package_version. Generating unknown version. > > set version=unknown > >@@ -16,25 +16,16 @@ goto :gotversion > > :getversion > >-for /f "delims== tokens=2" %%v in (%~dps0..\version.mk) do set version=%%v >- >-set version=!version:^"=! >-set version=!version: =! >+for /f "delims== tokens=2" %%v in (%~dps0..\package_version) do set version=%%v >+set version=!version:"=! > > :gotversion > >+set version=!version: =! > set version_out=#define %~2 "%version%" >-set version_mk=%~2 = "%version%" > > echo %version_out%> "%~1_temp" > >-if %version%==unknown goto :skipgenerate >- >-echo # static version string; update manually every release.> "%~dp0..\version.mk" >-echo %version_mk%>> "%~dp0..\version.mk" >- >-:skipgenerate >- > echo n | comp "%~1_temp" "%~1" > NUL 2> NUL > > if not errorlevel 1 goto exit >diff --git a/Source/ThirdParty/libwebrtc/libwebrtc.xcodeproj/project.pbxproj b/Source/ThirdParty/libwebrtc/libwebrtc.xcodeproj/project.pbxproj >index 3ecf5a614d3e0005af38476f7576417498a0cac2..77707826d6f50e3353629ac0eb685cf04c983efe 100644 >--- a/Source/ThirdParty/libwebrtc/libwebrtc.xcodeproj/project.pbxproj >+++ b/Source/ThirdParty/libwebrtc/libwebrtc.xcodeproj/project.pbxproj >@@ -535,6 +535,8 @@ > 414D71141E4AE98C0023E526 /* user_socket.c in Sources */ = {isa = PBXBuildFile; fileRef = 414D71121E4AE9820023E526 /* user_socket.c */; }; > 414D71171E4AEAFB0023E526 /* sctp_indata.c in Sources */ = {isa = PBXBuildFile; fileRef = 414D71151E4AEACD0023E526 /* sctp_indata.c */; }; > 414D71191E4AEB110023E526 /* sctp_userspace.c in Sources */ = {isa = PBXBuildFile; fileRef = 414D71181E4AEB110023E526 /* sctp_userspace.c */; }; >+ 4153CD2721CC661000C3E188 /* LPC_fit.c in Sources */ = {isa = PBXBuildFile; fileRef = 4100CDE521CACFD000F9B87D /* LPC_fit.c */; }; >+ 4153CD2821CC664800C3E188 /* vq_sse2.c in Sources */ = {isa = PBXBuildFile; fileRef = 4100CDED21CAD1F500F9B87D /* vq_sse2.c */; }; > 415F1FA621272FBA00064CBF /* adaptive_digital_gain_applier.cc in Sources */ = {isa = PBXBuildFile; fileRef = 41A08BE421272F85001D5D7B /* adaptive_digital_gain_applier.cc */; }; > 415F1FA721272FBA00064CBF /* adaptive_digital_gain_applier.h in Headers */ = {isa = PBXBuildFile; fileRef = 41A08BDB21272F84001D5D7B /* adaptive_digital_gain_applier.h */; }; > 415F1FA821272FBA00064CBF /* adaptive_mode_level_estimator_agc.cc in Sources */ = {isa = PBXBuildFile; fileRef = 41A08BE921272F86001D5D7B /* adaptive_mode_level_estimator_agc.cc */; }; >@@ -3246,7 +3248,6 @@ > 5CDD8EEA1E43C9F600621E92 /* find_pred_coefs_FLP.c in Sources */ = {isa = PBXBuildFile; fileRef = 5CDD8EA61E43C9C100621E92 /* find_pred_coefs_FLP.c */; }; > 5CDD8EEB1E43C9F600621E92 /* inner_product_FLP.c in Sources */ = {isa = PBXBuildFile; fileRef = 5CDD8EA71E43C9C100621E92 /* inner_product_FLP.c */; }; > 5CDD8EEC1E43C9F600621E92 /* k2a_FLP.c in Sources */ = {isa = PBXBuildFile; fileRef = 5CDD8EA81E43C9C100621E92 /* k2a_FLP.c */; }; >- 5CDD8EED1E43C9F600621E92 /* levinsondurbin_FLP.c in Sources */ = {isa = PBXBuildFile; fileRef = 5CDD8EA91E43C9C100621E92 /* levinsondurbin_FLP.c */; }; > 5CDD8EEE1E43C9F600621E92 /* LPC_analysis_filter_FLP.c in Sources */ = {isa = PBXBuildFile; fileRef = 5CDD8EAA1E43C9C100621E92 /* LPC_analysis_filter_FLP.c */; }; > 5CDD8EEF1E43C9F600621E92 /* LPC_inv_pred_gain_FLP.c in Sources */ = {isa = PBXBuildFile; fileRef = 5CDD8EAB1E43C9C100621E92 /* LPC_inv_pred_gain_FLP.c */; }; > 5CDD8EF01E43C9F600621E92 /* LTP_analysis_filter_FLP.c in Sources */ = {isa = PBXBuildFile; fileRef = 5CDD8EAC1E43C9C100621E92 /* LTP_analysis_filter_FLP.c */; }; >@@ -3254,7 +3255,6 @@ > 5CDD8EF21E43C9F600621E92 /* main_FLP.h in Headers */ = {isa = PBXBuildFile; fileRef = 5CDD8EAE1E43C9C100621E92 /* main_FLP.h */; }; > 5CDD8EF31E43C9F600621E92 /* noise_shape_analysis_FLP.c in Sources */ = {isa = PBXBuildFile; fileRef = 5CDD8EAF1E43C9C100621E92 /* noise_shape_analysis_FLP.c */; }; > 5CDD8EF41E43C9F600621E92 /* pitch_analysis_core_FLP.c in Sources */ = {isa = PBXBuildFile; fileRef = 5CDD8EB01E43C9C100621E92 /* pitch_analysis_core_FLP.c */; }; >- 5CDD8EF51E43C9F600621E92 /* prefilter_FLP.c in Sources */ = {isa = PBXBuildFile; fileRef = 5CDD8EB11E43C9C100621E92 /* prefilter_FLP.c */; }; > 5CDD8EF61E43C9F600621E92 /* process_gains_FLP.c in Sources */ = {isa = PBXBuildFile; fileRef = 5CDD8EB21E43C9C100621E92 /* process_gains_FLP.c */; }; > 5CDD8EF71E43C9F600621E92 /* regularize_correlations_FLP.c in Sources */ = {isa = PBXBuildFile; fileRef = 5CDD8EB31E43C9C100621E92 /* regularize_correlations_FLP.c */; }; > 5CDD8EF81E43C9F600621E92 /* residual_energy_FLP.c in Sources */ = {isa = PBXBuildFile; fileRef = 5CDD8EB41E43C9C100621E92 /* residual_energy_FLP.c */; }; >@@ -3262,7 +3262,6 @@ > 5CDD8EFA1E43C9F600621E92 /* scale_vector_FLP.c in Sources */ = {isa = PBXBuildFile; fileRef = 5CDD8EB61E43C9C100621E92 /* scale_vector_FLP.c */; }; > 5CDD8EFB1E43C9F600621E92 /* schur_FLP.c in Sources */ = {isa = PBXBuildFile; fileRef = 5CDD8EB71E43C9C100621E92 /* schur_FLP.c */; }; > 5CDD8EFC1E43C9F600621E92 /* SigProc_FLP.h in Headers */ = {isa = PBXBuildFile; fileRef = 5CDD8EB81E43C9C100621E92 /* SigProc_FLP.h */; }; >- 5CDD8EFD1E43C9F600621E92 /* solve_LS_FLP.c in Sources */ = {isa = PBXBuildFile; fileRef = 5CDD8EB91E43C9C100621E92 /* solve_LS_FLP.c */; }; > 5CDD8EFE1E43C9F600621E92 /* sort_FLP.c in Sources */ = {isa = PBXBuildFile; fileRef = 5CDD8EBA1E43C9C100621E92 /* sort_FLP.c */; }; > 5CDD8EFF1E43C9F600621E92 /* structs_FLP.h in Headers */ = {isa = PBXBuildFile; fileRef = 5CDD8EBB1E43C9C100621E92 /* structs_FLP.h */; }; > 5CDD8F001E43C9F600621E92 /* warped_autocorrelation_FLP.c in Sources */ = {isa = PBXBuildFile; fileRef = 5CDD8EBC1E43C9C100621E92 /* warped_autocorrelation_FLP.c */; }; >@@ -3283,14 +3282,12 @@ > 5CDD8F471E43CB1E00621E92 /* main_FIX.h in Headers */ = {isa = PBXBuildFile; fileRef = 5CDD8F101E43CAF900621E92 /* main_FIX.h */; }; > 5CDD8F481E43CB1E00621E92 /* noise_shape_analysis_FIX.c in Sources */ = {isa = PBXBuildFile; fileRef = 5CDD8F121E43CAF900621E92 /* noise_shape_analysis_FIX.c */; }; > 5CDD8F491E43CB1E00621E92 /* pitch_analysis_core_FIX.c in Sources */ = {isa = PBXBuildFile; fileRef = 5CDD8F131E43CAF900621E92 /* pitch_analysis_core_FIX.c */; }; >- 5CDD8F4A1E43CB1E00621E92 /* prefilter_FIX.c in Sources */ = {isa = PBXBuildFile; fileRef = 5CDD8F141E43CAF900621E92 /* prefilter_FIX.c */; }; > 5CDD8F4B1E43CB1E00621E92 /* process_gains_FIX.c in Sources */ = {isa = PBXBuildFile; fileRef = 5CDD8F151E43CAF900621E92 /* process_gains_FIX.c */; }; > 5CDD8F4C1E43CB1E00621E92 /* regularize_correlations_FIX.c in Sources */ = {isa = PBXBuildFile; fileRef = 5CDD8F161E43CAF900621E92 /* regularize_correlations_FIX.c */; }; > 5CDD8F4D1E43CB1E00621E92 /* residual_energy_FIX.c in Sources */ = {isa = PBXBuildFile; fileRef = 5CDD8F171E43CAF900621E92 /* residual_energy_FIX.c */; }; > 5CDD8F4E1E43CB1E00621E92 /* residual_energy16_FIX.c in Sources */ = {isa = PBXBuildFile; fileRef = 5CDD8F181E43CAF900621E92 /* residual_energy16_FIX.c */; }; > 5CDD8F4F1E43CB1E00621E92 /* schur_FIX.c in Sources */ = {isa = PBXBuildFile; fileRef = 5CDD8F191E43CAF900621E92 /* schur_FIX.c */; }; > 5CDD8F501E43CB1E00621E92 /* schur64_FIX.c in Sources */ = {isa = PBXBuildFile; fileRef = 5CDD8F1A1E43CAF900621E92 /* schur64_FIX.c */; }; >- 5CDD8F511E43CB1E00621E92 /* solve_LS_FIX.c in Sources */ = {isa = PBXBuildFile; fileRef = 5CDD8F1B1E43CAF900621E92 /* solve_LS_FIX.c */; }; > 5CDD8F521E43CB1E00621E92 /* structs_FIX.h in Headers */ = {isa = PBXBuildFile; fileRef = 5CDD8F1C1E43CAF900621E92 /* structs_FIX.h */; }; > 5CDD8F531E43CB1E00621E92 /* vector_ops_FIX.c in Sources */ = {isa = PBXBuildFile; fileRef = 5CDD8F1D1E43CAF900621E92 /* vector_ops_FIX.c */; }; > 5CDD8F541E43CB1E00621E92 /* warped_autocorrelation_FIX.c in Sources */ = {isa = PBXBuildFile; fileRef = 5CDD8F1E1E43CAF900621E92 /* warped_autocorrelation_FIX.c */; }; >@@ -3655,6 +3652,15 @@ > /* Begin PBXFileReference section */ > 37119A8020CCB6DD002C6DC9 /* Version.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Version.xcconfig; sourceTree = "<group>"; }; > 37119A8120CCB6DD002C6DC9 /* WebKitTargetConditionals.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = WebKitTargetConditionals.xcconfig; sourceTree = "<group>"; }; >+ 4100CDE521CACFD000F9B87D /* LPC_fit.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = LPC_fit.c; path = silk/LPC_fit.c; sourceTree = "<group>"; }; >+ 4100CDE821CAD03300F9B87D /* vq_sse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = vq_sse.h; path = x86/vq_sse.h; sourceTree = "<group>"; }; >+ 4100CDEB21CAD1F500F9B87D /* pitch_sse4_1.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pitch_sse4_1.c; path = x86/pitch_sse4_1.c; sourceTree = "<group>"; }; >+ 4100CDEC21CAD1F500F9B87D /* celt_lpc_sse.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = celt_lpc_sse.c; path = x86/celt_lpc_sse.c; sourceTree = "<group>"; }; >+ 4100CDED21CAD1F500F9B87D /* vq_sse2.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = vq_sse2.c; path = x86/vq_sse2.c; sourceTree = "<group>"; }; >+ 4100CDEE21CAD1F600F9B87D /* pitch_sse.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pitch_sse.c; path = x86/pitch_sse.c; sourceTree = "<group>"; }; >+ 4100CDEF21CAD1F600F9B87D /* pitch_sse2.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pitch_sse2.c; path = x86/pitch_sse2.c; sourceTree = "<group>"; }; >+ 4100CDF021CAD1F600F9B87D /* celt_lpc_sse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = celt_lpc_sse.h; path = x86/celt_lpc_sse.h; sourceTree = "<group>"; }; >+ 4100CDF121CAD1F700F9B87D /* pitch_sse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = pitch_sse.h; path = x86/pitch_sse.h; sourceTree = "<group>"; }; > 4102F68421273204006AE8D7 /* rtcstatstraversal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rtcstatstraversal.h; sourceTree = "<group>"; }; > 4102F68521273204006AE8D7 /* jseptransportcontroller.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = jseptransportcontroller.h; sourceTree = "<group>"; }; > 4102F68621273205006AE8D7 /* transportstats.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = transportstats.cc; sourceTree = "<group>"; }; >@@ -7159,7 +7165,6 @@ > 5CDD8EA61E43C9C100621E92 /* find_pred_coefs_FLP.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = find_pred_coefs_FLP.c; path = silk/float/find_pred_coefs_FLP.c; sourceTree = "<group>"; }; > 5CDD8EA71E43C9C100621E92 /* inner_product_FLP.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = inner_product_FLP.c; path = silk/float/inner_product_FLP.c; sourceTree = "<group>"; }; > 5CDD8EA81E43C9C100621E92 /* k2a_FLP.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = k2a_FLP.c; path = silk/float/k2a_FLP.c; sourceTree = "<group>"; }; >- 5CDD8EA91E43C9C100621E92 /* levinsondurbin_FLP.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = levinsondurbin_FLP.c; path = silk/float/levinsondurbin_FLP.c; sourceTree = "<group>"; }; > 5CDD8EAA1E43C9C100621E92 /* LPC_analysis_filter_FLP.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = LPC_analysis_filter_FLP.c; path = silk/float/LPC_analysis_filter_FLP.c; sourceTree = "<group>"; }; > 5CDD8EAB1E43C9C100621E92 /* LPC_inv_pred_gain_FLP.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = LPC_inv_pred_gain_FLP.c; path = silk/float/LPC_inv_pred_gain_FLP.c; sourceTree = "<group>"; }; > 5CDD8EAC1E43C9C100621E92 /* LTP_analysis_filter_FLP.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = LTP_analysis_filter_FLP.c; path = silk/float/LTP_analysis_filter_FLP.c; sourceTree = "<group>"; }; >@@ -7167,7 +7172,6 @@ > 5CDD8EAE1E43C9C100621E92 /* main_FLP.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = main_FLP.h; path = silk/float/main_FLP.h; sourceTree = "<group>"; }; > 5CDD8EAF1E43C9C100621E92 /* noise_shape_analysis_FLP.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = noise_shape_analysis_FLP.c; path = silk/float/noise_shape_analysis_FLP.c; sourceTree = "<group>"; }; > 5CDD8EB01E43C9C100621E92 /* pitch_analysis_core_FLP.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pitch_analysis_core_FLP.c; path = silk/float/pitch_analysis_core_FLP.c; sourceTree = "<group>"; }; >- 5CDD8EB11E43C9C100621E92 /* prefilter_FLP.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = prefilter_FLP.c; path = silk/float/prefilter_FLP.c; sourceTree = "<group>"; }; > 5CDD8EB21E43C9C100621E92 /* process_gains_FLP.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = process_gains_FLP.c; path = silk/float/process_gains_FLP.c; sourceTree = "<group>"; }; > 5CDD8EB31E43C9C100621E92 /* regularize_correlations_FLP.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = regularize_correlations_FLP.c; path = silk/float/regularize_correlations_FLP.c; sourceTree = "<group>"; }; > 5CDD8EB41E43C9C100621E92 /* residual_energy_FLP.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = residual_energy_FLP.c; path = silk/float/residual_energy_FLP.c; sourceTree = "<group>"; }; >@@ -7175,7 +7179,6 @@ > 5CDD8EB61E43C9C100621E92 /* scale_vector_FLP.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = scale_vector_FLP.c; path = silk/float/scale_vector_FLP.c; sourceTree = "<group>"; }; > 5CDD8EB71E43C9C100621E92 /* schur_FLP.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = schur_FLP.c; path = silk/float/schur_FLP.c; sourceTree = "<group>"; }; > 5CDD8EB81E43C9C100621E92 /* SigProc_FLP.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SigProc_FLP.h; path = silk/float/SigProc_FLP.h; sourceTree = "<group>"; }; >- 5CDD8EB91E43C9C100621E92 /* solve_LS_FLP.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = solve_LS_FLP.c; path = silk/float/solve_LS_FLP.c; sourceTree = "<group>"; }; > 5CDD8EBA1E43C9C100621E92 /* sort_FLP.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = sort_FLP.c; path = silk/float/sort_FLP.c; sourceTree = "<group>"; }; > 5CDD8EBB1E43C9C100621E92 /* structs_FLP.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = structs_FLP.h; path = silk/float/structs_FLP.h; sourceTree = "<group>"; }; > 5CDD8EBC1E43C9C100621E92 /* warped_autocorrelation_FLP.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = warped_autocorrelation_FLP.c; path = silk/float/warped_autocorrelation_FLP.c; sourceTree = "<group>"; }; >@@ -7196,14 +7199,12 @@ > 5CDD8F101E43CAF900621E92 /* main_FIX.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = main_FIX.h; path = silk/fixed/main_FIX.h; sourceTree = "<group>"; }; > 5CDD8F121E43CAF900621E92 /* noise_shape_analysis_FIX.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = noise_shape_analysis_FIX.c; path = silk/fixed/noise_shape_analysis_FIX.c; sourceTree = "<group>"; }; > 5CDD8F131E43CAF900621E92 /* pitch_analysis_core_FIX.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pitch_analysis_core_FIX.c; path = silk/fixed/pitch_analysis_core_FIX.c; sourceTree = "<group>"; }; >- 5CDD8F141E43CAF900621E92 /* prefilter_FIX.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = prefilter_FIX.c; path = silk/fixed/prefilter_FIX.c; sourceTree = "<group>"; }; > 5CDD8F151E43CAF900621E92 /* process_gains_FIX.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = process_gains_FIX.c; path = silk/fixed/process_gains_FIX.c; sourceTree = "<group>"; }; > 5CDD8F161E43CAF900621E92 /* regularize_correlations_FIX.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = regularize_correlations_FIX.c; path = silk/fixed/regularize_correlations_FIX.c; sourceTree = "<group>"; }; > 5CDD8F171E43CAF900621E92 /* residual_energy_FIX.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = residual_energy_FIX.c; path = silk/fixed/residual_energy_FIX.c; sourceTree = "<group>"; }; > 5CDD8F181E43CAF900621E92 /* residual_energy16_FIX.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = residual_energy16_FIX.c; path = silk/fixed/residual_energy16_FIX.c; sourceTree = "<group>"; }; > 5CDD8F191E43CAF900621E92 /* schur_FIX.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = schur_FIX.c; path = silk/fixed/schur_FIX.c; sourceTree = "<group>"; }; > 5CDD8F1A1E43CAF900621E92 /* schur64_FIX.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = schur64_FIX.c; path = silk/fixed/schur64_FIX.c; sourceTree = "<group>"; }; >- 5CDD8F1B1E43CAF900621E92 /* solve_LS_FIX.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = solve_LS_FIX.c; path = silk/fixed/solve_LS_FIX.c; sourceTree = "<group>"; }; > 5CDD8F1C1E43CAF900621E92 /* structs_FIX.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = structs_FIX.h; path = silk/fixed/structs_FIX.h; sourceTree = "<group>"; }; > 5CDD8F1D1E43CAF900621E92 /* vector_ops_FIX.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = vector_ops_FIX.c; path = silk/fixed/vector_ops_FIX.c; sourceTree = "<group>"; }; > 5CDD8F1E1E43CAF900621E92 /* warped_autocorrelation_FIX.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = warped_autocorrelation_FIX.c; path = silk/fixed/warped_autocorrelation_FIX.c; sourceTree = "<group>"; }; >@@ -13033,6 +13034,14 @@ > 5CDD8D131E43C75500621E92 /* x86 */ = { > isa = PBXGroup; > children = ( >+ 4100CDEC21CAD1F500F9B87D /* celt_lpc_sse.c */, >+ 4100CDF021CAD1F600F9B87D /* celt_lpc_sse.h */, >+ 4100CDEE21CAD1F600F9B87D /* pitch_sse.c */, >+ 4100CDF121CAD1F700F9B87D /* pitch_sse.h */, >+ 4100CDEF21CAD1F600F9B87D /* pitch_sse2.c */, >+ 4100CDEB21CAD1F500F9B87D /* pitch_sse4_1.c */, >+ 4100CDE821CAD03300F9B87D /* vq_sse.h */, >+ 4100CDED21CAD1F500F9B87D /* vq_sse2.c */, > 5CDD8D1A1E43C76400621E92 /* x86_celt_map.c */, > 5CDD8D1B1E43C76400621E92 /* x86cpu.c */, > 5CDD8D1C1E43C76400621E92 /* x86cpu.h */, >@@ -13085,6 +13094,7 @@ > 5CDD8D851E43C7D900621E92 /* log2lin.c */, > 5CDD8D861E43C7D900621E92 /* LP_variable_cutoff.c */, > 5CDD8D871E43C7D900621E92 /* LPC_analysis_filter.c */, >+ 4100CDE521CACFD000F9B87D /* LPC_fit.c */, > 5CDD8D881E43C7D900621E92 /* LPC_inv_pred_gain.c */, > 5CDD8D891E43C7D900621E92 /* MacroCount.h */, > 5CDD8D8A1E43C7D900621E92 /* MacroDebug.h */, >@@ -13177,7 +13187,6 @@ > 5CDD8EA61E43C9C100621E92 /* find_pred_coefs_FLP.c */, > 5CDD8EA71E43C9C100621E92 /* inner_product_FLP.c */, > 5CDD8EA81E43C9C100621E92 /* k2a_FLP.c */, >- 5CDD8EA91E43C9C100621E92 /* levinsondurbin_FLP.c */, > 5CDD8EAA1E43C9C100621E92 /* LPC_analysis_filter_FLP.c */, > 5CDD8EAB1E43C9C100621E92 /* LPC_inv_pred_gain_FLP.c */, > 5CDD8EAC1E43C9C100621E92 /* LTP_analysis_filter_FLP.c */, >@@ -13185,7 +13194,6 @@ > 5CDD8EAE1E43C9C100621E92 /* main_FLP.h */, > 5CDD8EAF1E43C9C100621E92 /* noise_shape_analysis_FLP.c */, > 5CDD8EB01E43C9C100621E92 /* pitch_analysis_core_FLP.c */, >- 5CDD8EB11E43C9C100621E92 /* prefilter_FLP.c */, > 5CDD8EB21E43C9C100621E92 /* process_gains_FLP.c */, > 5CDD8EB31E43C9C100621E92 /* regularize_correlations_FLP.c */, > 5CDD8EB41E43C9C100621E92 /* residual_energy_FLP.c */, >@@ -13193,7 +13201,6 @@ > 5CDD8EB61E43C9C100621E92 /* scale_vector_FLP.c */, > 5CDD8EB71E43C9C100621E92 /* schur_FLP.c */, > 5CDD8EB81E43C9C100621E92 /* SigProc_FLP.h */, >- 5CDD8EB91E43C9C100621E92 /* solve_LS_FLP.c */, > 5CDD8EBA1E43C9C100621E92 /* sort_FLP.c */, > 5CDD8EBB1E43C9C100621E92 /* structs_FLP.h */, > 5CDD8EBC1E43C9C100621E92 /* warped_autocorrelation_FLP.c */, >@@ -13221,14 +13228,12 @@ > 5CDD8F101E43CAF900621E92 /* main_FIX.h */, > 5CDD8F121E43CAF900621E92 /* noise_shape_analysis_FIX.c */, > 5CDD8F131E43CAF900621E92 /* pitch_analysis_core_FIX.c */, >- 5CDD8F141E43CAF900621E92 /* prefilter_FIX.c */, > 5CDD8F151E43CAF900621E92 /* process_gains_FIX.c */, > 5CDD8F161E43CAF900621E92 /* regularize_correlations_FIX.c */, > 5CDD8F181E43CAF900621E92 /* residual_energy16_FIX.c */, > 5CDD8F171E43CAF900621E92 /* residual_energy_FIX.c */, > 5CDD8F1A1E43CAF900621E92 /* schur64_FIX.c */, > 5CDD8F191E43CAF900621E92 /* schur_FIX.c */, >- 5CDD8F1B1E43CAF900621E92 /* solve_LS_FIX.c */, > 5CDD8F1C1E43CAF900621E92 /* structs_FIX.h */, > 5CDD8F1D1E43CAF900621E92 /* vector_ops_FIX.c */, > 5CDD8F1E1E43CAF900621E92 /* warped_autocorrelation_FIX.c */, >@@ -15713,8 +15718,8 @@ > 5C088C1C1E4AA44400403995 /* mediasession.cc in Sources */, > 5C088C1E1E4AA44400403995 /* rtcpmuxfilter.cc in Sources */, > 5C088C201E4AA44400403995 /* srtpfilter.cc in Sources */, >- 41239B4D2147743A00396F81 /* video_stream_encoder_create.cc in Sources */, > 4100CDF921CAE33400F9B87D /* srtpsession.cc in Sources */, >+ 41239B4D2147743A00396F81 /* video_stream_encoder_create.cc in Sources */, > ); > runOnlyForDeploymentPostprocessing = 0; > }; >@@ -15817,7 +15822,6 @@ > 5CDD8F441E43CB1E00621E92 /* k2a_Q16_FIX.c in Sources */, > 5CDD8D461E43C79C00621E92 /* kiss_fft.c in Sources */, > 5CDD8D481E43C79C00621E92 /* laplace.c in Sources */, >- 5CDD8EED1E43C9F600621E92 /* levinsondurbin_FLP.c in Sources */, > 5CDD8E5D1E43C80C00621E92 /* lin2log.c in Sources */, > 5CDD8E5E1E43C80C00621E92 /* log2lin.c in Sources */, > 5CDD8E5F1E43C80C00621E92 /* LP_variable_cutoff.c in Sources */, >@@ -15859,8 +15863,6 @@ > 5CDD8EF41E43C9F600621E92 /* pitch_analysis_core_FLP.c in Sources */, > 5CDD8E721E43C80C00621E92 /* pitch_est_tables.c in Sources */, > 5CDD8E731E43C80C00621E92 /* PLC.c in Sources */, >- 5CDD8F4A1E43CB1E00621E92 /* prefilter_FIX.c in Sources */, >- 5CDD8EF51E43C9F600621E92 /* prefilter_FLP.c in Sources */, > 5CDD8F4B1E43CB1E00621E92 /* process_gains_FIX.c in Sources */, > 5CDD8EF61E43C9F600621E92 /* process_gains_FLP.c in Sources */, > 5CDD8E751E43C80C00621E92 /* process_NLSFs.c in Sources */, >@@ -15876,6 +15878,7 @@ > 5CDD8E791E43C80C00621E92 /* resampler_private_AR2.c in Sources */, > 5CDD8E7A1E43C80C00621E92 /* resampler_private_down_FIR.c in Sources */, > 5CDD8E7B1E43C80C00621E92 /* resampler_private_IIR_FIR.c in Sources */, >+ 4153CD2821CC664800C3E188 /* vq_sse2.c in Sources */, > 5CDD8E7C1E43C80C00621E92 /* resampler_private_up2_HQ.c in Sources */, > 5CDD8E7E1E43C80C00621E92 /* resampler_rom.c in Sources */, > 5CDD8F4E1E43CB1E00621E92 /* residual_energy16_FIX.c in Sources */, >@@ -15888,8 +15891,7 @@ > 5CDD8EFB1E43C9F600621E92 /* schur_FLP.c in Sources */, > 5CDD8E821E43C80C00621E92 /* shell_coder.c in Sources */, > 5CDD8E831E43C80C00621E92 /* sigm_Q15.c in Sources */, >- 5CDD8F511E43CB1E00621E92 /* solve_LS_FIX.c in Sources */, >- 5CDD8EFD1E43C9F600621E92 /* solve_LS_FLP.c in Sources */, >+ 4153CD2721CC661000C3E188 /* LPC_fit.c in Sources */, > 5CDD8E851E43C80C00621E92 /* sort.c in Sources */, > 5CDD8EFE1E43C9F600621E92 /* sort_FLP.c in Sources */, > 5CDD8E861E43C80C00621E92 /* stereo_decode_pred.c in Sources */,
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 192867
:
357699
|
357703
|
357709
|
357897
|
357903