// file: $isip/class/numeric/Bark/bark_05.cc
// version: $Id: bark_05.cc 7042 2001-06-09 03:19:15Z picone $
//

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

// method: compute
//
// arguments:
//  float& bark: (output) equivalent bark scaled value
//  float freq: (input) frequency value in Hz
//
// return: a boolean value indicating status
//
// this method maps the input data from one scale to another via a
// nonlinear transformation.
//
boolean Bark::compute(float& bark_a, float freq_a) {

  // declare local variables
  //
  float tmp1 = A2 * freq_a;
  float tmp2 = B2 * freq_a;

  // assign the value
  //
  bark_a = A1 * Integral::atan(tmp1) + B1 * Integral::atan(tmp2 * tmp2);

  // exit gracefully
  //
  return true;
}

// method: compute
//
// arguments:
//  VectorFloat& bark: (output) bark-scaled data
//  const VectorFloat& freq: (input) frequency data in Hz
//
// return: a boolean value indicating status
//
// this method maps the freq data to the Bark scale using a nonlinear
// transformation.
//
boolean Bark::compute(VectorFloat& bark_a, const VectorFloat& freq_a) {

  // declare local variables
  //
  long length = freq_a.length();
  float tmp;
  boolean status = true;

  // allocate space
  //
  bark_a.setLength(length, false);

  // loop over all the data
  //
  for (long k = 0; k < length; k++) {
    status = compute(tmp, (float)freq_a(k));
    bark_a(k) = tmp;
  }

  // exit gracefully
  //
  return status;
}

