gravix-rtc-react-native 0.0.0-stage → 0.2.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 (378) hide show
  1. package/CHANGELOG.md +134 -0
  2. package/LICENSE +20 -0
  3. package/LICENSES/Apache-2.0.txt +175 -0
  4. package/NOTICE +68 -0
  5. package/README.md +313 -2
  6. package/android/build.gradle +137 -0
  7. package/android/consumer-rules.pro +29 -0
  8. package/android/src/main/AndroidManifest.xml +9 -0
  9. package/android/src/main/cpp/CMakeLists.txt +48 -0
  10. package/android/src/main/cpp/gx_dfn_engine.c +332 -0
  11. package/android/src/main/cpp/gx_fx_jni.cpp +34 -0
  12. package/android/src/main/cpp/gx_ns_jni.c +162 -0
  13. package/android/src/main/cpp/third_party/onnxruntime/LICENSE +21 -0
  14. package/android/src/main/cpp/third_party/onnxruntime/include/onnxruntime_c_api.h +9227 -0
  15. package/android/src/main/cpp/third_party/onnxruntime/include/onnxruntime_ep_c_api.h +3315 -0
  16. package/android/src/main/cpp/third_party/onnxruntime/include/onnxruntime_error_code.h +98 -0
  17. package/android/src/main/java/com/gravitycompile/gravixrtc/GravixAudioHooks.kt +144 -0
  18. package/android/src/main/java/com/gravitycompile/gravixrtc/GravixAudioModule.kt +105 -0
  19. package/android/src/main/java/com/gravitycompile/gravixrtc/GravixNativeAudio.kt +310 -0
  20. package/android/src/main/java/com/gravitycompile/gravixrtc/GravixRtc.kt +134 -0
  21. package/android/src/main/java/com/gravitycompile/gravixrtc/GravixRtcModule.kt +176 -0
  22. package/android/src/main/java/com/gravitycompile/gravixrtc/GravixRtcPackage.kt +39 -0
  23. package/android/src/main/java/com/gravitycompile/gravixrtc/audio/AudioDeviceKind.java +44 -0
  24. package/android/src/main/java/com/gravitycompile/gravixrtc/audio/AudioManagerUtils.kt +120 -0
  25. package/android/src/main/java/com/gravitycompile/gravixrtc/audio/AudioSwitchManager.java +270 -0
  26. package/android/src/main/java/com/gravitycompile/gravixrtc/audio/AudioType.kt +50 -0
  27. package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicCaptureRouter.kt +375 -0
  28. package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicDecoder.kt +339 -0
  29. package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicInterruptionWatcher.kt +82 -0
  30. package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicMicRelease.kt +117 -0
  31. package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicMixKernel.kt +191 -0
  32. package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicMixerEngine.kt +617 -0
  33. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/AudioRoutePolicy.kt +137 -0
  34. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GravixCaptureProcessing.kt +67 -0
  35. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxCaptureDump.kt +143 -0
  36. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxCaptureSwitcher.kt +196 -0
  37. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxNoiseProcessor.kt +795 -0
  38. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxNsLogic.kt +180 -0
  39. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxNsNative.kt +83 -0
  40. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxNsStudio.kt +372 -0
  41. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxRecordStartGuard.kt +76 -0
  42. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxRecorderSeam.kt +434 -0
  43. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxSingerSource.kt +37 -0
  44. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxVoiceFx.kt +160 -0
  45. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/OtherAppAudioPolicy.kt +143 -0
  46. package/android/src/main/java/org/webrtc/audio/WebRtcAudioTrackHelper.kt +43 -0
  47. package/docs/ANDROID_NATIVE_HOOKS.md +102 -0
  48. package/docs/FEATURE_MATRIX.md +192 -0
  49. package/docs/IOS_NATIVE_HOOKS.md +190 -0
  50. package/gravix-rtc-react-native.podspec +49 -0
  51. package/ios/GravixRtc.h +7 -0
  52. package/ios/GravixRtc.mm +273 -0
  53. package/ios/GravixRtcSetup.h +29 -0
  54. package/ios/GravixRtcSetup.m +52 -0
  55. package/ios/audio/GravixRtcIosAudio.m +157 -0
  56. package/ios/audio/GxAudioDevice.h +62 -0
  57. package/ios/audio/GxAudioDevice.m +857 -0
  58. package/ios/audio/GxAudioSetup.h +34 -0
  59. package/ios/audio/GxAudioSetup.m +70 -0
  60. package/ios/audio/GxCompat.swift +53 -0
  61. package/ios/audio/GxIosAudio.swift +99 -0
  62. package/ios/audio/GxMusicController.swift +150 -0
  63. package/ios/audio/GxMusicPost.swift +362 -0
  64. package/ios/audio/GxNoiseProcessor.swift +718 -0
  65. package/ios/audio/GxNsDfn3CoreML.swift +195 -0
  66. package/ios/audio/GxNsStudioEngine.swift +237 -0
  67. package/ios/audio/GxNsStudioPack.swift +212 -0
  68. package/ios/audio/GxVoiceFx.swift +161 -0
  69. package/ios/audio/gx_adm_state.h +153 -0
  70. package/ios/gxcore/apple/gx_music_post.c +312 -0
  71. package/ios/gxcore/apple/gx_pcm.c +30 -0
  72. package/ios/gxcore/apple/gxns_build.h +19 -0
  73. package/ios/gxcore/apple/gxns_ios.c +17 -0
  74. package/ios/gxcore/apple/include/gx_fx.h +3 -0
  75. package/ios/gxcore/apple/include/gx_music_post.h +88 -0
  76. package/ios/gxcore/apple/include/gx_ns.h +3 -0
  77. package/ios/gxcore/apple/include/gx_pcm.h +33 -0
  78. package/ios/gxcore/apple/include/gxns_ios.h +18 -0
  79. package/ios/gxcore/apple/include/module.modulemap +10 -0
  80. package/ios/gxcore/apple/shim/rnnoise.h +2 -0
  81. package/ios/gxcore/apple/shim/speex_resampler.h +2 -0
  82. package/ios/gxcore/apple/units/gx_fx_forward.cpp +3 -0
  83. package/ios/gxcore/apple/units/gx_ns.c +7 -0
  84. package/ios/gxcore/apple/units/gx_ns_timer.c +7 -0
  85. package/ios/gxcore/apple/units/rnnoise_celt_lpc.c +7 -0
  86. package/ios/gxcore/apple/units/rnnoise_denoise.c +7 -0
  87. package/ios/gxcore/apple/units/rnnoise_kiss_fft.c +7 -0
  88. package/ios/gxcore/apple/units/rnnoise_pitch.c +7 -0
  89. package/ios/gxcore/apple/units/rnnoise_rnn.c +7 -0
  90. package/ios/gxcore/apple/units/rnnoise_rnn_data.c +7 -0
  91. package/ios/gxcore/apple/units/speexdsp_resample.c +7 -0
  92. package/ios/resources/ns/DFN3-NOTICE.txt +10 -0
  93. package/ios/resources/ns/DeepFilterNet-LICENSE-APACHE +201 -0
  94. package/ios/resources/ns/DeepFilterNet-LICENSE-MIT +19 -0
  95. package/ios/resources/ns/gxns_dfn3.mlmodelc/analytics/coremldata.bin +0 -0
  96. package/ios/resources/ns/gxns_dfn3.mlmodelc/coremldata.bin +0 -0
  97. package/ios/resources/ns/gxns_dfn3.mlmodelc/metadata.json +338 -0
  98. package/ios/resources/ns/gxns_dfn3.mlmodelc/model.mil +927 -0
  99. package/ios/resources/ns/gxns_dfn3.mlmodelc/weights/weight.bin +0 -0
  100. package/lib/module/android/bindings.js +49 -0
  101. package/lib/module/android/bindings.js.map +1 -0
  102. package/lib/module/android/index.js +13 -0
  103. package/lib/module/android/index.js.map +1 -0
  104. package/lib/module/android/micMute.js +341 -0
  105. package/lib/module/android/micMute.js.map +1 -0
  106. package/lib/module/android/nativeAudio.js +47 -0
  107. package/lib/module/android/nativeAudio.js.map +1 -0
  108. package/lib/module/android/noiseSuppression.js +170 -0
  109. package/lib/module/android/noiseSuppression.js.map +1 -0
  110. package/lib/module/android/roomMusic.js +142 -0
  111. package/lib/module/android/roomMusic.js.map +1 -0
  112. package/lib/module/android/singerMode.js +31 -0
  113. package/lib/module/android/singerMode.js.map +1 -0
  114. package/lib/module/android/voiceEffects.js +65 -0
  115. package/lib/module/android/voiceEffects.js.map +1 -0
  116. package/lib/module/audio/AudioManager.js +79 -0
  117. package/lib/module/audio/AudioManager.js.map +1 -0
  118. package/lib/module/audio/AudioSession.js +90 -0
  119. package/lib/module/audio/AudioSession.js.map +1 -0
  120. package/lib/module/audio/remoteVolume.js +54 -0
  121. package/lib/module/audio/remoteVolume.js.map +1 -0
  122. package/lib/module/components/VideoView.js +109 -0
  123. package/lib/module/components/VideoView.js.map +1 -0
  124. package/lib/module/features/audioScenario.js +53 -0
  125. package/lib/module/features/audioScenario.js.map +1 -0
  126. package/lib/module/features/beauty.js +828 -0
  127. package/lib/module/features/beauty.js.map +1 -0
  128. package/lib/module/features/micRelease.js +89 -0
  129. package/lib/module/features/micRelease.js.map +1 -0
  130. package/lib/module/features/noiseSuppression.js +213 -0
  131. package/lib/module/features/noiseSuppression.js.map +1 -0
  132. package/lib/module/features/roomMusic.js +90 -0
  133. package/lib/module/features/roomMusic.js.map +1 -0
  134. package/lib/module/features/roomMusicAndroid.js +294 -0
  135. package/lib/module/features/roomMusicAndroid.js.map +1 -0
  136. package/lib/module/features/roomMusicIos.js +250 -0
  137. package/lib/module/features/roomMusicIos.js.map +1 -0
  138. package/lib/module/features/roomMusicTypes.js +53 -0
  139. package/lib/module/features/roomMusicTypes.js.map +1 -0
  140. package/lib/module/features/screenShare.js +22 -0
  141. package/lib/module/features/screenShare.js.map +1 -0
  142. package/lib/module/features/singerMode.js +73 -0
  143. package/lib/module/features/singerMode.js.map +1 -0
  144. package/lib/module/features/voiceEffects.js +148 -0
  145. package/lib/module/features/voiceEffects.js.map +1 -0
  146. package/lib/module/hooks/context.js +34 -0
  147. package/lib/module/hooks/context.js.map +1 -0
  148. package/lib/module/hooks/hooks.js +145 -0
  149. package/lib/module/hooks/hooks.js.map +1 -0
  150. package/lib/module/hooks/types.js +4 -0
  151. package/lib/module/hooks/types.js.map +1 -0
  152. package/lib/module/hooks/useRoomEvents.js +30 -0
  153. package/lib/module/hooks/useRoomEvents.js.map +1 -0
  154. package/lib/module/index.js +43 -0
  155. package/lib/module/index.js.map +1 -0
  156. package/lib/module/ios/autoAttach.js +14 -0
  157. package/lib/module/ios/autoAttach.js.map +1 -0
  158. package/lib/module/ios/iosAudio.js +149 -0
  159. package/lib/module/ios/iosAudio.js.map +1 -0
  160. package/lib/module/join/appStateLifecycle.js +54 -0
  161. package/lib/module/join/appStateLifecycle.js.map +1 -0
  162. package/lib/module/micPolicy.js +249 -0
  163. package/lib/module/micPolicy.js.map +1 -0
  164. package/lib/module/native/NativeGravixAudio.js +18 -0
  165. package/lib/module/native/NativeGravixAudio.js.map +1 -0
  166. package/lib/module/native/NativeGravixRtc.js +13 -0
  167. package/lib/module/native/NativeGravixRtc.js.map +1 -0
  168. package/lib/module/native/module.js +23 -0
  169. package/lib/module/native/module.js.map +1 -0
  170. package/lib/module/package.json +1 -0
  171. package/lib/module/polyfills/DOMException.js +22 -0
  172. package/lib/module/polyfills/DOMException.js.map +1 -0
  173. package/lib/module/polyfills/early.js +18 -0
  174. package/lib/module/polyfills/early.js.map +1 -0
  175. package/lib/module/polyfills/event.js +71 -0
  176. package/lib/module/polyfills/event.js.map +1 -0
  177. package/lib/module/polyfills/sha256.js +92 -0
  178. package/lib/module/polyfills/sha256.js.map +1 -0
  179. package/lib/module/polyfills/subtleHmac.js +91 -0
  180. package/lib/module/polyfills/subtleHmac.js.map +1 -0
  181. package/lib/module/polyfills/textCoding.js +164 -0
  182. package/lib/module/polyfills/textCoding.js.map +1 -0
  183. package/lib/module/registerGlobals.js +135 -0
  184. package/lib/module/registerGlobals.js.map +1 -0
  185. package/lib/module/unsupported.js +90 -0
  186. package/lib/module/unsupported.js.map +1 -0
  187. package/lib/module/version.js +7 -0
  188. package/lib/module/version.js.map +1 -0
  189. package/lib/typescript/package.json +1 -0
  190. package/lib/typescript/src/android/bindings.d.ts +14 -0
  191. package/lib/typescript/src/android/bindings.d.ts.map +1 -0
  192. package/lib/typescript/src/android/index.d.ts +9 -0
  193. package/lib/typescript/src/android/index.d.ts.map +1 -0
  194. package/lib/typescript/src/android/micMute.d.ts +124 -0
  195. package/lib/typescript/src/android/micMute.d.ts.map +1 -0
  196. package/lib/typescript/src/android/nativeAudio.d.ts +40 -0
  197. package/lib/typescript/src/android/nativeAudio.d.ts.map +1 -0
  198. package/lib/typescript/src/android/noiseSuppression.d.ts +48 -0
  199. package/lib/typescript/src/android/noiseSuppression.d.ts.map +1 -0
  200. package/lib/typescript/src/android/roomMusic.d.ts +80 -0
  201. package/lib/typescript/src/android/roomMusic.d.ts.map +1 -0
  202. package/lib/typescript/src/android/singerMode.d.ts +27 -0
  203. package/lib/typescript/src/android/singerMode.d.ts.map +1 -0
  204. package/lib/typescript/src/android/voiceEffects.d.ts +30 -0
  205. package/lib/typescript/src/android/voiceEffects.d.ts.map +1 -0
  206. package/lib/typescript/src/audio/AudioManager.d.ts +32 -0
  207. package/lib/typescript/src/audio/AudioManager.d.ts.map +1 -0
  208. package/lib/typescript/src/audio/AudioSession.d.ts +70 -0
  209. package/lib/typescript/src/audio/AudioSession.d.ts.map +1 -0
  210. package/lib/typescript/src/audio/remoteVolume.d.ts +8 -0
  211. package/lib/typescript/src/audio/remoteVolume.d.ts.map +1 -0
  212. package/lib/typescript/src/components/VideoView.d.ts +44 -0
  213. package/lib/typescript/src/components/VideoView.d.ts.map +1 -0
  214. package/lib/typescript/src/features/audioScenario.d.ts +24 -0
  215. package/lib/typescript/src/features/audioScenario.d.ts.map +1 -0
  216. package/lib/typescript/src/features/beauty.d.ts +377 -0
  217. package/lib/typescript/src/features/beauty.d.ts.map +1 -0
  218. package/lib/typescript/src/features/micRelease.d.ts +28 -0
  219. package/lib/typescript/src/features/micRelease.d.ts.map +1 -0
  220. package/lib/typescript/src/features/noiseSuppression.d.ts +64 -0
  221. package/lib/typescript/src/features/noiseSuppression.d.ts.map +1 -0
  222. package/lib/typescript/src/features/roomMusic.d.ts +41 -0
  223. package/lib/typescript/src/features/roomMusic.d.ts.map +1 -0
  224. package/lib/typescript/src/features/roomMusicAndroid.d.ts +60 -0
  225. package/lib/typescript/src/features/roomMusicAndroid.d.ts.map +1 -0
  226. package/lib/typescript/src/features/roomMusicIos.d.ts +56 -0
  227. package/lib/typescript/src/features/roomMusicIos.d.ts.map +1 -0
  228. package/lib/typescript/src/features/roomMusicTypes.d.ts +76 -0
  229. package/lib/typescript/src/features/roomMusicTypes.d.ts.map +1 -0
  230. package/lib/typescript/src/features/screenShare.d.ts +12 -0
  231. package/lib/typescript/src/features/screenShare.d.ts.map +1 -0
  232. package/lib/typescript/src/features/singerMode.d.ts +20 -0
  233. package/lib/typescript/src/features/singerMode.d.ts.map +1 -0
  234. package/lib/typescript/src/features/voiceEffects.d.ts +46 -0
  235. package/lib/typescript/src/features/voiceEffects.d.ts.map +1 -0
  236. package/lib/typescript/src/hooks/context.d.ts +12 -0
  237. package/lib/typescript/src/hooks/context.d.ts.map +1 -0
  238. package/lib/typescript/src/hooks/hooks.d.ts +54 -0
  239. package/lib/typescript/src/hooks/hooks.d.ts.map +1 -0
  240. package/lib/typescript/src/hooks/types.d.ts +8 -0
  241. package/lib/typescript/src/hooks/types.d.ts.map +1 -0
  242. package/lib/typescript/src/hooks/useRoomEvents.d.ts +13 -0
  243. package/lib/typescript/src/hooks/useRoomEvents.d.ts.map +1 -0
  244. package/lib/typescript/src/index.d.ts +37 -0
  245. package/lib/typescript/src/index.d.ts.map +1 -0
  246. package/lib/typescript/src/ios/autoAttach.d.ts +2 -0
  247. package/lib/typescript/src/ios/autoAttach.d.ts.map +1 -0
  248. package/lib/typescript/src/ios/iosAudio.d.ts +96 -0
  249. package/lib/typescript/src/ios/iosAudio.d.ts.map +1 -0
  250. package/lib/typescript/src/join/appStateLifecycle.d.ts +14 -0
  251. package/lib/typescript/src/join/appStateLifecycle.d.ts.map +1 -0
  252. package/lib/typescript/src/micPolicy.d.ts +104 -0
  253. package/lib/typescript/src/micPolicy.d.ts.map +1 -0
  254. package/lib/typescript/src/native/NativeGravixAudio.d.ts +21 -0
  255. package/lib/typescript/src/native/NativeGravixAudio.d.ts.map +1 -0
  256. package/lib/typescript/src/native/NativeGravixRtc.d.ts +31 -0
  257. package/lib/typescript/src/native/NativeGravixRtc.d.ts.map +1 -0
  258. package/lib/typescript/src/native/module.d.ts +7 -0
  259. package/lib/typescript/src/native/module.d.ts.map +1 -0
  260. package/lib/typescript/src/polyfills/DOMException.d.ts +3 -0
  261. package/lib/typescript/src/polyfills/DOMException.d.ts.map +1 -0
  262. package/lib/typescript/src/polyfills/early.d.ts +2 -0
  263. package/lib/typescript/src/polyfills/early.d.ts.map +1 -0
  264. package/lib/typescript/src/polyfills/event.d.ts +2 -0
  265. package/lib/typescript/src/polyfills/event.d.ts.map +1 -0
  266. package/lib/typescript/src/polyfills/sha256.d.ts +3 -0
  267. package/lib/typescript/src/polyfills/sha256.d.ts.map +1 -0
  268. package/lib/typescript/src/polyfills/subtleHmac.d.ts +37 -0
  269. package/lib/typescript/src/polyfills/subtleHmac.d.ts.map +1 -0
  270. package/lib/typescript/src/polyfills/textCoding.d.ts +36 -0
  271. package/lib/typescript/src/polyfills/textCoding.d.ts.map +1 -0
  272. package/lib/typescript/src/registerGlobals.d.ts +42 -0
  273. package/lib/typescript/src/registerGlobals.d.ts.map +1 -0
  274. package/lib/typescript/src/unsupported.d.ts +42 -0
  275. package/lib/typescript/src/unsupported.d.ts.map +1 -0
  276. package/lib/typescript/src/version.d.ts +3 -0
  277. package/lib/typescript/src/version.d.ts.map +1 -0
  278. package/metro/index.js +39 -0
  279. package/metro/noise-stub.js +10 -0
  280. package/native/gxfx/include/gx_fx.h +82 -0
  281. package/native/gxfx/src/gx_fx.cpp +527 -0
  282. package/native/gxfx/third_party/README.md +4 -0
  283. package/native/gxfx/third_party/signalsmith-linear/LICENSE.txt +21 -0
  284. package/native/gxfx/third_party/signalsmith-linear/approx.h +191 -0
  285. package/native/gxfx/third_party/signalsmith-linear/fft.h +1386 -0
  286. package/native/gxfx/third_party/signalsmith-linear/linear.h +1129 -0
  287. package/native/gxfx/third_party/signalsmith-linear/platform/approx-cmsisdsp.h +40 -0
  288. package/native/gxfx/third_party/signalsmith-linear/platform/basic-fill-warnings.h +61 -0
  289. package/native/gxfx/third_party/signalsmith-linear/platform/fft-accelerate.h +340 -0
  290. package/native/gxfx/third_party/signalsmith-linear/platform/fft-cmsisdsp.h +307 -0
  291. package/native/gxfx/third_party/signalsmith-linear/platform/fft-ipp.h +532 -0
  292. package/native/gxfx/third_party/signalsmith-linear/platform/fft-linear.h +213 -0
  293. package/native/gxfx/third_party/signalsmith-linear/platform/fft-pffft-double.h +221 -0
  294. package/native/gxfx/third_party/signalsmith-linear/platform/fft-pffft.h +221 -0
  295. package/native/gxfx/third_party/signalsmith-linear/platform/linear-accelerate.h +593 -0
  296. package/native/gxfx/third_party/signalsmith-linear/platform/linear-cmsisdsp.h +713 -0
  297. package/native/gxfx/third_party/signalsmith-linear/platform/linear-xsimd-dispatch.cpp +6 -0
  298. package/native/gxfx/third_party/signalsmith-linear/platform/linear-xsimd.h +818 -0
  299. package/native/gxfx/third_party/signalsmith-linear/stft.h +700 -0
  300. package/native/gxfx/third_party/signalsmith-stretch-LICENSE.txt +21 -0
  301. package/native/gxfx/third_party/signalsmith-stretch.h +1060 -0
  302. package/native/gxns/CMakeLists.txt +67 -0
  303. package/native/gxns/include/gx_ns.h +285 -0
  304. package/native/gxns/src/gx_ns.c +1518 -0
  305. package/native/gxns/src/gx_ns_timer.c +84 -0
  306. package/native/gxns/src/gx_ns_timer.h +29 -0
  307. package/native/gxns/third_party/VENDOR.md +43 -0
  308. package/native/gxns/third_party/rnnoise/AUTHORS +1 -0
  309. package/native/gxns/third_party/rnnoise/COPYING +31 -0
  310. package/native/gxns/third_party/rnnoise/include/rnnoise.h +117 -0
  311. package/native/gxns/third_party/rnnoise/src/_kiss_fft_guts.h +182 -0
  312. package/native/gxns/third_party/rnnoise/src/arch.h +261 -0
  313. package/native/gxns/third_party/rnnoise/src/celt_lpc.c +172 -0
  314. package/native/gxns/third_party/rnnoise/src/celt_lpc.h +45 -0
  315. package/native/gxns/third_party/rnnoise/src/common.h +48 -0
  316. package/native/gxns/third_party/rnnoise/src/denoise.c +664 -0
  317. package/native/gxns/third_party/rnnoise/src/kiss_fft.c +601 -0
  318. package/native/gxns/third_party/rnnoise/src/kiss_fft.h +203 -0
  319. package/native/gxns/third_party/rnnoise/src/opus_types.h +159 -0
  320. package/native/gxns/third_party/rnnoise/src/pitch.c +523 -0
  321. package/native/gxns/third_party/rnnoise/src/pitch.h +149 -0
  322. package/native/gxns/third_party/rnnoise/src/rnn.c +178 -0
  323. package/native/gxns/third_party/rnnoise/src/rnn.h +65 -0
  324. package/native/gxns/third_party/rnnoise/src/rnn_data.c +11051 -0
  325. package/native/gxns/third_party/rnnoise/src/rnn_data.h +34 -0
  326. package/native/gxns/third_party/rnnoise/src/tansig_table.h +45 -0
  327. package/native/gxns/third_party/speexdsp/AUTHORS +18 -0
  328. package/native/gxns/third_party/speexdsp/COPYING +35 -0
  329. package/native/gxns/third_party/speexdsp/arch.h +232 -0
  330. package/native/gxns/third_party/speexdsp/resample.c +1239 -0
  331. package/native/gxns/third_party/speexdsp/resample_neon.h +339 -0
  332. package/native/gxns/third_party/speexdsp/resample_sse.h +128 -0
  333. package/native/gxns/third_party/speexdsp/speex_resampler.h +343 -0
  334. package/package.json +186 -4
  335. package/src/android/bindings.ts +61 -0
  336. package/src/android/index.ts +10 -0
  337. package/src/android/micMute.ts +422 -0
  338. package/src/android/nativeAudio.ts +94 -0
  339. package/src/android/noiseSuppression.ts +209 -0
  340. package/src/android/roomMusic.ts +193 -0
  341. package/src/android/singerMode.ts +53 -0
  342. package/src/android/voiceEffects.ts +126 -0
  343. package/src/audio/AudioManager.ts +111 -0
  344. package/src/audio/AudioSession.ts +190 -0
  345. package/src/audio/remoteVolume.ts +58 -0
  346. package/src/components/VideoView.tsx +152 -0
  347. package/src/features/audioScenario.ts +58 -0
  348. package/src/features/beauty.ts +1057 -0
  349. package/src/features/micRelease.ts +108 -0
  350. package/src/features/noiseSuppression.ts +251 -0
  351. package/src/features/roomMusic.ts +106 -0
  352. package/src/features/roomMusicAndroid.ts +310 -0
  353. package/src/features/roomMusicIos.ts +300 -0
  354. package/src/features/roomMusicTypes.ts +97 -0
  355. package/src/features/screenShare.ts +19 -0
  356. package/src/features/singerMode.ts +70 -0
  357. package/src/features/voiceEffects.ts +245 -0
  358. package/src/hooks/context.tsx +38 -0
  359. package/src/hooks/hooks.ts +247 -0
  360. package/src/hooks/types.ts +10 -0
  361. package/src/hooks/useRoomEvents.ts +35 -0
  362. package/src/index.tsx +134 -0
  363. package/src/ios/autoAttach.ts +11 -0
  364. package/src/ios/iosAudio.ts +202 -0
  365. package/src/join/appStateLifecycle.ts +55 -0
  366. package/src/micPolicy.ts +312 -0
  367. package/src/native/NativeGravixAudio.ts +30 -0
  368. package/src/native/NativeGravixRtc.ts +38 -0
  369. package/src/native/module.ts +22 -0
  370. package/src/polyfills/DOMException.ts +20 -0
  371. package/src/polyfills/early.ts +16 -0
  372. package/src/polyfills/event.ts +88 -0
  373. package/src/polyfills/sha256.ts +112 -0
  374. package/src/polyfills/subtleHmac.ts +124 -0
  375. package/src/polyfills/textCoding.ts +197 -0
  376. package/src/registerGlobals.ts +201 -0
  377. package/src/unsupported.ts +139 -0
  378. package/src/version.ts +4 -0
