Mercurial > hg > svcore
comparison data/fileio/CSVFileReader.cpp @ 1488:53fa8d57b728 import-audio-data
Add wave model as possible target for CSV import
author | Chris Cannam |
---|---|
date | Thu, 28 Jun 2018 14:49:46 +0100 |
parents | 48e9f538e6e9 |
children | 8d4f09552ba4 |
comparison
equal
deleted
inserted
replaced
1487:71202259002d | 1488:53fa8d57b728 |
---|---|
21 #include "model/SparseOneDimensionalModel.h" | 21 #include "model/SparseOneDimensionalModel.h" |
22 #include "model/SparseTimeValueModel.h" | 22 #include "model/SparseTimeValueModel.h" |
23 #include "model/EditableDenseThreeDimensionalModel.h" | 23 #include "model/EditableDenseThreeDimensionalModel.h" |
24 #include "model/RegionModel.h" | 24 #include "model/RegionModel.h" |
25 #include "model/NoteModel.h" | 25 #include "model/NoteModel.h" |
26 #include "model/WritableWaveFileModel.h" | |
26 #include "DataFileReaderFactory.h" | 27 #include "DataFileReaderFactory.h" |
27 | 28 |
28 #include <QFile> | 29 #include <QFile> |
29 #include <QFileInfo> | 30 #include <QFileInfo> |
30 #include <QString> | 31 #include <QString> |
182 SparseOneDimensionalModel *model1 = 0; | 183 SparseOneDimensionalModel *model1 = 0; |
183 SparseTimeValueModel *model2 = 0; | 184 SparseTimeValueModel *model2 = 0; |
184 RegionModel *model2a = 0; | 185 RegionModel *model2a = 0; |
185 NoteModel *model2b = 0; | 186 NoteModel *model2b = 0; |
186 EditableDenseThreeDimensionalModel *model3 = 0; | 187 EditableDenseThreeDimensionalModel *model3 = 0; |
188 WritableWaveFileModel *modelW = 0; | |
187 Model *model = 0; | 189 Model *model = 0; |
188 | 190 |
189 QTextStream in(m_device); | 191 QTextStream in(m_device); |
190 | 192 |
191 unsigned int warnings = 0, warnLimit = 10; | 193 unsigned int warnings = 0, warnLimit = 10; |
265 (sampleRate, | 267 (sampleRate, |
266 windowSize, | 268 windowSize, |
267 valueColumns, | 269 valueColumns, |
268 EditableDenseThreeDimensionalModel::NoCompression); | 270 EditableDenseThreeDimensionalModel::NoCompression); |
269 model = model3; | 271 model = model3; |
272 break; | |
273 | |
274 case CSVFormat::WaveFileModel: | |
275 modelW = new WritableWaveFileModel | |
276 (sampleRate, valueColumns); | |
277 model = modelW; | |
270 break; | 278 break; |
271 } | 279 } |
272 | 280 |
273 if (model) { | 281 if (model) { |
274 if (m_filename != "") { | 282 if (m_filename != "") { |
400 | 408 |
401 // SVDEBUG << "Setting bin values for count " << lineno << ", frame " | 409 // SVDEBUG << "Setting bin values for count " << lineno << ", frame " |
402 // << frameNo << ", time " << RealTime::frame2RealTime(frameNo, sampleRate) << endl; | 410 // << frameNo << ", time " << RealTime::frame2RealTime(frameNo, sampleRate) << endl; |
403 | 411 |
404 model3->setColumn(lineno, values); | 412 model3->setColumn(lineno, values); |
405 } | 413 |
406 | 414 } else if (modelType == CSVFormat::WaveFileModel) { |
415 | |
416 int channels = modelW->getChannelCount(); | |
417 | |
418 float **samples = | |
419 breakfastquay::allocate_and_zero_channels<float> | |
420 (channels, 1); | |
421 | |
422 for (int i = 0; i < list.size() && i < channels; ++i) { | |
423 | |
424 if (m_format.getColumnPurpose(i) != CSVFormat::ColumnValue) { | |
425 continue; | |
426 } | |
427 | |
428 bool ok = false; | |
429 float value = list[i].toFloat(&ok); | |
430 | |
431 samples[i][0] = value; | |
432 } | |
433 | |
434 bool ok = modelW->addSamples(samples, 1); | |
435 | |
436 breakfastquay::deallocate_channels(samples, channels); | |
437 | |
438 if (!ok) { | |
439 if (warnings < warnLimit) { | |
440 SVCERR << "WARNING: CSVFileReader::load: " | |
441 << "Unable to add sample to wave-file model" | |
442 << endl; | |
443 SVCERR << line << endl; | |
444 ++warnings; | |
445 } | |
446 } | |
447 } | |
448 | |
407 ++lineno; | 449 ++lineno; |
408 if (timingType == CSVFormat::ImplicitTiming || | 450 if (timingType == CSVFormat::ImplicitTiming || |
409 list.size() == 0) { | 451 list.size() == 0) { |
410 frameNo += windowSize; | 452 frameNo += windowSize; |
411 } | 453 } |