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,664 @@
|
|
|
1
|
+
/* Copyright (c) 2018 Gregor Richards
|
|
2
|
+
* Copyright (c) 2017 Mozilla */
|
|
3
|
+
/*
|
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
|
5
|
+
modification, are permitted provided that the following conditions
|
|
6
|
+
are met:
|
|
7
|
+
|
|
8
|
+
- Redistributions of source code must retain the above copyright
|
|
9
|
+
notice, this list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
- Redistributions in binary form must reproduce the above copyright
|
|
12
|
+
notice, this list of conditions and the following disclaimer in the
|
|
13
|
+
documentation and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
16
|
+
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
17
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
18
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
|
|
19
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
20
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
21
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
22
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
23
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
24
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
25
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
#ifdef HAVE_CONFIG_H
|
|
29
|
+
#include "config.h"
|
|
30
|
+
#endif
|
|
31
|
+
|
|
32
|
+
#include <stdlib.h>
|
|
33
|
+
#include <string.h>
|
|
34
|
+
#include <stdio.h>
|
|
35
|
+
#include "kiss_fft.h"
|
|
36
|
+
#include "common.h"
|
|
37
|
+
#include <math.h>
|
|
38
|
+
#include "rnnoise.h"
|
|
39
|
+
#include "pitch.h"
|
|
40
|
+
#include "arch.h"
|
|
41
|
+
#include "rnn.h"
|
|
42
|
+
#include "rnn_data.h"
|
|
43
|
+
|
|
44
|
+
#define FRAME_SIZE_SHIFT 2
|
|
45
|
+
#define FRAME_SIZE (120<<FRAME_SIZE_SHIFT)
|
|
46
|
+
#define WINDOW_SIZE (2*FRAME_SIZE)
|
|
47
|
+
#define FREQ_SIZE (FRAME_SIZE + 1)
|
|
48
|
+
|
|
49
|
+
#define PITCH_MIN_PERIOD 60
|
|
50
|
+
#define PITCH_MAX_PERIOD 768
|
|
51
|
+
#define PITCH_FRAME_SIZE 960
|
|
52
|
+
#define PITCH_BUF_SIZE (PITCH_MAX_PERIOD+PITCH_FRAME_SIZE)
|
|
53
|
+
|
|
54
|
+
#define SQUARE(x) ((x)*(x))
|
|
55
|
+
|
|
56
|
+
#define NB_BANDS 22
|
|
57
|
+
|
|
58
|
+
#define CEPS_MEM 8
|
|
59
|
+
#define NB_DELTA_CEPS 6
|
|
60
|
+
|
|
61
|
+
#define NB_FEATURES (NB_BANDS+3*NB_DELTA_CEPS+2)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
#ifndef TRAINING
|
|
65
|
+
#define TRAINING 0
|
|
66
|
+
#endif
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
/* The built-in model, used if no file is given as input */
|
|
70
|
+
extern const struct RNNModel rnnoise_model_orig;
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
static const opus_int16 eband5ms[] = {
|
|
74
|
+
/*0 200 400 600 800 1k 1.2 1.4 1.6 2k 2.4 2.8 3.2 4k 4.8 5.6 6.8 8k 9.6 12k 15.6 20k*/
|
|
75
|
+
0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 34, 40, 48, 60, 78, 100
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
typedef struct {
|
|
80
|
+
int init;
|
|
81
|
+
kiss_fft_state *kfft;
|
|
82
|
+
float half_window[FRAME_SIZE];
|
|
83
|
+
float dct_table[NB_BANDS*NB_BANDS];
|
|
84
|
+
} CommonState;
|
|
85
|
+
|
|
86
|
+
struct DenoiseState {
|
|
87
|
+
float analysis_mem[FRAME_SIZE];
|
|
88
|
+
float cepstral_mem[CEPS_MEM][NB_BANDS];
|
|
89
|
+
int memid;
|
|
90
|
+
float synthesis_mem[FRAME_SIZE];
|
|
91
|
+
float pitch_buf[PITCH_BUF_SIZE];
|
|
92
|
+
float pitch_enh_buf[PITCH_BUF_SIZE];
|
|
93
|
+
float last_gain;
|
|
94
|
+
int last_period;
|
|
95
|
+
float mem_hp_x[2];
|
|
96
|
+
float lastg[NB_BANDS];
|
|
97
|
+
RNNState rnn;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
static void compute_band_energy(float *bandE, const kiss_fft_cpx *X) {
|
|
101
|
+
int i;
|
|
102
|
+
float sum[NB_BANDS] = {0};
|
|
103
|
+
for (i=0;i<NB_BANDS-1;i++)
|
|
104
|
+
{
|
|
105
|
+
int j;
|
|
106
|
+
int band_size;
|
|
107
|
+
band_size = (eband5ms[i+1]-eband5ms[i])<<FRAME_SIZE_SHIFT;
|
|
108
|
+
for (j=0;j<band_size;j++) {
|
|
109
|
+
float tmp;
|
|
110
|
+
float frac = (float)j/band_size;
|
|
111
|
+
tmp = SQUARE(X[(eband5ms[i]<<FRAME_SIZE_SHIFT) + j].r);
|
|
112
|
+
tmp += SQUARE(X[(eband5ms[i]<<FRAME_SIZE_SHIFT) + j].i);
|
|
113
|
+
sum[i] += (1-frac)*tmp;
|
|
114
|
+
sum[i+1] += frac*tmp;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
sum[0] *= 2;
|
|
118
|
+
sum[NB_BANDS-1] *= 2;
|
|
119
|
+
for (i=0;i<NB_BANDS;i++)
|
|
120
|
+
{
|
|
121
|
+
bandE[i] = sum[i];
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
static void compute_band_corr(float *bandE, const kiss_fft_cpx *X, const kiss_fft_cpx *P) {
|
|
126
|
+
int i;
|
|
127
|
+
float sum[NB_BANDS] = {0};
|
|
128
|
+
for (i=0;i<NB_BANDS-1;i++)
|
|
129
|
+
{
|
|
130
|
+
int j;
|
|
131
|
+
int band_size;
|
|
132
|
+
band_size = (eband5ms[i+1]-eband5ms[i])<<FRAME_SIZE_SHIFT;
|
|
133
|
+
for (j=0;j<band_size;j++) {
|
|
134
|
+
float tmp;
|
|
135
|
+
float frac = (float)j/band_size;
|
|
136
|
+
tmp = X[(eband5ms[i]<<FRAME_SIZE_SHIFT) + j].r * P[(eband5ms[i]<<FRAME_SIZE_SHIFT) + j].r;
|
|
137
|
+
tmp += X[(eband5ms[i]<<FRAME_SIZE_SHIFT) + j].i * P[(eband5ms[i]<<FRAME_SIZE_SHIFT) + j].i;
|
|
138
|
+
sum[i] += (1-frac)*tmp;
|
|
139
|
+
sum[i+1] += frac*tmp;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
sum[0] *= 2;
|
|
143
|
+
sum[NB_BANDS-1] *= 2;
|
|
144
|
+
for (i=0;i<NB_BANDS;i++)
|
|
145
|
+
{
|
|
146
|
+
bandE[i] = sum[i];
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
static void interp_band_gain(float *g, const float *bandE) {
|
|
151
|
+
int i;
|
|
152
|
+
memset(g, 0, FREQ_SIZE);
|
|
153
|
+
for (i=0;i<NB_BANDS-1;i++)
|
|
154
|
+
{
|
|
155
|
+
int j;
|
|
156
|
+
int band_size;
|
|
157
|
+
band_size = (eband5ms[i+1]-eband5ms[i])<<FRAME_SIZE_SHIFT;
|
|
158
|
+
for (j=0;j<band_size;j++) {
|
|
159
|
+
float frac = (float)j/band_size;
|
|
160
|
+
g[(eband5ms[i]<<FRAME_SIZE_SHIFT) + j] = (1-frac)*bandE[i] + frac*bandE[i+1];
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
CommonState common;
|
|
167
|
+
|
|
168
|
+
static void check_init() {
|
|
169
|
+
int i;
|
|
170
|
+
if (common.init) return;
|
|
171
|
+
common.kfft = rnn_fft_alloc_twiddles(2*FRAME_SIZE, NULL, NULL, NULL, 0);
|
|
172
|
+
for (i=0;i<FRAME_SIZE;i++)
|
|
173
|
+
common.half_window[i] = sin(.5*M_PI*sin(.5*M_PI*(i+.5)/FRAME_SIZE) * sin(.5*M_PI*(i+.5)/FRAME_SIZE));
|
|
174
|
+
for (i=0;i<NB_BANDS;i++) {
|
|
175
|
+
int j;
|
|
176
|
+
for (j=0;j<NB_BANDS;j++) {
|
|
177
|
+
common.dct_table[i*NB_BANDS + j] = cos((i+.5)*j*M_PI/NB_BANDS);
|
|
178
|
+
if (j==0) common.dct_table[i*NB_BANDS + j] *= sqrt(.5);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
common.init = 1;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
static void dct(float *out, const float *in) {
|
|
185
|
+
int i;
|
|
186
|
+
check_init();
|
|
187
|
+
for (i=0;i<NB_BANDS;i++) {
|
|
188
|
+
int j;
|
|
189
|
+
float sum = 0;
|
|
190
|
+
for (j=0;j<NB_BANDS;j++) {
|
|
191
|
+
sum += in[j] * common.dct_table[j*NB_BANDS + i];
|
|
192
|
+
}
|
|
193
|
+
out[i] = sum*sqrt(2./22);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
#if 0
|
|
198
|
+
static void idct(float *out, const float *in) {
|
|
199
|
+
int i;
|
|
200
|
+
check_init();
|
|
201
|
+
for (i=0;i<NB_BANDS;i++) {
|
|
202
|
+
int j;
|
|
203
|
+
float sum = 0;
|
|
204
|
+
for (j=0;j<NB_BANDS;j++) {
|
|
205
|
+
sum += in[j] * common.dct_table[i*NB_BANDS + j];
|
|
206
|
+
}
|
|
207
|
+
out[i] = sum*sqrt(2./22);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
#endif
|
|
211
|
+
|
|
212
|
+
static void forward_transform(kiss_fft_cpx *out, const float *in) {
|
|
213
|
+
int i;
|
|
214
|
+
kiss_fft_cpx x[WINDOW_SIZE];
|
|
215
|
+
kiss_fft_cpx y[WINDOW_SIZE];
|
|
216
|
+
check_init();
|
|
217
|
+
for (i=0;i<WINDOW_SIZE;i++) {
|
|
218
|
+
x[i].r = in[i];
|
|
219
|
+
x[i].i = 0;
|
|
220
|
+
}
|
|
221
|
+
rnn_fft(common.kfft, x, y, 0);
|
|
222
|
+
for (i=0;i<FREQ_SIZE;i++) {
|
|
223
|
+
out[i] = y[i];
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
static void inverse_transform(float *out, const kiss_fft_cpx *in) {
|
|
228
|
+
int i;
|
|
229
|
+
kiss_fft_cpx x[WINDOW_SIZE];
|
|
230
|
+
kiss_fft_cpx y[WINDOW_SIZE];
|
|
231
|
+
check_init();
|
|
232
|
+
for (i=0;i<FREQ_SIZE;i++) {
|
|
233
|
+
x[i] = in[i];
|
|
234
|
+
}
|
|
235
|
+
for (;i<WINDOW_SIZE;i++) {
|
|
236
|
+
x[i].r = x[WINDOW_SIZE - i].r;
|
|
237
|
+
x[i].i = -x[WINDOW_SIZE - i].i;
|
|
238
|
+
}
|
|
239
|
+
rnn_fft(common.kfft, x, y, 0);
|
|
240
|
+
/* output in reverse order for IFFT. */
|
|
241
|
+
out[0] = WINDOW_SIZE*y[0].r;
|
|
242
|
+
for (i=1;i<WINDOW_SIZE;i++) {
|
|
243
|
+
out[i] = WINDOW_SIZE*y[WINDOW_SIZE - i].r;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
static void apply_window(float *x) {
|
|
248
|
+
int i;
|
|
249
|
+
check_init();
|
|
250
|
+
for (i=0;i<FRAME_SIZE;i++) {
|
|
251
|
+
x[i] *= common.half_window[i];
|
|
252
|
+
x[WINDOW_SIZE - 1 - i] *= common.half_window[i];
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
int rnnoise_get_size() {
|
|
257
|
+
return sizeof(DenoiseState);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
int rnnoise_get_frame_size() {
|
|
261
|
+
return FRAME_SIZE;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
int rnnoise_init(DenoiseState *st, RNNModel *model) {
|
|
265
|
+
memset(st, 0, sizeof(*st));
|
|
266
|
+
if (model)
|
|
267
|
+
st->rnn.model = model;
|
|
268
|
+
else
|
|
269
|
+
st->rnn.model = &rnnoise_model_orig;
|
|
270
|
+
st->rnn.vad_gru_state = calloc(sizeof(float), st->rnn.model->vad_gru_size);
|
|
271
|
+
st->rnn.noise_gru_state = calloc(sizeof(float), st->rnn.model->noise_gru_size);
|
|
272
|
+
st->rnn.denoise_gru_state = calloc(sizeof(float), st->rnn.model->denoise_gru_size);
|
|
273
|
+
return 0;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
DenoiseState *rnnoise_create(RNNModel *model) {
|
|
277
|
+
DenoiseState *st;
|
|
278
|
+
st = malloc(rnnoise_get_size());
|
|
279
|
+
rnnoise_init(st, model);
|
|
280
|
+
return st;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
void rnnoise_destroy(DenoiseState *st) {
|
|
284
|
+
free(st->rnn.vad_gru_state);
|
|
285
|
+
free(st->rnn.noise_gru_state);
|
|
286
|
+
free(st->rnn.denoise_gru_state);
|
|
287
|
+
free(st);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/* GRAVIX PATCH (gx_ns): allocation-free state reset for route changes on the
|
|
291
|
+
real-time audio thread. Clears all signal state and the three GRU states in
|
|
292
|
+
place; keeps the model pointer and the GRU buffers. */
|
|
293
|
+
void rnnoise_reset(DenoiseState *st) {
|
|
294
|
+
const RNNModel *model = st->rnn.model;
|
|
295
|
+
float *vad = st->rnn.vad_gru_state;
|
|
296
|
+
float *noise = st->rnn.noise_gru_state;
|
|
297
|
+
float *denoise = st->rnn.denoise_gru_state;
|
|
298
|
+
memset(st, 0, sizeof(*st));
|
|
299
|
+
st->rnn.model = model;
|
|
300
|
+
st->rnn.vad_gru_state = vad;
|
|
301
|
+
st->rnn.noise_gru_state = noise;
|
|
302
|
+
st->rnn.denoise_gru_state = denoise;
|
|
303
|
+
memset(vad, 0, sizeof(float) * model->vad_gru_size);
|
|
304
|
+
memset(noise, 0, sizeof(float) * model->noise_gru_size);
|
|
305
|
+
memset(denoise, 0, sizeof(float) * model->denoise_gru_size);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
#if TRAINING
|
|
309
|
+
int lowpass = FREQ_SIZE;
|
|
310
|
+
int band_lp = NB_BANDS;
|
|
311
|
+
#endif
|
|
312
|
+
|
|
313
|
+
static void frame_analysis(DenoiseState *st, kiss_fft_cpx *X, float *Ex, const float *in) {
|
|
314
|
+
int i;
|
|
315
|
+
float x[WINDOW_SIZE];
|
|
316
|
+
RNN_COPY(x, st->analysis_mem, FRAME_SIZE);
|
|
317
|
+
for (i=0;i<FRAME_SIZE;i++) x[FRAME_SIZE + i] = in[i];
|
|
318
|
+
RNN_COPY(st->analysis_mem, in, FRAME_SIZE);
|
|
319
|
+
apply_window(x);
|
|
320
|
+
forward_transform(X, x);
|
|
321
|
+
#if TRAINING
|
|
322
|
+
for (i=lowpass;i<FREQ_SIZE;i++)
|
|
323
|
+
X[i].r = X[i].i = 0;
|
|
324
|
+
#endif
|
|
325
|
+
compute_band_energy(Ex, X);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
static int compute_frame_features(DenoiseState *st, kiss_fft_cpx *X, kiss_fft_cpx *P,
|
|
329
|
+
float *Ex, float *Ep, float *Exp, float *features, const float *in) {
|
|
330
|
+
int i;
|
|
331
|
+
float E = 0;
|
|
332
|
+
float *ceps_0, *ceps_1, *ceps_2;
|
|
333
|
+
float spec_variability = 0;
|
|
334
|
+
float Ly[NB_BANDS];
|
|
335
|
+
float p[WINDOW_SIZE];
|
|
336
|
+
float pitch_buf[PITCH_BUF_SIZE>>1];
|
|
337
|
+
int pitch_index;
|
|
338
|
+
float gain;
|
|
339
|
+
float *(pre[1]);
|
|
340
|
+
float tmp[NB_BANDS];
|
|
341
|
+
float follow, logMax;
|
|
342
|
+
frame_analysis(st, X, Ex, in);
|
|
343
|
+
RNN_MOVE(st->pitch_buf, &st->pitch_buf[FRAME_SIZE], PITCH_BUF_SIZE-FRAME_SIZE);
|
|
344
|
+
RNN_COPY(&st->pitch_buf[PITCH_BUF_SIZE-FRAME_SIZE], in, FRAME_SIZE);
|
|
345
|
+
pre[0] = &st->pitch_buf[0];
|
|
346
|
+
rnn_pitch_downsample(pre, pitch_buf, PITCH_BUF_SIZE, 1);
|
|
347
|
+
rnn_pitch_search(pitch_buf+(PITCH_MAX_PERIOD>>1), pitch_buf, PITCH_FRAME_SIZE,
|
|
348
|
+
PITCH_MAX_PERIOD-3*PITCH_MIN_PERIOD, &pitch_index);
|
|
349
|
+
pitch_index = PITCH_MAX_PERIOD-pitch_index;
|
|
350
|
+
|
|
351
|
+
gain = rnn_remove_doubling(pitch_buf, PITCH_MAX_PERIOD, PITCH_MIN_PERIOD,
|
|
352
|
+
PITCH_FRAME_SIZE, &pitch_index, st->last_period, st->last_gain);
|
|
353
|
+
st->last_period = pitch_index;
|
|
354
|
+
st->last_gain = gain;
|
|
355
|
+
for (i=0;i<WINDOW_SIZE;i++)
|
|
356
|
+
p[i] = st->pitch_buf[PITCH_BUF_SIZE-WINDOW_SIZE-pitch_index+i];
|
|
357
|
+
apply_window(p);
|
|
358
|
+
forward_transform(P, p);
|
|
359
|
+
compute_band_energy(Ep, P);
|
|
360
|
+
compute_band_corr(Exp, X, P);
|
|
361
|
+
for (i=0;i<NB_BANDS;i++) Exp[i] = Exp[i]/sqrt(.001+Ex[i]*Ep[i]);
|
|
362
|
+
dct(tmp, Exp);
|
|
363
|
+
for (i=0;i<NB_DELTA_CEPS;i++) features[NB_BANDS+2*NB_DELTA_CEPS+i] = tmp[i];
|
|
364
|
+
features[NB_BANDS+2*NB_DELTA_CEPS] -= 1.3;
|
|
365
|
+
features[NB_BANDS+2*NB_DELTA_CEPS+1] -= 0.9;
|
|
366
|
+
features[NB_BANDS+3*NB_DELTA_CEPS] = .01*(pitch_index-300);
|
|
367
|
+
logMax = -2;
|
|
368
|
+
follow = -2;
|
|
369
|
+
for (i=0;i<NB_BANDS;i++) {
|
|
370
|
+
Ly[i] = log10(1e-2+Ex[i]);
|
|
371
|
+
Ly[i] = MAX16(logMax-7, MAX16(follow-1.5, Ly[i]));
|
|
372
|
+
logMax = MAX16(logMax, Ly[i]);
|
|
373
|
+
follow = MAX16(follow-1.5, Ly[i]);
|
|
374
|
+
E += Ex[i];
|
|
375
|
+
}
|
|
376
|
+
if (!TRAINING && E < 0.04) {
|
|
377
|
+
/* If there's no audio, avoid messing up the state. */
|
|
378
|
+
RNN_CLEAR(features, NB_FEATURES);
|
|
379
|
+
return 1;
|
|
380
|
+
}
|
|
381
|
+
dct(features, Ly);
|
|
382
|
+
features[0] -= 12;
|
|
383
|
+
features[1] -= 4;
|
|
384
|
+
ceps_0 = st->cepstral_mem[st->memid];
|
|
385
|
+
ceps_1 = (st->memid < 1) ? st->cepstral_mem[CEPS_MEM+st->memid-1] : st->cepstral_mem[st->memid-1];
|
|
386
|
+
ceps_2 = (st->memid < 2) ? st->cepstral_mem[CEPS_MEM+st->memid-2] : st->cepstral_mem[st->memid-2];
|
|
387
|
+
for (i=0;i<NB_BANDS;i++) ceps_0[i] = features[i];
|
|
388
|
+
st->memid++;
|
|
389
|
+
for (i=0;i<NB_DELTA_CEPS;i++) {
|
|
390
|
+
features[i] = ceps_0[i] + ceps_1[i] + ceps_2[i];
|
|
391
|
+
features[NB_BANDS+i] = ceps_0[i] - ceps_2[i];
|
|
392
|
+
features[NB_BANDS+NB_DELTA_CEPS+i] = ceps_0[i] - 2*ceps_1[i] + ceps_2[i];
|
|
393
|
+
}
|
|
394
|
+
/* Spectral variability features. */
|
|
395
|
+
if (st->memid == CEPS_MEM) st->memid = 0;
|
|
396
|
+
for (i=0;i<CEPS_MEM;i++)
|
|
397
|
+
{
|
|
398
|
+
int j;
|
|
399
|
+
float mindist = 1e15f;
|
|
400
|
+
for (j=0;j<CEPS_MEM;j++)
|
|
401
|
+
{
|
|
402
|
+
int k;
|
|
403
|
+
float dist=0;
|
|
404
|
+
for (k=0;k<NB_BANDS;k++)
|
|
405
|
+
{
|
|
406
|
+
float tmp;
|
|
407
|
+
tmp = st->cepstral_mem[i][k] - st->cepstral_mem[j][k];
|
|
408
|
+
dist += tmp*tmp;
|
|
409
|
+
}
|
|
410
|
+
if (j!=i)
|
|
411
|
+
mindist = MIN32(mindist, dist);
|
|
412
|
+
}
|
|
413
|
+
spec_variability += mindist;
|
|
414
|
+
}
|
|
415
|
+
features[NB_BANDS+3*NB_DELTA_CEPS+1] = spec_variability/CEPS_MEM-2.1;
|
|
416
|
+
return TRAINING && E < 0.1;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
static void frame_synthesis(DenoiseState *st, float *out, const kiss_fft_cpx *y) {
|
|
420
|
+
float x[WINDOW_SIZE];
|
|
421
|
+
int i;
|
|
422
|
+
inverse_transform(x, y);
|
|
423
|
+
apply_window(x);
|
|
424
|
+
for (i=0;i<FRAME_SIZE;i++) out[i] = x[i] + st->synthesis_mem[i];
|
|
425
|
+
RNN_COPY(st->synthesis_mem, &x[FRAME_SIZE], FRAME_SIZE);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
static void biquad(float *y, float mem[2], const float *x, const float *b, const float *a, int N) {
|
|
429
|
+
int i;
|
|
430
|
+
for (i=0;i<N;i++) {
|
|
431
|
+
float xi, yi;
|
|
432
|
+
xi = x[i];
|
|
433
|
+
yi = x[i] + mem[0];
|
|
434
|
+
mem[0] = mem[1] + (b[0]*(double)xi - a[0]*(double)yi);
|
|
435
|
+
mem[1] = (b[1]*(double)xi - a[1]*(double)yi);
|
|
436
|
+
y[i] = yi;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
static void pitch_filter(kiss_fft_cpx *X, const kiss_fft_cpx *P, const float *Ex, const float *Ep,
|
|
441
|
+
const float *Exp, const float *g) {
|
|
442
|
+
int i;
|
|
443
|
+
float r[NB_BANDS];
|
|
444
|
+
float rf[FREQ_SIZE] = {0};
|
|
445
|
+
for (i=0;i<NB_BANDS;i++) {
|
|
446
|
+
#if 0
|
|
447
|
+
if (Exp[i]>g[i]) r[i] = 1;
|
|
448
|
+
else r[i] = Exp[i]*(1-g[i])/(.001 + g[i]*(1-Exp[i]));
|
|
449
|
+
r[i] = MIN16(1, MAX16(0, r[i]));
|
|
450
|
+
#else
|
|
451
|
+
if (Exp[i]>g[i]) r[i] = 1;
|
|
452
|
+
else r[i] = SQUARE(Exp[i])*(1-SQUARE(g[i]))/(.001 + SQUARE(g[i])*(1-SQUARE(Exp[i])));
|
|
453
|
+
r[i] = sqrt(MIN16(1, MAX16(0, r[i])));
|
|
454
|
+
#endif
|
|
455
|
+
r[i] *= sqrt(Ex[i]/(1e-8+Ep[i]));
|
|
456
|
+
}
|
|
457
|
+
interp_band_gain(rf, r);
|
|
458
|
+
for (i=0;i<FREQ_SIZE;i++) {
|
|
459
|
+
X[i].r += rf[i]*P[i].r;
|
|
460
|
+
X[i].i += rf[i]*P[i].i;
|
|
461
|
+
}
|
|
462
|
+
float newE[NB_BANDS];
|
|
463
|
+
compute_band_energy(newE, X);
|
|
464
|
+
float norm[NB_BANDS];
|
|
465
|
+
float normf[FREQ_SIZE]={0};
|
|
466
|
+
for (i=0;i<NB_BANDS;i++) {
|
|
467
|
+
norm[i] = sqrt(Ex[i]/(1e-8+newE[i]));
|
|
468
|
+
}
|
|
469
|
+
interp_band_gain(normf, norm);
|
|
470
|
+
for (i=0;i<FREQ_SIZE;i++) {
|
|
471
|
+
X[i].r *= normf[i];
|
|
472
|
+
X[i].i *= normf[i];
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
float rnnoise_process_frame(DenoiseState *st, float *out, const float *in) {
|
|
477
|
+
int i;
|
|
478
|
+
kiss_fft_cpx X[FREQ_SIZE];
|
|
479
|
+
kiss_fft_cpx P[WINDOW_SIZE];
|
|
480
|
+
float x[FRAME_SIZE];
|
|
481
|
+
float Ex[NB_BANDS], Ep[NB_BANDS];
|
|
482
|
+
float Exp[NB_BANDS];
|
|
483
|
+
float features[NB_FEATURES];
|
|
484
|
+
float g[NB_BANDS];
|
|
485
|
+
float gf[FREQ_SIZE]={1};
|
|
486
|
+
float vad_prob = 0;
|
|
487
|
+
int silence;
|
|
488
|
+
static const float a_hp[2] = {-1.99599, 0.99600};
|
|
489
|
+
static const float b_hp[2] = {-2, 1};
|
|
490
|
+
biquad(x, st->mem_hp_x, in, b_hp, a_hp, FRAME_SIZE);
|
|
491
|
+
silence = compute_frame_features(st, X, P, Ex, Ep, Exp, features, x);
|
|
492
|
+
|
|
493
|
+
if (!silence) {
|
|
494
|
+
compute_rnn(&st->rnn, g, &vad_prob, features);
|
|
495
|
+
pitch_filter(X, P, Ex, Ep, Exp, g);
|
|
496
|
+
for (i=0;i<NB_BANDS;i++) {
|
|
497
|
+
float alpha = .6f;
|
|
498
|
+
g[i] = MAX16(g[i], alpha*st->lastg[i]);
|
|
499
|
+
st->lastg[i] = g[i];
|
|
500
|
+
}
|
|
501
|
+
interp_band_gain(gf, g);
|
|
502
|
+
#if 1
|
|
503
|
+
for (i=0;i<FREQ_SIZE;i++) {
|
|
504
|
+
X[i].r *= gf[i];
|
|
505
|
+
X[i].i *= gf[i];
|
|
506
|
+
}
|
|
507
|
+
#endif
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
frame_synthesis(st, out, X);
|
|
511
|
+
return vad_prob;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
#if TRAINING
|
|
515
|
+
|
|
516
|
+
static float uni_rand() {
|
|
517
|
+
return rand()/(double)RAND_MAX-.5;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
static void rand_resp(float *a, float *b) {
|
|
521
|
+
a[0] = .75*uni_rand();
|
|
522
|
+
a[1] = .75*uni_rand();
|
|
523
|
+
b[0] = .75*uni_rand();
|
|
524
|
+
b[1] = .75*uni_rand();
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
int main(int argc, char **argv) {
|
|
528
|
+
int i;
|
|
529
|
+
int count=0;
|
|
530
|
+
static const float a_hp[2] = {-1.99599, 0.99600};
|
|
531
|
+
static const float b_hp[2] = {-2, 1};
|
|
532
|
+
float a_noise[2] = {0};
|
|
533
|
+
float b_noise[2] = {0};
|
|
534
|
+
float a_sig[2] = {0};
|
|
535
|
+
float b_sig[2] = {0};
|
|
536
|
+
float mem_hp_x[2]={0};
|
|
537
|
+
float mem_hp_n[2]={0};
|
|
538
|
+
float mem_resp_x[2]={0};
|
|
539
|
+
float mem_resp_n[2]={0};
|
|
540
|
+
float x[FRAME_SIZE];
|
|
541
|
+
float n[FRAME_SIZE];
|
|
542
|
+
float xn[FRAME_SIZE];
|
|
543
|
+
int vad_cnt=0;
|
|
544
|
+
int gain_change_count=0;
|
|
545
|
+
float speech_gain = 1, noise_gain = 1;
|
|
546
|
+
FILE *f1, *f2;
|
|
547
|
+
int maxCount;
|
|
548
|
+
DenoiseState *st;
|
|
549
|
+
DenoiseState *noise_state;
|
|
550
|
+
DenoiseState *noisy;
|
|
551
|
+
st = rnnoise_create(NULL);
|
|
552
|
+
noise_state = rnnoise_create(NULL);
|
|
553
|
+
noisy = rnnoise_create(NULL);
|
|
554
|
+
if (argc!=4) {
|
|
555
|
+
fprintf(stderr, "usage: %s <speech> <noise> <count>\n", argv[0]);
|
|
556
|
+
return 1;
|
|
557
|
+
}
|
|
558
|
+
f1 = fopen(argv[1], "r");
|
|
559
|
+
f2 = fopen(argv[2], "r");
|
|
560
|
+
maxCount = atoi(argv[3]);
|
|
561
|
+
for(i=0;i<150;i++) {
|
|
562
|
+
short tmp[FRAME_SIZE];
|
|
563
|
+
fread(tmp, sizeof(short), FRAME_SIZE, f2);
|
|
564
|
+
}
|
|
565
|
+
while (1) {
|
|
566
|
+
kiss_fft_cpx X[FREQ_SIZE], Y[FREQ_SIZE], N[FREQ_SIZE], P[WINDOW_SIZE];
|
|
567
|
+
float Ex[NB_BANDS], Ey[NB_BANDS], En[NB_BANDS], Ep[NB_BANDS];
|
|
568
|
+
float Exp[NB_BANDS];
|
|
569
|
+
float Ln[NB_BANDS];
|
|
570
|
+
float features[NB_FEATURES];
|
|
571
|
+
float g[NB_BANDS];
|
|
572
|
+
short tmp[FRAME_SIZE];
|
|
573
|
+
float vad=0;
|
|
574
|
+
float E=0;
|
|
575
|
+
if (count==maxCount) break;
|
|
576
|
+
if ((count%1000)==0) fprintf(stderr, "%d\r", count);
|
|
577
|
+
if (++gain_change_count > 2821) {
|
|
578
|
+
speech_gain = pow(10., (-40+(rand()%60))/20.);
|
|
579
|
+
noise_gain = pow(10., (-30+(rand()%50))/20.);
|
|
580
|
+
if (rand()%10==0) noise_gain = 0;
|
|
581
|
+
noise_gain *= speech_gain;
|
|
582
|
+
if (rand()%10==0) speech_gain = 0;
|
|
583
|
+
gain_change_count = 0;
|
|
584
|
+
rand_resp(a_noise, b_noise);
|
|
585
|
+
rand_resp(a_sig, b_sig);
|
|
586
|
+
lowpass = FREQ_SIZE * 3000./24000. * pow(50., rand()/(double)RAND_MAX);
|
|
587
|
+
for (i=0;i<NB_BANDS;i++) {
|
|
588
|
+
if (eband5ms[i]<<FRAME_SIZE_SHIFT > lowpass) {
|
|
589
|
+
band_lp = i;
|
|
590
|
+
break;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
if (speech_gain != 0) {
|
|
595
|
+
fread(tmp, sizeof(short), FRAME_SIZE, f1);
|
|
596
|
+
if (feof(f1)) {
|
|
597
|
+
rewind(f1);
|
|
598
|
+
fread(tmp, sizeof(short), FRAME_SIZE, f1);
|
|
599
|
+
}
|
|
600
|
+
for (i=0;i<FRAME_SIZE;i++) x[i] = speech_gain*tmp[i];
|
|
601
|
+
for (i=0;i<FRAME_SIZE;i++) E += tmp[i]*(float)tmp[i];
|
|
602
|
+
} else {
|
|
603
|
+
for (i=0;i<FRAME_SIZE;i++) x[i] = 0;
|
|
604
|
+
E = 0;
|
|
605
|
+
}
|
|
606
|
+
if (noise_gain!=0) {
|
|
607
|
+
fread(tmp, sizeof(short), FRAME_SIZE, f2);
|
|
608
|
+
if (feof(f2)) {
|
|
609
|
+
rewind(f2);
|
|
610
|
+
fread(tmp, sizeof(short), FRAME_SIZE, f2);
|
|
611
|
+
}
|
|
612
|
+
for (i=0;i<FRAME_SIZE;i++) n[i] = noise_gain*tmp[i];
|
|
613
|
+
} else {
|
|
614
|
+
for (i=0;i<FRAME_SIZE;i++) n[i] = 0;
|
|
615
|
+
}
|
|
616
|
+
biquad(x, mem_hp_x, x, b_hp, a_hp, FRAME_SIZE);
|
|
617
|
+
biquad(x, mem_resp_x, x, b_sig, a_sig, FRAME_SIZE);
|
|
618
|
+
biquad(n, mem_hp_n, n, b_hp, a_hp, FRAME_SIZE);
|
|
619
|
+
biquad(n, mem_resp_n, n, b_noise, a_noise, FRAME_SIZE);
|
|
620
|
+
for (i=0;i<FRAME_SIZE;i++) xn[i] = x[i] + n[i];
|
|
621
|
+
if (E > 1e9f) {
|
|
622
|
+
vad_cnt=0;
|
|
623
|
+
} else if (E > 1e8f) {
|
|
624
|
+
vad_cnt -= 5;
|
|
625
|
+
} else if (E > 1e7f) {
|
|
626
|
+
vad_cnt++;
|
|
627
|
+
} else {
|
|
628
|
+
vad_cnt+=2;
|
|
629
|
+
}
|
|
630
|
+
if (vad_cnt < 0) vad_cnt = 0;
|
|
631
|
+
if (vad_cnt > 15) vad_cnt = 15;
|
|
632
|
+
|
|
633
|
+
if (vad_cnt >= 10) vad = 0;
|
|
634
|
+
else if (vad_cnt > 0) vad = 0.5f;
|
|
635
|
+
else vad = 1.f;
|
|
636
|
+
|
|
637
|
+
frame_analysis(st, Y, Ey, x);
|
|
638
|
+
frame_analysis(noise_state, N, En, n);
|
|
639
|
+
for (i=0;i<NB_BANDS;i++) Ln[i] = log10(1e-2+En[i]);
|
|
640
|
+
int silence = compute_frame_features(noisy, X, P, Ex, Ep, Exp, features, xn);
|
|
641
|
+
pitch_filter(X, P, Ex, Ep, Exp, g);
|
|
642
|
+
//printf("%f %d\n", noisy->last_gain, noisy->last_period);
|
|
643
|
+
for (i=0;i<NB_BANDS;i++) {
|
|
644
|
+
g[i] = sqrt((Ey[i]+1e-3)/(Ex[i]+1e-3));
|
|
645
|
+
if (g[i] > 1) g[i] = 1;
|
|
646
|
+
if (silence || i > band_lp) g[i] = -1;
|
|
647
|
+
if (Ey[i] < 5e-2 && Ex[i] < 5e-2) g[i] = -1;
|
|
648
|
+
if (vad==0 && noise_gain==0) g[i] = -1;
|
|
649
|
+
}
|
|
650
|
+
count++;
|
|
651
|
+
#if 1
|
|
652
|
+
fwrite(features, sizeof(float), NB_FEATURES, stdout);
|
|
653
|
+
fwrite(g, sizeof(float), NB_BANDS, stdout);
|
|
654
|
+
fwrite(Ln, sizeof(float), NB_BANDS, stdout);
|
|
655
|
+
fwrite(&vad, sizeof(float), 1, stdout);
|
|
656
|
+
#endif
|
|
657
|
+
}
|
|
658
|
+
fprintf(stderr, "matrix size: %d x %d\n", count, NB_FEATURES + 2*NB_BANDS + 1);
|
|
659
|
+
fclose(f1);
|
|
660
|
+
fclose(f2);
|
|
661
|
+
return 0;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
#endif
|