2026-11-12 16:34:18 +06:00
|
|
|
#include "../include/audio_engine.hpp"
|
2026-11-12 20:19:00 +06:00
|
|
|
|
2026-11-13 02:02:50 +06:00
|
|
|
|
2026-11-12 20:19:00 +06:00
|
|
|
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<AudioEngine*>(pDevice->pUserData);
|
|
|
|
|
float* output = static_cast<float*> (pOutput);
|
|
|
|
|
for (ma_uint32 i = 0; i < frameCount; ++i){
|
|
|
|
|
float buf = data->synth_.generate();
|
|
|
|
|
output[i*2] = buf;
|
|
|
|
|
output[i*2+1] = buf;
|
|
|
|
|
}
|
|
|
|
|
}
|