chenlh
2026-03-13 67b7b35ceb551ae5a14338ad0770b6e2ee62f02b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
 
#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;
}