audioBuf.h/cpp : Added toneFlags(),muteFlags(),gain( ... gainA,gainN).
Added _setFlag() to handle setting flags on all channels. setFlag() now sets both input and output channels if both kInFl and kOutFl are set. Previously it only set the input channel if both kInFl and kOutFl were set.
This commit is contained in:
parent
e763ed1607
commit
04a1bec0c3
102
cwAudioBuf.cpp
102
cwAudioBuf.cpp
@ -5,6 +5,7 @@
|
||||
#include "cwTime.h"
|
||||
#include "cwTextBuf.h"
|
||||
#include "cwAudioDevice.h"
|
||||
#include "cwAudioBufDecls.h"
|
||||
#include "cwAudioBuf.h"
|
||||
|
||||
/*
|
||||
@ -216,26 +217,43 @@ namespace cw
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void _theBufCalcTimeStamp( double srate, const time::spec_t* baseTimeStamp, unsigned frmCnt, time::spec_t* retTimeStamp )
|
||||
{
|
||||
if( retTimeStamp == NULL )
|
||||
return;
|
||||
void _setFlag( audioBuf_t* p, unsigned devIdx, unsigned chIdx, unsigned flags, unsigned ioIdx )
|
||||
{
|
||||
|
||||
double secs = frmCnt / srate;
|
||||
unsigned int_secs = floor(secs);
|
||||
double frac_secs = secs - int_secs;
|
||||
bool enableFl = flags & kEnableFl ? true : false;
|
||||
unsigned i = chIdx != kInvalidIdx ? chIdx : 0;
|
||||
unsigned n = chIdx != kInvalidIdx ? chIdx+1 : p->devArray[devIdx].ioArray[ioIdx].chCnt;
|
||||
|
||||
for(; i<n; ++i)
|
||||
{
|
||||
cmApCh* cp = p->devArray[devIdx].ioArray[ioIdx].chArray + i;
|
||||
cp->fl = cwEnaFlag(cp->fl, flags & (kChFl|kToneFl|kMeterFl|kMuteFl|kPassFl), enableFl );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
retTimeStamp->tv_nsec = floor(baseTimeStamp->tv_nsec + frac_secs * 1000000000);
|
||||
retTimeStamp->tv_sec = baseTimeStamp->tv_sec + int_secs;
|
||||
void _theBufCalcTimeStamp( double srate, const time::spec_t* baseTimeStamp, unsigned frmCnt, time::spec_t* retTimeStamp )
|
||||
{
|
||||
if( retTimeStamp == NULL )
|
||||
return;
|
||||
|
||||
if( retTimeStamp->tv_nsec > 1000000000 )
|
||||
{
|
||||
retTimeStamp->tv_nsec -= 1000000000;
|
||||
retTimeStamp->tv_sec += 1;
|
||||
}
|
||||
}
|
||||
double secs = frmCnt / srate;
|
||||
unsigned int_secs = floor(secs);
|
||||
double frac_secs = secs - int_secs;
|
||||
|
||||
retTimeStamp->tv_nsec = floor(baseTimeStamp->tv_nsec + frac_secs * 1000000000);
|
||||
retTimeStamp->tv_sec = baseTimeStamp->tv_sec + int_secs;
|
||||
|
||||
if( retTimeStamp->tv_nsec > 1000000000 )
|
||||
{
|
||||
retTimeStamp->tv_nsec -= 1000000000;
|
||||
retTimeStamp->tv_sec += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -558,21 +576,16 @@ unsigned cw::audio::buf::channelCount( handle_t h, unsigned devIdx, unsigned fla
|
||||
|
||||
void cw::audio::buf::setFlag( handle_t h, unsigned devIdx, unsigned chIdx, unsigned flags )
|
||||
{
|
||||
|
||||
if( devIdx == kInvalidIdx )
|
||||
return;
|
||||
|
||||
audioBuf_t* p = _handleToPtr(h);
|
||||
unsigned idx = flags & kInFl ? kInApIdx : kOutApIdx;
|
||||
bool enableFl = flags & kEnableFl ? true : false;
|
||||
unsigned i = chIdx != kInvalidIdx ? chIdx : 0;
|
||||
unsigned n = chIdx != kInvalidIdx ? chIdx+1 : p->devArray[devIdx].ioArray[idx].chCnt;
|
||||
|
||||
for(; i<n; ++i)
|
||||
{
|
||||
cmApCh* cp = p->devArray[devIdx].ioArray[idx].chArray + i;
|
||||
cp->fl = cwEnaFlag(cp->fl, flags & (kChFl|kToneFl|kMeterFl|kMuteFl|kPassFl), enableFl );
|
||||
}
|
||||
|
||||
if( flags & kInFl )
|
||||
_setFlag( p, devIdx, chIdx, flags, kInApIdx );
|
||||
|
||||
if( flags & kOutFl )
|
||||
_setFlag( p, devIdx, chIdx, flags, kOutApIdx );
|
||||
|
||||
}
|
||||
|
||||
@ -599,12 +612,29 @@ void cw::audio::buf::enableTone( handle_t h, unsigned devIdx, unsigned chIdx,
|
||||
bool cw::audio::buf::isToneEnabled( handle_t h, unsigned devIdx, unsigned chIdx, unsigned flags )
|
||||
{ return isFlag(h,devIdx,chIdx,flags | kToneFl); }
|
||||
|
||||
void cw::audio::buf::toneFlags( handle_t h, unsigned devIdx, unsigned flags, bool* enableFlA, unsigned chCnt )
|
||||
{
|
||||
chCnt = std::min( chCnt, channelCount(h,devIdx,flags));
|
||||
|
||||
for(unsigned i=0; i<chCnt; ++i)
|
||||
enableFlA[i] = isFlag(h, devIdx, i, flags | kToneFl);
|
||||
}
|
||||
|
||||
|
||||
void cw::audio::buf::enableMute( handle_t h, unsigned devIdx, unsigned chIdx, unsigned flags )
|
||||
{ setFlag(h,devIdx,chIdx,flags | kMuteFl); }
|
||||
|
||||
bool cw::audio::buf::isMuteEnabled( handle_t h, unsigned devIdx, unsigned chIdx, unsigned flags )
|
||||
{ return isFlag(h,devIdx,chIdx,flags | kMuteFl); }
|
||||
|
||||
void cw::audio::buf::muteFlags( handle_t h, unsigned devIdx, unsigned flags, bool* muteFlA, unsigned chCnt )
|
||||
{
|
||||
chCnt = std::min( chCnt, channelCount(h,devIdx,flags));
|
||||
|
||||
for(unsigned i=0; i<chCnt; ++i)
|
||||
muteFlA[i] = isFlag(h, devIdx, i, flags | kToneFl);
|
||||
}
|
||||
|
||||
void cw::audio::buf::enablePass( handle_t h, unsigned devIdx, unsigned chIdx, unsigned flags )
|
||||
{ setFlag(h,devIdx,chIdx,flags | kPassFl); }
|
||||
|
||||
@ -647,12 +677,27 @@ double cw::audio::buf::gain( handle_t h, unsigned devIdx, unsigned chIdx, unsign
|
||||
{
|
||||
if( devIdx == kInvalidIdx )
|
||||
return 0;
|
||||
|
||||
audioBuf_t* p = _handleToPtr(h);
|
||||
|
||||
unsigned idx = flags & kInFl ? kInApIdx : kOutApIdx;
|
||||
return p->devArray[devIdx].ioArray[idx].chArray[chIdx].gain;
|
||||
}
|
||||
|
||||
void cw::audio::buf::gain( handle_t h, unsigned devIdx, unsigned flags, double* gainA, unsigned gainN )
|
||||
{
|
||||
if( devIdx == kInvalidIdx )
|
||||
return;
|
||||
|
||||
audioBuf_t* p = _handleToPtr(h);
|
||||
unsigned idx = flags & kInFl ? kInApIdx : kOutApIdx;
|
||||
unsigned n = std::min(gainN,channelCount(h,devIdx,flags));
|
||||
|
||||
for(unsigned i=0; i<n; ++i)
|
||||
gainA[i] = p->devArray[devIdx].ioArray[idx].chArray[i].gain;
|
||||
|
||||
}
|
||||
|
||||
|
||||
unsigned cw::audio::buf::getStatus( handle_t h, unsigned devIdx, unsigned flags, double* meterArray, unsigned meterCnt, unsigned* faultCntPtr )
|
||||
{
|
||||
@ -811,8 +856,6 @@ void cw::audio::buf::advance( handle_t h, unsigned devIdx, unsigned flags )
|
||||
cmApCh* cp = ioPtr->chArray + i;
|
||||
cp->oi = (cp->oi + ioPtr->dspFrameCnt) % ioPtr->n;
|
||||
atomicUIntDecr(&cp->fn,ioPtr->dspFrameCnt);
|
||||
|
||||
|
||||
}
|
||||
|
||||
// count the number of samples input from this device
|
||||
@ -830,7 +873,6 @@ void cw::audio::buf::advance( handle_t h, unsigned devIdx, unsigned flags )
|
||||
cmApCh* cp = ioPtr->chArray + i;
|
||||
cp->ii = (cp->ii + ioPtr->dspFrameCnt) % ioPtr->n;
|
||||
atomicUIntIncr(&cp->fn,ioPtr->dspFrameCnt);
|
||||
|
||||
}
|
||||
|
||||
// count the number of samples output from this device
|
||||
|
39
cwAudioBuf.h
39
cwAudioBuf.h
@ -45,7 +45,21 @@ namespace cw
|
||||
|
||||
typedef device::sample_t sample_t;
|
||||
typedef handle<struct audioBuf_str> handle_t;
|
||||
|
||||
|
||||
// Channel flags
|
||||
enum
|
||||
{
|
||||
kInFl = 0x01, //< Identify an input channel
|
||||
kOutFl = 0x02, //< Identify an output channel
|
||||
kEnableFl = 0x04, //< Set to enable a channel, Clear to disable.
|
||||
|
||||
kChFl = 0x08, //< Used to enable/disable a channel
|
||||
kMuteFl = 0x10, //< Mute this channel
|
||||
kToneFl = 0x20, //< Generate a tone on this channel
|
||||
kMeterFl = 0x40, //< Turn meter's on/off
|
||||
kPassFl = 0x80 //< Pass input channels throught to the output. Must use getIO() to implement this functionality.
|
||||
|
||||
};
|
||||
|
||||
// Allocate and initialize an audio buffer.
|
||||
// devCnt - count of devices this buffer will handle.
|
||||
@ -97,21 +111,6 @@ namespace cw
|
||||
device::audioPacket_t* outPktArray, //< empty audio packet for outgoing audio (to DAC)
|
||||
unsigned outPktCnt); //< count of outgoing audio packets
|
||||
|
||||
// Channel flags
|
||||
enum
|
||||
{
|
||||
kInFl = 0x01, //< Identify an input channel
|
||||
kOutFl = 0x02, //< Identify an output channel
|
||||
kEnableFl = 0x04, //< Set to enable a channel, Clear to disable.
|
||||
|
||||
kChFl = 0x08, //< Used to enable/disable a channel
|
||||
kMuteFl = 0x10, //< Mute this channel
|
||||
kToneFl = 0x20, //< Generate a tone on this channel
|
||||
kMeterFl = 0x40, //< Turn meter's on/off
|
||||
kPassFl = 0x80 //< Pass input channels throught to the output. Must use getIO() to implement this functionality.
|
||||
|
||||
};
|
||||
|
||||
// Return the meter window period as set by initialize()
|
||||
unsigned meterMs(handle_t h);
|
||||
|
||||
@ -122,7 +121,7 @@ namespace cw
|
||||
unsigned channelCount( handle_t h, unsigned devIdx, unsigned flags );
|
||||
|
||||
// Set chIdx to -1 to enable all channels on this device.
|
||||
// Set flags to {kInFl | kOutFl} | {kChFl | kToneFl | kMeterFl} | { kEnableFl=on | 0=off }
|
||||
// Set flags to kInFl | kOutFl | {kChFl | kToneFl | kMeterFl} | { kEnableFl=on | 0=off }
|
||||
void setFlag( handle_t h, unsigned devIdx, unsigned chIdx, unsigned flags );
|
||||
|
||||
// Return true if the the flags is set.
|
||||
@ -141,6 +140,7 @@ namespace cw
|
||||
|
||||
// Returns true if an input/output tone is enabled on the specified device.
|
||||
bool isToneEnabled(handle_t h, unsigned devIdx, unsigned chIdx, unsigned flags );
|
||||
void toneFlags( handle_t h, unsigned devIdx, unsigned flags, bool* enableFlA, unsigned enableFlN );
|
||||
|
||||
// Mute a specified channel.
|
||||
// Set chIdx to -1 to apply the change to all channels on this device.
|
||||
@ -148,7 +148,8 @@ namespace cw
|
||||
void enableMute( handle_t h, unsigned devIdx, unsigned chIdx, unsigned flags );
|
||||
|
||||
// Returns true if an input/output channel is muted on the specified device.
|
||||
bool isMuteEnabled(handle_t h, unsigned devIdx, unsigned chIdx, unsigned flags );
|
||||
bool isMuteEnabled(handle_t h, unsigned devIdx, unsigned chIdx, unsigned flags );
|
||||
void muteFlags( handle_t h, unsigned devIdx, unsigned flags, bool* muteFlA, unsigned muteFlN );
|
||||
|
||||
// Set the specified channel to pass through.
|
||||
// Set chIdx to -1 to apply the change to all channels on this device.
|
||||
@ -175,7 +176,9 @@ namespace cw
|
||||
|
||||
// Return the current gain seting for the specified channel.
|
||||
double gain( handle_t h, unsigned devIdx, unsigned chIdx, unsigned flags );
|
||||
void gain( handle_t h, unsigned devIdx, unsigned flags, double* gainA, unsigned gainN );
|
||||
|
||||
|
||||
// Get the meter and fault status of the channel input or output channel array of a device.
|
||||
// Set 'flags' to { kInFl | kOutFl }.
|
||||
// The returns value is the count of channels actually written to meterArray.
|
||||
|
Loading…
Reference in New Issue
Block a user