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 🙏

© 2026 – Pkg Stats / Ryan Hefner

beat-tracker

v1.0.3

Published

A lightweight beat tracking library for the browser

Readme

BeatTracker

A lightweight, pure JavaScript beat tracking library for the browser. It uses Web Workers for off-main-thread processing and FFT for spectral analysis to detect beats in audio files.

Note: The current version performs best with piano music.

Features

  • Web Worker Support: Performs heavy computations (FFT, spectral flux) in a background thread to keep the UI responsive.
  • Spectral Flux Analysis: Uses frequency domain analysis to detect onset strength.
  • Intelligent Beat Tracking: Implements an agent-based approach with tempo induction and phase alignment.
  • Zero External Dependencies: Self-contained logic using only native Web APIs.

Installation

This is a standalone module. Copy the src folder to your project.

Usage

Basic Usage

import { beatsEval } from './path/to/BeatTracker.js';

// Get an AudioBuffer (e.g., from AudioContext.decodeAudioData)
const audioContext = new AudioContext();
const response = await fetch('music.mp3');
const arrayBuffer = await response.arrayBuffer();
const audioBuffer = await audioContext.decodeAudioData(arrayBuffer);

// Analyze beats
try {
    const beatSamples = await beatsEval(audioBuffer, (progress) => {
        console.log(`Progress: ${progress.progress * 100}%`);
    });
    
    console.log('Detected beat sample indices:', beatSamples);
    
    // Convert samples to seconds
    const beatTimes = beatSamples.map(sample => sample / audioBuffer.sampleRate);
    console.log('Beat times (seconds):', beatTimes);
    
} catch (err) {
    console.error('Beat tracking failed:', err);
}

Finding Nearest Beat in Window

If you need to find a beat near a specific timestamp (e.g., for quantization or syncing):

import { findNearestBeatInWindow } from './path/to/BeatTracker.js';

const centerSample = 44100 * 10; // 10 seconds in
const result = await findNearestBeatInWindow(audioBuffer, centerSample);

console.log('Nearest beat sample:', result.nearestBeatSample);

Running the Example

Due to browser security restrictions on Web Workers and ES Modules (CORS), you cannot run the example directly from the file system (file://). You must serve it via a local HTTP server.

  1. Navigate to the project root:

    cd /path/to/BeatTracker
  2. Start a local server. For example, using Python:

    # Python 3
    python3 -m http.server 8000

    Or using Node.js http-server:

    npx http-server
  3. Open your browser and visit: http://localhost:8000/example/

Project Structure

BeatTracker/
├── src/
│   ├── BeatsTracker.js       # Main entry point and logic
│   ├── SpectralFluxWorker.js # Web Worker for processing
│   └── fftv5.js             # FFT implementation
├── example/
│   ├── index.html           # Demo interface
│   └── app.js               # Demo logic
└── README.md

License

MIT