From 869d367ed94dad2cd08a8257becbdff20b764831 Mon Sep 17 00:00:00 2001 From: kevin Date: Sat, 11 Dec 2021 15:14:27 -0500 Subject: [PATCH] cwIo : added audioGroupDeviceCount(),audioGroupDeviceIndex(),audioDeviceLabel(),audioDeviceUserId() --- cwIo.cpp | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- cwIo.h | 14 +++++++++--- 2 files changed, 76 insertions(+), 4 deletions(-) diff --git a/cwIo.cpp b/cwIo.cpp index 637cff1..ecf3965 100644 --- a/cwIo.cpp +++ b/cwIo.cpp @@ -1081,7 +1081,7 @@ namespace cw } - // This function is called by the audio device drivers to when incoming audio arrives + // This function is called by the audio device drivers when incoming audio arrives // or when there is available space to write outgoing audio. // If all in/out devices in a group are ready to be source/sink audio data then this function // triggers the group thread condition var thereby causing an application callback @@ -2078,6 +2078,17 @@ unsigned cw::io::audioDeviceLabelToIndex( handle_t h, const char* label ) return kInvalidIdx; } +const char* cw::io::audioDeviceLabel( handle_t h, unsigned devIdx ) +{ + io_t* p = _handleToPtr(h); + audioDev_t* ad; + + if((ad = _audioDeviceIndexToRecd(p,devIdx)) != nullptr ) + return ad->label; + + return nullptr; +} + cw::rc_t cw::io::audioDeviceSetUserId( handle_t h, unsigned devIdx, unsigned userId ) { io_t* p = _handleToPtr(h); @@ -2119,6 +2130,18 @@ const char* cw::io::audioDeviceName( handle_t h, unsigned devIdx ) return ad->devName; } +unsigned cw::io::audioDeviceUserId( handle_t h, unsigned devIdx ) +{ + io_t* p = _handleToPtr(h); + audioDev_t* ad; + + if((ad = _audioDeviceIndexToRecd(p, devIdx )) == nullptr ) + return kInvalidId; + + return ad->userId; +} + + double cw::io::audioDeviceSampleRate( handle_t h, unsigned devIdx ) { io_t* p = _handleToPtr(h); @@ -2397,6 +2420,47 @@ unsigned cw::io::audioGroupDspFrameCount( handle_t h, unsigned groupIdx ) return 0; } +unsigned cw::io::audioGroupDeviceCount( handle_t h, unsigned groupIdx, unsigned inOrOutFl ) +{ + audioGroup_t* ag; + io_t* p = _handleToPtr(h); + unsigned n = 0; + + if((ag = _audioGroupFromIndex( p, groupIdx )) != nullptr ) + { + audio_group_dev_t* agd = cwIsFlag(inOrOutFl,kInFl) ? ag->msg.iDevL : ag->msg.oDevL; + for(; agd!=nullptr; agd=agd->link) + ++n; + } + + return n; +} + +unsigned cw::io::audioGroupDeviceIndex( handle_t h, unsigned groupIdx, unsigned inOrOutFl, unsigned groupDevIdx ) +{ + audioGroup_t* ag; + io_t* p = _handleToPtr(h); + unsigned n = 0; + + if((ag = _audioGroupFromIndex( p, groupIdx )) != nullptr ) + { + audio_group_dev_t* agd = cwIsFlag(inOrOutFl,kInFl) ? ag->msg.iDevL : ag->msg.oDevL; + + for(; agd!=nullptr; agd=agd->link) + { + if( n == groupDevIdx ) + return agd->devIdx; + ++n; + } + } + + cwLogError(kInvalidIdRC,"The audio group device index '%i' could found on group index: '%i' .",groupDevIdx,groupIdx); + + + return kInvalidIdx; +} + + //---------------------------------------------------------------------------------------------------------- // // Socket diff --git a/cwIo.h b/cwIo.h index 6c49789..63a7f62 100644 --- a/cwIo.h +++ b/cwIo.h @@ -82,12 +82,12 @@ namespace cw double srate; // Group sample rate. unsigned dspFrameCnt; // Count of samples in each buffer pointed to by iBufArray[] and oBufArray[] - sample_t** iBufArray; // Array of iBufChCnt ptrs to buffers of size bufSmpCnt + sample_t** iBufArray; // iBufArray[iBufChCnt] Array ptrs to buffers of size dspFrameCnt unsigned iBufChCnt; // Count of elements in iBufArray[] time::spec_t* iTimeStampPtr; // audio_group_dev_t* iDevL; // Linked list of input devices which map directly to channels in iBufArray[] - sample_t** oBufArray; // + sample_t** oBufArray; // oBufArray[oBufChCnt] Array of ptrs to buffers of size dspFrameCnt unsigned oBufChCnt; // time::spec_t* oTimeStampPtr; // audio_group_dev_t* oDevL; // Linked list of output devices which map directly to channels in oBufArray[] @@ -178,7 +178,7 @@ namespace cw unsigned serialDeviceCount( handle_t h ); unsigned serialDeviceIndex( handle_t h, const char* label ); const char* serialDeviceLabel( handle_t h, unsigned devIdx ); - unsigned serialDeviceId( handle_t h, unsigned devIdx ); + unsigned serialDeviceId( handle_t h, unsigned devIdx ); // defaults to device index void serialDeviceSetId( handle_t h, unsigned devIdx, unsigned id ); rc_t serialDeviceSend( handle_t h, unsigned devIdx, const void* byteA, unsigned byteN ); @@ -204,9 +204,11 @@ namespace cw unsigned audioDeviceCount( handle_t h ); unsigned audioDeviceLabelToIndex( handle_t h, const char* label ); + const char* audioDeviceLabel( handle_t h, unsigned devIdx ); rc_t audioDeviceSetUserId( handle_t h, unsigned devIdx, unsigned userId ); bool audioDeviceIsEnabled( handle_t h, unsigned devIdx ); const char* audioDeviceName( handle_t h, unsigned devIdx ); + unsigned audioDeviceUserId( handle_t h, unsigned devIdx ); double audioDeviceSampleRate( handle_t h, unsigned devIdx ); unsigned audioDeviceFramesPerCycle( handle_t h, unsigned devIdx ); unsigned audioDeviceChannelCount( handle_t h, unsigned devIdx, unsigned inOrOutFlag ); @@ -227,6 +229,12 @@ namespace cw rc_t audioGroupSetUserId( handle_t h, unsigned groupIdx, unsigned userId ); double audioGroupSampleRate( handle_t h, unsigned groupIdx ); unsigned audioGroupDspFrameCount( handle_t h, unsigned groupIdx ); + + // Get the count of in or out devices assigned to this group. + unsigned audioGroupDeviceCount( handle_t h, unsigned groupIdx, unsigned inOrOutFl ); + + // Get the device index of each of the devices assigned to this group + unsigned audioGroupDeviceIndex( handle_t h, unsigned groupIdx, unsigned inOrOutFl, unsigned groupDeviceIdx ); //---------------------------------------------------------------------------------------------------------- //