Skip to content

Commit 4004f83

Browse files
committed
Added part of the pitch detection algorithm
1 parent 41fbff7 commit 4004f83

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
all:
2-
gcc -ggdb pitchdetector.c -o pitchdetector `pkg-config --libs --cflags gtk+-3.0` -lsndfile --std=c99
2+
gcc -ggdb pitchdetector.c -o pitchdetector `pkg-config --libs --cflags gtk+-3.0` -lsndfile --std=gnu99

pitchdetector.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include<sndfile.h>
44
#include<stdio.h>
55
#include<limits.h>
6+
#include<math.h>
67

78
#define TO_FLOAT(x) ((double)(x)/(double)SHRT_MAX)
89

@@ -15,8 +16,24 @@ static GtkWidget *window_spin;
1516
static GtkWidget *drawing_area;
1617
static GtkAdjustment *scroll_adj;
1718

19+
static const float SCAN_DOMAIN_RATIO = 1.0f;
20+
static const int MIN_FREQ = 30;
21+
static const int MAX_FREQ = 2100;
22+
static const int MAX_FALLS = 20;
23+
static const int WINDOW_LENGTH = 500;
24+
static const double EXP_FALL_MULT = 2.0;
25+
//Constants
26+
static const double E_TO_15TH = 3269017.372472111;
27+
static const double LN_2 = 0.693147181;
28+
29+
double exp_fall_function(double val)
30+
{
31+
return EXP_FALL_MULT * pow(M_E, log(val)/LN_2) / E_TO_15TH;
32+
}
33+
34+
static short *snd_data;
35+
static float *p_pos;
1836

19-
short *snd_data;
2037
SF_INFO *file_info;
2138
void delete(GtkWidget *widget, gpointer data)
2239
{
@@ -37,7 +54,7 @@ draw_callback(GtkWidget *widget, cairo_t *cr, gpointer data)
3754
gdk_cairo_set_source_rgba (cr, &color);
3855

3956
int draw_offset = (int) gtk_adjustment_get_value(scroll_adj);
40-
int frames = gtk_spin_button_get_value_as_int(window_spin);
57+
int frames = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(window_spin));
4158
double x = 0.0;
4259
double x_step = (double) width / (double) frames;
4360

0 commit comments

Comments
 (0)