Mercurial > hg > svcore
diff 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 |
line wrap: on
line diff
--- a/data/fileio/CSVFileReader.cpp Fri Sep 07 18:12:20 2018 +0100 +++ b/data/fileio/CSVFileReader.cpp Sat Sep 08 20:43:14 2018 +0100 @@ -308,11 +308,15 @@ break; case CSVFormat::WaveFileModel: + { + bool normalise = (m_format.getAudioSampleRange() + == CSVFormat::SampleRangeOther); modelW = new WritableWaveFileModel - (sampleRate, valueColumns); + (sampleRate, valueColumns, QString(), normalise); model = modelW; break; } + } if (model && model->isOK()) { if (m_filename != "") { @@ -469,6 +473,24 @@ (channels, 1); int channel = 0; + float shift = 0.f; + float scale = 1.f; + + switch (m_format.getAudioSampleRange()) { + case CSVFormat::SampleRangeSigned1: + case CSVFormat::SampleRangeOther: + shift = 0.f; + scale = 1.f; + break; + case CSVFormat::SampleRangeUnsigned255: + shift = -128.f; + scale = 1.f / 128.f; + break; + case CSVFormat::SampleRangeSigned32767: + shift = 0.f; + scale = 1.f / 32768.f; + break; + } for (int i = 0; i < list.size() && channel < channels; ++i) { @@ -479,6 +501,9 @@ bool ok = false; float value = list[i].toFloat(&ok); + + value += shift; + value *= scale; samples[channel][0] = value;