excaliburjs / Excalibur

🎮 Your friendly TypeScript 2D game engine for the web 🗡️
https://excaliburjs.com
BSD 2-Clause "Simplified" License
1.8k stars 190 forks source link

Sound profile feature for dynamic sounds #804

Open eonarheim opened 7 years ago

eonarheim commented 7 years ago

Context

It would be super cool to change the volume and other properties of a sound over time while it is playing. Perhaps other properties could also be controlled, like pitch, or anything else web audio supports.

Proposal

Potentially add a ex.Sound.playWith(profile: ISoundProfile) that takes a ISoundProfile to describe how the sound should change over time.

// all of these properties are optional
var profile: ISoundProfile = {
   delay: 20, // delay in milliseconds to wait before playing any sound
   volume: [ {time: .2, volume: .8}, { time: 1, volume: .5 }], // time is a percentage of the whole track 1 being the end, 0 being teh beginning
   interpolator: ex.EasingFunctions =  EasingFunctions.EaseInOutCubic
}
andrewmbyrd commented 7 years ago

I believe I've got a solid understanding of how to implement a bezier curve in general, but where would it be best to put the code? Since play is a Promise, it seems hard to have any aspect of the sound change while the sound is playing.

HTMLAudioElement seems to at least have an ontimeupdate event listener that could be useful, but I couldn't find any such function for AudioBufferSourceNode

github-actions[bot] commented 3 years ago

This issue hasn't had any recent activity lately and is being marked as stale automatically.