exponentialRampToValueAtTime
This commit is contained in:
parent
40900f472c
commit
257a354be7
20
app.js
20
app.js
@ -528,8 +528,7 @@ function stopShoot(note) {
|
|||||||
if (!cannonSprites[note].oscillator) return
|
if (!cannonSprites[note].oscillator) return
|
||||||
|
|
||||||
var oscillator = cannonSprites[note].oscillator
|
var oscillator = cannonSprites[note].oscillator
|
||||||
velocity = oscillator.velocity.gain.value
|
oscillator.velocity.gain.exponentialRampToValueAtTime(0, Tone.Transport.seconds, 0.5)
|
||||||
oscillator.velocity.gain.exponentialRampToValueAtTime(1, Tone.Transport.seconds, 0.5)
|
|
||||||
oscillator.stop(Tone.Transport.seconds + 0.5)
|
oscillator.stop(Tone.Transport.seconds + 0.5)
|
||||||
|
|
||||||
delete(cannonSprites[note].oscillator)
|
delete(cannonSprites[note].oscillator)
|
||||||
@ -576,7 +575,7 @@ function update(time) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function playNote(note, velocity=0.7, duration=0, time=Tone.Transport.seconds) {
|
function playNote(note, velocity=0.7, duration=0, time=audioCtx.currentTime) {
|
||||||
if(oscillators[note]) return
|
if(oscillators[note]) return
|
||||||
|
|
||||||
var oscillator = audioCtx.createOscillator()
|
var oscillator = audioCtx.createOscillator()
|
||||||
@ -592,19 +591,14 @@ function playNote(note, velocity=0.7, duration=0, time=Tone.Transport.seconds) {
|
|||||||
|
|
||||||
depth.connect(oscillator.detune)
|
depth.connect(oscillator.detune)
|
||||||
|
|
||||||
if (duration) {
|
oscillators[note] = oscillator
|
||||||
oscillator.velocity.gain.exponentialRampToValueAtTime(1, time + duration, 0.5)
|
if (duration) stopNote(note, time + duration)
|
||||||
oscillator.stop(time + duration + 0.5)
|
|
||||||
} else {
|
|
||||||
oscillators[note] = oscillator
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function stopNote(note, time=Tone.Transport.seconds) {
|
function stopNote(note, time=audioCtx.currentTime) {
|
||||||
if(!oscillators[note]) return
|
if(!oscillators[note]) return
|
||||||
|
|
||||||
velocity = oscillators[note].velocity.gain.value
|
oscillators[note].velocity.gain.exponentialRampToValueAtTime(0, time + 0.5)
|
||||||
oscillators[note].velocity.gain.exponentialRampToValueAtTime(1, time, 0.5)
|
|
||||||
oscillators[note].stop(time + 0.5)
|
oscillators[note].stop(time + 0.5)
|
||||||
|
|
||||||
delete(oscillators[note])
|
delete(oscillators[note])
|
||||||
@ -628,7 +622,7 @@ function playNoise(startGain=0.5, bandHz=1000, duration, time) {
|
|||||||
frequency: bandHz,
|
frequency: bandHz,
|
||||||
})
|
})
|
||||||
const gain = new GainNode(audioCtx)
|
const gain = new GainNode(audioCtx)
|
||||||
gain.gain.exponentialRampToValueAtTime(0.5, time, duration)
|
gain.gain.exponentialRampToValueAtTime(0, time, duration)
|
||||||
noise.connect(bandpass).connect(gain).connect(audioCtx.destination)
|
noise.connect(bandpass).connect(gain).connect(audioCtx.destination)
|
||||||
noise.start()
|
noise.start()
|
||||||
noise.stop(time + duration)
|
noise.stop(time + duration)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user