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 🙏

© 2025 – Pkg Stats / Ryan Hefner

sf2create

v0.0.3

Published

Create SF2 (SoundFont v2) files from WAV data.

Readme

SF2Create

Create SoundFont v2 (.sf2) files from WAV data using JavaScript.

Note: this module was largely written by an LLM with some human feedback.

Install

npm install sf2create

Usage

Basic usage: const sf2Blob = createSf2File(dataStructure)

Example: Melodic Instrument

import { createSf2File } from './create-sf2.mjs';
import fs from 'fs';

// Define your sound data
const soundData = {
  name: 'MySoundFont',
  author: 'My Name', // Optional, defaults to the package name
  samples: [
    {
      name: 'piano',
      rawMonoData: new Float32Array(44100).fill(0.5), // 1 second of sound
      sampleRate: 44100,
      rootNote: 60,
    }
  ],
};

// Create the SoundFont file
const sf2Blob = createSf2File(soundData);

// Write to disk
fs.writeFileSync('output.sf2', Buffer.from(await sf2Blob.arrayBuffer()));

Example: Drum Kit

To create a drum kit, set isDrumKit: true. The rootNote for each sample specifies the MIDI key it maps to. If rootNote is not provided, it will be inferred from the sample name based on the General MIDI drum map.

import { createSf2File } from './create-sf2.mjs';
import fs from 'fs';

const drumData = {
  name: 'MyDrumKit',
  isDrumKit: true,
  samples: [
    {
      name: 'Kick', // Will default to rootNote 36
      rawMonoData: new Float32Array(22050).fill(0.9),
    },
    {
      name: 'Snare', // Will default to rootNote 38
      rawMonoData: new Float32Array(22050).fill(0.8),
    },
    {
      name: 'Open Hi-Hat', // Defaults to rootNote 46, exclusiveClass 1
      rawMonoData: new Float32Array(44100).fill(0.5),
    },
    {
      name: 'Closed Hi-Hat', // Defaults to rootNote 42, exclusiveClass 1
      rawMonoData: new Float32Array(11025).fill(0.6),
    }
  ]
};

const sf2Blob = createSf2File(drumData);
fs.writeFileSync('drumkit.sf2', Buffer.from(await sf2Blob.arrayBuffer()));

Command-Line Tool

A basic command-line tool create-sf2-from-wavs.mjs is included for converting .wav files into an SF2 instrument.

For melodic instruments, filenames must contain a note name (e.g., MySample-A4.wav).

node create-sf2-from-wavs.mjs "MyInstrument" samples/*.wav

For drum kits, use the --drums flag. Note names are not required; the tool will use sample names (e.g., kick.wav, snare.wav) to look up default MIDI notes.

node create-sf2-from-wavs.mjs --drums "MyDrumKit" drum-samples/*.wav

Testing

Run the tests:

npm test

Notes

  • Supports 16-bit mono and stereo samples.
  • Loop points can be specified for samples.
  • Supports basic melodic instruments and GM-compatible drum kits.

Technical references