From a5f18e9f84b84f3c10c2470748d28fa1eeae0979 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Fri, 25 Dec 2015 21:21:02 +0100 Subject: [PATCH] wip adding packed matcher --- main.c | 10 +++++++++ src/vec_match.c | 58 +++++++++++++++++++++++++++++++++++++++++++------ src/vec_match.h | 23 ++++---------------- 3 files changed, 65 insertions(+), 26 deletions(-) diff --git a/main.c b/main.c index 6025363..451b7a1 100644 --- a/main.c +++ b/main.c @@ -21,6 +21,8 @@ static float data_cprs[16] = { static float data_cprs2[16]; +static float data_cprs3[16]; + int main(void) { for (int i = 0; i < 16; i++) { @@ -36,6 +38,14 @@ int main(void) } printf("\n"); + len = vec_unpack(data_cprs3, 16, data_cprs2, len); + printf("unpacked len = %d\n", len); + + for (int i = 0; i < len; i++) { + printf("%.1f, ", data_cprs3[i]); + } + printf("\n"); + return 0; diff --git a/src/vec_match.c b/src/vec_match.c index 08b7749..98708b5 100644 --- a/src/vec_match.c +++ b/src/vec_match.c @@ -8,11 +8,14 @@ #define SQUARE(a) ((a)*(a)) -bool vec_match(const float *data, - const float *ref, - const vec_match_cfg_t *cfg, - float *fuzzy_match_error, - float *abs_match_error) +#define F2ZEROES(f) roundf(-(f)) +#define ZEROES2F(z) (0.0f - z) + + +bool vec_match_do(const float *data, const float *ref, + const vec_match_cfg_t *cfg, + float *fuzzy_match_error, float *abs_match_error, + bool packed) { int a, b; @@ -67,8 +70,24 @@ bool vec_match(const float *data, +bool vec_match(const float *data, const float *ref, const vec_match_cfg_t *cfg, + float *fuzzy_match_error, float *abs_match_error) +{ + return vec_match_do(data, ref, cfg, fuzzy_match_error, abs_match_error, false); +} + + + +bool vec_match_packed(const float *data, const float *ref, const vec_match_cfg_t *cfg, + float *fuzzy_match_error, float *abs_match_error) +{ + return vec_match_do(data, ref, cfg, fuzzy_match_error, abs_match_error, true); +} + + -uint32_t vec_pack(float *result, uint32_t result_capacity, const float *data, uint32_t data_length, float threshold) +uint32_t vec_pack(float *result, uint32_t result_capacity, + const float *data, uint32_t data_length, float threshold) { uint32_t result_len = 0; uint32_t zeroes = 0; @@ -80,7 +99,7 @@ uint32_t vec_pack(float *result, uint32_t result_capacity, const float *data, ui // write zero marker to result if (zeroes) { if (result_len < result_capacity) { - result[result_len] = 0.0f - zeroes; // float and negative + result[result_len] = ZEROES2F(zeroes); // float and negative } zeroes = 0; @@ -110,3 +129,28 @@ uint32_t vec_pack(float *result, uint32_t result_capacity, const float *data, ui +uint32_t vec_unpack(float *result, uint32_t result_capacity, + const float *compr_data, uint32_t compr_length) +{ + uint32_t idx = 0; + + for (uint32_t i = 0; i < compr_length; i++) { + if (compr_data[i] < 0) { + uint32_t zeroes = F2ZEROES(compr_data[i]); + for (uint32_t j = 0; j < zeroes; j++) { + if (idx < result_capacity) { + result[idx] = 0; + } + idx++; + } + } else { + if (idx < result_capacity) { + result[idx] = compr_data[i]; + } + idx++; + } + } + + return idx; +} + diff --git a/src/vec_match.h b/src/vec_match.h index a98a2a1..0aebc9c 100644 --- a/src/vec_match.h +++ b/src/vec_match.h @@ -22,11 +22,7 @@ typedef struct { * @param abs_match_error error metric calculated from raw data (can be used if envelope match passes) * @return envelope match status (match using drift and offset) */ -bool vec_match(const float *data, - const float *ref, - const vec_match_cfg_t *cfg, - float *fuzzy_match_error, - float *abs_match_error); +bool vec_match(const float *data, const float *ref, const vec_match_cfg_t *cfg, float *fuzzy_match_error, float *abs_match_error); /** @@ -37,11 +33,7 @@ bool vec_match(const float *data, * * Params otherwise the same as vec_match() */ -bool vec_match_packed(const float *data, - const float *ref, - const vec_match_cfg_t *cfg, - float *fuzzy_match_error, - float *abs_match_error); +bool vec_match_packed(const float *data, const float *ref, const vec_match_cfg_t *cfg, float *fuzzy_match_error, float *abs_match_error); /** @@ -59,11 +51,7 @@ bool vec_match_packed(const float *data, * @param threshold max value to be considered zero in the compression * @return length of result vector */ -uint32_t vec_pack(float *result, - uint32_t result_capacity, - const float *data, - uint32_t length, - float threshold); +uint32_t vec_pack(float *result, uint32_t result_capacity, const float *data, uint32_t length, float threshold); /** @@ -78,7 +66,4 @@ uint32_t vec_pack(float *result, * @param compr_length compressed data vector length * @return */ -uint32_t vec_unpack(float *result, - uint32_t result_capacity, - const float *compr_data, - uint32_t compr_length); +uint32_t vec_unpack(float *result, uint32_t result_capacity, const float *compr_data, uint32_t compr_length);