Sound
Sounds can be included in your project by specificying them at compile time in your HXML file
Once included in your project you can play a sound file via the file name of the sound you want to access.
Channel instance represents actively playing sound. It’s possible to control following parameters on each Channel: : Priority of the Channel instance (when limiting maximum audible channels, lowest priority Channels get muted when limit is reached) mute
: Mutes channels. Note that playback still continues when channel is muted. volume
: Control volume of the Channel. fadeTo(volume, ?time = 1, ?onEnd: ()->Void)
: Transit channel to specified volume over set period of time with optional callback when transition ends. / removeEffect(e:Effect)
: Add and remove effects (see below) pause
: Allows to temporarily pause sound playback. duration
: Represents duration of the Sound. : Allow to control playback position of the Channel. loop
: Sets channel playback to loop. queue(s:Sound)
: Allows to queue next Sound to play with this Channel instance. It’s possible to queue multiple sounds.
Sound groups allow to control volume (multiplier), max audioble channels at once and force mono playback on Channel instances.
Audio Manager instance provides API to general management of audio. It can be obtained with hxd.snd.Manager.get()
call. Primary use is access to masterVolume, spatialization listener, as well as default sound and channel groups.
When playing a sound, it’s possible to attach effects to the Channel or ChannelGroup instance. Due to backend difference, some backends may not support all effect types. Following sample showcases usage of pitch effect:
HTML5
- Pitch: Due to how WebAudio works, changing pitch gradually can lead to audio cuts. This cannot be avoided due to pitch being applied only once in 128 samples and impossibility to obtain accurate current sample of audio buffer.
- Spatialization: Velocity is not supported.