-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathDump.h
executable file
·67 lines (51 loc) · 1.15 KB
/
Dump.h
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
#pragma once
#include <iomanip>
#include <iostream>
#include <fstream>
#include <span>
#include <sstream>
namespace stftpitchshift
{
class Dump
{
public:
Dump(const std::string& filename, const size_t minindex = 0, const size_t maxindex = 0) :
filename(filename),
minindex(minindex),
maxindex(maxindex),
fileindex(0)
{
}
template<class T>
void operator()(const std::span<const T> data)
{
if (fileindex < minindex)
{
++fileindex;
return;
}
if (fileindex > maxindex && maxindex > minindex)
{
++fileindex;
return;
}
std::stringstream filepath;
filepath << filename;
filepath << ".";
filepath << std::setw(10) << std::setfill('0') << fileindex;
filepath << ".raw";
std::ofstream file(
filepath.str(),
std::ios::out | std::ios::binary);
file.write(
reinterpret_cast<const char*>(data.data()),
data.size() * sizeof(T));
++fileindex;
}
private:
const std::string filename;
const size_t minindex;
const size_t maxindex;
size_t fileindex;
};
}