Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented variable sampling rate #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Test_Yin.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ int main(int argc, char** argv) {

while (pitch < 10 ) {
Yin_init(&yin, buffer_length, 0.05);
pitch = Yin_getPitch(&yin, audio);
pitch = Yin_getPitch(&yin, audio, 44100);
buffer_length++;
}

Expand Down
11 changes: 6 additions & 5 deletions Yin.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,12 @@ void Yin_init(Yin *yin, int16_t bufferSize, float threshold){

/**
* Runs the Yin pitch detection algortihm
* @param yin Initialised Yin object
* @param buffer Buffer of samples to analyse
* @return Fundamental frequency of the signal in Hz. Returns -1 if pitch can't be found
* @param yin Initialised Yin object
* @param buffer Buffer of samples to analyse
* @param sampling_Rate Sampling rate of buffer
* @return Fundamental frequency of the signal in Hz. Returns -1 if pitch can't be found
*/
float Yin_getPitch(Yin *yin, int16_t* buffer){
float Yin_getPitch(Yin *yin, int16_t* buffer, int sampling_rate){
int16_t tauEstimate = -1;
float pitchInHertz = -1;

Expand All @@ -203,7 +204,7 @@ float Yin_getPitch(Yin *yin, int16_t* buffer){

/* Step 5: Interpolate the shift value (tau) to improve the pitch estimate. */
if(tauEstimate != -1){
pitchInHertz = YIN_SAMPLING_RATE / Yin_parabolicInterpolation(yin, tauEstimate);
pitchInHertz = sampling_rate / Yin_parabolicInterpolation(yin, tauEstimate);
}

return pitchInHertz;
Expand Down
12 changes: 5 additions & 7 deletions Yin.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@

#include <stdint.h>

#define YIN_SAMPLING_RATE 44100
#define YIN_DEFAULT_THRESHOLD 0.15

/**
* @struct Yin
* @breif Object to encapsulate the parameters for the Yin pitch detection algorithm
Expand All @@ -28,11 +25,12 @@ void Yin_init(Yin *yin, int16_t bufferSize, float threshold);

/**
* Runs the Yin pitch detection algortihm
* @param yin Initialised Yin object
* @param buffer Buffer of samples to analyse
* @return Fundamental frequency of the signal in Hz. Returns -1 if pitch can't be found
* @param yin Initialised Yin object
* @param buffer Buffer of samples to analyse
* @param sampling_Rate Sampling rate of buffer
* @return Fundamental frequency of the signal in Hz. Returns -1 if pitch can't be found
*/
float Yin_getPitch(Yin *yin, int16_t* buffer);
float Yin_getPitch(Yin *yin, int16_t* buffer, int sampling_rate);

/**
* Certainty of the pitch found
Expand Down