#include "../include/audio_engine.hpp" int AudioEngine::start(){ if (device_is_started) throw std::runtime_error("ошибка: повторный запуск"); if (device_is_init){ result_start = ma_device_start(&device); if (result_start == MA_SUCCESS){ device_is_started = true; } else { throw std::runtime_error("ошибка: запуск не удался"); } } else{ throw std::runtime_error("ошибка: запуск не удался. девайс не был проинициализирован"); } return 0; } int AudioEngine::stop(){ if (!device_is_started) throw std::runtime_error("ошибка: повторная остановка"); result_stop = ma_device_stop(&device); if (result_stop == MA_SUCCESS){ device_is_started = false; } return 0; } void AudioEngine::data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount){ AudioEngine* data = static_cast(pDevice->pUserData); float* output = static_cast(pOutput); for (ma_uint32 i = 0; i < frameCount; ++i){ float left_acc = 0.0f; float right_acc = 0.0f; for (auto& synth : data->synths){ StereoSample buf = synth->generate(); left_acc += buf.left; right_acc += buf.right; } output[i * 2] = left_acc; output[i * 2 + 1] = right_acc; } }