Giter Club home page Giter Club logo

audiopitchr's Introduction

AudioPitchr

Example: https://akumpf.github.io/AudioPitchr/example/

** EXPERIMENTAL ** This code is volatile and prone to large changes.

AudioPitchr is a Web Audio based analysis toolset for determining the musical structure of any arbitrary audio source in realtime.

AudioPitchr example output with chords, root notes, intervals, and signal to noise db.

Usage

AudioPitchr can be installed as an NPM module.

npm install AudioPitchr

Then, in javascript you can use it like this.

const audioCtx          = new AudioContext(); // consider OfflineAudioContext?
const audioSampleRate   = audioCtx.sampleRate;

const pitchr            = require("AudioPitchr");
const frameHop          = 1024*4;
const chromagram        = pitchr.Chromagram(frameHop,audioSampleRate);
const chromachord       = pitchr.Chromachord;  

const disallowSusChords = false;

let buff        = new Float32Array(4096);
let scriptNode  = audioCtx.createScriptProcessor(frameHop, 1, 1);
scriptNode.onaudioprocess = function(audioProcessingEvent) {
  // Mono-ize the input data (alternative, could apply to left and right separately)...
  let inputBuffer = audioProcessingEvent.inputBuffer;
  let outputBuffer = audioProcessingEvent.outputBuffer;
  buff.fill(0,0,buff.length);
  let buffDiv = outputBuffer.numberOfChannels;
  for (let channel = 0; channel < outputBuffer.numberOfChannels; channel++) {
    let inputData = inputBuffer.getChannelData(channel);
    let outputData = outputBuffer.getChannelData(channel);
    for (let sample = 0; sample < inputBuffer.length; sample++) {
      outputData[sample] = inputData[sample];
      buff[sample] += inputData[sample]/buffDiv;
    }
  }
  // --
  chroma.processAudioFrame(buff);
  if(chroma.isReady()){
    let cgram     = chroma.getChromagram();
    let bestChord = chromachord.detectChord(cgram,disallowSusChords);
    console.log(chromachord.getTextDesc(bestChord));
  }

Building

The source should be sufficient for most Node projects, but to build the combined audiopitchr.js bundle file, use browserify:

browserify index.js -o audiopitchr.js

License

AudioPitchr is released as open source under the GNU GPLv3 license.

audiopitchr's People

Contributors

akumpf avatar

Stargazers

Yaroslav Bolyukin avatar

Watchers

 avatar James Cloos avatar  avatar  avatar

Forkers

iwillcodeu

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.