SoDaRadio-12.2.0-cut_dependencies:6c82803
Loading...
Searching...
No Matches
SoDa::AudioQt Class Reference

Qt audio interface class. More...

#include <AudioQt.hxx>

Inheritance diagram for SoDa::AudioQt:
SoDa::AudioIfc SoDa::Thread SoDa::Base SoDa::Debug

Public Member Functions

 ~AudioQt ()
int send (void *buf, unsigned int len, bool when_ready=false)
 send – send a buffer to the audio output
bool sendBufferReady (unsigned int len)
 sendBufferReady – is there enough space in the audio device send buffer for a call from send?
virtual int recv (std::vector< float > &buf, bool when_ready=false)
 recv – get a buffer of data from the audio input
bool recvBufferReady (unsigned int len)
 recvBufferReady – are there samples waiting in the audio device?
void sleepOut ()
 stop the output stream so that we don't encounter a buffer underflow while the reciever is muted.
void wakeOut ()
 start the output stream
virtual void sleepIn ()
 stop the input stream so that we don't encounter a buffer overflow while the transmitter is inactive.
virtual void wakeIn ()
 start the input stream
std::string currentPlaybackState ()
virtual std::string currentCaptureState ()
void run ()
 the run method – maintains incoming audio sample buffers
void subscribeToMailBoxes (const std::vector< MailBoxBasePtr > &mailboxes)
 the creator of this thread may offer one or more mailboxes to this object.
Public Member Functions inherited from SoDa::AudioIfc
virtual bool setOutGain (float gain)
 set the gain for the output device.
virtual bool setInGain (float gain)
 set the gain for the input device.
virtual float getOutGain ()
 get the gain for the output device.
virtual float getInGain ()
 get the gain for the input device.
Public Member Functions inherited from SoDa::Thread
void registerThread (SoDa::ThreadPtr me)
void operator() ()
void start ()
 Execute the thread's run loop.
void join ()
 more properly "Wait for this thread to exit its run loop".
void execCommand (CommandPtr cmd)
 Execute (dispatch) a message removed from the command stream to one of the basic Command handler functions.
virtual void execGetCommand (CommandPtr cmd)
 optional method to handle "GET" commands – commands that request a response
virtual void execSetCommand (CommandPtr cmd)
 optional method to handle "SET" commands – commands that set internal state in the object.
virtual void execRepCommand (CommandPtr cmd)
 optional method that reports status or the result of some action.
virtual void shutDown ()
 optional method that performs cleanup – may not delete.
void sleep_ms (unsigned int milliseconds)
void sleep_us (unsigned int microseconds)
uint32_t getID ()
 Get the process/thread ID for this thread – helps with figuring out who caused a segfault.
Public Member Functions inherited from SoDa::Base
 Base (const std::string &oname)
 The constructor – pass a name for the object.
void registerSelf (BasePtr ptr)
std::string & getObjName ()
 get the name of this object
BasePtr findSoDaObject (const std::string &oname)
 find a SoDa Object by name.
double getTime ()
 Get a time stamp in nS resolution that monotonically increases and that is very inexpensive (typically < 100nS).
BasePtr getSelfPtr ()
 get a pointer to myself.
Public Member Functions inherited from SoDa::Debug
 Debug (std::string _unit_name=std::string("UNKNOWN"))
 Debug (const char *_unit_name_cstr)
 Debug (unsigned int _debug_level, std::string _unit_name=std::string("UNKNOWN"))
 Debug (unsigned int _debug_level, const char *_unit_name_cstr)
void debugMsg (const std::string &msg, unsigned int threshold=1)
void debugMsg (const SoDa::Format &fmt, unsigned int threshold=1)
void debugMsg (const char *msg, unsigned int threshold=1)
void setDebugLevel (unsigned int v)
unsigned int getDebugLevel ()

Static Public Member Functions

static AudioQtPtr make (unsigned int _sample_rate, unsigned int _sample_count_hint=1024, std::string audio_sock_basename=std::string("soda_"))
Static Public Member Functions inherited from SoDa::Debug
static void setDefaultLevel (unsigned int v)
static unsigned int getDefaultLevel ()
static void setGlobalLevel (unsigned int v)
static unsigned int getGlobalLevel ()

