Exemple #1
0
char * decode(char *data, int k, int m, unsigned *index, int miss, int chunksize)
{
	fec_t *test;
	char *output;
	unsigned char *inpkts[k];
	unsigned char *outpkts[miss];
	int i, j=0, h;

	output = (char *)malloc((k * chunksize + 1) * sizeof(char));
	for (i = 0; i < k; i++) {
		inpkts[i] = data + index[i] * chunksize;
	}
	for (i = 0; i < k; i++) {
		if (index[i] != i) {
			outpkts[j] = output + i * chunksize; 
			j++;
		}
		else {
			for (h = 0; h < chunksize; h++) {
				output[i * chunksize + h] = inpkts[i][h];
			}
		}
	}
	test = fec_new(k, m);
	fec_decode(test, inpkts, outpkts, index, chunksize);
	output[k * chunksize] = '\0';
	fec_free(test);
	return output;
}
Exemple #2
0
// decode a block of data using a fec scheme
//  _q              :   fec object
//  _dec_msg_len    :   decoded message length
//  _msg_enc        :   encoded message
//  _msg_dec        :   decoded message
void fec_decode_soft(fec _q,
                     unsigned int _dec_msg_len,
                     unsigned char * _msg_enc,
                     unsigned char * _msg_dec)
{
    if (_q->decode_soft_func != NULL) {
        // call internal decoding method
        _q->decode_soft_func(_q, _dec_msg_len, _msg_enc, _msg_dec);
    } else {
        // pack bytes and use hard-decision decoding
        unsigned enc_msg_len = fec_get_enc_msg_length(_q->scheme, _dec_msg_len);
        unsigned char msg_enc_hard[enc_msg_len];
        unsigned int i;
        for (i=0; i<enc_msg_len; i++) {
            // TODO : use pack bytes
            msg_enc_hard[i] = 0;
            msg_enc_hard[i] |= (_msg_enc[8*i+0] >> 0) & 0x80;
            msg_enc_hard[i] |= (_msg_enc[8*i+1] >> 1) & 0x40;
            msg_enc_hard[i] |= (_msg_enc[8*i+2] >> 2) & 0x20;
            msg_enc_hard[i] |= (_msg_enc[8*i+3] >> 3) & 0x10;
            msg_enc_hard[i] |= (_msg_enc[8*i+4] >> 4) & 0x08;
            msg_enc_hard[i] |= (_msg_enc[8*i+5] >> 5) & 0x04;
            msg_enc_hard[i] |= (_msg_enc[8*i+6] >> 6) & 0x02;
            msg_enc_hard[i] |= (_msg_enc[8*i+7] >> 7) & 0x01;
        }

        // use hard-decoding method
        fec_decode(_q, _dec_msg_len, msg_enc_hard, _msg_dec);
    }
}
Exemple #3
0
// Helper function to keep code base small
void fec_test_codec(fec_scheme _fs, unsigned int _n, void * _opts)
{
#if !LIBFEC_ENABLED
    if ( _fs == LIQUID_FEC_CONV_V27    ||
         _fs == LIQUID_FEC_CONV_V29    ||
         _fs == LIQUID_FEC_CONV_V39    ||
         _fs == LIQUID_FEC_CONV_V615   ||
         _fs == LIQUID_FEC_CONV_V27P23 ||
         _fs == LIQUID_FEC_CONV_V27P34 ||
         _fs == LIQUID_FEC_CONV_V27P45 ||
         _fs == LIQUID_FEC_CONV_V27P56 ||
         _fs == LIQUID_FEC_CONV_V27P67 ||
         _fs == LIQUID_FEC_CONV_V27P78 ||
         _fs == LIQUID_FEC_CONV_V29P23 ||
         _fs == LIQUID_FEC_CONV_V29P34 ||
         _fs == LIQUID_FEC_CONV_V29P45 ||
         _fs == LIQUID_FEC_CONV_V29P56 ||
         _fs == LIQUID_FEC_CONV_V29P67 ||
         _fs == LIQUID_FEC_CONV_V29P78 ||
         _fs == LIQUID_FEC_RS_M8)
    {
        AUTOTEST_WARN("convolutional, Reed-Solomon codes unavailable (install libfec)\n");
        return;
    }
#endif

    // generate fec object
    fec q = fec_create(_fs,_opts);

    // create arrays
    unsigned int n_enc = fec_get_enc_msg_length(_fs,_n);
    unsigned char msg[_n];          // original message
    unsigned char msg_enc[n_enc];   // encoded message
    unsigned char msg_dec[_n];      // decoded message

    // initialze message
    unsigned int i;
    for (i=0; i<_n; i++) {
        msg[i] = rand() & 0xff;
        msg_dec[i] = 0;
    }

    // encode message
    fec_encode(q,_n,msg,msg_enc);

    // channel: add single error
    msg_enc[0] ^= 0x01;

    // decode message
    fec_decode(q,_n,msg_enc,msg_dec);

    // validate output
    CONTEND_SAME_DATA(msg,msg_dec,_n);

    // clean up objects
    fec_destroy(q);
}
Exemple #4
0
// Execute the packetizer to decode an input message, return validity
// check of resulting data
//
//  _p      :   packetizer object
//  _pkt    :   input message (coded soft bits)
//  _msg    :   decoded output message
int packetizer_decode_soft(packetizer _p,
                           unsigned char * _pkt,
                           unsigned char * _msg)
{
    // copy coded message to internal buffer[0]
    memmove(_p->buffer_0, _pkt, 8*_p->packet_len);

    // 
    // decode outer level using soft decoding
    //

    // run the de-interleaver: buffer[0] > buffer[1]
    interleaver_decode_soft(_p->plan[1].q,
                            _p->buffer_0,
                            _p->buffer_1);

    // run the decoder: buffer[1] > buffer[0]
    fec_decode_soft(_p->plan[1].f,
                    _p->plan[1].dec_msg_len,
                    _p->buffer_1,
                    _p->buffer_0);

    // 
    // decode inner level using hard decoding
    //

    // run the de-interleaver: buffer[0] > buffer[1]
    interleaver_decode(_p->plan[0].q,
                       _p->buffer_0,
                       _p->buffer_1);

    // run the decoder: buffer[1] > buffer[0]
    fec_decode(_p->plan[0].f,
               _p->plan[0].dec_msg_len,
               _p->buffer_1,
               _p->buffer_0);

    // strip crc, validate message
    unsigned int key = 0;
    unsigned int i;
    for (i=0; i<_p->crc_length; i++) {
        key <<= 8;

        key |= _p->buffer_0[_p->msg_len+i];
    }

    // copy result to output
    memmove(_msg, _p->buffer_0, _p->msg_len);

    // return crc validity
    return crc_validate_message(_p->check,
                                _p->buffer_0,
                                _p->msg_len,
                                key);
}
//
// AUTOTEST: repeat/3 codec
//
void autotest_rep5_codec()
{
    unsigned int n=4;
    unsigned char msg[] = {0x25, 0x62, 0x3F, 0x52};
    fec_scheme fs = LIQUID_FEC_REP5;

    // create arrays
    unsigned int n_enc = fec_get_enc_msg_length(fs,n);
    unsigned char msg_dec[n];
    unsigned char msg_enc[n_enc];

    // create object
    fec q = fec_create(fs,NULL);
    if (liquid_autotest_verbose)
        fec_print(q);

    // encode message
    fec_encode(q, n, msg, msg_enc);
    
    // corrupt encoded message, but no so much that it
    // can't be decoded
    msg_enc[ 0] = ~msg_enc[ 0];
    msg_enc[ 4] = ~msg_enc[ 4];
//  msg_enc[ 8] = ~msg_enc[ 8];
//  msg_enc[12] = ~msg_enc[12];
//  msg_enc[16] = ~msg_enc[16];

    msg_enc[ 1] = ~msg_enc[ 1];
//  msg_enc[ 5] = ~msg_enc[ 5];
    msg_enc[ 9] = ~msg_enc[ 9];
//  msg_enc[13] = ~msg_enc[13];
//  msg_enc[17] = ~msg_enc[17];

//  msg_enc[ 2] = ~msg_enc[ 2];
//  msg_enc[ 6] = ~msg_enc[ 6];
    msg_enc[10] = ~msg_enc[10];
    msg_enc[14] = ~msg_enc[14];
//  msg_enc[18] = ~msg_enc[18];

    msg_enc[ 3] = ~msg_enc[ 3];
//  msg_enc[ 7] = ~msg_enc[ 7];
//  msg_enc[11] = ~msg_enc[11];
//  msg_enc[15] = ~msg_enc[15];
    msg_enc[19] = ~msg_enc[19];

    // decode message
    fec_decode(q, n, msg_enc, msg_dec);

    // validate data are the same
    CONTEND_SAME_DATA(msg, msg_dec, n);

    // clean up objects
    fec_destroy(q);
}
Exemple #6
0
// Execute the packetizer to decode an input message, return validity
// check of resulting data
//
//  _p      :   packetizer object
//  _pkt    :   input message (coded bytes)
//  _msg    :   decoded output message
int packetizer_decode(packetizer _p,
                      unsigned char * _pkt,
                      unsigned char * _msg)
{
    // copy coded message to internal buffer[0]
    memmove(_p->buffer_0, _pkt, _p->packet_len);

    // execute fec/interleaver plans
    unsigned int i;
    for (i=_p->plan_len; i>0; i--) {
        // run the de-interleaver: buffer[0] > buffer[1]
        interleaver_decode(_p->plan[i-1].q,
                           _p->buffer_0,
                           _p->buffer_1);

        // run the decoder: buffer[1] > buffer[0]
        fec_decode(_p->plan[i-1].f,
                   _p->plan[i-1].dec_msg_len,
                   _p->buffer_1,
                   _p->buffer_0);
    }

    // strip crc, validate message
    unsigned int key = 0;
    for (i=0; i<_p->crc_length; i++) {
        key <<= 8;

        key |= _p->buffer_0[_p->msg_len+i];
    }

    // copy result to output
    memmove(_msg, _p->buffer_0, _p->msg_len);

    // return crc validity
    return crc_validate_message(_p->check,
                                _p->buffer_0,
                                _p->msg_len,
                                key);
}
//
// AUTOTEST: Hamming (7,4) codec
//
void autotest_hamming74_codec()
{
    unsigned int n=4;
    unsigned char msg[] = {0x25, 0x62, 0x3F, 0x52};
    fec_scheme fs = LIQUID_FEC_HAMMING74;

    // create arrays
    unsigned int n_enc = fec_get_enc_msg_length(fs,n);
    unsigned char msg_dec[n];
    unsigned char msg_enc[n_enc];

    // create object
    fec q = fec_create(fs,NULL);
    if (liquid_autotest_verbose)
        fec_print(q);

    // encode message
    fec_encode(q, n, msg, msg_enc);
    
    // corrupt encoded message
    msg_enc[0] ^= 0x04; // position 5
#if 0
    msg_enc[1] ^= 0x04; //
    msg_enc[2] ^= 0x02; //
    msg_enc[3] ^= 0x01; //
    msg_enc[4] ^= 0x80; //
    msg_enc[5] ^= 0x40; //
    msg_enc[6] ^= 0x20; //
#endif

    // decode message
    fec_decode(q, n, msg_enc, msg_dec);

    // validate data are the same
    CONTEND_SAME_DATA(msg, msg_dec, n);

    // clean up objects
    fec_destroy(q);
}
unsigned int test_fec_decoding(void)
{
	uint8_t input[15] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E};
	uint8_t output[32];

	TimerA_configureContinuousMode(__MSP430_BASEADDRESS_T0A5__, TIMERA_CLOCKSOURCE_SMCLK, TIMERA_CLOCKSOURCE_DIVIDER_1, TIMERA_TAIE_INTERRUPT_DISABLE, TIMERA_DO_CLEAR);

	fec_init_encode(input);
	fec_set_length(15);
	fec_encode(&output[0]);
	fec_encode(&output[4]);
	fec_encode(&output[8]);
	fec_encode(&output[12]);
	fec_encode(&output[16]);
	fec_encode(&output[20]);
	fec_encode(&output[24]);
	fec_encode(&output[28]);

	memset(input, 0, 15);

	fec_init_decode(input);
	fec_set_length(15);

	TimerA_clear(__MSP430_BASEADDRESS_T0A5__);
	fec_decode(&output[0]);
	fec_decode(&output[4]);
	fec_decode(&output[8]);
	fec_decode(&output[12]);
	fec_decode(&output[16]);
	fec_decode(&output[20]);
	fec_decode(&output[24]);
	fec_decode(&output[28]);
	TimerA_stop(__MSP430_BASEADDRESS_T0A5__);

	return TA0R - TIMER_OFFSET;
}
Exemple #9
0
int rs_decode(void *code,char *data[],int size)
{
	int k=get_k(code);
	int n=get_n(code);
	int index[n];
	int count=0;
	for(int i=0;i<n;i++)
	{
		if(data[i]!=0)
		{
			index[count++]=i;
		}
	}
	if(count<k)
		return -1;
	for(int i=0;i<n;i++)
	{
		if(i<count)
			data[i]=data[index[i]];
		else
			data[i]=0;
	}
	return fec_decode(code,(void**)data,index,size);
}
Exemple #10
0
int melp_chn_read(struct melp_param *par, struct melp_param *prev_par)
{
    int erase = 0;
    int i, bit_cntr;
    unsigned int *bit_ptr; 

    /*	Read channel output buffer into bit buffer */
    bit_ptr = bit_buffer;
    for (i = 0; i < NUM_CH_BITS; i++) {
	erase |= unpack_code(&par->chptr,&par->chbit,&bit_buffer[bit_order[i]],
			     1,CHWORDSIZE,ERASE_MASK);
	bit_ptr++;
    }

    /*	Read information from  bit buffer	*/
    bit_ptr = bit_buffer;
    bit_cntr = 0;

    unpack_code(&bit_ptr,&bit_cntr,&par->gain_index[1],5,1,0);
    
    /* Read sync bit */
    unpack_code(&bit_ptr,&bit_cntr,&i,1,1,0);
    unpack_code(&bit_ptr,&bit_cntr,&par->gain_index[0],3,1,0);
    unpack_code(&bit_ptr,&bit_cntr,&par->pitch_index,PIT_BITS,1,0);
    
    unpack_code(&bit_ptr,&bit_cntr,&par->jit_index,1,1,0);
    unpack_code(&bit_ptr,&bit_cntr,&par->bpvc_index,
			 NUM_BANDS-1,1,0);
    
    for (i = 0; i < par->msvq_stages; i++) 
      unpack_code(&bit_ptr,&bit_cntr,&par->msvq_index[i],
			   par->msvq_bits[i],1,0);

    unpack_code(&bit_ptr,&bit_cntr,&par->fsvq_index[0],
			 FS_BITS,1,0);
    
    /* Clear unvoiced flag */
    par->uv_flag = 0;
    
    erase = fec_decode(par,erase);
    
    /* Decode new frame if no erasures occurred */
    if (erase) {
	
	/* Erasure: frame repeat */
		
	/* Save correct values of pointers */
	prev_par->chptr = par->chptr;
	prev_par->chbit = par->chbit;
	*par = *prev_par; 
		
	/* Force all subframes to equal last one */
	for (i = 0; i < NUM_GAINFR-1; i++) {
	    par->gain[i] = par->gain[NUM_GAINFR-1];
	}
    }
    else {
	
	/* Decode line spectrum frequencies	*/
	vq_msd2(msvq_cb,&par->lsf[1],(float*)NULL,(float*)NULL,par->msvq_index,
		par->msvq_levels,par->msvq_stages,LPC_ORD,0);
	i = FS_LEVELS;
	if (par->uv_flag)
	  fill(par->fs_mag,1.,NUM_HARM);
	else
	  {	
	      /* Decode Fourier magnitudes */
	      vq_msd2(fsvq_cb,par->fs_mag,(float*)NULL,(float*)NULL,
		      par->fsvq_index,&i,1,NUM_HARM,0);
	  }

	/* Decode gain terms with uniform log quantizer	*/
	q_gain_dec(par->gain, par->gain_index,GN_QLO,GN_QUP,GN_QLEV);

	/* Fractional pitch: */
	/* Decode logarithmic pitch period */
	if (par->uv_flag)
	  par->pitch = UV_PITCH;
	else 
	  {
	      quant_u_dec(par->pitch_index,&par->pitch,PIT_QLO,PIT_QUP,
			  PIT_QLEV);
	      par->pitch = pow(10.0,par->pitch);
	  }

	/* Decode jitter and bandpass voicing */
	quant_u_dec(par->jit_index,&par->jitter,0.0,MAX_JITTER,2);
	q_bpvc_dec(&par->bpvc[0],&par->bpvc_index,par->uv_flag,
		   NUM_BANDS);
    }

    /* Return erase flag */
    return(erase);
}
Exemple #11
0
int main(void)
{
	int i, j;
	unsigned char buf[NR_PKTS * PKT_SIZE];
	unsigned char pktbuf[(NR_PKTS + DROPS) * PKT_SIZE];
	struct fec_parms *fec;
	unsigned char *srcs[NR_PKTS];
	unsigned char *pkt[NR_PKTS + DROPS];
	int pktnr[NR_PKTS + DROPS];
	struct timeval then, now;

	srand(3453);
	for (i=0; i < sizeof(buf); i++)
		if (i < ERASE_SIZE)
			buf[i] = rand();
		else
			buf[i] = 0;

	for (i=0; i < NR_PKTS + DROPS; i++)
		srcs[i] = buf + (i * PKT_SIZE);

	for (i=0; i < NR_PKTS + DROPS; i++) {
		pkt[i] = malloc(PKT_SIZE);
		pktnr[i] = -1;
	}
	fec = fec_new(NR_PKTS, NR_PKTS + DROPS);
	if (!fec) {
		printf("fec_init() failed\n");
		exit(1);
	}
	j = 0;
	for (i=0; i < NR_PKTS + DROPS; i++) {
#if 1
		if (i == 27  || i == 40  || i == 44 || i == 45 || i == 56 )
			continue;
#endif
		if (i == 69 || i == 93 || i == 103)
			continue;
		fec_encode(fec, srcs, pkt[j], i, PKT_SIZE);
		pktnr[j] = i;
		j++;
	}
	gettimeofday(&then, NULL);
	if (fec_decode(fec, pkt, pktnr, PKT_SIZE)) {
		printf("Decode failed\n");
		exit(1);
	}

	for (i=0; i < NR_PKTS; i++)
		memcpy(pktbuf + (i*PKT_SIZE), pkt[i], PKT_SIZE);
	gettimeofday(&now, NULL);
	now.tv_sec -= then.tv_sec;
	now.tv_usec -= then.tv_usec;
	if (now.tv_usec < 0) {
		now.tv_usec += 1000000;
		now.tv_sec--;
	}

	if (memcmp(pktbuf, buf, ERASE_SIZE)) {
		int fd;
		printf("Compare failed\n");
		fd = open("before", O_WRONLY|O_TRUNC|O_CREAT, 0644);
		if (fd >= 0)
			write(fd, buf, ERASE_SIZE);
		close(fd);
		fd = open("after", O_WRONLY|O_TRUNC|O_CREAT, 0644);
		if (fd >= 0)
			write(fd, pktbuf, ERASE_SIZE);
		
		exit(1);
	}

	printf("Decoded in %ld.%06lds\n", now.tv_sec, now.tv_usec);
	return 0;
}
Exemple #12
0
int
test_decode(void *code, int k, int index[], int sz, char *s)
{
    int errors;
    int reconstruct = 0 ;
    int item, i ;

    static int prev_k = 0, prev_sz = 0;
    static u_char **d_original = NULL, **d_src = NULL ;

    if (sz < 1 || sz > 8192) {
	fprintf(stderr, "test_decode: size %d invalid, must be 1..8K\n",
		sz);
	return 1 ;
    }
    if (k < 1 || k > GF_SIZE + 1) {
	fprintf(stderr, "test_decode: k %d invalid, must be 1..%d\n",
		k, GF_SIZE + 1 );
	return 2 ;
    }
    if (prev_k != k || prev_sz != sz) {
	if (d_original != NULL) {
	    for (i = 0 ; i < prev_k ; i++ ) {
		free(d_original[i]);
		free(d_src[i]);
	    }
	    free(d_original);
	    free(d_src);
	    d_original = NULL ;
	    d_src = NULL ;
	}
    }
    prev_k = k ;
    prev_sz = sz ;
    if (d_original == NULL) {
	d_original = my_malloc(k * sizeof(void *), "d_original ptr");
	d_src = my_malloc(k * sizeof(void *), "d_src ptr");

	for (i = 0 ; i < k ; i++ ) {
	    d_original[i] = my_malloc(sz, "d_original data");
	    d_src[i] = my_malloc(sz, "d_src data");
	}
	/*
	 * build sample data
	 */
	for (i = 0 ; i < k ; i++ ) {
	    for (item=0; item < sz; item++)
		d_original[i][item] = ((item ^ i) + 3) & GF_SIZE;
	}
    }

    errors = 0 ;

    for( i = 0 ; i < k ; i++ )
	if (index[i] >= k ) reconstruct ++ ;

    TICK(ticks[2]);
    for( i = 0 ; i < k ; i++ )
	fec_encode(code, d_original, d_src[i], index[i], sz );
    TOCK(ticks[2]);

    TICK(ticks[1]);
    if (fec_decode(code, d_src, index, sz)) {
	fprintf(stderr, "detected singular matrix for %s  \n", s);
	return 1 ;
    }
    TOCK(ticks[1]);

    for (i=0; i<k; i++)
	if (bcmp(d_original[i], d_src[i], sz )) {
	    errors++;
	    fprintf(stderr, "error reconstructing block %d\n", i);
	}
    if (errors)
	fprintf(stderr, "Errors reconstructing %d blocks out of %d\n",
	    errors, k);

    fprintf(stderr,
	"  k %3d, l %3d  c_enc %10.6f MB/s c_dec %10.6f MB/s     \r",
	k, reconstruct,
	(double)(k * sz * reconstruct)/(double)ticks[2],
	(double)(k * sz * reconstruct)/(double)ticks[1]);
    return errors ;
}
Exemple #13
0
void rx_data_isr()
{

    //Read number of bytes in RXFIFO
    uint8_t rxBytes = ReadSingleReg(RXBYTES);
#ifdef LOG_PHY_ENABLED
    log_print_stack_string(LOG_PHY, "rx_data_isr (%d bytes received)", rxBytes);
#endif

#ifdef D7_PHY_USE_FEC
    if(fec)
    {
        uint8_t fecbuffer[4];

        //If length is not set get the length from RXFIFO and set PKTLEN
        if (packetLength == 0) {
            ReadBurstReg(RXFIFO, fecbuffer, 4);
            fec_decode(fecbuffer);
            fec_set_length(*buffer);
            packetLength = ((*buffer & 0xFE) + 2) << 1;
            remainingBytes = packetLength - 4;
            WriteSingleReg(PKTLEN, (uint8_t)(packetLength & 0x00FF));
            WriteSingleReg(FIFOTHR, RADIO_FIFOTHR_FIFO_THR_17_48);
            rxBytes -= 4;
        }

        //If remaining bytes is equal or less than 255 - fifo size, set length to fixed
        if(remainingBytes < 192)
            set_length_infinite(false);

        //Read data from buffer and decode
        while (rxBytes >= 4) {
            ReadBurstReg(RXFIFO, fecbuffer, 4);

            if(fec_decode(fecbuffer) == false)
                break;

            remainingBytes -= 4;
            rxBytes -= 4;
        }
    } else {
#endif
        //If length is not set get the length from RXFIFO and set PKTLEN
        if (packetLength == 0) {
            packetLength = ReadSingleReg(RXFIFO);
            WriteSingleReg(PKTLEN, packetLength);
            WriteSingleReg(FIFOTHR, RADIO_FIFOTHR_FIFO_THR_17_48);
            remainingBytes = packetLength - 1;
            bufferPosition[0] = packetLength;
            bufferPosition++;
            rxBytes--;
#ifdef LOG_PHY_ENABLED
            log_print_stack_string(LOG_PHY, "rx_data_isr getting packetLength (%d)", packetLength);
#endif
        }

        //Never read the entire buffer as long as more data is going to be received
        if (remainingBytes > rxBytes) {
            rxBytes--;
        } else {
            rxBytes = remainingBytes;
        }

        //Read data from buffer
        ReadBurstReg(RXFIFO, bufferPosition, rxBytes);
        remainingBytes -= rxBytes;
        bufferPosition += rxBytes;
#ifdef D7_PHY_USE_FEC
    }
#endif

    //When all data has been received read rssi and lqi value and set packetreceived flag
    if(remainingBytes == 0)
    {
        rx_data.rssi = calculate_rssi(ReadSingleReg(RXFIFO));
        rx_data.lqi = ReadSingleReg(RXFIFO) & 0x7F;
        rx_data.length = *buffer;
        rx_data.data = buffer;
#ifdef LOG_PHY_ENABLED
        log_print_stack_string(LOG_PHY, "rx_data_isr packet received");
#endif
    }

#ifdef LOG_PHY_ENABLED
    log_print_stack_string(LOG_PHY, "rx_data_isr 1");
#endif
}
Exemple #14
0
BOOLEAN melp_chn_read(struct quant_param *qpar, struct melp_param *par,
		      struct melp_param *prev_par, unsigned char chbuf[])
{
	register int16_t i;
	unsigned char *bit_ptr;
	BOOLEAN erase = FALSE;
	int16_t index, bit_cntr, dontcare;

