@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.
Files changed (278) hide show
  1. package/README.md +278 -0
  2. package/android/build.gradle +167 -0
  3. package/android/lc3Lib/CMakeLists.txt +6 -0
  4. package/android/lc3Lib/build.gradle +109 -0
  5. package/android/lc3Lib/proguard-rules.pro +33 -0
  6. package/android/lc3Lib/src/main/AndroidManifest.xml +2 -0
  7. package/android/lc3Lib/src/main/cpp/CMakeLists.txt +8 -0
  8. package/android/lc3Lib/src/main/cpp/google_opus_stuff/CMakeLists.txt +30 -0
  9. package/android/lc3Lib/src/main/cpp/google_opus_stuff/jni/CMakeLists.txt +7 -0
  10. package/android/lc3Lib/src/main/cpp/google_opus_stuff/jni/ogg_opus_encoder.cc +96 -0
  11. package/android/lc3Lib/src/main/cpp/google_opus_stuff/jni/ogg_opus_encoder.h +53 -0
  12. package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/Makefile.am +6 -0
  13. package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/config_types.h +26 -0
  14. package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/config_types.h.in +26 -0
  15. package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/ogg.h +209 -0
  16. package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/os_types.h +158 -0
  17. package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus.h +981 -0
  18. package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_custom.h +342 -0
  19. package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_defines.h +799 -0
  20. package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_multistream.h +660 -0
  21. package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_projection.h +568 -0
  22. package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_types.h +166 -0
  23. package/android/lc3Lib/src/main/cpp/google_opus_stuff/ogg_opus_encoder.cc +268 -0
  24. package/android/lc3Lib/src/main/cpp/google_opus_stuff/ogg_opus_encoder.h +115 -0
  25. package/android/lc3Lib/src/main/cpp/google_opus_stuff/opus_tools/opus_header.h +59 -0
  26. package/android/lc3Lib/src/main/cpp/liblc3/CMakeLists.txt +38 -0
  27. package/android/lc3Lib/src/main/cpp/liblc3/include/lc3.h +309 -0
  28. package/android/lc3Lib/src/main/cpp/liblc3/include/lc3_private.h +162 -0
  29. package/android/lc3Lib/src/main/cpp/liblc3/include/rnnoise.h +114 -0
  30. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/CMakeLists.txt +19 -0
  31. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/attdet.c +92 -0
  32. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/attdet.h +44 -0
  33. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/bits.c +375 -0
  34. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/bits.h +315 -0
  35. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/bwdet.c +129 -0
  36. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/bwdet.h +69 -0
  37. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/common.h +148 -0
  38. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/energy.c +70 -0
  39. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/energy.h +43 -0
  40. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/fastmath.h +158 -0
  41. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/lc3.c +702 -0
  42. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/ltpf.c +893 -0
  43. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/ltpf.h +111 -0
  44. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/ltpf_arm.h +506 -0
  45. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/ltpf_neon.h +281 -0
  46. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/makefile.mk +35 -0
  47. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/mdct.c +452 -0
  48. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/mdct.h +57 -0
  49. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/mdct_neon.h +296 -0
  50. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/meson.build +46 -0
  51. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/plc.c +61 -0
  52. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/plc.h +57 -0
  53. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/sns.c +880 -0
  54. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/sns.h +103 -0
  55. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/spec.c +904 -0
  56. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/spec.h +119 -0
  57. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/tables.c +3457 -0
  58. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/tables.h +94 -0
  59. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/tns.c +457 -0
  60. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/tns.h +99 -0
  61. package/android/lc3Lib/src/main/cpp/liblc3/liblc3.cpp +159 -0
  62. package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/_kiss_fft_guts.h +182 -0
  63. package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/arch.h +261 -0
  64. package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/celt_lpc.c +279 -0
  65. package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/celt_lpc.h +59 -0
  66. package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/common.h +48 -0
  67. package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/compile.sh +3 -0
  68. package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/denoise.c +646 -0
  69. package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/kiss_fft.c +601 -0
  70. package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/kiss_fft.h +203 -0
  71. package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/opus_types.h +159 -0
  72. package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/pitch.c +526 -0
  73. package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/pitch.h +149 -0
  74. package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn.c +178 -0
  75. package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn.h +69 -0
  76. package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn_data.c +11051 -0
  77. package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn_data.h +34 -0
  78. package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn_reader.c +168 -0
  79. package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn_train.py +66 -0
  80. package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/tansig_table.h +45 -0
  81. package/android/lc3Lib/src/main/java/com/mentra/lc3Lib/Lc3Cpp.java +38 -0
  82. package/android/lc3Lib/third_party/CMakeLists.txt +23 -0
  83. package/android/lc3Lib/third_party/CMakeLists_libogg.txt +18 -0
  84. package/android/lc3Lib/third_party/CMakeLists_libopus.txt +18 -0
  85. package/android/lc3Lib/third_party/CMakeLists_opus-tools.txt +23 -0
  86. package/android/lc3Lib/third_party/opus_tools/src/AUTHORS +5 -0
  87. package/android/lc3Lib/third_party/opus_tools/src/CMakeLists.txt +4 -0
  88. package/android/lc3Lib/third_party/opus_tools/src/COPYING +371 -0
  89. package/android/lc3Lib/third_party/opus_tools/src/ChangeLog +3 -0
  90. package/android/lc3Lib/third_party/opus_tools/src/Makefile.am +42 -0
  91. package/android/lc3Lib/third_party/opus_tools/src/Makefile.unix +23 -0
  92. package/android/lc3Lib/third_party/opus_tools/src/NEWS +0 -0
  93. package/android/lc3Lib/third_party/opus_tools/src/README +0 -0
  94. package/android/lc3Lib/third_party/opus_tools/src/autogen.sh +115 -0
  95. package/android/lc3Lib/third_party/opus_tools/src/configure.ac +293 -0
  96. package/android/lc3Lib/third_party/opus_tools/src/src/arch.h +239 -0
  97. package/android/lc3Lib/third_party/opus_tools/src/src/audio-in.c +1046 -0
  98. package/android/lc3Lib/third_party/opus_tools/src/src/diag_range.c +245 -0
  99. package/android/lc3Lib/third_party/opus_tools/src/src/diag_range.h +28 -0
  100. package/android/lc3Lib/third_party/opus_tools/src/src/info_opus.c +320 -0
  101. package/android/lc3Lib/third_party/opus_tools/src/src/info_opus.h +51 -0
  102. package/android/lc3Lib/third_party/opus_tools/src/src/lpc.c +157 -0
  103. package/android/lc3Lib/third_party/opus_tools/src/src/lpc.h +27 -0
  104. package/android/lc3Lib/third_party/opus_tools/src/src/opus_header.c +286 -0
  105. package/android/lc3Lib/third_party/opus_tools/src/src/opus_header.h +59 -0
  106. package/android/lc3Lib/third_party/opus_tools/src/src/opusdec.c +884 -0
  107. package/android/lc3Lib/third_party/opus_tools/src/src/opusenc.c +1021 -0
  108. package/android/lc3Lib/third_party/opus_tools/src/src/opusenc.h +101 -0
  109. package/android/lc3Lib/third_party/opus_tools/src/src/opusinfo.c +639 -0
  110. package/android/lc3Lib/third_party/opus_tools/src/src/opusinfo.h +51 -0
  111. package/android/lc3Lib/third_party/opus_tools/src/src/os_support.h +167 -0
  112. package/android/lc3Lib/third_party/opus_tools/src/src/resample.c +1137 -0
  113. package/android/lc3Lib/third_party/opus_tools/src/src/speex_resampler.h +344 -0
  114. package/android/lc3Lib/third_party/opus_tools/src/src/stack_alloc.h +115 -0
  115. package/android/lc3Lib/third_party/opus_tools/src/src/wav_io.c +125 -0
  116. package/android/lc3Lib/third_party/opus_tools/src/src/wav_io.h +62 -0
  117. package/android/lc3Lib/third_party/opus_tools/src/src/wave_out.c +223 -0
  118. package/android/lc3Lib/third_party/opus_tools/src/src/wave_out.h +60 -0
  119. package/android/settings.gradle +1 -0
  120. package/android/src/main/AndroidManifest.xml +40 -0
  121. package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkModule.kt +528 -0
  122. package/android/src/main/java/com/mentra/bluetoothsdk/Bridge.kt +610 -0
  123. package/android/src/main/java/com/mentra/bluetoothsdk/DeviceManager.kt +1616 -0
  124. package/android/src/main/java/com/mentra/bluetoothsdk/DeviceStore.kt +314 -0
  125. package/android/src/main/java/com/mentra/bluetoothsdk/MentraBluetoothModels.kt +1710 -0
  126. package/android/src/main/java/com/mentra/bluetoothsdk/MentraBluetoothSdk.kt +554 -0
  127. package/android/src/main/java/com/mentra/bluetoothsdk/ObservableStore.kt +68 -0
  128. package/android/src/main/java/com/mentra/bluetoothsdk/controllers/ControllerManager.kt +158 -0
  129. package/android/src/main/java/com/mentra/bluetoothsdk/controllers/R1.kt +934 -0
  130. package/android/src/main/java/com/mentra/bluetoothsdk/services/Foreground.kt +175 -0
  131. package/android/src/main/java/com/mentra/bluetoothsdk/services/PhoneMic.kt +1109 -0
  132. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/G1.java +3974 -0
  133. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/G2.kt +3551 -0
  134. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/Mach1.java +1327 -0
  135. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLive.java +6959 -0
  136. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraNex.kt +1655 -0
  137. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraosBle.java +53675 -0
  138. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/SGCManager.kt +202 -0
  139. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/Simulated.kt +224 -0
  140. package/android/src/main/java/com/mentra/bluetoothsdk/stt/STTTools.kt +340 -0
  141. package/android/src/main/java/com/mentra/bluetoothsdk/stt/SherpaOnnxTranscriber.kt +465 -0
  142. package/android/src/main/java/com/mentra/bluetoothsdk/stt/VadGateSpeechPolicy.kt +221 -0
  143. package/android/src/main/java/com/mentra/bluetoothsdk/utils/AES.java +106 -0
  144. package/android/src/main/java/com/mentra/bluetoothsdk/utils/AudioSessionMonitor.kt +189 -0
  145. package/android/src/main/java/com/mentra/bluetoothsdk/utils/BitmapJavaUtils.java +169 -0
  146. package/android/src/main/java/com/mentra/bluetoothsdk/utils/BlePhotoUploadService.java +179 -0
  147. package/android/src/main/java/com/mentra/bluetoothsdk/utils/Constants.kt +44 -0
  148. package/android/src/main/java/com/mentra/bluetoothsdk/utils/G1Text.kt +436 -0
  149. package/android/src/main/java/com/mentra/bluetoothsdk/utils/IncidentLogBleRelayNaming.java +29 -0
  150. package/android/src/main/java/com/mentra/bluetoothsdk/utils/IncidentLogBleUploadService.java +76 -0
  151. package/android/src/main/java/com/mentra/bluetoothsdk/utils/K900ProtocolUtils.java +791 -0
  152. package/android/src/main/java/com/mentra/bluetoothsdk/utils/MessageChunker.java +186 -0
  153. package/android/src/main/java/com/mentra/bluetoothsdk/utils/NexSGCUtils.kt +589 -0
  154. package/android/src/main/java/com/mentra/bluetoothsdk/utils/PhoneAudioMonitor.kt +303 -0
  155. package/android/src/main/java/com/mentra/bluetoothsdk/utils/SmartGlassesConnectionState.java +9 -0
  156. package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/ByteUtilAudioPlayer.java +655 -0
  157. package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/Lc3Player.java +441 -0
  158. package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/PCMAudioPlayer.java +431 -0
  159. package/android/src/main/res/values/strings.xml +4 -0
  160. package/app.plugin.js +1 -0
  161. package/build/BluetoothSdk.types.d.ts +498 -0
  162. package/build/BluetoothSdk.types.d.ts.map +1 -0
  163. package/build/BluetoothSdk.types.js +23 -0
  164. package/build/BluetoothSdk.types.js.map +1 -0
  165. package/build/BluetoothSdkModule.d.ts +71 -0
  166. package/build/BluetoothSdkModule.d.ts.map +1 -0
  167. package/build/BluetoothSdkModule.js +106 -0
  168. package/build/BluetoothSdkModule.js.map +1 -0
  169. package/build/index.d.ts +3 -0
  170. package/build/index.d.ts.map +1 -0
  171. package/build/index.js +5 -0
  172. package/build/index.js.map +1 -0
  173. package/expo-module.config.json +9 -0
  174. package/ios/BluetoothSdkModule.swift +665 -0
  175. package/ios/MentraBluetoothSDK.podspec +77 -0
  176. package/ios/Packages/CoreObjC/CoreObjC.xcodeproj/project.pbxproj +213 -0
  177. package/ios/Packages/CoreObjC/PcmConverter.h +22 -0
  178. package/ios/Packages/CoreObjC/PcmConverter.m +266 -0
  179. package/ios/Packages/CoreObjC/attdet.c +92 -0
  180. package/ios/Packages/CoreObjC/attdet.h +44 -0
  181. package/ios/Packages/CoreObjC/bits.c +375 -0
  182. package/ios/Packages/CoreObjC/bits.h +315 -0
  183. package/ios/Packages/CoreObjC/bwdet.c +129 -0
  184. package/ios/Packages/CoreObjC/bwdet.h +69 -0
  185. package/ios/Packages/CoreObjC/common.h +151 -0
  186. package/ios/Packages/CoreObjC/energy.c +70 -0
  187. package/ios/Packages/CoreObjC/energy.h +43 -0
  188. package/ios/Packages/CoreObjC/fastmath.h +158 -0
  189. package/ios/Packages/CoreObjC/lc3.c +704 -0
  190. package/ios/Packages/CoreObjC/lc3.h +313 -0
  191. package/ios/Packages/CoreObjC/lc3_cpp.h +283 -0
  192. package/ios/Packages/CoreObjC/lc3_private.h +163 -0
  193. package/ios/Packages/CoreObjC/ltpf.c +905 -0
  194. package/ios/Packages/CoreObjC/ltpf.h +111 -0
  195. package/ios/Packages/CoreObjC/ltpf_arm.h +506 -0
  196. package/ios/Packages/CoreObjC/ltpf_neon.h +281 -0
  197. package/ios/Packages/CoreObjC/makefile.mk +35 -0
  198. package/ios/Packages/CoreObjC/mdct.c +469 -0
  199. package/ios/Packages/CoreObjC/mdct.h +57 -0
  200. package/ios/Packages/CoreObjC/mdct_neon.h +296 -0
  201. package/ios/Packages/CoreObjC/meson.build +61 -0
  202. package/ios/Packages/CoreObjC/plc.c +61 -0
  203. package/ios/Packages/CoreObjC/plc.h +57 -0
  204. package/ios/Packages/CoreObjC/rnnoise.h +114 -0
  205. package/ios/Packages/CoreObjC/sns.c +880 -0
  206. package/ios/Packages/CoreObjC/sns.h +103 -0
  207. package/ios/Packages/CoreObjC/spec.c +907 -0
  208. package/ios/Packages/CoreObjC/spec.h +119 -0
  209. package/ios/Packages/CoreObjC/tables.c +3457 -0
  210. package/ios/Packages/CoreObjC/tables.h +94 -0
  211. package/ios/Packages/CoreObjC/tns.c +457 -0
  212. package/ios/Packages/CoreObjC/tns.h +99 -0
  213. package/ios/Packages/SherpaOnnx/Model/joiner.onnx +0 -0
  214. package/ios/Packages/SherpaOnnx/Model/tokens.txt +502 -0
  215. package/ios/Packages/SherpaOnnx/SherpaOnnx.swift +1659 -0
  216. package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/Headers/cargs.h +162 -0
  217. package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/Headers/sherpa-onnx/c-api/c-api.h +1852 -0
  218. package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/Headers/sherpa-onnx/c-api/cxx-api.h +674 -0
  219. package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/Info.plist +44 -0
  220. package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64/libsherpa-onnx.a +0 -0
  221. package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64/sherpa-onnx.a +0 -0
  222. package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64_x86_64-simulator/libsherpa-onnx.a +0 -0
  223. package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64_x86_64-simulator/sherpa-onnx.a +0 -0
  224. package/ios/Packages/VAD/Common/VAD/VADQuality.swift +41 -0
  225. package/ios/Packages/VAD/Common/VAD/VADState.swift +26 -0
  226. package/ios/Packages/VAD/Common/VAD/VADStrategy.swift +29 -0
  227. package/ios/Packages/VAD/Common/VAD/VADType.swift +14 -0
  228. package/ios/Packages/VAD/Data/Configuration.swift +68 -0
  229. package/ios/Packages/VAD/Data/FrameSize.swift +39 -0
  230. package/ios/Packages/VAD/Data/Record.swift +13 -0
  231. package/ios/Packages/VAD/Data/Result.swift +22 -0
  232. package/ios/Packages/VAD/Data/SampleRate.swift +48 -0
  233. package/ios/Packages/VAD/Silero/Model/silero_vad.onnx +0 -0
  234. package/ios/Packages/VAD/Silero/SileroVAD.swift +284 -0
  235. package/ios/Packages/VAD/Silero/SileroVADStrategy.swift +64 -0
  236. package/ios/Packages/libbz2/module.modulemap +5 -0
  237. package/ios/Packages/libbz2/shim.h +1 -0
  238. package/ios/Source/Bridge.swift +353 -0
  239. package/ios/Source/Bridging-Header.h +16 -0
  240. package/ios/Source/DeviceManager.swift +1478 -0
  241. package/ios/Source/DeviceStore.swift +295 -0
  242. package/ios/Source/MentraBluetoothSDK.swift +2439 -0
  243. package/ios/Source/ObservableStore.swift +88 -0
  244. package/ios/Source/PrivacyInfo.xcprivacy +23 -0
  245. package/ios/Source/controllers/ControllerManager.swift +187 -0
  246. package/ios/Source/controllers/R1.swift +827 -0
  247. package/ios/Source/services/PhoneMic.swift +662 -0
  248. package/ios/Source/sgcs/Frame.swift +651 -0
  249. package/ios/Source/sgcs/G1.swift +2505 -0
  250. package/ios/Source/sgcs/G2.swift +3730 -0
  251. package/ios/Source/sgcs/Mach1.swift +543 -0
  252. package/ios/Source/sgcs/MentraLive.swift +4708 -0
  253. package/ios/Source/sgcs/MentraNex.swift +2479 -0
  254. package/ios/Source/sgcs/SGCManager.swift +243 -0
  255. package/ios/Source/sgcs/Simulated.swift +270 -0
  256. package/ios/Source/sgcs/mentraos_ble.pb.swift +3811 -0
  257. package/ios/Source/stt/STTTools.swift +154 -0
  258. package/ios/Source/stt/SherpaOnnxTranscriber.swift +401 -0
  259. package/ios/Source/utils/AudioSessionMonitor.swift +283 -0
  260. package/ios/Source/utils/Constants.swift +74 -0
  261. package/ios/Source/utils/Enums.swift +95 -0
  262. package/ios/Source/utils/G1Text.swift +2067 -0
  263. package/ios/Source/utils/JSCExperiment.swift +241 -0
  264. package/ios/Source/utils/MemoryMonitor.swift +44 -0
  265. package/ios/Source/utils/MessageChunker.swift +164 -0
  266. package/ios/Source/utils/Models.swift +135 -0
  267. package/ios/Source/utils/PhoneAudioMonitor.swift +226 -0
  268. package/ios/Source/utils/TarBz2Extractor.swift +206 -0
  269. package/package.json +78 -0
  270. package/plugin/build/index.d.ts +6 -0
  271. package/plugin/build/index.js +12 -0
  272. package/plugin/build/withAndroid.d.ts +4 -0
  273. package/plugin/build/withAndroid.js +80 -0
  274. package/plugin/build/withIos.d.ts +4 -0
  275. package/plugin/build/withIos.js +64 -0
  276. package/src/BluetoothSdk.types.ts +581 -0
  277. package/src/BluetoothSdkModule.ts +259 -0
  278. package/src/index.ts +4 -0
