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

goertzel-node

v2.1.0

Published

WebAudio Node that implements a goertzel filter

Downloads

8

Readme

goertzel-node

A WebAudio Node that implements the goertzel algorithm.

The Goertzel algorithm is a Digital Signal Processing (DSP) technique that provides a means for efficient evaluation of individual terms of the Discrete Fourier Transform (DFT),

-Wikipedia

This package implement a WebAudio node which detects if a specified frequency is present in the audio stream using the goertzel algorithm.

Features

  • Exposes a (settable) threshold based simple boolean detected.
  • Runs in real-time in WebAudio using a ScriptProcessorNode.
  • Efficient and performant.
  • Uses asm.js if available in the browser.
  • Passes through the audio stream for further processing and output.
  • Allows specification of which channel is to be analyzed.

ToDo

  • Move to upcoming AudioWorkletNode when available.

Internals

GoertzelNode uses the ScriptProcessorNode and performs the Goertzel algorithm on every chunk of data that comes through the ScriptProcessorNode. The calculations are performed on a chunk by chunk bases and the outputs (power, and detected) are updated on every chunk as well.

Usage

The package exposes a node.js style API, and is designed to be used tools such as browserify.

A standalone browserified file is also available here, which creates a global named GoertzelNode when included in the html.

npm install goertzel-node


var GoertzelNode = require('goertzel-node'); // only if using browserify.

var audioContext = new AudioContext();
var osc = audioContext.createOscillator();
var gn = new GoertzelNode(audioContext);

gn.targetFrequency = 440; // 440Hz

osc.connect(gn);
gn.connect(audioContext.destination);
osc.start(0);

var result = gn.detected; //boolean true/false

API

Constructor

  • GoertzelNode : Creates a new GoertzelNode.

    • eg :
    var gn = new GoertzelNode(audioContext);
    • arguments: - audioContext : AudioContext - The AudioContext within which the GoertzelNode is to be created.

Methods

Properties

  • targetFrequency: Number - The value of the frequency (in Hertz) that is to be detected by the GoertzelNode. It defaults to 440.

    eg:

    gn.targetFrequency = 440; // Set the frequency to be detected to be 440.
    • targetFrequency can be set at any time. Once set, the GoertzelNode will start calculating and outputting the values for that frequency at every chunk.
  • passthrough: Boolean - Boolean value defining if the Node passes the audio through to the destination or not. Default value is true.

    eg:

    osc.connect(gn);
    gn.connect(context.destination);
    gn.passthrough = false; // Ensures that audio from the oscillator doesn't get played out.
  • channel: Number - The channel of the input audio stream to be used for analysis. The default value is 1.

    eg:

    gn.channel = 1; // Set the channel of the input audio stream to be analyzed.
    • Since WebAudio streams can have multiple channels and the Goertzel algorithm run on individual channels, this property allows one to choose which channel to run the Goertzel algorithm on.
  • power: Number - Returns the power of the audio of the input audio stream at the targetFrequency. This value is normalised to chunkSize and should be a maximum of 0.25 for a perfect match.

    eg:

    var power = gn.power;  // Get the power.
    • This is the result of Goertzel algorithm. It can be used to decide if enough energy is detected at the targetFrequency.
  • threshold: Number - Sets a threshold of power used to decide if the targetFrequency was detected.

    eg:

    gn.threshold = 0.22;  // Set the threshold to 0.22.
    • If calculated power power is higher than threshold then detected is set as true.
  • detected: Boolean - Returns if the targetFrequency was detected in the input audio stream.

    eg:

    var detected = gn.detected; // If the frequency was detected in the input audio stream.

License

MIT

See License file