Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent creation of filters if not enabled. #631

Merged
merged 16 commits into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions USER_MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,7 @@ LDPC | Low Density Parity Check Codes - a family of powerful FEC codes
* Improve validation of frequencies in Options dialog. (PR #628)
* Fix typo resulting in TX device sample rate being used for filter initialization. (PR #630)
* Fix intermittent crash resulting from object thread starting before object is fully initialized. (PR #630)
* Prevent creation of filters if not enabled. (PR #631)
2. Enhancements:
* Allow user to refresh status message even if it hasn't been changed. (PR #632)
* Increase priority of status message highlight. (PR #632)
Expand Down
15 changes: 11 additions & 4 deletions src/dlg_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@

extern FreeDVInterface freedvInterface;
extern wxConfigBase *pConfig;
extern wxMutex g_mutexProtectingCallbackData;

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=
// Class FilterDlg
Expand Down Expand Up @@ -743,14 +744,10 @@ void FilterDlg::updateControlState()
}

void FilterDlg::OnMicInEnable(wxScrollEvent& event) {
wxGetApp().appConfiguration.filterConfiguration.micInChannel.eqEnable = m_MicInEnable->GetValue();
updateControlState();
adjRunTimeMicInFilter();
}

void FilterDlg::OnSpkOutEnable(wxScrollEvent& event) {
wxGetApp().appConfiguration.filterConfiguration.spkOutChannel.eqEnable = m_SpkOutEnable->GetValue();
updateControlState();
adjRunTimeSpkOutFilter();
}

Expand Down Expand Up @@ -847,19 +844,29 @@ void FilterDlg::plotSpkOutFilterSpectrum(void) {
void FilterDlg::adjRunTimeMicInFilter(void) {
// signal an adjustment in running filter coeffs

g_mutexProtectingCallbackData.Lock();
ExchangeData(EXCHANGE_DATA_OUT);
if (m_running) {
*m_newMicInFilter = true;
}
wxGetApp().appConfiguration.filterConfiguration.micInChannel.eqEnable = m_MicInEnable->GetValue();
g_mutexProtectingCallbackData.Unlock();

updateControlState();
}

void FilterDlg::adjRunTimeSpkOutFilter(void) {
// signal an adjustment in running filter coeffs

g_mutexProtectingCallbackData.Lock();
ExchangeData(EXCHANGE_DATA_OUT);
if (m_running) {
*m_newSpkOutFilter = true;
}
wxGetApp().appConfiguration.filterConfiguration.spkOutChannel.eqEnable = m_SpkOutEnable->GetValue();
g_mutexProtectingCallbackData.Unlock();

updateControlState();
}


Expand Down
52 changes: 38 additions & 14 deletions src/eq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void *MainFrame::designAnEQFilter(const char filterType[], float freqHz, float g
void MainFrame::designEQFilters(paCallBackData *cb, int rxSampleRate, int txSampleRate)
{
// init Mic In Equaliser Filters
if (m_newMicInFilter) {
if (cb->micInEQEnable) {
assert(cb->sbqMicInBass == nullptr && cb->sbqMicInTreble == nullptr && cb->sbqMicInMid == nullptr);
//printf("designing new Min In filters\n");
cb->sbqMicInBass = designAnEQFilter("bass", wxGetApp().appConfiguration.filterConfiguration.micInChannel.bassFreqHz, wxGetApp().appConfiguration.filterConfiguration.micInChannel.bassGaindB, txSampleRate);
Expand All @@ -73,7 +73,7 @@ void MainFrame::designEQFilters(paCallBackData *cb, int rxSampleRate, int txSam

// init Spk Out Equaliser Filters

if (m_newSpkOutFilter) {
if (cb->spkOutEQEnable) {
assert(cb->sbqSpkOutBass == nullptr && cb->sbqSpkOutTreble == nullptr && cb->sbqSpkOutMid == nullptr);
//printf("designing new Spk Out filters\n");
//printf("designEQFilters: wxGetApp().appConfiguration.filterConfiguration.spkOutChannel.bassFreqHz: %f\n",wxGetApp().appConfiguration.filterConfiguration.spkOutChannel.bassFreqHz);
Expand All @@ -94,13 +94,25 @@ void MainFrame::deleteEQFilters(paCallBackData *cb)
{
if (m_newMicInFilter)
{
assert(cb->sbqMicInBass != nullptr && cb->sbqMicInTreble != nullptr && cb->sbqMicInMid != nullptr);
if (cb->sbqMicInBass != nullptr)
{
sox_biquad_destroy(cb->sbqMicInBass);
}

if (cb->sbqMicInTreble != nullptr)
{
sox_biquad_destroy(cb->sbqMicInTreble);
}

sox_biquad_destroy(cb->sbqMicInBass);
sox_biquad_destroy(cb->sbqMicInTreble);
sox_biquad_destroy(cb->sbqMicInMid);
if (cb->sbqMicInMid != nullptr)
{
sox_biquad_destroy(cb->sbqMicInMid);
}

if (cb->sbqMicInVol) sox_biquad_destroy(cb->sbqMicInVol);
if (cb->sbqMicInVol != nullptr)
{
sox_biquad_destroy(cb->sbqMicInVol);
}

cb->sbqMicInBass = nullptr;
cb->sbqMicInTreble = nullptr;
Expand All @@ -109,14 +121,26 @@ void MainFrame::deleteEQFilters(paCallBackData *cb)
}

if (m_newSpkOutFilter)
{
assert(cb->sbqSpkOutBass != nullptr && cb->sbqSpkOutTreble != nullptr && cb->sbqSpkOutMid != nullptr);

sox_biquad_destroy(cb->sbqSpkOutBass);
sox_biquad_destroy(cb->sbqSpkOutTreble);
sox_biquad_destroy(cb->sbqSpkOutMid);
{
if (cb->sbqSpkOutBass != nullptr)
{
sox_biquad_destroy(cb->sbqSpkOutBass);
}

if (cb->sbqSpkOutTreble != nullptr)
{
sox_biquad_destroy(cb->sbqSpkOutTreble);
}

if (cb->sbqSpkOutMid != nullptr)
{
sox_biquad_destroy(cb->sbqSpkOutMid);
}

if (cb->sbqSpkOutVol) sox_biquad_destroy(cb->sbqSpkOutVol);
if (cb->sbqSpkOutVol != nullptr)
{
sox_biquad_destroy(cb->sbqSpkOutVol);
}

cb->sbqSpkOutBass = nullptr;
cb->sbqSpkOutTreble = nullptr;
Expand Down
62 changes: 48 additions & 14 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1493,26 +1493,39 @@ void MainFrame::OnTimer(wxTimerEvent &evt)

// Run time update of EQ filters -----------------------------------

if (m_newMicInFilter || m_newSpkOutFilter) {
g_mutexProtectingCallbackData.Lock();
g_mutexProtectingCallbackData.Lock();

bool micEqEnableOld = g_rxUserdata->micInEQEnable;
bool spkrEqEnableOld = g_rxUserdata->spkOutEQEnable;

if (m_newMicInFilter || m_newSpkOutFilter ||
micEqEnableOld != wxGetApp().appConfiguration.filterConfiguration.micInChannel.eqEnable ||
spkrEqEnableOld != wxGetApp().appConfiguration.filterConfiguration.spkOutChannel.eqEnable) {

deleteEQFilters(g_rxUserdata);

if (g_nSoundCards == 1)
g_rxUserdata->micInEQEnable = wxGetApp().appConfiguration.filterConfiguration.micInChannel.eqEnable;
g_rxUserdata->spkOutEQEnable = wxGetApp().appConfiguration.filterConfiguration.spkOutChannel.eqEnable;

if (
wxGetApp().appConfiguration.filterConfiguration.micInChannel.eqEnable ||
wxGetApp().appConfiguration.filterConfiguration.spkOutChannel.eqEnable)
{
// RX In isn't used here but we need to provide it anyway.
designEQFilters(g_rxUserdata, wxGetApp().appConfiguration.audioConfiguration.soundCard1Out.sampleRate, wxGetApp().appConfiguration.audioConfiguration.soundCard1In.sampleRate);
}
else
{
designEQFilters(g_rxUserdata, wxGetApp().appConfiguration.audioConfiguration.soundCard2Out.sampleRate, wxGetApp().appConfiguration.audioConfiguration.soundCard2In.sampleRate);
if (g_nSoundCards == 1)
{
// RX In isn't used here but we need to provide it anyway.
designEQFilters(g_rxUserdata, wxGetApp().appConfiguration.audioConfiguration.soundCard1Out.sampleRate, wxGetApp().appConfiguration.audioConfiguration.soundCard1In.sampleRate);
}
else
{
designEQFilters(g_rxUserdata, wxGetApp().appConfiguration.audioConfiguration.soundCard2Out.sampleRate, wxGetApp().appConfiguration.audioConfiguration.soundCard2In.sampleRate);
}
}
g_mutexProtectingCallbackData.Unlock();

m_newMicInFilter = m_newSpkOutFilter = false;
}
g_mutexProtectingCallbackData.Unlock();

g_rxUserdata->micInEQEnable = wxGetApp().appConfiguration.filterConfiguration.micInChannel.eqEnable;
g_rxUserdata->spkOutEQEnable = wxGetApp().appConfiguration.filterConfiguration.spkOutChannel.eqEnable;

// set some run time options (if applicable)
freedvInterface.setRunTimeOptions(
(int)wxGetApp().appConfiguration.freedv700Clip,
Expand Down Expand Up @@ -2639,9 +2652,20 @@ void MainFrame::startRxStream()

m_newMicInFilter = m_newSpkOutFilter = true;
g_mutexProtectingCallbackData.Lock();
designEQFilters(g_rxUserdata, wxGetApp().appConfiguration.audioConfiguration.soundCard2Out.sampleRate, wxGetApp().appConfiguration.audioConfiguration.soundCard2In.sampleRate);

g_rxUserdata->micInEQEnable = wxGetApp().appConfiguration.filterConfiguration.micInChannel.eqEnable;
g_rxUserdata->spkOutEQEnable = wxGetApp().appConfiguration.filterConfiguration.spkOutChannel.eqEnable;

if (
wxGetApp().appConfiguration.filterConfiguration.micInChannel.eqEnable ||
wxGetApp().appConfiguration.filterConfiguration.spkOutChannel.eqEnable)
{
designEQFilters(
g_rxUserdata,
wxGetApp().appConfiguration.audioConfiguration.soundCard2Out.sampleRate,
wxGetApp().appConfiguration.audioConfiguration.soundCard2In.sampleRate);
}

m_newMicInFilter = m_newSpkOutFilter = false;
g_mutexProtectingCallbackData.Unlock();

Expand Down Expand Up @@ -2884,6 +2908,16 @@ void MainFrame::startRxStream()
}

if (g_verbose) fprintf(stderr, "starting tx/rx processing thread\n");

// Work around an issue where the buttons stay disabled even if there
// is an error opening one or more audio device(s).
bool txDevicesRunning =
(!txInSoundDevice || txInSoundDevice->isRunning()) &&
(!txOutSoundDevice || txOutSoundDevice->isRunning());
bool rxDevicesRunning =
(rxInSoundDevice && rxInSoundDevice->isRunning()) &&
(rxOutSoundDevice && rxOutSoundDevice->isRunning());
m_RxRunning = txDevicesRunning && rxDevicesRunning;
}
}

Expand Down
23 changes: 13 additions & 10 deletions src/pipeline/EqualizerStep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,12 @@
//
//=========================================================================


#include "EqualizerStep.h"

#include <cstring>
#include "../sox_biquad.h"
#include <assert.h>

// TBD -- use std::mutex instead of wxMutex to remove wxWidgets dependency.
#include <wx/wx.h>
extern wxMutex g_mutexProtectingCallbackData;

EqualizerStep::EqualizerStep(int sampleRate, bool* enableFilter, void** bassFilter, void** midFilter, void** trebleFilter, void** volFilter)
: sampleRate_(sampleRate)
, enableFilter_(enableFilter)
Expand Down Expand Up @@ -63,18 +59,25 @@ std::shared_ptr<short> EqualizerStep::execute(std::shared_ptr<short> inputSample

memcpy(outputSamples, inputSamples.get(), sizeof(short)*numInputSamples);

g_mutexProtectingCallbackData.Lock();
if (*enableFilter_)
{
sox_biquad_filter(*bassFilter_, outputSamples, outputSamples, numInputSamples);
sox_biquad_filter(*trebleFilter_, outputSamples, outputSamples, numInputSamples);
sox_biquad_filter(*midFilter_, outputSamples, outputSamples, numInputSamples);
if (*bassFilter_)
{
sox_biquad_filter(*bassFilter_, outputSamples, outputSamples, numInputSamples);
}
if (*trebleFilter_)
{
sox_biquad_filter(*trebleFilter_, outputSamples, outputSamples, numInputSamples);
}
if (*midFilter_)
{
sox_biquad_filter(*midFilter_, outputSamples, outputSamples, numInputSamples);
}
if (*volFilter_)
{
sox_biquad_filter(*volFilter_, outputSamples, outputSamples, numInputSamples);
}
}
g_mutexProtectingCallbackData.Unlock();

*numOutputSamples = numInputSamples;
return std::shared_ptr<short>(outputSamples, std::default_delete<short[]>());
Expand Down
6 changes: 4 additions & 2 deletions src/pipeline/TxRxThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ void TxRxThread::initializePipeline_()
&g_rxUserdata->sbqMicInMid,
&g_rxUserdata->sbqMicInTreble,
&g_rxUserdata->sbqMicInVol);
pipeline_->appendPipelineStep(std::shared_ptr<IPipelineStep>(equalizerStep));
auto equalizerLockStep = new ExclusiveAccessStep(equalizerStep, callbackLockFn, callbackUnlockFn);
pipeline_->appendPipelineStep(std::shared_ptr<IPipelineStep>(equalizerLockStep));

// Take TX audio post-equalizer and send it to RX for possible monitoring use.
if (equalizedMicAudioLink_ != nullptr)
Expand Down Expand Up @@ -426,7 +427,8 @@ void TxRxThread::initializePipeline_()
&g_rxUserdata->sbqSpkOutMid,
&g_rxUserdata->sbqSpkOutTreble,
&g_rxUserdata->sbqSpkOutVol);
pipeline_->appendPipelineStep(std::shared_ptr<IPipelineStep>(equalizerStep));
auto equalizerLockStep = new ExclusiveAccessStep(equalizerStep, callbackLockFn, callbackUnlockFn);
pipeline_->appendPipelineStep(std::shared_ptr<IPipelineStep>(equalizerLockStep));

// Resample for plot step (speech out)
auto resampleForPlotOutStep = new ResampleForPlotStep(g_plotSpeechOutFifo);
Expand Down
Loading