// file: $isip_ifc/class/sp/SignalDetector/sigd_05.cc
// version: $Id: sigd_05.cc 10214 2005-08-15 05:01:23Z stanley $
//

// isip include files
//
#include "SignalDetector.h"

// method: setdefaultParameters
//
// arguments: none
//
// return: boolean
//
// set the default values for the data fields
//
boolean SignalDetector::setdefaultParameters() {
  
  // 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;
  
  return true;
}

// method: setNumChannels
//
// arguments:
//  long num_channels: (input) the number of channels to set
//
// return: a boolean value indicating status
//
// this method sets the number of channels
//
boolean SignalDetector::setNumChannels(long num_channels_a) {
  
  if (num_channels_a < 0) {
    return Error::handle(name(), L"setNumChannels", Error::ARG,
			 __FILE__, __LINE__);
  }
  
  num_channels_d = num_channels_a;
  
  // exit gracefully
  //
  return true;
}

// method: setSampleNumBytes
//
// arguments:
//  long sample_num_bytes: (input) the number of bytes per sample 
//
// return: a boolean value indicating status
//
// this method sets the number of bytes per sample
//
boolean SignalDetector::setSampleNumBytes(long sample_num_bytes_a) {
  
  // set the data
  //
  sample_num_bytes_d = (Long) sample_num_bytes_a;
  
  // exit gracefully
  //
  return true;
}

// method: setSampleFrequency
//
// arguments:
//  float sample_rate: (input) the sampling frequency
//
// return: a boolean value indicating status
//
// this method sets the sample frequency
//
boolean SignalDetector::setSampleFrequency(float sample_rate_a) {
  
  // set the data
  //
  sample_frequency_d = (Float) sample_rate_a;
  
  // exit gracefully
  //
  return true;
}


// method: setChannelToBeProcessed
//
// arguments:
//  long chan: (input) the channel o be preocessed
//
// return: a boolean value indicating status
//
// this method sets the channel that is to be processed
//
boolean SignalDetector::setChannelToBeProcessed(long chan_a) {
  
  // set the data
  //
  channel_to_be_processed_d = (Long) chan_a;
  
  // exit gracefully
  //
  return true;
}


// method: setFrameDuration
//
// arguments:
//  float frame_dur: (input) the frame duration
//
// return: a boolean value indicating status
//
// this method sets the frame duration
//
boolean SignalDetector::setFrameDuration(float frame_dur_a) {
  
  // set the data
  //
  frame_duration_d = (Float) frame_dur_a;
  
  // exit gracefully
  //
  return true;
}



// method: setWindowDuration
//
// arguments:
//  float win_dur: (input) the window duration
//
// return: a boolean value indicating status
//
// this method sets the window duration
//
boolean SignalDetector::setWindowDuration(float win_dur_a) {
  
  // set the data
  //
  window_duration_d = (Float) win_dur_a;
  
  // exit gracefully
  //
  return true;
}


// method: setPreemphasis
//
// arguments:
//  float preemphasis: (input) the preemphasis factor
//
// return: a boolean value indicating status
//
// this method sets the preemphasis factor
//
boolean SignalDetector::setPreemphasis(float preemphasis_a) {
  
  // set the data
  //
  preemphasis_d = (Float) preemphasis_a;
  
  // exit gracefully
  //
  return true;
}


// method: setSigNominalLevel
//
// arguments:
//  float sig_nom_lev: (input) the signal nominal level
//
// return: a boolean value indicating status
//
// this method sets the signal nominal level
//
boolean SignalDetector::setSigNominalLevel(float sig_nom_lev_a) {
  
  // set the data
  //
  signal_nominal_level_d = (Float) sig_nom_lev_a;
  
  // exit gracefully
  //
  return true;
}

// method: setSigAdaptDelta
//
// arguments:
//  float sig_delta: (input) the signal delta
//
// return: a boolean value indicating status
//
// this method sets the signal delta
//
boolean SignalDetector::setSigAdaptDelta(float sig_delta_a) {
  
  // set the data
  //
  signal_adaptation_delta_d = (Float) sig_delta_a;
  
  // exit gracefully
  //
  return true;
}

// method: setSigAdaptConst
//
// arguments:
//  float signal_adapt: (input) the sampling frequency
//
// return: a boolean value indicating status
//
// this method sets the sample frequency
//
boolean SignalDetector::setSigAdaptConst(float signal_adapt_a) {
  
  // set the data
  //
  signal_adaptation_constant_d = (Float) signal_adapt_a;
  
  // exit gracefully
  //
  return true;
}

// method: setNoiseNominalLevel
//
// arguments:
//  float noise_nom_lev: (input) the noise nominal level
//
// return: a boolean value indicating status
//
// this method sets the noise nominal level
//
boolean SignalDetector::setNoiseNominalLevel(float noise_nom_lev_a) {
  
  // set the data
  //
  noise_nominal_level_d = (Float) noise_nom_lev_a;
  
  // exit gracefully
  //
  return true;
}