Protected Member Functions

 AudioQt (unsigned int _sample_rate, unsigned int _sample_count_hint=1024, std::string audio_sock_basename=std::string("soda_"))
 constructor
void setupNetwork (std::string audio_sock_basename)
 setup the network sockets for the audio link to the user interface.
Protected Member Functions inherited from SoDa::AudioIfc
 AudioIfc (unsigned int _sample_rate, unsigned int _sample_count_hint, const std::string &name="AudioIfc")
Protected Member Functions inherited from SoDa::Thread
 Thread (const std::string &oname, const std::string &version=std::string("12.2.0"))
 make the thread object.
Protected Member Functions inherited from SoDa::Debug
std::string curDateTime ()

Private Attributes

std::shared_ptr< SoDa::UD::ServerSocketaudio_rx_socket
std::shared_ptr< SoDa::UD::ServerSocketaudio_tx_socket
CmdMBoxPtr cmd_stream
 command stream from UI and other units
CmdMBox::Subscription cmd_subs
 subscription ID for command stream
bool ignore_tx_data
SoDa::CircularBuffer< char > * audio_cbuffer_p
float ang
float ang_incr

Additional Inherited Members

Static Public Attributes inherited from SoDa::Debug
static std::mutex debug_msg_mutex
Protected Attributes inherited from SoDa::AudioIfc
unsigned int sample_rate
unsigned int sample_count_hint
float in_gain
float out_gain
int datatype_size
Protected Attributes inherited from SoDa::Thread
std::weak_ptr< Threadself
 A pointer to ourself.
Protected Attributes inherited from SoDa::Debug
std::string unit_name
 the name of the unit reporting status
unsigned int debug_level
 the debug level (threshold) for messages
Static Protected Attributes inherited from SoDa::Debug
static unsigned int default_debug_level
static unsigned int global_debug_level

Detailed Description

Qt audio interface class.

AudioQt implements the interface specified by AudioIfc. It should be interchangable with other audio interface handlers.

When BasebandRX posts data to the audio interface, it is transmitted via a unix domain socket to the GUI where the audio output device is managed. In the standard SoDaRadio configuration, this is turned into a QtAudio output stream.

BasebandTX watches for incoming data on its audio input mailbox. This arrives from the GUI (a QtAudio stream) via a unix domain socket.

The AudioQt object runs as a thread, solely to listen in on the incoming (transmit) audio socket. As samples arrive, they are appended to a dequeue of buffers to be passed back to the BasebandTX object when it needs data. The listener thread also subscribes to the cmd mailbox ring: it throws away incoming and buffered samples while the radio is in TX mode. This allows the process sourcing the audio stream to be ignorant of the current state of the transceiver.

Definition at line 75 of file AudioQt.hxx.

Constructor & Destructor Documentation

◆ AudioQt()

SoDa::AudioQt::AudioQt ( unsigned int _sample_rate,
unsigned int _sample_count_hint = 1024,
std::string audio_sock_basename = std::string("soda_") )
protected

constructor

Parameters
_sample_ratein Hz 48000 is a good choice
_sample_count_hintthe size of the buffers passed to and from the audio device (in samples)
audio_sock_basenamestarting string for the unix-domain sockets that carry the RX audio stream from the SoDaServer (radio) process and the TX audio stream from the Qt GUI.

Referenced by make().

◆ ~AudioQt()

SoDa::AudioQt::~AudioQt ( )
inline

Definition at line 101 of file AudioQt.hxx.

Member Function Documentation

◆ currentCaptureState()

virtual std::string SoDa::AudioQt::currentCaptureState ( )
inlinevirtual

Reimplemented from SoDa::AudioIfc.

Definition at line 167 of file AudioQt.hxx.

◆ currentPlaybackState()

std::string SoDa::AudioQt::currentPlaybackState ( )
inlinevirtual

Reimplemented from SoDa::AudioIfc.

Definition at line 163 of file AudioQt.hxx.

◆ make()

AudioQtPtr SoDa::AudioQt::make ( unsigned int _sample_rate,
unsigned int _sample_count_hint = 1024,
std::string audio_sock_basename = std::string("soda_") )
inlinestatic

Definition at line 91 of file AudioQt.hxx.

References AudioQt().

◆ recv()

virtual int SoDa::AudioQt::recv ( std::vector< float > & buf,
bool when_ready = false )
virtual

recv – get a buffer of data from the audio input

