mirror of
				https://github.com/f4exb/sdrangel.git
				synced 2025-10-30 04:20:21 -04:00 
			
		
		
		
	File Sink: implemented arbitrary sample rate selection
This commit is contained in:
		
							parent
							
								
									66e45e6638
								
							
						
					
					
						commit
						73c9340e4e
					
				| @ -49,15 +49,14 @@ FileSinkGui::FileSinkGui(DeviceSinkAPI *deviceAPI, QWidget* parent) : | |||||||
| 	m_lastEngineState((DSPDeviceSinkEngine::State)-1) | 	m_lastEngineState((DSPDeviceSinkEngine::State)-1) | ||||||
| { | { | ||||||
| 	ui->setupUi(this); | 	ui->setupUi(this); | ||||||
|  | 
 | ||||||
| 	ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::ReverseGold)); | 	ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::ReverseGold)); | ||||||
| 	ui->centerFrequency->setValueRange(7, 0, pow(10,7)); | 	ui->centerFrequency->setValueRange(7, 0, pow(10,7)); | ||||||
| 	ui->fileNameText->setText(m_fileName); |  | ||||||
| 
 | 
 | ||||||
| 	ui->sampleRate->clear(); |     ui->sampleRate->setColorMapper(ColorMapper(ColorMapper::ReverseGreenYellow)); | ||||||
| 	for (int i = 0; i < FileSinkSampleRates::getNbRates(); i++) |     ui->sampleRate->setValueRange(7, 32000U, 9000000U); | ||||||
| 	{ | 
 | ||||||
| 		ui->sampleRate->addItem(QString::number(FileSinkSampleRates::getRate(i))); | 	ui->fileNameText->setText(m_fileName); | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	connect(&(m_deviceAPI->getMainWindow()->getMasterTimer()), SIGNAL(timeout()), this, SLOT(tick())); | 	connect(&(m_deviceAPI->getMainWindow()->getMasterTimer()), SIGNAL(timeout()), this, SLOT(tick())); | ||||||
| 	connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateHardware())); | 	connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateHardware())); | ||||||
| @ -195,8 +194,7 @@ void FileSinkGui::updateSampleRateAndFrequency() | |||||||
| void FileSinkGui::displaySettings() | void FileSinkGui::displaySettings() | ||||||
| { | { | ||||||
|     ui->centerFrequency->setValue(m_settings.m_centerFrequency / 1000); |     ui->centerFrequency->setValue(m_settings.m_centerFrequency / 1000); | ||||||
|     unsigned int sampleRateIndex = FileSinkSampleRates::getRateIndex(m_settings.m_sampleRate); |     ui->sampleRate->setValue(m_settings.m_sampleRate); | ||||||
|     ui->sampleRate->setCurrentIndex(sampleRateIndex); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void FileSinkGui::sendSettings() | void FileSinkGui::sendSettings() | ||||||
| @ -249,10 +247,9 @@ void FileSinkGui::on_centerFrequency_changed(quint64 value) | |||||||
|     sendSettings(); |     sendSettings(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void FileSinkGui::on_sampleRate_currentIndexChanged(int index) | void FileSinkGui::on_sampleRate_changed(quint64 value) | ||||||
| { | { | ||||||
| 	int newrate = FileSinkSampleRates::getRate(index); |     m_settings.m_sampleRate = value; | ||||||
|     m_settings.m_sampleRate = newrate * 1000; |  | ||||||
|     sendSettings(); |     sendSettings(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -338,38 +335,3 @@ void FileSinkGui::tick() | |||||||
| 		m_deviceSampleSink->getInputMessageQueue()->push(message); | 		m_deviceSampleSink->getInputMessageQueue()->push(message); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 |  | ||||||
| const unsigned int FileSinkSampleRates::m_nb_rates = 17; |  | ||||||
| const unsigned int FileSinkSampleRates::m_rates[FileSinkSampleRates::m_nb_rates] = { |  | ||||||
| 		32, 48, 64, 72, 128, 192, 256, 288, 300, 384, 512, 1000, 2000, 3000, 4000, 5000, 6000}; |  | ||||||
| 
 |  | ||||||
| unsigned int FileSinkSampleRates::getRate(unsigned int rate_index) |  | ||||||
| { |  | ||||||
| 	if (rate_index < m_nb_rates) |  | ||||||
| 	{ |  | ||||||
| 		return m_rates[rate_index]; |  | ||||||
| 	} |  | ||||||
| 	else |  | ||||||
| 	{ |  | ||||||
| 		return m_rates[0]; |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| unsigned int FileSinkSampleRates::getRateIndex(unsigned int rate) |  | ||||||
| { |  | ||||||
| 	for (unsigned int i=0; i < m_nb_rates; i++) |  | ||||||
| 	{ |  | ||||||
| 		if (rate/1000 == m_rates[i]) |  | ||||||
| 		{ |  | ||||||
| 			return i; |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	return 0; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| unsigned int FileSinkSampleRates::getNbRates() |  | ||||||
| { |  | ||||||
| 	return FileSinkSampleRates::m_nb_rates; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
|  | |||||||
| @ -78,22 +78,13 @@ private slots: | |||||||
|     void handleDSPMessages(); |     void handleDSPMessages(); | ||||||
|     void handleSinkMessages(); |     void handleSinkMessages(); | ||||||
|     void on_centerFrequency_changed(quint64 value); |     void on_centerFrequency_changed(quint64 value); | ||||||
|  |     void on_sampleRate_changed(quint64 value); | ||||||
| 	void on_startStop_toggled(bool checked); | 	void on_startStop_toggled(bool checked); | ||||||
| 	void on_showFileDialog_clicked(bool checked); | 	void on_showFileDialog_clicked(bool checked); | ||||||
| 	void on_interp_currentIndexChanged(int index); | 	void on_interp_currentIndexChanged(int index); | ||||||
|     void on_sampleRate_currentIndexChanged(int index); |  | ||||||
|     void updateHardware(); |     void updateHardware(); | ||||||
|     void updateStatus(); |     void updateStatus(); | ||||||
| 	void tick(); | 	void tick(); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| class FileSinkSampleRates { |  | ||||||
| public: |  | ||||||
| 	static unsigned int getRate(unsigned int rate_index); |  | ||||||
| 	static unsigned int getRateIndex(unsigned int rate); |  | ||||||
| 	static unsigned int getNbRates(); |  | ||||||
| 	static const unsigned int m_nb_rates; |  | ||||||
| 	static const unsigned int m_rates[]; |  | ||||||
| }; |  | ||||||
| 
 |  | ||||||
| #endif // INCLUDE_FILESINKGUI_H
 | #endif // INCLUDE_FILESINKGUI_H
 | ||||||
|  | |||||||
| @ -6,7 +6,7 @@ | |||||||
|    <rect> |    <rect> | ||||||
|     <x>0</x> |     <x>0</x> | ||||||
|     <y>0</y> |     <y>0</y> | ||||||
|     <width>246</width> |     <width>315</width> | ||||||
|     <height>190</height> |     <height>190</height> | ||||||
|    </rect> |    </rect> | ||||||
|   </property> |   </property> | ||||||
| @ -35,7 +35,16 @@ | |||||||
|    <property name="spacing"> |    <property name="spacing"> | ||||||
|     <number>3</number> |     <number>3</number> | ||||||
|    </property> |    </property> | ||||||
|    <property name="margin"> |    <property name="leftMargin"> | ||||||
|  |     <number>2</number> | ||||||
|  |    </property> | ||||||
|  |    <property name="topMargin"> | ||||||
|  |     <number>2</number> | ||||||
|  |    </property> | ||||||
|  |    <property name="rightMargin"> | ||||||
|  |     <number>2</number> | ||||||
|  |    </property> | ||||||
|  |    <property name="bottomMargin"> | ||||||
|     <number>2</number> |     <number>2</number> | ||||||
|    </property> |    </property> | ||||||
|    <item> |    <item> | ||||||
| @ -274,16 +283,31 @@ | |||||||
|       </widget> |       </widget> | ||||||
|      </item> |      </item> | ||||||
|      <item> |      <item> | ||||||
|       <widget class="QComboBox" name="sampleRate"> |       <widget class="ValueDial" name="sampleRate" native="true"> | ||||||
|        <property name="toolTip"> |        <property name="sizePolicy"> | ||||||
|         <string>Sample rate selection (kS/s)</string> |         <sizepolicy hsizetype="Maximum" vsizetype="Maximum"> | ||||||
|  |          <horstretch>0</horstretch> | ||||||
|  |          <verstretch>0</verstretch> | ||||||
|  |         </sizepolicy> | ||||||
|  |        </property> | ||||||
|  |        <property name="minimumSize"> | ||||||
|  |         <size> | ||||||
|  |          <width>32</width> | ||||||
|  |          <height>16</height> | ||||||
|  |         </size> | ||||||
|  |        </property> | ||||||
|  |        <property name="font"> | ||||||
|  |         <font> | ||||||
|  |          <family>DejaVu Sans Mono</family> | ||||||
|  |          <pointsize>12</pointsize> | ||||||
|  |         </font> | ||||||
|        </property> |        </property> | ||||||
|       </widget> |       </widget> | ||||||
|      </item> |      </item> | ||||||
|      <item> |      <item> | ||||||
|       <widget class="QLabel" name="sampleRateUnit"> |       <widget class="QLabel" name="sampleRateUnit"> | ||||||
|        <property name="text"> |        <property name="text"> | ||||||
|         <string>kS/s</string> |         <string>S/s</string> | ||||||
|        </property> |        </property> | ||||||
|       </widget> |       </widget> | ||||||
|      </item> |      </item> | ||||||
| @ -365,6 +389,33 @@ | |||||||
|  </customwidgets> |  </customwidgets> | ||||||
|  <resources> |  <resources> | ||||||
|   <include location="../../../sdrbase/resources/res.qrc"/> |   <include location="../../../sdrbase/resources/res.qrc"/> | ||||||
|  |   <include location="../../../sdrbase/resources/res.qrc"/> | ||||||
|  |   <include location="../../../sdrbase/resources/res.qrc"/> | ||||||
|  |   <include location="../../../sdrbase/resources/res.qrc"/> | ||||||
|  |   <include location="../../../sdrbase/resources/res.qrc"/> | ||||||
|  |   <include location="../../../sdrbase/resources/res.qrc"/> | ||||||
|  |   <include location="../../../sdrbase/resources/res.qrc"/> | ||||||
|  |   <include location="../../../sdrbase/resources/res.qrc"/> | ||||||
|  |   <include location="../../../sdrbase/resources/res.qrc"/> | ||||||
|  |   <include location="../../../sdrbase/resources/res.qrc"/> | ||||||
|  |   <include location="../../../sdrbase/resources/res.qrc"/> | ||||||
|  |   <include location="../../../sdrbase/resources/res.qrc"/> | ||||||
|  |   <include location="../../../sdrbase/resources/res.qrc"/> | ||||||
|  |   <include location="../../../sdrbase/resources/res.qrc"/> | ||||||
|  |   <include location="../../../sdrbase/resources/res.qrc"/> | ||||||
|  |   <include location="../../../sdrbase/resources/res.qrc"/> | ||||||
|  |   <include location="../../../sdrbase/resources/res.qrc"/> | ||||||
|  |   <include location="../../../sdrbase/resources/res.qrc"/> | ||||||
|  |   <include location="../../../sdrbase/resources/res.qrc"/> | ||||||
|  |   <include location="../../../sdrbase/resources/res.qrc"/> | ||||||
|  |   <include location="../../../sdrbase/resources/res.qrc"/> | ||||||
|  |   <include location="../../../sdrbase/resources/res.qrc"/> | ||||||
|  |   <include location="../../../sdrbase/resources/res.qrc"/> | ||||||
|  |   <include location="../../../sdrbase/resources/res.qrc"/> | ||||||
|  |   <include location="../../../sdrbase/resources/res.qrc"/> | ||||||
|  |   <include location="../../../sdrbase/resources/res.qrc"/> | ||||||
|  |   <include location="../../../sdrbase/resources/res.qrc"/> | ||||||
|  |   <include location="../../../sdrbase/resources/res.qrc"/> | ||||||
|  </resources> |  </resources> | ||||||
|  <connections/> |  <connections/> | ||||||
| </ui> | </ui> | ||||||
|  | |||||||
| @ -33,7 +33,7 @@ QByteArray FileSinkSettings::serialize() const | |||||||
| { | { | ||||||
|     SimpleSerializer s(1); |     SimpleSerializer s(1); | ||||||
| 
 | 
 | ||||||
|     s.writeS32(1, m_sampleRate); |     s.writeU64(1, m_sampleRate); | ||||||
|     s.writeU32(2, m_log2Interp); |     s.writeU32(2, m_log2Interp); | ||||||
| 
 | 
 | ||||||
|     return s.final(); |     return s.final(); | ||||||
| @ -52,7 +52,7 @@ bool FileSinkSettings::deserialize(const QByteArray& data) | |||||||
|     if (d.getVersion() == 1) |     if (d.getVersion() == 1) | ||||||
|     { |     { | ||||||
|         int intval; |         int intval; | ||||||
|         d.readS32(1, &m_sampleRate, 48000); |         d.readU64(1, &m_sampleRate, 48000); | ||||||
|         d.readU32(2, &m_log2Interp, 0); |         d.readU32(2, &m_log2Interp, 0); | ||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -21,7 +21,7 @@ | |||||||
| 
 | 
 | ||||||
| struct FileSinkSettings { | struct FileSinkSettings { | ||||||
|     quint64 m_centerFrequency; |     quint64 m_centerFrequency; | ||||||
|     qint32 m_sampleRate; |     quint64 m_sampleRate; | ||||||
|     quint32 m_log2Interp; |     quint32 m_log2Interp; | ||||||
| 
 | 
 | ||||||
|     FileSinkSettings(); |     FileSinkSettings(); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user