First Version with basic functionality #1

Merged
alex merged 1 commits from dev into master 5 years ago

@ -0,0 +1,29 @@
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
FORMS += \
mainwindow.ui
TRANSLATIONS += \
PA_Calculator_en_US.ts
CONFIG += lrelease
CONFIG += embed_translations
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="en_US"></TS>

@ -0,0 +1,23 @@
#include "mainwindow.h"
#include <QApplication>
#include <QLocale>
#include <QTranslator>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTranslator translator;
const QStringList uiLanguages = QLocale::system().uiLanguages();
for (const QString &locale : uiLanguages) {
const QString baseName = "PA_Calculator_" + QLocale(locale).name();
if (translator.load(":/i18n/" + baseName)) {
a.installTranslator(&translator);
break;
}
}
MainWindow w;
w.show();
return a.exec();
}

@ -0,0 +1,106 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QString>
#include <QtMath>
#include <QMessageBox>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_ComboBox_selectSensUnit_currentIndexChanged(int index)
{
double oldValue=ui->doubleSpinBox_ampInputSens->value();
if (index==0){
ui->doubleSpinBox_ampInputSens->setSuffix(QString(" V"));
ui->doubleSpinBox_ampInputSens->setDecimals(2);
ui->doubleSpinBox_ampInputSens->setValue(0.7746*qPow(10,oldValue/20));
}else{
ui->doubleSpinBox_ampInputSens->setSuffix(QString(" dBu"));
ui->doubleSpinBox_ampInputSens->setDecimals(1);
ui->doubleSpinBox_ampInputSens->setValue(20*std::log10(oldValue/0.7746));
}
}
void MainWindow::on_pushButton_requestLimiter_clicked()
{
qreal vMaxSpeakerInRMS=20*std::log10(qSqrt(ui->spinBox_speakerImp->value()*ui->spinBox_speakerRMSPower->value())/0.7746);
qreal vMaxSpeakerInPeak=20*std::log10(qSqrt(ui->spinBox_speakerImp->value()*ui->spinBox_speakerPeakPower->value())/0.7746);
qreal vAmpSens_volt=0;
qreal vAmpsens_dBu=0;
if(ui->ComboBox_selectSensUnit->currentIndex()==0){
vAmpSens_volt=ui->doubleSpinBox_ampInputSens->value();
vAmpsens_dBu=20*std::log10(vAmpSens_volt/0.7746);
}else{
vAmpSens_volt=qPow(10,ui->doubleSpinBox_ampInputSens->value()/20)*0.7746;
vAmpsens_dBu=ui->doubleSpinBox_ampInputSens->value();
}
qreal voltageGain=20*std::log10(qSqrt(ui->spinBox_AmpImp->value()*ui->spinBox_AmpPower->value())/vAmpSens_volt);
qreal vMaxAmpInRMS=vMaxSpeakerInRMS-voltageGain;
qreal vMaxAmpInPeak=vMaxSpeakerInPeak-voltageGain;
qreal thresholdRMS=-18-(ui->spinBox_digitalNominalLevel->value()-vMaxAmpInRMS);
qreal thresholdPeak=-18-(ui->spinBox_digitalNominalLevel->value()-vMaxAmpInPeak);
qreal attackTimeRMS=(double)1000/ui->spinBox_speakerHPF->value();
qreal releaseTimeRMS=attackTimeRMS*8;
qreal releaseTimePeak=attackTimeRMS;
if (vAmpsens_dBu<vMaxAmpInRMS){
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"));
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(ui->spinBox_speakerImp->value()*ui->spinBox_speakerRMSPower->value()),'f',2)+QString(" V)"));
ui->label_UMaxAmpInRMS->setText(QString("not applicable"));
thresholdPeak=-18-(ui->spinBox_digitalNominalLevel->value()-vAmpsens_dBu);
ui->label_thresholdPeak->setText(QString::number(thresholdPeak,'f',1)+QString(" dBFS"));
ui->label_releaseTimePeak->setText(QString::number(releaseTimePeak,'f',2)+QString(" ms"));
ui->label_UMaxSpeakerInPeak->setText(QString::number(vMaxSpeakerInPeak,'f',2)+QString(" dBU (")+QString::number(qSqrt(ui->spinBox_speakerImp->value()*ui->spinBox_speakerPeakPower->value()),'f',2)+QString(" V)"));
ui->label_UMaxAmpInPeak->setText(QString::number(vAmpSens_volt,'f',2)+QString(" V (= input sensitivity)"));
}else if (vAmpsens_dBu<vMaxAmpInPeak){
QMessageBox msgBox(QMessageBox::Warning,"Amplifier can't deliver maximum peak power","The maximum power level of the amplifier is below the maximum peak 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::number(thresholdRMS,'f',1)+QString(" dBFS"));
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(ui->spinBox_speakerImp->value()*ui->spinBox_speakerRMSPower->value()),'f',2)+QString(" V)"));
ui->label_UMaxAmpInRMS->setText(QString::number(vMaxAmpInRMS,'f',2)+QString(" dBU (")+QString::number(qPow(10,vMaxAmpInRMS/20)*0.7746,'f',2)+QString(" V)"));
thresholdPeak=-18-(ui->spinBox_digitalNominalLevel->value()-vAmpsens_dBu);
ui->label_thresholdPeak->setText(QString::number(thresholdPeak,'f',1)+QString(" dBFS"));
ui->label_releaseTimePeak->setText(QString::number(releaseTimePeak,'f',2)+QString(" ms"));
ui->label_UMaxSpeakerInPeak->setText(QString::number(vMaxSpeakerInPeak,'f',2)+QString(" dBU (")+QString::number(qSqrt(ui->spinBox_speakerImp->value()*ui->spinBox_speakerPeakPower->value()),'f',2)+QString(" V)"));
ui->label_UMaxAmpInPeak->setText(QString::number(vAmpSens_volt,'f',2)+QString(" V (= input sensitivity)"));
}else{
ui->label_thresholdRMS->setText(QString::number(thresholdRMS,'f',1)+QString(" dBFS"));
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(ui->spinBox_speakerImp->value()*ui->spinBox_speakerRMSPower->value()),'f',2)+QString(" V)"));
ui->label_UMaxAmpInRMS->setText(QString::number(vMaxAmpInRMS,'f',2)+QString(" dBU (")+QString::number(qPow(10,vMaxAmpInRMS/20)*0.7746,'f',2)+QString(" V)"));
ui->label_thresholdPeak->setText(QString::number(thresholdPeak,'f',1)+QString(" dBFS"));
ui->label_releaseTimePeak->setText(QString::number(releaseTimePeak,'f',2)+QString(" ms"));
ui->label_UMaxSpeakerInPeak->setText(QString::number(vMaxSpeakerInPeak,'f',2)+QString(" dBU (")+QString::number(qSqrt(ui->spinBox_speakerImp->value()*ui->spinBox_speakerPeakPower->value()),'f',2)+QString(" V)"));
ui->label_UMaxAmpInPeak->setText(QString::number(vMaxAmpInPeak,'f',2)+QString(" dBU (")+QString::number(qPow(10,vMaxAmpInPeak/20)*0.7746,'f',2)+QString(" V)"));
}
}

