double coding_gain_1d_collapsed(const double _r[2*B_SZ],const int *_f){ int j; int i; double r[2*B_SZ]; double rgt[2*B_SZ*B_SZ]; double grgt[B_SZ*B_SZ]; double cg; /* R*G^T */ for(j=0;j<2*B_SZ;j++){ for(i=0;i<2*B_SZ;i++){ r[i]=_r[abs(i-j)]; } analysis(&rgt[j*B_SZ],1,r,1,1,_f); } #if PRINT_CG_MATH print_matrix(stdout,"rgt",rgt,B_SZ,2*B_SZ,B_SZ); #endif /* G*R*G^T */ analysis(grgt,B_SZ,rgt,B_SZ,B_SZ,_f); #if PRINT_CG_MATH print_matrix(stdout,"grgt",grgt,B_SZ,B_SZ,B_SZ); #endif /* H */ for(j=0;j<B_SZ;j++){ for(i=0;i<B_SZ;i++){ r[i]=i==j?1:0; } synthesis(&rgt[j],B_SZ,r,1,1,_f); } #if PRINT_CG_MATH print_matrix(stdout,"hi",rgt,B_SZ,2*B_SZ,B_SZ); fprintf(stdout,"G,H=\n"); #endif /* (G*R*G^T)_ii * (H^T*H)_ii */ cg=0; for(j=0;j<B_SZ;j++){ double h; h=0; for(i=0;i<2*B_SZ;i++){ h+=rgt[i*B_SZ+j]*rgt[i*B_SZ+j]; } #if PRINT_CG_MATH fprintf(stdout," %- 12.6G, %- 12.6G\n",grgt[j*B_SZ+j],h); #endif cg-=10*log10(grgt[j*B_SZ+j]*h); } return cg/B_SZ; }
/* This is the function that is called when the program starts. */ int main(int argc, char *argv[]){ int bufPos, read; //initialization memset(&input, 0, sizeof(struct wavpcm_input)); input.resource = INPUTWAVFILE; wavpcm_input_open(&input); memset(&output, 0, sizeof(struct wavpcm_output)); output.resource = OUTPUTWAVFILE; wavpcm_output_copy_settings(&input, &output); wavpcm_output_open(&output); memset(&historyChunkAnalysis, 0, sizeof(struct chunk)); memset(&historyChunkSynthesis, 0, sizeof(struct chunk)); memset(largeCryptoBuffer, 0, sizeof(largeCryptoBuffer)); memset(wavbuffer, 0, sizeof(wavbuffer)); #ifdef CRYPTO //Create RSA ctx master & slave calculate_parameters_RSA(&RSA_ctx_master); calculate_parameters_RSA(&RSA_ctx_slave); //Create ENC ctx master & slave ENC_ctx_master.counter = 0; ENC_ctx_slave.counter = 0; //Start protocol STSprotocol(&ENC_ctx_master, &ENC_ctx_slave, &RSA_ctx_master, &RSA_ctx_slave); #endif for (bufPos = 0; bufPos < input.samplesAvailable; ) { placeInLargeBuffer = 0; while (placeInLargeBuffer < 15 * NB_OF_SMALL_BUFFERS_IN_LARGE) { //read a buffer read = wavpcm_input_read(&input, wavbuffer); if (read != BUFFERSIZE) { if ((input.samplesAvailable - bufPos) * 2 != read) { printf("Warning: Not a full buffer read, amount read: %d. samplesAvailable: %d. bufPos: %d", read, input.samplesAvailable, bufPos); } } //process the buffer bufPos += read/2; analysis(wavbuffer, &historyChunkAnalysis); //Split bands into subbands #ifdef cheatMono if(stillMono){ //Check if new buffer is still mono for(i=0; i < BUFFERSIZE_DIV2; i++){ if(wavbuffer[2*i] != wavbuffer[2*i+1]){ stillMono = 0; break; } } } if(stillMono){ //if still mono, use it to cheat (de)quantize quantizeBandsMono((short *) (largeCryptoBuffer + placeInLargeBuffer), &historyChunkAnalysis); }else{ #endif //quantize the bands, use largeCryptoBuffer to write the output in quantizeBands((short *) (largeCryptoBuffer + placeInLargeBuffer), &historyChunkAnalysis); #ifdef cheatMono } #endif //compress this new output (in place) compress30Samples((short *) (largeCryptoBuffer + placeInLargeBuffer)); //Compress samples to fit into the bytes that we give to crypto //increment position in largeCryptoBuffer placeInLargeBuffer += 15; } #ifdef CRYPTO //encrypt sendData(&ENC_ctx_master, largeCryptoBuffer, sizeof(largeCryptoBuffer), &ciphermessage); //channel //decrypt readData(&ENC_ctx_slave, &ciphermessage, largeCryptoBuffer, &decrypt_size); #endif //Now dequantize and merge bands back together placeInLargeBuffer = 0; while (placeInLargeBuffer < 15 * NB_OF_SMALL_BUFFERS_IN_LARGE) { //decompress. This is not in place because the amount of data expands. However, wavbuffer can be used again decompress30samples((largeCryptoBuffer + placeInLargeBuffer), wavbuffer); //dequantize the bands, working in place in wavbuffer #ifdef cheatMono if(stillMono){ //if still mono, use it to cheat (de)quantize dequantizeBandsMono(wavbuffer); }else{ #endif dequantizeBands(wavbuffer); #ifdef cheatMono } #endif //synthesis filter bank, again using wavbuffer for both input and output synthesis(wavbuffer, wavbuffer, wavbuffer + 10, wavbuffer + 20, wavbuffer + 5, wavbuffer + 15, wavbuffer + 25, &historyChunkSynthesis); //write the output to file wavpcm_output_write(&output, wavbuffer, 40); placeInLargeBuffer += 15; } } wavpcm_input_close(&input); wavpcm_output_close(&output); return 0; }
int main(void) { int i = 0; double (*magPhase)[2]; double * x; double (*y)[1024]; double **outputy; double * timeStretched; double * previousPhaseFrame; double * synthesizedOutput; //hard coded the test values ie hop, windowSize and the input length hop = 256; windowSize =1024; xlength = 10643328 + hop*3; // adds zeros to the input... think this is for time scaling sort of step = 7; alpha = pow(2,(step/(float)12)); hopOut = round(alpha*hop); numberSlices = (((xlength-windowSize)/hop)); phaseCumulative = malloc(windowSize * sizeof(double)); x = malloc(xlength * sizeof(double)); outputy = malloc(numberSlices * sizeof(double *)); outputy[0] = malloc(numberSlices * windowSize * sizeof(double)); previousPhaseFrame = malloc(windowSize * sizeof(double)); magPhase = malloc(2*windowSize*sizeof(double)); init(); //reads fromt the file FILE *fopen(), *fp; fp = fopen("input.txt","r"); //hard coded the test input source int index =0; for(index = 0;index<hop*3;index++) { x[index] = 0; } while (!feof(fp) ) { index++; fscanf(fp,"%lg",&x[index]); if(debug == 1) { printf("%lg",x[index]); printf("%s","\n"); } } fclose(fp); for(i = 1; i < numberSlices; i++) outputy[i] = outputy[0] + i * windowSize; if(xlength %hop != 0) xlength = numberSlices*hop + windowSize; y = malloc((xlength/hop)*windowSize* sizeof(double *)); //note the number of column is different from the number of slicerSlices createFrames(x,y); for(index = 0;index<windowSize;index++) { previousPhaseFrame[index] = 0; } for(index = 0;index<numberSlices;index++) { analyse(y[index],magPhase); process(magPhase,previousPhaseFrame); outputy[index] = synthesis(magPhase); } timeStretched = fusionFrames(outputy);//should check this timeStretched value before linear interpolation, to see what comes out // do the linear interpolation synthesizedOutput = interpolate(timeStretched); for(i = 0;i<interlength;i++) { printf("%f",synthesizedOutput[i]); printf("%s","\n"); } return 0; }
double coding_gain_2d_collapsed(const double _r[2*B_SZ*2*B_SZ],const int *_f){ int v; int u; int j; int i; double r[2*B_SZ]; double s[2*B_SZ*B_SZ]; double rggt[2*B_SZ*2*B_SZ*B_SZ*B_SZ]; double ggrggt[B_SZ*B_SZ*B_SZ*B_SZ]; double cg; #if NN_SEARCH double basis[B_SZ]; for(v=0;v<B_SZ;v++)basis[v]=v<(B_SZ>>1)?0:255; (NE_POST_FILTER_DOUBLE[B_SZ_LOG-OD_LOG_BSIZE0])(basis,basis,_f); for(v=0;v<B_SZ;v++)if(basis[v]<0)return -100; #endif /* R*(G2*P*G1)^T */ for(v=0;v<2*B_SZ;v++){ for(j=0;j<2*B_SZ;j++){ for(u=0;u<2*B_SZ;u++){ for(i=0;i<2*B_SZ;i++){ r[i]=_r[abs(u-v)*2*B_SZ+abs(i-j)]; } analysis(&s[u*B_SZ],1,r,1,1,_f); } analysis(&rggt[(v*2*B_SZ+j)*B_SZ*B_SZ],B_SZ,s,B_SZ,B_SZ,_f); } } #if PRINT_CG_MATH print_matrix(stdout,"rggt",rggt,B_SZ*B_SZ,4*B_SZ*B_SZ,B_SZ*B_SZ); #endif /* G1*P*G2*R*(G2*P*G1)^T */ for(v=0;v<B_SZ;v++){ for(j=0;j<B_SZ;j++){ for(u=0;u<2*B_SZ;u++){ analysis(&s[u*B_SZ],1,&rggt[2*B_SZ*B_SZ*B_SZ*u+v*B_SZ+j],B_SZ*B_SZ,1,_f); } analysis(&ggrggt[(v*B_SZ+j)*B_SZ*B_SZ],B_SZ,s,B_SZ,B_SZ,_f); } } #if PRINT_CG_MATH print_matrix(stdout,"ggrggt",ggrggt,B_SZ*B_SZ,B_SZ*B_SZ,B_SZ*B_SZ); #endif /* H */ for(j=0;j<B_SZ;j++){ for(i=0;i<B_SZ;i++){ r[i]=i==j?1:0; } synthesis(&s[j],B_SZ,r,1,1,_f); } #if PRINT_CG_MATH print_matrix(stdout,"hi",s,B_SZ,2*B_SZ,B_SZ); #endif /* H1*P*H2 */ for(i=0;i<2*B_SZ;i++){ r[i]=0; } for(u=0;u<2*B_SZ;u++){ for(j=0;j<B_SZ;j++){ r[B_SZ]=s[B_SZ*u+j]; for(i=0;i<B_SZ;i++){ synthesis(&rggt[B_SZ*B_SZ*u*2*B_SZ+j+i*B_SZ],B_SZ*B_SZ,&r[B_SZ-i],1,1,_f); } } } #if PRINT_CG_MATH print_matrix(stdout,"hhi",rggt,B_SZ*B_SZ,4*B_SZ*B_SZ,B_SZ*B_SZ); fprintf(stdout,"G,H=\n"); #endif /* ((H1*P*H2)^T*H1*P*H2)_ii */ for(j=0;j<B_SZ*B_SZ;j++){ s[j]=0; for(i=0;i<4*B_SZ*B_SZ;i++){ s[j]+=rggt[i*B_SZ*B_SZ+j]*rggt[i*B_SZ*B_SZ+j]; } } /* (G1*P*G2*R*(G1*P*G2)^T)_ii * ((H1*P*H2)^T*H1*P*H2)_ii */ cg=0; for(j=0;j<B_SZ*B_SZ;j++){ #if PRINT_CG_MATH fprintf(stdout," %- 12.6G, %- 12.6G\n",ggrggt[B_SZ*B_SZ*j+j],s[j]); #endif cg-=10*log10(ggrggt[B_SZ*B_SZ*j+j]*s[j]); } return cg/(B_SZ*B_SZ); }
double coding_gain_2d(const double _r[2*B_SZ*2*B_SZ*2*B_SZ*2*B_SZ],const int *_f){ int v; int u; int j; int i; double r[2*B_SZ]; double s[2*B_SZ*B_SZ]; double rggt[2*B_SZ*2*B_SZ*B_SZ*B_SZ]; double ggrggt[B_SZ*B_SZ*B_SZ*B_SZ]; double cg; /* R*(G2*P*G1)^T */ for(v=0;v<2*B_SZ;v++){ for(j=0;j<2*B_SZ;j++){ for(u=0;u<2*B_SZ;u++){ analysis(&s[u*B_SZ],1,&_r[2*B_SZ*2*B_SZ*2*B_SZ*u+2*B_SZ*v+j],2*B_SZ*2*B_SZ,1,_f); } analysis(&rggt[(v*2*B_SZ+j)*B_SZ*B_SZ],B_SZ,s,B_SZ,B_SZ,_f); } } #if PRINT_CG_MATH print_matrix(stdout,"rggt",rggt,B_SZ*B_SZ,4*B_SZ*B_SZ,B_SZ*B_SZ); #endif /* G1*P*G2*R*(G2*P*G1)^T */ for(v=0;v<B_SZ;v++){ for(j=0;j<B_SZ;j++){ for(u=0;u<2*B_SZ;u++){ analysis(&s[u*B_SZ],1,&rggt[2*B_SZ*B_SZ*B_SZ*u+v*B_SZ+j],B_SZ*B_SZ,1,_f); } analysis(&ggrggt[(v*B_SZ+j)*B_SZ*B_SZ],B_SZ,s,B_SZ,B_SZ,_f); } } #if PRINT_CG_MATH print_matrix(stdout,"ggrggt",ggrggt,B_SZ*B_SZ,B_SZ*B_SZ,B_SZ*B_SZ); #endif /* H */ for(j=0;j<B_SZ;j++){ for(i=0;i<B_SZ;i++){ r[i]=i==j?1:0; } synthesis(&s[j],B_SZ,r,1,1,_f); } #if PRINT_CG_MATH print_matrix(stdout,"hi",s,B_SZ,2*B_SZ,B_SZ); #endif /* H1*P*H2 */ for(i=0;i<2*B_SZ;i++){ r[i]=0; } for(u=0;u<2*B_SZ;u++){ for(j=0;j<B_SZ;j++){ r[B_SZ]=s[B_SZ*u+j]; for(i=0;i<B_SZ;i++){ synthesis(&rggt[B_SZ*B_SZ*u*2*B_SZ+j+i*B_SZ],B_SZ*B_SZ,&r[B_SZ-i],1,1,_f); } } } #if PRINT_CG_MATH print_matrix(stdout,"hhi",rggt,B_SZ*B_SZ,4*B_SZ*B_SZ,B_SZ*B_SZ); fprintf(stdout,"G,H=\n"); #endif /* ((H1*P*H2)^T*H1*P*H2)_ii */ for(j=0;j<B_SZ*B_SZ;j++){ s[j]=0; for(i=0;i<4*B_SZ*B_SZ;i++){ s[j]+=rggt[i*B_SZ*B_SZ+j]*rggt[i*B_SZ*B_SZ+j]; } } /* (G1*P*G2*R*(G1*P*G2)^T)_ii * ((H1*P*H2)^T*H1*P*H2)_ii */ cg=0; for(j=0;j<B_SZ*B_SZ;j++){ fprintf(stdout," %- 12.6G, %- 12.6G\n",ggrggt[B_SZ*B_SZ*j+j],s[j]); cg-=10*log10(ggrggt[B_SZ*B_SZ*j+j]*s[j]); } return cg/(B_SZ*B_SZ); }
void TextToSpeech::make_wav(const std::string& sentence, int fperiod) { /* file name buffer size */ const size_t FILE_NAME_BUF_SIZE = 128; /* output wav file */ FILE *wavfp = fopen(wav_filename_.c_str(), "wb"); if (wavfp == NULL) { fprintf(stderr, "ERROR: Getfp() in open_jtalk.c: Cannot open %s.\n", wav_filename_.c_str()); return; } /* sentence */ char talk_str[FILE_NAME_BUF_SIZE]; strcpy(talk_str, sentence.c_str()); /* directory name of dictionary */ char dn_mecab[FILE_NAME_BUF_SIZE]; strcpy(dn_mecab, dic_dir_.c_str()); /* file names of models */ char fn_ms_dur[FILE_NAME_BUF_SIZE]; strcpy(fn_ms_dur, (voice_dir_ + "/dur.pdf").c_str()); char fn_ms_mgc[FILE_NAME_BUF_SIZE]; strcpy(fn_ms_mgc, (voice_dir_ + "/mgc.pdf").c_str()); char fn_ms_lf0[FILE_NAME_BUF_SIZE]; strcpy(fn_ms_lf0, (voice_dir_ + "/lf0.pdf").c_str()); char *fn_ms_lpf = NULL; /* file names of trees */ char fn_ts_dur[FILE_NAME_BUF_SIZE]; strcpy(fn_ts_dur, (voice_dir_ + "/tree-dur.inf").c_str()); char fn_ts_mgc[FILE_NAME_BUF_SIZE]; strcpy(fn_ts_mgc, (voice_dir_ + "/tree-mgc.inf").c_str()); char fn_ts_lf0[FILE_NAME_BUF_SIZE]; strcpy(fn_ts_lf0, (voice_dir_ + "/tree-lf0.inf").c_str()); char *fn_ts_lpf = NULL; /* file names of windows */ const int FN_WS_BUF_SIZE = 3; char **fn_ws_mgc = new char*[FN_WS_BUF_SIZE]; char **fn_ws_lf0 = new char*[FN_WS_BUF_SIZE]; for (int i = 0; i < FN_WS_BUF_SIZE; ++i) { fn_ws_mgc[i] = new char[FILE_NAME_BUF_SIZE]; fn_ws_lf0[i] = new char[FILE_NAME_BUF_SIZE]; sprintf(fn_ws_mgc[i], (voice_dir_ + "/mgc.win%d").c_str(), i+1); sprintf(fn_ws_lf0[i], (voice_dir_ + "/lf0.win%d").c_str(), i+1); } char **fn_ws_lpf = NULL; int num_ws_mgc = FN_WS_BUF_SIZE, num_ws_lf0 = FN_WS_BUF_SIZE, num_ws_lpf = 0; /* file names of global variance */ char fn_ms_gvm[FILE_NAME_BUF_SIZE]; strcpy(fn_ms_gvm, (voice_dir_ + "/gv-mgc.pdf").c_str()); char fn_ms_gvf[FILE_NAME_BUF_SIZE]; strcpy(fn_ms_gvf, (voice_dir_ + "/gv-lf0.pdf").c_str()); char *fn_ms_gvl = NULL; /* file names of global variance trees */ char fn_ts_gvm[FILE_NAME_BUF_SIZE]; strcpy(fn_ts_gvm, (voice_dir_ + "/tree-gv-mgc.inf").c_str()); char fn_ts_gvf[FILE_NAME_BUF_SIZE]; strcpy(fn_ts_gvf, (voice_dir_ + "/tree-gv-lf0.inf").c_str()); char *fn_ts_gvl = NULL; /* file names of global variance switch */ char fn_gv_switch[FILE_NAME_BUF_SIZE]; strcpy(fn_gv_switch, (voice_dir_ + "/gv-switch.inf").c_str()); /* global parameter */ int sampling_rate = params_.sampling_rate; double alpha = params_.alpha; int stage = params_.stage; double beta = params_.beta; int audio_buff_size = params_.audio_buff_size; double uv_threshold = params_.uv_threshold; double gv_weight_mgc = params_.gv_weight_mgc; double gv_weight_lf0 = params_.gv_weight_lf0; double gv_weight_lpf = params_.gv_weight_lpf; HTS_Boolean use_log_gain = FALSE; /* initialize and load */ initialize(sampling_rate, fperiod, alpha, stage, beta, audio_buff_size, uv_threshold, use_log_gain, gv_weight_mgc, gv_weight_lf0, gv_weight_lpf); load(dn_mecab, fn_ms_dur, fn_ts_dur, fn_ms_mgc, fn_ts_mgc, fn_ws_mgc, num_ws_mgc, fn_ms_lf0, fn_ts_lf0, fn_ws_lf0, num_ws_lf0, fn_ms_lpf, fn_ts_lpf, fn_ws_lpf, num_ws_lpf, fn_ms_gvm, fn_ts_gvm, fn_ms_gvl, fn_ts_gvl, fn_ms_gvf, fn_ts_gvf, fn_gv_switch); /* synthesis */ synthesis(talk_str, wavfp); /* free */ fclose(wavfp); }
void TextToSpeech::make_wav(const std::string& sentence, int fperiod) { /* sentence */ const char *talk_str = sentence.c_str(); /* directory name of dictionary */ const char *dn_mecab = dic_dir_.c_str(); /* file names of models */ std::string fn_ms_dur_str = voice_dir_ + "/dur.pdf"; std::string fn_ms_mgc_str = voice_dir_ + "/mgc.pdf"; std::string fn_ms_lf0_str = voice_dir_ + "/lf0.pdf"; const char *fn_ms_dur = fn_ms_dur_str.c_str(); const char *fn_ms_mgc = fn_ms_mgc_str.c_str(); const char *fn_ms_lf0 = fn_ms_lf0_str.c_str(); const char *fn_ms_lpf = NULL; /* file names of trees */ std::string fn_ts_dur_str = voice_dir_ + "/tree-dur.inf"; std::string fn_ts_mgc_str = voice_dir_ + "/tree-mgc.inf"; std::string fn_ts_lf0_str = voice_dir_ + "/tree-lf0.inf"; const char *fn_ts_dur = fn_ts_dur_str.c_str(); const char *fn_ts_mgc = fn_ts_mgc_str.c_str(); const char *fn_ts_lf0 = fn_ts_lf0_str.c_str(); const char *fn_ts_lpf = NULL; /* file names of windows */ const int FN_WS_BUF_SIZE = 3; std::string fn_ws_mgc_str[FN_WS_BUF_SIZE]; std::string fn_ws_lf0_str[FN_WS_BUF_SIZE]; const char *fn_ws_mgc[FN_WS_BUF_SIZE]; const char *fn_ws_lf0[FN_WS_BUF_SIZE]; for (int i = 0; i < FN_WS_BUF_SIZE; ++i) { std::stringstream ss1; ss1 << voice_dir_ << "/mgc.win" << i + 1; fn_ws_mgc_str[i] = ss1.str(); fn_ws_mgc[i] = fn_ws_mgc_str[i].c_str(); std::stringstream ss2; ss2 << voice_dir_ << "/lf0.win" << i + 1; fn_ws_lf0_str[i] = ss2.str(); fn_ws_lf0[i] = fn_ws_lf0_str[i].c_str(); } const char **fn_ws_lpf = NULL; int num_ws_mgc = FN_WS_BUF_SIZE, num_ws_lf0 = FN_WS_BUF_SIZE, num_ws_lpf = 0; /* file names of global variance */ std::string fn_ms_gvm_str = voice_dir_ + "/gv-mgc.pdf"; std::string fn_ms_gvf_str = voice_dir_ + "/gv-lf0.pdf"; const char *fn_ms_gvm = fn_ms_gvm_str.c_str(); const char *fn_ms_gvf = fn_ms_gvf_str.c_str(); const char *fn_ms_gvl = NULL; /* file names of global variance trees */ std::string fn_ts_gvm_str = voice_dir_ + "/tree-gv-mgc.inf"; std::string fn_ts_gvf_str = voice_dir_ + "/tree-gv-lf0.inf"; const char *fn_ts_gvm = fn_ts_gvm_str.c_str(); const char *fn_ts_gvf = fn_ts_gvf_str.c_str(); const char *fn_ts_gvl = NULL; /* file names of global variance switch */ std::string fn_gv_switch_str = voice_dir_ + "/gv-switch.inf"; const char *fn_gv_switch = fn_gv_switch_str.c_str(); /* global parameter */ int sampling_rate = params_.sampling_rate; double alpha = params_.alpha; int stage = params_.stage; double beta = params_.beta; int audio_buff_size = params_.audio_buff_size; double uv_threshold = params_.uv_threshold; double gv_weight_mgc = params_.gv_weight_mgc; double gv_weight_lf0 = params_.gv_weight_lf0; double gv_weight_lpf = params_.gv_weight_lpf; HTS_Boolean use_log_gain = FALSE; /* initialize and load */ initialize(sampling_rate, fperiod, alpha, stage, beta, audio_buff_size, uv_threshold, use_log_gain, gv_weight_mgc, gv_weight_lf0, gv_weight_lpf); load(dn_mecab, fn_ms_dur, fn_ts_dur, fn_ms_mgc, fn_ts_mgc, fn_ws_mgc, num_ws_mgc, fn_ms_lf0, fn_ts_lf0, fn_ws_lf0, num_ws_lf0, fn_ms_lpf, fn_ts_lpf, fn_ws_lpf, num_ws_lpf, fn_ms_gvm, fn_ts_gvm, fn_ms_gvl, fn_ts_gvl, fn_ms_gvf, fn_ts_gvf, fn_gv_switch); /* init alsa player */ play_info_t play_info; play_h_ = play_init(&play_info, "default", SND_PCM_FORMAT_S16_LE, 1, sampling_rate, audio_buff_size, 8); /* synthesis */ synthesis(talk_str); }
void AmpEst(float *ampest, WavePar WP, complex *Refl, int nx, int nt, int nxs, int nts, float dt, float *xsyn, int Nsyn, float *xrcv, float *xsrc, float fxs2, float fxs, float dxs, float dxsrc, float dx, int ixa, int ixb, int ntfft, int nw, int nw_low, int nw_high, int mode, int reci, int nshots, int *ixpossyn, int npossyn, float *pmin, float *f1min, float *f1plus, float *f2p, float *G_d, int *muteW, int smooth, int shift, int above, int pad, int nt0, int *synpos, int verbose) { int l, i, j, ix, iw, nfreq, first=0; float Amax, *At, *wavelet, *iRN, *f1d, *Gp, Wmax, *Wt, *f1dw, Am, Wm; complex *Gdf, *f1df, *Af, *Fop; double tfft; nfreq = ntfft/2+1; wavelet = (float *)calloc(ntfft,sizeof(float)); Gdf = (complex *)malloc(nfreq*sizeof(complex)); f1df = (complex *)malloc(nfreq*sizeof(complex)); Af = (complex *)calloc(nfreq,sizeof(complex)); At = (float *)malloc(nxs*ntfft*sizeof(complex)); Wt = (float *)malloc(nxs*ntfft*sizeof(complex)); Fop = (complex *)calloc(nxs*nw*Nsyn,sizeof(complex)); iRN = (float *)calloc(Nsyn*nxs*ntfft,sizeof(float)); f1d = (float *)calloc(Nsyn*nxs*ntfft,sizeof(float)); f1dw = (float *)calloc(Nsyn*nxs*ntfft,sizeof(float)); Gp = (float *)calloc(Nsyn*nxs*ntfft,sizeof(float)); freqwave(wavelet, WP.nt, WP.dt, WP.fp, WP.fmin, WP.flef, WP.frig, WP.fmax, WP.t0, WP.db, WP.shift, WP.cm, WP.cn, WP.w, WP.scale, WP.scfft, WP.inv, WP.eps, 0); Wmax = maxest(wavelet,WP.nt); if (verbose) vmess("Calculating amplitude"); //memcpy(f1d, G_d, Nsyn*nxs*ntfft*sizeof(float)); mode=-1; synthesis(Refl, Fop, f1min, iRN, nx, nt, nxs, nts, dt, xsyn, Nsyn, xrcv, xsrc, fxs2, fxs, dxs, dxsrc, dx, ixa, ixb, ntfft, nw, nw_low, nw_high, mode, reci, nshots, ixpossyn, npossyn, &tfft, &first, verbose); for (l = 0; l < Nsyn; l++) { for (i = 0; i < npossyn; i++) { j=0; Gp[l*nxs*nts+i*nts+j] = -iRN[l*nxs*nts+i*nts+j] + f1plus[l*nxs*nts+i*nts+j]; for (j = 1; j < nts; j++) { Gp[l*nxs*nts+i*nts+j] = -iRN[l*nxs*nts+i*nts+j] + f1plus[l*nxs*nts+i*nts+nts-j]; } } } applyMute(Gp, muteW, smooth, 2, Nsyn, nxs, nts, ixpossyn, npossyn, shift, pad, nt0); for (l = 0; l < Nsyn; l++) { for (i = 0; i < npossyn; i++) { ix = ixpossyn[i]; j=0; f1d[l*nxs*nts+i*nts+j] = G_d[l*nxs*nts+ix*nts+j]; f1dw[l*nxs*nts+i*nts+j] = G_d[l*nxs*nts+ix*nts+j]; for (j = 1; j < nts; j++) { f1d[l*nxs*nts+i*nts+j] = G_d[l*nxs*nts+ix*nts+j]; f1dw[l*nxs*nts+i*nts+j] = G_d[l*nxs*nts+ix*nts+nts-j]; } } } /*for (l = 0; l < Nsyn; l++) { for (i = 0; i < npossyn; i++) { ix = ixpossyn[i]; rc1fft(&Gp[l*nxs*ntfft+i*ntfft],Gdf,ntfft,-1); rc1fft(&f1d[l*nxs*ntfft+ix*ntfft],f1df,ntfft,-1); for (iw=0; iw<nfreq; iw++) { Af[iw].r += f1df[iw].r*Gdf[iw].r-f1df[iw].i*Gdf[iw].i; Af[iw].i += f1df[iw].r*Gdf[iw].i+f1df[iw].i*Gdf[iw].r; } } cr1fft(&Af[0],At,ntfft,1); //Amax = maxest(At,ntfft); Amax = At[0]; ampest[l] = (Wmax*Wmax)/(Amax/((float)ntfft)); memset(&Af[0],0.0, sizeof(float)*2*nfreq); vmess("Wmax:%.8f Amax:%.8f",Wmax,Amax); }*/ for (l = 0; l < Nsyn; l++) { Wm = 0.0; Am = 0.0; convol(&Gp[l*nxs*nts], &f1d[l*nxs*nts], At, nxs, nts, dt, 0); convol(&f1dw[l*nxs*nts], &f1d[l*nxs*nts], Wt, nxs, nts, dt, 0); for (i = 0; i < npossyn; i++) { Wm += Wt[i*nts]; Am += At[i*nts]; } ampest[l] = sqrtf(Wm/Am); } if (verbose) vmess("Amplitude calculation finished"); free(Gdf);free(f1df);free(Af);free(At);free(wavelet); free(iRN);free(f1d);free(Gp);free(Fop); return; }