npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sounds-some-sounds

v3.1.0

Published

Add sounds to your game in a minute

Downloads

1,652

Readme

sounds-some-sounds (Demo)

Add sounds to your game in a minute.

How to use

Load build/index.js script,

<script src="https://unpkg.com/[email protected]/build/index.js"></script>

or install from npm and import.

> npm i sounds-some-sounds
import * as sss from "sounds-some-sounds";

Initialize the library with init() function. The first argument allows you to set a random number seed for sound generation. Generated sound effects and music can be changed by setting another random number seed.

addEventListener("load", () => {
  sss.init(42);
  update();

Since Safari and Chrome require playing the first sound within the event handler of a user operation, startAudio() should be called in the event handler.

addEventListener("touchstart", () => {
  sss.startAudio();
// It should also be called in 'mousedown' and 'keydown' events.

update() should be called per a frame for updating sounds.

function update() {
  requestAnimationFrame(update);
  // update function should be called in an animation frame handler
  sss.update();

Call playSoundEffect() to play a sound effect.

sss.playSoundEffect("coin");

You can specify the type of sound effect with the first argument. The type corresponds to the jsfx preset sound effects (Coin, Laser, Explosion, Powerup, Hit, Jump, Select and Random (Lucky)). You can hear these sounds on the demo page.

Use playMml() and generateMml() to play an automatically generated background music.

sss.playMml(sss.generateMml());

playMml() plays music described in MML (Music Macro Language). generateMml() generate MML with melody and drums procedurally.

You can also specify the MML string manually.

sss.playMml([
  // Specify the tone as `@synth`.
  // `@s308454596`sets the random number seed to generate the tone.
  "@synth@s308454596 v50 l16 o4 r4b4 >c+erer8.<b b2 >c+2 <b2 >c+ec+<ar>c+r<a f+g+af+rf+er e2",
  "@synth@s771118616 v35 l4 o4 f+f+ f+1 >c+ <g+ f+f+ eg+ ab b2",
  "@synth@s848125671 v40 l4 o4 d+16d+16f+16e16e16e16e16<b16 >ee b8.b16r8>f+8 c+c+ <b>f+ <aa a2 bb",
  // Set the drum part with '@d'.
  "@explosion@d@s364411560 v40 l16 o4 cr8.cr8. cr8.cr8. cr8.cr8. cr8.cr8. cr8.cr8. cr8.cr8. cr8.cr8. cr8.cr8.",
  "@explosion@d@s152275772 v40 l16 o4 r8crcrcr8. cccrcr8. crcrcr8. crcrcr8. crcrcr8. crcrcr8. crcrcr8. crcrcr",
  "@hit@d@s234851483 v50 l16 o4 rcr4^16c rcr4. ccr4^16c rcr4.^16 cr4^16c rcr4.^16 cr4^16c rcr4.",
]);

Sound effects are automatically quantized to the background music. The quantize interval can be changed with the setQuantize() function. setQuantize(0) disables quantization.

Functions

// Play sound effect
function playSoundEffect(
  // The list of SoundEffectType is as follows:
  // "coin", "jump", "powerUp", "laser", "hit", "select", "click", "explosion", "random",
  // "synth", "tone"
  type: SoundEffectType,
  options?: {
    // Random seed (default = 0)
    seed?: number;
    // Number of simultaneous sounds (default = 2)
    numberOfSounds?: number;
    // Sound volume (default = 1)
    volume?: number;
    // To set the pitch of the sound, set one of the following 3 parameters
    pitch?: number; // MIDI note number
    freq?: number; // Frequency (Hz)
    note?: string; // Note string (e.g. "C4", "F#3", "Ab5")
  }
): SoundEffect;
// Play music described in MML
function playMml(
  mmlStrings: string[],
  options?: {
    // Sound volume (default = 1)
    volume?: number;
    // Playback speed (default = 1)
    speed?: number;
    // Looping at the end of the music (default = true)
    isLooping?: boolean;
  }
): Track;
// Stop MML music
function stopMml(track?: Track): void;
// Generate MML strings
function generateMml(options?: {
  // Random seed (default = 0)
  seed?: number;
  // Generated music length (16 notes = 1 bar) (default = 32)
  noteLength?: number;
  // Number of simultaneous parts (default = 4)
  partCount?: number;
  // Probability of drum part generation (default = 0.5)
  drumPartRatio?: number;
}): string[];
// Initialize the library
function init(
  // Used to generate sound effects and MMLs
  baseRandomSeed?: number,
  // When reusing an existing AudioContext
  audioContext?: AudioContext
): void;
// The startAudio function needs to be called from within
// the user operation event handler to enable audio playback in the browser
function startAudio(): void;
// The update function needs to be called every
// certain amount of time (typically 60 times per second)
function update(): void;
// Set the tempo of the music
function setTempo(tempo?: number): void;
// Set the quantize timing of sound effects by the length of the note
function setQuantize(noteLength?: number): void;
// Set a master volume
function setVolume(volume?: number): void;
// Reset all states
function reset(): void;
// Set a random seed number
function setSeed(baseRandomSeed?: number): void;