tomwalters@268
|
1 // Copyright 2010, Thomas Walters
|
tomwalters@268
|
2 //
|
tomwalters@268
|
3 // AIM-C: A C++ implementation of the Auditory Image Model
|
tomwalters@268
|
4 // http://www.acousticscale.org/AIMC
|
tomwalters@268
|
5 //
|
tomwalters@318
|
6 // Licensed under the Apache License, Version 2.0 (the "License");
|
tomwalters@318
|
7 // you may not use this file except in compliance with the License.
|
tomwalters@318
|
8 // You may obtain a copy of the License at
|
tomwalters@268
|
9 //
|
tomwalters@318
|
10 // http://www.apache.org/licenses/LICENSE-2.0
|
tomwalters@268
|
11 //
|
tomwalters@318
|
12 // Unless required by applicable law or agreed to in writing, software
|
tomwalters@318
|
13 // distributed under the License is distributed on an "AS IS" BASIS,
|
tomwalters@318
|
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
tomwalters@318
|
15 // See the License for the specific language governing permissions and
|
tomwalters@318
|
16 // limitations under the License.
|
tomwalters@268
|
17
|
tomwalters@268
|
18 /*! \file
|
tomwalters@268
|
19 * \brief Basic data structure for a bank of signals with a common sample
|
tomwalters@268
|
20 * rate (in Hz), a centre frequency (in Hz) for each channel, a start time
|
tomwalters@268
|
21 * for the signal (in samples) and optionally, a set of strobe points in each
|
tomwalters@268
|
22 * channel (a vector of the indices of certain points). This is a struct
|
tomwalters@268
|
23 * rather than a class, and data members are accessed directly. Therefore is
|
tomwalters@268
|
24 * is up to the users of this structure to use it properly. Never assume that
|
tomwalters@268
|
25 * a SignalBank will be set up correctly when you receive it. A basic
|
tomwalters@268
|
26 * constructor and initialisation routines are provided.
|
tomwalters@268
|
27 */
|
tomwalters@268
|
28
|
tomwalters@268
|
29 /*! \author: Thomas Walters <tom@acousticscale.org>
|
tomwalters@268
|
30 * \date 2010/01/23
|
tomwalters@296
|
31 * \version \$Id$
|
tomwalters@268
|
32 */
|
tomwalters@268
|
33
|
tomwalters@283
|
34 #ifndef AIMC_SUPPORT_SIGNALBANK_H_
|
tomwalters@283
|
35 #define AIMC_SUPPORT_SIGNALBANK_H_
|
tomwalters@268
|
36
|
tomwalters@268
|
37 #include <deque>
|
tomwalters@268
|
38 #include <vector>
|
tomwalters@268
|
39
|
tomwalters@268
|
40 #include "Support/Common.h"
|
tomwalters@268
|
41
|
tomwalters@268
|
42 namespace aimc {
|
tomwalters@268
|
43 using std::deque;
|
tomwalters@268
|
44 using std::vector;
|
tomwalters@268
|
45 class SignalBank {
|
tomwalters@268
|
46 public:
|
tomwalters@268
|
47 SignalBank();
|
tomwalters@268
|
48 ~SignalBank();
|
tomwalters@268
|
49 bool Initialize(int channel_count, int signal_length, float sample_rate);
|
tomwalters@268
|
50
|
tomwalters@268
|
51 /* \brief Initialize the signal bank with the same parameters, buffer size
|
tomwalters@268
|
52 * and centre frequencies as the input signal bank
|
tomwalters@268
|
53 */
|
tomwalters@268
|
54 bool Initialize(const SignalBank &input);
|
tomwalters@268
|
55 bool Validate() const;
|
tomwalters@273
|
56
|
tomwalters@397
|
57 // Return a const reference to an individual signal. Allows for
|
tomwalters@397
|
58 // signal[channel][sample] referencing of SignalBanks.
|
tomwalters@273
|
59 inline const vector<float> &operator[](int channel) const {
|
tomwalters@273
|
60 return signals_[channel];
|
tomwalters@273
|
61 };
|
tomwalters@273
|
62
|
tomwalters@397
|
63 // Return a const reference to an individual signal.
|
tomwalters@336
|
64 inline const vector<float> &get_signal(int channel) const {
|
tomwalters@336
|
65 return signals_[channel];
|
tomwalters@336
|
66 };
|
tomwalters@569
|
67
|
tomwalters@569
|
68 inline const vector<int>& get_strobes(int channel) const {
|
tomwalters@569
|
69 //DCHECK(channel > 0);
|
tomwalters@569
|
70 //DCHECK(channel < strobes.size());
|
tomwalters@569
|
71 return strobes_[channel];
|
tomwalters@569
|
72 };
|
tomwalters@443
|
73
|
tomwalters@397
|
74 // Return a reference to the signal vector. The reference is not
|
tomwalters@397
|
75 // const, so the vector is directly modifiable. In order to maintain
|
tomwalters@397
|
76 // consistency of the data within the filterbank, the size of this
|
tomwalters@397
|
77 // vector should not be changed. Changes to the vector size can be picked
|
tomwalters@397
|
78 // up with a call to Validate(), which will return false if the sizes of
|
tomwalters@397
|
79 // channle vectors are not consistent.
|
tomwalters@397
|
80 inline vector<float> &get_mutable_signal(int channel) {
|
tomwalters@397
|
81 return signals_[channel];
|
tomwalters@397
|
82 };
|
tomwalters@443
|
83
|
tomwalters@337
|
84 inline void set_signal(int channel, vector<float> input) {
|
tomwalters@337
|
85 signals_[channel] = input;
|
tomwalters@337
|
86 }
|
tomwalters@336
|
87
|
tomwalters@305
|
88 inline float sample(int channel, int index) const {
|
tomwalters@305
|
89 return signals_[channel][index];
|
tomwalters@305
|
90 }
|
tomwalters@305
|
91
|
tomwalters@305
|
92 inline void set_sample(int channel, int index, float value) {
|
tomwalters@305
|
93 signals_[channel][index] = value;
|
tomwalters@305
|
94 }
|
tomwalters@305
|
95
|
tomwalters@277
|
96 int strobe(int channel, int index) const;
|
tomwalters@277
|
97 int strobe_count(int channel) const;
|
tomwalters@277
|
98 void AddStrobe(int channel, int time);
|
tomwalters@277
|
99 void ResetStrobes(int channel);
|
tomwalters@268
|
100 float sample_rate() const;
|
tomwalters@268
|
101 int buffer_length() const;
|
tomwalters@268
|
102 int start_time() const;
|
tomwalters@268
|
103 void set_start_time(int start_time);
|
tomwalters@277
|
104 float centre_frequency(int i) const;
|
tomwalters@268
|
105 void set_centre_frequency(int i, float cf);
|
tomwalters@268
|
106 bool initialized() const;
|
tomwalters@268
|
107 int channel_count() const;
|
tom@420
|
108 void Clear();
|
tomwalters@268
|
109 private:
|
tomwalters@268
|
110 int channel_count_;
|
tomwalters@268
|
111 int buffer_length_;
|
tomwalters@268
|
112 vector<vector<float> > signals_;
|
tomwalters@277
|
113 vector<vector<int> > strobes_;
|
tomwalters@268
|
114 vector<float> centre_frequencies_;
|
tomwalters@268
|
115 float sample_rate_;
|
tomwalters@268
|
116 int start_time_;
|
tomwalters@268
|
117 bool initialized_;
|
tomwalters@268
|
118 DISALLOW_COPY_AND_ASSIGN(SignalBank);
|
tomwalters@268
|
119 };
|
tomwalters@268
|
120 }
|
tomwalters@268
|
121
|
tomwalters@283
|
122 #endif // AIMC_SUPPORT_SIGNALBANK_H_
|