@ -26,7 +26,7 @@
//#define DEBUG
//#define DEBUG
const u nsigned in t IMBE_INTERLEAVE [ ] = {
const u int32_ t IMBE_INTERLEAVE [ ] = {
0 , 7 , 12 , 19 , 24 , 31 , 36 , 43 , 48 , 55 , 60 , 67 , 72 , 79 , 84 , 91 , 96 , 103 , 108 , 115 , 120 , 127 , 132 , 139 ,
0 , 7 , 12 , 19 , 24 , 31 , 36 , 43 , 48 , 55 , 60 , 67 , 72 , 79 , 84 , 91 , 96 , 103 , 108 , 115 , 120 , 127 , 132 , 139 ,
1 , 6 , 13 , 18 , 25 , 30 , 37 , 42 , 49 , 54 , 61 , 66 , 73 , 78 , 85 , 90 , 97 , 102 , 109 , 114 , 121 , 126 , 133 , 138 ,
1 , 6 , 13 , 18 , 25 , 30 , 37 , 42 , 49 , 54 , 61 , 66 , 73 , 78 , 85 , 90 , 97 , 102 , 109 , 114 , 121 , 126 , 133 , 138 ,
2 , 9 , 14 , 21 , 26 , 33 , 38 , 45 , 50 , 57 , 62 , 69 , 74 , 81 , 86 , 93 , 98 , 105 , 110 , 117 , 122 , 129 , 134 , 141 ,
2 , 9 , 14 , 21 , 26 , 33 , 38 , 45 , 50 , 57 , 62 , 69 , 74 , 81 , 86 , 93 , 98 , 105 , 110 , 117 , 122 , 129 , 134 , 141 ,
@ -41,7 +41,7 @@ const int dvsi_interleave[49] = {
2 , 5 , 8 , 11 , 14 , 17 , 20 , 23 , 26 , 29 , 32 , 35 , 38
2 , 5 , 8 , 11 , 14 , 17 , 20 , 23 , 26 , 29 , 32 , 35 , 38
} ;
} ;
const u nsigned in t INTERLEAVE_TABLE_5_20 [ ] = {
const u int32_ t INTERLEAVE_TABLE_5_20 [ ] = {
0U , 40U , 80U , 120U , 160U ,
0U , 40U , 80U , 120U , 160U ,
2U , 42U , 82U , 122U , 162U ,
2U , 42U , 82U , 122U , 162U ,
4U , 44U , 84U , 124U , 164U ,
4U , 44U , 84U , 124U , 164U ,
@ -63,7 +63,7 @@ const unsigned int INTERLEAVE_TABLE_5_20[] = {
36U , 76U , 116U , 156U , 196U ,
36U , 76U , 116U , 156U , 196U ,
38U , 78U , 118U , 158U , 198U } ;
38U , 78U , 118U , 158U , 198U } ;
const u nsigned in t INTERLEAVE_TABLE_9_20 [ ] = {
const u int32_ t INTERLEAVE_TABLE_9_20 [ ] = {
0U , 40U , 80U , 120U , 160U , 200U , 240U , 280U , 320U ,
0U , 40U , 80U , 120U , 160U , 200U , 240U , 280U , 320U ,
2U , 42U , 82U , 122U , 162U , 202U , 242U , 282U , 322U ,
2U , 42U , 82U , 122U , 162U , 202U , 242U , 282U , 322U ,
4U , 44U , 84U , 124U , 164U , 204U , 244U , 284U , 324U ,
4U , 44U , 84U , 124U , 164U , 204U , 244U , 284U , 324U ,
@ -85,16 +85,16 @@ const unsigned int INTERLEAVE_TABLE_9_20[] = {
36U , 76U , 116U , 156U , 196U , 236U , 276U , 316U , 356U ,
36U , 76U , 116U , 156U , 196U , 236U , 276U , 316U , 356U ,
38U , 78U , 118U , 158U , 198U , 238U , 278U , 318U , 358U } ;
38U , 78U , 118U , 158U , 198U , 238U , 278U , 318U , 358U } ;
const u nsigned in t INTERLEAVE_TABLE_26_4 [ ] = {
const u int32_ t INTERLEAVE_TABLE_26_4 [ ] = {
0U , 4U , 8U , 12U , 16U , 20U , 24U , 28U , 32U , 36U , 40U , 44U , 48U , 52U , 56U , 60U , 64U , 68U , 72U , 76U , 80U , 84U , 88U , 92U , 96U , 100U ,
0U , 4U , 8U , 12U , 16U , 20U , 24U , 28U , 32U , 36U , 40U , 44U , 48U , 52U , 56U , 60U , 64U , 68U , 72U , 76U , 80U , 84U , 88U , 92U , 96U , 100U ,
1U , 5U , 9U , 13U , 17U , 21U , 25U , 29U , 33U , 37U , 41U , 45U , 49U , 53U , 57U , 61U , 65U , 69U , 73U , 77U , 81U , 85U , 89U , 93U , 97U , 101U ,
1U , 5U , 9U , 13U , 17U , 21U , 25U , 29U , 33U , 37U , 41U , 45U , 49U , 53U , 57U , 61U , 65U , 69U , 73U , 77U , 81U , 85U , 89U , 93U , 97U , 101U ,
2U , 6U , 10U , 14U , 18U , 22U , 26U , 30U , 34U , 38U , 42U , 46U , 50U , 54U , 58U , 62U , 66U , 70U , 74U , 78U , 82U , 86U , 90U , 94U , 98U , 102U ,
2U , 6U , 10U , 14U , 18U , 22U , 26U , 30U , 34U , 38U , 42U , 46U , 50U , 54U , 58U , 62U , 66U , 70U , 74U , 78U , 82U , 86U , 90U , 94U , 98U , 102U ,
3U , 7U , 11U , 15U , 19U , 23U , 27U , 31U , 35U , 39U , 43U , 47U , 51U , 55U , 59U , 63U , 67U , 71U , 75U , 79U , 83U , 87U , 91U , 95U , 99U , 103U } ;
3U , 7U , 11U , 15U , 19U , 23U , 27U , 31U , 35U , 39U , 43U , 47U , 51U , 55U , 59U , 63U , 67U , 71U , 75U , 79U , 83U , 87U , 91U , 95U , 99U , 103U } ;
const u nsigned char WHITENING_DATA [ ] = { 0x93U , 0xD7U , 0x51U , 0x21U , 0x9CU , 0x2FU , 0x6CU , 0xD0U , 0xEFU , 0x0FU ,
const u int32_t WHITENING_DATA [ ] = { 0x93U , 0xD7U , 0x51U , 0x21U , 0x9CU , 0x2FU , 0x6CU , 0xD0U , 0xEFU , 0x0FU ,
0xF8U , 0x3DU , 0xF1U , 0x73U , 0x20U , 0x94U , 0xEDU , 0x1EU , 0x7CU , 0xD8U } ;
0xF8U , 0x3DU , 0xF1U , 0x73U , 0x20U , 0x94U , 0xEDU , 0x1EU , 0x7CU , 0xD8U } ;
const u nsigned char BIT_MASK_TABLE [ ] = { 0x80U , 0x40U , 0x20U , 0x10U , 0x08U , 0x04U , 0x02U , 0x01U } ;
const u int8_t BIT_MASK_TABLE [ ] = { 0x80U , 0x40U , 0x20U , 0x10U , 0x08U , 0x04U , 0x02U , 0x01U } ;
# define WRITE_BIT(p,i,b) p[(i)>>3] = (b) ? (p[(i)>>3] | BIT_MASK_TABLE[(i)&7]) : (p[(i)>>3] & ~BIT_MASK_TABLE[(i)&7])
# define WRITE_BIT(p,i,b) p[(i)>>3] = (b) ? (p[(i)>>3] | BIT_MASK_TABLE[(i)&7]) : (p[(i)>>3] & ~BIT_MASK_TABLE[(i)&7])
# define READ_BIT(p,i) (p[(i)>>3] & BIT_MASK_TABLE[(i)&7])
# define READ_BIT(p,i) (p[(i)>>3] & BIT_MASK_TABLE[(i)&7])
@ -148,6 +148,7 @@ void YSFCodec::process_udp()
m_modeinfo . hw_vocoder_loaded = true ;
m_modeinfo . hw_vocoder_loaded = true ;
m_ambedev = new SerialAMBE ( " YSF " ) ;
m_ambedev = new SerialAMBE ( " YSF " ) ;
m_ambedev - > connect_to_serial ( m_vocoder ) ;
m_ambedev - > connect_to_serial ( m_vocoder ) ;
connect ( m_ambedev , SIGNAL ( connected ( bool ) ) , this , SLOT ( ambe_connect_status ( bool ) ) ) ;
connect ( m_ambedev , SIGNAL ( data_ready ( ) ) , this , SLOT ( get_ambe ( ) ) ) ;
connect ( m_ambedev , SIGNAL ( data_ready ( ) ) , this , SLOT ( get_ambe ( ) ) ) ;
}
}
else {
else {
@ -160,6 +161,7 @@ void YSFCodec::process_udp()
m_modem - > set_modem_flags ( m_rxInvert , m_txInvert , m_pttInvert , m_useCOSAsLockout , m_duplex ) ;
m_modem - > set_modem_flags ( m_rxInvert , m_txInvert , m_pttInvert , m_useCOSAsLockout , m_duplex ) ;
m_modem - > set_modem_params ( m_rxfreq , m_txfreq , m_txDelay , m_rxLevel , m_rfLevel , m_ysfTXHang , m_cwIdTXLevel , m_dstarTXLevel , m_dmrTXLevel , m_ysfTXLevel , m_p25TXLevel , m_nxdnTXLevel , m_pocsagTXLevel , m_m17TXLevel ) ;
m_modem - > set_modem_params ( m_rxfreq , m_txfreq , m_txDelay , m_rxLevel , m_rfLevel , m_ysfTXHang , m_cwIdTXLevel , m_dstarTXLevel , m_dmrTXLevel , m_ysfTXLevel , m_p25TXLevel , m_nxdnTXLevel , m_pocsagTXLevel , m_m17TXLevel ) ;
m_modem - > connect_to_serial ( m_modemport ) ;
m_modem - > connect_to_serial ( m_modemport ) ;
connect ( m_modem , SIGNAL ( connected ( bool ) ) , this , SLOT ( mmdvm_connect_status ( bool ) ) ) ;
connect ( m_modem , SIGNAL ( modem_data_ready ( QByteArray ) ) , this , SLOT ( process_modem_data ( QByteArray ) ) ) ;
connect ( m_modem , SIGNAL ( modem_data_ready ( QByteArray ) ) , this , SLOT ( process_modem_data ( QByteArray ) ) ) ;
}
}
@ -257,7 +259,7 @@ void YSFCodec::process_udp()
if ( m_modeinfo . type = = 3 ) {
if ( m_modeinfo . type = = 3 ) {
decode_vw ( p_data ) ;
decode_vw ( p_data ) ;
}
}
else {
else if ( m_modeinfo . type ! = 1 ) {
decode_dn ( p_data ) ;
decode_dn ( p_data ) ;
}
}
}
}
@ -371,64 +373,65 @@ void YSFCodec::decode_vw(uint8_t* data)
data + = YSF_SYNC_LENGTH_BYTES + YSF_FICH_LENGTH_BYTES ;
data + = YSF_SYNC_LENGTH_BYTES + YSF_FICH_LENGTH_BYTES ;
u nsigned in t offset = 0U ;
u int32_ t offset = 0U ;
// We have a total of 5 VCH sections, iterate through each
// We have a total of 5 VCH sections, iterate through each
for ( u nsigned in t j = 0U ; j < 5U ; j + + , offset + = 18U ) {
for ( u int32_ t j = 0U ; j < 5U ; j + + , offset + = 18U ) {
: : memcpy ( vch , data + offset , 18U ) ;
: : memcpy ( vch , data + offset , 18U ) ;
for ( u nsigned in t i = 0U ; i < 144U ; i + + ) {
for ( u int32_ t i = 0U ; i < 144U ; i + + ) {
u nsigned in t n = IMBE_INTERLEAVE [ i ] ;
u int32_ t n = IMBE_INTERLEAVE [ i ] ;
bit [ i ] = READ_BIT ( vch , n ) ;
bit [ i ] = READ_BIT ( vch , n ) ;
}
}
u nsigned in t c0data = 0U ;
u int32_ t c0data = 0U ;
for ( u nsigned in t i = 0U ; i < 12U ; i + + )
for ( u int32_ t i = 0U ; i < 12U ; i + + )
c0data = ( c0data < < 1 ) | ( bit [ i ] ? 0x01U : 0x00U ) ;
c0data = ( c0data < < 1 ) | ( bit [ i ] ? 0x01U : 0x00U ) ;
bool prn [ 114U ] ;
bool prn [ 114U ] ;
// Create the whitening vector and save it for future use
// Create the whitening vector and save it for future use
u nsigned in t p = 16U * c0data ;
u int32_ t p = 16U * c0data ;
for ( u nsigned in t i = 0U ; i < 114U ; i + + ) {
for ( u int32_ t i = 0U ; i < 114U ; i + + ) {
p = ( 173U * p + 13849U ) % 65536U ;
p = ( 173U * p + 13849U ) % 65536U ;
prn [ i ] = p > = 32768U ;
prn [ i ] = p > = 32768U ;
}
}
// De-whiten some bits
// De-whiten some bits
for ( u nsigned in t i = 0U ; i < 114U ; i + + )
for ( u int32_ t i = 0U ; i < 114U ; i + + )
bit [ i + 23U ] ^ = prn [ i ] ;
bit [ i + 23U ] ^ = prn [ i ] ;
u nsigned in t offset = 0U ;
u int32_ t offset = 0U ;
for ( u nsigned in t i = 0U ; i < 12U ; i + + , offset + + )
for ( u int32_ t i = 0U ; i < 12U ; i + + , offset + + )
WRITE_BIT ( imbe , offset , bit [ i + 0U ] ) ;
WRITE_BIT ( imbe , offset , bit [ i + 0U ] ) ;
for ( u nsigned in t i = 0U ; i < 12U ; i + + , offset + + )
for ( u int32_ t i = 0U ; i < 12U ; i + + , offset + + )
WRITE_BIT ( imbe , offset , bit [ i + 23U ] ) ;
WRITE_BIT ( imbe , offset , bit [ i + 23U ] ) ;
for ( u nsigned in t i = 0U ; i < 12U ; i + + , offset + + )
for ( u int32_ t i = 0U ; i < 12U ; i + + , offset + + )
WRITE_BIT ( imbe , offset , bit [ i + 46U ] ) ;
WRITE_BIT ( imbe , offset , bit [ i + 46U ] ) ;
for ( u nsigned in t i = 0U ; i < 12U ; i + + , offset + + )
for ( u int32_ t i = 0U ; i < 12U ; i + + , offset + + )
WRITE_BIT ( imbe , offset , bit [ i + 69U ] ) ;
WRITE_BIT ( imbe , offset , bit [ i + 69U ] ) ;
for ( u nsigned in t i = 0U ; i < 11U ; i + + , offset + + )
for ( u int32_ t i = 0U ; i < 11U ; i + + , offset + + )
WRITE_BIT ( imbe , offset , bit [ i + 92U ] ) ;
WRITE_BIT ( imbe , offset , bit [ i + 92U ] ) ;
for ( u nsigned in t i = 0U ; i < 11U ; i + + , offset + + )
for ( u int32_ t i = 0U ; i < 11U ; i + + , offset + + )
WRITE_BIT ( imbe , offset , bit [ i + 107U ] ) ;
WRITE_BIT ( imbe , offset , bit [ i + 107U ] ) ;
for ( u nsigned in t i = 0U ; i < 11U ; i + + , offset + + )
for ( u int32_ t i = 0U ; i < 11U ; i + + , offset + + )
WRITE_BIT ( imbe , offset , bit [ i + 122U ] ) ;
WRITE_BIT ( imbe , offset , bit [ i + 122U ] ) ;
for ( u nsigned in t i = 0U ; i < 7U ; i + + , offset + + )
for ( u int32_ t i = 0U ; i < 7U ; i + + , offset + + )
WRITE_BIT ( imbe , offset , bit [ i + 137U ] ) ;
WRITE_BIT ( imbe , offset , bit [ i + 137U ] ) ;
for ( int i = 0 ; i < 11 ; + + i ) {
for ( int i = 0 ; i < 11 ; + + i ) {
m_rxcodecq . append ( imbe [ i ] ) ;
m_rximbecodecq . append ( imbe [ i ] ) ;
//m_rxcodecq.append(imbe[i]);
}
}
}
}
}
}
void YSFCodec : : decode_vd1 ( uint8_t * data , uint8_t * dt )
void YSFCodec : : decode_vd1 ( uint8_t * data , uint8_t * dt )
{
{
u nsigned char dch [ 45U ] ;
u int8_t dch [ 45U ] ;
const u nsigned char * p1 = data ;
const u int8_t * p1 = data ;
u nsigned char * p2 = dch ;
u int8_t * p2 = dch ;
for ( u nsigned in t i = 0U ; i < 5U ; i + + ) {
for ( u int32_ t i = 0U ; i < 5U ; i + + ) {
: : memcpy ( p2 , p1 , 9U ) ;
: : memcpy ( p2 , p1 , 9U ) ;
p1 + = 18U ; p2 + = 9U ;
p1 + = 18U ; p2 + = 9U ;
}
}
@ -436,8 +439,8 @@ void YSFCodec::decode_vd1(uint8_t* data, uint8_t *dt)
CYSFConvolution conv ;
CYSFConvolution conv ;
conv . start ( ) ;
conv . start ( ) ;
for ( u nsigned in t i = 0U ; i < 180U ; i + + ) {
for ( u int32_ t i = 0U ; i < 180U ; i + + ) {
u nsigned in t n = INTERLEAVE_TABLE_9_20 [ i ] ;
u int32_ t n = INTERLEAVE_TABLE_9_20 [ i ] ;
uint8_t s0 = READ_BIT ( dch , n ) ? 1U : 0U ;
uint8_t s0 = READ_BIT ( dch , n ) ? 1U : 0U ;
n + + ;
n + + ;
@ -446,12 +449,12 @@ void YSFCodec::decode_vd1(uint8_t* data, uint8_t *dt)
conv . decode ( s0 , s1 ) ;
conv . decode ( s0 , s1 ) ;
}
}
u nsigned char output [ 23U ] ;
u int8_t output [ 23U ] ;
conv . chainback ( output , 176U ) ;
conv . chainback ( output , 176U ) ;
bool ret = CCRC : : checkCCITT162 ( output , 22U ) ;
bool ret = CCRC : : checkCCITT162 ( output , 22U ) ;
if ( ret ) {
if ( ret ) {
for ( u nsigned in t i = 0U ; i < 20U ; i + + ) {
for ( u int32_ t i = 0U ; i < 20U ; i + + ) {
output [ i ] ^ = WHITENING_DATA [ i ] ;
output [ i ] ^ = WHITENING_DATA [ i ] ;
}
}
: : memcpy ( dt , output , 20U ) ;
: : memcpy ( dt , output , 20U ) ;
@ -460,11 +463,11 @@ void YSFCodec::decode_vd1(uint8_t* data, uint8_t *dt)
void YSFCodec : : decode_vd2 ( uint8_t * data , uint8_t * dt )
void YSFCodec : : decode_vd2 ( uint8_t * data , uint8_t * dt )
{
{
u nsigned char dch [ 25U ] ;
u int8_t dch [ 25U ] ;
const u nsigned char * p1 = data ;
const u int8_t * p1 = data ;
u nsigned char * p2 = dch ;
u int8_t * p2 = dch ;
for ( u nsigned in t i = 0U ; i < 5U ; i + + ) {
for ( u int32_ t i = 0U ; i < 5U ; i + + ) {
: : memcpy ( p2 , p1 , 5U ) ;
: : memcpy ( p2 , p1 , 5U ) ;
p1 + = 18U ; p2 + = 5U ;
p1 + = 18U ; p2 + = 5U ;
}
}
@ -472,8 +475,8 @@ void YSFCodec::decode_vd2(uint8_t* data, uint8_t *dt)
CYSFConvolution conv ;
CYSFConvolution conv ;
conv . start ( ) ;
conv . start ( ) ;
for ( u nsigned in t i = 0U ; i < 100U ; i + + ) {
for ( u int32_ t i = 0U ; i < 100U ; i + + ) {
u nsigned in t n = INTERLEAVE_TABLE_5_20 [ i ] ;
u int32_ t n = INTERLEAVE_TABLE_5_20 [ i ] ;
uint8_t s0 = READ_BIT ( dch , n ) ? 1U : 0U ;
uint8_t s0 = READ_BIT ( dch , n ) ? 1U : 0U ;
n + + ;
n + + ;
@ -482,12 +485,12 @@ void YSFCodec::decode_vd2(uint8_t* data, uint8_t *dt)
conv . decode ( s0 , s1 ) ;
conv . decode ( s0 , s1 ) ;
}
}
u nsigned char output [ 13U ] ;
u int8_t output [ 13U ] ;
conv . chainback ( output , 96U ) ;
conv . chainback ( output , 96U ) ;
bool ret = CCRC : : checkCCITT162 ( output , 12U ) ;
bool ret = CCRC : : checkCCITT162 ( output , 12U ) ;
if ( ret ) {
if ( ret ) {
for ( u nsigned in t i = 0U ; i < 10U ; i + + ) {
for ( u int32_ t i = 0U ; i < 10U ; i + + ) {
output [ i ] ^ = WHITENING_DATA [ i ] ;
output [ i ] ^ = WHITENING_DATA [ i ] ;
}
}
: : memcpy ( dt , output , YSF_CALLSIGN_LENGTH ) ;
: : memcpy ( dt , output , YSF_CALLSIGN_LENGTH ) ;
@ -747,7 +750,7 @@ void YSFCodec::send_frame()
void YSFCodec : : encode_header ( bool eot )
void YSFCodec : : encode_header ( bool eot )
{
{
u nsigned char callsign [ 12 ] ;
u int8_t callsign [ 12 ] ;
: : memcpy ( callsign , " " , 10 ) ;
: : memcpy ( callsign , " " , 10 ) ;
: : memcpy ( callsign , m_modeinfo . callsign . toStdString ( ) . c_str ( ) , : : strlen ( m_modeinfo . callsign . toStdString ( ) . c_str ( ) ) ) ;
: : memcpy ( callsign , m_modeinfo . callsign . toStdString ( ) . c_str ( ) , : : strlen ( m_modeinfo . callsign . toStdString ( ) . c_str ( ) ) ) ;
@ -802,7 +805,7 @@ void YSFCodec::encode_header(bool eot)
void YSFCodec : : encode_vw ( )
void YSFCodec : : encode_vw ( )
{
{
u nsigned char callsign [ 12 ] ;
u int8_t callsign [ 12 ] ;
: : memcpy ( callsign , " " , 10 ) ;
: : memcpy ( callsign , " " , 10 ) ;
: : memcpy ( callsign , m_modeinfo . callsign . toStdString ( ) . c_str ( ) , : : strlen ( m_modeinfo . callsign . toStdString ( ) . c_str ( ) ) ) ;
: : memcpy ( callsign , m_modeinfo . callsign . toStdString ( ) . c_str ( ) , : : strlen ( m_modeinfo . callsign . toStdString ( ) . c_str ( ) ) ) ;
uint8_t * p_frame = m_ysfFrame ;
uint8_t * p_frame = m_ysfFrame ;
@ -857,18 +860,18 @@ void YSFCodec::encode_vw()
}
}
}
}
void YSFCodec : : encode_imbe ( u nsigned char * data , const unsigned char * imbe )
void YSFCodec : : encode_imbe ( u int8_t* data , const uint8_t * imbe )
{
{
bool bTemp [ 144U ] ;
bool bTemp [ 144U ] ;
bool * bit = bTemp ;
bool * bit = bTemp ;
// c0
// c0
u nsigned in t c0 = 0U ;
u int32_ t c0 = 0U ;
for ( u nsigned in t i = 0U ; i < 12U ; i + + ) {
for ( u int32_ t i = 0U ; i < 12U ; i + + ) {
bool b = READ_BIT ( imbe , i ) ;
bool b = READ_BIT ( imbe , i ) ;
c0 = ( c0 < < 1 ) | ( b ? 0x01U : 0x00U ) ;
c0 = ( c0 < < 1 ) | ( b ? 0x01U : 0x00U ) ;
}
}
u nsigned in t g2 = CGolay24128 : : encode23127 ( c0 ) ;
u int32_ t g2 = CGolay24128 : : encode23127 ( c0 ) ;
for ( int i = 23 ; i > = 0 ; i - - ) {
for ( int i = 23 ; i > = 0 ; i - - ) {
bit [ i ] = ( g2 & 0x01U ) = = 0x01U ;
bit [ i ] = ( g2 & 0x01U ) = = 0x01U ;
g2 > > = 1 ;
g2 > > = 1 ;
@ -876,8 +879,8 @@ void YSFCodec::encode_imbe(unsigned char* data, const unsigned char* imbe)
bit + = 23U ;
bit + = 23U ;
// c1
// c1
u nsigned in t c1 = 0U ;
u int32_ t c1 = 0U ;
for ( u nsigned in t i = 12U ; i < 24U ; i + + ) {
for ( u int32_ t i = 12U ; i < 24U ; i + + ) {
bool b = READ_BIT ( imbe , i ) ;
bool b = READ_BIT ( imbe , i ) ;
c1 = ( c1 < < 1 ) | ( b ? 0x01U : 0x00U ) ;
c1 = ( c1 < < 1 ) | ( b ? 0x01U : 0x00U ) ;
}
}
@ -889,8 +892,8 @@ void YSFCodec::encode_imbe(unsigned char* data, const unsigned char* imbe)
bit + = 23U ;
bit + = 23U ;
// c2
// c2
u nsigned in t c2 = 0 ;
u int32_ t c2 = 0 ;
for ( u nsigned in t i = 24U ; i < 36U ; i + + ) {
for ( u int32_ t i = 24U ; i < 36U ; i + + ) {
bool b = READ_BIT ( imbe , i ) ;
bool b = READ_BIT ( imbe , i ) ;
c2 = ( c2 < < 1 ) | ( b ? 0x01U : 0x00U ) ;
c2 = ( c2 < < 1 ) | ( b ? 0x01U : 0x00U ) ;
}
}
@ -902,8 +905,8 @@ void YSFCodec::encode_imbe(unsigned char* data, const unsigned char* imbe)
bit + = 23U ;
bit + = 23U ;
// c3
// c3
u nsigned in t c3 = 0U ;
u int32_ t c3 = 0U ;
for ( u nsigned in t i = 36U ; i < 48U ; i + + ) {
for ( u int32_ t i = 36U ; i < 48U ; i + + ) {
bool b = READ_BIT ( imbe , i ) ;
bool b = READ_BIT ( imbe , i ) ;
c3 = ( c3 < < 1 ) | ( b ? 0x01U : 0x00U ) ;
c3 = ( c3 < < 1 ) | ( b ? 0x01U : 0x00U ) ;
}
}
@ -915,50 +918,50 @@ void YSFCodec::encode_imbe(unsigned char* data, const unsigned char* imbe)
bit + = 23U ;
bit + = 23U ;
// c4
// c4
for ( u nsigned in t i = 0U ; i < 11U ; i + + )
for ( u int32_ t i = 0U ; i < 11U ; i + + )
bit [ i ] = READ_BIT ( imbe , i + 48U ) ;
bit [ i ] = READ_BIT ( imbe , i + 48U ) ;
CHamming : : encode15113_1 ( bit ) ;
CHamming : : encode15113_1 ( bit ) ;
bit + = 15U ;
bit + = 15U ;
// c5
// c5
for ( u nsigned in t i = 0U ; i < 11U ; i + + )
for ( u int32_ t i = 0U ; i < 11U ; i + + )
bit [ i ] = READ_BIT ( imbe , i + 59U ) ;
bit [ i ] = READ_BIT ( imbe , i + 59U ) ;
CHamming : : encode15113_1 ( bit ) ;
CHamming : : encode15113_1 ( bit ) ;
bit + = 15U ;
bit + = 15U ;
// c6
// c6
for ( u nsigned in t i = 0U ; i < 11U ; i + + )
for ( u int32_ t i = 0U ; i < 11U ; i + + )
bit [ i ] = READ_BIT ( imbe , i + 70U ) ;
bit [ i ] = READ_BIT ( imbe , i + 70U ) ;
CHamming : : encode15113_1 ( bit ) ;
CHamming : : encode15113_1 ( bit ) ;
bit + = 15U ;
bit + = 15U ;
// c7
// c7
for ( u nsigned in t i = 0U ; i < 7U ; i + + )
for ( u int32_ t i = 0U ; i < 7U ; i + + )
bit [ i ] = READ_BIT ( imbe , i + 81U ) ;
bit [ i ] = READ_BIT ( imbe , i + 81U ) ;
bool prn [ 114U ] ;
bool prn [ 114U ] ;
// Create the whitening vector and save it for future use
// Create the whitening vector and save it for future use
u nsigned in t p = 16U * c0 ;
u int32_ t p = 16U * c0 ;
for ( u nsigned in t i = 0U ; i < 114U ; i + + ) {
for ( u int32_ t i = 0U ; i < 114U ; i + + ) {
p = ( 173U * p + 13849U ) % 65536U ;
p = ( 173U * p + 13849U ) % 65536U ;
prn [ i ] = p > = 32768U ;
prn [ i ] = p > = 32768U ;
}
}
// Whiten some bits
// Whiten some bits
for ( u nsigned in t i = 0U ; i < 114U ; i + + )
for ( u int32_ t i = 0U ; i < 114U ; i + + )
bTemp [ i + 23U ] ^ = prn [ i ] ;
bTemp [ i + 23U ] ^ = prn [ i ] ;
// Interleave
// Interleave
for ( u nsigned in t i = 0U ; i < 144U ; i + + ) {
for ( u int32_ t i = 0U ; i < 144U ; i + + ) {
u nsigned in t n = IMBE_INTERLEAVE [ i ] ;
u int32_ t n = IMBE_INTERLEAVE [ i ] ;
WRITE_BIT ( data , n , bTemp [ i ] ) ;
WRITE_BIT ( data , n , bTemp [ i ] ) ;
}
}
}
}
void YSFCodec : : encode_dv2 ( )
void YSFCodec : : encode_dv2 ( )
{
{
u nsigned char callsign [ 12 ] ;
u int8_t callsign [ 12 ] ;
: : memcpy ( callsign , " " , 10 ) ;
: : memcpy ( callsign , " " , 10 ) ;
: : memcpy ( callsign , m_modeinfo . callsign . toStdString ( ) . c_str ( ) , : : strlen ( m_modeinfo . callsign . toStdString ( ) . c_str ( ) ) ) ;
: : memcpy ( callsign , m_modeinfo . callsign . toStdString ( ) . c_str ( ) , : : strlen ( m_modeinfo . callsign . toStdString ( ) . c_str ( ) ) ) ;
uint8_t * p_frame = m_ysfFrame ;
uint8_t * p_frame = m_ysfFrame ;
@ -1148,7 +1151,7 @@ void YSFCodec::generate_vch_vd2(const uint8_t *a)
{
{
uint8_t buf [ 104 ] ;
uint8_t buf [ 104 ] ;
uint8_t result [ 104 ] ;
uint8_t result [ 104 ] ;
//u nsigned char a[56];
//u int8_t a[56];
uint8_t vch [ 13 ] ;
uint8_t vch [ 13 ] ;
memset ( vch , 0 , 13 ) ;
memset ( vch , 0 , 13 ) ;
/*
/*
@ -1300,26 +1303,16 @@ void YSFCodec::process_rx_data()
cnt = 0 ;
cnt = 0 ;
}
}
if ( m_modeinfo . type = = 3 ) {
if ( ( ! m_tx ) & & ( m_rximbecodecq . size ( ) > 10 ) ) {
if ( m_rxcodecq . size ( ) > 10 ) {
for ( int i = 0 ; i < 11 ; + + i ) {
for ( int i = 0 ; i < 11 ; + + i ) {
imbe [ i ] = m_rx codecq. dequeue ( ) ;
imbe [ i ] = m_rx imbe codecq. dequeue ( ) ;
}
}
vocoder . decode_4400 ( pcm , imbe ) ;
vocoder . decode_4400 ( pcm , imbe ) ;
m_audio - > write ( pcm , 160 ) ;
m_audio - > write ( pcm , 160 ) ;
emit update_output_level ( m_audio - > level ( ) ) ;
emit update_output_level ( m_audio - > level ( ) ) ;
}
}
else if ( ( m_modeinfo . stream_state = = STREAM_END ) | | ( m_modeinfo . stream_state = = STREAM_LOST ) ) {
m_rxtimer - > stop ( ) ;
else if ( ( ! m_tx ) & & ( m_rxcodecq . size ( ) > 6 ) ) {
m_audio - > stop_playback ( ) ;
m_rxwatchdog = 0 ;
m_modeinfo . streamid = 0 ;
m_rxcodecq . clear ( ) ;
qDebug ( ) < < " YSF FR playback stopped " ;
}
}
else {
if ( ( ! m_tx ) & & ( m_rxcodecq . size ( ) > 6 ) ) {
for ( int i = 0 ; i < 7 ; + + i ) {
for ( int i = 0 ; i < 7 ; + + i ) {
ambe [ i ] = m_rxcodecq . dequeue ( ) ;
ambe [ i ] = m_rxcodecq . dequeue ( ) ;
}
}
@ -1342,15 +1335,16 @@ void YSFCodec::process_rx_data()
emit update_output_level ( m_audio - > level ( ) ) ;
emit update_output_level ( m_audio - > level ( ) ) ;
}
}
}
}
else if ( ( m_modeinfo . stream_state = = STREAM_END ) | | ( m_modeinfo . stream_state = = STREAM_LOST ) ) {
else if ( ( ( m_modeinfo . stream_state = = STREAM_END ) | | ( m_modeinfo . stream_state = = STREAM_LOST ) ) & & ( m_rxmodemq . size ( ) < 100 ) ) {
m_rxtimer - > stop ( ) ;
m_rxtimer - > stop ( ) ;
m_audio - > stop_playback ( ) ;
m_audio - > stop_playback ( ) ;
m_rxwatchdog = 0 ;
m_rxwatchdog = 0 ;
m_modeinfo . streamid = 0 ;
m_modeinfo . streamid = 0 ;
m_rxcodecq . clear ( ) ;
m_rxcodecq . clear ( ) ;
m_rximbecodecq . clear ( ) ;
//m_ambedev->clear_queue();
//m_ambedev->clear_queue();
qDebug ( ) < < " YSF VD playback stopped" ;
qDebug ( ) < < " YSF playback stopped" ;
return ;
return ;
}
}
}
}
}