~ubuntu-branches/ubuntu/quantal/pd-ekext/quantal

« back to all changes in this revision

Viewing changes to framescore~.c

  • Committer: Bazaar Package Importer
  • Author(s): Hans-Christoph Steiner
  • Date: 2010-08-18 17:14:25 UTC
  • Revision ID: james.westby@ubuntu.com-20100818171425-7wehl0fqtaacqulx
Tags: upstream-0.1.1
ImportĀ upstreamĀ versionĀ 0.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  framescore~ : Weighted block comparison.
 
3
 *  Copyright (C) 2005 Edward Kelly <morph_2016@yahoo.co.uk>
 
4
 *
 
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.
 
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
 *  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
 
17
 */
 
18
 
 
19
#include "m_pd.h"
 
20
 
 
21
static t_class *framescore_tilde_class;
 
22
 
 
23
typedef struct _framescore_tilde 
 
24
{
 
25
  t_object x_obj;
 
26
  t_float f;
 
27
  t_float f_max, f_win, f_accum;
 
28
  t_outlet *f_score;
 
29
} t_framescore_tilde;
 
30
 
 
31
t_int *framescore_tilde_perform(t_int *w)
 
32
{
 
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]);
 
36
  int                 n =                  (int)(w[4]);
 
37
  float vector1;
 
38
  float vector2;
 
39
  x->f_accum = 0;
 
40
  float block_accum = 0;
 
41
  x->f_max = 0;
 
42
  float score = 0;
 
43
  float avg = 0;
 
44
  int block = n;
 
45
  x->f_win = x->f_win > 0 ? x->f_win : 0.01;
 
46
 
 
47
  while (n--)
 
48
    {
 
49
      vector1 = (*in1++);
 
50
      vector2 = (*in2++);
 
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;
 
57
    }
 
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);
 
62
  
 
63
  return(w+5);
 
64
}
 
65
 
 
66
void framescore_tilde_dsp(t_framescore_tilde *x, t_signal **sp)
 
67
{
 
68
  dsp_add(framescore_tilde_perform, 4, x,
 
69
          sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
 
70
}
 
71
 
 
72
void *framescore_tilde_new(t_floatarg f)
 
73
{
 
74
  t_framescore_tilde *x = (t_framescore_tilde *)pd_new(framescore_tilde_class);
 
75
 
 
76
  x->f_win = f;
 
77
 
 
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"));
 
81
 
 
82
  return (void *)x;
 
83
}
 
84
 
 
85
 
 
86
void framescore_tilde_setup(void)
 
87
{
 
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);
 
92
 
 
93
  post("|+++++++++++framescore~+++++++++++++|");
 
94
  post("|+++++weighted block comparison+++++|");
 
95
  post("|+++edward+++++++kelly+++++++2005+++|");
 
96
 
 
97
  class_addmethod(framescore_tilde_class, (t_method)framescore_tilde_dsp,
 
98
                  gensym("dsp"), 0);
 
99
 
 
100
  CLASS_MAINSIGNALIN(framescore_tilde_class, t_framescore_tilde, f);
 
101
}