| 
									
										
										
										
											2019-02-17 03:40:11 +01:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							| 
									
										
										
										
											2023-11-19 13:31:45 +01:00
										 |  |  | // Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany //
 | 
					
						
							|  |  |  | // written by Christian Daniel                                                   //
 | 
					
						
							|  |  |  | // Copyright (C) 2016-2020, 2022 Edouard Griffiths, F4EXB <f4exb06@gmail.com>    //
 | 
					
						
							|  |  |  | // Copyright (C) 2022 Jon Beniston, M7RCE <jon@beniston.com>                     //
 | 
					
						
							| 
									
										
										
										
											2019-02-17 03:40:11 +01:00
										 |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // This program is free software; you can redistribute it and/or modify          //
 | 
					
						
							|  |  |  | // it under the terms of the GNU General Public License as published by          //
 | 
					
						
							|  |  |  | // the Free Software Foundation as version 3 of the License, or                  //
 | 
					
						
							| 
									
										
										
										
											2019-04-11 14:43:33 +02:00
										 |  |  | // (at your option) any later version.                                           //
 | 
					
						
							| 
									
										
										
										
											2019-02-17 03:40:11 +01:00
										 |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // This program is distributed in the hope that it will be useful,               //
 | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of                //
 | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the                  //
 | 
					
						
							|  |  |  | // GNU General Public License V3 for more details.                               //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // You should have received a copy of the GNU General Public License             //
 | 
					
						
							|  |  |  | // along with this program. If not, see <http://www.gnu.org/licenses/>.          //
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <math.h>
 | 
					
						
							| 
									
										
										
										
											2018-03-23 18:08:38 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | #include <QTreeWidgetItem>
 | 
					
						
							| 
									
										
										
										
											2019-02-17 03:40:11 +01:00
										 |  |  | #include <QMessageBox>
 | 
					
						
							| 
									
										
										
										
											2022-11-08 22:55:40 +01:00
										 |  |  | #include <QFileDialog>
 | 
					
						
							| 
									
										
										
										
											2019-02-17 03:40:11 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "audio/audiodevicemanager.h"
 | 
					
						
							|  |  |  | #include "audiodialog.h"
 | 
					
						
							| 
									
										
										
										
											2022-12-20 10:31:15 +00:00
										 |  |  | #include "gui/dialpopup.h"
 | 
					
						
							| 
									
										
										
										
											2016-05-04 17:07:26 +02:00
										 |  |  | #include "ui_audiodialog.h"
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 13:36:09 +02:00
										 |  |  | AudioDialogX::AudioDialogX(AudioDeviceManager* audioDeviceManager, QWidget* parent) : | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	QDialog(parent), | 
					
						
							| 
									
										
										
										
											2016-05-04 17:07:26 +02:00
										 |  |  | 	ui(new Ui::AudioDialog), | 
					
						
							| 
									
										
										
										
											2018-03-24 03:36:49 +01:00
										 |  |  | 	m_audioDeviceManager(audioDeviceManager) | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	ui->setupUi(this); | 
					
						
							| 
									
										
										
										
											2017-01-06 12:43:18 +01:00
										 |  |  | 	QTreeWidgetItem* treeItem; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 12:43:18 +01:00
										 |  |  | 	// out panel
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-27 22:32:04 +02:00
										 |  |  | 	AudioDeviceManager::OutputDeviceInfo outDeviceInfo; | 
					
						
							| 
									
										
										
										
											2022-11-17 14:50:16 +00:00
										 |  |  | 	AudioDeviceInfo defaultOutputDeviceInfo = AudioDeviceInfo::defaultOutputDevice(); | 
					
						
							| 
									
										
										
										
											2017-01-06 12:43:18 +01:00
										 |  |  | 	treeItem = new QTreeWidgetItem(ui->audioOutTree); | 
					
						
							| 
									
										
										
										
											2018-03-27 22:32:04 +02:00
										 |  |  | 	treeItem->setText(1, AudioDeviceManager::m_defaultDeviceName); | 
					
						
							|  |  |  | 	bool found = m_audioDeviceManager->getOutputDeviceInfo(AudioDeviceManager::m_defaultDeviceName, outDeviceInfo); | 
					
						
							|  |  |  | 	treeItem->setText(0, found ? "__" : "_D"); | 
					
						
							| 
									
										
										
										
											2018-03-26 11:55:45 +02:00
										 |  |  | 	ui->audioOutTree->setCurrentItem(treeItem); | 
					
						
							| 
									
										
										
										
											2017-01-06 12:43:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 14:50:16 +00:00
										 |  |  | 	const QList<AudioDeviceInfo>& outputDevices = m_audioDeviceManager->getOutputDevices(); | 
					
						
							| 
									
										
										
										
											2017-01-06 12:43:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 14:50:16 +00:00
										 |  |  |     for(QList<AudioDeviceInfo>::const_iterator it = outputDevices.begin(); it != outputDevices.end(); ++it) | 
					
						
							| 
									
										
										
										
											2017-01-06 12:43:18 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         treeItem = new QTreeWidgetItem(ui->audioOutTree); | 
					
						
							| 
									
										
										
										
											2018-03-27 22:32:04 +02:00
										 |  |  |         treeItem->setText(1, it->deviceName()); | 
					
						
							|  |  |  |         bool systemDefault = it->deviceName() == defaultOutputDeviceInfo.deviceName(); | 
					
						
							|  |  |  |         found = m_audioDeviceManager->getOutputDeviceInfo(it->deviceName(), outDeviceInfo); | 
					
						
							|  |  |  |         treeItem->setText(0, QString(systemDefault ? "S" : "_") + QString(found ? "_" : "D")); | 
					
						
							| 
									
										
										
										
											2018-03-26 18:41:09 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-27 22:32:04 +02:00
										 |  |  |         if (systemDefault) { | 
					
						
							|  |  |  |             treeItem->setBackground(1, QBrush(qRgb(96,96,96))); | 
					
						
							| 
									
										
										
										
											2018-03-26 18:41:09 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-01-06 12:43:18 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-27 22:32:04 +02:00
										 |  |  |     ui->audioOutTree->resizeColumnToContents(0); | 
					
						
							|  |  |  |     ui->audioOutTree->resizeColumnToContents(1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 12:43:18 +01:00
										 |  |  |     // in panel
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-27 22:32:04 +02:00
										 |  |  |     AudioDeviceManager::InputDeviceInfo inDeviceInfo; | 
					
						
							| 
									
										
										
										
											2022-11-17 14:50:16 +00:00
										 |  |  |     AudioDeviceInfo defaultInputDeviceInfo = AudioDeviceInfo::defaultInputDevice(); | 
					
						
							| 
									
										
										
										
											2017-01-06 12:43:18 +01:00
										 |  |  |     treeItem = new QTreeWidgetItem(ui->audioInTree); | 
					
						
							| 
									
										
										
										
											2018-03-27 22:32:04 +02:00
										 |  |  |     treeItem->setText(1, AudioDeviceManager::m_defaultDeviceName); | 
					
						
							|  |  |  |     found = m_audioDeviceManager->getInputDeviceInfo(AudioDeviceManager::m_defaultDeviceName, inDeviceInfo); | 
					
						
							|  |  |  |     treeItem->setText(0, found ? "__" : "_D"); | 
					
						
							| 
									
										
										
										
											2018-03-26 11:55:45 +02:00
										 |  |  |     ui->audioInTree->setCurrentItem(treeItem); | 
					
						
							| 
									
										
										
										
											2017-01-06 12:43:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 14:50:16 +00:00
										 |  |  |     const QList<AudioDeviceInfo>& inputDevices = m_audioDeviceManager->getInputDevices(); | 
					
						
							| 
									
										
										
										
											2017-01-06 12:43:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 14:50:16 +00:00
										 |  |  |     for(QList<AudioDeviceInfo>::const_iterator it = inputDevices.begin(); it != inputDevices.end(); ++it) | 
					
						
							| 
									
										
										
										
											2017-01-06 12:43:18 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         treeItem = new QTreeWidgetItem(ui->audioInTree); | 
					
						
							| 
									
										
										
										
											2018-03-27 22:32:04 +02:00
										 |  |  |         treeItem->setText(1, it->deviceName()); | 
					
						
							|  |  |  |         bool systemDefault = it->deviceName() == defaultInputDeviceInfo.deviceName(); | 
					
						
							|  |  |  |         found = m_audioDeviceManager->getInputDeviceInfo(it->deviceName(), inDeviceInfo); | 
					
						
							|  |  |  |         treeItem->setText(0, QString(systemDefault ? "S" : "_") + QString(found ? "_" : "D")); | 
					
						
							| 
									
										
										
										
											2018-03-26 18:41:09 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-27 22:32:04 +02:00
										 |  |  |         if (systemDefault) { | 
					
						
							|  |  |  |             treeItem->setBackground(1, QBrush(qRgb(96,96,96))); | 
					
						
							| 
									
										
										
										
											2018-03-26 18:41:09 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-03-26 11:55:45 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-27 22:32:04 +02:00
										 |  |  |     ui->audioInTree->resizeColumnToContents(0); | 
					
						
							|  |  |  |     ui->audioInTree->resizeColumnToContents(1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-26 11:55:45 +02:00
										 |  |  |     m_outputUDPPort = 9998; | 
					
						
							|  |  |  |     m_outIndex = -1; | 
					
						
							|  |  |  |     m_inIndex = -1; | 
					
						
							| 
									
										
										
										
											2017-01-06 12:43:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-26 11:55:45 +02:00
										 |  |  | 	ui->tabWidget->setCurrentIndex(0); | 
					
						
							| 
									
										
										
										
											2022-12-20 10:31:15 +00:00
										 |  |  |     DialPopup::addPopupsToChildDials(this); | 
					
						
							| 
									
										
										
										
											2018-03-26 11:55:45 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AudioDialogX::~AudioDialogX() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	delete ui; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AudioDialogX::accept() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_inIndex = ui->audioInTree->indexOfTopLevelItem(ui->audioInTree->currentItem()); | 
					
						
							|  |  |  |     m_outIndex = ui->audioOutTree->indexOfTopLevelItem(ui->audioOutTree->currentItem()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (ui->tabWidget->currentIndex() == 0) // output
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         updateOutputDeviceInfo(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (ui->outputResetKey->isChecked()) { | 
					
						
							|  |  |  |             m_audioDeviceManager->unsetOutputDeviceInfo(m_outIndex-1); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             m_audioDeviceManager->setOutputDeviceInfo(m_outIndex-1, m_outputDeviceInfo); | 
					
						
							| 
									
										
										
										
											2017-01-06 12:43:18 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-03-26 11:55:45 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     else if (ui->tabWidget->currentIndex() == 1) // input
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         updateInputDeviceInfo(); | 
					
						
							| 
									
										
										
										
											2017-01-06 12:43:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-26 11:55:45 +02:00
										 |  |  |         if (ui->inputResetKey->isChecked()) { | 
					
						
							|  |  |  |             m_audioDeviceManager->unsetInputDeviceInfo(m_inIndex-1); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             m_audioDeviceManager->setInputDeviceInfo(m_inIndex-1, m_inputDeviceInfo); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-01-06 12:43:18 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-01-06 03:02:57 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-26 11:55:45 +02:00
										 |  |  |     QDialog::accept(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AudioDialogX::reject() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QDialog::reject(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AudioDialogX::on_audioInTree_currentItemChanged( | 
					
						
							|  |  |  |         QTreeWidgetItem* currentItem, | 
					
						
							|  |  |  |         QTreeWidgetItem* previousItem) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     AudioDeviceManager::InputDeviceInfo inDeviceInfo; | 
					
						
							| 
									
										
										
										
											2018-03-27 22:32:04 +02:00
										 |  |  |     QString inDeviceName = currentItem->text(1); | 
					
						
							| 
									
										
										
										
											2018-03-26 11:55:45 +02:00
										 |  |  |     int newIndex = ui->audioInTree->indexOfTopLevelItem(currentItem); | 
					
						
							|  |  |  |     int oldIndex = ui->audioInTree->indexOfTopLevelItem(previousItem); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (newIndex != oldIndex) { | 
					
						
							|  |  |  |         ui->inputResetKey->setChecked(false); | 
					
						
							| 
									
										
										
										
											2017-09-30 04:05:32 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-01-06 03:02:57 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-30 09:42:29 +02:00
										 |  |  |     m_audioDeviceManager->getInputDeviceInfo(inDeviceName, inDeviceInfo); | 
					
						
							| 
									
										
										
										
											2018-03-26 11:55:45 +02:00
										 |  |  |     m_inputDeviceInfo = inDeviceInfo; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-26 11:55:45 +02:00
										 |  |  |     updateInputDisplay(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AudioDialogX::on_audioOutTree_currentItemChanged( | 
					
						
							|  |  |  |         QTreeWidgetItem* currentItem, | 
					
						
							|  |  |  |         QTreeWidgetItem* previousItem) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     AudioDeviceManager::OutputDeviceInfo outDeviceInfo; | 
					
						
							| 
									
										
										
										
											2018-03-27 22:32:04 +02:00
										 |  |  |     QString outDeviceName = currentItem->text(1); | 
					
						
							| 
									
										
										
										
											2018-03-26 11:55:45 +02:00
										 |  |  |     int newIndex = ui->audioOutTree->indexOfTopLevelItem(currentItem); | 
					
						
							|  |  |  |     int oldIndex = ui->audioOutTree->indexOfTopLevelItem(previousItem); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (newIndex != oldIndex) { | 
					
						
							|  |  |  |         ui->outputResetKey->setChecked(false); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-01-06 12:43:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-30 09:42:29 +02:00
										 |  |  |     m_audioDeviceManager->getOutputDeviceInfo(outDeviceName, outDeviceInfo); | 
					
						
							| 
									
										
										
										
											2018-03-26 11:55:45 +02:00
										 |  |  |     m_outputDeviceInfo = outDeviceInfo; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     updateOutputDisplay(); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-26 11:55:45 +02:00
										 |  |  | void AudioDialogX::on_inputVolume_valueChanged(int value) | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-03-26 11:55:45 +02:00
										 |  |  |     float volume = value / 100.0f; | 
					
						
							|  |  |  |     ui->inputVolumeText->setText(QString("%1").arg(volume, 0, 'f', 2)); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-12 18:36:27 +01:00
										 |  |  | void AudioDialogX::on_inputReset_clicked(bool checked) | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-12 18:36:27 +01:00
										 |  |  |     (void) checked; | 
					
						
							| 
									
										
										
										
											2018-03-26 11:55:45 +02:00
										 |  |  |     m_inputDeviceInfo.resetToDefaults(); | 
					
						
							|  |  |  |     updateInputDisplay(); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-01-06 03:13:53 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-12 18:36:27 +01:00
										 |  |  | void AudioDialogX::on_inputCleanup_clicked(bool checked) | 
					
						
							| 
									
										
										
										
											2018-03-26 11:55:45 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-12 18:36:27 +01:00
										 |  |  |     (void) checked; | 
					
						
							| 
									
										
										
										
											2018-03-26 11:55:45 +02:00
										 |  |  |     m_audioDeviceManager->inputInfosCleanup(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AudioDialogX::updateInputDisplay() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ui->inputSampleRate->setValue(m_inputDeviceInfo.sampleRate); | 
					
						
							| 
									
										
										
										
											2018-03-30 19:41:41 +02:00
										 |  |  |     ui->inputVolume->setValue(round(m_inputDeviceInfo.volume * 100.0f)); | 
					
						
							| 
									
										
										
										
											2018-03-26 11:55:45 +02:00
										 |  |  |     ui->inputVolumeText->setText(QString("%1").arg(m_inputDeviceInfo.volume, 0, 'f', 2)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AudioDialogX::updateInputDeviceInfo() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_inputDeviceInfo.sampleRate = ui->inputSampleRate->value(); | 
					
						
							|  |  |  |     m_inputDeviceInfo.volume = ui->inputVolume->value() / 100.0f; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AudioDialogX::on_outputUDPPort_editingFinished() | 
					
						
							| 
									
										
										
										
											2017-01-06 03:13:53 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-03-26 11:55:45 +02:00
										 |  |  |     bool ok; | 
					
						
							|  |  |  |     quint16 udpPort = ui->outputUDPPort->text().toInt(&ok); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if((!ok) || (udpPort < 1024)) { | 
					
						
							|  |  |  |         udpPort = 9999; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_outputUDPPort = udpPort; | 
					
						
							|  |  |  |     ui->outputUDPPort->setText(tr("%1").arg(m_outputDeviceInfo.udpPort)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-12 18:36:27 +01:00
										 |  |  | void AudioDialogX::on_outputReset_clicked(bool checked) | 
					
						
							| 
									
										
										
										
											2018-03-26 11:55:45 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-12 18:36:27 +01:00
										 |  |  |     (void) checked; | 
					
						
							| 
									
										
										
										
											2018-03-26 11:55:45 +02:00
										 |  |  |     m_outputDeviceInfo.resetToDefaults(); | 
					
						
							|  |  |  |     updateOutputDisplay(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-12 18:36:27 +01:00
										 |  |  | void AudioDialogX::on_outputCleanup_clicked(bool checked) | 
					
						
							| 
									
										
										
										
											2018-03-26 11:55:45 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-12 18:36:27 +01:00
										 |  |  |     (void) checked; | 
					
						
							| 
									
										
										
										
											2018-03-26 11:55:45 +02:00
										 |  |  |     m_audioDeviceManager->outputInfosCleanup(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-14 08:31:18 +01:00
										 |  |  | void AudioDialogX::on_outputSampleRate_valueChanged(int value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_outputDeviceInfo.sampleRate = value; | 
					
						
							|  |  |  |     updateOutputSDPString(); | 
					
						
							| 
									
										
										
										
											2019-02-17 06:15:12 +01:00
										 |  |  |     check(); | 
					
						
							| 
									
										
										
										
											2019-02-14 08:31:18 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AudioDialogX::on_decimationFactor_currentIndexChanged(int index) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-02-15 07:57:16 +01:00
										 |  |  |     m_outputDeviceInfo.udpDecimationFactor = index + 1; | 
					
						
							| 
									
										
										
										
											2019-02-14 08:31:18 +01:00
										 |  |  |     updateOutputSDPString(); | 
					
						
							| 
									
										
										
										
											2019-02-17 06:15:12 +01:00
										 |  |  |     check(); | 
					
						
							| 
									
										
										
										
											2019-02-14 08:31:18 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AudioDialogX::on_outputUDPChannelCodec_currentIndexChanged(int index) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-11-12 22:13:44 +01:00
										 |  |  |     m_outputDeviceInfo.udpChannelCodec = (AudioOutputDevice::UDPChannelCodec) index; | 
					
						
							| 
									
										
										
										
											2019-02-14 08:31:18 +01:00
										 |  |  |     updateOutputSDPString(); | 
					
						
							| 
									
										
										
										
											2019-02-17 06:15:12 +01:00
										 |  |  |     check(); | 
					
						
							| 
									
										
										
										
											2019-02-14 08:31:18 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AudioDialogX::on_outputUDPChannelMode_currentIndexChanged(int index) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-11-12 22:13:44 +01:00
										 |  |  |     m_outputDeviceInfo.udpChannelMode = (AudioOutputDevice::UDPChannelMode) index; | 
					
						
							| 
									
										
										
										
											2019-02-14 08:31:18 +01:00
										 |  |  |     updateOutputSDPString(); | 
					
						
							| 
									
										
										
										
											2019-02-17 06:15:12 +01:00
										 |  |  |     check(); | 
					
						
							| 
									
										
										
										
											2019-02-14 08:31:18 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-08 22:55:40 +01:00
										 |  |  | void AudioDialogX::on_record_toggled(bool checked) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ui->showFileDialog->setEnabled(!checked); | 
					
						
							|  |  |  |     m_outputDeviceInfo.recordToFile = checked; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AudioDialogX::on_showFileDialog_clicked(bool checked) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     (void) checked; | 
					
						
							|  |  |  |     QFileDialog fileDialog( | 
					
						
							|  |  |  |         this, | 
					
						
							|  |  |  |         tr("Save record file"), | 
					
						
							|  |  |  |         m_outputDeviceInfo.fileRecordName, | 
					
						
							|  |  |  |         tr("WAV Files (*.wav)") | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     fileDialog.setOptions(QFileDialog::DontUseNativeDialog); | 
					
						
							|  |  |  |     fileDialog.setFileMode(QFileDialog::AnyFile); | 
					
						
							|  |  |  |     QStringList fileNames; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (fileDialog.exec()) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         fileNames = fileDialog.selectedFiles(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (fileNames.size() > 0) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             m_outputDeviceInfo.fileRecordName = fileNames.at(0); | 
					
						
							|  |  |  | 		    ui->fileNameText->setText(m_outputDeviceInfo.fileRecordName); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AudioDialogX::on_recordSilenceTime_valueChanged(int value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_outputDeviceInfo.recordSilenceTime = value; | 
					
						
							|  |  |  |     ui->recordSilenceText->setText(tr("%1").arg(value / 10.0, 0, 'f', 1)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-26 11:55:45 +02:00
										 |  |  | void AudioDialogX::updateOutputDisplay() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-02-17 06:15:12 +01:00
										 |  |  |     ui->outputSampleRate->blockSignals(true); | 
					
						
							|  |  |  |     ui->outputUDPChannelMode->blockSignals(true); | 
					
						
							|  |  |  |     ui->outputUDPChannelCodec->blockSignals(true); | 
					
						
							|  |  |  |     ui->decimationFactor->blockSignals(true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-26 11:55:45 +02:00
										 |  |  |     ui->outputSampleRate->setValue(m_outputDeviceInfo.sampleRate); | 
					
						
							|  |  |  |     ui->outputUDPAddress->setText(m_outputDeviceInfo.udpAddress); | 
					
						
							|  |  |  |     ui->outputUDPPort->setText(tr("%1").arg(m_outputDeviceInfo.udpPort)); | 
					
						
							|  |  |  |     ui->outputUDPCopy->setChecked(m_outputDeviceInfo.copyToUDP); | 
					
						
							|  |  |  |     ui->outputUDPUseRTP->setChecked(m_outputDeviceInfo.udpUseRTP); | 
					
						
							| 
									
										
										
										
											2018-03-26 21:10:09 +02:00
										 |  |  |     ui->outputUDPChannelMode->setCurrentIndex((int) m_outputDeviceInfo.udpChannelMode); | 
					
						
							| 
									
										
										
										
											2019-02-13 07:53:38 +01:00
										 |  |  |     ui->outputUDPChannelCodec->setCurrentIndex((int) m_outputDeviceInfo.udpChannelCodec); | 
					
						
							| 
									
										
										
										
											2019-02-15 07:57:16 +01:00
										 |  |  |     ui->decimationFactor->setCurrentIndex(m_outputDeviceInfo.udpDecimationFactor == 0 ? 0 : m_outputDeviceInfo.udpDecimationFactor - 1); | 
					
						
							| 
									
										
										
										
											2022-11-08 22:55:40 +01:00
										 |  |  |     ui->record->setChecked(m_outputDeviceInfo.recordToFile); | 
					
						
							|  |  |  |     ui->fileNameText->setText(m_outputDeviceInfo.fileRecordName); | 
					
						
							|  |  |  |     ui->showFileDialog->setEnabled(!m_outputDeviceInfo.recordToFile); | 
					
						
							|  |  |  |     ui->recordSilenceTime->setValue(m_outputDeviceInfo.recordSilenceTime); | 
					
						
							|  |  |  |     ui->recordSilenceText->setText(tr("%1").arg(m_outputDeviceInfo.recordSilenceTime / 10.0, 0, 'f', 1)); | 
					
						
							| 
									
										
										
										
											2019-02-17 06:15:12 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-14 08:31:18 +01:00
										 |  |  |     updateOutputSDPString(); | 
					
						
							| 
									
										
										
										
											2019-02-17 06:15:12 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ui->outputSampleRate->blockSignals(false); | 
					
						
							|  |  |  |     ui->outputUDPChannelMode->blockSignals(false); | 
					
						
							|  |  |  |     ui->outputUDPChannelCodec->blockSignals(false); | 
					
						
							|  |  |  |     ui->decimationFactor->blockSignals(false); | 
					
						
							| 
									
										
										
										
											2017-01-06 03:13:53 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-03-26 11:55:45 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | void AudioDialogX::updateOutputDeviceInfo() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_outputDeviceInfo.sampleRate = ui->outputSampleRate->value(); | 
					
						
							|  |  |  |     m_outputDeviceInfo.udpAddress = ui->outputUDPAddress->text(); | 
					
						
							|  |  |  |     m_outputDeviceInfo.udpPort = m_outputUDPPort; | 
					
						
							|  |  |  |     m_outputDeviceInfo.copyToUDP = ui->outputUDPCopy->isChecked(); | 
					
						
							|  |  |  |     m_outputDeviceInfo.udpUseRTP = ui->outputUDPUseRTP->isChecked(); | 
					
						
							| 
									
										
										
										
											2020-11-12 22:13:44 +01:00
										 |  |  |     m_outputDeviceInfo.udpChannelMode = (AudioOutputDevice::UDPChannelMode) ui->outputUDPChannelMode->currentIndex(); | 
					
						
							|  |  |  |     m_outputDeviceInfo.udpChannelCodec = (AudioOutputDevice::UDPChannelCodec) ui->outputUDPChannelCodec->currentIndex(); | 
					
						
							| 
									
										
										
										
											2019-02-15 07:57:16 +01:00
										 |  |  |     m_outputDeviceInfo.udpDecimationFactor = ui->decimationFactor->currentIndex() + 1; | 
					
						
							| 
									
										
										
										
											2022-11-08 22:55:40 +01:00
										 |  |  |     m_outputDeviceInfo.recordToFile = ui->record->isChecked(); | 
					
						
							|  |  |  |     m_outputDeviceInfo.fileRecordName = ui->fileNameText->text(); | 
					
						
							|  |  |  |     m_outputDeviceInfo.recordSilenceTime = ui->recordSilenceTime->value(); | 
					
						
							| 
									
										
										
										
											2018-03-26 11:55:45 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-14 08:31:18 +01:00
										 |  |  | void AudioDialogX::updateOutputSDPString() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QString format; | 
					
						
							| 
									
										
										
										
											2020-11-12 22:13:44 +01:00
										 |  |  |     int nChannels = m_outputDeviceInfo.udpChannelMode == AudioOutputDevice::UDPChannelStereo ? 2 : 1; | 
					
						
							| 
									
										
										
										
											2019-02-17 18:30:19 +01:00
										 |  |  |     uint32_t effectiveSampleRate = m_outputDeviceInfo.sampleRate / (m_outputDeviceInfo.udpDecimationFactor == 0 ? 1 : m_outputDeviceInfo.udpDecimationFactor); | 
					
						
							| 
									
										
										
										
											2019-02-14 08:31:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-17 06:15:12 +01:00
										 |  |  |     switch (m_outputDeviceInfo.udpChannelCodec) | 
					
						
							| 
									
										
										
										
											2019-02-14 08:31:18 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-11-12 22:13:44 +01:00
										 |  |  |     case AudioOutputDevice::UDPCodecALaw: | 
					
						
							| 
									
										
										
										
											2019-02-14 08:31:18 +01:00
										 |  |  |         format = "PCMA"; | 
					
						
							| 
									
										
										
										
											2019-02-17 06:15:12 +01:00
										 |  |  |         break; | 
					
						
							| 
									
										
										
										
											2020-11-12 22:13:44 +01:00
										 |  |  |     case AudioOutputDevice::UDPCodecULaw: | 
					
						
							| 
									
										
										
										
											2019-02-17 06:15:12 +01:00
										 |  |  |         format = "PCMU"; | 
					
						
							|  |  |  |         break; | 
					
						
							| 
									
										
										
										
											2020-11-12 22:13:44 +01:00
										 |  |  |     case AudioOutputDevice::UDPCodecG722: | 
					
						
							| 
									
										
										
										
											2019-02-17 06:15:12 +01:00
										 |  |  |         format = "G722"; | 
					
						
							| 
									
										
										
										
											2019-02-17 18:30:19 +01:00
										 |  |  |         effectiveSampleRate /= 2; // codec does a decimation by 2
 | 
					
						
							| 
									
										
										
										
											2019-02-17 06:15:12 +01:00
										 |  |  |         break; | 
					
						
							| 
									
										
										
										
											2020-11-12 22:13:44 +01:00
										 |  |  |     case AudioOutputDevice::UDPCodecL8: | 
					
						
							| 
									
										
										
										
											2019-02-17 06:15:12 +01:00
										 |  |  |         format = "L8"; | 
					
						
							|  |  |  |         break; | 
					
						
							| 
									
										
										
										
											2020-11-12 22:13:44 +01:00
										 |  |  |     case AudioOutputDevice::UDPCodecOpus: | 
					
						
							| 
									
										
										
										
											2019-02-18 02:30:43 +01:00
										 |  |  |         format = "opus"; | 
					
						
							| 
									
										
										
										
											2019-02-19 02:07:26 +01:00
										 |  |  |         nChannels = 2; // always 2 even for mono
 | 
					
						
							|  |  |  |         effectiveSampleRate = 48000; // always 48000 regardless of input rate
 | 
					
						
							| 
									
										
										
										
											2019-02-18 02:30:43 +01:00
										 |  |  |         break; | 
					
						
							| 
									
										
										
										
											2020-11-12 22:13:44 +01:00
										 |  |  |     case AudioOutputDevice::UDPCodecL16: | 
					
						
							| 
									
										
										
										
											2019-02-17 06:15:12 +01:00
										 |  |  |     default: | 
					
						
							|  |  |  |         format = "L16"; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-17 18:30:19 +01:00
										 |  |  |     ui->outputSDPText->setText(tr("%1/%2/%3").arg(format).arg(effectiveSampleRate).arg(nChannels)); | 
					
						
							| 
									
										
										
										
											2019-02-17 06:15:12 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AudioDialogX::check() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-11-12 22:13:44 +01:00
										 |  |  |     int nChannels = m_outputDeviceInfo.udpChannelMode == AudioOutputDevice::UDPChannelStereo ? 2 : 1; | 
					
						
							| 
									
										
										
										
											2019-02-17 06:15:12 +01:00
										 |  |  |     uint32_t decimationFactor = m_outputDeviceInfo.udpDecimationFactor == 0 ? 1 : m_outputDeviceInfo.udpDecimationFactor; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-12 22:13:44 +01:00
										 |  |  |     if (m_outputDeviceInfo.udpChannelCodec == AudioOutputDevice::UDPCodecALaw) | 
					
						
							| 
									
										
										
										
											2019-02-17 06:15:12 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-02-17 03:40:11 +01:00
										 |  |  |         if ((nChannels != 1) || (m_outputDeviceInfo.sampleRate/decimationFactor != 8000)) { | 
					
						
							|  |  |  |             QMessageBox::information(this, tr("Message"), tr("PCMA must be 8000 Hz single channel")); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-11-12 22:13:44 +01:00
										 |  |  |     else if (m_outputDeviceInfo.udpChannelCodec == AudioOutputDevice::UDPCodecULaw) | 
					
						
							| 
									
										
										
										
											2019-02-17 03:40:11 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         if ((nChannels != 1) || (m_outputDeviceInfo.sampleRate/decimationFactor != 8000)) { | 
					
						
							|  |  |  |             QMessageBox::information(this, tr("Message"), tr("PCMU must be 8000 Hz single channel")); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-11-12 22:13:44 +01:00
										 |  |  |     else if (m_outputDeviceInfo.udpChannelCodec == AudioOutputDevice::UDPCodecG722) | 
					
						
							| 
									
										
										
										
											2019-02-17 03:40:11 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         if ((nChannels != 1) || (m_outputDeviceInfo.sampleRate/decimationFactor != 16000)) { | 
					
						
							|  |  |  |             QMessageBox::information(this, tr("Message"), tr("G722 must be 16000 Hz single channel")); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-11-12 22:13:44 +01:00
										 |  |  |     else if (m_outputDeviceInfo.udpChannelCodec == AudioOutputDevice::UDPCodecOpus) | 
					
						
							| 
									
										
										
										
											2019-02-18 18:29:37 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         int effectiveSampleRate = m_outputDeviceInfo.sampleRate/decimationFactor; | 
					
						
							| 
									
										
										
										
											2019-02-18 22:06:43 +01:00
										 |  |  |         if ((effectiveSampleRate != 48000) && (effectiveSampleRate != 24000) && (effectiveSampleRate != 16000) && (effectiveSampleRate != 12000)) { | 
					
						
							| 
									
										
										
										
											2019-02-18 18:29:37 +01:00
										 |  |  |             QMessageBox::information(this, tr("Message"), tr("Opus takes only 48, 24, 16 or 12 kHz sample rates")); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-02-14 08:31:18 +01:00
										 |  |  | } |