source: src/cvec.c @ 75be651

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

src/cvec.{c,h}: add cvec_set, cvec_zeros and cvec_ones

  • Property mode set to 100644
File size: 3.0 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 "cvec.h"
23
24cvec_t * new_cvec( uint_t length, uint_t channels) {
25  cvec_t * s = AUBIO_NEW(cvec_t);
26  uint_t i,j;
27  s->channels = channels;
28  s->length = length/2 + 1;
29  s->norm = AUBIO_ARRAY(smpl_t*,s->channels);
30  s->phas = AUBIO_ARRAY(smpl_t*,s->channels);
31  for (i=0; i< s->channels; i++) {
32    s->norm[i] = AUBIO_ARRAY(smpl_t,s->length);
33    s->phas[i] = AUBIO_ARRAY(smpl_t,s->length);
34    for (j=0; j< s->length; j++) {
35      s->norm[i][j]=0.;
36      s->phas[i][j]=0.;
37    }
38  }
39  return s;
40}
41
42void del_cvec(cvec_t *s) {
43  uint_t i;
44  for (i=0; i<s->channels; i++) {
45    AUBIO_FREE(s->norm[i]);
46    AUBIO_FREE(s->phas[i]);
47  }
48  AUBIO_FREE(s->norm);
49  AUBIO_FREE(s->phas);
50  AUBIO_FREE(s);
51}
52
53void cvec_write_norm(cvec_t *s, smpl_t data, uint_t channel, uint_t position) {
54  s->norm[channel][position] = data;
55}
56void cvec_write_phas(cvec_t *s, smpl_t data, uint_t channel, uint_t position) {
57  s->phas[channel][position] = data;
58}
59smpl_t cvec_read_norm(cvec_t *s, uint_t channel, uint_t position) {
60  return s->norm[channel][position];
61}
62smpl_t cvec_read_phas(cvec_t *s, uint_t channel, uint_t position) {
63  return s->phas[channel][position];
64}
65void cvec_put_norm_channel(cvec_t *s, smpl_t * data, uint_t channel) {
66  s->norm[channel] = data;
67}
68void cvec_put_phas_channel(cvec_t *s, smpl_t * data, uint_t channel) {
69  s->phas[channel] = data;
70}
71smpl_t * cvec_get_norm_channel(cvec_t *s, uint_t channel) {
72  return s->norm[channel];
73}
74smpl_t * cvec_get_phas_channel(cvec_t *s, uint_t channel) {
75  return s->phas[channel];
76}
77smpl_t ** cvec_get_norm(cvec_t *s) {
78  return s->norm;
79}
80smpl_t ** cvec_get_phas(cvec_t *s) {
81  return s->phas;
82}
83
84/* helper functions */
85
86void cvec_print(cvec_t *s) {
87  uint_t i,j;
88  for (i=0; i< s->channels; i++) {
89    AUBIO_MSG("norm: ");
90    for (j=0; j< s->length; j++) {
91      AUBIO_MSG(AUBIO_SMPL_FMT " ", s->norm[i][j]);
92    }
93    AUBIO_MSG("\n");
94    AUBIO_MSG("phas: ");
95    for (j=0; j< s->length; j++) {
96      AUBIO_MSG(AUBIO_SMPL_FMT " ", s->phas[i][j]);
97    }
98    AUBIO_MSG("\n");
99  }
100}
101
102void cvec_set(cvec_t *s, smpl_t val) {
103  uint_t i,j;
104  for (i=0; i< s->channels; i++) {
105    for (j=0; j< s->length; j++) {
106      s->norm[i][j] = val;
107    }
108  }
109}
110
111void cvec_zeros(cvec_t *s) {
112  cvec_set(s, 0.);
113}
114
115void cvec_ones(cvec_t *s) {
116  cvec_set(s, 1.);
117}
118
Note: See TracBrowser for help on using the repository browser.