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

View File

@@ -1,9 +1,16 @@
#include "magnitude.hpp" #include "magnitude.hpp"
#include "utils/var.hpp"
namespace hr::plugins namespace hr::plugins
{ {
magnitude::magnitude(const setup& st) : plugin{ st } 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) void magnitude::process(fvec_t& base, real_time timestamp)
@@ -18,10 +25,10 @@ namespace hr::plugins
m /= frames; m /= frames;
result::bit b; result::bit b;
b.m_value.push_back(m); b.m_value = m;
b.m_duration = timestamp; b.m_duration = timestamp;
m_result.set_bit(b); m_result.set_bit(0, b);
} }
result magnitude::get_result() result magnitude::get_result()

View File

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

View File

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

View File

@@ -1,3 +1,11 @@
#pragma once #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 #pragma once
#include <vector> #include <vector>
#include "utils/real_time/real_time.hpp"
#include "utils/fvec/fvec.hpp"
#include <hack/logger/logger.hpp> #include <hack/logger/logger.hpp>
#include "utils/real_time/real_time.hpp"
#include "utils/using.hpp"
namespace hr namespace hr
{ {
@@ -11,35 +11,47 @@ namespace hr
{ {
struct bit struct bit
{ {
std::string m_name;
real_time m_duration; 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 empty() const
{ {
bool res = true; return m_data.empty();
try
{
if (!m_data.empty()) res = m_data.at(0).m_value.empty();
}
catch(std::exception& e)
{
hack::error()(e.what());
}
return res;
} }
std::size_t size() std::size_t size()
{ {
if (!empty()) return m_data.size(); if (!empty()) return m_data.at(0).size();
else return 0; 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_block_size = 1'024;
std::size_t m_step_size = 512; std::size_t m_step_size = 512;
std::string m_plugin_name;
std::string m_plugin_description;
DOMAIN_PLUGIN m_domain = DOMAIN_PLUGIN::TIME; DOMAIN_PLUGIN m_domain = DOMAIN_PLUGIN::TIME;
}; };
} }