@@ -0,0 +1,332 @@
1
+ /* Copyright (c) 2024-2026 Gravity Compile. MIT License; see LICENSE. */
2
+ /*
3
+ * libgxns_dfn.so (arm64-v8a): DeepFilterNet3 streaming engine on a minimal
4
+ * ONNX Runtime (bundled libonnxruntime.so, ORT 1.31.0), exposed as a
5
+ * gx_ns_external_engine for libgxns (gx_ns_set_external_engine).
6
+ *
7
+ * Model contract (release manifest, reference_stream.py): 48 kHz mono, 480
8
+ * float samples in [-1, 1] -> 480 out per call; every input except
9
+ * input_frame / gx_dft_cos / gx_dft_sin is a state fed back from the output
10
+ * `new_<name>`. All tensors are bound to buffers allocated at load (two
11
+ * ping-pong sets for the states), so a frame only copies 480 samples in and
12
+ * out around OrtApi::Run (which may still allocate internally).
13
+ */
14
+ #include <jni.h>
15
+ #include <math.h>
16
+ #include <stdint.h>
17
+ #include <stdlib.h>
18
+ #include <string.h>
19
+ #include <time.h>
20
+ #include <android/log.h>
21
+ #include "gx_ns.h"
22
+ #include "onnxruntime_c_api.h"
23
+
24
+ #define TAG "GravixNS"
25
+ #define LOGW(...) __android_log_print(ANDROID_LOG_WARN, TAG, __VA_ARGS__)
26
+ #define MAXT 24
27
+ #define NFFT 960
28
+ #define NBIN 481
29
+
30
+ typedef struct {
31
+ gx_ns_external_engine ext; /* first: the pointer handed to gx_ns */
32
+ const OrtApi *api;
33
+ OrtEnv *env;
34
+ OrtSession *sess;
35
+ OrtMemoryInfo *mem;
36
+ size_t n_in, n_out;
37
+ char *in_names[MAXT], *out_names[MAXT];
38
+ float *in_buf[2][MAXT]; /* per parity: state inputs alias the other parity's outputs */
39
+ size_t in_len[MAXT];
40
+ int out_state_of[MAXT]; /* output j -> input index of its state, -1 = audio out */
41
+ int frame_in, cos_in, sin_in;
42
+ OrtValue *in_val[2][MAXT], *out_val[2][MAXT];
43
+ float *audio_out;
44
+ float *tables;
45
+ int parity;
46
+ int failed;
47
+ } gxdfn;
48
+
49
+ static void drop(const OrtApi *a, OrtStatus *s) {
50
+ if (s) a->ReleaseStatus(s);
51
+ }
52
+
53
+ static const OrtApi *ort(void) { return OrtGetApiBase()->GetApi(ORT_API_VERSION); }
54
+
55
+ static int ok(gxdfn *e, OrtStatus *s, const char *what) {
56
+ if (!s) return 1;
57
+ LOGW("[GravixNS] dfn3 %s: %s", what, e->api->GetErrorMessage(s));
58
+ e->api->ReleaseStatus(s);
59
+ return 0;
60
+ }
61
+
62
+ static void init_states(gxdfn *e, int parity) {
63
+ size_t i, k;
64
+ for (i = 0; i < e->n_in; i++) {
65
+ float *b = e->in_buf[parity][i];
66
+ if ((int)i == e->frame_in || (int)i == e->cos_in || (int)i == e->sin_in) continue;
67
+ memset(b, 0, sizeof(float) * e->in_len[i]);
68
+ if (!strcmp(e->in_names[i], "erb_norm_state"))
69
+ for (k = 0; k < e->in_len[i]; k++) b[k] = -60.f + (-30.f) * (float)k / (float)(e->in_len[i] - 1);
70
+ else if (!strcmp(e->in_names[i], "band_unit_norm_state"))
71
+ for (k = 0; k < e->in_len[i]; k++) b[k] = 0.001f + (0.0001f - 0.001f) * (float)k / (float)(e->in_len[i] - 1);
72
+ }
73
+ }
74
+
75
+ static int dfn_process(void *user, float *out, const float *in, int n) {
76
+ gxdfn *e = (gxdfn *)user;
77
+ OrtStatus *s;
78
+ int p = e->parity;
79
+ if (e->failed || n != GX_NS_BLOCK) return -1;
80
+ memcpy(e->in_buf[p][e->frame_in], in, sizeof(float) * GX_NS_BLOCK);
81
+ s = e->api->Run(e->sess, NULL, (const char *const *)e->in_names, (const OrtValue *const *)e->in_val[p], e->n_in,
82
+ (const char *const *)e->out_names, e->n_out, e->out_val[p]);
83
+ if (s) {
84
+ e->failed = 1;
85
+ ok(e, s, "run");
86
+ return -1;
87
+ }
88
+ memcpy(out, e->audio_out, sizeof(float) * GX_NS_BLOCK);
89
+ e->parity = p ^ 1;
90
+ return 0;
91
+ }
92
+
93
+ static void dfn_reset(void *user) {
94
+ gxdfn *e = (gxdfn *)user;
95
+ init_states(e, e->parity);
96
+ }
97
+
98
+ static void dfn_free(gxdfn *e) {
99
+ size_t i;
100
+ int p;
101
+ OrtAllocator *al = NULL;
102
+ if (!e) return;
103
+ if (e->api) {
104
+ drop(e->api, e->api->GetAllocatorWithDefaultOptions(&al));
105
+ for (p = 0; p < 2; p++)
106
+ for (i = 0; i < MAXT; i++) {
107
+ if (e->in_val[p][i]) e->api->ReleaseValue(e->in_val[p][i]);
108
+ if (e->out_val[p][i]) e->api->ReleaseValue(e->out_val[p][i]);
109
+ }
110
+ for (i = 0; i < MAXT; i++) {
111
+ if (al && e->in_names[i]) drop(e->api, e->api->AllocatorFree(al, e->in_names[i]));
112
+ if (al && e->out_names[i]) drop(e->api, e->api->AllocatorFree(al, e->out_names[i]));
113
+ }
114
+ if (e->sess) e->api->ReleaseSession(e->sess);
115
+ if (e->mem) e->api->ReleaseMemoryInfo(e->mem);
116
+ if (e->env) e->api->ReleaseEnv(e->env);
117
+ }
118
+ for (p = 0; p < 2; p++)
119
+ for (i = 0; i < MAXT; i++)
120
+ if (e->in_buf[p][i] && (int)i != e->cos_in && (int)i != e->sin_in) free(e->in_buf[p][i]);
121
+ free(e->audio_out);
122
+ free(e->tables);
123
+ free(e);
124
+ }
125
+
126
+ static int tensor_shape(gxdfn *e, OrtTypeInfo *ti, int64_t *dims, size_t *nd, size_t *len) {
127
+ const OrtTensorTypeAndShapeInfo *tsi;
128
+ size_t i;
129
+ if (!ok(e, e->api->CastTypeInfoToTensorInfo(ti, &tsi), "cast")) return 0;
130
+ if (!ok(e, e->api->GetDimensionsCount(tsi, nd), "ndims") || *nd > 8) return 0;
131
+ if (!ok(e, e->api->GetDimensions(tsi, dims, *nd), "dims")) return 0;
132
+ *len = 1;
133
+ for (i = 0; i < *nd; i++) {
134
+ if (dims[i] <= 0) dims[i] = 1;
135
+ *len *= (size_t)dims[i];
136
+ }
137
+ return 1;
138
+ }
139
+
140
+ /* Loads the model (bytes are copied by ORT) and binds every tensor.
141
+ * latency = the model's algorithmic delay at 48 kHz (std 1440, LL 480). */
142
+ static gxdfn *dfn_create(const void *model, size_t bytes, int latency) {
143
+ gxdfn *e = (gxdfn *)calloc(1, sizeof(gxdfn));
144
+ OrtSessionOptions *so = NULL;
145
+ OrtAllocator *al = NULL;
146
+ size_t i, j;
147
+ int p;
148
+ if (!e) return NULL;
149
+ e->api = ort();
150
+ if (!e->api) { free(e); return NULL; }
151
+ e->frame_in = e->cos_in = e->sin_in = -1;
152
+ if (!ok(e, e->api->CreateEnv(ORT_LOGGING_LEVEL_WARNING, "gxns", &e->env), "env")) goto fail;
153
+ if (!ok(e, e->api->CreateSessionOptions(&so), "options")) goto fail;
154
+ drop(e->api, e->api->SetIntraOpNumThreads(so, 1));
155
+ drop(e->api, e->api->SetInterOpNumThreads(so, 1));
156
+ drop(e->api, e->api->AddSessionConfigEntry(so, "session.load_model_format", "ORT"));
157
+ drop(e->api, e->api->AddSessionConfigEntry(so, "session.intra_op.allow_spinning", "0"));
158
+ if (!ok(e, e->api->CreateSessionFromArray(e->env, model, bytes, so, &e->sess), "load")) goto fail;
159
+ e->api->ReleaseSessionOptions(so);
160
+ so = NULL;
161
+ if (!ok(e, e->api->CreateCpuMemoryInfo(OrtArenaAllocator, OrtMemTypeDefault, &e->mem), "meminfo")) goto fail;
162
+ if (!ok(e, e->api->GetAllocatorWithDefaultOptions(&al), "allocator")) goto fail;
163
+ if (!ok(e, e->api->SessionGetInputCount(e->sess, &e->n_in), "inputs") ||
164
+ !ok(e, e->api->SessionGetOutputCount(e->sess, &e->n_out), "outputs") || e->n_in > MAXT || e->n_out > MAXT)
165
+ goto fail;
166
+
167
+ /* DFT tables, shared by both parities */
168
+ e->tables = (float *)malloc(sizeof(float) * NFFT * NBIN * 2);
169
+ if (!e->tables) goto fail;
170
+ for (i = 0; i < NFFT; i++)
171
+ for (j = 0; j < NBIN; j++) {
172
+ double a = (double)((i * j) % NFFT) * (2.0 * M_PI / NFFT);
173
+ e->tables[i * NBIN + j] = (float)cos(a);
174
+ e->tables[NFFT * NBIN + i * NBIN + j] = (float)sin(a);
175
+ }
176
+
177
+ for (i = 0; i < e->n_in; i++) {
178
+ OrtTypeInfo *ti = NULL;
179
+ int64_t dims[8];
180
+ size_t nd, len;
181
+ if (!ok(e, e->api->SessionGetInputName(e->sess, i, al, &e->in_names[i]), "in name")) goto fail;
182
+ if (!ok(e, e->api->SessionGetInputTypeInfo(e->sess, i, &ti), "in type")) goto fail;
183
+ if (!tensor_shape(e, ti, dims, &nd, &len)) { e->api->ReleaseTypeInfo(ti); goto fail; }
184
+ e->api->ReleaseTypeInfo(ti);
185
+ e->in_len[i] = len;
186
+ if (!strcmp(e->in_names[i], "input_frame")) e->frame_in = (int)i;
187
+ else if (!strcmp(e->in_names[i], "gx_dft_cos")) e->cos_in = (int)i;
188
+ else if (!strcmp(e->in_names[i], "gx_dft_sin")) e->sin_in = (int)i;
189
+ for (p = 0; p < 2; p++) {
190
+ if ((int)i == e->cos_in) e->in_buf[p][i] = e->tables;
191
+ else if ((int)i == e->sin_in) e->in_buf[p][i] = e->tables + NFFT * NBIN;
192
+ else if (!(e->in_buf[p][i] = (float *)calloc(len, sizeof(float)))) goto fail;
193
+ if (((int)i == e->cos_in || (int)i == e->sin_in) && len != NFFT * NBIN) goto fail;
194
+ if (!ok(e, e->api->CreateTensorWithDataAsOrtValue(e->mem, e->in_buf[p][i], len * sizeof(float), dims, nd,
195
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT, &e->in_val[p][i]),
196
+ "in value"))
197
+ goto fail;
198
+ }
199
+ }
200
+ if (e->frame_in < 0 || e->cos_in < 0 || e->sin_in < 0 || e->in_len[e->frame_in] != GX_NS_BLOCK) goto fail;
201
+
202
+ e->audio_out = (float *)calloc(GX_NS_BLOCK, sizeof(float));
203
+ if (!e->audio_out) goto fail;
204
+ for (j = 0; j < e->n_out; j++) {
205
+ OrtTypeInfo *ti = NULL;
206
+ int64_t dims[8];
207
+ size_t nd, len;
208
+ if (!ok(e, e->api->SessionGetOutputName(e->sess, j, al, &e->out_names[j]), "out name")) goto fail;
209
+ if (!ok(e, e->api->SessionGetOutputTypeInfo(e->sess, j, &ti), "out type")) goto fail;
210
+ if (!tensor_shape(e, ti, dims, &nd, &len)) { e->api->ReleaseTypeInfo(ti); goto fail; }
211
+ e->api->ReleaseTypeInfo(ti);
212
+ e->out_state_of[j] = -1;
213
+ if (!strncmp(e->out_names[j], "new_", 4)) {
214
+ for (i = 0; i < e->n_in; i++)
215
+ if (!strcmp(e->in_names[i], e->out_names[j] + 4)) e->out_state_of[j] = (int)i;
216
+ if (e->out_state_of[j] < 0 || e->in_len[e->out_state_of[j]] != len) goto fail;
217
+ } else if (len != GX_NS_BLOCK) {
218
+ goto fail;
219
+ }
220
+ for (p = 0; p < 2; p++) {
221
+ /* parity p reads states from in_buf[p] and writes them into in_buf[p^1] */
222
+ float *dst = e->out_state_of[j] >= 0 ? e->in_buf[p ^ 1][e->out_state_of[j]] : e->audio_out;
223
+ if (!ok(e, e->api->CreateTensorWithDataAsOrtValue(e->mem, dst, len * sizeof(float), dims, nd,
224
+ ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT, &e->out_val[p][j]),
225
+ "out value"))
226
+ goto fail;
227
+ }
228
+ }
229
+ init_states(e, 0);
230
+ e->ext.process = dfn_process;
231
+ e->ext.reset = dfn_reset;
232
+ e->ext.user = e;
233
+ e->ext.latency_samples = latency;
234
+ return e;
235
+ fail:
236
+ if (so) e->api->ReleaseSessionOptions(so);
237
+ dfn_free(e);
238
+ return NULL;
239
+ }
240
+
241
+ /* ---------------- JNI (com.gravitycompile.gravixrtc.processing.GxNsStudio) ---------------- */
242
+ #define JNI_FN(name) Java_com_gravitycompile_gravixrtc_processing_GxNsStudio_##name
243
+
244
+ /* model: direct ByteBuffer with the .ort bytes. Returns the gx_ns_external_engine* or 0. */
245
+ JNIEXPORT jlong JNICALL JNI_FN(nativeCreate)(JNIEnv *env, jclass cls, jobject model, jint latency) {
246
+ void *p = (*env)->GetDirectBufferAddress(env, model);
247
+ jlong n = (*env)->GetDirectBufferCapacity(env, model);
248
+ (void)cls;
249
+ if (!p || n <= 0) return 0;
250
+ return (jlong)(intptr_t)dfn_create(p, (size_t)n, latency);
251
+ }
252
+
253
+ /* Only once gx_ns no longer references it (detached + a block processed, or never attached). */
254
+ JNIEXPORT void JNICALL JNI_FN(nativeDestroy)(JNIEnv *env, jclass cls, jlong h) {
255
+ (void)env; (void)cls;
256
+ dfn_free((gxdfn *)(intptr_t)h);
257
+ }
258
+
259
+ static double now_us(void) {
260
+ struct timespec ts;
261
+ clock_gettime(CLOCK_MONOTONIC, &ts);
262
+ return ts.tv_sec * 1e6 + ts.tv_nsec / 1e3;
263
+ }
264
+
265
+ static int cmp_d(const void *a, const void *b) {
266
+ double x = *(const double *)a, y = *(const double *)b;
267
+ return x < y ? -1 : x > y;
268
+ }
269
+
270
+ /*
271
+ * First-run benchmark (plan §4) on its own engine instance, on the calling
272
+ * (background) thread: `warm` frames, then `frames` timed frames of the clip
273
+ * (int16 PCM, looped). out[0..5] = p50 us, p95 us, max us, in rms dBFS*100,
274
+ * out rms dBFS*100, parity SNR dB*100 vs `ref` (int16, the reference loop's
275
+ * output for the same clip; 0 len = not compared -> -99900).
276
+ */
277
+ JNIEXPORT jint JNICALL JNI_FN(nativeBenchmark)(JNIEnv *env, jclass cls, jlong h, jshortArray clip, jshortArray ref,
278
+ jint warm, jint frames, jintArray out) {
279
+ gxdfn *e = (gxdfn *)(intptr_t)h;
280
+ jint n = (*env)->GetArrayLength(env, clip), nref = ref ? (*env)->GetArrayLength(env, ref) : 0;
281
+ jshort *c, *r = NULL;
282
+ double *t;
283
+ float in[GX_NS_BLOCK], o[GX_NS_BLOCK];
284
+ double si = 0, so_ = 0, sn = 0, ss = 0;
285
+ long cnt = 0;
286
+ int f, k, total = warm + frames, rc = 0, nb = n / GX_NS_BLOCK;
287
+ jint v[6];
288
+ (void)cls;
289
+ if (!e || nb <= 0 || frames <= 0) return -1;
290
+ t = (double *)malloc(sizeof(double) * frames);
291
+ if (!t) return -1;
292
+ c = (*env)->GetShortArrayElements(env, clip, NULL);
293
+ if (nref) r = (*env)->GetShortArrayElements(env, ref, NULL);
294
+ init_states(e, e->parity);
295
+ for (f = 0; f < total; f++) {
296
+ int b = f % nb;
297
+ double t0;
298
+ for (k = 0; k < GX_NS_BLOCK; k++) in[k] = c[b * GX_NS_BLOCK + k] / 32768.f;
299
+ t0 = now_us();
300
+ if (dfn_process(e, o, in, GX_NS_BLOCK) != 0) { rc = -2; break; }
301
+ if (f >= warm) t[f - warm] = now_us() - t0;
302
+ for (k = 0; k < GX_NS_BLOCK; k++) {
303
+ if (!isfinite(o[k])) { rc = -3; break; }
304
+ si += (double)in[k] * in[k];
305
+ so_ += (double)o[k] * o[k];
306
+ cnt++;
307
+ }
308
+ /* parity: the first pass over the clip from a clean state matches the reference loop */
309
+ if (r && f < nb && (f + 1) * GX_NS_BLOCK <= nref)
310
+ for (k = 0; k < GX_NS_BLOCK; k++) {
311
+ double d = o[k] - r[f * GX_NS_BLOCK + k] / 32768.0;
312
+ sn += d * d;
313
+ ss += (double)(r[f * GX_NS_BLOCK + k] / 32768.0) * (r[f * GX_NS_BLOCK + k] / 32768.0);
314
+ }
315
+ if (rc) break;
316
+ }
317
+ (*env)->ReleaseShortArrayElements(env, clip, c, JNI_ABORT);
318
+ if (r) (*env)->ReleaseShortArrayElements(env, ref, r, JNI_ABORT);
319
+ init_states(e, e->parity);
320
+ if (rc == 0) {
321
+ qsort(t, frames, sizeof(double), cmp_d);
322
+ v[0] = (jint)t[frames / 2];
323
+ v[1] = (jint)t[(frames * 95) / 100];
324
+ v[2] = (jint)t[frames - 1];
325
+ v[3] = (jint)(100.0 * 10.0 * log10(si / (cnt ? cnt : 1) + 1e-20));
326
+ v[4] = (jint)(100.0 * 10.0 * log10(so_ / (cnt ? cnt : 1) + 1e-20));
327
+ v[5] = ss > 0 ? (jint)(100.0 * 10.0 * log10(ss / (sn + 1e-20))) : -99900;
328
+ (*env)->SetIntArrayRegion(env, out, 0, 6, v);
329
+ }
330
+ free(t);
331
+ return rc;
332
+ }
@@ -0,0 +1,34 @@
1
+ // Copyright (c) 2024-2026 Gravity Compile. MIT License; see LICENSE.
2
+ // JNI bridge for GxVoiceFx.kt.
3
+ #include <jni.h>
4
+ #include "gx_fx.h"
5
+ #define JNI_FN(n) Java_com_gravitycompile_gravixrtc_processing_GxVoiceFx_##n
6
+ #define FX(h) reinterpret_cast<gx_fx *>(h)
7
+ extern "C" {
8
+ JNIEXPORT jlong JNICALL JNI_FN(nativeCreate)(JNIEnv *, jclass) { return reinterpret_cast<jlong>(gx_fx_create()); }
9
+ JNIEXPORT jint JNICALL JNI_FN(nativeSetPreset)(JNIEnv *, jclass, jlong h, jint p) { return h ? gx_fx_set_preset(FX(h), p) : -1; }
10
+ JNIEXPORT void JNICALL JNI_FN(nativeRebuild)(JNIEnv *, jclass, jlong h) { if (h) gx_fx_rebuild(FX(h)); }
11
+ JNIEXPORT void JNICALL JNI_FN(nativeSetBypass)(JNIEnv *, jclass, jlong h, jboolean on) { if (h) gx_fx_set_bypass(FX(h), on); }
12
+ JNIEXPORT void JNICALL JNI_FN(nativeSetWatchdog)(JNIEnv *, jclass, jlong h, jint us, jint n) { if (h) gx_fx_set_watchdog(FX(h), us, n); }
13
+ JNIEXPORT jint JNICALL JNI_FN(nativeProcess)(JNIEnv *env, jclass, jlong h, jobject buf, jint n, jint rate) {
14
+ if (!h || n <= 0) return GX_FX_PASSTHROUGH;
15
+ auto *p = static_cast<float *>(env->GetDirectBufferAddress(buf));
16
+ if (!p || env->GetDirectBufferCapacity(buf) < static_cast<jlong>(n) * 4) return GX_FX_PASSTHROUGH;
17
+ return gx_fx_process_int16_scale(FX(h), p, n, rate);
18
+ }
19
+ // requested, active, rate, bypass, watchdog, latency_ms, frames, over, max_us
20
+ JNIEXPORT void JNICALL JNI_FN(nativeStatus)(JNIEnv *env, jclass, jlong h, jintArray out) {
21
+ gx_fx_status s = {};
22
+ if (h) gx_fx_get_status(FX(h), &s);
23
+ jint v[9] = {s.requested, s.active, s.rate, s.bypass, s.watchdog, s.latency_ms, (jint)s.frames, (jint)s.over, (jint)s.max_us};
24
+ env->SetIntArrayRegion(out, 0, 9, v);
25
+ }
26
+ // blocks, p50, p95, max, latency
27
+ JNIEXPORT jint JNICALL JNI_FN(nativeBenchmark)(JNIEnv *env, jclass, jint p, jint rate, jint sec, jintArray out) {
28
+ gx_fx_bench b = {};
29
+ int rc = gx_fx_benchmark(p, rate, sec, &b);
30
+ jint v[5] = {b.blocks, b.p50_us, b.p95_us, b.max_us, b.latency_ms};
31
+ env->SetIntArrayRegion(out, 0, 5, v);
32
+ return rc;
33
+ }
34
+ }
@@ -0,0 +1,162 @@
1
+ /* Copyright (c) 2024-2026 Gravity Compile. MIT License; see LICENSE. */
2
+ /*
3
+ * JNI bridge for GxNoiseProcessor.kt (com.gravitycompile.gravixrtc.processing.GxNsNative).
4
+ * process() runs on WebRTC's audio thread: no allocation, no locks, no logging.
5
+ */
6
+ #include <jni.h>
7
+ #include <stdint.h>
8
+ #include "gx_ns.h"
9
+
10
+ #define JNI_FN(name) Java_com_gravitycompile_gravixrtc_processing_GxNsNative_##name
11
+ #define ST(h) ((struct gx_ns *)(intptr_t)(h))
12
+
13
+ JNIEXPORT jlong JNICALL JNI_FN(nativeCreate)(JNIEnv *env, jclass cls, jint engine, jint agcEnabled,
14
+ jint agcOrder, jint watchdogUs, jint p95WindowBlocks) {
15
+ gx_ns_config c;
16
+ (void)env; (void)cls;
17
+ gx_ns_default_config(&c);
18
+ c.initial_engine = (gx_ns_engine)engine;
19
+ c.agc_enabled = agcEnabled ? 1 : 0;
20
+ c.agc_order = (gx_ns_agc_order)agcOrder;
21
+ if (watchdogUs > 0) c.watchdog_us = watchdogUs;
22
+ if (p95WindowBlocks > 0) c.ext_p95_window = p95WindowBlocks; /* studio rolling-p95 window (10 ms blocks) */
23
+ c.max_external_latency = 1440; /* DFN3 standard: 30 ms (LL: 10 ms) */
24
+ return (jlong)(intptr_t)gx_ns_create(&c);
25
+ }
26
+
27
+ JNIEXPORT void JNICALL JNI_FN(nativeDestroy)(JNIEnv *env, jclass cls, jlong h) {
28
+ (void)env; (void)cls;
29
+ if (h) gx_ns_destroy(ST(h));
30
+ }
31
+
32
+ /* In place on a direct ByteBuffer of `n` native-order floats (int16 scale).
33
+ * Returns 0 ok, -1 unsupported rate, -2 not a direct buffer / too small. */
34
+ JNIEXPORT jint JNICALL JNI_FN(nativeProcess)(JNIEnv *env, jclass cls, jlong h, jobject buf, jint n,
35
+ jint rate) {
36
+ float *p;
37
+ (void)cls;
38
+ if (!h || n <= 0) return -2;
39
+ p = (float *)(*env)->GetDirectBufferAddress(env, buf);
40
+ if (!p || (*env)->GetDirectBufferCapacity(env, buf) < (jlong)n * 4) return -2;
41
+ return gx_ns_process(ST(h), p, n, rate);
42
+ }
43
+
44
+ JNIEXPORT void JNICALL JNI_FN(nativeSetEngine)(JNIEnv *env, jclass cls, jlong h, jint e) {
45
+ (void)env; (void)cls;
46
+ if (h) gx_ns_set_engine(ST(h), (gx_ns_engine)e);
47
+ }
48
+
49
+ JNIEXPORT void JNICALL JNI_FN(nativeSetBypass)(JNIEnv *env, jclass cls, jlong h, jboolean b) {
50
+ (void)env; (void)cls;
51
+ if (h) gx_ns_set_bypass(ST(h), b ? 1 : 0);
52
+ }
53
+
54
+ JNIEXPORT void JNICALL JNI_FN(nativeSetAutoMusic)(JNIEnv *env, jclass cls, jlong h, jboolean on) {
55
+ (void)env; (void)cls;
56
+ if (h) gx_ns_set_auto_music(ST(h), on ? 1 : 0);
57
+ }
58
+
59
+ JNIEXPORT void JNICALL JNI_FN(nativeResetMusic)(JNIEnv *env, jclass cls, jlong h) {
60
+ (void)env; (void)cls;
61
+ if (h) gx_ns_reset_music(ST(h));
62
+ }
63
+
64
+ JNIEXPORT void JNICALL JNI_FN(nativeSetBypassMakeup)(JNIEnv *env, jclass cls, jlong h, jfloat db) {
65
+ (void)env; (void)cls;
66
+ if (h) gx_ns_set_bypass_makeup(ST(h), db);
67
+ }
68
+
69
+ JNIEXPORT void JNICALL JNI_FN(nativeSetSingerLevel)(JNIEnv *env, jclass cls, jlong h, jfloat target, jfloat max_db, jfloat rise) {
70
+ (void)env; (void)cls;
71
+ if (h) gx_ns_set_singer_level(ST(h), target, max_db, rise);
72
+ }
73
+
74
+ JNIEXPORT void JNICALL JNI_FN(nativeSetAgc)(JNIEnv *env, jclass cls, jlong h, jboolean on, jint order) {
75
+ (void)env; (void)cls;
76
+ if (!h) return;
77
+ gx_ns_set_agc_order(ST(h), (gx_ns_agc_order)order);
78
+ gx_ns_set_agc(ST(h), on ? 1 : 0);
79
+ }
80
+
81
+ JNIEXPORT void JNICALL JNI_FN(nativeRequestReset)(JNIEnv *env, jclass cls, jlong h) {
82
+ (void)env; (void)cls;
83
+ if (h) gx_ns_request_reset(ST(h));
84
+ }
85
+
86
+ /* Studio attenuation limit (centi-dB, 0 = none) and rolling-p95 budget (us, 0 = off). */
87
+ JNIEXPORT void JNICALL JNI_FN(nativeSetStudioLimits)(JNIEnv *env, jclass cls, jlong h, jint attenCentiDb, jint p95BudgetUs) {
88
+ (void)env; (void)cls;
89
+ if (!h) return;
90
+ gx_ns_set_atten_limit(ST(h), (float)attenCentiDb / 100.f);
91
+ gx_ns_set_ext_p95_budget(ST(h), p95BudgetUs);
92
+ }
93
+
94
+ JNIEXPORT void JNICALL JNI_FN(nativeResetStats)(JNIEnv *env, jclass cls, jlong h) {
95
+ (void)env; (void)cls;
96
+ if (h) gx_ns_reset_stats(ST(h));
97
+ }
98
+
99
+ /* out[0..12] = frames, p50, p95, p99, max, over, consecutive, underflows, extErrors, switches,
100
+ * studio rolling p95 us, studio slow (0/1), studio suppress (0/1); shorter arrays get a prefix (>= 10). */
101
+ JNIEXPORT void JNICALL JNI_FN(nativeStats)(JNIEnv *env, jclass cls, jlong h, jintArray out) {
102
+ gx_ns_stats s;
103
+ jint v[13];
104
+ jsize len;
105
+ (void)cls;
106
+ if (!h || (len = (*env)->GetArrayLength(env, out)) < 10) return;
107
+ gx_ns_get_stats(ST(h), &s);
108
+ v[0] = (jint)s.frames; v[1] = (jint)s.p50_us; v[2] = (jint)s.p95_us; v[3] = (jint)s.p99_us; v[4] = (jint)s.max_us;
109
+ v[5] = (jint)s.over_budget; v[6] = (jint)s.consecutive_over; v[7] = (jint)s.underflows; v[8] = (jint)s.ext_errors;
110
+ v[9] = (jint)s.engine_switches;
111
+ v[10] = (jint)s.ext_p95_us; v[11] = (jint)s.ext_slow; v[12] = (jint)s.ext_suppress;
112
+ (*env)->SetIntArrayRegion(env, out, 0, len >= 13 ? 13 : len >= 12 ? 12 : 10, v);
113
+ }
114
+
115
+ /* out[0..6] = requested, active, crossfading, reason, rate, latencySamples, agcGainDb*100
116
+ * (+ out[7] = preGainDb*100 when the array has 8; + out[8..10] = the APPLIED
117
+ * pre-gain*100, applied AGC*100, pause attenuation*100 when it has 11: the
118
+ * held values above are not what a pause gets; + out[11] = auto music detected
119
+ * when it has 12); returns vad*1000 */
120
+ JNIEXPORT jint JNICALL JNI_FN(nativeStatus)(JNIEnv *env, jclass cls, jlong h, jintArray out) {
121
+ gx_ns_status s;
122
+ jint v[19];
123
+ jsize len;
124
+ (void)cls;
125
+ if (!h || (len = (*env)->GetArrayLength(env, out)) < 7) return 0;
126
+ gx_ns_get_status(ST(h), &s);
127
+ v[0] = s.requested; v[1] = s.active; v[2] = s.crossfading; v[3] = s.reason; v[4] = s.rate; v[5] = s.latency_samples;
128
+ v[6] = (jint)(s.agc_gain_db * 100.f); v[7] = (jint)(s.pregain_db * 100.f);
129
+ v[8] = (jint)(s.pregain_applied_db * 100.f); v[9] = (jint)(s.agc_applied_db * 100.f); v[10] = (jint)(s.pause_att_db * 100.f);
130
+ v[11] = s.music_detected;
131
+ /* 0.11.4: levels (dBFS x100) and the bypass gains (dB x100) */
132
+ v[12] = (jint)(s.pre_rms_db * 100.f); v[13] = (jint)(s.pre_peak_db * 100.f);
133
+ v[14] = (jint)(s.post_rms_db * 100.f); v[15] = (jint)(s.post_peak_db * 100.f);
134
+ v[16] = (jint)(s.makeup_db * 100.f); v[17] = (jint)(s.singer_gain_db * 100.f); v[18] = (jint)(s.singer_level_db * 100.f);
135
+ (*env)->SetIntArrayRegion(env, out, 0, len >= 19 ? 19 : len >= 12 ? 12 : len >= 11 ? 11 : len >= 8 ? 8 : 7, v);
136
+ return (jint)(s.vad * 1000.f);
137
+ }
138
+
139
+ JNIEXPORT jstring JNICALL JNI_FN(nativeReasonName)(JNIEnv *env, jclass cls, jint r) {
140
+ (void)cls;
141
+ return (*env)->NewStringUTF(env, gx_ns_reason_name((gx_ns_reason)r));
142
+ }
143
+
144
+ /* Studio engine seam: `enginePtr` is a gx_ns_external_engine* owned by the
145
+ * engine's own library (e.g. an ORT DFN3 build), or 0 to detach. The struct is
146
+ * copied. Returns gx_ns_set_external_engine's result. */
147
+ JNIEXPORT jint JNICALL JNI_FN(nativeAttachExternal)(JNIEnv *env, jclass cls, jlong h, jlong enginePtr) {
148
+ (void)env; (void)cls;
149
+ if (!h) return -1;
150
+ return gx_ns_set_external_engine(ST(h), (const gx_ns_external_engine *)(intptr_t)enginePtr);
151
+ }
152
+
153
+ JNIEXPORT jint JNICALL JNI_FN(nativeBlocks)(JNIEnv *env, jclass cls, jlong h) {
154
+ (void)env; (void)cls;
155
+ return h ? (jint)gx_ns_blocks_processed(ST(h)) : 0;
156
+ }
157
+
158
+ /* Pre-gain the core settles on for speech at `db` dBFS (studio benchmark input). */
159
+ JNIEXPORT jfloat JNICALL JNI_FN(nativePregainForLevel)(JNIEnv *env, jclass cls, jfloat db) {
160
+ (void)env; (void)cls;
161
+ return gx_ns_pregain_for_level(db);
162
+ }
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Microsoft Corporation
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.