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

sample-loader

v0.1.1

Published

A web audio sample loader

Downloads

1

Readme

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