Mercurial > hg > svcore
changeset 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 | ad46f6e80369 |
children | 9c09a3f05139 |
files | data/fileio/CSVFileReader.cpp data/model/WritableWaveFileModel.cpp data/model/WritableWaveFileModel.h |
diffstat | 3 files changed, 33 insertions(+), 4 deletions(-) [+] |
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;
--- 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;
--- 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(); /**