コード例 #1
0
ファイル: LoRaPHYUS915.cpp プロジェクト: OpenNuvoton/mbed
bool LoRaPHYUS915::tx_config(tx_config_params_t* config, int8_t* tx_power,
                             lorawan_time_t* tx_toa)
{
    int8_t phy_dr = datarates_US915[config->datarate];
    int8_t tx_power_limited = limit_tx_power(config->tx_power,
                                             bands[channels[config->channel].band].max_tx_pwr,
                                             config->datarate);

    uint32_t bandwidth = get_bandwidth(config->datarate);
    int8_t phy_tx_power = 0;

    // Calculate physical TX power
    phy_tx_power = compute_tx_power( tx_power_limited, US915_DEFAULT_MAX_ERP, 0 );

    _radio->lock();

    _radio->set_channel(channels[config->channel].frequency);

    _radio->set_tx_config(MODEM_LORA, phy_tx_power, 0, bandwidth, phy_dr, 1, 8,
                          false, true, 0, 0, false, 3000);

    // Setup maximum payload lenght of the radio driver
    _radio->set_max_payload_length(MODEM_LORA, config->pkt_len);

    // Get the time-on-air of the next tx frame
    *tx_toa = _radio->time_on_air(MODEM_LORA, config->pkt_len);

    _radio->unlock();

    *tx_power = tx_power_limited;

    return true;
}
コード例 #2
0
ファイル: gdashboard.c プロジェクト: nestoru/goaccess
/* iterate over the key/value pairs in the hash table */
static void
raw_data_iter (gpointer k, gpointer v, gpointer data_ptr)
{
   char *data;
   GRawData *raw_data = data_ptr;
   int hits;
   unsigned long long bw = 0;
   unsigned long long usecs = 0;

   hits = GPOINTER_TO_INT (v);
   data = (gchar *) k;
   bw = get_bandwidth (data, raw_data->module);

   raw_data->items[raw_data->idx].bw = bw;
   raw_data->items[raw_data->idx].data = data;
   raw_data->items[raw_data->idx].hits = hits;

   /* serve time in usecs */
   if (conf.serve_usecs) {
      usecs = get_serve_time (data, raw_data->module);
      raw_data->items[raw_data->idx].usecs = usecs / hits;
   }

   raw_data->idx++;
}
コード例 #3
0
ファイル: largematrix.cpp プロジェクト: erwincoumans/dynamo
void DL_largematrix::analyse_structure(){
  if (nrcols!=nrrows) {
    DL_dsystem->get_companion()->Msg("Warning: DL_largematrix::analyse_structure():\n Can only solve square systems, and this matrix is not square!!!\n");
    return;
  }
  switch (sm) {
  case lud_bcksub:
    get_bandwidth();
    return;
  case conjug_grad:
    if (2*get_nrnonzero()<nrelem) // use sparse matrix representation
      full2riss();
    return;
  case svd:
    return;
  }
}
コード例 #4
0
ファイル: LoRaPHYKR920.cpp プロジェクト: betzw/mbed
bool LoRaPHYKR920::tx_config(tx_config_params_t* config, int8_t* tx_power,
                             lorawan_time_t* tx_toa)
{
    int8_t phy_dr = datarates_KR920[config->datarate];

    if (config->tx_power > bands[channels[config->channel].band].max_tx_pwr) {
        config->tx_power = bands[channels[config->channel].band].max_tx_pwr;
    }

    uint32_t bandwidth = get_bandwidth(config->datarate);
    float max_eirp = get_max_eirp(channels[config->channel].frequency);
    int8_t phy_tx_power = 0;

    // Take the minimum between the max_eirp and txConfig->MaxEirp.
    // The value of txConfig->MaxEirp could have changed during runtime, e.g. due to a MAC command.
    max_eirp = MIN(config->max_eirp, max_eirp);

    // Calculate physical TX power
    phy_tx_power = compute_tx_power(config->tx_power, max_eirp, config->antenna_gain);

    // Setup the radio frequency
    _radio->lock();

    _radio->set_channel(channels[config->channel].frequency);

    _radio->set_tx_config(MODEM_LORA, phy_tx_power, 0, bandwidth, phy_dr, 1, 8,
                          false, true, 0, 0, false, 3000 );

    // Setup maximum payload lenght of the radio driver
    _radio->set_max_payload_length(MODEM_LORA, config->pkt_len);
    // Get the time-on-air of the next tx frame
    *tx_toa =_radio->time_on_air(MODEM_LORA, config->pkt_len);

    _radio->unlock();

    *tx_power = config->tx_power;
    return true;
}
コード例 #5
0
ファイル: fa_aacenc.c プロジェクト: BGCX067/falab-svn-to-git
uintptr_t aacenc_init(int sample_rate, int bit_rate, int chn_num,
                      int mpeg_version, int aac_objtype, int band_width, int speed_level,
                      int ms_enable, int lfe_enable, int tns_enable, int block_switch_enable, int psy_enable,
                      int blockswitch_method, int quantize_method)
{
    int i;
    int bits_average;
    int bits_res_maxsize;
    int real_band_width;
    fa_aacenc_ctx_t *f = (fa_aacenc_ctx_t *)malloc(sizeof(fa_aacenc_ctx_t));

    chn_info_t chn_info_tmp[MAX_CHANNELS];
/*
    if (bit_rate > 256000 || bit_rate < 32000)
        return (uintptr_t)NULL;
*/
    memset(f, 0, sizeof(fa_aacenc_ctx_t));
    f->speed_level = speed_level;

    /*init rom*/
    fa_aacenc_rom_init();

    /*init configuration*/
    f->cfg.sample_rate   = sample_rate;
    f->cfg.bit_rate      = bit_rate;
    f->cfg.chn_num       = chn_num;
    f->cfg.mpeg_version  = mpeg_version;
    f->cfg.aac_objtype   = aac_objtype;
    f->cfg.ms_enable     = ms_enable;
    f->cfg.lfe_enable    = lfe_enable;
    f->cfg.tns_enable    = tns_enable;
    f->cfg.sample_rate_index = get_samplerate_index(sample_rate);

    f->sample = (float *)malloc(sizeof(float)*chn_num*AAC_FRAME_LEN);
    memset(f->sample, 0, sizeof(float)*chn_num*AAC_FRAME_LEN);

    f->block_switch_en = block_switch_enable;
    f->psy_enable      = psy_enable;

    f->band_width = get_bandwidth(chn_num, sample_rate, bit_rate);
    if (speed_level > 5) {
        if (f->band_width > 10000)
            f->band_width = 10000;
    }
    if (band_width >= 5000 && band_width <= 20000) {
        if (band_width < f->band_width)
            f->band_width = band_width;
    }
    printf("band width= %d kHz\n", f->band_width);

    memset(chn_info_tmp, 0, sizeof(chn_info_t)*MAX_CHANNELS);
    get_aac_chn_info(chn_info_tmp, chn_num, lfe_enable);

    bits_average  = (bit_rate*1024)/(sample_rate*chn_num);
    bits_res_maxsize = get_aac_bitreservoir_maxsize(bits_average, sample_rate);
    f->h_bitstream = fa_bitstream_init((6144/8)*chn_num);


    switch (blockswitch_method) {
        case BLOCKSWITCH_PSY:
            f->blockswitch_method = BLOCKSWITCH_PSY;
            f->do_blockswitch  = fa_blockswitch_psy;
            break;
        case BLOCKSWITCH_VAR:
            f->blockswitch_method = BLOCKSWITCH_VAR;
            f->do_blockswitch  = fa_blockswitch_var;
            break;
        default:
            f->blockswitch_method = BLOCKSWITCH_VAR;
            f->do_blockswitch  = fa_blockswitch_var;
            break;

    }

    switch (quantize_method) {
        case QUANTIZE_LOOP:
            f->quantize_method = QUANTIZE_LOOP;
            f->do_quantize = fa_quantize_loop;
            break;
        case QUANTIZE_FAST:
            f->quantize_method = QUANTIZE_FAST;
            f->do_quantize = fa_quantize_fast;
            break;
        default:
            f->quantize_method = QUANTIZE_LOOP;
            f->do_quantize = fa_quantize_loop;

    }

    /*init psy and mdct quant */
    for (i = 0; i < chn_num; i++) {
        f->ctx[i].pe                = 0.0;
        f->ctx[i].var_max_prev      = 0.0;
        f->ctx[i].block_type        = ONLY_LONG_BLOCK;
        f->ctx[i].psy_enable        = psy_enable;
        f->ctx[i].window_shape      = SINE_WINDOW;
        f->ctx[i].common_scalefac   = 0;
        memset(f->ctx[i].scalefactor, 0, sizeof(int)*8*FA_SWB_NUM_MAX);
        memset(f->ctx[i].scalefactor_win, 0, sizeof(int)*8*FA_SWB_NUM_MAX);

        f->ctx[i].num_window_groups = 1;
        f->ctx[i].window_group_length[0] = 1;
        f->ctx[i].window_group_length[1] = 0;
        f->ctx[i].window_group_length[2] = 0;
        f->ctx[i].window_group_length[3] = 0;
        f->ctx[i].window_group_length[4] = 0;
        f->ctx[i].window_group_length[5] = 0;
        f->ctx[i].window_group_length[6] = 0;
        f->ctx[i].window_group_length[7] = 0;

        memset(f->ctx[i].lastx, 0, sizeof(int)*8);
        memset(f->ctx[i].avgenergy, 0, sizeof(float)*8);

        f->ctx[i].used_bits= 0;

        f->ctx[i].bits_average     = bits_average;
        f->ctx[i].bits_res_maxsize = bits_res_maxsize;
        f->ctx[i].res_buf          = (unsigned char *)malloc(sizeof(unsigned char)*(bits_res_maxsize/8 + 1));
        memset(f->ctx[i].res_buf, 0, sizeof(unsigned char)*(bits_res_maxsize/8 + 1));
        f->ctx[i].bits_res_size    = 0;
        f->ctx[i].last_common_scalefac = 0;

        f->ctx[i].h_aacpsy        = fa_aacpsy_init(sample_rate);
        f->ctx[i].h_aac_analysis  = fa_aacfilterbank_init();

        f->ctx[i].h_tns           = fa_tns_init(f->cfg.mpeg_version, f->cfg.aac_objtype, f->cfg.sample_rate_index);

        memcpy(&(f->ctx[i].chn_info), &(chn_info_tmp[i]), sizeof(chn_info_t));
        f->ctx[i].chn_info.common_window = 0;

        if (f->ctx[i].chn_info.lfe == 1) 
            real_band_width = 2000;
        else 
            real_band_width = f->band_width;
        
        switch (sample_rate) {
            case 48000:
                f->ctx[i].cutoff_line_long = get_cutoff_line(48000, 1024, real_band_width);
                f->ctx[i].cutoff_line_short= get_cutoff_line(48000, 128 , real_band_width);
                f->ctx[i].cutoff_sfb_long  = get_cutoff_sfb(FA_SWB_48k_LONG_NUM , fa_swb_48k_long_offset , f->ctx[i].cutoff_line_long);
                f->ctx[i].cutoff_sfb_short = get_cutoff_sfb(FA_SWB_48k_SHORT_NUM, fa_swb_48k_short_offset, f->ctx[i].cutoff_line_short);
                /*f->ctx[i].h_mdctq_long = fa_mdctquant_init(1024, FA_SWB_48k_LONG_NUM ,fa_swb_48k_long_offset, 1);*/
                /*f->ctx[i].h_mdctq_short= fa_mdctquant_init(128 , FA_SWB_48k_SHORT_NUM,fa_swb_48k_short_offset, 8);*/
                f->ctx[i].h_mdctq_long = fa_mdctquant_init(1024, f->ctx[i].cutoff_sfb_long , fa_swb_48k_long_offset, 1);
                f->ctx[i].h_mdctq_short= fa_mdctquant_init(128 , f->ctx[i].cutoff_sfb_short, fa_swb_48k_short_offset, 8);
                /*f->ctx[i].sfb_num_long = FA_SWB_48k_LONG_NUM;*/
                /*f->ctx[i].sfb_num_short= FA_SWB_48k_SHORT_NUM;*/
                f->ctx[i].sfb_num_long = f->ctx[i].cutoff_sfb_long;
                f->ctx[i].sfb_num_short= f->ctx[i].cutoff_sfb_short;
                break;
            case 44100:
                f->ctx[i].cutoff_line_long = get_cutoff_line(44100, 1024, real_band_width);
                f->ctx[i].cutoff_line_short= get_cutoff_line(44100, 128 , real_band_width);
                f->ctx[i].cutoff_sfb_long  = get_cutoff_sfb(FA_SWB_44k_LONG_NUM , fa_swb_44k_long_offset , f->ctx[i].cutoff_line_long);
                f->ctx[i].cutoff_sfb_short = get_cutoff_sfb(FA_SWB_44k_SHORT_NUM, fa_swb_44k_short_offset, f->ctx[i].cutoff_line_short);
                /*f->ctx[i].h_mdctq_long = fa_mdctquant_init(1024, FA_SWB_44k_LONG_NUM ,fa_swb_44k_long_offset, 1);*/
                /*f->ctx[i].h_mdctq_short= fa_mdctquant_init(128 , FA_SWB_44k_SHORT_NUM,fa_swb_44k_short_offset, 8);*/
                f->ctx[i].h_mdctq_long = fa_mdctquant_init(1024, f->ctx[i].cutoff_sfb_long , fa_swb_44k_long_offset, 1);
                f->ctx[i].h_mdctq_short= fa_mdctquant_init(128 , f->ctx[i].cutoff_sfb_short, fa_swb_44k_short_offset, 8);
                f->ctx[i].sfb_num_long = f->ctx[i].cutoff_sfb_long;
                f->ctx[i].sfb_num_short= f->ctx[i].cutoff_sfb_short;
                break;
            case 32000:
                f->ctx[i].cutoff_line_long = get_cutoff_line(32000, 1024, real_band_width);
                f->ctx[i].cutoff_line_short= get_cutoff_line(32000, 128 , real_band_width);
                f->ctx[i].cutoff_sfb_long  = get_cutoff_sfb(FA_SWB_32k_LONG_NUM , fa_swb_32k_long_offset , f->ctx[i].cutoff_line_long);
                f->ctx[i].cutoff_sfb_short = get_cutoff_sfb(FA_SWB_32k_SHORT_NUM, fa_swb_32k_short_offset, f->ctx[i].cutoff_line_short);
                /*f->ctx[i].h_mdctq_long = fa_mdctquant_init(1024, FA_SWB_32k_LONG_NUM ,fa_swb_32k_long_offset, 1);*/
                /*f->ctx[i].h_mdctq_short= fa_mdctquant_init(128 , FA_SWB_32k_SHORT_NUM,fa_swb_32k_short_offset, 8);*/
                f->ctx[i].h_mdctq_long = fa_mdctquant_init(1024, f->ctx[i].cutoff_sfb_long , fa_swb_32k_long_offset, 1);
                f->ctx[i].h_mdctq_short= fa_mdctquant_init(128 , f->ctx[i].cutoff_sfb_short, fa_swb_32k_short_offset, 8);
                /*f->ctx[i].sfb_num_long = FA_SWB_32k_LONG_NUM;*/
                /*f->ctx[i].sfb_num_short= FA_SWB_32k_SHORT_NUM;*/
                f->ctx[i].sfb_num_long = f->ctx[i].cutoff_sfb_long;
                f->ctx[i].sfb_num_short= f->ctx[i].cutoff_sfb_short;
                break;
        }


        memset(f->ctx[i].mdct_line, 0, sizeof(float)*2*AAC_FRAME_LEN);

        /*f->ctx[i].max_pred_sfb = get_max_pred_sfb(f->cfg.sample_rate_index);*/

        f->ctx[i].quant_ok = 0;
    }

    /*f->bitres_maxsize = get_aac_bitreservoir_maxsize(f->cfg.bit_rate, f->cfg.sample_rate);*/
    

    return (uintptr_t)f;
}
コード例 #6
0
/*get the channel current in use*/
int get_extchannel(int radio, Channel_t *extchannel_get)
{
	int ret = 0;
	int bandWidth = 0;
	int wlan_mode = 0;
	FILE *fin;
	char c;
    char str[256] = {0};
	char cmd[256] = {0};
	char exchannel[8] = {0};
	char vap_name[8] = {0};
	Channel_t channel_get;
	memset(&channel_get, 0, sizeof(Channel_t));

	ret = get_bandwidth(radio, &bandWidth);

	if (ret == T_FAILURE) {
		printf("Error: Get BandWidth Failure\n");
		return T_FAILURE;
	}

	if (BANDWIDTH_40 == bandWidth) {
		
		ret = get_current_channel(radio, &channel_get);
		
		if (T_FAILURE == ret) {
			
			printf("Error:Get Operation Channel Failure\n");
			return T_FAILURE;
			
		} else {

			nvram_get_wlan_mode(radio, &wlan_mode);
    		ret = construct_vap(vap_name, radio, 0, wlan_mode);

			if (T_FAILURE == ret) {
				
				printf("Error:Get Vap Name Failure\n");
				return T_FAILURE;
			}

			//iwpriv athN get_chextoffset | awk '{gsub(/get_chextoffset:/,"");print}' | awk '{print $2}' > /tmp/extchannel
			sprintf(cmd, "iwpriv %s get_chextoffset | awk '{gsub(/get_chextoffset:/,\"\");print}' | awk '{print $2}' > /tmp/extchannel", vap_name);
    		EXE_COMMAND(cmd);
    		fin = fopen("/tmp/extchannel","r");
            
    		while ((c=fgetc(fin)) != EOF){
        		ungetc(c,fin);        
        		readline(str,fin);
        		strcpy_delspace(str, exchannel);
   			}
			
			fclose(fin);
			EXE_COMMAND("rm -fr /tmp/extchannel");

			if (!strcmp(exchannel, "1")) {
				extchannel_get->chan_number = channel_get.chan_number + 4;
				extchannel_get->frequency = channel_get.frequency + 20;
			} else if (!strcmp(exchannel, "-1")) {
				extchannel_get->chan_number = channel_get.chan_number - 4;
				extchannel_get->frequency = channel_get.frequency - 20;
			} else {
				printf("Error: CMD get_chextoffset Failure\n");
				return T_FAILURE;
			}
		}
		
	} else {
	
		printf("Get BandWidth Not 40MHz\n");
		return T_FAILURE;
	}

	return T_SUCCESS;
}
コード例 #7
0
ファイル: fa_aacenc.c プロジェクト: jackyxinli/falab
uintptr_t aacenc_init(int sample_rate, int bit_rate, int chn_num, float qcof, int vbr_flag,
                      int mpeg_version, int aac_objtype, float band_width, int speed_level,
                      int ms_enable, int lfe_enable, int tns_enable, int block_switch_enable, int psy_enable, int psy_model,
                      int blockswitch_method, int quantize_method, int time_resolution_first)
{
    int i;
    int bits_adj;
    int bits_average;
    int bits_res_maxsize;
    int real_band_width;
    float bits_thr_cof;
    float adj;
    fa_aacenc_ctx_t *f = (fa_aacenc_ctx_t *)malloc(sizeof(fa_aacenc_ctx_t));

    chn_info_t chn_info_tmp[MAX_CHANNELS];
/*
    if (bit_rate > 256000 || bit_rate < 32000)
        return (uintptr_t)NULL;
*/
    memset(f, 0, sizeof(fa_aacenc_ctx_t));
    f->speed_level = speed_level;

    /*init rom*/
    fa_aacenc_rom_init();

    /*init configuration*/
    f->cfg.sample_rate   = sample_rate;
    f->cfg.bit_rate      = bit_rate;
    f->cfg.qcof          = qcof;
    f->cfg.vbr_flag      = vbr_flag;
    f->cfg.chn_num       = chn_num;
    f->cfg.mpeg_version  = mpeg_version;
    f->cfg.aac_objtype   = aac_objtype;
    f->cfg.ms_enable     = ms_enable;
    f->cfg.lfe_enable    = lfe_enable;
    f->cfg.tns_enable    = tns_enable;
    f->cfg.sample_rate_index = get_samplerate_index(sample_rate);

    f->sample = (float *)malloc(sizeof(float)*chn_num*AAC_FRAME_LEN);
    memset(f->sample, 0, sizeof(float)*chn_num*AAC_FRAME_LEN);

    f->block_switch_en = block_switch_enable;
    f->psy_enable      = psy_enable;
    f->psy_model       = psy_model;

    if (vbr_flag) {
        f->band_width = get_bandwidth1(chn_num, sample_rate, qcof, &(f->cfg.bit_rate)); 
        bit_rate = f->cfg.bit_rate;
        /*printf("\nNOTE: final bitrate/chn = %d\n", f->cfg.bit_rate);*/
    } else {
        f->band_width = get_bandwidth(chn_num, sample_rate, bit_rate, &(f->cfg.qcof));
        /*printf("\nNOTE: final qcof = %f\n", f->cfg.qcof);*/
    }

    bits_adj = 0;

    if (bit_rate >= 200000 && bit_rate < 260000)
        bits_adj = 9000;
    if (bit_rate >= 140000 && bit_rate < 200000)
        bits_adj = 4000;
    if (bit_rate >= 90000  && bit_rate < 110000)
        bits_adj = -2000;

#if 0
    bits_thr_cof  = get_bit_thr_cof(chn_num, sample_rate, bit_rate);
    adj = get_adj_cof(chn_num, sample_rate, bit_rate);
#else 
    bits_thr_cof  = get_bit_thr_cof(chn_num, sample_rate, bit_rate+bits_adj);
    adj = get_adj_cof(chn_num, sample_rate, bit_rate+bits_adj);
#endif
    /*printf("bits thr cof=%f\n", bits_thr_cof);*/

    if (speed_level > 5) {
        if (f->band_width > 10000.)
            f->band_width = 10000.;
    }
    /*if (band_width >= 5000 && band_width <= 20000) {*/
    if (band_width >= 5000. && band_width <= BW_MAX) {
        if (band_width < f->band_width)
            f->band_width = band_width;
    }
    printf("band width= %f kHz\n", f->band_width);

    memset(chn_info_tmp, 0, sizeof(chn_info_t)*MAX_CHANNELS);
    get_aac_chn_info(chn_info_tmp, chn_num, lfe_enable);

    /*bits_average  = (bit_rate*1024)/(sample_rate*chn_num);*/
    bits_average  = ((bit_rate+bits_adj)*1024)/(sample_rate*chn_num);
    bits_res_maxsize = get_aac_bitreservoir_maxsize(bits_average, sample_rate);
    f->h_bitstream = fa_bitstream_init((6144/8)*chn_num);


    switch (blockswitch_method) {
        case BLOCKSWITCH_PSY:
            f->blockswitch_method = BLOCKSWITCH_PSY;
            f->do_blockswitch  = fa_blockswitch_psy;
            break;
        case BLOCKSWITCH_VAR:
            f->blockswitch_method = BLOCKSWITCH_VAR;
            f->do_blockswitch  = fa_blockswitch_var;
            break;
        default:
            f->blockswitch_method = BLOCKSWITCH_VAR;
            f->do_blockswitch  = fa_blockswitch_var;
            break;

    }

    switch (quantize_method) {
        case QUANTIZE_LOOP:
            f->quantize_method = QUANTIZE_LOOP;
            f->do_quantize = fa_quantize_loop;
            break;
        case QUANTIZE_FAST:
            f->quantize_method = QUANTIZE_FAST;
            f->do_quantize = fa_quantize_fast;
            break;
        case QUANTIZE_BEST:
            f->quantize_method = QUANTIZE_BEST;
            f->do_quantize = fa_quantize_best;
            /*f->do_quantize = fa_quantize_fast;*/
            /*f->do_quantize = fa_quantize_loop;*/
            break;
        default:
            f->quantize_method = QUANTIZE_BEST;
            f->do_quantize = fa_quantize_best;

    }

    /*init psy and mdct quant */
    for (i = 0; i < chn_num; i++) {
        f->ctx[i].h_blockctrl = fa_blockswitch_init(2048);
        f->ctx[i].time_resolution_first = time_resolution_first;

        f->ctx[i].pe                = 0.0;
        f->ctx[i].var_max_prev      = 0.0;
        f->ctx[i].block_type        = ONLY_LONG_BLOCK;
        f->ctx[i].psy_enable        = psy_enable;
        f->ctx[i].window_shape      = SINE_WINDOW;
        f->ctx[i].common_scalefac   = 0;
        memset(f->ctx[i].scalefactor, 0, sizeof(int)*8*FA_SWB_NUM_MAX);
        memset(f->ctx[i].scalefactor_win, 0, sizeof(int)*8*FA_SWB_NUM_MAX);
        memset(f->ctx[i].maxscale_win,0, sizeof(int)*8*FA_SWB_NUM_MAX);
        memset(f->ctx[i].xmin, 0, sizeof(float)*8*FA_SWB_NUM_MAX);

        memset(f->ctx[i].miu,0, sizeof(float)*8*FA_SWB_NUM_MAX);
        memset(f->ctx[i].miuhalf,0, sizeof(float)*8*FA_SWB_NUM_MAX);
        memset(f->ctx[i].miu2, 0, sizeof(float)*8*FA_SWB_NUM_MAX);
        memset(f->ctx[i].pdft, 0, sizeof(float)*8*FA_SWB_NUM_MAX);
        memset(f->ctx[i].Px, 0, sizeof(float)*8*FA_SWB_NUM_MAX);
        memset(f->ctx[i].Tm, 0, sizeof(float)*8*FA_SWB_NUM_MAX);
        memset(f->ctx[i].Ti, 0, sizeof(float)*8*FA_SWB_NUM_MAX);
        memset(f->ctx[i].Ti1,0, sizeof(float)*8*FA_SWB_NUM_MAX);
        memset(f->ctx[i].G  ,0, sizeof(float)*8*FA_SWB_NUM_MAX);
        f->ctx[i].Pt_long  = 0;
        f->ctx[i].Pt_short = 0;
        f->ctx[i].up = 0;
        f->ctx[i].step_down_db = 0.0;
        f->ctx[i].bit_thr_cof = bits_thr_cof;
        f->ctx[i].adj         = adj;

        f->ctx[i].num_window_groups = 1;
        f->ctx[i].window_group_length[0] = 1;
        f->ctx[i].window_group_length[1] = 0;
        f->ctx[i].window_group_length[2] = 0;
        f->ctx[i].window_group_length[3] = 0;
        f->ctx[i].window_group_length[4] = 0;
        f->ctx[i].window_group_length[5] = 0;
        f->ctx[i].window_group_length[6] = 0;
        f->ctx[i].window_group_length[7] = 0;

        memset(f->ctx[i].lastx, 0, sizeof(int)*8);
        memset(f->ctx[i].avgenergy, 0, sizeof(float)*8);

        f->ctx[i].used_bits= 0;

        f->ctx[i].bits_average     = bits_average;
        f->ctx[i].bits_res_maxsize = bits_res_maxsize;
        f->ctx[i].res_buf          = (unsigned char *)malloc(sizeof(unsigned char)*(bits_res_maxsize/8 + 1));
        memset(f->ctx[i].res_buf, 0, sizeof(unsigned char)*(bits_res_maxsize/8 + 1));
        f->ctx[i].bits_res_size    = 0;
        f->ctx[i].last_common_scalefac = 0;

        f->ctx[i].h_aacpsy        = fa_aacpsy_init(sample_rate);
        f->ctx[i].h_aac_analysis  = fa_aacfilterbank_init();

        f->ctx[i].h_tns           = fa_tns_init(f->cfg.mpeg_version, f->cfg.aac_objtype, f->cfg.sample_rate_index);
        f->ctx[i].tns_active      = 0;

        memcpy(&(f->ctx[i].chn_info), &(chn_info_tmp[i]), sizeof(chn_info_t));
        f->ctx[i].chn_info.common_window = 0;

        if (f->ctx[i].chn_info.lfe == 1) 
            real_band_width = 2000;
        else 
            real_band_width = (int)f->band_width;
        
        switch (sample_rate) {
            case 48000:
                f->ctx[i].cutoff_line_long = get_cutoff_line(48000, 1024, real_band_width);
                f->ctx[i].cutoff_line_short= get_cutoff_line(48000, 128 , real_band_width);
                f->ctx[i].cutoff_sfb_long  = get_cutoff_sfb(FA_SWB_48k_LONG_NUM , fa_swb_48k_long_offset , f->ctx[i].cutoff_line_long);
                f->ctx[i].cutoff_sfb_short = get_cutoff_sfb(FA_SWB_48k_SHORT_NUM, fa_swb_48k_short_offset, f->ctx[i].cutoff_line_short);
                f->ctx[i].h_mdctq_long = fa_mdctquant_init(1024, f->ctx[i].cutoff_sfb_long , fa_swb_48k_long_offset, 1);
                f->ctx[i].h_mdctq_short= fa_mdctquant_init(128 , f->ctx[i].cutoff_sfb_short, fa_swb_48k_short_offset, 8);
                f->ctx[i].sfb_num_long = f->ctx[i].cutoff_sfb_long;
                f->ctx[i].sfb_num_short= f->ctx[i].cutoff_sfb_short;
                f->ctx[i].Pt_long  = fa_protect_db_48k_long;
                f->ctx[i].Pt_short = fa_protect_db_48k_short;
                break;
            case 44100:
                f->ctx[i].cutoff_line_long = get_cutoff_line(44100, 1024, real_band_width);
                f->ctx[i].cutoff_line_short= get_cutoff_line(44100, 128 , real_band_width);
                f->ctx[i].cutoff_sfb_long  = get_cutoff_sfb(FA_SWB_44k_LONG_NUM , fa_swb_44k_long_offset , f->ctx[i].cutoff_line_long);
                f->ctx[i].cutoff_sfb_short = get_cutoff_sfb(FA_SWB_44k_SHORT_NUM, fa_swb_44k_short_offset, f->ctx[i].cutoff_line_short);
                f->ctx[i].h_mdctq_long = fa_mdctquant_init(1024, f->ctx[i].cutoff_sfb_long , fa_swb_44k_long_offset, 1);
                f->ctx[i].h_mdctq_short= fa_mdctquant_init(128 , f->ctx[i].cutoff_sfb_short, fa_swb_44k_short_offset, 8);
                f->ctx[i].sfb_num_long = f->ctx[i].cutoff_sfb_long;
                f->ctx[i].sfb_num_short= f->ctx[i].cutoff_sfb_short;
                f->ctx[i].Pt_long  = fa_protect_db_44k_long;
                f->ctx[i].Pt_short = fa_protect_db_44k_short;
                break;
            case 32000:
                f->ctx[i].cutoff_line_long = get_cutoff_line(32000, 1024, real_band_width);
                f->ctx[i].cutoff_line_short= get_cutoff_line(32000, 128 , real_band_width);
                f->ctx[i].cutoff_sfb_long  = get_cutoff_sfb(FA_SWB_32k_LONG_NUM , fa_swb_32k_long_offset , f->ctx[i].cutoff_line_long);
                f->ctx[i].cutoff_sfb_short = get_cutoff_sfb(FA_SWB_32k_SHORT_NUM, fa_swb_32k_short_offset, f->ctx[i].cutoff_line_short);
                f->ctx[i].h_mdctq_long = fa_mdctquant_init(1024, f->ctx[i].cutoff_sfb_long , fa_swb_32k_long_offset, 1);
                f->ctx[i].h_mdctq_short= fa_mdctquant_init(128 , f->ctx[i].cutoff_sfb_short, fa_swb_32k_short_offset, 8);
                f->ctx[i].sfb_num_long = f->ctx[i].cutoff_sfb_long;
                f->ctx[i].sfb_num_short= f->ctx[i].cutoff_sfb_short;
                f->ctx[i].Pt_long  = fa_protect_db_32k_long;
                f->ctx[i].Pt_short = fa_protect_db_32k_short;
                break;
        }


        memset(f->ctx[i].mdct_line, 0, sizeof(float)*2*AAC_FRAME_LEN);

        /*f->ctx[i].max_pred_sfb = get_max_pred_sfb(f->cfg.sample_rate_index);*/

        f->ctx[i].quant_ok = 0;

        if (f->band_width < BW_MAX) {
            if (time_resolution_first)
                fa_quantqdf_para_init(&(f->ctx[i].qp), 0.9);
            else 
                /*fa_quantqdf_para_init(&(f->ctx[i].qp), 0.95);*/
                fa_quantqdf_para_init(&(f->ctx[i].qp), 0.85);
        } else { 
            if (time_resolution_first)
                fa_quantqdf_para_init(&(f->ctx[i].qp), 0.9);
            else 
                /*fa_quantqdf_para_init(&(f->ctx[i].qp), 1.0);*/
                fa_quantqdf_para_init(&(f->ctx[i].qp), 0.9);
        }

    }

    /*f->bitres_maxsize = get_aac_bitreservoir_maxsize(f->cfg.bit_rate, f->cfg.sample_rate);*/
    

    return (uintptr_t)f;
}