All Projects → zya → Beet.js

zya / Beet.js

Licence: mit
Polyrhythmic Sequencer library for Web Audio API.

Programming Languages

javascript
184084 projects - #8 most used programming language
js
455 projects

Projects that are alternatives of or similar to Beet.js

Daw
GridSound (0.33.0) wants to be an open source online digital audio workstation following the new WebAudio API 🎛🎹🎵✨
Stars: ✭ 804 (+824.14%)
Mutual labels:  audio, music, webaudio
Xsound
Web Audio API Library for Synthesizer, Effects, Visualization, Multi-Track Recording, Audio Streaming, Visual Audio Sprite ...
Stars: ✭ 123 (+41.38%)
Mutual labels:  audio, music, webaudio
Jssynth
Make music in your browser with this synthesizer and sequencer
Stars: ✭ 25 (-71.26%)
Mutual labels:  audio, music, webaudio
Otto
Sampler, Sequencer, Multi-engine synth and effects - in a box! [WIP]
Stars: ✭ 2,390 (+2647.13%)
Mutual labels:  audio, music, sequencing
Waveform Playlist
Multitrack Web Audio editor and player with canvas waveform preview. Set cues, fades and shift multiple tracks in time. Record audio tracks or provide audio annotations. Export your mix to AudioBuffer or WAV! Project inspired by Audacity.
Stars: ✭ 919 (+956.32%)
Mutual labels:  audio, music, webaudio
Blipkit
C library for creating the beautiful sound of old sound chips
Stars: ✭ 23 (-73.56%)
Mutual labels:  library, audio, music
Redoflacs
Parallel BASH commandline FLAC compressor, verifier, organizer, analyzer, and retagger
Stars: ✭ 71 (-18.39%)
Mutual labels:  library, audio, music
Arduino Music Player
MOD/S3M/XM/IT Music Player for Arduino
Stars: ✭ 85 (-2.3%)
Mutual labels:  audio, music
Theorytracker
🎼 HTML5/WebAudio multi-track functional harmony analysis and songwriting app! -- https://hlorenzi.github.io/theorytracker/
Stars: ✭ 62 (-28.74%)
Mutual labels:  music, webaudio
Fountain Of Colors
Music visualizer for Rainmeter
Stars: ✭ 65 (-25.29%)
Mutual labels:  audio, music
Audio
This is a library for declarative use of Web Audio API with Angular
Stars: ✭ 67 (-22.99%)
Mutual labels:  audio, webaudio
Nokia Composer
Nokia Composer in 512 bytes
Stars: ✭ 86 (-1.15%)
Mutual labels:  music, webaudio
Sound Source Localization Algorithm doa estimation
关于语音信号声源定位DOA估计所用的一些传统算法
Stars: ✭ 58 (-33.33%)
Mutual labels:  audio, music
Ctag Straempler
An open source eurorack sample streaming and sound synthesis module.
Stars: ✭ 65 (-25.29%)
Mutual labels:  audio, music
Bpm
Library and tool for dealing with beats per second detection
Stars: ✭ 57 (-34.48%)
Mutual labels:  audio, music
Audiokit
Swift audio synthesis, processing, & analysis platform for iOS, macOS and tvOS
Stars: ✭ 8,827 (+10045.98%)
Mutual labels:  audio, music
Videojs Record
video.js plugin for recording audio/video/image files
Stars: ✭ 1,074 (+1134.48%)
Mutual labels:  audio, webaudio
Stereo
A Flutter plugin for playing music on iOS and Android.
Stars: ✭ 66 (-24.14%)
Mutual labels:  library, audio
Androidaudioconverter
Convert audio files inside your Android app easily. Supported formats: AAC, MP3, M4A, WMA, WAV and FLAC.
Stars: ✭ 1,156 (+1228.74%)
Mutual labels:  library, audio
Omg Music
Music making, remixing, and collaborating tools for the web
Stars: ✭ 74 (-14.94%)
Mutual labels:  music, webaudio

