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

soundscenemanager

v1.0.6

Published

A framework for managing multiple sounds that need to change based on the 'scene' on an application.

Downloads

7

Readme

SoundSceneManager

Simple scene manager for fading between various sets of sounds..

npm version

Usage

npm install soundscenemanager
var soundscenemanager = require('soundscenemanager');

var oceanBgSound = context.createBufferSource();
oceanBgSound.buffer = downloadedOceanBuffer; //some downloaded AudioBuffer

var options = {
	scenes:[{
		name:"ocean",
		sounds:[{
			name:"background",
			node: oceanBgSound,
		}]
	}, {
		name:"city",
		sounds:[{
			name:"kitchen",
			node: kitchenSound,
		}]
	}],
	fadeDuration: 1,
	startingScene: "ocean",
	context: context
}

var s = soundscenemanager(options);

// Transition to the next scene (city).
s.transitionToNextScene(context.currentTime+10, 2);

// Fades out all audio.
s.mute(context.currentTime+20, 2);

API

Constructor

eg :

var oceanBgSound = context.createBufferSource();
oceanBgSound.buffer = downloadedOceanBuffer;

var options ={
	scenes:[{
		name:"ocean",
		maxVolume : 0.7,
		sounds:[{
			name:"background",
			node: oceanBgSound,
		},{
			name:"diver",
			node: diverSound,
		}]
	},{
		name:"city",
		sounds:[{
			name:"kitchen",
			node: kitchenSound,
		},{
			name:"club",
			node: clubSound,
		}]
	}],
	fadeDuration: 1,
	startingScene: "ocean",
	fadeInAtStart: true,
	fadeInAtStartDuration : 5,
	context: context
}
var s = soundscenemanager(options);
  • options object attribute contains the data about the various scenes in the following format:
    • scenes : Array - Array of scene objects which are being managed by this SoundSceneManager. Each scenes object should have the following properties:
      • name : String - The name of the scene.
      • maxVolume : Number - The maximum volume of this scene [0,1];
      • fadeInAtStart : Boolean - If the starting scene should fade in.
      • fadeInAtStartDuration : Number - Time taken (sec) for the starting scene to fade in.
      • sounds : Array - Array of sound objects which are a part of this specific scene. Each sound object should have the following properties:
        • name : String - A name for identifying the sound object.
        • node : AudioNode/SoundModel/Audio - An AudioNode which will be connected to the SoundSceneManager and faded in/out. It's preferable that this AudioNode isn't connected to any other AudioNodes, as it will be disconnected in the process of initializing the SoundSceneManager. A Sonoport SoundModel object is also accepted here and so is an HTML5 Audio object. Note: If using an HTML5 Audio element with a cross-origin source, ensure that the CORS header is set and the crossOrigin property is set on the Audio Object before calling play on the Audio Object.
    • fadeDuration : Number - Default duration, in seconds, of all fadesin/fadeouts.
    • startingScene : String - The name of the first scene to fade in at startup.
    • context : AudioContext - AudioContext within which all the AudioNodes are created.

