~ubuntu-branches/ubuntu/natty/pd-zexy/natty

« back to all changes in this revision

Viewing changes to src/pdf~.c

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard, IOhannes m zmölnig, Jonas Smedegaard
  • Date: 2010-08-20 12:17:41 UTC
  • mfrom: (2.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100820121741-4kxozn8b9rhee9fr
Tags: 2.2.3-1
* New upstream version

[ IOhannes m zmölnig ]
* Adopt package, on behalf of Multimedia Team.
  Closes: #546964
* Simply debian/rules with CDBS, and don't unconditionally strip
  binaries.
  Closes: #437763
* Install into /usr/lib/pd/extra/zexy/. Document usage in REAME.Debian
  and warn about change in NEWS.
* git'ify package. Add Vcs-* stanzas to control file.
* Use dpkg source format 3.0 (quilt). Drop build-dependency on quilt.

[ Jonas Smedegaard ]
* Enable CDBS copyright-check routine.
* Add copyright and licensing header to debian/rules.
* Add myself as uploader.
* Rewrite debian/copyright using rev. 135 of draft DEP5 format.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************
 
2
 *
 
3
 * zexy - implementation file
 
4
 *
 
5
 * copyleft (c) IOhannes m zm�lnig
 
6
 *
 
7
 *   1999:forum::f�r::uml�ute:2004
 
8
 *
 
9
 *   institute of electronic music and acoustics (iem)
 
10
 *
 
11
 ******************************************************
 
12
 *
 
13
 * license: GNU General Public License v.2
 
14
 *
 
15
 ******************************************************/
 
16
 
 
17
/* get the ProbabilityDensityFunction of a signal */
 
18
 
 
19
#include "zexy.h"
 
20
 
 
21
/* ------------------------ pdf~ ----------------------------- */
 
22
 
 
23
static t_class *pdf_class;
 
24
 
 
25
typedef struct _pdf
 
26
{
 
27
  t_object x_obj;
 
28
 
 
29
  t_float *buf;
 
30
  int size;
 
31
  t_float halfsize;
 
32
} t_pdf;
 
33
 
 
34
static void clear_pdfbuf(t_pdf *x)
 
35
{
 
36
  int n = x->size;
 
37
  t_float *buf = x->buf;
 
38
 
 
39
  while (n--) *buf++=0.;
 
40
}
 
41
 
 
42
static void pdf_bang(t_pdf *x)
 
43
{
 
44
  int n = x->size;
 
45
  t_float *buf = x->buf, max = 0;
 
46
  t_atom a[2];
 
47
 
 
48
  while (n--) if (max < *buf++) max = buf[-1];
 
49
 
 
50
  n=x->size;
 
51
  buf = x->buf;
 
52
 
 
53
  if (max==0.) max=1.;
 
54
  max = 1./max;
 
55
 
 
56
  while (n--)
 
57
    {
 
58
      SETFLOAT(a, *buf++*max);
 
59
      SETFLOAT(a+1,x->size-n-1);
 
60
      outlet_list(x->x_obj.ob_outlet, &s_list, 2, (t_atom*)&a);
 
61
    }
 
62
}
 
63
 
 
64
static void pdf_float(t_pdf *x, t_floatarg f)
 
65
{
 
66
  if (f) pdf_bang(x); else clear_pdfbuf(x);
 
67
}
 
68
 
 
69
static t_int *pdf_perform(t_int *w)
 
70
{
 
71
  t_sample *in = (t_sample *)(w[1]);
 
72
  t_pdf *x = (t_pdf *)(w[2]);
 
73
  int n = (int)(w[3]);
 
74
 
 
75
  t_float *buf = x->buf;
 
76
  t_float halfsize = x->halfsize;
 
77
 
 
78
  while (n--)
 
79
    {
 
80
      t_sample f = *in++;
 
81
      int iindex = ((f + 1.0) * halfsize)+0.5;
 
82
      buf[(iindex<0)?0:((iindex>=x->size)?x->size-1:iindex)]+=1.;
 
83
    }
 
84
  return (w+4);
 
85
}
 
86
 
 
87
static void pdf_dsp(t_pdf *x, t_signal **sp)
 
88
{
 
89
  x->halfsize = (x->size - 1) / 2.0;
 
90
 
 
91
  dsp_add(pdf_perform, 3, sp[0]->s_vec, x, sp[0]->s_n);
 
92
}
 
93
 
 
94
static void *pdf_new(t_floatarg f)
 
95
{
 
96
  int i = f;
 
97
  t_pdf *x = (t_pdf *)pd_new(pdf_class);
 
98
  t_float *buf;
 
99
 
 
100
  x->size = (i)?i:64;
 
101
  x->buf = (t_float *)getbytes(x->size * sizeof(*x->buf));
 
102
  buf = x->buf;
 
103
  clear_pdfbuf(x);
 
104
 
 
105
  outlet_new(&x->x_obj, &s_list);
 
106
    
 
107
  return (x);
 
108
}
 
109
 
 
110
static void pdf_free(t_pdf *x)
 
111
{
 
112
  if(x->buf)
 
113
    freebytes(x->buf, x->size*sizeof(*x->buf));
 
114
}
 
115
 
 
116
static void pdf_tilde_helper(void)
 
117
{
 
118
  post("\n%c pdf~\t:: get the probability density function of a signal (-1.0 to +1.0)", HEARTSYMBOL);
 
119
  post("'bang'\t  : output a list of the probabilities of 'n' function values"
 
120
       "\n'clear'\t  : clear the buffer (set all probabilities to zero)"
 
121
       "\n<1/0>\t  : short for 'bang' and 'clear'"
 
122
       "\n'help'\t  : view this");
 
123
  post("creation :: 'pdf~ [<n>]':: get the pdf for <n> (default: 64) values");
 
124
}
 
125
 
 
126
void pdf_tilde_setup(void)
 
127
{
 
128
  pdf_class = class_new(gensym("pdf~"), (t_newmethod)pdf_new, (t_method)pdf_free,
 
129
                        sizeof(t_pdf), 0, A_DEFFLOAT, 0);
 
130
 
 
131
  class_addmethod(pdf_class, nullfn, gensym("signal"), 0);
 
132
  class_addmethod(pdf_class, (t_method)pdf_dsp, gensym("dsp"), 0);
 
133
 
 
134
  class_addmethod(pdf_class, (t_method)pdf_bang, gensym("bang"), 0);
 
135
  class_addmethod(pdf_class, (t_method)clear_pdfbuf, gensym("clear"), 0);
 
136
  class_addfloat(pdf_class, pdf_float);
 
137
 
 
138
  class_addmethod(pdf_class, (t_method)pdf_tilde_helper, gensym("help"), 0);
 
139
  zexy_register("pdf~");
 
140
}