audio-automator
v0.0.0
Published
A better way to change AudioParam values
Downloads
1
Readme
audio-automator
Description
A better way to change AudioParam values.
This library was created to deal with some of the issues I've encountered when working with the WebAudio AudioParam (MDN) automation features. The web-audio-api provides 6 functions for automating param values, as well as letting you set the param.value directly:
- AudioParam.cancelScheduledValues()
- AudioParam.exponentialRampToValueAtTime()
- AudioParam.linearRampToValueAtTime()
- AudioParam.setTargetAtTime()
- AudioParam.setValueAtTime()
- AudioParam.setValueCurveAtTime()
There are however, some annoyances with the API (IMHO), so I created this library. For example, when using any of the 6 functions above, the param.value does not change while automations are occurring, so you cannot inspect where in the automation you are (you have to calculate this yourself by keeping track of timings). Also, when you cancel an automation, the "value" jumps back to the value when the automation started (which may or may not be what you intended).
I've "fixed" these issues by always setting the param.value directly, and not using the built-in web audio automation functions. This allows me to expose different types of automation easing functions, as well as allowing end users to inspect automation timings and values at any time. It also lets you schedule new automations that just "pick up from the right spot". Meaning you don't have to cancel running automations if you don't want to. Just schedule a new one, and the most recent automation added will work correctly.
You can check out a live demo here:
Getting Started
Install the module with: npm install audio-automator
Documentation
Basic Usage
import AudioAutomator from 'audio-automator';
// create a context, and a gain node (which we will automate)
const audioContext = new AudioContext();
const gain = audioContext.createGain();
// create our AudioAutomator
const auto = new AudioAutomator(audioContext);
// Automate the gain node:
// This waits for 3 seconds, then starts using a `sinInOut` easing
// function to change the value of the gain node to 0.5. It will
// take 1.2 seconds to complete the automation.
auto.sinInOut(gain.gain, 0.5, 1.2, 3);
Links
License
Copyright (c) 2016 skratchdot
Licensed under the MIT license.