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,76 @@
1
+ // Copyright (c) 2026 Gravity Compile. MIT License; see LICENSE.
2
+
3
+ package com.gravitycompile.gravixrtc.processing
4
+
5
+ import android.util.Log
6
+ import org.webrtc.audio.JavaAudioDeviceModule.AudioRecordErrorCallback
7
+ import org.webrtc.audio.JavaAudioDeviceModule.AudioRecordStartErrorCode
8
+
9
+ /**
10
+ * Reports microphone failures (refused start, init failure, runtime error) to JS.
11
+ *
12
+ * Background: on webrtc-sdk 150 a refused start left a latch set and the next
13
+ * start aborted the process (SIGABRT at jvm.cc:81, 2026-11-02). The stock
14
+ * WebRtcAudioRecord of org.jitsi:webrtc 155.0.1 has no such latch (startRecording
15
+ * only asserts that no record thread runs, and a refused start leaves none), so
16
+ * the guard is now only the error callback, set on the builder by
17
+ * GravixAudioHooks (no reflection).
18
+ */
19
+ internal object GxRecordStartGuard {
20
+ private const val TAG = "GxRecordStartGuard"
21
+
22
+ /**
23
+ * Receives each recorder failure (`kind`, `code`, `message`) for JS. Called
24
+ * with WebRTC's recorder locks held: it must only hand the event off.
25
+ */
26
+ @Volatile
27
+ var eventSink: ((Map<String, Any?>) -> Unit)? = null
28
+
29
+ /** The builder's error callback; [previous] (an app's own) is chained. */
30
+ fun callback(previous: AudioRecordErrorCallback? = null): AudioRecordErrorCallback = Callback(previous)
31
+
32
+ /**
33
+ * Runs inside WebRTC's recorder start / init / record thread, on the
34
+ * native call's stack: it must not block, and nothing may escape it, because
35
+ * an exception here would reach native code and abort the process. The
36
+ * parameters are nullable so Kotlin's generated null checks cannot throw.
37
+ */
38
+ private class Callback(
39
+ private val previous: AudioRecordErrorCallback?,
40
+ ) : AudioRecordErrorCallback {
41
+ override fun onWebRtcAudioRecordStartError(code: AudioRecordStartErrorCode?, message: String?) {
42
+ Log.w(TAG, "microphone start refused ($code): $message; the next start retries")
43
+ report("start", code?.name, message)
44
+ chain { it.onWebRtcAudioRecordStartError(code, message) }
45
+ }
46
+
47
+ override fun onWebRtcAudioRecordInitError(message: String?) {
48
+ Log.w(TAG, "microphone init failed: $message")
49
+ report("init", null, message)
50
+ chain { it.onWebRtcAudioRecordInitError(message) }
51
+ }
52
+
53
+ override fun onWebRtcAudioRecordError(message: String?) {
54
+ Log.w(TAG, "microphone error: $message")
55
+ report("runtime", null, message)
56
+ chain { it.onWebRtcAudioRecordError(message) }
57
+ }
58
+
59
+ private fun report(kind: String, code: String?, message: String?) {
60
+ try {
61
+ eventSink?.invoke(mapOf("kind" to kind, "code" to code, "message" to message))
62
+ } catch (t: Throwable) {
63
+ Log.w(TAG, "microphone failure event not sent: $t")
64
+ }
65
+ }
66
+
67
+ private inline fun chain(call: (AudioRecordErrorCallback) -> Unit) {
68
+ val next = previous ?: return
69
+ try {
70
+ call(next)
71
+ } catch (t: Throwable) {
72
+ Log.w(TAG, "previous error callback failed: $t")
73
+ }
74
+ }
75
+ }
76
+ }
@@ -0,0 +1,434 @@
1
+ // Copyright (c) 2026 Gravity Compile. MIT License; see LICENSE.
2
+
3
+ package com.gravitycompile.gravixrtc.processing
4
+
5
+ import android.media.AudioFormat
6
+ import android.media.AudioRecord
7
+ import android.os.SystemClock
8
+ import android.util.Log
9
+ import com.gravitycompile.gravixrtc.music.MusicMixerEngine
10
+ import org.webrtc.audio.JavaAudioDeviceModule
11
+ import java.nio.ByteBuffer
12
+ import java.nio.ByteOrder
13
+
14
+ /**
15
+ * The capture seam of the Gravix audio features on react-native-webrtc 155's
16
+ * WebRTC build (org.jitsi:webrtc 155.0.1, a stock libwebrtc).
17
+ *
18
+ * That build has no capture buffer callback, no capture post-processing slot and
19
+ * no recorder release flag. Its `WebRtcAudioRecord$AudioRecordThread` reads the
20
+ * private field `WebRtcAudioRecord.audioRecord` on every loop and calls
21
+ * `audioRecord.read(byteBuffer, capacity)` before it hands the buffer to the
22
+ * native side (`nativeDataIsRecorded`). So the seam is the AudioRecord itself:
23
+ * at each recording start (the record-state callback, on the record thread,
24
+ * before its loop) the AudioRecord WebRTC opened is replaced by a
25
+ * [GxAudioRecord] with the same source, rate, channels, format, buffer and
26
+ * preferred device. Its read():
27
+ *
28
+ * 1. reads the microphone (or, while [released], delivers silence: the
29
+ * hardware recorder is stopped, the OS mic indicator goes off),
30
+ * 2. zeroes the voice under the engine mute (the stock module mute would zero
31
+ * the music too, after read),
32
+ * 3. hands the frame to [MusicMixerEngine.onBuffer] (room music mixed in; with
33
+ * bytesRead = 0 it paces the silent path to real time),
34
+ * 4. runs [GravixCaptureProcessing] (noise suppression -> voice effect ->
35
+ * post-effect music) on the 10 ms frame as int16-scale floats.
36
+ *
37
+ * Behaviour change versus the webrtc-sdk build (documented in
38
+ * docs/ANDROID_NATIVE_HOOKS.md): steps 3-4 now run BEFORE WebRTC's audio
39
+ * processing module (software AEC / NS / AGC) instead of after it.
40
+ *
41
+ * Every failure leaves WebRTC's own recorder in place (the features then report
42
+ * not attached); nothing here may throw into the record thread.
43
+ */
44
+ internal object GxRecorderSeam {
45
+ private const val TAG = "GxRecorderSeam"
46
+
47
+ @Volatile private var adm: JavaAudioDeviceModule? = null
48
+
49
+ /** The recorder the record thread reads now (null: not attached / not recording). */
50
+ @Volatile
51
+ var current: GxAudioRecord? = null
52
+ private set
53
+
54
+ /** Attached at least once in this process (diagnostics / capabilities). */
55
+ @Volatile
56
+ var everAttached = false
57
+ private set
58
+
59
+ /** Music release (MusicMicRelease): the hardware recorder is stopped, silence is clocked. */
60
+ @Volatile
61
+ var released = false
62
+
63
+ /** Mute releases the mic: the hardware recorder is stopped while the mic is muted. */
64
+ @Volatile
65
+ var closedByMute = false
66
+
67
+ /** The engine mute (user mute + other-app auto mute), applied to the voice before the mix. */
68
+ @Volatile
69
+ var engineMuted = false
70
+ private set
71
+
72
+ /** The last reopen after a release failed (no microphone). */
73
+ @Volatile
74
+ var reopenFailed = false
75
+ private set
76
+
77
+ /** The capture source a switch asks for (null: WebRTC's own). Applied by the record thread. */
78
+ @Volatile private var wantSource: Int? = null
79
+ @Volatile private var originalSource: Int? = null
80
+
81
+ private var failureLogged = false
82
+
83
+ /** Guards the module mute against the record-state callbacks (attach / detach). */
84
+ private val muteLock = Any()
85
+
86
+ // reopen retry (record thread only): one try per REOPEN_RETRY_MS, one error log per episode
87
+ private const val REOPEN_RETRY_MS = 500L
88
+ private var lastReopenTryMs = 0L
89
+
90
+ // processing buffers (record thread only)
91
+ private var floatBuf: ByteBuffer? = null
92
+ private var procRate = 0
93
+ private var procChannels = 0
94
+
95
+ fun install(module: JavaAudioDeviceModule) {
96
+ adm = module
97
+ }
98
+
99
+ fun reset() {
100
+ synchronized(muteLock) {
101
+ // a reload drops a voice-only mute with the module that owned it
102
+ if (engineMuted) try { adm?.setMicrophoneMute(false) } catch (_: Throwable) {}
103
+ engineMuted = false
104
+ released = false
105
+ closedByMute = false
106
+ reopenFailed = false
107
+ wantSource = null
108
+ current = null
109
+ adm = null
110
+ }
111
+ }
112
+
113
+ /** WebRTC's recorder (package-private class, private field of the module). */
114
+ fun webRtcAudioRecord(): Any? = try {
115
+ val m = adm ?: return null
116
+ JavaAudioDeviceModule::class.java.getDeclaredField("audioInput").apply { isAccessible = true }.get(m)
117
+ } catch (_: Throwable) {
118
+ null
119
+ }
120
+
121
+ private fun field(input: Any, name: String) =
122
+ input.javaClass.getDeclaredField(name).apply { isAccessible = true }
123
+
124
+ /** The record thread runs (WebRTC started recording and has not stopped). */
125
+ fun threadAlive(): Boolean = try {
126
+ webRtcAudioRecord()?.let { (field(it, "audioThread").get(it) as? Thread)?.isAlive == true } ?: false
127
+ } catch (_: Throwable) {
128
+ false
129
+ }
130
+
131
+ /** The hardware recorder is capturing right now. */
132
+ fun recorderOpen(): Boolean {
133
+ val r = current ?: return try {
134
+ val input = webRtcAudioRecord() ?: return false
135
+ (field(input, "audioRecord").get(input) as? AudioRecord)?.recordingState == AudioRecord.RECORDSTATE_RECORDING
136
+ } catch (_: Throwable) {
137
+ false
138
+ }
139
+ return r.recordingState == AudioRecord.RECORDSTATE_RECORDING
140
+ }
141
+
142
+ /** Effective release: music release or mute release. */
143
+ private fun wantsClosed() = released || closedByMute
144
+
145
+ /**
146
+ * The engine mute. With the seam attached the voice is zeroed in read() (the music
147
+ * stays); without it the module mute is used, as before.
148
+ */
149
+ fun applyEngineMute(muted: Boolean) {
150
+ synchronized(muteLock) {
151
+ engineMuted = muted
152
+ val m = adm ?: return
153
+ try {
154
+ m.setMicrophoneMute(if (current != null) false else muted)
155
+ } catch (t: Throwable) {
156
+ Log.w(TAG, "module mute failed: $t")
157
+ }
158
+ }
159
+ }
160
+
161
+ /** Capture source switch (singer mode, other-app VOICE_COMMUNICATION); null = WebRTC's own. */
162
+ fun requestSource(source: Int?): Int? {
163
+ wantSource = source
164
+ return originalSource
165
+ }
166
+
167
+ fun originalSource(): Int? = originalSource ?: try {
168
+ webRtcAudioRecord()?.let { field(it, "audioSource").getInt(it) }
169
+ } catch (_: Throwable) {
170
+ null
171
+ }
172
+
173
+ /** A requested source the record thread has not switched to yet. */
174
+ fun switchPending(): Boolean {
175
+ val r = current ?: return false
176
+ val want = wantSource ?: originalSource ?: return false
177
+ return want != r.source
178
+ }
179
+
180
+ fun currentSource(): Int? = current?.source ?: originalSource()
181
+
182
+ // ============================== record thread ==============================
183
+
184
+ /** Record-state callback "start": WebRTC's AudioRecord is RECORDING, its loop has not run yet. */
185
+ fun onRecordStart() {
186
+ try {
187
+ val input = webRtcAudioRecord() ?: return
188
+ val f = field(input, "audioRecord")
189
+ val orig = f.get(input) as? AudioRecord ?: return
190
+ if (orig is GxAudioRecord) {
191
+ current = orig
192
+ return
193
+ }
194
+ val src = field(input, "audioSource").getInt(input)
195
+ originalSource = src
196
+ reopenFailed = false
197
+ lastReopenTryMs = 0L
198
+ val rec = build(wantSource ?: src, orig) ?: build(src, orig) ?: return
199
+ orig.stop()
200
+ if (!wantsClosed()) {
201
+ rec.startRecording()
202
+ if (rec.recordingState != AudioRecord.RECORDSTATE_RECORDING) {
203
+ Log.w(TAG, "replacement recorder refused to start: WebRTC's own recorder stays")
204
+ rec.release()
205
+ orig.startRecording()
206
+ return
207
+ }
208
+ }
209
+ f.set(input, rec)
210
+ // WebRTC's platform AEC / NS object follows the recorder (same enable flags as stock,
211
+ // and adm.setNoiseSuppressorEnabled keeps reaching the live session)
212
+ repointEffects(input, rec.audioSessionId)
213
+ orig.release()
214
+ synchronized(muteLock) {
215
+ current = rec
216
+ everAttached = true
217
+ // the voice mute moves from the module (zeroes after read, music too) into read()
218
+ if (engineMuted) adm?.setMicrophoneMute(false)
219
+ }
220
+ Log.i(TAG, "attached: source=${rec.source} rate=${rec.sampleRate} ch=${rec.channelCount} session=${rec.audioSessionId} closed=${wantsClosed()}")
221
+ } catch (t: Throwable) {
222
+ Log.w(TAG, "not attached (WebRTC's recorder stays): $t")
223
+ }
224
+ }
225
+
226
+ /** Record-state callback "stop": the record thread ended. */
227
+ fun onRecordStop() {
228
+ synchronized(muteLock) {
229
+ current = null
230
+ if (engineMuted) try { adm?.setMicrophoneMute(true) } catch (_: Throwable) {}
231
+ }
232
+ reopenFailed = false
233
+ }
234
+
235
+ /**
236
+ * Moves WebRTC's own `WebRtcAudioEffects` (the platform AEC / NS it created with the
237
+ * builder's enable flags) to [session]: stock `enable()` creates both effects and sets each
238
+ * one on or OFF as WebRTC wants, so the swapped recorder gets exactly stock's effect state.
239
+ */
240
+ private fun repointEffects(input: Any, session: Int) {
241
+ try {
242
+ val fx = field(input, "effects").get(input) ?: return
243
+ val c = fx.javaClass
244
+ c.getDeclaredMethod("release").apply { isAccessible = true }.invoke(fx)
245
+ c.getDeclaredMethod("enable", Int::class.javaPrimitiveType).apply { isAccessible = true }.invoke(fx, session)
246
+ } catch (t: Throwable) {
247
+ Log.w(TAG, "platform AEC / NS not moved to session $session: $t")
248
+ }
249
+ }
250
+
251
+ /** A recorder like [orig] (same rate, channel mask, format, buffer, device) on [source]. */
252
+ private fun build(source: Int, orig: AudioRecord): GxAudioRecord? = try {
253
+ val bytesPerFrame = orig.channelCount * when (orig.audioFormat) {
254
+ AudioFormat.ENCODING_PCM_8BIT -> 1
255
+ AudioFormat.ENCODING_PCM_FLOAT -> 4
256
+ else -> 2
257
+ }
258
+ val bufBytes = (orig.bufferSizeInFrames * bytesPerFrame).coerceAtLeast(
259
+ AudioRecord.getMinBufferSize(orig.sampleRate, orig.channelConfiguration, orig.audioFormat)
260
+ )
261
+ val rec = GxAudioRecord(source, orig.sampleRate, orig.channelConfiguration, orig.audioFormat, bufBytes)
262
+ if (rec.state != AudioRecord.STATE_INITIALIZED) {
263
+ rec.release()
264
+ Log.w(TAG, "recorder on source $source not initialised")
265
+ null
266
+ } else {
267
+ try { orig.preferredDevice?.let { rec.setPreferredDevice(it) } } catch (_: Throwable) {}
268
+ rec
269
+ }
270
+ } catch (t: Throwable) {
271
+ Log.w(TAG, "recorder on source $source failed: $t")
272
+ null
273
+ }
274
+
275
+ /** GxAudioRecord.read: see the class comment for the steps. Never throws. */
276
+ fun read(rec: GxAudioRecord, buf: ByteBuffer, size: Int, mode: Int?): Int {
277
+ var r = rec
278
+ try {
279
+ r = switchIfWanted(rec)
280
+ } catch (t: Throwable) {
281
+ logOnce("source switch failed", t)
282
+ }
283
+ var bytesRead: Int
284
+ if (wantsClosed()) {
285
+ try {
286
+ if (r.recordingState == AudioRecord.RECORDSTATE_RECORDING) r.stop()
287
+ } catch (t: Throwable) {
288
+ logOnce("recorder stop failed", t)
289
+ }
290
+ zero(buf, size)
291
+ bytesRead = 0
292
+ } else {
293
+ var open = try { r.recordingState == AudioRecord.RECORDSTATE_RECORDING } catch (_: Throwable) { false }
294
+ if (!open) {
295
+ val now = SystemClock.elapsedRealtime()
296
+ if (!reopenFailed || now - lastReopenTryMs >= REOPEN_RETRY_MS) {
297
+ lastReopenTryMs = now
298
+ open = try {
299
+ r.startRecording()
300
+ r.recordingState == AudioRecord.RECORDSTATE_RECORDING
301
+ } catch (_: Throwable) {
302
+ false
303
+ }
304
+ if (!open && !reopenFailed) Log.e(TAG, "recorder reopen FAILED (no microphone): silence is delivered, retrying every $REOPEN_RETRY_MS ms")
305
+ if (open && reopenFailed) Log.i(TAG, "recorder reopened after a failure")
306
+ reopenFailed = !open
307
+ }
308
+ }
309
+ if (!open) {
310
+ zero(buf, size)
311
+ bytesRead = 0
312
+ } else {
313
+ bytesRead = if (mode == null) r.rawRead(buf, size) else r.rawRead(buf, size, mode)
314
+ if (bytesRead < 0) return bytesRead
315
+ if (bytesRead != size) return bytesRead // WebRTC drops short reads
316
+ if (engineMuted) zero(buf, size)
317
+ }
318
+ }
319
+ val channels = r.channelCount
320
+ val rate = r.sampleRate
321
+ // music (and, with bytesRead = 0, the real-time clock of the silent path)
322
+ MusicMixerEngine.onBuffer(buf, r.audioFormat, channels, rate, bytesRead, System.nanoTime())
323
+ try {
324
+ if (r.audioFormat == AudioFormat.ENCODING_PCM_16BIT) process(buf, size, rate, channels)
325
+ } catch (t: Throwable) {
326
+ logOnce("capture processing failed", t)
327
+ }
328
+ return size
329
+ }
330
+
331
+ private fun switchIfWanted(rec: GxAudioRecord): GxAudioRecord {
332
+ val want = wantSource ?: originalSource ?: return rec
333
+ if (want == rec.source) return rec
334
+ val input = webRtcAudioRecord() ?: return rec
335
+ val t0 = SystemClock.elapsedRealtime()
336
+ val next = build(want, rec)
337
+ if (next == null) {
338
+ // refused: stay on the current source, and do not retry every frame (unless a newer
339
+ // request came in meanwhile)
340
+ if (wantSource == want) wantSource = rec.source.takeIf { it != originalSource }
341
+ return rec
342
+ }
343
+ rec.stop()
344
+ if (!wantsClosed()) {
345
+ next.startRecording()
346
+ if (next.recordingState != AudioRecord.RECORDSTATE_RECORDING) {
347
+ Log.w(TAG, "capture source $want refused to start: back to ${rec.source}")
348
+ next.release()
349
+ rec.startRecording()
350
+ if (wantSource == want) wantSource = rec.source.takeIf { it != originalSource }
351
+ return rec
352
+ }
353
+ }
354
+ field(input, "audioRecord").set(input, next)
355
+ repointEffects(input, next.audioSessionId)
356
+ current = next
357
+ rec.release()
358
+ Log.i(TAG, "capture source -> $want in ${SystemClock.elapsedRealtime() - t0} ms (session=${next.audioSessionId})")
359
+ return next
360
+ }
361
+
362
+ /** int16 -> int16-scale float (the APM post-processing format) -> chain -> int16. */
363
+ private fun process(buf: ByteBuffer, size: Int, rate: Int, channels: Int) {
364
+ if (!GravixCaptureProcessing.hasProcessors() || channels != 1) return
365
+ val frames = size / 2
366
+ if (rate != procRate || channels != procChannels) {
367
+ procRate = rate
368
+ procChannels = channels
369
+ GravixCaptureProcessing.initialize(rate, channels)
370
+ }
371
+ var fb = floatBuf
372
+ if (fb == null || fb.capacity() != frames * 4) {
373
+ fb = ByteBuffer.allocateDirect(frames * 4).order(ByteOrder.nativeOrder())
374
+ floatBuf = fb
375
+ }
376
+ val pcm = buf.duplicate().order(ByteOrder.LITTLE_ENDIAN)
377
+ for (i in 0 until frames) fb.putFloat(i * 4, pcm.getShort(i * 2).toFloat())
378
+ GravixCaptureProcessing.process(1, frames, fb)
379
+ for (i in 0 until frames) {
380
+ val v = fb.getFloat(i * 4)
381
+ val s = if (v >= 32767f) 32767 else if (v <= -32768f) -32768 else v.toInt()
382
+ pcm.putShort(i * 2, s.toShort())
383
+ }
384
+ }
385
+
386
+ private fun zero(buf: ByteBuffer, size: Int) {
387
+ val n = minOf(size, buf.capacity())
388
+ var i = 0
389
+ while (i + 8 <= n) { buf.putLong(i, 0L); i += 8 }
390
+ while (i < n) { buf.put(i, 0); i++ }
391
+ }
392
+
393
+ private fun logOnce(what: String, t: Throwable) {
394
+ if (failureLogged) return
395
+ failureLogged = true
396
+ Log.e(TAG, "$what; the capture goes on", t)
397
+ }
398
+
399
+ fun state(): Map<String, Any?> = mapOf(
400
+ "attached" to (current != null),
401
+ "everAttached" to everAttached,
402
+ "released" to released,
403
+ "closedByMute" to closedByMute,
404
+ "engineMuted" to engineMuted,
405
+ "reopenFailed" to reopenFailed,
406
+ "source" to current?.source,
407
+ "originalSource" to originalSource,
408
+ )
409
+ }
410
+
411
+ /**
412
+ * The AudioRecord WebRTC's record thread reads after [GxRecorderSeam.onRecordStart]
413
+ * swapped it in. A real recorder (same parameters as WebRTC's own); read() goes
414
+ * through the seam.
415
+ */
416
+ internal class GxAudioRecord(
417
+ val source: Int,
418
+ sampleRate: Int,
419
+ channelConfig: Int,
420
+ audioFormat: Int,
421
+ bufferBytes: Int,
422
+ ) : AudioRecord(source, sampleRate, channelConfig, audioFormat, bufferBytes) {
423
+ override fun read(audioBuffer: ByteBuffer, sizeInBytes: Int): Int =
424
+ GxRecorderSeam.read(this, audioBuffer, sizeInBytes, null)
425
+
426
+ override fun read(audioBuffer: ByteBuffer, sizeInBytes: Int, readMode: Int): Int =
427
+ GxRecorderSeam.read(this, audioBuffer, sizeInBytes, readMode)
428
+
429
+ // AudioRecord.read(ByteBuffer, int) delegates to the overridable 3-argument read: going
430
+ // through it here would re-enter the seam. The 3-argument super call reads the device.
431
+ fun rawRead(b: ByteBuffer, n: Int): Int = super.read(b, n, READ_BLOCKING)
432
+
433
+ fun rawRead(b: ByteBuffer, n: Int, mode: Int): Int = super.read(b, n, mode)
434
+ }
@@ -0,0 +1,37 @@
1
+ // Copyright (c) 2026 Gravity Compile. MIT License; see LICENSE.
2
+
3
+ package com.gravitycompile.gravixrtc.processing
4
+
5
+ /**
6
+ * The capture source singer mode records from (GravixSingerCaptureSource in
7
+ * Dart). WebRTC builds its recorder with VOICE_COMMUNICATION, the call path:
8
+ * on most phones the HAL runs its own echo canceller, noise suppressor and
9
+ * AGC there whatever the app asks (they pull held and high notes down).
10
+ * [GxCaptureSwitcher] re-opens the recorder with the source below; the audio
11
+ * device module is not rebuilt.
12
+ *
13
+ * - "mic": MIC (1), the default: what Agora's GAME_STREAMING / wired-headset
14
+ * chat room and ZEGO's KTV mode record from.
15
+ * - "voiceRecognition": VOICE_RECOGNITION (6); the CDD requires noise
16
+ * reduction and AGC off on it.
17
+ * - "unprocessed": UNPROCESSED (9) where the phone says it supports it
18
+ * (AudioManager.PROPERTY_SUPPORT_AUDIO_SOURCE_UNPROCESSED, API 24+), else
19
+ * VOICE_RECOGNITION. Flat and raw; quiet on some built-in mics.
20
+ * - "keep" / anything else: no change (null).
21
+ *
22
+ * The constants are MediaRecorder.AudioSource's, as plain ints so the JVM
23
+ * unit tests need no Android framework.
24
+ */
25
+ internal object GxSingerSource {
26
+ const val MIC = 1
27
+ const val VOICE_RECOGNITION = 6
28
+ const val VOICE_COMMUNICATION = 7
29
+ const val UNPROCESSED = 9
30
+
31
+ fun resolve(name: String?, sdkInt: Int, unprocessedSupported: Boolean): Int? = when (name) {
32
+ "mic" -> MIC
33
+ "voiceRecognition" -> VOICE_RECOGNITION
34
+ "unprocessed" -> if (sdkInt >= 24 && unprocessedSupported) UNPROCESSED else VOICE_RECOGNITION
35
+ else -> null
36
+ }
37
+ }