annotate src/helper.c @ 243:d13189c1005c

Fix broken xtract_stateful.h
author Jamie Bullock <jamie@jamiebullock.com>
date Thu, 05 Jun 2014 20:31:33 +0100
parents ef80f7c52c6d
children 8c768f32a6a8
rev   line source
jamie@141 1 /*
jamie@141 2 * Copyright (C) 2012 Jamie Bullock
jamie@140 3 *
jamie@141 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
jamie@141 5 * of this software and associated documentation files (the "Software"), to
jamie@141 6 * deal in the Software without restriction, including without limitation the
jamie@141 7 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
jamie@141 8 * sell copies of the Software, and to permit persons to whom the Software is
jamie@141 9 * furnished to do so, subject to the following conditions:
jamie@107 10 *
jamie@141 11 * The above copyright notice and this permission notice shall be included in
jamie@141 12 * all copies or substantial portions of the Software.
jamie@107 13 *
jamie@141 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
jamie@141 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
jamie@141 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
jamie@141 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
jamie@141 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
jamie@141 19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
jamie@141 20 * IN THE SOFTWARE.
jamie@107 21 *
jamie@107 22 */
jamie@107 23
jamie@107 24 /* helper.c: helper functions. */
jamie@107 25
jamie@113 26 #include <stdio.h>
jamie@113 27
jamie@159 28 #include "../xtract/libxtract.h"
jamie@107 29
jamie@113 30 #ifdef WORDS_BIGENDIAN
jamie@113 31 #define INDEX 0
jamie@113 32 #else
jamie@113 33 #define INDEX 1
jamie@113 34 #endif
jamie@113 35
jamie@146 36 int xtract_windowed(const double *data, const int N, const void *argv, double *result)
jamie@140 37 {
jamie@107 38
jamie@107 39 int n;
jamie@146 40 const double *window;
jamie@107 41
jamie@107 42 n = N;
jamie@146 43 window = (const double *)argv;
jamie@107 44
jamie@107 45 while(n--)
jamie@107 46 result[n] = data[n] * window[n];
jamie@107 47
jamie@107 48 return XTRACT_SUCCESS;
jamie@107 49
jamie@107 50 }
jamie@107 51
jamie@146 52 int xtract_features_from_subframes(const double *data, const int N, const int feature, const void *argv, double *result)
jamie@140 53 {
jamie@107 54
jamie@146 55 const double *frame1,
jamie@107 56 *frame2;
jamie@146 57 double *result1,
jamie@107 58 *result2;
jamie@107 59
jamie@113 60 int n, rv;
jamie@107 61
jamie@107 62 n = N >> 1;
jamie@107 63
jamie@107 64 frame1 = data;
jamie@107 65 frame2 = data + n;
jamie@107 66 result1 = result;
jamie@107 67 result2 = result + n;
jamie@107 68
jamie@107 69 rv = xtract[feature](frame1, n, argv, result1);
jamie@107 70
jamie@107 71 if(rv == XTRACT_SUCCESS)
jamie@107 72 rv = xtract[feature](frame2, n, argv, result2);
jamie@107 73
jamie@107 74 return rv;
jamie@107 75
jamie@107 76 }
jamie@113 77
andrea@211 78 //inline int xtract_is_denormal(double const d)
andrea@211 79 int xtract_is_denormal(double const d)
jamie@140 80 {
jamie@113 81 if(sizeof(d) != 2 * sizeof(int))
jamie@113 82 fprintf(stderr, "libxtract: Error: xtract_is_denormal() detects inconsistent wordlength for type 'double'\n");
jamie@113 83
jamie@113 84 int l = ((int *)&d)[INDEX];
jamie@113 85 return (l&0x7ff00000) == 0 && d!=0; //Check for 0 may not be necessary
jamie@113 86 }
jamie@113 87
andrea@211 88 //inline bool xtract_is_poweroftwo(unsigned int x)
andrea@211 89 bool xtract_is_poweroftwo(unsigned int x)
jamie@140 90 {
jamie@140 91 return ((x != 0) && !(x & (x - 1)));
jamie@140 92 }
jamie@140 93