/*
  Native calls for correlate

  @author Scott Fernandez
  @version $Id: correlate.c,v 1.2 2011/10/14 20:47:37 ntn Exp $
 */
#include "native.h"
#include "dotprod.c"

JNIEXPORT inline jint JNICALL Java_nxm_dsp_prim_correlate_correlateNative(
    JNIEnv *env, jobject jobj,
    jobject inbuf, jobject impbuf, jobject outbuf, jint to_calc, jint impSize) {
  jfloat *in, *imp, *out;
  jint val;
  in = GetArray(inbuf);
  imp = GetArray(impbuf);
  out = GetArray(outbuf);
  val = sliding_dot_product(in, imp, out, to_calc, impSize);
  ReleaseArray(inbuf, in);
  ReleaseArray(impbuf, imp);
  ReleaseArray(outbuf, out);
  return val;
}

JNIEXPORT inline jint JNICALL Java_nxm_dsp_prim_correlate_normalizedCorrelateNative(
    JNIEnv *env, jobject jobj,
    jobject inbuf, jobject impbuf, jobject outbuf, jint to_calc,
    jint impSize, jobject in_norm_factors_buf) {
  jfloat *in, *imp, *out, *in_norm_factors;
  jint val;
  in = GetArray(inbuf);
  imp = GetArray(impbuf);
  out = GetArray(outbuf);
  in_norm_factors = GetArray(in_norm_factors_buf);
  val = normalized_sliding_dot_product(in, imp, out, to_calc, impSize, in_norm_factors);
  ReleaseArray(inbuf, in);
  ReleaseArray(impbuf, imp);
  ReleaseArray(outbuf, out);
  ReleaseArray(in_norm_factors_buf, in_norm_factors);
  return val;
}
