Use std::atomic for PlaybackStep.
parent
664fd2a898
commit
0ee65a38eb
13
src/main.cpp
13
src/main.cpp
|
|
@ -149,7 +149,7 @@ int g_AEstatus2[4];
|
|||
|
||||
// playing and recording from sound files
|
||||
|
||||
extern SNDFILE *g_sfPlayFile;
|
||||
extern std::atomic<SNDFILE*> g_sfPlayFile;
|
||||
extern bool g_playFileToMicIn;
|
||||
extern bool g_loopPlayFileToMicIn;
|
||||
extern int g_playFileToMicInEventId;
|
||||
|
|
@ -358,8 +358,8 @@ void MainApp::UnitTest_()
|
|||
// Transmit until file has finished playing
|
||||
SF_INFO sfInfo;
|
||||
sfInfo.format = 0;
|
||||
g_sfPlayFile = sf_open((const char*)utTxFile.ToUTF8(), SFM_READ, &sfInfo);
|
||||
g_sfTxFs = sfInfo.samplerate;
|
||||
g_sfPlayFile.store(sf_open((const char*)utTxFile.ToUTF8(), SFM_READ, &sfInfo), std::memory_order_release);
|
||||
g_loopPlayFileToMicIn = false;
|
||||
g_playFileToMicIn = true;
|
||||
|
||||
|
|
@ -1150,7 +1150,7 @@ MainFrame::MainFrame(wxWindow *parent) : TopFrame(parent, wxID_ANY, _("FreeDV ")
|
|||
Connect(wxEVT_IDLE, wxIdleEventHandler(MainFrame::OnIdle), NULL, this);
|
||||
#endif //_USE_ONIDLE
|
||||
|
||||
g_sfPlayFile = NULL;
|
||||
g_sfPlayFile.store(nullptr, std::memory_order_release);
|
||||
g_playFileToMicIn = false;
|
||||
g_loopPlayFileToMicIn = false;
|
||||
|
||||
|
|
@ -1339,10 +1339,11 @@ MainFrame::~MainFrame()
|
|||
}
|
||||
sox_biquad_finish();
|
||||
|
||||
if (g_sfPlayFile != NULL)
|
||||
auto tmpPlayFile = g_sfPlayFile.load(std::memory_order_acquire);
|
||||
if (tmpPlayFile != NULL)
|
||||
{
|
||||
sf_close(g_sfPlayFile);
|
||||
g_sfPlayFile = NULL;
|
||||
sf_close(tmpPlayFile);
|
||||
g_sfPlayFile.store(nullptr, std::memory_order_release);
|
||||
}
|
||||
if (g_sfRecFile != NULL)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ void PlaybackStep::nonRtThreadEntry_()
|
|||
playbackResampler_->getInputSampleRate() != fileSampleRate ||
|
||||
playbackResampler_->getOutputSampleRate() != getInputSampleRate()))
|
||||
{
|
||||
//log_info("Create SR (in = %d, out = %d)", fileSampleRate, inputSampleRate_);
|
||||
log_info("Create SR (in = %d, out = %d)", fileSampleRate, inputSampleRate_);
|
||||
if (playbackResampler_ != nullptr)
|
||||
{
|
||||
delete playbackResampler_;
|
||||
|
|
@ -163,7 +163,7 @@ void PlaybackStep::nonRtThreadEntry_()
|
|||
|
||||
if ((int)numRead == 0 && outputFifo_.numUsed() == 0)
|
||||
{
|
||||
//log_info("file read complete");
|
||||
log_info("file read complete");
|
||||
buf = nullptr;
|
||||
fileCompleteFn_();
|
||||
readComplete = true;
|
||||
|
|
@ -172,11 +172,12 @@ void PlaybackStep::nonRtThreadEntry_()
|
|||
}
|
||||
else if (playFile != oldPlayFile)
|
||||
{
|
||||
log_info("Resetting read for next round");
|
||||
readComplete = false;
|
||||
}
|
||||
oldPlayFile = playFile;
|
||||
g_mutexProtectingCallbackData.Unlock();
|
||||
|
||||
oldPlayFile = playFile;
|
||||
fileIoThreadSem_.wait();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ extern FreeDVInterface freedvInterface;
|
|||
extern wxWindow* g_parent;
|
||||
|
||||
#include <sndfile.h>
|
||||
extern SNDFILE* g_sfPlayFile;
|
||||
extern std::atomic<SNDFILE*> g_sfPlayFile;
|
||||
extern SNDFILE* g_sfRecFileFromModulator;
|
||||
extern SNDFILE* g_sfRecFile;
|
||||
extern SNDFILE* g_sfRecMicFile;
|
||||
|
|
@ -166,10 +166,10 @@ void TxRxThread::initializePipeline_()
|
|||
auto playMicIn = new PlaybackStep(
|
||||
inputSampleRate_,
|
||||
[]() { return g_sfTxFs; },
|
||||
[]() { return g_sfPlayFile; },
|
||||
[]() { return g_sfPlayFile.load(std::memory_order_acquire); },
|
||||
[]() {
|
||||
if (g_loopPlayFileToMicIn)
|
||||
sf_seek(g_sfPlayFile, 0, SEEK_SET);
|
||||
sf_seek(g_sfPlayFile.load(std::memory_order_acquire), 0, SEEK_SET);
|
||||
else {
|
||||
log_info("playFileFromRadio finished, issuing event!");
|
||||
g_parent->CallAfter(&MainFrame::StopPlayFileToMicIn);
|
||||
|
|
|
|||
|
|
@ -5,10 +5,11 @@
|
|||
Playing and recording files.
|
||||
*/
|
||||
|
||||
#include <atomic>
|
||||
#include "main.h"
|
||||
|
||||
extern wxMutex g_mutexProtectingCallbackData;
|
||||
SNDFILE *g_sfPlayFile;
|
||||
std::atomic<SNDFILE*> g_sfPlayFile;
|
||||
bool g_playFileToMicIn;
|
||||
bool g_loopPlayFileToMicIn;
|
||||
int g_playFileToMicInEventId;
|
||||
|
|
@ -59,9 +60,11 @@ void MainFrame::StopPlayFileToMicIn(void)
|
|||
g_mutexProtectingCallbackData.Lock();
|
||||
if (g_playFileToMicIn)
|
||||
{
|
||||
auto tmpPlayFile = g_sfPlayFile.load(std::memory_order_acquire);
|
||||
g_sfPlayFile.store(nullptr, std::memory_order_release);
|
||||
|
||||
g_playFileToMicIn = false;
|
||||
sf_close(g_sfPlayFile);
|
||||
g_sfPlayFile = nullptr;
|
||||
sf_close(tmpPlayFile);
|
||||
SetStatusText(wxT(""));
|
||||
VoiceKeyerProcessEvent(VK_PLAY_FINISHED);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -200,7 +200,7 @@ void MainFrame::OnSetMonitorVKAudioVol( wxCommandEvent& event )
|
|||
popup->Popup();
|
||||
}
|
||||
|
||||
extern SNDFILE *g_sfPlayFile;
|
||||
extern std::atomic<SNDFILE*> g_sfPlayFile;
|
||||
extern bool g_playFileToMicIn;
|
||||
extern bool g_loopPlayFileToMicIn;
|
||||
extern FreeDVInterface freedvInterface;
|
||||
|
|
@ -235,7 +235,7 @@ int MainFrame::VoiceKeyerStartTx(void)
|
|||
return VK_IDLE;
|
||||
}
|
||||
|
||||
g_sfPlayFile = tmpPlayFile;
|
||||
g_sfPlayFile.store(tmpPlayFile, std::memory_order_release);
|
||||
|
||||
SetStatusText(wxT("Voice Keyer: Playing file ") + wxString::FromUTF8(vkFileName_.c_str()) + wxT(" to mic input") , 0);
|
||||
g_loopPlayFileToMicIn = false;
|
||||
|
|
|
|||
Loading…
Reference in New Issue