annotate src/Support/SignalBank.h @ 611:0fbaf443ec82

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