From 48df7e77d7457c91386a4465320cd00de9ba4af9 Mon Sep 17 00:00:00 2001 From: Alexander Diamadis Date: Thu, 3 Mar 2022 17:32:01 +0100 Subject: [PATCH] Gain Structure Optimization Option added --- source/library.cpp | 92 ++++++++++++--------------- source/mainwindow.cpp | 28 ++++++++- source/mainwindow.h | 2 + source/mainwindow.ui | 143 ++++++++++++++++++++++++++++++++---------- 4 files changed, 180 insertions(+), 85 deletions(-) diff --git a/source/library.cpp b/source/library.cpp index c4b9211..dbc4dd4 100644 --- a/source/library.cpp +++ b/source/library.cpp @@ -254,28 +254,24 @@ void library::printAllAmps() void library::on_listWidget_ampView_currentRowChanged(int currentRow) { - if (initAmps){ - if (currentRow>=0){ - ui->lineEdit_ampName->setText(QString::fromStdString(m_pCamp[currentRow].getName())); - ui->comboBox_sensUnit->setCurrentIndex(m_pCamp[currentRow].getSensivityUnit()); - ui->doubleSpinBox_inputSensitivity->setValue(m_pCamp[currentRow].getSensitivity()); - refreshModeOverview(); - ui->listWidget_modeSelector->setCurrentRow(0); - ui->lineEdit_ampName->setEnabled(true); - ui->doubleSpinBox_inputSensitivity->setEnabled(true); - ui->comboBox_sensUnit->setEnabled(true); - ui->lineEdit_modeName->setEnabled(true); - ui->listWidget_modeSelector->setEnabled(true); - ui->spinBox_ratedImp->setEnabled(true); - ui->spinBox_ratedPower->setEnabled(true); + if (currentRow>=0){ + ui->lineEdit_ampName->setText(QString::fromStdString(m_pCamp[currentRow].getName())); + ui->comboBox_sensUnit->setCurrentIndex(m_pCamp[currentRow].getSensivityUnit()); + ui->doubleSpinBox_inputSensitivity->setValue(m_pCamp[currentRow].getSensitivity()); + refreshModeOverview(); + ui->listWidget_modeSelector->setCurrentRow(0); + ui->lineEdit_ampName->setEnabled(true); + ui->doubleSpinBox_inputSensitivity->setEnabled(true); + ui->comboBox_sensUnit->setEnabled(true); + ui->lineEdit_modeName->setEnabled(true); + ui->listWidget_modeSelector->setEnabled(true); + ui->spinBox_ratedImp->setEnabled(true); + ui->spinBox_ratedPower->setEnabled(true); - }else - { - ui->lineEdit_ampName->setEnabled(false); - ui->doubleSpinBox_inputSensitivity->setEnabled(false); - } - }else { - initAmps =true; + }else + { + ui->lineEdit_ampName->setEnabled(false); + ui->doubleSpinBox_inputSensitivity->setEnabled(false); } } @@ -436,29 +432,25 @@ void library::on_pushButton_addSpeaker_clicked() void library::on_listWidget_speakerView_currentRowChanged(int currentRow) { - if (initSpeaker){ - if (currentRow>=0){ - ui->lineEdit_speakerName->setText(QString::fromStdString(m_pSpeaker[currentRow].getName())); - ui->spinBox_speakerImp->setValue(m_pSpeaker[currentRow].getImpedance()); - ui->spinBox_speakerRMSPower->setValue(m_pSpeaker[currentRow].getRMSPower()); - ui->spinBox_speakerPeakPower->setValue(m_pSpeaker[currentRow].getPeakPower()); - ui->spinBox_speakerHPF->setValue(m_pSpeaker[currentRow].getHPF()); + if (currentRow>=0){ + ui->lineEdit_speakerName->setText(QString::fromStdString(m_pSpeaker[currentRow].getName())); + ui->spinBox_speakerImp->setValue(m_pSpeaker[currentRow].getImpedance()); + ui->spinBox_speakerRMSPower->setValue(m_pSpeaker[currentRow].getRMSPower()); + ui->spinBox_speakerPeakPower->setValue(m_pSpeaker[currentRow].getPeakPower()); + ui->spinBox_speakerHPF->setValue(m_pSpeaker[currentRow].getHPF()); - ui->lineEdit_speakerName->setEnabled(true); - ui->spinBox_speakerImp->setEnabled(true); - ui->spinBox_speakerRMSPower->setEnabled(true); - ui->spinBox_speakerPeakPower->setEnabled(true); - ui->spinBox_speakerHPF->setEnabled(true); + ui->lineEdit_speakerName->setEnabled(true); + ui->spinBox_speakerImp->setEnabled(true); + ui->spinBox_speakerRMSPower->setEnabled(true); + ui->spinBox_speakerPeakPower->setEnabled(true); + ui->spinBox_speakerHPF->setEnabled(true); - }else { - ui->lineEdit_speakerName->setEnabled(false); - //ui->spinBox_speakerImp->setEnabled(false); - //ui->spinBox_speakerRMSPower->setEnabled(false); - //ui->spinBox_speakerPeakPower->setEnabled(false); - //ui->spinBox_speakerHPF->setEnabled(false); - } - }else{ - initSpeaker=true; + }else { + ui->lineEdit_speakerName->setEnabled(false); + //ui->spinBox_speakerImp->setEnabled(false); + //ui->spinBox_speakerRMSPower->setEnabled(false); + //ui->spinBox_speakerPeakPower->setEnabled(false); + //ui->spinBox_speakerHPF->setEnabled(false); } } @@ -579,17 +571,13 @@ void library::on_pushButton_Apply_clicked() void library::on_listWidget_dacView_currentRowChanged(int currentRow) { - if (initDacs){ - if (currentRow>=0){ - ui->lineEdit_dacName->setText(QString::fromStdString(m_pDac[currentRow].name())); - ui->spinBox_dacOutputLevel->setValue(m_pDac[currentRow].outputLevel()); - ui->lineEdit_dacName->setEnabled(true); - ui->spinBox_dacOutputLevel->setEnabled(true); - }else{ - ui->lineEdit_dacName->setEnabled(false); - } + if (currentRow>=0){ + ui->lineEdit_dacName->setText(QString::fromStdString(m_pDac[currentRow].name())); + ui->spinBox_dacOutputLevel->setValue(m_pDac[currentRow].outputLevel()); + ui->lineEdit_dacName->setEnabled(true); + ui->spinBox_dacOutputLevel->setEnabled(true); }else{ - initDacs=true; + ui->lineEdit_dacName->setEnabled(false); } } diff --git a/source/mainwindow.cpp b/source/mainwindow.cpp index 7cb8f2d..9a8d6f4 100644 --- a/source/mainwindow.cpp +++ b/source/mainwindow.cpp @@ -68,6 +68,7 @@ void MainWindow::on_pushButton_requestLimiter_clicked() return; } + qreal vMaxSpeakerInRMS=20*std::log10(qSqrt(speakerImp*speakerRMS)/0.7746); qreal vMaxSpeakerInPeak=20*std::log10(qSqrt(speakerImp*speakerPeak)/0.7746); @@ -91,6 +92,7 @@ void MainWindow::on_pushButton_requestLimiter_clicked() qreal releaseTimeRMS=attackTimeRMS*8; qreal releaseTimePeak=attackTimeRMS; + bool rmsRequired=true; @@ -98,6 +100,7 @@ void MainWindow::on_pushButton_requestLimiter_clicked() QMessageBox msgBox(QMessageBox::Warning,"Amplifier can't deliver maximum RMS power","The maximum power level of the amplifier is below the maximum RMS power level of the speaker. To protect the speaker from a distorted signal the amplifier might deliver, a peak limiter is required with the amplifiers input sensitivty set as its threshold."); msgBox.exec(); ui->label_thresholdRMS->setText(QString("not required")); + rmsRequired=false; ui->label_attackTimeRMS->setText(QString::number(attackTimeRMS,'f',2)+QString(" ms")); ui->label_releaseTimeRMS->setText(QString::number(releaseTimeRMS,'f',2)+QString(" ms")); ui->label_UMaxSpeakerInRMS->setText(QString::number(vMaxSpeakerInRMS,'f',2)+QString(" dBU (")+QString::number(qSqrt(speakerImp*speakerRMS),'f',2)+QString(" V)")); @@ -137,7 +140,20 @@ void MainWindow::on_pushButton_requestLimiter_clicked() ui->label_UMaxAmpInPeak->setText(QString::number(vMaxAmpInPeak,'f',2)+QString(" dBU (")+QString::number(qPow(10,vMaxAmpInPeak/20)*0.7746,'f',2)+QString(" V)")); } - + if (ui->checkBox_optimizeGain->checkState()){ + qreal diff=0; + qreal digitalHeadroom=ui->spinBox_digitalHeadroom->value(); + while (thresholdPeak+diff+1<=-digitalHeadroom){ + diff++; + } + ui->label_thresholdPeak->setText(QString::number(thresholdPeak+diff,'f',1)+QString(" dBFS")); + if (rmsRequired){ + ui->label_thresholdRMS->setText(QString::number(thresholdRMS+diff,'f',1)+QString(" dBFS")); + } + ui->label_inputVolumeControl->setText(QString::number(-diff)+QString(" dB")); + }else { + ui->label_inputVolumeControl->setText(QString("0 dB")); + } } @@ -351,3 +367,13 @@ void MainWindow::on_actionOpen_Loudness_Analyzer_triggered() analyzerWindow.exec(); } + +void MainWindow::on_checkBox_optimizeGain_stateChanged(int arg1) +{ + if (ui->checkBox_optimizeGain->checkState()){ + ui->spinBox_digitalHeadroom->setEnabled(true); + }else{ + ui->spinBox_digitalHeadroom->setEnabled(false); + } +} + diff --git a/source/mainwindow.h b/source/mainwindow.h index 2311435..4642821 100644 --- a/source/mainwindow.h +++ b/source/mainwindow.h @@ -42,6 +42,8 @@ private slots: void on_actionOpen_Loudness_Analyzer_triggered(); + void on_checkBox_optimizeGain_stateChanged(int arg1); + private: Ui::MainWindow *ui; cAmp* m_pCAmp; diff --git a/source/mainwindow.ui b/source/mainwindow.ui index d6a12bb..32ed940 100644 --- a/source/mainwindow.ui +++ b/source/mainwindow.ui @@ -51,6 +51,9 @@ + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + @@ -226,6 +229,9 @@ QLayout::SetDefaultConstraint + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + @@ -407,6 +413,9 @@ + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + @@ -427,16 +436,6 @@ - - - - Load DAC from library - - - - - - @@ -444,6 +443,23 @@ + + + + Output Gain Structure + + + + + + + Optimize + + + true + + + @@ -460,6 +476,16 @@ + + + + Load DAC from library + + + + + + @@ -472,31 +498,34 @@ - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - Qt::Vertical + + + true - - - 20 - 40 - + + dB - + + 0 + + + 30 + + + 5 + + + + + + + Qt::LeftToRight + + + Digital Headroom + + @@ -538,6 +567,12 @@ + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + @@ -568,9 +603,15 @@ + + Qt::LeftToRight + Threshold: + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + @@ -655,6 +696,9 @@ + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + @@ -759,6 +803,41 @@ + + + + + 16 + + + + Amplifier + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + Input Volume Control: + + + + + + + 0 dB + + + + + + + +