aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorJamie Bullock <jamie@postlude.co.uk>2007-10-06 16:36:00 +0000
committerJamie Bullock <jamie@postlude.co.uk>2007-10-06 16:36:00 +0000
commit7044486fdcc4d806f46c35ec4787ae48fa26c369 (patch)
tree06134837cf5be10309e18065700ae95592a6851f /examples
parent944e692ddd2862827821ef498dc6e5a570c26752 (diff)
downloadLibXtract-7044486fdcc4d806f46c35ec4787ae48fa26c369.tar.gz
LibXtract-7044486fdcc4d806f46c35ec4787ae48fa26c369.tar.bz2
LibXtract-7044486fdcc4d806f46c35ec4787ae48fa26c369.zip
Removed fftw_plan from xtraction functions. Created new init function xtract_init_fft() for creating plans, which have global scope. Updated examples to reflect the change. New configure option: --with-fft_optimisation (0 = FFTW_ESTIMATE, 1 = FFTW_MEASURE, 2 = FFTW_PATIENT).
Diffstat (limited to 'examples')
-rw-r--r--examples/MSP/xtract~.c27
-rw-r--r--examples/puredata/simple-example.pd30
-rw-r--r--examples/puredata/xtract/f0.pd30
-rw-r--r--examples/puredata/xtract/xtract-help.pd53
-rw-r--r--examples/puredata/xtract~.c36
5 files changed, 118 insertions, 58 deletions
diff --git a/examples/MSP/xtract~.c b/examples/MSP/xtract~.c
index 11a40f5..69b7f69 100644
--- a/examples/MSP/xtract~.c
+++ b/examples/MSP/xtract~.c
@@ -40,6 +40,9 @@ typedef struct _xtract {
void *outlet; /*Float outlet */
t_float f;
t_int feature;
+ t_symbol *feature_name;
+ t_int init_blocksize;
+ t_int done_init;
t_int feature_type;
tracked_memory memory;
void *argv;
@@ -75,6 +78,11 @@ static t_int *xtract_perform_vector(t_int *w) {
if(x->feature == XTRACT_PEAK_SPECTRUM)
N >>= 1;
+ if(N != x->init_blocksize && x->done_init){
+ post("xtract~ %s: Blocksize mismatch, try specifying the blocksize as a second argument", x->feature_name->s_name);
+ return (w+5);
+ }
+
n = N;
temp_in = (float *)getbytes(N * sizeof(float));
@@ -114,14 +122,12 @@ static void *xtract_tilde_new(t_symbol *me, t_int argc, t_atom *argv) {
t_symbol *tmp;
t_xtract_tilde *x = (t_xtract_tilde *)newobject(xtract_tilde_class);
xtract_mel_filter *mf;
- t_int n, N, f, F, n_args, type, blocksize;
+ t_int n, N, f, F, n_args, type;
t_float *argv_max;
xtract_function_descriptor_t *fd;
char *p_name, *p_desc, *author;
int year;
-
- blocksize = BLOCKSIZE; /* Default */
tmp = NULL;
p_name = p_desc = author = NULL;
@@ -129,16 +135,17 @@ static void *xtract_tilde_new(t_symbol *me, t_int argc, t_atom *argv) {
f = F = XTRACT_FEATURES;
- /* N = BLOCKSIZE;*/
+ N = BLOCKSIZE;
x->argv = NULL;
+ x->done_init = 0;
if(argc)
tmp = argv[0].a_w.w_sym; /*atom_getsymbol(argv); */
if(argc > 1)
- blocksize = (t_int)argv[1].a_w.w_long;
+ N = (t_int)argv[1].a_w.w_long;
- N = blocksize;
+ x->init_blocksize = N;
/* get function descriptors */
fd = (xtract_function_descriptor_t *)xtract_make_descriptors();
@@ -214,6 +221,14 @@ static void *xtract_tilde_new(t_symbol *me, t_int argc, t_atom *argv) {
else if(x->feature == XTRACT_BARK_COEFFICIENTS)
xtract_init_bark(N, NYQUIST, x->argv);
+ /* Initialise fft_plan if required */
+ if(x->feature == XTRACT_AUTOCORRELATION_FFT ||
+ x->feature == XTRACT_SPECTRUM ||
+ x->feature == XTRACT_DCT){
+ xtract_init_fft(N, x->feature);
+ x->done_init = 1;
+ }
+
if(x->feature == XTRACT_AUTOCORRELATION ||
x->feature == XTRACT_AUTOCORRELATION_FFT ||
x->feature == XTRACT_MFCC || x->feature == XTRACT_AMDF ||
diff --git a/examples/puredata/simple-example.pd b/examples/puredata/simple-example.pd
index 510fb2f..80e8761 100644
--- a/examples/puredata/simple-example.pd
+++ b/examples/puredata/simple-example.pd
@@ -1,8 +1,26 @@
-#N canvas 0 0 450 300 10;
+#N canvas 5 48 450 300 10;
+#X obj 154 42 osc~ 440;
+#X floatatom 154 180 8 0 0 0 - - -;
+#N canvas 619 86 450 300 spectral_mean 1;
#X obj 144 80 xtract~ spectrum;
-#X obj 154 26 osc~ 440;
-#X obj 145 129 xtract~ spectral_mean;
-#X floatatom 146 184 5 0 0 0 - - -;
+#X obj 346 21 block~ 1024;
+#X obj 145 47 inlet~;
+#X obj 145 190 outlet;
+#X obj 145 129 xtract~ spectral_centroid;
+#X msg 269 57 list \$1;
+#X msg 270 11 44100;
+#X obj 270 33 / 1024;
+#X obj 67 130 print~;
+#X obj 73 104 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
+-1;
+#X connect 0 0 4 0;
+#X connect 0 0 8 0;
+#X connect 2 0 0 0;
+#X connect 4 0 3 0;
+#X connect 5 0 0 1;
+#X connect 6 0 7 0;
+#X connect 7 0 5 0;
+#X connect 9 0 8 0;
+#X restore 154 115 pd spectral_mean;
#X connect 0 0 2 0;
-#X connect 1 0 0 0;
-#X connect 2 0 3 0;
+#X connect 2 0 1 0;
diff --git a/examples/puredata/xtract/f0.pd b/examples/puredata/xtract/f0.pd
index 47dc649..6ea0714 100644
--- a/examples/puredata/xtract/f0.pd
+++ b/examples/puredata/xtract/f0.pd
@@ -53,7 +53,7 @@
#X connect 4 0 3 0;
#X connect 4 0 1 1;
#X restore 587 66 pd noise;
-#N canvas 135 136 496 580 pda 0;
+#N canvas 554 114 496 580 pda 0;
#X obj 99 100 xtract~ f0;
#X obj 197 6 inlet~;
#X msg 361 203 list \$1;
@@ -79,7 +79,6 @@
#X msg 60 48 list \$1;
#X obj 274 59 r \$0-window-gen;
#X obj 274 80 a_hann 2048;
-#X obj 147 195 xtract~ spectrum;
#X obj 148 222 xtract~ peak_spectrum;
#X obj 149 315 xtract~ lowest_value;
#X obj 150 243 a_blockswap~ 2048;
@@ -87,15 +86,16 @@
#X obj 358 150 / 2048;
#X msg 358 171 \$1 10;
#X obj 356 105 r \$0-peak-args;
+#X obj 147 195 xtract~ spectrum 2048;
#X connect 0 0 2 0;
#X connect 0 0 8 0;
#X connect 0 0 9 0;
#X connect 0 0 11 0;
#X connect 1 0 19 0;
-#X connect 2 0 27 1;
-#X connect 3 0 25 0;
+#X connect 2 0 26 1;
+#X connect 3 0 32 0;
#X connect 4 0 22 0;
-#X connect 7 0 27 0;
+#X connect 7 0 26 0;
#X connect 8 0 9 1;
#X connect 9 0 12 0;
#X connect 10 0 12 0;
@@ -112,14 +112,14 @@
#X connect 22 0 0 1;
#X connect 23 0 24 0;
#X connect 24 0 3 1;
-#X connect 25 0 26 0;
-#X connect 26 0 28 0;
-#X connect 27 0 10 0;
-#X connect 28 0 5 0;
+#X connect 25 0 27 0;
+#X connect 26 0 10 0;
+#X connect 27 0 5 0;
+#X connect 28 0 29 0;
#X connect 29 0 30 0;
-#X connect 30 0 31 0;
-#X connect 31 0 26 1;
-#X connect 32 0 29 0;
+#X connect 30 0 25 1;
+#X connect 31 0 28 0;
+#X connect 32 0 25 0;
#X restore 357 262 pd pda;
#N canvas 0 0 596 417 d_saw 0;
#X obj 382 176 phasor~;
@@ -250,14 +250,14 @@
#X obj 11 -226 cnv 15 500 200 empty empty PDA_comparison 20 12 0 14
-261681 -66577 0;
#X obj 34 -94 hsl 128 15 2 2.05 0 0 \$0-inharmonicity empty fm-inharmonicity
--2 -6 0 8 -225271 -1 -1 800 1;
+-2 -6 0 8 -225271 -1 -1 0 1;
#X obj 34 -50 hsl 128 15 0 0.5 0 0 \$0-noisiness empty noisiness -2
-6 0 8 -225271 -1 -1 0 1;
#X obj 33 -135 hsl 128 15 30 3000 0 0 \$0-fund empty f0 -2 -6 0 8 -225271
--1 -1 300 1;
+-1 -1 0 1;
#X obj 32 -172 tgl 15 0 \$0-sine empty sine 0 -6 0 8 -225280 -1 -1
0 1;
-#X obj 73 -172 tgl 15 0 \$0-fm empty fm 0 -6 0 8 -225280 -1 -1 1 1
+#X obj 73 -172 tgl 15 0 \$0-fm empty fm 0 -6 0 8 -225280 -1 -1 0 1
;
#X obj 110 -172 tgl 15 0 \$0-saw empty saw 0 -6 0 8 -225280 -1 -1 0
1;
diff --git a/examples/puredata/xtract/xtract-help.pd b/examples/puredata/xtract/xtract-help.pd
index 6a7435b..8e0959b 100644
--- a/examples/puredata/xtract/xtract-help.pd
+++ b/examples/puredata/xtract/xtract-help.pd
@@ -6,34 +6,37 @@ library: LibXtract. Please refer to the documentation at libxtract.sourceforge.n
\, for a full explanation of the library and the functions it provides.
Only the operation of the PD external will be explained here along
with a few use case scenarios.;
-#X text 20 148 [xtract~] must always be called with one argument \,
-in the following form: [xtract~ <feature>] \, where <feature> is a
-feature supported by the LibXtract library. A complete list of features
-may be obtained by sending the external a |help( message:;
-#X obj 27 262 xtract~;
-#X msg 27 233 help;
-#X text 26 298 Other than this help message \, the data sent to the
+#X obj 27 299 xtract~;
+#X msg 27 270 help;
+#X text 27 328 Other than this help message \, the data sent to the
left inlet should always be a 'signal' (i.e. audio rate). This is the
data from a which a given feature will be extracted.;
-#X obj 182 490 xtract~ mean;
-#X floatatom 132 586 10 0 0 0 - - -;
-#X floatatom 253 523 5 0 0 0 - - -;
-#X msg 182 522 list \$1;
-#X obj 132 556 xtract~ variance;
-#X obj 181 466 phasor~ 0.1;
-#X text 39 641 Below are some possible use cases (click to open):;
-#X text 26 352 The outlet may be a scalar (control rate) \, or a vector
+#X obj 183 520 xtract~ mean;
+#X floatatom 133 616 10 0 0 0 - - -;
+#X floatatom 254 553 5 0 0 0 - - -;
+#X msg 183 552 list \$1;
+#X obj 133 586 xtract~ variance;
+#X obj 182 496 phasor~ 0.1;
+#X text 40 671 Below are some possible use cases (click to open):;
+#X text 27 382 The outlet may be a scalar (control rate) \, or a vector
(audio rate) \, depending on the nature of the feature that is being
extracted.;
-#X obj 42 665 f0;
-#X obj 83 665 mfcc;
-#X text 27 405 Any additional arguments that need to be passed to the
+#X obj 43 695 f0;
+#X obj 84 695 mfcc;
+#X text 28 435 Any additional arguments that need to be passed to the
feature extraction function must be provided as a list to the right
inlet \, e.g.;
-#X connect 5 0 4 0;
-#X connect 7 0 9 0;
-#X connect 7 0 10 0;
-#X connect 10 0 11 1;
-#X connect 11 0 8 0;
-#X connect 12 0 7 0;
-#X connect 12 0 11 0;
+#X text 24 231 A complete list of features may be obtained by sending
+the external a |help( message:;
+#X text 20 148 [xtract~] must always be called with one argument \,
+in the following form: [xtract~ <feature>] \, where <feature> is a
+feature supported by the LibXtract library.;
+#X text 21 198 An optional second argument can be used to explicitly
+set the blocksize for FFT-based features;
+#X connect 4 0 3 0;
+#X connect 6 0 8 0;
+#X connect 6 0 9 0;
+#X connect 9 0 10 1;
+#X connect 10 0 7 0;
+#X connect 11 0 6 0;
+#X connect 11 0 10 0;
diff --git a/examples/puredata/xtract~.c b/examples/puredata/xtract~.c
index 3f07cd3..e58aea0 100644
--- a/examples/puredata/xtract~.c
+++ b/examples/puredata/xtract~.c
@@ -48,6 +48,9 @@ typedef struct _xtract {
t_float f;
t_int feature;
t_int feature_type;
+ t_symbol *feature_name;
+ t_int init_blocksize;
+ t_int done_init;
tracked_memory memory;
void *argv;
} t_xtract_tilde;
@@ -72,6 +75,7 @@ static t_int *xtract_perform(t_int *w) {
}
static t_int *xtract_perform_vector(t_int *w) {
+
t_sample *in = (t_sample *)(w[1]);
t_sample *out = (t_sample *)(w[2]);
t_float *tmp_in, *tmp_out;
@@ -79,6 +83,11 @@ static t_int *xtract_perform_vector(t_int *w) {
t_int N = (t_int)(w[4]), n;
t_int return_code = 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);
+ return (w+5);
+ }
+
n = N;
tmp_in = copybytes(in, N * sizeof(t_float));
@@ -112,7 +121,6 @@ static void xtract_dsp(t_xtract_tilde *x, t_signal **sp) {
static void *xtract_new(t_symbol *me, t_int argc, t_atom *argv) {
- t_symbol *tmp;
t_xtract_tilde *x = (t_xtract_tilde *)pd_new(xtract_class);
xtract_mel_filter *mf;
t_int n, N, f, F, n_args, type;
@@ -130,8 +138,14 @@ static void *xtract_new(t_symbol *me, t_int argc, t_atom *argv) {
N = BLOCKSIZE;
x->argv = NULL;
+ x->done_init = 0;
- tmp = atom_getsymbol(argv);
+ if(argc)
+ x->feature_name = atom_getsymbol(argv);
+ if(argc > 1)
+ N = atom_getint(&argv[1]);
+
+ x->init_blocksize = N;
/* get function descriptors */
fd = (xtract_function_descriptor_t *)xtract_make_descriptors();
@@ -139,7 +153,7 @@ static void *xtract_new(t_symbol *me, t_int argc, t_atom *argv) {
/* iterate over descriptors */
while(f--){
/* map creation arg to feature */
- if(tmp == gensym(fd[f].algo.name)){
+ if(x->feature_name == gensym(fd[f].algo.name)){
x->feature = f;
break;
}
@@ -170,7 +184,6 @@ static void *xtract_new(t_symbol *me, t_int argc, t_atom *argv) {
x->memory.argv = 0;
}
-
p_name = fd[f].algo.p_name;
p_desc = fd[f].algo.p_desc;
author = fd[f].algo.author;
@@ -203,10 +216,21 @@ static void *xtract_new(t_symbol *me, t_int argc, t_atom *argv) {
mf->filters[n] = (float *)getbytes(N * sizeof(float));
xtract_init_mfcc(N, NYQUIST, XTRACT_EQUAL_GAIN, 80.0f,
- 18000.0f, mf->n_filters, mf->filters);
+ 18000.0f, mf->n_filters, mf->filters);
+ x->done_init = 1;
}
- else if(x->feature == XTRACT_BARK_COEFFICIENTS)
+ else if(x->feature == XTRACT_BARK_COEFFICIENTS){
xtract_init_bark(N, NYQUIST, x->argv);
+ x->done_init = 1;
+ }
+
+ /* Initialise fft_plan if required */
+ if(x->feature == XTRACT_AUTOCORRELATION_FFT ||
+ x->feature == XTRACT_SPECTRUM ||
+ x->feature == XTRACT_DCT){
+ xtract_init_fft(N, x->feature);
+ x->done_init = 1;
+ }
if(x->feature == XTRACT_AUTOCORRELATION ||
x->feature == XTRACT_AUTOCORRELATION_FFT ||