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

freelizer

v1.0.0

Published

Simple package on pure JavaScript with Audio Web API usage that was made for purpose of calculation sound frequency from microphone

Downloads

4

Readme

Freelizer

Simple package on pure JavaScript with Audio Web API usage that was made for purpose of calculating sound frequency from microphone.

Live example of usage

Some important information

Has been tested only in desktop and mobile Google Chrome version 87.0. Package doesn't include polyfills. Stable work in other browsers isn't guaranteed. Requires support of Web Audio API. Has 0 dependencies from other packages.

Data that library provides

  1. Frequency of sound from microphone.
  2. Nearest note letter that nearest to sound frequency.
  3. Frequency of nearest note.
  4. Octave number of nearest note.
  5. Deviation between frequency of sound from microphone and frequency of nearest note.

Usage example

import { freelizer } from 'freelizer'

;(async function () {
    try {
      const { start, subscribe } = await freelizer()
      start()
      subscribe(console.log)
    } catch (error) {
      // Error handling goes here
    }
})()

A little explanation for usage example

Import freelizer function

import { freelizer } from 'freelizer'

Call freelizer function. Beware, that freelizer is asynchronous. It returns an object that contains functions. Call of freelizer asks for permission of using microphone.

const { start, subscribe } = await freelizer()

Use start() function to launch process of sound listening.

start()

Use subscribe() function that takes callback-function as argument. Callback-function will get data object as parameter. Callback will be called on each animation frame.

subscribe(console.log)

Example of console output:

{
  frequency: 163.71831025615992,
  note: "E",
  noteFrequency: 164.81377845643485,
  octave: 3,
  deviation: -1.0954682002749223,
}

freelizer

Asynchronous function that call returns an object that contains functions for library mainpulation. These functions are:

  • start()
  • stop()
  • subscribe()
  • unsubscribe()

Calling example:

const { start, stop, subscribe, unsubscribe } = await freelizer()

Error handling

Since the function is asynchronous it recommended to use try/catch statement. The most frequent cause of errors is situation when user blocks microphone usage.

try {
  const { start, subscribe } = await freelizer()
} catch (error) {
  // Error handling goes here
}

start

Function that launch process of sound listening. During this process all functions-subscribers are called on each animation frame.

stop

The opposite of start function. It stops process of sound listening.

subscribe

Provides mechanism of subscription to sound listening stream. It takes callback-function as argument. Callback-function will get data object as parameter. Callback will be called on each animation frame.

Usage

const callbackExample = data => console.log(data)
subscribe(callbackExample)

Callback-function argument

Callback-function takes object that contains the following fileds:

  • frequency: Float Number
  • note: String
  • noteFrequency: Float Number
  • octave: Integer Number
  • deviation: Float Number
{
  frequency: 163.71831025615992,
  note: "E",
  noteFrequency: 164.81377845643485,
  octave: 3,
  deviation: -1.0954682002749223,
}

Its possible to subscribe as many functions as needed.

unsubscribe

Unsubscribes callback-function from listening of stream. Takes callback-function that previously was transmitted to subscribe function. Remember that it doesn't work with annonymous functions.

Usage

Example that logs data in console for 5 seconds:

const { start, stop, subscribe, unsubscribe } = await freelizer()
start()
const callbackExample = (data) => console.log(data)
subscribe(callbackExample)
setTimeout(() => unsubscribe(callbackExample), 5000)

Sources

ACF2+ algorithm

Original algorithm that returns frequency value from waveform was taken from "Simple pitch detection" repository.

Theory of music