📄 celp_encoder.c
字号:
{ /* -----------------------------------------------------------------*/ /* Check if a bit rate is one of the allowed bit rates */ /* -----------------------------------------------------------------*/ if (bit_rate == BIT_RATE_1) { *RPE_configuration = 0; *frame_size = FIFTEEN_MS; *n_subframes = 6; } else if (bit_rate == BIT_RATE_2) { *RPE_configuration = 1; *frame_size = TEN_MS; *n_subframes = 4; } else if (bit_rate == BIT_RATE_3) { *RPE_configuration = 2; *frame_size = FIFTEEN_MS; *n_subframes = 8; } else if (bit_rate == BIT_RATE_4) { *RPE_configuration = 3; *frame_size = FIFTEEN_MS; *n_subframes = 10; } else { fprintf(stderr, "ERROR: Bit Rate not in the set of supported bit rates \n"); fprintf (stderr, "Supported bit rates when FineRate Control disabled: \n"); fprintf (stderr, " RPE_Configuration 0: %d bps\n", BIT_RATE_1); fprintf (stderr, " RPE_Configuration 1: %d bps\n", BIT_RATE_2); fprintf (stderr, " RPE_Configuration 2: %d bps\n", BIT_RATE_3); fprintf (stderr, " RPE_Configuration 3: %d bps\n", BIT_RATE_4); exit(1); } } else { /* FineRate Control on */ /* -----------------------------------------------------------------*/ /* Determine RPE_Configuration */ /* -----------------------------------------------------------------*/ if (InputConfiguration == -1) { /* RPE_Configuration not specified on command line: determine configuration from bitrate */ if ((bit_rate >= BIT_RATE_1) && (bit_rate <= BIT_RATE_3)) { *RPE_configuration = 0; } else if ((bit_rate > BIT_RATE_3) && (bit_rate <= BIT_RATE_4)) { *RPE_configuration = 1; } else if ((bit_rate >= BIT_RATE_5) && (bit_rate <= BIT_RATE_6)) { *RPE_configuration = 2; } else if ((bit_rate >= BIT_RATE_7) && (bit_rate <= BIT_RATE_8)) { *RPE_configuration = 3; } else { fprintf (stderr, "ERROR: Bit Rate not in the set of supported bit rates \n"); fprintf (stderr, "Supported bit rates when FineRate Control enabled: \n"); fprintf (stderr, " RPE_Configuration 0: %d-%d bps\n", BIT_RATE_1, BIT_RATE_2); fprintf (stderr, " RPE_Configuration 1: %d-%d bps\n", BIT_RATE_3, BIT_RATE_4); fprintf (stderr, " RPE_Configuration 2: %d-%d bps\n", BIT_RATE_5, BIT_RATE_6); fprintf (stderr, " RPE_Configuration 3: %d-%d bps\n", BIT_RATE_7, BIT_RATE_8); exit (1); } } else { /* RPE_Configuration specified on command line: check consistency with the specified bitrate */ if (((InputConfiguration == 0) && ((bit_rate < BIT_RATE_1) || (bit_rate > BIT_RATE_2))) || ((InputConfiguration == 1) && ((bit_rate < BIT_RATE_3) || (bit_rate > BIT_RATE_4))) || ((InputConfiguration == 2) && ((bit_rate < BIT_RATE_5) || (bit_rate > BIT_RATE_6))) || ((InputConfiguration == 3) && ((bit_rate < BIT_RATE_7) || (bit_rate > BIT_RATE_8)))) { fprintf (stderr, "ERROR: Bit Rate not in the set of supported bit rates \n"); fprintf (stderr, "Supported bit rates when FineRate Control enabled: \n"); fprintf (stderr, " RPE_Configuration 0: %d-%d bps\n", BIT_RATE_1, BIT_RATE_2); fprintf (stderr, " RPE_Configuration 1: %d-%d bps\n", BIT_RATE_3, BIT_RATE_4); fprintf (stderr, " RPE_Configuration 2: %d-%d bps\n", BIT_RATE_5, BIT_RATE_6); fprintf (stderr, " RPE_Configuration 3: %d-%d bps\n", BIT_RATE_7, BIT_RATE_8); exit (1); } else { *RPE_configuration = InputConfiguration; } } /* -----------------------------------------------------------------*/ /* Set CELP coding parameters according to RPE_Confguration */ /* -----------------------------------------------------------------*/ switch (*RPE_configuration) { case 0 : *frame_size = FIFTEEN_MS; *n_subframes = 6; break; case 1 : *frame_size = TEN_MS; *n_subframes = 4; break; case 2 : *frame_size = FIFTEEN_MS; *n_subframes = 8; break; case 3 : *frame_size = FIFTEEN_MS; *n_subframes = 10; break; default : fprintf (stderr, "ERROR: Invalid RPE_Configuration \n"); exit (1); break; } } if (SampleRateMode == fs16kHz) { *lpc_order = ORDER_LPC_16; } *sbfrm_size = (*frame_size) / (*n_subframes); if ((prev_Qlsp_coefficients=(float *)calloc(*lpc_order, sizeof(float)))==NULL) { fprintf(stderr,"\n memory allocation error in initialization_encoder\n"); exit(5); } for (x = 0;x < (*lpc_order); x++) { *(prev_Qlsp_coefficients + x) = (x + 1) / (float)((*lpc_order) + 1); } *num_lpc_indices = N_INDICES_VQ16; *n_lpc_analysis = 1; *n_lag_candidates = MAX_N_LAG_CANDIDATES; *min_pitch_frequency = (float)1.0/(float)Lmax; *max_pitch_frequency = (float)1.0/(float)Lmin; PHI_BUFFER = ((3 * (*frame_size)) + (*sbfrm_size)/2); /* RPE only */ *num_shape_cbks = 2; *num_gain_cbks = 2; /* -----------------------------------------------------------------*/ /* Malloc parameters and set them */ /* -----------------------------------------------------------------*/ if ( (( *window_offsets = (long *)malloc((unsigned int)(*n_lpc_analysis) * sizeof(long))) == NULL )|| (( PHI_sp_pp_buf = (float *)malloc((unsigned int)PHI_BUFFER * sizeof(float))) == NULL )|| (( Downsampled_signal = (float *)malloc((unsigned int)(PHI_BUFFER/2) * sizeof(float))) == NULL )|| (( *window_sizes = (long *)malloc((unsigned int)(*n_lpc_analysis) * sizeof(long))) == NULL ) ) { fprintf(stderr,"MALLOC FAILURE in Routine abs_initialisation_encoder \n"); exit(1); } if (*RPE_configuration == 1) { (*window_sizes)[0] = TWENTY_MS; } else { (*window_sizes)[0] = TWENTY_MS + FIVE_MS; } (*window_offsets)[0] = 2 * (*frame_size) - (*window_sizes)[0]/2; /* -----------------------------------------------------------------*/ /* Initilialising data */ /* -----------------------------------------------------------------*/ for(k = 0; k < (int)PHI_BUFFER; k++) { PHI_sp_pp_buf[k] = (float)0.0; } /* -----------------------------------------------------------------*/ /* Call various init routines to allocate memory */ /* -----------------------------------------------------------------*/ PHI_allocate_energy_table(*sbfrm_size, ACBK_SIZE, Sa); PHI_init_excitation_analysis(Lmax, *lpc_order, *sbfrm_size, *RPE_configuration); *org_frame_bit_allocation = PHI_init_bit_allocation(SampleRateMode, *RPE_configuration, QuantizationMode, LosslessCodingMode, FineRateControl, *num_lpc_indices, *n_subframes, *num_shape_cbks, *num_gain_cbks); PHI_InitLpcAnalysisEncoder(*window_sizes, *n_lpc_analysis, ORDER_LPC_16, ORDER_LPC_8, (float)GAMMA_BE, bit_rate, sampling_frequency, SampleRateMode, *frame_size, *num_lpc_indices, *n_subframes, *num_shape_cbks, *num_gain_cbks, *org_frame_bit_allocation, num_indices, QuantizationMode, InstCtxt->PHI_Priv); /* -----------------------------------------------------------------*/ /* Initialise windows for wideband LPC analysis */ /* -----------------------------------------------------------------*/ { int x; float *pin; float *pout; long i; if ((SquaredHammingWindow=(float **)calloc((unsigned int)*n_lpc_analysis, sizeof(float *)))==NULL) { fprintf(stderr,"MALLOC FAILURE in Routine celp_initialisation_encoder \n"); exit(1); } for (i=0;i<*n_lpc_analysis;i++) { if((SquaredHammingWindow[i]=(float *)calloc((unsigned int)(*window_sizes)[i], sizeof(float)))==NULL) { fprintf(stderr,"MALLOC FAILURE in Routine celp_initialisation_encoder \n"); exit(1); } /* -------------------------------------------------------------*/ /* Generate Hamming Window For Lpc */ /* -------------------------------------------------------------*/ pout = SquaredHammingWindow[i]; for(x=0; x < (int)(*window_sizes)[i];x++) { *pout++ = (float)(0.540000 - 0.460000 * cos(6.283185307 * ((double)x-(double)0.00000)/(double)((*window_sizes)[i]))); } for(x = 0; x < (int)(*window_sizes)[i]; x++) { SquaredHammingWindow[i][x] *= SquaredHammingWindow[i][x]; } } /* -----------------------------------------------------------------*/ /* Generate Gamma Array for Bandwidth Expansion */ /* -----------------------------------------------------------------*/ if ( (( PHI_GammaArrayBE = (float *)malloc((unsigned int)(*lpc_order) * sizeof(float))) == NULL ) ) { fprintf(stderr,"MALLOC FAILURE in Routine celp_initialisation_encoder \n"); exit(1); } pin = PHI_GammaArrayBE; pout = PHI_GammaArrayBE; *pout++ = (float)GAMMA_BE; for (x=1; x < (int)*lpc_order; x++) { *pout++ = (float)GAMMA_BE * *pin++; } } gamma_num=PAN_GAM_MA; gamma_den=PAN_GAM_AR; /* -----------------------------------------------------------------*/ /* Initialise windows for LPC analysis */ /* -----------------------------------------------------------------*/ { int x; float *pin; float *pout; long i; if ((HammingWindow=(float **)calloc((unsigned int)*n_lpc_analysis, sizeof(float *)))==NULL) { fprintf(stderr,"MALLOC FAILURE in Routine celp_initialisation_encoder \n"); exit(1); } for (i=0;i<*n_lpc_analysis;i++) { if ((HammingWindow[i]=(float *)calloc((unsigned int)(((*window_sizes)[i])/2), sizeof(float)))==NULL) { fprintf(stderr,"MALLOC FAILURE in Routine celp_initialisation_encoder \n"); exit(1); } /* -------------------------------------------------------------*/ /* Generate Hamming Window For Lpc */ /* -------------------------------------------------------------*/ pout = HammingWindow[i]; for (x=0; x < (int)(((*window_sizes)[i])/2);x++) { *pout++ = (float)(0.540000 - 0.460000 * cos(6.283185307 * ((double)x-(double)0.00000)/(double)((((*window_sizes)[i])/2)))); } } /* -----------------------------------------------------------------*/ /* Generate Gamma Array for Bandwidth Expansion */ /* -----------------------------------------------------------------*/ if ( (( PAN_GammaArrayBE = (float *)malloc((unsigned int)(*lpc_order/2) * sizeof(float))) == NULL ) ) { fprintf(stderr,"MALLOC FAILURE in Routine celp_initialisation_encoder \n"); exit(1); } pin = PAN_GammaArrayBE; pout = PAN_GammaArrayBE; *pout++ = (float)PAN_GAMMA_BE; for(x=1; x < (int)*lpc_order/2; x++) { *pout++ = (float)PAN_GAMMA_BE * *pin++; } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -