Skip to content

Commit

Permalink
Merge pull request #1946 from srcejon/freq_scanner
Browse files Browse the repository at this point in the history
Couple of bug fixes
  • Loading branch information
f4exb authored Jan 4, 2024
2 parents d259443 + 14430bc commit 024924f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
18 changes: 10 additions & 8 deletions plugins/samplesource/fileinput/fileinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ FileInput::FileInput(DeviceAPI *deviceAPI) :
m_sampleRate(48000),
m_sampleSize(0),
m_centerFrequency(435000000),
m_dataStartPos(0),
m_recordLengthMuSec(0),
m_startingTimeStamp(0)
{
Expand Down Expand Up @@ -156,11 +157,11 @@ void FileInput::openFileStream()
if (headerOK && (m_sampleRate > 0) && (m_sampleSize > 0))
{
#ifdef ANDROID
qint64 pos = m_inputFile.pos();
m_dataStartPos = m_inputFile.pos();
#else
qint64 pos = m_ifstream.tellg();
m_dataStartPos = m_ifstream.tellg();
#endif
m_recordLengthMuSec = ((fileSize - pos) * 1000000UL) / ((m_sampleSize == 24 ? 8 : 4) * m_sampleRate);
m_recordLengthMuSec = ((fileSize - m_dataStartPos) * 1000000UL) / ((m_sampleSize == 24 ? 8 : 4) * m_sampleRate);
}
else
{
Expand All @@ -184,7 +185,8 @@ void FileInput::openFileStream()
m_ifstream.seekg(0,std::ios_base::beg);
bool crcOK = FileRecord::readHeader(m_ifstream, header);
#endif
m_sampleRate = header.sampleRate;
m_dataStartPos = sizeof(FileRecord::Header);
m_sampleRate = header.sampleRate;
m_centerFrequency = header.centerFrequency;
m_startingTimeStamp = header.startTimeStamp;
m_sampleSize = header.sampleSize;
Expand All @@ -193,7 +195,7 @@ void FileInput::openFileStream()
if (crcOK && (m_sampleRate > 0) && (m_sampleSize > 0))
{
qDebug("FileInput::openFileStream: CRC32 OK for header: %s", qPrintable(crcHex));
m_recordLengthMuSec = ((fileSize - sizeof(FileRecord::Header)) * 1000000UL) / ((m_sampleSize == 24 ? 8 : 4) * m_sampleRate);
m_recordLengthMuSec = ((fileSize - m_dataStartPos) * 1000000UL) / ((m_sampleSize == 24 ? 8 : 4) * m_sampleRate);
}
else if (!crcOK)
{
Expand Down Expand Up @@ -260,12 +262,12 @@ void FileInput::seekFileStream(int seekMillis)
quint64 seekPoint = ((m_recordLengthMuSec * seekMillis) / 1000) * m_sampleRate;
seekPoint /= 1000000UL;
m_fileInputWorker->setSamplesCount(seekPoint);
seekPoint *= (m_sampleSize == 24 ? 8 : 4); // + sizeof(FileRecord::Header)
seekPoint *= (m_sampleSize == 24 ? 8 : 4);
#ifdef ANDROID
m_inputFile.seek(seekPoint + sizeof(FileRecord::Header));
m_inputFile.seek(seekPoint + m_dataStartPos);
#else
m_ifstream.clear();
m_ifstream.seekg(seekPoint + sizeof(FileRecord::Header), std::ios::beg);
m_ifstream.seekg(seekPoint + m_dataStartPos, std::ios::beg);
#endif
}
}
Expand Down
1 change: 1 addition & 0 deletions plugins/samplesource/fileinput/fileinput.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ class FileInput : public DeviceSampleSource {
int m_sampleRate;
quint32 m_sampleSize;
quint64 m_centerFrequency;
qint64 m_dataStartPos; //!< Position of IQ data in file
quint64 m_recordLengthMuSec; //!< record length in microseconds computed from file size
quint64 m_startingTimeStamp;
QTimer m_masterTimer;
Expand Down
7 changes: 5 additions & 2 deletions sdrgui/gui/glspectrumview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2444,13 +2444,13 @@ float GLSpectrumView::calPower(float power) const

int GLSpectrumView::frequencyToBin(int64_t frequency) const
{
float rbw = m_sampleRate / (float)m_fftSize;
float rbw = (m_ssbSpectrum ? (m_sampleRate/2) : m_sampleRate) / (float)m_fftSize;
return (frequency - m_frequencyScale.getRangeMin()) / rbw;
}

int64_t GLSpectrumView::binToFrequency(int bin) const
{
float rbw = m_sampleRate / (float)m_fftSize;
float rbw = (m_ssbSpectrum ? (m_sampleRate/2) : m_sampleRate) / (float)m_fftSize;
return m_frequencyScale.getRangeMin() + bin * rbw;
}

Expand Down Expand Up @@ -3453,6 +3453,9 @@ void GLSpectrumView::applyChanges()

void GLSpectrumView::updateHistogramMarkers()
{
if (m_sampleRate == 0) {
return;
}
int64_t centerFrequency;
int frequencySpan;
getFrequencyZoom(centerFrequency, frequencySpan);
Expand Down

0 comments on commit 024924f

Please sign in to comment.