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
62
63
64
65
66
67
68
69
|
| #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 dry = 0, early = 0, late = 0.8; int input_mix_on = 0, hight_cut_on = 0; // 1~6
| int low_cut_on = 0; double input_mix = 0, high_cut_freq = 0, low_cut_freq = 0, cross_seed = 0; int taps_on = 1; double taps_count = 0.5; // 7~12
| double taps_pre_delay = 0.2, taps_decay = 0.5, taps_length = 0.1; int early_difus_on = 1; double early_difus_count = 0.5, early_difus_delay = 0.3; // 7~19
| double early_difus_feedback = 0.3, early_difus_mod_amt = 0.2, early_difus_mod_rate = 0.1; int late_mode = 1, late_reflect_on = 1; double late_line_count = 0.3; // 20~25
| double late_line_size = 0.4, late_line_mod_amt = 0.2, late_line_decay = 0.3, late_line_mod_rate = 0.1, late_difus_count = 0.1, late_difus_delay = 0.2; // 26~31
| double late_difus_feedback = 0.3, late_difus_mod_amt = 0.3, late_difus_mod_rate = 0.4; int eq_low_shelf_on = 0, eq_high_shelf_on = 0, eq_low_pass_on = 0; // 32~37
| double eq_low_shelf_freq = 0.1, eq_low_shelf_gain = 0.1, eq_high_shelf_freq = 0.1, eq_high_shelf_gain = 0.1, eq_low_pass_freq = 0.2; // 38~42
|
| Reverb *reverb[1];
| reverb_wrapper_init((void **)reverb, channels, frame_size, sample_rate, dry, early, late, input_mix_on, hight_cut_on,
| low_cut_on, input_mix, high_cut_freq, low_cut_freq, cross_seed, taps_on, taps_count, taps_pre_delay, taps_decay, taps_length, early_difus_on, early_difus_count, early_difus_delay,
| early_difus_feedback, early_difus_mod_amt, early_difus_mod_rate, late_mode, late_reflect_on, late_line_count, late_line_size, late_line_mod_amt, late_line_decay = 0.1, late_line_mod_rate, late_difus_count, late_difus_delay, // 20~31
| late_difus_feedback, late_difus_mod_amt, late_difus_mod_rate, eq_low_shelf_on, eq_high_shelf_on, eq_low_pass_on, eq_low_shelf_freq, eq_low_shelf_gain, eq_high_shelf_freq = 0.1, eq_high_shelf_gain, eq_low_pass_freq // 32~42
| );
|
|
| // 读入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;
| }
|
|