a LOT of new stuff

This commit is contained in:
Ryzerth
2020-08-16 03:39:05 +02:00
parent 31a95031e4
commit eadaf3ce6b
34 changed files with 3988 additions and 203 deletions

View File

@ -11,8 +11,8 @@ struct RadioContext_t {
std::string name;
int demod = 1;
SigPath sigPath;
watcher<float> volume;
watcher<int> audioDevice;
// watcher<float> volume;
// watcher<int> audioDevice;
};
MOD_EXPORT void* _INIT_(mod::API_t* _API, ImGuiContext* imctx, std::string _name) {
@ -21,24 +21,24 @@ MOD_EXPORT void* _INIT_(mod::API_t* _API, ImGuiContext* imctx, std::string _name
ctx->name = _name;
ctx->sigPath.init(_name, 200000, 1000, API->registerVFO(_name, mod::API_t::REF_CENTER, 0, 200000, 200000, 1000));
ctx->sigPath.start();
ctx->volume.val = 1.0f;
ctx->volume.markAsChanged();
API->bindVolumeVariable(&ctx->volume.val);
ctx->audioDevice.val = ctx->sigPath.audio.getDeviceId();
ctx->audioDevice.changed(); // clear change
// ctx->volume.val = 1.0f;
// ctx->volume.markAsChanged();
// API->bindVolumeVariable(&ctx->volume.val);
// ctx->audioDevice.val = ctx->sigPath.audio.getDeviceId();
// ctx->audioDevice.changed(); // clear change
ImGui::SetCurrentContext(imctx);
return ctx;
}
MOD_EXPORT void _NEW_FRAME_(RadioContext_t* ctx) {
if (ctx->volume.changed()) {
ctx->sigPath.setVolume(ctx->volume.val);
}
if (ctx->audioDevice.changed()) {
ctx->sigPath.audio.stop();
ctx->sigPath.audio.setDevice(ctx->audioDevice.val);
ctx->sigPath.audio.start();
}
// if (ctx->volume.changed()) {
// ctx->sigPath.setVolume(ctx->volume.val);
// }
// if (ctx->audioDevice.changed()) {
// ctx->sigPath.audio.stop();
// ctx->sigPath.audio.setDevice(ctx->audioDevice.val);
// ctx->sigPath.audio.start();
// }
}
MOD_EXPORT void _DRAW_MENU_(RadioContext_t* ctx) {
@ -85,9 +85,9 @@ MOD_EXPORT void _DRAW_MENU_(RadioContext_t* ctx) {
ImGui::EndGroup();
ImGui::PushItemWidth(ImGui::GetWindowSize().x);
ImGui::Combo(CONCAT("##_audio_dev_", ctx->name), &ctx->audioDevice.val, ctx->sigPath.audio.devTxtList.c_str());
ImGui::PopItemWidth();
// ImGui::PushItemWidth(ImGui::GetWindowSize().x);
// ImGui::Combo(CONCAT("##_audio_dev_", ctx->name), &ctx->audioDevice.val, ctx->sigPath.audio.devTxtList.c_str());
// ImGui::PopItemWidth();
}
MOD_EXPORT void _HANDLE_EVENT_(RadioContext_t* ctx, int eventId) {
@ -96,9 +96,9 @@ MOD_EXPORT void _HANDLE_EVENT_(RadioContext_t* ctx, int eventId) {
ctx->sigPath.updateBlockSize();
}
else if (eventId == mod::EVENT_SELECTED_VFO_CHANGED) {
if (API->getSelectedVFOName() == ctx->name) {
API->bindVolumeVariable(&ctx->volume.val);
}
// if (API->getSelectedVFOName() == ctx->name) {
// API->bindVolumeVariable(&ctx->volume.val);
// }
}
}

View File

@ -4,6 +4,14 @@ SigPath::SigPath() {
}
int SigPath::sampleRateChangeHandler(void* ctx, float sampleRate) {
SigPath* _this = (SigPath*)ctx;
_this->audioResamp.stop();
_this->audioResamp.setOutputSampleRate(sampleRate, sampleRate / 2.0f, sampleRate / 2.0f);
_this->audioResamp.start();
return _this->audioResamp.getOutputBlockSize();
}
void SigPath::init(std::string vfoName, uint64_t sampleRate, int blockSize, dsp::stream<dsp::complex_t>* input) {
this->sampleRate = sampleRate;
this->blockSize = blockSize;
@ -18,7 +26,8 @@ void SigPath::init(std::string vfoName, uint64_t sampleRate, int blockSize, dsp:
ssbDemod.init(input, 6000, 3000, 22);
audioResamp.init(&demod.output, 200000, 48000, 800);
audio.init(&audioResamp.output, 64);
API->registerMonoStream(&audioResamp.output, vfoName, vfoName, sampleRateChangeHandler, this);
API->setBlockSize(vfoName, audioResamp.getOutputBlockSize());
}
void SigPath::setSampleRate(float sampleRate) {
@ -28,10 +37,6 @@ void SigPath::setSampleRate(float sampleRate) {
setDemodulator(_demod);
}
void SigPath::setVolume(float volume) {
audio.setVolume(volume);
}
void SigPath::setDemodulator(int demId) {
if (demId < 0 || demId >= _DEMOD_COUNT) {
return;
@ -64,7 +69,7 @@ void SigPath::setDemodulator(int demId) {
demod.setSampleRate(200000);
demod.setDeviation(100000);
audioResamp.setInput(&demod.output);
audioResamp.setInputSampleRate(200000, API->getVFOOutputBlockSize(vfoName));
audioResamp.setInputSampleRate(200000, API->getVFOOutputBlockSize(vfoName), 15000, 15000);
demod.start();
}
if (demId == DEMOD_NFM) {
@ -110,10 +115,5 @@ void SigPath::updateBlockSize() {
void SigPath::start() {
demod.start();
audioResamp.start();
audio.start();
}
void SigPath::DEBUG_TEST() {
audio.stop();
audio.start();
API->startStream(vfoName);
}

View File

@ -19,16 +19,11 @@ public:
void setSampleRate(float sampleRate);
void setVFOFrequency(long frequency);
void setVolume(float volume);
void updateBlockSize();
void setDemodulator(int demod);
void DEBUG_TEST();
io::AudioSink audio;
enum {
DEMOD_FM,
DEMOD_NFM,
@ -39,6 +34,8 @@ public:
};
private:
static int sampleRateChangeHandler(void* ctx, float sampleRate);
dsp::stream<dsp::complex_t> input;
// Demodulators