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

pitchy

v4.1.0

Published

A simple pitch detection library.

Downloads

2,744

Readme

pitchy

npm GitHub Workflow Status

pitchy is a simple pitch-detection library written entirely in JavaScript that aims to be fast and accurate enough to be used in real-time applications such as tuners. To do this, it uses the McLeod Pitch Method, described in the paper A Smarter Way to Find Pitch by Philip McLeod and Geoff Wyvill.

A playground page is available to allow experimentation with the library and how different configurations may impact the quality of the results.

Note for v4 users: as of v4, Pitchy is distributed as a pure ES module. There are several implications of this for using various build and test tools: a Gist by sindresorhus gives a more detailed overview (including suggestions for various tools) than what can be covered in this README. The short version is that you may want to consider migrating your own project to ES modules. If all else fails, you can continue to use v3, as v4 contains no functional changes.

Installation

You can install pitchy using NPM (or similar tools such as Yarn):

npm install pitchy

You can also use a CDN, such as esm.sh, directly from a browser or Deno:

import { PitchDetector } from "https://esm.sh/pitchy@4";

Note that this package is ESM-only, meaning it can't be used with require. However, it can still be used from CommonJS code, albeit only in async contexts, using dynamic import:

const { PitchDetector } = await import("pitchy");

Usage

The main functionality of this module is exposed by the PitchDetector class. Instances of PitchDetector are generally created using one of the three static helper methods corresponding to the desired output buffer type:

  • PitchDetector.forFloat32Array(inputLength)
  • PitchDetector.forFloat64Array(inputLength)
  • PitchDetector.forNumberArray(inputLength)

Once a PitchDetector instance is created, the findPitch(input, sampleRate) method can be used to find the pitch of the time-domain data in input, returning an array consisting of the detected pitch (in Hz) and a "clarity" measure from 0 to 1 that indicates how "clear" the pitch is (low values indicate noise rather than a true pitch).

For efficiency reasons, the input to the findPitch method must always have the length indicated by the inputLength that was passed when constructing the PitchDetector.

An Autocorrelator class with a similar interface to PitchDetector is exposed for those who want to use the autocorrelation function for other things.

A simple usage example is available on GitHub Pages.

License

This is free software, distributed under the MIT license.