// file: $isip_ifc/class/sp/SignalDetector/sigd_00.cc
// version: $Id: sigd_00.cc 10210 2005-08-12 20:24:51Z stanley $
//

// isip include files
//
#include <SignalDetector.h>

// method: constructor
//
// arguments: none
//
// return: none
//
// this is the default constructor for the signal_detector_01 class
//
SignalDetector::SignalDetector() {
  
  // set default algorithm
  //
  algorithm_d = DEF_ALGORITHM;
  implementation_d = DEF_IMPLEMENTATION;
  
  // data format parameters
  //
  num_channels_d = DEF_NUM_CHANNELS;
  sample_num_bytes_d = DEF_SAMPLE_NUM_BYTES;
  channel_to_be_processed_d = DEF_CHANNEL_TO_BE_PROCESSED;
  
  // signal processing parameters
  //
  sample_frequency_d = DEF_SAMPLE_FREQUENCY;
  frame_duration_d = DEF_FRAME_DURATION;
  window_duration_d = DEF_WINDOW_DURATION;
  preemphasis_d = DEF_PREEMPHASIS;
  
  // variable related to the output signal
  //
  pad_time_d = DEF_PAD_TIME;
  
  // signal level-related energy parameters
  //
  signal_nominal_level_d = DEF_SIGNAL_NOMINAL_LEVEL;
  signal_adaptation_delta_d = DEF_SIGNAL_ADAPTATION_DELTA;
  signal_adaptation_constant_d = DEF_SIGNAL_ADAPTATION_CONSTANT;
  
  // noise level-related energy parameters
  //
  noise_nominal_level_d = DEF_NOISE_NOMINAL_LEVEL;
  noise_adaptation_delta_d = DEF_NOISE_ADAPTATION_DELTA;
  noise_adaptation_constant_d = DEF_NOISE_ADAPTATION_CONSTANT;
  noise_floor_d = DEF_NOISE_FLOOR;
  
  // utterance parameters
  //
  utterance_delta_d = DEF_UTTERANCE_DELTA;
  utterance_minimum_duration_d = DEF_UTTERANCE_MINIMUM_DURATION;
  utterance_minimum_separation_d = DEF_UTTERANCE_MINIMUM_SEPARATION;
  utterance_maximum_duration_d = DEF_UTTERANCE_MAXIMUM_DURATION;
  
  // initialize adaptation constants
  //
  noise_threshold_d = noise_floor_d;
  signal_threshold_d = noise_floor_d;
  
  
  // exit gracefully
  //
}

// method: destructor
//
// arguments: none
//
// return: none
//
// this is the default destructor for the signal_detector_01 class
//

SignalDetector::~SignalDetector() {
  
}


// method: clear
//
// arguments:
//  Integral::CMODE ctype: (input) clear mode
//
// return: a boolean value indicating status
//
// this method resets the data members to the default values
//
boolean SignalDetector::clear(Integral::CMODE ctype_a) {
  
  
  // clear all the buffers
  //
  states_d.clear(ctype_a);
  durations_d.clear(ctype_a);
  egy_d.clear(ctype_a);
  zc_d.clear(ctype_a);
  cbuf_d.clear(ctype_a);
  start_points_d.clear(ctype_a);
  stop_points_d.clear(ctype_a);
  
  // set the default values
  //
  
  // variables relating to signal processing
  //
  num_channels_d = DEF_NUM_CHANNELS;
  sample_frequency_d = DEF_SAMPLE_FREQUENCY;
  sample_num_bytes_d = DEF_SAMPLE_NUM_BYTES;
  channel_to_be_processed_d = DEF_CHANNEL_TO_BE_PROCESSED;
  frame_duration_d = DEF_FRAME_DURATION;
  window_duration_d = DEF_WINDOW_DURATION;
  
  // variables relating to preprocessing of the audio data
  //
  preemphasis_d = DEF_PREEMPHASIS;
  
  // variable related to the output signal
  //
  pad_time_d = DEF_PAD_TIME;
  
  // signal level-related energy parameters
  //
  signal_nominal_level_d = DEF_SIGNAL_NOMINAL_LEVEL;
  signal_adaptation_delta_d = DEF_SIGNAL_ADAPTATION_DELTA;
  signal_adaptation_constant_d = DEF_SIGNAL_ADAPTATION_CONSTANT;
  
  // noise level-related energy parameters
  //
  noise_nominal_level_d = DEF_NOISE_NOMINAL_LEVEL;
  noise_adaptation_delta_d = DEF_NOISE_ADAPTATION_DELTA;
  noise_adaptation_constant_d = DEF_NOISE_ADAPTATION_CONSTANT;
  noise_floor_d = DEF_NOISE_FLOOR;
  
  // utterance-related parameters
  //
  utterance_minimum_duration_d = DEF_UTTERANCE_MINIMUM_DURATION;
  utterance_maximum_duration_d = DEF_UTTERANCE_MINIMUM_SEPARATION;
  utterance_minimum_separation_d = DEF_UTTERANCE_MAXIMUM_DURATION;
  utterance_delta_d = DEF_UTTERANCE_DELTA; 
  
  // variables to handle the zero crossing values
  //
  zc_utterance_thresh_d = DEF_ZC_UTTERANCE_THRESH;                            
  zc_negative_thresh_d = DEF_ZC_POSITIVE_THRESH;
  zc_positive_thresh_d = DEF_ZC_NEGATIVE_THRESH;
  debug_level_d = Integral::BRIEF;
  
  // exit gracefully
  //
  return true;
}


