loukai-app 0.3.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 (290) hide show
  1. package/README.md +558 -0
  2. package/bin/loukai.js +32 -0
  3. package/package.json +243 -0
  4. package/src/main/appState.js +250 -0
  5. package/src/main/audioEngine.js +478 -0
  6. package/src/main/creator/conversionService.js +503 -0
  7. package/src/main/creator/downloadManager.js +1128 -0
  8. package/src/main/creator/ffmpegService.js +487 -0
  9. package/src/main/creator/installLogger.js +51 -0
  10. package/src/main/creator/keyDetection.js +212 -0
  11. package/src/main/creator/llmService.js +370 -0
  12. package/src/main/creator/lrclibService.js +340 -0
  13. package/src/main/creator/python/crepe_runner.py +189 -0
  14. package/src/main/creator/python/demucs_runner.py +158 -0
  15. package/src/main/creator/python/whisper_runner.py +172 -0
  16. package/src/main/creator/pythonRunner.js +268 -0
  17. package/src/main/creator/stemBuilder.js +491 -0
  18. package/src/main/creator/systemChecker.js +474 -0
  19. package/src/main/handlers/appHandlers.js +45 -0
  20. package/src/main/handlers/audioHandlers.js +33 -0
  21. package/src/main/handlers/autotuneHandlers.js +28 -0
  22. package/src/main/handlers/canvasHandlers.js +84 -0
  23. package/src/main/handlers/creatorHandlers.js +159 -0
  24. package/src/main/handlers/editorHandlers.js +98 -0
  25. package/src/main/handlers/effectsHandlers.js +100 -0
  26. package/src/main/handlers/fileHandlers.js +45 -0
  27. package/src/main/handlers/index.js +78 -0
  28. package/src/main/handlers/libraryHandlers.js +96 -0
  29. package/src/main/handlers/mixerHandlers.js +64 -0
  30. package/src/main/handlers/playerHandlers.js +39 -0
  31. package/src/main/handlers/preferencesHandlers.js +46 -0
  32. package/src/main/handlers/queueHandlers.js +81 -0
  33. package/src/main/handlers/rendererHandlers.js +63 -0
  34. package/src/main/handlers/settingsHandlers.js +42 -0
  35. package/src/main/handlers/webServerHandlers.js +105 -0
  36. package/src/main/main.js +2351 -0
  37. package/src/main/preload.js +252 -0
  38. package/src/main/settingsManager.js +139 -0
  39. package/src/main/statePersistence.js +193 -0
  40. package/src/main/utils/pathValidator.js +112 -0
  41. package/src/main/webServer.js +2535 -0
  42. package/src/native/autotune.js +417 -0
  43. package/src/renderer/adapters/ElectronBridge.js +677 -0
  44. package/src/renderer/canvas.html +80 -0
  45. package/src/renderer/components/App.jsx +303 -0
  46. package/src/renderer/components/AppRoot.jsx +37 -0
  47. package/src/renderer/components/AudioDeviceSettings.jsx +145 -0
  48. package/src/renderer/components/EffectsPanelWrapper.jsx +267 -0
  49. package/src/renderer/components/MixerTab.jsx +233 -0
  50. package/src/renderer/components/MixerTabWrapper.jsx +31 -0
  51. package/src/renderer/components/PortalSelect.jsx +239 -0
  52. package/src/renderer/components/QueueTab.jsx +116 -0
  53. package/src/renderer/components/RequestsListWrapper.jsx +78 -0
  54. package/src/renderer/components/ServerTab.jsx +472 -0
  55. package/src/renderer/components/SongInfoBarWrapper.jsx +77 -0
  56. package/src/renderer/components/StatusBar.jsx +92 -0
  57. package/src/renderer/components/TabNavigation.jsx +77 -0
  58. package/src/renderer/components/TransportControlsWrapper.jsx +69 -0
  59. package/src/renderer/components/creator/CreateTab.jsx +1236 -0
  60. package/src/renderer/dist/assets/kaiPlayer-CoMx__a_.js +2 -0
  61. package/src/renderer/dist/assets/kaiPlayer-CoMx__a_.js.map +1 -0
  62. package/src/renderer/dist/assets/microphoneEngine-BaCUhhQc.js +2 -0
  63. package/src/renderer/dist/assets/microphoneEngine-BaCUhhQc.js.map +1 -0
  64. package/src/renderer/dist/assets/player-DVrqp7N5.js +3 -0
  65. package/src/renderer/dist/assets/player-DVrqp7N5.js.map +1 -0
  66. package/src/renderer/dist/assets/songLoaders-BaTgGib4.js +2 -0
  67. package/src/renderer/dist/assets/songLoaders-BaTgGib4.js.map +1 -0
  68. package/src/renderer/dist/assets/webrtcManager-BhCHWceK.js +2 -0
  69. package/src/renderer/dist/assets/webrtcManager-BhCHWceK.js.map +1 -0
  70. package/src/renderer/dist/js/autoTuneWorklet.js +224 -0
  71. package/src/renderer/dist/js/micPitchDetectorWorklet.js +137 -0
  72. package/src/renderer/dist/js/musicAnalysisWorklet.js +216 -0
  73. package/src/renderer/dist/js/phaseVocoderWorklet.js +341 -0
  74. package/src/renderer/dist/js/soundtouch-worklet.js +1395 -0
  75. package/src/renderer/dist/renderer.css +1 -0
  76. package/src/renderer/dist/renderer.js +62 -0
  77. package/src/renderer/dist/renderer.js.map +1 -0
  78. package/src/renderer/dist/renderer.woff2 +0 -0
  79. package/src/renderer/hooks/useKeyboardShortcuts.js +154 -0
  80. package/src/renderer/index.html +24 -0
  81. package/src/renderer/index.html.backup +372 -0
  82. package/src/renderer/js/PlayerInterface.js +267 -0
  83. package/src/renderer/js/autoTuneWorklet.js +224 -0
  84. package/src/renderer/js/butterchurnVerify.js +46 -0
  85. package/src/renderer/js/canvas-app.js +114 -0
  86. package/src/renderer/js/cdgPlayer.js +685 -0
  87. package/src/renderer/js/kaiPlayer.js +1200 -0
  88. package/src/renderer/js/karaokeRenderer.js +3392 -0
  89. package/src/renderer/js/micPitchDetectorWorklet.js +137 -0
  90. package/src/renderer/js/microphoneEngine.js +656 -0
  91. package/src/renderer/js/musicAnalysisWorklet.js +216 -0
  92. package/src/renderer/js/phaseVocoderWorklet.js +341 -0
  93. package/src/renderer/js/player.js +232 -0
  94. package/src/renderer/js/referencePitchTracker.js +130 -0
  95. package/src/renderer/js/songLoaders.js +334 -0
  96. package/src/renderer/js/soundtouch-worklet.js +1395 -0
  97. package/src/renderer/js/webrtcManager.js +511 -0
  98. package/src/renderer/lib/butterchurn.min.js +6739 -0
  99. package/src/renderer/lib/butterchurnPresets.min.js +1 -0
  100. package/src/renderer/lib/cdgraphics-wrapper.js +16 -0
  101. package/src/renderer/lib/cdgraphics.js +299 -0
  102. package/src/renderer/public/js/autoTuneWorklet.js +224 -0
  103. package/src/renderer/public/js/micPitchDetectorWorklet.js +137 -0
  104. package/src/renderer/public/js/musicAnalysisWorklet.js +216 -0
  105. package/src/renderer/public/js/phaseVocoderWorklet.js +341 -0
  106. package/src/renderer/public/js/soundtouch-worklet.js +1395 -0
  107. package/src/renderer/react-entry.jsx +44 -0
  108. package/src/renderer/styles/tailwind.css +106 -0
  109. package/src/renderer/utils/qrCodeGenerator.js +98 -0
  110. package/src/renderer/vite.config.js +31 -0
  111. package/src/shared/adapters/BridgeInterface.js +195 -0
  112. package/src/shared/components/EffectsPanel.jsx +177 -0
  113. package/src/shared/components/LibraryPanel.jsx +701 -0
  114. package/src/shared/components/LineDetailCanvas.jsx +167 -0
  115. package/src/shared/components/LyricLine.jsx +505 -0
  116. package/src/shared/components/LyricRejection.jsx +84 -0
  117. package/src/shared/components/LyricSuggestion.jsx +80 -0
  118. package/src/shared/components/LyricsEditorCanvas.jsx +271 -0
  119. package/src/shared/components/MixerPanel.jsx +94 -0
  120. package/src/shared/components/PlayerControls.jsx +206 -0
  121. package/src/shared/components/PortalSelect.jsx +239 -0
  122. package/src/shared/components/QueueList.jsx +365 -0
  123. package/src/shared/components/QuickSearch.jsx +126 -0
  124. package/src/shared/components/RequestsList.jsx +121 -0
  125. package/src/shared/components/SongEditor.jsx +1362 -0
  126. package/src/shared/components/SongInfoBar.jsx +81 -0
  127. package/src/shared/components/ThemeToggle.jsx +106 -0
  128. package/src/shared/components/Toast.jsx +30 -0
  129. package/src/shared/components/VisualizationSettings.jsx +243 -0
  130. package/src/shared/constants.js +95 -0
  131. package/src/shared/context/BridgeContext.jsx +32 -0
  132. package/src/shared/contexts/AudioContext.jsx +37 -0
  133. package/src/shared/contexts/PlayerContext.jsx +66 -0
  134. package/src/shared/contexts/SettingsContext.jsx +50 -0
  135. package/src/shared/defaults.js +158 -0
  136. package/src/shared/formatUtils.js +59 -0
  137. package/src/shared/formatUtils.test.js +207 -0
  138. package/src/shared/hooks/useAppState.js +97 -0
  139. package/src/shared/hooks/useAudioEngine.js +264 -0
  140. package/src/shared/hooks/usePlayer.js +89 -0
  141. package/src/shared/hooks/useSettingsPersistence.js +74 -0
  142. package/src/shared/hooks/useWebRTC.js +118 -0
  143. package/src/shared/ipcContracts.js +299 -0
  144. package/src/shared/package.json +3 -0
  145. package/src/shared/services/creatorService.js +373 -0
  146. package/src/shared/services/creatorService.test.js +413 -0
  147. package/src/shared/services/editorService.js +213 -0
  148. package/src/shared/services/editorService.test.js +219 -0
  149. package/src/shared/services/effectsService.js +271 -0
  150. package/src/shared/services/effectsService.test.js +418 -0
  151. package/src/shared/services/libraryService.js +438 -0
  152. package/src/shared/services/libraryService.test.js +474 -0
  153. package/src/shared/services/mixerService.js +172 -0
  154. package/src/shared/services/mixerService.test.js +399 -0
  155. package/src/shared/services/playerService.js +221 -0
  156. package/src/shared/services/playerService.test.js +357 -0
  157. package/src/shared/services/preferencesService.js +219 -0
  158. package/src/shared/services/queueService.js +226 -0
  159. package/src/shared/services/queueService.test.js +430 -0
  160. package/src/shared/services/requestsService.js +155 -0
  161. package/src/shared/services/requestsService.test.js +362 -0
  162. package/src/shared/services/serverSettingsService.js +151 -0
  163. package/src/shared/services/settingsService.js +257 -0
  164. package/src/shared/services/settingsService.test.js +295 -0
  165. package/src/shared/state/StateManager.js +263 -0
  166. package/src/shared/utils/audio.js +42 -0
  167. package/src/shared/utils/format.js +32 -0
  168. package/src/shared/utils/lyricsUtils.js +162 -0
  169. package/src/test/setup.js +40 -0
  170. package/src/utils/cdgLoader.js +180 -0
  171. package/src/utils/m4aLoader.js +333 -0
  172. package/src/web/App.jsx +578 -0
  173. package/src/web/adapters/WebBridge.js +428 -0
  174. package/src/web/components/PlayerSettingsPanel.jsx +231 -0
  175. package/src/web/components/SongSearch.jsx +180 -0
  176. package/src/web/dist/assets/index-0H-RnRrV.js +51 -0
  177. package/src/web/dist/assets/index-0H-RnRrV.js.map +1 -0
  178. package/src/web/dist/assets/index-DYW2zB0u.css +1 -0
  179. package/src/web/dist/index.html +15 -0
  180. package/src/web/index.html +14 -0
  181. package/src/web/main.jsx +10 -0
  182. package/src/web/package-lock.json +1765 -0
  183. package/src/web/pages/SongRequestPage.jsx +619 -0
  184. package/src/web/styles/tailwind.css +68 -0
  185. package/src/web/vite.config.js +27 -0
  186. package/static/fonts/material-icons.woff2 +0 -0
  187. package/static/images/butterchurn-screenshots/Aderrasi - Potion of Spirits.png +0 -0
  188. package/static/images/butterchurn-screenshots/Aderrasi - Songflower _Moss Posy_.png +0 -0
  189. package/static/images/butterchurn-screenshots/Aderrasi - Storm of the Eye _Thunder_ - mash0000 - quasi pseudo meta concentrics.png +0 -0
  190. package/static/images/butterchurn-screenshots/Aderrasi _ Geiss - Airhandler _Kali Mix_ - Canvas Mix.png +0 -0
  191. package/static/images/butterchurn-screenshots/An AdamFX n Martin Infusion 2 flexi - Why The Sky Looks Diffrent Today - AdamFx n Martin Infusion - Tack Tile Disfunction B.png +0 -0
  192. package/static/images/butterchurn-screenshots/Cope - The Neverending Explosion of Red Liquid Fire.png +0 -0
  193. proton lights __Krash_s beat code_ _Phat_remix02b.png +0 -0
  194. package/static/images/butterchurn-screenshots/Eo_S_ _ Phat - cubetrace - v2.png +0 -0
  195. package/static/images/butterchurn-screenshots/Eo_S_ _ Zylot - skylight _Stained Glass Majesty mix_.png +0 -0
  196. package/static/images/butterchurn-screenshots/Flexi - alien fish pond.png +0 -0
  197. package/static/images/butterchurn-screenshots/Flexi - area 51.png +0 -0
  198. package/static/images/butterchurn-screenshots/Flexi - infused with the spiral.png +0 -0
  199. package/static/images/butterchurn-screenshots/Flexi - mindblob _shiny mix_.png +0 -0
  200. package/static/images/butterchurn-screenshots/Flexi - mindblob mix.png +0 -0
  201. package/static/images/butterchurn-screenshots/Flexi - predator-prey-spirals.png +0 -0
  202. package/static/images/butterchurn-screenshots/Flexi - smashing fractals _acid etching mix_.png +0 -0
  203. package/static/images/butterchurn-screenshots/Flexi - truly soft piece of software - this is generic texturing _Jelly_ .png +0 -0
  204. package/static/images/butterchurn-screenshots/Flexi _ Martin - astral projection.png +0 -0
  205. package/static/images/butterchurn-screenshots/Flexi _ Martin - cascading decay swing.png +0 -0
  206. package/static/images/butterchurn-screenshots/Flexi _ amandio c - piercing 05 - Kopie _2_ - Kopie.png +0 -0
  207. package/static/images/butterchurn-screenshots/Flexi _ stahlregen - jelly showoff parade.png +0 -0
  208. package/static/images/butterchurn-screenshots/Flexi_ fishbrain_ Geiss _ Martin - tokamak witchery.png +0 -0
  209. package/static/images/butterchurn-screenshots/Flexi_ martin _ geiss - dedicated to the sherwin maxawow.png +0 -0
  210. package/static/images/butterchurn-screenshots/Fumbling_Foo _ Flexi_ Martin_ Orb_ Unchained - Star Nova v7b.png +0 -0
  211. package/static/images/butterchurn-screenshots/Geiss - Cauldron - painterly 2 _saturation remix_.png +0 -0
  212. package/static/images/butterchurn-screenshots/Geiss - Reaction Diffusion 2.png +0 -0
  213. package/static/images/butterchurn-screenshots/Geiss - Spiral Artifact.png +0 -0
  214. package/static/images/butterchurn-screenshots/Geiss - Thumb Drum.png +0 -0
  215. package/static/images/butterchurn-screenshots/Geiss _ Flexi _ Martin - disconnected.png +0 -0
  216. package/static/images/butterchurn-screenshots/Geiss_ Flexi _ Stahlregen - Thumbdrum Tokamak _crossfiring aftermath jelly mashup_.png +0 -0
  217. package/static/images/butterchurn-screenshots/Goody - The Wild Vort.png +0 -0
  218. package/static/images/butterchurn-screenshots/Idiot - Star Of Annon.png +0 -0
  219. package/static/images/butterchurn-screenshots/Krash _ Illusion - Spiral Movement.png +0 -0
  220. package/static/images/butterchurn-screenshots/Martin - QBikal - Surface Turbulence IIb.png +0 -0
  221. package/static/images/butterchurn-screenshots/Martin - acid wiring.png +0 -0
  222. package/static/images/butterchurn-screenshots/Martin - charisma.png +0 -0
  223. package/static/images/butterchurn-screenshots/Martin - liquid arrows.png +0 -0
  224. package/static/images/butterchurn-screenshots/Milk Artist At our Best - FED - SlowFast Ft AdamFX n Martin - HD CosmoFX.png +0 -0
  225. package/static/images/butterchurn-screenshots/ORB - Waaa.png +0 -0
  226. package/static/images/butterchurn-screenshots/Phat_fiShbRaiN_Eo_S_Mandala_Chasers_remix.png +0 -0
  227. package/static/images/butterchurn-screenshots/Rovastar - Oozing Resistance.png +0 -0
  228. package/static/images/butterchurn-screenshots/Rovastar _ Loadus _ Geiss - FractalDrop _Triple Mix_.png +0 -0
  229. package/static/images/butterchurn-screenshots/TonyMilkdrop - Leonardo Da Vinci_s Balloon _Flexi - merry-go-round _ techstyle_.png +0 -0
  230. package/static/images/butterchurn-screenshots/TonyMilkdrop - Magellan_s Nebula _Flexi - you enter first _ multiverse_.png +0 -0
  231. package/static/images/butterchurn-screenshots/Unchained - Rewop.png +0 -0
  232. package/static/images/butterchurn-screenshots/Unchained - Unified Drag 2.png +0 -0
  233. package/static/images/butterchurn-screenshots/Unchained _ Rovastar - Wormhole Pillars _Hall of Shadows mix_.png +0 -0
  234. package/static/images/butterchurn-screenshots/Zylot - Paint Spill _Music Reactive Paint Mix_.png +0 -0
  235. package/static/images/butterchurn-screenshots/Zylot - Star Ornament.png +0 -0
  236. package/static/images/butterchurn-screenshots/Zylot - True Visionary _Final Mix_.png +0 -0
  237. package/static/images/butterchurn-screenshots/_Aderrasi - Wanderer in Curved Space - mash0000 - faclempt kibitzing meshuggana schmaltz _Geiss color mix_.png +0 -0
  238. package/static/images/butterchurn-screenshots/_Geiss - Artifact 01.png +0 -0
  239. package/static/images/butterchurn-screenshots/_Geiss - Desert Rose 2.png +0 -0
  240. package/static/images/butterchurn-screenshots/_Geiss - untitled.png +0 -0
  241. package/static/images/butterchurn-screenshots/_Mig_049.png +0 -0
  242. package/static/images/butterchurn-screenshots/_Mig_085.png +0 -0
  243. package/static/images/butterchurn-screenshots/_Rovastar _ Geiss - Hurricane Nightmare _Posterize Mix_.png +0 -0
  244. package/static/images/butterchurn-screenshots/___ Royal - Mashup _197_.png +0 -0
  245. package/static/images/butterchurn-screenshots/___ Royal - Mashup _220_.png +0 -0
  246. package/static/images/butterchurn-screenshots/___ Royal - Mashup _431_.png +0 -0
  247. package/static/images/butterchurn-screenshots/cope _ martin - mother-of-pearl.png +0 -0
  248. package/static/images/butterchurn-screenshots/fiShbRaiN _ Flexi - witchcraft 2_0.png +0 -0
  249. package/static/images/butterchurn-screenshots/flexi - bouncing balls _double mindblob neon mix_.png +0 -0
  250. package/static/images/butterchurn-screenshots/flexi - mom_ why the sky looks different today.png +0 -0
  251. package/static/images/butterchurn-screenshots/flexi - patternton_ district of media_ capitol of the united abstractions of fractopia.png +0 -0
  252. package/static/images/butterchurn-screenshots/flexi - swing out on the spiral.png +0 -0
  253. package/static/images/butterchurn-screenshots/flexi - what is the matrix.png +0 -0
  254. package/static/images/butterchurn-screenshots/flexi _ amandio c - organic _random mashup_.png +0 -0
  255. package/static/images/butterchurn-screenshots/flexi _ amandio c - organic12-3d-2_milk.png +0 -0
  256. package/static/images/butterchurn-screenshots/flexi _ fishbrain - neon mindblob grafitti.png +0 -0
  257. package/static/images/butterchurn-screenshots/flexi _ geiss - pogo cubes vs_ tokamak vs_ game of life _stahls jelly 4_5 finish_.png +0 -0
  258. package/static/images/butterchurn-screenshots/high-altitude basket unraveling - singh grooves nitrogen argon nz_.png +0 -0
  259. package/static/images/butterchurn-screenshots/martin - The Bridge of Khazad-Dum.png +0 -0
  260. package/static/images/butterchurn-screenshots/martin - angel flight.png +0 -0
  261. package/static/images/butterchurn-screenshots/martin - another kind of groove.png +0 -0
  262. package/static/images/butterchurn-screenshots/martin - bombyx mori.png +0 -0
  263. package/static/images/butterchurn-screenshots/martin - castle in the air.png +0 -0
  264. package/static/images/butterchurn-screenshots/martin - chain breaker.png +0 -0
  265. package/static/images/butterchurn-screenshots/martin - disco mix 4.png +0 -0
  266. package/static/images/butterchurn-screenshots/martin - extreme heat.png +0 -0
  267. package/static/images/butterchurn-screenshots/martin - frosty caves 2.png +0 -0
  268. package/static/images/butterchurn-screenshots/martin - fruit machine.png +0 -0
  269. package/static/images/butterchurn-screenshots/martin - ghost city.png +0 -0
  270. package/static/images/butterchurn-screenshots/martin - glass corridor.png +0 -0
  271. package/static/images/butterchurn-screenshots/martin - infinity _2010 update_.png +0 -0
  272. package/static/images/butterchurn-screenshots/martin - mandelbox explorer - high speed demo version.png +0 -0
  273. package/static/images/butterchurn-screenshots/martin - mucus cervix.png +0 -0
  274. package/static/images/butterchurn-screenshots/martin - reflections on black tiles.png +0 -0
  275. package/static/images/butterchurn-screenshots/martin - stormy sea _2010 update_.png +0 -0
  276. package/static/images/butterchurn-screenshots/martin - witchcraft reloaded.png +0 -0
  277. package/static/images/butterchurn-screenshots/martin _ flexi - diamond cutter _prismaticvortex_com_ - camille - i wish i wish i wish i was constrained.png +0 -0
  278. package/static/images/butterchurn-screenshots/martin _shadow harlequins shape code_ - fata morgana.png +0 -0
  279. package/static/images/butterchurn-screenshots/martin_ flexi_ fishbrain _ sto - enterstate _random mashup_.png +0 -0
  280. package/static/images/butterchurn-screenshots/sawtooth grin roam.png +0 -0
  281. package/static/images/butterchurn-screenshots/shifter - dark tides bdrv mix 2.png +0 -0
  282. package/static/images/butterchurn-screenshots/suksma - Rovastar - Sunflower Passion _Enlightment Mix__Phat_edit _ flexi und martin shaders - circumflex in character classes in regular expression.png +0 -0
  283. package/static/images/butterchurn-screenshots/suksma - heretical crosscut playpen.png +0 -0
  284. package/static/images/butterchurn-screenshots/suksma - uninitialized variabowl _hydroponic chronic_.png +0 -0
  285. package/static/images/butterchurn-screenshots/suksma - vector exp 1 - couldn_t not.png +0 -0
  286. package/static/images/butterchurn-screenshots/yin - 191 - Temporal singularities.png +0 -0
  287. package/static/images/logo-512.png +0 -0
  288. package/static/images/logo.png +0 -0
  289. package/static/loukai-logo.png +0 -0
  290. package/static/screenshot-generator.html +610 -0
