source: src/fvec.c @ e460e60

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since e460e60 was a6db140, checked in by Paul Brossier <piem@piem.org>, 15 years ago

src/*.[ch]: update copyrights and license from 2003 / GPLv2 to 2003-2009 / GPLv3

  • Property mode set to 100644
File size: 3.1 KB
Line 
1/*
2  Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
3
4  This file is part of aubio.
5
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.
10
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/>.
18
19*/
20
21#include "aubio_priv.h"
22#include "fvec.h"
23
24fvec_t * new_fvec( uint_t length, uint_t channels) {
25  fvec_t * s = AUBIO_NEW(fvec_t);
26  uint_t i,j;
27  s->channels = channels;
28  s->length = length;
29  s->data = AUBIO_ARRAY(smpl_t*,s->channels);
30  for (i=0; i< s->channels; i++) {
31    s->data[i] = AUBIO_ARRAY(smpl_t, s->length);
32    for (j=0; j< s->length; j++) {
33      s->data[i][j]=0.;
34    }
35  }
36  return s;
37}
38
39void del_fvec(fvec_t *s) {
40  uint_t i;
41  for (i=0; i<s->channels; i++) {
42    AUBIO_FREE(s->data[i]);
43  }
44  AUBIO_FREE(s->data);
45  AUBIO_FREE(s);
46}
47
48void fvec_write_sample(fvec_t *s, smpl_t data, uint_t channel, uint_t position) {
49  s->data[channel][position] = data;
50}
51smpl_t fvec_read_sample(fvec_t *s, uint_t channel, uint_t position) {
52  return s->data[channel][position];
53}
54void fvec_put_channel(fvec_t *s, smpl_t * data, uint_t channel) {
55  s->data[channel] = data;
56}
57smpl_t * fvec_get_channel(fvec_t *s, uint_t channel) {
58  return s->data[channel];
59}
60
61smpl_t ** fvec_get_data(fvec_t *s) {
62  return s->data;
63}
64
65/* helper functions */
66
67void fvec_print(fvec_t *s) {
68  uint_t i,j;
69  for (i=0; i< s->channels; i++) {
70    for (j=0; j< s->length; j++) {
71      AUBIO_MSG(AUBIO_SMPL_FMT " ", s->data[i][j]);
72    }
73    AUBIO_MSG("\n");
74  }
75}
76
77void fvec_set(fvec_t *s, smpl_t val) {
78  uint_t i,j;
79  for (i=0; i< s->channels; i++) {
80    for (j=0; j< s->length; j++) {
81      s->data[i][j] = val;
82    }
83  }
84}
85
86void fvec_zeros(fvec_t *s) {
87  fvec_set(s, 0.);
88}
89
90void fvec_ones(fvec_t *s) {
91  fvec_set(s, 1.);
92}
93
94void fvec_rev(fvec_t *s) {
95  uint_t i,j;
96  for (i=0; i< s->channels; i++) {
97    for (j=0; j< FLOOR(s->length/2); j++) {
98      ELEM_SWAP(s->data[i][j], s->data[i][s->length-1-j]);
99    }
100  }
101}
102
103void fvec_weight(fvec_t *s, fvec_t *weight) {
104  uint_t i,j;
105  uint_t length = MIN(s->length, weight->length);
106  for (i=0; i< s->channels; i++) {
107    for (j=0; j< length; j++) {
108      s->data[i][j] *= weight->data[0][j];
109    }
110  }
111}
112
113void fvec_copy(fvec_t *s, fvec_t *t) {
114  uint_t i,j;
115  uint_t channels = MIN(s->channels, t->channels);
116  uint_t length = MIN(s->length, t->length);
117  if (s->channels != t->channels) {
118    AUBIO_ERR("warning, trying to copy %d channels to %d channels\n", 
119            s->channels, t->channels);
120  }
121  if (s->length != t->length) {
122    AUBIO_ERR("warning, trying to copy %d elements to %d elements \n", 
123            s->length, t->length);
124  }
125  for (i=0; i< channels; i++) {
126    for (j=0; j< length; j++) {
127      t->data[i][j] = s->data[i][j];
128    }
129  }
130}
131
Note: See TracBrowser for help on using the repository browser.