annotate src/Support/SignalBank.cc @ 5:3c782dec2fc0

- Ported over HTK file output - Added some more meat to the Slaney IIR gammatone implementation - Ported over the AIM-MAT sf2003 parabola strobe algorithm - Finished making the SAI implementation compile - Ported over the strobe list class (now uses STL deques internally)
author tomwalters
date Thu, 18 Feb 2010 16:55:40 +0000
parents bc394a985042
children 9122efd2b227
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@0 6 // This program is free software: you can redistribute it and/or modify
tomwalters@0 7 // it under the terms of the GNU General Public License as published by
tomwalters@0 8 // the Free Software Foundation, either version 3 of the License, or
tomwalters@0 9 // (at your option) any later version.
tomwalters@0 10 //
tomwalters@0 11 // This program is distributed in the hope that it will be useful,
tomwalters@0 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
tomwalters@0 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
tomwalters@0 14 // GNU General Public License for more details.
tomwalters@0 15 //
tomwalters@0 16 // You should have received a copy of the GNU General Public License
tomwalters@0 17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
tomwalters@0 18
tomwalters@0 19 /*! \file
tomwalters@0 20 * \brief
tomwalters@0 21 */
tomwalters@0 22
tomwalters@0 23 /*! \author: Thomas Walters <tom@acousticscale.org>
tomwalters@0 24 * \date 2010/01/23
tomwalters@0 25 * \version \$Id$
tomwalters@0 26 */
tomwalters@0 27
tomwalters@0 28 #include "Support/SignalBank.h"
tomwalters@0 29
tomwalters@0 30 namespace aimc {
tomwalters@0 31 using std::deque;
tomwalters@0 32 using std::vector;
tomwalters@0 33
tomwalters@0 34 SignalBank::SignalBank() {
tomwalters@0 35 sample_rate_ = 0.0f;
tomwalters@0 36 start_time_ = 0;
tomwalters@0 37 channel_count_ = 0;
tomwalters@0 38 buffer_length_ = 0;
tomwalters@0 39 initialized_ = false;
tomwalters@0 40 }
tomwalters@0 41
tomwalters@0 42 SignalBank::~SignalBank() {
tomwalters@0 43 }
tomwalters@0 44
tomwalters@0 45 bool SignalBank::Initialize(int channel_count,
tomwalters@0 46 int signal_length,
tomwalters@0 47 float sample_rate) {
tomwalters@0 48 if (channel_count < 1)
tomwalters@0 49 return false;
tomwalters@0 50 if (signal_length < 1)
tomwalters@0 51 return false;
tomwalters@0 52 if (sample_rate < 0.0f)
tomwalters@0 53 return false;
tomwalters@0 54
tomwalters@0 55 start_time_ = 0;
tomwalters@0 56 sample_rate_ = sample_rate;
tomwalters@0 57 buffer_length_ = signal_length;
tomwalters@0 58 channel_count_ = channel_count;
tomwalters@0 59 signals_.resize(channel_count_);
tomwalters@0 60 strobes_.resize(channel_count_);
tomwalters@0 61 centre_frequencies_.resize(channel_count_, 0.0f);
tomwalters@0 62 for (int i = 0; i < channel_count_; ++i) {
tomwalters@0 63 signals_[i].resize(buffer_length_, 0.0f);
tomwalters@0 64 }
tomwalters@0 65 initialized_ = true;
tomwalters@0 66 return true;
tomwalters@0 67 }
tomwalters@0 68
tomwalters@0 69 bool SignalBank::Initialize(const SignalBank &input) {
tomwalters@0 70 if (input.channel_count() < 1)
tomwalters@0 71 return false;
tomwalters@0 72 if (input.buffer_length() < 1)
tomwalters@0 73 return false;
tomwalters@0 74 if (input.sample_rate() < 0.0f)
tomwalters@0 75 return false;
tomwalters@0 76
tomwalters@0 77 start_time_ = input.start_time();
tomwalters@0 78 sample_rate_ = input.sample_rate();
tomwalters@0 79 buffer_length_ = input.buffer_length();
tomwalters@0 80 channel_count_ = input.channel_count();
tomwalters@0 81
tomwalters@0 82 signals_.resize(channel_count_);
tomwalters@0 83 strobes_.resize(channel_count_);
tomwalters@0 84
tomwalters@0 85 centre_frequencies_.resize(channel_count_, 0.0f);
tomwalters@0 86 for (int i = 0; i < channel_count_; ++i) {
tomwalters@5 87 centre_frequencies_[i] = input.centre_frequency(i);
tomwalters@0 88 }
tomwalters@0 89
tomwalters@0 90 for (int i = 0; i < channel_count_; ++i) {
tomwalters@0 91 signals_[i].resize(buffer_length_, 0.0f);
tomwalters@5 92 strobes_[i].resize(0);
tomwalters@0 93 }
tomwalters@0 94 initialized_ = true;
tomwalters@0 95 return true;
tomwalters@0 96 }
tomwalters@0 97
tomwalters@0 98 bool SignalBank::Validate() const {
tomwalters@0 99 if (sample_rate_ <= 0.0f)
tomwalters@0 100 return false;
tomwalters@0 101
tomwalters@0 102 if (static_cast<int>(signals_.size()) < 1)
tomwalters@0 103 return false;
tomwalters@0 104
tomwalters@0 105 if (static_cast<int>(signals_.size()) != channel_count_)
tomwalters@0 106 return false;
tomwalters@0 107
tomwalters@0 108 if (static_cast<int>(strobes_.size()) != channel_count_)
tomwalters@0 109 return false;
tomwalters@0 110
tomwalters@0 111 for (int i = 0; i < channel_count_; ++i) {
tomwalters@0 112 if (static_cast<int>(signals_[i].size()) != buffer_length_)
tomwalters@0 113 return false;
tomwalters@0 114 }
tomwalters@0 115 return true;
tomwalters@0 116 }
tomwalters@0 117
tomwalters@1 118 float SignalBank::sample(int channel, int index) const {
tomwalters@0 119 return signals_[channel][index];
tomwalters@0 120 }
tomwalters@0 121
tomwalters@1 122 void SignalBank::set_sample(int channel, int index, float value) {
tomwalters@0 123 signals_[channel][index] = value;
tomwalters@0 124 }
tomwalters@0 125
tomwalters@5 126 int SignalBank::strobe(int channel, int index) const {
tomwalters@5 127 return strobes_[channel][index];
tomwalters@5 128 }
tomwalters@5 129
tomwalters@5 130 int SignalBank::strobe_count(int channel) const {
tomwalters@5 131 return strobes_[channel].size();
tomwalters@5 132 }
tomwalters@5 133
tomwalters@5 134 void SignalBank::AddStrobe(int channel, int time) {
tomwalters@5 135 strobes_[channel].push_back(time);
tomwalters@5 136 }
tomwalters@5 137
tomwalters@5 138 void SignalBank::ResetStrobes(int channel) {
tomwalters@5 139 strobes_[channel].resize(0);
tomwalters@0 140 }
tomwalters@0 141
tomwalters@0 142 float SignalBank::sample_rate() const {
tomwalters@0 143 return sample_rate_;
tomwalters@0 144 }
tomwalters@0 145
tomwalters@0 146 int SignalBank::buffer_length() const {
tomwalters@0 147 return buffer_length_;
tomwalters@0 148 }
tomwalters@0 149
tomwalters@0 150 int SignalBank::start_time() const {
tomwalters@0 151 return start_time_;
tomwalters@0 152 }
tomwalters@0 153
tomwalters@0 154 void SignalBank::set_start_time(int start_time) {
tomwalters@0 155 start_time_ = start_time;
tomwalters@0 156 }
tomwalters@0 157
tomwalters@5 158 float SignalBank::centre_frequency(int i) const {
tomwalters@0 159 if (i < channel_count_)
tomwalters@0 160 return centre_frequencies_[i];
tomwalters@0 161 else
tomwalters@0 162 return 0.0f;
tomwalters@0 163 }
tomwalters@0 164
tomwalters@0 165 void SignalBank::set_centre_frequency(int i, float cf) {
tomwalters@0 166 if (i < channel_count_)
tomwalters@0 167 centre_frequencies_[i] = cf;
tomwalters@0 168 }
tomwalters@0 169
tomwalters@0 170 bool SignalBank::initialized() const {
tomwalters@0 171 return initialized_;
tomwalters@0 172 }
tomwalters@0 173
tomwalters@0 174 int SignalBank::channel_count() const {
tomwalters@0 175 return channel_count_;
tomwalters@0 176 }
tomwalters@0 177 }