// file: $isip_ifc/class/algo/Constant/const_05.cc
// version: $Id: const_05.cc 10532 2006-03-29 21:26:30Z raghavan $
//

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

// method: apply
//
// arguments:
//  Vector<AlgorithmData>& output: (output) output data
//  const Vector< CircularBuffer<AlgorithmData> >& input: (input) input data
//
// return: a boolean value indicating status
//
// this method calls the appropriate computation methods
//
boolean Constant::apply(Vector<AlgorithmData>& output_a,
			const Vector< CircularBuffer<AlgorithmData> >&
			input_a) {

  // start the debugging output
  //
  displayStart(this);

  // add one frame to indicator we process one frame
  //
  frame_index_d++;

  // calculate the whole frames needed to process
  //
  double  num_frames = signal_duration_d / frame_dur_d;
  long frame = (long)Integral::round(num_frames);

  // determine the number of input channels and force the output to be
  // that number
  //
  long len = input_a.length();
  output_a.setLength(len);
  data_d.setLength(len);
  
  // branch in the implementation: WRITE
  //
  if (implementation_d == WRITE) {
		  
    if (frame_index_d  != frame - 1) {
      
      // loop over the channels 
      //
      for (long c = 0; c < len; c++) {
	
	// display the channel number
	//
	displayChannel(c);

	output_a(c).assign(input_a(c)(0));
	data_d(c).assign(input_a(c)(0));
      }
      
      // possibly display the data
      //
      display(output_a, input_a,  name());

      return true;
    }
    
    // write output to a file
    //
    computeWrite(output_a, input_a);

  }
  
  // implementation: READ
  //
  else if (implementation_d == READ) {

    // read input from a file
    //
    computeRead(output_a, input_a);
    
  }

  // implementation: UNKNOWN
  //
  else {
     return Error::handle(name(), L"apply", ERR_UNSUPM,
			  __FILE__, __LINE__);
  }

  // finish the debugging output
  //
  displayFinish(this);

  // exit gracefully
  //
  return true;
}
