fix compression

This commit is contained in:
2026-04-07 18:52:29 +03:00
parent a279cdf3e3
commit 377b7913bb
9 changed files with 38 additions and 20 deletions

View File

@@ -23,6 +23,10 @@ namespace monitor::components
} m_current_audio;
std::map<std::string, music> m_audio_data;
// это меняющеесе значение в зависимости от плагина, а не
// как может показаться от аудио файла
std::size_t m_compression;
std::vector<std::string> m_domains = { "time", "frequensy"};
public:

View File

@@ -51,7 +51,7 @@ namespace monitor::components
{
m_current_audio.m_current_time = time;
double seconds = time.asSeconds();
int current_sample_index = (int)(seconds * m_current_audio.m_setup.m_sample_rate);
double current_sample_index = seconds * m_current_audio.m_setup.m_sample_rate / m_compression;
// send to:: components/markers
VE::event e { utils::event_type::INCREMENT_MARKER_AUDIO_POSITION, current_sample_index };

View File

@@ -47,6 +47,14 @@ namespace monitor::components
break;
}
case utils::event_type::SET_COMPRESSION:
{
auto c = std::any_cast<std::size_t>(e.m_data);
m_compression = c;
hack::log()(m_compression);
break;
}
case utils::event_type::SET_AUDIO_POSITION:
{
auto d = std::any_cast<double>(e.m_data);

View File

@@ -42,8 +42,6 @@ namespace monitor::components
m_graph.init(m_snapshot_id, m_setup);
m_graph.set_plugin(m_base_plugins[0]);
hack::log()(m_base_plugins[0]->m_result.m_size, m_setup.m_sample_rate);
// m_fft_scaled.init(m_snapshot_id, m_setup);
// send to: components/audio
@@ -75,6 +73,14 @@ namespace monitor::components
{
plugin->init();
plugin->fill();
std::size_t compression = 1;
if (plugin->m_compression)
compression = plugin->m_compression_step;
// send to: components/audio
VE::event e { utils::event_type::SET_COMPRESSION, compression };
EMIT(e);
}
else
{

View File

@@ -36,10 +36,8 @@ namespace monitor::components
{
case utils::event_type::INCREMENT_MARKER_AUDIO_POSITION:
{
auto t = std::any_cast<int>(e.m_data);
m_marker_audio_position = (double)t/11;
hack::log()(t, m_marker_audio_position);
auto p = std::any_cast<double>(e.m_data);
m_marker_audio_position = p;
break;
}

View File

@@ -25,7 +25,6 @@ namespace monitor::libs
void audio::set_file(std::filesystem::path p)
{
if (!m_music.openFromFile(p)) hack::error()("dont open file:", p.string());
hack::log()("0", m_music.getDuration().asMicroseconds());
}
void audio::set_callback(std::function<void(sf::Time)> c)

View File

@@ -10,6 +10,7 @@ namespace monitor::utils
STATUS_COMPLETED,
INIT_AUDIO,
CHANGE_AUDIO,
SET_COMPRESSION,
/// делать

View File

@@ -44,21 +44,24 @@ namespace monitor::utils
std::vector<hr::fvec_t> m_line_data;
// говорит нужно ли делать сжатие графика ли нет
bool m_comporession = false;
bool m_compression = false;
// шаг сжатия
std::size_t m_comporession_step = 0;
std::size_t m_compression_step = 0;
public:
virtual bool empty() { return m_result.empty(); }
// HERE
// начинаем тут
// перенести это все в папаки с плагинами т.е. код должен быть у каждого плагина
// т.к. m_compression_step у fft и у RAW_DATA работает по разному и это нужно учитывать
virtual void init()
{
try
{
m_comporession = m_result.m_size > m_size;
hack::log()(m_comporession);
if (!m_comporession) m_size = m_result.m_size;
m_compression = m_result.m_size > m_size;
if (!m_compression) m_size = m_result.m_size;
m_line_count = m_result.m_data.size();
m_line_data.reserve(m_line_count);
@@ -80,9 +83,9 @@ namespace monitor::utils
virtual void fill()
{
if (m_comporession)
if (m_compression)
{
m_comporession_step = m_result.m_size / m_size;
m_compression_step = m_result.m_size / m_size;
std::size_t line_count = 0;
for (auto& gd : m_line_data)
@@ -91,17 +94,16 @@ namespace monitor::utils
for (auto& g : gd)
{
float tmp_e = 0.f;
for (std::size_t j = bin_index - m_comporession_step; j < bin_index; ++j)
for (std::size_t j = bin_index - m_compression_step; j < bin_index; ++j)
{
auto e = m_result.m_data[line_count][j].m_value;
tmp_e = hack::math::max_abs(e, tmp_e);
}
g = tmp_e;
bin_index += m_comporession_step;
bin_index += m_compression_step;
if (bin_index > m_result.m_size) bin_index = m_result.m_size;
}
m_size = bin_index / m_comporession_step;
hack::log()(m_comporession_step, m_size);
m_size = bin_index / m_compression_step;
++line_count;
}
}

View File

@@ -43,7 +43,7 @@ namespace monitor::utils::plugins
// для заполнения начальными данными
virtual void fill()
{
if (m_comporession) hack::error()("Данных больше чем можем отрисовать на экране, см. что-то с масштабированием...");
if (m_compression) hack::error()("Данных больше чем можем отрисовать на экране, см. что-то с масштабированием...");
std::size_t line_count = 0;
for (auto el : m_result.m_data)