@@ -0,0 +1,656 @@
1
+ /**
2
+ * MicrophoneEngine - Shared microphone input and auto-tune processing
3
+ *
4
+ * This class handles all microphone-related functionality including:
5
+ * - Audio worklet loading (pitch detection, pitch shifting, music analysis)
6
+ * - Microphone input capture and routing
7
+ * - Auto-tune enable/disable and settings
8
+ * - Pitch tracking loop
9
+ *
10
+ * Used by both KAIPlayer and CDGPlayer to eliminate code duplication.
11
+ */
12
+
13
+ import { ReferencePitchTracker } from './referencePitchTracker.js';
14
+
15
+ export class MicrophoneEngine {
16
+ /**
17
+ * @param {AudioContext} audioContext - Web Audio API context
18
+ * @param {AudioNode} outputNode - Destination node for microphone audio
19
+ * @param {Object} options - Configuration options
20
+ * @param {Function} options.getCurrentPosition - Callback to get current playback position (for pitch tracking)
21
+ */
22
+ constructor(audioContext, outputNode, options = {}) {
23
+ this.audioContext = audioContext;
24
+ this.outputNode = outputNode;
25
+ this.getCurrentPosition = options.getCurrentPosition || (() => 0);
26
+
27
+ // Microphone input
28
+ this.microphoneStream = null;
29
+ this.microphoneSource = null;
30
+ this.microphoneGain = null;
31
+ this.inputDevice = 'default';
32
+
33
+ // Auto-tune worklets
34
+ this.micPitchDetectorNode = null;
35
+ this.pitchShifterNode = null;
36
+ this.pitchShifterMakeupGain = null; // Compensate for volume loss in pitch shifter
37
+ this.compressor = null; // Dynamics compressor to prevent clipping
38
+ this.musicAnalysisNode = null;
39
+ this.autoTuneWorkletsLoaded = false;
40
+
41
+ // Pitch tracking
42
+ this.referencePitchTracker = new ReferencePitchTracker();
43
+ this.pitchTrackingInterval = null;
44
+ this.currentMicPitch = null;
45
+ this.currentPitchShift = 0; // For speed smoothing
46
+
47
+ // Settings
48
+ this.autotuneSettings = {
49
+ enabled: false,
50
+ strength: 50, // 0-100
51
+ speed: 20, // 1-100
52
+ preferVocals: true,
53
+ };
54
+
55
+ this.micToSpeakers = true;
56
+ this.enableMic = true;
57
+ }
58
+
59
+ /**
60
+ * Load auto-tune audio worklets into the audio context
61
+ */
62
+ async loadAutoTuneWorklet() {
63
+ try {
64
+ if (!this.audioContext) {
65
+ console.warn('[MicEngine] AudioContext not initialized');
66
+ return;
67
+ }
68
+
69
+ // Ensure AudioContext is running (not suspended) before loading worklets
70
+ if (this.audioContext.state === 'suspended') {
71
+ // console.log('[MicEngine] Resuming suspended AudioContext before loading worklets');
72
+ await this.audioContext.resume();
73
+ }
74
+
75
+ // console.log('[MicEngine] Loading worklet modules...');
76
+
77
+ // Load mic pitch detector worklet
78
+ await this.audioContext.audioWorklet.addModule('js/micPitchDetectorWorklet.js');
79
+
80
+ // Load phase vocoder pitch shifter worklet (high-quality formant-preserving pitch shift)
81
+ await this.audioContext.audioWorklet.addModule('js/phaseVocoderWorklet.js');
82
+
83
+ // Load music analysis worklet (for pitch detection from music)
84
+ await this.audioContext.audioWorklet.addModule('js/musicAnalysisWorklet.js');
85
+
86
+ this.autoTuneWorkletsLoaded = true;
87
+ // console.log('[MicEngine] ✅ Worklets loaded successfully (using phase vocoder)');
88
+ } catch (error) {
89
+ console.error('[MicEngine] ❌ Failed to load worklets:', error);
90
+ this.autoTuneWorkletsLoaded = false;
91
+ }
92
+ }
93
+
94
+ /**
95
+ * Start microphone input
96
+ * @param {string} deviceId - Microphone device ID
97
+ */
98
+ async startMicrophoneInput(deviceId = 'default') {
99
+ try {
100
+ // Don't start mic if disabled
101
+ if (!this.enableMic) {
102
+ return;
103
+ }
104
+
105
+ // Store device ID
106
+ this.inputDevice = deviceId;
107
+
108
+ // Stop existing microphone if running
109
+ this.stopMicrophoneInput();
110
+
111
+ const constraints = {
112
+ audio: {
113
+ deviceId: deviceId !== 'default' ? { exact: deviceId } : undefined,
114
+ channelCount: 1,
115
+ sampleRate: 44100,
116
+ echoCancellation: false,
117
+ noiseSuppression: false,
118
+ autoGainControl: false,
119
+ },
120
+ };
121
+
122
+ // Get microphone stream
123
+ this.microphoneStream = await navigator.mediaDevices.getUserMedia(constraints);
124
+
125
+ // Create audio source from microphone
126
+ this.microphoneSource = this.audioContext.createMediaStreamSource(this.microphoneStream);
127
+
128
+ // Create gain node for microphone volume control
129
+ this.microphoneGain = this.audioContext.createGain();
130
+ this.microphoneGain.gain.value = 1.0; // Full volume, can be adjusted
131
+
132
+ // Connect microphone to gain node
133
+ this.microphoneSource.connect(this.microphoneGain);
134
+
135
+ // Only route to speakers if micToSpeakers is enabled
136
+ if (this.micToSpeakers) {
137
+ // If auto-tune is available and enabled, route through it
138
+ if (this.autoTuneWorkletsLoaded && this.autotuneSettings.enabled) {
139
+ this.enableAutoTune();
140
+ } else {
141
+ // Direct connection to output
142
+ this.microphoneGain.connect(this.outputNode);
143
+ }
144
+ } else {
145
+ // Mic not routed to speakers - captured but silent
146
+ }
147
+ } catch (error) {
148
+ console.error('[MicEngine] Failed to start microphone input:', error);
149
+ this.stopMicrophoneInput();
150
+ }
151
+ }
152
+
153
+ /**
154
+ * Enable auto-tune processing
155
+ */
156
+ enableAutoTune() {
157
+ try {
158
+ if (!this.autoTuneWorkletsLoaded || !this.microphoneGain) {
159
+ console.log(
160
+ '[MicEngine] ❌ Cannot enable - worklets loaded:',
161
+ this.autoTuneWorkletsLoaded,
162
+ 'mic exists:',
163
+ Boolean(this.microphoneGain)
164
+ );
165
+ return;
166
+ }
167
+
168
+ // console.log('[MicEngine] Enabling auto-tune...');
169
+
170
+ // Disconnect current mic connections
171
+ this.microphoneGain.disconnect();
172
+
173
+ // Create mic pitch detector node if it doesn't exist
174
+ if (!this.micPitchDetectorNode) {
175
+ // console.log('[MicEngine] Creating mic pitch detector node');
176
+ this.micPitchDetectorNode = new AudioWorkletNode(this.audioContext, 'mic-pitch-detector');
177
+
178
+ // Listen for pitch detection results
179
+ this.micPitchDetectorNode.port.onmessage = (event) => {
180
+ if (event.data.type === 'pitch') {
181
+ this.currentMicPitch = event.data.frequency;
182
+ }
183
+ };
184
+ }
185
+
186
+ // Create pitch shifter node if it doesn't exist
187
+ if (!this.pitchShifterNode) {
188
+ // console.log('[MicEngine] Creating phase vocoder pitch shifter node');
189
+ this.pitchShifterNode = new AudioWorkletNode(this.audioContext, 'phase-vocoder-processor');
190
+
191
+ // Send sample rate to worklet
192
+ this.pitchShifterNode.port.postMessage({
193
+ type: 'setSampleRate',
194
+ value: this.audioContext.sampleRate,
195
+ });
196
+
197
+ // Initialize pitch shift to 0 (no change)
198
+ if (this.pitchShifterNode.parameters) {
199
+ this.pitchShifterNode.parameters.get('pitchSemitones').value = 0;
200
+ // console.log('[MicEngine] Initialized phase vocoder pitch shift to 0 semitones');
201
+ }
202
+ }
203
+
204
+ // Create makeup gain node (phase vocoder preserves volume better than SoundTouch)
205
+ if (!this.pitchShifterMakeupGain) {
206
+ // console.log('[MicEngine] Creating makeup gain node');
207
+ this.pitchShifterMakeupGain = this.audioContext.createGain();
208
+ // Phase vocoder preserves volume well, only need slight boost
209
+ this.pitchShifterMakeupGain.gain.value = 1.2;
210
+ console.log(
211
+ '[MicEngine] Set makeup gain to 1.2x (phase vocoder has better volume preservation)'
212
+ );
213
+ }
214
+
215
+ // Create dynamics compressor to prevent clipping and smooth out peaks
216
+ if (!this.compressor) {
217
+ // console.log('[MicEngine] Creating dynamics compressor');
218
+ this.compressor = this.audioContext.createDynamicsCompressor();
219
+ // Gentle compression to catch peaks without squashing dynamics
220
+ this.compressor.threshold.value = -24; // dB
221
+ this.compressor.knee.value = 12; // dB (soft knee for natural sound)
222
+ this.compressor.ratio.value = 3; // 3:1 compression ratio
223
+ this.compressor.attack.value = 0.003; // 3ms attack (fast enough to catch transients)
224
+ this.compressor.release.value = 0.1; // 100ms release (natural envelope)
225
+ // console.log('[MicEngine] Compressor configured for smooth auto-tune output');
226
+ }
227
+
228
+ // Create music analysis node for pitch detection from music (fallback)
229
+ if (!this.musicAnalysisNode) {
230
+ // console.log('[MicEngine] Creating music analysis node');
231
+ this.musicAnalysisNode = new AudioWorkletNode(
232
+ this.audioContext,
233
+ 'music-analysis-processor'
234
+ );
235
+
236
+ // Enable pitch detection in music analysis
237
+ this.musicAnalysisNode.port.postMessage({
238
+ type: 'setSampleRate',
239
+ value: this.audioContext.sampleRate,
240
+ });
241
+ this.musicAnalysisNode.port.postMessage({
242
+ type: 'enablePitchDetection',
243
+ value: true,
244
+ });
245
+
246
+ // Listen for music pitch detection
247
+ this.musicAnalysisNode.port.onmessage = (event) => {
248
+ if (event.data.type === 'analysis' && event.data.data.pitch) {
249
+ // Feed music pitch to reference tracker (used when preferVocals is false)
250
+ this.referencePitchTracker.updateMusicPitch(
251
+ event.data.data.pitch,
252
+ this.getCurrentPosition()
253
+ );
254
+ }
255
+ };
256
+ }
257
+
258
+ // Chain: mic → pitch detector → phase vocoder → makeup gain → compressor → output
259
+ console.log(
260
+ '[MicEngine] Connecting audio chain: mic → detector → phase vocoder → makeup → compressor → output'
261
+ );
262
+ this.microphoneGain.connect(this.micPitchDetectorNode);
263
+ this.micPitchDetectorNode.connect(this.pitchShifterNode);
264
+ this.pitchShifterNode.connect(this.pitchShifterMakeupGain);
265
+ this.pitchShifterMakeupGain.connect(this.compressor);
266
+ this.compressor.connect(this.outputNode);
267
+
268
+ // Enable reference pitch tracking
269
+ this.referencePitchTracker.setEnabled(true);
270
+ this.referencePitchTracker.setPreferVocals(this.autotuneSettings.preferVocals);
271
+
272
+ // Start pitch tracking loop
273
+ this.startPitchTracking();
274
+
275
+ console.log(
276
+ '[MicEngine] ✅ Auto-tune enabled with phase vocoder (formant-preserving pitch shift)'
277
+ );
278
+ } catch (error) {
279
+ console.error('[MicEngine] ❌ Failed to enable auto-tune:', error);
280
+ console.error('[MicEngine] Error name:', error.name);
281
+ console.error('[MicEngine] Error message:', error.message);
282
+ console.error('[MicEngine] Error stack:', error.stack);
283
+
284
+ // Try to restore direct connection on error
285
+ try {
286
+ if (this.microphoneGain) {
287
+ this.microphoneGain.disconnect();
288
+ if (this.micToSpeakers) {
289
+ this.microphoneGain.connect(this.outputNode);
290
+ // console.log('[MicEngine] Restored direct mic connection after error');
291
+ }
292
+ }
293
+ } catch (restoreError) {
294
+ console.error('[MicEngine] Failed to restore mic connection:', restoreError.message);
295
+ }
296
+ }
297
+ }
298
+
299
+ /**
300
+ * Disable auto-tune processing
301
+ */
302
+ disableAutoTune() {
303
+ try {
304
+ if (!this.microphoneGain) return;
305
+
306
+ // console.log('[MicEngine] Disabling auto-tune');
307
+
308
+ // Stop pitch tracking
309
+ this.stopPitchTracking();
310
+ this.referencePitchTracker.setEnabled(false);
311
+
312
+ // Disconnect worklet chain
313
+ this.microphoneGain.disconnect();
314
+ if (this.micPitchDetectorNode) {
315
+ this.micPitchDetectorNode.disconnect();
316
+ }
317
+ if (this.pitchShifterNode) {
318
+ this.pitchShifterNode.disconnect();
319
+ }
320
+ if (this.pitchShifterMakeupGain) {
321
+ this.pitchShifterMakeupGain.disconnect();
322
+ }
323
+ if (this.compressor) {
324
+ this.compressor.disconnect();
325
+ }
326
+ if (this.musicAnalysisNode) {
327
+ this.musicAnalysisNode.disconnect();
328
+ }
329
+
330
+ // Only reconnect if mic routing is enabled
331
+ if (this.micToSpeakers) {
332
+ // Direct connection to output
333
+ this.microphoneGain.connect(this.outputNode);
334
+ } else {
335
+ // Mic disabled - stay disconnected
336
+ }
337
+ } catch (error) {
338
+ console.error('[MicEngine] Failed to disable auto-tune:', error);
339
+ }
340
+ }
341
+
342
+ /**
343
+ * Update auto-tune settings
344
+ * @param {Object} settings - Auto-tune settings to update
345
+ */
346
+ setAutoTuneSettings(settings) {
347
+ this.autotuneSettings = { ...this.autotuneSettings, ...settings };
348
+
349
+ // Handle enable/disable
350
+ if (Object.hasOwn(settings, 'enabled')) {
351
+ if (settings.enabled) {
352
+ this.enableAutoTune();
353
+ } else {
354
+ this.disableAutoTune();
355
+ }
356
+ }
357
+
358
+ // Handle preferVocals change
359
+ if (Object.hasOwn(settings, 'preferVocals')) {
360
+ this.referencePitchTracker.setPreferVocals(settings.preferVocals);
361
+ }
362
+
363
+ // Note: strength and speed affect pitch shift amount which is calculated
364
+ // in the pitch tracking loop, not stored in the worklet
365
+ // The worklet just performs the pitch shift we tell it to
366
+
367
+ // If auto-tune should be enabled but isn't running, enable it
368
+ if (settings.enabled && this.microphoneGain && !this.pitchShifterNode) {
369
+ this.enableAutoTune();
370
+ }
371
+ }
372
+
373
+ /**
374
+ * Stop microphone input and cleanup
375
+ */
376
+ stopMicrophoneInput() {
377
+ // Stop pitch tracking
378
+ this.stopPitchTracking();
379
+
380
+ if (this.microphoneSource) {
381
+ this.microphoneSource.disconnect();
382
+ this.microphoneSource = null;
383
+ }
384
+
385
+ if (this.microphoneGain) {
386
+ this.microphoneGain.disconnect();
387
+ this.microphoneGain = null;
388
+ }
389
+
390
+ if (this.micPitchDetectorNode) {
391
+ this.micPitchDetectorNode.disconnect();
392
+ this.micPitchDetectorNode = null;
393
+ }
394
+
395
+ if (this.pitchShifterNode) {
396
+ this.pitchShifterNode.disconnect();
397
+ this.pitchShifterNode = null;
398
+ }
399
+
400
+ if (this.pitchShifterMakeupGain) {
401
+ this.pitchShifterMakeupGain.disconnect();
402
+ this.pitchShifterMakeupGain = null;
403
+ }
404
+
405
+ if (this.compressor) {
406
+ this.compressor.disconnect();
407
+ this.compressor = null;
408
+ }
409
+
410
+ if (this.musicAnalysisNode) {
411
+ this.musicAnalysisNode.disconnect();
412
+ this.musicAnalysisNode = null;
413
+ }
414
+
415
+ if (this.microphoneStream) {
416
+ this.microphoneStream.getTracks().forEach((track) => track.stop());
417
+ this.microphoneStream = null;
418
+ }
419
+ }
420
+
421
+ /**
422
+ * Set microphone gain/volume
423
+ * @param {number} gainValue - Linear gain value (0.0 to 1.0+)
424
+ */
425
+ setMicrophoneGain(gainValue) {
426
+ if (this.microphoneGain) {
427
+ this.microphoneGain.gain.value = gainValue;
428
+ }
429
+ }
430
+
431
+ /**
432
+ * Enable or disable microphone routing to speakers
433
+ * @param {boolean} enabled - Whether to route mic to speakers
434
+ */
435
+ setMicToSpeakers(enabled) {
436
+ this.micToSpeakers = enabled;
437
+
438
+ // Update routing if mic is currently active
439
+ if (this.microphoneGain) {
440
+ this.microphoneGain.disconnect();
441
+
442
+ if (enabled) {
443
+ // Reconnect to speakers
444
+ if (this.autoTuneWorkletsLoaded && this.autotuneSettings.enabled) {
445
+ this.enableAutoTune();
446
+ } else {
447
+ this.microphoneGain.connect(this.outputNode);
448
+ }
449
+ }
450
+ // If disabled, mic stays disconnected (captured but not routed)
451
+ }
452
+ }
453
+
454
+ /**
455
+ * Enable or disable microphone input entirely
456
+ * @param {boolean} enabled - Whether to enable microphone
457
+ */
458
+ async setEnableMic(enabled) {
459
+ this.enableMic = enabled;
460
+
461
+ if (enabled) {
462
+ // Restart mic with saved device preference
463
+ await this.startMicrophoneInput(this.inputDevice);
464
+ } else {
465
+ // Stop mic completely
466
+ this.stopMicrophoneInput();
467
+ }
468
+ }
469
+
470
+ /**
471
+ * Start pitch tracking loop for auto-tune
472
+ */
473
+ startPitchTracking() {
474
+ // Stop existing tracking first
475
+ this.stopPitchTracking();
476
+
477
+ if (!this.autotuneSettings.enabled || !this.pitchShifterNode) {
478
+ console.log(
479
+ '[MicEngine] Cannot start pitch tracking - enabled:',
480
+ this.autotuneSettings.enabled,
481
+ 'shifter exists:',
482
+ Boolean(this.pitchShifterNode)
483
+ );
484
+ return;
485
+ }
486
+
487
+ // console.log('[MicEngine] Starting pitch tracking loop (20Hz)');
488
+
489
+ // Update pitch tracking at ~20Hz (every 50ms)
490
+ this.pitchTrackingInterval = setInterval(() => {
491
+ // Update playback time in reference tracker
492
+ const currentTime = this.getCurrentPosition();
493
+ this.referencePitchTracker.updateTime(currentTime);
494
+
495
+ // Get target pitch from reference (vocals_f0 or music)
496
+ const targetPitch = this.referencePitchTracker.getCurrentTargetPitch();
497
+
498
+ // Get current mic pitch
499
+ const micPitch = this.currentMicPitch;
500
+
501
+ // Calculate pitch correction
502
+ if (targetPitch && micPitch && micPitch > 0) {
503
+ // DEBUG: Log pitch values every 2 seconds
504
+ if (!this._lastDebugLog || Date.now() - this._lastDebugLog > 2000) {
505
+ console.log('[AutoTune Debug]', {
506
+ targetPitch: targetPitch.toFixed(2) + 'Hz',
507
+ micPitch: micPitch.toFixed(2) + 'Hz',
508
+ source: this.referencePitchTracker.getCurrentSource(),
509
+ preferVocals: this.autotuneSettings.preferVocals,
510
+ });
511
+ this._lastDebugLog = Date.now();
512
+ }
513
+
514
+ // Calculate semitones difference
515
+ let semitones = 12 * Math.log2(targetPitch / micPitch);
516
+
517
+ // Octave correction: snap to nearest octave within ±12 semitones
518
+ // This prevents extreme pitch shifts when octave detection errors occur
519
+ // Example: +26 semitones becomes +2 semitones (subtract 24 = 2 octaves)
520
+ while (semitones > 12) {
521
+ semitones -= 12;
522
+ }
523
+ while (semitones < -12) {
524
+ semitones += 12;
525
+ }
526
+
527
+ // Safety clamp to valid range [-24, +24] (should rarely be needed after octave correction)
528
+ semitones = Math.max(-24, Math.min(24, semitones));
529
+
530
+ // DEBUG: Log correction being applied
531
+ if (!this._lastCorrectionLog || Date.now() - this._lastCorrectionLog > 2000) {
532
+ console.log('[AutoTune Correction]', {
533
+ semitones: semitones.toFixed(2),
534
+ strength: this.autotuneSettings.strength + '%',
535
+ targetShift: (semitones * (this.autotuneSettings.strength / 100)).toFixed(2),
536
+ currentShift: this.currentPitchShift.toFixed(2),
537
+ });
538
+ this._lastCorrectionLog = Date.now();
539
+ }
540
+
541
+ // Apply strength (0-100 -> 0-1)
542
+ const strength = this.autotuneSettings.strength / 100;
543
+ const targetShift = semitones * strength;
544
+
545
+ // Apply speed/smoothing (1-100 -> 0.01-1.0)
546
+ // Low speed = slow/gradual = natural sound
547
+ // High speed = fast/instant = robotic effect
548
+ const speed = this.autotuneSettings.speed / 100;
549
+ this.currentPitchShift = this.currentPitchShift * (1 - speed) + targetShift * speed;
550
+
551
+ // Final clamp for smoothed output (prevents accumulated errors)
552
+ this.currentPitchShift = Math.max(-24, Math.min(24, this.currentPitchShift));
553
+
554
+ // Set pitch shift on the worklet
555
+ if (this.pitchShifterNode.parameters) {
556
+ this.pitchShifterNode.parameters.get('pitchSemitones').value = this.currentPitchShift;
557
+ }
558
+ } else {
559
+ // No correction needed - keep pitch shift at 0 (pass-through)
560
+ // This allows mic audio to pass through unmodified when no target pitch
561
+ if (this.pitchShifterNode.parameters) {
562
+ this.pitchShifterNode.parameters.get('pitchSemitones').value = 0;
563
+ }
564
+ this.currentPitchShift = 0;
565
+ }
566
+ }, 50); // 20Hz update rate
567
+ }
568
+
569
+ /**
570
+ * Stop pitch tracking loop
571
+ */
572
+ stopPitchTracking() {
573
+ if (this.pitchTrackingInterval) {
574
+ clearInterval(this.pitchTrackingInterval);
575
+ this.pitchTrackingInterval = null;
576
+ // console.log('[MicEngine] Stopped pitch tracking loop');
577
+ }
578
+ }
579
+
580
+ /**
581
+ * Legacy method - stored pitch data is no longer used
582
+ * Pitch detection is now done in real-time from the vocal stem
583
+ * @deprecated
584
+ */
585
+ loadVocalsF0() {
586
+ // No-op - pitch detection is now done at runtime
587
+ }
588
+
589
+ /**
590
+ * Clear pitch reference data (resets real-time tracking state)
591
+ */
592
+ clearPitchReference() {
593
+ this.referencePitchTracker.clear();
594
+ }
595
+
596
+ /**
597
+ * Set whether playback is active (for pitch tracking)
598
+ * @param {boolean} playing - Whether audio is playing
599
+ */
600
+ setPlaying(playing) {
601
+ this.referencePitchTracker.setPlaying(playing);
602
+
603
+ // Only start pitch tracking if auto-tune is enabled
604
+ if (playing && this.autotuneSettings.enabled) {
605
+ this.startPitchTracking();
606
+ } else {
607
+ this.stopPitchTracking();
608
+ }
609
+ }
610
+
611
+ /**
612
+ * Connect a music source to the music analysis node for pitch detection
613
+ * @param {AudioNode} sourceNode - Audio source node to analyze
614
+ */
615
+ connectMusicSource(sourceNode) {
616
+ if (this.musicAnalysisNode && sourceNode) {
617
+ try {
618
+ sourceNode.connect(this.musicAnalysisNode);
619
+ // console.log('[MicEngine] Connected music source to pitch analysis');
620
+ } catch (error) {
621
+ console.error('[MicEngine] Failed to connect music source:', error);
622
+ }
623
+ }
624
+ }
625
+
626
+ /**
627
+ * Disconnect music source from analysis
628
+ * @param {AudioNode} sourceNode - Audio source node to disconnect
629
+ */
630
+ disconnectMusicSource(sourceNode) {
631
+ if (this.musicAnalysisNode && sourceNode) {
632
+ try {
633
+ sourceNode.disconnect(this.musicAnalysisNode);
634
+ } catch {
635
+ // May not be connected, that's okay
636
+ }
637
+ }
638
+ }
639
+
640
+ /**
641
+ * Update the audio context and output node (e.g., when contexts are recreated)
642
+ * @param {AudioContext} audioContext - New audio context
643
+ * @param {AudioNode} outputNode - New output node
644
+ */
645
+ updateAudioContext(audioContext, outputNode) {
646
+ // Stop everything first
647
+ this.stopMicrophoneInput();
648
+
649
+ // Update references
650
+ this.audioContext = audioContext;
651
+ this.outputNode = outputNode;
652
+
653
+ // Reset worklet loaded flag (worklets are lost when context is recreated)
654
+ this.autoTuneWorkletsLoaded = false;
655
+ }
656
+ }