~ubuntu-branches/ubuntu/precise/puredata/precise

« back to all changes in this revision

Viewing changes to src/d_dac.c

  • Committer: Bazaar Package Importer
  • Author(s): Guenter Geiger (Debian/GNU)
  • Date: 2005-04-08 16:21:52 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 hoary)
  • Revision ID: james.westby@ubuntu.com-20050408162152-88qyy276gx2qmx35
Tags: 0.38.4+amidi-3
* Incorporated mlock fix for 2.6 kernels
* moved allocation/deallocation out of midi poll() call for ALSA (this 
  cause problems on 2.6 kernel series when using -rt)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 1997-1999 Miller Puckette.
2
 
* For information on usage and redistribution, and for a DISCLAIMER OF ALL
3
 
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.  */
4
 
 
5
 
/*  The dac~ and adc~ routines.
6
 
*/
7
 
 
8
 
#include "m_pd.h"
9
 
#include "s_stuff.h"
10
 
 
11
 
/* T.Grill - include SIMD functionality */
12
 
#include "m_simd.h"
13
 
 
14
 
/* ----------------------------- dac~ --------------------------- */
15
 
static t_class *dac_class;
16
 
 
17
 
typedef struct _dac
18
 
{
19
 
    t_object x_obj;
20
 
    t_int x_n;
21
 
    t_int *x_vec;
22
 
    float x_f;
23
 
} t_dac;
24
 
 
25
 
static void *dac_new(t_symbol *s, int argc, t_atom *argv)
26
 
{
27
 
    t_dac *x = (t_dac *)pd_new(dac_class);
28
 
    t_atom defarg[2], *ap;
29
 
    int i;
30
 
    if (!argc)
31
 
    {
32
 
        argv = defarg;
33
 
        argc = 2;
34
 
        SETFLOAT(&defarg[0], 1);
35
 
        SETFLOAT(&defarg[1], 2);
36
 
    }
37
 
    x->x_n = argc;
38
 
    x->x_vec = (t_int *)getbytes(argc * sizeof(*x->x_vec));
39
 
    for (i = 0; i < argc; i++)
40
 
        x->x_vec[i] = atom_getintarg(i, argc, argv);
41
 
    for (i = 1; i < argc; i++)
42
 
        inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
43
 
    x->x_f = 0;
44
 
    return (x);
45
 
}
46
 
 
47
 
static void dac_dsp(t_dac *x, t_signal **sp)
48
 
{
49
 
    t_int i, *ip;
50
 
    t_signal **sp2;
51
 
    for (i = x->x_n, ip = x->x_vec, sp2 = sp; i--; ip++, sp2++)
52
 
    {
53
 
        int ch = *ip - 1;
54
 
        if ((*sp2)->s_n != DEFDACBLKSIZE)
55
 
            error("dac~: bad vector size");
56
 
        else if (ch >= 0 && ch < sys_get_outchannels())
57
 
            dsp_add(plus_perform, 4, sys_soundout + DEFDACBLKSIZE*ch,
58
 
                (*sp2)->s_vec, sys_soundout + DEFDACBLKSIZE*ch, DEFDACBLKSIZE);
59
 
    }    
60
 
}
61
 
 
62
 
static void dac_free(t_dac *x)
63
 
{
64
 
    freebytes(x->x_vec, x->x_n * sizeof(*x->x_vec));
65
 
}
66
 
 
67
 
static void dac_setup(void)
68
 
{
69
 
    dac_class = class_new(gensym("dac~"), (t_newmethod)dac_new,
70
 
        (t_method)dac_free, sizeof(t_dac), 0, A_GIMME, 0);
71
 
    CLASS_MAINSIGNALIN(dac_class, t_dac, x_f);
72
 
    class_addmethod(dac_class, (t_method)dac_dsp, gensym("dsp"), A_CANT, 0);
73
 
    class_sethelpsymbol(dac_class, gensym("adc~_dac~"));
74
 
}
75
 
 
76
 
/* ----------------------------- adc~ --------------------------- */
77
 
static t_class *adc_class;
78
 
 
79
 
typedef struct _adc
80
 
{
81
 
    t_object x_obj;
82
 
    t_int x_n;
83
 
    t_int *x_vec;
84
 
} t_adc;
85
 
 
86
 
static void *adc_new(t_symbol *s, int argc, t_atom *argv)
87
 
