-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathmain.cpp
executable file
·91 lines (73 loc) · 1.95 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
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
89
90
91
#include <iostream>
#include <StftPitchShift/CLI.h>
#include <StftPitchShift/IO.h>
#include <StftPitchShift/StftPitchShift.h>
#include <StftPitchShift/Version.h>
using namespace stftpitchshift;
const int OK = 0, NOK = 1;
int main(int argc, char** argv)
{
CLI cli(argc, argv);
if (!cli.error.empty())
{
std::cerr << "Unable to interpret the specified command line options!" << std::endl;
std::cerr << cli.error << std::endl;
return NOK;
}
if (cli.empty || cli.help)
{
std::cout << cli.usage() << std::endl;
return OK;
}
if (cli.version)
{
std::cout << StftPitchShiftVersion << std::endl;
return OK;
}
if (cli.input.empty())
{
std::cerr << "Missing input file name!" << std::endl;
std::cerr << "Please specify -h for full usage..." << std::endl;
return NOK;
}
if (cli.output.empty())
{
std::cerr << "Missing output file name!" << std::endl;
std::cerr << "Please specify -h for full usage..." << std::endl;
return NOK;
}
try
{
double samplerate;
size_t channels;
std::vector<double> indata, outdata;
IO::read(cli.input, indata, samplerate, channels);
outdata.resize(indata.size());
for (size_t channel = 0; channel < channels; ++channel)
{
const size_t size = indata.size() / channels;
const std::span<double> input = { indata.data() + channel * size, size };
const std::span<double> output = { outdata.data() + channel * size, size };
StftPitchShift stft(
cli.framesize,
std::get<1>(cli.framesize) / cli.hoprate,
samplerate,
cli.normalization,
cli.chronometry);
stft.shiftpitch(
input,
output,
cli.factors,
cli.quefrency,
cli.distortion);
}
IO::clip(outdata);
IO::write(cli.output, outdata, samplerate, channels);
}
catch (const std::exception& exception)
{
std::cerr << exception.what() << std::endl;
return NOK;
}
return OK;
}