	/* Read channel output buffer into bit buffer */
	bit_ptr = bit_buffer;
	qpar->chptr = chbuf;
	qpar->chbit = 0;
	for (i = 0; i < bitNum24; i++) {
		erase |= unpack_code(&(qpar->chptr), &(qpar->chbit), &index, 1,
				     chwordsize, ERASE_MASK);
		bit_buffer[bit_order[i]] = (unsigned char)index;
		bit_ptr++;
	}

	/* Read information from  bit buffer */
	bit_ptr = bit_buffer;
	bit_cntr = 0;

	(void)unpack_code(&bit_ptr, &bit_cntr, &qpar->gain_index[1], 5, 1, 0);

	/* Read sync bit */
	(void)unpack_code(&bit_ptr, &bit_cntr, &dontcare, 1, 1, 0);
	(void)unpack_code(&bit_ptr, &bit_cntr, &qpar->gain_index[0], 3, 1, 0);
	(void)unpack_code(&bit_ptr, &bit_cntr, &(qpar->pitch_index), PIT_BITS,
			  1, 0);

	(void)unpack_code(&bit_ptr, &bit_cntr, &qpar->jit_index[0], 1, 1, 0);
	(void)unpack_code(&bit_ptr, &bit_cntr, &qpar->bpvc_index[0],
			  NUM_BANDS - 1, 1, 0);

