summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKiritoDv <kiritodev01@gmail.com>2023-09-01 00:51:51 -0600
committerKiritoDv <kiritodev01@gmail.com>2023-09-01 00:51:51 -0600
commit113472302904ac84d4ddf70df32ca245ad156bf2 (patch)
tree9a82a79c2542749d26db93b414dc52e0ec72ed7f /lib
parent3bb2a8a13c4ff3b637bf02b9c01d632585b269bb (diff)
Migrated disassemble audio into audio manager class
Diffstat (limited to 'lib')
-rw-r--r--lib/binarytools/BinaryReader.cpp23
-rw-r--r--lib/binarytools/BinaryReader.h2
-rw-r--r--lib/hj/pyutils.h23
-rw-r--r--lib/hj/zip.h60
4 files changed, 108 insertions, 0 deletions
diff --git a/lib/binarytools/BinaryReader.cpp b/lib/binarytools/BinaryReader.cpp
index 3aff001..75044b0 100644
--- a/lib/binarytools/BinaryReader.cpp
+++ b/lib/binarytools/BinaryReader.cpp
@@ -2,6 +2,7 @@
#include "MemoryStream.h"
#include <cmath>
#include <stdexcept>
+#include <locale>
LUS::BinaryReader::BinaryReader(char* nBuffer, size_t nBufferSize) {
mStream = std::make_shared<MemoryStream>(nBuffer, nBufferSize);
@@ -113,6 +114,28 @@ uint64_t LUS::BinaryReader::ReadUInt64() {
return result;
}
+unsigned short LUS::BinaryReader::ReadUShort() {
+ unsigned short result = 0;
+ mStream->Read((char*)&result, sizeof(unsigned short));
+
+ if (mEndianness != Endianness::Native) {
+ result = BSWAP16(result);
+ }
+
+ return result;
+}
+
+short LUS::BinaryReader::ReadShort() {
+ short result = 0;
+ mStream->Read((char*)&result, sizeof(short));
+
+ if (mEndianness != Endianness::Native) {
+ result = BSWAP16(result);
+ }
+
+ return result;
+}
+
float LUS::BinaryReader::ReadFloat() {
float result = NAN;
diff --git a/lib/binarytools/BinaryReader.h b/lib/binarytools/BinaryReader.h
index 59eeb52..91e2a40 100644
--- a/lib/binarytools/BinaryReader.h
+++ b/lib/binarytools/BinaryReader.h
@@ -34,6 +34,8 @@ class BinaryReader {
uint16_t ReadUInt16();
uint32_t ReadUInt32();
uint64_t ReadUInt64();
+ unsigned short ReadUShort();
+ short ReadShort();
float ReadFloat();
double ReadDouble();
std::string ReadString();
diff --git a/lib/hj/pyutils.h b/lib/hj/pyutils.h
new file mode 100644
index 0000000..c5da4ee
--- /dev/null
+++ b/lib/hj/pyutils.h
@@ -0,0 +1,23 @@
+#pragma once
+
+#include <vector>
+
+namespace PyUtils {
+template<typename T>
+std::vector<T> slice(std::vector<T> const &v, uint32_t m, uint32_t n = -1) {
+ auto first = v.cbegin() + m;
+ auto last = n == -1 ? v.cend() : v.cbegin() + n;
+
+ std::vector<T> vec(first, last);
+ return vec;
+}
+
+std::vector<uint32_t> range(uint32_t start, uint32_t end) {
+ std::vector<uint32_t> result;
+ for (uint32_t i = start; i < end; ++i) {
+ result.push_back(i);
+ }
+ return result;
+}
+
+} \ No newline at end of file
diff --git a/lib/hj/zip.h b/lib/hj/zip.h
new file mode 100644
index 0000000..0cc7ee2
--- /dev/null
+++ b/lib/hj/zip.h
@@ -0,0 +1,60 @@
+#pragma once
+#include <algorithm>
+#include <any>
+#include <iostream>
+#include <vector>
+#include <tuple>
+
+template<class TupType, size_t... I>
+void print_tuple(const TupType& _tup, std::index_sequence<I...>)
+{
+ std::cout << "(";
+ (..., (std::cout << (I == 0? "" : ", ") << std::get<I>(_tup)));
+ std::cout << ")\n";
+}
+
+template<class... T>
+void print_tuple(const std::tuple<T...>& _tup)
+{
+ print_tuple(_tup, std::make_index_sequence<sizeof...(T)>());
+}
+
+template<typename T>
+void variatic_min(std::vector<T> v, int &m) {
+ if (m > v.size()) m = v.size();
+}
+
+template<int N, typename... Ts>
+using NthTypeOf = typename std::tuple_element<N, std::tuple<Ts...>>::type;
+
+template <typename... Result, std::size_t... Indices>
+auto vec_to_tup_helper(const std::vector<std::any>& v, std::index_sequence<Indices...>) {
+ return std::make_tuple(
+ std::any_cast<NthTypeOf<Indices, Result...>>(v[Indices])...
+ );
+}
+
+template <typename ...Result>
+std::tuple<Result...> vec_to_tup(std::vector<std::any>& values) {
+ return vec_to_tup_helper<Result...>(values, std::make_index_sequence<sizeof...(Result)>());
+}
+
+template <typename T>
+void celem_at(std::vector<T> v, int i, std::vector<std::any> &r) {
+ r.push_back(v[i]);
+}
+
+template<typename... Types>
+std::vector<std::tuple<Types...>> zip(std::vector<Types>... args) {
+ int m = 0xFFFFFFFF;
+ std::vector<std::tuple<Types...>> res;
+
+ (variatic_min(args, m), ...);
+
+ for (int i = 0; i < m; i++) {
+ std::vector<std::any> vaux;
+ (celem_at(args, i, vaux), ...);
+ res.push_back(vec_to_tup<Types...>(vaux));
+ }
+ return res;
+} \ No newline at end of file