# HG changeset patch # User Chris Cannam # Date 1536435794 -3600 # Node ID 925d205c39b45f7e716e56850cbb10d5b45ca951 # Parent ad46f6e803698e925fafbdcc6b78054694eef270 Handle sample range specification for CSV import diff -r ad46f6e80369 -r 925d205c39b4 data/fileio/CSVFileReader.cpp --- 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; diff -r ad46f6e80369 -r 925d205c39b4 data/model/WritableWaveFileModel.cpp --- a/data/model/WritableWaveFileModel.cpp Fri Sep 07 18:12:20 2018 +0100 +++ b/data/model/WritableWaveFileModel.cpp Sat Sep 08 20:43:14 2018 +0100 @@ -38,7 +38,8 @@ WritableWaveFileModel::WritableWaveFileModel(sv_samplerate_t sampleRate, int channels, - QString path) : + QString path, + bool normaliseOnRead) : m_model(0), m_writer(0), m_reader(0), @@ -72,7 +73,7 @@ FileSource source(m_writer->getPath()); - m_reader = new WavFileReader(source, true); + m_reader = new WavFileReader(source, true, normaliseOnRead); if (!m_reader->getError().isEmpty()) { SVCERR << "WritableWaveFileModel: Error in creating wave file reader" << endl; delete m_reader; diff -r ad46f6e80369 -r 925d205c39b4 data/model/WritableWaveFileModel.h --- a/data/model/WritableWaveFileModel.h Fri Sep 07 18:12:20 2018 +0100 +++ b/data/model/WritableWaveFileModel.h Sat Sep 08 20:43:14 2018 +0100 @@ -28,7 +28,10 @@ Q_OBJECT public: - WritableWaveFileModel(sv_samplerate_t sampleRate, int channels, QString path = ""); + WritableWaveFileModel(sv_samplerate_t sampleRate, + int channels, + QString path = "", + bool normaliseOnRead = false); ~WritableWaveFileModel(); /**