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,34 @@
|
|
|
1
|
+
// Copyright (c) 2026 Gravity Compile. MIT License; see LICENSE.
|
|
2
|
+
|
|
3
|
+
#import <Foundation/Foundation.h>
|
|
4
|
+
|
|
5
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
6
|
+
|
|
7
|
+
/// Installs the Gravix iOS capture processing (noise suppression -> voice
|
|
8
|
+
/// effect -> post-effect room music).
|
|
9
|
+
///
|
|
10
|
+
/// react-native-webrtc 155 links JitsiWebRTC 155, a stock WebRTC build with no
|
|
11
|
+
/// audio processing module slot. Its only audio seam is
|
|
12
|
+
/// `WebRTCModuleOptions.audioDevice` (a complete `RTCAudioDevice`, read once
|
|
13
|
+
/// when react-native-webrtc builds its peer connection factory), so the chain
|
|
14
|
+
/// runs inside the Gravix audio device (`GxAudioDevice`) installed there.
|
|
15
|
+
/// See docs/IOS_NATIVE_HOOKS.md.
|
|
16
|
+
@interface GxAudioSetup : NSObject
|
|
17
|
+
|
|
18
|
+
/// Puts `GxAudioDevice` into `WebRTCModuleOptions.audioDevice`. NO (logged)
|
|
19
|
+
/// when the app did not opt in (Info.plist `GravixAudioDevice` not YES), the app set
|
|
20
|
+
/// its own audio device, or react-native-webrtc is not linked.
|
|
21
|
+
+ (BOOL)installProcessing;
|
|
22
|
+
|
|
23
|
+
/// Whether `GxAudioDevice` is in react-native-webrtc's options slot.
|
|
24
|
+
+ (BOOL)isInSlot;
|
|
25
|
+
|
|
26
|
+
/// Whether the Gravix chain is installed: our processing marked installed and
|
|
27
|
+
/// `GxAudioDevice` in react-native-webrtc's options slot (read once when its
|
|
28
|
+
/// module builds the factory; setup() must run before React Native starts).
|
|
29
|
+
/// Read for the capability map. An app-set device or the plist rollback: NO.
|
|
30
|
+
+ (BOOL)isChainLive;
|
|
31
|
+
|
|
32
|
+
@end
|
|
33
|
+
|
|
34
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Copyright (c) 2026 Gravity Compile. MIT License; see LICENSE.
|
|
2
|
+
|
|
3
|
+
#import "GxAudioSetup.h"
|
|
4
|
+
|
|
5
|
+
#import <objc/message.h>
|
|
6
|
+
#import "GxAudioDevice.h"
|
|
7
|
+
#import "gravix_rtc_react_native-Swift.h"
|
|
8
|
+
|
|
9
|
+
/// react-native-webrtc's options singleton, by name: its pod defines no module,
|
|
10
|
+
/// so its headers are not imported (the class is linked into the app).
|
|
11
|
+
static id GxWebRTCModuleOptions(void)
|
|
12
|
+
{
|
|
13
|
+
Class cls = NSClassFromString(@"WebRTCModuleOptions");
|
|
14
|
+
SEL sel = NSSelectorFromString(@"sharedInstance");
|
|
15
|
+
if (cls == Nil || ![cls respondsToSelector:sel]) {
|
|
16
|
+
return nil;
|
|
17
|
+
}
|
|
18
|
+
id options = ((id(*)(id, SEL))objc_msgSend)(cls, sel);
|
|
19
|
+
return [options respondsToSelector:NSSelectorFromString(@"audioDevice")] ? options : nil;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@implementation GxAudioSetup
|
|
23
|
+
|
|
24
|
+
+ (BOOL)isInSlot
|
|
25
|
+
{
|
|
26
|
+
id options = GxWebRTCModuleOptions();
|
|
27
|
+
return options != nil && [options valueForKey:@"audioDevice"] == [GxAudioDevice shared];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
+ (BOOL)isChainLive
|
|
31
|
+
{
|
|
32
|
+
// WebRTC 155 initialises the audio device lazily (first call / track), not when
|
|
33
|
+
// the factory is built, so `isUsable` cannot gate the cached capability map.
|
|
34
|
+
// The slot is read once in -[WebRTCModule init]; setup() runs before React
|
|
35
|
+
// Native starts (documented contract), so a device in the slot is the one the
|
|
36
|
+
// factory uses. The device logs `step=initialize` when WebRTC takes it.
|
|
37
|
+
return GxIosAudio.isProcessingInstalled && [self isInSlot];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
+ (BOOL)installProcessing
|
|
41
|
+
{
|
|
42
|
+
// OPT-IN (beta, 2026-12-01): not yet verified on a real iPhone (docs/IOS_NATIVE_HOOKS.md 8b).
|
|
43
|
+
// Info.plist boolean GravixAudioDevice = YES installs the Gravix device; absent or NO keeps
|
|
44
|
+
// WebRTC's built-in audio device and the features report unavailable.
|
|
45
|
+
id enabled = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"GravixAudioDevice"];
|
|
46
|
+
if (![enabled respondsToSelector:@selector(boolValue)] || ![enabled boolValue]) {
|
|
47
|
+
NSLog(@"[GravixAudio] step=install installed=0 reason=not_enabled (Info.plist GravixAudioDevice is not YES: "
|
|
48
|
+
@"WebRTC's built-in audio device, no voice effects / noise suppression / room music; the Gravix "
|
|
49
|
+
@"device is opt-in beta)");
|
|
50
|
+
return NO;
|
|
51
|
+
}
|
|
52
|
+
id options = GxWebRTCModuleOptions();
|
|
53
|
+
if (options == nil) {
|
|
54
|
+
NSLog(@"[GravixAudio] step=install installed=0 reason=no_webrtc_module_options (react-native-webrtc not linked)");
|
|
55
|
+
return NO;
|
|
56
|
+
}
|
|
57
|
+
GxAudioDevice *device = [GxAudioDevice shared];
|
|
58
|
+
id current = [options valueForKey:@"audioDevice"];
|
|
59
|
+
if (current != nil && current != device) {
|
|
60
|
+
NSLog(@"[GravixAudio] step=install installed=0 reason=app_audio_device class=%@", NSStringFromClass([current class]));
|
|
61
|
+
return NO;
|
|
62
|
+
}
|
|
63
|
+
[GxIosAudio prepare];
|
|
64
|
+
[options setValue:device forKey:@"audioDevice"];
|
|
65
|
+
[GxIosAudio markInstalledWithSlot:@"audio_device"];
|
|
66
|
+
NSLog(@"[GravixAudio] step=install installed=1 slot=WebRTCModuleOptions.audioDevice device=GxAudioDevice");
|
|
67
|
+
return YES;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Copyright (c) 2024-2026 Gravity Compile. MIT License; see LICENSE.
|
|
2
|
+
|
|
3
|
+
import Foundation
|
|
4
|
+
|
|
5
|
+
// Shared types of the iOS audio bridge (GravixRtcIosAudio). The audio feature
|
|
6
|
+
// sources are ported from the Flutter SDK (gravix_rtc 0.12.2, ios/gravix_rtc);
|
|
7
|
+
// on react-native-webrtc 155 they run inside the Gravix audio device
|
|
8
|
+
// (GxAudioDevice, docs/IOS_NATIVE_HOOKS.md).
|
|
9
|
+
|
|
10
|
+
/// A call from JS (GravixRtcIosAudio): the Flutter method-call shape.
|
|
11
|
+
struct GxMethodCall {
|
|
12
|
+
let method: String
|
|
13
|
+
let arguments: Any?
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/// A platform error answered to JS (rejects the promise with `code`).
|
|
17
|
+
final class GxError: NSObject {
|
|
18
|
+
let code: String
|
|
19
|
+
let message: String?
|
|
20
|
+
let details: Any?
|
|
21
|
+
init(code: String, message: String?, details: Any?) {
|
|
22
|
+
self.code = code
|
|
23
|
+
self.message = message
|
|
24
|
+
self.details = details
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/// Answered for an unknown method.
|
|
29
|
+
let GxNotImplemented = GxError(code: "not_implemented", message: "method not implemented on iOS", details: nil)
|
|
30
|
+
|
|
31
|
+
/// The reply of a call: a value, nil, or a GxError.
|
|
32
|
+
typealias GxResult = (Any?) -> Void
|
|
33
|
+
|
|
34
|
+
/// Native -> JS events. GravixRtcIosAudio sets `sink` while JS listens; with
|
|
35
|
+
/// no listener the events are dropped (the state stays readable by getState).
|
|
36
|
+
@objc(GxEvents)
|
|
37
|
+
public final class GxEvents: NSObject {
|
|
38
|
+
private static let lock = NSLock()
|
|
39
|
+
private static var _sink: ((String, [String: Any]) -> Void)?
|
|
40
|
+
|
|
41
|
+
@objc public static func setSink(_ sink: ((String, [String: Any]) -> Void)?) {
|
|
42
|
+
lock.lock(); _sink = sink; lock.unlock()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/// `onNsEvent`, `onVoiceEffects`, `onAudioEngineState`, ...
|
|
46
|
+
static func emit(_ name: String, _ body: Any?) {
|
|
47
|
+
lock.lock(); let s = _sink; lock.unlock()
|
|
48
|
+
s?(name, (body as? [String: Any]) ?? [:])
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/// Music events (`onCompleted`) carry the `music.` prefix on the JS side.
|
|
52
|
+
static func emitMusic(_ name: String, _ body: Any?) { emit("music." + name, body) }
|
|
53
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// Copyright (c) 2024-2026 Gravity Compile. MIT License; see LICENSE.
|
|
2
|
+
|
|
3
|
+
import AVFoundation
|
|
4
|
+
import Foundation
|
|
5
|
+
@_implementationOnly import gxns
|
|
6
|
+
|
|
7
|
+
/// Entry points for the Objective-C side (GravixRtcSetup, GxAudioDevice,
|
|
8
|
+
/// GravixRtcIosAudio). Swift never calls back into Objective-C, so the audio
|
|
9
|
+
/// sources need no React Native or react-native-webrtc headers.
|
|
10
|
+
@objc(GxIosAudio)
|
|
11
|
+
public final class GxIosAudio: NSObject {
|
|
12
|
+
// MARK: install (GravixRtcSetup, main thread, before React Native starts)
|
|
13
|
+
|
|
14
|
+
/// Creates the processor singletons off the audio thread (a `static let`
|
|
15
|
+
/// is initialised lazily on first use, which may allocate).
|
|
16
|
+
@objc public static func prepare() {
|
|
17
|
+
_ = GxNoiseProcessor.shared
|
|
18
|
+
_ = GxVoiceFx.shared
|
|
19
|
+
if #available(iOS 13.0, *) { _ = GxMusicPost.shared }
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/// GravixRtcSetup put the Gravix audio device into react-native-webrtc's
|
|
23
|
+
/// options (`slot` names how).
|
|
24
|
+
@objc public static func markInstalled(slot: String) { GxNoiseProcessor.shared.markInstalled(slot: slot) }
|
|
25
|
+
|
|
26
|
+
@objc public static var isProcessingInstalled: Bool { GxNoiseProcessor.shared.isInstalled }
|
|
27
|
+
|
|
28
|
+
// MARK: audio device (GxAudioDevice, WebRTC audio device thread)
|
|
29
|
+
|
|
30
|
+
private static let deviceActive: OpaquePointer = gxns_flag_new(0)!
|
|
31
|
+
|
|
32
|
+
/// The Gravix audio device runs a unit (capture or playout).
|
|
33
|
+
@objc public static var isDeviceActive: Bool { gxns_flag_get(deviceActive) != 0 }
|
|
34
|
+
@objc public static func setDeviceActive(_ on: Bool) { gxns_flag_set(deviceActive, on ? 1 : 0) }
|
|
35
|
+
|
|
36
|
+
/// A capture stream starts at `rate` (unit start, route or rate change).
|
|
37
|
+
@objc public static func captureStreamStarted(rate: Int, vpioAgc: String) {
|
|
38
|
+
GxNoiseProcessor.shared.audioProcessingInitialize(sampleRate: rate, channels: 1)
|
|
39
|
+
GxNoiseProcessor.shared.deviceConfiguredInput(rate: rate, vpioAgc: vpioAgc)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/// Whether the device should switch VPIO's AGC off (ours runs).
|
|
43
|
+
@objc public static var wantsVpioAgcOff: Bool { GxNoiseProcessor.shared.wantsVpioAgcOff }
|
|
44
|
+
|
|
45
|
+
// MARK: JS calls
|
|
46
|
+
|
|
47
|
+
/// Methods that need the Gravix audio device; without it they answer `not_installed`.
|
|
48
|
+
static let needsSlot: Set<String> = ["fxConfigure", "nsConfigure", "nsSetSingerMode", "music.start"]
|
|
49
|
+
|
|
50
|
+
/// Calls `completion(value, nil)` or `completion(nil, [code, message])` on
|
|
51
|
+
/// the main queue.
|
|
52
|
+
@objc public static func call(_ method: String, args: [String: Any]?, completion: @escaping (Any?, [String]?) -> Void) {
|
|
53
|
+
let done: GxResult = { value in
|
|
54
|
+
let finish = {
|
|
55
|
+
if let e = value as? GxError {
|
|
56
|
+
completion(nil, [e.code, e.message ?? e.code])
|
|
57
|
+
} else {
|
|
58
|
+
completion(value, nil)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if Thread.isMainThread { finish() } else { DispatchQueue.main.async(execute: finish) }
|
|
62
|
+
}
|
|
63
|
+
if needsSlot.contains(method), !isProcessingInstalled {
|
|
64
|
+
done(GxError(code: "not_installed",
|
|
65
|
+
message: "Gravix audio processing is not installed: call GravixRtcSetup.setup() before React Native starts",
|
|
66
|
+
details: nil))
|
|
67
|
+
return
|
|
68
|
+
}
|
|
69
|
+
if method.hasPrefix("music.") {
|
|
70
|
+
guard #available(iOS 13.0, *) else { done(GxError(code: "UNSUPPORTED", message: "iOS 13+", details: nil)); return }
|
|
71
|
+
GxMusicController.shared.handle(GxMethodCall(method: String(method.dropFirst(6)), arguments: args), result: done)
|
|
72
|
+
return
|
|
73
|
+
}
|
|
74
|
+
let c = GxMethodCall(method: method, arguments: args)
|
|
75
|
+
if GxNoiseProcessor.shared.handle(c, result: done) { return }
|
|
76
|
+
if GxVoiceFx.shared.handle(c, result: done) { return }
|
|
77
|
+
done(GxNotImplemented)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// MARK: - Real-time entry points (GxAudioDevice IO threads, plain C calls)
|
|
82
|
+
|
|
83
|
+
/// One capture block, mono int16-scale floats in place: noise suppression ->
|
|
84
|
+
/// voice effect -> room music. No locks or logs; allocation-free except the
|
|
85
|
+
/// studio noise suppressor's Core ML prediction (as in the Flutter SDK).
|
|
86
|
+
@_cdecl("gx_ios_capture_process")
|
|
87
|
+
public func gx_ios_capture_process(_ samples: UnsafeMutablePointer<Float>, _ frames: Int32, _ rate: Int32) {
|
|
88
|
+
GxNoiseProcessor.shared.processCapture(samples, frames: Int(frames), rate: rate)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/// The room-music monitor for one playout block (int16-scale floats).
|
|
92
|
+
/// Returns 1 when `dst` was filled, 0 when no song with monitor runs.
|
|
93
|
+
@_cdecl("gx_ios_monitor_read")
|
|
94
|
+
public func gx_ios_monitor_read(_ dst: UnsafeMutablePointer<Float>, _ frames: Int32) -> Int32 {
|
|
95
|
+
if #available(iOS 13.0, *) {
|
|
96
|
+
return GxMusicPost.shared.monitorRead(dst, frames: Int(frames)) ? 1 : 0
|
|
97
|
+
}
|
|
98
|
+
return 0
|
|
99
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// Copyright (c) 2024-2026 Gravity Compile. MIT License; see LICENSE.
|
|
2
|
+
|
|
3
|
+
import AVFoundation
|
|
4
|
+
import Foundation
|
|
5
|
+
|
|
6
|
+
/// Room music on iOS, React Native port of the Flutter `GravixMusicMixer`
|
|
7
|
+
/// (gravix_rtc 0.12.2), post-effect route only.
|
|
8
|
+
///
|
|
9
|
+
/// The song is mixed AFTER noise suppression and the voice effect, inside the
|
|
10
|
+
/// APM capture post-processing slot (`GxMusicPost`), so the effect stays on the
|
|
11
|
+
/// voice while a song plays and `setMicVolume` / `setDucking` work. The host
|
|
12
|
+
/// hears the song through GxAudioDevice, which mixes `GxMusicPost.monitorRead`
|
|
13
|
+
/// into the playout block (the voice processing unit then cancels it from the mic).
|
|
14
|
+
///
|
|
15
|
+
/// Not ported: `postMix: false` (the 0.11 input-mixer route, a rollback path
|
|
16
|
+
/// in Flutter) answers `UNSUPPORTED`. A mic mute on iOS silences the song for
|
|
17
|
+
/// listeners too (iOS has no voice-only mute; see docs/IOS_NATIVE_HOOKS.md).
|
|
18
|
+
///
|
|
19
|
+
/// Methods: start {source, musicVolume, micVolume, ducking, duckLevel, monitor,
|
|
20
|
+
/// loop} -> {durationMs, mixRoute}, setLoop {on}, setMicVolume {volume},
|
|
21
|
+
/// setDucking {on, level}, pause / resume / stop, setVolume {volume},
|
|
22
|
+
/// seekTo {positionMs}, isActive -> Bool, getState -> map. Event: music.onCompleted.
|
|
23
|
+
@available(iOS 13.0, *)
|
|
24
|
+
final class GxMusicController: NSObject {
|
|
25
|
+
static let shared = GxMusicController()
|
|
26
|
+
|
|
27
|
+
private let lock = NSRecursiveLock()
|
|
28
|
+
|
|
29
|
+
/// The post route keeps noise suppression and the voice effect ON while a
|
|
30
|
+
/// song plays (the song joins after them): unlike the 0.11 input-mixer
|
|
31
|
+
/// route, it never calls GxNoiseProcessor.musicSession (Flutter 0.12.0).
|
|
32
|
+
private var post = false
|
|
33
|
+
|
|
34
|
+
// MARK: - JS methods
|
|
35
|
+
|
|
36
|
+
func handle(_ call: GxMethodCall, result: @escaping GxResult) {
|
|
37
|
+
let args = (call.arguments as? [String: Any?]) ?? [:]
|
|
38
|
+
switch call.method {
|
|
39
|
+
case "start":
|
|
40
|
+
guard let path = (args["source"] as? String) ?? (args["path"] as? String), !path.isEmpty else {
|
|
41
|
+
result(GxError(code: "OPEN_FAILED", message: "no source", details: nil))
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
if let postMix = args["postMix"] as? Bool, !postMix {
|
|
45
|
+
result(GxError(code: "UNSUPPORTED", message: "postMix: false (input-mixer route) is not available in React Native", details: nil))
|
|
46
|
+
return
|
|
47
|
+
}
|
|
48
|
+
let gain = ((args["musicVolume"] as? NSNumber) ?? (args["gain"] as? NSNumber))?.floatValue ?? 1.0
|
|
49
|
+
do {
|
|
50
|
+
let dur = try startPost(path: path, gain: gain,
|
|
51
|
+
monitor: (args["monitor"] as? Bool) ?? true,
|
|
52
|
+
loop: (args["loop"] as? Bool) ?? false,
|
|
53
|
+
micGain: (args["micVolume"] as? NSNumber)?.floatValue ?? 1.0,
|
|
54
|
+
ducking: (args["ducking"] as? Bool) ?? false,
|
|
55
|
+
duckLevel: (args["duckLevel"] as? NSNumber)?.floatValue ?? 0.35)
|
|
56
|
+
result(["durationMs": dur, "mixRoute": "post"])
|
|
57
|
+
} catch {
|
|
58
|
+
result(GxError(code: "OPEN_FAILED", message: error.localizedDescription, details: nil))
|
|
59
|
+
}
|
|
60
|
+
case "setLoop":
|
|
61
|
+
GxMusicPost.shared.setLoop((args["on"] as? Bool) ?? false)
|
|
62
|
+
result(nil)
|
|
63
|
+
case "setMicVolume":
|
|
64
|
+
GxMusicPost.shared.setMicGain(Self.clampGain((args["volume"] as? NSNumber)?.floatValue ?? 1.0))
|
|
65
|
+
result(nil)
|
|
66
|
+
case "setDucking":
|
|
67
|
+
GxMusicPost.shared.setDucking((args["on"] as? Bool) ?? false,
|
|
68
|
+
level: Self.clampDuck((args["level"] as? NSNumber)?.floatValue ?? 0.35))
|
|
69
|
+
result(nil)
|
|
70
|
+
case "pause":
|
|
71
|
+
GxMusicPost.shared.pause(); result(nil)
|
|
72
|
+
case "resume":
|
|
73
|
+
GxMusicPost.shared.resume(); result(nil)
|
|
74
|
+
case "stop":
|
|
75
|
+
stopPost(); result(nil)
|
|
76
|
+
case "setVolume", "setMusicVolume":
|
|
77
|
+
let g = ((args["volume"] as? NSNumber) ?? (args["gain"] as? NSNumber))?.floatValue ?? 1.0
|
|
78
|
+
GxMusicPost.shared.setMusicGain(Self.clampGain(g))
|
|
79
|
+
result(nil)
|
|
80
|
+
case "seekTo", "seek":
|
|
81
|
+
GxMusicPost.shared.seek(toMs: (args["positionMs"] as? NSNumber)?.intValue ?? 0)
|
|
82
|
+
result(nil)
|
|
83
|
+
case "isActive":
|
|
84
|
+
result(isPost)
|
|
85
|
+
case "getState":
|
|
86
|
+
var m = GxMusicPost.shared.state()
|
|
87
|
+
let device = GxIosAudio.isDeviceActive
|
|
88
|
+
m["monitorAttached"] = device && isPost && GxMusicPost.shared.monitorWanted
|
|
89
|
+
m["graphHooked"] = device
|
|
90
|
+
m["slotInstalled"] = GxNoiseProcessor.shared.isInstalled
|
|
91
|
+
result(m)
|
|
92
|
+
default:
|
|
93
|
+
result(GxNotImplemented)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/// 0...2 (Android parity: the C core amplifies up to 2x).
|
|
98
|
+
static func clampGain(_ g: Float) -> Float { g.isFinite ? min(max(g, 0), 2) : 1 }
|
|
99
|
+
static func clampDuck(_ g: Float) -> Float { g.isFinite ? min(max(g, 0), 1) : 0.35 }
|
|
100
|
+
|
|
101
|
+
// MARK: - Post-effect route
|
|
102
|
+
|
|
103
|
+
private var isPost: Bool {
|
|
104
|
+
lock.lock(); defer { lock.unlock() }
|
|
105
|
+
return post
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
private func startPost(path: String, gain: Float, monitor: Bool, loop: Bool,
|
|
109
|
+
micGain: Float, ducking: Bool, duckLevel: Float) throws -> Int
|
|
110
|
+
{
|
|
111
|
+
guard let url = Self.fileURL(path) else {
|
|
112
|
+
throw NSError(domain: "GxMusicController", code: 2, userInfo: [NSLocalizedDescriptionKey: "invalid source path"])
|
|
113
|
+
}
|
|
114
|
+
let p = GxMusicPost.shared
|
|
115
|
+
p.onCompleted = { [weak self] in
|
|
116
|
+
guard let self else { return }
|
|
117
|
+
self.lock.lock()
|
|
118
|
+
let was = self.post
|
|
119
|
+
self.post = false
|
|
120
|
+
self.lock.unlock()
|
|
121
|
+
if was { GxEvents.emitMusic("onCompleted", nil) }
|
|
122
|
+
}
|
|
123
|
+
let dur = try p.start(url: url, musicGain: Self.clampGain(gain), micGain: Self.clampGain(micGain),
|
|
124
|
+
ducking: ducking, duckLevel: Self.clampDuck(duckLevel), monitor: monitor, loop: loop)
|
|
125
|
+
lock.lock()
|
|
126
|
+
post = true
|
|
127
|
+
lock.unlock()
|
|
128
|
+
return dur
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/// `file:///...` URL or a plain path. nil for other schemes (http and
|
|
132
|
+
/// asset URLs must be downloaded / resolved by the app first).
|
|
133
|
+
static func fileURL(_ path: String) -> URL? {
|
|
134
|
+
if path.hasPrefix("file://") {
|
|
135
|
+
if let u = URL(string: path), u.isFileURL { return u }
|
|
136
|
+
// unescaped path (spaces): take it literally
|
|
137
|
+
return URL(fileURLWithPath: String(path.dropFirst("file://".count)))
|
|
138
|
+
}
|
|
139
|
+
if path.contains("://") { return nil }
|
|
140
|
+
return URL(fileURLWithPath: path)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
private func stopPost() {
|
|
144
|
+
lock.lock()
|
|
145
|
+
let was = post
|
|
146
|
+
post = false
|
|
147
|
+
lock.unlock()
|
|
148
|
+
if was { GxMusicPost.shared.stop() }
|
|
149
|
+
}
|
|
150
|
+
}
|