summaryrefslogtreecommitdiff
path: root/src/util/include
diff options
context:
space:
mode:
authorailurux <ailuruxx@gmail.com>2024-01-11 05:54:30 +0000
committercooljqln <cooljqln@noreply.codeberg.org>2024-01-11 05:54:30 +0000
commit0e04eb918ec976017276306181282769d8896c83 (patch)
tree562da509df2ab03d3906cf3c0f56063f6acc9865 /src/util/include
parent55bde70b9651b411ac0135bd4704f5b6972ea799 (diff)
downloadtangara-fw-0e04eb918ec976017276306181282769d8896c83.tar.gz
wav-codec (#13)
here is a wav decoder, enjoy! Reviewed-on: https://codeberg.org/cool-tech-zone/tangara-fw/pulls/13 Reviewed-by: cooljqln <cooljqln@noreply.codeberg.org> Co-authored-by: ailurux <ailuruxx@gmail.com> Co-committed-by: ailurux <ailuruxx@gmail.com>
Diffstat (limited to 'src/util/include')
-rw-r--r--src/util/include/debug.hpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/util/include/debug.hpp b/src/util/include/debug.hpp
new file mode 100644
index 00000000..620b0974
--- /dev/null
+++ b/src/util/include/debug.hpp
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2023 jacqueline <me@jacqueline.id.au>
+ *
+ * SPDX-License-Identifier: GPL-3.0-only
+ */
+
+#pragma once
+
+#include <iomanip>
+#include <ostream>
+
+#include <string>
+#include "span.hpp"
+
+namespace util {
+
+inline std::string format_hex_string(cpp::span<const std::byte> data) {
+ std::ostringstream oss;
+ std::ostringstream ascii_values;
+ int count = 0;
+ for (auto byte : data) {
+ if (count % 16 == 0) {
+ if (ascii_values.str().size() > 0) {
+ oss << "\t|" << ascii_values.str() << "|";
+ // Reset ascii values
+ ascii_values.str("");
+ }
+ oss << std::endl;
+ oss << "0x" << std::uppercase << std::setfill('0') << std::setw(2)
+ << std::hex << count << '\t';
+ } else if (count % 8 == 0) {
+ oss << " ";
+ }
+ int byte_val = (int)byte;
+ oss << "[0x" << std::uppercase << std::setfill('0') << std::setw(2)
+ << std::hex << byte_val << ']';
+ if (byte_val >= 32 && byte_val < 127) {
+ ascii_values << (char)byte;
+ } else {
+ ascii_values << ".";
+ }
+ count++;
+ }
+ return oss.str();
+}
+
+} // namespace util