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

piano-notes-ts

v0.0.2

Published

TypeScript version of Chris Wilson's Piano-Notes library for playing high-quality, public domain samples

Downloads

3

Readme

piano-notes-ts

TypeScript library for playing high-quality, public-domain piano note samples. Forked from Chris Wilson's Piano-Notes library.

Usage

Install from NPM

npm install piano-notes-ts

Then import Notes and whichever audio samples you want:

import { Notes } from '../piano-notes-ts'
import { Piano_500 } from '../piano-notes-ts' 	// 500ms samples, ~1MB
import { Piano_1000 } from '../piano-notes-ts'	// 1-second samples, ~2MB
import { Piano_2000 } from '../piano-notes-ts'	// 2-second samples, ~4MB

let notes = new Notes();

Then, for whichever of the samples you've imported, load them into the notes instance:

notes.loadAudio([ Piano_500, Piano_1000 ]); // can load either one sample or multiple in an array

Then play the notes at your leisure:

notes.A4.play(500)
notes.Bb5.play()	// defaults to 1000ms

Samples

All the samples are loaded as base64 strings in Piano_500, etc., so that you don't have to download a bunch of mp3 files and locate them. The following describes the process for generating these files in case you want to add more samples, but isn't something you need to run otherwise.

Source

The University of Iowa Electronic Music Studios has generously provided free, high-quality .aiff files of all 88 notes on a Steinway & Sons Model B. These were downloaded using the ./samples/download.sh script, but you don't need to do this unless you want to format them differently than I have.

Conversion

We want mp3 files for maximum browser compatibility and file size. The original sample have a small amount of silence in the beginning that needs to be cut, and they need to be reduced to 1 seconds. This StackOverflow has useful advice on how to do this with ffmpeg:

ffmpeg -i ./samples/original/Piano.ff.C4.aiff -af loudnorm,silenceremove=start_periods=1:start_silence=0:start_threshold=-40dB,afade=out:st=0.25:d=0.25 -to 0.5 ./samples/test.mp3

You can format them all with ./samples/format.sh. This will create three samples for each of the 88 notes: a 500ms, 1-second and 2-second version, all mp3s.

Biniaries

To avoid any lag or complicated paths to the modules, each duration of samples are converted to base64 and wrapped into a JSON file to be imported. To do so--again, you don't have to do this unless you're rebuilding--one runs the Node module convertNotes.js in the code directory.

This produces three files in the data/audio directory: audio_500.json, audio_1000.json and audio_2000.json. At present, they're 1MB, 2MB and 3.9 MB respectively.