Code Monkey home page Code Monkey logo

pitch-detection's Introduction

Pitch detection algorithms

Autocorrelation-based C++ pitch detection algorithms with O(nlogn) running time:

Build and install

Using this project should be as easy as make && sudo make install on Linux with a modern GCC - I don't officially support other platforms.

This project depends on ffts. To run the tests, you need googletest, and run make -C test/ && ./test/test. To run the bench, you need google benchmark, and run make -C test/ bench && ./test/bench.

Usage

The code is lightly documented in the public header file. Compile your code with -lpitch_detection.

The namespaces are pitch and pitch_alloc.

The pitch namespace functions are for automatic buffer allocation:

#include <pitch_detection.h>

//std::vector<double> audio_buffer with sample rate e.g. 48000

double pitch_yin = pitch::yin(audio_buffer, 48000);
double pitch_mpm = pitch::mpm(audio_buffer, 48000);

Manual memory allocation

If you want to detect pitch for multiple audio buffers of a uniform size, you can do more manual memory control with the pitch_alloc namespace:

#include <pitch_detection.h>

//buffers have fixed length e.g. 48000, same as sample rate

pitch_alloc::Mpm ma(48000);
pitch_alloc::Yin ya(48000);

for (int i = 0; i < 10000; ++i) {
        //std::vector<double> audio_buffer size 48000 sample rate 48000

        auto pitch_yin = pitch_alloc::yin(audio_buffer, 48000, &ya);
        auto pitch_mpm = pitch_alloc::mpm(audio_buffer, 48000, &ma);
}

Advantages of manual memory allocation

The auto allocation strategy performs hundreds of thousands of allocations:

auto-alloc

Manual allocation, as expected, performs less allocations by several orders of magnitude:

manual-alloc

pitch-detection's People

Contributors

forgemistress avatar sevagh 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.