// method: setNoiseAdaptDelta
//
// arguments:
//  float noise_delta: (input) the noise delta
//
// return: a boolean value indicating status
//
// this method sets the noise delta
//
boolean SignalDetector::setNoiseAdaptDelta(float noise_delta_a) {
  
  // set the data
  //
  noise_adaptation_delta_d = (Float) noise_delta_a;
  
  // exit gracefully
  //
  return true;
}

// method: setNoiseAdaptConst
//
// arguments:
//  float noise_adapt: (input) the noise adaptation level
//
// return: a boolean value indicating status
//
// this method sets the noise adaptation level
//
boolean SignalDetector::setNoiseAdaptConst(float noise_adapt_a) {
  
  // set the data
  //
  noise_adaptation_constant_d = (Float) noise_adapt_a;
  
  // exit gracefully
  //
  return true;
}


// method: setNoiseFloor
//
// arguments:
//  float noise_floor: (input) the noise floor level
//
// return: a boolean value indicating status
//
// this method sets the noise floor level
//
boolean SignalDetector::setNoiseFloor(float noise_floor_a) {
  
  // set the data
  //
  noise_floor_d = (Float) noise_floor_a;
  
  // exit gracefully
  //
  return true;
}

// method: setUttDelta
//
// arguments:
//  float utt_delta: (input) the utterance delta level
//
// return: a boolean value indicating status
//
// this method sets the utterance delta value
//
boolean SignalDetector::setUttDelta(float utt_delta_a) {
  
  // set the data
  //
  utterance_delta_d = (Float) utt_delta_a;
  
  // exit gracefully
  //
  return true;
}

// method: setMinUttDur
//
// arguments:
//  float min_utt_dur: (input) the minimum utterance duration value
//
// return: a boolean value indicating status
//
// this method sets the minimum utterance duration value
//
boolean SignalDetector::setMinUttDur(float min_utt_dur_a) {
  
  // set the data
  //
  utterance_minimum_duration_d = (Float) min_utt_dur_a;
  
  // exit gracefully
  //
  return true;
}

// method: setMinUttSep
//
// arguments:
//  float min_utt_sep: (input) the minimum utterance separation
//
// return: a boolean value indicating status
//
// this method sets the minimum utterance separation value
//
boolean SignalDetector::setMinUttSep(float min_utt_sep_a) {
  
  // set the data
  //
  utterance_minimum_separation_d = (Float) min_utt_sep_a;
  
  // exit gracefully
  //
  return true;
}

// method: setMaxUttDur
//
// arguments:
//  float max_utt_dur: (input) the maximum utterance duration value
//
// return: a boolean value indicating status
//
// this method sets the maximum utterance duration
//
boolean SignalDetector::setMaxUttDur(float max_utt_dur_a) {
  
  // set the data
  //
  utterance_maximum_duration_d = (Float) max_utt_dur_a;
  
  // exit gracefully
  //
  return true;
}


// method: setZcUttThreshold
//
// arguments:
//  long zc_utt_thresh: (input) the zero crossing utterance threshold
//
// return: a boolean value indicating status
//
// this method sets the  zero crossing utterance threshold 
//
boolean SignalDetector::setZcUttThreshold(long zc_utt_thresh_a) {
  
  // set the data
  //
  zc_utterance_thresh_d = (Long) zc_utt_thresh_a;
  
  // exit gracefully
  //
  return true;
}


// method: setZcNegThreshold
//
// arguments:
//  long zc_neg_thresh: (input) the zero crossing utterance threshold
//
// return: a boolean value indicating status
//
// this method sets the zero crossing negative threshold
//
boolean SignalDetector::setZcNegThreshold(long zc_neg_thresh_a) {
  
  // set the data
  //
  zc_negative_thresh_d = (Long) zc_neg_thresh_a;
  
  // exit gracefully
  //
  return true;
}

// method: setZcPosThreshold
//
// arguments:
//  long zc_pos_thresh: (input) the zero crossing utterance threshold
//
// return: a boolean value indicating status
//
// this method sets the zero crossing positive threshold 
//
boolean SignalDetector::setZcPosThreshold(long zc_pos_thresh_a) {
  
  // set the data
  //
  zc_positive_thresh_d = (Long) zc_pos_thresh_a;
  
  // exit gracefully
  //
  return true;
}


// method: setPadTime
//
// arguments:
//  float pad_time: (input) the sampling frequency
//
// return: a boolean value indicating status
//
// this method sets the sample frequency
//
boolean SignalDetector::setPadTime(float pad_time_a) {
  
  // set the data
  //
  pad_time_d = (Float) pad_time_a;
  
  // exit gracefully
  //
  return true;
}


// method: getNumChannels 
//
// return: a long value indicating the number of channels
//
// this method gets the number of channnels
//
long SignalDetector::getNumChannels() {
  
  return ((long) num_channels_d);
  
}

// method: getSampleNumBytes
//
// return: a long value indicating the number of bytes per sample
//
// this method gets the number of bytes per sample
//
long SignalDetector::getSampleNumBytes() {
  
  return ((long) sample_num_bytes_d);
  
}

// method: getSampleFrequency 
//
// return: a long value containing the sample frequency of the audio data
//
// this method gets the sample frequency
//
long SignalDetector::getSampleFrequency() {
  
  return ((long) sample_frequency_d);
  
}

