74 lines
2.2 KiB
C++
74 lines
2.2 KiB
C++
/**
|
|
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 <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef OUR_DICK_AUDIO_STREAM_HPP
|
|
#define OUR_DICK_AUDIO_STREAM_HPP
|
|
|
|
#include <utility> //forward
|
|
#include <portaudio.h>
|
|
|
|
#include "detail/utility.hpp"
|
|
#include "detail.hpp"
|
|
|
|
namespace audio{
|
|
|
|
enum class stream_fmt{
|
|
float32 = paFloat32,
|
|
};
|
|
|
|
class stream
|
|
{
|
|
private:
|
|
detail::callback_iface* m_cb = nullptr;
|
|
PaStream* m_stream = nullptr;
|
|
PaError m_err = paNoError;
|
|
|
|
public:
|
|
template<typename Callback, typename... Args>
|
|
stream(int in_c, int out_c, stream_fmt fmt, double samplerate, size_t buffersize, Callback&& cb, Args&&... cbargs):
|
|
m_cb(new detail::callback_impl<Callback,Args...>(std::forward<Callback>(cb), std::forward<Args>(cbargs)...)),
|
|
m_stream(initialize_global_instance()),
|
|
m_err(open_default_stream(&m_stream, in_c, out_c, fmt, samplerate, buffersize, m_cb)){}
|
|
|
|
~stream();
|
|
|
|
int start();
|
|
int stop();
|
|
int abort();
|
|
int close();
|
|
|
|
bool is_stopped()const;
|
|
bool is_active()const;
|
|
|
|
int 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,
|
|
stream_fmt 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
|