Index: apps/plugins/pitch_detector.c =================================================================== --- apps/plugins/pitch_detector.c (revision 22691) +++ apps/plugins/pitch_detector.c (working copy) @@ -178,6 +178,37 @@ float2fixed(0.50), }; +#define DEFAULT_REFERENCE 5 /* 440 */ +const fixed reference_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 */ +}; + +const fixed ref [] = +{ + 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 +310,7 @@ unsigned sample_size; unsigned lowest_freq; unsigned yin_threshold; + unsigned reference; bool use_sharps; bool display_hz; } tuner_settings; @@ -325,6 +357,7 @@ settings->sample_size = BUFFER_SIZE; settings->lowest_freq = period2freq(BUFFER_SIZE / 4); settings->yin_threshold = DEFAULT_YIN_THRESHOLD; + settings->reference = DEFAULT_REFERENCE; settings->use_sharps = true; settings->display_hz = false; } @@ -426,6 +459,21 @@ { "0.50", -1 }, }; +static const struct opt_items reference_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 +517,7 @@ "Accidentals", "Display Frequency (Hz)", "Reset Settings", + "Reference Frequency (Hz)", "Quit"); while(!done) @@ -518,7 +567,18 @@ &reset, BOOL, noyes_text, 2, tuner_settings_reset_query); break; - case 8: + case 8: + rb->set_option( + "Reference Frequency (Hz)", + &tuner_settings.reference, + INT, reference_text, + sizeof(reference_text) / + sizeof(reference_text[0]), + NULL); + break; + + + case 9: exit_tuner = true; case 0: default: @@ -708,25 +768,26 @@ if (fp_lt(freq, FP_LOW)) freq = FP_LOW; lfreq = log(freq); - + fixed xx; + xx=reference_table[tuner_settings.reference]; /* 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)))) + while (fp_lt(lfreq, fp_sub(fp_add(lfreqs[0],xx), 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],xx), 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],xx)), FP_ZERO) ? + fp_sub(lfreq,fp_add(lfreqs[i],xx)) : fp_neg(fp_sub(lfreq,fp_add(lfreqs[i],xx))); if (fp_lt(ldf, mldf)) { mldf = ldf; note = i; } } - nfreq = freqs[note]; + nfreq = (fp_mul(freqs[note],ref[tuner_settings.reference])); 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))