/
shmblg4
/
spectrum-visualizer
Обзор
Документация
Войти
/
shmblg4
/
spectrum-visualizer
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
main.cpp
125 строк
3 KB
Matvey Gotfrid
initial commit
04 фев 2025, 07:58
04 фев 2025, 07:58
f5566ef
Код
Авторство
О чём код?
#include "src/SpectrumVisualizer.h" #include "src/ToneGenerator.hpp" #include "src/uart.hpp" #include "src/Audio_recorder_v2.hpp" #include "src/Audio_player_v2.hpp" #include <thread> constexpr int UART_BAUDRATE = 921600; constexpr int UART_PORT_NUMBER = 8; constexpr int RECORDER_SAMPLE_RATE = 10240; constexpr int RECORDER_BITS_PER_SAMPLE = 16; AtomicQueue<uart::uart_dt_t> snd_mic_buffer(10'000'000); AtomicQueue<uart::uart_dt_t> snd_din_buffer(10'000'000); Audio_player<uart::uart_dt_t> audio_player(&snd_din_buffer, RECORDER_BITS_PER_SAMPLE, RECORDER_SAMPLE_RATE); Audio_recorder<uart::uart_dt_t> audio_recorder(&snd_mic_buffer, RECORDER_BITS_PER_SAMPLE, RECORDER_SAMPLE_RATE); // int main(int argc, char *argv[]) // { // uart::uart_ctx_t *ctx = uart::new_uart_connection(UART_PORT_NUMBER, UART_BAUDRATE); // QApplication app(argc, argv); // SpectrumVisualizer visualizer; // visualizer.show(); // audio_recorder.start(); // audio_player.start(); // std::thread uart_thread(uart::controller, ctx); // short rx_data_show[uart::block_size]; // while (uart::_flag_uart_running_port) // { // if (uart::ready_to_tx(ctx) || snd_mic_buffer.Size() > uart::block_size) // { // for (int i = 0; i < uart::block_size; i++) // { // short tx_data; // if (snd_mic_buffer.Pull(tx_data)) // { // ctx->tx_buff.Push(tx_data); // } // } // } // if (uart::ready_to_rx(ctx)) // { // memset(rx_data_show, 0, sizeof(short) * uart::block_size); // for (int i = 0; i < uart::block_size; i++) // { // if (ctx->rx_buff.Pull(rx_data_show[i])) // { // snd_din_buffer.Push(rx_data_show[i]); // } // } // visualizer.read_rx_Data(&rx_data_show[0]); // } // } // audio_recorder.stop(); // audio_player.stop(); // return app.exec(); // } typedef void t_void; t_void uart_thread_graph() { } int main(int argc, char *argv[]) { uart::uart_ctx_t *ctx = uart::new_uart_connection(UART_PORT_NUMBER, UART_BAUDRATE); std::thread t_uart_thread_graph(uart_thread_graph); QApplication app(argc, argv); SpectrumVisualizer visualizer; visualizer.show(); audio_recorder.start(); audio_player.start(); std::thread uart_thread(uart::controller, ctx); short rx_data_show[uart::block_size]; while (uart::_flag_uart_running_port) { if (uart::ready_to_tx(ctx) || snd_mic_buffer.Size() > uart::block_size) { for (int i = 0; i < uart::block_size; i++) { short tx_data; if (snd_mic_buffer.Pull(tx_data)) { ctx->tx_buff.Push(tx_data); } } } if (uart::ready_to_rx(ctx)) { memset(rx_data_show, 0, sizeof(short) * uart::block_size); for (int i = 0; i < uart::block_size; i++) { short rx_data; if (ctx->rx_buff.Pull(rx_data)) { snd_din_buffer.Push(rx_data); rx_data_show[i] = rx_data; } } visualizer.read_rx_Data(&rx_data_show[0]); } } audio_recorder.stop(); audio_player.stop(); return app.exec(); }