Methods

  • transitionToScene : Transition to a given scene. Fades out the audio from the current scene and fades in the audio from the given scene. If the nextScene is the same as current scene, this method will not do anything.

    • eg :

      s.transitionToScene('nextSceneName', context.currentTime+10, 2);
    • arguments :

      • nextSceneName : String - The name of the scene to transition to. If null, the current scene will fade out.
      • startTime : Number - Start time for the transtion in the same time coordinate system as the AudioContext currentTime attribute.
      • fadeDuration : Number - Duration in seconds of the transtion.
  • transitionToNextScene : Similar to transitionToScene except it transtions to the next scene based on the order of the scenes as defined in the scenes array in the constructor options. If the current scene is the last scene in the array, this will transition to the first scene in the array.

    • eg :

      s.transitionToNextScene(context.currentTime+10, 2);
    • arguments :

      • startTime : Number - Start time for the transtion in the same time coordinate system as the AudioContext currentTime attribute.
      • fadeDuration : Number - Duration in seconds of the transtion.
  • transitionToPrevScene : Similar to transitionToScene except it transtions to the previous scene based on the order of the scenes as defined in the scenes array in the constructor options. If the current scene is the first scene in the array, this will transition to the last scene in the array.

    • eg :

      s.transitionToPrevScene(context.currentTime+10, 2);
    • arguments :

      • startTime : Number - Start time for the transtion in the same time coordinate system as the AudioContext currentTime attribute.
      • fadeDuration : Number - Duration in seconds of the transtion.
  • mute : Fades out all audio from the SoundSceneManager.

    • eg :

      s.mute(context.currentTime+10, 2);
    • arguments :

      • startTime : Number - Start time for begining of the fadeout in the same time coordinate system as the AudioContext currentTime attribute.
      • fadeDuration : Number - Duration in seconds taken for the fadeout.
  • unMute : Fades in all audio from the SoundSceneManager if faded out.

    • eg :

      s.unMute(context.currentTime+10, 2);
    • arguments :

      • startTime : Number - Start time for begining of the fadein in the same time coordinate system as the AudioContext currentTime attribute.
      • fadeDuration : Number - Duration in seconds taken for the fadein.
  • toggleMute : Toggles between mute and unMute APIs based on the current state of the SoundSceneManager.

    • eg :

      s.toggle(context.currentTime+10, 2);
    • arguments :

      • startTime : Number - Start time for begining of the fadein/fadeout in the same time coordinate system as the AudioContext currentTime attribute.
      • fadeDuration : Number - Duration in seconds taken for the fadein/fadeout.
  • addScene : Adding a new scene for the SoundSceneManager to manage.

    • eg :

      var newScene = {
      	name:"ocean",
      	sounds:[{
      		name:"background",
      		node: oceanBgSound,
      	},{
      		name:"diver",
      		node: diverSound,
      	}]
      }
      s.addScene(newScene);
    • arguments :

      • newScene : Object - A new scene object that should have the following properties :
        • name : String - The name of the scene.
        • maxVolume : Number - The maximum volume of this scene [0,1];`
        • sounds : Array - Array of sound objects which are a part of this specific scene. Each sound object should have the following properties:
          • name : String - A name for identifying the sound object.
          • node : AudioNode - An AudioNode which will be connected to the SoundSceneManager and faded in/out. It's preferable that this AudioNode isn't connected to any other AudioNodes, as it will be disconnected in the process of initializing the SoundSceneManager. A Sonoport SoundModel object is also accepted here and so is an HTML5 Audio object. Note: If using an HTML5 Audio element with a cross-origin source, ensure that the CORS header is set and the crossOrigin property is set on the Audio Object before calling play on the Audio Object.
  • addSoundToScene : Add a new sound to ax existing scene.

    • eg :

      var newSound = {
      	name:"background",
      	node: oceanBgSound,
      }
      
      s.addSoundToScene(newSound,sceneName);
    • arguments :

      • newSound : Object - A new sound object that should have the following properties :
        • name : String - A name for identifying the sound object.
        • node : AudioNode - An AudioNode which will be connected to the SoundSceneManager and faded in/out. It's preferable that this AudioNode isn't connected to any other AudioNodes, as it will be disconnected in the process of initializing the SoundSceneManager. A Sonoport SoundModel object is also accepted here and so is an HTML5 Audio object. Note: If using an HTML5 Audio element with a cross-origin source, ensure that the CORS header is set and the crossOrigin property is set on the Audio Object before calling play on the Audio Object.
      • sceneName : String - The name of the scene we want to add this Sound to.

Properties

  • fadeDuration : Number - Default duration, in seconds, of all fadein/fadeouts.

  • currentSound : Object - The current scene object that's playing or being faded in.

  • isMuted : Boolean - Indicates if the SoundSceneManager is muted.

License

Apache-2.0

See License file