	for (i = 0; i < MSVQ_STAGES; i++)
		(void)unpack_code(&bit_ptr, &bit_cntr, &(qpar->msvq_index[i]),
				  msvq_bits[i], 1, 0);

	(void)unpack_code(&bit_ptr, &bit_cntr, &qpar->fsvq_index, FS_BITS, 1,
			  0);

	/* Clear unvoiced flag */
	qpar->uv_flag[0] = FALSE;

	erase = (BOOLEAN) fec_decode(qpar, erase);

	/* Decode new frame if no erasures occurred */
	if (erase) {		/* Erasure: frame repeat */
		*par = *prev_par;

		/* Force all subframes to equal last one */
		fill(par->gain, par->gain[NUM_GAINFR - 1], NUM_GAINFR - 1);

	} else {

		/* Decode line spectrum frequencies */
		vq_msd2(msvq_cb, par->lsf, msvq_cb_mean, qpar->msvq_index,
			msvq_levels, MSVQ_STAGES, LPC_ORD, 2);
		dontcare = FS_LEVELS;
		if (qpar->uv_flag[0])
			fill(par->fs_mag, ONE_Q13, NUM_HARM);
		else		/* Decode Fourier magnitudes */
			vq_msd2(fsvq_cb, par->fs_mag, (int16_t *) NULL,
				&(qpar->fsvq_index), &dontcare, 1, NUM_HARM, 0);

		/* Decode gain terms with uniform log quantizer */
		q_gain_dec(par->gain, qpar->gain_index, GN_QLO_Q8, GN_QUP_Q8,
			   GN_QLEV_M1_Q10, 5);

		/* Decode voicing information */
		par->uv_flag = qpar->uv_flag[0];

		/* Fractional pitch: Decode logarithmic pitch period */
		if (qpar->uv_flag[0])
			par->pitch = UV_PITCH_Q7;
		else {
			quant_u_dec(qpar->pitch_index, &par->pitch, PIT_QLO_Q12,
				    PIT_QUP_Q12, PIT_QLEV_M1_Q8, 7);
			par->pitch = pow10_fxp(par->pitch, 7);
		}

		/* Decode jitter */
		/*      quant_u_dec(par->jit_index, &par->jitter, 0.0, MAX_JITTER, 2);    */

		if (qpar->jit_index[0] == 0)
			par->jitter = 0;
		else
			par->jitter = MAX_JITTER_Q15;

		/* Decode bandpass voicing */
		q_bpvc_dec(par->bpvc, qpar->bpvc_index[0], qpar->uv_flag[0],
			   NUM_BANDS);
	}

