// file: $SPEECH_HOMEWORK/hw4/class/snr_ratio/v1.0/snr_set_0.cc // // system include files // #include // isip include files // #include "signal_noise_ratio.h" #include "signal_noise_ratio_constants.h" #include // method: set_param_cc // // arguments: // char_1* param: (input) parameter string // char_1* value: (input) value string // // return: a logical_1 indicating status // // This function sets a given parameter (param) to a value (value) // logical_1 Signal::set_param_cc (char_1* param_a, char_1* value_a) { Param_file pfile; // check for valid arguments // if (param_a == (char_1*)NULL) { error_handler_cc((char_1*)"set_param_cc", (char_1*)"invalid parameter pointer"); } if (value_a == (char_1*)NULL) { error_handler_cc((char_1*)"set_param_cc", (char_1*)"invalid value to set"); } // set number of channels // if (strcmp ((char*) param_a, (char*) SIGNAL_NUM_CHANNELS_NAME) == 0) { int_4 num_chans; if (pfile.convert_string_cc(num_chans, value_a) != ISIP_TRUE) { error_handler_cc((char_1*)"set_param_cc", (char_1*)"invalid number of channels in parameter file"); } else { set_num_chans_cc(num_chans); } } // set number of bytes // else if (strcmp ((char*) param_a, (char*) SIGNAL_NUM_BYTES_NAME) == 0) { int_4 num_bytes; if (pfile.convert_string_cc(num_bytes, value_a) != ISIP_TRUE) { error_handler_cc((char_1*)"set_param_cc", (char_1*)"invalid number of bytes in parameter file"); } else { set_num_bytes_cc(num_bytes); } } // set sample frequency // else if (strcmp ((char*) param_a, (char*) SIGNAL_SAMPLE_FREQUENCY_NAME) == 0) { float_4 sample_freq; if (pfile.convert_string_cc(sample_freq, value_a) != ISIP_TRUE) { error_handler_cc((char_1*)"set_param_cc", (char_1*)"invalid sample frequency in parameter file"); } else { set_sample_frequency_cc(sample_freq); } } // set signal threshold // else if (strcmp ((char*) param_a, (char*) SIGNAL_SIGNAL_THRESHOLD_NAME) == 0) { float_4 signal_threshold; if (pfile.convert_string_cc(signal_threshold, value_a) != ISIP_TRUE) { error_handler_cc((char_1*)"set_param_cc", (char_1*)"invalid signal threshold in parameter file"); } else { set_signal_threshold_cc(signal_threshold); } } // set noise threshold // else if (strcmp ((char*) param_a, (char*) SIGNAL_NOISE_THRESHOLD_NAME) == 0) { float_4 noise_threshold; if (pfile.convert_string_cc(noise_threshold, value_a) != ISIP_TRUE) { error_handler_cc((char_1*)"set_param_cc", (char_1*)"invalid noise threshold in parameter file"); } else { set_noise_threshold_cc(noise_threshold); } } // set frame duration // else if (strcmp ((char*) param_a, (char*) SIGNAL_FRAME_DURATION_NAME) == 0) { float_4 frame_duration; if (pfile.convert_string_cc(frame_duration, value_a) != ISIP_TRUE) { error_handler_cc((char_1*)"set_param_cc", (char_1*)"invalid frame duration in parameter file"); } else { set_frame_duration_cc(frame_duration); } } // set window duration // else if (strcmp ((char*) param_a, (char*) SIGNAL_WINDOW_DURATION_NAME) == 0) { float_4 window_duration; if (pfile.convert_string_cc(window_duration, value_a) != ISIP_TRUE) { error_handler_cc((char_1*)"set_param_cc", (char_1*)"invalid window duration in parameter file"); } else { set_window_duration_cc(window_duration); } } // set window method // else if (strcmp ((char*) param_a, (char*) SIGNAL_WINDOW_METHOD_NAME) == 0) { if (strcmp ((char*) value_a, (char*) SIGNAL_WINDOW_METHOD_HAMMING_NAME) == 0) { set_window_method_cc(SIGNAL_WINDOW_METHOD_HAMMING); } else if (strcmp ((char*) value_a, (char*) SIGNAL_WINDOW_METHOD_RECTANGULAR_NAME) == 0) { set_window_method_cc(SIGNAL_WINDOW_METHOD_RECTANGULAR); } else { error_handler_cc((char_1*)"set_param_cc", (char_1*)"invalid window method to set"); } } // set pre_emphasize flag // else if (strcmp ((char*) param_a, (char*) SIGNAL_PRE_EMPHASIZE_NAME) == 0) { if (strcmp((char*) value_a, (char*) SIGNAL_PRE_EMPHASIZE_ON_STRING) == 0) { set_pre_emphasize_cc(ISIP_TRUE); } else if (strcmp((char*) value_a, (char*) SIGNAL_PRE_EMPHASIZE_OFF_STRING) == 0) { set_pre_emphasize_cc(ISIP_FALSE); } else { error_handler_cc((char_1*)"set_param_cc", (char_1*)"invalid value for pre_emphasize flag"); } } // set pre_emphasize value // else if (strcmp ((char*) param_a, (char*) SIGNAL_PRE_EMPHASIZE_VALUE_NAME) == 0) { float_4 pre_emphasize; if (pfile.convert_string_cc(pre_emphasize, value_a) != ISIP_TRUE) { error_handler_cc((char_1*)"set_param_cc", (char_1*)"invalid pre_emphasize value in parameter file"); } else { set_pre_emphasize_value_cc(pre_emphasize); } } // set number of bins // else if (strcmp ((char*) param_a, (char*) SIGNAL_NUM_BINS_NAME) == 0) { int_4 num_bins; if (pfile.convert_string_cc(num_bins, value_a) != ISIP_TRUE) { error_handler_cc((char_1*)"set_param_cc", (char_1*)"invalid number of bins in parameter file"); } else { set_num_bins_cc(num_bins); } } // set debug level // else if (strcmp ((char*) param_a, (char*) SIGNAL_DEBUG_LEVEL) == 0) { int_4 debug_level; if (pfile.convert_string_cc(debug_level, value_a) != ISIP_TRUE) { error_handler_cc((char_1*)"set_param_cc", (char_1*)"invalid debug level to set"); } else { set_debug_cc(debug_level); } } // invalid setting argument // else { error_handler_cc((char_1*)"set_param_cc", (char_1*)"invalid parameter to set"); } // exit gracefully // return ISIP_TRUE; }