Skip to content

Commit

Permalink
fix with picks when gain and attenuation is the same
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxAlyokhin committed Jul 16, 2023
1 parent adfd154 commit c8e5594
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions client/src/js/audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -701,17 +701,22 @@ export function audio(motion) {
previousMotionMaximum = 0
}

// +10ms to have time to setTargetAtTime in setGain()
const end = audioContext.currentTime + settings.audio.release + settings.audio.attack + 0.01
const end = audioContext.currentTime + settings.audio.release + settings.audio.attack

// +10ms to have time to setTargetAtTime in setGain()
// Schedule the volume decay and oscillator stop and for
// the last elements in the arrays at the moment of stopping the movement
setTimeout(() => {
envelopeArray[envelopeArray.length - 1].gain.exponentialRampToValueAtTime(settings.audio.attenuation, end)
if (settings.audio.gain === settings.audio.attenuation) {
envelopeArray[envelopeArray.length - 1].gain.setTargetAtTime(0.0001, end, .005)
} else {
envelopeArray[envelopeArray.length - 1].gain.exponentialRampToValueAtTime(settings.audio.attenuation, end)
}
}, 10)

if (settings.audio.LFO.enabled) LFOArray[LFOArray.length - 1].stop(end)
oscillatorArray[oscillatorArray.length - 1].stop(end)
// +10ms for end setTargetAtTime()
if (settings.audio.LFO.enabled) LFOArray[LFOArray.length - 1].stop(end + .02)
oscillatorArray[oscillatorArray.length - 1].stop(end + .02)

// Schedule the removal of these elements, they will be the first in the arrays
// at the time of the timeout call
Expand All @@ -734,7 +739,7 @@ export function audio(motion) {
isAudioElement.classList.remove('motion__is-audio--yes')
}

}, (settings.audio.release + settings.audio.attack) * 1000)
}, (settings.audio.release + settings.audio.attack + .02) * 1000)
)

setTimeout(() => {
Expand Down

0 comments on commit c8e5594

Please sign in to comment.