[PD-dev] myfft~.c:2:10: fatal error: fftw3.h: No such file or directory

Alexandros Drymonitis adrcki at gmail.com
Wed Oct 18 08:41:45 CEST 2023


OK, it's using the d_fft_fftsg.c file instead, if not compiled with the 
FFTW3 library then. Got that. I made this little external, and it seems 
to work (with a fixed FFT size, but I don't really care for now), still 
I'm including the code here. I'd be grateful if someone can take a look 
and verify it's OK.

I have copied the d_fft_fftsg.c file to the directory of my external and 
renamed it to pd_fft.h, which I'm including in my file (I commented out 
the line that includes the m_private_utils.h file, as I got an error 
saying that this is a private file). All this external is trying to do 
is an FFT analysis and resynthesis, as it is done in the ASCII patch below:

```
[inlet~]
|      ________[tabreceive~ hann]
[*~ ]
|
[rfft~]
|       |
[rifft~]
|       ________[tabreceive~ hann]
[*~ ]
|       ________[normalize_val (1 / (fft_size * 3 / 2) (
[*~ ]
|
[outlet~]
```

And here's the code:

```
#include <m_pd.h>
#include <stdlib.h>
#include "pd_fft.h"

#define FFTSIZE 1024

static t_class *myfft_tilde_class;

typedef struct _myfft_tilde {
     t_object obj;
     t_float f;
     t_outlet *x_out;
     t_sample *x_hann;
     t_float x_normalize;
} t_myfft_tilde;

static void make_hann(t_myfft_tilde *x)
{
     int i;
     float twopi = 2. * 3.14159;
     x->x_hann = (t_float *)getbytes(FFTSIZE*sizeof(t_float));
     for (i = 0; i < FFTSIZE; i++) {
         x->x_hann[i] = (cos(((float)i/(float)FFTSIZE)*twopi) * -0.5) + 0.5;
     }
}

t_int *myfft_tilde_perform(t_int *w)
{
     int i;
     t_myfft_tilde *x = (t_myfft_tilde *)(w[1]);
     t_sample *in = (t_sample *)(w[2]);
     t_sample *out = (t_sample *)(w[3]);
     int n = (int)(w[4]);

     for (i = 0; i < n; i++)
         in[i] *= x->x_hann[i];
     mayer_realfft(n, in);
     mayer_realifft(n, in);
     for (i = 0; i < n; i++)
         out[i] = (in[i] * x->x_hann[i]) * x->x_normalize;

     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, 
(t_int)sp[0]->s_n);
}

void *myfft_tilde_new(t_symbol *s)
{
     t_myfft_tilde *x = (t_myfft_tilde *)pd_new(myfft_tilde_class);

     outlet_new(&x->obj, &s_signal);

     make_hann(x);

     x->x_normalize = 1.0 / ((1024.0 * 3.0) / 2.0);

     return (void *)x;
}

void myfft_tilde_free(t_myfft_tilde *x)
{
     outlet_free(x->x_out);
     free(x->x_hann);
}

void myfft_tilde_setup(void)
{
     myfft_tilde_class = class_new(gensym("myfft~"), 
(t_newmethod)myfft_tilde_new,
         (t_method)myfft_tilde_free, sizeof(t_myfft_tilde), 
CLASS_DEFAULT, 0, 0);
     class_addmethod(myfft_tilde_class, (t_method)myfft_tilde_dsp, 
gensym("dsp"), 0);
     CLASS_MAINSIGNALIN(myfft_tilde_class, t_myfft_tilde, f);
}
```

On 10/17/23 10:00, IOhannes m zmoelnig wrote:
> On 10/17/23 08:31, Alexandros Drymonitis wrote:
>> The FFTW3 library is used by Pd
>
> it's not.
>
>> , and it is #included in the d_fft_fftw.c file. I have compiled Pd 
>> myself, and no such error occurred, so, this 
>
> Pd *could* use FFTW3, but you have to be very explicit if you want to 
> build Pd with FFTW3 (install fftw3 *and* configure Pd with 
> `--enable-fftw`)
>
> so in virtually all cases it uses the mayer-fft (which is built into 
> Pd, so doesn't require any external dependencies).
>
>> file must be somewhere in my system. Any idea how to solve this?
>
>
> install the fftw3 library (and headers).
>
> gfmadsr
> IOhannes
>
> _______________________________________________
> Pd-dev mailing list
> Pd-dev at lists.iem.at
> https://lists.puredata.info/listinfo/pd-dev





More information about the Pd-dev mailing list