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

webaudiomixer

v1.0.9

Published

Automatic track mixing using the Web Audio API

Downloads

4

Readme

Logo

Web Audio Mixer

npm

🎛 Automatic track mixing using the Web Audio API

For a demo, please visit wam.dj. Click "Try the Demo" or Sign up, connect with SoundCloud and set up a play queue of your own songs!

The library uses Joe Sullivan's idea and algorithm for detecting beats using the Web Audio API. It uses WAAClock (which is based on an article by Chris Wilson - A Tale of Two Clocks) to schedule events based on the times calculated from the beat detection. If we know the BPM and a point in time when a drum hits, we can move to any beat in a track, or schedule another track to start on a beat.

The above idea aligns the beats of two tracks, but to properly mix, they need to play at the same tempo. Using the playbackRate and detune methods, the library time stretches the new track to match the current track. Currently, this is not a cross-browser solution, so I plan on using a Javascript implementation like PhaseVocoderJS to polyfill this behaviour.

Install

npm i webaudiomixer --save

Usage

import WebAudioMixer from 'webaudiomixer';

const context = new AudioContext();
const mixer = new WebAudioMixer({
    context
});
// Connect the mixer to the output
mixer.connect(context.destination);

Creating a play queue

You can add tracks to the play queue with a URL to an audio source. The add method returns a unique ID which you can assign back to the track in your application. Any events or references to the track will use that ID.

Add a track to the play queue

const id = mixer.add(stream_url);

Start the queue

mixer.play();

Pause all tracks

mixer.pause();

Remove a track from the play queue

const removed = mixer.remove(id);

Seek to a time in the track (in seconds)

mixer.seek(id, time);

Disconnect the AudioNode

mixer.disconnect();

⚠️ TODO: Removing/replacing a track once it's started, loaded or scheduled.

Events

You can listen for events to update the UI of your application. The events are emitted in the tolerance zone (0.10s) of the event happening in the Web Audio clock. If you need greater precision, schedule things using the times from the analyzed payload, or access information in mixer.tracks directly.

| Event | Payload | Description | |----------|-------------------|-----------------------------------------------------| | analyzed | { id, payload } | Track has been analyzed by the beat matching module | | loaded | { id, track } | Track has been loaded into an AudioBuffer | | mixin | { id, time } | Track is being mixed in at time | | mixout | { id, time } | Track has been mixed out at time | | playing | { id, time } | Track will begin playing at time | | paused | { id, time } | Track will be paused at time | | trackEnd | { id } | Track is stopped and destroyed |

⚠️ TODO: Helper method to find a track by ID, so that you can access the AudioBuffer, and other real-time information.

Options

| Option | Default | Description | |-------------------|--------------------|------------------------------------------------------------------------------| | context | new AudioContext() | I recommend passing in an AudioContext from your app | | maxBpmDiff | 8 | Maximum BPM difference between two tracks for the playbackRate to be changed | | mixLength | 20 | Time in seconds a track should crossfade and mix for | | playbackRateTween | 60 | Time in seconds a track should ramp back to it's original playbackRate | | volume | 1.0 | Initial value of the gainNode |

Final Year Project

This library was developed as a part of my Final Year Project for Web Development BSc at Staffordshire University. My report was titled Automatic track mixing using the Web Audio API and it researched the possibilities of using the Web Audio API to improving the experience of streaming music online.