Browse Source

WavFileRecord: Increase performance of 24-bit file writes.

chirpmodem-v8.0.0
Jon Beniston 1 month ago
parent
commit
b79eaf971a
  1. 19
      sdrbase/dsp/wavfilerecord.cpp
  2. 2
      sdrbase/dsp/wavfilerecord.h

19
sdrbase/dsp/wavfilerecord.cpp

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include <algorithm>
#include <cstddef>
#include <cstring>
@ -100,19 +101,23 @@ void WavFileRecord::feed(const SampleVector::const_iterator& begin, const Sample @@ -100,19 +101,23 @@ void WavFileRecord::feed(const SampleVector::const_iterator& begin, const Sample
if (SDR_RX_SAMP_SZ == 16)
{
m_sampleFile.write(reinterpret_cast<const char*>(&*(begin)), (end - begin)*sizeof(Sample));
m_byteCount += end - begin;
m_byteCount += (end - begin) * sizeof(Sample);
}
else
{
// Converted from 24 bit to 16 bit a block at a time for efficiency
const std::size_t count = end - begin;
m_convertBuffer.resize(2 * count);
qint16 *out = m_convertBuffer.data();
for (SampleVector::const_iterator it = begin; it != end; ++it)
{
// Convert from 24-bit to 16-bit
int16_t samples[2];
samples[0] = std::min(32767, std::max(it->real() >> 8, -32768));
samples[1] = std::min(32767, std::max(it->imag() >> 8, -32768));
m_sampleFile.write(reinterpret_cast<const char*>(&samples), 4);
m_byteCount += 4;
*out++ = (qint16) std::min(32767, std::max(it->real() >> 8, -32768));
*out++ = (qint16) std::min(32767, std::max(it->imag() >> 8, -32768));
}
m_sampleFile.write(reinterpret_cast<const char*>(m_convertBuffer.data()), 4 * count);
m_byteCount += 4 * count;
}
}
}

2
sdrbase/dsp/wavfilerecord.h

@ -26,6 +26,7 @@ @@ -26,6 +26,7 @@
#include <iostream>
#include <fstream>
#include <ctime>
#include <vector>
#include <QDateTime>
#include <QFile>
@ -149,6 +150,7 @@ private: @@ -149,6 +150,7 @@ private:
#endif
QString m_currentFileName;
quint64 m_byteCount;
std::vector<qint16> m_convertBuffer; //!< 24 bit samples converted to 16, a block at a time
qint64 m_msShift;
int m_nbChannels;

Loading…
Cancel
Save