mirror of
				https://github.com/f4exb/sdrangel.git
				synced 2025-10-30 12:30:20 -04:00 
			
		
		
		
	FileSource channel: fixes (2)
This commit is contained in:
		
							parent
							
								
									27ba28d406
								
							
						
					
					
						commit
						45cf4c86d5
					
				| @ -198,18 +198,25 @@ void FileSource::pullAudio(int nbSamples) | ||||
| void FileSource::start() | ||||
| { | ||||
|     qDebug("FileSource::start"); | ||||
| 
 | ||||
|     if (m_running) { | ||||
|         stop(); | ||||
|     } | ||||
| 
 | ||||
|     m_running = true; | ||||
| 
 | ||||
| 	if (getMessageQueueToGUI()) | ||||
|     { | ||||
|         MsgReportFileSourceAcquisition *report = MsgReportFileSourceAcquisition::create(true); // acquisition on
 | ||||
|         getMessageQueueToGUI()->push(report); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| void FileSource::stop() | ||||
| { | ||||
|     qDebug("FileSource::stop"); | ||||
|     m_running = false; | ||||
| 
 | ||||
| 	if (getMessageQueueToGUI()) | ||||
|     { | ||||
|         MsgReportFileSourceAcquisition *report = MsgReportFileSourceAcquisition::create(false); // acquisition off
 | ||||
|         getMessageQueueToGUI()->push(report); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| bool FileSource::handleMessage(const Message& cmd) | ||||
| @ -361,6 +368,7 @@ void FileSource::openFileStream() | ||||
| 	m_ifstream.open(m_fileName.toStdString().c_str(), std::ios::binary | std::ios::ate); | ||||
| #endif | ||||
| 	quint64 fileSize = m_ifstream.tellg(); | ||||
|     m_samplesCount = 0; | ||||
| 
 | ||||
| 	if (fileSize > sizeof(FileRecord::Header)) | ||||
| 	{ | ||||
| @ -399,7 +407,8 @@ void FileSource::openFileStream() | ||||
| 			<< " length: " << m_recordLength << " seconds" | ||||
| 			<< " sample rate: " << m_fileSampleRate << " S/s" | ||||
| 			<< " center frequency: " << m_centerFrequency << " Hz" | ||||
| 			<< " sample size: " << m_sampleSize << " bits"; | ||||
| 			<< " sample size: " << m_sampleSize << " bits" | ||||
|             << " starting TS: " << m_startingTimeStamp << "s"; | ||||
| 
 | ||||
| 	if (getMessageQueueToGUI()) { | ||||
| 	    MsgReportFileSourceStreamData *report = MsgReportFileSourceStreamData::create(m_fileSampleRate, | ||||
| @ -422,6 +431,7 @@ void FileSource::seekFileStream(int seekMillis) | ||||
| 	if ((m_ifstream.is_open()) && !m_running) | ||||
| 	{ | ||||
|         quint64 seekPoint = ((m_recordLength * seekMillis) / 1000) * m_fileSampleRate; | ||||
|         m_samplesCount = seekPoint; | ||||
|         seekPoint *= (m_sampleSize == 24 ? 8 : 4); // + sizeof(FileSink::Header)
 | ||||
| 		m_ifstream.clear(); | ||||
| 		m_ifstream.seekg(seekPoint + sizeof(FileRecord::Header), std::ios::beg); | ||||
| @ -441,6 +451,7 @@ void FileSource::handleEOF() | ||||
|     if (m_settings.m_loop) | ||||
|     { | ||||
|         seekFileStream(0); | ||||
|         m_samplesCount = 0; | ||||
|         start(); | ||||
|     } | ||||
|     else | ||||
|  | ||||
| @ -102,6 +102,49 @@ bool FileSourceGUI::handleMessage(const Message& message) | ||||
|         blockApplySettings(false); | ||||
|         return true; | ||||
|     } | ||||
|     else if (FileSource::MsgReportFileSourceAcquisition::match(message)) | ||||
| 	{ | ||||
| 		m_acquisition = ((FileSource::MsgReportFileSourceAcquisition&)message).getAcquisition(); | ||||
| 		updateWithAcquisition(); | ||||
| 		return true; | ||||
| 	} | ||||
| 	else if (FileSource::MsgReportFileSourceStreamData::match(message)) | ||||
| 	{ | ||||
| 		m_fileSampleRate = ((FileSource::MsgReportFileSourceStreamData&)message).getSampleRate(); | ||||
| 		m_fileSampleSize = ((FileSource::MsgReportFileSourceStreamData&)message).getSampleSize(); | ||||
| 		m_startingTimeStamp = ((FileSource::MsgReportFileSourceStreamData&)message).getStartingTimeStamp(); | ||||
| 		m_recordLength = ((FileSource::MsgReportFileSourceStreamData&)message).getRecordLength(); | ||||
| 		updateWithStreamData(); | ||||
| 		return true; | ||||
| 	} | ||||
| 	else if (FileSource::MsgReportFileSourceStreamTiming::match(message)) | ||||
| 	{ | ||||
| 		m_samplesCount = ((FileSource::MsgReportFileSourceStreamTiming&)message).getSamplesCount(); | ||||
| 		updateWithStreamTime(); | ||||
| 		return true; | ||||
| 	} | ||||
| 	else if (FileSource::MsgPlayPause::match(message)) | ||||
| 	{ | ||||
| 	    FileSource::MsgPlayPause& notif = (FileSource::MsgPlayPause&) message; | ||||
| 	    bool checked = notif.getPlayPause(); | ||||
| 	    ui->play->setChecked(checked); | ||||
| 	    ui->navTime->setEnabled(!checked); | ||||
| 	    m_enableNavTime = !checked; | ||||
| 
 | ||||
| 	    return true; | ||||
| 	} | ||||
| 	else if (FileSource::MsgReportHeaderCRC::match(message)) | ||||
| 	{ | ||||
| 		FileSource::MsgReportHeaderCRC& notif = (FileSource::MsgReportHeaderCRC&) message; | ||||
| 
 | ||||
|         if (notif.isOK()) { | ||||
| 			ui->crcLabel->setStyleSheet("QLabel { background-color : green; }"); | ||||
| 		} else { | ||||
| 			ui->crcLabel->setStyleSheet("QLabel { background-color : red; }"); | ||||
| 		} | ||||
| 
 | ||||
| 		return true; | ||||
| 	} | ||||
|     else | ||||
|     { | ||||
|         return false; | ||||
| @ -113,6 +156,16 @@ FileSourceGUI::FileSourceGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, Bas | ||||
|         ui(new Ui::FileSourceGUI), | ||||
|         m_pluginAPI(pluginAPI), | ||||
|         m_deviceUISet(deviceUISet), | ||||
|         m_sampleRate(0), | ||||
|         m_shiftFrequencyFactor(0.0), | ||||
|         m_fileSampleRate(0), | ||||
|         m_fileSampleSize(0), | ||||
|         m_recordLength(0), | ||||
|         m_startingTimeStamp(0), | ||||
|         m_samplesCount(0), | ||||
|         m_acquisition(false), | ||||
|         m_enableNavTime(false), | ||||
|         m_doApplySettings(true), | ||||
|         m_tickCount(0) | ||||
| { | ||||
|     (void) channelTx; | ||||
| @ -190,6 +243,54 @@ void FileSourceGUI::configureFileName() | ||||
| 	m_fileSource->getInputMessageQueue()->push(message); | ||||
| } | ||||
| 
 | ||||
| void FileSourceGUI::updateWithAcquisition() | ||||
| { | ||||
| 	ui->play->setChecked(m_acquisition); | ||||
| 	ui->showFileDialog->setEnabled(!m_acquisition); | ||||
| } | ||||
| 
 | ||||
| void FileSourceGUI::updateWithStreamData() | ||||
| { | ||||
| 	ui->sampleRateText->setText(tr("%1k").arg((float) m_fileSampleRate / 1000)); | ||||
| 	ui->sampleSizeText->setText(tr("%1b").arg(m_fileSampleSize)); | ||||
| 	QTime recordLength(0, 0, 0, 0); | ||||
| 	recordLength = recordLength.addSecs(m_recordLength); | ||||
| 	QString s_time = recordLength.toString("HH:mm:ss"); | ||||
| 	ui->recordLengthText->setText(s_time); | ||||
| 	updateWithStreamTime(); | ||||
| } | ||||
| 
 | ||||
| void FileSourceGUI::updateWithStreamTime() | ||||
| { | ||||
|     qint64 t_sec = 0; | ||||
|     qint64 t_msec = 0; | ||||
| 
 | ||||
| 	if (m_fileSampleRate > 0) | ||||
|     { | ||||
| 		t_sec = m_samplesCount / m_fileSampleRate; | ||||
|         t_msec = (m_samplesCount - (t_sec * m_fileSampleRate)) * 1000LL / m_fileSampleRate; | ||||
| 	} | ||||
| 
 | ||||
| 	QTime t(0, 0, 0, 0); | ||||
| 	t = t.addSecs(t_sec); | ||||
| 	t = t.addMSecs(t_msec); | ||||
| 	QString s_timems = t.toString("HH:mm:ss.zzz"); | ||||
| 	ui->relTimeText->setText(s_timems); | ||||
| 
 | ||||
|     qint64 startingTimeStampMsec = m_startingTimeStamp * 1000LL; | ||||
| 	QDateTime dt = QDateTime::fromMSecsSinceEpoch(startingTimeStampMsec); | ||||
|     dt = dt.addSecs(t_sec); | ||||
|     dt = dt.addMSecs(t_msec); | ||||
| 	QString s_date = dt.toString("yyyy-MM-dd HH:mm:ss.zzz"); | ||||
| 	ui->absTimeText->setText(s_date); | ||||
| 
 | ||||
| 	if (!m_enableNavTime) | ||||
| 	{ | ||||
| 		float posRatio = (float) t_sec / (float) m_recordLength; | ||||
| 		ui->navTime->setValue((int) (posRatio * 1000.0)); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| void FileSourceGUI::displaySettings() | ||||
| { | ||||
|     m_channelMarker.blockSignals(true); | ||||
| @ -362,6 +463,8 @@ void FileSourceGUI::tick() | ||||
| { | ||||
|     if (++m_tickCount == 20) // once per second
 | ||||
|     { | ||||
| 		FileSource::MsgConfigureFileSourceStreamTiming* message = FileSource::MsgConfigureFileSourceStreamTiming::create(); | ||||
| 		m_fileSource->getInputMessageQueue()->push(message); | ||||
|         m_tickCount = 0; | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -66,6 +66,12 @@ private: | ||||
|     int m_sampleRate; | ||||
|     double m_shiftFrequencyFactor; //!< Channel frequency shift factor
 | ||||
|     QString m_fileName; | ||||
|     int m_fileSampleRate; | ||||
|     quint32 m_fileSampleSize; | ||||
|     quint64 m_recordLength; | ||||
|     quint64 m_startingTimeStamp; | ||||
|     quint64 m_samplesCount; | ||||
|     bool m_acquisition; | ||||
|   	bool m_enableNavTime; | ||||
|     bool m_doApplySettings; | ||||
| 
 | ||||
| @ -82,6 +88,9 @@ private: | ||||
|     void applySettings(bool force = false); | ||||
|     void applyChannelSettings(); | ||||
|     void configureFileName(); | ||||
| 	void updateWithAcquisition(); | ||||
| 	void updateWithStreamData(); | ||||
| 	void updateWithStreamTime(); | ||||
|     void displaySettings(); | ||||
|     void displayRateAndShift(); | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user