diff --git a/ft8/util.cpp b/ft8/util.cpp
index fe9112a6d..d55cb5e5f 100644
--- a/ft8/util.cpp
+++ b/ft8/util.cpp
@@ -18,7 +18,6 @@
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see . //
///////////////////////////////////////////////////////////////////////////////////
-#include
#include
#include
#include
@@ -37,61 +36,6 @@ double now()
return tv.tv_sec + tv.tv_usec / 1000000.0;
}
-void writewav(const std::vector &samples, const char *filename, int rate)
-{
- float mx = 0;
- for (ulong i = 0; i < samples.size(); i++)
- {
- mx = std::max(mx, std::abs(samples[i]));
- }
- std::vector v(samples.size());
- for (ulong i = 0; i < samples.size(); i++)
- {
- v[i] = (samples[i] / mx) * 0.95;
- }
-
- SF_INFO sf;
- sf.channels = 1;
- sf.samplerate = rate;
- sf.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16;
- SNDFILE *f = sf_open(filename, SFM_WRITE, &sf);
- assert(f);
- sf_write_float(f, v.data(), v.size());
- sf_write_sync(f);
- sf_close(f);
-}
-
-std::vector readwav(const char *filename, int &rate_out)
-{
- SF_INFO info;
- memset(&info, 0, sizeof(info));
- SNDFILE *sf = sf_open(filename, SFM_READ, &info);
- if (sf == 0)
- {
- fprintf(stderr, "cannot open %s\n", filename);
- exit(1); // XXX
- }
- rate_out = info.samplerate;
-
- std::vector out;
-
- while (1)
- {
- float buf[512];
- int n = sf_read_float(sf, buf, 512);
- if (n <= 0)
- break;
- for (int i = 0; i < n; i++)
- {
- out.push_back(buf[i]);
- }
- }
-
- sf_close(sf);
-
- return out;
-}
-
void writetxt(std::vector v, const char *filename)
{
FILE *fp = fopen(filename, "w");
diff --git a/ft8/util.h b/ft8/util.h
index d56ee88b4..7f855b4cc 100644
--- a/ft8/util.h
+++ b/ft8/util.h
@@ -27,8 +27,6 @@
namespace FT8
{
double now();
-void writewav(const std::vector &samples, const char *filename, int rate);
-std::vector readwav(const char *filename, int &rate_out);
void writetxt(std::vector v, const char *filename);
std::complex goertzel(std::vector v, int rate, int i0, int n, float hz);
float vmax(const std::vector &v);
diff --git a/sdrbase/dsp/wavfilerecord.cpp b/sdrbase/dsp/wavfilerecord.cpp
index 2647e69e9..ccba9f42e 100644
--- a/sdrbase/dsp/wavfilerecord.cpp
+++ b/sdrbase/dsp/wavfilerecord.cpp
@@ -325,7 +325,7 @@ void WavFileRecord::writeHeader()
writeHeader(m_sampleFile, header);
}
-bool WavFileRecord::readHeader(std::ifstream& sampleFile, Header& header)
+bool WavFileRecord::readHeader(std::ifstream& sampleFile, Header& header, bool check)
{
memset(&header, 0, sizeof(Header));
@@ -336,7 +336,7 @@ bool WavFileRecord::readHeader(std::ifstream& sampleFile, Header& header)
return false;
}
- if (!checkHeader(header)) {
+ if (check && !checkHeader(header)) {
return false;
}
diff --git a/sdrbase/dsp/wavfilerecord.h b/sdrbase/dsp/wavfilerecord.h
index 9cf2db22b..c763c4808 100644
--- a/sdrbase/dsp/wavfilerecord.h
+++ b/sdrbase/dsp/wavfilerecord.h
@@ -111,7 +111,7 @@ public:
virtual bool stopRecording() override;
virtual bool isRecording() const override { return m_recordOn; }
- static bool readHeader(std::ifstream& samplefile, Header& header);
+ static bool readHeader(std::ifstream& samplefile, Header& header, bool check=true);
static bool readHeader(QFile& samplefile, Header& header);
static void writeHeader(std::ofstream& samplefile, Header& header);
static void writeHeader(QFile& samplefile, Header& header);
diff --git a/sdrbench/test_ft8.cpp b/sdrbench/test_ft8.cpp
index 2c960d374..936fc23b0 100644
--- a/sdrbench/test_ft8.cpp
+++ b/sdrbench/test_ft8.cpp
@@ -15,10 +15,14 @@
// along with this program. If not, see . //
///////////////////////////////////////////////////////////////////////////////////
+#include
+#include
+
#include "mainbench.h"
+#include "dsp/wavfilerecord.h"
+
#ifdef LINUX
#include "ft8/ft8.h"
-#include "ft8/util.h"
#include "ft8/unpack.h"
#include
@@ -104,13 +108,70 @@ void MainBench::testFT8(const QString& wavFile)
double budget = 2.5; // compute for this many seconds per cycle
TestFT8Callback testft8Callback;
- int rate;
- std::vector s = FT8::readwav(wavFile.toStdString().c_str(), rate);
+ std::ifstream wfile;
+
+#ifdef Q_OS_WIN
+ wfile.open(m_settings.m_fileName.toStdWString().c_str(), std::ios::binary | std::ios::ate);
+#else
+ wfile.open(wavFile.toStdString().c_str(), std::ios::binary | std::ios::ate);
+#endif
+ WavFileRecord::Header header;
+ wfile.seekg(0, std::ios_base::beg);
+ bool headerOK = WavFileRecord::readHeader(wfile, header, false);
+
+ if (!headerOK)
+ {
+ qDebug("MainBench::testFT8: test file is not a wave file");
+ return;
+ }
+
+ if (header.m_sampleRate != 12000)
+ {
+ qDebug("MainBench::testFT8: wave file sample rate is not 12000 S/s");
+ return;
+ }
+
+ if (header.m_bitsPerSample != 16)
+ {
+ qDebug("MainBench::testFT8: sample size is not 16 bits");
+ return;
+ }
+
+ if (header.m_audioFormat != 1)
+ {
+ qDebug("MainBench::testFT8: wav file format is not PCM");
+ return;
+ }
+
+ if (header.m_dataHeader.m_size != 360000)
+ {
+ qDebug("MainBench::testFT8: wave file size is not 15s at 12000 S/s");
+ return;
+ }
+
+ const int bufsize = 1000;
+ int16_t buffer[bufsize];
+ std::vector samples;
+ uint32_t remainder = header.m_dataHeader.m_size;
+
+ while (remainder != 0)
+ {
+ wfile.read((char *) buffer, bufsize*2);
+
+ for (int i = 0; i < bufsize; i++) {
+ samples.push_back(buffer[i] / 32768.0f);
+ }
+
+ remainder -= bufsize*2;
+ }
+
+ wfile.close();
+
FT8::entry(
- s.data(),
- s.size(),
- 0.5 * rate,
- rate,
+ samples.data(),
+ samples.size(),
+ 0.5 * header.m_sampleRate,
+ header.m_sampleRate,
150,
3600, // 2900,
hints,