soundhub.js

v5.9.0

A group holds only so many voices

Put your sounds in a named group, give the group a maxInstances limit, and play as much as you like. Once the group is full, the oldest instance stops so the new one can start. Watch the slots below fill up, then take the arcade game for a spin and hear what happens when you fire faster than the limit allows.

  1. 1

    Create the group

    sm.createSoundGroup('weapons', { maxInstances: 3 })
  2. 2

    Play into it

    sm.play('laser', { createNewInstance: true, groupId: 'weapons' })
  3. 3

    The limit does the rest

    4th shot → oldest instance stops
Audio Invaders in play: three shots in the air, shot-away shield blocks above the ship, and the weapons voice slots full Play Audio Invaders Three groups, one keyboard. Fire faster than the limit and hear a shot get cut off.

Voice lab

Two groups, two limits. Hammer the buttons and watch a slot get taken over.

RETRO PONG 1 PLAYER · 2 PLAYER · FREE PLAY
▶ INSERT COIN

Also from this workshop

Retro Pong is a full game rather than a demo, and its audio runs on this same library: stereo-panned effects, a serve you aim yourself, power-ups, mines, and an end-of-match sequence that tells you how the match went.

  • Sound soundhub, panned per hit
  • Install npm i retro-pong-game
  • Drop-in one constructor call on any page