5#include "../vae_config.hpp"
6#include "../vae_util.hpp"
8#include "../../../external/portaudio/include/portaudio.h"
9#include "../../../external/portaudio/src/common/pa_debugprint.h"
11namespace vae {
namespace core {
27 PaError err = Pa_StopStream(
mStream);
32 PaError err = Pa_CloseStream(
mStream);
42 const void *in,
void *out,
unsigned long frames,
43 const PaStreamCallbackTimeInfo* timeInfo,
44 PaStreamCallbackFlags statusFlags,
void *data
48 auto inFloat =
static_cast<const float*
>(in);
49 auto outFloat =
static_cast<float*
>(out);
51 ->swapBufferInterleaved(inFloat, outFloat, frames);
64 ) :
Device(backend, config) { }
69 const PaDeviceInfo* deviceInfo = Pa_GetDeviceInfo(device.
id);
71 if (deviceInfo ==
nullptr) {
79 PaStreamParameters inputParameters;
80 inputParameters.device = device.
id;
81 inputParameters.sampleFormat = paFloat32;
82 inputParameters.suggestedLatency = deviceInfo->defaultLowInputLatency;
83 inputParameters.hostApiSpecificStreamInfo = NULL;
85 inputParameters.channelCount = device.
channelsIn;
87 PaStreamParameters outputParameters;
88 outputParameters.device = device.
id;
89 outputParameters.sampleFormat = paFloat32;
90 outputParameters.suggestedLatency = deviceInfo->defaultLowOutputLatency;
91 outputParameters.hostApiSpecificStreamInfo = NULL;
104 0 < inputParameters.channelCount ? &inputParameters : NULL,
105 0 < outputParameters.channelCount ? &outputParameters : NULL,
115 if (err != paNoError) {
121 err = Pa_SetStreamFinishedCallback(
125 if (err != paNoError) {
132 const PaStreamInfo* streamInfo = Pa_GetStreamInfo(
mStream);
134 Uint(streamInfo->sampleRate),
144 if (err != paNoError) {
169 PaUtil_SetDebugPrintFunction(&
debugLog);
170 PaError err = Pa_Initialize();
171 if (err != paNoError) {
187 return Pa_GetDeviceCount();
191 const PaDeviceInfo* deviceInfo = Pa_GetDeviceInfo(index);
192 if (deviceInfo ==
nullptr) {
198 info.
channelsIn = deviceInfo->maxInputChannels;
206 const char*
getName()
const override {
return "portaudio"; };
209 return getDevice(Pa_GetDefaultOutputDevice());
213 return getDevice(Pa_GetDefaultInputDevice());
Backend interface used to query devices before creating a actual device object.
static void debugLog(const char *message)
const char * getName() const override
Returns name of the api.
unsigned int getDeviceCount() override
Gets number of devices, needed to iterate them.
DeviceInfo getDevice(unsigned int index) override
Returns a spefic device info for index.
DeviceInfo getDefaultOutputDevice() override
Device * createDevice(const EngineConfig &config) override
Creates a device instance for this backend.
DeviceInfo getDefaultInputDevice() override
static BackendPortAudio & instance()
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...
Portaudio backend implementation.
static void StreamFinished(void *data)
bool openDevice(DeviceInfo &device) override
Opens a specific audio device.
bool closeDevice() override
Closes the currently open device.
static int AudioCallback(const void *in, void *out, unsigned long frames, const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags, void *data)
Function called from the PortAudio thread.
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.
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.
Size internalSampleRate
Samplerate requested from device.
Data shared with audio thread.
#define VAE_DEBUG(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)