forked from rgerganov/tesla-opener
-
Notifications
You must be signed in to change notification settings - Fork 0
/
geniq.cpp
48 lines (42 loc) · 1.42 KB
/
geniq.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
#include <cstdio>
#include <cstdint>
#include <vector>
#include <string>
using namespace std;
const int SAMPLE_RATE = 2000000;
const int SYMBOL_RATE = 2000;
vector<uint8_t> out_cu8;
vector<int8_t> out_cs8;
void generate_samples()
{
string data = "101010101010101010101010100010101100101100110010110011001100110011001011010011010010110101001010110100110100110010101011010010110001010110010110011001011001100110011001100101101001101001011010100101011010011010011001010101101001011000101011001011001100101100110011001100110010110100110100101101010010101101001101001100101010110100101";
int spb = SAMPLE_RATE / SYMBOL_RATE; // samples per bit
for (int i = 0 ; i < (int) data.size() ; i++) {
for (int j = 0 ; j < spb ; j++) {
out_cu8.push_back(data[i] == '1' ? 255 : 127);
out_cu8.push_back(127);
out_cs8.push_back(data[i] == '1' ? 127 : 0);
out_cs8.push_back(0);
}
}
}
template<typename T>
void save_to_file(const string &fname, vector<T> &out)
{
printf("Saving to %s\n", fname.c_str());
FILE *f = fopen(fname.c_str(), "wb");
fwrite(out.data(), 1, out.size(), f);
fclose(f);
}
int main(int argc, char *argv[])
{
if (argc < 2) {
printf("Usage: %s <fname>\n", argv[0]);
return 1;
}
string fname = argv[1];
generate_samples();
save_to_file(fname + ".cu8", out_cu8);
save_to_file(fname + ".cs8", out_cs8);
return 0;
}