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,216 @@
|
|
|
1
|
+
// AudioWorklet processor for real-time music analysis
|
|
2
|
+
class MusicAnalysisProcessor extends AudioWorkletProcessor {
|
|
3
|
+
constructor() {
|
|
4
|
+
super();
|
|
5
|
+
|
|
6
|
+
// Analysis parameters
|
|
7
|
+
this.fftSize = 512;
|
|
8
|
+
this.bufferSize = this.fftSize * 2; // Need double for FFT
|
|
9
|
+
this.buffer = new Float32Array(this.bufferSize);
|
|
10
|
+
this.bufferIndex = 0;
|
|
11
|
+
|
|
12
|
+
// Analysis results
|
|
13
|
+
this.analysisFrameCount = 0;
|
|
14
|
+
this.analysisRate = 4; // Send analysis every 4 frames (~15Hz at 60fps)
|
|
15
|
+
|
|
16
|
+
// Pre-allocate arrays for efficiency
|
|
17
|
+
this.frequencyData = new Float32Array(this.fftSize / 2);
|
|
18
|
+
this.tempBuffer = new Float32Array(this.fftSize);
|
|
19
|
+
|
|
20
|
+
// Pitch detection parameters
|
|
21
|
+
this.sampleRate = 48000; // Will be updated from options
|
|
22
|
+
this.pitchDetectionEnabled = false;
|
|
23
|
+
this.lastPitch = null;
|
|
24
|
+
this.smoothingFactor = 0.7;
|
|
25
|
+
this.minSignalThreshold = 0.01;
|
|
26
|
+
|
|
27
|
+
// Handle messages from main thread
|
|
28
|
+
this.port.onmessage = (event) => {
|
|
29
|
+
if (event.data.type === 'setSampleRate') {
|
|
30
|
+
this.sampleRate = event.data.value;
|
|
31
|
+
} else if (event.data.type === 'enablePitchDetection') {
|
|
32
|
+
this.pitchDetectionEnabled = event.data.value;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
process(inputs, _outputs, _parameters) {
|
|
38
|
+
const input = inputs[0];
|
|
39
|
+
|
|
40
|
+
if (!input || !input[0]) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const inputChannel = input[0];
|
|
45
|
+
|
|
46
|
+
// Fill circular buffer
|
|
47
|
+
for (let i = 0; i < inputChannel.length; i++) {
|
|
48
|
+
this.buffer[this.bufferIndex] = inputChannel[i];
|
|
49
|
+
this.bufferIndex = (this.bufferIndex + 1) % this.bufferSize;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Perform analysis at reduced rate to avoid overwhelming main thread
|
|
53
|
+
this.analysisFrameCount++;
|
|
54
|
+
if (this.analysisFrameCount >= this.analysisRate) {
|
|
55
|
+
this.analysisFrameCount = 0;
|
|
56
|
+
this.performAnalysis();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
detectPitch(buffer) {
|
|
63
|
+
// Check signal strength first
|
|
64
|
+
let sumSquares = 0;
|
|
65
|
+
for (let i = 0; i < buffer.length; i++) {
|
|
66
|
+
sumSquares += buffer[i] * buffer[i];
|
|
67
|
+
}
|
|
68
|
+
const rms = Math.sqrt(sumSquares / buffer.length);
|
|
69
|
+
|
|
70
|
+
if (rms < this.minSignalThreshold) {
|
|
71
|
+
return null; // Signal too weak
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Autocorrelation-based pitch detection
|
|
75
|
+
// Music range: ~80 Hz (bass) to ~2000 Hz (upper harmonics)
|
|
76
|
+
const minPeriod = Math.floor(this.sampleRate / 2000); // 2000 Hz max
|
|
77
|
+
const maxPeriod = Math.floor(this.sampleRate / 80); // 80 Hz min
|
|
78
|
+
|
|
79
|
+
let maxCorrelation = 0;
|
|
80
|
+
let bestPeriod = 0;
|
|
81
|
+
|
|
82
|
+
// Calculate autocorrelation for each possible period
|
|
83
|
+
for (let period = minPeriod; period < maxPeriod; period++) {
|
|
84
|
+
let correlation = 0;
|
|
85
|
+
for (let i = 0; i < buffer.length - period; i++) {
|
|
86
|
+
correlation += buffer[i] * buffer[i + period];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (correlation > maxCorrelation) {
|
|
90
|
+
maxCorrelation = correlation;
|
|
91
|
+
bestPeriod = period;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Require minimum correlation strength
|
|
96
|
+
const correlationThreshold = sumSquares * 0.3;
|
|
97
|
+
if (bestPeriod > 0 && maxCorrelation > correlationThreshold) {
|
|
98
|
+
const frequency = this.sampleRate / bestPeriod;
|
|
99
|
+
|
|
100
|
+
// Apply exponential smoothing
|
|
101
|
+
if (this.lastPitch !== null) {
|
|
102
|
+
return this.lastPitch * this.smoothingFactor + frequency * (1 - this.smoothingFactor);
|
|
103
|
+
}
|
|
104
|
+
return frequency;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
performAnalysis() {
|
|
111
|
+
// Copy buffer data in correct order for FFT
|
|
112
|
+
const startIndex = this.bufferIndex;
|
|
113
|
+
for (let i = 0; i < this.fftSize; i++) {
|
|
114
|
+
const bufferIdx = (startIndex + i) % this.bufferSize;
|
|
115
|
+
this.tempBuffer[i] = this.buffer[bufferIdx];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Apply window function (Hann window)
|
|
119
|
+
for (let i = 0; i < this.fftSize; i++) {
|
|
120
|
+
const windowValue = 0.5 * (1 - Math.cos((2 * Math.PI * i) / (this.fftSize - 1)));
|
|
121
|
+
this.tempBuffer[i] *= windowValue;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Detect pitch if enabled
|
|
125
|
+
let detectedPitch = null;
|
|
126
|
+
if (this.pitchDetectionEnabled) {
|
|
127
|
+
detectedPitch = this.detectPitch(this.tempBuffer);
|
|
128
|
+
this.lastPitch = detectedPitch;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Perform FFT (simplified real-to-complex)
|
|
132
|
+
this.simpleFFT(this.tempBuffer, this.frequencyData);
|
|
133
|
+
|
|
134
|
+
// Analyze frequency bands
|
|
135
|
+
const analysis = this.analyzeFrequencyBands(this.frequencyData);
|
|
136
|
+
|
|
137
|
+
// Add pitch to analysis if detected
|
|
138
|
+
if (detectedPitch) {
|
|
139
|
+
analysis.pitch = detectedPitch;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Send results to main thread
|
|
143
|
+
this.port.postMessage({
|
|
144
|
+
type: 'analysis',
|
|
145
|
+
data: analysis,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Simplified FFT implementation for AudioWorklet
|
|
150
|
+
simpleFFT(timeData, freqData) {
|
|
151
|
+
const N = timeData.length;
|
|
152
|
+
const halfN = N / 2;
|
|
153
|
+
|
|
154
|
+
// Convert to magnitude spectrum (simplified)
|
|
155
|
+
for (let i = 0; i < halfN; i++) {
|
|
156
|
+
let real = 0;
|
|
157
|
+
let imag = 0;
|
|
158
|
+
|
|
159
|
+
for (let j = 0; j < N; j++) {
|
|
160
|
+
const angle = (-2 * Math.PI * i * j) / N;
|
|
161
|
+
real += timeData[j] * Math.cos(angle);
|
|
162
|
+
imag += timeData[j] * Math.sin(angle);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Magnitude
|
|
166
|
+
freqData[i] = Math.sqrt(real * real + imag * imag) / N;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
analyzeFrequencyBands(frequencyData) {
|
|
171
|
+
const binCount = frequencyData.length;
|
|
172
|
+
const bassEnd = Math.floor(binCount * 0.1); // 0-10% (bass)
|
|
173
|
+
const midEnd = Math.floor(binCount * 0.4); // 10-40% (mids)
|
|
174
|
+
// 40-100% is treble
|
|
175
|
+
|
|
176
|
+
let bassSum = 0,
|
|
177
|
+
midSum = 0,
|
|
178
|
+
trebleSum = 0,
|
|
179
|
+
totalEnergy = 0;
|
|
180
|
+
let weightedSum = 0; // for spectral centroid
|
|
181
|
+
|
|
182
|
+
for (let i = 0; i < binCount; i++) {
|
|
183
|
+
const value = frequencyData[i];
|
|
184
|
+
totalEnergy += value;
|
|
185
|
+
weightedSum += value * i;
|
|
186
|
+
|
|
187
|
+
if (i < bassEnd) {
|
|
188
|
+
bassSum += value;
|
|
189
|
+
} else if (i < midEnd) {
|
|
190
|
+
midSum += value;
|
|
191
|
+
} else {
|
|
192
|
+
trebleSum += value;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Calculate averages and normalize
|
|
197
|
+
const bassAvg = bassEnd > 0 ? bassSum / bassEnd : 0;
|
|
198
|
+
const midAvg = midEnd - bassEnd > 0 ? midSum / (midEnd - bassEnd) : 0;
|
|
199
|
+
const trebleAvg = binCount - midEnd > 0 ? trebleSum / (binCount - midEnd) : 0;
|
|
200
|
+
const energyAvg = binCount > 0 ? totalEnergy / binCount : 0;
|
|
201
|
+
|
|
202
|
+
// Calculate spectral centroid (normalized)
|
|
203
|
+
const centroid = totalEnergy > 0 ? weightedSum / totalEnergy / binCount : 0;
|
|
204
|
+
|
|
205
|
+
// Apply smoothing and scaling for visual effects
|
|
206
|
+
return {
|
|
207
|
+
energy: Math.min(energyAvg * 50, 1.0), // Scale and clamp
|
|
208
|
+
bass: Math.min(bassAvg * 100, 1.0),
|
|
209
|
+
mid: Math.min(midAvg * 80, 1.0),
|
|
210
|
+
treble: Math.min(trebleAvg * 60, 1.0),
|
|
211
|
+
centroid: centroid,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
registerProcessor('music-analysis-processor', MusicAnalysisProcessor);
|
|
@@ -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);
|