#include #include #include "delay_mono.h" #include "delay_mono_wrapper.h" #include "dr_wav.h" int ch = 1; int n = 1024; float sample_rate = 48000; float wetdry = 90; float delay_time = 900; float feedback = 68; float high_ratio = 0.7; float hpf = 150; float lpf = 13000; bool processWavFile(const char* inputPath, const char* outputPath, void *handle, int sampleRate = 48000, int blockSize = 64) { int i; Delay_mono *h = (Delay_mono *)handle; // ----- ¶ÁÈ¡ÊäÈë WAV ----- drwav wavIn; if (!drwav_init_file(&wavIn, inputPath, NULL)) { std::cerr << "Err:Can't open input file " << inputPath << std::endl; return false; } if (wavIn.sampleRate != sampleRate) { std::cerr << " Warning:sampleRate is not correct " << std::endl; } int channels = wavIn.channels; drwav_uint64 totalLen = wavIn.totalPCMFrameCount; std::cout << "InputFile:" << inputPath << "\n" << "SampleRate:" << sampleRate << " Hz\n" << "Channels:" << channels << "\n" << "Frames:" << totalLen << std::endl; std::vector inPcm(totalLen * channels); drwav_read_pcm_frames_f32(&wavIn, totalLen, inPcm.data()); drwav_uninit(&wavIn); std::vector outPcm(totalLen * channels, 0.0f); int frames = totalLen / n - 1; for (i = 0; i < frames; i++) { delay_mono_wrapper_process(h, wavIn.sampleRate, wetdry, delay_time, feedback, high_ratio, hpf, lpf, inPcm.data() + i * n, outPcm.data() + i * n); } // ----- дÈëÊä³ö WAV£¨¸¡µã¸ñʽ£©----- drwav_data_format format; format.container = drwav_container_riff; format.format = DR_WAVE_FORMAT_IEEE_FLOAT; format.channels = channels; format.sampleRate = sampleRate; format.bitsPerSample = 32; drwav wavOut; if (!drwav_init_file_write(&wavOut, outputPath, &format, NULL)) { std::cerr << "Err:can't output wav file: " << outputPath << std::endl; return false; } drwav_write_pcm_frames(&wavOut, totalLen, outPcm.data()); drwav_uninit(&wavOut); std::cout << "\n Output wav file:" << outputPath << std::endl; return 0; } int main() { void *work; delay_mono_wrapper_init(&work, ch, n, sample_rate, wetdry, delay_time, feedback, high_ratio, hpf, lpf); processWavFile("ain.wav", "aout.wav", work, sample_rate, n); delay_mono_wrapper_delete(work); }