beet.js

Polyrhythmic Sequencer library for Web Audio API.

The sequencer can have multiple layers where each layer has a different step count. This feature allows the user to create complex polyrhythms and euclidean rhythms using a simple api.

Installation

You can install beet from npm.

npm install beet.js

Or grab the latest version from build folder and include it in your html.

<script src='beet.min.js'></script>

Example Usage

var context = new AudioContext();

// initialize beet
var beet = new Beet({
  context: context,
  tempo: 100
});

// create a euclidean pattern - 5 pulses distrubted in 7 steps
var pattern = beet.pattern(5,7);

// create a beet layer - pass it the pattern and a callback
var layer = beet.layer(pattern, callback);

function callback(time){
  var osc = context.createOscillator();
  osc.connect(context.destination);
  osc.start(time);
  osc.stop(time + 0.1);
}

// add the layer
beet.add(layer);

// start the sequencer
beet.start();

API

Beet

new Beet(opts)

Beet constructor. Returns a new instance of beet.

Parameters

  • opts (required) - an object containing the initialisation options
    • context (required) - an instance of AudioContext
    • tempo (optional) - speed in BPM - defaults to 120

beet.start(time)

Starts the sequencer after a given time in seconds.

Parameters

  • time - a number in seconds - defaults to 0

beet.stop(time)

Stops the sequencer after a given time in seconds and resets the current step number.

Parameters

  • time (optional) - a number in seconds - defaults to 0

beet.pause(time)

Pauses the sequencer after a given time in seconds but keeps the current step number.

Parameters

  • time (optional) - a number in seconds - defaults to 0

beet.add(layer(s))

Adds a given beet.layer to the list of layers to play. Can also be used with multiple layers. beet.add(layer1, layer2)

Parameters

  • layer (Required) - a beet.layer object.

beet.remove(layer)

Removes a given beet.layer from the list of layers to play.

Parameters

  • layer (Required) - a beet.layer object.

Pattern

The pattern method will return a pattern object based on the provided values. If pulses and steps are passed in as numbers, an equally distributed pattern will be generated and returned. Alternatively, you can use a custom pattern string. For example '1000101010'.

beet.pattern(pulses, steps)

Returns a pattern object containing a bjorklund sequence with equally distributed number of pulses over steps.

Parameters

  • pulses (required) - number of pulses (active steps) in the sequence
  • steps (optional) - number of steps in the sequence - value of pulses will be used steps is not specified.

example

var pattern = beet.pattern(3, 7);
// a pattern object containing a sequence as below
// '1010100'

var pattern2 = beet.pattern(4);
// a pattern object with a sequence as below
// '1111'

beet.pattern(patternString)

Returns a pattern object containing a the custom pattern. This can be used to generated custom sequences when neccessary.

Parameters

  • patternString (required) - a binary sequence string with an arbitrary length using 1's for pulses and 0's for empty slots.

example

var pattern = beet.pattern('100010010');
var pattern2 = beet.pattern('10001111');

.update(pulses, steps)

Updates the pattern object with the new values. You can also update the values directly. See example below.

Parameters

  • pulses (required) - number of pulses (active steps) in the sequence.
  • steps (optional) - number of steps in the sequence. value of pulses will be used steps is not specified.

example

var pattern = beet.pattern(2, 5);
pattern.update(5,8); // updates the pattern to '10100'

// you can also set the values separately
pattern.pulses = 4;
pattern.steps = 8;

.shift(offset)

Shifts the sequence by the offset and returns the pattern object.

Parameters

  • offset (required) - number of steps to shift the sequence by

example

var pattern = beet.pattern(1, 4); // returns '1000'
pattern.shift(1) // updates the sequence to '0100'

Layer

layer(pattern, onCallback, offCallback)

Creates a beet.layer object and returns it.

