jamie@1: /* libxtract feature extraction library jamie@1: * jamie@1: * Copyright (C) 2006 Jamie Bullock jamie@1: * jamie@1: * This program is free software; you can redistribute it and/or modify jamie@1: * it under the terms of the GNU General Public License as published by jamie@1: * the Free Software Foundation; either version 2 of the License, or jamie@1: * (at your option) any later version. jamie@1: * jamie@1: * This program is distributed in the hope that it will be useful, jamie@1: * but WITHOUT ANY WARRANTY; without even the implied warranty of jamie@1: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jamie@1: * GNU General Public License for more details. jamie@1: * jamie@1: * You should have received a copy of the GNU General Public License jamie@1: * along with this program; if not, write to the Free Software jamie@1: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, jamie@1: * USA. jamie@1: */ jamie@1: jamie@1: /* xtract_delta.c: defines functions that extract a feature as a single value from more than one input vector */ jamie@1: jamie@106: #include jamie@106: jamie@38: #include "xtract/libxtract.h" jamie@1: jamie@43: int xtract_flux(const float *data, const int N, const void *argv , float *result){ jamie@1: jamie@117: /* FIX: don't be lazy -- take the lnorm of the difference vector! */ jamie@106: return xtract_lnorm(data, N, argv, result); jamie@105: jamie@106: } jamie@106: jamie@106: int xtract_lnorm(const float *data, const int N, const void *argv , float *result){ jamie@106: jamie@107: int n, jamie@106: type; jamie@106: jamie@111: float order; jamie@106: jamie@106: order = *(float *)argv; jamie@111: type = *((float *)argv+1); jamie@106: jamie@108: order = order > 0 ? order : 2.f; jamie@106: jamie@111: *result = 0.f; jamie@111: jamie@106: switch(type){ jamie@106: jamie@106: case XTRACT_POSITIVE_SLOPE: jamie@106: for(n = 0; n < N; n++){ jamie@106: if(data[n] > 0) jamie@111: *result += powf(data[n], order); jamie@106: } jamie@106: break; jamie@106: default: jamie@106: for(n = 0; n < N; n++) jamie@106: *result += powf(data[n], order); jamie@106: break; jamie@106: jamie@106: } jamie@106: jamie@106: *result = powf(*result, 1.f / order); jamie@106: jamie@106: return XTRACT_SUCCESS; jamie@1: jamie@1: } jamie@1: jamie@43: int xtract_attack_time(const float *data, const int N, const void *argv , float *result){ jamie@1: jamie@56: return XTRACT_FEATURE_NOT_IMPLEMENTED; jamie@1: jamie@1: } jamie@1: jamie@43: int xtract_decay_time(const float *data, const int N, const void *argv, float *result){ jamie@1: jamie@56: return XTRACT_FEATURE_NOT_IMPLEMENTED; jamie@1: jamie@1: } jamie@1: jamie@106: int xtract_difference_vector(const float *data, const int N, const void *argv, float *result){ jamie@1: jamie@107: const float *frame1, jamie@106: *frame2; jamie@106: jamie@106: int n; jamie@106: jamie@106: n = N >> 1; jamie@106: jamie@106: frame1 = data; jamie@106: frame2 = data + n; jamie@106: jamie@106: while(n--) jamie@106: result[n] = frame1[n] - frame2[n]; jamie@106: jamie@106: return XTRACT_SUCCESS; jamie@1: jamie@1: }