view src/paranormal/beatdetect.c @ 334:a9f1bd76a3e6 trunk

[svn] - apply_xform(): check for NULL vfield (broken scripts) - add tan(), asin(), acos(), atan(), log() to script engine.
author nenolod
date Tue, 05 Dec 2006 03:40:04 -0800
parents 65c4d8591b4a
children 3b034150d31e
line wrap: on
line source

#include "paranormal.h"

/*
 * This algorithm is by Janusz Gregorcyzk, the implementation is
 * mine, however.
 *
 *   -- nenolod
 */
int
pn_is_new_beat(void)
{
  gint i;
  gint total = 0;
  gboolean ret = FALSE;
  static gint previous;

  for (i = 1; i < 512; i++)
    {
       total += abs (pn_sound_data->pcm_data[0][i] -
		     pn_sound_data->pcm_data[0][i - 1]);
    }

  total /= 512;

  ret = (total > (2 * previous));

  previous = total;

  return ret;
}