Giter Club home page Giter Club logo

audio-frequency-tempered's Introduction

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.

audio-frequency-tempered's People

Contributors

brunoimbrizi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

toseben konekowo

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.