// file: $isip/doc/examples/class/mmedia/mmedia_example_00/example.cc
// version: $Id: example.cc 6855 2001-04-30 03:47:08Z duncan $
//

// isip include files
//
#include <AudioFile.h>
#include <CommandLine.h>

// excise_signal: program to excise part of an audio signal from one
// file and output it to a new file.
//
// this is an example excise_signal utility
//
int main(int argc, const char** argv) {

  // configure the command line parser and an Sdb object.
  //
  CommandLine cmdl;

  // 2 parameters: start time and stop time
  //
  Float start_time;
  Float stop_time;
  String start_param(L"start_time");
  String stop_param(L"stop_time");
  cmdl.addOptionParam(start_time, start_param, 0.0);
  cmdl.addOptionParam(stop_time, stop_param, 0.0);

  // parse the command line
  //
  cmdl.parse(argc,argv);

  Filename input;
  Filename output;

  // read the input and output as the arguments
  //
  cmdl.getArgument(input, 0);
  cmdl.getArgument(output, 1);
  
  // declare AudioFile objects for read and write
  //
  AudioFile src;
  AudioFile dst;

  // open the input file
  //
  src.open(input);

  // we want the output file to have the same format as the input, so
  // assign the object before opening the new file
  //
  dst.assign(src);
  dst.open(output, File::WRITE_ONLY);

  // read in the data into a buffer and write it to the new file
  //
  Vector<VectorFloat> buf(src.getNumChannels());
  src.getData(buf, start_time, stop_time - start_time);
  dst.writeAudioData(buf);

  // close the files
  //
  src.close();
  dst.close();
  
  // exit gracefully
  //
  Integral::exit();
}
