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.
- package/README.md +558 -0
- package/bin/loukai.js +32 -0
- package/package.json +243 -0
- package/src/main/appState.js +250 -0
- package/src/main/audioEngine.js +478 -0
- package/src/main/creator/conversionService.js +503 -0
- package/src/main/creator/downloadManager.js +1128 -0
- package/src/main/creator/ffmpegService.js +487 -0
- package/src/main/creator/installLogger.js +51 -0
- package/src/main/creator/keyDetection.js +212 -0
- package/src/main/creator/llmService.js +370 -0
- package/src/main/creator/lrclibService.js +340 -0
- package/src/main/creator/python/crepe_runner.py +189 -0
- package/src/main/creator/python/demucs_runner.py +158 -0
- package/src/main/creator/python/whisper_runner.py +172 -0
- package/src/main/creator/pythonRunner.js +268 -0
- package/src/main/creator/stemBuilder.js +491 -0
- package/src/main/creator/systemChecker.js +474 -0
- package/src/main/handlers/appHandlers.js +45 -0
- package/src/main/handlers/audioHandlers.js +33 -0
- package/src/main/handlers/autotuneHandlers.js +28 -0
- package/src/main/handlers/canvasHandlers.js +84 -0
- package/src/main/handlers/creatorHandlers.js +159 -0
- package/src/main/handlers/editorHandlers.js +98 -0
- package/src/main/handlers/effectsHandlers.js +100 -0
- package/src/main/handlers/fileHandlers.js +45 -0
- package/src/main/handlers/index.js +78 -0
- package/src/main/handlers/libraryHandlers.js +96 -0
- package/src/main/handlers/mixerHandlers.js +64 -0
- package/src/main/handlers/playerHandlers.js +39 -0
- package/src/main/handlers/preferencesHandlers.js +46 -0
- package/src/main/handlers/queueHandlers.js +81 -0
- package/src/main/handlers/rendererHandlers.js +63 -0
- package/src/main/handlers/settingsHandlers.js +42 -0
- package/src/main/handlers/webServerHandlers.js +105 -0
- package/src/main/main.js +2351 -0
- package/src/main/preload.js +252 -0
- package/src/main/settingsManager.js +139 -0
- package/src/main/statePersistence.js +193 -0
- package/src/main/utils/pathValidator.js +112 -0
- package/src/main/webServer.js +2535 -0
- package/src/native/autotune.js +417 -0
- package/src/renderer/adapters/ElectronBridge.js +677 -0
- package/src/renderer/canvas.html +80 -0
- package/src/renderer/components/App.jsx +303 -0
- package/src/renderer/components/AppRoot.jsx +37 -0
- package/src/renderer/components/AudioDeviceSettings.jsx +145 -0
- package/src/renderer/components/EffectsPanelWrapper.jsx +267 -0
- package/src/renderer/components/MixerTab.jsx +233 -0
- package/src/renderer/components/MixerTabWrapper.jsx +31 -0
- package/src/renderer/components/PortalSelect.jsx +239 -0
- package/src/renderer/components/QueueTab.jsx +116 -0
- package/src/renderer/components/RequestsListWrapper.jsx +78 -0
- package/src/renderer/components/ServerTab.jsx +472 -0
- package/src/renderer/components/SongInfoBarWrapper.jsx +77 -0
- package/src/renderer/components/StatusBar.jsx +92 -0
- package/src/renderer/components/TabNavigation.jsx +77 -0
- package/src/renderer/components/TransportControlsWrapper.jsx +69 -0
- package/src/renderer/components/creator/CreateTab.jsx +1236 -0
- package/src/renderer/dist/assets/kaiPlayer-CoMx__a_.js +2 -0
- package/src/renderer/dist/assets/kaiPlayer-CoMx__a_.js.map +1 -0
- package/src/renderer/dist/assets/microphoneEngine-BaCUhhQc.js +2 -0
- package/src/renderer/dist/assets/microphoneEngine-BaCUhhQc.js.map +1 -0
- package/src/renderer/dist/assets/player-DVrqp7N5.js +3 -0
- package/src/renderer/dist/assets/player-DVrqp7N5.js.map +1 -0
- package/src/renderer/dist/assets/songLoaders-BaTgGib4.js +2 -0
- package/src/renderer/dist/assets/songLoaders-BaTgGib4.js.map +1 -0
- package/src/renderer/dist/assets/webrtcManager-BhCHWceK.js +2 -0
- package/src/renderer/dist/assets/webrtcManager-BhCHWceK.js.map +1 -0
- package/src/renderer/dist/js/autoTuneWorklet.js +224 -0
- package/src/renderer/dist/js/micPitchDetectorWorklet.js +137 -0
- package/src/renderer/dist/js/musicAnalysisWorklet.js +216 -0
- package/src/renderer/dist/js/phaseVocoderWorklet.js +341 -0
- package/src/renderer/dist/js/soundtouch-worklet.js +1395 -0
- package/src/renderer/dist/renderer.css +1 -0
- package/src/renderer/dist/renderer.js +62 -0
- package/src/renderer/dist/renderer.js.map +1 -0
- package/src/renderer/dist/renderer.woff2 +0 -0
- package/src/renderer/hooks/useKeyboardShortcuts.js +154 -0
- package/src/renderer/index.html +24 -0
- package/src/renderer/index.html.backup +372 -0
- package/src/renderer/js/PlayerInterface.js +267 -0
- package/src/renderer/js/autoTuneWorklet.js +224 -0
- package/src/renderer/js/butterchurnVerify.js +46 -0
- package/src/renderer/js/canvas-app.js +114 -0
- package/src/renderer/js/cdgPlayer.js +685 -0
- package/src/renderer/js/kaiPlayer.js +1200 -0
- package/src/renderer/js/karaokeRenderer.js +3392 -0
- package/src/renderer/js/micPitchDetectorWorklet.js +137 -0
- package/src/renderer/js/microphoneEngine.js +656 -0
- package/src/renderer/js/musicAnalysisWorklet.js +216 -0
- package/src/renderer/js/phaseVocoderWorklet.js +341 -0
- package/src/renderer/js/player.js +232 -0
- package/src/renderer/js/referencePitchTracker.js +130 -0
- package/src/renderer/js/songLoaders.js +334 -0
- package/src/renderer/js/soundtouch-worklet.js +1395 -0
- package/src/renderer/js/webrtcManager.js +511 -0
- package/src/renderer/lib/butterchurn.min.js +6739 -0
- package/src/renderer/lib/butterchurnPresets.min.js +1 -0
- package/src/renderer/lib/cdgraphics-wrapper.js +16 -0
- package/src/renderer/lib/cdgraphics.js +299 -0
- package/src/renderer/public/js/autoTuneWorklet.js +224 -0
- package/src/renderer/public/js/micPitchDetectorWorklet.js +137 -0
- package/src/renderer/public/js/musicAnalysisWorklet.js +216 -0
- package/src/renderer/public/js/phaseVocoderWorklet.js +341 -0
- package/src/renderer/public/js/soundtouch-worklet.js +1395 -0
- package/src/renderer/react-entry.jsx +44 -0
- package/src/renderer/styles/tailwind.css +106 -0
- package/src/renderer/utils/qrCodeGenerator.js +98 -0
- package/src/renderer/vite.config.js +31 -0
- package/src/shared/adapters/BridgeInterface.js +195 -0
- package/src/shared/components/EffectsPanel.jsx +177 -0
- package/src/shared/components/LibraryPanel.jsx +701 -0
- package/src/shared/components/LineDetailCanvas.jsx +167 -0
- package/src/shared/components/LyricLine.jsx +505 -0
- package/src/shared/components/LyricRejection.jsx +84 -0
- package/src/shared/components/LyricSuggestion.jsx +80 -0
- package/src/shared/components/LyricsEditorCanvas.jsx +271 -0
- package/src/shared/components/MixerPanel.jsx +94 -0
- package/src/shared/components/PlayerControls.jsx +206 -0
- package/src/shared/components/PortalSelect.jsx +239 -0
- package/src/shared/components/QueueList.jsx +365 -0
- package/src/shared/components/QuickSearch.jsx +126 -0
- package/src/shared/components/RequestsList.jsx +121 -0
- package/src/shared/components/SongEditor.jsx +1362 -0
- package/src/shared/components/SongInfoBar.jsx +81 -0
- package/src/shared/components/ThemeToggle.jsx +106 -0
- package/src/shared/components/Toast.jsx +30 -0
- package/src/shared/components/VisualizationSettings.jsx +243 -0
- package/src/shared/constants.js +95 -0
- package/src/shared/context/BridgeContext.jsx +32 -0
- package/src/shared/contexts/AudioContext.jsx +37 -0
- package/src/shared/contexts/PlayerContext.jsx +66 -0
- package/src/shared/contexts/SettingsContext.jsx +50 -0
- package/src/shared/defaults.js +158 -0
- package/src/shared/formatUtils.js +59 -0
- package/src/shared/formatUtils.test.js +207 -0
- package/src/shared/hooks/useAppState.js +97 -0
- package/src/shared/hooks/useAudioEngine.js +264 -0
- package/src/shared/hooks/usePlayer.js +89 -0
- package/src/shared/hooks/useSettingsPersistence.js +74 -0
- package/src/shared/hooks/useWebRTC.js +118 -0
- package/src/shared/ipcContracts.js +299 -0
- package/src/shared/package.json +3 -0
- package/src/shared/services/creatorService.js +373 -0
- package/src/shared/services/creatorService.test.js +413 -0
- package/src/shared/services/editorService.js +213 -0
- package/src/shared/services/editorService.test.js +219 -0
- package/src/shared/services/effectsService.js +271 -0
- package/src/shared/services/effectsService.test.js +418 -0
- package/src/shared/services/libraryService.js +438 -0
- package/src/shared/services/libraryService.test.js +474 -0
- package/src/shared/services/mixerService.js +172 -0
- package/src/shared/services/mixerService.test.js +399 -0
- package/src/shared/services/playerService.js +221 -0
- package/src/shared/services/playerService.test.js +357 -0
- package/src/shared/services/preferencesService.js +219 -0
- package/src/shared/services/queueService.js +226 -0
- package/src/shared/services/queueService.test.js +430 -0
- package/src/shared/services/requestsService.js +155 -0
- package/src/shared/services/requestsService.test.js +362 -0
- package/src/shared/services/serverSettingsService.js +151 -0
- package/src/shared/services/settingsService.js +257 -0
- package/src/shared/services/settingsService.test.js +295 -0
- package/src/shared/state/StateManager.js +263 -0
- package/src/shared/utils/audio.js +42 -0
- package/src/shared/utils/format.js +32 -0
- package/src/shared/utils/lyricsUtils.js +162 -0
- package/src/test/setup.js +40 -0
- package/src/utils/cdgLoader.js +180 -0
- package/src/utils/m4aLoader.js +333 -0
- package/src/web/App.jsx +578 -0
- package/src/web/adapters/WebBridge.js +428 -0
- package/src/web/components/PlayerSettingsPanel.jsx +231 -0
- package/src/web/components/SongSearch.jsx +180 -0
- package/src/web/dist/assets/index-0H-RnRrV.js +51 -0
- package/src/web/dist/assets/index-0H-RnRrV.js.map +1 -0
- package/src/web/dist/assets/index-DYW2zB0u.css +1 -0
- package/src/web/dist/index.html +15 -0
- package/src/web/index.html +14 -0
- package/src/web/main.jsx +10 -0
- package/src/web/package-lock.json +1765 -0
- package/src/web/pages/SongRequestPage.jsx +619 -0
- package/src/web/styles/tailwind.css +68 -0
- package/src/web/vite.config.js +27 -0
- package/static/fonts/material-icons.woff2 +0 -0
- package/static/images/butterchurn-screenshots/Aderrasi - Potion of Spirits.png +0 -0
- package/static/images/butterchurn-screenshots/Aderrasi - Songflower _Moss Posy_.png +0 -0
- package/static/images/butterchurn-screenshots/Aderrasi - Storm of the Eye _Thunder_ - mash0000 - quasi pseudo meta concentrics.png +0 -0
- package/static/images/butterchurn-screenshots/Aderrasi _ Geiss - Airhandler _Kali Mix_ - Canvas Mix.png +0 -0
- 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
- package/static/images/butterchurn-screenshots/Cope - The Neverending Explosion of Red Liquid Fire.png +0 -0
- proton lights __Krash_s beat code_ _Phat_remix02b.png +0 -0
- package/static/images/butterchurn-screenshots/Eo_S_ _ Phat - cubetrace - v2.png +0 -0
- package/static/images/butterchurn-screenshots/Eo_S_ _ Zylot - skylight _Stained Glass Majesty mix_.png +0 -0
- package/static/images/butterchurn-screenshots/Flexi - alien fish pond.png +0 -0
- package/static/images/butterchurn-screenshots/Flexi - area 51.png +0 -0
- package/static/images/butterchurn-screenshots/Flexi - infused with the spiral.png +0 -0
- package/static/images/butterchurn-screenshots/Flexi - mindblob _shiny mix_.png +0 -0
- package/static/images/butterchurn-screenshots/Flexi - mindblob mix.png +0 -0
- package/static/images/butterchurn-screenshots/Flexi - predator-prey-spirals.png +0 -0
- package/static/images/butterchurn-screenshots/Flexi - smashing fractals _acid etching mix_.png +0 -0
- package/static/images/butterchurn-screenshots/Flexi - truly soft piece of software - this is generic texturing _Jelly_ .png +0 -0
- package/static/images/butterchurn-screenshots/Flexi _ Martin - astral projection.png +0 -0
- package/static/images/butterchurn-screenshots/Flexi _ Martin - cascading decay swing.png +0 -0
- package/static/images/butterchurn-screenshots/Flexi _ amandio c - piercing 05 - Kopie _2_ - Kopie.png +0 -0
- package/static/images/butterchurn-screenshots/Flexi _ stahlregen - jelly showoff parade.png +0 -0
- package/static/images/butterchurn-screenshots/Flexi_ fishbrain_ Geiss _ Martin - tokamak witchery.png +0 -0
- package/static/images/butterchurn-screenshots/Flexi_ martin _ geiss - dedicated to the sherwin maxawow.png +0 -0
- package/static/images/butterchurn-screenshots/Fumbling_Foo _ Flexi_ Martin_ Orb_ Unchained - Star Nova v7b.png +0 -0
- package/static/images/butterchurn-screenshots/Geiss - Cauldron - painterly 2 _saturation remix_.png +0 -0
- package/static/images/butterchurn-screenshots/Geiss - Reaction Diffusion 2.png +0 -0
- package/static/images/butterchurn-screenshots/Geiss - Spiral Artifact.png +0 -0
- package/static/images/butterchurn-screenshots/Geiss - Thumb Drum.png +0 -0
- package/static/images/butterchurn-screenshots/Geiss _ Flexi _ Martin - disconnected.png +0 -0
- package/static/images/butterchurn-screenshots/Geiss_ Flexi _ Stahlregen - Thumbdrum Tokamak _crossfiring aftermath jelly mashup_.png +0 -0
- package/static/images/butterchurn-screenshots/Goody - The Wild Vort.png +0 -0
- package/static/images/butterchurn-screenshots/Idiot - Star Of Annon.png +0 -0
- package/static/images/butterchurn-screenshots/Krash _ Illusion - Spiral Movement.png +0 -0
- package/static/images/butterchurn-screenshots/Martin - QBikal - Surface Turbulence IIb.png +0 -0
- package/static/images/butterchurn-screenshots/Martin - acid wiring.png +0 -0
- package/static/images/butterchurn-screenshots/Martin - charisma.png +0 -0
- package/static/images/butterchurn-screenshots/Martin - liquid arrows.png +0 -0
- package/static/images/butterchurn-screenshots/Milk Artist At our Best - FED - SlowFast Ft AdamFX n Martin - HD CosmoFX.png +0 -0
- package/static/images/butterchurn-screenshots/ORB - Waaa.png +0 -0
- package/static/images/butterchurn-screenshots/Phat_fiShbRaiN_Eo_S_Mandala_Chasers_remix.png +0 -0
- package/static/images/butterchurn-screenshots/Rovastar - Oozing Resistance.png +0 -0
- package/static/images/butterchurn-screenshots/Rovastar _ Loadus _ Geiss - FractalDrop _Triple Mix_.png +0 -0
- package/static/images/butterchurn-screenshots/TonyMilkdrop - Leonardo Da Vinci_s Balloon _Flexi - merry-go-round _ techstyle_.png +0 -0
- package/static/images/butterchurn-screenshots/TonyMilkdrop - Magellan_s Nebula _Flexi - you enter first _ multiverse_.png +0 -0
- package/static/images/butterchurn-screenshots/Unchained - Rewop.png +0 -0
- package/static/images/butterchurn-screenshots/Unchained - Unified Drag 2.png +0 -0
- package/static/images/butterchurn-screenshots/Unchained _ Rovastar - Wormhole Pillars _Hall of Shadows mix_.png +0 -0
- package/static/images/butterchurn-screenshots/Zylot - Paint Spill _Music Reactive Paint Mix_.png +0 -0
- package/static/images/butterchurn-screenshots/Zylot - Star Ornament.png +0 -0
- package/static/images/butterchurn-screenshots/Zylot - True Visionary _Final Mix_.png +0 -0
- package/static/images/butterchurn-screenshots/_Aderrasi - Wanderer in Curved Space - mash0000 - faclempt kibitzing meshuggana schmaltz _Geiss color mix_.png +0 -0
- package/static/images/butterchurn-screenshots/_Geiss - Artifact 01.png +0 -0
- package/static/images/butterchurn-screenshots/_Geiss - Desert Rose 2.png +0 -0
- package/static/images/butterchurn-screenshots/_Geiss - untitled.png +0 -0
- package/static/images/butterchurn-screenshots/_Mig_049.png +0 -0
- package/static/images/butterchurn-screenshots/_Mig_085.png +0 -0
- package/static/images/butterchurn-screenshots/_Rovastar _ Geiss - Hurricane Nightmare _Posterize Mix_.png +0 -0
- package/static/images/butterchurn-screenshots/___ Royal - Mashup _197_.png +0 -0
- package/static/images/butterchurn-screenshots/___ Royal - Mashup _220_.png +0 -0
- package/static/images/butterchurn-screenshots/___ Royal - Mashup _431_.png +0 -0
- package/static/images/butterchurn-screenshots/cope _ martin - mother-of-pearl.png +0 -0
- package/static/images/butterchurn-screenshots/fiShbRaiN _ Flexi - witchcraft 2_0.png +0 -0
- package/static/images/butterchurn-screenshots/flexi - bouncing balls _double mindblob neon mix_.png +0 -0
- package/static/images/butterchurn-screenshots/flexi - mom_ why the sky looks different today.png +0 -0
- package/static/images/butterchurn-screenshots/flexi - patternton_ district of media_ capitol of the united abstractions of fractopia.png +0 -0
- package/static/images/butterchurn-screenshots/flexi - swing out on the spiral.png +0 -0
- package/static/images/butterchurn-screenshots/flexi - what is the matrix.png +0 -0
- package/static/images/butterchurn-screenshots/flexi _ amandio c - organic _random mashup_.png +0 -0
- package/static/images/butterchurn-screenshots/flexi _ amandio c - organic12-3d-2_milk.png +0 -0
- package/static/images/butterchurn-screenshots/flexi _ fishbrain - neon mindblob grafitti.png +0 -0
- package/static/images/butterchurn-screenshots/flexi _ geiss - pogo cubes vs_ tokamak vs_ game of life _stahls jelly 4_5 finish_.png +0 -0
- package/static/images/butterchurn-screenshots/high-altitude basket unraveling - singh grooves nitrogen argon nz_.png +0 -0
- package/static/images/butterchurn-screenshots/martin - The Bridge of Khazad-Dum.png +0 -0
- package/static/images/butterchurn-screenshots/martin - angel flight.png +0 -0
- package/static/images/butterchurn-screenshots/martin - another kind of groove.png +0 -0
- package/static/images/butterchurn-screenshots/martin - bombyx mori.png +0 -0
- package/static/images/butterchurn-screenshots/martin - castle in the air.png +0 -0
- package/static/images/butterchurn-screenshots/martin - chain breaker.png +0 -0
- package/static/images/butterchurn-screenshots/martin - disco mix 4.png +0 -0
- package/static/images/butterchurn-screenshots/martin - extreme heat.png +0 -0
- package/static/images/butterchurn-screenshots/martin - frosty caves 2.png +0 -0
- package/static/images/butterchurn-screenshots/martin - fruit machine.png +0 -0
- package/static/images/butterchurn-screenshots/martin - ghost city.png +0 -0
- package/static/images/butterchurn-screenshots/martin - glass corridor.png +0 -0
- package/static/images/butterchurn-screenshots/martin - infinity _2010 update_.png +0 -0
- package/static/images/butterchurn-screenshots/martin - mandelbox explorer - high speed demo version.png +0 -0
- package/static/images/butterchurn-screenshots/martin - mucus cervix.png +0 -0
- package/static/images/butterchurn-screenshots/martin - reflections on black tiles.png +0 -0
- package/static/images/butterchurn-screenshots/martin - stormy sea _2010 update_.png +0 -0
- package/static/images/butterchurn-screenshots/martin - witchcraft reloaded.png +0 -0
- package/static/images/butterchurn-screenshots/martin _ flexi - diamond cutter _prismaticvortex_com_ - camille - i wish i wish i wish i was constrained.png +0 -0
- package/static/images/butterchurn-screenshots/martin _shadow harlequins shape code_ - fata morgana.png +0 -0
- package/static/images/butterchurn-screenshots/martin_ flexi_ fishbrain _ sto - enterstate _random mashup_.png +0 -0
- package/static/images/butterchurn-screenshots/sawtooth grin roam.png +0 -0
- package/static/images/butterchurn-screenshots/shifter - dark tides bdrv mix 2.png +0 -0
- 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
- package/static/images/butterchurn-screenshots/suksma - heretical crosscut playpen.png +0 -0
- package/static/images/butterchurn-screenshots/suksma - uninitialized variabowl _hydroponic chronic_.png +0 -0
- package/static/images/butterchurn-screenshots/suksma - vector exp 1 - couldn_t not.png +0 -0
- package/static/images/butterchurn-screenshots/yin - 191 - Temporal singularities.png +0 -0
- package/static/images/logo-512.png +0 -0
- package/static/images/logo.png +0 -0
- package/static/loukai-logo.png +0 -0
- package/static/screenshot-generator.html +610 -0
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase Vocoder Audio Worklet Processor
|
|
3
|
+
*
|
|
4
|
+
* High-quality pitch shifting with formant preservation for vocal auto-tune.
|
|
5
|
+
* Uses FFT-based spectral processing for natural-sounding pitch correction.
|
|
6
|
+
*
|
|
7
|
+
* Algorithm:
|
|
8
|
+
* 1. FFT - Convert time-domain audio to frequency spectrum
|
|
9
|
+
* 2. Phase unwrapping - Track phase evolution across frames
|
|
10
|
+
* 3. Pitch shift - Resample spectrum to new pitch
|
|
11
|
+
* 4. Formant preservation - Maintain vocal tract characteristics
|
|
12
|
+
* 5. IFFT - Convert back to time domain
|
|
13
|
+
* 6. Overlap-add - Reconstruct continuous audio
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
class PhaseVocoderProcessor extends AudioWorkletProcessor {
|
|
17
|
+
constructor() {
|
|
18
|
+
super();
|
|
19
|
+
|
|
20
|
+
// Configuration
|
|
21
|
+
this.fftSize = 2048; // Balance between quality and latency
|
|
22
|
+
this.hopSize = 512; // 75% overlap (fftSize / 4)
|
|
23
|
+
this.sampleRate = 48000; // Will be updated from messages
|
|
24
|
+
|
|
25
|
+
// Pitch shift parameter (in semitones)
|
|
26
|
+
this.pitchShift = 0;
|
|
27
|
+
|
|
28
|
+
// Buffers
|
|
29
|
+
this.inputBuffer = new Float32Array(this.fftSize);
|
|
30
|
+
this.outputBuffer = new Float32Array(this.fftSize);
|
|
31
|
+
this.inputBufferIndex = 0;
|
|
32
|
+
this.outputBufferIndex = 0;
|
|
33
|
+
|
|
34
|
+
// FFT buffers (real and imaginary components)
|
|
35
|
+
this.fftReal = new Float32Array(this.fftSize);
|
|
36
|
+
this.fftImag = new Float32Array(this.fftSize);
|
|
37
|
+
|
|
38
|
+
// Phase tracking for synthesis
|
|
39
|
+
this.lastPhase = new Float32Array(this.fftSize / 2 + 1);
|
|
40
|
+
this.sumPhase = new Float32Array(this.fftSize / 2 + 1);
|
|
41
|
+
|
|
42
|
+
// Analysis phase tracking
|
|
43
|
+
this.analysisLastPhase = new Float32Array(this.fftSize / 2 + 1);
|
|
44
|
+
|
|
45
|
+
// Hann window (smooth spectral transitions)
|
|
46
|
+
this.window = new Float32Array(this.fftSize);
|
|
47
|
+
this.generateHannWindow();
|
|
48
|
+
|
|
49
|
+
// Overlap-add synthesis
|
|
50
|
+
this.overlapBuffer = new Float32Array(this.fftSize);
|
|
51
|
+
|
|
52
|
+
// Formant preservation envelope
|
|
53
|
+
this.spectralEnvelope = new Float32Array(this.fftSize / 2 + 1);
|
|
54
|
+
|
|
55
|
+
// Listen for parameter updates
|
|
56
|
+
this.port.onmessage = (event) => {
|
|
57
|
+
if (event.data.type === 'setSampleRate') {
|
|
58
|
+
this.sampleRate = event.data.value;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Generate Hann window for smooth spectral analysis
|
|
65
|
+
*/
|
|
66
|
+
generateHannWindow() {
|
|
67
|
+
for (let i = 0; i < this.fftSize; i++) {
|
|
68
|
+
this.window[i] = 0.5 * (1 - Math.cos((2 * Math.PI * i) / (this.fftSize - 1)));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Simple FFT implementation (Cooley-Tukey radix-2)
|
|
74
|
+
* In production, you might use a faster library, but this works for our purposes
|
|
75
|
+
*/
|
|
76
|
+
fft(real, imag) {
|
|
77
|
+
const n = real.length;
|
|
78
|
+
|
|
79
|
+
// Bit-reversal permutation
|
|
80
|
+
let j = 0;
|
|
81
|
+
for (let i = 0; i < n - 1; i++) {
|
|
82
|
+
if (i < j) {
|
|
83
|
+
[real[i], real[j]] = [real[j], real[i]];
|
|
84
|
+
[imag[i], imag[j]] = [imag[j], imag[i]];
|
|
85
|
+
}
|
|
86
|
+
let k = n / 2;
|
|
87
|
+
while (k <= j) {
|
|
88
|
+
j -= k;
|
|
89
|
+
k /= 2;
|
|
90
|
+
}
|
|
91
|
+
j += k;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Cooley-Tukey FFT
|
|
95
|
+
for (let size = 2; size <= n; size *= 2) {
|
|
96
|
+
const halfSize = size / 2;
|
|
97
|
+
const tableStep = n / size;
|
|
98
|
+
for (let i = 0; i < n; i += size) {
|
|
99
|
+
for (let j = i, k = 0; j < i + halfSize; j++, k += tableStep) {
|
|
100
|
+
const angle = (-2 * Math.PI * k) / n;
|
|
101
|
+
const cos = Math.cos(angle);
|
|
102
|
+
const sin = Math.sin(angle);
|
|
103
|
+
|
|
104
|
+
const evenReal = real[j];
|
|
105
|
+
const evenImag = imag[j];
|
|
106
|
+
const oddReal = real[j + halfSize];
|
|
107
|
+
const oddImag = imag[j + halfSize];
|
|
108
|
+
|
|
109
|
+
const tpReal = oddReal * cos - oddImag * sin;
|
|
110
|
+
const tpImag = oddReal * sin + oddImag * cos;
|
|
111
|
+
|
|
112
|
+
real[j] = evenReal + tpReal;
|
|
113
|
+
imag[j] = evenImag + tpImag;
|
|
114
|
+
real[j + halfSize] = evenReal - tpReal;
|
|
115
|
+
imag[j + halfSize] = evenImag - tpImag;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Inverse FFT
|
|
123
|
+
*/
|
|
124
|
+
ifft(real, imag) {
|
|
125
|
+
// Conjugate
|
|
126
|
+
for (let i = 0; i < imag.length; i++) {
|
|
127
|
+
imag[i] = -imag[i];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Forward FFT
|
|
131
|
+
this.fft(real, imag);
|
|
132
|
+
|
|
133
|
+
// Conjugate and scale
|
|
134
|
+
const n = real.length;
|
|
135
|
+
for (let i = 0; i < n; i++) {
|
|
136
|
+
real[i] /= n;
|
|
137
|
+
imag[i] = -imag[i] / n;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Extract spectral envelope for formant preservation
|
|
143
|
+
* Uses cepstral analysis to separate formants from harmonics
|
|
144
|
+
*/
|
|
145
|
+
extractSpectralEnvelope(magnitude) {
|
|
146
|
+
const numBins = magnitude.length;
|
|
147
|
+
|
|
148
|
+
// Simplified formant extraction using smoothing
|
|
149
|
+
// For each bin, average with nearby bins (smooths out harmonics, preserves formants)
|
|
150
|
+
const smoothingWindow = 8; // Bins to average
|
|
151
|
+
|
|
152
|
+
for (let i = 0; i < numBins; i++) {
|
|
153
|
+
let sum = 0;
|
|
154
|
+
let count = 0;
|
|
155
|
+
|
|
156
|
+
const start = Math.max(0, i - smoothingWindow);
|
|
157
|
+
const end = Math.min(numBins - 1, i + smoothingWindow);
|
|
158
|
+
|
|
159
|
+
for (let j = start; j <= end; j++) {
|
|
160
|
+
sum += magnitude[j];
|
|
161
|
+
count++;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
this.spectralEnvelope[i] = sum / count;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Process one frame with phase vocoder
|
|
170
|
+
*/
|
|
171
|
+
processFrame() {
|
|
172
|
+
const numBins = this.fftSize / 2 + 1;
|
|
173
|
+
|
|
174
|
+
// Apply window to input
|
|
175
|
+
for (let i = 0; i < this.fftSize; i++) {
|
|
176
|
+
this.fftReal[i] = this.inputBuffer[i] * this.window[i];
|
|
177
|
+
this.fftImag[i] = 0;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Forward FFT
|
|
181
|
+
this.fft(this.fftReal, this.fftImag);
|
|
182
|
+
|
|
183
|
+
// Extract magnitude and phase
|
|
184
|
+
const magnitude = new Float32Array(numBins);
|
|
185
|
+
const phase = new Float32Array(numBins);
|
|
186
|
+
|
|
187
|
+
for (let i = 0; i < numBins; i++) {
|
|
188
|
+
magnitude[i] = Math.sqrt(
|
|
189
|
+
this.fftReal[i] * this.fftReal[i] + this.fftImag[i] * this.fftImag[i]
|
|
190
|
+
);
|
|
191
|
+
phase[i] = Math.atan2(this.fftImag[i], this.fftReal[i]);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Extract formant envelope (vocal tract characteristics)
|
|
195
|
+
this.extractSpectralEnvelope(magnitude);
|
|
196
|
+
|
|
197
|
+
// Calculate pitch shift ratio
|
|
198
|
+
const shiftRatio = Math.pow(2, this.pitchShift / 12);
|
|
199
|
+
|
|
200
|
+
// Prepare synthesis buffers
|
|
201
|
+
const synthMagnitude = new Float32Array(numBins);
|
|
202
|
+
const synthPhase = new Float32Array(numBins);
|
|
203
|
+
|
|
204
|
+
// Pitch shift with formant preservation
|
|
205
|
+
for (let i = 0; i < numBins; i++) {
|
|
206
|
+
// Source bin for pitch shifting (resample spectrum)
|
|
207
|
+
const sourceBin = i / shiftRatio;
|
|
208
|
+
const sourceBinInt = Math.floor(sourceBin);
|
|
209
|
+
const sourceBinFrac = sourceBin - sourceBinInt;
|
|
210
|
+
|
|
211
|
+
if (sourceBinInt < numBins - 1) {
|
|
212
|
+
// Interpolate magnitude from source spectrum
|
|
213
|
+
const mag =
|
|
214
|
+
magnitude[sourceBinInt] * (1 - sourceBinFrac) +
|
|
215
|
+
magnitude[sourceBinInt + 1] * sourceBinFrac;
|
|
216
|
+
|
|
217
|
+
// Get formant envelope at OUTPUT bin (preserves formants)
|
|
218
|
+
const formant = this.spectralEnvelope[i];
|
|
219
|
+
const sourceFormant =
|
|
220
|
+
sourceBinInt < numBins - 1
|
|
221
|
+
? this.spectralEnvelope[sourceBinInt] * (1 - sourceBinFrac) +
|
|
222
|
+
this.spectralEnvelope[sourceBinInt + 1] * sourceBinFrac
|
|
223
|
+
: this.spectralEnvelope[sourceBinInt];
|
|
224
|
+
|
|
225
|
+
// Apply formant preservation: adjust magnitude to maintain formant shape
|
|
226
|
+
synthMagnitude[i] = sourceFormant > 0 ? mag * (formant / sourceFormant) : mag;
|
|
227
|
+
|
|
228
|
+
// Phase unwrapping and synthesis
|
|
229
|
+
const deltaPhase = phase[sourceBinInt] - this.analysisLastPhase[sourceBinInt];
|
|
230
|
+
this.analysisLastPhase[sourceBinInt] = phase[sourceBinInt];
|
|
231
|
+
|
|
232
|
+
// Expected phase advance
|
|
233
|
+
const binFreq = (sourceBinInt * this.sampleRate) / this.fftSize;
|
|
234
|
+
const expectedPhaseAdvance = (2 * Math.PI * this.hopSize * binFreq) / this.sampleRate;
|
|
235
|
+
|
|
236
|
+
// Phase deviation (instantaneous frequency)
|
|
237
|
+
let phaseDeviation = deltaPhase - expectedPhaseAdvance;
|
|
238
|
+
|
|
239
|
+
// Wrap to [-π, π]
|
|
240
|
+
while (phaseDeviation > Math.PI) phaseDeviation -= 2 * Math.PI;
|
|
241
|
+
while (phaseDeviation < -Math.PI) phaseDeviation += 2 * Math.PI;
|
|
242
|
+
|
|
243
|
+
// True frequency
|
|
244
|
+
const trueFreq =
|
|
245
|
+
binFreq + (phaseDeviation * this.sampleRate) / (2 * Math.PI * this.hopSize);
|
|
246
|
+
|
|
247
|
+
// Synthesis phase accumulation
|
|
248
|
+
this.sumPhase[i] += (2 * Math.PI * this.hopSize * trueFreq * shiftRatio) / this.sampleRate;
|
|
249
|
+
synthPhase[i] = this.sumPhase[i];
|
|
250
|
+
} else {
|
|
251
|
+
synthMagnitude[i] = 0;
|
|
252
|
+
synthPhase[i] = 0;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Convert back to complex form
|
|
257
|
+
for (let i = 0; i < numBins; i++) {
|
|
258
|
+
this.fftReal[i] = synthMagnitude[i] * Math.cos(synthPhase[i]);
|
|
259
|
+
this.fftImag[i] = synthMagnitude[i] * Math.sin(synthPhase[i]);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// Mirror for inverse FFT (real signal symmetry)
|
|
263
|
+
for (let i = numBins; i < this.fftSize; i++) {
|
|
264
|
+
this.fftReal[i] = this.fftReal[this.fftSize - i];
|
|
265
|
+
this.fftImag[i] = -this.fftImag[this.fftSize - i];
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// Inverse FFT
|
|
269
|
+
this.ifft(this.fftReal, this.fftImag);
|
|
270
|
+
|
|
271
|
+
// Apply window and overlap-add
|
|
272
|
+
for (let i = 0; i < this.fftSize; i++) {
|
|
273
|
+
this.overlapBuffer[i] += this.fftReal[i] * this.window[i];
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* AudioWorklet process callback
|
|
279
|
+
*/
|
|
280
|
+
process(inputs, outputs, parameters) {
|
|
281
|
+
const input = inputs[0];
|
|
282
|
+
const output = outputs[0];
|
|
283
|
+
|
|
284
|
+
if (!input || !input[0]) {
|
|
285
|
+
return true;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const inputChannel = input[0];
|
|
289
|
+
const outputChannel = output[0];
|
|
290
|
+
|
|
291
|
+
// Get pitch shift parameter
|
|
292
|
+
if (parameters.pitchSemitones && parameters.pitchSemitones.length > 0) {
|
|
293
|
+
this.pitchShift = parameters.pitchSemitones[0];
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// Process each sample
|
|
297
|
+
for (let i = 0; i < inputChannel.length; i++) {
|
|
298
|
+
// Add input to buffer
|
|
299
|
+
this.inputBuffer[this.inputBufferIndex++] = inputChannel[i];
|
|
300
|
+
|
|
301
|
+
// When buffer is full, process frame
|
|
302
|
+
if (this.inputBufferIndex >= this.fftSize) {
|
|
303
|
+
this.processFrame();
|
|
304
|
+
|
|
305
|
+
// Shift input buffer by hop size
|
|
306
|
+
for (let j = 0; j < this.fftSize - this.hopSize; j++) {
|
|
307
|
+
this.inputBuffer[j] = this.inputBuffer[j + this.hopSize];
|
|
308
|
+
}
|
|
309
|
+
this.inputBufferIndex = this.fftSize - this.hopSize;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// Output from overlap buffer
|
|
313
|
+
outputChannel[i] = this.overlapBuffer[0];
|
|
314
|
+
|
|
315
|
+
// Shift overlap buffer
|
|
316
|
+
for (let j = 0; j < this.fftSize - 1; j++) {
|
|
317
|
+
this.overlapBuffer[j] = this.overlapBuffer[j + 1];
|
|
318
|
+
}
|
|
319
|
+
this.overlapBuffer[this.fftSize - 1] = 0;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
return true;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Register processor parameters
|
|
327
|
+
*/
|
|
328
|
+
static get parameterDescriptors() {
|
|
329
|
+
return [
|
|
330
|
+
{
|
|
331
|
+
name: 'pitchSemitones',
|
|
332
|
+
defaultValue: 0,
|
|
333
|
+
minValue: -24,
|
|
334
|
+
maxValue: 24,
|
|
335
|
+
automationRate: 'k-rate',
|
|
336
|
+
},
|
|
337
|
+
];
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
registerProcessor('phase-vocoder-processor', PhaseVocoderProcessor);
|