chenlh
2026-03-26 36e42207da4c088b5bfd96f2cfc8944f890440d7
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <iostream>
#include <vector>
#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<float> inPcm(totalLen * channels);
    drwav_read_pcm_frames_f32(&wavIn, totalLen, inPcm.data());
    drwav_uninit(&wavIn);
 
    std::vector<float> 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);
 
 
}