[a3a01e1] | 1 | /* |
---|
[a6db140] | 2 | Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org> |
---|
[a3a01e1] | 3 | |
---|
[a6db140] | 4 | This file is part of aubio. |
---|
[a3a01e1] | 5 | |
---|
[a6db140] | 6 | aubio is free software: you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation, either version 3 of the License, or |
---|
| 9 | (at your option) any later version. |
---|
[a3a01e1] | 10 | |
---|
[a6db140] | 11 | aubio is distributed in the hope that it will be useful, |
---|
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 14 | GNU General Public License for more details. |
---|
| 15 | |
---|
| 16 | You should have received a copy of the GNU General Public License |
---|
| 17 | along with aubio. If not, see <http://www.gnu.org/licenses/>. |
---|
[a3a01e1] | 18 | |
---|
| 19 | */ |
---|
| 20 | |
---|
| 21 | #include "aubio_priv.h" |
---|
| 22 | #include "lvec.h" |
---|
| 23 | |
---|
[c7860af] | 24 | lvec_t * new_lvec( uint_t length) { |
---|
[767990e] | 25 | if ((sint_t)length <= 0) { |
---|
| 26 | return NULL; |
---|
| 27 | } |
---|
[a3a01e1] | 28 | lvec_t * s = AUBIO_NEW(lvec_t); |
---|
| 29 | s->length = length; |
---|
[c7860af] | 30 | s->data = AUBIO_ARRAY(lsmp_t, s->length); |
---|
[a3a01e1] | 31 | return s; |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | void del_lvec(lvec_t *s) { |
---|
| 35 | AUBIO_FREE(s->data); |
---|
| 36 | AUBIO_FREE(s); |
---|
| 37 | } |
---|
| 38 | |
---|
[c7860af] | 39 | void lvec_write_sample(lvec_t *s, lsmp_t data, uint_t position) { |
---|
| 40 | s->data[position] = data; |
---|
[a3a01e1] | 41 | } |
---|
[6ede3ab] | 42 | lsmp_t lvec_get_sample(lvec_t *s, uint_t position) { |
---|
[c7860af] | 43 | return s->data[position]; |
---|
[a3a01e1] | 44 | } |
---|
| 45 | |
---|
[c7860af] | 46 | lsmp_t * lvec_get_data(lvec_t *s) { |
---|
[a3a01e1] | 47 | return s->data; |
---|
| 48 | } |
---|
| 49 | |
---|
[79a01c5] | 50 | /* helper functions */ |
---|
| 51 | |
---|
| 52 | void lvec_print(lvec_t *s) { |
---|
[c7860af] | 53 | uint_t j; |
---|
| 54 | for (j=0; j< s->length; j++) { |
---|
| 55 | AUBIO_MSG(AUBIO_LSMP_FMT " ", s->data[j]); |
---|
[79a01c5] | 56 | } |
---|
[c7860af] | 57 | AUBIO_MSG("\n"); |
---|
[79a01c5] | 58 | } |
---|
| 59 | |
---|
[6ede3ab] | 60 | void lvec_set_all (lvec_t *s, smpl_t val) { |
---|
[c7860af] | 61 | uint_t j; |
---|
| 62 | for (j=0; j< s->length; j++) { |
---|
| 63 | s->data[j] = val; |
---|
[b849106] | 64 | } |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | void lvec_zeros(lvec_t *s) { |
---|
[923a7a8] | 68 | #if HAVE_MEMCPY_HACKS |
---|
| 69 | memset(s->data, 0, s->length * sizeof(lsmp_t)); |
---|
| 70 | #else |
---|
[6ede3ab] | 71 | lvec_set_all (s, 0.); |
---|
[923a7a8] | 72 | #endif |
---|
[b849106] | 73 | } |
---|
| 74 | |
---|
| 75 | void lvec_ones(lvec_t *s) { |
---|
[6ede3ab] | 76 | lvec_set_all (s, 1.); |
---|
[b849106] | 77 | } |
---|
| 78 | |
---|