![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
audio-slot
Advanced tools
Web Audio API triggerable audio slot described with JSON consisting of sources, processors, and modulators.
Web Audio API triggerable audio slot described with JSON consisting of sources, processors, and modulators.
Pass in an AudioContext extended with sources
, processors
, and modulators
and get back a single AudioNode. Because the entire setup of AudioNodes is done with a JSON object, it makes it simple and easy to persist and synchronize audio setups across a network. Used to manage each slot in soundbank.
$ npm install audio-slot
var AudioSlot = require('audio-slot')
audioContext
: instance of AudioContext extended with sources
, processors
, and modulators
lookups.
descriptor
: an object describing the desired configuration of AudioNodes. See example below.
Returns a slot
AudioNode.
A new descriptor object to update the internal nodes to. Will find and update all changed params, add new nodes and remove any unused nodes.
Trigger all source and modulator start methods.
Recommend triggering stop()
on sources at given time. This event may be ignored by some sources which specify their own off time such as oneshot samples.
Cut off playback of slot sources and modulators immediately.
Connect the slot output to another AudioNode (optionally specifying inputNumber
for nodes with multiple inputs)
Disconnect the slot from all previously connected destination AudioNodes.
var AudioSlot = require('audio-slot')
var audioContext = new webkitAudioContext()
audioContext.sources = {
sample: require('soundbank-sample'),
oscillator: require('soundbank-oscillator')
}
audioContext.processors = {
gain: audioContext.createGain.bind(audioContext), // can use built in nodes
filter: audioContext.createBiquadFilter.bind(audioContext),
delay: require('soundbank-delay')
}
audioContext.modulators = {
lfo: require('lfo'),
adsr: require('adsr')
}
audioContext.sampleCache = {}
loadAudioBuffer('/sounds/hiss.wav', function(err, buffer){
audioContext.sampleCache['hiss.wav'] = buffer
})
var slot = AudioSlot(audioContext, {
sources: [
{ node: 'sample', // coresponds to key in audioContext.sources
url: 'hiss.wav',
startOffset: 0.2,
endOffset: 1,
transpose: -3,
mode: 'loop',
amp: { // add a modulator from audioContext.modulators
node: 'adsr',
value: 1,
attack: 0.01,
decay: 0.3,
sustain: 0.6,
release: 0.4
}
}
],
processors: [
{ node: 'delay',
time: 0.1,
wet: 0.6
}
]
})
slot.connect(audioContext.destination)
// schedule a 2s playback of looped sample
slot.triggerOn(audioContext.currentTime)
slot.triggerOff(audioContext.currentTime + 2)
You can also use audio-slot instances as routing busses as by default they accept inputs from other nodes.
var bus = AudioSlot(audioContext, {
// specify how to handle trigger events
inputMode: 'on', // other options: bypass, holdOn, holdOff, bypassOn, bypassOff
volume: 1, // output gain
processors: [
{ node: 'filter',
type: 'lowpass',
frequency: { // modulate the frequency AudioParam with an lfo
node: 'lfo',
rate: 2,
amp: 100,
value: 200
}
}
]
})
// route in another audio node
slot.connect(bus)
bus.connect(audioContext.destination)
FAQs
Web Audio API FRP wrapper for creating, routing, and triggering AudioNodes.
The npm package audio-slot receives a total of 17 weekly downloads. As such, audio-slot popularity was classified as not popular.
We found that audio-slot demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.