Index: apps/plugins/pitch_detector.c =================================================================== --- apps/plugins/pitch_detector.c (revision 22691) +++ apps/plugins/pitch_detector.c (working copy) @@ -178,6 +178,38 @@ float2fixed(0.50), }; +#define DEFAULT_REFERENCE 5 /* 440 */ +/* log of Frequency of A normalised to 440Hz */ +const fixed lfreq_A_table [] = +{ + float2fixed (-0.016488123), /*435 Hz */ + float2fixed (-0.013175389), + float2fixed (-0.009870244), + float2fixed (-0.006572654), + float2fixed (-0.003282584), + float2fixed (0), /* 440 Hz reference standard A */ + float2fixed (0.003275132), + float2fixed (0.006542846), + float2fixed (0.009803175), + float2fixed (0.013056153), + float2fixed (0.016301812), /* 445 Hz */ +}; +/* Frequency of A normalised to 440Hz */ +const fixed freq_A [] = +{ + float2fixed (0.988636364), + float2fixed (0.990909091), + float2fixed (0.993181818), + float2fixed (0.995454545), + float2fixed (0.997727273), + float2fixed (1), + float2fixed (1.002272727), + float2fixed (1.004545455), + float2fixed (1.006818182), + float2fixed (1.009090909), + float2fixed (1.011363636), +}; + /* How loud the audio has to be to start displaying pitch */ /* Must be between 0 and 100 */ #define VOLUME_THRESHOLD (50) @@ -279,6 +311,7 @@ unsigned sample_size; unsigned lowest_freq; unsigned yin_threshold; + unsigned freq_A; bool use_sharps; bool display_hz; } tuner_settings; @@ -325,6 +358,7 @@ settings->sample_size = BUFFER_SIZE; settings->lowest_freq = period2freq(BUFFER_SIZE / 4); settings->yin_threshold = DEFAULT_YIN_THRESHOLD; + settings->freq_A = DEFAULT_REFERENCE; settings->use_sharps = true; settings->display_hz = false; } @@ -426,6 +460,23 @@ { "0.50", -1 }, }; +/* These are the display frequency options for note A */ + +static const struct opt_items freq_A_text[] = +{ + { "435", -1 }, + { "436", -1 }, + { "437", -1 }, + { "438", -1 }, + { "439", -1 }, + { "440", -1 }, + { "441", -1 }, + { "442", -1 }, + { "443", -1 }, + { "444", -1 }, + { "445", -1 }, +}; + static const struct opt_items accidental_text[] = { { "Flat", -1 }, @@ -469,6 +520,7 @@ "Accidentals", "Display Frequency (Hz)", "Reset Settings", + "Frequency of A(Hz)", "Quit"); while(!done) @@ -518,7 +570,18 @@ &reset, BOOL, noyes_text, 2, tuner_settings_reset_query); break; - case 8: + case 8: + rb->set_option( + "Frequency of A(Hz)", + &tuner_settings.freq_A, + INT, freq_A_text, + sizeof(freq_A_text) / + sizeof(freq_A_text[0]), + NULL); + break; + + + case 9: exit_tuner = true; case 0: default: @@ -708,25 +771,28 @@ if (fp_lt(freq, FP_LOW)) freq = FP_LOW; lfreq = log(freq); - - /* Get the frequency to within the range of our reference table */ - while (fp_lt(lfreq, fp_sub(lfreqs[0], fp_shr(LOG_D_NOTE, 1)))) + fixed lfreq_A_offset; + /* This calculates a log freq offset for note A */ + lfreq_A_offset=lfreq_A_table[tuner_settings.freq_A]; + /* Get the frequency to within the range of our freq_A table */ + while (fp_lt(lfreq, fp_sub(fp_add(lfreqs[0],lfreq_A_offset), fp_shr(LOG_D_NOTE, 1)))) lfreq = fp_add(lfreq, LOG_2); - while (fp_gte(lfreq, fp_sub(fp_add(lfreqs[0], LOG_2), + while (fp_gte(lfreq, fp_sub(fp_add(fp_add(lfreqs[0],lfreq_A_offset), LOG_2), fp_shr(LOG_D_NOTE, 1)))) lfreq = fp_sub(lfreq, LOG_2); mldf = LOG_D_NOTE; for (i=0; i<12; i++) { - ldf = fp_gt(fp_sub(lfreq,lfreqs[i]), FP_ZERO) ? - fp_sub(lfreq,lfreqs[i]) : fp_neg(fp_sub(lfreq,lfreqs[i])); + ldf = fp_gt(fp_sub(lfreq,fp_add(lfreqs[i],lfreq_A_offset)), FP_ZERO) ? + fp_sub(lfreq,fp_add(lfreqs[i],lfreq_A_offset)) : fp_neg(fp_sub(lfreq,fp_add(lfreqs[i],lfreq_A_offset))); if (fp_lt(ldf, mldf)) { mldf = ldf; note = i; } } - nfreq = freqs[note]; + /* this scales the calulated note by the freq offset for note A */ + nfreq = (fp_mul(freqs[note],freq_A[tuner_settings.freq_A])); while (fp_gt(fp_div(nfreq, freq), D_NOTE_SQRT)) nfreq = fp_shr(nfreq, 1); while (fp_gt(fp_div(freq, nfreq), D_NOTE_SQRT))