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

wam

v0.0.2

Published

Web Audio Modules

Downloads

1

Readme

#WAM: Web Audio Modules

Demo Image A sine oscillator module connected to a delay module

WAM is a collection of open-source modular computer music components –– each including a web audio engine & HTML5 GUI –– built by the web audio community.

WAM is designed to assist building expressive musical instruments in the browser.

Building an Instrument

Assigning Context

Given a context ctx:

WAM.setContext( ctx )

Adding Individual Modules

Individual modules can be added to your project using WAM.moduleName() and connected to each other (or to any web audio node) using .connect()

var mySine = WAM.sine()
var myDelay = WAM.delay()
mySine.connect(myDelay)
myDelay.connect( WAM.out() )

By default, modules are positioned on the page relative to each other, within the flow of the document. To place a module precisely on the page, specify x/y when creating the module. Example: WAM.sine(100,200) will create a module 100 px from the left and 200 px from the top of the document.

Chaining Modules (recommended)

Groups of modules can be both created and connected using WAM.route(). This way you don't need to .connect() every module.

var rack1 = WAM.route([
	WAM.sine(),
	WAM.delay(),
	WAM.out()
])

...creates the audiograph:

AudioGraph

More complex audiographs can be created using WAM.join() along with WAM.route():

var rack1 = WAM.route([
	WAM.join( WAM.sine(), WAM.sine(), WAM.sine() ),
	WAM.delay(),
	WAM.out()
])

...creates the audiograph:

AudioGraph

and this...

var rack1 = WAM.route([
	WAM.join( WAM.sine(), WAM.sine(), WAM.sine() ),
	WAM.join( WAM.delay(), WAM.delay() ),
	WAM.out()
])

...creates the audiograph:

AudioGraph

You can also connect groups:

var rack1 = WAM.route([
	WAM.join( WAM.sine(), WAM.sine(), WAM.sine() ),
	WAM.delay()
])

var rack2 = WAM.route([
	WAM.join( WAM.sine(), WAM.sine(), WAM.sine() ),
	WAM.delay()
])

var rack3 = WAM.route([
	WAM.reverb(),
	WAM.out()
])

rack1.connect(rack3)
rack2.connect(rack3)

Contributing Modules

All users are encouraged to add modules to WAM! I am accepting all pull requests of working modules. These can be audio effects, signal generators, granular synths... the sky's the limit.

Modules are written as JS object literals within WAM.js. Each object follows the same pattern of properties and methods.

Example Module: "Sine" (sine oscillator with frequency and volume controls)
Modules.sine = { 
	dependencies: [ "Tone" ],
	size: {
		w: 80,
		h: 52
	},
	audio: function() {
		this.toneosc = new Tone.Oscillator(440, "sine").start();
		this.toneosc.connect(this.output)
	},
	interface: [
		{
			type: "dial",
			label: "freq",
			action: function(data) {
				this.toneosc.frequency.value = data.value * 1000
			},
			size: {
				w: 40,
				h: 40
			},
			location: {
				x: 0,
				y: 0
			}
		},
		{
			type: "dial",
			label: "vol",
			action: function(data) {
				this.toneosc.volume.value = -100 + data.value*100
			},
			size: {
				w: 40,
				h: 40
			},
			location: {
				x: 40,
				y: 0
			}
		}
	]
}
But what does it all mean?

The core of a module is:

  • A bit of web audio code (held in the audio function) which is executed once when the module loads.
  • A list of NexusUI interface components which have actions that affect the audio code depending on data from the interface. Interface actions are executed whenever the interface is interacted with.

This is the same "sine" module with all size and location details removed. It should show a clearer picture of the module's core components.

Modules.sine = { 
	audio: function() {
		this.toneosc = new Tone.Oscillator(440, "sine").start();
		this.toneosc.connect(this.output)
	},
	interface: [
		{
			type: "dial",
			label: "freq",
			action: function(data) {
				this.toneosc.frequency.value = data.value * 1000
			}
		},
		{
			type: "dial",
			label: "vol",
			action: function(data) {
				this.toneosc.volume.value = -100 + data.value*100
			}
		}
	]
}

Anatomy of a Module

Each module also has the following built-in properties, which may be useful during development:

this.input

Gain node forming the audio input to the current module. This is connected to by other modules.

this.output

Gain node forming the audio output of the current module. This connects to other modules.

this.shell

The <div> containing the module.

this.components

An array of the NexusUI interface components in this module.

this.type

The type of this module (i.e. "sine").

Anatomy of WAM

WAM.context

AudioContext, set with WAM.setContext()

WAM.modules

Array of modules created within the current project.