|
#include <iostream>
|
#include <vector>
|
#include "reverb.h"
|
#include "reverb_wrapper.h"
|
#include "dr_wav.h"
|
|
|
int main()
|
{
|
unsigned int channels = 1, frame_size = 64, sample_rate = 48e3; double room_size = 0.3, wet_dry = 60.0, reverb_time = 1.9, pre_delay = 1.5;
|
double high_damp_freq = 6890.0, high_ratio = 0.36, diffusion = 3.5, density = 1.3, hpf = 100.0, lpf = 11000.0;
|
|
Reverb *reverb[1];
|
reverb_wrapper_init((void **)reverb, channels, frame_size, sample_rate, room_size, wet_dry, reverb_time, pre_delay, high_damp_freq,
|
high_ratio, diffusion, density, hpf, lpf);
|
|
|
// 读入wav语音文件
|
drwav_uint64 samples;
|
float* pSampleDataIn = drwav_open_file_and_read_pcm_frames_f32("E:\\music\\Voice_print\\mengwanzhou.wav", &channels, &sample_rate, &samples, NULL);
|
if (pSampleDataIn == NULL) {
|
return -1;
|
}
|
|
int frame_count = samples / frame_size;
|
samples = frame_count * frame_size;
|
std::vector<float> outputData(samples);
|
|
for (int i = 0; i < frame_count; i++) {
|
float *src = pSampleDataIn + i * frame_size;
|
float *dst = outputData.data() + i * frame_size;
|
reverb_wrapper_process(*reverb, src, dst);
|
}
|
|
// 将处理后音频数据写入wav文件
|
drwav_data_format format;
|
format.container = drwav_container_riff;
|
format.format = DR_WAVE_FORMAT_IEEE_FLOAT;
|
format.channels = channels;
|
format.sampleRate = sample_rate;
|
format.bitsPerSample = 32;
|
|
drwav wav;
|
if (!drwav_init_file_write(&wav, "output.wav", &format, NULL)) {
|
std::cerr << "Error: Cannot create output file" << std::endl;
|
return -1;
|
}
|
|
drwav_uint64 framesWritten = drwav_write_pcm_frames(&wav, samples, outputData.data());
|
if (framesWritten != samples) {
|
std::cerr << "Error: Did not write all frames." << std::endl;
|
}
|
|
drwav_uninit(&wav);
|
drwav_free(pSampleDataIn, NULL);
|
|
std::cout << "Done." << std::endl;
|
|
return 0;
|
}
|