From 813f4c7d89544d2c71518e0e121bdadfe339d3e2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Eduard=20M=C3=BCller?= Date: Tue, 20 Dec 2016 23:24:28 +0100 Subject: [PATCH] help compiler to optimize aubio_pitchyin_do ... by giving it addresses for all arrays which are referenced in inner loops --- src/pitch/pitchyin.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/pitch/pitchyin.c b/src/pitch/pitchyin.c index b65e3f7e..2a7f43db 100644 --- a/src/pitch/pitchyin.c +++ b/src/pitch/pitchyin.c @@ -127,32 +127,35 @@ aubio_pitchyin_getpitch (const fvec_t * yin) return 0; } - /* all the above in one */ void aubio_pitchyin_do (aubio_pitchyin_t * o, const fvec_t * input, fvec_t * out) { - smpl_t tol = o->tol; - fvec_t *yin = o->yin; - uint_t j, tau = 0; + const smpl_t tol = o->tol; + fvec_t* yin = o->yin; + const smpl_t *input_data = input->data; + const uint_t length = yin->length; + smpl_t *yin_data = yin->data; + uint_t j, tau; sint_t period; - smpl_t tmp = 0., tmp2 = 0.; - yin->data[0] = 1.; - for (tau = 1; tau < yin->length; tau++) { - yin->data[tau] = 0.; - for (j = 0; j < yin->length; j++) { - tmp = input->data[j] - input->data[j + tau]; - yin->data[tau] += SQR (tmp); + smpl_t tmp, tmp2 = 0.; + + yin_data[0] = 1.; + for (tau = 1; tau < length; tau++) { + yin_data[tau] = 0.; + for (j = 0; j < length; j++) { + tmp = input_data[j] - input_data[j + tau]; + yin_data[tau] += SQR (tmp); } - tmp2 += yin->data[tau]; + tmp2 += yin_data[tau]; if (tmp2 != 0) { yin->data[tau] *= tau / tmp2; } else { yin->data[tau] = 1.; } period = tau - 3; - if (tau > 4 && (yin->data[period] < tol) && - (yin->data[period] < yin->data[period + 1])) { + if (tau > 4 && (yin_data[period] < tol) && + (yin_data[period] < yin_data[period + 1])) { out->data[0] = fvec_quadratic_peak_pos (yin, period); goto beach; } -- 2.11.0