gravix-rtc-react-native 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (378) hide show
  1. package/CHANGELOG.md +134 -0
  2. package/LICENSE +20 -0
  3. package/LICENSES/Apache-2.0.txt +175 -0
  4. package/NOTICE +68 -0
  5. package/README.md +313 -2
  6. package/android/build.gradle +137 -0
  7. package/android/consumer-rules.pro +29 -0
  8. package/android/src/main/AndroidManifest.xml +9 -0
  9. package/android/src/main/cpp/CMakeLists.txt +48 -0
  10. package/android/src/main/cpp/gx_dfn_engine.c +332 -0
  11. package/android/src/main/cpp/gx_fx_jni.cpp +34 -0
  12. package/android/src/main/cpp/gx_ns_jni.c +162 -0
  13. package/android/src/main/cpp/third_party/onnxruntime/LICENSE +21 -0
  14. package/android/src/main/cpp/third_party/onnxruntime/include/onnxruntime_c_api.h +9227 -0
  15. package/android/src/main/cpp/third_party/onnxruntime/include/onnxruntime_ep_c_api.h +3315 -0
  16. package/android/src/main/cpp/third_party/onnxruntime/include/onnxruntime_error_code.h +98 -0
  17. package/android/src/main/java/com/gravitycompile/gravixrtc/GravixAudioHooks.kt +144 -0
  18. package/android/src/main/java/com/gravitycompile/gravixrtc/GravixAudioModule.kt +105 -0
  19. package/android/src/main/java/com/gravitycompile/gravixrtc/GravixNativeAudio.kt +310 -0
  20. package/android/src/main/java/com/gravitycompile/gravixrtc/GravixRtc.kt +134 -0
  21. package/android/src/main/java/com/gravitycompile/gravixrtc/GravixRtcModule.kt +176 -0
  22. package/android/src/main/java/com/gravitycompile/gravixrtc/GravixRtcPackage.kt +39 -0
  23. package/android/src/main/java/com/gravitycompile/gravixrtc/audio/AudioDeviceKind.java +44 -0
  24. package/android/src/main/java/com/gravitycompile/gravixrtc/audio/AudioManagerUtils.kt +120 -0
  25. package/android/src/main/java/com/gravitycompile/gravixrtc/audio/AudioSwitchManager.java +270 -0
  26. package/android/src/main/java/com/gravitycompile/gravixrtc/audio/AudioType.kt +50 -0
  27. package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicCaptureRouter.kt +375 -0
  28. package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicDecoder.kt +339 -0
  29. package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicInterruptionWatcher.kt +82 -0
  30. package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicMicRelease.kt +117 -0
  31. package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicMixKernel.kt +191 -0
  32. package/android/src/main/java/com/gravitycompile/gravixrtc/music/MusicMixerEngine.kt +617 -0
  33. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/AudioRoutePolicy.kt +137 -0
  34. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GravixCaptureProcessing.kt +67 -0
  35. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxCaptureDump.kt +143 -0
  36. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxCaptureSwitcher.kt +196 -0
  37. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxNoiseProcessor.kt +795 -0
  38. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxNsLogic.kt +180 -0
  39. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxNsNative.kt +83 -0
  40. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxNsStudio.kt +372 -0
  41. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxRecordStartGuard.kt +76 -0
  42. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxRecorderSeam.kt +434 -0
  43. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxSingerSource.kt +37 -0
  44. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/GxVoiceFx.kt +160 -0
  45. package/android/src/main/java/com/gravitycompile/gravixrtc/processing/OtherAppAudioPolicy.kt +143 -0
  46. package/android/src/main/java/org/webrtc/audio/WebRtcAudioTrackHelper.kt +43 -0
  47. package/docs/ANDROID_NATIVE_HOOKS.md +102 -0
  48. package/docs/FEATURE_MATRIX.md +192 -0
  49. package/docs/IOS_NATIVE_HOOKS.md +190 -0
  50. package/gravix-rtc-react-native.podspec +49 -0
  51. package/ios/GravixRtc.h +7 -0
  52. package/ios/GravixRtc.mm +273 -0
  53. package/ios/GravixRtcSetup.h +29 -0
  54. package/ios/GravixRtcSetup.m +52 -0
  55. package/ios/audio/GravixRtcIosAudio.m +157 -0
  56. package/ios/audio/GxAudioDevice.h +62 -0
  57. package/ios/audio/GxAudioDevice.m +857 -0
  58. package/ios/audio/GxAudioSetup.h +34 -0
  59. package/ios/audio/GxAudioSetup.m +70 -0
  60. package/ios/audio/GxCompat.swift +53 -0
  61. package/ios/audio/GxIosAudio.swift +99 -0
  62. package/ios/audio/GxMusicController.swift +150 -0
  63. package/ios/audio/GxMusicPost.swift +362 -0
  64. package/ios/audio/GxNoiseProcessor.swift +718 -0
  65. package/ios/audio/GxNsDfn3CoreML.swift +195 -0
  66. package/ios/audio/GxNsStudioEngine.swift +237 -0
  67. package/ios/audio/GxNsStudioPack.swift +212 -0
  68. package/ios/audio/GxVoiceFx.swift +161 -0
  69. package/ios/audio/gx_adm_state.h +153 -0
  70. package/ios/gxcore/apple/gx_music_post.c +312 -0
  71. package/ios/gxcore/apple/gx_pcm.c +30 -0
  72. package/ios/gxcore/apple/gxns_build.h +19 -0
  73. package/ios/gxcore/apple/gxns_ios.c +17 -0
  74. package/ios/gxcore/apple/include/gx_fx.h +3 -0
  75. package/ios/gxcore/apple/include/gx_music_post.h +88 -0
  76. package/ios/gxcore/apple/include/gx_ns.h +3 -0
  77. package/ios/gxcore/apple/include/gx_pcm.h +33 -0
  78. package/ios/gxcore/apple/include/gxns_ios.h +18 -0
  79. package/ios/gxcore/apple/include/module.modulemap +10 -0
  80. package/ios/gxcore/apple/shim/rnnoise.h +2 -0
  81. package/ios/gxcore/apple/shim/speex_resampler.h +2 -0
  82. package/ios/gxcore/apple/units/gx_fx_forward.cpp +3 -0
  83. package/ios/gxcore/apple/units/gx_ns.c +7 -0
  84. package/ios/gxcore/apple/units/gx_ns_timer.c +7 -0
  85. package/ios/gxcore/apple/units/rnnoise_celt_lpc.c +7 -0
  86. package/ios/gxcore/apple/units/rnnoise_denoise.c +7 -0
  87. package/ios/gxcore/apple/units/rnnoise_kiss_fft.c +7 -0
  88. package/ios/gxcore/apple/units/rnnoise_pitch.c +7 -0
  89. package/ios/gxcore/apple/units/rnnoise_rnn.c +7 -0
  90. package/ios/gxcore/apple/units/rnnoise_rnn_data.c +7 -0
  91. package/ios/gxcore/apple/units/speexdsp_resample.c +7 -0
  92. package/ios/resources/ns/DFN3-NOTICE.txt +10 -0
  93. package/ios/resources/ns/DeepFilterNet-LICENSE-APACHE +201 -0
  94. package/ios/resources/ns/DeepFilterNet-LICENSE-MIT +19 -0
  95. package/ios/resources/ns/gxns_dfn3.mlmodelc/analytics/coremldata.bin +0 -0
  96. package/ios/resources/ns/gxns_dfn3.mlmodelc/coremldata.bin +0 -0
  97. package/ios/resources/ns/gxns_dfn3.mlmodelc/metadata.json +338 -0
  98. package/ios/resources/ns/gxns_dfn3.mlmodelc/model.mil +927 -0
  99. package/ios/resources/ns/gxns_dfn3.mlmodelc/weights/weight.bin +0 -0
  100. package/lib/module/android/bindings.js +49 -0
  101. package/lib/module/android/bindings.js.map +1 -0
  102. package/lib/module/android/index.js +13 -0
  103. package/lib/module/android/index.js.map +1 -0
  104. package/lib/module/android/micMute.js +341 -0
  105. package/lib/module/android/micMute.js.map +1 -0
  106. package/lib/module/android/nativeAudio.js +47 -0
  107. package/lib/module/android/nativeAudio.js.map +1 -0
  108. package/lib/module/android/noiseSuppression.js +170 -0
  109. package/lib/module/android/noiseSuppression.js.map +1 -0
  110. package/lib/module/android/roomMusic.js +142 -0
  111. package/lib/module/android/roomMusic.js.map +1 -0
  112. package/lib/module/android/singerMode.js +31 -0
  113. package/lib/module/android/singerMode.js.map +1 -0
  114. package/lib/module/android/voiceEffects.js +65 -0
  115. package/lib/module/android/voiceEffects.js.map +1 -0
  116. package/lib/module/audio/AudioManager.js +79 -0
  117. package/lib/module/audio/AudioManager.js.map +1 -0
  118. package/lib/module/audio/AudioSession.js +90 -0
  119. package/lib/module/audio/AudioSession.js.map +1 -0
  120. package/lib/module/audio/remoteVolume.js +54 -0
  121. package/lib/module/audio/remoteVolume.js.map +1 -0
  122. package/lib/module/components/VideoView.js +109 -0
  123. package/lib/module/components/VideoView.js.map +1 -0
  124. package/lib/module/features/audioScenario.js +53 -0
  125. package/lib/module/features/audioScenario.js.map +1 -0
  126. package/lib/module/features/beauty.js +828 -0
  127. package/lib/module/features/beauty.js.map +1 -0
  128. package/lib/module/features/micRelease.js +89 -0
  129. package/lib/module/features/micRelease.js.map +1 -0
  130. package/lib/module/features/noiseSuppression.js +213 -0
  131. package/lib/module/features/noiseSuppression.js.map +1 -0
  132. package/lib/module/features/roomMusic.js +90 -0
  133. package/lib/module/features/roomMusic.js.map +1 -0
  134. package/lib/module/features/roomMusicAndroid.js +294 -0
  135. package/lib/module/features/roomMusicAndroid.js.map +1 -0
  136. package/lib/module/features/roomMusicIos.js +250 -0
  137. package/lib/module/features/roomMusicIos.js.map +1 -0
  138. package/lib/module/features/roomMusicTypes.js +53 -0
  139. package/lib/module/features/roomMusicTypes.js.map +1 -0
  140. package/lib/module/features/screenShare.js +22 -0
  141. package/lib/module/features/screenShare.js.map +1 -0
  142. package/lib/module/features/singerMode.js +73 -0
  143. package/lib/module/features/singerMode.js.map +1 -0
  144. package/lib/module/features/voiceEffects.js +148 -0
  145. package/lib/module/features/voiceEffects.js.map +1 -0
  146. package/lib/module/hooks/context.js +34 -0
  147. package/lib/module/hooks/context.js.map +1 -0
  148. package/lib/module/hooks/hooks.js +145 -0
  149. package/lib/module/hooks/hooks.js.map +1 -0
  150. package/lib/module/hooks/types.js +4 -0
  151. package/lib/module/hooks/types.js.map +1 -0
  152. package/lib/module/hooks/useRoomEvents.js +30 -0
  153. package/lib/module/hooks/useRoomEvents.js.map +1 -0
  154. package/lib/module/index.js +43 -0
  155. package/lib/module/index.js.map +1 -0
  156. package/lib/module/ios/autoAttach.js +14 -0
  157. package/lib/module/ios/autoAttach.js.map +1 -0
  158. package/lib/module/ios/iosAudio.js +149 -0
  159. package/lib/module/ios/iosAudio.js.map +1 -0
  160. package/lib/module/join/appStateLifecycle.js +54 -0
  161. package/lib/module/join/appStateLifecycle.js.map +1 -0
  162. package/lib/module/micPolicy.js +249 -0
  163. package/lib/module/micPolicy.js.map +1 -0
  164. package/lib/module/native/NativeGravixAudio.js +18 -0
  165. package/lib/module/native/NativeGravixAudio.js.map +1 -0
  166. package/lib/module/native/NativeGravixRtc.js +13 -0
  167. package/lib/module/native/NativeGravixRtc.js.map +1 -0
  168. package/lib/module/native/module.js +23 -0
  169. package/lib/module/native/module.js.map +1 -0
  170. package/lib/module/package.json +1 -0
  171. package/lib/module/polyfills/DOMException.js +22 -0
  172. package/lib/module/polyfills/DOMException.js.map +1 -0
  173. package/lib/module/polyfills/early.js +18 -0
  174. package/lib/module/polyfills/early.js.map +1 -0
  175. package/lib/module/polyfills/event.js +71 -0
  176. package/lib/module/polyfills/event.js.map +1 -0
  177. package/lib/module/polyfills/sha256.js +92 -0
  178. package/lib/module/polyfills/sha256.js.map +1 -0
  179. package/lib/module/polyfills/subtleHmac.js +91 -0
  180. package/lib/module/polyfills/subtleHmac.js.map +1 -0
  181. package/lib/module/polyfills/textCoding.js +164 -0
  182. package/lib/module/polyfills/textCoding.js.map +1 -0
  183. package/lib/module/registerGlobals.js +135 -0
  184. package/lib/module/registerGlobals.js.map +1 -0
  185. package/lib/module/unsupported.js +90 -0
  186. package/lib/module/unsupported.js.map +1 -0
  187. package/lib/module/version.js +7 -0
  188. package/lib/module/version.js.map +1 -0
  189. package/lib/typescript/package.json +1 -0
  190. package/lib/typescript/src/android/bindings.d.ts +14 -0
  191. package/lib/typescript/src/android/bindings.d.ts.map +1 -0
  192. package/lib/typescript/src/android/index.d.ts +9 -0
  193. package/lib/typescript/src/android/index.d.ts.map +1 -0
  194. package/lib/typescript/src/android/micMute.d.ts +124 -0
  195. package/lib/typescript/src/android/micMute.d.ts.map +1 -0
  196. package/lib/typescript/src/android/nativeAudio.d.ts +40 -0
  197. package/lib/typescript/src/android/nativeAudio.d.ts.map +1 -0
  198. package/lib/typescript/src/android/noiseSuppression.d.ts +48 -0
  199. package/lib/typescript/src/android/noiseSuppression.d.ts.map +1 -0
  200. package/lib/typescript/src/android/roomMusic.d.ts +80 -0
  201. package/lib/typescript/src/android/roomMusic.d.ts.map +1 -0
  202. package/lib/typescript/src/android/singerMode.d.ts +27 -0
  203. package/lib/typescript/src/android/singerMode.d.ts.map +1 -0
  204. package/lib/typescript/src/android/voiceEffects.d.ts +30 -0
  205. package/lib/typescript/src/android/voiceEffects.d.ts.map +1 -0
  206. package/lib/typescript/src/audio/AudioManager.d.ts +32 -0
  207. package/lib/typescript/src/audio/AudioManager.d.ts.map +1 -0
  208. package/lib/typescript/src/audio/AudioSession.d.ts +70 -0
  209. package/lib/typescript/src/audio/AudioSession.d.ts.map +1 -0
  210. package/lib/typescript/src/audio/remoteVolume.d.ts +8 -0
  211. package/lib/typescript/src/audio/remoteVolume.d.ts.map +1 -0
  212. package/lib/typescript/src/components/VideoView.d.ts +44 -0
  213. package/lib/typescript/src/components/VideoView.d.ts.map +1 -0
  214. package/lib/typescript/src/features/audioScenario.d.ts +24 -0
  215. package/lib/typescript/src/features/audioScenario.d.ts.map +1 -0
  216. package/lib/typescript/src/features/beauty.d.ts +377 -0
  217. package/lib/typescript/src/features/beauty.d.ts.map +1 -0
  218. package/lib/typescript/src/features/micRelease.d.ts +28 -0
  219. package/lib/typescript/src/features/micRelease.d.ts.map +1 -0
  220. package/lib/typescript/src/features/noiseSuppression.d.ts +64 -0
  221. package/lib/typescript/src/features/noiseSuppression.d.ts.map +1 -0
  222. package/lib/typescript/src/features/roomMusic.d.ts +41 -0
  223. package/lib/typescript/src/features/roomMusic.d.ts.map +1 -0
  224. package/lib/typescript/src/features/roomMusicAndroid.d.ts +60 -0
  225. package/lib/typescript/src/features/roomMusicAndroid.d.ts.map +1 -0
  226. package/lib/typescript/src/features/roomMusicIos.d.ts +56 -0
  227. package/lib/typescript/src/features/roomMusicIos.d.ts.map +1 -0
  228. package/lib/typescript/src/features/roomMusicTypes.d.ts +76 -0
  229. package/lib/typescript/src/features/roomMusicTypes.d.ts.map +1 -0
  230. package/lib/typescript/src/features/screenShare.d.ts +12 -0
  231. package/lib/typescript/src/features/screenShare.d.ts.map +1 -0
  232. package/lib/typescript/src/features/singerMode.d.ts +20 -0
  233. package/lib/typescript/src/features/singerMode.d.ts.map +1 -0
  234. package/lib/typescript/src/features/voiceEffects.d.ts +46 -0
  235. package/lib/typescript/src/features/voiceEffects.d.ts.map +1 -0
  236. package/lib/typescript/src/hooks/context.d.ts +12 -0
  237. package/lib/typescript/src/hooks/context.d.ts.map +1 -0
  238. package/lib/typescript/src/hooks/hooks.d.ts +54 -0
  239. package/lib/typescript/src/hooks/hooks.d.ts.map +1 -0
  240. package/lib/typescript/src/hooks/types.d.ts +8 -0
  241. package/lib/typescript/src/hooks/types.d.ts.map +1 -0
  242. package/lib/typescript/src/hooks/useRoomEvents.d.ts +13 -0
  243. package/lib/typescript/src/hooks/useRoomEvents.d.ts.map +1 -0
  244. package/lib/typescript/src/index.d.ts +37 -0
  245. package/lib/typescript/src/index.d.ts.map +1 -0
  246. package/lib/typescript/src/ios/autoAttach.d.ts +2 -0
  247. package/lib/typescript/src/ios/autoAttach.d.ts.map +1 -0
  248. package/lib/typescript/src/ios/iosAudio.d.ts +96 -0
  249. package/lib/typescript/src/ios/iosAudio.d.ts.map +1 -0
  250. package/lib/typescript/src/join/appStateLifecycle.d.ts +14 -0
  251. package/lib/typescript/src/join/appStateLifecycle.d.ts.map +1 -0
  252. package/lib/typescript/src/micPolicy.d.ts +104 -0
  253. package/lib/typescript/src/micPolicy.d.ts.map +1 -0
  254. package/lib/typescript/src/native/NativeGravixAudio.d.ts +21 -0
  255. package/lib/typescript/src/native/NativeGravixAudio.d.ts.map +1 -0
  256. package/lib/typescript/src/native/NativeGravixRtc.d.ts +31 -0
  257. package/lib/typescript/src/native/NativeGravixRtc.d.ts.map +1 -0
  258. package/lib/typescript/src/native/module.d.ts +7 -0
  259. package/lib/typescript/src/native/module.d.ts.map +1 -0
  260. package/lib/typescript/src/polyfills/DOMException.d.ts +3 -0
  261. package/lib/typescript/src/polyfills/DOMException.d.ts.map +1 -0
  262. package/lib/typescript/src/polyfills/early.d.ts +2 -0
  263. package/lib/typescript/src/polyfills/early.d.ts.map +1 -0
  264. package/lib/typescript/src/polyfills/event.d.ts +2 -0
  265. package/lib/typescript/src/polyfills/event.d.ts.map +1 -0
  266. package/lib/typescript/src/polyfills/sha256.d.ts +3 -0
  267. package/lib/typescript/src/polyfills/sha256.d.ts.map +1 -0
  268. package/lib/typescript/src/polyfills/subtleHmac.d.ts +37 -0
  269. package/lib/typescript/src/polyfills/subtleHmac.d.ts.map +1 -0
  270. package/lib/typescript/src/polyfills/textCoding.d.ts +36 -0
  271. package/lib/typescript/src/polyfills/textCoding.d.ts.map +1 -0
  272. package/lib/typescript/src/registerGlobals.d.ts +42 -0
  273. package/lib/typescript/src/registerGlobals.d.ts.map +1 -0
  274. package/lib/typescript/src/unsupported.d.ts +42 -0
  275. package/lib/typescript/src/unsupported.d.ts.map +1 -0
  276. package/lib/typescript/src/version.d.ts +3 -0
  277. package/lib/typescript/src/version.d.ts.map +1 -0
  278. package/metro/index.js +39 -0
  279. package/metro/noise-stub.js +10 -0
  280. package/native/gxfx/include/gx_fx.h +82 -0
  281. package/native/gxfx/src/gx_fx.cpp +527 -0
  282. package/native/gxfx/third_party/README.md +4 -0
  283. package/native/gxfx/third_party/signalsmith-linear/LICENSE.txt +21 -0
  284. package/native/gxfx/third_party/signalsmith-linear/approx.h +191 -0
  285. package/native/gxfx/third_party/signalsmith-linear/fft.h +1386 -0
  286. package/native/gxfx/third_party/signalsmith-linear/linear.h +1129 -0
  287. package/native/gxfx/third_party/signalsmith-linear/platform/approx-cmsisdsp.h +40 -0
  288. package/native/gxfx/third_party/signalsmith-linear/platform/basic-fill-warnings.h +61 -0
  289. package/native/gxfx/third_party/signalsmith-linear/platform/fft-accelerate.h +340 -0
  290. package/native/gxfx/third_party/signalsmith-linear/platform/fft-cmsisdsp.h +307 -0
  291. package/native/gxfx/third_party/signalsmith-linear/platform/fft-ipp.h +532 -0
  292. package/native/gxfx/third_party/signalsmith-linear/platform/fft-linear.h +213 -0
  293. package/native/gxfx/third_party/signalsmith-linear/platform/fft-pffft-double.h +221 -0
  294. package/native/gxfx/third_party/signalsmith-linear/platform/fft-pffft.h +221 -0
  295. package/native/gxfx/third_party/signalsmith-linear/platform/linear-accelerate.h +593 -0
  296. package/native/gxfx/third_party/signalsmith-linear/platform/linear-cmsisdsp.h +713 -0
  297. package/native/gxfx/third_party/signalsmith-linear/platform/linear-xsimd-dispatch.cpp +6 -0
  298. package/native/gxfx/third_party/signalsmith-linear/platform/linear-xsimd.h +818 -0
  299. package/native/gxfx/third_party/signalsmith-linear/stft.h +700 -0
  300. package/native/gxfx/third_party/signalsmith-stretch-LICENSE.txt +21 -0
  301. package/native/gxfx/third_party/signalsmith-stretch.h +1060 -0
  302. package/native/gxns/CMakeLists.txt +67 -0
  303. package/native/gxns/include/gx_ns.h +285 -0
  304. package/native/gxns/src/gx_ns.c +1518 -0
  305. package/native/gxns/src/gx_ns_timer.c +84 -0
  306. package/native/gxns/src/gx_ns_timer.h +29 -0
  307. package/native/gxns/third_party/VENDOR.md +43 -0
  308. package/native/gxns/third_party/rnnoise/AUTHORS +1 -0
  309. package/native/gxns/third_party/rnnoise/COPYING +31 -0
  310. package/native/gxns/third_party/rnnoise/include/rnnoise.h +117 -0
  311. package/native/gxns/third_party/rnnoise/src/_kiss_fft_guts.h +182 -0
  312. package/native/gxns/third_party/rnnoise/src/arch.h +261 -0
  313. package/native/gxns/third_party/rnnoise/src/celt_lpc.c +172 -0
  314. package/native/gxns/third_party/rnnoise/src/celt_lpc.h +45 -0
  315. package/native/gxns/third_party/rnnoise/src/common.h +48 -0
  316. package/native/gxns/third_party/rnnoise/src/denoise.c +664 -0
  317. package/native/gxns/third_party/rnnoise/src/kiss_fft.c +601 -0
  318. package/native/gxns/third_party/rnnoise/src/kiss_fft.h +203 -0
  319. package/native/gxns/third_party/rnnoise/src/opus_types.h +159 -0
  320. package/native/gxns/third_party/rnnoise/src/pitch.c +523 -0
  321. package/native/gxns/third_party/rnnoise/src/pitch.h +149 -0
  322. package/native/gxns/third_party/rnnoise/src/rnn.c +178 -0
  323. package/native/gxns/third_party/rnnoise/src/rnn.h +65 -0
  324. package/native/gxns/third_party/rnnoise/src/rnn_data.c +11051 -0
  325. package/native/gxns/third_party/rnnoise/src/rnn_data.h +34 -0
  326. package/native/gxns/third_party/rnnoise/src/tansig_table.h +45 -0
  327. package/native/gxns/third_party/speexdsp/AUTHORS +18 -0
  328. package/native/gxns/third_party/speexdsp/COPYING +35 -0
  329. package/native/gxns/third_party/speexdsp/arch.h +232 -0
  330. package/native/gxns/third_party/speexdsp/resample.c +1239 -0
  331. package/native/gxns/third_party/speexdsp/resample_neon.h +339 -0
  332. package/native/gxns/third_party/speexdsp/resample_sse.h +128 -0
  333. package/native/gxns/third_party/speexdsp/speex_resampler.h +343 -0
  334. package/package.json +186 -4
  335. package/src/android/bindings.ts +61 -0
  336. package/src/android/index.ts +10 -0
  337. package/src/android/micMute.ts +422 -0
  338. package/src/android/nativeAudio.ts +94 -0
  339. package/src/android/noiseSuppression.ts +209 -0
  340. package/src/android/roomMusic.ts +193 -0
  341. package/src/android/singerMode.ts +53 -0
  342. package/src/android/voiceEffects.ts +126 -0
  343. package/src/audio/AudioManager.ts +111 -0
  344. package/src/audio/AudioSession.ts +190 -0
  345. package/src/audio/remoteVolume.ts +58 -0
  346. package/src/components/VideoView.tsx +152 -0
  347. package/src/features/audioScenario.ts +58 -0
  348. package/src/features/beauty.ts +1057 -0
  349. package/src/features/micRelease.ts +108 -0
  350. package/src/features/noiseSuppression.ts +251 -0
  351. package/src/features/roomMusic.ts +106 -0
  352. package/src/features/roomMusicAndroid.ts +310 -0
  353. package/src/features/roomMusicIos.ts +300 -0
  354. package/src/features/roomMusicTypes.ts +97 -0
  355. package/src/features/screenShare.ts +19 -0
  356. package/src/features/singerMode.ts +70 -0
  357. package/src/features/voiceEffects.ts +245 -0
  358. package/src/hooks/context.tsx +38 -0
  359. package/src/hooks/hooks.ts +247 -0
  360. package/src/hooks/types.ts +10 -0
  361. package/src/hooks/useRoomEvents.ts +35 -0
  362. package/src/index.tsx +134 -0
  363. package/src/ios/autoAttach.ts +11 -0
  364. package/src/ios/iosAudio.ts +202 -0
  365. package/src/join/appStateLifecycle.ts +55 -0
  366. package/src/micPolicy.ts +312 -0
  367. package/src/native/NativeGravixAudio.ts +30 -0
  368. package/src/native/NativeGravixRtc.ts +38 -0
  369. package/src/native/module.ts +22 -0
  370. package/src/polyfills/DOMException.ts +20 -0
  371. package/src/polyfills/early.ts +16 -0
  372. package/src/polyfills/event.ts +88 -0
  373. package/src/polyfills/sha256.ts +112 -0
  374. package/src/polyfills/subtleHmac.ts +124 -0
  375. package/src/polyfills/textCoding.ts +197 -0
  376. package/src/registerGlobals.ts +201 -0
  377. package/src/unsupported.ts +139 -0
  378. package/src/version.ts +4 -0
