annotate src/paranormal/beatdetect.c @ 2168:3c9527d25346

fix a crash bug in mp4_is_our_file().
author Yoshiki Yazawa <yaz@cc.rim.or.jp>
date Sat, 17 Nov 2007 03:41:41 +0900
parents 3b034150d31e
children f1b6f1b2cdb3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1892
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 281
diff changeset
1 /*
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 281
diff changeset
2 * paranormal: iterated pipeline-driven visualization plugin
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 281
diff changeset
3 * Copyright (c) 2006, 2007 William Pitcock <nenolod@dereferenced.org>
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 281
diff changeset
4 * Portions copyright (c) 2001 Jamie Gennis <jgennis@mindspring.com>
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 281
diff changeset
5 *
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 281
diff changeset
6 * This program is free software; you can redistribute it and/or modify
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 281
diff changeset
7 * it under the terms of the GNU General Public License as published by
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 281
diff changeset
8 * the Free Software Foundation; under version 2 of the License.
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 281
diff changeset
9 *
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 281
diff changeset
10 * This program is distributed in the hope that it will be useful,
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 281
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 281
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 281
diff changeset
13 * GNU General Public License for more details.
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 281
diff changeset
14 *
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 281
diff changeset
15 * You should have received a copy of the GNU General Public License
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 281
diff changeset
16 * along with this program; if not, write to the Free Software
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 281
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 281
diff changeset
18 */
3b034150d31e Add GPL2 boilerplate text.
William Pitcock <nenolod@atheme.org>
parents: 281
diff changeset
19
170
13955c70fbec [svn] - split out beat detection code into beatdetect.c
nenolod
parents:
diff changeset
20 #include "paranormal.h"
13955c70fbec [svn] - split out beat detection code into beatdetect.c
nenolod
parents:
diff changeset
21
281
65c4d8591b4a [svn] - pinch xvs's beat detection algorithm.
nenolod
parents: 170
diff changeset
22 /*
65c4d8591b4a [svn] - pinch xvs's beat detection algorithm.
nenolod
parents: 170
diff changeset
23 * This algorithm is by Janusz Gregorcyzk, the implementation is
65c4d8591b4a [svn] - pinch xvs's beat detection algorithm.
nenolod
parents: 170
diff changeset
24 * mine, however.
65c4d8591b4a [svn] - pinch xvs's beat detection algorithm.
nenolod
parents: 170
diff changeset
25 *
65c4d8591b4a [svn] - pinch xvs's beat detection algorithm.
nenolod
parents: 170
diff changeset
26 * -- nenolod
65c4d8591b4a [svn] - pinch xvs's beat detection algorithm.
nenolod
parents: 170
diff changeset
27 */
170
13955c70fbec [svn] - split out beat detection code into beatdetect.c
nenolod
parents:
diff changeset
28 int
13955c70fbec [svn] - split out beat detection code into beatdetect.c
nenolod
parents:
diff changeset
29 pn_is_new_beat(void)
13955c70fbec [svn] - split out beat detection code into beatdetect.c
nenolod
parents:
diff changeset
30 {
281
65c4d8591b4a [svn] - pinch xvs's beat detection algorithm.
nenolod
parents: 170
diff changeset
31 gint i;
65c4d8591b4a [svn] - pinch xvs's beat detection algorithm.
nenolod
parents: 170
diff changeset
32 gint total = 0;
65c4d8591b4a [svn] - pinch xvs's beat detection algorithm.
nenolod
parents: 170
diff changeset
33 gboolean ret = FALSE;
65c4d8591b4a [svn] - pinch xvs's beat detection algorithm.
nenolod
parents: 170
diff changeset
34 static gint previous;
170
13955c70fbec [svn] - split out beat detection code into beatdetect.c
nenolod
parents:
diff changeset
35
281
65c4d8591b4a [svn] - pinch xvs's beat detection algorithm.
nenolod
parents: 170
diff changeset
36 for (i = 1; i < 512; i++)
65c4d8591b4a [svn] - pinch xvs's beat detection algorithm.
nenolod
parents: 170
diff changeset
37 {
65c4d8591b4a [svn] - pinch xvs's beat detection algorithm.
nenolod
parents: 170
diff changeset
38 total += abs (pn_sound_data->pcm_data[0][i] -
65c4d8591b4a [svn] - pinch xvs's beat detection algorithm.
nenolod
parents: 170
diff changeset
39 pn_sound_data->pcm_data[0][i - 1]);
65c4d8591b4a [svn] - pinch xvs's beat detection algorithm.
nenolod
parents: 170
diff changeset
40 }
65c4d8591b4a [svn] - pinch xvs's beat detection algorithm.
nenolod
parents: 170
diff changeset
41
65c4d8591b4a [svn] - pinch xvs's beat detection algorithm.
nenolod
parents: 170
diff changeset
42 total /= 512;
65c4d8591b4a [svn] - pinch xvs's beat detection algorithm.
nenolod
parents: 170
diff changeset
43
65c4d8591b4a [svn] - pinch xvs's beat detection algorithm.
nenolod
parents: 170
diff changeset
44 ret = (total > (2 * previous));
65c4d8591b4a [svn] - pinch xvs's beat detection algorithm.
nenolod
parents: 170
diff changeset
45
65c4d8591b4a [svn] - pinch xvs's beat detection algorithm.
nenolod
parents: 170
diff changeset
46 previous = total;
65c4d8591b4a [svn] - pinch xvs's beat detection algorithm.
nenolod
parents: 170
diff changeset
47
65c4d8591b4a [svn] - pinch xvs's beat detection algorithm.
nenolod
parents: 170
diff changeset
48 return ret;
170
13955c70fbec [svn] - split out beat detection code into beatdetect.c
nenolod
parents:
diff changeset
49 }