c@116
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
c@116
|
2 /*
|
c@116
|
3 Constant-Q library
|
c@116
|
4 Copyright (c) 2013-2014 Queen Mary, University of London
|
c@116
|
5
|
c@116
|
6 Permission is hereby granted, free of charge, to any person
|
c@116
|
7 obtaining a copy of this software and associated documentation
|
c@116
|
8 files (the "Software"), to deal in the Software without
|
c@116
|
9 restriction, including without limitation the rights to use, copy,
|
c@116
|
10 modify, merge, publish, distribute, sublicense, and/or sell copies
|
c@116
|
11 of the Software, and to permit persons to whom the Software is
|
c@116
|
12 furnished to do so, subject to the following conditions:
|
c@116
|
13
|
c@116
|
14 The above copyright notice and this permission notice shall be
|
c@116
|
15 included in all copies or substantial portions of the Software.
|
c@116
|
16
|
c@116
|
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
c@116
|
18 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
c@116
|
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
c@116
|
20 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
c@116
|
21 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
c@116
|
22 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
c@116
|
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
c@116
|
24
|
c@116
|
25 Except as contained in this notice, the names of the Centre for
|
c@116
|
26 Digital Music; Queen Mary, University of London; and Chris Cannam
|
c@116
|
27 shall not be used in advertising or otherwise to promote the sale,
|
c@116
|
28 use or other dealings in this Software without prior written
|
c@116
|
29 authorization.
|
c@116
|
30 */
|
c@116
|
31
|
c@116
|
32 #ifndef CQBASE_H
|
c@116
|
33 #define CQBASE_H
|
c@116
|
34
|
c@116
|
35 #include <vector>
|
c@116
|
36 #include <complex>
|
c@116
|
37
|
c@147
|
38 /**
|
c@147
|
39 * Interface class for Constant-Q implementations, containing common
|
c@147
|
40 * type declarations and means to query configuration parameters.
|
c@147
|
41 */
|
c@147
|
42 class CQBase
|
c@116
|
43 {
|
c@116
|
44 public:
|
c@147
|
45 /// A single complex-valued sample.
|
c@116
|
46 typedef std::complex<double> Complex;
|
c@147
|
47
|
c@147
|
48 /// A series of real-valued samples ordered in time.
|
c@116
|
49 typedef std::vector<double> RealSequence;
|
c@147
|
50
|
c@147
|
51 /// A series of real-valued samples ordered by bin (frequency or similar).
|
c@116
|
52 typedef std::vector<double> RealColumn;
|
c@147
|
53
|
c@147
|
54 /// A series of complex-valued samples ordered in time.
|
c@116
|
55 typedef std::vector<Complex> ComplexSequence;
|
c@147
|
56
|
c@147
|
57 /// A series of complex-valued samples ordered by bin (frequency or similar).
|
c@116
|
58 typedef std::vector<Complex> ComplexColumn;
|
c@147
|
59
|
c@147
|
60 /// A matrix of real-valued samples, indexed by time then bin number.
|
c@116
|
61 typedef std::vector<RealColumn> RealBlock;
|
c@147
|
62
|
c@147
|
63 /// A matrix of complex-valued samples, indexed by time then bin number.
|
c@116
|
64 typedef std::vector<ComplexColumn> ComplexBlock;
|
c@116
|
65
|
c@147
|
66 /**
|
c@147
|
67 * Return true if the Constant-Q implementation was successfully
|
c@147
|
68 * constructed, with a valid set of initialisation parameters.
|
c@147
|
69 */
|
c@147
|
70 virtual bool isValid() const = 0;
|
c@147
|
71
|
c@147
|
72 /**
|
c@147
|
73 * Return the sample rate used when constructing the specific
|
c@147
|
74 * Constant-Q implementation.
|
c@147
|
75 */
|
c@116
|
76 virtual double getSampleRate() const = 0;
|
c@147
|
77
|
c@147
|
78 /**
|
c@147
|
79 * Return the number of bins per octave specified when
|
c@147
|
80 * constructing the Constant-Q implementation.
|
c@147
|
81 */
|
c@116
|
82 virtual int getBinsPerOctave() const = 0;
|
c@147
|
83
|
c@147
|
84 /**
|
c@147
|
85 * Return the number of octaves spanned by the Constant-Q
|
c@147
|
86 * transform.
|
c@147
|
87 */
|
c@116
|
88 virtual int getOctaves() const = 0;
|
c@147
|
89
|
c@147
|
90 /**
|
c@147
|
91 * Return the total number of bins in each Constant-Q column
|
c@147
|
92 * (i.e. bins-per-octave times number of octaves).
|
c@147
|
93 */
|
c@116
|
94 virtual int getTotalBins() const = 0;
|
c@147
|
95
|
c@147
|
96 /**
|
c@147
|
97 * Return the spacing, in samples at the sample rate returned from
|
c@147
|
98 * getSampleRate(), between one column and the next.
|
c@147
|
99 */
|
c@116
|
100 virtual int getColumnHop() const = 0;
|
c@147
|
101
|
c@147
|
102 /**
|
c@147
|
103 * Return the latency of Constant-Q calculation, in samples at the
|
c@147
|
104 * sample rate returned from getSampleRate().
|
c@147
|
105 */
|
c@116
|
106 virtual int getLatency() const = 0;
|
c@147
|
107
|
c@147
|
108 /**
|
c@147
|
109 * Return the maximum frequency of the Constant-Q output, i.e. the
|
c@147
|
110 * frequency of the highest bin in the output. This will normally
|
c@147
|
111 * be the same as the maximum frequency passed to the constructor
|
c@147
|
112 * of the specific Constant-Q implementation.
|
c@147
|
113 */
|
c@116
|
114 virtual double getMaxFrequency() const = 0;
|
c@147
|
115
|
c@147
|
116 /**
|
c@147
|
117 * Return the minimum frequency of the Constant-Q output, i.e. the
|
c@147
|
118 * frequency of the lowest bin in the output. This is derived from
|
c@147
|
119 * the maximum frequency and octave count, and is not necessarily
|
c@147
|
120 * the same as any minimum frequency requested when constructing
|
c@147
|
121 * the Constant-Q implementation.
|
c@147
|
122 */
|
c@147
|
123 virtual double getMinFrequency() const = 0;
|
c@147
|
124
|
c@147
|
125 /**
|
c@147
|
126 * Return the frequency of a given bin in the Constant-Q
|
c@147
|
127 * output. This actually maps a continuous "bin scale" value to
|
c@147
|
128 * frequency: the bin parameter does not have to be an integer.
|
c@147
|
129 */
|
c@145
|
130 virtual double getBinFrequency(double bin) const = 0;
|
c@116
|
131 };
|
c@116
|
132
|
c@116
|
133 #endif
|