2
* framescore~ : Weighted block comparison.
3
* Copyright (C) 2005 Edward Kelly <morph_2016@yahoo.co.uk>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
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
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
static t_class *framescore_tilde_class;
23
typedef struct _framescore_tilde
27
t_float f_max, f_win, f_accum;
31
t_int *framescore_tilde_perform(t_int *w)
33
t_framescore_tilde *x = (t_framescore_tilde *)(w[1]);
34
t_sample *in1 = (t_sample *)(w[2]);
35
t_sample *in2 = (t_sample *)(w[3]);
40
float block_accum = 0;
45
x->f_win = x->f_win > 0 ? x->f_win : 0.01;
51
vector1 = vector1 > 0 ? vector1 : 0 - vector1;
52
vector2 = vector2 > 0 ? vector2 : 0 - vector2;
53
block_accum += vector2;
54
x->f_max = vector2 > x->f_max ? vector2 : x->f_max;
55
float diff = vector1 > vector2 ? vector1 - vector2 : vector2 - vector1;
56
x->f_accum += (1/((diff/x->f_win)+1)) * vector2;
58
score = x->f_accum / x->f_max;
59
block_accum /= x->f_max;
60
avg = score / block_accum;
61
outlet_float(x->f_score, avg);
66
void framescore_tilde_dsp(t_framescore_tilde *x, t_signal **sp)
68
dsp_add(framescore_tilde_perform, 4, x,
69
sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
72
void *framescore_tilde_new(t_floatarg f)
74
t_framescore_tilde *x = (t_framescore_tilde *)pd_new(framescore_tilde_class);
78
inlet_new (&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
79
floatinlet_new (&x->x_obj, &x->f_win);
80
x->f_score = outlet_new(&x->x_obj, gensym("float"));
86
void framescore_tilde_setup(void)
88
framescore_tilde_class = class_new(gensym("framescore~"),
89
(t_newmethod)framescore_tilde_new,
90
0, sizeof(t_framescore_tilde),
91
CLASS_DEFAULT, A_DEFFLOAT, 0);
93
post("|+++++++++++framescore~+++++++++++++|");
94
post("|+++++weighted block comparison+++++|");
95
post("|+++edward+++++++kelly+++++++2005+++|");
97
class_addmethod(framescore_tilde_class, (t_method)framescore_tilde_dsp,
100
CLASS_MAINSIGNALIN(framescore_tilde_class, t_framescore_tilde, f);