11#include <stdlib.h>
22#include <math.h>
33#include <string.h>
4- #include "autotune .h"
4+ #include "pitchcorrect .h"
55#include "Yin.h"
66#include "circular_buffer.h"
77
1111float min_freq = 20.0 ;
1212float max_freq = 3000.0 ;
1313
14- int autotune_create ( autotune * * p ) {
15- * p = malloc (sizeof (autotune ));
14+ int pitchcorrect_create ( pitchcorrect * * p ) {
15+ * p = malloc (sizeof (pitchcorrect ));
1616 return SP_OK ;
1717}
1818
19- int autotune_init (sp_data * sp , autotune * p ) {
19+ int pitchcorrect_init (sp_data * sp , pitchcorrect * p ) {
2020 pitchshift2_create (& p -> pshift2 );
2121 pitchshift2_init (sp , p -> pshift2 , min_freq , max_freq );
2222 pitchcalculate_create (& p -> pcalc );
@@ -46,19 +46,19 @@ int autotune_init(sp_data *sp, autotune *p) {
4646 return SP_OK ;
4747}
4848
49- float nearest_scale_freq_index (autotune * p , float freq ) {
49+ float nearest_scale_freq_index (pitchcorrect * p , float freq ) {
5050 if (freq < 0 ) {
5151 return 0.0 ;
5252 }
5353
5454 float nearest_difference = 10000.0 ;
5555 float nearest = 10.0 ;
5656 float nearest_index = -1 ;
57- for (int i = 0 ; i < p -> autotune_scale_freqs_count ; i ++ ) {
58- float diff = fabs (p -> autotune_scale_freqs [i ] - freq );
57+ for (int i = 0 ; i < p -> pitchcorrect_scale_freqs_count ; i ++ ) {
58+ float diff = fabs (p -> pitchcorrect_scale_freqs [i ] - freq );
5959 if (diff < nearest_difference ) {
6060 nearest_difference = diff ;
61- nearest = p -> autotune_scale_freqs [i ];
61+ nearest = p -> pitchcorrect_scale_freqs [i ];
6262 nearest_index = (float )i ;
6363 } else if (diff > nearest_difference ) {
6464 break ;
@@ -78,7 +78,7 @@ float semitone_ratio(float scale_freq, float detected_freq) {
7878 return 1.0 ;
7979}
8080
81- int yin_add_to_buff (sp_data * sp , autotune * p , float * in ) {
81+ int yin_add_to_buff (sp_data * sp , pitchcorrect * p , float * in ) {
8282 float lpf_out ;
8383 sp_butlp_compute (sp , p -> lpf , in , & lpf_out );
8484
@@ -93,7 +93,7 @@ int yin_add_to_buff(sp_data *sp, autotune *p, float *in) {
9393 return SP_OK ;
9494}
9595
96- int compute_yin_pitch (sp_data * sp , autotune * p ) {
96+ int compute_yin_pitch (sp_data * sp , pitchcorrect * p ) {
9797 if (p -> buff -> count >= p -> yin -> bufferSize ) {
9898 cb_pop_multiple (p -> buff , p -> intBuffer , p -> yin -> bufferSize , 16 );
9999 float freq = Yin_getPitch (p -> yin , p -> intBuffer );
@@ -111,7 +111,7 @@ int compute_yin_pitch(sp_data *sp, autotune *p) {
111111 return SP_OK ;
112112}
113113
114- int compute_nearest_scale_freq_index (sp_data * sp , autotune * p ) {
114+ int compute_nearest_scale_freq_index (sp_data * sp , pitchcorrect * p ) {
115115 p -> scale_freq_index_acc ++ ;
116116
117117 float freq = p -> detected_freq ;
@@ -130,8 +130,8 @@ int compute_nearest_scale_freq_index(sp_data *sp, autotune *p) {
130130 }
131131
132132 int integerScaleIndex = (int )roundf (p -> nearest_scale_freq_index );
133- if (integerScaleIndex >= 0 && integerScaleIndex < p -> autotune_scale_freqs_count ) {
134- p -> target_freq = p -> autotune_scale_freqs [integerScaleIndex ];
133+ if (integerScaleIndex >= 0 && integerScaleIndex < p -> pitchcorrect_scale_freqs_count ) {
134+ p -> target_freq = p -> pitchcorrect_scale_freqs [integerScaleIndex ];
135135 }
136136 }
137137
@@ -153,10 +153,10 @@ int compute_nearest_scale_freq_index(sp_data *sp, autotune *p) {
153153 return SP_OK ;
154154}
155155
156- int autotune_compute (sp_data * sp , autotune * p , float * in , float * out , float rms ) {
156+ int pitchcorrect_compute (sp_data * sp , pitchcorrect * p , float * in , float * out , float rms ) {
157157 if (p -> should_update_scale_freqs ) {
158- p -> autotune_scale_freqs = p -> tmp_scale_freqs ;
159- p -> autotune_scale_freqs_count = p -> tmp_scale_freqs_count ;
158+ p -> pitchcorrect_scale_freqs = p -> tmp_scale_freqs ;
159+ p -> pitchcorrect_scale_freqs_count = p -> tmp_scale_freqs_count ;
160160 p -> should_update_scale_freqs = false;
161161 p -> scale_freq_index_acc = 128 ;
162162 p -> should_smooth_scale_idx = false;
@@ -224,7 +224,7 @@ int autotune_compute(sp_data *sp, autotune *p, float *in, float *out, float rms)
224224 return SP_OK ;
225225}
226226
227- int autotune_set_scale_freqs ( autotune * p , float * frequencies , int count ) {
227+ int pitchcorrect_set_scale_freqs ( pitchcorrect * p , float * frequencies , int count ) {
228228 float * new_freqs = malloc (sizeof (float ) * count );
229229 memcpy (new_freqs , frequencies , sizeof (float ) * count );
230230 p -> tmp_scale_freqs = new_freqs ;
@@ -233,12 +233,12 @@ int autotune_set_scale_freqs(autotune *p, float *frequencies, int count) {
233233 return SP_OK ;
234234}
235235
236- int autotune_set_amount ( autotune * p , float amount ) {
236+ int pitchcorrect_set_amount ( pitchcorrect * p , float amount ) {
237237 p -> amount = amount ;
238238 return SP_OK ;
239239}
240240
241- int autotune_set_speed ( autotune * p , float speed ) {
241+ int pitchcorrect_set_speed ( pitchcorrect * p , float speed ) {
242242 p -> speed = speed ;
243243 p -> scale_freq_port -> htime = -0.05 * speed + 0.05 ;
244244 return SP_OK ;
0 commit comments