Giter VIP home page Giter VIP logo

audio-player's Introduction

audio-player npm

Build Status Code Climate js-standard-style license

Flexible audio player for browser

var ac = new AudioContext()
var player = require('audio-player')

var kick = player(ac, <AudioBuffer>)
kick.play()

## Features

Create players using a key to object

var drums = player(ac, {
  kick: <AudioBuffer>,
  snare: <AudioBuffer>,
  hihat: <AudioBuffer>
})
drums.play('kick')
drums.play('snare')

Map name notes to midi (and oposite)

var samples = { 'C2': <AudioBuffer>, 'Db2': <AudioBuffer>, ... }
var piano = player(ac, samples, { midi: true })
piano.play(69) // => Plays 'A4'
piano.play('C#2') // => Plays 'Db2'

Start and stop control

Unlike AudioBufferSourceNode, you can call start several times. Also, the stop function stops all the sounds.

var longSound = player(ac, <AudioBuffer>)
longSound.start() // one sample playing
longSound.start() // other sample playing (at same time)
longSound.stop() // stop both sounds

Events

var drums = player(ac, { kick: ..., snare: ..., hihat ... })
drums.onstarted = function (e) {
  console.log('start', e.name)
}
drums.onended = function (e) {
  console.log('ended', e.name)
}
drums.start('kick') // console logs 'started kick'
// console.logs 'ended kick' when sound stops

Amplitude envelope control

Basic filtering

## Install

Via npm: npm i --save audio-player or grab the browser ready file (4kb) which exports loadAudio as window global.

Usage

The API is very simple: player(ac, source, options)

Param Type Description
ac AudioContext the audio context
source Object the object to be loaded
options Object (Optional) the load options for that object

Run tests and examples

To run the test, clone this repo and:

npm install
npm test

To run the example:

npm i -g beefy
beefy example/example.js

License

MIT License

audio-player's People

Contributors

danigb avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.