Ultrasonic Audio File Player
Dependencies: mbed
Fork of TAU_ZOOLOG_Chirp_Generator by
Diff: main_filter3.cpp
- Revision:
- 5:65833e8cf4cf
- Parent:
- 4:85dbf3e4d432
- Child:
- 6:f14547e1cc04
--- a/main_filter3.cpp Sun Jul 09 14:06:17 2017 +0000 +++ b/main_filter3.cpp Sun Jul 09 16:11:46 2017 +0000 @@ -90,6 +90,11 @@ // trigger_pass variables float triggThresholdValue=TRIGGER_THRESHOLD_VALUE; +// number of samples to count +float sample_length=SAMPLE_LENGTH*(SampleRate/1000.0f); // compansate number of cycles based on sample rate +float quiet_length=QUIET_LENGTH*(SampleRate/1000.0f); // compansate number of cycles based on sample rate +bool trigger_HPF=TRIGGER_HPF; + // high pass variables // high pass @@ -140,11 +145,11 @@ void print_parameters() { - printf("\n%s Digital Filter.\nSTART MAIN LOOP, use mode %d, loop #%d, number of sections: %d\n", + printf("\r\n%s Digital Filter.\r\nSTART MAIN LOOP, use mode %d, loop #%d, number of sections: %d\r\n", FilterType[UseFilterMode], UseFilterMode, LoopCount, (UseFilterMode == IIRLPNORM_FILTER_MODE) ? NumSections : NumSectionsHP); if (UseFilterMode == PREDEFINED_OUTPUT_MODE) { - printf("Signal threshould: %d\nSignal scale: %5.2f\nNumber of cycles to detect threshold crossing: %d\nDelay after signal in microseconds: %d\nUse filter: %s\n", + printf("Signal threshould: %d\r\nSignal scale: %5.2f\r\nNumber of cycles to detect threshold crossing: %d\r\nDelay after signal in microseconds: %d\r\nUse filter: %s\r\n", signal_low_threshold, scale_for_predefined_output, num_of_cycles_to_detect_threshold_crossing, delay_after_signal_transmission, use_filter_with_predefined_output ? "Y" : "N"); } @@ -204,7 +209,7 @@ switch (UseFilterMode) { case IIRLPNORM_FILTER_MODE: FilterFunction = iirlpnorm_filter; - printf("Running IIRLPNORM filter\n"); + printf("Running IIRLPNORM filter\r\n"); memset(CurrInput, 0, sizeof(CurrInput)); memset(LastInput, 0, sizeof(LastInput)); memset(LLastInput, 0, sizeof(LLastInput)); @@ -213,7 +218,7 @@ case HIGH_PASS_FILTER_MODE: FilterFunction = highpath_filter; - printf("Running High Path filter\n"); + printf("Running High Path filter\r\n"); memset(CurrInput, 0, sizeof(CurrInput)); memset(LastInput, 0, sizeof(LastInput)); memset(LLastInput, 0, sizeof(LLastInput)); @@ -222,7 +227,7 @@ case PREDEFINED_OUTPUT_MODE: FilterFunction = predefined_output; - printf("Running Predefined Output\n"); + printf("Running Predefined Output\r\n"); memset(CurrInput, 0, sizeof(CurrInput)); memset(LastInput, 0, sizeof(LastInput)); memset(LLastInput, 0, sizeof(LLastInput)); @@ -234,19 +239,19 @@ case NO_FILTER_MODE: FilterFunction = no_filter; - printf("Running No filter\n"); + printf("Running No filter\r\n"); break; // end of case NO_FILTER_MODE case TRIGGERED_OUTPUT_MODE: FilterFunction = triggered_pass; - printf("Running Triggered Mode\n"); + printf("Running Triggered Mode\r\n"); break; // end of case Triggered Mode case TEST_OUTPUT_MODE: FilterFunction = test_output; - printf("Running test output\n"); + printf("Running test output\r\n"); break; // end of case TEST_OUTPUT_MODE @@ -254,7 +259,7 @@ printf("Wrong User Filter Mode"); // Default - no filter FilterFunction = no_filter; - printf("No filter\n"); + printf("No filter\r\n"); break; } // end of switch (UserFilterMode) @@ -281,7 +286,7 @@ // User button pressed // Main loop working with ADC/DAC is stopped // Here should be functionality which should be done before start another loop with ADC/DAC - printf("\nKeyboard key or User button pressed! Exit from main loop.\n"); + printf("\nKeyboard key or User button pressed! Exit from main loop.\r\n"); // Init filter variables memset(CurrInput, 0, sizeof(CurrInput)); @@ -291,11 +296,12 @@ // Input new use mode isInputNotValid = 1; while (isInputNotValid) { - printf("Please, select use mode: \n"); - printf("%d - IIRLPNORM filter\n", IIRLPNORM_FILTER_MODE); - printf("%d - High Pass filter\n", HIGH_PASS_FILTER_MODE); - printf("%d - No filter\n", NO_FILTER_MODE); - printf("%d - Predefined Output\n", PREDEFINED_OUTPUT_MODE); + printf("Please, select use mode: \r\n"); + printf("%d - IIRLPNORM filter\r\n", IIRLPNORM_FILTER_MODE); + printf("%d - High Pass filter\r\n", HIGH_PASS_FILTER_MODE); + printf("%d - No filter\r\n", NO_FILTER_MODE); + printf("%d - Predefined Output\r\n", PREDEFINED_OUTPUT_MODE); + printf("%d - Triggered Mode \r\n", TRIGGERED_OUTPUT_MODE); printf("Input your choice or hit Enter to continue main loop in the same use mode: "); memset(command, 0, sizeof(command)); gets(command); @@ -312,7 +318,7 @@ gets(command); signal_low_threshold = atoi(command); if (signal_low_threshold == 0) { - printf("\nWrong input - default is taken\n"); + printf("\r\nWrong input - default is taken\r\n"); signal_low_threshold = SIGNAL_LOW_THRESHOD; } @@ -323,7 +329,7 @@ gets(command); scale_for_predefined_output = atof(command); if (scale_for_predefined_output == float(0.0)) { - printf("\nWrong input - default is taken\n"); + printf("\r\nWrong input - default is taken\r\n"); scale_for_predefined_output = SCALE_FOR_PREDEFINED_OUTPUT; } isSignalClipped = false; @@ -339,7 +345,7 @@ } } if (isSignalClipped) { - printf("With amplitude scale %5.2f, signal will be clipped !!!. Select smaller scale.\n",scale_for_predefined_output); + printf("With amplitude scale %5.2f, signal will be clipped !!!. Select smaller scale.\r\n",scale_for_predefined_output); } } // end of while (isSignalClipped) printf("Enter delay after signal in microseconds (default - %d): ", DELAY_AFTER_SIGNAL_TRANSMISSION); @@ -347,7 +353,7 @@ gets(command); delay_after_signal_transmission = atoi(command); if (delay_after_signal_transmission == 0) { - printf("\nWrong input - default is taken\n"); + printf("\r\nWrong input - default is taken\r\n"); delay_after_signal_transmission = DELAY_AFTER_SIGNAL_TRANSMISSION; } printf("Enter number of cycles to detect threshold crossing (default - %d): ", NUM_OF_CYCLES_TO_DETECT_THRESHOLD_CROSSING); @@ -355,7 +361,7 @@ gets(command); num_of_cycles_to_detect_threshold_crossing = atoi(command); if (num_of_cycles_to_detect_threshold_crossing == 0) { - printf("\nWrong input - default is taken\n"); + printf("\r\nWrong input - default is taken\r\n"); num_of_cycles_to_detect_threshold_crossing = NUM_OF_CYCLES_TO_DETECT_THRESHOLD_CROSSING; } printf("Use high pass filter with predefined output: Y/N (default - %s): ", @@ -374,25 +380,60 @@ delay_after_signal_transmission = USE_FILTER_WITH_PREDEFINED_OUTPUT; } memset(command, 0, sizeof(command)); + isInputNotValid = 0; + } else if (UseFilterMode == TEST_OUTPUT_MODE) { + isInputNotValid = 0; + } else if (UseFilterMode == TRIGGERED_OUTPUT_MODE) { + + // define threshold + printf("Enter signal trigger threshold (default - %f): ", TRIGGER_THRESHOLD_VALUE); + memset(command, 0, sizeof(command)); + gets(command); + triggThresholdValue = atof(command); + if (triggThresholdValue == 0) { + printf("\r\nWrong input - default is taken\r\n"); + triggThresholdValue = TRIGGER_THRESHOLD_VALUE; + } + printf("\r\nChosen - %f\r\n",triggThresholdValue); + + // define record time + printf("Enter record time (millis) (default - %f): ", SAMPLE_LENGTH); + memset(command, 0, sizeof(command)); + gets(command); + sample_length = atof(command)*(SampleRate/1000.0f); // compansation for number of samples + if (sample_length == 0) { + printf("\r\nWrong input - default is taken\r\n"); + sample_length = SAMPLE_LENGTH*(SampleRate/1000.0f); + } + printf("\r\n Signal samples - %f\r\n",sample_length); + + // define silence time + printf("Enter silence time (millis) (default - %f): ", QUIET_LENGTH); + memset(command, 0, sizeof(command)); + gets(command); + quiet_length = atof(command)*(SampleRate/1000.0f); // compansation for number of samples + if (quiet_length == 0) { + printf("\r\nWrong input - default is taken\r\n"); + quiet_length = QUIET_LENGTH*(SampleRate/1000.0f); + } + printf("\r\n silence samples - %f\r\n",quiet_length); + + // enable TRIGGER HPF + printf("Enter enable trigger HPF (default - %d): ", TRIGGER_HPF); + memset(command, 0, sizeof(command)); + gets(command); + trigger_HPF = (bool)atoi(command); + printf("\r\nChosen - %d\r\n",trigger_HPF); + + // finish parameter settings + isInputNotValid = 0; + } else { + printf("\r\nWrong input - try again\r\n"); } - isInputNotValid = 0; - } else if (UseFilterMode == TEST_OUTPUT_MODE) { - isInputNotValid = 0; - } else if (UseFilterMode == TRIGGERED_OUTPUT_MODE) { - printf("Enter signal trigger threshold (default - %d): ", TRIGGER_THRESHOLD_VALUE); - memset(command, 0, sizeof(command)); - gets(command); - triggThresholdValue = atof(command); - if (triggThresholdValue == 0) { - printf("\nWrong input - default is taken\n"); - triggThresholdValue = TRIGGER_THRESHOLD_VALUE; - } - } else { - printf("\nWrong input - try again\n"); } - } - LoopCount++; - print_parameters(); + LoopCount++; + print_parameters(); - } // end while(True) + } // end while(True) + } }