mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-03-22 04:08:29 -04:00
FT8 demod: removed sndfile dependency
This commit is contained in:
parent
7cd08ef1e9
commit
65e9d1a167
56
ft8/util.cpp
56
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 <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
#include <sndfile.h>
|
||||
#include <sys/time.h>
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
@ -37,61 +36,6 @@ double now()
|
||||
return tv.tv_sec + tv.tv_usec / 1000000.0;
|
||||
}
|
||||
|
||||
void writewav(const std::vector<float> &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<float> 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<float> 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<float> 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<float> v, const char *filename)
|
||||
{
|
||||
FILE *fp = fopen(filename, "w");
|
||||
|
@ -27,8 +27,6 @@
|
||||
namespace FT8
|
||||
{
|
||||
double now();
|
||||
void writewav(const std::vector<float> &samples, const char *filename, int rate);
|
||||
std::vector<float> readwav(const char *filename, int &rate_out);
|
||||
void writetxt(std::vector<float> v, const char *filename);
|
||||
std::complex<float> goertzel(std::vector<float> v, int rate, int i0, int n, float hz);
|
||||
float vmax(const std::vector<float> &v);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -15,10 +15,14 @@
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include "mainbench.h"
|
||||
#include "dsp/wavfilerecord.h"
|
||||
|
||||
#ifdef LINUX
|
||||
#include "ft8/ft8.h"
|
||||
#include "ft8/util.h"
|
||||
#include "ft8/unpack.h"
|
||||
|
||||
#include <QMutex>
|
||||
@ -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<float> 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<float> 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,
|
||||
|
Loading…
Reference in New Issue
Block a user