int main (int argc, char **argv) { float mfcc_result[NUMFILTERBANK-1]; FILE *fptr; float Min=0.0f,Max=0.0f; int16_t *samples = NULL; uint16_t numFrame = 0; uint16_t i,j,k; int32_t Val_RGB; uint32_t idxCoeff; int tmp; char Len; Len = strlen(argv[1]); for ( i=0; i < Len-4; i++) { FileOut[i]= argv[1][i]; FileOutTxt[i]= argv[1][i]; } FileOut[Len-4] = '.'; FileOut[Len-3] = 'b'; FileOut[Len-2] = 'm'; FileOut[Len-1] = 'p'; FileOut[Len] = '\0'; FileOutTxt[Len-4] = '.'; FileOutTxt[Len-3] = 't'; FileOutTxt[Len-2] = 'x'; FileOutTxt[Len-1] = 't'; FileOutTxt[Len] = '\0'; /* Sotarage MFCC coeffience */ fptr=fopen(FileOutTxt,"w"); PreCalcFilterBank(FilterBank,fNorm, NUMBINHALF, NUMFILTERBANK); //printf("Length: %d \n", strlen(argv[1])); wavread(argv[1], &samples); printf("No. of channels: %d\n", header->num_channels); printf("Sample rate: %d\n", header->sample_rate); printf("Bit rate: %dkbps\n", header->byte_rate*8 / 1000); printf("Bits per sample: %d\n\n", header->bps); //printf("Sample 0: %d\n", samples[0]); //printf("Sample 1: %d\n", samples[1]); // Modify the header values & samples before writing the new file wavwrite("track2.wav", samples); numFrame = header->datachunk_size/(2*2*NUMBINHALF) ; //printf("Num Frame: %d \n", numFrame ); /* BMP = (RGB_data **)malloc((NUMFILTERBANK-1)*sizeof(RGB_data*)); for (i=0; i < NUMFILTERBANK-1; i++) { BMP[i] = (RGB_data *)malloc(sizeof(RGB_data)*(2*numFrame)) ; if(BMP[i] == NULL) { fprintf(stderr, "out of memory\n"); exit (0); } } */ BMP = (RGB_data *)malloc((NUMFILTERBANK-1)*sizeof(RGB_data*)*2*numFrame); //memset(BMP, 0, sizeof(BMP)); for (i = 0; i < 2*numFrame-1; i++) { for (j=0; j< 2*NUMBINHALF;j++) { V[j].Re = (float)(samples[i*NUMBINHALF + j]); //printf(" %d", samples[i*NUMBINHALF + j]); V[j].Im = (float)0.0f; } //printf("\n"); MFCC(V, FilterBank ,fNorm, mfcc_result); //printf("MFCC:"); for(idxCoeff = 0; idxCoeff < NUMFILTERBANK -1; idxCoeff++) { fprintf(fptr,"%f ", mfcc_result[idxCoeff]); //Val_RGB = (int)(255/(63.164356+46.877232)*(mfcc_result[idxCoeff]+10)); Val_RGB = (int)(255*(mfcc_result[idxCoeff])); //Val_RGB = tmp*tmp; //Val_RGB = Val_RGB/255; if (Val_RGB < 0) Val_RGB = 0; if (Val_RGB > 255) Val_RGB = 255; BMP[(NUMFILTERBANK - idxCoeff-2)*2*numFrame +i].g = (BYTE)(Val_RGB); BMP[(NUMFILTERBANK - idxCoeff-2)*2*numFrame +i].b = (BYTE)(Val_RGB); BMP[(NUMFILTERBANK - idxCoeff-2)*2*numFrame +i].r = (BYTE)(Val_RGB); //BMP[NUMFILTERBANK - idxCoeff-1][i].b = (BYTE)((Val_RGB & 0x00FF00)>>8); //BMP[NUMFILTERBANK - idxCoeff-1][i].r = (BYTE)((Val_RGB & 0xFF0000)>>16); //printf(" %d ", Val_RGB); //if (mfcc_result[idxCoeff] < Min) Min=mfcc_result[idxCoeff]; //if (mfcc_result[idxCoeff] > Max) Max=mfcc_result[idxCoeff]; } fprintf(fptr,"\r\n"); } //printf("Min: %f Max: %f \n", Min, Max); bmp_generator(FileOut, 2*numFrame, NUMFILTERBANK -1 ,(BYTE*) (BMP)); //bmpread("record_21.bmp"); free(header); free(samples); free(BMP); fclose(fptr); exit (0); }
//----------------------------------------------------------------------------- // Test program. // test.exe input.wav outout.wav f0 spec flag // input.wav : argv[1] Input file // output.wav : argv[2] Output file // f0 : argv[3] F0 scaling (a positive number) // spec : argv[4] Formant shift (a positive number) //----------------------------------------------------------------------------- int main(int argc, char *argv[]) { if (argc != 2 && argc != 3 && argc != 4 && argc != 5) { printf("error\n"); return 0; } int fs, nbit, x_length; double *x = wavread(argv[1], &fs, &nbit, &x_length); if (CheckLoadedFile(x, fs, nbit, x_length) == false) { printf("error: File not found.\n"); return 0; } // Allocate memories // The number of samples for F0 int f0_length = GetSamplesForDIO(fs, x_length, FRAMEPERIOD); double *f0 = new double[f0_length]; double *time_axis = new double[f0_length]; // FFT size for CheapTrick int fft_size = GetFFTSizeForCheapTrick(fs); double **spectrogram = new double *[f0_length]; double **aperiodicity = new double *[f0_length]; for (int i = 0; i < f0_length; ++i) { spectrogram[i] = new double[fft_size / 2 + 1]; aperiodicity[i] = new double[fft_size / 2 + 1]; } // F0 estimation F0Estimation(x, x_length, fs, f0_length, f0, time_axis); // Spectral envelope estimation SpectralEnvelopeEstimation(x, x_length, fs, time_axis, f0, f0_length, spectrogram); // Aperiodicity estimation by D4C AperiodicityEstimation(x, x_length, fs, time_axis, f0, f0_length, fft_size, aperiodicity); // Note that F0 must not be changed until all parameters are estimated. ParameterModification(argc, argv, fs, f0, f0_length, spectrogram); // The length of the output waveform int y_length = static_cast<int>((f0_length - 1) * FRAMEPERIOD / 1000.0 * fs) + 1; double *y = new double[y_length]; // Synthesis WaveformSynthesis(f0, f0_length, spectrogram, aperiodicity, fft_size, FRAMEPERIOD, fs, y_length, y); // Output wavwrite(y, y_length, fs, 16, argv[2]); printf("complete.\n"); delete[] x; delete[] time_axis; delete[] f0; delete[] y; for (int i = 0; i < f0_length; ++i) { delete[] spectrogram[i]; delete[] aperiodicity[i]; } delete[] spectrogram; delete[] aperiodicity; return 0; }
//----------------------------------------------------------------------------- // Test program. // test.exe input.wav outout.wav f0 spec flag // input.wav : argv[1] Input file // output.wav : argv[2] Output file // f0 : argv[3] F0 scaling (a positive number) // spec : argv[4] Formant shift (a positive number) //----------------------------------------------------------------------------- int main(int argc, char *argv[]) { if (argc != 2 && argc != 3 && argc != 4 && argc != 5) { printf("error\n"); return -2; } // 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) printf("error: File not found.\n"); else printf("error: The file is not .wav format.\n"); return -1; } 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); //--------------------------------------------------------------------------- // Analysis part //--------------------------------------------------------------------------- // 2016/02/02 // A new struct is introduced to implement safe program. WorldParameters world_parameters = { 0 }; // 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; // F0 estimation // DIO // F0EstimationDio(x, x_length, &world_parameters); // Harvest F0EstimationHarvest(x, x_length, &world_parameters); // Spectral envelope estimation SpectralEnvelopeEstimation(x, x_length, &world_parameters); // Aperiodicity estimation by D4C AperiodicityEstimation(x, x_length, &world_parameters); // Note that F0 must not be changed until all parameters are estimated. ParameterModification(argc, argv, fs, world_parameters.f0_length, world_parameters.fft_size, world_parameters.f0, world_parameters.spectrogram); //--------------------------------------------------------------------------- // Synthesis part (2016/04/19) // There are three samples in speech synthesis // 1: Conventional synthesis // 2: Example of real-time synthesis // 3: Example of real-time synthesis (Ring buffer is efficiently used) //--------------------------------------------------------------------------- char filename[100]; // The length of the output waveform int y_length = static_cast<int>((world_parameters.f0_length - 1) * world_parameters.frame_period / 1000.0 * fs) + 1; double *y = new double[y_length]; // Synthesis 1 (conventional synthesis) for (int i = 0; i < y_length; ++i) y[i] = 0.0; WaveformSynthesis(&world_parameters, fs, y_length, y); sprintf(filename, "01%s", argv[2]); wavwrite(y, y_length, fs, 16, filename); // Synthesis 2 (All frames are added at the same time) for (int i = 0; i < y_length; ++i) y[i] = 0.0; WaveformSynthesis2(&world_parameters, fs, y_length, y); sprintf(filename, "02%s", argv[2]); wavwrite(y, y_length, fs, 16, filename); // Synthesis 3 (Ring buffer is efficiently used.) for (int i = 0; i < y_length; ++i) y[i] = 0.0; WaveformSynthesis3(&world_parameters, fs, y_length, y); sprintf(filename, "03%s", argv[2]); wavwrite(y, y_length, fs, 16, filename); delete[] y; delete[] x; DestroyMemory(&world_parameters); printf("complete.\n"); return 0; }
int main() { //============================================================================= //STEP 1 - INITIALISATION //============================================================================= //Create input and output SIGNAL structures. SIGNAL input,output; int i=0; //Initialise SIGNAL structures. memset(&input,0,sizeof(SIGNAL)); memset(&output,0,sizeof(SIGNAL)); //============================================================================= //STEP 2 - OPEN AUDIO FILE AND READ INTO MEMORY //============================================================================= //Read input signal into memory. printf("Reading %s into memory...\n",kInputSignalLocation); wavread(kInputSignalLocation, &input); //============================================================================= //STEP 3 - PREPARE THE OUTPUT SIGNAL //============================================================================= //Set up output SIGNAL structure. Fill_SIGNAL(&output, input.frames, input.samplerate, input.channels, SF_FORMAT_WAV|SF_FORMAT_PCM_32, input.sections, input.seekable, NULL); //Allocate space for the 'output.data' buffer. output.data=(float *)malloc(sizeof(float)* input.frames*input.channels); //============================================================================= //STEP 4 - PROCESSING //============================================================================= //In this example we reverse the input signal //and store the results in the output signal for(i=0;i<input.frames;i++){ output.data[i]=input.data[input.frames-i]; //If the signal is stereo then a frame comprises two samples if (input.channels==2) output.data[i+1]=input.data[input.frames-i+1]; } //============================================================================= //STEP 5 - WRITE OUTPUT TO AUDIO FILE //============================================================================= //Write output file to disk printf("\n\nWriting audio to output file %s\n",kOutputSignalLocation); wavwrite(kOutputSignalLocation, &output); //============================================================================= //STEP 6 - CLEAN UP //============================================================================= free(input.data); free(output.data); return 0; }
//----------------------------------------------------------------------------- // Test program. // test.exe input.wav outout.wav f0 spec flag // input.wav : argv[1] Input file // output.wav : argv[2] Output file // f0 : argv[3] F0 scaling (a positive number) // spec : argv[4] Formant shift (a positive number) //----------------------------------------------------------------------------- int main(int argc, char *argv[]) { if (argc != 2 && argc != 3 && argc != 4 && argc != 5) { printf("error\n"); return -2; } // 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) printf("error: File not found.\n"); else printf("error: The file is not .wav format.\n"); return -1; } double *x = (double*) malloc(sizeof(double) * (x_length)); // wavread() must be called after GetAudioLength(). int fs, nbit; wavread(argv[1], &fs, &nbit, x); DisplayInformation(fs, nbit, x_length); //--------------------------------------------------------------------------- // Analysis part //--------------------------------------------------------------------------- // 2016/02/02 // A new struct is introduced to implement safe program. WorldParameters world_parameters = { 0 }; // 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; // 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); // Note that F0 must not be changed until all parameters are estimated. ParameterModification(argc, argv, fs, world_parameters.f0_length, world_parameters.fft_size, world_parameters.f0, world_parameters.spectrogram); //--------------------------------------------------------------------------- // Synthesis part //--------------------------------------------------------------------------- // The length of the output waveform int y_length = (int)((world_parameters.f0_length - 1) * world_parameters.frame_period / 1000.0 * fs) + 1; double *y = (double*) malloc(sizeof(double) * (y_length)); // Synthesis WaveformSynthesis(&world_parameters, fs, y_length, y); // Output wavwrite(y, y_length, fs, 16, argv[2]); if(y != NULL) { free(y); y = NULL; } if(x != NULL) { free(x); x = NULL; } DestroyMemory(&world_parameters); printf("complete.\n"); return 0; }
/** * 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; }
int main(int argc, char *argv[]) { int i; double *x,*x_cut,*f0,*t,*y; double **residualSpecgram; int fftl; int signalLen; int tLen; int offset,blank; int offsetSample, lengthSample; if(argc < 3) { printf("error: 引数の数が不正です.\n"); return 0; } /* printf("argc:%d\n", argc); for(i = 0;i < argc;i++) printf("%d:%s\n",i, argv[i]); //*/ FILE *fp; int fs, nbit; x = wavread(argv[1], &fs, &nbit, &signalLen); if(x == NULL) { printf("error: 指定されたファイルは存在しません.\n"); return 0; } printf("File information\n"); printf("Sampling : %d Hz %d Bit\n", fs, nbit); printf("Length %d [sample]\n", signalLen); printf("Length %f [sec]\n", (double)signalLen/(double)fs); // Cut x by offset and blank offset = atoi(argv[6]); offsetSample = offset*fs/1000; blank = atoi(argv[9]); if(blank < 0) // 負の場合はoffsetからの距離 { lengthSample = (-blank)*fs/1000; } else { lengthSample = signalLen - offsetSample - (blank*fs/1000); } if (lengthSample <= 0) { printf("Error: offset passes blank\n"); exit(0); } printf ("lengthSample: %d\n",lengthSample); x_cut = (double *)malloc(sizeof(double)*lengthSample); for (i=0; i<lengthSample ; i++) { if (i+offsetSample < signalLen) { x_cut[i] = x[i+offsetSample]; } else { x_cut[i] = 0.0; } } // F0は何サンプル分あるかを事前に計算する. tLen = getSamplesForDIO(fs, lengthSample, FRAMEPERIOD); printf ("tLen: %d\n",tLen); f0 = (double *)malloc(sizeof(double)*tLen); t = (double *)malloc(sizeof(double)*tLen); // f0 estimation by DIO DWORD elapsedTime; printf("\nAnalysis\n"); elapsedTime = timeGetTime(); dio(x_cut, lengthSample, fs, FRAMEPERIOD, t, f0); printf("DIO: %d [msec]\n", timeGetTime() - elapsedTime); fftl = getFFTLengthForStar(fs); residualSpecgram = (double **)malloc(sizeof(double *) * tLen); for(i = 0;i < tLen;i++) residualSpecgram[i] = (double *)malloc(sizeof(double) * (fftl/2+1)); // 非周期性指標の分析 elapsedTime = timeGetTime(); pt100(x_cut, lengthSample, fs, t, f0, residualSpecgram); printf("PLATINUM: %d [msec]\n", timeGetTime() - elapsedTime); // 時間長の伸縮 int lengthMsec, stLengthMsec, inputLengthMsec; double ratio; inputLengthMsec = (int)(tLen*FRAMEPERIOD); lengthMsec = atoi(argv[7]); stLengthMsec = atoi(argv[8]); int loop; loop = (lengthMsec-stLengthMsec)/(inputLengthMsec-stLengthMsec); ratio = (double)(lengthMsec) / (double)(inputLengthMsec - stLengthMsec); // 制御パラメタのメモリ確保 double *fixedF0; double **fixedResidualSpecgram; int tLen2; // tLen2 = (int)(0.5+(double)(lengthMsec+offset)/FRAMEPERIOD); //ここを修正 tLen2 = (int)(0.5+(double)(lengthMsec+stLengthMsec)/FRAMEPERIOD); fixedF0 = (double *) malloc(sizeof(double) * tLen2); fixedResidualSpecgram = (double **)malloc(sizeof(double *) * tLen2); for(i = 0;i < tLen2;i++) fixedResidualSpecgram[i] = (double *)malloc(sizeof(double) * (fftl/2+1)); // 最終波形のメモリ確保 int signalLen2; signalLen2 = (int)((lengthMsec+stLengthMsec)/1000.0*(double)fs); y = (double *)malloc(sizeof(double)*signalLen2); if (!y) { printf ("Error: y malloc() NULL\n"); } for(i = 0;i < signalLen2;i++) y[i] = 0.0; // printf("length:%d, %f\n",signalLen2, (double)signalLen2/(double)fs*1000.0); // printf("%d, %d, %d\n",lengthMsec, offset, fs); // 合成の前にF0の操作 (引数) equalizingPicth(f0, tLen, argv[3], atoi(argv[11]) ); // stretchTime(f0, tLen, fftl, residualSpecgram, // fixedF0, tLen2, fixedResidualSpecgram, stLengthMsec/(int)FRAMEPERIOD, ratio); int st, ed; int tempo; int pitchType; st = stLengthMsec+(inputLengthMsec-stLengthMsec)/3; ed = stLengthMsec+2*(inputLengthMsec-stLengthMsec)/3; tLen2 = stretchTime(f0, tLen, fftl, residualSpecgram, fixedF0, tLen2, fixedResidualSpecgram, st/(int)FRAMEPERIOD, ed/(int)FRAMEPERIOD, loop); pitchType=0; if (argc >= 13 && argv[12][0]=='!') { tempo = atoi(&(argv[12][1])); pitchType=0; } else if (argc >= 13 && strchr(argv[12],'Q') != NULL) { char *c; pitchType=1; c = strchr(argv[12],'Q'); c++; tempo = atoi(c); } else if (argc >= 13) { tempo = atoi(argv[12]); } else { tempo = 120; } printf ("tempo: %d\n",tempo); // ピッチベンドの取得 double *pitchBend=NULL; int bLen=0; if (pitchType==0) { if (argc >= 14) { bLen = getF0Contour(argv[13],NULL); pitchBend = (double *)malloc(sizeof(double) * bLen); bLen = getF0Contour(argv[13], pitchBend); } else { bLen = 3; pitchBend = (double *)malloc(sizeof(double) * bLen); pitchBend[0]=1.0; pitchBend[1]=1.0; pitchBend[2]=1.0; } } else if (pitchType==1) { int i,j; char arg1[100]; bLen = argc - 12; pitchBend = (double *)malloc(sizeof(double) * bLen); for (i=0; i<bLen; i++) { memset(arg1,0,sizeof(arg1)); for (j=0; j+1<sizeof(arg1) && argv[i+12][j] != '\0'; j++) { if (isdigit(argv[i+12][j]) || argv[i+12][j]=='.' || argv[i+12][j]=='+' || argv[i+12][j]=='-') { arg1[j]=argv[i+12][j]; } else { break; } } sscanf(arg1,"%lf",&(pitchBend[i])); pitchBend[i] = pow(2.0, pitchBend[i]/1200.0); } } createFinalPitch2(fixedF0, tLen2, pitchBend, bLen, fs, tempo); // 合成 printf("\nSynthesis\n"); elapsedTime = timeGetTime(); synthesisPt100(fixedF0, tLen2, fixedResidualSpecgram, fftl, FRAMEPERIOD, fs, y, signalLen2); printf("WORLD: %d [msec]\n", timeGetTime() - elapsedTime); // オフセットの設定 //offset = (int)((double)(offset+endOffset)/1000.0*(double)fs); //signalLen2 = (int)((lengthMsec)/1000.0*(double)fs); // signalLen2 -= offset; //for(i = 0;i < signalLen2;i++) y[i] = y[i+offset]; // printf("%d\n", signalLen2); // printf("%f %d\n", (double)signalLen2/(double)fs*1000, offset); // getch(); // ファイルの書き出し (内容には関係ないよ) char header[44]; short *output; double maxAmp; output = (short *)malloc(sizeof(short) * signalLen2); // 振幅の正規化 maxAmp = 0.0; double volume; volume = (double)atoi(argv[10]) / 100.0; printf ("volume: %lf\n",volume); for(i = 0;i < signalLen2;i++) maxAmp = (maxAmp < fabs(y[i])) ? fabs(y[i]) : maxAmp; if (maxAmp<=0.0) maxAmp=1.0; printf ("maxAmp: %lf\n",maxAmp); for(i = 0;i < signalLen2;i++) output[i] = (short)(32768.0*(y[i]*0.5 * volume/maxAmp)); fp = fopen(argv[1], "rb"); fread(header, sizeof(char), 44, fp); fclose(fp); fp = fopen(argv[2],"wb"); fwrite(header, sizeof(char), 44, fp); fwrite(output, sizeof(short), signalLen2, fp); fseek(fp, 40, SEEK_SET); signalLen2*=2; fwrite(&signalLen2, sizeof(int), 1, fp); fclose(fp); free(output); free(pitchBend); free(x); free(t); free(f0); free(fixedF0); free(y); for(i = 0;i < tLen;i++) { free(residualSpecgram[i]); } for(i = 0;i < tLen2;i++) { free(fixedResidualSpecgram[i]); } free(fixedResidualSpecgram); free(residualSpecgram); printf("complete.\n"); return 0; }