Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 73084a5

Browse files
committed
feat(wasm/compiler): add pure JavaScript async architecture
1 parent 7b5f78f commit 73084a5

14 files changed

+1379
-1410
lines changed

src/platforms/wasm/compiler/index.js

Lines changed: 83 additions & 93 deletions
Large diffs are not rendered by default.

src/platforms/wasm/compiler/modules/audio_manager.js

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
*/
2828

2929
/* eslint-disable no-console */
30-
/* eslint-disable import/prefer-default-export */
3130
/* eslint-disable no-restricted-syntax */
3231
/* eslint-disable max-len */
3332
/* eslint-disable guard-for-in */
@@ -74,7 +73,6 @@ const AUDIO_PROCESSOR_TYPES = {
7473
AUDIO_WORKLET: 'audio_worklet',
7574
};
7675

77-
7876
/**
7977
* TIMESTAMP IMPLEMENTATION DOCUMENTATION:
8078
*
@@ -188,7 +186,7 @@ class ScriptProcessorAudioProcessor extends AudioProcessor {
188186
if (!this.isProcessing) return;
189187

190188
// Get input data from the left channel
191-
const inputBuffer = audioProcessingEvent.inputBuffer;
189+
const { inputBuffer } = audioProcessingEvent;
192190
const inputData = inputBuffer.getChannelData(0);
193191

194192
// Convert float32 audio data to int16 range
@@ -288,7 +286,7 @@ class AudioWorkletAudioProcessor extends AudioProcessor {
288286
} catch (pathError) {
289287
// Collect detailed diagnostic information
290288
const diagnostic = {
291-
path: path,
289+
path,
292290
error: pathError.message,
293291
errorName: pathError.name,
294292
errorType: this.diagnoseAudioWorkletError(pathError, path),
@@ -604,7 +602,7 @@ export class AudioManager {
604602
processorType = AudioProcessorFactory.getBestProcessorType();
605603
console.log(`🎵 Auto-selected audio processor: ${processorType}`);
606604
console.log(
607-
`🎵 (Will automatically fallback to ScriptProcessor if AudioWorklet fails to load)`,
605+
'🎵 (Will automatically fallback to ScriptProcessor if AudioWorklet fails to load)',
608606
);
609607
}
610608

@@ -674,11 +672,10 @@ export class AudioManager {
674672
if (this.isAudioWorkletSupported()) {
675673
this.setProcessorType(AUDIO_PROCESSOR_TYPES.AUDIO_WORKLET);
676674
return true;
677-
} else {
678-
console.warn('🎵 AudioWorklet not supported, using ScriptProcessor');
679-
this.setProcessorType(AUDIO_PROCESSOR_TYPES.SCRIPT_PROCESSOR);
680-
return false;
681675
}
676+
console.warn('🎵 AudioWorklet not supported, using ScriptProcessor');
677+
this.setProcessorType(AUDIO_PROCESSOR_TYPES.SCRIPT_PROCESSOR);
678+
return false;
682679
}
683680

684681
/**
@@ -1027,7 +1024,7 @@ export class AudioManager {
10271024
* @param {File} file - The selected audio file
10281025
*/
10291026
updateButtonText(button, file) {
1030-
button.textContent = file.name.length > 20 ? `${file.name.substring(0, 17) }...` : file.name;
1027+
button.textContent = file.name.length > 20 ? `${file.name.substring(0, 17)}...` : file.name;
10311028
}
10321029

10331030
/**
@@ -1264,7 +1261,7 @@ window.useBestAudioProcessor = function () {
12641261
*/
12651262
window.forceAudioWorklet = function () {
12661263
audioManager.setProcessorType(AUDIO_PROCESSOR_TYPES.AUDIO_WORKLET);
1267-
console.log(`🎵 Forced AudioWorklet mode (with automatic ScriptProcessor fallback)`);
1264+
console.log('🎵 Forced AudioWorklet mode (with automatic ScriptProcessor fallback)');
12681265
return audioManager.getProcessorType();
12691266
};
12701267

@@ -1274,7 +1271,7 @@ window.forceAudioWorklet = function () {
12741271
*/
12751272
window.forceScriptProcessor = function () {
12761273
audioManager.setProcessorType(AUDIO_PROCESSOR_TYPES.SCRIPT_PROCESSOR);
1277-
console.log(`🎵 Forced ScriptProcessor mode`);
1274+
console.log('🎵 Forced ScriptProcessor mode');
12781275
return audioManager.getProcessorType();
12791276
};
12801277

@@ -1330,7 +1327,7 @@ window.testAudioWorkletPath = async function (customPath = null) {
13301327
continue;
13311328
}
13321329

1333-
console.log(`🎵 ✅ File exists and is accessible`);
1330+
console.log('🎵 ✅ File exists and is accessible');
13341331
} catch (fetchError) {
13351332
console.log(`🎵 ❌ Fetch error: ${fetchError.message}`);
13361333
continue;
@@ -1339,7 +1336,7 @@ window.testAudioWorkletPath = async function (customPath = null) {
13391336
// Now try loading as AudioWorklet module
13401337
// deno-lint-ignore no-await-in-loop
13411338
await testContext.audioWorklet.addModule(path);
1342-
console.log(`🎵 🎵 ✅ AudioWorklet module loaded successfully!`);
1339+
console.log('🎵 🎵 ✅ AudioWorklet module loaded successfully!');
13431340

13441341
testContext.close();
13451342
return true;
@@ -1364,8 +1361,8 @@ window.getAudioWorkletEnvironmentInfo = function () {
13641361
host: window.location.host,
13651362
pathname: window.location.pathname,
13661363
isSecureContext: self.isSecureContext,
1367-
audioWorkletSupported: 'audioWorklet' in
1368-
(window.AudioContext || window.webkitAudioContext).prototype,
1364+
audioWorkletSupported: 'audioWorklet'
1365+
in (window.AudioContext || window.webkitAudioContext).prototype,
13691366
userAgent: navigator.userAgent,
13701367
};
13711368

@@ -1409,11 +1406,13 @@ window.getAudioBufferStats = function () {
14091406
totalSamples: acc.totalSamples + stat.totalSamples,
14101407
totalMemoryKB: acc.totalMemoryKB + stat.memoryEstimateKB,
14111408
activeStreams: acc.activeStreams + 1,
1412-
}), { totalBufferCount: 0, totalSamples: 0, totalMemoryKB: 0, activeStreams: 0 });
1409+
}), {
1410+
totalBufferCount: 0, totalSamples: 0, totalMemoryKB: 0, activeStreams: 0,
1411+
});
14131412

14141413
return {
14151414
individual: stats,
1416-
totals: totals,
1415+
totals,
14171416
limit: {
14181417
maxBuffers: MAX_AUDIO_BUFFER_LIMIT,
14191418
description:
@@ -1454,7 +1453,7 @@ class AudioBufferStorage {
14541453
// Add new buffer
14551454
this.buffers.push({
14561455
samples: Array.from(sampleBuffer), // Convert to regular array for JSON serialization
1457-
timestamp: timestamp,
1456+
timestamp,
14581457
});
14591458
this.totalSamples += sampleBuffer.length;
14601459
}

src/platforms/wasm/compiler/modules/audio_worklet_processor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class FastLEDAudioProcessor extends AudioWorkletProcessor {
8383
type: 'audioData',
8484
data: {
8585
timestamp,
86-
samples: samples,
86+
samples,
8787
rms,
8888
peak,
8989
sampleRate: this.sampleRate,

0 commit comments

Comments
 (0)