@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,315 @@
|
|
|
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 - Bitstream management
|
|
21
|
+
*
|
|
22
|
+
* The bitstream is written by the 2 ends of the buffer :
|
|
23
|
+
*
|
|
24
|
+
* - Arthmetic coder put bits while increasing memory addresses
|
|
25
|
+
* in the buffer (forward)
|
|
26
|
+
*
|
|
27
|
+
* - Plain bits are puts starting the end of the buffer, with memeory
|
|
28
|
+
* addresses decreasing (backward)
|
|
29
|
+
*
|
|
30
|
+
* .---------------------------------------------------.
|
|
31
|
+
* | > > > > > > > > > > : : < < < < < < < < < |
|
|
32
|
+
* '---------------------------------------------------'
|
|
33
|
+
* |---------------------> - - - - - - - - - - - - - ->|
|
|
34
|
+
* |< - - - <-------------------|
|
|
35
|
+
* Arithmetic coding Plain bits
|
|
36
|
+
* `lc3_put_symbol()` `lc3_put_bits()`
|
|
37
|
+
*
|
|
38
|
+
* - The forward writing is protected against buffer overflow, it cannot
|
|
39
|
+
* write after the buffer, but can overwrite plain bits previously
|
|
40
|
+
* written in the buffer.
|
|
41
|
+
*
|
|
42
|
+
* - The backward writing is protected against overwrite of the arithmetic
|
|
43
|
+
* coder bitstream. In such way, the backward bitstream is always limited
|
|
44
|
+
* by the aritmetic coder bitstream, and can be overwritten by him.
|
|
45
|
+
*
|
|
46
|
+
* .---------------------------------------------------.
|
|
47
|
+
* | > > > > > > > > > > : : < < < < < < < < < |
|
|
48
|
+
* '---------------------------------------------------'
|
|
49
|
+
* |---------------------> - - - - - - - - - - - - - ->|
|
|
50
|
+
* |< - - - - - - - - - - - - - - <-------------------|
|
|
51
|
+
* Arithmetic coding Plain bits
|
|
52
|
+
* `lc3_get_symbol()` `lc3_get_bits()`
|
|
53
|
+
*
|
|
54
|
+
* - Reading is limited to read of the complementary end of the buffer.
|
|
55
|
+
*
|
|
56
|
+
* - The procedure `lc3_check_bits()` returns indication that read has been
|
|
57
|
+
* made crossing the other bit plane.
|
|
58
|
+
*
|
|
59
|
+
*
|
|
60
|
+
* Reference : Low Complexity Communication Codec (LC3)
|
|
61
|
+
* Bluetooth Specification v1.0
|
|
62
|
+
*
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
#ifndef __LC3_BITS_H
|
|
66
|
+
#define __LC3_BITS_H
|
|
67
|
+
|
|
68
|
+
#include "common.h"
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Bitstream mode
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
enum lc3_bits_mode {
|
|
76
|
+
LC3_BITS_MODE_READ,
|
|
77
|
+
LC3_BITS_MODE_WRITE,
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Arithmetic coder symbol interval
|
|
82
|
+
* The model split the interval in 17 symbols
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
struct lc3_ac_symbol {
|
|
86
|
+
uint16_t low : 16;
|
|
87
|
+
uint16_t range : 16;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
struct lc3_ac_model {
|
|
91
|
+
struct lc3_ac_symbol s[17];
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Bitstream context
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
#define LC3_ACCU_BITS (int)(8 * sizeof(unsigned))
|
|
99
|
+
|
|
100
|
+
struct lc3_bits_accu {
|
|
101
|
+
unsigned v;
|
|
102
|
+
int n, nover;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
#define LC3_AC_BITS (int)(24)
|
|
106
|
+
|
|
107
|
+
struct lc3_bits_ac {
|
|
108
|
+
unsigned low, range;
|
|
109
|
+
int cache, carry, carry_count;
|
|
110
|
+
bool error;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
struct lc3_bits_buffer {
|
|
114
|
+
const uint8_t *start, *end;
|
|
115
|
+
uint8_t *p_fw, *p_bw;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
typedef struct lc3_bits {
|
|
119
|
+
enum lc3_bits_mode mode;
|
|
120
|
+
struct lc3_bits_ac ac;
|
|
121
|
+
struct lc3_bits_accu accu;
|
|
122
|
+
struct lc3_bits_buffer buffer;
|
|
123
|
+
} lc3_bits_t;
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Setup bitstream reading/writing
|
|
128
|
+
* bits Bitstream context
|
|
129
|
+
* mode Either READ or WRITE mode
|
|
130
|
+
* buffer, len Output buffer and length (in bytes)
|
|
131
|
+
*/
|
|
132
|
+
void lc3_setup_bits(lc3_bits_t *bits,
|
|
133
|
+
enum lc3_bits_mode mode, void *buffer, int len);
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Return number of bits left in the bitstream
|
|
137
|
+
* bits Bitstream context
|
|
138
|
+
* return Number of bits left
|
|
139
|
+
*/
|
|
140
|
+
int lc3_get_bits_left(const lc3_bits_t *bits);
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Check if error occured on bitstream reading/writing
|
|
144
|
+
* bits Bitstream context
|
|
145
|
+
* return 0: Ok -1: Bitstream overflow or AC reading error
|
|
146
|
+
*/
|
|
147
|
+
int lc3_check_bits(const lc3_bits_t *bits);
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Put a bit
|
|
151
|
+
* bits Bitstream context
|
|
152
|
+
* v Bit value, 0 or 1
|
|
153
|
+
*/
|
|
154
|
+
static inline void lc3_put_bit(lc3_bits_t *bits, int v);
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Put from 1 to 32 bits
|
|
158
|
+
* bits Bitstream context
|
|
159
|
+
* v, n Value, in range 0 to 2^n - 1, and bits count (1 to 32)
|
|
160
|
+
*/
|
|
161
|
+
static inline void lc3_put_bits(lc3_bits_t *bits, unsigned v, int n);
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Put arithmetic coder symbol
|
|
165
|
+
* bits Bitstream context
|
|
166
|
+
* model, s Model distribution and symbol value
|
|
167
|
+
*/
|
|
168
|
+
static inline void lc3_put_symbol(lc3_bits_t *bits,
|
|
169
|
+
const struct lc3_ac_model *model, unsigned s);
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Flush and terminate bitstream writing
|
|
173
|
+
* bits Bitstream context
|
|
174
|
+
*/
|
|
175
|
+
void lc3_flush_bits(lc3_bits_t *bits);
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Get a bit
|
|
179
|
+
* bits Bitstream context
|
|
180
|
+
*/
|
|
181
|
+
static inline int lc3_get_bit(lc3_bits_t *bits);
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Get from 1 to 32 bits
|
|
185
|
+
* bits Bitstream context
|
|
186
|
+
* n Number of bits to read (1 to 32)
|
|
187
|
+
* return The value read
|
|
188
|
+
*/
|
|
189
|
+
static inline unsigned lc3_get_bits(lc3_bits_t *bits, int n);
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Get arithmetic coder symbol
|
|
193
|
+
* bits Bitstream context
|
|
194
|
+
* model Model distribution
|
|
195
|
+
* return The value read
|
|
196
|
+
*/
|
|
197
|
+
static inline unsigned lc3_get_symbol(lc3_bits_t *bits,
|
|
198
|
+
const struct lc3_ac_model *model);
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
/* ----------------------------------------------------------------------------
|
|
203
|
+
* Inline implementations
|
|
204
|
+
* -------------------------------------------------------------------------- */
|
|
205
|
+
|
|
206
|
+
void lc3_put_bits_generic(lc3_bits_t *bits, unsigned v, int n);
|
|
207
|
+
unsigned lc3_get_bits_generic(struct lc3_bits *bits, int n);
|
|
208
|
+
|
|
209
|
+
void lc3_ac_read_renorm(lc3_bits_t *bits);
|
|
210
|
+
void lc3_ac_write_renorm(lc3_bits_t *bits);
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Put a bit
|
|
215
|
+
*/
|
|
216
|
+
LC3_HOT static inline void lc3_put_bit(lc3_bits_t *bits, int v)
|
|
217
|
+
{
|
|
218
|
+
lc3_put_bits(bits, v, 1);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Put from 1 to 32 bits
|
|
223
|
+
*/
|
|
224
|
+
LC3_HOT static inline void lc3_put_bits(
|
|
225
|
+
struct lc3_bits *bits, unsigned v, int n)
|
|
226
|
+
{
|
|
227
|
+
struct lc3_bits_accu *accu = &bits->accu;
|
|
228
|
+
|
|
229
|
+
if (accu->n + n <= LC3_ACCU_BITS) {
|
|
230
|
+
accu->v |= v << accu->n;
|
|
231
|
+
accu->n += n;
|
|
232
|
+
} else {
|
|
233
|
+
lc3_put_bits_generic(bits, v, n);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Get a bit
|
|
239
|
+
*/
|
|
240
|
+
LC3_HOT static inline int lc3_get_bit(lc3_bits_t *bits)
|
|
241
|
+
{
|
|
242
|
+
return lc3_get_bits(bits, 1);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Get from 1 to 32 bits
|
|
247
|
+
*/
|
|
248
|
+
LC3_HOT static inline unsigned lc3_get_bits(struct lc3_bits *bits, int n)
|
|
249
|
+
{
|
|
250
|
+
struct lc3_bits_accu *accu = &bits->accu;
|
|
251
|
+
|
|
252
|
+
if (accu->n + n <= LC3_ACCU_BITS) {
|
|
253
|
+
int v = (accu->v >> accu->n) & ((1u << n) - 1);
|
|
254
|
+
return (accu->n += n), v;
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
return lc3_get_bits_generic(bits, n);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Put arithmetic coder symbol
|
|
263
|
+
*/
|
|
264
|
+
LC3_HOT static inline void lc3_put_symbol(
|
|
265
|
+
struct lc3_bits *bits, const struct lc3_ac_model *model, unsigned s)
|
|
266
|
+
{
|
|
267
|
+
const struct lc3_ac_symbol *symbols = model->s;
|
|
268
|
+
struct lc3_bits_ac *ac = &bits->ac;
|
|
269
|
+
unsigned range = ac->range >> 10;
|
|
270
|
+
|
|
271
|
+
ac->low += range * symbols[s].low;
|
|
272
|
+
ac->range = range * symbols[s].range;
|
|
273
|
+
|
|
274
|
+
ac->carry |= ac->low >> 24;
|
|
275
|
+
ac->low &= 0xffffff;
|
|
276
|
+
|
|
277
|
+
if (ac->range < 0x10000)
|
|
278
|
+
lc3_ac_write_renorm(bits);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Get arithmetic coder symbol
|
|
283
|
+
*/
|
|
284
|
+
LC3_HOT static inline unsigned lc3_get_symbol(
|
|
285
|
+
lc3_bits_t *bits, const struct lc3_ac_model *model)
|
|
286
|
+
{
|
|
287
|
+
const struct lc3_ac_symbol *symbols = model->s;
|
|
288
|
+
struct lc3_bits_ac *ac = &bits->ac;
|
|
289
|
+
|
|
290
|
+
unsigned range = (ac->range >> 10) & 0xffff;
|
|
291
|
+
|
|
292
|
+
ac->error |= (ac->low >= (range << 10));
|
|
293
|
+
if (ac->error)
|
|
294
|
+
ac->low = 0;
|
|
295
|
+
|
|
296
|
+
int s = 16;
|
|
297
|
+
|
|
298
|
+
if (ac->low < range * symbols[s].low) {
|
|
299
|
+
s >>= 1;
|
|
300
|
+
s -= ac->low < range * symbols[s].low ? 4 : -4;
|
|
301
|
+
s -= ac->low < range * symbols[s].low ? 2 : -2;
|
|
302
|
+
s -= ac->low < range * symbols[s].low ? 1 : -1;
|
|
303
|
+
s -= ac->low < range * symbols[s].low;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
ac->low -= range * symbols[s].low;
|
|
307
|
+
ac->range = range * symbols[s].range;
|
|
308
|
+
|
|
309
|
+
if (ac->range < 0x10000)
|
|
310
|
+
lc3_ac_read_renorm(bits);
|
|
311
|
+
|
|
312
|
+
return s;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
#endif /* __LC3_BITS_H */
|
|
@@ -0,0 +1,129 @@
|
|
|
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 "bwdet.h"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Bandwidth detector
|
|
24
|
+
*/
|
|
25
|
+
enum lc3_bandwidth lc3_bwdet_run(
|
|
26
|
+
enum lc3_dt dt, enum lc3_srate sr, const float *e)
|
|
27
|
+
{
|
|
28
|
+
/* Bandwidth regions (Table 3.6) */
|
|
29
|
+
|
|
30
|
+
struct region { int is : 8; int ie : 8; };
|
|
31
|
+
|
|
32
|
+
static const struct region bws_table[LC3_NUM_DT]
|
|
33
|
+
[LC3_NUM_BANDWIDTH-1][LC3_NUM_BANDWIDTH-1] = {
|
|
34
|
+
|
|
35
|
+
[LC3_DT_7M5] = {
|
|
36
|
+
{ { 51, 63+1 } },
|
|
37
|
+
{ { 45, 55+1 }, { 58, 63+1 } },
|
|
38
|
+
{ { 42, 51+1 }, { 53, 58+1 }, { 60, 63+1 } },
|
|
39
|
+
{ { 40, 48+1 }, { 51, 55+1 }, { 57, 60+1 }, { 61, 63+1 } },
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
[LC3_DT_10M] = {
|
|
43
|
+
{ { 53, 63+1 } },
|
|
44
|
+
{ { 47, 56+1 }, { 59, 63+1 } },
|
|
45
|
+
{ { 44, 52+1 }, { 54, 59+1 }, { 60, 63+1 } },
|
|
46
|
+
{ { 41, 49+1 }, { 51, 55+1 }, { 57, 60+1 }, { 61, 63+1 } },
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
static const int l_table[LC3_NUM_DT][LC3_NUM_BANDWIDTH-1] = {
|
|
51
|
+
[LC3_DT_7M5] = { 4, 4, 3, 2 },
|
|
52
|
+
[LC3_DT_10M] = { 4, 4, 3, 1 },
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/* --- Stage 1 ---
|
|
56
|
+
* Determine bw0 candidate */
|
|
57
|
+
|
|
58
|
+
enum lc3_bandwidth bw0 = LC3_BANDWIDTH_NB;
|
|
59
|
+
enum lc3_bandwidth bwn = (enum lc3_bandwidth)sr;
|
|
60
|
+
|
|
61
|
+
if (bwn <= bw0)
|
|
62
|
+
return bwn;
|
|
63
|
+
|
|
64
|
+
const struct region *bwr = bws_table[dt][bwn-1];
|
|
65
|
+
|
|
66
|
+
for (enum lc3_bandwidth bw = bw0; bw < bwn; bw++) {
|
|
67
|
+
int i = bwr[bw].is, ie = bwr[bw].ie;
|
|
68
|
+
int n = ie - i;
|
|
69
|
+
|
|
70
|
+
float se = e[i];
|
|
71
|
+
for (i++; i < ie; i++)
|
|
72
|
+
se += e[i];
|
|
73
|
+
|
|
74
|
+
if (se >= (10 << (bw == LC3_BANDWIDTH_NB)) * n)
|
|
75
|
+
bw0 = bw + 1;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/* --- Stage 2 ---
|
|
79
|
+
* Detect drop above cut-off frequency.
|
|
80
|
+
* The Tc condition (13) is precalculated, as
|
|
81
|
+
* Tc[] = 10 ^ (n / 10) , n = { 15, 23, 20, 20 } */
|
|
82
|
+
|
|
83
|
+
int hold = bw0 >= bwn;
|
|
84
|
+
|
|
85
|
+
if (!hold) {
|
|
86
|
+
int i0 = bwr[bw0].is, l = l_table[dt][bw0];
|
|
87
|
+
float tc = (const float []){
|
|
88
|
+
31.62277660, 199.52623150, 100, 100 }[bw0];
|
|
89
|
+
|
|
90
|
+
for (int i = i0 - l + 1; !hold && i <= i0 + 1; i++) {
|
|
91
|
+
hold = e[i-l] > tc * e[i];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return hold ? bw0 : bwn;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Return number of bits coding the bandwidth value
|
|
101
|
+
*/
|
|
102
|
+
int lc3_bwdet_get_nbits(enum lc3_srate sr)
|
|
103
|
+
{
|
|
104
|
+
return (sr > 0) + (sr > 1) + (sr > 3);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Put bandwidth indication
|
|
109
|
+
*/
|
|
110
|
+
void lc3_bwdet_put_bw(lc3_bits_t *bits,
|
|
111
|
+
enum lc3_srate sr, enum lc3_bandwidth bw)
|
|
112
|
+
{
|
|
113
|
+
int nbits_bw = lc3_bwdet_get_nbits(sr);
|
|
114
|
+
if (nbits_bw > 0)
|
|
115
|
+
lc3_put_bits(bits, bw, nbits_bw);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Get bandwidth indication
|
|
120
|
+
*/
|
|
121
|
+
int lc3_bwdet_get_bw(lc3_bits_t *bits,
|
|
122
|
+
enum lc3_srate sr, enum lc3_bandwidth *bw)
|
|
123
|
+
{
|
|
124
|
+
enum lc3_bandwidth max_bw = (enum lc3_bandwidth)sr;
|
|
125
|
+
int nbits_bw = lc3_bwdet_get_nbits(sr);
|
|
126
|
+
|
|
127
|
+
*bw = nbits_bw > 0 ? lc3_get_bits(bits, nbits_bw) : LC3_BANDWIDTH_NB;
|
|
128
|
+
return *bw > max_bw ? (*bw = max_bw), -1 : 0;
|
|
129
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
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 - Bandwidth detector
|
|
21
|
+
*
|
|
22
|
+
* Reference : Low Complexity Communication Codec (LC3)
|
|
23
|
+
* Bluetooth Specification v1.0
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
#ifndef __LC3_BWDET_H
|
|
27
|
+
#define __LC3_BWDET_H
|
|
28
|
+
|
|
29
|
+
#include "common.h"
|
|
30
|
+
#include "bits.h"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Bandwidth detector (cf. 3.3.5)
|
|
35
|
+
* dt, sr Duration and samplerate of the frame
|
|
36
|
+
* e Energy estimation per bands
|
|
37
|
+
* return Return detected bandwitdth
|
|
38
|
+
*/
|
|
39
|
+
enum lc3_bandwidth lc3_bwdet_run(
|
|
40
|
+
enum lc3_dt dt, enum lc3_srate sr, const float *e);
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Return number of bits coding the bandwidth value
|
|
44
|
+
* sr Samplerate of the frame
|
|
45
|
+
* return Number of bits coding the bandwidth value
|
|
46
|
+
*/
|
|
47
|
+
int lc3_bwdet_get_nbits(enum lc3_srate sr);
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Put bandwidth indication
|
|
51
|
+
* bits Bitstream context
|
|
52
|
+
* sr Samplerate of the frame
|
|
53
|
+
* bw Bandwidth detected
|
|
54
|
+
*/
|
|
55
|
+
void lc3_bwdet_put_bw(lc3_bits_t *bits,
|
|
56
|
+
enum lc3_srate sr, enum lc3_bandwidth bw);
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Get bandwidth indication
|
|
60
|
+
* bits Bitstream context
|
|
61
|
+
* sr Samplerate of the frame
|
|
62
|
+
* bw Return bandwidth indication
|
|
63
|
+
* return 0: Ok -1: Invalid bandwidth indication
|
|
64
|
+
*/
|
|
65
|
+
int lc3_bwdet_get_bw(lc3_bits_t *bits,
|
|
66
|
+
enum lc3_srate sr, enum lc3_bandwidth *bw);
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
#endif /* __LC3_BWDET_H */
|
|
@@ -0,0 +1,151 @@
|
|
|
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 - Common constants and types
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
#ifndef __LC3_COMMON_H
|
|
24
|
+
#define __LC3_COMMON_H
|
|
25
|
+
|
|
26
|
+
#include "lc3.h"
|
|
27
|
+
#include "fastmath.h"
|
|
28
|
+
|
|
29
|
+
#include <stdalign.h>
|
|
30
|
+
#include <limits.h>
|
|
31
|
+
#include <string.h>
|
|
32
|
+
|
|
33
|
+
#ifdef __ARM_ARCH
|
|
34
|
+
#include <arm_acle.h>
|
|
35
|
+
#endif
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Hot Function attribute
|
|
40
|
+
* Selectively disable sanitizer
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
#ifdef __clang__
|
|
44
|
+
|
|
45
|
+
#define LC3_HOT \
|
|
46
|
+
__attribute__((no_sanitize("bounds"))) \
|
|
47
|
+
__attribute__((no_sanitize("integer")))
|
|
48
|
+
|
|
49
|
+
#else /* __clang__ */
|
|
50
|
+
|
|
51
|
+
#define LC3_HOT
|
|
52
|
+
|
|
53
|
+
#endif /* __clang__ */
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Macros
|
|
58
|
+
* MIN/MAX Minimum and maximum between 2 values
|
|
59
|
+
* CLIP Clip a value between low and high limits
|
|
60
|
+
* SATXX Signed saturation on 'xx' bits
|
|
61
|
+
* ABS Return absolute value
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
#define LC3_MIN(a, b) ( (a) < (b) ? (a) : (b) )
|
|
65
|
+
#define LC3_MAX(a, b) ( (a) > (b) ? (a) : (b) )
|
|
66
|
+
|
|
67
|
+
#define LC3_CLIP(v, min, max) LC3_MIN(LC3_MAX(v, min), max)
|
|
68
|
+
#define LC3_SAT16(v) LC3_CLIP(v, -(1 << 15), (1 << 15) - 1)
|
|
69
|
+
#define LC3_SAT24(v) LC3_CLIP(v, -(1 << 23), (1 << 23) - 1)
|
|
70
|
+
|
|
71
|
+
#define LC3_ABS(v) ( (v) < 0 ? -(v) : (v) )
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
#if defined(__ARM_FEATURE_SAT) && !(__GNUC__ < 10)
|
|
75
|
+
|
|
76
|
+
#undef LC3_SAT16
|
|
77
|
+
#define LC3_SAT16(v) __ssat(v, 16)
|
|
78
|
+
|
|
79
|
+
#undef LC3_SAT24
|
|
80
|
+
#define LC3_SAT24(v) __ssat(v, 24)
|
|
81
|
+
|
|
82
|
+
#endif /* __ARM_FEATURE_SAT */
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Convert `dt` in us and `sr` in KHz
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
#define LC3_DT_US(dt) \
|
|
90
|
+
( (3 + (dt)) * 2500 )
|
|
91
|
+
|
|
92
|
+
#define LC3_SRATE_KHZ(sr) \
|
|
93
|
+
( (1 + (sr) + ((sr) == LC3_SRATE_48K)) * 8 )
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Return number of samples, delayed samples and
|
|
98
|
+
* encoded spectrum coefficients within a frame
|
|
99
|
+
* - For encoding, keep 1.25 ms for temporal window
|
|
100
|
+
* - For decoding, keep 18 ms of history, aligned on frames, and a frame
|
|
101
|
+
*/
|
|
102
|
+
|
|
103
|
+
#define LC3_NS(dt, sr) \
|
|
104
|
+
( 20 * (3 + (dt)) * (1 + (sr) + ((sr) == LC3_SRATE_48K)) )
|
|
105
|
+
|
|
106
|
+
#define LC3_ND(dt, sr) \
|
|
107
|
+
( (dt) == LC3_DT_7M5 ? 23 * LC3_NS(dt, sr) / 30 \
|
|
108
|
+
: 5 * LC3_NS(dt, sr) / 8 )
|
|
109
|
+
|
|
110
|
+
#define LC3_NE(dt, sr) \
|
|
111
|
+
( 20 * (3 + (dt)) * (1 + (sr)) )
|
|
112
|
+
|
|
113
|
+
#define LC3_MAX_NS \
|
|
114
|
+
LC3_NS(LC3_DT_10M, LC3_SRATE_48K)
|
|
115
|
+
|
|
116
|
+
#define LC3_MAX_NE \
|
|
117
|
+
LC3_NE(LC3_DT_10M, LC3_SRATE_48K)
|
|
118
|
+
|
|
119
|
+
#define LC3_NT(sr_hz) \
|
|
120
|
+
( (5 * LC3_SRATE_KHZ(sr)) / 4 )
|
|
121
|
+
|
|
122
|
+
#define LC3_NH(dt, sr) \
|
|
123
|
+
( ((3 - dt) + 1) * LC3_NS(dt, sr) )
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Bandwidth, mapped to Nyquist frequency of samplerates
|
|
128
|
+
*/
|
|
129
|
+
|
|
130
|
+
enum lc3_bandwidth {
|
|
131
|
+
LC3_BANDWIDTH_NB = LC3_SRATE_8K,
|
|
132
|
+
LC3_BANDWIDTH_WB = LC3_SRATE_16K,
|
|
133
|
+
LC3_BANDWIDTH_SSWB = LC3_SRATE_24K,
|
|
134
|
+
LC3_BANDWIDTH_SWB = LC3_SRATE_32K,
|
|
135
|
+
LC3_BANDWIDTH_FB = LC3_SRATE_48K,
|
|
136
|
+
|
|
137
|
+
LC3_NUM_BANDWIDTH,
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Complex floating point number
|
|
143
|
+
*/
|
|
144
|
+
|
|
145
|
+
struct lc3_complex
|
|
146
|
+
{
|
|
147
|
+
float re, im;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
#endif /* __LC3_COMMON_H */
|