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

@hexkeylab/engine

v2.3.0

Published

HexKeyLab audio engine (HKLE): sample-based just-intonation playback with click-free segment-loop crossfades. Bring your own Web Audio AudioContext; no app/DOM/MIDI coupling.

Downloads

411

Readme

@hexkeylab/engine (HKLE)

The HexKeyLab audio engine: sample-based, just-intonation playback with click-free looping. It never uses AudioBufferSourceNode.loop; sustained notes loop by crossfading discrete one-shot sources at analyzer-computed segment seams on the audio clock. Pitch glides and real-time retuning are first-class.

It is environment-agnostic: you bring a Web Audio AudioContext and a few host hooks; the engine has no DOM, MIDI, storage, or framework coupling. That makes it usable in a browser app, or in React Native via react-native-audio-api (a Web Audio implementation).

Zero runtime dependencies.

Install

npm install @hexkeylab/engine

Quick start

import { init, loadInstrument, sNoteOn, sNoteOff, sRampFreq } from '@hexkeylab/engine';

const ctx = new AudioContext();

// 1. Wire the engine to your audio graph + inject host hooks.
init(ctx, ctx.destination, {
  // Velocity (0–127) → linear gain. Defaults to v/127.
  velocityToGain: (v) => v / 127,
  // Supply bytes for an .hki bundle instrument, keyed by sample filename.
  // (Return null for CDN-style instruments, which fetch by URL instead.)
  instrumentProvider: async (key) => myHkiBytesFor(key),
  // Optional: override URL loading (e.g. resolve expo-asset URIs in RN).
  // audioFetch: (url) => fetch(url).then((r) => r.arrayBuffer()),
});

// 2. Load an instrument definition (see InstrumentDef).
await loadInstrument('viola', violaInstrumentDef);

// 3. Play and retune in real time. Instrument is per-voice — several
//    instruments can sound at once, no global mode to set.
sNoteOn('voice-1', 220, 100, 'viola'); // voiceKey, freq (Hz), velocity, instrument
sRampFreq('voice-1', 247.5, 0.2);      // glide to a JI-tuned pitch over 200 ms
sNoteOff('voice-1');

API surface

  • init(audioCtx, destNode, config?) — connect the engine and inject instrumentProvider / velocityToGain / onSeamEvent / audioFetch.
  • loadInstrument(key, instrDef, onProgress?) — decode + cache an InstrumentDef's samples (CDN URLs or .hki bytes).
  • Voice lifecyclesNoteOn(voiceKey, freq, velocity, instrumentKey, startAt?), sNoteOff, sRampFreq, sNoteOnFaded, sSlideAndFadeOut, sHardStop, sHardStopAll, sStopAll. Instrument is specified per note; each voice remembers it, so simultaneous different instruments just work.
  • ExpressionsSetAftertouch, sSetVoiceDamperDepth.
  • StategetActiveVoices, isInstrumentLoaded, unloadInstrument, tapMaster.
  • startSegmentLooper(opts) — standalone single-voice segment looper (audition / preview), independent of the voice manager.
  • .hki bundlesreadHkiInstrument(bytes){ key, def, audio } turns a single .hki byte buffer into everything loadInstrument needs; instrumentDefFromManifest(manifest) is the lower-level manifest → InstrumentDef mapping. readHki / writeHki (+ HkiManifest / HkiBundle / HkiSampleEntry) are re-exported for direct bundle access.
  • TypesInstrumentDef, SampleDef, SampleEngineConfig, SeamEvent, PaRampState, SegmentLooperOpts, SegmentLooper.

.hki instruments

Click-free looping depends on good loop segments. The HexKeyLab analyzer produces .hki bundles (sustained samples + zero-crossing-matched {a, b} segment pairs).

A .hki is self-contained — it carries both the instrument definition and its audio. readHkiInstrument decomposes one buffer into the pieces the engine wants, so no separately authored defs JSON is needed:

import { init, loadInstrument, sNoteOn, readHkiInstrument } from '@hexkeylab/engine';

const { key, def, audio } = readHkiInstrument(hkiBytes);

init(ctx, ctx.destination, {
  // Hand back the bundle's audio for its own key; return null for anything else.
  instrumentProvider: async (k) => (k === key ? audio : null),
});
await loadInstrument(key, def);
sNoteOn('voice-1', 220, 100, key);

The engine handles decode, trim, trend-normalization, and seam scheduling from there. (You can still author an InstrumentDef by hand and feed bytes through instrumentProvider yourself — that path is unchanged.)

License

MIT