/** This file is a part of our_dick Copyright (C) 2020 rexy712 This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ #ifndef OUR_DICK_AUDIO_STREAM_HPP #define OUR_DICK_AUDIO_STREAM_HPP #include //forward #include #include "util/sequence.hpp" #include "detail.hpp" #include "error.hpp" namespace audio{ class stream { private: detail::callback_iface* m_cb = nullptr; PaStream* m_stream = nullptr; mutable PaError m_err = paNoError; int m_in_channels; int m_out_channels; public: template stream(int in_c, int out_c, double samplerate, size_t buffersize, Callback&& cb, Args&&... cbargs): m_cb(new detail::callback_impl(std::forward(cb), std::forward(cbargs)...)), m_stream(initialize_global_instance()), m_err(open_default_stream(&m_stream, in_c, out_c, paFloat32, samplerate, buffersize, m_cb)), m_in_channels(in_c), m_out_channels(out_c){} ~stream(); error start(); error stop(); error abort(); error close(); bool is_stopped()const; bool is_active()const; int input_count()const; int output_count()const; error last_error()const; private: static PaStream* initialize_global_instance(); //to avoid using portaudio functions in the header static int open_default_stream(PaStream**, int in_c, int out_c, long unsigned int fmt, double samplerate, size_t bufsize, detail::callback_iface* cb); static int callback(const void* input, void* output, unsigned long framecount, const PaStreamCallbackTimeInfo* /*timeInfo*/, PaStreamCallbackFlags /*statusFlags*/, void* userdata); }; } #endif