-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAXEWaveformGen.cpp
More file actions
69 lines (51 loc) · 2.4 KB
/
AXEWaveformGen.cpp
File metadata and controls
69 lines (51 loc) · 2.4 KB
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
#include "AXEWaveformGen.hpp"
#include "AXEGlobalSettingsWindow.hpp"
#include "AXEJobSystem.hpp"
#include "Configuration/EngineConfiguration.hpp"
#include "Debug/EditorConsole.hpp"
#include "Debug/Logger.hpp"
#include "json_impl.hpp"
#include <algorithm>
#include <cstdlib>
#include <filesystem>
#include <fstream>
#include <string>
#define EC_THIS "WaveformGen"
namespace Shadow::AXE {
void cacheWaveforms() {
EC_NEWCAT(EC_THIS);
std::string globalLibraryPath = EngineConfiguration::getConfigDir() + "/AXEProjects/GlobalLibrary";
std::string cachePath = EngineConfiguration::getConfigDir() + "/AXECachedData";
PRINT("%s", globalLibraryPath.c_str());
JobSystem::submitJob("Cache waveform data", [globalLibraryPath, cachePath]() {
EC_PRINT(EC_THIS, "Generating waveforms as job");
if (!std::filesystem::exists(cachePath)) {
EC_PRINT(EC_THIS, "/AXECachedData dir doesn't exist, making now...");
std::filesystem::create_directory(cachePath);
}
for (const std::filesystem::directory_entry& file : std::filesystem::recursive_directory_iterator(globalLibraryPath)) {
if (file.is_regular_file()/* && file.path().extension() == ".wav" */) {
std::ifstream inFile(file.path(), std::ios::binary);
std::vector<unsigned char> buffer(std::istreambuf_iterator<char>(inFile), {});
std::size_t checksum = std::hash<std::string>{}(std::string(buffer.begin(), buffer.end()));
std::string uniqueName = file.path().string().substr(globalLibraryPath.length() + 1);
std::replace(uniqueName.begin(), uniqueName.end(), '/', '-');
std::string preProcessedWaveformFileName = uniqueName + ".json";
std::string waveformFileName = uniqueName + ".AXEwf";
EC_PRINT(EC_THIS, "Operating on file %s", uniqueName.c_str());
EC_PRINT(EC_THIS, " - HASH: %s", std::to_string(checksum).c_str());
std::system(std::string("audiowaveform -z " + std::to_string(/* getGlobalSettings()->samplesPerPixel */ 100) + " -i " + file.path().string() + " -o " + cachePath + "/" + preProcessedWaveformFileName).c_str());
// Post-process data
// We inject arbitrary props at this point
std::ifstream f(cachePath + "/" + preProcessedWaveformFileName);
json j = json::parse(f);
f.close();
j["audioHash"] = std::to_string(checksum);
JSON::dumpJsonToBson(j, cachePath + "/" + waveformFileName);
std::filesystem::remove(cachePath + "/" + preProcessedWaveformFileName);
}
}
return true;
});
}
}