add favicon, major performance optimizations
This commit is contained in:
@@ -151,6 +151,9 @@
|
||||
// Initialize audio components
|
||||
const initializeAudio = async (): Promise<void> => {
|
||||
try {
|
||||
// Optimize audio scheduling for better stability
|
||||
Tone.getContext().lookAhead = 0.1; // Keep default 100ms lookahead
|
||||
|
||||
// Create instruments
|
||||
synth = createPadSynth(isDay);
|
||||
arpSynth = createArpSynth(arpVolume);
|
||||
@@ -219,10 +222,13 @@
|
||||
arpSequence = new Tone.Sequence(
|
||||
(time: number, chord) => {
|
||||
if (arpSynth && chord && chord.notes) {
|
||||
// Capture synth reference for TypeScript
|
||||
const synth = arpSynth;
|
||||
// Calculate time between notes based on 16th notes
|
||||
const sixteenthNote = Tone.Time('16n').toSeconds();
|
||||
// Play arpeggio pattern through the chord notes
|
||||
chord.notes.forEach((note: string, index: number) => {
|
||||
const noteTime = time + index * 0.15; // 150ms between notes
|
||||
arpSynth!.triggerAttackRelease(note, '16n', noteTime);
|
||||
synth.triggerAttackRelease(note, '16n', time + index * sixteenthNote);
|
||||
});
|
||||
}
|
||||
},
|
||||
@@ -281,13 +287,12 @@
|
||||
const octave = parseInt(rootNote.slice(-1)); // e.g., 4 from 'C4'
|
||||
const bassNote = noteName + (octave - 2); // e.g., 'C2'
|
||||
|
||||
// Randomize release time: half to full chord duration
|
||||
// Quarter note = 1 beat, so random between 0.5 and 1.0 beats
|
||||
const randomRelease = 0.5 + Math.random() * 0.5;
|
||||
bassSynth.envelope.release = randomRelease * (60 / bpm);
|
||||
// Randomize note duration: half to full chord duration (2n to 4n)
|
||||
const randomDuration = 0.5 + Math.random() * 0.5;
|
||||
const noteDuration = Tone.Time('4n').toSeconds() * randomDuration;
|
||||
|
||||
// Trigger bass note
|
||||
bassSynth.triggerAttackRelease(bassNote, '4n', time);
|
||||
// Trigger bass note at the scheduled time
|
||||
bassSynth.triggerAttackRelease(bassNote, noteDuration, time);
|
||||
}
|
||||
},
|
||||
currentProgression,
|
||||
@@ -346,9 +351,14 @@
|
||||
}
|
||||
});
|
||||
|
||||
// Memoize delay time conversion to avoid repeated calculations
|
||||
const delayTimeSeconds = $derived.by(() => {
|
||||
return Tone.Time(delayTime).toSeconds();
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
if (delay && isInitialized) {
|
||||
delay.delayTime.value = delayTime;
|
||||
delay.delayTime.rampTo(delayTimeSeconds, 0.5);
|
||||
delay.feedback.rampTo(delayFeedback, 0.5);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user