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

pitch-analyser

v1.1.0

Published

A package that returns information about audio input (e.g. note and frequency)

Downloads

29

Readme

Pitch Analyser

A super simple package for reading audio input from a microphone. E.g. pitch frequency, music notes and the cents.

This package makes use of the Web Audio API

Here is an example project called note detector using this package here. (Repo / Demo)

CURRENT ISSUE: Known issue - Chrome does not resume the analyser after pausing.

WARNING: Breaking changes possible - This will be done as MINOR updates.

Not in active development, but at times I can make a breaking change to optimise usage. So keep that in mind, if you are one of the lovely people trying this package out.

Will remove the warning if this will not be the case anymore. Or help me out with this I guess? 🤷🏻‍♂️

Table of Content

Installing

Npm: npm i pitch-analyser

Usage

This package returns the frequency, music note and cents from audio input and nothing more.

  1. Import the package
import pitchAnalyser from 'pitch-analyser';
  1. Initialize the analyser In the callback we can do whatever we want with the payload
const analyser = new pitchAnalyser({
	callback: function(payload) {
		console.log(payload); // E.g. { frequency: 220, note: "A3" }
	}
});
  1. Stopping the analyser In case you want to stop the analyser. In componentWillUnmount in React for example.
componentWillUnmount() {
	analyser.close();
}

Thats all you need to do to get started. Check out this example project to see it in action. (Repo / Demo)

Payload format

The payload is an object and can look like this with default options.

{
	note: "D7",
	frequency: 2349.32,
	cents: -21 // if returnCents is set to true
}

Options

These are the few options available.

  • callback
  • returnNote
  • returnCents
  • decimals

callback

| Type | Default | isRequired | | -------- | ------- | ---------- | | function | null | true |

Through the callback you will receive the output and will need to handle what to do with it here.

new pitchAnalyser({
	callback: function(value) {
		// E.g. { frequency: 220, note: "A3" }
		console.log(value);
	}
});

returnNote

| Type | Default | isRequired | | ------- | ------- | ---------- | | boolean | true | false |

If this option is set to true, the frequency and note will be passed to the callback function.

new pitchAnalyser({
	returnNote: true,
	...other options...
});

returnCents

Requires returnNote

| Type | Default | isRequired | | ------- | ------- | ---------- | | boolean | false | false |

Will return the cents if set to true. Requires returnNote to be true.

new pitchAnalyser({
	returnNote: true, // Is required
	returnCents: true,
	...other options...
});

Methods/Properties

The methods and properties available for use. You will need to have access to the initializes analyser

Methods

  • resume
  • closeContext

Properties

  • audioContext

Methods

resume

An methods form the AudioContext. It is important to call this to start/resume the analyser, because on chrome it will not start automatically.

analyser.audioContext.resume();

closeContext

When you want fully stop the analyser (will remove the instance);

| Arguments | Type | Output | | --------- | -------- | ----------------------------------------------------------------------------- | | callback | function | If a callback is passed, it will be called when the audioContext has closed |

analyser.closeContext(callback);

Properties

audioContext

The native audioContext can be accessed here for if you are ambitious and need customization. Check the MDN docs or somewhere else for all the information about the usage of AudioContext

analyser.audioContext

License

This repo is under the MIT License