@@ -0,0 +1,213 @@
1
+ #ifndef SIGNALSMITH_LINEAR_PLATFORM_FFT_LINEAR_H
2
+ #define SIGNALSMITH_LINEAR_PLATFORM_FFT_LINEAR_H
3
+
4
+ #include "../linear.h"
5
+
6
+ namespace signalsmith { namespace linear {
7
+
8
+ namespace _impl_linear_fft {
9
+
10
+ /// SimpleFFT, but rewritten to use some Linear functions
11
+ template<typename Sample>
12
+ struct LinearFFT {
13
+ static constexpr bool prefersSplit = true;
14
+
15
+ using Complex = std::complex<Sample>;
16
+
17
+ LinearFFT(size_t size=0) {
18
+ resize(size);
19
+ }
20
+
21
+ void resize(size_t size) {
22
+ twiddles.resize(size*3/4);
23
+ for (size_t i = 0; i < size*3/4; ++i) {
24
+ Sample twiddlePhase = -2*M_PI*i/size;
25
+ twiddles[i] = std::polar(Sample(1), twiddlePhase);
26
+ }
27
+ working.resize(size);
28
+ }
29
+
30
+ void fft(const Complex *time, Complex *freq) {
31
+ size_t size = working.size();
32
+ if (size <= 1) {
33
+ *freq = *time;
34
+ return;
35
+ }
36
+ fftPass<false>(size, 1, time, freq, working.data());
37
+ }
38
+
39
+ void ifft(const Complex *freq, Complex *time) {
40
+ size_t size = working.size();
41
+ if (size <= 1) {
42
+ *time = *freq;
43
+ return;
44
+ }
45
+ fftPass<true>(size, 1, freq, time, working.data());
46
+ }
47
+
48
+ void fft(const Sample *inR, const Sample *inI, Sample *outR, Sample *outI) {
49
+ size_t size = working.size();
50
+ if (size <= 1) {
51
+ *outR = *inR;
52
+ *outI = *inI;
53
+ return;
54
+ }
55
+ Sample *workingR = (Sample *)working.data(), *workingI = workingR + size;
56
+ fftPass<false>(size, 1, inR, inI, outR, outI, workingR, workingI);
57
+ }
58
+ void ifft(const Sample *inR, const Sample *inI, Sample *outR, Sample *outI) {
59
+ size_t size = working.size();
60
+ if (size <= 1) {
61
+ *outR = *inR;
62
+ *outI = *inI;
63
+ return;
64
+ }
65
+ Sample *workingR = (Sample *)working.data(), *workingI = workingR + size;
66
+ fftPass<true>(size, 1, inR, inI, outR, outI, workingR, workingI);
67
+ }
68
+ private:
69
+ std::vector<Complex> twiddles;
70
+ std::vector<Complex> working;
71
+
72
+ template<bool conjB>
73
+ static Complex mul(const Complex &a, const Complex &b) {
74
+ return conjB ? Complex{
75
+ a.real()*b.real() + a.imag()*b.imag(),
76
+ a.imag()*b.real() - a.real()*b.imag()
77
+ } : Complex{
78
+ a.real()*b.real() - a.imag()*b.imag(),
79
+ a.imag()*b.real() + a.real()*b.imag()
80
+ };
81
+ }
82
+
83
+ // Calculate a [size]-point FFT, where each element is a block of [stride] values
84
+ template<bool inverse>
85
+ void fftPass(size_t size, size_t stride, const Complex *input, Complex *output, Complex *working) {
86
+ if (size/4 > 1) {
87
+ // Calculate four quarter-size FFTs
88
+ fftPass<inverse>(size/4, stride*4, input, working, output);
89
+ combine4<inverse>(size, stride, working, output);
90
+ } else if (size == 4) {
91
+ combine4<inverse>(4, stride, input, output);
92
+ } else {
93
+ // 2-point FFT
94
+ for (size_t s = 0; s < stride; ++s) {
95
+ Complex a = input[s];
96
+ Complex b = input[s + stride];
97
+ output[s] = a + b;
98
+ output[s + stride] = a - b;
99
+ }
100
+ }
101
+ }
102
+
103
+ // Combine interleaved results into a single spectrum
104
+ template<bool inverse>
105
+ void combine4(size_t size, size_t stride, const Complex *input, Complex *output) const {
106
+ auto twiddleStep = working.size()/size;
107
+ for (size_t i = 0; i < size/4; ++i) {
108
+ Complex twiddleB = twiddles[i*twiddleStep];
109
+ Complex twiddleC = twiddles[i*2*twiddleStep];
110
+ Complex twiddleD = twiddles[i*3*twiddleStep];
111
+
112
+ const Complex *inputA = input + 4*i*stride;
113
+ const Complex *inputB = input + (4*i + 1)*stride;
114
+ const Complex *inputC = input + (4*i + 2)*stride;
115
+ const Complex *inputD = input + (4*i + 3)*stride;
116
+ Complex *outputA = output + i*stride;
117
+ Complex *outputB = output + (i + size/4)*stride;
118
+ Complex *outputC = output + (i + size/4*2)*stride;
119
+ Complex *outputD = output + (i + size/4*3)*stride;
120
+ for (size_t s = 0; s < stride; ++s) {
121
+ Complex a = inputA[s];
122
+ Complex b = mul<inverse>(inputB[s], twiddleB);
123
+ Complex c = mul<inverse>(inputC[s], twiddleC);
124
+ Complex d = mul<inverse>(inputD[s], twiddleD);
125
+ Complex ac0 = a + c, ac1 = a - c;
126
+ Complex bd0 = b + d, bd1 = inverse ? (b - d) : (d - b);
127
+ Complex bd1i = {-bd1.imag(), bd1.real()};
128
+ outputA[s] = ac0 + bd0;
129
+ outputB[s] = ac1 + bd1i;
130
+ outputC[s] = ac0 - bd0;
131
+ outputD[s] = ac1 - bd1i;
132
+ }
133
+ }
134
+ }
135
+
136
+ // The same thing, but translated for split-complex input/output
137
+ template<bool inverse>
138
+ void fftPass(size_t size, size_t stride, const Sample *inputR, const Sample *inputI, Sample *outputR, Sample *outputI, Sample *workingR, Sample *workingI) const {
139
+ if (size/4 > 1) {
140
+ // Calculate four quarter-size FFTs
141
+ fftPass<inverse>(size/4, stride*4, inputR, inputI, workingR, workingI, outputR, outputI);
142
+ combine4<inverse>(size, stride, workingR, workingI, outputR, outputI);
143
+ } else if (size == 4) {
144
+ combine4<inverse>(4, stride, inputR, inputI, outputR, outputI);
145
+ } else {
146
+ // 2-point FFT
147
+ for (size_t s = 0; s < stride; ++s) {
148
+ Sample ar = inputR[s], ai = inputI[s];
149
+ Sample br = inputR[s + stride], bi = inputI[s + stride];
150
+ outputR[s] = ar + br;
151
+ outputI[s] = ai + bi;
152
+ outputR[s + stride] = ar - br;
153
+ outputI[s + stride] = ai - bi;
154
+ }
155
+ }
156
+ }
157
+
158
+ // Combine interleaved results into a single spectrum
159
+ template<bool inverse>
160
+ void combine4(size_t size, size_t stride, const Sample *inputR, const Sample *inputI, Sample *outputR, Sample *outputI) const {
161
+ auto twiddleStep = working.size()/size;
162
+ for (size_t i = 0; i < size/4; ++i) {
163
+ Complex twiddleB = twiddles[i*twiddleStep];
164
+ Complex twiddleC = twiddles[i*2*twiddleStep];
165
+ Complex twiddleD = twiddles[i*3*twiddleStep];
166
+
167
+ const Sample *inputAr = inputR + 4*i*stride, *inputAi = inputI + 4*i*stride;
168
+ const Sample *inputBr = inputR + (4*i + 1)*stride, *inputBi = inputI + (4*i + 1)*stride;
169
+ const Sample *inputCr = inputR + (4*i + 2)*stride, *inputCi = inputI + (4*i + 2)*stride;
170
+ const Sample *inputDr = inputR + (4*i + 3)*stride, *inputDi = inputI + (4*i + 3)*stride;
171
+ Sample *outputAr = outputR + i*stride, *outputAi = outputI + i*stride;
172
+ Sample *outputBr = outputR + (i + size/4)*stride, *outputBi = outputI + (i + size/4)*stride;
173
+ Sample *outputCr = outputR + (i + size/4*2)*stride, *outputCi = outputI + (i + size/4*2)*stride;
174
+ Sample *outputDr = outputR + (i + size/4*3)*stride, *outputDi = outputI + (i + size/4*3)*stride;
175
+ for (size_t s = 0; s < stride; ++s) {
176
+ Complex a = {inputAr[s], inputAi[s]};
177
+ Complex b = mul<inverse>({inputBr[s], inputBi[s]}, twiddleB);
178
+ Complex c = mul<inverse>({inputCr[s], inputCi[s]}, twiddleC);
179
+ Complex d = mul<inverse>({inputDr[s], inputDi[s]}, twiddleD);
180
+ Complex ac0 = a + c, ac1 = a - c;
181
+ Complex bd0 = b + d, bd1 = inverse ? (b - d) : (d - b);
182
+ Complex bd1i = {-bd1.imag(), bd1.real()};
183
+ outputAr[s] = ac0.real() + bd0.real();
184
+ outputAi[s] = ac0.imag() + bd0.imag();
185
+ outputBr[s] = ac1.real() + bd1i.real();
186
+ outputBi[s] = ac1.imag() + bd1i.imag();
187
+ outputCr[s] = ac0.real() - bd0.real();
188
+ outputCi[s] = ac0.imag() - bd0.imag();
189
+ outputDr[s] = ac1.real() - bd1i.real();
190
+ outputDi[s] = ac1.imag() - bd1i.imag();
191
+ }
192
+ }
193
+ }
194
+ };
195
+
196
+ } // namespace
197
+
198
+ template<>
199
+ struct Pow2FFT<float> : public _impl_linear_fft::LinearFFT<float> {
200
+ private:
201
+ using Super = _impl_linear_fft::LinearFFT<float>;
202
+ public:
203
+ using Complex = std::complex<float>;
204
+
205
+ Pow2FFT(size_t size=0) : Super(size) {}
206
+
207
+ // Allow move, but not copy
208
+ Pow2FFT(const Pow2FFT &other) = delete;
209
+ Pow2FFT(Pow2FFT &&other) : Super(std::move(other)) {}
210
+ };
211
+
212
+ }} // namespace
213
+ #endif // include guard
@@ -0,0 +1,221 @@
1
+ #ifndef SIGNALSMITH_LINEAR_PLATFORM_FFT_PFFFTDOUBLE_H
2
+ #define SIGNALSMITH_LINEAR_PLATFORM_FFT_PFFFTDOUBLE_H
3
+
4
+ #if defined(__has_include) && !__has_include("pffft/pffft_double.h")
5
+ # include "pffft_double.h"
6
+ #else
7
+ # include "pffft/pffft_double.h"
8
+ #endif
9
+
10
+ #include <memory>
11
+ #include <cmath>
12
+ #include <complex>
13
+ #include <cassert>
14
+
15
+ namespace signalsmith { namespace linear {
16
+
17
+ template<>
18
+ struct Pow2FFT<double> {
19
+ static constexpr bool prefersSplit = false;
20
+
21
+ using Complex = std::complex<double>;
22
+
23
+ Pow2FFT(size_t size=0) {
24
+ resize(size);
25
+ }
26
+ ~Pow2FFT() {
27
+ resize(0); // frees everything
28
+ }
29
+ // Allow move, but not copy
30
+ Pow2FFT(const Pow2FFT &other) = delete;
31
+ Pow2FFT(Pow2FFT &&other) : _size(other._size), hasSetup(other.hasSetup), fftSetup(other.fftSetup), fallback(std::move(other.fallback)), work(other.work), tmpAligned(other.tmpAligned) {
32
+ // Avoid double-free
33
+ other.hasSetup = false;
34
+ other.work = nullptr;
35
+ other.tmpAligned = nullptr;
36
+ }
37
+
38
+ void resize(size_t size) {
39
+ _size = size;
40
+ fallback = nullptr;
41
+ if (hasSetup) pffftd_destroy_setup(fftSetup);
42
+ if (work) pffftd_aligned_free(work);
43
+ work = nullptr;
44
+ if (tmpAligned) pffftd_aligned_free(tmpAligned);
45
+ tmpAligned = nullptr;
46
+
47
+ // We use this for split-real, even if there's no PFFFT setup
48
+ tmpAligned = (double *)pffftd_aligned_malloc(sizeof(double)*size*2);
49
+
50
+ if (size < 16) {
51
+ // PFFFT doesn't support smaller sizes
52
+ hasSetup = false;
53
+ fallback = std::unique_ptr<SimpleFFT<double>>{
54
+ new SimpleFFT<double>(size)
55
+ };
56
+ return;
57
+ }
58
+
59
+ work = (double *)pffftd_aligned_malloc(sizeof(double)*size*2);
60
+ fftSetup = pffftd_new_setup(int(size), PFFFT_COMPLEX);
61
+ hasSetup = fftSetup;
62
+ }
63
+
64
+ void fft(const Complex* input, Complex* output) {
65
+ if (fallback) return fallback->fft(input, output);
66
+ fftInner(input, output, PFFFT_FORWARD);
67
+ }
68
+ void fft(const double *inR, const double *inI, double *outR, double *outI) {
69
+ if (fallback) return fallback->fft(inR, inI, outR, outI);
70
+ fftInner(inR, inI, outR, outI, PFFFT_FORWARD);
71
+ }
72
+
73
+ void ifft(const Complex* input, Complex* output) {
74
+ if (fallback) return fallback->ifft(input, output);
75
+ fftInner(input, output, PFFFT_BACKWARD);
76
+ }
77
+ void ifft(const double *inR, const double *inI, double *outR, double *outI) {
78
+ if (fallback) return fallback->ifft(inR, inI, outR, outI);
79
+ fftInner(inR, inI, outR, outI, PFFFT_BACKWARD);
80
+ }
81
+
82
+ private:
83
+ void fftInner(const Complex *input, Complex *output, pffft_direction_t direction) {
84
+ // 32-byte alignment
85
+ if (size_t(input)&0x1F) {
86
+ // `tmpAligned` is always aligned, so copy into that
87
+ std::memcpy(static_cast<void *>(tmpAligned), static_cast<const void *>(input), sizeof(Complex)*_size);
88
+ input = (const Complex *)tmpAligned;
89
+ }
90
+ if (size_t(output)&0x1F) {
91
+ // Output to `tmpAligned` - might be in-place if input is unaligned, but that's fine
92
+ pffftd_transform_ordered(fftSetup, (const double *)input, tmpAligned, work, direction);
93
+ std::memcpy(static_cast<void *>(output), static_cast<const void *>(tmpAligned), sizeof(Complex)*_size);
94
+ } else {
95
+ pffftd_transform_ordered(fftSetup, (const double *)input, (double *)output, work, direction);
96
+ }
97
+ }
98
+ void fftInner(const double *inR, const double *inI, double *outR, double *outI, pffft_direction_t direction) {
99
+ for (size_t i = 0; i < _size; ++i) {
100
+ tmpAligned[2*i] = inR[i];
101
+ tmpAligned[2*i + 1] = inI[i];
102
+ }
103
+ // PFFFT supports in-place transforms
104
+ fftInner((const Complex *)tmpAligned, (Complex *)tmpAligned, direction);
105
+ // Un-interleave
106
+ for (size_t i = 0; i < _size; ++i) {
107
+ outR[i] = tmpAligned[2*i];
108
+ outI[i] = tmpAligned[2*i + 1];
109
+ }
110
+ }
111
+
112
+ size_t _size = 0;
113
+ bool hasSetup = false;
114
+ PFFFTD_Setup *fftSetup = nullptr;
115
+ std::unique_ptr<SimpleFFT<double>> fallback;
116
+ double *work = nullptr, *tmpAligned = nullptr;
117
+ };
118
+
119
+ template<>
120
+ struct Pow2RealFFT<double> {
121
+ private:
122
+ using FallbackFFT = SimpleRealFFT<double>; // this wraps the complex one
123
+ public:
124
+ static constexpr bool prefersSplit = false;
125
+
126
+ using Complex = std::complex<double>;
127
+
128
+ Pow2RealFFT(size_t size=0) {
129
+ resize(size);
130
+ }
131
+ ~Pow2RealFFT() {
132
+ resize(0);
133
+ }
134
+ // Allow move, but not copy
135
+ Pow2RealFFT(const Pow2RealFFT &other) = delete;
136
+ Pow2RealFFT(Pow2RealFFT &&other) : _size(other._size), hasSetup(other.hasSetup), fftSetup(other.fftSetup), fallback(std::move(other.fallback)), work(other.work), tmpAligned(other.tmpAligned) {
137
+ // Avoid double-free
138
+ other.hasSetup = false;
139
+ other.work = nullptr;
140
+ other.tmpAligned = nullptr;
141
+ }
142
+
143
+ void resize(size_t size) {
144
+ _size = size;
145
+ fallback = nullptr;
146
+ if (hasSetup) pffftd_destroy_setup(fftSetup);
147
+ if (work) pffftd_aligned_free(work);
148
+ work = nullptr;
149
+ if (tmpAligned) pffftd_aligned_free(tmpAligned);
150
+ tmpAligned = nullptr;
151
+
152
+ // We use this for split-real, even if there's no PFFFT setup
153
+ tmpAligned = (double *)pffftd_aligned_malloc(sizeof(double)*size*2);
154
+
155
+ // TODO: just go for it, and check for success before allocating `work`
156
+ if (size < 32) {
157
+ // PFFFT doesn't support smaller sizes
158
+ hasSetup = false;
159
+ fallback = std::unique_ptr<FallbackFFT>{
160
+ new FallbackFFT(size)
161
+ };
162
+ return;
163
+ }
164
+
165
+ work = (double *)pffftd_aligned_malloc(sizeof(double)*size);
166
+ fftSetup = pffftd_new_setup(int(size), PFFFT_REAL);
167
+ hasSetup = fftSetup;
168
+ }
169
+
170
+ void fft(const double *input, Complex *output) {
171
+ if (fallback) return fallback->fft(input, output);
172
+ fftInner(input, (double *)output, PFFFT_FORWARD);
173
+ }
174
+ void fft(const double *inR, double *outR, double *outI) {
175
+ if (fallback) return fallback->fft(inR, outR, outI);
176
+ fftInner(inR, tmpAligned, PFFFT_FORWARD);
177
+ for (size_t i = 0; i < _size/2; ++i) {
178
+ outR[i] = tmpAligned[2*i];
179
+ outI[i] = tmpAligned[2*i + 1];
180
+ }
181
+ }
182
+
183
+ void ifft(const Complex *input, double *output) {
184
+ if (fallback) return fallback->ifft(input, output);
185
+ fftInner((const double *)input, output, PFFFT_BACKWARD);
186
+ }
187
+ void ifft(const double *inR, const double *inI, double *outR) {
188
+ if (fallback) return fallback->ifft(inR, inI, outR);
189
+ for (size_t i = 0; i < _size/2; ++i) {
190
+ tmpAligned[2*i] = inR[i];
191
+ tmpAligned[2*i + 1] = inI[i];
192
+ }
193
+ fftInner(tmpAligned, outR, PFFFT_BACKWARD);
194
+ }
195
+
196
+ private:
197
+ void fftInner(const double *input, double *output, pffft_direction_t direction) {
198
+ // 32-byte alignment
199
+ if (size_t(input)&0x1F) {
200
+ // `tmpAligned` is always aligned, so copy into that
201
+ std::memcpy(static_cast<void *>(tmpAligned), static_cast<const void *>(input), sizeof(double)*_size);
202
+ input = tmpAligned;
203
+ }
204
+ if (size_t(output)&0x1F) {
205
+ // Output to `tmpAligned` - might be in-place if input is unaligned, but that's fine
206
+ pffftd_transform_ordered(fftSetup, input, tmpAligned, work, direction);
207
+ std::memcpy(static_cast<void *>(output), static_cast<const void *>(tmpAligned), sizeof(double)*_size);
208
+ } else {
209
+ pffftd_transform_ordered(fftSetup, input, output, work, direction);
210
+ }
211
+ }
212
+
213
+ size_t _size = 0;
214
+ bool hasSetup = false;
215
+ PFFFTD_Setup *fftSetup = nullptr;
216
+ std::unique_ptr<FallbackFFT> fallback;
217
+ double *work = nullptr, *tmpAligned = nullptr;
218
+ };
219
+
220
+ }} // namespace
221
+ #endif // include guard
@@ -0,0 +1,221 @@
1
+ #ifndef SIGNALSMITH_LINEAR_PLATFORM_FFT_PFFFT_H
2
+ #define SIGNALSMITH_LINEAR_PLATFORM_FFT_PFFFT_H
3
+
4
+ #if defined(__has_include) && !__has_include("pffft/pffft.h")
5
+ # include "pffft.h"
6
+ #else
7
+ # include "pffft/pffft.h"
8
+ #endif
9
+
10
+ #include <memory>
11
+ #include <cmath>
12
+ #include <complex>
13
+ #include <cassert>
14
+
15
+ namespace signalsmith { namespace linear {
16
+
17
+ template<>
18
+ struct Pow2FFT<float> {
19
+ static constexpr bool prefersSplit = false;
20
+
21
+ using Complex = std::complex<float>;
22
+
23
+ Pow2FFT(size_t size=0) {
24
+ resize(size);
25
+ }
26
+ ~Pow2FFT() {
27
+ resize(0); // frees everything
28
+ }
29
+ // Allow move, but not copy
30
+ Pow2FFT(const Pow2FFT &other) = delete;
31
+ Pow2FFT(Pow2FFT &&other) : _size(other._size), hasSetup(other.hasSetup), fftSetup(other.fftSetup), fallback(std::move(other.fallback)), work(other.work), tmpAligned(other.tmpAligned) {
32
+ // Avoid double-free
33
+ other.hasSetup = false;
34
+ other.work = nullptr;
35
+ other.tmpAligned = nullptr;
36
+ }
37
+
38
+ void resize(size_t size) {
39
+ _size = size;
40
+ fallback = nullptr;
41
+ if (hasSetup) pffft_destroy_setup(fftSetup);
42
+ if (work) pffft_aligned_free(work);
43
+ work = nullptr;
44
+ if (tmpAligned) pffft_aligned_free(tmpAligned);
45
+ tmpAligned = nullptr;
46
+
47
+ // We use this for split-real, even if there's no PFFFT setup
48
+ tmpAligned = (float *)pffft_aligned_malloc(sizeof(float)*size*2);
49
+
50
+ if (size < 16) {
51
+ // PFFFT doesn't support smaller sizes
52
+ hasSetup = false;
53
+ fallback = std::unique_ptr<SimpleFFT<float>>{
54
+ new SimpleFFT<float>(size)
55
+ };
56
+ return;
57
+ }
58
+
59
+ work = (float *)pffft_aligned_malloc(sizeof(float)*size*2);
60
+ fftSetup = pffft_new_setup(int(size), PFFFT_COMPLEX);
61
+ hasSetup = fftSetup;
62
+ }
63
+
64
+ void fft(const Complex* input, Complex* output) {
65
+ if (fallback) return fallback->fft(input, output);
66
+ fftInner(input, output, PFFFT_FORWARD);
67
+ }
68
+ void fft(const float *inR, const float *inI, float *outR, float *outI) {
69
+ if (fallback) return fallback->fft(inR, inI, outR, outI);
70
+ fftInner(inR, inI, outR, outI, PFFFT_FORWARD);
71
+ }
72
+
73
+ void ifft(const Complex* input, Complex* output) {
74
+ if (fallback) return fallback->ifft(input, output);
75
+ fftInner(input, output, PFFFT_BACKWARD);
76
+ }
77
+ void ifft(const float *inR, const float *inI, float *outR, float *outI) {
78
+ if (fallback) return fallback->ifft(inR, inI, outR, outI);
79
+ fftInner(inR, inI, outR, outI, PFFFT_BACKWARD);
80
+ }
81
+
82
+ private:
83
+ void fftInner(const Complex *input, Complex *output, pffft_direction_t direction) {
84
+ // 16-byte alignment
85
+ if (size_t(input)&0x0F) {
86
+ // `tmpAligned` is always aligned, so copy into that
87
+ std::memcpy(static_cast<void *>(tmpAligned), static_cast<const void *>(input), sizeof(Complex)*_size);
88
+ input = (const Complex *)tmpAligned;
89
+ }
90
+ if (size_t(output)&0x0F) {
91
+ // Output to `tmpAligned` - might be in-place if input is unaligned, but that's fine
92
+ pffft_transform_ordered(fftSetup, (const float *)input, tmpAligned, work, direction);
93
+ std::memcpy(static_cast<void *>(output), static_cast<const void *>(tmpAligned), sizeof(Complex)*_size);
94
+ } else {
95
+ pffft_transform_ordered(fftSetup, (const float *)input, (float *)output, work, direction);
96
+ }
97
+ }
98
+ void fftInner(const float *inR, const float *inI, float *outR, float *outI, pffft_direction_t direction) {
99
+ for (size_t i = 0; i < _size; ++i) {
100
+ tmpAligned[2*i] = inR[i];
101
+ tmpAligned[2*i + 1] = inI[i];
102
+ }
103
+ // PFFFT supports in-place transforms
104
+ fftInner((const Complex *)tmpAligned, (Complex *)tmpAligned, direction);
105
+ // Un-interleave
106
+ for (size_t i = 0; i < _size; ++i) {
107
+ outR[i] = tmpAligned[2*i];
108
+ outI[i] = tmpAligned[2*i + 1];
109
+ }
110
+ }
111
+
112
+ size_t _size = 0;
113
+ bool hasSetup = false;
114
+ PFFFT_Setup *fftSetup = nullptr;
115
+ std::unique_ptr<SimpleFFT<float>> fallback;
116
+ float *work = nullptr, *tmpAligned = nullptr;
117
+ };
118
+
119
+ template<>
120
+ struct Pow2RealFFT<float> {
121
+ private:
122
+ using FallbackFFT = SimpleRealFFT<float>; // this wraps the complex one
123
+ public:
124
+ static constexpr bool prefersSplit = false;
125
+
126
+ using Complex = std::complex<float>;
127
+
128
+ Pow2RealFFT(size_t size=0) {
129
+ resize(size);
130
+ }
131
+ ~Pow2RealFFT() {
132
+ resize(0);
133
+ }
134
+ // Allow move, but not copy
135
+ Pow2RealFFT(const Pow2RealFFT &other) = delete;
136
+ Pow2RealFFT(Pow2RealFFT &&other) : _size(other._size), hasSetup(other.hasSetup), fftSetup(other.fftSetup), fallback(std::move(other.fallback)), work(other.work), tmpAligned(other.tmpAligned) {
137
+ // Avoid double-free
138
+ other.hasSetup = false;
139
+ other.work = nullptr;
140
+ other.tmpAligned = nullptr;
141
+ }
142
+
143
+ void resize(size_t size) {
144
+ _size = size;
145
+ fallback = nullptr;
146
+ if (hasSetup) pffft_destroy_setup(fftSetup);
147
+ if (work) pffft_aligned_free(work);
148
+ work = nullptr;
149
+ if (tmpAligned) pffft_aligned_free(tmpAligned);
150
+ tmpAligned = nullptr;
151
+
152
+ // We use this for split-real, even if there's no PFFFT setup
153
+ tmpAligned = (float *)pffft_aligned_malloc(sizeof(float)*size*2);
154
+
155
+ // TODO: just go for it, and check for success before allocating `work`
156
+ if (size < 32) {
157
+ // PFFFT doesn't support smaller sizes
158
+ hasSetup = false;
159
+ fallback = std::unique_ptr<FallbackFFT>{
160
+ new FallbackFFT(size)
161
+ };
162
+ return;
163
+ }
164
+
165
+ work = (float *)pffft_aligned_malloc(sizeof(float)*size);
166
+ fftSetup = pffft_new_setup(int(size), PFFFT_REAL);
167
+ hasSetup = fftSetup;
168
+ }
169
+
170
+ void fft(const float *input, Complex *output) {
171
+ if (fallback) return fallback->fft(input, output);
172
+ fftInner(input, (float *)output, PFFFT_FORWARD);
173
+ }
174
+ void fft(const float *inR, float *outR, float *outI) {
175
+ if (fallback) return fallback->fft(inR, outR, outI);
176
+ fftInner(inR, tmpAligned, PFFFT_FORWARD);
177
+ for (size_t i = 0; i < _size/2; ++i) {
178
+ outR[i] = tmpAligned[2*i];
179
+ outI[i] = tmpAligned[2*i + 1];
180
+ }
181
+ }
182
+
183
+ void ifft(const Complex *input, float *output) {
184
+ if (fallback) return fallback->ifft(input, output);
185
+ fftInner((const float *)input, output, PFFFT_BACKWARD);
186
+ }
187
+ void ifft(const float *inR, const float *inI, float *outR) {
188
+ if (fallback) return fallback->ifft(inR, inI, outR);
189
+ for (size_t i = 0; i < _size/2; ++i) {
190
+ tmpAligned[2*i] = inR[i];
191
+ tmpAligned[2*i + 1] = inI[i];
192
+ }
193
+ fftInner(tmpAligned, outR, PFFFT_BACKWARD);
194
+ }
195
+
196
+ private:
197
+ void fftInner(const float *input, float *output, pffft_direction_t direction) {
198
+ // 16-byte alignment
199
+ if (size_t(input)&0x0F) {
200
+ // `tmpAligned` is always aligned, so copy into that
201
+ std::memcpy(tmpAligned, input, sizeof(float)*_size);
202
+ input = tmpAligned;
203
+ }
204
+ if (size_t(output)&0x0F) {
205
+ // Output to `tmpAligned` - might be in-place if input is unaligned, but that's fine
206
+ pffft_transform_ordered(fftSetup, input, tmpAligned, work, direction);
207
+ std::memcpy(output, tmpAligned, sizeof(float)*_size);
208
+ } else {
209
+ pffft_transform_ordered(fftSetup, input, output, work, direction);
210
+ }
211
+ }
212
+
213
+ size_t _size = 0;
214
+ bool hasSetup = false;
215
+ PFFFT_Setup *fftSetup = nullptr;
216
+ std::unique_ptr<FallbackFFT> fallback;
217
+ float *work = nullptr, *tmpAligned = nullptr;
218
+ };
219
+
220
+ }} // namespace
221
+ #endif // include guard