Mercurial > hg > svgui
changeset 1320:6440ba1ffc86 import-audio-data
Sample range
author | Chris Cannam |
---|---|
date | Thu, 06 Sep 2018 16:26:40 +0100 |
parents | fbda05431ce0 |
children | 4616e1e89189 |
files | widgets/CSVAudioFormatDialog.cpp widgets/CSVAudioFormatDialog.h |
diffstat | 2 files changed, 80 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/widgets/CSVAudioFormatDialog.cpp Thu Sep 06 13:58:09 2018 +0100 +++ b/widgets/CSVAudioFormatDialog.cpp Thu Sep 06 16:26:40 2018 +0100 @@ -38,6 +38,7 @@ int maxDisplayCols) : QDialog(parent), m_format(format), + m_sampleRange(RangeSigned1), m_maxDisplayCols(maxDisplayCols), m_fuzzyColumn(-1) { @@ -116,8 +117,7 @@ layout->setColumnStretch(3, 10); layout->setRowStretch(row++, 10); - m_sampleRateLabel = new QLabel(tr("Audio sample rate (Hz):")); - layout->addWidget(m_sampleRateLabel, row, 0); + layout->addWidget(new QLabel(tr("Audio sample rate (Hz):")), row, 0); int sampleRates[] = { 8000, 11025, 12000, 22050, 24000, 32000, @@ -139,6 +139,61 @@ connect(m_sampleRateCombo, SIGNAL(editTextChanged(QString)), this, SLOT(sampleRateChanged(QString))); + m_sampleRange = RangeSigned1; + bool knownSigned = false; + bool knownNonIntegral = false; + + for (int i = 0; i < columns; ++i) { + if (!(format.getColumnQualities()[i] & CSVFormat::ColumnIntegral)) { + knownNonIntegral = true; + if (m_sampleRange == RangeUnsigned255 || + m_sampleRange == RangeSigned32767) { + m_sampleRange = RangeOther; + } + } + if (format.getColumnQualities()[i] & CSVFormat::ColumnLarge) { + if (m_sampleRange == RangeSigned1 || + m_sampleRange == RangeUnsigned255) { + if (knownNonIntegral) { + m_sampleRange = RangeOther; + } else { + m_sampleRange = RangeSigned32767; + } + } + } + if (format.getColumnQualities()[i] & CSVFormat::ColumnSigned) { + knownSigned = true; + if (m_sampleRange == RangeUnsigned255) { + m_sampleRange = RangeSigned32767; + } + } + if (!(format.getColumnQualities()[i] & CSVFormat::ColumnSmall)) { + if (m_sampleRange == RangeSigned1) { + if (knownNonIntegral) { + m_sampleRange = RangeOther; + } else if (knownSigned) { + m_sampleRange = RangeSigned32767; + } else { + m_sampleRange = RangeUnsigned255; + } + } + } + } + + layout->addWidget(new QLabel(tr("Sample values are:")), row, 0); + + m_sampleRangeCombo = new QComboBox; + // NB must be in the same order as the CSVSampleRange enum + m_sampleRangeCombo->addItem(tr("Floating-point in range -1 to 1")); + m_sampleRangeCombo->addItem(tr("8-bit in range 0 to 255")); + m_sampleRangeCombo->addItem(tr("16-bit in range -32768 to 32767")); + m_sampleRangeCombo->addItem(tr("Unknown range: normalise on load")); + m_sampleRangeCombo->setCurrentIndex(int(m_sampleRange)); + + layout->addWidget(m_sampleRangeCombo, row++, 1); + connect(m_sampleRangeCombo, SIGNAL(activated(int)), + this, SLOT(sampleRangeChanged(int))); + QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); layout->addWidget(bb, row++, 0, 1, 4); @@ -160,6 +215,12 @@ return m_format; } +CSVAudioFormatDialog::CSVSampleRange +CSVAudioFormatDialog::getSampleRange() const +{ + return m_sampleRange; +} + void CSVAudioFormatDialog::sampleRateChanged(QString rateString) { @@ -169,6 +230,12 @@ } void +CSVAudioFormatDialog::sampleRangeChanged(int range) +{ + m_sampleRange = (CSVSampleRange) range; +} + +void CSVAudioFormatDialog::columnPurposeChanged(int) { updateFormatFromDialog();
--- a/widgets/CSVAudioFormatDialog.h Thu Sep 06 13:58:09 2018 +0100 +++ b/widgets/CSVAudioFormatDialog.h Thu Sep 06 16:26:40 2018 +0100 @@ -34,20 +34,30 @@ int maxDisplayCols = 5); ~CSVAudioFormatDialog(); + enum CSVSampleRange { + RangeSigned1 = 0, // -1 .. 1 + RangeUnsigned255, // 0 .. 255 + RangeSigned32767, // -32768 .. 32767 + RangeOther // Other/unknown: Normalise on load + }; + CSVFormat getFormat() const; + CSVSampleRange getSampleRange() const; protected slots: void sampleRateChanged(QString); + void sampleRangeChanged(int); void columnPurposeChanged(int purpose); void updateFormatFromDialog(); protected: CSVFormat m_format; + CSVSampleRange m_sampleRange; int m_maxDisplayCols; - QLabel *m_sampleRateLabel; QComboBox *m_sampleRateCombo; + QComboBox *m_sampleRangeCombo; QList<QComboBox *> m_columnPurposeCombos; int m_fuzzyColumn;