fix: refactor

This commit is contained in:
2026-07-20 10:39:07 +07:00
parent 3c77e98956
commit c8ebdb50b0
21 changed files with 2862 additions and 110 deletions
+42
View File
@@ -0,0 +1,42 @@
// SonicForge Studio Audio Engine Service
(function() {
let audioCtx = null;
function getAudioContext() {
if (!audioCtx) {
audioCtx = new (window.AudioContext || window.webkitAudioContext)();
}
if (audioCtx.state === 'suspended') {
audioCtx.resume();
}
return audioCtx;
}
function analyzeAudioBufferChannels(audioBuffer) {
if (!audioBuffer) return { channels: 1, isStereo: false, label: 'MONO' };
const numChannels = audioBuffer.numberOfChannels;
const isStereo = numChannels >= 2;
return {
channels: numChannels,
isStereo: isStereo,
label: isStereo ? 'STEREO' : 'MONO',
sampleRate: audioBuffer.sampleRate,
duration: audioBuffer.duration,
length: audioBuffer.length
};
}
async function decodeAudioFile(file) {
const ctx = getAudioContext();
const arrayBuffer = await file.arrayBuffer();
const audioBuffer = await ctx.decodeAudioData(arrayBuffer);
const channelInfo = analyzeAudioBufferChannels(audioBuffer);
return { audioBuffer, channelInfo };
}
window.SonicAudio = {
getAudioContext,
analyzeAudioBufferChannels,
decodeAudioFile
};
})();