#ifndef muz_AUDIOENGINE_HPP #define muz_AUDIOENGINE_HPP #include #include "commons.hpp" #include "AudioConf.hpp" namespace muz { class Signal; MUZ_ERROR(audio_error); /** * Make sound from signals. * @see Signal **/ class AudioEngine { public: explicit AudioEngine(AudioConf const& conf); virtual ~AudioEngine(); /** * Initialize the engine opening audio device. **/ void init(); /** * Run the engine, making sound. **/ void run(); /** * Push a new signal in the signals queue. */ void push_signal(std::unique_ptr signal); /** * Pop the current signal or does nothing if the queue is empty. **/ void pop_signal(); private: AudioConf m_conf; PaStream* m_stream = nullptr; std::vector> m_sig_queue; std::mutex m_sig_mtx; std::vector m_frame; /** * Throws an audio_error exception if err is an error. **/ void check_error(PaError err); /** * Gives the next sample of the current signal. * @see Signal **/ std::vector next(); /** * Portaudio audio callback. **/ static int callback(void const* input, void* output, unsigned long frames_per_buffer, PaStreamCallbackTimeInfo const* time, PaStreamCallbackFlags flags, void* data); }; } #endif