static int or51211_read_snr(struct dvb_frontend* fe, u16* snr) { struct or51211_state* state = fe->demodulator_priv; u8 rec_buf[2]; u8 snd_buf[3]; /* SNR after Equalizer */ snd_buf[0] = 0x04; snd_buf[1] = 0x00; snd_buf[2] = 0x04; if (i2c_writebytes(state,state->config->demod_address,snd_buf,3)) { printk(KERN_WARNING "%s: error writing snr reg\n", __func__); return -1; } if (i2c_readbytes(state,state->config->demod_address,rec_buf,2)) { printk(KERN_WARNING "%s: read_status read error\n", __func__); return -1; } state->snr = calculate_snr(rec_buf[0], 89599047); *snr = (state->snr) >> 16; dprintk("%s: noise = 0x%02x, snr = %d.%02d dB\n", __func__, rec_buf[0], state->snr >> 24, (((state->snr>>8) & 0xffff) * 100) >> 16); return 0; }
int mipb_frac::run() { bool targets=false; for (int user=0;user<lines;user++) { if (_rate_targets[user] != NOT_SET) targets=true; } if (targets) { for (int user=0;user<lines;user++) { if (_rate_targets[user] == NOT_SET) continue; _w_min[user]=0; _w_max[user]=1e-5; while(1) { reset_data(); load(); print_vector(_w,"_w"); print_vector(_b_total,"_b_total"); //getchar(); if (_b_total[user] > _rate_targets[user]) { _w_max[user] = _w[user]; } else if (_b_total[user] < _rate_targets[user]) { _w_min[user] = _w[user]; } if (abs(_b_total[user] - _rate_targets[user]) < _rate_tol) { printf("Converged on line %d\n",user); break; } _w[user] = (_w_max[user]+_w_min[user])/2; } } } else load(); init_lines(); calculate_snr(); }
int multiuser_new::run() { int tone,user,t_line,runs=0; FILE* fp[lines]; bool last_run=false; reset_data(); //fp[0]=fopen("line0_order.txt","w"); //fp[1]=fopen("line1_order.txt","w"); //calc_normalised_cost_matrix(); //print_cost_matrix(0,10); //calc_delta_p_debug=true; for (int user=0;user<lines;user++) { printf("rate target on line %d is %d\n",user,b_target[user]); if (b_target[user]!=NOT_SET) { t_line=user; } } while((abs(b_target[t_line] - b_total[t_line]) > 5) || last_run) { reset_data(); for (tone=0;tone<DMTCHANNELS;tone++) { for(user=0;user<lines;user++) { calc_delta_p_cost(tone,user); } } //print_cost_matrix(0,DMTCHANNELS-1); while(1) { min_cost(&tone,&user); if(all_tones_full) { break; } b[tone][user]++; // add bit to min cos tone b_total[user]++; total_bits++; update_power(tone,user); //update power on tone //fprintf(fp[user],"%d %d\n",tone,total_bits); if (last_run && graph_loading) write_current_stats(tone,user); if (b[tone][user] == MAXBITSPERTONE) { F[tone][user]=1; } if (b_total[user] == b_target[user]) { freeze_user(user); if (last_run) printf("just froze user %d cos he got his target\n",user); } for (int user=0;user<lines;user++) calc_delta_p_cost(tone,user); // update delta_p on all lines for this tone } /*for (int user=0;user<lines;user++) { printf("b_%d = %d\n",user,b_total[user]); }*/ //printf("w = %lf\n",w[t_line]); //getchar(); if (last_run) { printf("this is the last run so setting last_run to false\n"); last_run=false; break; } if (abs(b_target[t_line] - b_total[t_line]) < 5) { printf("Met the rate target, setting the last_run to true\n"); last_run=true; continue; } if (b_total[t_line] > b_target[t_line]) { // if rate > target_rate then this is the min weight // printf("Rate is greater than target, so increase the weight and we have found the min weight\n"); w_min[t_line]=w[t_line]; // set the min weight if (w_max[t_line] < 0) { // dont yet know the max weight // printf("dont yet know the max weight so increase the weight\n"); w[t_line]*=2; } } else { // this is the max weight // printf("Rate is less than target so decrease the weight and we have found the max weight\n"); w_max[t_line]=w[t_line]; if (w_min[t_line] < 0) { // printf("dont yet know the min weight so decrease the weight\n"); w[t_line]/=2; } } if (w_max[t_line] > 0 && w_min[t_line] > 0) { w[t_line] = (w_max[t_line]+w_min[t_line])/2; // printf("Currently bisecting, new weight is %lf\n",w[t_line]); } } //for (int user=0;user<lines;user++) // fclose(fp[user]); init_lines(); calculate_snr(); set_loading_algo(); return 0; }
static double snr_test (SINGLE_TEST *test_data, int number, int converter, int verbose, double *conversion_rate) { static float data [BUFFER_LEN + 1] ; static float output [MAX_SPEC_LEN] ; SRC_STATE *src_state ; SRC_DATA src_data ; clock_t start_clock, clock_time ; double output_peak, snr ; int k, output_len, input_len, error ; if (verbose != 0) { printf ("\tSignal-to-Noise Ratio Test %d.\n" "\t=====================================\n", number) ; printf ("\tFrequencies : [ ") ; for (k = 0 ; k < test_data->freq_count ; k++) printf ("%6.4f ", test_data->freqs [k]) ; printf ("]\n\tSRC Ratio : %8.4f\n", test_data->src_ratio) ; } else { printf ("\tSignal-to-Noise Ratio Test %d : ", number) ; fflush (stdout) ; } ; /* Set up the output array. */ if (test_data->src_ratio >= 1.0) { output_len = MAX_SPEC_LEN ; input_len = (int) ceil (MAX_SPEC_LEN / test_data->src_ratio) ; if (input_len > BUFFER_LEN) input_len = BUFFER_LEN ; } else { input_len = BUFFER_LEN ; output_len = (int) ceil (BUFFER_LEN * test_data->src_ratio) ; output_len &= ((-1) << 4) ; if (output_len > MAX_SPEC_LEN) output_len = MAX_SPEC_LEN ; input_len = (int) ceil (output_len / test_data->src_ratio) ; } ; memset (output, 0, sizeof (output)) ; /* Generate input data array. */ gen_windowed_sines (data, input_len, test_data->freqs, test_data->freq_count) ; /* Perform sample rate conversion. */ if ((src_state = src_new (converter, 1, &error)) == NULL) { printf ("\n\nLine %d : src_new() failed : %s.\n\n", __LINE__, src_strerror (error)) ; exit (1) ; } ; src_data.end_of_input = 1 ; /* Only one buffer worth of input. */ src_data.data_in = data ; src_data.input_frames = input_len ; src_data.src_ratio = test_data->src_ratio ; src_data.data_out = output ; src_data.output_frames = output_len ; start_clock = clock () ; if ((error = src_process (src_state, &src_data))) { printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ; exit (1) ; } ; clock_time = clock () - start_clock ; src_state = src_delete (src_state) ; if (clock_time <= 0) clock_time = 1 ; *conversion_rate = (1.0 * output_len * CLOCKS_PER_SEC) / clock_time ; if (test_data->src_ratio < 1.0) *conversion_rate /= test_data->src_ratio ; if (verbose != 0) { printf ("\tOutput Rate : %.0f samples/sec\n", *conversion_rate) ; printf ("\tOutput Len : %ld\n", src_data.output_frames_gen) ; } ; if (abs (src_data.output_frames_gen - output_len) > 4) { printf ("\n\nLine %d : output data length should be %d.\n\n", __LINE__, output_len) ; exit (1) ; } ; /* Check output peak. */ output_peak = find_peak (output, src_data.output_frames_gen) ; if (verbose != 0) printf ("\tOutput Peak : %6.4f\n", output_peak) ; if (fabs (output_peak - test_data->peak_value) > 0.01) { printf ("\n\nLine %d : output peak (%6.4f) should be %6.4f\n\n", __LINE__, output_peak, test_data->peak_value) ; save_oct_data ("snr_test.dat", data, BUFFER_LEN, output, output_len) ; exit (1) ; } ; /* Calculate signal-to-noise ratio. */ snr = calculate_snr (output, src_data.output_frames_gen) ; if (snr < 0.0) { /* An error occurred. */ save_oct_data ("snr_test.dat", data, BUFFER_LEN, output, src_data.output_frames_gen) ; exit (1) ; } ; if (verbose != 0) printf ("\tSNR Ratio : %.2f dB\n", snr) ; if (snr < test_data->snr) { printf ("\n\nLine %d : SNR (%5.2f) should be > %6.2f dB\n\n", __LINE__, snr, test_data->snr) ; exit (1) ; } ; if (verbose != 0) puts ("\t-------------------------------------\n\tPass\n") ; else puts ("Pass") ; return snr ; } /* snr_test */
int multiuser_new::run_a() { int tone,user,t_line,runs=0; FILE* fp; bool last_run=false; reset_data(); //calc_ave_bits(); //calc_ave_xtalk(); /* for (int user=0;user<lines;user++) { double max=0; int line=0; for (int xtalker=0;xtalker<lines;xtalker++) { if (xtalker==user) continue; if (ave_xtalk[user][xtalker] > max) { max = ave_xtalk[user][xtalker]; line = xtalker; } } printf("Worst xtalker into line %d = line %d\n",user,line); } */ //exit(0); //for (int user=0;user<lines;user++) { // printf("rate target on line %d is %d\n",user,b_target[user]); //} do { iter_count++; reset_data(); init_cost_matrix(); //for (int user=0;user<lines;user++) { // printf("w[%d] = %4.2lf\n",user,w[user]); //} while(1) { min_cost(&tone,&user); printf("Min tone/user was %d/%d\n",tone,user); //getchar(); //if (tone == 115 && user == 1) { // getchar(); //} if(all_tones_full) { printf("All tones are full on iteration number %d\n",iter_count); break; } b[tone][user]++; // add bit to min cos tone b_total[user]++; total_bits++; //printf("Added a bit to user %d tone %d\n",user,tone); //print_vector(cost[tone],"Costs on current tone"); update_power(tone,user); //update power on tone //print_vector(p[tone],"p on tone"); //getchar(); print_vector(b_total,"b_total"); printf("total bits = %d\n",total_bits); print_vector(p_used,"p_used"); if (!greedy) update_wp(); //print_vector(wp,"wp"); //getchar(); if (graph_loading) write_current_stats(tone,user); /* if (b[tone][user] == MAXBITSPERTONE) { F[tone][user]=1; } if (!rate_targets_off) { if (b_total[user] == b_target[user]) { freeze_user(user); printf("just froze user %d cos he got his target\n",user); printf("Power used by user %d when frozen = %lf\n",user,p_used[user]); init_cost_matrix(); user_re_init[user]=true; } } */ /*for (int user=0;user<lines;user++) { if (user_frozen[user] == true && user_re_init[user] == false) { init_cost_matrix(); user_re_init[user]=true; } }*/ /* bool update=false; for (int user1=0;user1<lines;user1++) { if (wp[user1] > 1.1) { update=true; break; } } */ for (int user=0;user<lines;user++) { calc_delta_p(tone,user); // update delta_p on all lines for this tone //cost[tone][user] = cf(tone,user); } //print_vector(_delta_p[tone][user],"Delta of adding another bit"); for (int tone=0;tone<DMTCHANNELS;tone++) { for (int user=0;user<lines;user++) { cost[tone][user] = cf(tone,user); } } //print_vector(cost[tone],"New costs"); //getchar(); } for (int user=0;user<lines;user++) { printf("rate on line %d is %d\n",user,b_total[user]); } //getchar(); calc_lost_bits(); sort_lost_bits(); print_lost_bits(); if (0) { char tag[100]; sprintf(tag,"iteration%d",iter_count); init_lines(); calculate_snr(); for (int user=0;user<lines;user++) { write_mw_stats(user,tag); } } update_w(); //getchar(); } while(!finished()); if (all_rates_good()) { printf("All lines met their rate target\n"); } else { double sum=0; for (int user=0;user<lines;user++) { sum+=pow(b_total[user]-b_target[user],2); } printf("Total distance from target = %lf\n",sqrt(sum)); } //isb_optimise_p(); init_lines(); calculate_snr(); set_loading_algo(); printf("max lead = %6.4lf max lag = %6.4lf\n",max_lead,max_lag); if (graph_loading) { write_stats_totals(); } return 0; }
int osb::run() { s_l=min_step; double prev_p_distance = DBL_MAX; //double min_p_distance = DBL_MAX; double p_distance = DBL_MAX; double prev_w_distance = DBL_MAX; //double min_w_distance = DBL_MAX; double w_distance = DBL_MAX; //double *best_l = new double [lines]; //double *best_w = new double [lines]; //bool first_run=true; bool reset_l=true; bool reset_w=true; while ( !(converged()) ) { //psd->print_cache_size(); prev_p_distance = p_distance; prev_w_distance = w_distance; if (reset_l) { prev_p_distance=DBL_MAX; } reset_l=false; if (reset_w) { prev_w_distance=DBL_MAX; } reset_w=false; for (int user=0;user<lines;user++) { last_rate[user]=current_rate[user]; last_pow[user]=current_pow[user]; } optimise_p(); for (int user=0;user<lines;user++) { current_rate[user]=rate(user); current_pow[user]=tot_pow(user); } p_distance = calc_p_distance(); printf("previous l distance was %lf\n",prev_p_distance); printf("current l distance is %lf\n",p_distance); printf("current lstep is %lf\n",s_l); update_l(); /* if (p_distance <= prev_p_distance) { if (p_distance <= min_p_distance) { min_p_distance=p_distance; for (int user=0;user<lines;user++) best_l[user]=l[user]; } update_l(); s_l *= 2; printf("l step size increased to %lf\n",s_l); } else { printf("Starting a new l trajectory\n"); for (int user=0;user<lines;user++) l[user] = best_l[user]; p_distance=min_p_distance; s_l = min_step; reset_l=true; continue; } */ /* w_distance = calc_w_distance(); printf("previous distance was %lf\n",prev_w_distance); printf("current distance is %lf\n",w_distance); printf("current step is %lf\n",s_w); if (w_distance <= prev_w_distance) { if (w_distance <= min_w_distance) { min_w_distance=w_distance; for (int user=1;user<lines;user++) best_w[user]=w[user]; } update_w(); s_w *= 2; printf("w step size increased to %lf\n",s_w); } else { printf("Starting a new w trajectory\n"); for (int user=1;user<lines;user++) w[user] = best_w[user]; w_distance=min_w_distance; s_w = min_w_step; reset_w=true; } */ /* if (!first_run) { int osc=0; for (int user=0;user<lines;user++) { if (pow_oscillating(user)) { osc++; } //printf("user %d's power is oscillating\n",user); if (osc==6) { s_l/=2; printf("Reducing step size to %lf\n",s_l); break; } } } */ //update_l(); //update_w(); // //getchar(); //first_run=false; } init_lines(); calculate_snr(); return 0; }
int main(int argc, char **argv){ size_t num_resampled_elements = PFA_NOUT_AZIMUTH * PFA_NOUT_RANGE; complex **resampled = new complex*[PFA_NOUT_AZIMUTH]; complex **data = new complex*[N_PULSES]; double **input_coords = new double*[PFA_NOUT_RANGE]; for(int p=0;p<N_PULSES;p++){ *(data+p) = new complex[PFA_NOUT_RANGE]; } for(int p=0;p<PFA_NOUT_AZIMUTH;p++){ *(resampled+p) = new complex[PFA_NOUT_RANGE]; } for(int p=0;p<PFA_NOUT_RANGE;p++){ *(input_coords+p) = new double[N_PULSES]; } float *window = new float[T_PFA]; double *output_coords = new double[PFA_NOUT_AZIMUTH]; complex *gold_resampled = new complex[num_resampled_elements]; size_t num_sw = PFA_NOUT_AZIMUTH/WIN_SIZE; read_kern2_data_file( data, input_coords, output_coords, window); fprintf(stderr,"end read in input data\n"); read_data_file( (char *) gold_resampled, sizeof(complex)*num_resampled_elements); struct timeval tim1,tim2; #ifdef serial fprintf(stderr,"serial version start\n"); gettimeofday(&tim1, NULL); for(size_t col=0;col<PFA_NOUT_RANGE;col++){ sar_interp2_col( col, num_sw, resampled, data, window, input_coords, output_coords); } gettimeofday(&tim2, NULL); fprintf(stderr,"serial version end\n"); #endif #ifdef parallel fprintf(stderr,"parallel version start\n"); gettimeofday(&tim1, NULL); ar::simt_tau::par_for(PFA_NOUT_RANGE, [&](size_t col) { sar_interp2_col(col,num_sw,resampled,data,window,input_coords,output_coords); }); gettimeofday(&tim2, NULL); fprintf(stderr,"parallel version end\n"); #endif double t1=tim1.tv_sec+(tim1.tv_usec/1000000.0); double t2=tim2.tv_sec+(tim2.tv_usec/1000000.0); fprintf(stderr,"interp1@@@ %f seconds elapsed\n", t2-t1); #ifdef WRITEtoFILE FILE *wbfp=fopen("interp2.wb","wb"); for(size_t p=0;p<PFA_NOUT_AZIMUTH;p++) fwrite(*(resampled+p), sizeof(complex), PFA_NOUT_RANGE, wbfp); fclose(wbfp); #endif double snr = calculate_snr((complex *) gold_resampled,resampled); fprintf(stderr,"snr=%f\n",snr); for(int p=0;p<N_PULSES;p++){ delete[] *(data+p); } for(int p=0;p<PFA_NOUT_AZIMUTH;p++){ delete[] *(resampled+p); } for(int p=0;p<PFA_NOUT_RANGE;p++){ delete[] *(input_coords+p); } delete[] data; delete[] resampled; delete[] window; delete[] input_coords; delete[] output_coords; delete[] gold_resampled; }
static void simple_test (int converter, int channel_count, double target_snr) { SRC_DATA src_data ; double freq, snr ; int ch, error, frames ; printf ("\t%-22s (%d channel%c) ............. ", "simple_test", channel_count, channel_count > 1 ? 's' : ' ') ; fflush (stdout) ; memset (input_serial, 0, sizeof (input_serial)) ; memset (input_interleaved, 0, sizeof (input_interleaved)) ; memset (output_interleaved, 0, sizeof (output_interleaved)) ; memset (output_serial, 0, sizeof (output_serial)) ; frames = MIN (ARRAY_LEN (input_serial) / channel_count, 1 << 16) ; /* Calculate channel_count separate windowed sine waves. */ for (ch = 0 ; ch < channel_count ; ch++) { freq = (200.0 + 33.333333333 * ch) / 44100.0 ; gen_windowed_sines (1, &freq, 1.0, input_serial + ch * frames, frames) ; } ; /* Interleave the data in preparation for SRC. */ interleave_data (input_serial, input_interleaved, frames, channel_count) ; /* Choose a converstion ratio <= 1.0. */ src_data.src_ratio = 0.95 ; src_data.data_in = input_interleaved ; src_data.input_frames = frames ; src_data.data_out = output_interleaved ; src_data.output_frames = frames ; if ((error = src_simple (&src_data, converter, channel_count))) { printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ; exit (1) ; } ; if (fabs (src_data.output_frames_gen - src_data.src_ratio * src_data.input_frames) > 2) { printf ("\n\nLine %d : bad output data length %ld should be %d.\n", __LINE__, src_data.output_frames_gen, (int) floor (src_data.src_ratio * src_data.input_frames)) ; printf ("\tsrc_ratio : %.4f\n", src_data.src_ratio) ; printf ("\tinput_len : %ld\n", src_data.input_frames) ; printf ("\toutput_len : %ld\n\n", src_data.output_frames_gen) ; exit (1) ; } ; /* De-interleave data so SNR can be calculated for each channel. */ deinterleave_data (output_interleaved, output_serial, frames, channel_count) ; for (ch = 0 ; ch < channel_count ; ch++) { snr = calculate_snr (output_serial + ch * frames, frames, 1) ; if (snr < target_snr) { printf ("\n\nLine %d: channel %d snr %f should be %f\n", __LINE__, ch, snr, target_snr) ; save_oct_float ("output.dat", input_serial, channel_count * frames, output_serial, channel_count * frames) ; exit (1) ; } ; } ; puts ("ok") ; return ; } /* simple_test */
static void callback_test (int converter, int channel_count, double target_snr) { TEST_CB_DATA test_callback_data ; SRC_STATE *src_state = NULL ; double freq, snr, src_ratio ; int ch, error, frames, read_total, read_count ; printf ("\t%-22s (%d channel%c) ............. ", "callback_test", channel_count, channel_count > 1 ? 's' : ' ') ; fflush (stdout) ; memset (input_serial, 0, sizeof (input_serial)) ; memset (input_interleaved, 0, sizeof (input_interleaved)) ; memset (output_interleaved, 0, sizeof (output_interleaved)) ; memset (output_serial, 0, sizeof (output_serial)) ; memset (&test_callback_data, 0, sizeof (test_callback_data)) ; frames = MIN (ARRAY_LEN (input_serial) / channel_count, 1 << 16) ; /* Calculate channel_count separate windowed sine waves. */ for (ch = 0 ; ch < channel_count ; ch++) { freq = (200.0 + 33.333333333 * ch) / 44100.0 ; gen_windowed_sines (1, &freq, 1.0, input_serial + ch * frames, frames) ; } ; /* Interleave the data in preparation for SRC. */ interleave_data (input_serial, input_interleaved, frames, channel_count) ; /* Perform sample rate conversion. */ src_ratio = 0.95 ; test_callback_data.channels = channel_count ; test_callback_data.total_frames = frames ; test_callback_data.current_frame = 0 ; test_callback_data.data = input_interleaved ; if ((src_state = src_callback_new (test_callback_func, converter, channel_count, &error, &test_callback_data)) == NULL) { printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ; exit (1) ; } ; read_total = 0 ; while (read_total < frames) { read_count = src_callback_read (src_state, src_ratio, frames - read_total, output_interleaved + read_total * channel_count) ; if (read_count <= 0) break ; read_total += read_count ; } ; if ((error = src_error (src_state)) != 0) { printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ; exit (1) ; } ; src_state = src_delete (src_state) ; if (fabs (read_total - src_ratio * frames) > 2) { printf ("\n\nLine %d : bad output data length %d should be %d.\n", __LINE__, read_total, (int) floor (src_ratio * frames)) ; printf ("\tsrc_ratio : %.4f\n", src_ratio) ; printf ("\tinput_len : %d\n", frames) ; printf ("\toutput_len : %d\n\n", read_total) ; exit (1) ; } ; /* De-interleave data so SNR can be calculated for each channel. */ deinterleave_data (output_interleaved, output_serial, frames, channel_count) ; for (ch = 0 ; ch < channel_count ; ch++) { snr = calculate_snr (output_serial + ch * frames, frames, 1) ; if (snr < target_snr) { printf ("\n\nLine %d: channel %d snr %f should be %f\n", __LINE__, ch, snr, target_snr) ; save_oct_float ("output.dat", input_serial, channel_count * frames, output_serial, channel_count * frames) ; exit (1) ; } ; } ; puts ("ok") ; return ; } /* callback_test */
static void process_test (int converter, int channel_count, double target_snr) { SRC_STATE *src_state ; SRC_DATA src_data ; double freq, snr ; int ch, error, frames, current_in, current_out ; printf ("\t%-22s (%d channel%c) ............. ", "process_test", channel_count, channel_count > 1 ? 's' : ' ') ; fflush (stdout) ; memset (input_serial, 0, sizeof (input_serial)) ; memset (input_interleaved, 0, sizeof (input_interleaved)) ; memset (output_interleaved, 0, sizeof (output_interleaved)) ; memset (output_serial, 0, sizeof (output_serial)) ; frames = MIN (ARRAY_LEN (input_serial) / channel_count, 1 << 16) ; /* Calculate channel_count separate windowed sine waves. */ for (ch = 0 ; ch < channel_count ; ch++) { freq = (200.0 + 33.333333333 * ch) / 44100.0 ; gen_windowed_sines (1, &freq, 1.0, input_serial + ch * frames, frames) ; } ; /* Interleave the data in preparation for SRC. */ interleave_data (input_serial, input_interleaved, frames, channel_count) ; /* Perform sample rate conversion. */ if ((src_state = src_new (converter, channel_count, &error)) == NULL) { printf ("\n\nLine %d : src_new() failed : %s\n\n", __LINE__, src_strerror (error)) ; exit (1) ; } ; src_data.end_of_input = 0 ; /* Set this later. */ /* Choose a converstion ratio < 1.0. */ src_data.src_ratio = 0.95 ; src_data.data_in = input_interleaved ; src_data.data_out = output_interleaved ; current_in = current_out = 0 ; while (1) { src_data.input_frames = MAX (MIN (BLOCK_LEN, frames - current_in), 0) ; src_data.output_frames = MAX (MIN (BLOCK_LEN, frames - current_out), 0) ; if ((error = src_process (src_state, &src_data))) { printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ; exit (1) ; } ; if (src_data.end_of_input && src_data.output_frames_gen == 0) break ; current_in += src_data.input_frames_used ; current_out += src_data.output_frames_gen ; src_data.data_in += src_data.input_frames_used * channel_count ; src_data.data_out += src_data.output_frames_gen * channel_count ; src_data.end_of_input = (current_in >= frames) ? 1 : 0 ; } ; src_state = src_delete (src_state) ; if (fabs (current_out - src_data.src_ratio * current_in) > 2) { printf ("\n\nLine %d : bad output data length %d should be %d.\n", __LINE__, current_out, (int) floor (src_data.src_ratio * current_in)) ; printf ("\tsrc_ratio : %.4f\n", src_data.src_ratio) ; printf ("\tinput_len : %d\n", frames) ; printf ("\toutput_len : %d\n\n", current_out) ; exit (1) ; } ; /* De-interleave data so SNR can be calculated for each channel. */ deinterleave_data (output_interleaved, output_serial, frames, channel_count) ; for (ch = 0 ; ch < channel_count ; ch++) { snr = calculate_snr (output_serial + ch * frames, frames, 1) ; if (snr < target_snr) { printf ("\n\nLine %d: channel %d snr %f should be %f\n", __LINE__, ch, snr, target_snr) ; save_oct_float ("output.dat", input_serial, channel_count * frames, output_serial, channel_count * frames) ; exit (1) ; } ; } ; puts ("ok") ; return ; } /* process_test */