Variations
Added in 6.5.0
The same footstep a hundred times in a row sounds like a machine. Record three or four takes, give them one name, and let the hub pick one each time:
soundHub.createVariations('footstep', ['step1', 'step2', 'step3'], {
pitch: [0.95, 1.05],
volume: [0.8, 1],
});
soundHub.play('footstep'); // never the same take twice in a row
Try it
Four takes, one name
IdlePlay the footstep a few times, then walk. Set the spread to 0 and the order to cycle to hear it turn into a loop.
order
Plays0
Same take twice in a row0
The takes it picks show up here
The four takes are rendered in the page and added with addBuffer, so this demo loads no files.
Code
Your clicks show up here as soundhub calls
How it works
- Load the takes as ordinary sounds, from separate files with
loadSoundsor from one file withsetSoundSprite. - Give them a name with
createVariations. The name is not a sound itself, it only points at the takes. play(name)picks a take by theorderyou chose, draws a playback rate and a volume factor from the ranges, and plays that take. What it returns is the take'sSound.
The takes overlap by default, so a quick run of footsteps does not cut each step off. stop(name) stops every take the name started.
Where the name works
| Method | With a variation name |
|---|---|
play | Plays one take |
stop | Stops every take and its instances |
duck | Works as a target and as a trigger |
| everything else | Use the ids of the takes |
Events come from the take, so a started event carries 'step2' as originalId, not 'footstep'. To follow every play of the set, listen once per take with an originalId filter.
The methods
| Method | What it does |
|---|---|
createVariations | Give several takes one name. |
removeVariations | Forget the name, keep the takes. |
getVariations | The takes behind a name. |
The options are described on the VariationOptions page.