@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,44 @@
|
|
|
1
|
+
/******************************************************************************
|
|
2
|
+
*
|
|
3
|
+
* Copyright 2022 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at:
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*
|
|
17
|
+
******************************************************************************/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* LC3 - Time domain attack detector
|
|
21
|
+
*
|
|
22
|
+
* Reference : Low Complexity Communication Codec (LC3)
|
|
23
|
+
* Bluetooth Specification v1.0
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
#ifndef __LC3_ATTDET_H
|
|
27
|
+
#define __LC3_ATTDET_H
|
|
28
|
+
|
|
29
|
+
#include "common.h"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Time domain attack detector
|
|
34
|
+
* dt, sr Duration and samplerate of the frame
|
|
35
|
+
* nbytes Size in bytes of the frame
|
|
36
|
+
* attdet Context of the Attack Detector
|
|
37
|
+
* x [-6..-1] Previous, [0..ns-1] Current samples
|
|
38
|
+
* return 1: Attack detected 0: Otherwise
|
|
39
|
+
*/
|
|
40
|
+
bool lc3_attdet_run(enum lc3_dt dt, enum lc3_srate sr,
|
|
41
|
+
int nbytes, lc3_attdet_analysis_t *attdet, const int16_t *x);
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
#endif /* __LC3_ATTDET_H */
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
/******************************************************************************
|
|
2
|
+
*
|
|
3
|
+
* Copyright 2022 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at:
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*
|
|
17
|
+
******************************************************************************/
|
|
18
|
+
|
|
19
|
+
#include "bits.h"
|
|
20
|
+
#include "common.h"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
/* ----------------------------------------------------------------------------
|
|
24
|
+
* Common
|
|
25
|
+
* -------------------------------------------------------------------------- */
|
|
26
|
+
|
|
27
|
+
static inline int ac_get(struct lc3_bits_buffer *);
|
|
28
|
+
static inline void accu_load(struct lc3_bits_accu *, struct lc3_bits_buffer *);
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Arithmetic coder return range bits
|
|
32
|
+
* ac Arithmetic coder
|
|
33
|
+
* return 1 + log2(ac->range)
|
|
34
|
+
*/
|
|
35
|
+
static int ac_get_range_bits(const struct lc3_bits_ac *ac)
|
|
36
|
+
{
|
|
37
|
+
int nbits = 0;
|
|
38
|
+
|
|
39
|
+
for (unsigned r = ac->range; r; r >>= 1, nbits++);
|
|
40
|
+
|
|
41
|
+
return nbits;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Arithmetic coder return pending bits
|
|
46
|
+
* ac Arithmetic coder
|
|
47
|
+
* return Pending bits
|
|
48
|
+
*/
|
|
49
|
+
static int ac_get_pending_bits(const struct lc3_bits_ac *ac)
|
|
50
|
+
{
|
|
51
|
+
return 26 - ac_get_range_bits(ac) +
|
|
52
|
+
((ac->cache >= 0) + ac->carry_count) * 8;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Return number of bits left in the bitstream
|
|
57
|
+
* bits Bitstream context
|
|
58
|
+
* return >= 0: Number of bits left < 0: Overflow
|
|
59
|
+
*/
|
|
60
|
+
static int get_bits_left(const struct lc3_bits *bits)
|
|
61
|
+
{
|
|
62
|
+
const struct lc3_bits_buffer *buffer = &bits->buffer;
|
|
63
|
+
const struct lc3_bits_accu *accu = &bits->accu;
|
|
64
|
+
const struct lc3_bits_ac *ac = &bits->ac;
|
|
65
|
+
|
|
66
|
+
uintptr_t end = (uintptr_t)buffer->p_bw +
|
|
67
|
+
(bits->mode == LC3_BITS_MODE_READ ? LC3_ACCU_BITS/8 : 0);
|
|
68
|
+
|
|
69
|
+
uintptr_t start = (uintptr_t)buffer->p_fw -
|
|
70
|
+
(bits->mode == LC3_BITS_MODE_READ ? LC3_AC_BITS/8 : 0);
|
|
71
|
+
|
|
72
|
+
int n = end > start ? (int)(end - start) : -(int)(start - end);
|
|
73
|
+
|
|
74
|
+
return 8 * n - (accu->n + accu->nover + ac_get_pending_bits(ac));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Setup bitstream writing
|
|
79
|
+
*/
|
|
80
|
+
void lc3_setup_bits(struct lc3_bits *bits,
|
|
81
|
+
enum lc3_bits_mode mode, void *buffer, int len)
|
|
82
|
+
{
|
|
83
|
+
*bits = (struct lc3_bits){
|
|
84
|
+
.mode = mode,
|
|
85
|
+
.accu = {
|
|
86
|
+
.n = mode == LC3_BITS_MODE_READ ? LC3_ACCU_BITS : 0,
|
|
87
|
+
},
|
|
88
|
+
.ac = {
|
|
89
|
+
.range = 0xffffff,
|
|
90
|
+
.cache = -1
|
|
91
|
+
},
|
|
92
|
+
.buffer = {
|
|
93
|
+
.start = (uint8_t *)buffer, .end = (uint8_t *)buffer + len,
|
|
94
|
+
.p_fw = (uint8_t *)buffer, .p_bw = (uint8_t *)buffer + len,
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
if (mode == LC3_BITS_MODE_READ) {
|
|
99
|
+
struct lc3_bits_ac *ac = &bits->ac;
|
|
100
|
+
struct lc3_bits_accu *accu = &bits->accu;
|
|
101
|
+
struct lc3_bits_buffer *buffer = &bits->buffer;
|
|
102
|
+
|
|
103
|
+
ac->low = ac_get(buffer) << 16;
|
|
104
|
+
ac->low |= ac_get(buffer) << 8;
|
|
105
|
+
ac->low |= ac_get(buffer);
|
|
106
|
+
|
|
107
|
+
accu_load(accu, buffer);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Return number of bits left in the bitstream
|
|
113
|
+
*/
|
|
114
|
+
int lc3_get_bits_left(const struct lc3_bits *bits)
|
|
115
|
+
{
|
|
116
|
+
return LC3_MAX(get_bits_left(bits), 0);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Return number of bits left in the bitstream
|
|
121
|
+
*/
|
|
122
|
+
int lc3_check_bits(const struct lc3_bits *bits)
|
|
123
|
+
{
|
|
124
|
+
const struct lc3_bits_ac *ac = &bits->ac;
|
|
125
|
+
|
|
126
|
+
return -(get_bits_left(bits) < 0 || ac->error);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
/* ----------------------------------------------------------------------------
|
|
131
|
+
* Writing
|
|
132
|
+
* -------------------------------------------------------------------------- */
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Flush the bits accumulator
|
|
136
|
+
* accu Bitstream accumulator
|
|
137
|
+
* buffer Bitstream buffer
|
|
138
|
+
*/
|
|
139
|
+
static inline void accu_flush(
|
|
140
|
+
struct lc3_bits_accu *accu, struct lc3_bits_buffer *buffer)
|
|
141
|
+
{
|
|
142
|
+
int nbytes = LC3_MIN(accu->n >> 3,
|
|
143
|
+
LC3_MAX(buffer->p_bw - buffer->p_fw, 0));
|
|
144
|
+
|
|
145
|
+
accu->n -= 8 * nbytes;
|
|
146
|
+
|
|
147
|
+
for ( ; nbytes; accu->v >>= 8, nbytes--)
|
|
148
|
+
*(--buffer->p_bw) = accu->v & 0xff;
|
|
149
|
+
|
|
150
|
+
if (accu->n >= 8)
|
|
151
|
+
accu->n = 0;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Arithmetic coder put byte
|
|
156
|
+
* buffer Bitstream buffer
|
|
157
|
+
* byte Byte to output
|
|
158
|
+
*/
|
|
159
|
+
static inline void ac_put(struct lc3_bits_buffer *buffer, int byte)
|
|
160
|
+
{
|
|
161
|
+
if (buffer->p_fw < buffer->end)
|
|
162
|
+
*(buffer->p_fw++) = byte;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Arithmetic coder range shift
|
|
167
|
+
* ac Arithmetic coder
|
|
168
|
+
* buffer Bitstream buffer
|
|
169
|
+
*/
|
|
170
|
+
LC3_HOT static inline void ac_shift(
|
|
171
|
+
struct lc3_bits_ac *ac, struct lc3_bits_buffer *buffer)
|
|
172
|
+
{
|
|
173
|
+
if (ac->low < 0xff0000 || ac->carry)
|
|
174
|
+
{
|
|
175
|
+
if (ac->cache >= 0)
|
|
176
|
+
ac_put(buffer, ac->cache + ac->carry);
|
|
177
|
+
|
|
178
|
+
for ( ; ac->carry_count > 0; ac->carry_count--)
|
|
179
|
+
ac_put(buffer, ac->carry ? 0x00 : 0xff);
|
|
180
|
+
|
|
181
|
+
ac->cache = ac->low >> 16;
|
|
182
|
+
ac->carry = 0;
|
|
183
|
+
}
|
|
184
|
+
else
|
|
185
|
+
ac->carry_count++;
|
|
186
|
+
|
|
187
|
+
ac->low = (ac->low << 8) & 0xffffff;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Arithmetic coder termination
|
|
192
|
+
* ac Arithmetic coder
|
|
193
|
+
* buffer Bitstream buffer
|
|
194
|
+
* end_val/nbits End value and count of bits to terminate (1 to 8)
|
|
195
|
+
*/
|
|
196
|
+
static void ac_terminate(struct lc3_bits_ac *ac,
|
|
197
|
+
struct lc3_bits_buffer *buffer)
|
|
198
|
+
{
|
|
199
|
+
int nbits = 25 - ac_get_range_bits(ac);
|
|
200
|
+
unsigned mask = 0xffffff >> nbits;
|
|
201
|
+
unsigned val = ac->low + mask;
|
|
202
|
+
unsigned high = ac->low + ac->range;
|
|
203
|
+
|
|
204
|
+
bool over_val = val >> 24;
|
|
205
|
+
bool over_high = high >> 24;
|
|
206
|
+
|
|
207
|
+
val = (val & 0xffffff) & ~mask;
|
|
208
|
+
high = (high & 0xffffff);
|
|
209
|
+
|
|
210
|
+
if (over_val == over_high) {
|
|
211
|
+
|
|
212
|
+
if (val + mask >= high) {
|
|
213
|
+
nbits++;
|
|
214
|
+
mask >>= 1;
|
|
215
|
+
val = ((ac->low + mask) & 0xffffff) & ~mask;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
ac->carry |= val < ac->low;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
ac->low = val;
|
|
222
|
+
|
|
223
|
+
for (; nbits > 8; nbits -= 8)
|
|
224
|
+
ac_shift(ac, buffer);
|
|
225
|
+
ac_shift(ac, buffer);
|
|
226
|
+
|
|
227
|
+
int end_val = ac->cache >> (8 - nbits);
|
|
228
|
+
|
|
229
|
+
if (ac->carry_count) {
|
|
230
|
+
ac_put(buffer, ac->cache);
|
|
231
|
+
for ( ; ac->carry_count > 1; ac->carry_count--)
|
|
232
|
+
ac_put(buffer, 0xff);
|
|
233
|
+
|
|
234
|
+
end_val = nbits < 8 ? 0 : 0xff;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (buffer->p_fw < buffer->end) {
|
|
238
|
+
*buffer->p_fw &= 0xff >> nbits;
|
|
239
|
+
*buffer->p_fw |= end_val << (8 - nbits);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Flush and terminate bitstream
|
|
245
|
+
*/
|
|
246
|
+
void lc3_flush_bits(struct lc3_bits *bits)
|
|
247
|
+
{
|
|
248
|
+
struct lc3_bits_ac *ac = &bits->ac;
|
|
249
|
+
struct lc3_bits_accu *accu = &bits->accu;
|
|
250
|
+
struct lc3_bits_buffer *buffer = &bits->buffer;
|
|
251
|
+
|
|
252
|
+
int nleft = buffer->p_bw - buffer->p_fw;
|
|
253
|
+
for (int n = 8 * nleft - accu->n; n > 0; n -= 32)
|
|
254
|
+
lc3_put_bits(bits, 0, LC3_MIN(n, 32));
|
|
255
|
+
|
|
256
|
+
accu_flush(accu, buffer);
|
|
257
|
+
|
|
258
|
+
ac_terminate(ac, buffer);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Write from 1 to 32 bits,
|
|
263
|
+
* exceeding the capacity of the accumulator
|
|
264
|
+
*/
|
|
265
|
+
LC3_HOT void lc3_put_bits_generic(struct lc3_bits *bits, unsigned v, int n)
|
|
266
|
+
{
|
|
267
|
+
struct lc3_bits_accu *accu = &bits->accu;
|
|
268
|
+
|
|
269
|
+
/* --- Fulfill accumulator and flush -- */
|
|
270
|
+
|
|
271
|
+
int n1 = LC3_MIN(LC3_ACCU_BITS - accu->n, n);
|
|
272
|
+
if (n1) {
|
|
273
|
+
accu->v |= v << accu->n;
|
|
274
|
+
accu->n = LC3_ACCU_BITS;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
accu_flush(accu, &bits->buffer);
|
|
278
|
+
|
|
279
|
+
/* --- Accumulate remaining bits -- */
|
|
280
|
+
|
|
281
|
+
accu->v = v >> n1;
|
|
282
|
+
accu->n = n - n1;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Arithmetic coder renormalization
|
|
287
|
+
*/
|
|
288
|
+
LC3_HOT void lc3_ac_write_renorm(struct lc3_bits *bits)
|
|
289
|
+
{
|
|
290
|
+
struct lc3_bits_ac *ac = &bits->ac;
|
|
291
|
+
|
|
292
|
+
for ( ; ac->range < 0x10000; ac->range <<= 8)
|
|
293
|
+
ac_shift(ac, &bits->buffer);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
/* ----------------------------------------------------------------------------
|
|
298
|
+
* Reading
|
|
299
|
+
* -------------------------------------------------------------------------- */
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Arithmetic coder get byte
|
|
303
|
+
* buffer Bitstream buffer
|
|
304
|
+
* return Byte read, 0 on overflow
|
|
305
|
+
*/
|
|
306
|
+
static inline int ac_get(struct lc3_bits_buffer *buffer)
|
|
307
|
+
{
|
|
308
|
+
return buffer->p_fw < buffer->end ? *(buffer->p_fw++) : 0;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Load the accumulator
|
|
313
|
+
* accu Bitstream accumulator
|
|
314
|
+
* buffer Bitstream buffer
|
|
315
|
+
*/
|
|
316
|
+
static inline void accu_load(struct lc3_bits_accu *accu,
|
|
317
|
+
struct lc3_bits_buffer *buffer)
|
|
318
|
+
{
|
|
319
|
+
int nbytes = LC3_MIN(accu->n >> 3, buffer->p_bw - buffer->start);
|
|
320
|
+
|
|
321
|
+
accu->n -= 8 * nbytes;
|
|
322
|
+
|
|
323
|
+
for ( ; nbytes; nbytes--) {
|
|
324
|
+
accu->v >>= 8;
|
|
325
|
+
accu->v |= *(--buffer->p_bw) << (LC3_ACCU_BITS - 8);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
if (accu->n >= 8) {
|
|
329
|
+
accu->nover = LC3_MIN(accu->nover + accu->n, LC3_ACCU_BITS);
|
|
330
|
+
accu->v >>= accu->n;
|
|
331
|
+
accu->n = 0;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Read from 1 to 32 bits,
|
|
337
|
+
* exceeding the capacity of the accumulator
|
|
338
|
+
*/
|
|
339
|
+
LC3_HOT unsigned lc3_get_bits_generic(struct lc3_bits *bits, int n)
|
|
340
|
+
{
|
|
341
|
+
struct lc3_bits_accu *accu = &bits->accu;
|
|
342
|
+
struct lc3_bits_buffer *buffer = &bits->buffer;
|
|
343
|
+
|
|
344
|
+
/* --- Fulfill accumulator and read -- */
|
|
345
|
+
|
|
346
|
+
accu_load(accu, buffer);
|
|
347
|
+
|
|
348
|
+
int n1 = LC3_MIN(LC3_ACCU_BITS - accu->n, n);
|
|
349
|
+
unsigned v = (accu->v >> accu->n) & ((1u << n1) - 1);
|
|
350
|
+
accu->n += n1;
|
|
351
|
+
|
|
352
|
+
/* --- Second round --- */
|
|
353
|
+
|
|
354
|
+
int n2 = n - n1;
|
|
355
|
+
|
|
356
|
+
if (n2) {
|
|
357
|
+
accu_load(accu, buffer);
|
|
358
|
+
|
|
359
|
+
v |= ((accu->v >> accu->n) & ((1u << n2) - 1)) << n1;
|
|
360
|
+
accu->n += n2;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
return v;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Arithmetic coder renormalization
|
|
368
|
+
*/
|
|
369
|
+
LC3_HOT void lc3_ac_read_renorm(struct lc3_bits *bits)
|
|
370
|
+
{
|
|
371
|
+
struct lc3_bits_ac *ac = &bits->ac;
|
|
372
|
+
|
|
373
|
+
for ( ; ac->range < 0x10000; ac->range <<= 8)
|
|
374
|
+
ac->low = ((ac->low << 8) | ac_get(&bits->buffer)) & 0xffffff;
|
|
375
|
+
}
|