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

« back to all changes in this revision

Viewing changes to src/demultiplex~.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
#include "zexy.h"
 
18
 
 
19
/* ------------------------------------------------------------------------------ */
 
20
 
 
21
/* demux~ : demultiplex a signal to a specified output */
 
22
 
 
23
static t_class *demux_class;
 
24
 
 
25
typedef struct _demux {
 
26
  t_object x_obj;
 
27
 
 
28
  int output;
 
29
 
 
30
  int n_out;
 
31
  t_sample **out;
 
32
 
 
33
} t_demux;
 
34
 
 
35
static void demux_output(t_demux *x, t_floatarg f)
 
36
{
 
37
  if ((f>=0)&&(f<x->n_out)){
 
38
    x->output=f;
 
39
  } else
 
40
    error("demultiplex: %d is channel out of range (0..%d)", (int)f, x->n_out);
 
41
}
 
42
 
 
43
 
 
44
static t_int *demux_perform(t_int *w)
 
45
{
 
46
  t_demux *x = (t_demux *)(w[1]);
 
47
  t_sample *in = (t_sample *)(w[2]);
 
48
  int N = (int)(w[3]);
 
49
  int n = N;
 
50
 
 
51
  int channel=x->n_out;
 
52
 
 
53
  while(channel--){
 
54
    t_sample*out=x->out[channel];
 
55
    n=N;
 
56
    if(x->output==channel){
 
57
      while(n--)*out++=*in++;
 
58
    } else
 
59
      while(n--)*out++=0.f;
 
60
  }
 
61
  return (w+4);
 
62
}
 
63
 
 
64
static void demux_dsp(t_demux *x, t_signal **sp)
 
65
{
 
66
  int n = x->n_out;
 
67
  t_sample **dummy=x->out;
 
68
  while(n--)*dummy++=sp[x->n_out-n]->s_vec;
 
69
  dsp_add(demux_perform, 3, x, sp[0]->s_vec, sp[0]->s_n);
 
70
}
 
71
 
 
72
 
 
73
static void demux_helper(void)
 
74
{
 
75
  post("\n%c demux~\t:: demultiplex a signal to one of various outlets", HEARTSYMBOL);
 
76
  post("<#out>\t : the outlet-number (counting from 0) to witch the inlet is routed"
 
77
       "'help'\t : view this");
 
78
  post("creation : \"demux~ [arg1 [arg2...]]\"\t: the number of arguments equals the number of outlets\n");
 
79
}
 
80
 
 
81
static void demux_free(t_demux *x)
 
82
{
 
83
  freebytes(x->out, x->n_out * sizeof(t_sample *));
 
84
}
 
85
 
 
86
static void *demux_new(t_symbol *s, int argc, t_atom *argv)
 
87
{
 
88
  t_demux *x = (t_demux *)pd_new(demux_class);
 
89
  int i;
 
90
  ZEXY_USEVAR(s);
 
91
  ZEXY_USEVAR(argv);
 
92
 
 
93
  if (!argc)argc=2;
 
94
  x->n_out=argc;
 
95
  x->output=0;
 
96
 
 
97
  while(argc--)outlet_new(&x->x_obj, gensym("signal"));
 
98
 
 
99
  x->out = (t_sample **)getbytes(x->n_out * sizeof(t_sample *));
 
100
  i=x->n_out;
 
101
  while(i--)x->out[i]=0;
 
102
 
 
103
  return (x);
 
104
}
 
105
 
 
106
void demultiplex_tilde_setup(void)
 
107
{
 
108
  demux_class = class_new(gensym("demultiplex~"), (t_newmethod)demux_new, (t_method)demux_free, sizeof(t_demux), 0, A_GIMME, 0);
 
109
  class_addcreator((t_newmethod)demux_new, gensym("demux~"), A_GIMME, 0);
 
110
 
 
111
  class_addfloat(demux_class, demux_output);
 
112
  class_addmethod(demux_class, (t_method)demux_dsp, gensym("dsp"), 0);
 
113
  class_addmethod(demux_class, nullfn, gensym("signal"), 0);
 
114
 
 
115
  class_addmethod(demux_class, (t_method)demux_helper, gensym("help"), 0);
 
116
 
 
117
  zexy_register("demultiplex~");
 
118
}
 
119
void demux_tilde_setup(void)
 
120
{
 
121
  demultiplex_tilde_setup();
 
122
}
 
123
 
 
124
 
 
125