From dce0f4e05280c29abe244060e34085cd42d68a41 Mon Sep 17 00:00:00 2001 From: Denis Thiessen Date: Mon, 17 Jun 2024 17:04:15 +0200 Subject: [PATCH] feat: Added final sonification effect. --- src/core/audio/AudioHandler.jsx | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/core/audio/AudioHandler.jsx b/src/core/audio/AudioHandler.jsx index eab83d2..0e96860 100644 --- a/src/core/audio/AudioHandler.jsx +++ b/src/core/audio/AudioHandler.jsx @@ -203,21 +203,34 @@ export function playDetailModelSonification(textDensity, linkDensity) { if (offCooldown) { const synth = drumSynth.toDestination(); + // To circumvent a bug with reverb creation. Doesn't affect the lack of reverb though... See below. + const reverbAmount = linkDensity === 0 ? 1 : linkDensity; + const reverb = new Tone.Reverb(reverbAmount).toDestination(); + + reverb.wet.value = 0; + reverb.wet.rampTo(1, 0.25); + const textDensityFrequencyString = 2 * textDensity + "n"; - var loop2 = new Tone.Loop((time) => { - synth.triggerAttackRelease("C3", textDensityFrequencyString, time); - synth.triggerAttackRelease( - "C3", - textDensityFrequencyString, - time + (0.1 + 0.8 / textDensity) - ); - }, "4n").start(); - loop2.iterations = (linkDensity - 1) / 2 + 1; - Tone.Transport.start(); + + const now = Tone.now(); + + synth.triggerAttackRelease("C3", textDensityFrequencyString, now); + + const reverbSynth = linkDensity > 0 ? drumSynth.connect(reverb) : drumSynth; + reverbSynth.triggerAttackRelease( + "C3", + textDensityFrequencyString, + now + 0.2 + ); + pushToSonificationLog("detail_model"); offCooldown = false; setTimeout(() => { offCooldown = true; + reverb.wet.value = 0; + synth.disconnect(); + reverbSynth.disconnect(); + Tone.Transport.stop(); }, 500); } }