neume.js

0.8.0 • Public • Published

neume.js

Bower Build Status Coverage Status

What is?

Neume (/ˈnjuːm/; ja: ニューム) is a Web Audio API library for developing browser music. The architecture of neume.js provides a very simple interface for creating web-based audio application and generates optimized audio-graph for Web Audio API.

Examples

Installation

Bower

$ bower install neume.js

Downloads

You'll also need a Promise polyfill for older browsers.

Here is boilerplate html in order to play a sine wave metronome in neume.js. → sample

<!DOCTYPE html>
<html>
<head>
  <title>neume.js metronome</title>
  <script src="/path/to/neume.min.js"></script>
</head>
<body>
  <button id="start">start</button>
  <script>
    var neu = neume(new AudioContext());

    function Sine($, freq, dur) {
      return $("sin", { freq: freq })
      .$("xline", { dur: dur }).on("end", $.stop);
    }

    var timer = null;

    function start() {
      if (timer) {
        timer.stop();
        timer = null;
      } else {
        timer = neu.Interval("4n", function(e) {
          var freq = [ 880, 440, 440, 440 ][e.count % 4];
          var dur = [ 0.5, 0.125, 0.125, 0.125 ][e.count % 4];

          neu.Synth(Sine, freq, dur).start(e.playbackTime);
        }).start();
      }
    }

    document.getElementById("start").onclick = start;
  </script>
</body>
</html>

How do work?

This example makes a modulated 880(±20) Hz sine wave with an exponential decay of about one second.

// initialize neume interface with AudioContext
var neu = neume(new AudioContext());

// define synth and play it
neu.Synth(function($) {
  return $("sin", { freq: $("sin", { freq: 8 }).mul(20).add(880) })
  .$("xline", { start: 0.25, end: 0.001, dur: 1 }).on("end", $.stop);
}).start();

Above code generates an audio-graph like a below. Graphs are optimized flexibly by neume.js.

                        +-------------------+
                        | OscillatorNode    |
                        | - type     : sine |
                        | - frequency: 8    |
                        | - detune   : 0    |
                        +-------------------+
+-------------------+     |
| OscillatorNode    |   +------------+
| - type     : sine |   | GainNode   |
| - frequency: 880  <---| - gain: 20 |
| - detune   : 0    |   +------------+
+-------------------+
  |
+-----------------------+
| GainNode              |
| - gain: 0.25 -> 0.001 |
+-----------------------+
  |
+-----------+
| GainNode  | * This node is used to
| - gain: 1 |     fade volume for a synth instance.
+-----------+
  |

In SuperCollider

{
  SinOsc.ar(SinOsc.kr(8) * 20 + 880) *
    XLine.kr(0.25, 0.001, 1, doneAction:2)
}.play;

In MAX patch

max-capture

Tools

Documents

License

Neume.js is available under the The MIT License.

Package Sidebar

Install

npm i neume.js

Weekly Downloads

7

Version

0.8.0

License

MIT

Last publish

Collaborators

  • mohayonao