aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorJamie Bullock <jamie@jamiebullock.com>2013-01-09 12:45:29 +0000
committerJamie Bullock <jamie@jamiebullock.com>2013-01-09 12:45:29 +0000
commitc277634b13117e721e43f34a09cafb93c725fa3f (patch)
treeb4f57d1cf0c430eb700df37b074abd7e4e0acf17 /examples
parent812e693b8c025c73ff5cddae3581b547465ab915 (diff)
downloadLibXtract-c277634b13117e721e43f34a09cafb93c725fa3f.tar.gz
LibXtract-c277634b13117e721e43f34a09cafb93c725fa3f.tar.bz2
LibXtract-c277634b13117e721e43f34a09cafb93c725fa3f.zip
switched from single to double precision througout. closes #9
Diffstat (limited to 'examples')
-rw-r--r--examples/MSP/xtract~.c41
-rw-r--r--examples/puredata/xtract~.c38
-rw-r--r--examples/simpletest/simpletest.c26
3 files changed, 57 insertions, 48 deletions
diff --git a/examples/MSP/xtract~.c b/examples/MSP/xtract~.c
index 3e50de0..e46ec6a 100644
--- a/examples/MSP/xtract~.c
+++ b/examples/MSP/xtract~.c
@@ -51,6 +51,8 @@ typedef struct _xtract {
t_int feature_type;
tracked_memory memory;
void *argv;
+ double *data;
+ double *result;
} t_xtract_tilde;
static t_int *xtract_perform(t_int *w) {
@@ -58,9 +60,13 @@ static t_int *xtract_perform(t_int *w) {
t_xtract_tilde *x = (t_xtract_tilde *)(w[2]);
t_int N = (t_int)(w[3]);
t_int return_code = 0;
- float result = 0.f;
+ double result = 0.f;
- return_code = xtract[x->feature]((float *)in, N, x->argv, &result);
+ for(n = 0; n < N; ++n){
+ x->data[n] = (double)in[n];
+ }
+
+ return_code = xtract[x->feature](x->data, N, x->argv, &result);
if(return_code == XTRACT_FEATURE_NOT_IMPLEMENTED)
perror("Feature not implemented");
@@ -68,14 +74,13 @@ static t_int *xtract_perform(t_int *w) {
/* set nan, inf or -inf to 0 */
result = (isinf(result) || isnan(result) ? 0 : result);
- outlet_float(x->outlet, result);
+ outlet_float(x->outlet, (float)result);
return (w+4);
}
static t_int *xtract_perform_vector(t_int *w) {
t_sample *in = (t_float *)(w[1]);
t_sample *out = (t_float *)(w[2]);
- float *temp_in, *temp_out;
t_xtract_tilde *x = (t_xtract_tilde *)(w[3]);
t_int N = (t_int)(w[4]), n;
t_int return_code = 0;
@@ -87,28 +92,20 @@ static t_int *xtract_perform_vector(t_int *w) {
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));
- temp_out= (float *)getbytes(N * sizeof(float));
-
- while(n--)
- temp_in[n] = in[n];
+ for(n = 0; n < N; ++n){
+ x->data[n] = (double)in[n];
+ }
- n = N;
+ return_code = xtract[x->feature](x->data, N, x->argv, x->result);
- return_code = xtract[x->feature](temp_in, N, x->argv, temp_out);
-
- while(n--)
- out[n] = temp_out[n];
+ for(n = 0; n < N; ++n){
+ out[n] = (float)x->result[n];
+ }
if(return_code == XTRACT_FEATURE_NOT_IMPLEMENTED)
perror("Feature not implemented");
- freebytes(temp_in, sizeof(float) * N);
- freebytes(temp_out, sizeof(float) * N);
-
return (w+5);
}
@@ -144,6 +141,10 @@ static void *xtract_tilde_new(t_symbol *me, t_int argc, t_atom *argv) {
x->argv = NULL;
x->done_init = 0;
+
+ x->data = (double *)getbytes(N * sizeof(double));
+ x->result = (double *)getbytes(N * sizeof(double));
+
if(argc)
tmp = argv[0].a_w.w_sym; /*atom_getsymbol(argv); */
@@ -312,6 +313,8 @@ static void xtract_tilde_free(t_xtract_tilde *x) {
if(x->argv != NULL && x->memory.argv)
freebytes(x->argv, x->memory.argv);
+ freebytes(x->data);
+ freebytes(x->result);
}
int main(void) {
diff --git a/examples/puredata/xtract~.c b/examples/puredata/xtract~.c
index 2223bc7..8ec1c15 100644
--- a/examples/puredata/xtract~.c
+++ b/examples/puredata/xtract~.c
@@ -51,7 +51,9 @@ typedef struct _tracked_memory {
typedef struct _xtract {
t_object x_obj;
t_float f;
- t_float *window;
+ double *window;
+ double *data;
+ double *result;
t_int feature,
is_scalar,
is_subframe,
@@ -68,17 +70,21 @@ static t_int *xtract_perform(t_int *w) {
t_xtract_tilde *x = (t_xtract_tilde *)(w[2]);
t_int N = (t_int)(w[3]);
t_int rv = 0;
- float result = 0;
+ double result = 0.0;
- rv = xtract[x->feature]((float *)in, N, x->argv, &result);
+ for(n = 0; n < N; ++n) {
+ x->data[n] = (double)in[n];
+ }
+
+ rv = xtract[x->feature](x->data, N, x->argv, &result);
if(rv == XTRACT_FEATURE_NOT_IMPLEMENTED)
pd_error(x, "Feature not implemented");
/* set nan, inf or -inf to 0 */
- result = (isinf(result) || isnan(result) ? 0 : result);
+ result = (isinf(result) || isnan(result) ? 0.0 : result);
- outlet_float(x->x_obj.ob_outlet, result);
+ outlet_float(x->x_obj.ob_outlet, (float)result);
return (w+4);
}
@@ -86,7 +92,6 @@ 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;
t_xtract_tilde *x = (t_xtract_tilde *)(w[3]);
t_int N = (t_int)(w[4]), n;
t_int rv = 0;
@@ -98,31 +103,28 @@ static t_int *xtract_perform_vector(t_int *w) {
n = N;
- tmp_in = copybytes(in, N * sizeof(t_float));
- tmp_out = getbytes(N * sizeof(t_float));
+ for(n = 0; n < N; ++n) {
+ x->data[n] = (double)in[n];
+ }
if(x->feature == XTRACT_PEAK_SPECTRUM || x->feature == XTRACT_LPC)
N >>= 1;
if(x->is_subframe){
- rv = xtract_features_from_subframes(tmp_in, N, x->feature,
- x->argv, tmp_out);
+ rv = xtract_features_from_subframes(x->data, N, x->feature,
+ x->argv, x->result);
}
else{
- rv = xtract[x->feature](tmp_in, N, x->argv, tmp_out);
-
+ rv = xtract[x->feature](x->data, N, x->argv, x->result);
}
if(rv == XTRACT_FEATURE_NOT_IMPLEMENTED)
pd_error(x, "Feature not implemented");
while(n--)
- out[n] = tmp_out[n];
-
- freebytes(tmp_in, N * sizeof(t_float));
- freebytes(tmp_out, N * sizeof(t_float));
+ out[n] = (float)x->result[n];
return (w+5);
}
@@ -169,6 +171,10 @@ static void *xtract_new(t_symbol *me, t_int argc, t_atom *argv) {
x->is_subframe = 0;
x->feature = -1;
+ /* Allocate data area */
+ x->data = (double *)getbytes(N * sizeof(double));
+ x->result = (double *)getbytes(N * sizeof(double));
+
/* Parse arguments */
if(argc){
arg1 = atom_getsymbol(argv);
diff --git a/examples/simpletest/simpletest.c b/examples/simpletest/simpletest.c
index 33290c3..7b6cb22 100644
--- a/examples/simpletest/simpletest.c
+++ b/examples/simpletest/simpletest.c
@@ -35,18 +35,18 @@
int main(void)
{
- float mean = 0.f;
- float input[BLOCKSIZE];
- float spectrum[BLOCKSIZE];
- float mfccs[MFCC_FREQ_BANDS * sizeof(float)];
- float argf[4];
+ double mean = 0.f;
+ double input[BLOCKSIZE];
+ double spectrum[BLOCKSIZE];
+ double mfccs[MFCC_FREQ_BANDS * sizeof(double)];
+ double argd[4];
int n;
xtract_mel_filter mel_filters;
/* fill the input array with a sawtooth wave */
for(n = 0; n < BLOCKSIZE; ++n)
{
- input[n] = ((n % PERIOD) / (float)PERIOD) - .5;
+ input[n] = ((n % PERIOD) / (double)PERIOD) - .5;
}
/* get the mean of the input */
@@ -54,13 +54,13 @@ int main(void)
printf("\nInput mean = %.2f\n\n", mean);
/* get the spectrum */
- argf[0] = SAMPLERATE / (float)BLOCKSIZE;
- argf[1] = XTRACT_MAGNITUDE_SPECTRUM;
- argf[2] = 0.f; /* No DC component */
- argf[3] = 0.f; /* No Normalisation */
+ argd[0] = SAMPLERATE / (double)BLOCKSIZE;
+ argd[1] = XTRACT_MAGNITUDE_SPECTRUM;
+ argd[2] = 0.f; /* No DC component */
+ argd[3] = 0.f; /* No Normalisation */
xtract_init_fft(BLOCKSIZE, XTRACT_SPECTRUM);
- xtract[XTRACT_SPECTRUM]((void *)&input, BLOCKSIZE, &argf[0], (void *)&spectrum[0]);
+ xtract[XTRACT_SPECTRUM]((void *)&input, BLOCKSIZE, &argd[0], (void *)&spectrum[0]);
/* print the spectral bins */
printf("\nSpectral bins:\n");
@@ -71,10 +71,10 @@ int main(void)
/* compute the MFCCs */
mel_filters.n_filters = MFCC_FREQ_BANDS;
- mel_filters.filters = malloc(MFCC_FREQ_BANDS * sizeof(float *));
+ mel_filters.filters = malloc(MFCC_FREQ_BANDS * sizeof(double *));
for(n = 0; n < MFCC_FREQ_BANDS; ++n)
{
- mel_filters.filters[n] = malloc(BLOCKSIZE * sizeof(float));
+ mel_filters.filters[n] = malloc(BLOCKSIZE * sizeof(double));
}
xtract_init_mfcc(BLOCKSIZE >> 1, SAMPLERATE >> 1, XTRACT_EQUAL_GAIN, MFCC_FREQ_MIN, MFCC_FREQ_MAX, mel_filters.n_filters, mel_filters.filters);