Max 5 API Reference
00001 /** 00002 @file 00003 fftinfo~.c - communicate fft size and hop, etc... to the contents of a pfft~ subpatch 00004 00005 revised August 2001 00006 updated 3/22/09 ajm: new API 00007 00008 @ingroup examples 00009 */ 00010 00011 #include "ext.h" 00012 #include "ext_obex.h" 00013 #include "z_dsp.h" 00014 #include "r_pfft.h" // public pfft struct in r_pfft.h 00015 00016 typedef struct _fftinfo 00017 { 00018 t_pxobject x_obj; 00019 t_pfftpub *x_pfft; // pointer to owning fftpatcher struct 00020 00021 long x_fftsize; // size of input fft (in samples) 00022 long x_ffthop; // hop size for window advance 00023 long x_n; // vector size (half of fft size if fullspect = 0) 00024 int x_fullspect; // if full spectra are used 00025 00026 void *x_out[4]; // array of outlets 00027 00028 } t_fftinfo; 00029 00030 void fftinfo_bang(t_fftinfo *x); 00031 void fftinfo_dsp(t_fftinfo *x, t_signal **sp, short *count); 00032 void fftinfo_assist(t_fftinfo *x, void *b, long m, long a, char *s); 00033 void *fftinfo_new(t_symbol *s, short ac, t_atom *av); 00034 00035 t_symbol *ps_spfft; 00036 00037 void *fftinfo_class; 00038 00039 int fftinfo_warning; // so it only posts a warning once to the Max window if not inside a pfft 00040 00041 00042 int main(void) 00043 { 00044 t_class *c; 00045 00046 c = class_new("fftinfo~", (method)fftinfo_new, (method)dsp_free, (short)sizeof(t_fftinfo), 0L, A_GIMME, 0); 00047 class_addmethod(c, (method)fftinfo_assist, "assist", A_CANT, 0); 00048 class_addmethod(c, (method)fftinfo_dsp, "dsp", A_CANT, 0); 00049 class_addmethod(c, (method)fftinfo_bang, "bang", 0); 00050 00051 class_dspinit(c); 00052 class_register(CLASS_BOX, c); 00053 fftinfo_class = c; 00054 00055 ps_spfft = gensym("__pfft~__"); // owning pfft~ is bound to this while patch is loaded 00056 fftinfo_warning = 1; 00057 00058 return 0; 00059 } 00060 00061 void fftinfo_bang(t_fftinfo *x) 00062 { 00063 if (x->x_pfft) { 00064 // just output current values 00065 outlet_int(x->x_out[3], x->x_fullspect); // fullspect flag 00066 outlet_int(x->x_out[2], x->x_ffthop); 00067 outlet_int(x->x_out[1], x->x_n); 00068 outlet_int(x->x_out[0], x->x_fftsize); 00069 } 00070 else if (fftinfo_warning) { 00071 object_warn((t_object *)x, "fftinfo~ only functions inside a pfft~",0); 00072 fftinfo_warning = 0; 00073 } 00074 } 00075 00076 void fftinfo_dsp(t_fftinfo *x, t_signal **sp, short *count) 00077 { 00078 if (x->x_pfft) { 00079 outlet_int(x->x_out[3], (x->x_fullspect = (x->x_pfft->x_fullspect)?1:0)); 00080 outlet_int(x->x_out[2], (x->x_ffthop = x->x_pfft->x_ffthop)); 00081 outlet_int(x->x_out[1], (x->x_n = sp[0]->s_n)); 00082 outlet_int(x->x_out[0], (x->x_fftsize = x->x_pfft->x_fftsize)); 00083 } 00084 else if (fftinfo_warning) { 00085 object_warn((t_object *)x, "fftinfo~ only functions inside a pfft~",0); 00086 fftinfo_warning = 0; 00087 } 00088 } 00089 00090 void fftinfo_assist(t_fftinfo *x, void *b, long m, long a, char *s) 00091 { 00092 if (m == ASSIST_INLET) 00093 sprintf(s,"(signal) Dummy"); 00094 else { 00095 switch (a) { 00096 case 0: sprintf(s,"(int) FFT Frame Size"); break; 00097 case 1: sprintf(s,"(int) Spectral Frame Size"); break; 00098 case 2: sprintf(s,"(int) FFT Hop Size"); break; 00099 case 3: sprintf(s,"(int) Full Spectrum Flag (0/1)"); break; 00100 } 00101 } 00102 } 00103 00104 void *fftinfo_new(t_symbol *s, short ac, t_atom *av) 00105 { 00106 t_fftinfo *x; 00107 00108 x = object_alloc(fftinfo_class); 00109 dsp_setup((t_pxobject *)x,1); 00110 00111 x->x_out[3] = intout(x); // fullspect flag 00112 x->x_out[2] = intout(x); 00113 x->x_out[1] = intout(x); 00114 x->x_out[0] = intout(x); 00115 00116 x->x_fftsize = x->x_ffthop = x->x_fullspect = x->x_n = 0; // init to 0 00117 x->x_obj.z_misc = Z_PUT_FIRST; 00118 x->x_pfft = (t_pfftpub *)ps_spfft->s_thing; 00119 00120 if (x->x_pfft) { 00121 // these are now correctly initialized in pfft~ when patch is laoded 00122 x->x_fftsize = x->x_pfft->x_fftsize; 00123 x->x_ffthop = x->x_pfft->x_ffthop; 00124 x->x_fullspect = (x->x_pfft->x_fullspect) ? 1 : 0; 00125 // get temp values for x_n until we turn on dsp and find the real ones 00126 if (x->x_fullspect) 00127 x->x_n = x->x_fftsize; // in "fullspect mode", frame size = fft size 00128 else 00129 x->x_n = x->x_fftsize/2; // in "regular mode", frame size = fft size / 2 00130 } 00131 00132 return (x); 00133 } 00134 00135 00136
Copyright © 2008, Cycling '74