aboutsummaryrefslogtreecommitdiff
path: root/src/spec2_clip_max~.c
blob: 2aebcdc64e92108af223baa19ed8452df89f2776 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.

iem_spec2 written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2006 */

#include "m_pd.h"
#include "iemlib.h"

/* -------------------------- spec2_clip_max~ ------------------------------ */
static t_class *spec2_clip_max_tilde_class;

typedef struct _spec2_clip_max_tilde
{
  t_object  x_obj;
  t_float   x_msi;
} t_spec2_clip_max_tilde;

static t_int *spec2_clip_max_tilde_perform(t_int *w)
{
  t_float *in = (t_float *)(w[1]);
  t_float *max = (t_float *)(w[2]);
  t_float *out = (t_float *)(w[3]);
  int i, n = (t_int)(w[4]);
  
  for(i=0; i<=n; i++)
  {
    if(in[i] > max[i])
      out[i] = max[i];
    else
      out[i] = in[i];
  }
  return(w+5);
}

static t_int *spec2_clip_max_tilde_perf16(t_int *w)
{
  t_float *in = (t_float *)(w[1]);
  t_float *max = (t_float *)(w[2]);
  t_float *out = (t_float *)(w[3]);
  int n = (t_int)(w[4]);
  
  while(n)
  {
    if(in[0] > max[0])
      out[0] = max[0];
    else
      out[0] = in[0];
    
    if(in[1] > max[1])
      out[1] = max[1];
    else
      out[1] = in[1];
    
    if(in[2] > max[2])
      out[2] = max[2];
    else
      out[2] = in[2];
    
    if(in[3] > max[3])
      out[3] = max[3];
    else
      out[3] = in[3];
    
    if(in[4] > max[4])
      out[4] = max[4];
    else
      out[4] = in[4];
    
    if(in[5] > max[5])
      out[5] = max[5];
    else
      out[5] = in[5];
    
    if(in[6] > max[6])
      out[6] = max[6];
    else
      out[6] = in[6];
    
    if(in[7] > max[7])
      out[7] = max[7];
    else
      out[7] = in[7];
    
    if(in[8] > max[8])
      out[8] = max[8];
    else
      out[8] = in[8];
    
    if(in[9] > max[9])
      out[9] = max[9];
    else
      out[9] = in[9];
    
    if(in[10] > max[10])
      out[10] = max[10];
    else
      out[10] = in[10];
    
    if(in[11] > max[11])
      out[11] = max[11];
    else
      out[11] = in[11];
    
    if(in[12] > max[12])
      out[12] = max[12];
    else
      out[12] = in[12];
    
    if(in[13] > max[13])
      out[13] = max[13];
    else
      out[13] = in[13];
    
    if(in[14] > max[14])
      out[14] = max[14];
    else
      out[14] = in[14];
    
    if(in[15] > max[15])
      out[15] = max[15];
    else
      out[15] = in[15];
    
    in += 16;
    max += 16;
    out += 16;
    n -= 16;
  }
  if(in[0] > max[0])
    out[0] = max[0];
  else
    out[0] = in[0];
  return(w+5);
}

static void spec2_clip_max_tilde_dsp(t_spec2_clip_max_tilde *x, t_signal **sp)
{
  int n = (sp[0]->s_n)/2;
  
  if(n&15)
    dsp_add(spec2_clip_max_tilde_perform, 4, sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, n);
  else
    dsp_add(spec2_clip_max_tilde_perf16, 4, sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, n);
}

static void *spec2_clip_max_tilde_new(void)
{
  t_spec2_clip_max_tilde *x = (t_spec2_clip_max_tilde *)pd_new(spec2_clip_max_tilde_class);
  
  inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
  outlet_new(&x->x_obj, &s_signal);
  x->x_msi = 0.0f;
  return (x);
}

static void spec2_clip_max_tilde_free(t_spec2_clip_max_tilde *x)
{
}

void spec2_clip_max_tilde_setup(void)
{
  spec2_clip_max_tilde_class = class_new(gensym("spec2_clip_max~"), (t_newmethod)spec2_clip_max_tilde_new, (t_method)spec2_clip_max_tilde_free,
    sizeof(t_spec2_clip_max_tilde), 0, 0);
  CLASS_MAINSIGNALIN(spec2_clip_max_tilde_class, t_spec2_clip_max_tilde, x_msi);
  class_addmethod(spec2_clip_max_tilde_class, (t_method)spec2_clip_max_tilde_dsp, gensym("dsp"), 0);
//  class_sethelpsymbol(spec2_clip_max_tilde_class, gensym("iemhelp2/spec2_clip_max~-help"));
}