// method: getChannelToBeProcessed 
//
// return: get the index of the channel that needs to be processing 
//
// this method gets the sample frequency
//
long SignalDetector::getChannelToBeProcessed() {
  
  return ((long) channel_to_be_processed_d);
  
}

// method: getFrameDuration
//
// return: gets the frame duration 
//
// this method gets the frame duration
//
float SignalDetector::getFrameDuration() {
  
  return ((float) frame_duration_d);
  
}

// method: getWindowDuration
//
// return: gets the window duration 
//
// this method gets the window duration
//
float SignalDetector::getWindowDuration() {
  
  return ((float) window_duration_d);
  
}

// method: getPreemphasis
//
// return: gets the preemphasis
//
// this method gets the preemphasis
//
float SignalDetector::getPreemphasis() {
  
  return ((float) preemphasis_d);
  
}

// method: getSigNominalLevel
//
// return: gets the signal nominal level 
//
// this method gets the signal nominal level
//
float SignalDetector::getSigNominalLevel() {
  
  return ((float) signal_nominal_level_d);
  
}

// method: getSigAdaptDelta
//
// return: gets the signal adaptation delta value
//
// this method gets the signal adaptation delta value
//
float SignalDetector::getSigAdaptDelta() {
  
  return ((float) signal_adaptation_delta_d);
  
}

// method: getSigAdaptConst
//
// return: gets the  signal adaptation constant value
//
// this method gets the frame duration
//
float SignalDetector::getSigAdaptConst() {
  
  return ((float) frame_duration_d);
  
}

// method: getNoiseNominalLevel
//
// return: gets the nominal noise level
//
// this method gets the nominal noise level
//
float SignalDetector::getNoiseNominalLevel() {
  
  return ((float) noise_nominal_level_d);
  
}

// method: getNoiseAdaptDelta
//
// return: gets the noise adaptation delta 
//
// this method gets the noise adaptation delta
//
float SignalDetector::getNoiseAdaptDelta() {
  
  return ((float) noise_adaptation_delta_d);
  
}

// method: getNoiseAdaptConst
//
// return: gets the noise adaptation constant 
//
// this method gets the noise adaptation constant
//
float SignalDetector::getNoiseAdaptConst() {
  
  return ((float) noise_adaptation_constant_d);
  
}

// method: getNoiseFloor
//
// return: gets the noise floor 
//
// this method gets the noise floor
//
float SignalDetector::getNoiseFloor() {
  
  return ((float) noise_floor_d);
  
}

// method: getUttDelta
//
// return: gets the utterance delta 
//
// this method gets the utterance delta
//
float SignalDetector::getUttDelta() {
  
  return ((float) utterance_delta_d);
  
}

// method: getMinUttDur
//
// return: gets the minimum utterance duration 
//
// this method gets the minimum utterance duration
//
float SignalDetector::getMinUttDur() {
  
  return ((float) utterance_minimum_duration_d);
  
}

// method: getMinUttSep
//
// return: gets the minimum utterance separation 
//
// this method gets the minimum utterance separation
//
float SignalDetector::getMinUttSep() {
  
  return ((float) utterance_minimum_separation_d);
  
}

// method: getMaxUttDur
//
// return: gets the maximum utterance duration
//
// this method gets the maximum utterance duration
//
float SignalDetector::getMaxUttDur() {
  
  return ((float) utterance_maximum_duration_d);
  
}

// method: getZcUttThreshold
//
// return: gets the zero crossing utterance threshold 
//
// this method gets the zero crossing utterance threshold
//
long SignalDetector::getZcUttThreshold() {
  
  return ((long) zc_utterance_thresh_d);
  
}

// method: getZcNegThreshold
//
// return: gets the zero crossing negative threshold 
//
// this method gets the zero crossing negative threshold
//
long SignalDetector::getZcNegThreshold() {
  
  return ((long) zc_negative_thresh_d);
  
}

// method: getZcPosThreshold
//
// return: gets the zero crossing positive threshold 
//
// this method gets the zero crossing positive threshold
//
long SignalDetector::getZcPosThreshold() {
  
  return ((long) zc_positive_thresh_d);
  
}

// method: getPadTime
//
// return: gets the pad time 
//
// this method gets the pad time
//
long SignalDetector::getPadTime() {
  
  return ((long) pad_time_d);
  
}


// method: getUttStatus
//
// return: gets the Utterance status 
//
// this method gets the utterance status
//
Vector<Boolean> SignalDetector::getUttStatus() {
  
  return utt_in_progress_d;
  
}

// method: getEndTime
//
// arguments:
//  VectorFloat& start_time: (input) start time to process
//  VectorFloat& end_time: (input) stop time to process
//  long channel_index: (input) channel tag to process
//  
// return: status 
//
// this method gets the utterance status
//
boolean SignalDetector::getEndTime(VectorFloat& start_time_a, VectorFloat& end_time_a, long channel_index_a ) {
  
  start_time_a  = start_points_d (channel_index_a);
  end_time_a =  stop_points_d (channel_index_a);
  return true;
  
}
