Git Product home page Git Product logo

tuner's Introduction

@chordbook/tuner

A web-based library for pitch detection of stringed instruments. It uses the Web Audio API to capture audio from the microphone, and uses the pitchy to detect the predominant pitch.

๐ŸŽธ View Demo ๐Ÿช•

Features

  • โœ… Uses your devices microphone to detect the pitch of stringed instruments
  • โœ… Filters noise from low and high frequencies outside the range of stringed instruments
  • โœ… Does not try to detect when the volume is too low

Installation

npm install @chordbook/tuner

Usage

import { createTuner } from '@chordbook/tuner'

const tuner = createTuner({
  // The callback to call when a note is detected.
  onNote: note => {
    console.log('Note:', note)
  },

  // Here are some other settings you can fiddle with and their default values.
  // (let us know if you find values that work better).

  // The number of milliseconds between each pitch detection.
  updateInterval: 50,

  // The frequency of middle A. Defaults to 440Hz.
  a4: 440,

  // The minimum clarity threshold. Anything below this will be ignored
  clarityThreshold: 0.9,

  // The minimum volume threshold. -1000 means 1/1000th the volume of the loudest sound.
  minVolumeDecibels: -1000,

  // The minimum and maximum frequencies to detect. To reduce noise, everything else is
  // filtered out using a lowpass and highpass filter.
  minFrequency: 27.5, // A0, Lowest note on a piano
  maxFrequency: 4186.01, // C8, Highest note on a piano

  // The sample rate to use for the audio context.
  // https://developer.mozilla.org/en-US/docs/Web/API/BaseAudioContext/sampleRate
  sampleRate: 44100,

  // The size of buffer to use for frequency analysis, which maps to the `fftSize`:
  // https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/fftSize
  bufferSize: 8192,

  // https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/smoothingTimeConstant
  smoothingTimeConstant: 0.8
})

// Request access to the microphone and begin pitch detection
tuner.start()

// Stop listening
tuner.stop()

When a pitch is clearly detected, the onNote callback is called with an object containing the following properties:

{
  // The frequency of the detected note
  "frequency": 612.2498364209699,
  // The node name (e.g. "A", "C#")
  "name": "Dโ™ฏ",
  // The note number (0-89)
  "value": 75,
  // The number of cents the detected frequency is off from the nearest note
  "cents": -29,
  // The octave of the detected note
  "octave": 5,
  // The clarity of the detected note (0-1)
  "clarity": 0.9656978357299373
}

Contributing

Contributions are welcome!

  1. Clone this repository: git clone https://github.com/chordbook/tuner.git
  2. Install dependencies: npm install
  3. Start the development server: npm run dev
  4. Open http://localhost:5173/ in your browser

License

This project is licensed under the GPLv3.0 license.

tuner's People

Contributors

bkeepers avatar dependabot[bot] avatar

Stargazers

I could fran avatar  avatar

Watchers

 avatar

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.