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

audio-frequency-tempered

v1.0.1

Published

Distributes audio frequency data according to a logarithmic scale.

Downloads

111

Readme

audio-frequency-tempered

Distributes the data returned from AnalyserNode.getByteFrequencyData() according to a logarithmic scale. Low frequency bins are shared by multiple bars, while high frequency ones are bundled together.

The technique comes from Henrique Vianna's audioMotion-analyzer.

Install

npm install audio-frequency-tempered

Example

const { createAudioBars, updateAudioBars } = require('audio-frequency-tempered');

// create audio context, analyser, data array
// omitted: source, gain, connect, etc.
const audioCtx = new AudioContext();
const analyser = audioCtx.createAnalyser();
const audioData = new Uint8Array(analyser.frequencyBinCount);

// create audio bars
const audioBars = createAudioBars({ groupLevel: 8 });

// on update
analyser.getByteFrequencyData(audioData);
updateAudioBars(audioData);

audioBars.forEach(bar => console.log(bar));

Output:

{ value: 0.6078, factor: 1, iniBin: 6, endBin: 9 }
{ value: 0.8196, factor: 1, iniBin: 10, endBin: 18 }
{ value: 0.8980, factor: 1, iniBin: 19, endBin: 37 }
{ value: 0.7254, factor: 1, iniBin: 38, endBin: 73 }
{ value: 0.5215, factor: 1, iniBin: 74, endBin: 146 }
{ value: 0.4352, factor: 1, iniBin: 147, endBin: 292 }
{ value: 0.4627, factor: 1, iniBin: 293, endBin: 584 }
{ value: 0.4313, factor: 1, iniBin: 585, endBin: 1167 }
{ value: 0.3411, factor: 1, iniBin: 1168, endBin: 2333 }
{ value: 0.0000, factor: 1, iniBin: 2334, endBin: 3110 }

Demo

demo

audio-frequency-tempered demo

Usage

createAudioBars(options)

  • options
    • groupLevel (default 5) 1 to 8, where 1 = 1/24 octave and 8 = full octave
    • sampleRate (default 44100) audioContext.sampleRate
    • frequencyBinCount (default 1024) analyser.frequencyBinCount
    • minFreq (default 20) minimum frequency (Hz)
    • maxFreq (default 22000) maximum frequency (Hz)

Returns an array of 'bar' objects { iniBin, endBin, factor, value }

  • iniBin - initial bin of the analyser frequency data
  • endBin - end bin of the analyser frequency data
  • factor - interpolation factor - when multiple bars share the same bin
  • value - normalised maximum energy value of the frequencies between iniBin and endBin

updateAudioBars(audioData)

  • audioData Uint8Array passed to analyser.getByteFrequencyData

Returns null

getAudioBars()

Returns the previously created array of audio bars.

getAudioEnergy()

Returns the average audio energy (sum of bar values / number of bars).

See Also

License

MIT, see LICENSE for details.