// file: $isip/class/algo/Correlation/corr_06.cc
// version: $Id: corr_06.cc 8165 2002-05-31 21:57:33Z picone $
//

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

// method: getLeadingPad
//
// arguments: none 
//
// return: a long value indicating leading pad (in units of frames)
//
long Correlation::getLeadingPad() const {

  // in FRAME_INTERNAL mode, we only deal with the current frame
  //
  if (cmode_d == FRAME_INTERNAL) {
    return DEF_LEADING_PAD;
  }
  
  // in CROSS_FRAME mode, we need to compute the overlap.
  //
  else if (cmode_d == CROSS_FRAME) {

    // only algorithm_d == CROSS requires a leading pad. all other
    // algorithms only require access to previous data.
    //
    if (algorithm_d == CROSS) {
      float overlap = (float)order_d / (frame_dur_d * sample_freq_d);
      return (long)Integral::ceil(overlap);
    }
    else
      return DEF_LEADING_PAD;      
  }

  // else: exit ungracefully
  //
  else {
    return Error::handle(name(), L"getLeadingPad",
			 ERR_UNSUPM, __FILE__, __LINE__);
  }
}

// method: getTrailingPad
//
// arguments: none 
//
// return: a long value indicating the trailing pad (in units of frames)
//
long Correlation::getTrailingPad() const {

  // in FRAME-INTERNAL mode, we only deal with the current frame
  //
  if (cmode_d == FRAME_INTERNAL) {
    return DEF_TRAILING_PAD;
  }

  // in CROSS_FRAME mode, we need to compute the overlap.
  //
  else if (cmode_d == CROSS_FRAME) {

    // only two algorithms (AUTO and CONV) need a leading pad
    //
    if (algorithm_d == AUTO || algorithm_d == CONV) {
      float overlap = (float)order_d / (frame_dur_d*sample_freq_d);
      return (long)Integral::ceil(overlap);
    }
    else
      return DEF_TRAILING_PAD;      
  }    

  // else: exit ungracefully
  //
  else {
    return Error::handle(name(), L"getTrailingPad",
			 ERR_UNSUPM, __FILE__, __LINE__);
  }
}
