Finished soapy module + added file source + added RTL_TCP source (windows only rn)

This commit is contained in:
Ryzerth
2020-10-04 02:56:02 +02:00
parent 47b04ffef4
commit 60342de9c0
21 changed files with 602 additions and 27 deletions

View File

@ -7,6 +7,8 @@ else()
set(CMAKE_CXX_FLAGS "-O3 -std=c++17 -fpermissive")
endif (MSVC)
include_directories("src/")
file(GLOB SRC "src/*.cpp")
add_library(file_source SHARED ${SRC})

View File

@ -3,6 +3,8 @@
#include <module.h>
#include <gui/gui.h>
#include <signal_path/signal_path.h>
#include <wavreader.h>
#include <core.h>
#define CONCAT(a, b) ((std::string(a) + b).c_str())
@ -29,6 +31,11 @@ public:
handler.tuneHandler = tune;
handler.stream = &stream;
sigpath::sourceManager.registerSource("File", &handler);
reader = new WavReader("D:/satpic/raw_recordings/NOAA-18_09-08-2018_21-39-00_baseband_NR.wav");
spdlog::info("Samplerate: {0}, Bit depth: {1}, Channel count: {2}", reader->getSampleRate(), reader->getBitDepth(), reader->getChannelCount());
spdlog::info("FileSourceModule '{0}': Instance created!", name);
}
@ -39,6 +46,7 @@ public:
private:
static void menuSelected(void* ctx) {
FileSourceModule* _this = (FileSourceModule*)ctx;
core::setInputSampleRate(_this->reader->getSampleRate());
spdlog::info("FileSourceModule '{0}': Menu Select!", _this->name);
}
@ -49,11 +57,15 @@ private:
static void start(void* ctx) {
FileSourceModule* _this = (FileSourceModule*)ctx;
_this->workerThread = std::thread(worker, _this);
spdlog::info("FileSourceModule '{0}': Start!", _this->name);
}
static void stop(void* ctx) {
FileSourceModule* _this = (FileSourceModule*)ctx;
_this->stream.stopWriter();
_this->workerThread.join();
_this->stream.clearWriteStop();
spdlog::info("FileSourceModule '{0}': Stop!", _this->name);
}
@ -62,15 +74,39 @@ private:
spdlog::info("FileSourceModule '{0}': Tune: {1}!", _this->name, freq);
}
static void menuHandler(void* ctx) {
FileSourceModule* _this = (FileSourceModule*)ctx;
ImGui::Text("Hi from %s!", _this->name.c_str());
}
static void worker(void* ctx) {
FileSourceModule* _this = (FileSourceModule*)ctx;
double sampleRate = _this->reader->getSampleRate();
int blockSize = sampleRate / 200.0;
int16_t* inBuf = new int16_t[blockSize * 2];
dsp::complex_t* outBuf = new dsp::complex_t[blockSize];
_this->stream.setMaxLatency(blockSize * 2);
while (true) {
_this->reader->readSamples(inBuf, blockSize * 2 * sizeof(int16_t));
for (int i = 0; i < blockSize; i++) {
outBuf[i].q = (float)inBuf[i * 2] / (float)0x7FFF;
outBuf[i].i = (float)inBuf[(i * 2) + 1] / (float)0x7FFF;
}
if (_this->stream.write(outBuf, blockSize) < 0) { break; };
//std::this_thread::sleep_for(std::chrono::milliseconds(5));
}
delete[] inBuf;
delete[] outBuf;
}
std::string name;
dsp::stream<dsp::complex_t> stream;
SourceManager::SourceHandler handler;
WavReader* reader;
std::thread workerThread;
};
MOD_EXPORT void _INIT_() {

View File

@ -0,0 +1,62 @@
#pragma once
#pragma once
#include <stdint.h>
#include <fstream>
#define WAV_SIGNATURE "RIFF"
#define WAV_TYPE "WAVE"
#define WAV_FORMAT_MARK "fmt "
#define WAV_DATA_MARK "data"
#define WAV_SAMPLE_TYPE_PCM 1
class WavReader {
public:
WavReader(std::string path) {
file = std::ifstream(path.c_str(), std::ios::binary);
file.read((char*)&hdr, sizeof(WavHeader_t));
}
uint16_t getBitDepth() {
return hdr.bitDepth;
}
uint16_t getChannelCount() {
return hdr.channelCount;
}
uint32_t getSampleRate() {
return hdr.sampleRate;
}
void readSamples(void* data, size_t size) {
file.read((char*)data, size);
bytesRead += size;
}
void close() {
file.close();
}
private:
struct WavHeader_t {
char signature[4]; // "RIFF"
uint32_t fileSize; // data bytes + sizeof(WavHeader_t) - 8
char fileType[4]; // "WAVE"
char formatMarker[4]; // "fmt "
uint32_t formatHeaderLength; // Always 16
uint16_t sampleType; // PCM (1)
uint16_t channelCount;
uint32_t sampleRate;
uint32_t bytesPerSecond;
uint16_t bytesPerSample;
uint16_t bitDepth;
char dataMarker[4]; // "data"
uint32_t dataSize;
};
std::ifstream file;
size_t bytesRead = 0;
WavHeader_t hdr;
};