5#include "../vae_config.hpp"
6#include "../vae_util.hpp"
8#include "../../../external/rtaudio/RtAudio.h"
10namespace vae {
namespace core {
17 if (
mAudio.isStreamRunning()) {
19 auto result =
mAudio.stopStream();
20 if (result != RTAUDIO_NO_ERROR) {
25 if (
mAudio.isStreamOpen()) {
36 void* out,
void* in,
unsigned int frames,
37 double streamTime, RtAudioStreamStatus status,
void* data
41 auto inFloat =
static_cast<const float*
>(in);
42 auto outFloat =
static_cast<float*
>(out);
44 ->swapBufferInterleaved(inFloat, outFloat, frames);
52 ) :
Device(backend, config) { };
60 VAE_ERROR(
"Failed to open deivce with index out of bounds")
65 RtAudio::StreamParameters inParams, outParams;
66 inParams.deviceId = device.
id;
68 outParams.deviceId = device.
id;
74 RtAudioErrorType result;
77 result =
mAudio.openStream(
78 outParams.nChannels ? &outParams :
nullptr,
79 inParams.nChannels ? &inParams :
nullptr,
85 if (result != RTAUDIO_NO_ERROR) {
86 VAE_ERROR(
"Failed to open RtAudio device with code %i", result)
100 result =
mAudio.startStream();
103 if (result != RTAUDIO_NO_ERROR) {
104 VAE_ERROR(
"Failed to open RtAudio device with code %i", result)
130 return mAudio.getDeviceCount();
134 const auto rtInfo =
mAudio.getDeviceInfo(index);
147 const char*
getName()
const override {
return "rtaudio"; };
#define TKLB_ASSERT(condition)
Wrap assertions.
Backend interface used to query devices before creating a actual device object.
virtual Size getDeviceCount()=0
Gets number of devices, needed to iterate them.
unsigned int getDeviceCount() override
Gets number of devices, needed to iterate them.
DeviceInfo getDefaultOutputDevice() override
const char * getName() const override
Returns name of the api.
static BackendRtAudio & instance()
DeviceInfo getDefaultInputDevice() override
Device * createDevice(const EngineConfig &config) override
Creates a device instance for this backend.
DeviceInfo getDevice(unsigned int index) override
Returns a spefic device info for index.
Interface for audio devices.
AudioThreadWorker mWorker
const EngineConfig & mConfig
void init(Size sampleRate, Uchar channelsIn, Uchar channelsOut, Size bufferSize)
initializes buffers, queues and resamplers if needed Has to be called in openDevice once the samplera...
static int AudioCallback(void *out, void *in, unsigned int frames, double streamTime, RtAudioStreamStatus status, void *data)
Function called from the RtAudio thread.
bool openDevice(DeviceInfo &device) override
Opens a specific audio device.
bool closeDevice() override
Closes the currently open device.
DeviceRtaudio(Backend &backend, const EngineConfig &config)
static void stringCopy(char *dst, const char *src, size_t size, bool terminate=true)
constexpr unsigned char MaxChannels
Maximum channel count used to pre allocate buffers.
Contains Typedefinitions and basic structures use by the public API and internally.
unsigned int Size
How the elements are addressed in the heapbuffer.
Basic struct describing a audio device.
unsigned int sampleRate
TODO not used?
unsigned int bufferSize
desired bufferSize
unsigned char channelsOut
char name[255]
Device name reported from backend.
int id
Negative values for invalid device.
char api[4]
API abbreviation.
Settings for the engine defined at EnginePimpl::init.
Size preferredBufferSize
Buffer size that will be requested from device.
Data shared with audio thread.
#define VAE_ERROR(msg,...)
#define VAE_PROFILER_SCOPE_NAMED(name)
Profiles a scope and names it.
#define VAE_PROFILER_OVERLOAD_NEW()
Overloads new and delete of class to be tracked.
#define VAE_ASSERT(condition)