Parameters
buffloat vector of samples coming from the audio input device
when_readyif true, test with recvBufferReady and return 0 if not ready otherwise perform the recv regardless.
Returns
number of elements transferred from the audio input

Implements SoDa::AudioIfc.

◆ recvBufferReady()

bool SoDa::AudioQt::recvBufferReady ( unsigned int len)
virtual

recvBufferReady – are there samples waiting in the audio device?

Parameters
lenthe number of samples that we wish to get
Returns
true if len samples are waiting in in the device buffer

Implements SoDa::AudioIfc.

◆ run()

void SoDa::AudioQt::run ( )
virtual

the run method – maintains incoming audio sample buffers

Reimplemented from SoDa::Thread.

◆ send()

int SoDa::AudioQt::send ( void * buf,
unsigned int len,
bool when_ready = false )
virtual

send – send a buffer to the audio output

Parameters
bufbuffer of type described by the DataFormat selected at init
lennumber of elements in the buffer to send
when_readyif true, test with sendBufferReady and return 0 if not ready otherwise perform the send regardless.
Returns
number of elements transferred to the audio output

Implements SoDa::AudioIfc.

◆ sendBufferReady()

bool SoDa::AudioQt::sendBufferReady ( unsigned int len)
virtual

sendBufferReady – is there enough space in the audio device send buffer for a call from send?

Parameters
lenthe number of samples that we wish to send
Returns
true if there is sufficient space.

Implements SoDa::AudioIfc.

◆ setupNetwork()

void SoDa::AudioQt::setupNetwork ( std::string audio_sock_basename)
protected

setup the network sockets for the audio link to the user interface.

◆ sleepIn()

virtual void SoDa::AudioQt::sleepIn ( )
virtual

stop the input stream so that we don't encounter a buffer overflow while the transmitter is inactive.

This will also empty the incoming transmit buffer.

Implements SoDa::AudioIfc.

◆ sleepOut()

void SoDa::AudioQt::sleepOut ( )
inlinevirtual

stop the output stream so that we don't encounter a buffer underflow while the reciever is muted.

Implements SoDa::AudioIfc.

Definition at line 144 of file AudioQt.hxx.

◆ subscribeToMailBoxes()

void SoDa::AudioQt::subscribeToMailBoxes ( const std::vector< MailBoxBasePtr > & mailboxes)
virtual

the creator of this thread may offer one or more mailboxes to this object.

The thread may "subscribe" to the mailboxes as it chooses.

Parameters
mailboxesA list of all mailboxes that we know about.

Implements SoDa::Thread.

◆ wakeIn()

virtual void SoDa::AudioQt::wakeIn ( )
virtual

start the input stream

Implements SoDa::AudioIfc.

◆ wakeOut()

void SoDa::AudioQt::wakeOut ( )
inlinevirtual

start the output stream

Implements SoDa::AudioIfc.

Definition at line 149 of file AudioQt.hxx.

Member Data Documentation

◆ ang

float SoDa::AudioQt::ang
private

Definition at line 199 of file AudioQt.hxx.

◆ ang_incr

float SoDa::AudioQt::ang_incr
private

Definition at line 200 of file AudioQt.hxx.

◆ audio_cbuffer_p

SoDa::CircularBuffer<char>* SoDa::AudioQt::audio_cbuffer_p
private

Definition at line 196 of file AudioQt.hxx.

◆ audio_rx_socket

std::shared_ptr<SoDa::UD::ServerSocket> SoDa::AudioQt::audio_rx_socket
private

Definition at line 184 of file AudioQt.hxx.

◆ audio_tx_socket

std::shared_ptr<SoDa::UD::ServerSocket> SoDa::AudioQt::audio_tx_socket
private

Definition at line 185 of file AudioQt.hxx.

◆ cmd_stream

CmdMBoxPtr SoDa::AudioQt::cmd_stream
private

command stream from UI and other units

Definition at line 188 of file AudioQt.hxx.

◆ cmd_subs

CmdMBox::Subscription SoDa::AudioQt::cmd_subs
private

subscription ID for command stream

Definition at line 189 of file AudioQt.hxx.

◆ ignore_tx_data

bool SoDa::AudioQt::ignore_tx_data
private

Definition at line 191 of file AudioQt.hxx.


The documentation for this class was generated from the following file: