Skip to content

Library for generating types of noise with the Web Audio API

Notifications You must be signed in to change notification settings

ichabodcole/NoiseGenJS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NoiseGenJS

A Javascript/CoffeeScript library for generating several types of ambient noise using the Web Audio API. DEMO

Installation

bower install noisegenjs

Basic Usage

// Create a new AudioContext to connect to
var context = new webkitAudioContext()

// Create a NoiseGen instance. The noise type can be "brown", "white" or "pink". The type default is "brown".
noiseGen = new NoiseGen(context, [noiseType="brown", "white", "pink"])

// Change the noise type.
noiseGen.setNoiseType("pink")

// Create a new gain node to control volume
var volume = context.createGain();

// Connect to the NoiseGen node to the gain node
noiseGen.connect(volume)

// Connect the gain node to the context output.
volume.connect(context.destination)

// Control volume like this
volume.gain.value = .8

// Finally
noiseGen.start()

// You can also silence playback by calling stop.
noiseGen.stop()

// If you no longer need a noiseGen object call the "remove" method before deleting the instance.
noiseGen.remove()
delete noiseGen

In addition to standard script linking, NoiseGen is AMD compliant and works great with requirejs.

About

Library for generating types of noise with the Web Audio API

Resources

Stars

Watchers

Forks

Packages

No packages published