comparison data/fileio/CSVFileReader.cpp @ 1517:925d205c39b4 import-audio-data

Handle sample range specification for CSV import
author Chris Cannam
date Sat, 08 Sep 2018 20:43:14 +0100
parents 3299b42d8bdd
children 9c09a3f05139
comparison
equal deleted inserted replaced
1516:ad46f6e80369 1517:925d205c39b4
306 EditableDenseThreeDimensionalModel::NoCompression); 306 EditableDenseThreeDimensionalModel::NoCompression);
307 model = model3; 307 model = model3;
308 break; 308 break;
309 309
310 case CSVFormat::WaveFileModel: 310 case CSVFormat::WaveFileModel:
311 {
312 bool normalise = (m_format.getAudioSampleRange()
313 == CSVFormat::SampleRangeOther);
311 modelW = new WritableWaveFileModel 314 modelW = new WritableWaveFileModel
312 (sampleRate, valueColumns); 315 (sampleRate, valueColumns, QString(), normalise);
313 model = modelW; 316 model = modelW;
314 break; 317 break;
318 }
315 } 319 }
316 320
317 if (model && model->isOK()) { 321 if (model && model->isOK()) {
318 if (m_filename != "") { 322 if (m_filename != "") {
319 model->setObjectName(m_filename); 323 model->setObjectName(m_filename);
467 float **samples = 471 float **samples =
468 breakfastquay::allocate_and_zero_channels<float> 472 breakfastquay::allocate_and_zero_channels<float>
469 (channels, 1); 473 (channels, 1);
470 474
471 int channel = 0; 475 int channel = 0;
476 float shift = 0.f;
477 float scale = 1.f;
478
479 switch (m_format.getAudioSampleRange()) {
480 case CSVFormat::SampleRangeSigned1:
481 case CSVFormat::SampleRangeOther:
482 shift = 0.f;
483 scale = 1.f;
484 break;
485 case CSVFormat::SampleRangeUnsigned255:
486 shift = -128.f;
487 scale = 1.f / 128.f;
488 break;
489 case CSVFormat::SampleRangeSigned32767:
490 shift = 0.f;
491 scale = 1.f / 32768.f;
492 break;
493 }
472 494
473 for (int i = 0; i < list.size() && channel < channels; ++i) { 495 for (int i = 0; i < list.size() && channel < channels; ++i) {
474 496
475 if (m_format.getColumnPurpose(i) != 497 if (m_format.getColumnPurpose(i) !=
476 CSVFormat::ColumnValue) { 498 CSVFormat::ColumnValue) {
477 continue; 499 continue;
478 } 500 }
479 501
480 bool ok = false; 502 bool ok = false;
481 float value = list[i].toFloat(&ok); 503 float value = list[i].toFloat(&ok);
504
505 value += shift;
506 value *= scale;
482 507
483 samples[channel][0] = value; 508 samples[channel][0] = value;
484 509
485 ++channel; 510 ++channel;
486 } 511 }