//-----------------------------------------------------------------------------
//
// we define non-integral constants in the default constructor
//
//-----------------------------------------------------------------------------

// constants: class name
//
const String SignalDetector::CLASS_NAME(L"SignalDetector");

// constants: i/o related
//
const String SignalDetector::DEF_PARAM(L"");
const String SignalDetector::PARAM_ALGORITHM(L"algorithm");
const String SignalDetector::PARAM_IMPLEMENTATION(L"implementation");
const String SignalDetector::PARAM_NUM_CHANNELS(L"num_channels");
const String SignalDetector::PARAM_SAMPLE_FREQUENCY(L"sample_frequency");
const String SignalDetector::PARAM_SAMPLE_NUM_BYTES(L"sample_num_bytes");
const String SignalDetector::PARAM_CHANNEL_TO_BE_PROCESSED(L"channel_to_be_processed");
const String SignalDetector::PARAM_FRAME_DURATION(L"frame_duration");
const String SignalDetector::PARAM_WINDOW_DURATION(L"window_duration");
const String SignalDetector::PARAM_PREEMPHASIS(L"preemphasis");
const String SignalDetector::PARAM_SIGNAL_NOMINAL_LEVEL(L"nominal_signal_level");
const String SignalDetector::PARAM_SIGNAL_ADAPTATION_CONSTANT(L"signal_adaptation_constant");
const String SignalDetector::PARAM_SIGNAL_ADAPTATION_DELTA(L"signal_adaptation_delta");
const String SignalDetector::PARAM_NOISE_NOMINAL_LEVEL(L"nominal_noise_level");
const String SignalDetector::PARAM_NOISE_ADAPTATION_CONSTANT(L"noise_adaptation_constant");
const String SignalDetector::PARAM_NOISE_ADAPTATION_DELTA(L"noise_adaptation_delta");
const String SignalDetector::PARAM_NOISE_FLOOR(L"noise_floor");
const String SignalDetector::PARAM_UTTERANCE_MINIMUM_DURATION(L"minimum_utterance_duration");
const String SignalDetector::PARAM_UTTERANCE_MAXIMUM_DURATION(L"maximum_utterance_duration");
const String SignalDetector::PARAM_UTTERANCE_MINIMUM_SEPARATION(L"minimum_utterance_separation");
const String SignalDetector::PARAM_UTTERANCE_DELTA(L"utterance_delta");
const String SignalDetector::PARAM_ZC_UTTERANCE_THRESH(L"zc_utt_thresh");
const String SignalDetector::PARAM_ZC_POSITIVE_THRESH(L"postive_zc_thresh");
const String SignalDetector::PARAM_ZC_NEGATIVE_THRESH(L"negative_zc_thresh");
const String SignalDetector::PARAM_PAD_TIME(L"pad_time");
const String SignalDetector::PARAM_DBGL(L"debug_level");

// constants: name map(s) for the enumerated values
//
const NameMap SignalDetector::ALGO_MAP(L"AL_DEFAULT");
const NameMap SignalDetector::IMPL_MAP(L"IM_DEFAULT");

// static instantiations: memory manager
//
MemoryManager SignalDetector::mgr_d(sizeof(SignalDetector));
