soundbed

0.1.8 • Public • Published

Build status

soundbed

An ambient audio generator.

Use SoundBed to generate audio for animation, simulations or general ambient effects in a web browser. The module uses the Web Audo API and by default will generate a low, rumbling hum that naturally varies in frequency. Use the options below for different configurations. Your browser must support the Web Audio API.

Install

To include soundbed as a component in your project, use the node module.

npm install soundbed --save

You can also use the standalone version and reference the js file from your document.

<html>
  <head>
    <script src="scripts/soundbed.min.js" type="text/javascript" charset="utf-8"></script>
  </head>
  ...

Usage

The module exports a SoundBed class. In a nodejs project, you create a player via:

var SoundBed = require('../src/soundbed');
var player = new SoundBed.Player();

In the browser, the SoundBed namespace is exposed.

<html>
  <head>
    <script src="scripts/soundbed.min.js" type="text/javascript" charset="utf-8"></script>
  </head>
  <body>
    <script>
      var player = new SoundBed.Player();
      player.init({
        oscAFreq: 60,
        oscBFreq: 120,
        oscARate: 0.01,
        oscBRate: -0.01,
        freqMin: 60,
        freqMax: 120,
        volumeMin: 0.1,
        volumeMax: 1
      });
    </script>
  </body>
</html>

Configure

By default, a SoundBed player creates two Web Audio Oscillator nodes and cycles their frequencies in opposite directions inside an RequestAnimationFrame loop. In each frame the player maps Perlin noise to a minimum/maximum range to determine the frequency. It also cycles the overall volume using the Perlin values.

You can pass the following options when initializing a Player.

  • perlin (default = true)

    When set to true, the oscillators' frequencies cycle via Perlin noise.

  • reverb

    Reverb level. Valid values are 0 - 5 and map to the following:

    0 = none

    1 = inverse

    2 = small

    3 = medium

    4 = large

    5 = huge

  • delayTime (default = 0)

    Delay time.

  • oscAFreq (default = 150)

    Oscillator A's initial frequency.

  • oscBFreq (default = 200)

    Oscillator B's initial frequency.

  • oscARate (default = 0.001)

    Oscillator A's cycle rate through its frequency min/max.

  • oscBRate (default = -0.001)

    Oscillator B's cycle rate through its frequency min/max.

  • freqMin (default = 150)

    Both oscillators' minimum frequency.

  • freqMax (default = 200)

    Both oscillators' maximum frequency.

  • volume (default = 0.25)

    The player's initial volume. Valid values between 0 and 1.

  • volumeMin (default = 0.1)

    The player's minimum volume. Valid values between 0 and 1.

  • volumeMax (default = 0.25)

    The player's maximum volume. Valid values between 0 and 1.

  • beforeStep (default = function() {})

    A function called at the beginning of each animation frame.

Please review the docs or check out the examples.

Building this project

This project uses Grunt. To build the project first install the node modules.

npm install

Next, run grunt.

grunt

To run the tests, run 'npm test'.

npm test

To check test coverage run 'grunt coverage'.

grunt coverage

A pre-commit hook is defined in /pre-commit that runs jshint. To use the hook, run the following:

ln -s ../../pre-commit .git/hooks/pre-commit

A post-commit hook is defined in /post-commit that runs the Plato complexity analysis tools. To use the hook, run the following:

ln -s ../../post-commit .git/hooks/post-commit

View the code complexity report.

Readme

Keywords

Package Sidebar

Install

npm i soundbed

Weekly Downloads

9

Version

0.1.8

License

MIT

Last publish

Collaborators

  • vinceallenvince