diff options
Diffstat (limited to 'apps/plugins')
-rw-r--r-- | apps/plugins/pitch_detector.c | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/apps/plugins/pitch_detector.c b/apps/plugins/pitch_detector.c index 188bab6016..5f375d1007 100644 --- a/apps/plugins/pitch_detector.c +++ b/apps/plugins/pitch_detector.c | |||
@@ -118,7 +118,7 @@ typedef struct _fixed fixed; | |||
118 | #define fp_data(x) ((x).a) | 118 | #define fp_data(x) ((x).a) |
119 | #define fp_frac(x) (fp_sub((x), int2fixed(fixed2int(x)))) | 119 | #define fp_frac(x) (fp_sub((x), int2fixed(fixed2int(x)))) |
120 | #define FP_ZERO ((fixed){0}) | 120 | #define FP_ZERO ((fixed){0}) |
121 | #define FP_LOW ((fixed){1}) | 121 | #define FP_LOW ((fixed){2}) |
122 | 122 | ||
123 | /* Some defines for converting between period and frequency */ | 123 | /* Some defines for converting between period and frequency */ |
124 | 124 | ||
@@ -719,8 +719,8 @@ void draw_bar(fixed wrong_by_cents) | |||
719 | } | 719 | } |
720 | 720 | ||
721 | /* Calculate how wrong the note is and draw the GUI */ | 721 | /* Calculate how wrong the note is and draw the GUI */ |
722 | void display_frequency (fixed freq) | 722 | void display_frequency (fixed freq) |
723 | { | 723 | { |
724 | fixed ldf, mldf; | 724 | fixed ldf, mldf; |
725 | fixed lfreq, nfreq; | 725 | fixed lfreq, nfreq; |
726 | fixed orig_freq; | 726 | fixed orig_freq; |
@@ -729,7 +729,7 @@ void display_frequency (fixed freq) | |||
729 | 729 | ||
730 | if (fp_lt(freq, FP_LOW)) | 730 | if (fp_lt(freq, FP_LOW)) |
731 | freq = FP_LOW; | 731 | freq = FP_LOW; |
732 | 732 | ||
733 | /* We calculate the frequency and its log as if */ | 733 | /* We calculate the frequency and its log as if */ |
734 | /* the reference frequency of A were 440 Hz. */ | 734 | /* the reference frequency of A were 440 Hz. */ |
735 | orig_freq = freq; | 735 | orig_freq = freq; |
@@ -741,15 +741,15 @@ void display_frequency (fixed freq) | |||
741 | /* i.e. into the right octave. */ | 741 | /* i.e. into the right octave. */ |
742 | while (fp_lt(lfreq, fp_sub(notes[0].logfreq, fp_shr(LOG_D_NOTE, 1)))) | 742 | while (fp_lt(lfreq, fp_sub(notes[0].logfreq, fp_shr(LOG_D_NOTE, 1)))) |
743 | lfreq = fp_add(lfreq, LOG_2); | 743 | lfreq = fp_add(lfreq, LOG_2); |
744 | while (fp_gte(lfreq, fp_sub(fp_add(notes[0].logfreq, LOG_2), | 744 | while (fp_gte(lfreq, fp_sub(fp_add(notes[0].logfreq, LOG_2), |
745 | fp_shr(LOG_D_NOTE, 1)))) | 745 | fp_shr(LOG_D_NOTE, 1)))) |
746 | lfreq = fp_sub(lfreq, LOG_2); | 746 | lfreq = fp_sub(lfreq, LOG_2); |
747 | mldf = LOG_D_NOTE; | 747 | mldf = LOG_D_NOTE; |
748 | for (i=0; i<12; i++) | 748 | for (i=0; i<12; i++) |
749 | { | 749 | { |
750 | ldf = fp_gt(fp_sub(lfreq,notes[i].logfreq), FP_ZERO) ? | 750 | ldf = fp_gt(fp_sub(lfreq,notes[i].logfreq), FP_ZERO) ? |
751 | fp_sub(lfreq,notes[i].logfreq) : fp_neg(fp_sub(lfreq,notes[i].logfreq)); | 751 | fp_sub(lfreq,notes[i].logfreq) : fp_neg(fp_sub(lfreq,notes[i].logfreq)); |
752 | if (fp_lt(ldf, mldf)) | 752 | if (fp_lt(ldf, mldf)) |
753 | { | 753 | { |
754 | mldf = ldf; | 754 | mldf = ldf; |
755 | note = i; | 755 | note = i; |
@@ -758,11 +758,10 @@ void display_frequency (fixed freq) | |||
758 | nfreq = notes[note].freq; | 758 | nfreq = notes[note].freq; |
759 | while (fp_gt(fp_div(nfreq, freq), D_NOTE_SQRT)) | 759 | while (fp_gt(fp_div(nfreq, freq), D_NOTE_SQRT)) |
760 | nfreq = fp_shr(nfreq, 1); | 760 | nfreq = fp_shr(nfreq, 1); |
761 | |||
761 | while (fp_gt(fp_div(freq, nfreq), D_NOTE_SQRT)) | 762 | while (fp_gt(fp_div(freq, nfreq), D_NOTE_SQRT)) |
762 | { | ||
763 | nfreq = fp_shl(nfreq, 1); | 763 | nfreq = fp_shl(nfreq, 1); |
764 | } | 764 | |
765 | |||
766 | ldf = fp_mul(int2fixed(1200), log(fp_div(freq,nfreq))); | 765 | ldf = fp_mul(int2fixed(1200), log(fp_div(freq,nfreq))); |
767 | 766 | ||
768 | rb->lcd_clear_display(); | 767 | rb->lcd_clear_display(); |
@@ -772,7 +771,7 @@ void display_frequency (fixed freq) | |||
772 | draw_note(notes[note].name); | 771 | draw_note(notes[note].name); |
773 | if(tuner_settings.display_hz) | 772 | if(tuner_settings.display_hz) |
774 | { | 773 | { |
775 | rb->snprintf(str_buf,30, "%s : %d cents (%d.%02dHz)", | 774 | rb->snprintf(str_buf,30, "%s : %d cents (%d.%02dHz)", |
776 | notes[note].name, fp_round(ldf) ,fixed2int(orig_freq), | 775 | notes[note].name, fp_round(ldf) ,fixed2int(orig_freq), |
777 | fp_round(fp_mul(fp_frac(orig_freq), | 776 | fp_round(fp_mul(fp_frac(orig_freq), |
778 | int2fixed(DISPLAY_HZ_PRECISION)))); | 777 | int2fixed(DISPLAY_HZ_PRECISION)))); |