@ddlab/tuner

0.1.0 • Public • Published

@ddlab/tuner

A guitar tuner in a browser from @ddlab

For detailed explanation how it works see "The Tuning Algorithm" section.

To embed it in your javascript project read the following section.

Package Usage

npm i @ddlab/tuner;

Initialize a tuner widget:

import {initTuner} from '@ddlab/tuner';
initTuner(document.body);

Other Examples

Analyzing static data:

import {getTuningInfo} from '@ddlab/tuner';

const deltaFreq = sampleRate / fftSize;
const {noteStr, cents, isInTune} = getTuningInfo(freqData, deltaFreq);

Continuously analyzing mic stream

import {getTuningInfo, initAudio} from '@ddlab/tuner';

const {getFreqData, deltaFreq} = await initAudio(); // this must go after some user event
const loop = () => {
    const {noteStr, cents, isInTune} = getTuningInfo(getFreqData(), deltaFreq);
    // ...
    requestAnimationFrame(loop);
};

Warning: initialization (initAudio) has to occur after some user event due to browsers' autoplay policies. For example: addEventListener('keypress', () => initTuner(document.body));

The Tuning Algorithm

To find out how many cents a played note is out-of-tune, the following steps has to be made:

  1. Get a frequency spectrum
  2. Find fundamental peak freq. (in 50-400Hz range) in a spectrum
  3. Find harmonic peaks frequencies in a spectrum
  4. Calculate the harmonic average distance to nearest in-tune note
  5. Convert the diff to cents and represent it

References

License

GNU GENERAL PUBLIC LICENSE


© Dominykas Dukštas (@ddlab) 2019

Package Sidebar

Install

npm i @ddlab/tuner

Weekly Downloads

2

Version

0.1.0

License

GNU GENERAL PUBLIC LICENSE

Unpacked Size

662 kB

Total Files

35

Last publish

Collaborators

  • dukstas