rebuid struct project

This commit is contained in:
2026-03-18 15:46:48 +03:00
parent afe54548a0
commit a49fc7d5e3
7 changed files with 72 additions and 51 deletions

View File

@@ -8,16 +8,20 @@ auto main() -> int
// данных для чтения m_block_size; см. установки по умолчанию.
// Передается по ссылке и заполняется необходимыми данными
hr::setup setup;
setup.m_plugin_name = "Raw Data";
setup.m_plugin_description = "Ни чего не вычисляет, просто прокидывает сырые данные дальше в вашу программу, для сохранения единой концепции.";
// setup.m_domain = hr::DOMAIN_PLUGIN::FREQUENSY;
setup.m_file = "./sin.wav";
auto r = hr::run<hr::plugins::raw_data>(setup);
hack::log()("size:", r.m_data.size());
hack::log()("size:", r.size());
// if (!r.empty())
// {
// std::vector<float> s;
// for (auto p : r.m_data) s.push_back(p.m_value[0]);
// hack::log()(s);
// std::vector<float> res;
// for (auto& p : r.m_data)
// for (auto s : p)
// res.push_back(s.m_value);
// hack::log()(res);
// }
}

View File

@@ -1,9 +1,16 @@
#include "magnitude.hpp"
#include "utils/var.hpp"
namespace hr::plugins
{
magnitude::magnitude(const setup& st) : plugin{ st }
{
m_setup.m_plugin_name = "Raw Data";
m_setup.m_plugin_description = "Ни чего не вычисляет, просто прокидывает сырые данные дальше в вашу программу, для сохранения единой концепции.";
GUARD_DOMAIN(FREQUENSY);
m_result.init(1);
}
void magnitude::process(fvec_t& base, real_time timestamp)
@@ -18,10 +25,10 @@ namespace hr::plugins
m /= frames;
result::bit b;
b.m_value.push_back(m);
b.m_value = m;
b.m_duration = timestamp;
m_result.set_bit(b);
m_result.set_bit(0, b);
}
result magnitude::get_result()

View File

@@ -1,4 +1,5 @@
#include "raw_data.hpp"
#include "utils/var.hpp"
namespace hr::plugins
{
@@ -7,17 +8,22 @@ namespace hr::plugins
// Он не работает в частотной области
raw_data::raw_data(const setup& st) : plugin{ st }
{
if (st.m_domain != DOMAIN_PLUGIN::TIME)
hack::error()("Этот плагин работает только во временной области!");
GUARD_DOMAIN(TIME);
// Только 1 тип данных будет в этом плагине, а имеено
// сырые данные из файла
m_result.init(1);
}
void raw_data::process(fvec_t& base, real_time timestamp)
{
result::bit b;
b.m_value = base;
b.m_duration = timestamp;
m_tmp.set_bit(b);
m_size += base.size();
for (auto& v : base)
{
result::bit b;
b.m_value = v;
b.m_duration = timestamp;
m_result.set_bit(0, b);
}
}
void raw_data::process(cvec_t& fft, fvec_t& base, real_time timestamp)
@@ -26,23 +32,6 @@ namespace hr::plugins
result raw_data::get_result()
{
if (m_tmp.m_data.empty())
return m_result;
m_result.m_data.reserve(m_size);
std::size_t index = 0;
for (auto& t : m_tmp.m_data)
{
for (auto s : t.m_value)
{
result::bit b;
b.m_value.push_back(s);
b.m_duration = t.m_duration;
m_result.set_bit(b);
}
}
return m_result;
}
}

View File

@@ -12,8 +12,6 @@ namespace hr::plugins
private:
result m_result;
result m_tmp;
std::size_t m_size = 0;
public:
void process(fvec_t& base, real_time timestamp) override;

View File

@@ -1,3 +1,11 @@
#pragma once
namespace hr { }
#define GUARD_DOMAIN(x) if (m_setup.m_domain != DOMAIN_PLUGIN::x) \
{\
hack::error()("plugin name:", m_setup.m_plugin_name);\
hack::warn()("Этот плагин работает только в " #x " области!"); \
std::terminate();\
}
namespace hr {
}

View File

@@ -1,9 +1,9 @@
#pragma once
#include <vector>
#include "utils/real_time/real_time.hpp"
#include "utils/fvec/fvec.hpp"
#include <hack/logger/logger.hpp>
#include "utils/real_time/real_time.hpp"
#include "utils/using.hpp"
namespace hr
{
@@ -11,35 +11,47 @@ namespace hr
{
struct bit
{
std::string m_name;
real_time m_duration;
fvec_t m_value;
base_t m_value;
};
void set_bit(bit& b)
void set_bit(std::size_t index, bit& b)
{
m_data.push_back(b);
try
{
m_data.at(index).push_back(b);
}
catch(std::exception& e)
{
hack::error()("Хрень какая-то с массивом данных");
hack::warn()(e.what());
}
}
bool empty() const
{
bool res = true;
try
{
if (!m_data.empty()) res = m_data.at(0).m_value.empty();
}
catch(std::exception& e)
{
hack::error()(e.what());
}
return res;
return m_data.empty();
}
std::size_t size()
{
if (!empty()) return m_data.size();
if (!empty()) return m_data.at(0).size();
else return 0;
}
std::vector<bit> m_data;
// инициализирует кол-во данных для расчета в плагине
// см. ниже
void init(std::size_t count_data)
{
for (std::size_t i = 0; i < count_data; ++i)
m_data.push_back(std::vector<bit>{});
}
// схема такая:
// Первый вектор - кол-во типов замеров, например 7 т.е можно выстроить 7 линий на графике
// если захотелось увидеть их
// Второй вектор - данные для каждой линии, т.е. именно сими биты
std::vector<std::vector<bit>> m_data;
};
}

View File

@@ -21,6 +21,9 @@ namespace hr
std::size_t m_block_size = 1'024;
std::size_t m_step_size = 512;
std::string m_plugin_name;
std::string m_plugin_description;
DOMAIN_PLUGIN m_domain = DOMAIN_PLUGIN::TIME;
};
}