From 0e04eb918ec976017276306181282769d8896c83 Mon Sep 17 00:00:00 2001 From: ailurux Date: Thu, 11 Jan 2024 05:54:30 +0000 Subject: wav-codec (#13) here is a wav decoder, enjoy! Reviewed-on: https://codeberg.org/cool-tech-zone/tangara-fw/pulls/13 Reviewed-by: cooljqln Co-authored-by: ailurux Co-committed-by: ailurux --- src/util/include/debug.hpp | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/util/include/debug.hpp (limited to 'src/util/include/debug.hpp') 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 + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#pragma once + +#include +#include + +#include +#include "span.hpp" + +namespace util { + +inline std::string format_hex_string(cpp::span 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 -- cgit v1.2.3