
Security News
Feross on the 10 Minutes or Less Podcast: Nobody Reads the Code
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.
sample-loader
Advanced tools
A powerful and easy audio buffer loader for browser:
var ac = new AudioContext()
var load = require('sample-loader')(ac)
// a simple audio buffer player (use `sample-player` instead)
function play(buffer) {
var source = ac.createBufferSource()
source.buffer = buffer
source.connect(ac.destinaton)
source.start(ac.currentTime)
}
load('@drum-machines/maestro').then(function (buffers) {
play(buffers['snare'])
})
## Install
Via npm: npm i --save sample-loader or grab the browser ready file (4kb) which exports loader as window globals.
sample-loader is a flexible function to load samples from server. You can create a loader with an AudioContext instance and an (optional) options hash map:
var loader = require('sample-loader')
var ac = new AudioContext()
var load = loader(ac, { /* options (can be null) */ })
The returned load function receives only one parameter: the samples to load and returns always a Promise.
You can load individual or collection of files:
load('http://path/to/file.mp3').then(function (buffer) {
// buffer is an AudioBuffer
play(buffer)
})
load(['samples/snare.mp3', 'samples/kick.mp3']).then(function (buffers) {
// buffers is an array of AudioBuffers
play(buffers[0])
})
load({ snare: 'samples/snare.mp3', kick: 'samples/kick.mp3' }).then(function (buffers) {
// buffers is a hash of names to AudioBuffers
play(buffers['snare'])
})
You can load midi.js soundfont files, and works out of the box with Benjamin Gleitzman's package of
pre-rendered sound fonts. No server setup, just prepend @soundfont before the instrument name:
load('@soundfont/acoustic_grand_piano').then(function(buffers) {
play(buffers['C2'])
})
Can load drum-machines by prepending @drum-machines before the instrument name:
load('@drum-machines/CR-78').then(function (buffers) {
play(buffers['snare'])
})
You can add you own server samples repositories with the options parameter:
var load = loader(ac, { repositories: {
'@my-repo': 'http://myserver.com/samples'
}})
and then:
load('@my-repo/file.mp3')
MIT License
FAQs
A web audio sample loader
The npm package sample-loader receives a total of 1 weekly downloads. As such, sample-loader popularity was classified as not popular.
We found that sample-loader 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
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.