| 
									
										
										
										
											2017-10-18 23:16:13 +02:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							| 
									
										
										
										
											2023-11-18 06:36:53 +01:00
										 |  |  | // Copyright (C) 2017-2020, 2022 Edouard Griffiths, F4EXB <f4exb06@gmail.com>    //
 | 
					
						
							|  |  |  | // Copyright (C) 2021 Jon Beniston, M7RCE <jon@beniston.com>                     //
 | 
					
						
							| 
									
										
										
										
											2017-10-18 23:16:13 +02: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 06:39:30 +02:00
										 |  |  | // (at your option) any later version.                                           //
 | 
					
						
							| 
									
										
										
										
											2017-10-18 23:16:13 +02: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 <QColor>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-08 22:40:24 +02:00
										 |  |  | #include "audio/audiodevicemanager.h"
 | 
					
						
							| 
									
										
										
										
											2017-10-18 23:16:13 +02:00
										 |  |  | #include "util/simpleserializer.h"
 | 
					
						
							|  |  |  | #include "settings/serializable.h"
 | 
					
						
							|  |  |  | #include "ssbmodsettings.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const int SSBModSettings::m_agcTimeConstant[] = { | 
					
						
							|  |  |  |         1, | 
					
						
							|  |  |  |         2, | 
					
						
							|  |  |  |         5, | 
					
						
							|  |  |  |        10, | 
					
						
							|  |  |  |        20, | 
					
						
							|  |  |  |        50, | 
					
						
							|  |  |  |       100, | 
					
						
							|  |  |  |       200, | 
					
						
							|  |  |  |       500, | 
					
						
							|  |  |  |       990}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const int SSBModSettings::m_nbAGCTimeConstants = 10; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | SSBModSettings::SSBModSettings() : | 
					
						
							| 
									
										
										
										
											2022-01-09 05:27:12 +01:00
										 |  |  |     m_channelMarker(nullptr), | 
					
						
							|  |  |  |     m_spectrumGUI(nullptr), | 
					
						
							|  |  |  |     m_cwKeyerGUI(nullptr), | 
					
						
							|  |  |  |     m_rollupState(nullptr) | 
					
						
							| 
									
										
										
										
											2017-10-18 23:16:13 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     resetToDefaults(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SSBModSettings::resetToDefaults() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_inputFrequencyOffset = 0; | 
					
						
							|  |  |  |     m_bandwidth = 3000.0; | 
					
						
							|  |  |  |     m_lowCutoff = 300.0; | 
					
						
							|  |  |  |     m_usb = true; | 
					
						
							|  |  |  |     m_toneFrequency = 1000.0; | 
					
						
							|  |  |  |     m_volumeFactor = 1.0; | 
					
						
							|  |  |  |     m_spanLog2 = 3; | 
					
						
							|  |  |  |     m_audioBinaural = false; | 
					
						
							|  |  |  |     m_audioFlipChannels = false; | 
					
						
							|  |  |  |     m_dsb = false; | 
					
						
							|  |  |  |     m_audioMute = false; | 
					
						
							|  |  |  |     m_playLoop = false; | 
					
						
							|  |  |  |     m_agc = false; | 
					
						
							| 
									
										
										
										
											2020-11-25 14:19:21 +01:00
										 |  |  |     m_cmpPreGainDB = -10; | 
					
						
							|  |  |  |     m_cmpThresholdDB = -60; | 
					
						
							| 
									
										
										
										
											2017-10-18 23:16:13 +02:00
										 |  |  |     m_rgbColor = QColor(0, 255, 0).rgb(); | 
					
						
							| 
									
										
										
										
											2017-11-19 19:14:33 +01:00
										 |  |  |     m_title = "SSB Modulator"; | 
					
						
							| 
									
										
										
										
											2018-04-13 08:41:34 +02:00
										 |  |  |     m_modAFInput = SSBModInputAF::SSBModInputNone; | 
					
						
							| 
									
										
										
										
											2018-03-29 16:57:42 +02:00
										 |  |  |     m_audioDeviceName = AudioDeviceManager::m_defaultDeviceName; | 
					
						
							| 
									
										
										
										
											2019-07-30 18:31:24 +02:00
										 |  |  |     m_feedbackAudioDeviceName = AudioDeviceManager::m_defaultDeviceName; | 
					
						
							| 
									
										
										
										
											2019-07-31 02:38:50 +02:00
										 |  |  |     m_feedbackVolumeFactor = 0.5f; | 
					
						
							| 
									
										
										
										
											2019-07-30 19:42:44 +02:00
										 |  |  |     m_feedbackAudioEnable = false; | 
					
						
							| 
									
										
										
										
											2019-11-17 11:09:07 +01:00
										 |  |  |     m_streamIndex = 0; | 
					
						
							| 
									
										
										
										
											2018-12-21 02:02:16 +01:00
										 |  |  |     m_useReverseAPI = false; | 
					
						
							|  |  |  |     m_reverseAPIAddress = "127.0.0.1"; | 
					
						
							|  |  |  |     m_reverseAPIPort = 8888; | 
					
						
							|  |  |  |     m_reverseAPIDeviceIndex = 0; | 
					
						
							|  |  |  |     m_reverseAPIChannelIndex = 0; | 
					
						
							| 
									
										
										
										
											2022-04-12 16:20:45 +02:00
										 |  |  |     m_workspaceIndex = 0; | 
					
						
							| 
									
										
										
										
											2022-04-12 18:27:27 +02:00
										 |  |  |     m_hidden = false; | 
					
						
							| 
									
										
										
										
											2017-10-18 23:16:13 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QByteArray SSBModSettings::serialize() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     SimpleSerializer s(1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     s.writeS32(1, m_inputFrequencyOffset); | 
					
						
							|  |  |  |     s.writeS32(2, roundf(m_bandwidth / 100.0)); | 
					
						
							|  |  |  |     s.writeS32(3, roundf(m_toneFrequency / 10.0)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_spectrumGUI) { | 
					
						
							|  |  |  |         s.writeBlob(4, m_spectrumGUI->serialize()); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     s.writeU32(5, m_rgbColor); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_cwKeyerGUI) { | 
					
						
							|  |  |  |         s.writeBlob(6, m_cwKeyerGUI->serialize()); | 
					
						
							| 
									
										
										
										
											2019-08-03 01:47:36 +02:00
										 |  |  |     } else { // standalone operation with presets
 | 
					
						
							|  |  |  |         s.writeBlob(6, m_cwKeyerSettings.serialize()); | 
					
						
							| 
									
										
										
										
											2017-10-18 23:16:13 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     s.writeS32(7, roundf(m_lowCutoff / 100.0)); | 
					
						
							|  |  |  |     s.writeS32(8, m_spanLog2); | 
					
						
							|  |  |  |     s.writeBool(9, m_audioBinaural); | 
					
						
							|  |  |  |     s.writeBool(10, m_audioFlipChannels); | 
					
						
							|  |  |  |     s.writeBool(11, m_dsb); | 
					
						
							|  |  |  |     s.writeBool(12, m_agc); | 
					
						
							| 
									
										
										
										
											2020-11-25 14:19:21 +01:00
										 |  |  |     s.writeS32(13, m_cmpPreGainDB); | 
					
						
							|  |  |  |     s.writeS32(14, m_cmpThresholdDB); | 
					
						
							| 
									
										
										
										
											2017-10-18 23:16:13 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (m_channelMarker) { | 
					
						
							|  |  |  |         s.writeBlob(18, m_channelMarker->serialize()); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-19 19:14:33 +01:00
										 |  |  |     s.writeString(19, m_title); | 
					
						
							| 
									
										
										
										
											2018-03-29 16:57:42 +02:00
										 |  |  |     s.writeString(20, m_audioDeviceName); | 
					
						
							| 
									
										
										
										
											2018-04-13 08:41:34 +02:00
										 |  |  |     s.writeS32(21, (int) m_modAFInput); | 
					
						
							| 
									
										
										
										
											2018-12-21 02:02:16 +01:00
										 |  |  |     s.writeBool(22, m_useReverseAPI); | 
					
						
							|  |  |  |     s.writeString(23, m_reverseAPIAddress); | 
					
						
							|  |  |  |     s.writeU32(24, m_reverseAPIPort); | 
					
						
							|  |  |  |     s.writeU32(25, m_reverseAPIDeviceIndex); | 
					
						
							|  |  |  |     s.writeU32(26, m_reverseAPIChannelIndex); | 
					
						
							| 
									
										
										
										
											2019-07-30 18:31:24 +02:00
										 |  |  |     s.writeString(27, m_feedbackAudioDeviceName); | 
					
						
							|  |  |  |     s.writeReal(28, m_feedbackVolumeFactor); | 
					
						
							| 
									
										
										
										
											2019-07-30 19:42:44 +02:00
										 |  |  |     s.writeBool(29, m_feedbackAudioEnable); | 
					
						
							| 
									
										
										
										
											2019-11-17 11:09:07 +01:00
										 |  |  |     s.writeS32(30, m_streamIndex); | 
					
						
							| 
									
										
										
										
											2022-01-09 05:27:12 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (m_rollupState) { | 
					
						
							|  |  |  |         s.writeBlob(31, m_rollupState->serialize()); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-11-19 19:14:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-12 16:20:45 +02:00
										 |  |  |     s.writeS32(32, m_workspaceIndex); | 
					
						
							|  |  |  |     s.writeBlob(33, m_geometryBytes); | 
					
						
							| 
									
										
										
										
											2022-04-12 18:27:27 +02:00
										 |  |  |     s.writeBool(34, m_hidden); | 
					
						
							| 
									
										
										
										
											2022-04-12 16:20:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-18 23:16:13 +02:00
										 |  |  |     return s.final(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool SSBModSettings::deserialize(const QByteArray& data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     SimpleDeserializer d(data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if(!d.isValid()) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         resetToDefaults(); | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if(d.getVersion() == 1) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         QByteArray bytetmp; | 
					
						
							|  |  |  |         qint32 tmp; | 
					
						
							| 
									
										
										
										
											2018-12-21 02:02:16 +01:00
										 |  |  |         uint32_t utmp; | 
					
						
							| 
									
										
										
										
											2017-10-18 23:16:13 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         d.readS32(1, &tmp, 0); | 
					
						
							|  |  |  |         m_inputFrequencyOffset = tmp; | 
					
						
							|  |  |  |         d.readS32(2, &tmp, 30); | 
					
						
							|  |  |  |         m_bandwidth = tmp * 100.0; | 
					
						
							|  |  |  |         d.readS32(3, &tmp, 100); | 
					
						
							|  |  |  |         m_toneFrequency = tmp * 10.0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (m_spectrumGUI) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             d.readBlob(4, &bytetmp); | 
					
						
							|  |  |  |             m_spectrumGUI->deserialize(bytetmp); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         d.readU32(5, &m_rgbColor); | 
					
						
							| 
									
										
										
										
											2019-08-03 01:47:36 +02:00
										 |  |  |         d.readBlob(6, &bytetmp); | 
					
						
							| 
									
										
										
										
											2017-10-18 23:16:13 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (m_cwKeyerGUI) { | 
					
						
							|  |  |  |             m_cwKeyerGUI->deserialize(bytetmp); | 
					
						
							| 
									
										
										
										
											2019-08-03 01:47:36 +02:00
										 |  |  |         } else { // standalone operation with presets
 | 
					
						
							|  |  |  |             m_cwKeyerSettings.deserialize(bytetmp); | 
					
						
							| 
									
										
										
										
											2017-10-18 23:16:13 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         d.readS32(7, &tmp, 3); | 
					
						
							|  |  |  |         m_lowCutoff = tmp * 100.0; | 
					
						
							|  |  |  |         d.readS32(8, &m_spanLog2, 3); | 
					
						
							|  |  |  |         d.readBool(9, &m_audioBinaural, false); | 
					
						
							|  |  |  |         d.readBool(10, &m_audioFlipChannels, false); | 
					
						
							|  |  |  |         d.readBool(11, &m_dsb, false); | 
					
						
							|  |  |  |         d.readBool(12, &m_agc, false); | 
					
						
							| 
									
										
										
										
											2020-11-25 14:19:21 +01:00
										 |  |  |         d.readS32(13, &m_cmpPreGainDB, -10); | 
					
						
							|  |  |  |         d.readS32(14, &m_cmpThresholdDB, -60); | 
					
						
							| 
									
										
										
										
											2017-10-18 23:16:13 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-09 05:27:12 +01:00
										 |  |  |         if (m_channelMarker) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2017-11-19 19:14:33 +01:00
										 |  |  |             d.readBlob(18, &bytetmp); | 
					
						
							|  |  |  |             m_channelMarker->deserialize(bytetmp); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         d.readString(19, &m_title, "SSB Modulator"); | 
					
						
							| 
									
										
										
										
											2018-03-29 16:57:42 +02:00
										 |  |  |         d.readString(20, &m_audioDeviceName, AudioDeviceManager::m_defaultDeviceName); | 
					
						
							| 
									
										
										
										
											2018-04-13 08:41:34 +02:00
										 |  |  |         d.readS32(21, &tmp, 0); | 
					
						
							| 
									
										
										
										
											2022-01-09 05:27:12 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 08:41:34 +02:00
										 |  |  |         if ((tmp < 0) || (tmp > (int) SSBModInputAF::SSBModInputTone)) { | 
					
						
							|  |  |  |             m_modAFInput = SSBModInputNone; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             m_modAFInput = (SSBModInputAF) tmp; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-21 02:02:16 +01:00
										 |  |  |         d.readBool(22, &m_useReverseAPI, false); | 
					
						
							|  |  |  |         d.readString(23, &m_reverseAPIAddress, "127.0.0.1"); | 
					
						
							|  |  |  |         d.readU32(24, &utmp, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if ((utmp > 1023) && (utmp < 65535)) { | 
					
						
							|  |  |  |             m_reverseAPIPort = utmp; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             m_reverseAPIPort = 8888; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         d.readU32(25, &utmp, 0); | 
					
						
							|  |  |  |         m_reverseAPIDeviceIndex = utmp > 99 ? 99 : utmp; | 
					
						
							|  |  |  |         d.readU32(26, &utmp, 0); | 
					
						
							|  |  |  |         m_reverseAPIChannelIndex = utmp > 99 ? 99 : utmp; | 
					
						
							| 
									
										
										
										
											2019-07-30 18:31:24 +02:00
										 |  |  |         d.readString(27, &m_feedbackAudioDeviceName, AudioDeviceManager::m_defaultDeviceName); | 
					
						
							|  |  |  |         d.readReal(28, &m_feedbackVolumeFactor, 1.0); | 
					
						
							| 
									
										
										
										
											2019-07-30 19:42:44 +02:00
										 |  |  |         d.readBool(29, &m_feedbackAudioEnable, false); | 
					
						
							| 
									
										
										
										
											2019-11-17 11:09:07 +01:00
										 |  |  |         d.readS32(30, &m_streamIndex, 0); | 
					
						
							| 
									
										
										
										
											2022-01-09 05:27:12 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (m_rollupState) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             d.readBlob(31, &bytetmp); | 
					
						
							|  |  |  |             m_rollupState->deserialize(bytetmp); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-12-21 02:02:16 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-12 16:20:45 +02:00
										 |  |  |         d.readS32(32, &m_workspaceIndex, 0); | 
					
						
							|  |  |  |         d.readBlob(33, &m_geometryBytes); | 
					
						
							| 
									
										
										
										
											2022-04-12 18:27:27 +02:00
										 |  |  |         d.readBool(34, &m_hidden, false); | 
					
						
							| 
									
										
										
										
											2022-04-12 16:20:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-18 23:16:13 +02:00
										 |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         resetToDefaults(); | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |