@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,309 @@
|
|
|
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
|
+
* Low Complexity Communication Codec (LC3)
|
|
21
|
+
*
|
|
22
|
+
* This implementation conforms to :
|
|
23
|
+
* Low Complexity Communication Codec (LC3)
|
|
24
|
+
* Bluetooth Specification v1.0
|
|
25
|
+
*
|
|
26
|
+
*
|
|
27
|
+
* The LC3 is an efficient low latency audio codec.
|
|
28
|
+
*
|
|
29
|
+
* - Unlike most other codecs, the LC3 codec is focused on audio streaming
|
|
30
|
+
* in constrained (on packet sizes and interval) tranport layer.
|
|
31
|
+
* In this way, the LC3 does not handle :
|
|
32
|
+
* VBR (Variable Bitrate), based on input signal complexity
|
|
33
|
+
* ABR (Adaptative Bitrate). It does not rely on any bit reservoir,
|
|
34
|
+
* a frame will be strictly encoded in the bytes budget given by
|
|
35
|
+
* the user (or transport layer).
|
|
36
|
+
*
|
|
37
|
+
* However, the bitrate (bytes budget for encoding a frame) can be
|
|
38
|
+
* freely changed at any time. But will not rely on signal complexity,
|
|
39
|
+
* it can follow a temporary bandwidth increase or reduction.
|
|
40
|
+
*
|
|
41
|
+
* - Unlike classic codecs, the LC3 codecs does not run on fixed amount
|
|
42
|
+
* of samples as input. It operates only on fixed frame duration, for
|
|
43
|
+
* any supported samplerates (8 to 48 KHz). Two frames duration are
|
|
44
|
+
* available 7.5ms and 10ms.
|
|
45
|
+
*
|
|
46
|
+
*
|
|
47
|
+
* --- About 44.1 KHz samplerate ---
|
|
48
|
+
*
|
|
49
|
+
* The Bluetooth specification reference the 44.1 KHz samplerate, although
|
|
50
|
+
* there is no support in the core algorithm of the codec of 44.1 KHz.
|
|
51
|
+
* We can summarize the 44.1 KHz support by "you can put any samplerate
|
|
52
|
+
* around the defined base samplerates". Please mind the following items :
|
|
53
|
+
*
|
|
54
|
+
* 1. The frame size will not be 7.5 ms or 10 ms, but is scaled
|
|
55
|
+
* by 'supported samplerate' / 'input samplerate'
|
|
56
|
+
*
|
|
57
|
+
* 2. The bandwidth will be hard limited (to 20 KHz) if you select 48 KHz.
|
|
58
|
+
* The encoded bandwidth will also be affected by the above inverse
|
|
59
|
+
* factor of 20 KHz.
|
|
60
|
+
*
|
|
61
|
+
* Applied to 44.1 KHz, we get :
|
|
62
|
+
*
|
|
63
|
+
* 1. About 8.16 ms frame duration, instead of 7.5 ms
|
|
64
|
+
* About 10.88 ms frame duration, instead of 10 ms
|
|
65
|
+
*
|
|
66
|
+
* 2. The bandwidth becomes limited to 18.375 KHz
|
|
67
|
+
*
|
|
68
|
+
*
|
|
69
|
+
* --- How to encode / decode ---
|
|
70
|
+
*
|
|
71
|
+
* An encoder / decoder context needs to be setup. This context keeps states
|
|
72
|
+
* on the current stream to proceed, and samples that overlapped across
|
|
73
|
+
* frames.
|
|
74
|
+
*
|
|
75
|
+
* You have two ways to setup the encoder / decoder :
|
|
76
|
+
*
|
|
77
|
+
* - Using static memory allocation (this module does not rely on
|
|
78
|
+
* any dynamic memory allocation). The types `lc3_xxcoder_mem_16k_t`,
|
|
79
|
+
* and `lc3_xxcoder_mem_48k_t` have size of the memory needed for
|
|
80
|
+
* encoding up to 16 KHz or 48 KHz.
|
|
81
|
+
*
|
|
82
|
+
* - Using dynamic memory allocation. The `lc3_xxcoder_size()` procedure
|
|
83
|
+
* returns the needed memory size, for a given configuration. The memory
|
|
84
|
+
* space must be aligned to a pointer size. As an example, you can setup
|
|
85
|
+
* encoder like this :
|
|
86
|
+
*
|
|
87
|
+
* | enc = lc3_setup_encoder(frame_us, samplerate,
|
|
88
|
+
* | malloc(lc3_encoder_size(frame_us, samplerate)));
|
|
89
|
+
* | ...
|
|
90
|
+
* | free(enc);
|
|
91
|
+
*
|
|
92
|
+
* Note :
|
|
93
|
+
* - A NULL memory adress as input, will return a NULL encoder context.
|
|
94
|
+
* - The returned encoder handle is set at the address of the allocated
|
|
95
|
+
* memory space, you can directly free the handle.
|
|
96
|
+
*
|
|
97
|
+
* Next, call the `lc3_encode()` encoding procedure, for each frames.
|
|
98
|
+
* To handle multichannel streams (Stereo or more), you can proceed with
|
|
99
|
+
* interleaved channels PCM stream like this :
|
|
100
|
+
*
|
|
101
|
+
* | for(int ich = 0; ich < nch: ich++)
|
|
102
|
+
* | lc3_encode(encoder[ich], pcm + ich, nch, ...);
|
|
103
|
+
*
|
|
104
|
+
* with `nch` as the number of channels in the PCM stream
|
|
105
|
+
*
|
|
106
|
+
* ---
|
|
107
|
+
*
|
|
108
|
+
* Antoine SOULIER, Tempow / Google LLC
|
|
109
|
+
*
|
|
110
|
+
*/
|
|
111
|
+
|
|
112
|
+
#ifndef __LC3_H
|
|
113
|
+
#define __LC3_H
|
|
114
|
+
|
|
115
|
+
#ifdef __cplusplus
|
|
116
|
+
extern "C" {
|
|
117
|
+
#endif
|
|
118
|
+
|
|
119
|
+
#include <stdint.h>
|
|
120
|
+
#include <stdbool.h>
|
|
121
|
+
|
|
122
|
+
#include "lc3_private.h"
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Limitations
|
|
127
|
+
* - On the bitrate, in bps, of a stream
|
|
128
|
+
* - On the size of the frames in bytes
|
|
129
|
+
*/
|
|
130
|
+
|
|
131
|
+
#define LC3_MIN_BITRATE 16000
|
|
132
|
+
#define LC3_MAX_BITRATE 320000
|
|
133
|
+
|
|
134
|
+
#define LC3_MIN_FRAME_BYTES 20
|
|
135
|
+
#define LC3_MAX_FRAME_BYTES 400
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Parameters check
|
|
140
|
+
* LC3_CHECK_DT_US(us) True when frame duration in us is suitable
|
|
141
|
+
* LC3_CHECK_SR_HZ(sr) True when samplerate in Hz is suitable
|
|
142
|
+
*/
|
|
143
|
+
|
|
144
|
+
#define LC3_CHECK_DT_US(us) \
|
|
145
|
+
( ((us) == 7500) || ((us) == 10000) )
|
|
146
|
+
|
|
147
|
+
#define LC3_CHECK_SR_HZ(sr) \
|
|
148
|
+
( ((sr) == 8000) || ((sr) == 16000) || ((sr) == 24000) || \
|
|
149
|
+
((sr) == 32000) || ((sr) == 48000) )
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* PCM Sample Format
|
|
154
|
+
* S16 Signed 16 bits, in 16 bits words (int16_t)
|
|
155
|
+
* S24 Signed 24 bits, using low three bytes of 32 bits words (int32_t).
|
|
156
|
+
* The high byte sign extends (bits 31..24 set to b23).
|
|
157
|
+
* S24_3LE Signed 24 bits packed in 3 bytes little endian
|
|
158
|
+
* FLOAT Floating point 32 bits (float type), in range -1 to 1
|
|
159
|
+
*/
|
|
160
|
+
|
|
161
|
+
enum lc3_pcm_format {
|
|
162
|
+
LC3_PCM_FORMAT_S16,
|
|
163
|
+
LC3_PCM_FORMAT_S24,
|
|
164
|
+
LC3_PCM_FORMAT_S24_3LE,
|
|
165
|
+
LC3_PCM_FORMAT_FLOAT,
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Handle
|
|
171
|
+
*/
|
|
172
|
+
|
|
173
|
+
typedef struct lc3_encoder *lc3_encoder_t;
|
|
174
|
+
typedef struct lc3_decoder *lc3_decoder_t;
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Static memory of encoder context
|
|
179
|
+
*
|
|
180
|
+
* Propose types suitable for static memory allocation, supporting
|
|
181
|
+
* any frame duration, and maximum samplerates 16k and 48k respectively
|
|
182
|
+
* You can customize your type using the `LC3_ENCODER_MEM_T` or
|
|
183
|
+
* `LC3_DECODER_MEM_T` macro.
|
|
184
|
+
*/
|
|
185
|
+
|
|
186
|
+
typedef LC3_ENCODER_MEM_T(10000, 16000) lc3_encoder_mem_16k_t;
|
|
187
|
+
typedef LC3_ENCODER_MEM_T(10000, 48000) lc3_encoder_mem_48k_t;
|
|
188
|
+
|
|
189
|
+
typedef LC3_DECODER_MEM_T(10000, 16000) lc3_decoder_mem_16k_t;
|
|
190
|
+
typedef LC3_DECODER_MEM_T(10000, 48000) lc3_decoder_mem_48k_t;
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Return the number of PCM samples in a frame
|
|
195
|
+
* dt_us Frame duration in us, 7500 or 10000
|
|
196
|
+
* sr_hz Samplerate in Hz, 8000, 16000, 24000, 32000 or 48000
|
|
197
|
+
* return Number of PCM samples, -1 on bad parameters
|
|
198
|
+
*/
|
|
199
|
+
int lc3_frame_samples(int dt_us, int sr_hz);
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Return the size of frames, from bitrate
|
|
203
|
+
* dt_us Frame duration in us, 7500 or 10000
|
|
204
|
+
* bitrate Target bitrate in bit per second
|
|
205
|
+
* return The floor size in bytes of the frames, -1 on bad parameters
|
|
206
|
+
*/
|
|
207
|
+
int lc3_frame_bytes(int dt_us, int bitrate);
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Resolve the bitrate, from the size of frames
|
|
211
|
+
* dt_us Frame duration in us, 7500 or 10000
|
|
212
|
+
* nbytes Size in bytes of the frames
|
|
213
|
+
* return The according bitrate in bps, -1 on bad parameters
|
|
214
|
+
*/
|
|
215
|
+
int lc3_resolve_bitrate(int dt_us, int nbytes);
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Return algorithmic delay, as a number of samples
|
|
219
|
+
* dt_us Frame duration in us, 7500 or 10000
|
|
220
|
+
* sr_hz Samplerate in Hz, 8000, 16000, 24000, 32000 or 48000
|
|
221
|
+
* return Number of algorithmic delay samples, -1 on bad parameters
|
|
222
|
+
*/
|
|
223
|
+
int lc3_delay_samples(int dt_us, int sr_hz);
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Return size needed for an encoder
|
|
227
|
+
* dt_us Frame duration in us, 7500 or 10000
|
|
228
|
+
* sr_hz Samplerate in Hz, 8000, 16000, 24000, 32000 or 48000
|
|
229
|
+
* return Size of then encoder in bytes, 0 on bad parameters
|
|
230
|
+
*
|
|
231
|
+
* The `sr_hz` parameter is the samplerate of the PCM input stream,
|
|
232
|
+
* and will match `sr_pcm_hz` of `lc3_setup_encoder()`.
|
|
233
|
+
*/
|
|
234
|
+
unsigned lc3_encoder_size(int dt_us, int sr_hz);
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Setup encoder
|
|
238
|
+
* dt_us Frame duration in us, 7500 or 10000
|
|
239
|
+
* sr_hz Samplerate in Hz, 8000, 16000, 24000, 32000 or 48000
|
|
240
|
+
* sr_pcm_hz Input samplerate, downsampling option of input, or 0
|
|
241
|
+
* mem Encoder memory space, aligned to pointer type
|
|
242
|
+
* return Encoder as an handle, NULL on bad parameters
|
|
243
|
+
*
|
|
244
|
+
* The `sr_pcm_hz` parameter is a downsampling option of PCM input,
|
|
245
|
+
* the value `0` fallback to the samplerate of the encoded stream `sr_hz`.
|
|
246
|
+
* When used, `sr_pcm_hz` is intended to be higher or equal to the encoder
|
|
247
|
+
* samplerate `sr_hz`. The size of the context needed, given by
|
|
248
|
+
* `lc3_encoder_size()` will be set accordingly to `sr_pcm_hz`.
|
|
249
|
+
*/
|
|
250
|
+
lc3_encoder_t lc3_setup_encoder(
|
|
251
|
+
int dt_us, int sr_hz, int sr_pcm_hz, void *mem);
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Encode a frame
|
|
255
|
+
* encoder Handle of the encoder
|
|
256
|
+
* fmt PCM input format
|
|
257
|
+
* pcm, stride Input PCM samples, and count between two consecutives
|
|
258
|
+
* nbytes Target size, in bytes, of the frame (20 to 400)
|
|
259
|
+
* out Output buffer of `nbytes` size
|
|
260
|
+
* return 0: On success -1: Wrong parameters
|
|
261
|
+
*/
|
|
262
|
+
int lc3_encode(lc3_encoder_t encoder, enum lc3_pcm_format fmt,
|
|
263
|
+
const void *pcm, int stride, int nbytes, void *out);
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Return size needed for an decoder
|
|
267
|
+
* dt_us Frame duration in us, 7500 or 10000
|
|
268
|
+
* sr_hz Samplerate in Hz, 8000, 16000, 24000, 32000 or 48000
|
|
269
|
+
* return Size of then decoder in bytes, 0 on bad parameters
|
|
270
|
+
*
|
|
271
|
+
* The `sr_hz` parameter is the samplerate of the PCM output stream,
|
|
272
|
+
* and will match `sr_pcm_hz` of `lc3_setup_decoder()`.
|
|
273
|
+
*/
|
|
274
|
+
unsigned lc3_decoder_size(int dt_us, int sr_hz);
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Setup decoder
|
|
278
|
+
* dt_us Frame duration in us, 7500 or 10000
|
|
279
|
+
* sr_hz Samplerate in Hz, 8000, 16000, 24000, 32000 or 48000
|
|
280
|
+
* sr_pcm_hz Output samplerate, upsampling option of output (or 0)
|
|
281
|
+
* mem Decoder memory space, aligned to pointer type
|
|
282
|
+
* return Decoder as an handle, NULL on bad parameters
|
|
283
|
+
*
|
|
284
|
+
* The `sr_pcm_hz` parameter is an upsampling option of PCM output,
|
|
285
|
+
* the value `0` fallback to the samplerate of the decoded stream `sr_hz`.
|
|
286
|
+
* When used, `sr_pcm_hz` is intended to be higher or equal to the decoder
|
|
287
|
+
* samplerate `sr_hz`. The size of the context needed, given by
|
|
288
|
+
* `lc3_decoder_size()` will be set accordingly to `sr_pcm_hz`.
|
|
289
|
+
*/
|
|
290
|
+
lc3_decoder_t lc3_setup_decoder(
|
|
291
|
+
int dt_us, int sr_hz, int sr_pcm_hz, void *mem);
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Decode a frame
|
|
295
|
+
* decoder Handle of the decoder
|
|
296
|
+
* in, nbytes Input bitstream, and size in bytes, NULL performs PLC
|
|
297
|
+
* fmt PCM output format
|
|
298
|
+
* pcm, stride Output PCM samples, and count between two consecutives
|
|
299
|
+
* return 0: On success 1: PLC operated -1: Wrong parameters
|
|
300
|
+
*/
|
|
301
|
+
int lc3_decode(lc3_decoder_t decoder, const void *in, int nbytes,
|
|
302
|
+
enum lc3_pcm_format fmt, void *pcm, int stride);
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
#ifdef __cplusplus
|
|
306
|
+
}
|
|
307
|
+
#endif
|
|
308
|
+
|
|
309
|
+
#endif /* __LC3_H */
|
|
@@ -0,0 +1,162 @@
|
|
|
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
|
+
#ifndef __LC3_PRIVATE_H
|
|
20
|
+
#define __LC3_PRIVATE_H
|
|
21
|
+
|
|
22
|
+
#include <stdint.h>
|
|
23
|
+
#include <stdbool.h>
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Return number of samples, delayed samples and
|
|
28
|
+
* encoded spectrum coefficients within a frame
|
|
29
|
+
* - For encoding, keep 1.25 ms of temporal winodw
|
|
30
|
+
* - For decoding, keep 18 ms of history, aligned on frames, and a frame
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
#define __LC3_NS(dt_us, sr_hz) \
|
|
34
|
+
( (dt_us * sr_hz) / 1000 / 1000 )
|
|
35
|
+
|
|
36
|
+
#define __LC3_ND(dt_us, sr_hz) \
|
|
37
|
+
( (dt_us) == 7500 ? 23 * __LC3_NS(dt_us, sr_hz) / 30 \
|
|
38
|
+
: 5 * __LC3_NS(dt_us, sr_hz) / 8 )
|
|
39
|
+
|
|
40
|
+
#define __LC3_NT(sr_hz) \
|
|
41
|
+
( (5 * sr_hz) / 4000 )
|
|
42
|
+
|
|
43
|
+
#define __LC3_NH(dt_us, sr_hz) \
|
|
44
|
+
( ((3 - ((dt_us) >= 10000)) + 1) * __LC3_NS(dt_us, sr_hz) )
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Frame duration 7.5ms or 10ms
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
enum lc3_dt {
|
|
52
|
+
LC3_DT_7M5,
|
|
53
|
+
LC3_DT_10M,
|
|
54
|
+
|
|
55
|
+
LC3_NUM_DT
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Sampling frequency
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
enum lc3_srate {
|
|
63
|
+
LC3_SRATE_8K,
|
|
64
|
+
LC3_SRATE_16K,
|
|
65
|
+
LC3_SRATE_24K,
|
|
66
|
+
LC3_SRATE_32K,
|
|
67
|
+
LC3_SRATE_48K,
|
|
68
|
+
|
|
69
|
+
LC3_NUM_SRATE,
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Encoder state and memory
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
typedef struct lc3_attdet_analysis {
|
|
78
|
+
int32_t en1, an1;
|
|
79
|
+
int p_att;
|
|
80
|
+
} lc3_attdet_analysis_t;
|
|
81
|
+
|
|
82
|
+
struct lc3_ltpf_hp50_state {
|
|
83
|
+
int64_t s1, s2;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
typedef struct lc3_ltpf_analysis {
|
|
87
|
+
bool active;
|
|
88
|
+
int pitch;
|
|
89
|
+
float nc[2];
|
|
90
|
+
|
|
91
|
+
struct lc3_ltpf_hp50_state hp50;
|
|
92
|
+
int16_t x_12k8[384];
|
|
93
|
+
int16_t x_6k4[178];
|
|
94
|
+
int tc;
|
|
95
|
+
} lc3_ltpf_analysis_t;
|
|
96
|
+
|
|
97
|
+
typedef struct lc3_spec_analysis {
|
|
98
|
+
float nbits_off;
|
|
99
|
+
int nbits_spare;
|
|
100
|
+
} lc3_spec_analysis_t;
|
|
101
|
+
|
|
102
|
+
struct lc3_encoder {
|
|
103
|
+
enum lc3_dt dt;
|
|
104
|
+
enum lc3_srate sr, sr_pcm;
|
|
105
|
+
|
|
106
|
+
lc3_attdet_analysis_t attdet;
|
|
107
|
+
lc3_ltpf_analysis_t ltpf;
|
|
108
|
+
lc3_spec_analysis_t spec;
|
|
109
|
+
|
|
110
|
+
int16_t *xt;
|
|
111
|
+
float *xs, *xd, s[0];
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
#define LC3_ENCODER_BUFFER_COUNT(dt_us, sr_hz) \
|
|
115
|
+
( ( __LC3_NS(dt_us, sr_hz) + __LC3_NT(sr_hz) ) / 2 + \
|
|
116
|
+
__LC3_NS(dt_us, sr_hz) + __LC3_ND(dt_us, sr_hz) )
|
|
117
|
+
|
|
118
|
+
#define LC3_ENCODER_MEM_T(dt_us, sr_hz) \
|
|
119
|
+
struct { \
|
|
120
|
+
struct lc3_encoder __e; \
|
|
121
|
+
float __s[LC3_ENCODER_BUFFER_COUNT(dt_us, sr_hz)]; \
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Decoder state and memory
|
|
127
|
+
*/
|
|
128
|
+
|
|
129
|
+
typedef struct lc3_ltpf_synthesis {
|
|
130
|
+
bool active;
|
|
131
|
+
int pitch;
|
|
132
|
+
float c[2*12], x[12];
|
|
133
|
+
} lc3_ltpf_synthesis_t;
|
|
134
|
+
|
|
135
|
+
typedef struct lc3_plc_state {
|
|
136
|
+
uint16_t seed;
|
|
137
|
+
int count;
|
|
138
|
+
float alpha;
|
|
139
|
+
} lc3_plc_state_t;
|
|
140
|
+
|
|
141
|
+
struct lc3_decoder {
|
|
142
|
+
enum lc3_dt dt;
|
|
143
|
+
enum lc3_srate sr, sr_pcm;
|
|
144
|
+
|
|
145
|
+
lc3_ltpf_synthesis_t ltpf;
|
|
146
|
+
lc3_plc_state_t plc;
|
|
147
|
+
|
|
148
|
+
float *xh, *xs, *xd, *xg, s[0];
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
#define LC3_DECODER_BUFFER_COUNT(dt_us, sr_hz) \
|
|
152
|
+
( __LC3_NH(dt_us, sr_hz) + __LC3_ND(dt_us, sr_hz) + \
|
|
153
|
+
__LC3_NS(dt_us, sr_hz) )
|
|
154
|
+
|
|
155
|
+
#define LC3_DECODER_MEM_T(dt_us, sr_hz) \
|
|
156
|
+
struct { \
|
|
157
|
+
struct lc3_decoder __d; \
|
|
158
|
+
float __s[LC3_DECODER_BUFFER_COUNT(dt_us, sr_hz)]; \
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
#endif /* __LC3_PRIVATE_H */
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/* Copyright (c) 2018 Gregor Richards
|
|
2
|
+
* Copyright (c) 2017 Mozilla */
|
|
3
|
+
/*
|
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
|
5
|
+
modification, are permitted provided that the following conditions
|
|
6
|
+
are met:
|
|
7
|
+
|
|
8
|
+
- Redistributions of source code must retain the above copyright
|
|
9
|
+
notice, this list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
- Redistributions in binary form must reproduce the above copyright
|
|
12
|
+
notice, this list of conditions and the following disclaimer in the
|
|
13
|
+
documentation and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
16
|
+
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
17
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
18
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
|
|
19
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
20
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
21
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
22
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
23
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
24
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
25
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
#ifndef RNNOISE_H
|
|
29
|
+
#define RNNOISE_H 1
|
|
30
|
+
|
|
31
|
+
#include <stdio.h>
|
|
32
|
+
|
|
33
|
+
#ifdef __cplusplus
|
|
34
|
+
extern "C" {
|
|
35
|
+
#endif
|
|
36
|
+
|
|
37
|
+
#ifndef RNNOISE_EXPORT
|
|
38
|
+
# if defined(WIN32)
|
|
39
|
+
# if defined(RNNOISE_BUILD) && defined(DLL_EXPORT)
|
|
40
|
+
# define RNNOISE_EXPORT __declspec(dllexport)
|
|
41
|
+
# else
|
|
42
|
+
# define RNNOISE_EXPORT
|
|
43
|
+
# endif
|
|
44
|
+
# elif defined(__GNUC__) && defined(RNNOISE_BUILD)
|
|
45
|
+
# define RNNOISE_EXPORT __attribute__ ((visibility ("default")))
|
|
46
|
+
# else
|
|
47
|
+
# define RNNOISE_EXPORT
|
|
48
|
+
# endif
|
|
49
|
+
#endif
|
|
50
|
+
|
|
51
|
+
typedef struct DenoiseState DenoiseState;
|
|
52
|
+
typedef struct RNNModel RNNModel;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Return the size of DenoiseState
|
|
56
|
+
*/
|
|
57
|
+
RNNOISE_EXPORT int rnnoise_get_size();
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Return the number of samples processed by rnnoise_process_frame at a time
|
|
61
|
+
*/
|
|
62
|
+
RNNOISE_EXPORT int rnnoise_get_frame_size();
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Initializes a pre-allocated DenoiseState
|
|
66
|
+
*
|
|
67
|
+
* If model is NULL the default model is used.
|
|
68
|
+
*
|
|
69
|
+
* See: rnnoise_create() and rnnoise_model_from_file()
|
|
70
|
+
*/
|
|
71
|
+
RNNOISE_EXPORT int rnnoise_init(DenoiseState *st, RNNModel *model);
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Allocate and initialize a DenoiseState
|
|
75
|
+
*
|
|
76
|
+
* If model is NULL the default model is used.
|
|
77
|
+
*
|
|
78
|
+
* The returned pointer MUST be freed with rnnoise_destroy().
|
|
79
|
+
*/
|
|
80
|
+
RNNOISE_EXPORT DenoiseState *rnnoise_create(RNNModel *model);
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Free a DenoiseState produced by rnnoise_create.
|
|
84
|
+
*
|
|
85
|
+
* The optional custom model must be freed by rnnoise_model_free() after.
|
|
86
|
+
*/
|
|
87
|
+
RNNOISE_EXPORT void rnnoise_destroy(DenoiseState *st);
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Denoise a frame of samples
|
|
91
|
+
*
|
|
92
|
+
* in and out must be at least rnnoise_get_frame_size() large.
|
|
93
|
+
*/
|
|
94
|
+
RNNOISE_EXPORT float rnnoise_process_frame(DenoiseState *st, float *out, const float *in);
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Load a model from a file
|
|
98
|
+
*
|
|
99
|
+
* It must be deallocated with rnnoise_model_free()
|
|
100
|
+
*/
|
|
101
|
+
RNNOISE_EXPORT RNNModel *rnnoise_model_from_file(FILE *f);
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Free a custom model
|
|
105
|
+
*
|
|
106
|
+
* It must be called after all the DenoiseStates referring to it are freed.
|
|
107
|
+
*/
|
|
108
|
+
RNNOISE_EXPORT void rnnoise_model_free(RNNModel *model);
|
|
109
|
+
|
|
110
|
+
#ifdef __cplusplus
|
|
111
|
+
}
|
|
112
|
+
#endif
|
|
113
|
+
|
|
114
|
+
#endif
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
add_library(liblc
|
|
2
|
+
STATIC
|
|
3
|
+
attdet.c
|
|
4
|
+
bits.c
|
|
5
|
+
bwdet.c
|
|
6
|
+
energy.c
|
|
7
|
+
lc3.c
|
|
8
|
+
ltpf.c
|
|
9
|
+
mdct.c
|
|
10
|
+
plc.c
|
|
11
|
+
sns.c
|
|
12
|
+
spec.c
|
|
13
|
+
tables.c
|
|
14
|
+
tns.c
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
target_include_directories(liblc3 PUBLIC ../include)
|
|
18
|
+
|
|
19
|
+
#target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE liblc3)
|
|
@@ -0,0 +1,92 @@
|
|
|
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 "attdet.h"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Time domain attack detector
|
|
24
|
+
*/
|
|
25
|
+
bool lc3_attdet_run(enum lc3_dt dt, enum lc3_srate sr,
|
|
26
|
+
int nbytes, struct lc3_attdet_analysis *attdet, const int16_t *x)
|
|
27
|
+
{
|
|
28
|
+
/* --- Check enabling --- */
|
|
29
|
+
|
|
30
|
+
const int nbytes_ranges[LC3_NUM_DT][LC3_NUM_SRATE - LC3_SRATE_32K][2] = {
|
|
31
|
+
[LC3_DT_7M5] = { { 61, 149 }, { 75, 149 } },
|
|
32
|
+
[LC3_DT_10M] = { { 81, INT_MAX }, { 100, INT_MAX } },
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
if (sr < LC3_SRATE_32K ||
|
|
36
|
+
nbytes < nbytes_ranges[dt][sr - LC3_SRATE_32K][0] ||
|
|
37
|
+
nbytes > nbytes_ranges[dt][sr - LC3_SRATE_32K][1] )
|
|
38
|
+
return 0;
|
|
39
|
+
|
|
40
|
+
/* --- Filtering & Energy calculation --- */
|
|
41
|
+
|
|
42
|
+
int nblk = 4 - (dt == LC3_DT_7M5);
|
|
43
|
+
int32_t e[4];
|
|
44
|
+
|
|
45
|
+
for (int i = 0; i < nblk; i++) {
|
|
46
|
+
e[i] = 0;
|
|
47
|
+
|
|
48
|
+
if (sr == LC3_SRATE_32K) {
|
|
49
|
+
int16_t xn2 = (x[-4] + x[-3]) >> 1;
|
|
50
|
+
int16_t xn1 = (x[-2] + x[-1]) >> 1;
|
|
51
|
+
int16_t xn, xf;
|
|
52
|
+
|
|
53
|
+
for (int j = 0; j < 40; j++, x += 2, xn2 = xn1, xn1 = xn) {
|
|
54
|
+
xn = (x[0] + x[1]) >> 1;
|
|
55
|
+
xf = (3 * xn - 4 * xn1 + 1 * xn2) >> 3;
|
|
56
|
+
e[i] += (xf * xf) >> 5;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
else {
|
|
61
|
+
int16_t xn2 = (x[-6] + x[-5] + x[-4]) >> 2;
|
|
62
|
+
int16_t xn1 = (x[-3] + x[-2] + x[-1]) >> 2;
|
|
63
|
+
int16_t xn, xf;
|
|
64
|
+
|
|
65
|
+
for (int j = 0; j < 40; j++, x += 3, xn2 = xn1, xn1 = xn) {
|
|
66
|
+
xn = (x[0] + x[1] + x[2]) >> 2;
|
|
67
|
+
xf = (3 * xn - 4 * xn1 + 1 * xn2) >> 3;
|
|
68
|
+
e[i] += (xf * xf) >> 5;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/* --- Attack detection ---
|
|
74
|
+
* The attack block `p_att` is defined as the normative value + 1,
|
|
75
|
+
* in such way, it will be initialized to 0 */
|
|
76
|
+
|
|
77
|
+
int p_att = 0;
|
|
78
|
+
int32_t a[4];
|
|
79
|
+
|
|
80
|
+
for (int i = 0; i < nblk; i++) {
|
|
81
|
+
a[i] = LC3_MAX(attdet->an1 >> 2, attdet->en1);
|
|
82
|
+
attdet->en1 = e[i], attdet->an1 = a[i];
|
|
83
|
+
|
|
84
|
+
if ((e[i] >> 3) > a[i] + (a[i] >> 4))
|
|
85
|
+
p_att = i + 1;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
int att = attdet->p_att >= 1 + (nblk >> 1) || p_att > 0;
|
|
89
|
+
attdet->p_att = p_att;
|
|
90
|
+
|
|
91
|
+
return att;
|
|
92
|
+
}
|