Mercurial > hg > svcore
diff 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 |
line wrap: on
line diff
--- a/data/fileio/CSVFileReader.cpp Mon Jun 25 14:12:27 2018 +0100 +++ b/data/fileio/CSVFileReader.cpp Thu Jun 28 14:49:46 2018 +0100 @@ -23,6 +23,7 @@ #include "model/EditableDenseThreeDimensionalModel.h" #include "model/RegionModel.h" #include "model/NoteModel.h" +#include "model/WritableWaveFileModel.h" #include "DataFileReaderFactory.h" #include <QFile> @@ -184,6 +185,7 @@ RegionModel *model2a = 0; NoteModel *model2b = 0; EditableDenseThreeDimensionalModel *model3 = 0; + WritableWaveFileModel *modelW = 0; Model *model = 0; QTextStream in(m_device); @@ -268,6 +270,12 @@ EditableDenseThreeDimensionalModel::NoCompression); model = model3; break; + + case CSVFormat::WaveFileModel: + modelW = new WritableWaveFileModel + (sampleRate, valueColumns); + model = modelW; + break; } if (model) { @@ -402,8 +410,42 @@ // << frameNo << ", time " << RealTime::frame2RealTime(frameNo, sampleRate) << endl; model3->setColumn(lineno, values); + + } else if (modelType == CSVFormat::WaveFileModel) { + + int channels = modelW->getChannelCount(); + + float **samples = + breakfastquay::allocate_and_zero_channels<float> + (channels, 1); + + for (int i = 0; i < list.size() && i < channels; ++i) { + + if (m_format.getColumnPurpose(i) != CSVFormat::ColumnValue) { + continue; + } + + bool ok = false; + float value = list[i].toFloat(&ok); + + samples[i][0] = value; + } + + bool ok = modelW->addSamples(samples, 1); + + breakfastquay::deallocate_channels(samples, channels); + + if (!ok) { + if (warnings < warnLimit) { + SVCERR << "WARNING: CSVFileReader::load: " + << "Unable to add sample to wave-file model" + << endl; + SVCERR << line << endl; + ++warnings; + } + } } - + ++lineno; if (timingType == CSVFormat::ImplicitTiming || list.size() == 0) {