New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

sample-loader

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sample-loader

A web audio sample loader

latest
Source
npmnpm
Version
0.1.1
Version published
Maintainers
1
Created
Source

sample-loader npm

Samplr

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'])
})

Features

  • Load individual audio files or collection of them
  • Load base64 encoded audio strings
  • Compatile with midi.js soundfonts
  • Ready to use instruments with no setup

## Install

Via npm: npm i --save sample-loader or grab the browser ready file (4kb) which exports loader as window globals.

User guide

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.

Load audio files

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'])
})

Load soundfont files

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'])
})

Other instruments

Can load drum-machines by prepending @drum-machines before the instrument name:

load('@drum-machines/CR-78').then(function (buffers) {
  play(buffers['snare'])
})

Add instrument sources

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')

License

MIT License

Keywords

music

FAQs

Package last updated on 09 Dec 2015

Did you know?

Socket

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.

Install

Related posts