Files
osc/src/audio_engine.cpp
T

44 lines
1.3 KiB
C++
Raw Normal View History

#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<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;
}
}