{
88
 
    t_adc *x = (t_adc *)pd_new(adc_class);
89
 
    t_atom defarg[2], *ap;
90
 
    int i;
91
 
    if (!argc)
92
 
    {
93
 
        argv = defarg;
94
 
        argc = 2;
95
 
        SETFLOAT(&defarg[0], 1);
96
 
        SETFLOAT(&defarg[1], 2);
97
 
    }
98
 
    x->x_n = argc;
99
 
    x->x_vec = (t_int *)getbytes(argc * sizeof(*x->x_vec));
100
 
    for (i = 0; i < argc; i++)
101
 
        x->x_vec[i] = atom_getintarg(i, argc, argv);
102
 
    for (i = 0; i < argc; i++)
103
 
        outlet_new(&x->x_obj, &s_signal);
104
 
    return (x);
105
 
}
106
 
 
107
 
t_int *copy_perform(t_int *w)
108
 
{
109
 
    t_float *in1 = (t_float *)(w[1]);
110
 
    t_float *out = (t_float *)(w[2]);
111
 
    int n = (int)(w[3]);
112
 
    while (n--) *out++ = *in1++; 
113
 
    return (w+4);
114
 
}
115
 
 
116
 
t_int *copy_perf8(t_int *w)
117
 
{
118
 
    t_float *in1 = (t_float *)(w[1]);
119
 
    t_float *out = (t_float *)(w[2]);
120
 
    int n = (int)(w[3]);
121
 
    
122
 
    for (; n; n -= 8, in1 += 8, out += 8)
123
 
    {
124
 
        float f0 = in1[0];
125
 
        float f1 = in1[1];
126
 
        float f2 = in1[2];
127
 
        float f3 = in1[3];
128
 
        float f4 = in1[4];
129
 
        float f5 = in1[5];
130
 
        float f6 = in1[6];
131
 
        float f7 = in1[7];
132
 
 
133
 
        out[0] = f0;
134
 
        out[1] = f1;
135
 
        out[2] = f2;
136
 
        out[3] = f3;
137
 
        out[4] = f4;
138
 
        out[5] = f5;
139
 
        out[6] = f6;
140
 
        out[7] = f7;
141
 
    }
142
 
    return (w+4);
143
 
}
144
 
 
145
 
void dsp_add_copy(t_sample *in, t_sample *out, int n)
146
 
{
147
 
    if (n&7)
148
 
        dsp_add(copy_perform, 3, in, out, n);
149
 
        else if(SIMD_CHECK2(n,in,out))
150
 
        dsp_add(copy_perf_simd, 3, in, out, n);
151
 
    else        
152
 
        dsp_add(copy_perf8, 3, in, out, n);
153
 
}
154
 
 
155
 
static void adc_dsp(t_adc *x, t_signal **sp)
156
 
{
157
 
    t_int i, *ip;
158
 
    t_signal **sp2;
159
 
    for (i = x->x_n, ip = x->x_vec, sp2 = sp; i--; ip++, sp2++)
160
 
    {
161
 
        int ch = *ip - 1;
162
 
        if ((*sp2)->s_n != DEFDACBLKSIZE)
163
 
            error("adc~: bad vector size");
164
 
        else if (ch >= 0 && ch < sys_get_inchannels())
165
 
            dsp_add_copy(sys_soundin + DEFDACBLKSIZE*ch,
166
 
                (*sp2)->s_vec, DEFDACBLKSIZE);
167
 
        else dsp_add_zero((*sp2)->s_vec, DEFDACBLKSIZE);
168
 
    }    
169
 
}
170
 
 
171
 
static void adc_free(t_adc *x)
172
 
{
173
 
    freebytes(x->x_vec, x->x_n * sizeof(*x->x_vec));
174
 
}
175
 
 
176
 
static void adc_setup(void)
177
 
{
178
 
    adc_class = class_new(gensym("adc~"), (t_newmethod)adc_new,
179
 
        (t_method)adc_free, sizeof(t_adc), 0, A_GIMME, 0);
180
 
    class_addmethod(adc_class, (t_method)adc_dsp, gensym("dsp"), A_CANT, 0);
181
 
    class_sethelpsymbol(adc_class, gensym("adc~_dac~"));
182
 
}
183
 
 
184
 
void d_dac_setup(void)
185
 
{
186
 
    dac_setup();
187
 
    adc_setup();
188
 
}
189