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