comparison src/paranormal-ng/beatdetect.c @ 2078:1fa3c8cd366a

paranormal-ng: a GL visualiser. lots to do, most stuff won't work, but hey, this will do cool stuff too soon
author William Pitcock <nenolod@atheme.org>
date Mon, 15 Oct 2007 06:20:13 -0500
parents
children f1b6f1b2cdb3
comparison
equal deleted inserted replaced
2077:e5b639ab62b0 2078:1fa3c8cd366a
1 /*
2 * paranormal: iterated pipeline-driven visualization plugin
3 * Copyright (c) 2006, 2007 William Pitcock <nenolod@dereferenced.org>
4 * Portions copyright (c) 2001 Jamie Gennis <jgennis@mindspring.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; under version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20 #include "paranormal.h"
21
22 /*
23 * This algorithm is by Janusz Gregorcyzk, the implementation is
24 * mine, however.
25 *
26 * -- nenolod
27 */
28 int
29 pn_is_new_beat(void)
30 {
31 gint i;
32 gint total = 0;
33 gboolean ret = FALSE;
34 static gint previous;
35
36 for (i = 1; i < 512; i++)
37 {
38 total += abs (pn_sound_data->pcm_data[0][i] -
39 pn_sound_data->pcm_data[0][i - 1]);
40 }
41
42 total /= 512;
43
44 ret = (total > (2 * previous));
45
46 previous = total;
47
48 return ret;
49 }