-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
54 lines (47 loc) · 1.85 KB
/
main.cpp
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
#include "src/esola.cpp"
#include "src/argparse.h"
using namespace std;
using namespace kfr;
using namespace argparse;
int parse(ArgumentParser& parser, int argc, const char* argv[]) {
parser.add_argument()
.names({"-t", "--time_scale"})
.required(true);
parser.add_argument()
.names({"-i", "--input_file"})
.required(true);
parser.add_argument()
.names({"-o", "--output_file"})
.required(true);
parser.enable_help();
auto err = parser.parse(argc, argv);
if (err) {
std::cout << err << std::endl;
return -1;
}
if (parser.exists("help")) {
parser.print_help();
return 0;
}
return 1;
}
int main(int argc, const char* argv[]) {
ArgumentParser parser("esola", "ESOLA C++");
int code = parse(parser, argc, argv);
if (code != 1) {
return code;
}
const auto input_filepath = parser.get<std::string>("input_file");
const auto output_filepath = parser.get<std::string>("output_file");
const auto time_scaling_factor = parser.get<float>("time_scale");
audio_reader_wav<float> reader(open_file_for_reading(input_filepath));
univector2d<float> audio = reader.read_channels();
const auto input_audio = std::make_shared<univector<float>>(audio[0]);
auto output_audio = std::make_shared<univector<f32>>();
esola(input_audio, output_audio, float(1.0/time_scaling_factor), 3, reader.format().samplerate);
audio_writer_wav<f32> writer(open_file_for_writing(KFR_FILEPATH(output_filepath)),
audio_format{ 1, audio_sample_type::i16, reader.format().samplerate, false });
writer.write(output_audio->data(), output_audio->size());
std::cout << "File with " << time_scaling_factor << "x time-stretch created at " << output_filepath << std::endl;
return 0;
}