diff options
author | Jamie Bullock <jamie@postlude.co.uk> | 2007-12-29 17:33:17 +0000 |
---|---|---|
committer | Jamie Bullock <jamie@postlude.co.uk> | 2007-12-29 17:33:17 +0000 |
commit | eb32acabd365e47e36863ee737505db463bd9f91 (patch) | |
tree | 5258b5b6e2ae35fc3c72b356f6e26f37660bf6c1 /examples | |
parent | 2e66bd6092fe93ca7fa953c4af9d0e16bbf69905 (diff) | |
download | LibXtract-eb32acabd365e47e36863ee737505db463bd9f91.tar.gz LibXtract-eb32acabd365e47e36863ee737505db463bd9f91.tar.bz2 LibXtract-eb32acabd365e47e36863ee737505db463bd9f91.zip |
- PD example brought in line with new delta features and subframe function
- subframe-test.pd added
- fix to a_blockswap~.pd
Diffstat (limited to 'examples')
-rw-r--r-- | examples/puredata/subframe-test.pd | 131 | ||||
-rw-r--r-- | examples/puredata/xtract/a_blockswap~.pd | 64 | ||||
-rw-r--r-- | examples/puredata/xtract~.c | 115 |
3 files changed, 258 insertions, 52 deletions
diff --git a/examples/puredata/subframe-test.pd b/examples/puredata/subframe-test.pd new file mode 100644 index 0000000..3a835a5 --- /dev/null +++ b/examples/puredata/subframe-test.pd @@ -0,0 +1,131 @@ +#N canvas 667 50 557 639 10; +#X obj 263 -160 xtract~ subframe windowed 64; +#X obj 442 -125 tabsend~ windowed; +#N canvas 0 0 450 300 (subpatch) 0; +#X array windowed 64 float 5; +#A 0 0 0.00988792 0.0386044 0.0571912 0.0189603 -0.101949 -0.277669 +-0.42422 -0.437499 -0.251716 0.11162 0.534831 0.846232 0.89682 0.634185 +0.135697 -0.418906 -0.823923 -0.937159 -0.739218 -0.334947 0.101471 +0.40821 0.503437 0.407727 0.215338 0.0353621 -0.0632974 -0.0748772 +-0.0405181 -0.00868179 -3.27457e-15 0 0.00657018 0.0386642 0.0864644 +0.104272 0.0386758 -0.128569 -0.351139 -0.525142 -0.535095 -0.31781 +0.0907861 0.554834 0.890148 0.946246 0.679244 0.177795 -0.372091 -0.768033 +-0.878652 -0.69562 -0.326984 0.0615718 0.325607 0.401064 0.317179 0.162825 +0.0298987 -0.0329445 -0.0328739 -0.0102196 -6.65005e-15; +#X coords 0 1 63 -1 200 140 1; +#X restore 46 -552 graph; +#X obj 264 -125 xtract~ subframe spectrum 64; +#N canvas 0 0 450 300 (subpatch) 0; +#X array sf_mags1 16 float 5; +#A 0 0.00733392 0.14449 0.240482 0.109887 0.00135916 0.000113993 5.63786e-05 +7.59283e-05 7.22785e-05 6.48168e-05 5.62613e-05 5.20935e-05 4.72571e-05 +4.40774e-05 4.34346e-05 1.76297e-06; +#X coords 0 1 15 -1 200 140 1; +#X restore 261 -551 graph; +#N canvas 0 0 450 300 (subpatch) 0; +#X array sf_mags2 32 float 5; +#A 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0077164 0.1443 0.240599 0.109809 +0.00131069 0.00011119 0.000100841 0.00010453 9.17035e-05 7.68611e-05 +6.53814e-05 5.45444e-05 4.76852e-05 4.18391e-05 4.00649e-05 1.43191e-06 +; +#X coords 0 1 31 -1 200 140 1; +#X restore 259 -389 graph; +#N canvas 0 0 450 300 (subpatch) 0; +#X array both 35 float 5; +#A 0 0.00733392 0.14449 0.240482 0.109887 0.00135916 0.000113993 5.63786e-05 +7.59283e-05 7.22785e-05 6.48168e-05 5.62613e-05 5.20935e-05 4.72571e-05 +4.40774e-05 4.34346e-05 1.76297e-06 0.0077164 0.1443 0.240599 0.109809 +0.00131069 0.00011119 0.000100841 0.00010453 9.17035e-05 7.68611e-05 +6.53814e-05 5.45444e-05 4.76852e-05 4.18391e-05 4.00649e-05 1.43191e-06 +0 0 0; +#X coords 0 1 34 -1 200 140 1; +#X restore 46 -393 graph; +#N canvas 18 175 447 500 get_mags 0; +#X obj 71 265 +~; +#X obj 72 233 tabreceive~ sf_mags1; +#X obj 221 233 tabreceive~ sf_mags2; +#X obj 101 30 tabsend~ sf_mags1; +#X obj 70 86 tabsend~ temp; +#X obj 69 124 tabreceive~ temp; +#X obj 70 175 tabsend~ sf_mags2; +#X obj 70 302 outlet~; +#X obj 70 -10 inlet~; +#X obj 70 59 a_blockswap~ 64; +#X obj 69 151 a_blockswap~ 32; +#N canvas 0 0 450 300 graph4 0; +#X array temp 16 float 5; +#A 0 0.0077164 0.1443 0.240599 0.109809 0.00131069 0.00011119 0.000100841 +0.00010453 9.17035e-05 7.68611e-05 6.53814e-05 5.45444e-05 4.76852e-05 +4.18391e-05 4.00649e-05 1.43191e-06; +#X coords 0 1 15 -1 200 140 1; +#X restore 226 -6 graph; +#X connect 0 0 7 0; +#X connect 1 0 0 0; +#X connect 2 0 0 1; +#X connect 5 0 10 0; +#X connect 8 0 3 0; +#X connect 8 0 9 0; +#X connect 9 0 4 0; +#X connect 10 0 6 0; +#X restore 263 -94 pd get_mags; +#N canvas 0 0 450 300 graph4 0; +#X array diff 16 float 5; +#A 0 -0.000382476 0.000189289 -0.000116706 7.71508e-05 4.8466e-05 2.80288e-06 +-4.44625e-05 -2.86015e-05 -1.9425e-05 -1.20443e-05 -9.12002e-06 -2.45091e-06 +-4.28088e-07 2.23831e-06 3.36968e-06 3.31062e-07; +#X coords 0 1 15 -1 200 140 1; +#X restore 46 -234 graph; +#N canvas 6 433 450 300 diff 0; +#X obj 134 136 tabsend~ diff; +#X obj 134 49 tabreceive~ both; +#X obj 135 78 xtract~ difference_vector 32; +#X obj 348 10 block~ 32; +#X connect 1 0 2 0; +#X connect 2 0 0 0; +#X restore 260 -43 pd diff; +#N canvas 3 50 450 300 flux 0; +#X obj 143 17 tabreceive~ diff; +#X obj 371 -13 block~ 16; +#X obj 144 53 xtract~ flux 16; +#X obj 144 90 outlet; +#X connect 0 0 2 0; +#X connect 2 0 3 0; +#X restore 262 -16 pd flux; +#X obj 262 -70 tabsend~ both; +#N canvas 9 100 467 310 source 0; +#X obj 162 -117 noise~; +#X obj 100 -40 *~; +#X obj 105 140 hsl 100 10 0 1 0 0 vol vol-set empty -2 -6 0 10 -204786 +-1 -1 9900 1; +#X msg 212 -58 1; +#X obj 115 -94 r vol; +#X obj 161 -40 *~; +#X obj 212 -89 t b f; +#X obj 225 -30 -; +#X obj 101 20 outlet~; +#X text 111 118 noise <-> sine; +#X obj 336 -87 loadbang; +#X obj 100 -115 osc~ 4000; +#X msg 336 -61 \; vol 1 \; vol-set 1; +#X connect 0 0 5 0; +#X connect 1 0 8 0; +#X connect 3 0 7 0; +#X connect 4 0 1 1; +#X connect 4 0 6 0; +#X connect 5 0 8 0; +#X connect 6 0 3 0; +#X connect 6 1 7 1; +#X connect 7 0 5 1; +#X connect 10 0 12 0; +#X connect 11 0 1 0; +#X coords 0 -1 1 1 110 60 1 100 100; +#X restore 263 -231 pd source; +#X floatatom 262 40 5 0 0 0 spectral_flux - -; +#X obj 262 7 a_bavg 128; +#X connect 0 0 1 0; +#X connect 0 0 3 0; +#X connect 3 0 7 0; +#X connect 7 0 11 0; +#X connect 10 0 14 0; +#X connect 12 0 0 0; +#X connect 14 0 13 0; diff --git a/examples/puredata/xtract/a_blockswap~.pd b/examples/puredata/xtract/a_blockswap~.pd index 959ecfd..65dbd10 100644 --- a/examples/puredata/xtract/a_blockswap~.pd +++ b/examples/puredata/xtract/a_blockswap~.pd @@ -1,29 +1,43 @@ -#N canvas 670 208 475 328 10; -#X obj 70 159 samplerate~; -#X obj 70 223 phasor~; -#X msg 163 159 0.5; +#N canvas 415 243 512 595 10; +#X obj 141 161 samplerate~; +#X obj 141 401 phasor~; #X obj 23 10 inlet~; -#X obj 23 34 tabsend~ input; -#X obj 385 4 table input; -#X obj 76 272 tabread~ input; -#X obj 75 299 outlet~; -#X obj 70 194 / \$1; +#X obj 140 523 outlet~; #X obj 141 78 loadbang; #X text 232 72 Clone of zexy blockswap~; #X text 232 90 First argument gives block size; -#X msg 209 158 \; input resize \$1; -#X obj 141 109 t b b b; -#X obj 75 249 *~ \$1; -#X obj 209 135 f \$1; -#X connect 0 0 8 0; -#X connect 1 0 14 0; -#X connect 2 0 1 1; -#X connect 3 0 4 0; -#X connect 6 0 7 0; -#X connect 8 0 1 0; -#X connect 9 0 13 0; -#X connect 13 0 0 0; -#X connect 13 1 2 0; -#X connect 13 2 15 0; -#X connect 14 0 6 0; -#X connect 15 0 12 0; +#X obj 245 167 f \$1; +#X obj 245 343 /; +#X obj 141 109 t b b; +#X obj 284 264 / 2; +#X obj 245 265 t b a; +#X obj 245 304 f; +#X obj 245 213 - 1; +#X obj 141 332 / \$1; +#X obj 140 473 *~ \$1; +#X obj 385 4 table \$0-input; +#X obj 23 34 tabsend~ \$0-input; +#X msg 321 315 \; \$1-input resize \$2; +#X obj 321 265 pack \$0 \$1; +#X obj 245 189 t a a b; +#X obj 141 496 tabread~ \$0-input; +#X connect 0 0 14 0; +#X connect 1 0 15 0; +#X connect 2 0 17 0; +#X connect 4 0 9 0; +#X connect 7 0 20 0; +#X connect 8 0 1 1; +#X connect 9 0 0 0; +#X connect 9 1 7 0; +#X connect 10 0 12 1; +#X connect 11 0 12 0; +#X connect 11 1 8 1; +#X connect 12 0 8 0; +#X connect 13 0 11 0; +#X connect 14 0 1 0; +#X connect 15 0 21 0; +#X connect 19 0 18 0; +#X connect 20 0 13 0; +#X connect 20 1 10 0; +#X connect 20 2 19 0; +#X connect 21 0 3 0; diff --git a/examples/puredata/xtract~.c b/examples/puredata/xtract~.c index f82aab6..7a33993 100644 --- a/examples/puredata/xtract~.c +++ b/examples/puredata/xtract~.c @@ -46,11 +46,13 @@ typedef struct _tracked_memory { typedef struct _xtract { t_object x_obj; t_float f; - t_int feature; - t_int feature_type; + t_float *window; + t_int feature, + is_scalar, + is_subframe, + init_blocksize, + done_init; t_symbol *feature_name; - t_int init_blocksize; - t_int done_init; tracked_memory memory; void *argv; } t_xtract_tilde; @@ -59,12 +61,12 @@ static t_int *xtract_perform(t_int *w) { t_sample *in = (t_sample *)(w[1]); t_xtract_tilde *x = (t_xtract_tilde *)(w[2]); t_int N = (t_int)(w[3]); - t_int return_code = 0; + t_int rv = 0; float result = 0; - return_code = xtract[x->feature]((float *)in, N, x->argv, &result); + rv = xtract[x->feature]((float *)in, N, x->argv, &result); - if(return_code == XTRACT_FEATURE_NOT_IMPLEMENTED) + if(rv == XTRACT_FEATURE_NOT_IMPLEMENTED) pd_error(x, "Feature not implemented"); /* set nan, inf or -inf to 0 */ @@ -81,7 +83,7 @@ static t_int *xtract_perform_vector(t_int *w) { t_float *tmp_in, *tmp_out; t_xtract_tilde *x = (t_xtract_tilde *)(w[3]); t_int N = (t_int)(w[4]), n; - t_int return_code = 0; + t_int rv = 0; if(N != x->init_blocksize && x->done_init){ error("xtract~ %s: Blocksize mismatch, try specifying the blocksize as a second argument", x->feature_name->s_name); @@ -96,12 +98,22 @@ static t_int *xtract_perform_vector(t_int *w) { if(x->feature == XTRACT_PEAK_SPECTRUM || x->feature == XTRACT_LPC) N >>= 1; - return_code = xtract[x->feature](tmp_in, N, x->argv, tmp_out); + if(x->is_subframe){ + + rv = xtract_features_from_subframes(tmp_in, N, x->feature, + x->argv, tmp_out); + } + else{ + + rv = xtract[x->feature](tmp_in, N, x->argv, tmp_out); - if(return_code == XTRACT_FEATURE_NOT_IMPLEMENTED) + } + + if(rv == XTRACT_FEATURE_NOT_IMPLEMENTED) pd_error(x, "Feature not implemented"); - while(n--) out[n] = tmp_out[n]; + while(n--) + out[n] = tmp_out[n]; freebytes(tmp_in, N * sizeof(t_float)); freebytes(tmp_out, N * sizeof(t_float)); @@ -111,7 +123,7 @@ static t_int *xtract_perform_vector(t_int *w) { static void xtract_dsp(t_xtract_tilde *x, t_signal **sp) { - if(x->feature_type == XTRACT_VECTOR) + if(!x->is_scalar) dsp_add(xtract_perform_vector, 4, sp[0]->s_vec, sp[1]->s_vec, x, sp[0]->s_n); @@ -123,15 +135,20 @@ static void *xtract_new(t_symbol *me, t_int argc, t_atom *argv) { t_xtract_tilde *x = (t_xtract_tilde *)pd_new(xtract_class); xtract_mel_filter *mf; - t_int n, N, f, F, n_args, type; + t_int n, N, M, f, F, + n_args, + type; t_float *argv_max; + t_symbol *arg1; xtract_function_descriptor_t *fd; - char *p_name, *p_desc, *author; + char *p_name, + *p_desc, + *author; int year; p_name = p_desc = author = NULL; - n_args = type = x->feature = 0; + n_args = type = 0; f = F = XTRACT_FEATURES; @@ -139,13 +156,29 @@ static void *xtract_new(t_symbol *me, t_int argc, t_atom *argv) { x->argv = NULL; x->done_init = 0; + x->is_scalar = 0; + x->is_subframe = 0; + x->feature = -1; - if(argc) - x->feature_name = atom_getsymbol(argv); - if(argc > 1) - N = atom_getint(&argv[1]); + /* Parse arguments */ + if(argc){ + arg1 = atom_getsymbol(argv); + if(arg1 == gensym("subframe")) + x->is_subframe = 1; + else + x->feature_name = atom_getsymbol(argv); + } + if(argc > 1){ + if(x->is_subframe) + x->feature_name = atom_getsymbol(argv+1); + else + N = atom_getint(argv+1); + } + if(argc > 2) + N = atom_getint(argv+2); x->init_blocksize = N; + M = N >> 1; /* get function descriptors */ fd = (xtract_function_descriptor_t *)xtract_make_descriptors(); @@ -159,6 +192,9 @@ static void *xtract_new(t_symbol *me, t_int argc, t_atom *argv) { } } + if(x->feature == -1) + post("xtract~: feature not found: %s", x->feature_name->s_name); + /* allocate memory for feature arguments */ n_args = fd[f].argc; type = fd[f].argv.type; @@ -200,6 +236,11 @@ static void *xtract_new(t_symbol *me, t_int argc, t_atom *argv) { else post("xtract~: No arguments given"); + /* Adjust frame size if we are using subframe features */ + if(x->is_subframe) + N = M; + + post("xtract~: window size: %d", N); /* do init if needed */ if(x->feature == XTRACT_MFCC){ @@ -223,6 +264,11 @@ static void *xtract_new(t_symbol *me, t_int argc, t_atom *argv) { xtract_init_bark(N, NYQUIST, x->argv); x->done_init = 1; } + else if(x->feature == XTRACT_WINDOWED){ + x->window = xtract_init_window(N, XTRACT_HANN); + x->argv = x->window; + x->done_init = 1; + } /* Initialise fft_plan if required */ if(x->feature == XTRACT_AUTOCORRELATION_FFT || @@ -232,6 +278,10 @@ static void *xtract_new(t_symbol *me, t_int argc, t_atom *argv) { x->done_init = 1; } + if(fd[f].is_scalar) + x->is_scalar = 1; + +/* if(x->feature == XTRACT_AUTOCORRELATION || x->feature == XTRACT_AUTOCORRELATION_FFT || x->feature == XTRACT_MFCC || x->feature == XTRACT_AMDF || @@ -241,23 +291,31 @@ static void *xtract_new(t_symbol *me, t_int argc, t_atom *argv) { x->feature == XTRACT_PEAK_SPECTRUM || x->feature == XTRACT_HARMONIC_SPECTRUM || x->feature == XTRACT_LPC || - x->feature == XTRACT_LPCC) + x->feature == XTRACT_LPCC || + x->feature == XTRACT_WINDOWED) x->feature_type = XTRACT_VECTOR; - - else if (x->feature == XTRACT_FLUX || x->feature == XTRACT_ATTACK_TIME || - x->feature == XTRACT_DECAY_TIME || x->feature == XTRACT_DELTA) - x->feature_type = XTRACT_DELTA; - + */ + /* else if (x->feature == XTRACT_FLUX || x->feature == XTRACT_ATTACK_TIME || + x->feature == XTRACT_DECAY_TIME || x->feature == XTRACT_DIFFERENCE_VECTOR) + x->feature_type = XTRACT_DELTA; */ +/* else x->feature_type = XTRACT_SCALAR; +*/ /* argv through right inlet */ inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("list"), gensym("list")); /* if feature is vector, create signal out */ - if(x->feature_type == XTRACT_VECTOR) outlet_new(&x->x_obj, &s_signal); + if(!x->is_scalar) + outlet_new(&x->x_obj, &s_signal); /* otherwise: float */ - else outlet_new(&x->x_obj, &s_float); + else + outlet_new(&x->x_obj, &s_float); + + if(x->is_scalar && x->is_subframe) + post( + "xtract~: warning: subframes not yet supported for scalar features"); /* free the function descriptors */ xtract_free_descriptors(fd); @@ -303,6 +361,9 @@ static void xtract_tilde_free(t_xtract_tilde *x) { if(x->argv != NULL && x->memory.argv) freebytes(x->argv, x->memory.argv); + + if(x->window != NULL) + xtract_free_window(x->window); } void xtract_tilde_setup(void) { |