@ -38,6 +38,8 @@ FullRateVoice::FullRateVoice() :
{
{
imbeData = new uint8_t [ IMBE_BUF_LEN ] ;
imbeData = new uint8_t [ IMBE_BUF_LEN ] ;
: : memset ( imbeData , 0x00U , IMBE_BUF_LEN ) ;
: : memset ( imbeData , 0x00U , IMBE_BUF_LEN ) ;
additionalData = new uint8_t [ ADDITIONAL_LENGTH ] ;
: : memset ( additionalData , 0x00U , ADDITIONAL_LENGTH ) ;
}
}
/* Initializes a instance of the FullRateVoice class. */
/* Initializes a instance of the FullRateVoice class. */
@ -65,6 +67,21 @@ FullRateVoice::~FullRateVoice()
delete [ ] additionalData ;
delete [ ] additionalData ;
}
}
/* */
uint8_t FullRateVoice : : getLength ( )
{
if ( isVoice9or18 ( ) ) {
return LENGTH_918 ;
}
if ( isVoice3thru8 ( ) | | isVoice12thru17 ( ) ) {
return LENGTH ;
}
return LENGTH_121011 ;
}
/* Decode a full rate voice frame. */
/* Decode a full rate voice frame. */
bool FullRateVoice : : decode ( const uint8_t * data )
bool FullRateVoice : : decode ( const uint8_t * data )
@ -85,25 +102,14 @@ bool FullRateVoice::decode(const uint8_t* data)
m_superframeCnt = ( uint8_t ) ( ( data [ 13U ] > > 2 ) & 0x03U ) ; // Superframe Counter
m_superframeCnt = ( uint8_t ) ( ( data [ 13U ] > > 2 ) & 0x03U ) ; // Superframe Counter
m_busy = ( uint8_t ) ( data [ 13U ] & 0x03U ) ;
m_busy = ( uint8_t ) ( data [ 13U ] & 0x03U ) ;
if ( isVoice3thru8 ( ) | | isVoice12thru17 ( ) | | isVoice9or10 ( ) ) {
if ( isVoice3thru8 ( ) | | isVoice12thru17 ( ) | | isVoice9or18 ( ) ) {
if ( additionalData ! = nullptr )
delete additionalData ;
additionalData = new uint8_t [ ADDITIONAL_LENGTH ] ;
: : memset ( additionalData , 0x00U , ADDITIONAL_LENGTH ) ;
: : memset ( additionalData , 0x00U , ADDITIONAL_LENGTH ) ;
if ( isVoice9or1 0 ( ) ) {
if ( isVoice9or18 ( ) ) {
// CAI 9 and 1 0 are 3 bytes of additional data not 4
// CAI 9 and 1 8 are 3 bytes of additional data not 4
: : memcpy ( additionalData , data + 14U , ADDITIONAL_LENGTH - 1U ) ;
: : memcpy ( additionalData , data + 14U , ADDITIONAL_LENGTH - 1U ) ;
} else {
} else {
uint8_t buffer [ ADDITIONAL_LENGTH - 1U ] ;
: : memcpy ( additionalData , data + 14U , ADDITIONAL_LENGTH ) ;
: : memset ( buffer , 0x00U , ADDITIONAL_LENGTH - 1U ) ;
: : memcpy ( buffer , data + 14U , ADDITIONAL_LENGTH - 1U ) ;
buffer [ 2U ] & = 0xC0U ; // mask low bits
uint32_t offset = 0 ;
for ( uint8_t i = 0 ; i < ADDITIONAL_LENGTH - 1U ; i + + , offset + = 6 ) {
Utils : : hex2Bin ( additionalData [ i ] , buffer , offset ) ;
}
}
}
} else {
} else {
if ( additionalData ! = nullptr )
if ( additionalData ! = nullptr )
@ -130,22 +136,12 @@ void FullRateVoice::encode(uint8_t* data)
data [ 13U ] = ( uint8_t ) ( ( ( m_superframeCnt & 0x03U ) < < 2 ) + // Superframe Count
data [ 13U ] = ( uint8_t ) ( ( ( m_superframeCnt & 0x03U ) < < 2 ) + // Superframe Count
( m_busy & 0x03U ) ) ; // Busy Status
( m_busy & 0x03U ) ) ; // Busy Status
if ( ( isVoice3thru8 ( ) | | isVoice12thru17 ( ) | | isVoice9or10 ( ) ) & &
if ( isVoice3thru8 ( ) | | isVoice12thru17 ( ) | | isVoice9or18 ( ) ) {
additionalData ! = nullptr ) {
if ( isVoice9or18 ( ) ) {
if ( isVoice9or10 ( ) ) {
// CAI 9 and 18 are 3 bytes of additional data not 4
// CAI 9 and 10 are 3 bytes of additional data not 4
: : memcpy ( data + 14U , additionalData , ADDITIONAL_LENGTH - 1U ) ;
: : memcpy ( data + 14U , additionalData , ADDITIONAL_LENGTH - 1U ) ;
} else {
} else {
uint8_t buffer [ ADDITIONAL_LENGTH - 1U ] ;
: : memcpy ( data + 14U , additionalData , ADDITIONAL_LENGTH ) ;
: : memset ( buffer , 0x00U , ADDITIONAL_LENGTH - 1U ) ;
: : memcpy ( buffer , additionalData , ADDITIONAL_LENGTH - 1U ) ;
uint32_t offset = 0 ;
for ( uint8_t i = 0 ; i < ADDITIONAL_LENGTH - 1U ; i + + , offset + = 6 ) {
buffer [ i ] = Utils : : bin2Hex ( additionalData , offset ) ;
}
: : memcpy ( data + 14U , buffer , ADDITIONAL_LENGTH - 1U ) ;
}
}
}
}
}
}
@ -180,9 +176,9 @@ bool FullRateVoice::isVoice12thru17()
/* Helper indicating if the frame is voice 9 or 10. */
/* Helper indicating if the frame is voice 9 or 10. */
bool FullRateVoice : : isVoice9or1 0 ( )
bool FullRateVoice : : isVoice9or1 8 ( )
{
{
if ( ( m_frameType = = DFSIFrameType : : LDU1_VOICE9 ) | | ( m_frameType = = DFSIFrameType : : LDU2_VOICE1 0 ) ) {
if ( ( m_frameType = = DFSIFrameType : : LDU1_VOICE9 ) | | ( m_frameType = = DFSIFrameType : : LDU2_VOICE1 8 ) ) {
return true ;
return true ;
} else {
} else {
return false ;
return false ;