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

waver-js

v1.0.16

Published

Advanced audio processing engine (a.k.a. audio shaders)

Downloads

6

Readme

waver-js - JavaScript "shaders" for audio

Contents:

  1. Install
  2. Usage
  3. API
  4. Language rules

Install:

npm install waver-js --save

Usage:

test.wv:

input media iSound;

node pan nPan;
node gain nGain;

param float pRange;

iSound => nPan => nGain => wv_audioDestination;

nPan.pan {
  Math.sin(Math.PI * 0.5 * Date.now() * 0.001) * this.pRange
}

nGain.gain {
  ((Date.now() * 0.001) % 1.35) / 1.35
}

index.js:

import { createWaver, createAudioContext } from 'waver-js';

const context = createAudioContext();
const sound = document.getElementById("sound");

function startup(source) {
  sound.play();

  const waver = createWaver(context, source);
  const soundSource = context.createMediaElementSource(sound);

  waver.bindInput('iSound', soundSource);
  waver.setParam('pRange', 0.65);
  waver.enabled = true;
}

fetch('./test.wv')
  .then(response => response.text())
  .then(source => startup(source));

API

Waver.createAudioContext()

  • return: AudioContext instance;

Creates instance of AudioContext.


Waver.createWaver()

  • return: Waver instance;

Creates instance od Waver.


Waver(context, source)

  • context: AudioContext instance;
  • source: string with waver program code;

Waver class constructor. It compile source program or throw an error on failure.


Waver.dispose()

Release resources of this instance.


Waver.bindOutput(id, value)

  • id: string with output id;
  • value: AudioNode instance used as output.

Binds given AudioNode as output.


Waver.bindInput(id, value)

  • id: string with input id;
  • value: AudioNode instance used as input.

Binds given AudioNode as input.


Waver.setParam(id, value)

  • id: string with param id;
  • value: parameter value.

Apply given value to waver parameter.


Waver.start()

Start playing waver inputs.


Waver.stop()

Stop playing waver inputs.


get Waver.valid

  • value: boolean;

It tells if this waver is valid (it's properly compiled)


get Waver.outputs

  • value: array[string];

It tells what outputs are used by this waver.


get Waver.inputs

  • value: array[string];

It tells what inputs are used by this waver.


get Waver.params

  • value: array[string];

It tells what params are used by this waver.


get Waver.nodes

  • value: array[string];

It tells what nodes are used by this waver.


get/set Waver.enabled

  • value: boolean;

Tell or change it's enabled state (if this waver is able to process).

Language Rules

There are 3 types of operations:

  • Node/param declarations;
  • Connection chains;
  • Nodes setup/update;

Node/param declaration

There are 4 declaration modes:

  • output - Tells about output node;
  • input - Tells about input node;
  • node - Tells about internal processing node;
  • param - Tells about manipulation parameter;

Example

output destination oTarget;
input buffer iSound;
node gain nGain;
param float pVolume;

output (output <type> <name>;) It's used as last node in connection chain. type: available types and their WebAudio API mappings:

input (input <type> <name>;) It's used as first node in connection chain. type: available types and their WebAudio API mappings:

node (node <type> <name> [(<param>)];) It's used as intermediate node in connection chain. You can set initialization parameter in parenthesis after it's name. type: available types and their WebAudio API mappings:

  • biquadFilter: BiquadFilterNode - Initialization parameter is a type name (node biquadFilter nFilter(highpass);)
  • delay: DelayNode - Initialization parameter is a delay value in seconds (node delay nDelay(0.5);)
  • compressor: DynamicsCompressorNode
  • gain: GainNode - Initialization parameter is a gain value in factor units (node gain nGain(0.5);)
  • oscillator: OscillatorNode - Initialization parameter is a type name (node oscillator nOscillator(sine);)
  • pan: StereoPannerNode - Initialization parameter is a pan value in [-1; 1] space (node pan nPan(-1);)

param (param <type> <name>;) It's used as node manipulation parameter as a way to control nodes from outside of waver. You can set initialization parameter in parenthesis after it's name. type: available types and their JavaScript mappings:

  • float: number

Connection chain

Nodes are connected in chains where all node names are separated by arrow (=>).

Example

iSound => nGain => nPan => oTarget;

Node setup/update

Here you assign expression to node properties (a-rate AudioParam or node property) or declare JavaScript lambda to update it. When use lambda, you can access params by this context (nPan { this.pPanning }).

Example

nPan.pan = pPanning;
nGain.gain = 0.5;
nPan2.pan {
  Math.sin(Math.PI * 0.5 * Date.now() * 0.001) * this.pRange
}