	/* Return erase flag */
	return (erase);
}
Exemple #15
0
int
main(int argc, char *argv[])
{
    char buf[256];
    void *code ;
    
    int k = 4, n = 8;
    int i, item, sz = 1;
    
    int index[n], re_index[k] ;


    static u_char **d_original = NULL, **d_src = NULL, **data ;

        d_original = malloc(k * sizeof(void *));
        data = malloc(k * sizeof(void *));
        d_src = malloc(n * sizeof(void *));
        
        for (i = 0 ; i < k ; i++ ) {
            d_original[i] = malloc(sz);
            data[i] = malloc(sz);
        }
        for (i = 0 ; i < n ; i++ ) {
            d_src[i] = malloc(sz);
        }

    code = fec_new(k, n);

    for (i = 0 ; i < k ; i++ ) {
        for (item=0; item < 1; item++) {
            d_original[i][item] = 3+i;
            printf("d_original[%d][%d] = %d, ",i, item, d_original[i][item]);
            printf("\n");
        }
    }

    for( i = 0 ; i < n ; i++ ) {
        index[i] = n-i-1;
        printf("index[%d] = %d \n", i, index[i]);
    }

    for( i = 0 ; i < n ; i++ ) {
        printf("=======================================\n");
        fec_encode(code, d_original, d_src[i], index[i], sz );
        printf("i = %d, d_src = %x, index = %d \n", i, d_src[i][0], index[i]);
        printf("=======================================\n");
    }

    data[0][0] = d_src[0][0];
    data[1][0] = d_src[1][0];
    data[2][0] = d_src[2][0];
    data[3][0] = d_src[3][0];

    re_index[0] = 7;
    re_index[1] = 6;
    re_index[2] = 5;
    re_index[3] = 4;

    for (i = 0 ; i < k ; i++ ) {
        for (item=0; item < 1; item++) {
            printf("before decode data: data[%d][%d] = %d, ",i, item, data[i][item]);
            printf("\n");
        }
    }

    fec_decode(code, data, re_index, sz);

    for (i = 0 ; i < k ; i++ ) {
        for (item=0; item < 1; item++) {
            printf("decode data: data[%d][%d] = %d, ",i, item, data[i][item]);
            printf("\n");
        }
    }

    fec_free(code);
    return 0;
}