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); }
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); }