@@ -0,0 +1,313 @@
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
+ * - On the number of samples by frames
130
+ */
131
+
132
+ #define LC3_MIN_BITRATE 16000
133
+ #define LC3_MAX_BITRATE 320000
134
+
135
+ #define LC3_MIN_FRAME_BYTES 20
136
+ #define LC3_MAX_FRAME_BYTES 400
137
+
138
+ #define LC3_MIN_FRAME_SAMPLES __LC3_NS( 7500, 8000)
139
+ #define LC3_MAX_FRAME_SAMPLES __LC3_NS(10000, 48000)
140
+
141
+
142
+ /**
143
+ * Parameters check
144
+ * LC3_CHECK_DT_US(us) True when frame duration in us is suitable
145
+ * LC3_CHECK_SR_HZ(sr) True when samplerate in Hz is suitable
146
+ */
147
+
148
+ #define LC3_CHECK_DT_US(us) \
149
+ ( ((us) == 7500) || ((us) == 10000) )
150
+
151
+ #define LC3_CHECK_SR_HZ(sr) \
152
+ ( ((sr) == 8000) || ((sr) == 16000) || ((sr) == 24000) || \
153
+ ((sr) == 32000) || ((sr) == 48000) )
154
+
155
+
156
+ /**
157
+ * PCM Sample Format
158
+ * S16 Signed 16 bits, in 16 bits words (int16_t)
159
+ * S24 Signed 24 bits, using low three bytes of 32 bits words (int32_t).
160
+ * The high byte sign extends (bits 31..24 set to b23).
161
+ * S24_3LE Signed 24 bits packed in 3 bytes little endian
162
+ * FLOAT Floating point 32 bits (float type), in range -1 to 1
163
+ */
164
+
165
+ enum lc3_pcm_format {
166
+ LC3_PCM_FORMAT_S16,
167
+ LC3_PCM_FORMAT_S24,
168
+ LC3_PCM_FORMAT_S24_3LE,
169
+ LC3_PCM_FORMAT_FLOAT,
170
+ };
171
+
172
+
173
+ /**
174
+ * Handle
175
+ */
176
+
177
+ typedef struct lc3_encoder *lc3_encoder_t;
178
+ typedef struct lc3_decoder *lc3_decoder_t;
179
+
180
+
181
+ /**
182
+ * Static memory of encoder context
183
+ *
184
+ * Propose types suitable for static memory allocation, supporting
185
+ * any frame duration, and maximum samplerates 16k and 48k respectively
186
+ * You can customize your type using the `LC3_ENCODER_MEM_T` or
187
+ * `LC3_DECODER_MEM_T` macro.
188
+ */
189
+
190
+ typedef LC3_ENCODER_MEM_T(10000, 16000) lc3_encoder_mem_16k_t;
191
+ typedef LC3_ENCODER_MEM_T(10000, 48000) lc3_encoder_mem_48k_t;
192
+
193
+ typedef LC3_DECODER_MEM_T(10000, 16000) lc3_decoder_mem_16k_t;
194
+ typedef LC3_DECODER_MEM_T(10000, 48000) lc3_decoder_mem_48k_t;
195
+
196
+
197
+ /**
198
+ * Return the number of PCM samples in a frame
199
+ * dt_us Frame duration in us, 7500 or 10000
200
+ * sr_hz Samplerate in Hz, 8000, 16000, 24000, 32000 or 48000
201
+ * return Number of PCM samples, -1 on bad parameters
202
+ */
203
+ int lc3_frame_samples(int dt_us, int sr_hz);
204
+
205
+ /**
206
+ * Return the size of frames, from bitrate
207
+ * dt_us Frame duration in us, 7500 or 10000
208
+ * bitrate Target bitrate in bit per second
209
+ * return The floor size in bytes of the frames, -1 on bad parameters
210
+ */
211
+ int lc3_frame_bytes(int dt_us, int bitrate);
212
+
213
+ /**
214
+ * Resolve the bitrate, from the size of frames
215
+ * dt_us Frame duration in us, 7500 or 10000
216
+ * nbytes Size in bytes of the frames
217
+ * return The according bitrate in bps, -1 on bad parameters
218
+ */
219
+ int lc3_resolve_bitrate(int dt_us, int nbytes);
220
+
221
+ /**
222
+ * Return algorithmic delay, as a number of samples
223
+ * dt_us Frame duration in us, 7500 or 10000
224
+ * sr_hz Samplerate in Hz, 8000, 16000, 24000, 32000 or 48000
225
+ * return Number of algorithmic delay samples, -1 on bad parameters
226
+ */
227
+ int lc3_delay_samples(int dt_us, int sr_hz);
228
+
229
+ /**
230
+ * Return size needed for an encoder
231
+ * dt_us Frame duration in us, 7500 or 10000
232
+ * sr_hz Samplerate in Hz, 8000, 16000, 24000, 32000 or 48000
233
+ * return Size of then encoder in bytes, 0 on bad parameters
234
+ *
235
+ * The `sr_hz` parameter is the samplerate of the PCM input stream,
236
+ * and will match `sr_pcm_hz` of `lc3_setup_encoder()`.
237
+ */
238
+ unsigned lc3_encoder_size(int dt_us, int sr_hz);
239
+
240
+ /**
241
+ * Setup encoder
242
+ * dt_us Frame duration in us, 7500 or 10000
243
+ * sr_hz Samplerate in Hz, 8000, 16000, 24000, 32000 or 48000
244
+ * sr_pcm_hz Input samplerate, downsampling option of input, or 0
245
+ * mem Encoder memory space, aligned to pointer type
246
+ * return Encoder as an handle, NULL on bad parameters
247
+ *
248
+ * The `sr_pcm_hz` parameter is a downsampling option of PCM input,
249
+ * the value `0` fallback to the samplerate of the encoded stream `sr_hz`.
250
+ * When used, `sr_pcm_hz` is intended to be higher or equal to the encoder
251
+ * samplerate `sr_hz`. The size of the context needed, given by
252
+ * `lc3_encoder_size()` will be set accordingly to `sr_pcm_hz`.
253
+ */
254
+ lc3_encoder_t lc3_setup_encoder(
255
+ int dt_us, int sr_hz, int sr_pcm_hz, void *mem);
256
+
257
+ /**
258
+ * Encode a frame
259
+ * encoder Handle of the encoder
260
+ * fmt PCM input format
261
+ * pcm, stride Input PCM samples, and count between two consecutives
262
+ * nbytes Target size, in bytes, of the frame (20 to 400)
263
+ * out Output buffer of `nbytes` size
264
+ * return 0: On success -1: Wrong parameters
265
+ */
266
+ int lc3_encode(lc3_encoder_t encoder, enum lc3_pcm_format fmt,
267
+ const void *pcm, int stride, int nbytes, void *out);
268
+
269
+ /**
270
+ * Return size needed for an decoder
271
+ * dt_us Frame duration in us, 7500 or 10000
272
+ * sr_hz Samplerate in Hz, 8000, 16000, 24000, 32000 or 48000
273
+ * return Size of then decoder in bytes, 0 on bad parameters
274
+ *
275
+ * The `sr_hz` parameter is the samplerate of the PCM output stream,
276
+ * and will match `sr_pcm_hz` of `lc3_setup_decoder()`.
277
+ */
278
+ unsigned lc3_decoder_size(int dt_us, int sr_hz);
279
+
280
+ /**
281
+ * Setup decoder
282
+ * dt_us Frame duration in us, 7500 or 10000
283
+ * sr_hz Samplerate in Hz, 8000, 16000, 24000, 32000 or 48000
284
+ * sr_pcm_hz Output samplerate, upsampling option of output (or 0)
285
+ * mem Decoder memory space, aligned to pointer type
286
+ * return Decoder as an handle, NULL on bad parameters
287
+ *
288
+ * The `sr_pcm_hz` parameter is an upsampling option of PCM output,
289
+ * the value `0` fallback to the samplerate of the decoded stream `sr_hz`.
290
+ * When used, `sr_pcm_hz` is intended to be higher or equal to the decoder
291
+ * samplerate `sr_hz`. The size of the context needed, given by
292
+ * `lc3_decoder_size()` will be set accordingly to `sr_pcm_hz`.
293
+ */
294
+ lc3_decoder_t lc3_setup_decoder(
295
+ int dt_us, int sr_hz, int sr_pcm_hz, void *mem);
296
+
297
+ /**
298
+ * Decode a frame
299
+ * decoder Handle of the decoder
300
+ * in, nbytes Input bitstream, and size in bytes, NULL performs PLC
301
+ * fmt PCM output format
302
+ * pcm, stride Output PCM samples, and count between two consecutives
303
+ * return 0: On success 1: PLC operated -1: Wrong parameters
304
+ */
305
+ int lc3_decode(lc3_decoder_t decoder, const void *in, int nbytes,
306
+ enum lc3_pcm_format fmt, void *pcm, int stride);
307
+
308
+
309
+ #ifdef __cplusplus
310
+ }
311
+ #endif
312
+
313
+ #endif /* __LC3_H */
@@ -0,0 +1,283 @@
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) - C++ interface
21
+ */
22
+
23
+ #ifndef __LC3_CPP_H
24
+ #define __LC3_CPP_H
25
+
26
+ #include <cassert>
27
+ #include <memory>
28
+ #include <vector>
29
+ #include <stdlib.h>
30
+
31
+ #include "lc3.h"
32
+
33
+ namespace lc3 {
34
+
35
+ // PCM Sample Format
36
+ // - Signed 16 bits, in 16 bits words (int16_t)
37
+ // - Signed 24 bits, using low three bytes of 32 bits words (int32_t)
38
+ // The high byte sign extends (bits 31..24 set to b23)
39
+ // - Signed 24 bits packed in 3 bytes little endian
40
+ // - Floating point 32 bits (float type), in range -1 to 1
41
+
42
+ enum class PcmFormat {
43
+ kS16 = LC3_PCM_FORMAT_S16,
44
+ kS24 = LC3_PCM_FORMAT_S24,
45
+ kS24In3Le = LC3_PCM_FORMAT_S24_3LE,
46
+ kF32 = LC3_PCM_FORMAT_FLOAT
47
+ };
48
+
49
+ // Base Encoder/Decoder Class
50
+ template <typename T>
51
+ class Base {
52
+ protected:
53
+ Base(int dt_us, int sr_hz, int sr_pcm_hz, size_t nchannels)
54
+ : dt_us_(dt_us),
55
+ sr_hz_(sr_hz),
56
+ sr_pcm_hz_(sr_pcm_hz == 0 ? sr_hz : sr_pcm_hz),
57
+ nchannels_(nchannels) {
58
+ states.reserve(nchannels_);
59
+ }
60
+
61
+ virtual ~Base() = default;
62
+
63
+ int dt_us_, sr_hz_;
64
+ int sr_pcm_hz_;
65
+ size_t nchannels_;
66
+
67
+ using state_ptr = std::unique_ptr<T, decltype(&free)>;
68
+ std::vector<state_ptr> states;
69
+
70
+ public:
71
+ // Return the number of PCM samples in a frame
72
+ int GetFrameSamples() { return lc3_frame_samples(dt_us_, sr_pcm_hz_); }
73
+
74
+ // Return the size of frames, from bitrate
75
+ int GetFrameBytes(int bitrate) { return lc3_frame_bytes(dt_us_, bitrate); }
76
+
77
+ // Resolve the bitrate, from the size of frames
78
+ int ResolveBitrate(int nbytes) { return lc3_resolve_bitrate(dt_us_, nbytes); }
79
+
80
+ // Return algorithmic delay, as a number of samples
81
+ int GetDelaySamples() { return lc3_delay_samples(dt_us_, sr_pcm_hz_); }
82
+
83
+ }; // class Base
84
+
85
+ // Encoder Class
86
+ class Encoder : public Base<struct lc3_encoder> {
87
+ template <typename T>
88
+ int EncodeImpl(PcmFormat fmt, const T *pcm, int frame_size, uint8_t *out) {
89
+ if (states.size() != nchannels_) return -1;
90
+
91
+ enum lc3_pcm_format cfmt = static_cast<lc3_pcm_format>(fmt);
92
+ int ret = 0;
93
+
94
+ for (size_t ich = 0; ich < nchannels_; ich++)
95
+ ret |= lc3_encode(states[ich].get(), cfmt, pcm + ich, nchannels_,
96
+ frame_size, out + ich * frame_size);
97
+
98
+ return ret;
99
+ }
100
+
101
+ public:
102
+ // Encoder construction / destruction
103
+ //
104
+ // The frame duration `dt_us` is 7500 or 10000 us.
105
+ // The samplerate `sr_hz` is 8000, 16000, 24000, 32000 or 48000 Hz.
106
+ //
107
+ // The `sr_pcm_hz` parameter is a downsampling option of PCM input,
108
+ // the value 0 fallback to the samplerate of the encoded stream `sr_hz`.
109
+ // When used, `sr_pcm_hz` is intended to be higher or equal to the encoder
110
+ // samplerate `sr_hz`.
111
+
112
+ Encoder(int dt_us, int sr_hz, int sr_pcm_hz = 0, size_t nchannels = 1)
113
+ : Base(dt_us, sr_hz, sr_pcm_hz, nchannels) {
114
+ for (size_t ich = 0; ich < nchannels_; ich++) {
115
+ auto s = state_ptr(
116
+ (lc3_encoder_t)malloc(lc3_encoder_size(dt_us_, sr_pcm_hz_)), free);
117
+
118
+ if (lc3_setup_encoder(dt_us_, sr_hz_, sr_pcm_hz_, s.get()))
119
+ states.push_back(std::move(s));
120
+ }
121
+ }
122
+
123
+ ~Encoder() override = default;
124
+
125
+ // Reset encoder state
126
+
127
+ void Reset() {
128
+ for (auto &s : states)
129
+ lc3_setup_encoder(dt_us_, sr_hz_, sr_pcm_hz_, s.get());
130
+ }
131
+
132
+ // Encode
133
+ //
134
+ // The input PCM samples are given in signed 16 bits, 24 bits, float,
135
+ // according the type of `pcm` input buffer, or by selecting a format.
136
+ //
137
+ // The PCM samples are read in interleaved way, and consecutive
138
+ // `nchannels` frames of size `frame_size` are output in `out` buffer.
139
+ //
140
+ // The value returned is 0 on successs, -1 otherwise.
141
+
142
+ int Encode(const int16_t *pcm, int frame_size, uint8_t *out) {
143
+ return EncodeImpl(PcmFormat::kS16, pcm, frame_size, out);
144
+ }
145
+
146
+ int Encode(const int32_t *pcm, int frame_size, uint8_t *out) {
147
+ return EncodeImpl(PcmFormat::kS24, pcm, frame_size, out);
148
+ }
149
+
150
+ int Encode(const float *pcm, int frame_size, uint8_t *out) {
151
+ return EncodeImpl(PcmFormat::kF32, pcm, frame_size, out);
152
+ }
153
+
154
+ int Encode(PcmFormat fmt, const void *pcm, int frame_size, uint8_t *out) {
155
+ uintptr_t pcm_ptr = reinterpret_cast<uintptr_t>(pcm);
156
+
157
+ switch (fmt) {
158
+ case PcmFormat::kS16:
159
+ assert(pcm_ptr % alignof(int16_t) == 0);
160
+ return EncodeImpl(fmt, reinterpret_cast<const int16_t *>(pcm),
161
+ frame_size, out);
162
+
163
+ case PcmFormat::kS24:
164
+ assert(pcm_ptr % alignof(int32_t) == 0);
165
+ return EncodeImpl(fmt, reinterpret_cast<const int32_t *>(pcm),
166
+ frame_size, out);
167
+
168
+ case PcmFormat::kS24In3Le:
169
+ return EncodeImpl(fmt, reinterpret_cast<const int8_t(*)[3]>(pcm),
170
+ frame_size, out);
171
+
172
+ case PcmFormat::kF32:
173
+ assert(pcm_ptr % alignof(float) == 0);
174
+ return EncodeImpl(fmt, reinterpret_cast<const float *>(pcm), frame_size,
175
+ out);
176
+ }
177
+
178
+ return -1;
179
+ }
180
+
181
+ }; // class Encoder
182
+
183
+ // Decoder Class
184
+ class Decoder : public Base<struct lc3_decoder> {
185
+ template <typename T>
186
+ int DecodeImpl(const uint8_t *in, int frame_size, PcmFormat fmt, T *pcm) {
187
+ if (states.size() != nchannels_) return -1;
188
+
189
+ enum lc3_pcm_format cfmt = static_cast<enum lc3_pcm_format>(fmt);
190
+ int ret = 0;
191
+
192
+ for (size_t ich = 0; ich < nchannels_; ich++)
193
+ ret |= lc3_decode(states[ich].get(), in + ich * frame_size, frame_size,
194
+ cfmt, pcm + ich, nchannels_);
195
+
196
+ return ret;
197
+ }
198
+
199
+ public:
200
+ // Decoder construction / destruction
201
+ //
202
+ // The frame duration `dt_us` is 7500 or 10000 us.
203
+ // The samplerate `sr_hz` is 8000, 16000, 24000, 32000 or 48000 Hz.
204
+ //
205
+ // The `sr_pcm_hz` parameter is an downsampling option of PCM output,
206
+ // the value 0 fallback to the samplerate of the decoded stream `sr_hz`.
207
+ // When used, `sr_pcm_hz` is intended to be higher or equal to the decoder
208
+ // samplerate `sr_hz`.
209
+
210
+ Decoder(int dt_us, int sr_hz, int sr_pcm_hz = 0, size_t nchannels = 1)
211
+ : Base(dt_us, sr_hz, sr_pcm_hz, nchannels) {
212
+ for (size_t i = 0; i < nchannels_; i++) {
213
+ auto s = state_ptr(
214
+ (lc3_decoder_t)malloc(lc3_decoder_size(dt_us_, sr_pcm_hz_)), free);
215
+
216
+ if (lc3_setup_decoder(dt_us_, sr_hz_, sr_pcm_hz_, s.get()))
217
+ states.push_back(std::move(s));
218
+ }
219
+ }
220
+
221
+ ~Decoder() override = default;
222
+
223
+ // Reset decoder state
224
+
225
+ void Reset() {
226
+ for (auto &s : states)
227
+ lc3_setup_decoder(dt_us_, sr_hz_, sr_pcm_hz_, s.get());
228
+ }
229
+
230
+ // Decode
231
+ //
232
+ // Consecutive `nchannels` frames of size `frame_size` are decoded
233
+ // in the `pcm` buffer in interleaved way.
234
+ //
235
+ // The PCM samples are output in signed 16 bits, 24 bits, float,
236
+ // according the type of `pcm` output buffer, or by selecting a format.
237
+ //
238
+ // The value returned is 0 on successs, 1 when PLC has been performed,
239
+ // and -1 otherwise.
240
+
241
+ int Decode(const uint8_t *in, int frame_size, int16_t *pcm) {
242
+ return DecodeImpl(in, frame_size, PcmFormat::kS16, pcm);
243
+ }
244
+
245
+ int Decode(const uint8_t *in, int frame_size, int32_t *pcm) {
246
+ return DecodeImpl(in, frame_size, PcmFormat::kS24In3Le, pcm);
247
+ }
248
+
249
+ int Decode(const uint8_t *in, int frame_size, float *pcm) {
250
+ return DecodeImpl(in, frame_size, PcmFormat::kF32, pcm);
251
+ }
252
+
253
+ int Decode(const uint8_t *in, int frame_size, PcmFormat fmt, void *pcm) {
254
+ uintptr_t pcm_ptr = reinterpret_cast<uintptr_t>(pcm);
255
+
256
+ switch (fmt) {
257
+ case PcmFormat::kS16:
258
+ assert(pcm_ptr % alignof(int16_t) == 0);
259
+ return DecodeImpl(in, frame_size, fmt,
260
+ reinterpret_cast<int16_t *>(pcm));
261
+
262
+ case PcmFormat::kS24:
263
+ assert(pcm_ptr % alignof(int32_t) == 0);
264
+ return DecodeImpl(in, frame_size, fmt,
265
+ reinterpret_cast<int32_t *>(pcm));
266
+
267
+ case PcmFormat::kS24In3Le:
268
+ return DecodeImpl(in, frame_size, fmt,
269
+ reinterpret_cast<int8_t(*)[3]>(pcm));
270
+
271
+ case PcmFormat::kF32:
272
+ assert(pcm_ptr % alignof(float) == 0);
273
+ return DecodeImpl(in, frame_size, fmt, reinterpret_cast<float *>(pcm));
274
+ }
275
+
276
+ return -1;
277
+ }
278
+
279
+ }; // class Decoder
280
+
281
+ } // namespace lc3
282
+
283
+ #endif /* __LC3_CPP_H */