Exemplo n.º 1
0
void melp_chn_write(struct melp_param *par)

{
    int i, bit_cntr;
    unsigned int *bit_ptr; 
    
    /* FEC: code additional information in redundant indeces */
    fec_code(par);
    
    /*	Fill bit buffer	*/
    bit_ptr = bit_buffer;
    bit_cntr = 0;

    pack_code(par->gain_index[1],&bit_ptr,&bit_cntr,5,1);
    
    /* Toggle and write sync bit */
    if (sync_bit)
	sync_bit = 0;
    else
	sync_bit = 1;
    pack_code(sync_bit,&bit_ptr,&bit_cntr,1,1);
    pack_code(par->gain_index[0],&bit_ptr,&bit_cntr,3,1);
    pack_code(par->pitch_index,&bit_ptr,&bit_cntr,PIT_BITS,1);
    pack_code(par->jit_index,&bit_ptr,&bit_cntr,1,1);
    pack_code(par->bpvc_index,&bit_ptr,&bit_cntr,NUM_BANDS-1,1);
    
    for (i = 0; i < par->msvq_stages; i++) 
      pack_code(par->msvq_index[i],&bit_ptr,&bit_cntr,par->msvq_bits[i],1);
    
    pack_code(par->fsvq_index[0],&bit_ptr,&bit_cntr,
	      FS_BITS,1);
    
    /*	Write channel output buffer	*/
    for (i = 0; i < NUM_CH_BITS; i++) {
	pack_code(bit_buffer[bit_order[i]],&par->chptr,&par->chbit,
		  1,CHWORDSIZE);
	if (i == 0)
	    *(par->chptr) |= 0x8000; /* set beginning of frame bit */
    }

}
Exemplo n.º 2
0
void melp_chn_write(struct quant_param *qpar, unsigned char chbuf[])
{
	register int16_t i;
	unsigned char *bit_ptr;
	int16_t bit_cntr;

	/* FEC: code additional information in redundant indeces */
	fec_code(qpar);

	/* Fill bit buffer */
	bit_ptr = bit_buffer;
	bit_cntr = 0;

	pack_code(qpar->gain_index[1], &bit_ptr, &bit_cntr, 5, 1);

	/* Toggle and write sync bit */
	sync_bit = melpe_sub(1, sync_bit);
	pack_code(sync_bit, &bit_ptr, &bit_cntr, 1, 1);

	pack_code(qpar->gain_index[0], &bit_ptr, &bit_cntr, 3, 1);
	pack_code(qpar->pitch_index, &bit_ptr, &bit_cntr, PIT_BITS, 1);
	pack_code(qpar->jit_index[0], &bit_ptr, &bit_cntr, 1, 1);
	pack_code(qpar->bpvc_index[0], &bit_ptr, &bit_cntr, NUM_BANDS - 1, 1);

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

	pack_code(qpar->fsvq_index, &bit_ptr, &bit_cntr, FS_BITS, 1);

	/* Write channel output buffer */
	qpar->chptr = chbuf;
	qpar->chbit = 0;
	for (i = 0; i < bitNum24; i++) {
		pack_code(bit_buffer[bit_order[i]], &qpar->chptr, &qpar->chbit,
			  1, chwordsize);
		if (i == 0)	/* set beginning of frame bit */
			*(qpar->chptr) |= (uint16_t) 0x8000;
	}
}
Exemplo n.º 3
0
/****************************************************************************
**
** Function:		low_rate_chn_write
**
** Description: Write channel buffer for low rate ( 1200bps )
**
** Arguments:
**
**	quant_param par ---- The quantization structure
**
** Return value:	None
**
*****************************************************************************/
void low_rate_chn_write(struct quant_param *qpar)
{
	register int16_t i;
	int16_t bit_cntr, cnt;
	int16_t uv1, uv2, cuv;
	int16_t uv_index = 0, bp_prot1 = 0, bp_prot2 = 0, lsp_prot = 0;
	int16_t uv_parity;
	unsigned char *bit_ptr;

	/* FEC: code additional information in redundant indices */
	low_rate_fec_code(qpar);

	/* ====== Fill bit buffer ====== */
	bit_ptr = bit_buffer;
	bit_cntr = 0;

	/* ====== Toggle and write sync bit ====== */
	sync_bit = melpe_sub(1, sync_bit);
	pack_code(sync_bit, &bit_ptr, &bit_cntr, 1, 1);

	/* ===== Count the number of voiced frame ===== */
	cnt = 0;
	for (i = 0; i < NF; i++) {
		if (!qpar->uv_flag[i])
			cnt++;
	}

	/* ====== Packing global voicing and pitch information ====== */
	if (cnt <= 1) {		/* UUU UUV UVU VUU */
		uv_index = 0;
		bp_prot1 = 0;
		if (!qpar->uv_flag[0])
			bp_prot2 = 3;
		else if (!qpar->uv_flag[1])
			bp_prot2 = 2;
		else if (!qpar->uv_flag[2])
			bp_prot2 = 1;
		else {
			bp_prot2 = 0;
			lsp_prot = 0;
		}

		if (bp_prot2 == 0)
			qpar->pitch_index = UV_PIND;
		else
			qpar->pitch_index =
			    low_rate_pitch_enc[bp_prot2][qpar->pitch_index];
	} else if (cnt == 2) {	/* UVV VUV VVU */
		if (qpar->uv_flag[0]) {
			uv_index = 4;
			bp_prot1 = 3;
		} else if (qpar->uv_flag[1]) {
			uv_index = 2;
			bp_prot1 = 2;
		} else if (qpar->uv_flag[2]) {
			uv_index = 1;
			bp_prot1 = 1;
			lsp_prot = 7;
		}
	} else if (cnt == 3) {	/* VVV */
		uv_index = (int16_t) (qpar->pitch_index / PITCH_VQ_SIZE);
		qpar->pitch_index = melpe_sub(qpar->pitch_index,
					(int16_t) (uv_index * PITCH_VQ_SIZE));
		uv_index = vvv_index_map[uv_index];
	}

	pack_code(uv_index, &bit_ptr, &bit_cntr, UV_BITS, 1);

	uv_parity = parity(uv_index, 3);

	pack_code(uv_parity, &bit_ptr, &bit_cntr, 1, 1);

	pack_code(qpar->pitch_index, &bit_ptr, &bit_cntr, PITCH_VQ_BITS, 1);

	/* ====== Packing LSF indices ====== */
	uv1 = qpar->uv_flag[0];
	uv2 = qpar->uv_flag[1];
	cuv = qpar->uv_flag[2];

	if ((uv1 == 1) && (uv2 == 1) && (cuv == 1)) {
		pack_code(qpar->lsf_index[0][0], &bit_ptr, &bit_cntr, 9, 1);
		pack_code(qpar->lsf_index[1][0], &bit_ptr, &bit_cntr, 9, 1);
		pack_code(qpar->lsf_index[2][0], &bit_ptr, &bit_cntr, 9, 1);
		pack_code(qpar->lsf_index[0][1], &bit_ptr, &bit_cntr, 4, 1);
		pack_code(qpar->lsf_index[1][1], &bit_ptr, &bit_cntr, 4, 1);
		pack_code(qpar->lsf_index[2][1], &bit_ptr, &bit_cntr, 4, 1);
		pack_code(lsp_prot, &bit_ptr, &bit_cntr, 3, 1);
	} else if ((uv1 == 1) && (uv2 == 1) && (cuv != 1)) {
		pack_code(qpar->lsf_index[0][0], &bit_ptr, &bit_cntr, 9, 1);
		pack_code(qpar->lsf_index[1][0], &bit_ptr, &bit_cntr, 9, 1);
		pack_code(qpar->lsf_index[2][0], &bit_ptr, &bit_cntr, 8, 1);
		pack_code(qpar->lsf_index[2][1], &bit_ptr, &bit_cntr, 6, 1);
		pack_code(qpar->lsf_index[2][2], &bit_ptr, &bit_cntr, 5, 1);
		pack_code(qpar->lsf_index[2][3], &bit_ptr, &bit_cntr, 5, 1);
	} else if ((uv1 == 1) && (uv2 != 1) && (cuv == 1)) {
		pack_code(qpar->lsf_index[0][0], &bit_ptr, &bit_cntr, 9, 1);
		pack_code(qpar->lsf_index[1][0], &bit_ptr, &bit_cntr, 8, 1);
		pack_code(qpar->lsf_index[1][1], &bit_ptr, &bit_cntr, 6, 1);
		pack_code(qpar->lsf_index[1][2], &bit_ptr, &bit_cntr, 5, 1);
		pack_code(qpar->lsf_index[1][3], &bit_ptr, &bit_cntr, 5, 1);
		pack_code(qpar->lsf_index[2][0], &bit_ptr, &bit_cntr, 9, 1);
	} else if ((uv1 != 1) && (uv2 == 1) && (cuv == 1)) {
		pack_code(qpar->lsf_index[0][0], &bit_ptr, &bit_cntr, 8, 1);
		pack_code(qpar->lsf_index[0][1], &bit_ptr, &bit_cntr, 6, 1);
		pack_code(qpar->lsf_index[0][2], &bit_ptr, &bit_cntr, 5, 1);
		pack_code(qpar->lsf_index[0][3], &bit_ptr, &bit_cntr, 5, 1);
		pack_code(qpar->lsf_index[1][0], &bit_ptr, &bit_cntr, 9, 1);
		pack_code(qpar->lsf_index[2][0], &bit_ptr, &bit_cntr, 9, 1);
	} else {
		if ((uv1 != 1) && (uv2 != 1) && (cuv == 1)) {
			/* ---- Interpolation [4 inp + (8+6+6+6) res + 9 uv] ---- */
			pack_code(qpar->lsf_index[0][0], &bit_ptr, &bit_cntr, 9,
				  1);
		} else {
			pack_code(qpar->lsf_index[0][0], &bit_ptr, &bit_cntr, 8,
				  1);
			pack_code(qpar->lsf_index[0][1], &bit_ptr, &bit_cntr, 6,
				  1);
			pack_code(qpar->lsf_index[0][2], &bit_ptr, &bit_cntr, 5,
				  1);
			pack_code(qpar->lsf_index[0][3], &bit_ptr, &bit_cntr, 5,
				  1);
		}

		pack_code(qpar->lsf_index[1][0], &bit_ptr, &bit_cntr, 4, 1);

		if ((uv1 != 1) && (uv2 != 1) && (cuv == 1)) {
			pack_code(qpar->lsf_index[2][0], &bit_ptr, &bit_cntr, 8,
				  1);
			pack_code(qpar->lsf_index[2][1], &bit_ptr, &bit_cntr, 6,
				  1);
			pack_code(qpar->lsf_index[2][2], &bit_ptr, &bit_cntr, 6,
				  1);
			pack_code(qpar->lsf_index[2][3], &bit_ptr, &bit_cntr, 6,
				  1);
			pack_code(lsp_prot, &bit_ptr, &bit_cntr, 3, 1);
		} else {
			pack_code(qpar->lsf_index[2][0], &bit_ptr, &bit_cntr, 8,
				  1);
			pack_code(qpar->lsf_index[2][1], &bit_ptr, &bit_cntr, 6,
				  1);
		}
	}

	/* ====== Packing gain index ====== */
	pack_code(qpar->gain_index[0], &bit_ptr, &bit_cntr, GAIN_VQ_BITS, 1);

	/* ====== Packing voicing indices ====== */
	for (i = 0; i < NF; i++) {
		if (!qpar->uv_flag[i])
			pack_code(qpar->bpvc_index[i], &bit_ptr, &bit_cntr, 2,
				  1);
	}
	if (cnt == 2)
		pack_code(bp_prot1, &bit_ptr, &bit_cntr, 2, 1);
	else if (cnt == 1) {
		pack_code(bp_prot2, &bit_ptr, &bit_cntr, 2, 1);
		pack_code(bp_prot1, &bit_ptr, &bit_cntr, 2, 1);
	} else if (cnt == 0) {	/* UUU */
		pack_code(qpar->bpvc_index[0], &bit_ptr, &bit_cntr, 2, 1);
		pack_code(bp_prot2, &bit_ptr, &bit_cntr, 2, 1);
		pack_code(bp_prot1, &bit_ptr, &bit_cntr, 2, 1);
	}

	/* ====== Packing Fourier magnitudes ====== */
	pack_code(qpar->fs_index, &bit_ptr, &bit_cntr, FS_BITS, 1);

	/* ====== Packing jitter index ====== */
	pack_code(qpar->jit_index[0], &bit_ptr, &bit_cntr, 1, 1);

	/* ======== Write channel output buffer ======== */
	qpar->chptr = chbuf;
	qpar->chbit = 0;
	for (i = 0; i < bitNum12; i++) {
		pack_code(bit_buffer[i], &qpar->chptr, &qpar->chbit, 1,
			  chwordsize);
		if (i == 0)
			*(qpar->chptr) |= 0x8000;	/* set beginning of frame bit */
	}
}