Parameters

  • pattern (required) - a beet.pattern object.
  • onCallback (required) - a function to call on pattern's pulses e.g. 1's
  • offCallback (optional) - a function to call on pattern's empty slots e.g. 0's.

example

var pattern = beet.pattern(1, 4); // returns '1000'
var layer = beet.layer(pattern, on, off);
// on will be called on 1
// off will be called on 0's

Callback format

The callbacks are functions that will be called from the scheduler. The functions will be called with time, step and timeFromScheduled parameters. You can use the time parameter for web audio methods. step can be used to change audio behaviour according to the current step. timeFromScheduled is a value in seconds which corresponds to the time it will take for an audio event to occur from the time it was scheduled (time - context.currentTime). It can be used to schedule JS events using setTimeout.

example

function callback (time, step, timeFromScheduled) {
    var osc = context.createOscillator();
    osc.connect(context.destination);
    if(step === 1){
      osc.frequency.value = 880;
    }
    osc.start(time);
    osc.stop(time + 0.2);
    setTimeout(function(){
      // trigger some js event such as animation - will be synced to the audio
    }, timeFromScheduled * 1000);
}

Play/Pause/Stop layers

You can play and pause individual layers using:

var pattern = beet.pattern(1, 4); // returns '1000'
var layer = beet.layer(pattern, on, off);
layer.play()
layer.pause()
layer.stop()

Utils

Beet comes with a series of useful utilities for web audio api. These might me moved to a separate module in the future as these are not specific to beet's functionality. But for now, features will be added gradually.

.envelope(audioparam, now, opts)

Applies an envelope to the audio param given a series of options.

Parameters

  • audioparam (required) - an AudioParam object to be automated.
  • now (required) - the time for the automation to start, e.g. the time parameter in beet callback.
  • opts (optional) - an JavaScript object that contains the envelope parameters.
    • start (optional) - the start value for the automation curve. the audio param will be set to this value at the beginning of the automation.
    • peak (optional) - the maximum value for the automation curve that the attack stage will end up in.
    • attack (optional) - the time in seconds for the attack stage.
    • decay (optional) - the time in seconds for the decay stage.
    • sustain (optional) - the value for that the decay stage will end up in.
    • release (optional) - the time in seconds for the release stage.

example

var osc = context.createOscillator();
var gain = context.createGain();
osc.connect(gain);
gain.connect(context.destination);

beet.utils.envelope(gain.gain, time, {
  start: 0,
  peake: 1.0,
  attack: 0.1,
  decay: 0.2,
  sustain: 0.8,
  release: 0.5
});

osc.start(time);
osc.stop(time + 2);

.load(path, success, failure, context)

Loads an audio file for a given path and returns a decoded AudioBuffer object.

Parameters

  • path (required) - the path to your audio file.
  • success (required) - function to be called on load success. The passed function will be called with a buffer parameters which is an AudioBuffer object.
  • failure (required) - function to be called on load or decode error.
  • context (optional) - an instance of AudioContext, if not provided, global variable context will be used

example

beet.utils.load('path/to/file.wav', function(buffer){
  // do something with the buffer
}, failureHandler, context);

.mtof(midi_note)

Converts a give midi note to a frequency value in hz.

Parameters

  • midi_note (required) - the midi note number (0 to 127).

example

beet.utils.mtof(69); // will return 440 for A4

.ntof(note_name)

Converts a given note name to a frequency value in hz.

Parameters

  • note_name (required) - the note name followed by octave e.g. 'a4'

example

beet.utils.ntof('a4'); // will return 440 for A4

.mtop(midi_note)

Converts a given midi note to a value representing the playbackRate.

Parameters

  • midi_note (required) - the midi note number (0 to 127).

example

beet.utils.mtop(60); // will return 1 for C4 - meaning the sample will be played in the original speed
beet.utils.mtop(72); // will return 2 for C3
beet.utils.mtop(48); // will return 0.5 for C2
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].