-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsfo.cc
49 lines (36 loc) · 1.15 KB
/
sfo.cc
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
/*
Sampling frequency offset
Copyright 2020 Ahmet Inan <[email protected]>
*/
#include <iostream>
#include <cmath>
#include "complex.hh"
#include "resampler.hh"
#include "wav.hh"
int main(int argc, char **argv)
{
if (argc != 4) {
std::cerr << "usage: " << argv[0] << " OUTPUT INPUT PPM" << std::endl;
return 1;
}
typedef float value;
typedef DSP::Complex<value> cmplx;
const char *out_name = argv[1];
const char *inp_name = argv[2];
value ppm = std::atof(argv[3]);
DSP::ReadWAV<value> inp_file(inp_name);
if (inp_file.channels() < 1 || inp_file.channels() > 2) {
std::cerr << "Only real or analytic signal (one or two channels) supported." << std::endl;
return 1;
}
DSP::WriteWAV<value> out_file(out_name, inp_file.rate(), inp_file.bits(), inp_file.channels());
DSP::Resampler2<value, cmplx, 129, 3> resample(inp_file.rate(), (inp_file.rate() * 19) / 40, 2);
value sfo = (inp_file.rate() * ppm) / value(1000000);
while (out_file.good() && inp_file.good()) {
cmplx input;
inp_file.read(reinterpret_cast<value *>(&input), 1);
cmplx output[2];
out_file.write(reinterpret_cast<value *>(output), resample(output, input, sfo), 2);
}
return 0;
}