AudioDecoderSpeex::AudioDecoderSpeex() : _speex_dec_state(speex_decoder_init(&speex_wb_mode)) { if (!_speex_dec_state) { throw MediaException(_("AudioDecoderSpeex: state initialization failed.")); } speex_bits_init(&_speex_bits); speex_decoder_ctl(_speex_dec_state, SPEEX_GET_FRAME_SIZE, &_speex_framesize); #ifdef RESAMPLING_SPEEX int err = 0; _resampler = speex_resampler_init(1, 16000, 44100, SPEEX_RESAMPLER_QUALITY_DEFAULT, &err); if (err != RESAMPLER_ERR_SUCCESS) { throw MediaException(_("AudioDecoderSpeex: initialization failed.")); } spx_uint32_t num = 0, den = 0; speex_resampler_get_ratio (_resampler, &num, &den); assert(num && den); boost::rational<boost::uint32_t> numsamples(den, num); numsamples *= _speex_framesize * 2 /* convert to stereo */; _target_frame_size = boost::rational_cast<boost::uint32_t>(numsamples); #endif }
/* char *telescope_name(int telescope_id); char *data_category(int data_type); char *backend_name(int machine_id); void angle_split(double angle,int *dd,int *mm,double *ss); void cal(double djm,int *year,int *month,int *day); long numsamples(FILE *filename,int headersize,int nbits,int nifs,int nchans); */ int main(int argc,char *argv[]){ FILE *fil; int i; char key_name[N]=""; int key_length; int size_int=sizeof(int),size_double=sizeof(double); int nsamples=0; long numsamps; int size_header=0; long size_data; int dd,mm; double ss; int year,month,day; double total_obs; double low_channel,high_channel,total_bandwidth; char unit[N]; int index_chan=0; if(help_required(argv[1])){ help_header(); exit(-1); } //Default value of key parameters // rawdatafile=""; // source_name="uknown"; src_raj=0; src_dej=0; telescope_id=11; //Telescope="uknown" machine_id=11; //Datataking Machine="uknown" data_type=11; //Data file="uknown" barycentric=0; //Barycentric="No" pulsarcentric=0; //pulsarcentric="Yes" az_start=0; za_start=0; tstart=0; tsamp=0; nbits=0; nsamples=0; total_obs=0; ibeam=0; nbeams=0; nifs=0; low_channel=0; high_channel=0; foff=0; nchans=0; total_bandwidth=0; refdm=0; size_data=0; size_header=0; //END if((fil=fopen(argv[1],"rb")) == NULL){ fprintf(stderr,"Error:Cannot open file!\n"); exit(-1); } //read HEADER_START of *.fil if(fread(&key_length,size_int,1,fil) < 1){ fprintf(stderr,"Error read key_length\n"); exit(-1); } size_header=size_header+size_int*1; if((fgets(key_name,key_length+1,fil)) == NULL){ fprintf(stderr,"Error:Failed to read key_name\n"); exit(-1); } size_header=size_header+key_length*1; if(strcmp(key_name,"HEADER_START")){ fprintf(stderr,"Error:Failed to read header\n"); exit(-1); } //read HEADER of *.fil while(1){ if(fread(&key_length,size_int,1,fil) < 1){ fprintf(stderr,"Error read key_length\n"); exit(-1); } size_header=size_header+size_int*1; if((fgets(key_name,key_length+1,fil)) == NULL){ fprintf(stderr,"Error:Failed to read key_name\n"); exit(-1); } size_header=size_header+key_length*1; //find key_parameters if(strcmp(key_name,"telescope_id") == 0){ if(fread(&telescope_id,size_int,1,fil) < 1){ fprintf(stderr,"Error:Failed to read telescope_id\n"); exit(-1); } size_header=size_header+size_int*1; } else if(strcmp(key_name,"FREQUENCY_START") == 0){ index_chan=0; } else if(strcmp(key_name,"FREQUENCY_END") == 0){ fch1=0; foff=0; } else if(strcmp(key_name,"fchannel") == 0){ if(fread(&frequency_table[index_chan++],size_double,1,fil) < 1){ fprintf(stderr,"Error:Failed to read fchannel\n"); exit(-1); } size_header=size_header+size_double*1; } else if(strcmp(key_name,"machine_id") == 0){ if(fread(&machine_id,size_int,1,fil) < 1){ fprintf(stderr,"Error:Failed to read telescope_id\n"); exit(-1); } size_header=size_header+size_int*1; } else if(strcmp(key_name,"data_type") == 0){ if(fread(&data_type,size_int,1,fil) < 1){ fprintf(stderr,"Error:Failed to read data_type\n"); exit(-1); } size_header=size_header+size_int*1; } else if(strcmp(key_name,"nchans") == 0){ if(fread(&nchans,size_int,1,fil) < 1){ fprintf(stderr,"Error:Failed to read nchans\n"); exit(-1); } size_header=size_header+size_int*1; } else if(strcmp(key_name,"nbits") == 0){ if(fread(&nbits,size_int,1,fil) < 1){ fprintf(stderr,"Error:Failed to read nbits\n"); exit(-1); } size_header=size_header+size_int*1; } else if(strcmp(key_name,"nifs") == 0){ if(fread(&nifs,size_int,1,fil) < 1){ fprintf(stderr,"Error:Failed to read nifs\n"); exit(-1); } size_header=size_header+size_int*1; } else if(strcmp(key_name,"scan_number") == 0){ if(fread(&scan_number,size_int,1,fil) < 1){ fprintf(stderr,"Error:Failed to read scan_number\n"); exit(-1); } size_header=size_header+size_int*1; } else if(strcmp(key_name,"barycentric") == 0){ if(fread(&barycentric,size_int,1,fil) < 1){ fprintf(stderr,"Error:Failed to read barycentric\n"); exit(-1); } size_header=size_header+size_int*1; } else if(strcmp(key_name,"pulsarcentric") == 0){ if(fread(&pulsarcentric,size_int,1,fil) < 1){ fprintf(stderr,"Error:Failed to read pulsarcentric\n"); exit(-1); } size_header=size_header+size_int*1; } else if(strcmp(key_name,"tstart") == 0){ if(fread(&tstart,size_double,1,fil) < 1){ fprintf(stderr,"Error:Failed to read tstart\n"); exit(-1); } size_header=size_header+size_double*1; } else if(strcmp(key_name,"mjdobs") == 0){ if(fread(&mjdobs,size_double,1,fil) < 1){ fprintf(stderr,"Error:Failed to read mjdobs\n"); exit(-1); } size_header=size_header+size_double*1; } else if(strcmp(key_name,"tsamp") == 0){ if(fread(&tsamp,size_double,1,fil) < 1){ fprintf(stderr,"Error:Failed to read tsamp\n"); exit(-1); } size_header=size_header+size_double*1; } else if(strcmp(key_name,"fch1") == 0){ if(fread(&fch1,size_double,1,fil) < 1){ fprintf(stderr,"Error:Failed to read fch1\n"); exit(-1); } size_header=size_header+size_double*1; } else if(strcmp(key_name,"foff") == 0){ if(fread(&foff,size_double,1,fil) < 1){ fprintf(stderr,"Error:Failed to read foff\n"); exit(-1); } size_header=size_header+size_double*1; } else if(strcmp(key_name,"refdm") == 0){ if(fread(&refdm,size_double,1,fil) < 1){ fprintf(stderr,"Error:Failed to read refdm\n"); exit(-1); } size_header=size_header+size_double*1; } else if(strcmp(key_name,"az_start") == 0){ if(fread(&az_start,size_double,1,fil) < 1){ fprintf(stderr,"Error:Failed to read az_start\n"); exit(-1); } size_header=size_header+size_double*1; } else if(strcmp(key_name,"za_start") == 0){ if(fread(&za_start,size_double,1,fil) < 1){ fprintf(stderr,"Error:Failed to read za_start\n"); exit(-1); } size_header=size_header+size_double*1; } else if(strcmp(key_name,"src_raj") == 0){ if(fread(&src_raj,size_double,1,fil) < 1){ fprintf(stderr,"Error:Failed to read src_raj\n"); exit(-1); } size_header=size_header+size_double*1; } else if(strcmp(key_name,"src_dej") == 0){ if(fread(&src_dej,size_double,1,fil) < 1){ fprintf(stderr,"Error:Failed to read src_dej\n"); exit(-1); } size_header=size_header+size_double*1; } else if(strcmp(key_name,"ibeam") == 0){ if(fread(&ibeam,size_int,1,fil) < 1){ fprintf(stderr,"Error:Failed to read ibeam\n"); exit(-1); } size_header=size_header+size_int*1; } else if(strcmp(key_name,"nbeams") == 0){ if(fread(&nbeams,size_int,1,fil) < 1){ fprintf(stderr,"Error:Failed to read nbeams\n"); exit(-1); } size_header=size_header+size_int*1; } else if(strcmp(key_name,"nsamples") == 0){ if(fread(&nsamples,size_int,1,fil) < 1){ fprintf(stderr,"Error:Failed to read nsamples\n"); exit(-1); } size_header=size_header+size_int*1; } else if(strcmp(key_name,"rawdatafile") == 0){ if(fread(&key_length,size_int,1,fil) < 1){ fprintf(stderr,"Error:Failed to read rawdatafile_length\n"); exit(-1); } size_header=size_header+size_int*1; if(fgets(rawdatafile,key_length+1,fil) ==NULL){ fprintf(stderr,"Error:Failed to read rawdatafile\n"); } size_header=size_header+key_length*1; } else if(strcmp(key_name,"source_name") == 0){ if(fread(&key_length,size_int,1,fil) < 1){ fprintf(stderr,"Error:Failed to read source_name_length\n"); exit(-1); } size_header=size_header+size_int*1; if(fgets(source_name,key_length+1,fil) ==NULL){ fprintf(stderr,"Error:Failed to read source_name\n"); } size_header=size_header+key_length*1; } else if(strcmp(key_name,"HEADER_END") == 0) break; else{ fprintf(stderr,"Error:Failed to recognize key parameter\n"); } } //Data file if(strcmp(rawdatafile,"") != 0) printf("%-38s : %s\n","Data file",rawdatafile); else printf("%-38s : %s\n","Data file",argv[1]); //Source name printf("%-38s : %s\n","Source Name",source_name); //Source RA (J2000) angle_split(src_raj,&dd,&mm,&ss); printf("%-38s : %d:%d:%.1lf\n","Source RA (J2000)",dd,mm,ss); //Source DEC (J2000) angle_split(src_dej,&dd,&mm,&ss); printf("%-38s : %d:%d:%.1lf\n","Source DEC (J2000)",dd,mm,ss); //Telescope printf("%-38s : %s\n","Telescope",telescope_name(telescope_id)); //Datataking Machine printf("%-38s : %s\n","Datataking Machine",backend_name(machine_id)); //Data type printf("%-38s : %s\n","Data type",data_category(data_type)); //Barycentric if(barycentric==1) printf("%-38s : %s\n","Barycentric","Yes"); else printf("%-38s : %s\n","Barycentric","No"); //Pulsarcentric if(pulsarcentric==1) printf("%-38s : %s\n","Pulsarcentric","Yes"); else printf("%-38s : %s\n","Pulsarcentric","No"); //Telescope azimuth angle (degrees) printf("%-38s : %lf\n","Telescope azimuth angle (degrees)",az_start); //Telescope zenith angle (degrees) printf("%-38s : %lf\n","Telescope zenith angle (degrees)",za_start); //Time stamp of first sample (MJD) printf("%-38s : %.12lf\n","Time stamp of first sample (MJD)",tstart); //Gregorian date cal(tstart,&year,&month,&day); printf("%-38s : %d/%.2d/%.2d\n","Gregorian date",year,month,day); //Sample time (us) printf("%-38s : %lf\n","Sample time (us)",tsamp*1.0e6); //Number of bits per sample printf("%-38s : %d\n","Number of bits per sample",nbits); //Number of samples //Warning:nifs*nchans*nsamples should be even; if(nsamples == 0){ numsamps=numsamples(fil,size_header,nbits,nifs,nchans); size_data=(long)nifs*nchans*numsamps*nbits/8; total_obs=numsamps*tsamp; printf("%-38s : %ld\n","Number of samples",numsamps); } else{ printf("%-38s : %d\n","Number of samples",nsamples); size_data=nifs*nchans*nsamples*nbits/8; total_obs=nsamples*tsamp; } //Observation length strcpy(unit,"(s)"); if(total_obs>60.0){ total_obs/=60.0; strcpy(unit,"(m)"); if(total_obs>60.0){ total_obs/=60.0; strcpy(unit,"(h)"); if(total_obs>24.0){ total_obs/=24.0; strcpy(unit,"(d)"); } } } printf("%s %-19s : %lf\n","Observation length",unit,total_obs); //Beam number printf("%-38s : %d\n","Beam number",ibeam); //Number of beams printf("%-38s : %d\n","Number of beams",nbeams); //Number of IFs printf("%-38s : %d\n","Number of IFs",nifs); //frequency table if(index_chan > 0){ printf("%-38s : ","Frequency"); for(i=0;i<index_chan;i++){ printf("%lf ",frequency_table[i]); } } else{ //Low channel (MHz) if(foff < 0) low_channel=fch1+(nchans-1)*foff; else if(foff > 0) low_channel=fch1; printf("%-38s : %lf\n","Low channel (MHz)",low_channel); //High channel (MHz) if(foff > 0) high_channel=fch1+(nchans-1)*foff; else if(foff < 0) high_channel=fch1; printf("%-38s : %lf\n","High channel (MHz)",high_channel); //Central freq (MHz) printf("%-38s : %lf\n","Central freq (MHz)",(high_channel+low_channel)/2.); //Channel bandwidth (MHz) printf("%-38s : %lf\n","Channel bandwidth (MHz)",foff); //Number of channels printf("%-38s : %d\n","Number of channels",nchans); //Total Bandwidth (MHz) total_bandwidth=fabs(foff)*nchans; printf("%-38s : %lf\n","Total Bandwidth (MHz)",total_bandwidth); } //Reference dispersion measure (cm-3 pc) printf("%-38s : %lf\n","Reference dispersion measure (cm-3 pc)",refdm); //Data size (bytes) printf("%-38s : %ld\n","Data size (bytes)",size_data); //Header size (bytes) printf("%-38s : %d\n","Header size (bytes)",size_header); fclose(fil); return 0; }