Cleanup / Reformat

This commit is contained in:
Charles J. Cliffe 2014-11-22 22:33:32 -05:00
parent 58708a720e
commit 39ba38b82a
10 changed files with 353 additions and 395 deletions

View File

@ -61,9 +61,9 @@ AppFrame::AppFrame() :
audioInputQueue = new AudioThreadInputQueue;
audioThread = new AudioThread(audioInputQueue);
t1 = new std::thread(&AudioThread::threadMain, audioThread);
threadAudio = new std::thread(&AudioThread::threadMain, audioThread);
demodulatorTest = demodMgr.newThread(this);
demodulatorTest = demodMgr.newThread();
demodulatorTest->params.audioInputQueue = audioInputQueue;
demodulatorTest->init();
@ -77,7 +77,7 @@ AppFrame::AppFrame() :
iqVisualQueue = new SDRThreadIQDataQueue;
sdrThread->setIQVisualQueue(iqVisualQueue);
t_SDR = new std::thread(&SDRThread::threadMain, sdrThread);
threadSDR = new std::thread(&SDRThread::threadMain, sdrThread);
// static const int attribs[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, 0 };
// wxLogStatus("Double-buffered display %s supported", wxGLCanvas::IsDisplaySupported(attribs) ? "is" : "not");

View File

@ -19,7 +19,6 @@ public:
void OnThread(wxCommandEvent& event);
void OnEventInput(wxThreadEvent& event);
void setFrequency(unsigned int freq);
int getFrequency();
@ -47,8 +46,8 @@ private:
SDRThreadIQDataQueue* iqVisualQueue;
DemodulatorThreadOutputQueue* audioVisualQueue;
std::thread *t1;
std::thread *t_SDR;
std::thread *threadAudio;
std::thread *threadSDR;
// event table
wxDECLARE_EVENT_TABLE();

View File

@ -44,6 +44,20 @@ static int audioCallback(const void *inputBuffer, void *outputBuffer, unsigned l
return paContinue;
}
AudioThread::AudioThread(AudioThreadInputQueue *inputQueue) :
inputQueue(inputQueue), stream(NULL), audio_queue_ptr(0) {
}
AudioThread::~AudioThread() {
PaError err;
err = Pa_StopStream(stream);
err = Pa_CloseStream(stream);
Pa_Terminate();
std::cout << std::endl << "Audio Thread Done." << std::endl << std::endl;
}
void AudioThread::threadMain() {
PaError err;
err = Pa_Initialize();

View File

@ -33,19 +33,9 @@ public:
std::queue<std::vector<float> > audio_queue;
unsigned int audio_queue_ptr;
AudioThread(AudioThreadInputQueue *inputQueue) :
inputQueue(inputQueue), stream(NULL), audio_queue_ptr(0) {
AudioThread(AudioThreadInputQueue *inputQueue);
}
~AudioThread() {
PaError err;
err = Pa_StopStream(stream);
err = Pa_CloseStream(stream);
Pa_Terminate();
std::cout << std::endl << "Audio Thread Done." << std::endl << std::endl;
}
~AudioThread();
void threadMain();

View File

@ -0,0 +1,40 @@
#include <DemodulatorMgr.h>
DemodulatorInstance::DemodulatorInstance() :
t_Demod(NULL), threadQueueDemod(NULL), demodulatorThread(NULL) {
}
void DemodulatorInstance::setVisualOutputQueue(DemodulatorThreadOutputQueue *tQueue) {
demodulatorThread->setVisualOutputQueue(tQueue);
}
void DemodulatorInstance::init() {
if (threadQueueDemod) {
delete threadQueueDemod;
}
if (demodulatorThread) {
delete demodulatorThread;
}
threadQueueDemod = new DemodulatorThreadInputQueue;
demodulatorThread = new DemodulatorThread(threadQueueDemod, &params);
t_Demod = new std::thread(&DemodulatorThread::threadMain, demodulatorThread);
}
DemodulatorMgr::DemodulatorMgr() {
}
DemodulatorMgr::~DemodulatorMgr() {
while (demods.size()) {
DemodulatorInstance *d = demods.back();
demods.pop_back();
delete d;
}
}
DemodulatorInstance *DemodulatorMgr::newThread() {
DemodulatorInstance *newDemod = new DemodulatorInstance;
demods.push_back(newDemod);
return newDemod;
}

View File

@ -13,48 +13,18 @@ public:
DemodulatorThreadInputQueue* threadQueueDemod;
DemodulatorThreadParameters params;
DemodulatorInstance() :
t_Demod(NULL), threadQueueDemod(NULL), demodulatorThread(NULL) {
}
void setVisualOutputQueue(DemodulatorThreadOutputQueue *tQueue) {
demodulatorThread->setVisualOutputQueue(tQueue);
}
void init() {
if (threadQueueDemod) {
delete threadQueueDemod;
}
if (demodulatorThread) {
delete demodulatorThread;
}
threadQueueDemod = new DemodulatorThreadInputQueue;
demodulatorThread = new DemodulatorThread(threadQueueDemod, &params);
t_Demod = new std::thread(&DemodulatorThread::threadMain, demodulatorThread);
}
DemodulatorInstance();
void setVisualOutputQueue(DemodulatorThreadOutputQueue *tQueue);
void init();
};
class DemodulatorMgr {
public:
DemodulatorMgr() {
DemodulatorMgr();
~DemodulatorMgr();
}
~DemodulatorMgr() {
while (demods.size()) {
DemodulatorInstance *d = demods.back();
demods.pop_back();
delete d;
}
}
DemodulatorInstance *newThread(wxEvtHandler* pParent) {
DemodulatorInstance *newDemod = new DemodulatorInstance;
demods.push_back(newDemod);
return newDemod;
}
DemodulatorInstance *newThread();
private:
std::vector<DemodulatorInstance *> demods;
};

