From 3e717d7aa06881ebd55a94ee02a6581a3dbfae79 Mon Sep 17 00:00:00 2001 From: jcable Date: Mon, 12 Jan 2026 20:33:12 +0000 Subject: [PATCH 1/3] fix segfaults --- src/ctransmitdata.cpp | 2 +- src/resample/speexresampler.cpp | 9 ++++++++- src/sourcedecoders/AudioSourceEncoder.cpp | 4 ++-- src/sourcedecoders/AudioSourceEncoder.h | 1 + 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/ctransmitdata.cpp b/src/ctransmitdata.cpp index 24e6f1f9f..4ebb6795c 100644 --- a/src/ctransmitdata.cpp +++ b/src/ctransmitdata.cpp @@ -137,7 +137,7 @@ void CTransmitData::FlushData() cerr << "problem writing to sound card" << endl; } #else - pSound->Write(vecsDataOut); + if (pSound) pSound->Write(vecsDataOut); #endif } else diff --git a/src/resample/speexresampler.cpp b/src/resample/speexresampler.cpp index 696f375d4..3e9fe81eb 100644 --- a/src/resample/speexresampler.cpp +++ b/src/resample/speexresampler.cpp @@ -28,11 +28,15 @@ void SpeexResampler::Free() /* this function is only called when the input and output sample rates are different */ void SpeexResampler::Resample(CVector<_REAL>& rInput, CVector<_REAL>& rOutput) { + if (vecfOutput.size() == 0) { + cerr << "SpeexResampler::Resample(): zero size output buffer, doing nothing" << endl; + } size_t iOutputBlockSize = vecfOutput.size(); if ((rOutput.Size() != int(iOutputBlockSize)) || (GetFreeInputSize()& rInput, CVector<_REAL>& rOutput) } if (output_frames_gen != iOutputBlockSize) - cerr << "SpeexResampler::Resample(): output_frames_gen(" << output_frames_gen << ") != iOutputBlockSize(" << iOutputBlockSize << ")" << endl; for (size_t i = 0; i < iOutputBlockSize; i++) rOutput[int(i)] = _REAL(vecfOutput[i]); iInputBuffered = input_frames - input_frames_used; + if(iInputBuffered>1000000) { + cerr << "too many input frames" << endl; + return; + } if(iInputBuffered>0) { cerr << "resampling buffered " << iInputBuffered << " frames" << endl; if(vecfInput.size()EncUpdate(AudioParam); } @@ -195,7 +194,6 @@ cerr<<"Audio param changed"<= iAudioPayloadLen "< Date: Mon, 12 Jan 2026 21:27:48 +0000 Subject: [PATCH 2/3] add signalling --- src/main-Qt/ctx.cpp | 4 +++- src/main-Qt/ctx.h | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main-Qt/ctx.cpp b/src/main-Qt/ctx.cpp index 8d5b233ef..2bfff60b5 100644 --- a/src/main-Qt/ctx.cpp +++ b/src/main-Qt/ctx.cpp @@ -54,6 +54,7 @@ CTx::run() void CTx::LoadSettings() { tx.LoadSettings(); + emit InputDeviceChanged(QString::fromStdString(tx.GetInputDevice())); emit OutputDeviceChanged(QString::fromStdString(tx.GetOutputDevice())); } @@ -75,12 +76,13 @@ void CTx::SetOutputDevice(QString s) void CTx::SetInputDevice(string s) { tx.SetInputDevice(s); - emit OutputDeviceChanged(QString::fromStdString(tx.GetOutputDevice())); + emit InputDeviceChanged(QString::fromStdString(tx.GetInputDevice())); } void CTx::SetOutputDevice(string s) { tx.SetOutputDevice(s); + emit OutputDeviceChanged(QString::fromStdString(tx.GetOutputDevice())); } std::string CTx::GetInputDevice() diff --git a/src/main-Qt/ctx.h b/src/main-Qt/ctx.h index 7b5cad9b1..eab1bc47c 100644 --- a/src/main-Qt/ctx.h +++ b/src/main-Qt/ctx.h @@ -57,6 +57,7 @@ public slots: ERunState eRunState; signals: void OutputDeviceChanged(QString); + void InputDeviceChanged(QString); }; From 70ab9041c6bc2b00874f844ce9723efb29bfd09c Mon Sep 17 00:00:00 2001 From: jcable Date: Tue, 13 Jan 2026 23:35:11 +0000 Subject: [PATCH 3/3] rationalise --- src/DrmReceiver.cpp | 2 +- src/DrmTransmitter.cpp | 2 +- src/GUI-QT/SoundCardSelMenu.cpp | 85 ++++++++++++++++++--------------- src/GUI-QT/SoundCardSelMenu.h | 19 ++++---- src/GUI-QT/TransmDlg.cpp | 3 -- src/Parameter.h | 2 +- src/main-Qt/crx.cpp | 9 +++- src/main-Qt/crx.h | 3 +- 8 files changed, 71 insertions(+), 54 deletions(-) diff --git a/src/DrmReceiver.cpp b/src/DrmReceiver.cpp index b4b2de573..736d08d60 100644 --- a/src/DrmReceiver.cpp +++ b/src/DrmReceiver.cpp @@ -1430,7 +1430,7 @@ CDRMReceiver::LoadSettings() Parameters.SetNewAudSampleRate(s.Get("Receiver", "samplerateaud", int(DEFAULT_SOUNDCRD_SAMPLE_RATE))); /* Sound card signal sample rate, some settings below depends on this one */ - Parameters.SetNewSoundcardSigSampleRate(s.Get("Receiver", "sampleratesig", int(DEFAULT_SOUNDCRD_SAMPLE_RATE))); + Parameters.SetNewSigSampleRate(s.Get("Receiver", "sampleratesig", int(DEFAULT_SOUNDCRD_SAMPLE_RATE))); /* Signal upscale ratio */ Parameters.SetNewSigUpscaleRatio(s.Get("Receiver", "sigupratio", int(1))); diff --git a/src/DrmTransmitter.cpp b/src/DrmTransmitter.cpp index d04ab2dcf..b4bd5545f 100644 --- a/src/DrmTransmitter.cpp +++ b/src/DrmTransmitter.cpp @@ -298,7 +298,7 @@ void CDRMTransmitter::LoadSettings() { s.Get(Transmitter, "samplerateaud", int(DEFAULT_SOUNDCRD_SAMPLE_RATE))); /* Sound card signal sample rate */ - Parameters.SetNewSoundcardSigSampleRate( + Parameters.SetNewSigSampleRate( s.Get(Transmitter, "sampleratesig", int(DEFAULT_SOUNDCRD_SAMPLE_RATE))); /* Fetch new sample rate if any */ diff --git a/src/GUI-QT/SoundCardSelMenu.cpp b/src/GUI-QT/SoundCardSelMenu.cpp index 7dc0d59d5..996225706 100644 --- a/src/GUI-QT/SoundCardSelMenu.cpp +++ b/src/GUI-QT/SoundCardSelMenu.cpp @@ -89,7 +89,7 @@ static const int AudioSampleRateTable[] = static const int SignalSampleRateTable[] = { - -24000, -48000, -96000, -192000, 0 + 24000, 48000, 96000, 192000, 0 }; @@ -100,36 +100,43 @@ static const int SignalSampleRateTable[] = CSoundCardSelMenu::CSoundCardSelMenu(CTRx& ntrx, CFileMenu* pFileMenu, QWidget* parent) : QMenu(parent), trx(ntrx), - menuSigInput(nullptr), menuInputDev(nullptr), - menuInputSampleRate(nullptr),menuOutputSampleRate(nullptr), - menuOutputDev(nullptr), + menuInput(nullptr), menuInputDev(nullptr), menuInputSampleRate(nullptr), + menuOutput(nullptr), menuOutputDev(nullptr), menuOutputSampleRate(nullptr), bReceiver(trx.IsReceiver()) { setTitle(tr("Sound Card")); + const int *inputSampleRates, *outputSampleRates; + + if (bReceiver) { /* Receiver */ + menuInput = addMenu(tr("Signal Input")); + menuOutput = addMenu(tr("Audio Output")); + inputSampleRates = SignalSampleRateTable; + outputSampleRates = AudioSampleRateTable; + } else { + menuInput = addMenu(tr("Audio Input")); + menuOutput = addMenu(tr("Signal Output")); + inputSampleRates = AudioSampleRateTable; + outputSampleRates = SignalSampleRateTable; + } - if (bReceiver) - { /* Receiver */ - menuSigInput = addMenu(tr("Signal Input")); - menuInputDev = menuSigInput->addMenu(tr("Device")); - connect(menuInputDev, SIGNAL(triggered(QAction*)), this, SLOT(OnSoundInDevice(QAction*))); + menuInputDev = menuInput->addMenu(tr("Device")); + menuOutputDev = menuOutput->addMenu(tr("Device")); - QMenu* menuAudOutput = addMenu(tr("Audio Output")); - menuOutputDev = menuAudOutput->addMenu(tr("Device")); + menuInputSampleRate = InitSampleRate(menuInput, tr("Sample Rate"), inputSampleRates); + menuOutputSampleRate = InitSampleRate(menuOutput, tr("Sample Rate"), outputSampleRates); - menuInputChannel = InitChannel(menuSigInput, tr("Channel"), InputChannelTable); - menuOutputChannel = InitChannel(menuAudOutput, tr("Channel"), OutputChannelTable); - menuInputSampleRate = InitSampleRate(menuSigInput, tr("Sample Rate"), SignalSampleRateTable); + if (bReceiver) { /* Receiver */ + menuInputChannel = InitChannel(menuInput, tr("Channel"), InputChannelTable); + menuOutputChannel = InitChannel(menuOutput, tr("Channel"), OutputChannelTable); connect(menuInputChannel, SIGNAL(triggered(QAction*)), this, SLOT(OnSoundInChannel(QAction*))); connect(menuOutputChannel, SIGNAL(triggered(QAction*)), this, SLOT(OnSoundOutChannel(QAction*))); - connect(menuInputSampleRate, SIGNAL(triggered(QAction*)), this, SLOT(OnSoundSampleRate(QAction*))); - menuOutputSampleRate = InitSampleRate(menuAudOutput, tr("Sample Rate"), AudioSampleRateTable); - connect(menuOutputSampleRate, SIGNAL(triggered(QAction*)), this, SLOT(OnSoundSampleRate(QAction*))); - actionUpscale = menuSigInput->addAction(tr("2:1 upscale")); + actionUpscale = menuInput->addAction(tr("2:1 upscale")); connect(actionUpscale, SIGNAL(toggled(bool)), this, SLOT(OnSoundSignalUpscale(bool))); connect(this, SIGNAL(soundInDeviceChanged(QString)), &trx, SLOT(SetInputDevice(QString))); - connect(this, SIGNAL(soundSampleRateChanged(int)), &trx, SLOT(onSoundSampleRateChanged(int))); + connect(this, SIGNAL(soundInSampleRateChanged(int)), &trx, SLOT(onInSoundSampleRateChanged(int))); + connect(this, SIGNAL(soundOutSampleRateChanged(int)), &trx, SLOT(onOutSoundSampleRateChanged(int))); connect(this, SIGNAL(soundInDeviceChanged(QString)), &trx, SLOT(SetInputDevice(QString))); connect(this, SIGNAL(soundInChannelChanged(int)), &trx, SLOT(onSoundInChannelChanged(int))); connect(this, SIGNAL(soundOutChannelChanged(EOutChanSel)), &trx, SLOT(onSoundOutChannelChanged(EOutChanSel))); @@ -144,27 +151,24 @@ CSoundCardSelMenu::CSoundCardSelMenu(CTRx& ntrx, connect(&trx, SIGNAL(outputSampleRateChanged(int)), this, SLOT(OnSoundOutSampleRateChanged(int))); connect(&trx, SIGNAL(soundUpscaleRatioChanged(int)), this, SLOT(OnSoundUpscaleRatioChanged(int))); - - if (pFileMenu != nullptr) { - connect(pFileMenu, SIGNAL(soundFileChanged(QString)), this, SLOT(OnSoundFileChanged(QString))); - } } - else - { /* Transmitter */ - QMenu* menuAudio = addMenu(tr("Audio Input")); - menuInputDev = menuAudio->addMenu(tr("Device")); - connect(menuInputDev, SIGNAL(triggered(QAction*)), this, SLOT(OnSoundInDevice(QAction*))); - QMenu* menuSignal = addMenu(tr("Signal Output")); - menuOutputDev = menuSignal->addMenu(tr("Device")); - - connect(InitSampleRate(menuAudio, tr("Sample Rate"), AudioSampleRateTable), SIGNAL(triggered(QAction*)), this, SLOT(OnSoundSampleRate(QAction*))); - connect(InitSampleRate(menuSignal, tr("Sample Rate"), SignalSampleRateTable), SIGNAL(triggered(QAction*)), this, SLOT(OnSoundSampleRate(QAction*))); + if (pFileMenu != nullptr) { + connect(pFileMenu, SIGNAL(soundFileChanged(QString)), this, SLOT(OnSoundFileChanged(QString))); } + connect(menuInputDev, SIGNAL(triggered(QAction*)), this, SLOT(OnSoundInDevice(QAction*))); + connect(menuOutputDev, SIGNAL(triggered(QAction*)), this, SLOT(OnSoundOutDevice(QAction*))); + + connect(this, SIGNAL(soundInDeviceChanged(QString)), &trx, SLOT(SetInputDevice(QString))); connect(this, SIGNAL(soundOutDeviceChanged(QString)), &trx, SLOT(SetOutputDevice(QString))); + + connect(&trx, SIGNAL(InputDeviceChanged(QString)), this, SLOT(OnSoundInDeviceChanged(QString))); connect(&trx, SIGNAL(OutputDeviceChanged(QString)), this, SLOT(OnSoundOutDeviceChanged(QString))); + + connect(menuInputSampleRate, SIGNAL(triggered(QAction*)), this, SLOT(OnSoundInSampleRate(QAction*))); + connect(menuOutputSampleRate, SIGNAL(triggered(QAction*)), this, SLOT(OnSoundOutSampleRate(QAction*))); } void CSoundCardSelMenu::OnSoundInDevice(QAction* action) @@ -189,9 +193,14 @@ void CSoundCardSelMenu::OnSoundOutChannel(QAction* action) emit soundOutChannelChanged(EOutChanSel(action->data().toInt())); } -void CSoundCardSelMenu::OnSoundSampleRate(QAction* action) +void CSoundCardSelMenu::OnSoundInSampleRate(QAction* action) +{ + emit soundInSampleRateChanged(EOutChanSel(action->data().toInt())); +} + +void CSoundCardSelMenu::OnSoundOutSampleRate(QAction* action) { - emit soundSampleRateChanged(EOutChanSel(action->data().toInt())); + emit soundOutSampleRateChanged(EOutChanSel(action->data().toInt())); } void CSoundCardSelMenu::OnSoundSignalUpscale(bool bChecked) @@ -335,7 +344,7 @@ void CSoundCardSelMenu::OnSoundUpscaleRatioChanged(int upscaleRatio) void CSoundCardSelMenu::OnSoundFileChanged(QString filename) { if(filename == "") { - menuSigInput->setEnabled(true); + menuInput->setEnabled(true); menuInputDev->setEnabled(true); menuInputSampleRate->setEnabled(true); } @@ -343,7 +352,7 @@ void CSoundCardSelMenu::OnSoundFileChanged(QString filename) FileTyper::type t = FileTyper::resolve(filename.toStdString()); switch(t) { case FileTyper::unrecognised: - menuSigInput->setEnabled(true); + menuInput->setEnabled(true); menuInputDev->setEnabled(true); menuInputSampleRate->setEnabled(true); break; @@ -352,7 +361,7 @@ void CSoundCardSelMenu::OnSoundFileChanged(QString filename) case FileTyper::raw_af: case FileTyper::raw_pft: case FileTyper::pcm: - // menuSigInput->setEnabled(false); + // menuInput->setEnabled(false); // menuInputDev->setEnabled(false); menuInputSampleRate->setEnabled(false); } diff --git a/src/GUI-QT/SoundCardSelMenu.h b/src/GUI-QT/SoundCardSelMenu.h index c3d17e9d9..b12ec4dda 100644 --- a/src/GUI-QT/SoundCardSelMenu.h +++ b/src/GUI-QT/SoundCardSelMenu.h @@ -55,15 +55,16 @@ class CSoundCardSelMenu : public QMenu protected: CTRx& trx; - QMenu* menuSigInput; - QMenu* menuInputDev; - QMenu* menuInputSampleRate; - QMenu* menuOutputSampleRate; - QMenu* menuOutputDev; + QMenu* menuInput; + QMenu* menuInputDev; + QMenu* menuInputSampleRate; QMenu* menuInputChannel; + QMenu* menuOutput; + QMenu* menuOutputDev; + QMenu* menuOutputSampleRate; QMenu* menuOutputChannel; - const bool bReceiver; + const bool bReceiver; QAction* actionUpscale; QMenu* InitChannel(QMenu* parent, const QString& text, const CHANSEL* ChanSel); @@ -76,7 +77,8 @@ public slots: void OnSoundOutChannel(QAction*); void OnSoundInDevice(QAction*); void OnSoundOutDevice(QAction*); - void OnSoundSampleRate(QAction*); + void OnSoundInSampleRate(QAction*); + void OnSoundOutSampleRate(QAction*); void OnSoundSignalUpscale(bool); void OnSoundFileChanged(QString); // slots connected to signals from receiver @@ -89,7 +91,8 @@ public slots: void OnSoundOutChannelChanged(int chan); signals: - void soundSampleRateChanged(int); + void soundInSampleRateChanged(int); + void soundOutSampleRateChanged(int); void soundInDeviceChanged(QString); void soundOutDeviceChanged(QString); void soundInChannelChanged(int); diff --git a/src/GUI-QT/TransmDlg.cpp b/src/GUI-QT/TransmDlg.cpp index 3087caef7..b586bc01f 100644 --- a/src/GUI-QT/TransmDlg.cpp +++ b/src/GUI-QT/TransmDlg.cpp @@ -54,9 +54,6 @@ TransmDialog::TransmDialog(CTx& ntx, QWidget* parent) ProgrInputLevel->setScalePosition(QwtThermo::LeadingScale); #endif - /* Load transmitter settings */ - tx.LoadSettings(); - /* Set help text for the controls */ AddWhatsThisHelp(); diff --git a/src/Parameter.h b/src/Parameter.h index 06562a21c..286f65412 100644 --- a/src/Parameter.h +++ b/src/Parameter.h @@ -948,7 +948,7 @@ class CParameter sr = (sr + 12) / 25 * 25; // <- ok for DRM mode iNewAudSampleRate = sr; } - void SetNewSoundcardSigSampleRate(int sr) + void SetNewSigSampleRate(int sr) { /* Set to the nearest supported sample rate */ if (sr < 36000) sr = 24000; diff --git a/src/main-Qt/crx.cpp b/src/main-Qt/crx.cpp index abbabc492..47f78c2af 100644 --- a/src/main-Qt/crx.cpp +++ b/src/main-Qt/crx.cpp @@ -513,7 +513,14 @@ void CRx::onSoundOutChannelChanged(EOutChanSel e) emit OutputChannelChanged(int(e)); } -void CRx::onSoundSampleRateChanged(int n) +void CRx::onInSoundSampleRateChanged(int n) +{ + rx.GetParameters()->SetNewSigSampleRate(n); + Restart(); + emit inputSampleRateChanged(n); +} + +void CRx::onOutSoundSampleRateChanged(int n) { rx.GetParameters()->SetNewAudSampleRate(n); Restart(); diff --git a/src/main-Qt/crx.h b/src/main-Qt/crx.h index 21552453d..e646ae079 100644 --- a/src/main-Qt/crx.h +++ b/src/main-Qt/crx.h @@ -108,7 +108,8 @@ public slots: virtual void EnableAutoFrequenctAcquisition(bool); virtual void onSoundInChannelChanged(int); virtual void onSoundOutChannelChanged(EOutChanSel); - virtual void onSoundSampleRateChanged(int); + virtual void onInSoundSampleRateChanged(int); + virtual void onOutSoundSampleRateChanged(int); virtual void SetSoundSignalUpscale(int) override; private: