source: src/fmat.c @ 0af9003

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

src/fmat.c: use memcpy on each column

  • Property mode set to 100644
File size: 3.4 KB
Line 
1/*
2  Copyright (C) 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 "fmat.h"
23
24fmat_t * new_fmat (uint_t length, uint_t height) {
25  if ((sint_t)length <= 0 || (sint_t)height <= 0 ) {
26    return NULL;
27  }
28  fmat_t * s = AUBIO_NEW(fmat_t);
29  uint_t i,j;
30  s->height = height;
31  s->length = length;
32  s->data = AUBIO_ARRAY(smpl_t*,s->height);
33  for (i=0; i< s->height; i++) {
34    s->data[i] = AUBIO_ARRAY(smpl_t, s->length);
35    for (j=0; j< s->length; j++) {
36      s->data[i][j]=0.;
37    }
38  }
39  return s;
40}
41
42void del_fmat (fmat_t *s) {
43  uint_t i;
44  for (i=0; i<s->height; i++) {
45    AUBIO_FREE(s->data[i]);
46  }
47  AUBIO_FREE(s->data);
48  AUBIO_FREE(s);
49}
50
51void fmat_write_sample(fmat_t *s, smpl_t data, uint_t channel, uint_t position) {
52  s->data[channel][position] = data;
53}
54smpl_t fmat_read_sample(fmat_t *s, uint_t channel, uint_t position) {
55  return s->data[channel][position];
56}
57void fmat_put_channel(fmat_t *s, smpl_t * data, uint_t channel) {
58  s->data[channel] = data;
59}
60void fmat_get_channel(fmat_t *s, uint_t channel, fvec_t *output) {
61  output->data = s->data[channel];
62  output->length = s->length;
63  return;
64}
65
66smpl_t ** fmat_get_data(fmat_t *s) {
67  return s->data;
68}
69
70/* helper functions */
71
72void fmat_print(fmat_t *s) {
73  uint_t i,j;
74  for (i=0; i< s->height; i++) {
75    for (j=0; j< s->length; j++) {
76      AUBIO_MSG(AUBIO_SMPL_FMT " ", s->data[i][j]);
77    }
78    AUBIO_MSG("\n");
79  }
80}
81
82void fmat_set(fmat_t *s, smpl_t val) {
83  uint_t i,j;
84  for (i=0; i< s->height; i++) {
85    for (j=0; j< s->length; j++) {
86      s->data[i][j] = val;
87    }
88  }
89}
90
91void fmat_zeros(fmat_t *s) {
92#if HAVE_MEMCPY_HACKS
93  uint_t i;
94  for (i=0; i< s->height; i++) {
95    memset(s->data[i], 0, s->length * sizeof(smpl_t));
96  }
97#else
98  fmat_set(s, 0.);
99#endif
100}
101
102void fmat_ones(fmat_t *s) {
103  fmat_set(s, 1.);
104}
105
106void fmat_rev(fmat_t *s) {
107  uint_t i,j;
108  for (i=0; i< s->height; i++) {
109    for (j=0; j< FLOOR(s->length/2); j++) {
110      ELEM_SWAP(s->data[i][j], s->data[i][s->length-1-j]);
111    }
112  }
113}
114
115void fmat_weight(fmat_t *s, fmat_t *weight) {
116  uint_t i,j;
117  uint_t length = MIN(s->length, weight->length);
118  for (i=0; i< s->height; i++) {
119    for (j=0; j< length; j++) {
120      s->data[i][j] *= weight->data[0][j];
121    }
122  }
123}
124
125void fmat_copy(fmat_t *s, fmat_t *t) {
126  if (s->height != t->height) {
127    AUBIO_ERR("trying to copy %d rows to %d rows \n",
128            s->height, t->height);
129    return;
130  }
131  if (s->length != t->length) {
132    AUBIO_ERR("trying to copy %d columns to %d columns\n",
133            s->length, t->length);
134    return;
135  }
136#if HAVE_MEMCPY_HACKS
137  uint_t i;
138  for (i=0; i< s->height; i++) {
139    memcpy(t->data[i], s->data[i], t->length * sizeof(smpl_t));
140  }
141#else
142  uint_t i,j;
143  for (i=0; i< t->height; i++) {
144    for (j=0; j< t->length; j++) {
145      t->data[i][j] = s->data[i][j];
146    }
147  }
148#endif
149}
150
Note: See TracBrowser for help on using the repository browser.