summaryrefslogtreecommitdiff
path: root/src/fmat.h
blob: 8e65d110e19df4612138077f3c1332ae67ab4a8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
  Copyright (C) 2009-2015 Paul Brossier <piem@aubio.org>

  This file is part of aubio.

  aubio is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  aubio is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with aubio.  If not, see <http://www.gnu.org/licenses/>.

*/

#ifndef AUBIO_FMAT_H
#define AUBIO_FMAT_H

#ifdef __cplusplus
extern "C" {
#endif

/** \file

  Matrix of real valued data

  This file specifies the fmat_t type, which is used in aubio to store arrays
  of floating point values.

  \example test-fmat.c

*/

/** Buffer for real data */
typedef struct {
  uint_t length; /**< length of matrix */
  uint_t height; /**< height of matrix */
  smpl_t **data; /**< data array of size [length] * [height] */
} fmat_t;

/** fmat_t buffer creation function

  \param length the length of the matrix to create
  \param height the height of the matrix to create

*/
fmat_t * new_fmat(uint_t height, uint_t length);

/** fmat_t buffer deletion function

  \param s buffer to delete as returned by new_fmat()

*/
void del_fmat(fmat_t *s);

/** read sample value in a buffer

  \param s vector to read from
  \param channel channel to read from
  \param position sample position to read from

*/
smpl_t fmat_get_sample(const fmat_t *s, uint_t channel, uint_t position);

/** write sample value in a buffer

  \param s vector to write to
  \param data value to write in s->data[channel][position]
  \param channel channel to write to
  \param position sample position to write to

*/
void  fmat_set_sample(fmat_t *s, smpl_t data, uint_t channel, uint_t position);

/** read channel vector from a buffer

  \param s vector to read from
  \param channel channel to read from
  \param output ::fvec_t to output to

*/
void fmat_get_channel (const fmat_t *s, uint_t channel, fvec_t *output);

/** get vector buffer from an fmat data

  \param s vector to read from
  \param channel channel to read from

*/
smpl_t * fmat_get_channel_data (const fmat_t *s, uint_t channel);

/** read data from a buffer

  \param s vector to read from

*/
smpl_t ** fmat_get_data(const fmat_t *s);

/** print out fmat data

  \param s vector to print out

*/
void fmat_print(const fmat_t *s);

/** set all elements to a given value

  \param s vector to modify
  \param val value to set elements to

*/
void fmat_set(fmat_t *s, smpl_t val);

/** set all elements to zero

  \param s vector to modify

*/
void fmat_zeros(fmat_t *s);

/** set all elements to ones

  \param s vector to modify

*/
void fmat_ones(fmat_t *s);

/** revert order of vector elements

  \param s vector to revert

*/
void fmat_rev(fmat_t *s);

/** apply weight to vector

  If the weight vector is longer than s, only the first elements are used. If
  the weight vector is shorter than s, the last elements of s are not weighted.

  \param s vector to weight
  \param weight weighting coefficients

*/
void fmat_weight(fmat_t *s, const fmat_t *weight);

/** make a copy of a matrix

  \param s source vector
  \param t vector to copy to

*/
void fmat_copy(const fmat_t *s, fmat_t *t);

/** compute the product of a matrix by a vector

   \param s matrix to compute product with
   \param scale vector to compute product with
   \param output vector to store restults in

*/
void fmat_vecmul(const fmat_t *s, const fvec_t *scale, fvec_t *output);

#ifdef __cplusplus
}
#endif

#endif /* AUBIO_FMAT_H */