Bonsoir !

Je suis en train de tenter d'implémenter un external puredata en C pour le traitement de signal, et j'ai un problème de memory corruption que je n'arrive pas à résoudre... Tout d'abord, voici le code (les fonctions que vous ne connaissez pas m'ont été fournies dans un couple .c/.h ) :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
t_int           *myfft_tilde_perform(t_int *w) {
 
    t_myfft_tilde *fft = (t_myfft_tilde *)w[1];
    t_float *in = (t_float *)w[2];
    t_float *out = (t_float *)w[3];
    int n = (int)w[4];
 
    int i;
    for(i=0; i<n; i++)
    {
        fft->bigbuffer[fft->nextindex] = in[i];
        fft->nextindex = (fft->nextindex+1)%TAILLE;
    }
 
    if (!fft->isfull && fft->nextindex==0)
    {
        fft->isfull=1;
    }
 
    if (fft->isfull)
    {
 
        for(i=0; i<TAILLE; i++)
        {
            fft->bigbuffercpy[i] = fft->window[i] * fft->bigbuffer[i];
        }
 
        rdft(TAILLE, 1, fft->bigbuffercpy, fft->bitshuffle, fft->weighting);
 
        if (fft->nextindex==0)
        {
            i=(TAILLE-1)-64;
        }
        else
        {
            i=fft->nextindex-64;
        }
        int j;
        for(j=0; j<64; j++)
        {
            out[j] = fft->bigbuffercpy[i+j];
        }
    }
 
    return (w+5);
 
}
 
void            myfft_tilde_dsp(t_myfft_tilde *x, t_signal **sp) {
 
    dsp_add(myfft_tilde_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
 
}
 
void            myfft_tilde_free(t_myfft_tilde *x) {
 
    if (x->bitshuffle)
        freebytes(x->bitshuffle, TAILLE*2*sizeof(int));
    if (x->weighting)
        freebytes(x->weighting, TAILLE*2*sizeof(float));
    if (x->window)
        freebytes(x->window, TAILLE*sizeof(float));
    if (x->bigbuffer)
        freebytes(x->bigbuffer, TAILLE*sizeof(float));
    if (x->bigbuffercpy)
        freebytes(x->bigbuffercpy, TAILLE*sizeof(float));
 
}
 
void            *myfft_tilde_new(void) {
 
    t_myfft_tilde *fft = (t_myfft_tilde *)pd_new(myfft_tilde_class);
 
    fft->x_out = outlet_new(&fft->x_obj, &s_signal);
 
    fft->bitshuffle = (int *)calloc(TAILLE*2, sizeof(int));
    fft->weighting = (float *)calloc(TAILLE*2, sizeof(float));
    fft->window = (float *)calloc(TAILLE, sizeof(float));
    fft->bigbuffer = (float *)calloc(TAILLE, sizeof(float));
    fft->bigbuffercpy = (float *)calloc(TAILLE, sizeof(float));
 
    int i;
    for(i=0; i<TAILLE; i++)
    {
        fft->window[i] = 0.54 - 0.46*cos(TWOPI*i/TAILLE);
    }
 
    fft->nextindex=0;
    fft->isfull=0;
 
    init_rdft(TAILLE*2, fft->bitshuffle, fft->weighting);
 
    return (void *)fft;
}
 
void            myfft_tilde_setup(void) {
 
    myfft_tilde_class = class_new(gensym("myfft~"),
                              (t_newmethod)myfft_tilde_new,
                              (t_method)myfft_tilde_free,
                              0, sizeof(t_myfft_tilde),
                              CLASS_DEFAULT, A_GIMME, 0);
    CLASS_MAINSIGNALIN(myfft_tilde_class, t_myfft_tilde, f);
    class_addmethod(myfft_tilde_class, (t_method)myfft_tilde_dsp,
                gensym("dsp"), 0);
 
}
Je compile alors avec le makefile qui m'a également été fourni, et j'obtiens sur le terminal, au moment de l'ouverture du patch puredata utilisant mon external (également fourni) :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
*** Error in `puredata': malloc(): memory corruption: 0x084f4570 ***
Pd: signal 6
En utilisant des prints, j'ai pu voir que l'erreur survient lors de la création de l'outlet, mais je ne comprends pas pourquoi. Ha, et TAILLE est la taille des bigbuffer, et vaut pour l'instant 1024. Même en enlevant tous le calloc, l'erreur est toujours présente.

Merci !