diff options
-rw-r--r-- | examples/puredata/xtract~.c | 4 | ||||
-rw-r--r-- | src/scalar.c | 6 | ||||
-rw-r--r-- | src/vector.c | 11 |
3 files changed, 13 insertions, 8 deletions
diff --git a/examples/puredata/xtract~.c b/examples/puredata/xtract~.c index 93c7617..69c3e0d 100644 --- a/examples/puredata/xtract~.c +++ b/examples/puredata/xtract~.c @@ -171,7 +171,9 @@ static void *xtract_new(t_symbol *me, t_int argc, t_atom *argv) { case AVERAGE_DEVIATION: case ROLLOFF: case INHARMONICITY: + case MAGNITUDE_SPECTRUM: case ODD_EVEN_RATIO: + case LOWEST_VALUE: case F0: case FAILSAFE_F0: case TONALITY: @@ -196,7 +198,6 @@ static void *xtract_new(t_symbol *me, t_int argc, t_atom *argv) { case SPREAD: case ZCR: case LOUDNESS: - case LOWEST_VALUE: case HIGHEST_VALUE: case SUM: case RMS_AMPLITUDE: @@ -209,7 +210,6 @@ static void *xtract_new(t_symbol *me, t_int argc, t_atom *argv) { case DECAY_TIME: /*not implemented */ case DELTA_FEATURE: /*not implemented */ case AUTOCORRELATION_FFT: - case MAGNITUDE_SPECTRUM: case MFCC: case DCT: case AUTOCORRELATION: diff --git a/src/scalar.c b/src/scalar.c index c7d6edd..612fa3c 100644 --- a/src/scalar.c +++ b/src/scalar.c @@ -456,7 +456,7 @@ int xtract_lowest_value(const float *data, const int N, const void *argv, float int n = N; float temp; - *result = data[N]; + *result = data[--n]; while(n--){ if((temp = data[n]) > *(float *)argv) @@ -470,7 +470,7 @@ int xtract_highest_value(const float *data, const int N, const void *argv, float int n = N; - *result = data[N]; + *result = data[--n]; while(n--) *result = MAX(*result, data[n]); @@ -633,7 +633,7 @@ int xtract_failsafe_f0(const float *data, const int N, const void *argv, float * magnitudes = (float *)malloc(N * sizeof(float)); peaks = (float *)malloc(N * sizeof(float)); - xtract_magnitude_spectrum(data, N, NULL, magnitudes); + xtract_magnitude_spectrum(data, N, argv, magnitudes); argf[0] = 10.f; argf[1] = *(float *)argv; xtract_peaks(magnitudes, N, argf, peaks); diff --git a/src/vector.c b/src/vector.c index 3a6e587..739004e 100644 --- a/src/vector.c +++ b/src/vector.c @@ -32,7 +32,7 @@ int xtract_magnitude_spectrum(const float *data, const int N, const void *argv, float *result){ - float *temp, *input; + float *temp, *input, q; size_t bytes; int n , M = N >> 1; fftwf_plan plan; @@ -41,17 +41,22 @@ int xtract_magnitude_spectrum(const float *data, const int N, const void *argv, input = (float *)malloc(bytes = N * sizeof(float)); input = memcpy(input, data, bytes); + q = 0.f; + + q = *(float *)argv; + q = (q ? (q * .5) / M : 0.f); + plan = fftwf_plan_r2r_1d(N, input, temp, FFTW_R2HC, FFTW_ESTIMATE); fftwf_execute(plan); for(n = 1; n < M; n++){ result[n] = sqrt(SQ(temp[n]) + SQ(temp[N - n])) / N; - result[N-n] = 0.0f; + result[M + n] = n * q; } result[0] = fabs(temp[0]) / N; - result[M] = fabs(temp[M]) / N; + result[M] = q * .5; fftwf_destroy_plan(plan); fftwf_free(temp); |