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.
- package/CHANGELOG.md +134 -0
- package/LICENSE +20 -0
- package/LICENSES/Apache-2.0.txt +175 -0
- package/NOTICE +68 -0
- package/README.md +313 -2
- package/android/build.gradle +137 -0
- package/android/consumer-rules.pro +29 -0
- package/android/src/main/AndroidManifest.xml +9 -0
- package/android/src/main/cpp/CMakeLists.txt +48 -0
- package/android/src/main/cpp/gx_dfn_engine.c +332 -0
- package/android/src/main/cpp/gx_fx_jni.cpp +34 -0
- package/android/src/main/cpp/gx_ns_jni.c +162 -0
- package/android/src/main/cpp/third_party/onnxruntime/LICENSE +21 -0
- package/android/src/main/cpp/third_party/onnxruntime/include/onnxruntime_c_api.h +9227 -0
- package/android/src/main/cpp/third_party/onnxruntime/include/onnxruntime_ep_c_api.h +3315 -0
- package/android/src/main/cpp/third_party/onnxruntime/include/onnxruntime_error_code.h +98 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/GravixAudioHooks.kt +144 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/GravixAudioModule.kt +105 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/GravixNativeAudio.kt +310 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/GravixRtc.kt +134 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/GravixRtcModule.kt +176 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/GravixRtcPackage.kt +39 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/audio/AudioDeviceKind.java +44 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/audio/AudioManagerUtils.kt +120 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/audio/AudioSwitchManager.java +270 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/audio/AudioType.kt +50 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicCaptureRouter.kt +375 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicDecoder.kt +339 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicInterruptionWatcher.kt +82 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicMicRelease.kt +117 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicMixKernel.kt +191 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicMixerEngine.kt +617 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/processing/AudioRoutePolicy.kt +137 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GravixCaptureProcessing.kt +67 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxCaptureDump.kt +143 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxCaptureSwitcher.kt +196 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxNoiseProcessor.kt +795 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxNsLogic.kt +180 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxNsNative.kt +83 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxNsStudio.kt +372 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxRecordStartGuard.kt +76 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxRecorderSeam.kt +434 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxSingerSource.kt +37 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxVoiceFx.kt +160 -0
- package/android/src/main/java/com/gravitycompile/gravixrtc/processing/OtherAppAudioPolicy.kt +143 -0
- package/android/src/main/java/org/webrtc/audio/WebRtcAudioTrackHelper.kt +43 -0
- package/docs/ANDROID_NATIVE_HOOKS.md +102 -0
- package/docs/FEATURE_MATRIX.md +192 -0
- package/docs/IOS_NATIVE_HOOKS.md +190 -0
- package/gravix-rtc-react-native.podspec +49 -0
- package/ios/GravixRtc.h +7 -0
- package/ios/GravixRtc.mm +273 -0
- package/ios/GravixRtcSetup.h +29 -0
- package/ios/GravixRtcSetup.m +52 -0
- package/ios/audio/GravixRtcIosAudio.m +157 -0
- package/ios/audio/GxAudioDevice.h +62 -0
- package/ios/audio/GxAudioDevice.m +857 -0
- package/ios/audio/GxAudioSetup.h +34 -0
- package/ios/audio/GxAudioSetup.m +70 -0
- package/ios/audio/GxCompat.swift +53 -0
- package/ios/audio/GxIosAudio.swift +99 -0
- package/ios/audio/GxMusicController.swift +150 -0
- package/ios/audio/GxMusicPost.swift +362 -0
- package/ios/audio/GxNoiseProcessor.swift +718 -0
- package/ios/audio/GxNsDfn3CoreML.swift +195 -0
- package/ios/audio/GxNsStudioEngine.swift +237 -0
- package/ios/audio/GxNsStudioPack.swift +212 -0
- package/ios/audio/GxVoiceFx.swift +161 -0
- package/ios/audio/gx_adm_state.h +153 -0
- package/ios/gxcore/apple/gx_music_post.c +312 -0
- package/ios/gxcore/apple/gx_pcm.c +30 -0
- package/ios/gxcore/apple/gxns_build.h +19 -0
- package/ios/gxcore/apple/gxns_ios.c +17 -0
- package/ios/gxcore/apple/include/gx_fx.h +3 -0
- package/ios/gxcore/apple/include/gx_music_post.h +88 -0
- package/ios/gxcore/apple/include/gx_ns.h +3 -0
- package/ios/gxcore/apple/include/gx_pcm.h +33 -0
- package/ios/gxcore/apple/include/gxns_ios.h +18 -0
- package/ios/gxcore/apple/include/module.modulemap +10 -0
- package/ios/gxcore/apple/shim/rnnoise.h +2 -0
- package/ios/gxcore/apple/shim/speex_resampler.h +2 -0
- package/ios/gxcore/apple/units/gx_fx_forward.cpp +3 -0
- package/ios/gxcore/apple/units/gx_ns.c +7 -0
- package/ios/gxcore/apple/units/gx_ns_timer.c +7 -0
- package/ios/gxcore/apple/units/rnnoise_celt_lpc.c +7 -0
- package/ios/gxcore/apple/units/rnnoise_denoise.c +7 -0
- package/ios/gxcore/apple/units/rnnoise_kiss_fft.c +7 -0
- package/ios/gxcore/apple/units/rnnoise_pitch.c +7 -0
- package/ios/gxcore/apple/units/rnnoise_rnn.c +7 -0
- package/ios/gxcore/apple/units/rnnoise_rnn_data.c +7 -0
- package/ios/gxcore/apple/units/speexdsp_resample.c +7 -0
- package/ios/resources/ns/DFN3-NOTICE.txt +10 -0
- package/ios/resources/ns/DeepFilterNet-LICENSE-APACHE +201 -0
- package/ios/resources/ns/DeepFilterNet-LICENSE-MIT +19 -0
- package/ios/resources/ns/gxns_dfn3.mlmodelc/analytics/coremldata.bin +0 -0
- package/ios/resources/ns/gxns_dfn3.mlmodelc/coremldata.bin +0 -0
- package/ios/resources/ns/gxns_dfn3.mlmodelc/metadata.json +338 -0
- package/ios/resources/ns/gxns_dfn3.mlmodelc/model.mil +927 -0
- package/ios/resources/ns/gxns_dfn3.mlmodelc/weights/weight.bin +0 -0
- package/lib/module/android/bindings.js +49 -0
- package/lib/module/android/bindings.js.map +1 -0
- package/lib/module/android/index.js +13 -0
- package/lib/module/android/index.js.map +1 -0
- package/lib/module/android/micMute.js +341 -0
- package/lib/module/android/micMute.js.map +1 -0
- package/lib/module/android/nativeAudio.js +47 -0
- package/lib/module/android/nativeAudio.js.map +1 -0
- package/lib/module/android/noiseSuppression.js +170 -0
- package/lib/module/android/noiseSuppression.js.map +1 -0
- package/lib/module/android/roomMusic.js +142 -0
- package/lib/module/android/roomMusic.js.map +1 -0
- package/lib/module/android/singerMode.js +31 -0
- package/lib/module/android/singerMode.js.map +1 -0
- package/lib/module/android/voiceEffects.js +65 -0
- package/lib/module/android/voiceEffects.js.map +1 -0
- package/lib/module/audio/AudioManager.js +79 -0
- package/lib/module/audio/AudioManager.js.map +1 -0
- package/lib/module/audio/AudioSession.js +90 -0
- package/lib/module/audio/AudioSession.js.map +1 -0
- package/lib/module/audio/remoteVolume.js +54 -0
- package/lib/module/audio/remoteVolume.js.map +1 -0
- package/lib/module/components/VideoView.js +109 -0
- package/lib/module/components/VideoView.js.map +1 -0
- package/lib/module/features/audioScenario.js +53 -0
- package/lib/module/features/audioScenario.js.map +1 -0
- package/lib/module/features/beauty.js +828 -0
- package/lib/module/features/beauty.js.map +1 -0
- package/lib/module/features/micRelease.js +89 -0
- package/lib/module/features/micRelease.js.map +1 -0
- package/lib/module/features/noiseSuppression.js +213 -0
- package/lib/module/features/noiseSuppression.js.map +1 -0
- package/lib/module/features/roomMusic.js +90 -0
- package/lib/module/features/roomMusic.js.map +1 -0
- package/lib/module/features/roomMusicAndroid.js +294 -0
- package/lib/module/features/roomMusicAndroid.js.map +1 -0
- package/lib/module/features/roomMusicIos.js +250 -0
- package/lib/module/features/roomMusicIos.js.map +1 -0
- package/lib/module/features/roomMusicTypes.js +53 -0
- package/lib/module/features/roomMusicTypes.js.map +1 -0
- package/lib/module/features/screenShare.js +22 -0
- package/lib/module/features/screenShare.js.map +1 -0
- package/lib/module/features/singerMode.js +73 -0
- package/lib/module/features/singerMode.js.map +1 -0
- package/lib/module/features/voiceEffects.js +148 -0
- package/lib/module/features/voiceEffects.js.map +1 -0
- package/lib/module/hooks/context.js +34 -0
- package/lib/module/hooks/context.js.map +1 -0
- package/lib/module/hooks/hooks.js +145 -0
- package/lib/module/hooks/hooks.js.map +1 -0
- package/lib/module/hooks/types.js +4 -0
- package/lib/module/hooks/types.js.map +1 -0
- package/lib/module/hooks/useRoomEvents.js +30 -0
- package/lib/module/hooks/useRoomEvents.js.map +1 -0
- package/lib/module/index.js +43 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/ios/autoAttach.js +14 -0
- package/lib/module/ios/autoAttach.js.map +1 -0
- package/lib/module/ios/iosAudio.js +149 -0
- package/lib/module/ios/iosAudio.js.map +1 -0
- package/lib/module/join/appStateLifecycle.js +54 -0
- package/lib/module/join/appStateLifecycle.js.map +1 -0
- package/lib/module/micPolicy.js +249 -0
- package/lib/module/micPolicy.js.map +1 -0
- package/lib/module/native/NativeGravixAudio.js +18 -0
- package/lib/module/native/NativeGravixAudio.js.map +1 -0
- package/lib/module/native/NativeGravixRtc.js +13 -0
- package/lib/module/native/NativeGravixRtc.js.map +1 -0
- package/lib/module/native/module.js +23 -0
- package/lib/module/native/module.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/polyfills/DOMException.js +22 -0
- package/lib/module/polyfills/DOMException.js.map +1 -0
- package/lib/module/polyfills/early.js +18 -0
- package/lib/module/polyfills/early.js.map +1 -0
- package/lib/module/polyfills/event.js +71 -0
- package/lib/module/polyfills/event.js.map +1 -0
- package/lib/module/polyfills/sha256.js +92 -0
- package/lib/module/polyfills/sha256.js.map +1 -0
- package/lib/module/polyfills/subtleHmac.js +91 -0
- package/lib/module/polyfills/subtleHmac.js.map +1 -0
- package/lib/module/polyfills/textCoding.js +164 -0
- package/lib/module/polyfills/textCoding.js.map +1 -0
- package/lib/module/registerGlobals.js +135 -0
- package/lib/module/registerGlobals.js.map +1 -0
- package/lib/module/unsupported.js +90 -0
- package/lib/module/unsupported.js.map +1 -0
- package/lib/module/version.js +7 -0
- package/lib/module/version.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/android/bindings.d.ts +14 -0
- package/lib/typescript/src/android/bindings.d.ts.map +1 -0
- package/lib/typescript/src/android/index.d.ts +9 -0
- package/lib/typescript/src/android/index.d.ts.map +1 -0
- package/lib/typescript/src/android/micMute.d.ts +124 -0
- package/lib/typescript/src/android/micMute.d.ts.map +1 -0
- package/lib/typescript/src/android/nativeAudio.d.ts +40 -0
- package/lib/typescript/src/android/nativeAudio.d.ts.map +1 -0
- package/lib/typescript/src/android/noiseSuppression.d.ts +48 -0
- package/lib/typescript/src/android/noiseSuppression.d.ts.map +1 -0
- package/lib/typescript/src/android/roomMusic.d.ts +80 -0
- package/lib/typescript/src/android/roomMusic.d.ts.map +1 -0
- package/lib/typescript/src/android/singerMode.d.ts +27 -0
- package/lib/typescript/src/android/singerMode.d.ts.map +1 -0
- package/lib/typescript/src/android/voiceEffects.d.ts +30 -0
- package/lib/typescript/src/android/voiceEffects.d.ts.map +1 -0
- package/lib/typescript/src/audio/AudioManager.d.ts +32 -0
- package/lib/typescript/src/audio/AudioManager.d.ts.map +1 -0
- package/lib/typescript/src/audio/AudioSession.d.ts +70 -0
- package/lib/typescript/src/audio/AudioSession.d.ts.map +1 -0
- package/lib/typescript/src/audio/remoteVolume.d.ts +8 -0
- package/lib/typescript/src/audio/remoteVolume.d.ts.map +1 -0
- package/lib/typescript/src/components/VideoView.d.ts +44 -0
- package/lib/typescript/src/components/VideoView.d.ts.map +1 -0
- package/lib/typescript/src/features/audioScenario.d.ts +24 -0
- package/lib/typescript/src/features/audioScenario.d.ts.map +1 -0
- package/lib/typescript/src/features/beauty.d.ts +377 -0
- package/lib/typescript/src/features/beauty.d.ts.map +1 -0
- package/lib/typescript/src/features/micRelease.d.ts +28 -0
- package/lib/typescript/src/features/micRelease.d.ts.map +1 -0
- package/lib/typescript/src/features/noiseSuppression.d.ts +64 -0
- package/lib/typescript/src/features/noiseSuppression.d.ts.map +1 -0
- package/lib/typescript/src/features/roomMusic.d.ts +41 -0
- package/lib/typescript/src/features/roomMusic.d.ts.map +1 -0
- package/lib/typescript/src/features/roomMusicAndroid.d.ts +60 -0
- package/lib/typescript/src/features/roomMusicAndroid.d.ts.map +1 -0
- package/lib/typescript/src/features/roomMusicIos.d.ts +56 -0
- package/lib/typescript/src/features/roomMusicIos.d.ts.map +1 -0
- package/lib/typescript/src/features/roomMusicTypes.d.ts +76 -0
- package/lib/typescript/src/features/roomMusicTypes.d.ts.map +1 -0
- package/lib/typescript/src/features/screenShare.d.ts +12 -0
- package/lib/typescript/src/features/screenShare.d.ts.map +1 -0
- package/lib/typescript/src/features/singerMode.d.ts +20 -0
- package/lib/typescript/src/features/singerMode.d.ts.map +1 -0
- package/lib/typescript/src/features/voiceEffects.d.ts +46 -0
- package/lib/typescript/src/features/voiceEffects.d.ts.map +1 -0
- package/lib/typescript/src/hooks/context.d.ts +12 -0
- package/lib/typescript/src/hooks/context.d.ts.map +1 -0
- package/lib/typescript/src/hooks/hooks.d.ts +54 -0
- package/lib/typescript/src/hooks/hooks.d.ts.map +1 -0
- package/lib/typescript/src/hooks/types.d.ts +8 -0
- package/lib/typescript/src/hooks/types.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useRoomEvents.d.ts +13 -0
- package/lib/typescript/src/hooks/useRoomEvents.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +37 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/ios/autoAttach.d.ts +2 -0
- package/lib/typescript/src/ios/autoAttach.d.ts.map +1 -0
- package/lib/typescript/src/ios/iosAudio.d.ts +96 -0
- package/lib/typescript/src/ios/iosAudio.d.ts.map +1 -0
- package/lib/typescript/src/join/appStateLifecycle.d.ts +14 -0
- package/lib/typescript/src/join/appStateLifecycle.d.ts.map +1 -0
- package/lib/typescript/src/micPolicy.d.ts +104 -0
- package/lib/typescript/src/micPolicy.d.ts.map +1 -0
- package/lib/typescript/src/native/NativeGravixAudio.d.ts +21 -0
- package/lib/typescript/src/native/NativeGravixAudio.d.ts.map +1 -0
- package/lib/typescript/src/native/NativeGravixRtc.d.ts +31 -0
- package/lib/typescript/src/native/NativeGravixRtc.d.ts.map +1 -0
- package/lib/typescript/src/native/module.d.ts +7 -0
- package/lib/typescript/src/native/module.d.ts.map +1 -0
- package/lib/typescript/src/polyfills/DOMException.d.ts +3 -0
- package/lib/typescript/src/polyfills/DOMException.d.ts.map +1 -0
- package/lib/typescript/src/polyfills/early.d.ts +2 -0
- package/lib/typescript/src/polyfills/early.d.ts.map +1 -0
- package/lib/typescript/src/polyfills/event.d.ts +2 -0
- package/lib/typescript/src/polyfills/event.d.ts.map +1 -0
- package/lib/typescript/src/polyfills/sha256.d.ts +3 -0
- package/lib/typescript/src/polyfills/sha256.d.ts.map +1 -0
- package/lib/typescript/src/polyfills/subtleHmac.d.ts +37 -0
- package/lib/typescript/src/polyfills/subtleHmac.d.ts.map +1 -0
- package/lib/typescript/src/polyfills/textCoding.d.ts +36 -0
- package/lib/typescript/src/polyfills/textCoding.d.ts.map +1 -0
- package/lib/typescript/src/registerGlobals.d.ts +42 -0
- package/lib/typescript/src/registerGlobals.d.ts.map +1 -0
- package/lib/typescript/src/unsupported.d.ts +42 -0
- package/lib/typescript/src/unsupported.d.ts.map +1 -0
- package/lib/typescript/src/version.d.ts +3 -0
- package/lib/typescript/src/version.d.ts.map +1 -0
- package/metro/index.js +39 -0
- package/metro/noise-stub.js +10 -0
- package/native/gxfx/include/gx_fx.h +82 -0
- package/native/gxfx/src/gx_fx.cpp +527 -0
- package/native/gxfx/third_party/README.md +4 -0
- package/native/gxfx/third_party/signalsmith-linear/LICENSE.txt +21 -0
- package/native/gxfx/third_party/signalsmith-linear/approx.h +191 -0
- package/native/gxfx/third_party/signalsmith-linear/fft.h +1386 -0
- package/native/gxfx/third_party/signalsmith-linear/linear.h +1129 -0
- package/native/gxfx/third_party/signalsmith-linear/platform/approx-cmsisdsp.h +40 -0
- package/native/gxfx/third_party/signalsmith-linear/platform/basic-fill-warnings.h +61 -0
- package/native/gxfx/third_party/signalsmith-linear/platform/fft-accelerate.h +340 -0
- package/native/gxfx/third_party/signalsmith-linear/platform/fft-cmsisdsp.h +307 -0
- package/native/gxfx/third_party/signalsmith-linear/platform/fft-ipp.h +532 -0
- package/native/gxfx/third_party/signalsmith-linear/platform/fft-linear.h +213 -0
- package/native/gxfx/third_party/signalsmith-linear/platform/fft-pffft-double.h +221 -0
- package/native/gxfx/third_party/signalsmith-linear/platform/fft-pffft.h +221 -0
- package/native/gxfx/third_party/signalsmith-linear/platform/linear-accelerate.h +593 -0
- package/native/gxfx/third_party/signalsmith-linear/platform/linear-cmsisdsp.h +713 -0
- package/native/gxfx/third_party/signalsmith-linear/platform/linear-xsimd-dispatch.cpp +6 -0
- package/native/gxfx/third_party/signalsmith-linear/platform/linear-xsimd.h +818 -0
- package/native/gxfx/third_party/signalsmith-linear/stft.h +700 -0
- package/native/gxfx/third_party/signalsmith-stretch-LICENSE.txt +21 -0
- package/native/gxfx/third_party/signalsmith-stretch.h +1060 -0
- package/native/gxns/CMakeLists.txt +67 -0
- package/native/gxns/include/gx_ns.h +285 -0
- package/native/gxns/src/gx_ns.c +1518 -0
- package/native/gxns/src/gx_ns_timer.c +84 -0
- package/native/gxns/src/gx_ns_timer.h +29 -0
- package/native/gxns/third_party/VENDOR.md +43 -0
- package/native/gxns/third_party/rnnoise/AUTHORS +1 -0
- package/native/gxns/third_party/rnnoise/COPYING +31 -0
- package/native/gxns/third_party/rnnoise/include/rnnoise.h +117 -0
- package/native/gxns/third_party/rnnoise/src/_kiss_fft_guts.h +182 -0
- package/native/gxns/third_party/rnnoise/src/arch.h +261 -0
- package/native/gxns/third_party/rnnoise/src/celt_lpc.c +172 -0
- package/native/gxns/third_party/rnnoise/src/celt_lpc.h +45 -0
- package/native/gxns/third_party/rnnoise/src/common.h +48 -0
- package/native/gxns/third_party/rnnoise/src/denoise.c +664 -0
- package/native/gxns/third_party/rnnoise/src/kiss_fft.c +601 -0
- package/native/gxns/third_party/rnnoise/src/kiss_fft.h +203 -0
- package/native/gxns/third_party/rnnoise/src/opus_types.h +159 -0
- package/native/gxns/third_party/rnnoise/src/pitch.c +523 -0
- package/native/gxns/third_party/rnnoise/src/pitch.h +149 -0
- package/native/gxns/third_party/rnnoise/src/rnn.c +178 -0
- package/native/gxns/third_party/rnnoise/src/rnn.h +65 -0
- package/native/gxns/third_party/rnnoise/src/rnn_data.c +11051 -0
- package/native/gxns/third_party/rnnoise/src/rnn_data.h +34 -0
- package/native/gxns/third_party/rnnoise/src/tansig_table.h +45 -0
- package/native/gxns/third_party/speexdsp/AUTHORS +18 -0
- package/native/gxns/third_party/speexdsp/COPYING +35 -0
- package/native/gxns/third_party/speexdsp/arch.h +232 -0
- package/native/gxns/third_party/speexdsp/resample.c +1239 -0
- package/native/gxns/third_party/speexdsp/resample_neon.h +339 -0
- package/native/gxns/third_party/speexdsp/resample_sse.h +128 -0
- package/native/gxns/third_party/speexdsp/speex_resampler.h +343 -0
- package/package.json +186 -4
- package/src/android/bindings.ts +61 -0
- package/src/android/index.ts +10 -0
- package/src/android/micMute.ts +422 -0
- package/src/android/nativeAudio.ts +94 -0
- package/src/android/noiseSuppression.ts +209 -0
- package/src/android/roomMusic.ts +193 -0
- package/src/android/singerMode.ts +53 -0
- package/src/android/voiceEffects.ts +126 -0
- package/src/audio/AudioManager.ts +111 -0
- package/src/audio/AudioSession.ts +190 -0
- package/src/audio/remoteVolume.ts +58 -0
- package/src/components/VideoView.tsx +152 -0
- package/src/features/audioScenario.ts +58 -0
- package/src/features/beauty.ts +1057 -0
- package/src/features/micRelease.ts +108 -0
- package/src/features/noiseSuppression.ts +251 -0
- package/src/features/roomMusic.ts +106 -0
- package/src/features/roomMusicAndroid.ts +310 -0
- package/src/features/roomMusicIos.ts +300 -0
- package/src/features/roomMusicTypes.ts +97 -0
- package/src/features/screenShare.ts +19 -0
- package/src/features/singerMode.ts +70 -0
- package/src/features/voiceEffects.ts +245 -0
- package/src/hooks/context.tsx +38 -0
- package/src/hooks/hooks.ts +247 -0
- package/src/hooks/types.ts +10 -0
- package/src/hooks/useRoomEvents.ts +35 -0
- package/src/index.tsx +134 -0
- package/src/ios/autoAttach.ts +11 -0
- package/src/ios/iosAudio.ts +202 -0
- package/src/join/appStateLifecycle.ts +55 -0
- package/src/micPolicy.ts +312 -0
- package/src/native/NativeGravixAudio.ts +30 -0
- package/src/native/NativeGravixRtc.ts +38 -0
- package/src/native/module.ts +22 -0
- package/src/polyfills/DOMException.ts +20 -0
- package/src/polyfills/early.ts +16 -0
- package/src/polyfills/event.ts +88 -0
- package/src/polyfills/sha256.ts +112 -0
- package/src/polyfills/subtleHmac.ts +124 -0
- package/src/polyfills/textCoding.ts +197 -0
- package/src/registerGlobals.ts +201 -0
- package/src/unsupported.ts +139 -0
- package/src/version.ts +4 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
package com.gravitycompile.gravixrtc.processing
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Pure decisions of the noise-suppression processor (no Android, no JNI), so
|
|
5
|
+
* the JVM unit tests cover them: frame shape, route names, the watchdog and
|
|
6
|
+
* the engine actually used.
|
|
7
|
+
*/
|
|
8
|
+
internal object GxNsFrameShape {
|
|
9
|
+
private val RATES = intArrayOf(8000, 16000, 24000, 32000, 44100, 48000)
|
|
10
|
+
|
|
11
|
+
/** APM frames are 10 ms: rate = numFrames * 100, if gx_ns supports it. */
|
|
12
|
+
fun rateOf(numFrames: Int): Int? {
|
|
13
|
+
val r = numFrames * 100
|
|
14
|
+
return if (r in RATES) r else null
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Null when the buffer can be processed in place as mono full-band floats,
|
|
19
|
+
* else the reason to stay passthrough. [channels] = initialize()'s count
|
|
20
|
+
* (0 = not seen; the hook may be added after APM initialized).
|
|
21
|
+
*/
|
|
22
|
+
fun reject(numFrames: Int, capacityBytes: Int, direct: Boolean, channels: Int): String? = when {
|
|
23
|
+
!direct -> "buffer_not_direct"
|
|
24
|
+
channels > 1 -> "channels_$channels"
|
|
25
|
+
rateOf(numFrames) == null -> "rate_${numFrames * 100}"
|
|
26
|
+
capacityBytes != numFrames * 4 -> "layout_cap${capacityBytes}_frames$numFrames"
|
|
27
|
+
else -> null
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
internal object GxNsRoute {
|
|
32
|
+
/**
|
|
33
|
+
* The plan's route names from GxAudioSwitchManager's `current` (AudioRoutePolicy)
|
|
34
|
+
* and the audio mode: Bluetooth in a communication mode is SCO (HFP),
|
|
35
|
+
* in the media mode A2DP.
|
|
36
|
+
*/
|
|
37
|
+
fun of(current: String?, audioMode: Int?): String = when (current) {
|
|
38
|
+
AudioRoutePolicy.SPEAKER -> "speaker"
|
|
39
|
+
AudioRoutePolicy.EARPIECE -> "earpiece"
|
|
40
|
+
AudioRoutePolicy.WIRED -> "wired"
|
|
41
|
+
AudioRoutePolicy.USB -> "usb"
|
|
42
|
+
AudioRoutePolicy.BLUETOOTH ->
|
|
43
|
+
if (audioMode == AudioRoutePolicy.MODE_IN_COMMUNICATION || audioMode == AudioRoutePolicy.MODE_IN_CALL) "bt-sco" else "bt-a2dp"
|
|
44
|
+
else -> "unknown"
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
fun isBluetooth(route: String): Boolean = route.startsWith("bt-")
|
|
48
|
+
|
|
49
|
+
/** SCO / HFP microphones are 8-16 kHz content (auto keeps RNNoise there). */
|
|
50
|
+
fun isNarrowband(route: String): Boolean = route == "bt-sco"
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** 3 consecutive frames over the budget (owner spec §4). Audio thread only. */
|
|
54
|
+
internal class GxNsWatchdog(private val limitNs: Long, private val consecutive: Int) {
|
|
55
|
+
private var run = 0
|
|
56
|
+
var tripped = false
|
|
57
|
+
private set
|
|
58
|
+
|
|
59
|
+
/** Returns true exactly once, on the frame that trips it. */
|
|
60
|
+
fun onFrame(ns: Long): Boolean {
|
|
61
|
+
if (ns > limitNs) run++ else run = 0
|
|
62
|
+
if (!tripped && run >= consecutive) {
|
|
63
|
+
tripped = true
|
|
64
|
+
return true
|
|
65
|
+
}
|
|
66
|
+
return false
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
fun rearm() {
|
|
70
|
+
tripped = false
|
|
71
|
+
run = 0
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The engine actually run, from the requested one and the live conditions. */
|
|
76
|
+
internal object GxNsFallback {
|
|
77
|
+
data class Decision(val engine: Int, val reason: String)
|
|
78
|
+
|
|
79
|
+
fun decide(
|
|
80
|
+
requested: Int,
|
|
81
|
+
requestReason: String,
|
|
82
|
+
watchdogTripped: Boolean,
|
|
83
|
+
thermalHot: Boolean,
|
|
84
|
+
batterySaver: Boolean,
|
|
85
|
+
preferHeadset: Boolean,
|
|
86
|
+
route: String,
|
|
87
|
+
thermalFallback: Boolean = true,
|
|
88
|
+
batterySaverFallback: Boolean = true,
|
|
89
|
+
studioSlow: Boolean = false,
|
|
90
|
+
studioSuppress: Boolean = false,
|
|
91
|
+
): Decision {
|
|
92
|
+
if (requested == GxNsNative.ENGINE_OFF) return Decision(GxNsNative.ENGINE_OFF, requestReason)
|
|
93
|
+
if (preferHeadset && GxNsRoute.isBluetooth(route)) return Decision(GxNsNative.ENGINE_OFF, "headset_ns")
|
|
94
|
+
if (requested == GxNsNative.ENGINE_DFN3) {
|
|
95
|
+
if (watchdogTripped) return Decision(GxNsNative.ENGINE_RNNOISE, "watchdog_frame")
|
|
96
|
+
// gx_ns rolling p95 of the studio engine over ~2 s above budget (thermal drift mid-call)
|
|
97
|
+
if (studioSlow) return Decision(GxNsNative.ENGINE_RNNOISE, "studio_slow")
|
|
98
|
+
// gx_ns: studio output speech collapsed vs its input (live guard)
|
|
99
|
+
if (studioSuppress) return Decision(GxNsNative.ENGINE_RNNOISE, "studio_suppress")
|
|
100
|
+
if (thermalFallback && thermalHot) return Decision(GxNsNative.ENGINE_RNNOISE, "thermal")
|
|
101
|
+
if (batterySaverFallback && batterySaver) return Decision(GxNsNative.ENGINE_RNNOISE, "battery_saver")
|
|
102
|
+
}
|
|
103
|
+
return Decision(requested, requestReason)
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Our AGC runs only with an engine on and the own-AGC order (off / kill switch: WebRTC's AGC owns the level). */
|
|
108
|
+
internal object GxNsAgc {
|
|
109
|
+
fun ownOn(requested: Int, agcOrder: String?): Boolean =
|
|
110
|
+
requested != GxNsNative.ENGINE_OFF && agcOrder != "webrtcBeforeNs" && agcOrder != "none"
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Capture blocks inside gx_ns: the counter is odd while one is running. A
|
|
115
|
+
* retired studio engine is freed at once when [idle], else after [advancedSince].
|
|
116
|
+
*/
|
|
117
|
+
internal class GxNsInFlight {
|
|
118
|
+
private val seq = java.util.concurrent.atomic.AtomicLong(0)
|
|
119
|
+
fun enter() { seq.incrementAndGet() }
|
|
120
|
+
fun exit() { seq.incrementAndGet() }
|
|
121
|
+
fun snapshot(): Long = seq.get()
|
|
122
|
+
fun advancedSince(s0: Long): Boolean = seq.get() != s0
|
|
123
|
+
companion object {
|
|
124
|
+
fun idle(s: Long): Boolean = s and 1L == 0L
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Copies at most [limit] bytes; returns the count, or -1 once the source has more (never reads past limit + 1). */
|
|
129
|
+
internal fun gxNsCopyBounded(inp: java.io.InputStream, out: java.io.OutputStream, limit: Long): Long {
|
|
130
|
+
val buf = ByteArray(64 * 1024)
|
|
131
|
+
var total = 0L
|
|
132
|
+
while (true) {
|
|
133
|
+
val want = minOf(buf.size.toLong(), limit - total + 1).toInt()
|
|
134
|
+
val n = inp.read(buf, 0, want)
|
|
135
|
+
if (n < 0) return total
|
|
136
|
+
total += n
|
|
137
|
+
if (total > limit) return -1
|
|
138
|
+
out.write(buf, 0, n)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Studio packs only over https (the SHA-256 check is the integrity guard, https keeps the URL private). */
|
|
143
|
+
internal fun gxNsPackUrlOk(url: String): Boolean = url.startsWith("https://", ignoreCase = true)
|
|
144
|
+
|
|
145
|
+
/** `[GravixNS] <step> eng=<> route=<> rate=<> [+<ms>ms] [detail]` (plan §3, same as Dart/JS). */
|
|
146
|
+
internal fun gxNsLine(step: String, eng: String, route: String, rate: Int, elapsedMs: Long? = null, detail: String? = null): String {
|
|
147
|
+
val b = StringBuilder("[GravixNS] ").append(step).append(" eng=").append(eng).append(" route=").append(route)
|
|
148
|
+
.append(" rate=").append(if (rate > 0) rate.toString() else "?")
|
|
149
|
+
if (elapsedMs != null) b.append(" +").append(elapsedMs).append("ms")
|
|
150
|
+
if (!detail.isNullOrEmpty()) b.append(' ').append(detail)
|
|
151
|
+
return b.toString()
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Singer level normaliser settings from Dart (GravixSingerOptions.level*, 0.11.4). */
|
|
155
|
+
internal data class GxSingerLevel(
|
|
156
|
+
val enabled: Boolean = true,
|
|
157
|
+
val targetDbfs: Float = -16f,
|
|
158
|
+
val maxDb: Float = 24f,
|
|
159
|
+
val riseDbPerS: Float = 3f,
|
|
160
|
+
val onWired: Boolean = true,
|
|
161
|
+
val onBluetooth: Boolean = true,
|
|
162
|
+
val builtInMakeupDb: Float = 0f,
|
|
163
|
+
) {
|
|
164
|
+
companion object {
|
|
165
|
+
/** From the nsSetSingerMode arguments; missing / wrong-typed keys keep the defaults, values clamped. */
|
|
166
|
+
fun of(args: Map<String, Any?>): GxSingerLevel {
|
|
167
|
+
val d = GxSingerLevel()
|
|
168
|
+
fun n(k: String, v: Float, lo: Float, hi: Float) = ((args[k] as? Number)?.toFloat() ?: v).coerceIn(lo, hi)
|
|
169
|
+
return GxSingerLevel(
|
|
170
|
+
enabled = args["levelNormalizer"] as? Boolean ?: d.enabled,
|
|
171
|
+
targetDbfs = n("levelTargetDbfs", d.targetDbfs, -40f, -6f),
|
|
172
|
+
maxDb = n("levelMaxGainDb", d.maxDb, 0f, 30f),
|
|
173
|
+
riseDbPerS = n("levelRiseDbPerSec", d.riseDbPerS, 0.5f, 30f),
|
|
174
|
+
onWired = args["levelOnWired"] as? Boolean ?: d.onWired,
|
|
175
|
+
onBluetooth = args["levelOnBluetooth"] as? Boolean ?: d.onBluetooth,
|
|
176
|
+
builtInMakeupDb = n("builtInMakeupDb", d.builtInMakeupDb, 0f, 30f),
|
|
177
|
+
)
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
package com.gravitycompile.gravixrtc.processing
|
|
2
|
+
|
|
3
|
+
import java.nio.ByteBuffer
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* libgxns.so (android/src/main/cpp/gx_ns_jni.c over native/gxns). Loaded on
|
|
7
|
+
* first use; [loadError] says why it is unavailable (ABI without the library,
|
|
8
|
+
* a stripped build), in which case noise suppression resolves to off.
|
|
9
|
+
*/
|
|
10
|
+
internal object GxNsNative {
|
|
11
|
+
// gx_ns_engine
|
|
12
|
+
const val ENGINE_OFF = 0
|
|
13
|
+
const val ENGINE_RNNOISE = 1
|
|
14
|
+
const val ENGINE_DFN3 = 2
|
|
15
|
+
|
|
16
|
+
// gx_ns_agc_order
|
|
17
|
+
const val AGC_AFTER_NS = 0
|
|
18
|
+
const val AGC_BEFORE_NS = 1
|
|
19
|
+
|
|
20
|
+
@Volatile var loadError: String? = null
|
|
21
|
+
private set
|
|
22
|
+
|
|
23
|
+
/** libgxns loads on this device (capability flag). */
|
|
24
|
+
val libraryLoaded: Boolean get() = loaded
|
|
25
|
+
|
|
26
|
+
private val loaded: Boolean by lazy {
|
|
27
|
+
try {
|
|
28
|
+
System.loadLibrary("gxns")
|
|
29
|
+
true
|
|
30
|
+
} catch (t: Throwable) {
|
|
31
|
+
loadError = "library_missing: ${t.javaClass.simpleName}"
|
|
32
|
+
false
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
fun available(): Boolean = loaded
|
|
37
|
+
|
|
38
|
+
fun engineName(e: Int): String = when (e) {
|
|
39
|
+
ENGINE_RNNOISE -> "rnnoise"
|
|
40
|
+
ENGINE_DFN3 -> "dfn3"
|
|
41
|
+
else -> "off"
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
fun engineOf(name: String?): Int = when (name) {
|
|
45
|
+
"rnnoise" -> ENGINE_RNNOISE
|
|
46
|
+
"dfn3" -> ENGINE_DFN3
|
|
47
|
+
else -> ENGINE_OFF
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@JvmStatic external fun nativeCreate(engine: Int, agcEnabled: Int, agcOrder: Int, watchdogUs: Int, p95WindowBlocks: Int): Long
|
|
51
|
+
@JvmStatic external fun nativeDestroy(h: Long)
|
|
52
|
+
@JvmStatic external fun nativeProcess(h: Long, buf: ByteBuffer, n: Int, rate: Int): Int
|
|
53
|
+
@JvmStatic external fun nativeSetEngine(h: Long, engine: Int)
|
|
54
|
+
@JvmStatic external fun nativeSetBypass(h: Long, bypass: Boolean)
|
|
55
|
+
@JvmStatic external fun nativeSetAgc(h: Long, on: Boolean, order: Int)
|
|
56
|
+
/** Auto music (gx_ns_set_auto_music): music on the mic relaxes the chain. */
|
|
57
|
+
@JvmStatic external fun nativeSetAutoMusic(h: Long, on: Boolean)
|
|
58
|
+
/** Auto music starts over (a new capture stream). */
|
|
59
|
+
@JvmStatic external fun nativeResetMusic(h: Long)
|
|
60
|
+
/** Makeup gain (dB, 0..18) on the bypassed (dry) signal, before the -1 dBFS limiter (singer mode). */
|
|
61
|
+
@JvmStatic external fun nativeSetBypassMakeup(h: Long, db: Float)
|
|
62
|
+
/** Singer level normaliser on the bypass (0.11.4); maxDb 0 = off. */
|
|
63
|
+
@JvmStatic external fun nativeSetSingerLevel(h: Long, targetDbfs: Float, maxDb: Float, riseDbPerS: Float)
|
|
64
|
+
@JvmStatic external fun nativeRequestReset(h: Long)
|
|
65
|
+
@JvmStatic external fun nativeResetStats(h: Long)
|
|
66
|
+
|
|
67
|
+
/** Studio attenuation limit (centi-dB, 0 = none) + rolling-p95 budget (us, 0 = off), live. */
|
|
68
|
+
@JvmStatic external fun nativeSetStudioLimits(h: Long, attenCentiDb: Int, p95BudgetUs: Int)
|
|
69
|
+
|
|
70
|
+
/** out[0..9] = frames, p50, p95, p99, max, over, consecutive, underflows, extErrors, switches */
|
|
71
|
+
@JvmStatic external fun nativeStats(h: Long, out: IntArray)
|
|
72
|
+
|
|
73
|
+
/** out[0..6] = requested, active, crossfading, reason, rate, latency, agcGainDb*100
|
|
74
|
+
* (+ [7..10] pre-gain, applied pre-gain, applied AGC, pause attenuation, *100; + [11] auto music detected); returns vad*1000 */
|
|
75
|
+
@JvmStatic external fun nativeStatus(h: Long, out: IntArray): Int
|
|
76
|
+
@JvmStatic external fun nativeReasonName(reason: Int): String
|
|
77
|
+
/** gx_ns_pregain_for_level: the pre-gain (dB) for speech at [db] dBFS. */
|
|
78
|
+
@JvmStatic external fun nativePregainForLevel(db: Float): Float
|
|
79
|
+
|
|
80
|
+
/** Studio seam: a `gx_ns_external_engine*` from the engine's own library, or 0 to detach. */
|
|
81
|
+
@JvmStatic external fun nativeAttachExternal(h: Long, enginePtr: Long): Int
|
|
82
|
+
@JvmStatic external fun nativeBlocks(h: Long): Int
|
|
83
|
+
}
|
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
package com.gravitycompile.gravixrtc.processing
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.net.ConnectivityManager
|
|
5
|
+
import android.os.Build
|
|
6
|
+
import android.util.Log
|
|
7
|
+
import java.io.File
|
|
8
|
+
import java.io.FileInputStream
|
|
9
|
+
import java.net.HttpURLConnection
|
|
10
|
+
import java.net.URL
|
|
11
|
+
import java.nio.ByteBuffer
|
|
12
|
+
import java.nio.ByteOrder
|
|
13
|
+
import java.security.MessageDigest
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Studio engine (DeepFilterNet3) on the bundled minimal ONNX Runtime
|
|
17
|
+
* (libgxns_dfn.so + libgxort.so = ORT with a Gravix-private soname, arm64-v8a only).
|
|
18
|
+
*
|
|
19
|
+
* The studio files ship as arm64-v8a "native libraries" so other ABIs carry
|
|
20
|
+
* none of them: libgxns_dfn3_std.so (the .ort model), libgxns_dfn3_bench.so
|
|
21
|
+
* (2 s WAV clip), libgxns_dfn3_ref.so (reference output, int16). Read from the
|
|
22
|
+
* native library dir when extracted, else straight from the (split) APK, where
|
|
23
|
+
* they are stored uncompressed. An app drops them with `gravixNsStudio=false`
|
|
24
|
+
* (gradle.properties) or turns studio off at runtime with the manifest
|
|
25
|
+
* meta-data `com.gravitycompile.gravix_ns.studio` = false.
|
|
26
|
+
*
|
|
27
|
+
* Models:
|
|
28
|
+
* - standard (bundled): libgxns_dfn3_std.so, 30 ms latency.
|
|
29
|
+
* - low latency (downloaded, [GxNsPack]): dfn3_ll_int8.ort, 10 ms latency,
|
|
30
|
+
* used when present, verified and its benchmark passes.
|
|
31
|
+
* The SHA-256 of every model is compiled in here (release manifest 2026-10-21).
|
|
32
|
+
*/
|
|
33
|
+
internal object GxNsStudio {
|
|
34
|
+
private const val TAG = "GravixNS"
|
|
35
|
+
const val RUNTIME = "ort-1.31.0"
|
|
36
|
+
|
|
37
|
+
data class Model(val id: String, val file: String, val sha256: String, val bytes: Long, val latency: Int)
|
|
38
|
+
|
|
39
|
+
val STD = Model("std", "dfn3_std_int8.ort", "0e4c4f4fc2c5f564528419957267f017fb3d0fc8f1bc33765d06dca67230e14d", 2988880L, 1440)
|
|
40
|
+
val LL = Model("ll", "dfn3_ll_int8.ort", "581535e7e600034b52f3621e873939e972f1851e9babec34e882a11f6f1e9348", 11099368L, 480)
|
|
41
|
+
|
|
42
|
+
private const val STD_LIB = "libgxns_dfn3_std.so"
|
|
43
|
+
private const val BENCH_CLIP = "libgxns_dfn3_bench.so"
|
|
44
|
+
private const val BENCH_REF_STD = "libgxns_dfn3_ref.so"
|
|
45
|
+
private const val META_STUDIO = "com.gravitycompile.gravix_ns.studio"
|
|
46
|
+
|
|
47
|
+
@Volatile var loadError: String? = null
|
|
48
|
+
private set
|
|
49
|
+
|
|
50
|
+
private val loaded: Boolean by lazy {
|
|
51
|
+
if (Build.SUPPORTED_ABIS.firstOrNull() != "arm64-v8a") {
|
|
52
|
+
loadError = "abi_${Build.SUPPORTED_ABIS.firstOrNull()}"
|
|
53
|
+
false
|
|
54
|
+
} else {
|
|
55
|
+
try {
|
|
56
|
+
System.loadLibrary("gxort")
|
|
57
|
+
System.loadLibrary("gxns_dfn")
|
|
58
|
+
true
|
|
59
|
+
} catch (t: Throwable) {
|
|
60
|
+
loadError = "runtime_missing: ${t.javaClass.simpleName}"
|
|
61
|
+
false
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The runtime loads, the app did not turn studio off, and the bundled standard model is in the APK. */
|
|
67
|
+
fun available(ctx: Context): Boolean = loaded && manifestAllows(ctx) && libFileSize(ctx, STD_LIB) == STD.bytes
|
|
68
|
+
|
|
69
|
+
/** The best model on this device now: LL when its verified pack is present, else standard. */
|
|
70
|
+
fun bestModel(ctx: Context): Model = if (GxNsPack.llFile(ctx) != null) LL else STD
|
|
71
|
+
|
|
72
|
+
private fun manifestAllows(ctx: Context): Boolean = try {
|
|
73
|
+
@Suppress("DEPRECATION")
|
|
74
|
+
val ai = ctx.packageManager.getApplicationInfo(ctx.packageName, android.content.pm.PackageManager.GET_META_DATA)
|
|
75
|
+
val v = ai.metaData?.get(META_STUDIO)
|
|
76
|
+
if (v == null) true else v.toString().toBoolean().also { if (!it) loadError = "studio_disabled_manifest" }
|
|
77
|
+
} catch (_: Throwable) {
|
|
78
|
+
true
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** APKs holding this app's native libs: base + splits (an AAB installs lib/ in a config split). */
|
|
82
|
+
private fun apks(ctx: Context): List<String> {
|
|
83
|
+
val ai = ctx.applicationInfo
|
|
84
|
+
return listOfNotNull(ai.sourceDir) + (ai.splitSourceDirs?.toList() ?: emptyList())
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Block body, not `= File(dir ?: return null, ...)`: Kotlin 2.2 refuses a `return` inside an
|
|
88
|
+
// expression body ("Returns are prohibited in functions with expression body"), which broke
|
|
89
|
+
// gravix_rtc 0.5.0 in apps on Kotlin 2.2.x (seen with 2.2.20) at :gravix_rtc:compileReleaseKotlin.
|
|
90
|
+
private fun extracted(ctx: Context, name: String): File? {
|
|
91
|
+
val dir = ctx.applicationInfo.nativeLibraryDir ?: return null
|
|
92
|
+
return File(dir, name).takeIf { it.isFile }
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
private fun libFileSize(ctx: Context, name: String): Long {
|
|
96
|
+
extracted(ctx, name)?.let { return it.length() }
|
|
97
|
+
for (apk in apks(ctx)) {
|
|
98
|
+
try {
|
|
99
|
+
java.util.zip.ZipFile(apk).use { z -> z.getEntry("lib/arm64-v8a/$name")?.let { return it.size } }
|
|
100
|
+
} catch (_: Throwable) {
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return -1L
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
private fun libBytes(ctx: Context, name: String): ByteArray {
|
|
107
|
+
extracted(ctx, name)?.let { return it.readBytes() }
|
|
108
|
+
for (apk in apks(ctx)) {
|
|
109
|
+
val bytes = java.util.zip.ZipFile(apk).use { z ->
|
|
110
|
+
z.getEntry("lib/arm64-v8a/$name")?.let { e -> z.getInputStream(e).use { it.readBytes() } }
|
|
111
|
+
}
|
|
112
|
+
if (bytes != null) return bytes
|
|
113
|
+
}
|
|
114
|
+
throw java.io.FileNotFoundException(name)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
private fun readAll(ctx: Context, m: Model): ByteBuffer? {
|
|
118
|
+
val bytes = if (m === STD) {
|
|
119
|
+
libBytes(ctx, STD_LIB)
|
|
120
|
+
} else {
|
|
121
|
+
GxNsPack.llFile(ctx)?.readBytes() ?: return null
|
|
122
|
+
}
|
|
123
|
+
return ByteBuffer.allocateDirect(bytes.size).order(ByteOrder.nativeOrder()).apply { put(bytes); flip() }
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** A loaded engine: `ptr` = gx_ns_external_engine*, `model` its model. Background thread (loads ~100s of ms). */
|
|
127
|
+
class Engine(val ptr: Long, val model: Model)
|
|
128
|
+
|
|
129
|
+
fun create(ctx: Context, m: Model): Engine? {
|
|
130
|
+
if (!loaded) return null
|
|
131
|
+
val buf = try {
|
|
132
|
+
readAll(ctx, m)
|
|
133
|
+
} catch (t: Throwable) {
|
|
134
|
+
Log.w(TAG, "[GravixNS] dfn3 model ${m.id} unreadable: $t")
|
|
135
|
+
null
|
|
136
|
+
} ?: return null
|
|
137
|
+
val ptr = nativeCreate(buf, m.latency)
|
|
138
|
+
return if (ptr == 0L) null else Engine(ptr, m)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
fun destroy(e: Engine) = nativeDestroy(e.ptr)
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* First-run benchmark (plan §4): 20 warm-up + 200 timed frames of the 2 s
|
|
145
|
+
* clip on a separate engine, here (a background thread). outputOk = finite
|
|
146
|
+
* output, level within bounds and (standard) parity with the reference loop.
|
|
147
|
+
*/
|
|
148
|
+
fun benchmark(ctx: Context, m: Model): Map<String, Any?> {
|
|
149
|
+
val t0 = System.nanoTime()
|
|
150
|
+
val e = create(ctx, m) ?: return mapOf("ok" to false, "reason" to (loadError ?: "load_failed"), "model" to m.id)
|
|
151
|
+
try {
|
|
152
|
+
val clip = wavPcm16(libBytes(ctx, BENCH_CLIP))
|
|
153
|
+
val ref = if (m === STD) pcm16(libBytes(ctx, BENCH_REF_STD)) else null
|
|
154
|
+
val out = IntArray(6)
|
|
155
|
+
val rc = nativeBenchmark(e.ptr, clip, ref, 20, 200, out)
|
|
156
|
+
if (rc != 0) return mapOf("ok" to false, "reason" to "bench_rc_$rc", "model" to m.id)
|
|
157
|
+
val inDb = out[3] / 100.0
|
|
158
|
+
val outDb = out[4] / 100.0
|
|
159
|
+
val snr = if (out[5] == -99900) null else out[5] / 100.0
|
|
160
|
+
// Quiet-mic check (device run 2026-10-21: DFN3 erased a quiet iPhone mic): the clip at
|
|
161
|
+
// -45 dBFS speech, through the core's pre-gain, must keep its speech (out >= in - 6 dB).
|
|
162
|
+
val quiet = quietClip(clip)
|
|
163
|
+
val q = IntArray(6)
|
|
164
|
+
val qrc = nativeBenchmark(e.ptr, quiet, null, 0, clip.size / 480, q)
|
|
165
|
+
val quietInDb = q[3] / 100.0
|
|
166
|
+
val quietOutDb = q[4] / 100.0
|
|
167
|
+
val quietOk = qrc == 0 && quietOutDb >= quietInDb - 6.0
|
|
168
|
+
// a corrupt / wrong-scale model: silent, exploding, (std) far from the reference, or erasing quiet speech
|
|
169
|
+
val outputOk = outDb > inDb - 30.0 && outDb < inDb + 6.0 && (snr == null || snr >= 25.0) && quietOk
|
|
170
|
+
return mapOf(
|
|
171
|
+
"ok" to true, "model" to m.id, "sha256" to m.sha256, "runtime" to RUNTIME,
|
|
172
|
+
"p50Us" to out[0], "p95Us" to out[1], "maxUs" to out[2],
|
|
173
|
+
"inDb" to inDb, "outDb" to outDb, "paritySnrDb" to snr, "outputOk" to outputOk,
|
|
174
|
+
"quietInDb" to quietInDb, "quietOutDb" to quietOutDb,
|
|
175
|
+
"ms" to (System.nanoTime() - t0) / 1_000_000,
|
|
176
|
+
)
|
|
177
|
+
} finally {
|
|
178
|
+
destroy(e)
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** [clip] scaled to -45 dBFS RMS, then lifted by the core's pre-gain for that level. */
|
|
183
|
+
internal fun quietClip(clip: ShortArray): ShortArray {
|
|
184
|
+
var acc = 0.0
|
|
185
|
+
for (v in clip) acc += v.toDouble() * v
|
|
186
|
+
val rmsDb = 10.0 * Math.log10(acc / maxOf(1, clip.size) / (32768.0 * 32768.0) + 1e-20)
|
|
187
|
+
val gainDb = (QUIET_DBFS - rmsDb) + GxNsNative.nativePregainForLevel(QUIET_DBFS.toFloat())
|
|
188
|
+
val g = Math.pow(10.0, gainDb / 20.0)
|
|
189
|
+
return ShortArray(clip.size) { i -> (clip[i] * g).coerceIn(-32768.0, 32767.0).toInt().toShort() }
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
private const val QUIET_DBFS = -45.0
|
|
193
|
+
|
|
194
|
+
private fun pcm16(b: ByteArray): ShortArray {
|
|
195
|
+
val s = ShortArray(b.size / 2)
|
|
196
|
+
ByteBuffer.wrap(b).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer().get(s)
|
|
197
|
+
return s
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** The "data" chunk of a 16-bit PCM WAV. */
|
|
201
|
+
private fun wavPcm16(b: ByteArray): ShortArray {
|
|
202
|
+
var i = 12
|
|
203
|
+
val bb = ByteBuffer.wrap(b).order(ByteOrder.LITTLE_ENDIAN)
|
|
204
|
+
while (i + 8 <= b.size) {
|
|
205
|
+
val id = String(b, i, 4, Charsets.US_ASCII)
|
|
206
|
+
val len = bb.getInt(i + 4)
|
|
207
|
+
if (id == "data") return pcm16(b.copyOfRange(i + 8, minOf(b.size, i + 8 + len)))
|
|
208
|
+
i += 8 + len + (len and 1)
|
|
209
|
+
}
|
|
210
|
+
return ShortArray(0)
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
@JvmStatic private external fun nativeCreate(model: ByteBuffer, latency: Int): Long
|
|
214
|
+
@JvmStatic private external fun nativeDestroy(h: Long)
|
|
215
|
+
@JvmStatic private external fun nativeBenchmark(h: Long, clip: ShortArray, ref: ShortArray?, warm: Int, frames: Int, out: IntArray): Int
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* The low-latency DFN3 pack (plan Phase 3 delivery): Play asset pack on Play
|
|
220
|
+
* installs, our CDN otherwise (a Play app never downloads code; this is a model
|
|
221
|
+
* file, still Play-only by the owner's spec). SHA-256 verified before use;
|
|
222
|
+
* cached in the app's files dir.
|
|
223
|
+
*/
|
|
224
|
+
internal object GxNsPack {
|
|
225
|
+
private const val TAG = "GravixNS"
|
|
226
|
+
const val PLAY_PACK = "gravix_ns_ll"
|
|
227
|
+
private const val DIR = "gravix_ns"
|
|
228
|
+
|
|
229
|
+
@Volatile private var verified: File? = null
|
|
230
|
+
@Volatile private var fetching = false
|
|
231
|
+
|
|
232
|
+
/** The verified LL model file, or null. Cheap after the first verification. */
|
|
233
|
+
fun llFile(ctx: Context): File? {
|
|
234
|
+
verified?.let { if (it.length() == GxNsStudio.LL.bytes) return it }
|
|
235
|
+
val cached = File(File(ctx.filesDir, DIR), "${GxNsStudio.LL.sha256}.ort")
|
|
236
|
+
if (cached.length() == GxNsStudio.LL.bytes) {
|
|
237
|
+
verified = cached // verified when it was written (atomic rename after the SHA check)
|
|
238
|
+
return cached
|
|
239
|
+
}
|
|
240
|
+
val play = playPackFile(ctx)
|
|
241
|
+
if (play != null && play.length() == GxNsStudio.LL.bytes && sha256(play) == GxNsStudio.LL.sha256) {
|
|
242
|
+
verified = play
|
|
243
|
+
return play
|
|
244
|
+
}
|
|
245
|
+
return null
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** The installer is Google Play. */
|
|
249
|
+
fun isPlayInstall(ctx: Context): Boolean = try {
|
|
250
|
+
val installer = if (Build.VERSION.SDK_INT >= 30) {
|
|
251
|
+
ctx.packageManager.getInstallSourceInfo(ctx.packageName).installingPackageName
|
|
252
|
+
} else {
|
|
253
|
+
@Suppress("DEPRECATION")
|
|
254
|
+
ctx.packageManager.getInstallerPackageName(ctx.packageName)
|
|
255
|
+
}
|
|
256
|
+
installer == "com.android.vending"
|
|
257
|
+
} catch (_: Throwable) {
|
|
258
|
+
false
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Fetches the pack if allowed (background thread; never blocks a join).
|
|
263
|
+
* [source]: auto | playAssetPack | cdn | app; [download]: never | unmeteredIdle | any;
|
|
264
|
+
* [baseUrl]: the CDN folder holding dfn3_ll_int8.ort (null = no CDN).
|
|
265
|
+
* Returns a reason string for the log.
|
|
266
|
+
*/
|
|
267
|
+
fun ensure(ctx: Context, source: String, download: String, baseUrl: String?): String {
|
|
268
|
+
if (llFile(ctx) != null) return "present"
|
|
269
|
+
if (download == "never") return "download_never"
|
|
270
|
+
if (fetching) return "in_progress"
|
|
271
|
+
val play = isPlayInstall(ctx)
|
|
272
|
+
val useCdn = when (source) {
|
|
273
|
+
"cdn" -> !play
|
|
274
|
+
"auto" -> !play
|
|
275
|
+
else -> false
|
|
276
|
+
}
|
|
277
|
+
val usePlay = source == "playAssetPack" || (source == "auto" && play)
|
|
278
|
+
if (download == "unmeteredIdle" && metered(ctx)) return "metered"
|
|
279
|
+
fetching = true
|
|
280
|
+
try {
|
|
281
|
+
if (usePlay) return requestPlayPack(ctx)
|
|
282
|
+
if (useCdn) {
|
|
283
|
+
if (baseUrl.isNullOrEmpty()) return "no_cdn_url"
|
|
284
|
+
return downloadCdn(ctx, baseUrl.trimEnd('/') + "/" + GxNsStudio.LL.file)
|
|
285
|
+
}
|
|
286
|
+
return if (play) "play_install_no_cdn" else "source_$source"
|
|
287
|
+
} finally {
|
|
288
|
+
fetching = false
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
private fun metered(ctx: Context): Boolean = try {
|
|
293
|
+
(ctx.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager).isActiveNetworkMetered
|
|
294
|
+
} catch (_: Throwable) {
|
|
295
|
+
true
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
private fun downloadCdn(ctx: Context, url: String): String {
|
|
299
|
+
val dir = File(ctx.filesDir, DIR).apply { mkdirs() }
|
|
300
|
+
val part = File(dir, "${GxNsStudio.LL.sha256}.part")
|
|
301
|
+
val dst = File(dir, "${GxNsStudio.LL.sha256}.ort")
|
|
302
|
+
val t0 = System.nanoTime()
|
|
303
|
+
if (!gxNsPackUrlOk(url)) return "insecure_url"
|
|
304
|
+
var c: HttpURLConnection? = null
|
|
305
|
+
return try {
|
|
306
|
+
c = URL(url).openConnection() as HttpURLConnection
|
|
307
|
+
c.connectTimeout = 10_000
|
|
308
|
+
c.readTimeout = 20_000
|
|
309
|
+
c.instanceFollowRedirects = true
|
|
310
|
+
if (c.responseCode != 200) return "http_${c.responseCode}"
|
|
311
|
+
if (!gxNsPackUrlOk(c.url.toString())) return "insecure_redirect"
|
|
312
|
+
val n = c.inputStream.use { inp -> part.outputStream().use { gxNsCopyBounded(inp, it, GxNsStudio.LL.bytes) } }
|
|
313
|
+
if (n < 0) {
|
|
314
|
+
part.delete()
|
|
315
|
+
return "too_large"
|
|
316
|
+
}
|
|
317
|
+
val sha = sha256(part)
|
|
318
|
+
if (part.length() != GxNsStudio.LL.bytes || sha != GxNsStudio.LL.sha256) {
|
|
319
|
+
part.delete()
|
|
320
|
+
return "sha_mismatch"
|
|
321
|
+
}
|
|
322
|
+
if (!part.renameTo(dst)) return "rename_failed"
|
|
323
|
+
verified = dst
|
|
324
|
+
Log.i(TAG, "[GravixNS] pack src=cdn sha=ok bytes=${dst.length()} ms=${(System.nanoTime() - t0) / 1_000_000}")
|
|
325
|
+
"downloaded"
|
|
326
|
+
} catch (t: Throwable) {
|
|
327
|
+
part.delete()
|
|
328
|
+
"download_failed: ${t.javaClass.simpleName}"
|
|
329
|
+
} finally {
|
|
330
|
+
c?.disconnect()
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// Play Asset Delivery by reflection (the app adds the pack + the
|
|
335
|
+
// com.google.android.play:asset-delivery dependency; the plugin cannot).
|
|
336
|
+
private fun playManager(ctx: Context): Any? = try {
|
|
337
|
+
Class.forName("com.google.android.play.core.assetpacks.AssetPackManagerFactory")
|
|
338
|
+
.getMethod("getInstance", Context::class.java).invoke(null, ctx)
|
|
339
|
+
} catch (_: Throwable) {
|
|
340
|
+
null
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
private fun playPackFile(ctx: Context): File? = try {
|
|
344
|
+
val m = playManager(ctx) ?: return null
|
|
345
|
+
val loc = m.javaClass.getMethod("getPackLocation", String::class.java).invoke(m, PLAY_PACK) ?: return null
|
|
346
|
+
val path = loc.javaClass.getMethod("assetsPath").invoke(loc) as? String ?: return null
|
|
347
|
+
File(path, GxNsStudio.LL.file).takeIf { it.exists() }
|
|
348
|
+
} catch (_: Throwable) {
|
|
349
|
+
null
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
private fun requestPlayPack(ctx: Context): String = try {
|
|
353
|
+
val m = playManager(ctx) ?: return "play_no_asset_delivery"
|
|
354
|
+
m.javaClass.getMethod("fetch", List::class.java).invoke(m, listOf(PLAY_PACK))
|
|
355
|
+
"play_fetch_requested"
|
|
356
|
+
} catch (t: Throwable) {
|
|
357
|
+
"play_fetch_failed: ${t.javaClass.simpleName}"
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
fun sha256(f: File): String {
|
|
361
|
+
val md = MessageDigest.getInstance("SHA-256")
|
|
362
|
+
FileInputStream(f).use { inp ->
|
|
363
|
+
val buf = ByteArray(64 * 1024)
|
|
364
|
+
while (true) {
|
|
365
|
+
val n = inp.read(buf)
|
|
366
|
+
if (n <= 0) break
|
|
367
|
+
md.update(buf, 0, n)
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
return md.digest().joinToString("") { "%02x".format(it) }
|
|
371
|
+
}
|
|
372
|
+
}
|