int main(void) { FLOATING freq; InitGoertzel(); /* Demo 1 */ GenerateAndTest(TARGET_FREQUENCY - 250); GenerateAndTest(TARGET_FREQUENCY); GenerateAndTest(TARGET_FREQUENCY + 250); /* Demo 2 */ for (freq = TARGET_FREQUENCY - 300; freq <= TARGET_FREQUENCY + 300; freq += 15) { GenerateAndTest2(freq); } return 0; }
// returns -1 if no conclusive data could be produced, returns 0 - 15 depending on which tone is heard (row 1 of DTMF tones contains 0 - 3, etc.) static int determine(const SAMPLE *input) // the input[] should be of length MAX_N { int i; int max_Low_Power_Index; int max_High_Power_Index; int second_To_mLPI; int second_To_mHPI; setUpConstants(); for( i = 0; i < MAX_BINS; i++) { InitGoertzel(i); powers[i] = Test( i, input); } // Test to conclude winners for each half of frequencies max_Low_Power_Index= 0; max_High_Power_Index = MAX_BINS/2; second_To_mLPI = -1; second_To_mHPI = -1; for( i = 1; i < (MAX_BINS/2); i++) { if( powers[max_Low_Power_Index] <= powers[i]) { second_To_mLPI = max_Low_Power_Index; max_Low_Power_Index = i; } } for( i = (MAX_BINS/2 + 1); i < MAX_BINS; i++) { if( powers[max_High_Power_Index] <= powers[i]) { second_To_mHPI = max_High_Power_Index; max_High_Power_Index = i; } } if(powers[max_Low_Power_Index] < powers[second_To_mLPI] * THRESHOLD_COEFF_LOW || powers[max_High_Power_Index] < powers[second_To_mHPI] * THRESHOLD_COEFF_HIGH) { return -1; } else { return 4*max_Low_Power_Index + (max_High_Power_Index - 4); } }