comparison transform/FeatureExtractionPluginTransform.cpp @ 134:7a5ba9dadbf7

* Fix #1706927 NaNs from plugin outputs should not be used
author Chris Cannam
date Fri, 27 Apr 2007 15:39:48 +0000
parents b4110b17bca8
children 006c90387f40
comparison
equal deleted inserted replaced
133:a5733f662a5c 134:7a5ba9dadbf7
121 // std::cerr << "FeatureExtractionPluginTransform: output sample type " 121 // std::cerr << "FeatureExtractionPluginTransform: output sample type "
122 // << m_descriptor->sampleType << std::endl; 122 // << m_descriptor->sampleType << std::endl;
123 123
124 int binCount = 1; 124 int binCount = 1;
125 float minValue = 0.0, maxValue = 0.0; 125 float minValue = 0.0, maxValue = 0.0;
126 bool haveExtents = false;
126 127
127 if (m_descriptor->hasFixedBinCount) { 128 if (m_descriptor->hasFixedBinCount) {
128 binCount = m_descriptor->binCount; 129 binCount = m_descriptor->binCount;
129 } 130 }
130 131
132 // << binCount << std::endl; 133 // << binCount << std::endl;
133 134
134 if (binCount > 0 && m_descriptor->hasKnownExtents) { 135 if (binCount > 0 && m_descriptor->hasKnownExtents) {
135 minValue = m_descriptor->minValue; 136 minValue = m_descriptor->minValue;
136 maxValue = m_descriptor->maxValue; 137 maxValue = m_descriptor->maxValue;
138 haveExtents = true;
137 } 139 }
138 140
139 size_t modelRate = m_input->getSampleRate(); 141 size_t modelRate = m_input->getSampleRate();
140 size_t modelResolution = 1; 142 size_t modelResolution = 1;
141 143
161 m_output = new SparseOneDimensionalModel(modelRate, modelResolution, 163 m_output = new SparseOneDimensionalModel(modelRate, modelResolution,
162 false); 164 false);
163 165
164 } else if (binCount == 1) { 166 } else if (binCount == 1) {
165 167
166 SparseTimeValueModel *model = new SparseTimeValueModel 168 SparseTimeValueModel *model;
167 (modelRate, modelResolution, minValue, maxValue, false); 169 if (haveExtents) {
170 model = new SparseTimeValueModel
171 (modelRate, modelResolution, minValue, maxValue, false);
172 } else {
173 model = new SparseTimeValueModel
174 (modelRate, modelResolution, false);
175 }
168 model->setScaleUnits(outputs[m_outputFeatureNo].unit.c_str()); 176 model->setScaleUnits(outputs[m_outputFeatureNo].unit.c_str());
169 177
170 m_output = model; 178 m_output = model;
171 179
172 } else if (m_descriptor->sampleType == 180 } else if (m_descriptor->sampleType ==
178 // treat the first as pitch, second as duration in frames, 186 // treat the first as pitch, second as duration in frames,
179 // third (if present) as velocity. (Our note model doesn't 187 // third (if present) as velocity. (Our note model doesn't
180 // yet store velocity.) 188 // yet store velocity.)
181 //!!! todo: ask the user! 189 //!!! todo: ask the user!
182 190
183 NoteModel *model = new NoteModel 191 NoteModel *model;
184 (modelRate, modelResolution, minValue, maxValue, false); 192 if (haveExtents) {
193 model = new NoteModel
194 (modelRate, modelResolution, minValue, maxValue, false);
195 } else {
196 model = new NoteModel
197 (modelRate, modelResolution, false);
198 }
185 model->setScaleUnits(outputs[m_outputFeatureNo].unit.c_str()); 199 model->setScaleUnits(outputs[m_outputFeatureNo].unit.c_str());
186 200
187 m_output = model; 201 m_output = model;
188 202
189 } else { 203 } else {
190 204
191 m_output = new EditableDenseThreeDimensionalModel 205 EditableDenseThreeDimensionalModel *model =
206 new EditableDenseThreeDimensionalModel
192 (modelRate, modelResolution, binCount, false); 207 (modelRate, modelResolution, binCount, false);
193 208
194 if (!m_descriptor->binNames.empty()) { 209 if (!m_descriptor->binNames.empty()) {
195 std::vector<QString> names; 210 std::vector<QString> names;
196 for (size_t i = 0; i < m_descriptor->binNames.size(); ++i) { 211 for (size_t i = 0; i < m_descriptor->binNames.size(); ++i) {
197 names.push_back(m_descriptor->binNames[i].c_str()); 212 names.push_back(m_descriptor->binNames[i].c_str());
198 } 213 }
199 (dynamic_cast<EditableDenseThreeDimensionalModel *>(m_output)) 214 model->setBinNames(names);
200 ->setBinNames(names); 215 }
201 } 216
217 m_output = model;
202 } 218 }
203 } 219 }
204 220
205 FeatureExtractionPluginTransform::~FeatureExtractionPluginTransform() 221 FeatureExtractionPluginTransform::~FeatureExtractionPluginTransform()
206 { 222 {