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,16 @@
|
|
|
1
|
+
// Wrapper to load cdgraphics as a global variable
|
|
2
|
+
// Since cdgraphics uses ES modules, we need to load it dynamically
|
|
3
|
+
|
|
4
|
+
(async function () {
|
|
5
|
+
try {
|
|
6
|
+
// Import the ES module
|
|
7
|
+
const module = await import('./cdgraphics.js');
|
|
8
|
+
|
|
9
|
+
// Make it available globally
|
|
10
|
+
window.CDGraphics = module.default;
|
|
11
|
+
|
|
12
|
+
console.log('💿 CDGraphics library loaded');
|
|
13
|
+
} catch (error) {
|
|
14
|
+
console.error('💿 Failed to load CDGraphics:', error);
|
|
15
|
+
}
|
|
16
|
+
})();
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
class p {
|
|
2
|
+
WIDTH = 300;
|
|
3
|
+
HEIGHT = 216;
|
|
4
|
+
DISPLAY_WIDTH = 288;
|
|
5
|
+
DISPLAY_HEIGHT = 192;
|
|
6
|
+
DISPLAY_BOUNDS = [6, 12, 294, 204];
|
|
7
|
+
TILE_WIDTH = 6;
|
|
8
|
+
TILE_HEIGHT = 12;
|
|
9
|
+
hOffset = 0;
|
|
10
|
+
vOffset = 0;
|
|
11
|
+
keyColor = null;
|
|
12
|
+
bgColor = null;
|
|
13
|
+
borderColor = null;
|
|
14
|
+
clut = new Array(16).fill([0, 0, 0]);
|
|
15
|
+
pixels = new Uint8ClampedArray(this.WIDTH * this.HEIGHT).fill(0);
|
|
16
|
+
buffer = new Uint8ClampedArray(this.WIDTH * this.HEIGHT).fill(0);
|
|
17
|
+
imageData = new ImageData(this.WIDTH, this.HEIGHT);
|
|
18
|
+
backgroundRGBA = [0, 0, 0, 0];
|
|
19
|
+
contentBounds = [0, 0, 0, 0];
|
|
20
|
+
constructor() {
|
|
21
|
+
this.init();
|
|
22
|
+
}
|
|
23
|
+
init() {
|
|
24
|
+
((this.hOffset = 0),
|
|
25
|
+
(this.vOffset = 0),
|
|
26
|
+
(this.keyColor = null),
|
|
27
|
+
(this.bgColor = null),
|
|
28
|
+
(this.borderColor = null),
|
|
29
|
+
(this.clut = new Array(16).fill([0, 0, 0])),
|
|
30
|
+
(this.pixels = new Uint8ClampedArray(this.WIDTH * this.HEIGHT).fill(0)),
|
|
31
|
+
(this.buffer = new Uint8ClampedArray(this.WIDTH * this.HEIGHT).fill(0)),
|
|
32
|
+
(this.imageData = new ImageData(this.WIDTH, this.HEIGHT)),
|
|
33
|
+
(this.backgroundRGBA = [0, 0, 0, 0]),
|
|
34
|
+
(this.contentBounds = [0, 0, 0, 0]));
|
|
35
|
+
}
|
|
36
|
+
setCLUTEntry(t, s, o, i) {
|
|
37
|
+
this.clut[t] = [s * 17, o * 17, i * 17];
|
|
38
|
+
}
|
|
39
|
+
renderFrame({ forceKey: t = !1 } = {}) {
|
|
40
|
+
const [s, o, i, e] = [0, 0, this.WIDTH, this.HEIGHT];
|
|
41
|
+
let [n, l, h, a] = [this.WIDTH, this.HEIGHT, 0, 0],
|
|
42
|
+
_ = !1;
|
|
43
|
+
for (let c = o; c < e; c++)
|
|
44
|
+
for (let D = s; D < i; D++) {
|
|
45
|
+
let C;
|
|
46
|
+
if (
|
|
47
|
+
this.borderColor !== null &&
|
|
48
|
+
(D < this.DISPLAY_BOUNDS[0] ||
|
|
49
|
+
c < this.DISPLAY_BOUNDS[1] ||
|
|
50
|
+
D >= this.DISPLAY_BOUNDS[2] ||
|
|
51
|
+
c >= this.DISPLAY_BOUNDS[3])
|
|
52
|
+
)
|
|
53
|
+
C = this.borderColor;
|
|
54
|
+
else {
|
|
55
|
+
const E = D + this.hOffset,
|
|
56
|
+
O = c + this.vOffset,
|
|
57
|
+
d = E + O * this.WIDTH;
|
|
58
|
+
C = this.pixels[d];
|
|
59
|
+
}
|
|
60
|
+
const [L, A, H] = this.clut[C],
|
|
61
|
+
u = C === this.keyColor || (t && (C === this.bgColor || this.bgColor == null)),
|
|
62
|
+
T = 4 * (D + c * this.WIDTH);
|
|
63
|
+
((this.imageData.data[T] = L),
|
|
64
|
+
(this.imageData.data[T + 1] = A),
|
|
65
|
+
(this.imageData.data[T + 2] = H),
|
|
66
|
+
(this.imageData.data[T + 3] = u ? 0 : 255),
|
|
67
|
+
u || ((_ = !0), n > D && (n = D), l > c && (l = c), h < D && (h = D), a < c && (a = c)));
|
|
68
|
+
}
|
|
69
|
+
((this.contentBounds = _ || !t ? [n, l, h + 1, a + 1] : [0, 0, 0, 0]),
|
|
70
|
+
(this.backgroundRGBA =
|
|
71
|
+
this.bgColor === null
|
|
72
|
+
? [0, 0, 0, t ? 0 : 1]
|
|
73
|
+
: [...this.clut[this.bgColor], this.bgColor === this.keyColor || t ? 0 : 1]));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
class S {
|
|
77
|
+
color;
|
|
78
|
+
repeat;
|
|
79
|
+
constructor(t) {
|
|
80
|
+
((this.color = t[4] & 15), (this.repeat = t[5] & 15));
|
|
81
|
+
}
|
|
82
|
+
execute(t) {
|
|
83
|
+
(t.pixels.fill(this.color),
|
|
84
|
+
(t.bgColor = this.color),
|
|
85
|
+
(t.borderColor = null),
|
|
86
|
+
(t.hOffset = 0),
|
|
87
|
+
(t.vOffset = 0));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
class g {
|
|
91
|
+
color;
|
|
92
|
+
constructor(t) {
|
|
93
|
+
this.color = t[4] & 15;
|
|
94
|
+
}
|
|
95
|
+
execute(t) {
|
|
96
|
+
t.borderColor = this.color;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
class f {
|
|
100
|
+
// some players check bytes[doff+1] & 0x20 and ignores if it is set (?)
|
|
101
|
+
colors;
|
|
102
|
+
row;
|
|
103
|
+
column;
|
|
104
|
+
pixels;
|
|
105
|
+
constructor(t) {
|
|
106
|
+
((this.colors = [t[4] & 15, t[5] & 15]),
|
|
107
|
+
(this.row = t[6] & 31),
|
|
108
|
+
(this.column = t[7] & 63),
|
|
109
|
+
(this.pixels = t.slice(8, 20)));
|
|
110
|
+
}
|
|
111
|
+
/* blit a tile */
|
|
112
|
+
execute(t) {
|
|
113
|
+
const s = this.column * t.TILE_WIDTH,
|
|
114
|
+
o = this.row * t.TILE_HEIGHT;
|
|
115
|
+
if (s + 6 > t.WIDTH || o + 12 > t.HEIGHT) {
|
|
116
|
+
console.log(`TileBlock out of bounds (${this.row},${this.column})`);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
for (let i = 0; i < 12; i++) {
|
|
120
|
+
const e = this.pixels[i];
|
|
121
|
+
for (let n = 0; n < 6; n++) {
|
|
122
|
+
const l = this.colors[(e >> (5 - n)) & 1],
|
|
123
|
+
h = s + n + (o + i) * t.WIDTH;
|
|
124
|
+
this.op(t, h, l);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
op(t, s, o) {
|
|
129
|
+
t.pixels[s] = o;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
class R extends f {
|
|
133
|
+
op(t, s, o) {
|
|
134
|
+
t.pixels[s] = t.pixels[s] ^ o;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
class I {
|
|
138
|
+
color;
|
|
139
|
+
hCmd;
|
|
140
|
+
hOffset;
|
|
141
|
+
vCmd;
|
|
142
|
+
vOffset;
|
|
143
|
+
constructor(t) {
|
|
144
|
+
this.color = t[4] & 15;
|
|
145
|
+
const s = t[5] & 63;
|
|
146
|
+
((this.hCmd = (s & 48) >> 4), (this.hOffset = s & 7));
|
|
147
|
+
const o = t[6] & 63;
|
|
148
|
+
((this.vCmd = (o & 48) >> 4), (this.vOffset = o & 15));
|
|
149
|
+
}
|
|
150
|
+
execute(t) {
|
|
151
|
+
((t.hOffset = Math.min(this.hOffset, 5)), (t.vOffset = Math.min(this.vOffset, 11)));
|
|
152
|
+
let s = 0;
|
|
153
|
+
this.hCmd === 2 ? (s = t.TILE_WIDTH) : this.hCmd === 1 && (s = -t.TILE_WIDTH);
|
|
154
|
+
let o = 0;
|
|
155
|
+
if (
|
|
156
|
+
(this.vCmd === 2 ? (o = t.TILE_HEIGHT) : this.vCmd === 1 && (o = -t.TILE_HEIGHT),
|
|
157
|
+
s === 0 && o === 0)
|
|
158
|
+
)
|
|
159
|
+
return;
|
|
160
|
+
let i, e;
|
|
161
|
+
for (let l = 0; l < t.WIDTH; l++)
|
|
162
|
+
for (let h = 0; h < t.HEIGHT; h++)
|
|
163
|
+
((i = l + s), (e = h + o), (t.buffer[l + h * t.WIDTH] = this.getPixel(t, i, e)));
|
|
164
|
+
const n = t.pixels;
|
|
165
|
+
((t.pixels = t.buffer), (t.buffer = n));
|
|
166
|
+
}
|
|
167
|
+
getPixel(t, s, o) {
|
|
168
|
+
return s > 0 && s < t.WIDTH && o > 0 && o < t.HEIGHT ? t.pixels[s + o * t.WIDTH] : this.color;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
class m extends I {
|
|
172
|
+
getPixel(t, s, o) {
|
|
173
|
+
return (
|
|
174
|
+
(s = (s + t.WIDTH) % t.WIDTH),
|
|
175
|
+
(o = (o + t.HEIGHT) % t.HEIGHT),
|
|
176
|
+
t.pixels[s + o * t.WIDTH]
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
class P {
|
|
181
|
+
index;
|
|
182
|
+
constructor(t) {
|
|
183
|
+
this.index = t[4] & 15;
|
|
184
|
+
}
|
|
185
|
+
execute(t) {
|
|
186
|
+
t.keyColor = this.index;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
class G {
|
|
190
|
+
colors;
|
|
191
|
+
constructor(t) {
|
|
192
|
+
this.colors = Array(8);
|
|
193
|
+
for (let s = 0; s < 8; s++) {
|
|
194
|
+
const o = 4 + 2 * s;
|
|
195
|
+
let i = (t[o] & 63) << 6;
|
|
196
|
+
i += t[o + 1] & 63;
|
|
197
|
+
const e = [
|
|
198
|
+
i >> 8,
|
|
199
|
+
// red
|
|
200
|
+
(i & 240) >> 4,
|
|
201
|
+
// green
|
|
202
|
+
i & 15,
|
|
203
|
+
// blue
|
|
204
|
+
];
|
|
205
|
+
this.colors[s] = e;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
execute(t) {
|
|
209
|
+
for (let s = 0; s < 8; s++)
|
|
210
|
+
t.setCLUTEntry(s + this.clutOffset, this.colors[s][0], this.colors[s][1], this.colors[s][2]);
|
|
211
|
+
}
|
|
212
|
+
get clutOffset() {
|
|
213
|
+
return 0;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
class B extends G {
|
|
217
|
+
get clutOffset() {
|
|
218
|
+
return 8;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
class W {
|
|
222
|
+
COMMAND_MASK = 63;
|
|
223
|
+
CDG_COMMAND = 9;
|
|
224
|
+
BY_TYPE = {
|
|
225
|
+
1: S,
|
|
226
|
+
2: g,
|
|
227
|
+
6: f,
|
|
228
|
+
20: I,
|
|
229
|
+
24: m,
|
|
230
|
+
28: P,
|
|
231
|
+
30: G,
|
|
232
|
+
31: B,
|
|
233
|
+
38: R,
|
|
234
|
+
};
|
|
235
|
+
bytes;
|
|
236
|
+
numPackets;
|
|
237
|
+
pc;
|
|
238
|
+
constructor(t) {
|
|
239
|
+
((this.bytes = new Uint8Array(t)), (this.numPackets = t.byteLength / 24), (this.pc = -1));
|
|
240
|
+
}
|
|
241
|
+
// determine packet we should be at, based on spec
|
|
242
|
+
// of 4 packets per sector @ 75 sectors per second
|
|
243
|
+
parseThrough(t) {
|
|
244
|
+
const s = Math.floor(300 * t),
|
|
245
|
+
o = [];
|
|
246
|
+
for (
|
|
247
|
+
this.pc > s && ((this.pc = -1), (o.isRestarting = !0));
|
|
248
|
+
this.pc < s && this.pc < this.numPackets;
|
|
249
|
+
|
|
250
|
+
) {
|
|
251
|
+
this.pc++;
|
|
252
|
+
const i = this.pc * 24,
|
|
253
|
+
e = this.parse(this.bytes.slice(i, i + 24));
|
|
254
|
+
e && o.push(e);
|
|
255
|
+
}
|
|
256
|
+
return o;
|
|
257
|
+
}
|
|
258
|
+
parse(t) {
|
|
259
|
+
if ((t[0] & this.COMMAND_MASK) === this.CDG_COMMAND) {
|
|
260
|
+
const s = t[1] & this.COMMAND_MASK,
|
|
261
|
+
o = this.BY_TYPE[s];
|
|
262
|
+
return typeof o < 'u'
|
|
263
|
+
? new o(t)
|
|
264
|
+
: (console.log(`Unknown CDG instruction (instruction = ${s})`), !1);
|
|
265
|
+
}
|
|
266
|
+
return !1;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
class b {
|
|
270
|
+
/** @internal */
|
|
271
|
+
ctx;
|
|
272
|
+
/** @internal */
|
|
273
|
+
parser;
|
|
274
|
+
/** @internal */
|
|
275
|
+
forceKey;
|
|
276
|
+
/** Instantiates a new renderer with the given CD+G file data. The data must be an `ArrayBuffer`, which can be had via the `Response` of a `fetch()`. */
|
|
277
|
+
constructor(t) {
|
|
278
|
+
if (!(t instanceof ArrayBuffer)) throw new Error('buffer must be an ArrayBuffer');
|
|
279
|
+
((this.ctx = new p()), (this.parser = new W(t)));
|
|
280
|
+
}
|
|
281
|
+
/** Renders the frame at the given time index. */
|
|
282
|
+
render(t, s = {}) {
|
|
283
|
+
if (isNaN(t) || t < 0) throw new Error(`Invalid time: ${t}`);
|
|
284
|
+
const o = this.parser.parseThrough(t),
|
|
285
|
+
i = !!o.length || !!o.isRestarting || s.forceKey !== this.forceKey;
|
|
286
|
+
((this.forceKey = s.forceKey), o.isRestarting && this.ctx.init());
|
|
287
|
+
for (const e of o) e.execute(this.ctx);
|
|
288
|
+
return (
|
|
289
|
+
i && this.ctx.renderFrame(s),
|
|
290
|
+
{
|
|
291
|
+
imageData: this.ctx.imageData,
|
|
292
|
+
isChanged: i,
|
|
293
|
+
backgroundRGBA: this.ctx.backgroundRGBA,
|
|
294
|
+
contentBounds: this.ctx.contentBounds,
|
|
295
|
+
}
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
export { b as default };
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
class AutoTuneProcessor extends AudioWorkletProcessor {
|
|
2
|
+
constructor() {
|
|
3
|
+
super();
|
|
4
|
+
|
|
5
|
+
// Auto-tune parameters
|
|
6
|
+
this.enabled = false;
|
|
7
|
+
this.strength = 0.5; // 0-1 range
|
|
8
|
+
this.speed = 0.05; // How quickly to correct pitch
|
|
9
|
+
this.targetPitch = null;
|
|
10
|
+
this.currentKey = 'C';
|
|
11
|
+
|
|
12
|
+
// Pitch detection
|
|
13
|
+
this.sampleRate = 44100;
|
|
14
|
+
this.bufferSize = 2048;
|
|
15
|
+
this.buffer = new Float32Array(this.bufferSize);
|
|
16
|
+
this.bufferIndex = 0;
|
|
17
|
+
|
|
18
|
+
// Musical notes in Hz (A4 = 440Hz)
|
|
19
|
+
this.noteFrequencies = {
|
|
20
|
+
C: [65.41, 130.81, 261.63, 523.25, 1046.5],
|
|
21
|
+
'C#': [69.3, 138.59, 277.18, 554.37, 1108.73],
|
|
22
|
+
D: [73.42, 146.83, 293.66, 587.33, 1174.66],
|
|
23
|
+
'D#': [77.78, 155.56, 311.13, 622.25, 1244.51],
|
|
24
|
+
E: [82.41, 164.81, 329.63, 659.25, 1318.51],
|
|
25
|
+
F: [87.31, 174.61, 349.23, 698.46, 1396.91],
|
|
26
|
+
'F#': [92.5, 185.0, 369.99, 739.99, 1479.98],
|
|
27
|
+
G: [98.0, 196.0, 392.0, 783.99, 1567.98],
|
|
28
|
+
'G#': [103.83, 207.65, 415.3, 830.61, 1661.22],
|
|
29
|
+
A: [110.0, 220.0, 440.0, 880.0, 1760.0],
|
|
30
|
+
'A#': [116.54, 233.08, 466.16, 932.33, 1864.66],
|
|
31
|
+
B: [123.47, 246.94, 493.88, 987.77, 1975.53],
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// Scales for key detection
|
|
35
|
+
this.scales = {
|
|
36
|
+
C: ['C', 'D', 'E', 'F', 'G', 'A', 'B'],
|
|
37
|
+
G: ['G', 'A', 'B', 'C', 'D', 'E', 'F#'],
|
|
38
|
+
D: ['D', 'E', 'F#', 'G', 'A', 'B', 'C#'],
|
|
39
|
+
A: ['A', 'B', 'C#', 'D', 'E', 'F#', 'G#'],
|
|
40
|
+
E: ['E', 'F#', 'G#', 'A', 'B', 'C#', 'D#'],
|
|
41
|
+
B: ['B', 'C#', 'D#', 'E', 'F#', 'G#', 'A#'],
|
|
42
|
+
F: ['F', 'G', 'A', 'A#', 'C', 'D', 'E'],
|
|
43
|
+
'A#': ['A#', 'C', 'D', 'D#', 'F', 'G', 'A'],
|
|
44
|
+
'D#': ['D#', 'F', 'G', 'G#', 'A#', 'C', 'D'],
|
|
45
|
+
'G#': ['G#', 'A#', 'C', 'C#', 'D#', 'F', 'G'],
|
|
46
|
+
'C#': ['C#', 'D#', 'F', 'F#', 'G#', 'A#', 'B'],
|
|
47
|
+
'F#': ['F#', 'G#', 'A#', 'B', 'C#', 'D#', 'F'],
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// Phase vocoder for pitch shifting
|
|
51
|
+
this.fftSize = 2048;
|
|
52
|
+
this.hopSize = this.fftSize / 4;
|
|
53
|
+
this.analysisWindow = this.createWindow(this.fftSize);
|
|
54
|
+
this.synthesisWindow = this.createWindow(this.fftSize);
|
|
55
|
+
|
|
56
|
+
// Overlap-add buffers
|
|
57
|
+
this.inputBuffer = new Float32Array(this.fftSize);
|
|
58
|
+
this.outputBuffer = new Float32Array(this.fftSize);
|
|
59
|
+
this.overlapBuffer = new Float32Array(this.fftSize);
|
|
60
|
+
|
|
61
|
+
// Debug logging
|
|
62
|
+
this.frameCount = 0;
|
|
63
|
+
this.lastLogTime = 0;
|
|
64
|
+
|
|
65
|
+
// Handle parameter changes from main thread
|
|
66
|
+
this.port.onmessage = (event) => {
|
|
67
|
+
if (event.data.type === 'setEnabled') {
|
|
68
|
+
this.enabled = event.data.value;
|
|
69
|
+
} else if (event.data.type === 'setStrength') {
|
|
70
|
+
this.strength = event.data.value / 100; // Convert from 0-100 to 0-1
|
|
71
|
+
} else if (event.data.type === 'setSpeed') {
|
|
72
|
+
this.speed = event.data.value / 100; // Convert from 1-100 to 0.01-1
|
|
73
|
+
} else if (event.data.type === 'setKey') {
|
|
74
|
+
this.currentKey = event.data.value;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
createWindow(size) {
|
|
80
|
+
const window = new Float32Array(size);
|
|
81
|
+
for (let i = 0; i < size; i++) {
|
|
82
|
+
// Hann window
|
|
83
|
+
window[i] = 0.5 * (1 - Math.cos((2 * Math.PI * i) / (size - 1)));
|
|
84
|
+
}
|
|
85
|
+
return window;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
detectPitch(buffer) {
|
|
89
|
+
// Simple autocorrelation-based pitch detection
|
|
90
|
+
const minPeriod = Math.floor(this.sampleRate / 800); // 800 Hz max
|
|
91
|
+
const maxPeriod = Math.floor(this.sampleRate / 80); // 80 Hz min
|
|
92
|
+
|
|
93
|
+
let maxCorrelation = 0;
|
|
94
|
+
let bestPeriod = 0;
|
|
95
|
+
|
|
96
|
+
for (let period = minPeriod; period < maxPeriod; period++) {
|
|
97
|
+
let correlation = 0;
|
|
98
|
+
for (let i = 0; i < buffer.length - period; i++) {
|
|
99
|
+
correlation += buffer[i] * buffer[i + period];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (correlation > maxCorrelation) {
|
|
103
|
+
maxCorrelation = correlation;
|
|
104
|
+
bestPeriod = period;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (bestPeriod > 0 && maxCorrelation > 0.01) {
|
|
109
|
+
return this.sampleRate / bestPeriod;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
findNearestNote(frequency) {
|
|
116
|
+
if (!frequency) return null;
|
|
117
|
+
|
|
118
|
+
const scaleNotes = this.scales[this.currentKey] || this.scales['C'];
|
|
119
|
+
let minDiff = Infinity;
|
|
120
|
+
let nearestNote = null;
|
|
121
|
+
let nearestFreq = null;
|
|
122
|
+
|
|
123
|
+
for (const note of scaleNotes) {
|
|
124
|
+
const frequencies = this.noteFrequencies[note];
|
|
125
|
+
for (const freq of frequencies) {
|
|
126
|
+
const diff = Math.abs(frequency - freq);
|
|
127
|
+
if (diff < minDiff) {
|
|
128
|
+
minDiff = diff;
|
|
129
|
+
nearestNote = note;
|
|
130
|
+
nearestFreq = freq;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return { note: nearestNote, frequency: nearestFreq };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
processWithRobotEffect(inputSample) {
|
|
139
|
+
// Create a robotic auto-tune effect using wave shaping
|
|
140
|
+
// This is more audible than true pitch shifting but gives the characteristic sound
|
|
141
|
+
|
|
142
|
+
// Hard clip the signal for a more digital sound
|
|
143
|
+
let processed = Math.max(-1, Math.min(1, inputSample * 2));
|
|
144
|
+
|
|
145
|
+
// Add harmonic distortion for the "robotic" quality
|
|
146
|
+
processed = Math.sin(processed * Math.PI);
|
|
147
|
+
|
|
148
|
+
// Quantize to create stepped pitch effect
|
|
149
|
+
const steps = 16; // Number of quantization levels
|
|
150
|
+
processed = Math.round(processed * steps) / steps;
|
|
151
|
+
|
|
152
|
+
// Mix with original based on strength
|
|
153
|
+
return inputSample * (1 - this.strength) + processed * this.strength;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
process(inputs, outputs, _parameters) {
|
|
157
|
+
const input = inputs[0];
|
|
158
|
+
const output = outputs[0];
|
|
159
|
+
|
|
160
|
+
if (!input || !input[0]) {
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const inputChannel = input[0];
|
|
165
|
+
const outputChannel = output[0];
|
|
166
|
+
|
|
167
|
+
if (!this.enabled) {
|
|
168
|
+
// Pass through unprocessed
|
|
169
|
+
outputChannel.set(inputChannel);
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Fill detection buffer
|
|
174
|
+
for (let i = 0; i < inputChannel.length; i++) {
|
|
175
|
+
this.buffer[this.bufferIndex++] = inputChannel[i];
|
|
176
|
+
|
|
177
|
+
if (this.bufferIndex >= this.bufferSize) {
|
|
178
|
+
// Detect pitch
|
|
179
|
+
const detectedPitch = this.detectPitch(this.buffer);
|
|
180
|
+
|
|
181
|
+
if (detectedPitch) {
|
|
182
|
+
const nearest = this.findNearestNote(detectedPitch);
|
|
183
|
+
if (nearest) {
|
|
184
|
+
// Calculate pitch shift factor
|
|
185
|
+
const shiftFactor = nearest.frequency / detectedPitch;
|
|
186
|
+
|
|
187
|
+
// Log pitch detection every second
|
|
188
|
+
this.frameCount++;
|
|
189
|
+
const now = Date.now();
|
|
190
|
+
if (now - this.lastLogTime > 1000) {
|
|
191
|
+
this.lastLogTime = now;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Smooth the pitch correction based on speed parameter
|
|
195
|
+
if (this.targetPitch) {
|
|
196
|
+
this.targetPitch = this.targetPitch * (1 - this.speed) + shiftFactor * this.speed;
|
|
197
|
+
} else {
|
|
198
|
+
this.targetPitch = shiftFactor;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Reset buffer
|
|
204
|
+
this.bufferIndex = 0;
|
|
205
|
+
this.buffer.fill(0);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// Apply auto-tune effect
|
|
210
|
+
// For now, use the robotic effect which is more immediately audible
|
|
211
|
+
for (let i = 0; i < outputChannel.length; i++) {
|
|
212
|
+
outputChannel[i] = this.processWithRobotEffect(inputChannel[i]);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// Log that we're processing
|
|
216
|
+
if (this.frameCount % 1000 === 0) {
|
|
217
|
+
// Debug logging disabled for performance
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
registerProcessor('auto-tune-processor', AutoTuneProcessor);
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Microphone Pitch Detector AudioWorklet
|
|
3
|
+
* Detects fundamental frequency from microphone input
|
|
4
|
+
* Sends pitch data to main thread for auto-tune and coaching display
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
class MicPitchDetectorProcessor extends AudioWorkletProcessor {
|
|
8
|
+
constructor() {
|
|
9
|
+
super();
|
|
10
|
+
|
|
11
|
+
// Pitch detection parameters
|
|
12
|
+
this.sampleRate = 48000; // Will be updated from options
|
|
13
|
+
this.bufferSize = 2048;
|
|
14
|
+
this.buffer = new Float32Array(this.bufferSize);
|
|
15
|
+
this.bufferIndex = 0;
|
|
16
|
+
|
|
17
|
+
// Detection rate throttling
|
|
18
|
+
this.detectionCount = 0;
|
|
19
|
+
this.detectionInterval = 4; // Detect every 4 buffers (~46ms at 48kHz)
|
|
20
|
+
|
|
21
|
+
// Last detected pitch for smoothing
|
|
22
|
+
this.lastPitch = null;
|
|
23
|
+
this.smoothingFactor = 0.7; // Exponential smoothing
|
|
24
|
+
|
|
25
|
+
// Minimum signal threshold to avoid detecting noise
|
|
26
|
+
this.minSignalThreshold = 0.01;
|
|
27
|
+
|
|
28
|
+
// Handle messages from main thread
|
|
29
|
+
this.port.onmessage = (event) => {
|
|
30
|
+
if (event.data.type === 'setSampleRate') {
|
|
31
|
+
this.sampleRate = event.data.value;
|
|
32
|
+
} else if (event.data.type === 'setDetectionInterval') {
|
|
33
|
+
this.detectionInterval = event.data.value;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Detect pitch using autocorrelation
|
|
40
|
+
* Returns frequency in Hz or null if no pitch detected
|
|
41
|
+
*/
|
|
42
|
+
detectPitch(buffer) {
|
|
43
|
+
// Check signal strength first
|
|
44
|
+
let sumSquares = 0;
|
|
45
|
+
for (let i = 0; i < buffer.length; i++) {
|
|
46
|
+
sumSquares += buffer[i] * buffer[i];
|
|
47
|
+
}
|
|
48
|
+
const rms = Math.sqrt(sumSquares / buffer.length);
|
|
49
|
+
|
|
50
|
+
if (rms < this.minSignalThreshold) {
|
|
51
|
+
return null; // Signal too weak
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Autocorrelation-based pitch detection
|
|
55
|
+
// Vocal range: ~80 Hz (E2) to ~800 Hz (G5)
|
|
56
|
+
const minPeriod = Math.floor(this.sampleRate / 800); // 800 Hz max
|
|
57
|
+
const maxPeriod = Math.floor(this.sampleRate / 80); // 80 Hz min
|
|
58
|
+
|
|
59
|
+
let maxCorrelation = 0;
|
|
60
|
+
let bestPeriod = 0;
|
|
61
|
+
|
|
62
|
+
// Calculate autocorrelation for each possible period
|
|
63
|
+
for (let period = minPeriod; period < maxPeriod; period++) {
|
|
64
|
+
let correlation = 0;
|
|
65
|
+
for (let i = 0; i < buffer.length - period; i++) {
|
|
66
|
+
correlation += buffer[i] * buffer[i + period];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (correlation > maxCorrelation) {
|
|
70
|
+
maxCorrelation = correlation;
|
|
71
|
+
bestPeriod = period;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Require minimum correlation strength
|
|
76
|
+
const correlationThreshold = sumSquares * 0.3;
|
|
77
|
+
if (bestPeriod > 0 && maxCorrelation > correlationThreshold) {
|
|
78
|
+
const frequency = this.sampleRate / bestPeriod;
|
|
79
|
+
|
|
80
|
+
// Apply exponential smoothing
|
|
81
|
+
if (this.lastPitch !== null) {
|
|
82
|
+
return this.lastPitch * this.smoothingFactor + frequency * (1 - this.smoothingFactor);
|
|
83
|
+
}
|
|
84
|
+
return frequency;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
process(inputs, outputs) {
|
|
91
|
+
const input = inputs[0];
|
|
92
|
+
const output = outputs[0];
|
|
93
|
+
|
|
94
|
+
if (!input || !input[0]) {
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const inputChannel = input[0];
|
|
99
|
+
|
|
100
|
+
// Pass through audio unchanged
|
|
101
|
+
if (output && output[0]) {
|
|
102
|
+
output[0].set(inputChannel);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Fill detection buffer
|
|
106
|
+
for (let i = 0; i < inputChannel.length; i++) {
|
|
107
|
+
this.buffer[this.bufferIndex++] = inputChannel[i];
|
|
108
|
+
|
|
109
|
+
if (this.bufferIndex >= this.bufferSize) {
|
|
110
|
+
// Buffer full - perform detection (throttled)
|
|
111
|
+
this.detectionCount++;
|
|
112
|
+
if (this.detectionCount >= this.detectionInterval) {
|
|
113
|
+
this.detectionCount = 0;
|
|
114
|
+
|
|
115
|
+
const detectedPitch = this.detectPitch(this.buffer);
|
|
116
|
+
|
|
117
|
+
// Update last pitch for smoothing
|
|
118
|
+
this.lastPitch = detectedPitch;
|
|
119
|
+
|
|
120
|
+
// Send pitch data to main thread
|
|
121
|
+
this.port.postMessage({
|
|
122
|
+
type: 'pitch',
|
|
123
|
+
frequency: detectedPitch,
|
|
124
|
+
timestamp: Date.now(),
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Reset buffer
|
|
129
|
+
this.bufferIndex = 0;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
registerProcessor('mic-pitch-detector', MicPitchDetectorProcessor);
|