@ -0,0 +1,26 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private slots:
void on_ComboBox_selectSensUnit_currentIndexChanged(int index);
void on_pushButton_requestLimiter_clicked();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H

@ -0,0 +1,489 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>931</width>
<height>460</height>
</rect>
</property>
<property name="windowTitle">
<string>PA Calculator</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Amplifier Specifications</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Rated Power</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="spinBox_AmpPower">
<property name="suffix">
<string> W</string>
</property>
<property name="prefix">
<string/>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>10000</number>
</property>
<property name="value">
<number>380</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Impedance Rating</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="spinBox_AmpImp">
<property name="suffix">
<string> Ohm</string>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>32</number>
</property>
<property name="value">
<number>8</number>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Input Sensitivity</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBox_ampInputSens">
<property name="suffix">
<string> V</string>
</property>
<property name="minimum">
<double>0.010000000000000</double>
</property>
<property name="value">
<double>1.100000000000000</double>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="ComboBox_selectSensUnit">
<item>
<property name="text">
<string>in Volt</string>
</property>
</item>
<item>
<property name="text">
<string>in dBu</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Speaker Specifications</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Rated Impedance</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="spinBox_speakerImp">
<property name="suffix">
<string> Ohm</string>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>32</number>
</property>
<property name="value">
<number>8</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>RMS Power</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="spinBox_speakerRMSPower">
<property name="suffix">
<string> W</string>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>10000</number>
</property>
<property name="value">
<number>400</number>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Peak Power</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="spinBox_speakerPeakPower">
<property name="suffix">
<string> W</string>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>10000</number>
</property>
<property name="value">
<number>1200</number>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Crossover highpass-frequency</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="spinBox_speakerHPF">
<property name="suffix">
<string> Hz</string>
</property>
<property name="minimum">
<number>10</number>
</property>
<property name="maximum">
<number>20000</number>
</property>
<property name="value">
<number>120</number>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>DA-Converter Specifications</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<layout class="QFormLayout" name="formLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Nominal Output Level (at -18 dBFS)</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="spinBox_digitalNominalLevel">
<property name="suffix">
<string> dBu</string>
</property>
<property name="minimum">
<number>-100</number>
</property>
<property name="maximum">
<number>100</number>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QPushButton" name="pushButton_requestLimiter">
<property name="text">
<string>Request Limiter Settings</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QGroupBox" name="groupBox_4">
<property name="title">
<string>RMS Limiter</string>
</property>
<property name="flat">
<bool>false</bool>
</property>
<property name="checkable">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<layout class="QFormLayout" name="formLayout_4">
<item row="3" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>maximum Voltage at speaker input:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="label_UMaxSpeakerInRMS">
<property name="text">
<string>0 dBU</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>maximum Voltage at amplifier input:</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="label_UMaxAmpInRMS">
<property name="text">
<string>0 dBU</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Threshold:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_thresholdRMS">
<property name="font">
<font>
<pointsize>15</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>0 dBFS</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_12">
<property name="text">
<string>Attack Time:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label_attackTimeRMS">
<property name="font">
<font>
<pointsize>15</pointsize>
</font>
</property>
<property name="text">
<string>0 ms</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_14">
<property name="text">
<string>Release Time:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="label_releaseTimeRMS">
<property name="font">
<font>
<pointsize>15</pointsize>
</font>
</property>
<property name="text">
<string>0 ms</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_5">
<property name="title">
<string>Peak Limiter</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<layout class="QFormLayout" name="formLayout_5">
<item row="3" column="0">
<widget class="QLabel" name="label_13">
<property name="text">
<string>maximum Voltage at speaker input:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="label_UMaxSpeakerInPeak">
<property name="text">
<string>0 dBU</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_15">
<property name="text">
<string>maximum Voltage at amplifier input:</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="label_UMaxAmpInPeak">
<property name="text">
<string>0 dBU</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_16">
<property name="text">
<string>Threshold:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_thresholdPeak">
<property name="font">
<font>
<pointsize>15</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>0 dBFS</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_17">
<property name="text">
<string>Attack Time:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label_attackTimePeak">
<property name="font">
<font>
<pointsize>15</pointsize>
</font>
</property>
<property name="text">
<string>0 ms</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_18">
<property name="text">
<string>Release Time:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="label_releaseTimePeak">
<property name="font">
<font>
<pointsize>15</pointsize>
</font>
</property>
<property name="text">
<string>0 ms</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>931</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
Loading…
Cancel
Save