tomwalters@268: // Copyright 2010, Thomas Walters tomwalters@268: // tomwalters@268: // AIM-C: A C++ implementation of the Auditory Image Model tomwalters@268: // http://www.acousticscale.org/AIMC tomwalters@268: // tomwalters@318: // Licensed under the Apache License, Version 2.0 (the "License"); tomwalters@318: // you may not use this file except in compliance with the License. tomwalters@318: // You may obtain a copy of the License at tomwalters@268: // tomwalters@318: // http://www.apache.org/licenses/LICENSE-2.0 tomwalters@268: // tomwalters@318: // Unless required by applicable law or agreed to in writing, software tomwalters@318: // distributed under the License is distributed on an "AS IS" BASIS, tomwalters@318: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. tomwalters@318: // See the License for the specific language governing permissions and tomwalters@318: // limitations under the License. tomwalters@268: tomwalters@268: /*! \file tomwalters@268: * \brief Basic data structure for a bank of signals with a common sample tomwalters@268: * rate (in Hz), a centre frequency (in Hz) for each channel, a start time tomwalters@268: * for the signal (in samples) and optionally, a set of strobe points in each tomwalters@268: * channel (a vector of the indices of certain points). This is a struct tomwalters@268: * rather than a class, and data members are accessed directly. Therefore is tomwalters@268: * is up to the users of this structure to use it properly. Never assume that tomwalters@268: * a SignalBank will be set up correctly when you receive it. A basic tomwalters@268: * constructor and initialisation routines are provided. tomwalters@268: */ tomwalters@268: tomwalters@268: /*! \author: Thomas Walters tomwalters@268: * \date 2010/01/23 tomwalters@296: * \version \$Id$ tomwalters@268: */ tomwalters@268: tomwalters@283: #ifndef AIMC_SUPPORT_SIGNALBANK_H_ tomwalters@283: #define AIMC_SUPPORT_SIGNALBANK_H_ tomwalters@268: tomwalters@268: #include tomwalters@268: #include tomwalters@268: tomwalters@268: #include "Support/Common.h" tomwalters@268: tomwalters@268: namespace aimc { tomwalters@268: using std::deque; tomwalters@268: using std::vector; tomwalters@268: class SignalBank { tomwalters@268: public: tomwalters@268: SignalBank(); tomwalters@268: ~SignalBank(); tomwalters@268: bool Initialize(int channel_count, int signal_length, float sample_rate); tomwalters@268: tomwalters@268: /* \brief Initialize the signal bank with the same parameters, buffer size tomwalters@268: * and centre frequencies as the input signal bank tomwalters@268: */ tomwalters@268: bool Initialize(const SignalBank &input); tomwalters@268: bool Validate() const; tomwalters@273: tomwalters@397: // Return a const reference to an individual signal. Allows for tomwalters@397: // signal[channel][sample] referencing of SignalBanks. tomwalters@273: inline const vector &operator[](int channel) const { tomwalters@273: return signals_[channel]; tomwalters@273: }; tomwalters@273: tomwalters@397: // Return a const reference to an individual signal. tomwalters@336: inline const vector &get_signal(int channel) const { tomwalters@336: return signals_[channel]; tomwalters@336: }; tomwalters@569: tomwalters@569: inline const vector& get_strobes(int channel) const { tomwalters@569: //DCHECK(channel > 0); tomwalters@569: //DCHECK(channel < strobes.size()); tomwalters@569: return strobes_[channel]; tomwalters@569: }; tomwalters@443: tomwalters@397: // Return a reference to the signal vector. The reference is not tomwalters@397: // const, so the vector is directly modifiable. In order to maintain tomwalters@397: // consistency of the data within the filterbank, the size of this tomwalters@397: // vector should not be changed. Changes to the vector size can be picked tomwalters@397: // up with a call to Validate(), which will return false if the sizes of tomwalters@397: // channle vectors are not consistent. tomwalters@397: inline vector &get_mutable_signal(int channel) { tomwalters@397: return signals_[channel]; tomwalters@397: }; tomwalters@443: tomwalters@337: inline void set_signal(int channel, vector input) { tomwalters@337: signals_[channel] = input; tomwalters@337: } tomwalters@336: tomwalters@305: inline float sample(int channel, int index) const { tomwalters@305: return signals_[channel][index]; tomwalters@305: } tomwalters@305: tomwalters@305: inline void set_sample(int channel, int index, float value) { tomwalters@305: signals_[channel][index] = value; tomwalters@305: } tomwalters@305: tomwalters@277: int strobe(int channel, int index) const; tomwalters@277: int strobe_count(int channel) const; tomwalters@277: void AddStrobe(int channel, int time); tomwalters@277: void ResetStrobes(int channel); tomwalters@268: float sample_rate() const; tomwalters@268: int buffer_length() const; tomwalters@268: int start_time() const; tomwalters@268: void set_start_time(int start_time); tomwalters@277: float centre_frequency(int i) const; tomwalters@268: void set_centre_frequency(int i, float cf); tomwalters@268: bool initialized() const; tomwalters@268: int channel_count() const; tom@420: void Clear(); tomwalters@268: private: tomwalters@268: int channel_count_; tomwalters@268: int buffer_length_; tomwalters@268: vector > signals_; tomwalters@277: vector > strobes_; tomwalters@268: vector centre_frequencies_; tomwalters@268: float sample_rate_; tomwalters@268: int start_time_; tomwalters@268: bool initialized_; tomwalters@268: DISALLOW_COPY_AND_ASSIGN(SignalBank); tomwalters@268: }; tomwalters@268: } tomwalters@268: tomwalters@283: #endif // AIMC_SUPPORT_SIGNALBANK_H_