Coder Social home page Coder Social logo

aguai / libpyin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from xstreck1/libpyin

0.0 2.0 0.0 333 KB

Pitch / fundamental frequency detection library for C,C++,C#

License: GNU General Public License v3.0

CMake 0.23% QMake 0.72% C# 0.91% C 9.21% C++ 88.93%

libpyin's Introduction

LibPyin pitch detection library

LibPyin is a plug-in library for pitch (fundamental frequency) detection (see here https://en.wikipedia.org/wiki/Pitch_detection_algorithm). The library provides simple C and C++ interface for easy incorporability to projects in other languages.

The library depends on the Pyin algorithm by M. Mauch and S. Dixon. See https://code.soundsoftware.ac.uk/projects/pyin for details.

Compiling

A C++11 compliant compiler is needed, however there are no additional dependencies. The repository contains CMake and QMake files for easy compiling.

If do not want to use either for some reason, and are making a project from the code yourself, do set the LIBPYIN_BUILD_SHARED macro to make sure the symbols are correcly exported.

Use

When using from C++, include libpyincpp.h. When using from C, include libpyinc.h and link against LibPyin.

Can I use LibPyin Source in My Code?

Absolutelly, just copy-paste the source folder to your project and add it to the include path.

Examples

There is C, C++, and C# example present. Each example generates a short sine-wave of 440 hz and extracts the frequency from the wave. The usage is platform and language dependent.

For each example first compile the library.

C example on Unix

gcc main.c -L"." -lLibPyin -lm
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. // Add the current location to the path so the library is loaded
./a.out

C++ example on Unix

g++ main.cpp -L"." -lLibPyin -std=c++11
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. // Add the current location to the path so the library is loaded
./a.out

Unity example

  1. Download the Release of the complied .dll .
  2. Add LibPyin.dll and LoadLibrary.cs to your Assets.
  3. Call LoadLibrary.use(); from another script attached to a gameobject.

C# example on Windows

  1. Before building LibPyin, set on the /clr support on the VS Settings/General. (You may need to switch /EHs to /EHa at Code Generation).
  2. Build as Debug and Release
  3. Run Visual Studio Developer prompt.
  4. csc main.cs LoadLibrary.cs /unsafe /reference:Debug\LibPyin.dll /platform:x86
  5. main.exe

Cpp interface

Creates a PYIN object, for each track you should create one object
[in]sample_rate frequency of the track, e.g. 44100 samples per second
[in]block_size length of a block used for obtaining a pitch, the higher the slower, 2048 is recommended
[in]step_size length of a step between two mined pitches, the smaller the slower, 512 is recommended

PyinCpp(const int sample_rate, const int block_size = _DEFAULT_BLOCK_SIZE, const int step_size = _DEFAULT_STEP_SIZE);

The cut off is a number between [0-1] that says whether the pitch is still to be considered as correct based on the estimate probability (the pitch will be ignored if the probability is lower than the number)

void PyinCpp::setCutOff(const float cut_off);
float PyinCpp::getCutOff();

Reserves the internal vectors for the given number of expected samples

void PyinCpp::reserve(int sample_count);

Feed new data and obtain the pitches mined using the new data

std::vector<float> PyinCpp::feed(const std::vector<float> & new_samples);

Get all the mined pitches

const std::vector<float> & PyinCpp::getPitches() const;

Resets to the after-construction state

void PyinCpp::clear();

C interface

Initializes a PYIN object, must be called before using pyinc
[in]sample_rate frequency of the track, e.g. 44100 samples per second
[in]block_size length of a block used for obtaining a pitch, the higher the slower, 2048 is recommended
[in]step_size length of a step between two mined pitches, the smaller the slower, 512 is recommended

void pyinc_init(const int sample_rate, const int block_size, const int step_size);

The cut off is a number between [0-1] that says whether the pitch is still to be considered as correct based on the estimate probability (the pitch will be ignored if the probability is lower than the number)

void SHARED_EXPORT pyinc_set_cut_off(const float cut_off);
float SHARED_EXPORT pyinc_get_cut_off();

Reserves the internal vectors for the given number of expected samples

void pyinc_reserve(int sample_count);

Feed new data and obtain the pitches mined using the new data !THE RANGE IS VALID ONLY UNTIL THE NEXT CALL OF pyinc_feed OR pyinc_clear

struct pyinc_pitch_range pyinc_feed(const float * new_samples, int sample_count);

Get all the mined pitches

struct pyinc_pitch_range pyinc_get_pitches();

Resets to the after-construction state

void  pyinc_clear();

Licence

GNU GPLv3 with attribution. The authors of Pyin ask to kindly attribute their work via a citation:

@inproceedings{matthias2014a,
    author = {Matthias Mauch and Dixon, Simon},
    title = {pYIN: A Fundamental Frequency Estimator Using Probabilistic Threshold Distributions},
    booktitle = {Proceedings of the IEEE International Conference on Acoustics, Speech, and Signal Processing (ICASSP 2014)},
    note = {in press},
    year = {2014}
} 

libpyin's People

Contributors

xstreck1 avatar

Watchers

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