Public Member Functions | Static Public Member Functions | List of all members
respeaker::AloopOutputNode Class Referenceabstract
Inheritance diagram for respeaker::AloopOutputNode:

Public Member Functions

virtual bool OnStartThread ()=0
virtual std::string FetchBlock (bool &exit)=0
virtual std::string ProcessBlock (std::string block, bool &exit)=0
virtual bool OnJoinThread ()=0
virtual int SetMaxBlockDelayTime (int ms)=0
- Public Member Functions inherited from respeaker::BaseNode
BaseNodeGetId ()
void Uplink (BaseNode *uplink_node)
void RegisterDownlinkNode (BaseNode *downlink_node)
NodeParameterGetNodeOutputParameter ()
bool RecursivelyStartThread (ChainSharedData *shared_data)
bool RecursivelyJoinThread ()
virtual void StoreBlock (std::string block, bool &exit)
virtual void Pause ()
virtual void Resume ()
std::mutex * GetDownlinkDataQueueMutex (BaseNode *downlink_node_id=nullptr)
std::condition_variable * GetDownlinkDataQueueConditionVar (BaseNode *downlink_node_id=nullptr)
std::queue< std::string > & GetDownlinkDataQueue (BaseNode *downlink_node_id=nullptr)
int GetQueueDeepth ()
bool BindToCore (int core_index)
bool SetThreadPriority (int priority)

Static Public Member Functions

static AloopOutputNodeCreate (std::string output_device_name, bool output_interleaved=false)
static AloopOutputNodeCreate (std::string output_device_name, int period_time_ms, int buffer_time_ms, bool output_interleaved=false)

Additional Inherited Members

- Protected Member Functions inherited from respeaker::BaseNode
void EnableQueueFlush (bool enable)
void _Interleave (const int16_t *const *deinterleaved, size_t num_frames, size_t num_channels, int16_t *interleaved)
void _Deinterleave (const int16_t *interleaved, size_t num_frames, size_t num_channels, int16_t *const *deinterleaved)
void _Deinterleave (const float *interleaved, size_t num_frames, size_t num_channels, float *const *deinterleaved)
- Protected Attributes inherited from respeaker::BaseNode
BaseNode_uplink_node = nullptr
std::list< BaseNode * > _list_downlink_nodes
NodeParameter _input_parameter
NodeParameter _output_parameter
int _system_check = 0
ChainSharedData_chain_shared_data = nullptr
bool _is_head = false
bool _is_tail = false
bool _is_interleaved_after_process = false
int _num_frames_for_store_block
int _channels_for_store_block
int16_t * _buffer_for_store_block
std::unique_ptr< int16_t *[]> _channels_ptr

Member Function Documentation

◆ Create() [1/2]

static AloopOutputNode* respeaker::AloopOutputNode::Create ( std::string  output_device_name,
bool  output_interleaved = false 

Create a AloopOutputNode instance. Output audio stream to a specific Alsa device(eg. "hw:Loopback,0,0"). In this case, the third party ASR engine(eg. Snips, AVS) can capture the processed audio stream from Alsa (eg. "hw:Loopback,1,0") directly. Need to run "sudo modprobe snd-aloop" to enable aloop module first.

Note that the sample rate and channel number of the audio stream, are the same as the uplink node. And the format is fixed to S16_LE. And the period/buffer time of Alsa PCM handle is set to 32/128 ms by default. Use large period/buffer time will get large latency but good cpu usage, use low period/buffer time will get superb latency but heavy cpu usage. For more information about period/buffer time, please check this:

output_device_name- Users can obtain this by aplay -L.
output_interleaved- Set it true to output interleaved data, false to output deinterleaved data.

◆ Create() [2/2]

static AloopOutputNode* respeaker::AloopOutputNode::Create ( std::string  output_device_name,
int  period_time_ms,
int  buffer_time_ms,
bool  output_interleaved = false 
period_time_ms- Set period time of Alsa PCM handle, period time should be less than buffer time, default to 32ms
buffer_time_ms- Set buffer time of Alsa PCM handle, default to 128ms

◆ FetchBlock()

virtual std::string respeaker::AloopOutputNode::FetchBlock ( bool &  exit)
pure virtual

The head node must override this method, to do real audio data fetching

exit[out] - The exit flag of the ChainSharedData is set, the thread should join now.

Reimplemented from respeaker::BaseNode.

◆ OnJoinThread()

virtual bool respeaker::AloopOutputNode::OnJoinThread ( )
pure virtual

Do per node cleanup in this method.

Implements respeaker::BaseNode.

◆ OnStartThread()

virtual bool respeaker::AloopOutputNode::OnStartThread ( )
pure virtual

The derived node must configure the output parameter in this method

Implements respeaker::BaseNode.

◆ ProcessBlock()

virtual std::string respeaker::AloopOutputNode::ProcessBlock ( std::string  block,
bool &  exit 
pure virtual

Every node must implement this method.

exit[out] - The exit flag of the ChainSharedData is set, the thread should join now.

Implements respeaker::BaseNode.

◆ SetMaxBlockDelayTime()

virtual int respeaker::AloopOutputNode::SetMaxBlockDelayTime ( int  ms)
pure virtual

Set the "max block delay time" of this node. The "max block delay time" means the max acceptable latency from the queue of uplink node. As we known, this node get audio data(we call it "block") from the output queue of its uplink node. When the queue contains some blocks, for example 10 blocks, and each block has 40ms audio data, that means this aloop node has 10*40ms=400ms "block delay time". Under a high "block delay time"(eg. more than 400ms), your assistant will become "slow" and easy to make mistake. So we need to drain(drop) the audio data in queue when this situation happens(when the length of audio data is larger than the "max block delay time"). Note that this situation will not always happen. Note that this function should be called after OnStartThread().

ms- "max block delay time" in ms. Defalut to (5 * block_len_ms of uplink NodeParameter)ms. The minimum value is (2 * block_len_ms of uplink NodeParameter)ms.
int - The actually "max block delay time" in ms.

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