#include #include #include #include //libm17 #include #define DECODE_CALLSIGNS #define SHOW_VITERBI_ERRS float sample; //last raw sample from the stdin float last[8]; //look-back buffer for finding syncwords float dist; //Euclidean distance for finding syncwords in the symbol stream float pld[SYM_PER_PLD]; //raw frame symbols uint16_t soft_bit[2*SYM_PER_PLD]; //raw frame soft bits uint16_t d_soft_bit[2*SYM_PER_PLD]; //deinterleaved soft bits uint8_t lsf[30+1]; //complete LSF (one byte extra needed for the Viterbi decoder) uint16_t lich_chunk[96]; //raw, soft LSF chunk extracted from the LICH uint8_t lich_b[6]; //48-bit decoded LICH uint8_t lich_cnt; //LICH_CNT uint8_t lich_chunks_rcvd=0; //flags set for each LSF chunk received uint16_t expected_next_fn=0; //frame number of the next frame expected to arrive uint16_t enc_data[272]; //raw frame data soft bits uint8_t frame_data[19]; //decoded frame data, 144 bits (16+128), plus 4 flushing bits uint8_t syncd=0; //syncword found? uint8_t fl=0; //Frame=0 of LSF=1 uint8_t pushed; //counter for pushed symbols int main(void) { while(1) { //wait for another symbol if(fread((uint8_t*)&sample, 4, 1, stdin)<1) break; if(!syncd) { //push new symbol for(uint8_t i=0; i<7; i++) { last[i]=last[i+1]; } last[7]=sample; //calculate euclidean norm dist = eucl_norm(last, str_sync_symbols, 8); if(dist>5; //If we're at the start of a superframe, or we missed a frame, reset the LICH state if((lich_cnt==0) || ((fn % 0x8000)!=expected_next_fn)) lich_chunks_rcvd=0; lich_chunks_rcvd|=(1<