kopia lustrzana https://github.com/f4exb/sdrangel
				
				
				
			BFM demod: created a settings class
							rodzic
							
								
									2b2b0eff8d
								
							
						
					
					
						commit
						edd0adde3b
					
				|  | @ -3,6 +3,7 @@ project(bfm) | |||
| set(bfm_SOURCES | ||||
| 	bfmdemod.cpp | ||||
| 	bfmdemodgui.cpp | ||||
| 	bfmdemodsettings.cpp | ||||
| 	bfmplugin.cpp | ||||
| 	rdsdemod.cpp | ||||
| 	rdsdecoder.cpp | ||||
|  | @ -13,6 +14,7 @@ set(bfm_SOURCES | |||
| set(bfm_HEADERS | ||||
| 	bfmdemod.h | ||||
| 	bfmdemodgui.h | ||||
| 	bfmdemodsettings.h | ||||
| 	bfmplugin.h | ||||
| 	rdsdemod.h | ||||
| 	rdsdecoder.h | ||||
|  |  | |||
|  | @ -37,16 +37,13 @@ | |||
| #include "gui/basicchannelsettingsdialog.h" | ||||
| #include "mainwindow.h" | ||||
| 
 | ||||
| #include "bfmdemodsettings.h" | ||||
| #include "bfmdemod.h" | ||||
| #include "rdstmc.h" | ||||
| #include "ui_bfmdemodgui.h" | ||||
| 
 | ||||
| const QString BFMDemodGUI::m_channelID = "sdrangel.channel.bfm"; | ||||
| 
 | ||||
| const int BFMDemodGUI::m_rfBW[] = { | ||||
| 	80000, 100000, 120000, 140000, 160000, 180000, 200000, 220000, 250000 | ||||
| }; | ||||
| 
 | ||||
| //int requiredBW(int rfBW)
 | ||||
| //{
 | ||||
| //	if (rfBW <= 48000)
 | ||||
|  | @ -159,8 +156,8 @@ bool BFMDemodGUI::deserialize(const QByteArray& data) | |||
| 
 | ||||
| 		d.readS32(2, &tmp, 4); | ||||
| 		ui->rfBW->setValue(tmp); | ||||
| 		ui->rfBWText->setText(QString("%1 kHz").arg(m_rfBW[tmp] / 1000.0)); | ||||
| 		m_channelMarker.setBandwidth(m_rfBW[tmp]); | ||||
| 		ui->rfBWText->setText(QString("%1 kHz").arg(BFMDemodSettings::getRFBW(tmp) / 1000.0)); | ||||
| 		m_channelMarker.setBandwidth(BFMDemodSettings::getRFBW(tmp)); | ||||
| 
 | ||||
| 		d.readS32(3, &tmp, 3); | ||||
| 		ui->afBW->setValue(tmp); | ||||
|  | @ -247,8 +244,8 @@ void BFMDemodGUI::on_deltaFrequency_changed(qint64 value) | |||
| 
 | ||||
| void BFMDemodGUI::on_rfBW_valueChanged(int value) | ||||
| { | ||||
| 	ui->rfBWText->setText(QString("%1 kHz").arg(m_rfBW[value] / 1000.0)); | ||||
| 	m_channelMarker.setBandwidth(m_rfBW[value]); | ||||
| 	ui->rfBWText->setText(QString("%1 kHz").arg(BFMDemodSettings::getRFBW(value) / 1000.0)); | ||||
| 	m_channelMarker.setBandwidth(BFMDemodSettings::getRFBW(value)); | ||||
| 	applySettings(); | ||||
| } | ||||
| 
 | ||||
|  | @ -487,7 +484,7 @@ void BFMDemodGUI::applySettings(bool force) | |||
| 	    setTitleColor(m_channelMarker.getColor()); | ||||
| 
 | ||||
| 	    BFMDemod::MsgConfigureChannelizer *message = BFMDemod::MsgConfigureChannelizer::create( | ||||
| 	            requiredBW(m_rfBW[ui->rfBW->value()]), | ||||
| 	            requiredBW(BFMDemodSettings::getRFBW(ui->rfBW->value())), | ||||
| 	            m_channelMarker.getCenterFrequency()); | ||||
| 	    m_bfmDemod->getInputMessageQueue()->push(message); | ||||
| 
 | ||||
|  | @ -498,7 +495,7 @@ void BFMDemodGUI::applySettings(bool force) | |||
| 		ui->deltaFrequency->setValue(m_channelMarker.getCenterFrequency()); | ||||
| 
 | ||||
| 		m_bfmDemod->configure(m_bfmDemod->getInputMessageQueue(), | ||||
| 			m_rfBW[ui->rfBW->value()], | ||||
| 		    BFMDemodSettings::getRFBW(ui->rfBW->value()), | ||||
| 			ui->afBW->value() * 1000.0, | ||||
| 			ui->volume->value() / 10.0, | ||||
| 			ui->squelch->value(), | ||||
|  |  | |||
|  | @ -23,6 +23,7 @@ | |||
| #include "dsp/channelmarker.h" | ||||
| #include "dsp/movingaverage.h" | ||||
| #include "util/messagequeue.h" | ||||
| #include "bfmdemodsettings.h" | ||||
| 
 | ||||
| class PluginAPI; | ||||
| class DeviceSourceAPI; | ||||
|  | @ -84,6 +85,7 @@ private: | |||
| 	PluginAPI* m_pluginAPI; | ||||
| 	DeviceSourceAPI* m_deviceAPI; | ||||
| 	ChannelMarker m_channelMarker; | ||||
| 	BFMDemodSettings m_settings; | ||||
| 	bool m_doApplySettings; | ||||
| 	int m_rdsTimerCount; | ||||
| 
 | ||||
|  | @ -97,8 +99,6 @@ private: | |||
| 	std::vector<unsigned int> m_g14ComboIndex; | ||||
| 	MessageQueue m_inputMessageQueue; | ||||
| 
 | ||||
| 	static const int m_rfBW[]; | ||||
| 
 | ||||
| 	explicit BFMDemodGUI(PluginAPI* pluginAPI, DeviceSourceAPI *deviceAPI, QWidget* parent = NULL); | ||||
| 	virtual ~BFMDemodGUI(); | ||||
| 
 | ||||
|  |  | |||
|  | @ -0,0 +1,151 @@ | |||
| ///////////////////////////////////////////////////////////////////////////////////
 | ||||
| // Copyright (C) 2017 Edouard Griffiths, F4EXB.                                  //
 | ||||
| //                                                                               //
 | ||||
| // 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                  //
 | ||||
| //                                                                               //
 | ||||
| // 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 "dsp/dspengine.h" | ||||
| #include "util/simpleserializer.h" | ||||
| #include "settings/serializable.h" | ||||
| 
 | ||||
| #include "bfmdemodsettings.h" | ||||
| 
 | ||||
| const int BFMDemodSettings::m_nbRFBW = 9; | ||||
| const int BFMDemodSettings::m_rfBW[] = { | ||||
|     80000, 100000, 120000, 140000, 160000, 180000, 200000, 220000, 250000 | ||||
| }; | ||||
| 
 | ||||
| BFMDemodSettings::BFMDemodSettings() : | ||||
|     m_channelMarker(0), | ||||
|     m_spectrumGUI(0) | ||||
| { | ||||
|     resetToDefaults(); | ||||
| } | ||||
| 
 | ||||
| void BFMDemodSettings::resetToDefaults() | ||||
| { | ||||
|     m_inputSampleRate = 384000; | ||||
|     m_inputFrequencyOffset = 0; | ||||
|     m_rfBandwidth = getRFBW(4); | ||||
|     m_afBandwidth = 3000; | ||||
|     m_volume = 2.0; | ||||
|     m_squelch = -60.0; | ||||
|     m_audioSampleRate = DSPEngine::instance()->getAudioSampleRate(); | ||||
|     m_audioStereo = false; | ||||
|     m_lsbStereo = false; | ||||
|     m_showPilot = false; | ||||
|     m_rdsActive = false; | ||||
|     m_copyAudioToUDP = false; | ||||
|     m_udpAddress = "127.0.0.1"; | ||||
|     m_udpPort = 9999; | ||||
| } | ||||
| 
 | ||||
| QByteArray BFMDemodSettings::serialize() const | ||||
| { | ||||
|     SimpleSerializer s(1); | ||||
|     s.writeS32(1, m_inputFrequencyOffset); | ||||
|     s.writeS32(2, getRFBWIndex(m_rfBandwidth)); | ||||
|     s.writeS32(3, m_afBandwidth/1000.0); | ||||
|     s.writeS32(4, m_volume*10.0); | ||||
|     s.writeS32(5, m_squelch); | ||||
|     s.writeU32(7, m_rgbColor); | ||||
| 
 | ||||
|     if (m_spectrumGUI) { | ||||
|         s.writeBlob(8, m_spectrumGUI->serialize()); | ||||
|     } | ||||
| 
 | ||||
|     s.writeBool(9, m_audioStereo); | ||||
|     s.writeBool(10, m_lsbStereo); | ||||
| 
 | ||||
|     if (m_channelMarker) { | ||||
|         s.writeBlob(11, m_channelMarker->serialize()); | ||||
|     } | ||||
| 
 | ||||
|     return s.final(); | ||||
| } | ||||
| 
 | ||||
| bool BFMDemodSettings::deserialize(const QByteArray& data) | ||||
| { | ||||
|     SimpleDeserializer d(data); | ||||
| 
 | ||||
|     if(!d.isValid()) | ||||
|     { | ||||
|         resetToDefaults(); | ||||
|         return false; | ||||
|     } | ||||
| 
 | ||||
|     if(d.getVersion() == 1) | ||||
|     { | ||||
|         QByteArray bytetmp; | ||||
|         qint32 tmp; | ||||
|         QString strtmp; | ||||
| 
 | ||||
|         d.readS32(1, &tmp, 0); | ||||
|         m_inputFrequencyOffset = tmp; | ||||
|         d.readS32(2, &tmp, 4); | ||||
|         m_rfBandwidth = getRFBW(tmp); | ||||
|         d.readS32(3, &tmp, 3); | ||||
|         m_afBandwidth = tmp * 1000.0; | ||||
|         d.readS32(4, &tmp, 20); | ||||
|         m_volume = tmp * 0.1; | ||||
|         d.readS32(5, &tmp, -60); | ||||
|         m_squelch = tmp; | ||||
|         d.readU32(7, &m_rgbColor); | ||||
| 
 | ||||
|         d.readBlob(8, &bytetmp); | ||||
| 
 | ||||
|         if (m_spectrumGUI) { | ||||
|             m_spectrumGUI->deserialize(bytetmp); | ||||
|         } | ||||
| 
 | ||||
|         d.readBool(9, &m_audioStereo, false); | ||||
|         d.readBool(10, &m_lsbStereo, false); | ||||
| 
 | ||||
|         d.readBlob(11, &bytetmp); | ||||
| 
 | ||||
|         if (m_channelMarker) { | ||||
|             m_channelMarker->deserialize(bytetmp); | ||||
|         } | ||||
| 
 | ||||
|         return true; | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|         resetToDefaults(); | ||||
|         return false; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| int BFMDemodSettings::getRFBW(int index) | ||||
| { | ||||
|     if (index < 0) { | ||||
|         return m_rfBW[0]; | ||||
|     } else if (index < m_nbRFBW) { | ||||
|         return m_rfBW[index]; | ||||
|     } else { | ||||
|         return m_rfBW[m_nbRFBW-1]; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| int BFMDemodSettings::getRFBWIndex(int rfbw) | ||||
| { | ||||
|     for (int i = 0; i < m_nbRFBW; i++) | ||||
|     { | ||||
|         if (rfbw >= m_rfBW[i]) | ||||
|         { | ||||
|             return i; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     return 0; | ||||
| } | ||||
|  | @ -0,0 +1,58 @@ | |||
| ///////////////////////////////////////////////////////////////////////////////////
 | ||||
| // Copyright (C) 2017 Edouard Griffiths, F4EXB.                                  //
 | ||||
| //                                                                               //
 | ||||
| // 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                  //
 | ||||
| //                                                                               //
 | ||||
| // 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/>.          //
 | ||||
| ///////////////////////////////////////////////////////////////////////////////////
 | ||||
| 
 | ||||
| #ifndef PLUGINS_CHANNELRX_DEMODBFM_BFMDEMODSETTINGS_H_ | ||||
| #define PLUGINS_CHANNELRX_DEMODBFM_BFMDEMODSETTINGS_H_ | ||||
| 
 | ||||
| class Serializable; | ||||
| 
 | ||||
| struct BFMDemodSettings | ||||
| { | ||||
|     int m_inputSampleRate; | ||||
|     qint64 m_inputFrequencyOffset; | ||||
|     Real m_rfBandwidth; | ||||
|     Real m_afBandwidth; | ||||
|     Real m_volume; | ||||
|     Real m_squelch; | ||||
|     quint32 m_audioSampleRate; | ||||
|     bool m_audioStereo; | ||||
|     bool m_lsbStereo; | ||||
|     bool m_showPilot; | ||||
|     bool m_rdsActive; | ||||
|     bool m_copyAudioToUDP; | ||||
|     QString m_udpAddress; | ||||
|     quint16 m_udpPort; | ||||
|     quint32 m_rgbColor; | ||||
| 
 | ||||
|     Serializable *m_channelMarker; | ||||
|     Serializable *m_spectrumGUI; | ||||
| 
 | ||||
|     static const int m_nbRFBW; | ||||
|     static const int m_rfBW[]; | ||||
| 
 | ||||
|     BFMDemodSettings(); | ||||
|     void resetToDefaults(); | ||||
|     void setChannelMarker(Serializable *channelMarker) { m_channelMarker = channelMarker; } | ||||
|     void setSpectrumGUI(Serializable *spectrumGUI) { m_spectrumGUI = spectrumGUI; } | ||||
|     QByteArray serialize() const; | ||||
|     bool deserialize(const QByteArray& data); | ||||
| 
 | ||||
|     static int getRFBW(int index); | ||||
|     static int getRFBWIndex(int rfbw); | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| #endif /* PLUGINS_CHANNELRX_DEMODBFM_BFMDEMODSETTINGS_H_ */ | ||||
|  | @ -30,6 +30,7 @@ CONFIG(Debug):build_subdir = debug | |||
| 
 | ||||
| SOURCES += bfmdemod.cpp\ | ||||
|     bfmdemodgui.cpp\ | ||||
|     bfmdemodsettings.cpp\ | ||||
|     bfmplugin.cpp\ | ||||
|     rdsdemod.cpp\ | ||||
|     rdsdecoder.cpp\ | ||||
|  | @ -38,6 +39,7 @@ SOURCES += bfmdemod.cpp\ | |||
| 
 | ||||
| HEADERS += bfmdemod.h\ | ||||
|     bfmdemodgui.h\ | ||||
|     bfmdemodsettings.h\ | ||||
|     bfmplugin.h\ | ||||
|     rdsdemod.h\ | ||||
|     rdsdecoder.h\ | ||||
|  |  | |||
|  | @ -4,6 +4,7 @@ | |||
| #include <QWidget> | ||||
| #include "dsp/dsptypes.h" | ||||
| #include "util/export.h" | ||||
| #include "settings/serializable.h" | ||||
| 
 | ||||
| namespace Ui { | ||||
| 	class GLSpectrumGUI; | ||||
|  | @ -13,7 +14,7 @@ class MessageQueue; | |||
| class SpectrumVis; | ||||
| class GLSpectrum; | ||||
| 
 | ||||
| class SDRANGEL_API GLSpectrumGUI : public QWidget { | ||||
| class SDRANGEL_API GLSpectrumGUI : public QWidget, public Serializable { | ||||
| 	Q_OBJECT | ||||
| 
 | ||||
| public: | ||||
|  | @ -23,8 +24,8 @@ public: | |||
| 	void setBuddies(MessageQueue* messageQueue, SpectrumVis* spectrumVis, GLSpectrum* glSpectrum); | ||||
| 
 | ||||
| 	void resetToDefaults(); | ||||
| 	QByteArray serialize() const; | ||||
| 	bool deserialize(const QByteArray& data); | ||||
| 	virtual QByteArray serialize() const; | ||||
| 	virtual bool deserialize(const QByteArray& data); | ||||
| 
 | ||||
| private: | ||||
| 	Ui::GLSpectrumGUI* ui; | ||||
|  |  | |||
		Ładowanie…
	
		Reference in New Issue
	
	 f4exb
						f4exb