int main() { read_input(); jvec EP_l[4],MD_l[4],Q2_l[4],fP_l[4],fM_l[4],f0_l[4],fT_l[4]; for(int i=0;i<4;i++) study_il(EP_l[i],MD_l[i],Q2_l[i],fP_l[i],fM_l[i],f0_l[i],fT_l[i],il[0],il[i]); write("D_Pi",EP_l[0],MD_l[0],Q2_l[0],fP_l[0],fM_l[0],f0_l[0],fT_l[0]); { ofstream out_fP("plots/fP.xmg"); ofstream out_fM("plots/fM.xmg"); ofstream out_f0("plots/f0.xmg"); ofstream out_fT("plots/fT.xmg"); out_fP<<"@type xydy"<<endl; out_fM<<"@type xydy"<<endl; out_f0<<"@type xydy"<<endl; out_fT<<"@type xydy"<<endl; for(int ith=0;ith<nth;ith++) { if(ith) out_fP<<Q2_l[0][ith].med()<<" "<<fP_l[0][ith]<<endl; if(ith) out_fM<<Q2_l[0][ith].med()<<" "<<fM_l[0][ith]<<endl; out_f0<<Q2_l[0][ith].med()<<" "<<f0_l[0][ith]<<endl; if(ith) out_fT<<Q2_l[0][ith].med()<<" "<<fT_l[0][ith]<<endl; } } ///// jvec EP,MD,Q2,fP,fM,f0,fT; EP=parab_spline(EP_l+1,xs,xs_phys,"plots/EP_spline_s.xmg"); MD=parab_spline(MD_l+1,xs,xs_phys,"plots/MD_spline_s.xmg"); Q2=parab_spline(Q2_l+1,xs,xs_phys,"plots/Q2_spline_s.xmg"); fP=parab_spline(fP_l+1,xs,xs_phys,"plots/fP_spline_s.xmg"); fM=parab_spline(fM_l+1,xs,xs_phys,"plots/fM_spline_s.xmg"); f0=parab_spline(f0_l+1,xs,xs_phys,"plots/f0_spline_s.xmg"); fT=parab_spline(fT_l+1,xs,xs_phys,"plots/fT_spline_s.xmg"); fP[0]*=0; fT[0]*=0; ofstream out_fP("plots/fP_s.xmg"); ofstream out_fM("plots/fM_s.xmg"); ofstream out_f0("plots/f0_s.xmg"); ofstream out_fT("plots/fT_s.xmg"); out_fP<<"@type xydy"<<endl; out_fM<<"@type xydy"<<endl; out_f0<<"@type xydy"<<endl; out_fT<<"@type xydy"<<endl; for(int ith=0;ith<nth;ith++) { if(ith) out_fP<<Q2[ith].med()<<" "<<fP[ith]<<endl; if(ith) out_fM<<Q2[ith].med()<<" "<<fM[ith]<<endl; out_f0<<Q2[ith].med()<<" "<<f0[ith]<<endl; if(ith) out_fT<<Q2[ith].med()<<" "<<fT[ith]<<endl; } write("D_K",EP,MD,Q2,fP,fM,f0,fT); return 0; }
void study_il(jvec &EP,jvec &MD,jvec &Q2,jvec &fP,jvec &fM,jvec &f0,jvec &fT,int il_sea,int il) { int ic_base=8; jvec EP_ic[3],MD_ic[3],Q2_ic[3],fP_ic[3],fM_ic[3],f0_ic[3],fT_ic[3]; for(int dic=2;dic>=0;dic--) { int ic=ic_base+dic; Q2_ic[dic]=fP_ic[dic]=f0_ic[dic]=fT_ic[dic]=jvec(nth,njack); extr(EP_ic[dic],MD_ic[dic],Q2_ic[dic],fP_ic[dic],fM_ic[dic],f0_ic[dic],fT_ic[dic],il_sea,il,ic); } EP=parab_spline(EP_ic,xc,xc_phys,combine("plots/EP_spline_%d.xmg",il).c_str()); MD=parab_spline(MD_ic,xc,xc_phys,combine("plots/MD_spline_%d.xmg",il).c_str()); Q2=parab_spline(Q2_ic,xc,xc_phys,combine("plots/Q2_spline_%d.xmg",il).c_str()); fP=parab_spline(fP_ic,xc,xc_phys,combine("plots/fP_spline_%d.xmg",il).c_str()); fM=parab_spline(fM_ic,xc,xc_phys,combine("plots/fM_spline_%d.xmg",il).c_str()); f0=parab_spline(f0_ic,xc,xc_phys,combine("plots/f0_spline_%d.xmg",il).c_str()); fT=parab_spline(fT_ic,xc,xc_phys,combine("plots/fT_spline_%d.xmg",il).c_str()); fP[0]*=0; fT[0]*=0; ofstream out_fP(combine("plots/fP_%d.xmg",il).c_str()); ofstream out_fM(combine("plots/fM_%d.xmg",il).c_str()); ofstream out_f0(combine("plots/f0_%d.xmg",il).c_str()); ofstream out_fT(combine("plots/fT_%d.xmg",il).c_str()); out_fP<<"@type xydy"<<endl; out_fM<<"@type xydy"<<endl; out_f0<<"@type xydy"<<endl; out_fT<<"@type xydy"<<endl; for(int ith=0;ith<nth;ith++) { if(ith) out_fP<<Q2[ith].med()<<" "<<fP[ith]<<endl; if(ith) out_fM<<Q2[ith].med()<<" "<<fM[ith]<<endl; out_f0<<Q2[ith].med()<<" "<<f0[ith]<<endl; if(ith) out_fT<<Q2[ith].med()<<" "<<fT[ith]<<endl; } }
/** * Main function * */ int main(int argc, char *argv[]) { if (argc != 5) { std::cerr << argv[0] << "<input_wav_file> <output_f0_file> <output_spectrum_file> <output_aperiodicity_file>" << std::endl; return EXIT_FAILURE; } // 2016/01/28: Important modification. // Memory allocation is carried out in advanse. // This is for compatibility with C language. int x_length = GetAudioLength(argv[1]); if (x_length <= 0) { if (x_length == 0) std::cerr << "error: File \"" << argv[1] << "\" not found" << std::endl; else std::cerr << "error: File \"" << argv[1] << "\" is not a .wav format" << std::endl; return EXIT_FAILURE; } double *x = new double[x_length]; // wavread() must be called after GetAudioLength(). int fs, nbit; wavread(argv[1], &fs, &nbit, x); DisplayInformation(fs, nbit, x_length); // 2016/02/02 // A new struct is introduced to implement safe program. WorldParameters world_parameters; // You must set fs and frame_period before analysis/synthesis. world_parameters.fs = fs; // 5.0 ms is the default value. // Generally, the inverse of the lowest F0 of speech is the best. // However, the more elapsed time is required. world_parameters.frame_period = 5.0; //--------------------------------------------------------------------------- // Analysis part //--------------------------------------------------------------------------- // F0 estimation F0Estimation(x, x_length, &world_parameters); // Spectral envelope estimation SpectralEnvelopeEstimation(x, x_length, &world_parameters); // Aperiodicity estimation by D4C AperiodicityEstimation(x, x_length, &world_parameters); std::cout << "fft size = " << world_parameters.fft_size << std::endl; //--------------------------------------------------------------------------- // Saving part //--------------------------------------------------------------------------- // F0 saving std::ofstream out_f0(argv[2], std::ios::out | std::ios::binary); if(!out_f0) { std::cerr << "Cannot open file: " << argv[2] << std::endl; return EXIT_FAILURE; } out_f0.write(reinterpret_cast<const char*>(world_parameters.f0), std::streamsize(world_parameters.f0_length * sizeof(double))); out_f0.close(); // Spectrogram saving std::ofstream out_spectrogram(argv[3], std::ios::out | std::ios::binary); if(!out_spectrogram) { std::cerr << "Cannot open file: " << argv[3] << std::endl; return EXIT_FAILURE; } // write the sampling frequency out_spectrogram.write(reinterpret_cast<const char*>(&world_parameters.fs), std::streamsize( sizeof(world_parameters.fs) ) ); // write the sampling frequency out_spectrogram.write(reinterpret_cast<const char*>(&world_parameters.frame_period), std::streamsize( sizeof(world_parameters.frame_period) ) ); // write the spectrogram data for (int i=0; i<world_parameters.f0_length; i++) { out_spectrogram.write(reinterpret_cast<const char*>(world_parameters.spectrogram[i]), std::streamsize((world_parameters.fft_size / 2 + 1) * sizeof(double))); } out_spectrogram.close(); // Aperiodicity saving std::ofstream out_aperiodicity(argv[4], std::ios::out | std::ios::binary); if(!out_aperiodicity) { std::cerr << "Cannot open file: " << argv[4] << std::endl; return EXIT_FAILURE; } for (int i=0; i<world_parameters.f0_length; i++) { out_aperiodicity.write(reinterpret_cast<const char*>(world_parameters.aperiodicity[i]), std::streamsize((world_parameters.fft_size / 2 + 1) * sizeof(double))); } out_aperiodicity.close(); //--------------------------------------------------------------------------- // Cleaning part //--------------------------------------------------------------------------- delete[] x; DestroyMemory(&world_parameters); std::cout << "complete" << std::endl; return EXIT_SUCCESS; }