#pragma once #include #include #include #include #include #include "wx/wxprec.h" #ifndef WX_PRECOMP #include "wx/wx.h" #endif #include "wx/thread.h" #include "AudioThread.h" #include "ThreadQueue.h" #include "RtAudio.h" #include "DemodDefs.h" class AudioThreadInput: public ReferenceCounter { public: int frequency; int sampleRate; int channels; std::vector data; AudioThreadInput() : frequency(0), sampleRate(0), channels(0) { } ~AudioThreadInput() { } }; class AudioThreadCommand { public: enum AudioThreadCommandEnum { AUDIO_THREAD_CMD_NULL, AUDIO_THREAD_CMD_SET_DEVICE }; AudioThreadCommand() : cmd(AUDIO_THREAD_CMD_NULL), int_value(0) { } AudioThreadCommandEnum cmd; int int_value; }; typedef ThreadQueue AudioThreadInputQueue; typedef ThreadQueue AudioThreadCommandQueue; class AudioThread { public: AudioThreadInput *currentInput; AudioThreadInputQueue *inputQueue; std::atomic audio_queue_ptr; std::atomic underflow_count; std::atomic terminated; std::atomic active; float gain; AudioThread(AudioThreadInputQueue *inputQueue, DemodulatorThreadCommandQueue* threadQueueNotify); ~AudioThread(); void enumerateDevices(); void threadMain(); void terminate(); bool isActive(); void setActive(bool state); private: RtAudio dac; RtAudio::StreamParameters parameters; AudioThreadCommandQueue cmdQueue; DemodulatorThreadCommandQueue* threadQueueNotify; #ifdef __APPLE__ public: void bindThread(AudioThread *other); void removeThread(AudioThread *other); static std::map deviceController; static std::map deviceThread; static void deviceCleanup(); std::atomic *> boundThreads; #endif };