@mentra/bluetooth-sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +278 -0
- package/android/build.gradle +167 -0
- package/android/lc3Lib/CMakeLists.txt +6 -0
- package/android/lc3Lib/build.gradle +109 -0
- package/android/lc3Lib/proguard-rules.pro +33 -0
- package/android/lc3Lib/src/main/AndroidManifest.xml +2 -0
- package/android/lc3Lib/src/main/cpp/CMakeLists.txt +8 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/CMakeLists.txt +30 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/jni/CMakeLists.txt +7 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/jni/ogg_opus_encoder.cc +96 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/jni/ogg_opus_encoder.h +53 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/Makefile.am +6 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/config_types.h +26 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/config_types.h.in +26 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/ogg.h +209 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/os_types.h +158 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus.h +981 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_custom.h +342 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_defines.h +799 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_multistream.h +660 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_projection.h +568 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_types.h +166 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/ogg_opus_encoder.cc +268 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/ogg_opus_encoder.h +115 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/opus_tools/opus_header.h +59 -0
- package/android/lc3Lib/src/main/cpp/liblc3/CMakeLists.txt +38 -0
- package/android/lc3Lib/src/main/cpp/liblc3/include/lc3.h +309 -0
- package/android/lc3Lib/src/main/cpp/liblc3/include/lc3_private.h +162 -0
- package/android/lc3Lib/src/main/cpp/liblc3/include/rnnoise.h +114 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/CMakeLists.txt +19 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/attdet.c +92 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/attdet.h +44 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/bits.c +375 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/bits.h +315 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/bwdet.c +129 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/bwdet.h +69 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/common.h +148 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/energy.c +70 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/energy.h +43 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/fastmath.h +158 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/lc3.c +702 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/ltpf.c +893 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/ltpf.h +111 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/ltpf_arm.h +506 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/ltpf_neon.h +281 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/makefile.mk +35 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/mdct.c +452 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/mdct.h +57 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/mdct_neon.h +296 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/meson.build +46 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/plc.c +61 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/plc.h +57 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/sns.c +880 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/sns.h +103 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/spec.c +904 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/spec.h +119 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/tables.c +3457 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/tables.h +94 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/tns.c +457 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/tns.h +99 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3.cpp +159 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/_kiss_fft_guts.h +182 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/arch.h +261 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/celt_lpc.c +279 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/celt_lpc.h +59 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/common.h +48 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/compile.sh +3 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/denoise.c +646 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/kiss_fft.c +601 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/kiss_fft.h +203 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/opus_types.h +159 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/pitch.c +526 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/pitch.h +149 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn.c +178 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn.h +69 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn_data.c +11051 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn_data.h +34 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn_reader.c +168 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn_train.py +66 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/tansig_table.h +45 -0
- package/android/lc3Lib/src/main/java/com/mentra/lc3Lib/Lc3Cpp.java +38 -0
- package/android/lc3Lib/third_party/CMakeLists.txt +23 -0
- package/android/lc3Lib/third_party/CMakeLists_libogg.txt +18 -0
- package/android/lc3Lib/third_party/CMakeLists_libopus.txt +18 -0
- package/android/lc3Lib/third_party/CMakeLists_opus-tools.txt +23 -0
- package/android/lc3Lib/third_party/opus_tools/src/AUTHORS +5 -0
- package/android/lc3Lib/third_party/opus_tools/src/CMakeLists.txt +4 -0
- package/android/lc3Lib/third_party/opus_tools/src/COPYING +371 -0
- package/android/lc3Lib/third_party/opus_tools/src/ChangeLog +3 -0
- package/android/lc3Lib/third_party/opus_tools/src/Makefile.am +42 -0
- package/android/lc3Lib/third_party/opus_tools/src/Makefile.unix +23 -0
- package/android/lc3Lib/third_party/opus_tools/src/NEWS +0 -0
- package/android/lc3Lib/third_party/opus_tools/src/README +0 -0
- package/android/lc3Lib/third_party/opus_tools/src/autogen.sh +115 -0
- package/android/lc3Lib/third_party/opus_tools/src/configure.ac +293 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/arch.h +239 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/audio-in.c +1046 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/diag_range.c +245 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/diag_range.h +28 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/info_opus.c +320 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/info_opus.h +51 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/lpc.c +157 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/lpc.h +27 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opus_header.c +286 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opus_header.h +59 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opusdec.c +884 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opusenc.c +1021 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opusenc.h +101 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opusinfo.c +639 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opusinfo.h +51 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/os_support.h +167 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/resample.c +1137 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/speex_resampler.h +344 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/stack_alloc.h +115 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/wav_io.c +125 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/wav_io.h +62 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/wave_out.c +223 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/wave_out.h +60 -0
- package/android/settings.gradle +1 -0
- package/android/src/main/AndroidManifest.xml +40 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkModule.kt +528 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/Bridge.kt +610 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/DeviceManager.kt +1616 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/DeviceStore.kt +314 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/MentraBluetoothModels.kt +1710 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/MentraBluetoothSdk.kt +554 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/ObservableStore.kt +68 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/controllers/ControllerManager.kt +158 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/controllers/R1.kt +934 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/services/Foreground.kt +175 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/services/PhoneMic.kt +1109 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/G1.java +3974 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/G2.kt +3551 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/Mach1.java +1327 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLive.java +6959 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraNex.kt +1655 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraosBle.java +53675 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/SGCManager.kt +202 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/Simulated.kt +224 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/STTTools.kt +340 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/SherpaOnnxTranscriber.kt +465 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/VadGateSpeechPolicy.kt +221 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/AES.java +106 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/AudioSessionMonitor.kt +189 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/BitmapJavaUtils.java +169 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/BlePhotoUploadService.java +179 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/Constants.kt +44 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/G1Text.kt +436 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/IncidentLogBleRelayNaming.java +29 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/IncidentLogBleUploadService.java +76 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/K900ProtocolUtils.java +791 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/MessageChunker.java +186 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/NexSGCUtils.kt +589 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/PhoneAudioMonitor.kt +303 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/SmartGlassesConnectionState.java +9 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/ByteUtilAudioPlayer.java +655 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/Lc3Player.java +441 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/PCMAudioPlayer.java +431 -0
- package/android/src/main/res/values/strings.xml +4 -0
- package/app.plugin.js +1 -0
- package/build/BluetoothSdk.types.d.ts +498 -0
- package/build/BluetoothSdk.types.d.ts.map +1 -0
- package/build/BluetoothSdk.types.js +23 -0
- package/build/BluetoothSdk.types.js.map +1 -0
- package/build/BluetoothSdkModule.d.ts +71 -0
- package/build/BluetoothSdkModule.d.ts.map +1 -0
- package/build/BluetoothSdkModule.js +106 -0
- package/build/BluetoothSdkModule.js.map +1 -0
- package/build/index.d.ts +3 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +5 -0
- package/build/index.js.map +1 -0
- package/expo-module.config.json +9 -0
- package/ios/BluetoothSdkModule.swift +665 -0
- package/ios/MentraBluetoothSDK.podspec +77 -0
- package/ios/Packages/CoreObjC/CoreObjC.xcodeproj/project.pbxproj +213 -0
- package/ios/Packages/CoreObjC/PcmConverter.h +22 -0
- package/ios/Packages/CoreObjC/PcmConverter.m +266 -0
- package/ios/Packages/CoreObjC/attdet.c +92 -0
- package/ios/Packages/CoreObjC/attdet.h +44 -0
- package/ios/Packages/CoreObjC/bits.c +375 -0
- package/ios/Packages/CoreObjC/bits.h +315 -0
- package/ios/Packages/CoreObjC/bwdet.c +129 -0
- package/ios/Packages/CoreObjC/bwdet.h +69 -0
- package/ios/Packages/CoreObjC/common.h +151 -0
- package/ios/Packages/CoreObjC/energy.c +70 -0
- package/ios/Packages/CoreObjC/energy.h +43 -0
- package/ios/Packages/CoreObjC/fastmath.h +158 -0
- package/ios/Packages/CoreObjC/lc3.c +704 -0
- package/ios/Packages/CoreObjC/lc3.h +313 -0
- package/ios/Packages/CoreObjC/lc3_cpp.h +283 -0
- package/ios/Packages/CoreObjC/lc3_private.h +163 -0
- package/ios/Packages/CoreObjC/ltpf.c +905 -0
- package/ios/Packages/CoreObjC/ltpf.h +111 -0
- package/ios/Packages/CoreObjC/ltpf_arm.h +506 -0
- package/ios/Packages/CoreObjC/ltpf_neon.h +281 -0
- package/ios/Packages/CoreObjC/makefile.mk +35 -0
- package/ios/Packages/CoreObjC/mdct.c +469 -0
- package/ios/Packages/CoreObjC/mdct.h +57 -0
- package/ios/Packages/CoreObjC/mdct_neon.h +296 -0
- package/ios/Packages/CoreObjC/meson.build +61 -0
- package/ios/Packages/CoreObjC/plc.c +61 -0
- package/ios/Packages/CoreObjC/plc.h +57 -0
- package/ios/Packages/CoreObjC/rnnoise.h +114 -0
- package/ios/Packages/CoreObjC/sns.c +880 -0
- package/ios/Packages/CoreObjC/sns.h +103 -0
- package/ios/Packages/CoreObjC/spec.c +907 -0
- package/ios/Packages/CoreObjC/spec.h +119 -0
- package/ios/Packages/CoreObjC/tables.c +3457 -0
- package/ios/Packages/CoreObjC/tables.h +94 -0
- package/ios/Packages/CoreObjC/tns.c +457 -0
- package/ios/Packages/CoreObjC/tns.h +99 -0
- package/ios/Packages/SherpaOnnx/Model/joiner.onnx +0 -0
- package/ios/Packages/SherpaOnnx/Model/tokens.txt +502 -0
- package/ios/Packages/SherpaOnnx/SherpaOnnx.swift +1659 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/Headers/cargs.h +162 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/Headers/sherpa-onnx/c-api/c-api.h +1852 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/Headers/sherpa-onnx/c-api/cxx-api.h +674 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/Info.plist +44 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64/libsherpa-onnx.a +0 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64/sherpa-onnx.a +0 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64_x86_64-simulator/libsherpa-onnx.a +0 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64_x86_64-simulator/sherpa-onnx.a +0 -0
- package/ios/Packages/VAD/Common/VAD/VADQuality.swift +41 -0
- package/ios/Packages/VAD/Common/VAD/VADState.swift +26 -0
- package/ios/Packages/VAD/Common/VAD/VADStrategy.swift +29 -0
- package/ios/Packages/VAD/Common/VAD/VADType.swift +14 -0
- package/ios/Packages/VAD/Data/Configuration.swift +68 -0
- package/ios/Packages/VAD/Data/FrameSize.swift +39 -0
- package/ios/Packages/VAD/Data/Record.swift +13 -0
- package/ios/Packages/VAD/Data/Result.swift +22 -0
- package/ios/Packages/VAD/Data/SampleRate.swift +48 -0
- package/ios/Packages/VAD/Silero/Model/silero_vad.onnx +0 -0
- package/ios/Packages/VAD/Silero/SileroVAD.swift +284 -0
- package/ios/Packages/VAD/Silero/SileroVADStrategy.swift +64 -0
- package/ios/Packages/libbz2/module.modulemap +5 -0
- package/ios/Packages/libbz2/shim.h +1 -0
- package/ios/Source/Bridge.swift +353 -0
- package/ios/Source/Bridging-Header.h +16 -0
- package/ios/Source/DeviceManager.swift +1478 -0
- package/ios/Source/DeviceStore.swift +295 -0
- package/ios/Source/MentraBluetoothSDK.swift +2439 -0
- package/ios/Source/ObservableStore.swift +88 -0
- package/ios/Source/PrivacyInfo.xcprivacy +23 -0
- package/ios/Source/controllers/ControllerManager.swift +187 -0
- package/ios/Source/controllers/R1.swift +827 -0
- package/ios/Source/services/PhoneMic.swift +662 -0
- package/ios/Source/sgcs/Frame.swift +651 -0
- package/ios/Source/sgcs/G1.swift +2505 -0
- package/ios/Source/sgcs/G2.swift +3730 -0
- package/ios/Source/sgcs/Mach1.swift +543 -0
- package/ios/Source/sgcs/MentraLive.swift +4708 -0
- package/ios/Source/sgcs/MentraNex.swift +2479 -0
- package/ios/Source/sgcs/SGCManager.swift +243 -0
- package/ios/Source/sgcs/Simulated.swift +270 -0
- package/ios/Source/sgcs/mentraos_ble.pb.swift +3811 -0
- package/ios/Source/stt/STTTools.swift +154 -0
- package/ios/Source/stt/SherpaOnnxTranscriber.swift +401 -0
- package/ios/Source/utils/AudioSessionMonitor.swift +283 -0
- package/ios/Source/utils/Constants.swift +74 -0
- package/ios/Source/utils/Enums.swift +95 -0
- package/ios/Source/utils/G1Text.swift +2067 -0
- package/ios/Source/utils/JSCExperiment.swift +241 -0
- package/ios/Source/utils/MemoryMonitor.swift +44 -0
- package/ios/Source/utils/MessageChunker.swift +164 -0
- package/ios/Source/utils/Models.swift +135 -0
- package/ios/Source/utils/PhoneAudioMonitor.swift +226 -0
- package/ios/Source/utils/TarBz2Extractor.swift +206 -0
- package/package.json +78 -0
- package/plugin/build/index.d.ts +6 -0
- package/plugin/build/index.js +12 -0
- package/plugin/build/withAndroid.d.ts +4 -0
- package/plugin/build/withAndroid.js +80 -0
- package/plugin/build/withIos.d.ts +4 -0
- package/plugin/build/withIos.js +64 -0
- package/src/BluetoothSdk.types.ts +581 -0
- package/src/BluetoothSdkModule.ts +259 -0
- package/src/index.ts +4 -0
|
@@ -0,0 +1,526 @@
|
|
|
1
|
+
/* Copyright (c) 2007-2008 CSIRO
|
|
2
|
+
Copyright (c) 2007-2009 Xiph.Org Foundation
|
|
3
|
+
Written by Jean-Marc Valin */
|
|
4
|
+
/**
|
|
5
|
+
@file pitch.c
|
|
6
|
+
@brief Pitch analysis
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
Redistribution and use in source and binary forms, with or without
|
|
11
|
+
modification, are permitted provided that the following conditions
|
|
12
|
+
are met:
|
|
13
|
+
|
|
14
|
+
- Redistributions of source code must retain the above copyright
|
|
15
|
+
notice, this list of conditions and the following disclaimer.
|
|
16
|
+
|
|
17
|
+
- Redistributions in binary form must reproduce the above copyright
|
|
18
|
+
notice, this list of conditions and the following disclaimer in the
|
|
19
|
+
documentation and/or other materials provided with the distribution.
|
|
20
|
+
|
|
21
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
22
|
+
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
23
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
24
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
|
25
|
+
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
26
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
27
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
28
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
29
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
30
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
31
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
#ifdef HAVE_CONFIG_H
|
|
35
|
+
#include "config.h"
|
|
36
|
+
#endif
|
|
37
|
+
|
|
38
|
+
#include "pitch.h"
|
|
39
|
+
#include "common.h"
|
|
40
|
+
//#include "modes.h"
|
|
41
|
+
//#include "stack_alloc.h"
|
|
42
|
+
//#include "mathops.h"
|
|
43
|
+
#include "celt_lpc.h"
|
|
44
|
+
#include "math.h"
|
|
45
|
+
|
|
46
|
+
static void find_best_pitch(opus_val32 *xcorr, opus_val16 *y, int len,
|
|
47
|
+
int max_pitch, int *best_pitch
|
|
48
|
+
#ifdef FIXED_POINT
|
|
49
|
+
, int yshift, opus_val32 maxcorr
|
|
50
|
+
#endif
|
|
51
|
+
)
|
|
52
|
+
{
|
|
53
|
+
int i, j;
|
|
54
|
+
opus_val32 Syy=1;
|
|
55
|
+
opus_val16 best_num[2];
|
|
56
|
+
opus_val32 best_den[2];
|
|
57
|
+
#ifdef FIXED_POINT
|
|
58
|
+
int xshift;
|
|
59
|
+
|
|
60
|
+
xshift = celt_ilog2(maxcorr)-14;
|
|
61
|
+
#endif
|
|
62
|
+
|
|
63
|
+
best_num[0] = -1;
|
|
64
|
+
best_num[1] = -1;
|
|
65
|
+
best_den[0] = 0;
|
|
66
|
+
best_den[1] = 0;
|
|
67
|
+
best_pitch[0] = 0;
|
|
68
|
+
best_pitch[1] = 1;
|
|
69
|
+
for (j=0;j<len;j++)
|
|
70
|
+
Syy = ADD32(Syy, SHR32(MULT16_16(y[j],y[j]), yshift));
|
|
71
|
+
for (i=0;i<max_pitch;i++)
|
|
72
|
+
{
|
|
73
|
+
if (xcorr[i]>0)
|
|
74
|
+
{
|
|
75
|
+
opus_val16 num;
|
|
76
|
+
opus_val32 xcorr16;
|
|
77
|
+
xcorr16 = EXTRACT16(VSHR32(xcorr[i], xshift));
|
|
78
|
+
#ifndef FIXED_POINT
|
|
79
|
+
/* Considering the range of xcorr16, this should avoid both underflows
|
|
80
|
+
and overflows (inf) when squaring xcorr16 */
|
|
81
|
+
xcorr16 *= 1e-12f;
|
|
82
|
+
#endif
|
|
83
|
+
num = MULT16_16_Q15(xcorr16,xcorr16);
|
|
84
|
+
if (MULT16_32_Q15(num,best_den[1]) > MULT16_32_Q15(best_num[1],Syy))
|
|
85
|
+
{
|
|
86
|
+
if (MULT16_32_Q15(num,best_den[0]) > MULT16_32_Q15(best_num[0],Syy))
|
|
87
|
+
{
|
|
88
|
+
best_num[1] = best_num[0];
|
|
89
|
+
best_den[1] = best_den[0];
|
|
90
|
+
best_pitch[1] = best_pitch[0];
|
|
91
|
+
best_num[0] = num;
|
|
92
|
+
best_den[0] = Syy;
|
|
93
|
+
best_pitch[0] = i;
|
|
94
|
+
} else {
|
|
95
|
+
best_num[1] = num;
|
|
96
|
+
best_den[1] = Syy;
|
|
97
|
+
best_pitch[1] = i;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
Syy += SHR32(MULT16_16(y[i+len],y[i+len]),yshift) - SHR32(MULT16_16(y[i],y[i]),yshift);
|
|
102
|
+
Syy = MAX32(1, Syy);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
static void celt_fir5(const opus_val16 *x,
|
|
107
|
+
const opus_val16 *num,
|
|
108
|
+
opus_val16 *y,
|
|
109
|
+
int N,
|
|
110
|
+
opus_val16 *mem)
|
|
111
|
+
{
|
|
112
|
+
int i;
|
|
113
|
+
opus_val16 num0, num1, num2, num3, num4;
|
|
114
|
+
opus_val32 mem0, mem1, mem2, mem3, mem4;
|
|
115
|
+
num0=num[0];
|
|
116
|
+
num1=num[1];
|
|
117
|
+
num2=num[2];
|
|
118
|
+
num3=num[3];
|
|
119
|
+
num4=num[4];
|
|
120
|
+
mem0=mem[0];
|
|
121
|
+
mem1=mem[1];
|
|
122
|
+
mem2=mem[2];
|
|
123
|
+
mem3=mem[3];
|
|
124
|
+
mem4=mem[4];
|
|
125
|
+
for (i=0;i<N;i++)
|
|
126
|
+
{
|
|
127
|
+
opus_val32 sum = SHL32(EXTEND32(x[i]), SIG_SHIFT);
|
|
128
|
+
sum = MAC16_16(sum,num0,mem0);
|
|
129
|
+
sum = MAC16_16(sum,num1,mem1);
|
|
130
|
+
sum = MAC16_16(sum,num2,mem2);
|
|
131
|
+
sum = MAC16_16(sum,num3,mem3);
|
|
132
|
+
sum = MAC16_16(sum,num4,mem4);
|
|
133
|
+
mem4 = mem3;
|
|
134
|
+
mem3 = mem2;
|
|
135
|
+
mem2 = mem1;
|
|
136
|
+
mem1 = mem0;
|
|
137
|
+
mem0 = x[i];
|
|
138
|
+
y[i] = ROUND16(sum, SIG_SHIFT);
|
|
139
|
+
}
|
|
140
|
+
mem[0]=mem0;
|
|
141
|
+
mem[1]=mem1;
|
|
142
|
+
mem[2]=mem2;
|
|
143
|
+
mem[3]=mem3;
|
|
144
|
+
mem[4]=mem4;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
void pitch_downsample(celt_sig *x[], opus_val16 *x_lp,
|
|
149
|
+
int len, int C)
|
|
150
|
+
{
|
|
151
|
+
int i;
|
|
152
|
+
opus_val32 ac[5];
|
|
153
|
+
opus_val16 tmp=Q15ONE;
|
|
154
|
+
opus_val16 lpc[4], mem[5]={0,0,0,0,0};
|
|
155
|
+
opus_val16 lpc2[5];
|
|
156
|
+
opus_val16 c1 = QCONST16(.8f,15);
|
|
157
|
+
#ifdef FIXED_POINT
|
|
158
|
+
int shift;
|
|
159
|
+
opus_val32 maxabs = celt_maxabs32(x[0], len);
|
|
160
|
+
if (C==2)
|
|
161
|
+
{
|
|
162
|
+
opus_val32 maxabs_1 = celt_maxabs32(x[1], len);
|
|
163
|
+
maxabs = MAX32(maxabs, maxabs_1);
|
|
164
|
+
}
|
|
165
|
+
if (maxabs<1)
|
|
166
|
+
maxabs=1;
|
|
167
|
+
shift = celt_ilog2(maxabs)-10;
|
|
168
|
+
if (shift<0)
|
|
169
|
+
shift=0;
|
|
170
|
+
if (C==2)
|
|
171
|
+
shift++;
|
|
172
|
+
#endif
|
|
173
|
+
for (i=1;i<len>>1;i++)
|
|
174
|
+
x_lp[i] = SHR32(HALF32(HALF32(x[0][(2*i-1)]+x[0][(2*i+1)])+x[0][2*i]), shift);
|
|
175
|
+
x_lp[0] = SHR32(HALF32(HALF32(x[0][1])+x[0][0]), shift);
|
|
176
|
+
if (C==2)
|
|
177
|
+
{
|
|
178
|
+
for (i=1;i<len>>1;i++)
|
|
179
|
+
x_lp[i] += SHR32(HALF32(HALF32(x[1][(2*i-1)]+x[1][(2*i+1)])+x[1][2*i]), shift);
|
|
180
|
+
x_lp[0] += SHR32(HALF32(HALF32(x[1][1])+x[1][0]), shift);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
_celt_autocorr(x_lp, ac, NULL, 0,
|
|
184
|
+
4, len>>1);
|
|
185
|
+
|
|
186
|
+
/* Noise floor -40 dB */
|
|
187
|
+
#ifdef FIXED_POINT
|
|
188
|
+
ac[0] += SHR32(ac[0],13);
|
|
189
|
+
#else
|
|
190
|
+
ac[0] *= 1.0001f;
|
|
191
|
+
#endif
|
|
192
|
+
/* Lag windowing */
|
|
193
|
+
for (i=1;i<=4;i++)
|
|
194
|
+
{
|
|
195
|
+
/*ac[i] *= exp(-.5*(2*M_PI*.002*i)*(2*M_PI*.002*i));*/
|
|
196
|
+
#ifdef FIXED_POINT
|
|
197
|
+
ac[i] -= MULT16_32_Q15(2*i*i, ac[i]);
|
|
198
|
+
#else
|
|
199
|
+
ac[i] -= ac[i]*(.008f*i)*(.008f*i);
|
|
200
|
+
#endif
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
_celt_lpc(lpc, ac, 4);
|
|
204
|
+
for (i=0;i<4;i++)
|
|
205
|
+
{
|
|
206
|
+
tmp = MULT16_16_Q15(QCONST16(.9f,15), tmp);
|
|
207
|
+
lpc[i] = MULT16_16_Q15(lpc[i], tmp);
|
|
208
|
+
}
|
|
209
|
+
/* Add a zero */
|
|
210
|
+
lpc2[0] = lpc[0] + QCONST16(.8f,SIG_SHIFT);
|
|
211
|
+
lpc2[1] = lpc[1] + MULT16_16_Q15(c1,lpc[0]);
|
|
212
|
+
lpc2[2] = lpc[2] + MULT16_16_Q15(c1,lpc[1]);
|
|
213
|
+
lpc2[3] = lpc[3] + MULT16_16_Q15(c1,lpc[2]);
|
|
214
|
+
lpc2[4] = MULT16_16_Q15(c1,lpc[3]);
|
|
215
|
+
celt_fir5(x_lp, lpc2, x_lp, len>>1, mem);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
void celt_pitch_xcorr(const opus_val16 *_x, const opus_val16 *_y,
|
|
219
|
+
opus_val32 *xcorr, int len, int max_pitch)
|
|
220
|
+
{
|
|
221
|
+
|
|
222
|
+
#if 0 /* This is a simple version of the pitch correlation that should work
|
|
223
|
+
well on DSPs like Blackfin and TI C5x/C6x */
|
|
224
|
+
int i, j;
|
|
225
|
+
#ifdef FIXED_POINT
|
|
226
|
+
opus_val32 maxcorr=1;
|
|
227
|
+
#endif
|
|
228
|
+
for (i=0;i<max_pitch;i++)
|
|
229
|
+
{
|
|
230
|
+
opus_val32 sum = 0;
|
|
231
|
+
for (j=0;j<len;j++)
|
|
232
|
+
sum = MAC16_16(sum, _x[j], _y[i+j]);
|
|
233
|
+
xcorr[i] = sum;
|
|
234
|
+
#ifdef FIXED_POINT
|
|
235
|
+
maxcorr = MAX32(maxcorr, sum);
|
|
236
|
+
#endif
|
|
237
|
+
}
|
|
238
|
+
#ifdef FIXED_POINT
|
|
239
|
+
return maxcorr;
|
|
240
|
+
#endif
|
|
241
|
+
|
|
242
|
+
#else /* Unrolled version of the pitch correlation -- runs faster on x86 and ARM */
|
|
243
|
+
int i;
|
|
244
|
+
/*The EDSP version requires that max_pitch is at least 1, and that _x is
|
|
245
|
+
32-bit aligned.
|
|
246
|
+
Since it's hard to put asserts in assembly, put them here.*/
|
|
247
|
+
#ifdef FIXED_POINT
|
|
248
|
+
opus_val32 maxcorr=1;
|
|
249
|
+
#endif
|
|
250
|
+
celt_assert(max_pitch>0);
|
|
251
|
+
celt_assert((((unsigned char *)_x-(unsigned char *)NULL)&3)==0);
|
|
252
|
+
for (i=0;i<max_pitch-3;i+=4)
|
|
253
|
+
{
|
|
254
|
+
opus_val32 sum[4]={0,0,0,0};
|
|
255
|
+
xcorr_kernel(_x, _y+i, sum, len);
|
|
256
|
+
xcorr[i]=sum[0];
|
|
257
|
+
xcorr[i+1]=sum[1];
|
|
258
|
+
xcorr[i+2]=sum[2];
|
|
259
|
+
xcorr[i+3]=sum[3];
|
|
260
|
+
#ifdef FIXED_POINT
|
|
261
|
+
sum[0] = MAX32(sum[0], sum[1]);
|
|
262
|
+
sum[2] = MAX32(sum[2], sum[3]);
|
|
263
|
+
sum[0] = MAX32(sum[0], sum[2]);
|
|
264
|
+
maxcorr = MAX32(maxcorr, sum[0]);
|
|
265
|
+
#endif
|
|
266
|
+
}
|
|
267
|
+
/* In case max_pitch isn't a multiple of 4, do non-unrolled version. */
|
|
268
|
+
for (;i<max_pitch;i++)
|
|
269
|
+
{
|
|
270
|
+
opus_val32 sum;
|
|
271
|
+
sum = celt_inner_prod(_x, _y+i, len);
|
|
272
|
+
xcorr[i] = sum;
|
|
273
|
+
#ifdef FIXED_POINT
|
|
274
|
+
maxcorr = MAX32(maxcorr, sum);
|
|
275
|
+
#endif
|
|
276
|
+
}
|
|
277
|
+
#ifdef FIXED_POINT
|
|
278
|
+
return maxcorr;
|
|
279
|
+
#endif
|
|
280
|
+
#endif
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
void pitch_search(const opus_val16 *x_lp, opus_val16 *y,
|
|
284
|
+
int len, int max_pitch, int *pitch)
|
|
285
|
+
{
|
|
286
|
+
int i, j;
|
|
287
|
+
int lag;
|
|
288
|
+
int best_pitch[2]={0,0};
|
|
289
|
+
#ifdef FIXED_POINT
|
|
290
|
+
opus_val32 maxcorr;
|
|
291
|
+
opus_val32 xmax, ymax;
|
|
292
|
+
int shift=0;
|
|
293
|
+
#endif
|
|
294
|
+
int offset;
|
|
295
|
+
|
|
296
|
+
celt_assert(len>0);
|
|
297
|
+
celt_assert(max_pitch>0);
|
|
298
|
+
lag = len+max_pitch;
|
|
299
|
+
|
|
300
|
+
opus_val16 x_lp4[len>>2];
|
|
301
|
+
opus_val16 y_lp4[lag>>2];
|
|
302
|
+
opus_val32 xcorr[max_pitch>>1];
|
|
303
|
+
|
|
304
|
+
/* Downsample by 2 again */
|
|
305
|
+
for (j=0;j<len>>2;j++)
|
|
306
|
+
x_lp4[j] = x_lp[2*j];
|
|
307
|
+
for (j=0;j<lag>>2;j++)
|
|
308
|
+
y_lp4[j] = y[2*j];
|
|
309
|
+
|
|
310
|
+
#ifdef FIXED_POINT
|
|
311
|
+
xmax = celt_maxabs16(x_lp4, len>>2);
|
|
312
|
+
ymax = celt_maxabs16(y_lp4, lag>>2);
|
|
313
|
+
shift = celt_ilog2(MAX32(1, MAX32(xmax, ymax)))-11;
|
|
314
|
+
if (shift>0)
|
|
315
|
+
{
|
|
316
|
+
for (j=0;j<len>>2;j++)
|
|
317
|
+
x_lp4[j] = SHR16(x_lp4[j], shift);
|
|
318
|
+
for (j=0;j<lag>>2;j++)
|
|
319
|
+
y_lp4[j] = SHR16(y_lp4[j], shift);
|
|
320
|
+
/* Use double the shift for a MAC */
|
|
321
|
+
shift *= 2;
|
|
322
|
+
} else {
|
|
323
|
+
shift = 0;
|
|
324
|
+
}
|
|
325
|
+
#endif
|
|
326
|
+
|
|
327
|
+
/* Coarse search with 4x decimation */
|
|
328
|
+
|
|
329
|
+
#ifdef FIXED_POINT
|
|
330
|
+
maxcorr =
|
|
331
|
+
#endif
|
|
332
|
+
celt_pitch_xcorr(x_lp4, y_lp4, xcorr, len>>2, max_pitch>>2);
|
|
333
|
+
|
|
334
|
+
find_best_pitch(xcorr, y_lp4, len>>2, max_pitch>>2, best_pitch
|
|
335
|
+
#ifdef FIXED_POINT
|
|
336
|
+
, 0, maxcorr
|
|
337
|
+
#endif
|
|
338
|
+
);
|
|
339
|
+
|
|
340
|
+
/* Finer search with 2x decimation */
|
|
341
|
+
#ifdef FIXED_POINT
|
|
342
|
+
maxcorr=1;
|
|
343
|
+
#endif
|
|
344
|
+
for (i=0;i<max_pitch>>1;i++)
|
|
345
|
+
{
|
|
346
|
+
opus_val32 sum;
|
|
347
|
+
xcorr[i] = 0;
|
|
348
|
+
if (abs(i-2*best_pitch[0])>2 && abs(i-2*best_pitch[1])>2)
|
|
349
|
+
continue;
|
|
350
|
+
#ifdef FIXED_POINT
|
|
351
|
+
sum = 0;
|
|
352
|
+
for (j=0;j<len>>1;j++)
|
|
353
|
+
sum += SHR32(MULT16_16(x_lp[j],y[i+j]), shift);
|
|
354
|
+
#else
|
|
355
|
+
sum = celt_inner_prod(x_lp, y+i, len>>1);
|
|
356
|
+
#endif
|
|
357
|
+
xcorr[i] = MAX32(-1, sum);
|
|
358
|
+
#ifdef FIXED_POINT
|
|
359
|
+
maxcorr = MAX32(maxcorr, sum);
|
|
360
|
+
#endif
|
|
361
|
+
}
|
|
362
|
+
find_best_pitch(xcorr, y, len>>1, max_pitch>>1, best_pitch
|
|
363
|
+
#ifdef FIXED_POINT
|
|
364
|
+
, shift+1, maxcorr
|
|
365
|
+
#endif
|
|
366
|
+
);
|
|
367
|
+
|
|
368
|
+
/* Refine by pseudo-interpolation */
|
|
369
|
+
if (best_pitch[0]>0 && best_pitch[0]<(max_pitch>>1)-1)
|
|
370
|
+
{
|
|
371
|
+
opus_val32 a, b, c;
|
|
372
|
+
a = xcorr[best_pitch[0]-1];
|
|
373
|
+
b = xcorr[best_pitch[0]];
|
|
374
|
+
c = xcorr[best_pitch[0]+1];
|
|
375
|
+
if ((c-a) > MULT16_32_Q15(QCONST16(.7f,15),b-a))
|
|
376
|
+
offset = 1;
|
|
377
|
+
else if ((a-c) > MULT16_32_Q15(QCONST16(.7f,15),b-c))
|
|
378
|
+
offset = -1;
|
|
379
|
+
else
|
|
380
|
+
offset = 0;
|
|
381
|
+
} else {
|
|
382
|
+
offset = 0;
|
|
383
|
+
}
|
|
384
|
+
*pitch = 2*best_pitch[0]-offset;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
#ifdef FIXED_POINT
|
|
388
|
+
static opus_val16 compute_pitch_gain(opus_val32 xy, opus_val32 xx, opus_val32 yy)
|
|
389
|
+
{
|
|
390
|
+
opus_val32 x2y2;
|
|
391
|
+
int sx, sy, shift;
|
|
392
|
+
opus_val32 g;
|
|
393
|
+
opus_val16 den;
|
|
394
|
+
if (xy == 0 || xx == 0 || yy == 0)
|
|
395
|
+
return 0;
|
|
396
|
+
sx = celt_ilog2(xx)-14;
|
|
397
|
+
sy = celt_ilog2(yy)-14;
|
|
398
|
+
shift = sx + sy;
|
|
399
|
+
x2y2 = SHR32(MULT16_16(VSHR32(xx, sx), VSHR32(yy, sy)), 14);
|
|
400
|
+
if (shift & 1) {
|
|
401
|
+
if (x2y2 < 32768)
|
|
402
|
+
{
|
|
403
|
+
x2y2 <<= 1;
|
|
404
|
+
shift--;
|
|
405
|
+
} else {
|
|
406
|
+
x2y2 >>= 1;
|
|
407
|
+
shift++;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
den = celt_rsqrt_norm(x2y2);
|
|
411
|
+
g = MULT16_32_Q15(den, xy);
|
|
412
|
+
g = VSHR32(g, (shift>>1)-1);
|
|
413
|
+
return EXTRACT16(MIN32(g, Q15ONE));
|
|
414
|
+
}
|
|
415
|
+
#else
|
|
416
|
+
static opus_val16 compute_pitch_gain(opus_val32 xy, opus_val32 xx, opus_val32 yy)
|
|
417
|
+
{
|
|
418
|
+
return xy/sqrt(1+xx*yy);
|
|
419
|
+
}
|
|
420
|
+
#endif
|
|
421
|
+
|
|
422
|
+
static const int second_check[16] = {0, 0, 3, 2, 3, 2, 5, 2, 3, 2, 3, 2, 5, 2, 3, 2};
|
|
423
|
+
opus_val16 remove_doubling(opus_val16 *x, int maxperiod, int minperiod,
|
|
424
|
+
int N, int *T0_, int prev_period, opus_val16 prev_gain)
|
|
425
|
+
{
|
|
426
|
+
int k, i, T, T0;
|
|
427
|
+
opus_val16 g, g0;
|
|
428
|
+
opus_val16 pg;
|
|
429
|
+
opus_val32 xy,xx,yy,xy2;
|
|
430
|
+
opus_val32 xcorr[3];
|
|
431
|
+
opus_val32 best_xy, best_yy;
|
|
432
|
+
int offset;
|
|
433
|
+
int minperiod0;
|
|
434
|
+
|
|
435
|
+
minperiod0 = minperiod;
|
|
436
|
+
maxperiod /= 2;
|
|
437
|
+
minperiod /= 2;
|
|
438
|
+
*T0_ /= 2;
|
|
439
|
+
prev_period /= 2;
|
|
440
|
+
N /= 2;
|
|
441
|
+
x += maxperiod;
|
|
442
|
+
if (*T0_>=maxperiod)
|
|
443
|
+
*T0_=maxperiod-1;
|
|
444
|
+
|
|
445
|
+
T = T0 = *T0_;
|
|
446
|
+
opus_val32 yy_lookup[maxperiod+1];
|
|
447
|
+
dual_inner_prod(x, x, x-T0, N, &xx, &xy);
|
|
448
|
+
yy_lookup[0] = xx;
|
|
449
|
+
yy=xx;
|
|
450
|
+
for (i=1;i<=maxperiod;i++)
|
|
451
|
+
{
|
|
452
|
+
yy = yy+MULT16_16(x[-i],x[-i])-MULT16_16(x[N-i],x[N-i]);
|
|
453
|
+
yy_lookup[i] = MAX32(0, yy);
|
|
454
|
+
}
|
|
455
|
+
yy = yy_lookup[T0];
|
|
456
|
+
best_xy = xy;
|
|
457
|
+
best_yy = yy;
|
|
458
|
+
g = g0 = compute_pitch_gain(xy, xx, yy);
|
|
459
|
+
/* Look for any pitch at T/k */
|
|
460
|
+
for (k=2;k<=15;k++)
|
|
461
|
+
{
|
|
462
|
+
int T1, T1b;
|
|
463
|
+
opus_val16 g1;
|
|
464
|
+
opus_val16 cont=0;
|
|
465
|
+
opus_val16 thresh;
|
|
466
|
+
T1 = (2*T0+k)/(2*k);
|
|
467
|
+
if (T1 < minperiod)
|
|
468
|
+
break;
|
|
469
|
+
/* Look for another strong correlation at T1b */
|
|
470
|
+
if (k==2)
|
|
471
|
+
{
|
|
472
|
+
if (T1+T0>maxperiod)
|
|
473
|
+
T1b = T0;
|
|
474
|
+
else
|
|
475
|
+
T1b = T0+T1;
|
|
476
|
+
} else
|
|
477
|
+
{
|
|
478
|
+
T1b = (2*second_check[k]*T0+k)/(2*k);
|
|
479
|
+
}
|
|
480
|
+
dual_inner_prod(x, &x[-T1], &x[-T1b], N, &xy, &xy2);
|
|
481
|
+
xy = HALF32(xy + xy2);
|
|
482
|
+
yy = HALF32(yy_lookup[T1] + yy_lookup[T1b]);
|
|
483
|
+
g1 = compute_pitch_gain(xy, xx, yy);
|
|
484
|
+
if (abs(T1-prev_period)<=1)
|
|
485
|
+
cont = prev_gain;
|
|
486
|
+
else if (abs(T1-prev_period)<=2 && 5*k*k < T0)
|
|
487
|
+
cont = HALF16(prev_gain);
|
|
488
|
+
else
|
|
489
|
+
cont = 0;
|
|
490
|
+
thresh = MAX16(QCONST16(.3f,15), MULT16_16_Q15(QCONST16(.7f,15),g0)-cont);
|
|
491
|
+
/* Bias against very high pitch (very short period) to avoid false-positives
|
|
492
|
+
due to short-term correlation */
|
|
493
|
+
if (T1<3*minperiod)
|
|
494
|
+
thresh = MAX16(QCONST16(.4f,15), MULT16_16_Q15(QCONST16(.85f,15),g0)-cont);
|
|
495
|
+
else if (T1<2*minperiod)
|
|
496
|
+
thresh = MAX16(QCONST16(.5f,15), MULT16_16_Q15(QCONST16(.9f,15),g0)-cont);
|
|
497
|
+
if (g1 > thresh)
|
|
498
|
+
{
|
|
499
|
+
best_xy = xy;
|
|
500
|
+
best_yy = yy;
|
|
501
|
+
T = T1;
|
|
502
|
+
g = g1;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
best_xy = MAX32(0, best_xy);
|
|
506
|
+
if (best_yy <= best_xy)
|
|
507
|
+
pg = Q15ONE;
|
|
508
|
+
else
|
|
509
|
+
pg = best_xy/(best_yy+1);
|
|
510
|
+
|
|
511
|
+
for (k=0;k<3;k++)
|
|
512
|
+
xcorr[k] = celt_inner_prod(x, x-(T+k-1), N);
|
|
513
|
+
if ((xcorr[2]-xcorr[0]) > MULT16_32_Q15(QCONST16(.7f,15),xcorr[1]-xcorr[0]))
|
|
514
|
+
offset = 1;
|
|
515
|
+
else if ((xcorr[0]-xcorr[2]) > MULT16_32_Q15(QCONST16(.7f,15),xcorr[1]-xcorr[2]))
|
|
516
|
+
offset = -1;
|
|
517
|
+
else
|
|
518
|
+
offset = 0;
|
|
519
|
+
if (pg > g)
|
|
520
|
+
pg = g;
|
|
521
|
+
*T0_ = 2*T+offset;
|
|
522
|
+
|
|
523
|
+
if (*T0_<minperiod0)
|
|
524
|
+
*T0_=minperiod0;
|
|
525
|
+
return pg;
|
|
526
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/* Copyright (c) 2007-2008 CSIRO
|
|
2
|
+
Copyright (c) 2007-2009 Xiph.Org Foundation
|
|
3
|
+
Written by Jean-Marc Valin */
|
|
4
|
+
/**
|
|
5
|
+
@file pitch.h
|
|
6
|
+
@brief Pitch analysis
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
Redistribution and use in source and binary forms, with or without
|
|
11
|
+
modification, are permitted provided that the following conditions
|
|
12
|
+
are met:
|
|
13
|
+
|
|
14
|
+
- Redistributions of source code must retain the above copyright
|
|
15
|
+
notice, this list of conditions and the following disclaimer.
|
|
16
|
+
|
|
17
|
+
- Redistributions in binary form must reproduce the above copyright
|
|
18
|
+
notice, this list of conditions and the following disclaimer in the
|
|
19
|
+
documentation and/or other materials provided with the distribution.
|
|
20
|
+
|
|
21
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
22
|
+
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
23
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
24
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
|
25
|
+
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
26
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
27
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
28
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
29
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
30
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
31
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
#ifndef PITCH_H
|
|
35
|
+
#define PITCH_H
|
|
36
|
+
|
|
37
|
+
//#include "modes.h"
|
|
38
|
+
//#include "cpu_support.h"
|
|
39
|
+
#include "arch.h"
|
|
40
|
+
|
|
41
|
+
void pitch_downsample(celt_sig *x[], opus_val16 *x_lp,
|
|
42
|
+
int len, int C);
|
|
43
|
+
|
|
44
|
+
void pitch_search(const opus_val16 *x_lp, opus_val16 *y,
|
|
45
|
+
int len, int max_pitch, int *pitch);
|
|
46
|
+
|
|
47
|
+
opus_val16 remove_doubling(opus_val16 *x, int maxperiod, int minperiod,
|
|
48
|
+
int N, int *T0, int prev_period, opus_val16 prev_gain);
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
/* OPT: This is the kernel you really want to optimize. It gets used a lot
|
|
52
|
+
by the prefilter and by the PLC. */
|
|
53
|
+
static OPUS_INLINE void xcorr_kernel(const opus_val16 * x, const opus_val16 * y, opus_val32 sum[4], int len)
|
|
54
|
+
{
|
|
55
|
+
int j;
|
|
56
|
+
opus_val16 y_0, y_1, y_2, y_3;
|
|
57
|
+
celt_assert(len>=3);
|
|
58
|
+
y_3=0; /* gcc doesn't realize that y_3 can't be used uninitialized */
|
|
59
|
+
y_0=*y++;
|
|
60
|
+
y_1=*y++;
|
|
61
|
+
y_2=*y++;
|
|
62
|
+
for (j=0;j<len-3;j+=4)
|
|
63
|
+
{
|
|
64
|
+
opus_val16 tmp;
|
|
65
|
+
tmp = *x++;
|
|
66
|
+
y_3=*y++;
|
|
67
|
+
sum[0] = MAC16_16(sum[0],tmp,y_0);
|
|
68
|
+
sum[1] = MAC16_16(sum[1],tmp,y_1);
|
|
69
|
+
sum[2] = MAC16_16(sum[2],tmp,y_2);
|
|
70
|
+
sum[3] = MAC16_16(sum[3],tmp,y_3);
|
|
71
|
+
tmp=*x++;
|
|
72
|
+
y_0=*y++;
|
|
73
|
+
sum[0] = MAC16_16(sum[0],tmp,y_1);
|
|
74
|
+
sum[1] = MAC16_16(sum[1],tmp,y_2);
|
|
75
|
+
sum[2] = MAC16_16(sum[2],tmp,y_3);
|
|
76
|
+
sum[3] = MAC16_16(sum[3],tmp,y_0);
|
|
77
|
+
tmp=*x++;
|
|
78
|
+
y_1=*y++;
|
|
79
|
+
sum[0] = MAC16_16(sum[0],tmp,y_2);
|
|
80
|
+
sum[1] = MAC16_16(sum[1],tmp,y_3);
|
|
81
|
+
sum[2] = MAC16_16(sum[2],tmp,y_0);
|
|
82
|
+
sum[3] = MAC16_16(sum[3],tmp,y_1);
|
|
83
|
+
tmp=*x++;
|
|
84
|
+
y_2=*y++;
|
|
85
|
+
sum[0] = MAC16_16(sum[0],tmp,y_3);
|
|
86
|
+
sum[1] = MAC16_16(sum[1],tmp,y_0);
|
|
87
|
+
sum[2] = MAC16_16(sum[2],tmp,y_1);
|
|
88
|
+
sum[3] = MAC16_16(sum[3],tmp,y_2);
|
|
89
|
+
}
|
|
90
|
+
if (j++<len)
|
|
91
|
+
{
|
|
92
|
+
opus_val16 tmp = *x++;
|
|
93
|
+
y_3=*y++;
|
|
94
|
+
sum[0] = MAC16_16(sum[0],tmp,y_0);
|
|
95
|
+
sum[1] = MAC16_16(sum[1],tmp,y_1);
|
|
96
|
+
sum[2] = MAC16_16(sum[2],tmp,y_2);
|
|
97
|
+
sum[3] = MAC16_16(sum[3],tmp,y_3);
|
|
98
|
+
}
|
|
99
|
+
if (j++<len)
|
|
100
|
+
{
|
|
101
|
+
opus_val16 tmp=*x++;
|
|
102
|
+
y_0=*y++;
|
|
103
|
+
sum[0] = MAC16_16(sum[0],tmp,y_1);
|
|
104
|
+
sum[1] = MAC16_16(sum[1],tmp,y_2);
|
|
105
|
+
sum[2] = MAC16_16(sum[2],tmp,y_3);
|
|
106
|
+
sum[3] = MAC16_16(sum[3],tmp,y_0);
|
|
107
|
+
}
|
|
108
|
+
if (j<len)
|
|
109
|
+
{
|
|
110
|
+
opus_val16 tmp=*x++;
|
|
111
|
+
y_1=*y++;
|
|
112
|
+
sum[0] = MAC16_16(sum[0],tmp,y_2);
|
|
113
|
+
sum[1] = MAC16_16(sum[1],tmp,y_3);
|
|
114
|
+
sum[2] = MAC16_16(sum[2],tmp,y_0);
|
|
115
|
+
sum[3] = MAC16_16(sum[3],tmp,y_1);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
static OPUS_INLINE void dual_inner_prod(const opus_val16 *x, const opus_val16 *y01, const opus_val16 *y02,
|
|
120
|
+
int N, opus_val32 *xy1, opus_val32 *xy2)
|
|
121
|
+
{
|
|
122
|
+
int i;
|
|
123
|
+
opus_val32 xy01=0;
|
|
124
|
+
opus_val32 xy02=0;
|
|
125
|
+
for (i=0;i<N;i++)
|
|
126
|
+
{
|
|
127
|
+
xy01 = MAC16_16(xy01, x[i], y01[i]);
|
|
128
|
+
xy02 = MAC16_16(xy02, x[i], y02[i]);
|
|
129
|
+
}
|
|
130
|
+
*xy1 = xy01;
|
|
131
|
+
*xy2 = xy02;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/*We make sure a C version is always available for cases where the overhead of
|
|
135
|
+
vectorization and passing around an arch flag aren't worth it.*/
|
|
136
|
+
static OPUS_INLINE opus_val32 celt_inner_prod(const opus_val16 *x,
|
|
137
|
+
const opus_val16 *y, int N)
|
|
138
|
+
{
|
|
139
|
+
int i;
|
|
140
|
+
opus_val32 xy=0;
|
|
141
|
+
for (i=0;i<N;i++)
|
|
142
|
+
xy = MAC16_16(xy, x[i], y[i]);
|
|
143
|
+
return xy;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
void celt_pitch_xcorr(const opus_val16 *_x, const opus_val16 *_y,
|
|
147
|
+
opus_val32 *xcorr, int len, int max_pitch);
|
|
148
|
+
|
|
149
|
+
#endif
|