View File

@ -3,7 +3,7 @@
#include <vector>
DemodulatorThread::DemodulatorThread(DemodulatorThreadInputQueue* pQueue, DemodulatorThreadParameters *params_in) :
m_pQueue(pQueue), visOutQueue(NULL) {
inputQueue(pQueue), visOutQueue(NULL) {
DemodulatorThreadParameters defaultParams;
if (!params_in) {
@ -57,7 +57,7 @@ void DemodulatorThread::threadMain() {
while (1) {
DemodulatorThreadIQData inp;
m_pQueue->pop(inp);
inputQueue->pop(inp);
std::vector<signed char> *data = &inp.data;
if (data->size()) {
@ -139,22 +139,6 @@ void DemodulatorThread::threadMain() {
if (visOutQueue != NULL) {
visOutQueue->push(ati);
}
/*if (!TestDestroy()) {
DemodulatorThreadAudioData *audioOut = new DemodulatorThreadAudioData(task.data->frequency, params.audioSampleRate, newBuffer);
m_pQueue->sendAudioData(DemodulatorThreadTask::DEMOD_THREAD_AUDIO_DATA, audioOut);
if (params.audioInputQueue != NULL) {
AudioThreadInput ati;
ati.data = newBuffer;
params.audioInputQueue->push(ati);
// AudioThreadTask audio_task = AudioThreadTask(AudioThreadTask::AUDIO_THREAD_DATA);
// audio_task.data = new AudioThreadData(task.data->frequency, params.audioSampleRate, newBuffer);
// params.audioQueue->addTask(audio_task, AudioThreadQueue::AUDIO_PRIORITY_HIGHEST);
}
}*/
}
}
}

View File

@ -102,7 +102,7 @@ public:
}
protected:
DemodulatorThreadInputQueue* m_pQueue;
DemodulatorThreadInputQueue* inputQueue;
DemodulatorThreadOutputQueue* visOutQueue;
firfilt_crcf fir_filter;

View File

@ -15,11 +15,9 @@
#include <cstdint>
#include <condition_variable>
/** A thread-safe asynchronous queue */
template<class T, class Container = std::list<T>>
class ThreadQueue
{
class ThreadQueue {
typedef typename Container::value_type value_type;
typedef typename Container::size_type size_type;
@ -29,19 +27,16 @@ class ThreadQueue
/*! Create safe queue. */
ThreadQueue() = default;
ThreadQueue (ThreadQueue&& sq)
{
ThreadQueue(ThreadQueue&& sq) {
m_queue = std::move(sq.m_queue);
}
ThreadQueue (const ThreadQueue& sq)
{
ThreadQueue(const ThreadQueue& sq) {
std::lock_guard < std::mutex > lock(sq.m_mutex);
m_queue = sq.m_queue;
}
/*! Destroy safe queue. */
~ThreadQueue()
{
~ThreadQueue() {
std::lock_guard < std::mutex > lock(m_mutex);
}
@ -49,8 +44,7 @@ class ThreadQueue
* Sets the maximum number of items in the queue. Defaults is 0: No limit
* \param[in] item An item.
*/
void set_max_num_items (unsigned int max_num_items)
{
void set_max_num_items(unsigned int max_num_items) {
m_max_num_items = max_num_items;
}
@ -59,8 +53,7 @@ class ThreadQueue
* \param[in] item An item.
* \return true if an item was pushed into the queue
*/
bool push (const value_type& item)
{
bool push(const value_type& item) {
std::lock_guard < std::mutex > lock(m_mutex);
if (m_max_num_items > 0 && m_queue.size() > m_max_num_items)
@ -76,8 +69,7 @@ class ThreadQueue
* \param[in] item An item.
* \return true if an item was pushed into the queue
*/
bool push (const value_type&& item)
{
bool push(const value_type&& item) {
std::lock_guard < std::mutex > lock(m_mutex);
if (m_max_num_items > 0 && m_queue.size() > m_max_num_items)
@ -92,8 +84,7 @@ class ThreadQueue
* Pops item from the queue. If queue is empty, this function blocks until item becomes available.
* \param[out] item The item.
*/
void pop (value_type& item)
{
void pop(value_type& item) {
std::unique_lock < std::mutex > lock(m_mutex);
m_condition.wait(lock, [this]() // Lambda funct
{
@ -109,8 +100,7 @@ class ThreadQueue
* If queue is empty, this function blocks until item becomes available.
* \param[out] item The item.
*/
void move_pop (value_type& item)
{
void move_pop(value_type& item) {
std::unique_lock < std::mutex > lock(m_mutex);
m_condition.wait(lock, [this]() // Lambda funct
{
@ -125,8 +115,7 @@ class ThreadQueue
* \param[out] item The item.
* \return False is returned if no item is available.
*/
bool try_pop (value_type& item)
{
bool try_pop(value_type& item) {
std::unique_lock < std::mutex > lock(m_mutex);
if (m_queue.empty())
@ -143,8 +132,7 @@ class ThreadQueue
* \param[out] item The item.
* \return False is returned if no item is available.
*/
bool try_move_pop (value_type& item)
{
bool try_move_pop(value_type& item) {
std::unique_lock < std::mutex > lock(m_mutex);
if (m_queue.empty())
@ -161,12 +149,10 @@ class ThreadQueue
* \param[in] timeout The number of microseconds to wait.
* \return true if get an item from the queue, false if no item is received before the timeout.
*/
bool timeout_pop (value_type& item, std::uint64_t timeout)
{
bool timeout_pop(value_type& item, std::uint64_t timeout) {
std::unique_lock < std::mutex > lock(m_mutex);
if (m_queue.empty())
{
if (m_queue.empty()) {
if (timeout == 0)
return false;
@ -187,12 +173,10 @@ class ThreadQueue
* \param[in] timeout The number of microseconds to wait.
* \return true if get an item from the queue, false if no item is received before the timeout.
*/
bool timeout_move_pop (value_type& item, std::uint64_t timeout)
{
bool timeout_move_pop(value_type& item, std::uint64_t timeout) {
std::unique_lock < std::mutex > lock(m_mutex);
if (m_queue.empty())
{
if (m_queue.empty()) {
if (timeout == 0)
return false;
@ -209,8 +193,7 @@ class ThreadQueue
* Gets the number of items in the queue.
* \return Number of items in the queue.
*/
size_type size() const
{
size_type size() const {
std::lock_guard < std::mutex > lock(m_mutex);
return m_queue.size();
}
@ -219,8 +202,7 @@ class ThreadQueue
* Check if the queue is empty.
* \return true if queue is empty.
*/
bool empty() const
{
bool empty() const {
std::lock_guard < std::mutex > lock(m_mutex);
return m_queue.empty();
}
@ -229,10 +211,8 @@ class ThreadQueue
* Swaps the contents.
* \param[out] sq The ThreadQueue to swap with 'this'.
*/
void swap (ThreadQueue& sq)
{
if (this != &sq)
{
void swap(ThreadQueue& sq) {
if (this != &sq) {
std::lock_guard < std::mutex > lock1(m_mutex);
std::lock_guard < std::mutex > lock2(sq.m_mutex);
m_queue.swap(sq.m_queue);
@ -246,10 +226,8 @@ class ThreadQueue
}
/*! The copy assignment operator */
ThreadQueue& operator= (const ThreadQueue& sq)
{
if (this != &sq)
{
ThreadQueue& operator=(const ThreadQueue& sq) {
if (this != &sq) {
std::lock_guard < std::mutex > lock1(m_mutex);
std::lock_guard < std::mutex > lock2(sq.m_mutex);
std::queue<T, Container> temp { sq.m_queue };
@ -263,17 +241,16 @@ class ThreadQueue
}
/*! The move assignment operator */
ThreadQueue& operator= (ThreadQueue && sq)
{
ThreadQueue& operator=(ThreadQueue && sq) {
std::lock_guard < std::mutex > lock(m_mutex);
m_queue = std::move(sq.m_queue);
if (!m_queue.empty()) m_condition.notify_all();
if (!m_queue.empty())
m_condition.notify_all();
return *this;
}
private:
std::queue<T, Container> m_queue;
@ -284,7 +261,6 @@ class ThreadQueue
/*! Swaps the contents of two ThreadQueue objects. */
template<class T, class Container>
void swap (ThreadQueue<T, Container>& q1, ThreadQueue<T, Container>& q2)
{
void swap(ThreadQueue<T, Container>& q1, ThreadQueue<T, Container>& q2) {
q1.swap(q2);
}

View File

@ -1,4 +1,3 @@
#ifndef TIMER_H
#define TIMER_H
@ -13,8 +12,7 @@
* Class provides high resolution timing and useful time control functions
*/
class Timer
{
class Timer {
private:
unsigned long time_elapsed;
@ -31,7 +29,6 @@ private:
struct timezone time_zone;
#endif
bool paused_state;
bool lock_state;
float lock_rate;
@ -53,35 +50,30 @@ public:
*/
void stop(void);
/// Locks the timer to a specified framerate (for recording / benchmarking purposes typically)
/**
* Locks the timer to a specified framerate (for recording / benchmarking purposes typically)
*/
void lockFramerate(float f_rate);
/// Unlock any framerate lock that's been applied
/**
* Unlock any framerate lock that's been applied
*/
void unlock();
/// Check locked state
/**
* Check locked state
*/
bool locked();
/// Reset the timer counter
/**
* Resetting the timer will reset the current time to 0
*/
void reset(void);
/// Timer update
/**
* Calling the update command will bring the timer value up to date, this is meant
@ -89,7 +81,6 @@ public:
*/
void update(void);
/// Get the total time elapsed since the timer start, not counting paused time
/**
* Returns the total time elapsed in since the timer start() to the last update() but
@ -103,7 +94,6 @@ public:
*/
double getSeconds(void);
/// Get the total time elapsed since the timer start
/**
* Returns the total time elapsed in since the timer start() to the last update()
@ -117,7 +107,6 @@ public:
*/
double totalSeconds(void);
/// Set the amount of time elapsed
/**
* Force the timer duration to a specific value, useful for rolling forward or back in a system
@ -131,7 +120,6 @@ public:
*/
void setSeconds(double seconds_in);
/// Get the amount of times the update() command has been called
/**
* By using the number of times the update() command has been called you can easily determine
@ -140,7 +128,6 @@ public:
*/
unsigned long getNumUpdates(void);
/// Get the timer duration during the last update
/**
* Useful for determining the amount of time which elapsed during the last update
@ -154,7 +141,6 @@ public:
*/
double lastUpdateSeconds(void);
/// Set the timer pause state
/**
* Pause the timer, allowing for continued update() calls without an increment in timing but
@ -171,6 +157,5 @@ public:
bool paused();
};
#endif