Skip to content

Commit

Permalink
feat(drums): improve toms again
Browse files Browse the repository at this point in the history
  • Loading branch information
domi7777 committed Dec 20, 2024
1 parent 171331e commit 9a948c0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
7 changes: 4 additions & 3 deletions src/samples/drums/tom-high.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import {triggerTom} from './tom-low.ts';

export function playTom2High(volume = 100) {
triggerTom(volume, {
frequency: 250,
decayTime: 0.3,
pitchDecay: 0.15
frequency: 250, // Higher frequency for high tom
decayTime: 0.3, // Shorter decay
pitchDecay: 0.3, // Fast pitch decay
frequencyDrop: 0.9 // Moderate frequency drop
});
}
24 changes: 17 additions & 7 deletions src/samples/drums/tom-low.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ const defaults = {
frequency: 200, // Starting frequency
decayTime: 0.4, // How long the sound lasts
pitchDecay: 0.2, // How quickly the pitch drops
frequencyDrop: 0.5 // How much the frequency drops (1 = all the way)
};

export function triggerTom(volume = 50, settings = defaults) {
const context = createAudioContext();
const time = context.currentTime;
Expand All @@ -19,16 +21,23 @@ export function triggerTom(volume = 50, settings = defaults) {
// Set initial frequency
osc.frequency.setValueAtTime(settings.frequency, time);

// Frequency envelope - faster decay than kick
// Frequency envelope - less extreme drop than kick
const targetFreq = settings.frequency * (1 - settings.frequencyDrop);
osc.frequency.exponentialRampToValueAtTime(
settings.frequency * 0.01,
Math.max(targetFreq, 0.01), // Ensure we don't go below 0.01
time + settings.pitchDecay
);

// Amplitude envelope
gain.gain.setValueAtTime(gainValue, time);

// Smoother decay for the tom sound
// More pronounced initial attack for tom character
gain.gain.linearRampToValueAtTime(
gainValue * 0.7,
time + 0.01
);

// Then decay
gain.gain.exponentialRampToValueAtTime(
gainValue * 0.01,
time + settings.decayTime - 0.02
Expand All @@ -48,9 +57,10 @@ export function triggerTom(volume = 50, settings = defaults) {
}

export function playTom1Low(volume = 100) {
triggerTom(volume, {
frequency: 140,
decayTime: 0.4,
pitchDecay: 0.25
triggerTom(volume, {
frequency: 180, // Higher than kick but lower than high tom
decayTime: 0.35, // Medium decay
pitchDecay: 0.15, // Medium pitch decay
frequencyDrop: 0.4 // More pronounced drop than high tom
});
}

0 comments on commit 9a948c0

Please sign in to comment.