annotate trunk/src/Support/SignalBank.h @ 337:d10433224758

- Add support for reading and writing vectors from signal banks. Useful for Python.
author tomwalters
date Wed, 04 Aug 2010 20:56:29 +0000
parents 890332908f57
children 7a573750b186
rev   line source
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@273 57 inline const vector<float> &operator[](int channel) const {
tomwalters@273 58 return signals_[channel];
tomwalters@273 59 };
tomwalters@273 60
tomwalters@336 61 inline const vector<float> &get_signal(int channel) const {
tomwalters@336 62 return signals_[channel];
tomwalters@336 63 };
tomwalters@337 64
tomwalters@337 65 inline void set_signal(int channel, vector<float> input) {
tomwalters@337 66 signals_[channel] = input;
tomwalters@337 67 }
tomwalters@336 68
tomwalters@305 69 inline float sample(int channel, int index) const {
tomwalters@305 70 return signals_[channel][index];
tomwalters@305 71 }
tomwalters@305 72
tomwalters@305 73 inline void set_sample(int channel, int index, float value) {
tomwalters@305 74 signals_[channel][index] = value;
tomwalters@305 75 }
tomwalters@305 76
tomwalters@277 77 int strobe(int channel, int index) const;
tomwalters@277 78 int strobe_count(int channel) const;
tomwalters@277 79 void AddStrobe(int channel, int time);
tomwalters@277 80 void ResetStrobes(int channel);
tomwalters@268 81 float sample_rate() const;
tomwalters@268 82 int buffer_length() const;
tomwalters@268 83 int start_time() const;
tomwalters@268 84 void set_start_time(int start_time);
tomwalters@277 85 float centre_frequency(int i) const;
tomwalters@268 86 void set_centre_frequency(int i, float cf);
tomwalters@268 87 bool initialized() const;
tomwalters@268 88 int channel_count() const;
tomwalters@268 89 private:
tomwalters@268 90 int channel_count_;
tomwalters@268 91 int buffer_length_;
tomwalters@268 92 vector<vector<float> > signals_;
tomwalters@277 93 vector<vector<int> > strobes_;
tomwalters@268 94 vector<float> centre_frequencies_;
tomwalters@268 95 float sample_rate_;
tomwalters@268 96 int start_time_;
tomwalters@268 97 bool initialized_;
tomwalters@268 98 DISALLOW_COPY_AND_ASSIGN(SignalBank);
tomwalters@268 99 };
tomwalters@268 100 }
tomwalters@268 101
tomwalters@283 102 #endif // AIMC_SUPPORT_SIGNALBANK_H_