[DEV] start compleate rework

Conflicts:
	airtaudio/Interface.cpp
	airtaudio/Interface.h
This commit is contained in:
Edouard DUPIN 2015-01-26 23:46:53 +01:00
parent dd604bc736
commit 6aa1746a27
16 changed files with 254 additions and 287 deletions

View File

@ -76,22 +76,21 @@ enum airtaudio::errorType airtaudio::Api::openStream(airtaudio::StreamParameters
uint32_t sampleRate, uint32_t sampleRate,
uint32_t *bufferFrames, uint32_t *bufferFrames,
airtaudio::AirTAudioCallback callback, airtaudio::AirTAudioCallback callback,
void *userData,
airtaudio::StreamOptions *options) { airtaudio::StreamOptions *options) {
if (m_stream.state != airtaudio::api::STREAM_CLOSED) { if (m_stream.state != airtaudio::api::STREAM_CLOSED) {
ATA_ERROR("airtaudio::Api::openStream: a stream is already open!"); ATA_ERROR("airtaudio::Api::openStream: a stream is already open!");
return airtaudio::errorInvalidUse; return airtaudio::errorInvalidUse;
} }
if (oParams && oParams->nChannels < 1) { if (oParams && oParams->nChannels < 1) {
ATA_ERROR("airtaudio::Api::openStream: a non-NULL output StreamParameters structure cannot have an nChannels value less than one."); ATA_ERROR("airtaudio::Api::openStream: a non-nullptr output StreamParameters structure cannot have an nChannels value less than one.");
return airtaudio::errorInvalidUse; return airtaudio::errorInvalidUse;
} }
if (iParams && iParams->nChannels < 1) { if (iParams && iParams->nChannels < 1) {
ATA_ERROR("airtaudio::Api::openStream: a non-NULL input StreamParameters structure cannot have an nChannels value less than one."); ATA_ERROR("airtaudio::Api::openStream: a non-nullptr input StreamParameters structure cannot have an nChannels value less than one.");
return airtaudio::errorInvalidUse; return airtaudio::errorInvalidUse;
} }
if (oParams == NULL && iParams == NULL) { if (oParams == nullptr && iParams == nullptr) {
ATA_ERROR("airtaudio::Api::openStream: input and output StreamParameters structures are both NULL!"); ATA_ERROR("airtaudio::Api::openStream: input and output StreamParameters structures are both nullptr!");
return airtaudio::errorInvalidUse; return airtaudio::errorInvalidUse;
} }
if (formatBytes(format) == 0) { if (formatBytes(format) == 0) {
@ -148,9 +147,8 @@ enum airtaudio::errorType airtaudio::Api::openStream(airtaudio::StreamParameters
return airtaudio::errorSystemError; return airtaudio::errorSystemError;
} }
} }
m_stream.callbackInfo.callback = (void *) callback; m_stream.callbackInfo.callback = callback;
m_stream.callbackInfo.userData = userData; if (options != nullptr) {
if (options != NULL) {
options->numberOfBuffers = m_stream.nBuffers; options->numberOfBuffers = m_stream.nBuffers;
} }
m_stream.state = airtaudio::api::STREAM_STOPPED; m_stream.state = airtaudio::api::STREAM_STOPPED;
@ -190,7 +188,7 @@ void airtaudio::Api::tickStreamTime() {
// provide basic stream time support. // provide basic stream time support.
m_stream.streamTime += (m_stream.bufferSize * 1.0 / m_stream.sampleRate); m_stream.streamTime += (m_stream.bufferSize * 1.0 / m_stream.sampleRate);
#if defined(HAVE_GETTIMEOFDAY) #if defined(HAVE_GETTIMEOFDAY)
gettimeofday(&m_stream.lastTickTimestamp, NULL); gettimeofday(&m_stream.lastTickTimestamp, nullptr);
#endif #endif
} }
@ -222,7 +220,7 @@ double airtaudio::Api::getStreamTime() {
if (m_stream.state != airtaudio::api::STREAM_RUNNING || m_stream.streamTime == 0.0) { if (m_stream.state != airtaudio::api::STREAM_RUNNING || m_stream.streamTime == 0.0) {
return m_stream.streamTime; return m_stream.streamTime;
} }
gettimeofday(&now, NULL); gettimeofday(&now, nullptr);
then = m_stream.lastTickTimestamp; then = m_stream.lastTickTimestamp;
return m_stream.streamTime return m_stream.streamTime
+ ((now.tv_sec + 0.000001 * now.tv_usec) + ((now.tv_sec + 0.000001 * now.tv_usec)
@ -259,7 +257,6 @@ void airtaudio::Api::clearStreamInfo() {
m_stream.apiHandle = 0; m_stream.apiHandle = 0;
m_stream.deviceBuffer = 0; m_stream.deviceBuffer = 0;
m_stream.callbackInfo.callback = 0; m_stream.callbackInfo.callback = 0;
m_stream.callbackInfo.userData = 0;
m_stream.callbackInfo.isRunning = false; m_stream.callbackInfo.isRunning = false;
for (int32_t iii=0; iii<2; ++iii) { for (int32_t iii=0; iii<2; ++iii) {
m_stream.device[iii] = 11111; m_stream.device[iii] = 11111;
@ -808,8 +805,8 @@ void airtaudio::Api::convertBuffer(char *_outBuffer, char *_inBuffer, airtaudio:
} }
void airtaudio::Api::byteSwapBuffer(char *_buffer, uint32_t _samples, airtaudio::format _format) { void airtaudio::Api::byteSwapBuffer(char *_buffer, uint32_t _samples, airtaudio::format _format) {
register char val; char val;
register char *ptr; char *ptr;
ptr = _buffer; ptr = _buffer;
if (_format == airtaudio::SINT16) { if (_format == airtaudio::SINT16) {
for (uint32_t iii=0; iii<_samples; ++iii) { for (uint32_t iii=0; iii<_samples; ++iii) {

View File

@ -126,7 +126,6 @@ namespace airtaudio {
uint32_t _sampleRate, uint32_t _sampleRate,
uint32_t *_bufferFrames, uint32_t *_bufferFrames,
airtaudio::AirTAudioCallback _callback, airtaudio::AirTAudioCallback _callback,
void *_userData,
airtaudio::StreamOptions *_options); airtaudio::StreamOptions *_options);
virtual enum airtaudio::errorType closeStream(); virtual enum airtaudio::errorType closeStream();
virtual enum airtaudio::errorType startStream() = 0; virtual enum airtaudio::errorType startStream() = 0;

View File

@ -10,6 +10,8 @@
#define __AIRTAUDIO_CALLBACK_INFO_H__ #define __AIRTAUDIO_CALLBACK_INFO_H__
#include <thread> #include <thread>
#include <functional>
#include <airtaudio/base.h>
namespace airtaudio { namespace airtaudio {
// This global structure type is used to pass callback information // This global structure type is used to pass callback information
@ -19,8 +21,7 @@ namespace airtaudio {
public: public:
void* object; // Used as a "this" pointer. void* object; // Used as a "this" pointer.
std::thread* thread; std::thread* thread;
void* callback; airtaudio::AirTAudioCallback callback;
void* userData;
void* apiInfo; // void pointer for API specific callback information void* apiInfo; // void pointer for API specific callback information
bool isRunning; bool isRunning;
bool doRealtime; bool doRealtime;
@ -28,10 +29,9 @@ namespace airtaudio {
// Default constructor. // Default constructor.
CallbackInfo() : CallbackInfo() :
object(0), object(nullptr),
callback(0), callback(nullptr),
userData(0), apiInfo(nullptr),
apiInfo(0),
isRunning(false), isRunning(false),
doRealtime(false) { doRealtime(false) {

View File

@ -24,7 +24,6 @@ std::vector<airtaudio::api::type> airtaudio::Interface::getCompiledApi() {
void airtaudio::Interface::openRtApi(airtaudio::api::type _api) { void airtaudio::Interface::openRtApi(airtaudio::api::type _api) {
delete m_rtapi; delete m_rtapi;
m_rtapi = nullptr; m_rtapi = nullptr;
for (auto &it :m_apiAvaillable) { for (auto &it :m_apiAvaillable) {
@ -146,7 +145,6 @@ enum airtaudio::errorType airtaudio::Interface::openStream(
uint32_t _sampleRate, uint32_t _sampleRate,
uint32_t* _bufferFrames, uint32_t* _bufferFrames,
airtaudio::AirTAudioCallback _callback, airtaudio::AirTAudioCallback _callback,
void* _userData,
airtaudio::StreamOptions* _options) { airtaudio::StreamOptions* _options) {
if (m_rtapi == nullptr) { if (m_rtapi == nullptr) {
return airtaudio::errorInputNull; return airtaudio::errorInputNull;
@ -157,7 +155,6 @@ enum airtaudio::errorType airtaudio::Interface::openStream(
_sampleRate, _sampleRate,
_bufferFrames, _bufferFrames,
_callback, _callback,
_userData,
_options); _options);
} }

View File

@ -173,8 +173,6 @@ namespace airtaudio {
* allowable value is determined. * allowable value is determined.
* @param _callback A client-defined function that will be invoked * @param _callback A client-defined function that will be invoked
* when input data is available and/or output data is needed. * when input data is available and/or output data is needed.
* @param _userData An optional pointer to data that can be accessed
* from within the callback function.
* @param _options An optional pointer to a structure containing various * @param _options An optional pointer to a structure containing various
* global stream options, including a list of OR'ed airtaudio::streamFlags * global stream options, including a list of OR'ed airtaudio::streamFlags
* and a suggested number of stream buffers that can be used to * and a suggested number of stream buffers that can be used to
@ -193,7 +191,6 @@ namespace airtaudio {
uint32_t _sampleRate, uint32_t _sampleRate,
uint32_t *_bufferFrames, uint32_t *_bufferFrames,
airtaudio::AirTAudioCallback _callback, airtaudio::AirTAudioCallback _callback,
void *_userData = nullptr,
airtaudio::StreamOptions *_options = nullptr); airtaudio::StreamOptions *_options = nullptr);
/** /**

View File

@ -456,7 +456,7 @@ foundDevice:
return false; return false;
} }
// Set access ... check user preference. // Set access ... check user preference.
if ( _options != NULL if ( _options != nullptr
&& _options->flags & airtaudio::NONINTERLEAVED) { && _options->flags & airtaudio::NONINTERLEAVED) {
m_stream.userInterleaved = false; m_stream.userInterleaved = false;
result = snd_pcm_hw_params_set_access(phandle, hw_params, SND_PCM_ACCESS_RW_NONINTERLEAVED); result = snd_pcm_hw_params_set_access(phandle, hw_params, SND_PCM_ACCESS_RW_NONINTERLEAVED);
@ -630,7 +630,7 @@ setFormat:
return false; return false;
} }
// Set the software configuration to fill buffers with zeros and prevent device stopping on xruns. // Set the software configuration to fill buffers with zeros and prevent device stopping on xruns.
snd_pcm_sw_params_t *sw_params = NULL; snd_pcm_sw_params_t *sw_params = nullptr;
snd_pcm_sw_params_alloca(&sw_params); snd_pcm_sw_params_alloca(&sw_params);
snd_pcm_sw_params_current(phandle, sw_params); snd_pcm_sw_params_current(phandle, sw_params);
snd_pcm_sw_params_set_start_threshold(phandle, sw_params, *_bufferSize); snd_pcm_sw_params_set_start_threshold(phandle, sw_params, *_bufferSize);
@ -666,7 +666,7 @@ setFormat:
AlsaHandle *apiInfo = 0; AlsaHandle *apiInfo = 0;
if (m_stream.apiHandle == 0) { if (m_stream.apiHandle == 0) {
apiInfo = (AlsaHandle *) new AlsaHandle; apiInfo = (AlsaHandle *) new AlsaHandle;
if (apiInfo == NULL) { if (apiInfo == nullptr) {
ATA_ERROR("airtaudio::api::Alsa::probeDeviceOpen: error allocating AlsaHandle memory."); ATA_ERROR("airtaudio::api::Alsa::probeDeviceOpen: error allocating AlsaHandle memory.");
goto error; goto error;
} }
@ -682,7 +682,7 @@ setFormat:
uint64_t bufferBytes; uint64_t bufferBytes;
bufferBytes = m_stream.nUserChannels[_mode] * *_bufferSize * formatBytes(m_stream.userFormat); bufferBytes = m_stream.nUserChannels[_mode] * *_bufferSize * formatBytes(m_stream.userFormat);
m_stream.userBuffer[_mode] = (char *) calloc(bufferBytes, 1); m_stream.userBuffer[_mode] = (char *) calloc(bufferBytes, 1);
if (m_stream.userBuffer[_mode] == NULL) { if (m_stream.userBuffer[_mode] == nullptr) {
ATA_ERROR("airtaudio::api::Alsa::probeDeviceOpen: error allocating user buffer memory."); ATA_ERROR("airtaudio::api::Alsa::probeDeviceOpen: error allocating user buffer memory.");
goto error; goto error;
} }
@ -701,10 +701,10 @@ setFormat:
bufferBytes *= *_bufferSize; bufferBytes *= *_bufferSize;
if (m_stream.deviceBuffer) { if (m_stream.deviceBuffer) {
free(m_stream.deviceBuffer); free(m_stream.deviceBuffer);
m_stream.deviceBuffer = NULL; m_stream.deviceBuffer = nullptr;
} }
m_stream.deviceBuffer = (char *) calloc(bufferBytes, 1); m_stream.deviceBuffer = (char *) calloc(bufferBytes, 1);
if (m_stream.deviceBuffer == NULL) { if (m_stream.deviceBuffer == nullptr) {
ATA_ERROR("airtaudio::api::Alsa::probeDeviceOpen: error allocating device buffer memory."); ATA_ERROR("airtaudio::api::Alsa::probeDeviceOpen: error allocating device buffer memory.");
goto error; goto error;
} }
@ -737,7 +737,7 @@ setFormat:
m_stream.callbackInfo.object = (void *) this; m_stream.callbackInfo.object = (void *) this;
m_stream.callbackInfo.isRunning = true; m_stream.callbackInfo.isRunning = true;
m_stream.callbackInfo.thread = new std::thread(alsaCallbackHandler, &m_stream.callbackInfo); m_stream.callbackInfo.thread = new std::thread(alsaCallbackHandler, &m_stream.callbackInfo);
if (m_stream.callbackInfo.thread == NULL) { if (m_stream.callbackInfo.thread == nullptr) {
m_stream.callbackInfo.isRunning = false; m_stream.callbackInfo.isRunning = false;
ATA_ERROR("airtaudio::api::Alsa::error creating callback thread!"); ATA_ERROR("airtaudio::api::Alsa::error creating callback thread!");
goto error; goto error;
@ -745,7 +745,7 @@ setFormat:
} }
return true; return true;
error: error:
if (apiInfo != NULL) { if (apiInfo != nullptr) {
if (apiInfo->handles[0]) { if (apiInfo->handles[0]) {
snd_pcm_close(apiInfo->handles[0]); snd_pcm_close(apiInfo->handles[0]);
} }
@ -753,7 +753,7 @@ error:
snd_pcm_close(apiInfo->handles[1]); snd_pcm_close(apiInfo->handles[1]);
} }
delete apiInfo; delete apiInfo;
apiInfo = NULL; apiInfo = nullptr;
m_stream.apiHandle = 0; m_stream.apiHandle = 0;
} }
if (phandle) { if (phandle) {
@ -786,7 +786,7 @@ enum airtaudio::errorType airtaudio::api::Alsa::closeStream() {
apiInfo->runnable_cv.notify_one(); apiInfo->runnable_cv.notify_one();
} }
m_stream.mutex.unlock(); m_stream.mutex.unlock();
if (m_stream.callbackInfo.thread != NULL) { if (m_stream.callbackInfo.thread != nullptr) {
m_stream.callbackInfo.thread->join(); m_stream.callbackInfo.thread->join();
} }
if (m_stream.state == STREAM_RUNNING) { if (m_stream.state == STREAM_RUNNING) {
@ -800,7 +800,7 @@ enum airtaudio::errorType airtaudio::api::Alsa::closeStream() {
snd_pcm_drop(apiInfo->handles[1]); snd_pcm_drop(apiInfo->handles[1]);
} }
} }
if (apiInfo != NULL) { if (apiInfo != nullptr) {
if (apiInfo->handles[0]) { if (apiInfo->handles[0]) {
snd_pcm_close(apiInfo->handles[0]); snd_pcm_close(apiInfo->handles[0]);
} }
@ -808,11 +808,11 @@ enum airtaudio::errorType airtaudio::api::Alsa::closeStream() {
snd_pcm_close(apiInfo->handles[1]); snd_pcm_close(apiInfo->handles[1]);
} }
delete apiInfo; delete apiInfo;
apiInfo = NULL; apiInfo = nullptr;
m_stream.apiHandle = 0; m_stream.apiHandle = 0;
} }
for (int32_t iii=0; iii<2; ++iii) { for (int32_t iii=0; iii<2; ++iii) {
if (m_stream.userBuffer[iii] != NULL) { if (m_stream.userBuffer[iii] != nullptr) {
free(m_stream.userBuffer[iii]); free(m_stream.userBuffer[iii]);
m_stream.userBuffer[iii] = 0; m_stream.userBuffer[iii] = 0;
} }
@ -969,7 +969,6 @@ void airtaudio::api::Alsa::callbackEvent() {
return; // TODO : notify appl: airtaudio::errorWarning; return; // TODO : notify appl: airtaudio::errorWarning;
} }
int32_t doStopStream = 0; int32_t doStopStream = 0;
airtaudio::AirTAudioCallback callback = (airtaudio::AirTAudioCallback) m_stream.callbackInfo.callback;
double streamTime = getStreamTime(); double streamTime = getStreamTime();
airtaudio::streamStatus status = 0; airtaudio::streamStatus status = 0;
if (m_stream.mode != INPUT && apiInfo->xrun[0] == true) { if (m_stream.mode != INPUT && apiInfo->xrun[0] == true) {
@ -980,12 +979,11 @@ void airtaudio::api::Alsa::callbackEvent() {
status |= airtaudio::INPUT_OVERFLOW; status |= airtaudio::INPUT_OVERFLOW;
apiInfo->xrun[1] = false; apiInfo->xrun[1] = false;
} }
doStopStream = callback(m_stream.userBuffer[0], doStopStream = m_stream.callbackInfo.callback(m_stream.userBuffer[0],
m_stream.userBuffer[1], m_stream.userBuffer[1],
m_stream.bufferSize, m_stream.bufferSize,
streamTime, streamTime,
status, status);
m_stream.callbackInfo.userData);
if (doStopStream == 2) { if (doStopStream == 2) {
abortStream(); abortStream();
return; return;

View File

@ -120,24 +120,21 @@ enum airtaudio::errorType airtaudio::api::Android::abortStream() {
void airtaudio::api::Android::callBackEvent(void* _data, void airtaudio::api::Android::callBackEvent(void* _data,
int32_t _frameRate) { int32_t _frameRate) {
int32_t doStopStream = 0; int32_t doStopStream = 0;
airtaudio::AirTAudioCallback callback = (airtaudio::AirTAudioCallback) m_stream.callbackInfo.callback;
double streamTime = getStreamTime(); double streamTime = getStreamTime();
airtaudio::streamStatus status = 0; airtaudio::streamStatus status = 0;
if (m_stream.doConvertBuffer[OUTPUT] == true) { if (m_stream.doConvertBuffer[OUTPUT] == true) {
doStopStream = callback(m_stream.userBuffer[OUTPUT], doStopStream = m_stream.callbackInfo.callback(m_stream.userBuffer[OUTPUT],
NULL, nullptr,
_frameRate, _frameRate,
streamTime, streamTime,
status, status);
m_stream.callbackInfo.userData);
convertBuffer((char*)_data, (char*)m_stream.userBuffer[OUTPUT], m_stream.convertInfo[OUTPUT]); convertBuffer((char*)_data, (char*)m_stream.userBuffer[OUTPUT], m_stream.convertInfo[OUTPUT]);
} else { } else {
doStopStream = callback(_data, doStopStream = m_stream.callbackInfo.callback(_data,
NULL, nullptr,
_frameRate, _frameRate,
streamTime, streamTime,
status, status);
m_stream.callbackInfo.userData);
} }
if (doStopStream == 2) { if (doStopStream == 2) {
abortStream(); abortStream();
@ -149,8 +146,8 @@ void airtaudio::api::Android::callBackEvent(void* _data,
void airtaudio::api::Android::androidCallBackEvent(void* _data, void airtaudio::api::Android::androidCallBackEvent(void* _data,
int32_t _frameRate, int32_t _frameRate,
void* _userData) { void* _userData) {
if (_userData == NULL) { if (_userData == nullptr) {
ATA_INFO("callback event ... NULL pointer"); ATA_INFO("callback event ... nullptr pointer");
return; return;
} }
airtaudio::api::Android* myClass = static_cast<airtaudio::api::Android*>(_userData); airtaudio::api::Android* myClass = static_cast<airtaudio::api::Android*>(_userData);
@ -203,7 +200,7 @@ bool airtaudio::api::Android::probeDeviceOpen(uint32_t _device,
// Allocate necessary internal buffers. // Allocate necessary internal buffers.
uint64_t bufferBytes = m_stream.nUserChannels[_mode] * m_stream.bufferSize * formatBytes(m_stream.userFormat); uint64_t bufferBytes = m_stream.nUserChannels[_mode] * m_stream.bufferSize * formatBytes(m_stream.userFormat);
m_stream.userBuffer[_mode] = (char *) calloc(bufferBytes, 1); m_stream.userBuffer[_mode] = (char *) calloc(bufferBytes, 1);
if (m_stream.userBuffer[_mode] == NULL) { if (m_stream.userBuffer[_mode] == nullptr) {
ATA_ERROR("airtaudio::api::Android::probeDeviceOpen: error allocating user buffer memory."); ATA_ERROR("airtaudio::api::Android::probeDeviceOpen: error allocating user buffer memory.");
} }
setConvertInfo(_mode, _firstChannel); setConvertInfo(_mode, _firstChannel);

View File

@ -68,7 +68,7 @@ airtaudio::api::Asio::Asio() {
// CoInitialize beforehand, but it must be for appartment threading // CoInitialize beforehand, but it must be for appartment threading
// (in which case, CoInitilialize will return S_FALSE here). // (in which case, CoInitilialize will return S_FALSE here).
m_coInitialized = false; m_coInitialized = false;
HRESULT hr = CoInitialize(NULL); HRESULT hr = CoInitialize(nullptr);
if (FAILED(hr)) { if (FAILED(hr)) {
ATA_ERROR("airtaudio::api::Asio::ASIO requires a single-threaded appartment. Call CoInitializeEx(0,COINIT_APARTMENTTHREADED)"); ATA_ERROR("airtaudio::api::Asio::ASIO requires a single-threaded appartment. Call CoInitializeEx(0,COINIT_APARTMENTTHREADED)");
} }
@ -399,7 +399,7 @@ bool airtaudio::api::Asio::probeDeviceOpen(uint32_t _device,
} }
m_stream.bufferSize = *_bufferSize; m_stream.bufferSize = *_bufferSize;
m_stream.nBuffers = 2; m_stream.nBuffers = 2;
if ( _options != NULL if ( _options != nullptr
&& _options->flags & RTAUDIO_NONINTERLEAVED) { && _options->flags & RTAUDIO_NONINTERLEAVED) {
m_stream.userInterleaved = false; m_stream.userInterleaved = false;
} else { } else {
@ -409,19 +409,19 @@ bool airtaudio::api::Asio::probeDeviceOpen(uint32_t _device,
m_stream.deviceInterleaved[_mode] = false; m_stream.deviceInterleaved[_mode] = false;
// Allocate, if necessary, our AsioHandle structure for the stream. // Allocate, if necessary, our AsioHandle structure for the stream.
AsioHandle *handle = (AsioHandle *) m_stream.apiHandle; AsioHandle *handle = (AsioHandle *) m_stream.apiHandle;
if (handle == NULL) { if (handle == nullptr) {
handle = new AsioHandle; handle = new AsioHandle;
if (handle == NULL) { if (handle == nullptr) {
drivers.removeCurrentDriver(); drivers.removeCurrentDriver();
ATA_ERROR("airtaudio::api::Asio::probeDeviceOpen: error allocating AsioHandle memory."); ATA_ERROR("airtaudio::api::Asio::probeDeviceOpen: error allocating AsioHandle memory.");
return false; return false;
} }
handle->bufferInfos = 0; handle->bufferInfos = 0;
// Create a manual-reset event. // Create a manual-reset event.
handle->condition = CreateEvent(NULL, // no security handle->condition = CreateEvent(nullptr, // no security
TRUE, // manual-reset TRUE, // manual-reset
FALSE, // non-signaled initially FALSE, // non-signaled initially
NULL); // unnamed nullptr); // unnamed
m_stream.apiHandle = (void *) handle; m_stream.apiHandle = (void *) handle;
} }
// Create the ASIO internal buffers. Since RtAudio sets up input // Create the ASIO internal buffers. Since RtAudio sets up input
@ -431,16 +431,16 @@ bool airtaudio::api::Asio::probeDeviceOpen(uint32_t _device,
if ( _mode == INPUT if ( _mode == INPUT
&& m_stream.mode == OUTPUT) { && m_stream.mode == OUTPUT) {
ASIODisposeBuffers(); ASIODisposeBuffers();
if (handle->bufferInfos == NULL) { if (handle->bufferInfos == nullptr) {
free(handle->bufferInfos); free(handle->bufferInfos);
handle->bufferInfos = NULL; handle->bufferInfos = nullptr;
} }
} }
// Allocate, initialize, and save the bufferInfos in our stream callbackInfo structure. // Allocate, initialize, and save the bufferInfos in our stream callbackInfo structure.
bool buffersAllocated = false; bool buffersAllocated = false;
uint32_t i, nChannels = m_stream.nDeviceChannels[0] + m_stream.nDeviceChannels[1]; uint32_t i, nChannels = m_stream.nDeviceChannels[0] + m_stream.nDeviceChannels[1];
handle->bufferInfos = (ASIOBufferInfo *) malloc(nChannels * sizeof(ASIOBufferInfo)); handle->bufferInfos = (ASIOBufferInfo *) malloc(nChannels * sizeof(ASIOBufferInfo));
if (handle->bufferInfos == NULL) { if (handle->bufferInfos == nullptr) {
ATA_ERROR("airtaudio::api::Asio::probeDeviceOpen: error allocating bufferInfo memory for driver (" << driverName << ")."); ATA_ERROR("airtaudio::api::Asio::probeDeviceOpen: error allocating bufferInfo memory for driver (" << driverName << ").");
goto error; goto error;
} }
@ -460,7 +460,7 @@ bool airtaudio::api::Asio::probeDeviceOpen(uint32_t _device,
asioCallbacks.bufferSwitch = &bufferSwitch; asioCallbacks.bufferSwitch = &bufferSwitch;
asioCallbacks.sampleRateDidChange = &sampleRateChanged; asioCallbacks.sampleRateDidChange = &sampleRateChanged;
asioCallbacks.asioMessage = &asioMessages; asioCallbacks.asioMessage = &asioMessages;
asioCallbacks.bufferSwitchTimeInfo = NULL; asioCallbacks.bufferSwitchTimeInfo = nullptr;
result = ASIOCreateBuffers(handle->bufferInfos, nChannels, m_stream.bufferSize, &asioCallbacks); result = ASIOCreateBuffers(handle->bufferInfos, nChannels, m_stream.bufferSize, &asioCallbacks);
if (result != ASE_OK) { if (result != ASE_OK) {
ATA_ERROR("airtaudio::api::Asio::probeDeviceOpen: driver (" << driverName << ") error (" << getAsioErrorString(result) << ") creating buffers."); ATA_ERROR("airtaudio::api::Asio::probeDeviceOpen: driver (" << driverName << ") error (" << getAsioErrorString(result) << ") creating buffers.");
@ -480,7 +480,7 @@ bool airtaudio::api::Asio::probeDeviceOpen(uint32_t _device,
uint64_t bufferBytes; uint64_t bufferBytes;
bufferBytes = m_stream.nUserChannels[_mode] * *_bufferSize * formatBytes(m_stream.userFormat); bufferBytes = m_stream.nUserChannels[_mode] * *_bufferSize * formatBytes(m_stream.userFormat);
m_stream.userBuffer[_mode] = (char *) calloc(bufferBytes, 1); m_stream.userBuffer[_mode] = (char *) calloc(bufferBytes, 1);
if (m_stream.userBuffer[_mode] == NULL) { if (m_stream.userBuffer[_mode] == nullptr) {
ATA_ERROR("airtaudio::api::Asio::probeDeviceOpen: error allocating user buffer memory."); ATA_ERROR("airtaudio::api::Asio::probeDeviceOpen: error allocating user buffer memory.");
goto error; goto error;
} }
@ -499,10 +499,10 @@ bool airtaudio::api::Asio::probeDeviceOpen(uint32_t _device,
bufferBytes *= *_bufferSize; bufferBytes *= *_bufferSize;
if (m_stream.deviceBuffer) { if (m_stream.deviceBuffer) {
free(m_stream.deviceBuffer); free(m_stream.deviceBuffer);
m_stream.deviceBuffer = NULL; m_stream.deviceBuffer = nullptr;
} }
m_stream.deviceBuffer = (char *) calloc(bufferBytes, 1); m_stream.deviceBuffer = (char *) calloc(bufferBytes, 1);
if (m_stream.deviceBuffer == NULL) { if (m_stream.deviceBuffer == nullptr) {
ATA_ERROR("airtaudio::api::Asio::probeDeviceOpen: error allocating device buffer memory."); ATA_ERROR("airtaudio::api::Asio::probeDeviceOpen: error allocating device buffer memory.");
goto error; goto error;
} }
@ -544,10 +544,10 @@ error:
CloseHandle(handle->condition); CloseHandle(handle->condition);
if (handle->bufferInfos) { if (handle->bufferInfos) {
free(handle->bufferInfos); free(handle->bufferInfos);
handle->bufferInfos = NULL; handle->bufferInfos = nullptr;
} }
delete handle; delete handle;
handle = NULL; handle = nullptr;
m_stream.apiHandle = 0; m_stream.apiHandle = 0;
} }
for (int32_t i=0; i<2; i++) { for (int32_t i=0; i<2; i++) {
@ -703,15 +703,14 @@ bool airtaudio::api::Asio::callbackEvent(long bufferIndex) {
SetEvent(handle->condition); SetEvent(handle->condition);
} else { // spawn a thread to stop the stream } else { // spawn a thread to stop the stream
unsigned threadId; unsigned threadId;
m_stream.callbackInfo.thread = _beginthreadex(NULL, 0, &asioStopStream, m_stream.callbackInfo.thread = _beginthreadex(nullptr, 0, &asioStopStream,
&m_stream.callbackInfo, 0, &threadId); &m_stream.callbackInfo, 0, &threadId);
} }
return true; return true;
} }
// Invoke user callback to get fresh output data UNLESS we are // Invoke user callback to get fresh output data UNLESS we are
// draining stream. // draining stream.
if (handle->drainCounter == 0) { if (handle->drainCounter == 0) {
airtaudio::AirTAudioCallback callback = (airtaudio::AirTAudioCallback) info->callback;
double streamTime = getStreamTime(); double streamTime = getStreamTime();
rtaudio::streamStatus status = 0; rtaudio::streamStatus status = 0;
if (m_stream.mode != INPUT && asioXRun == true) { if (m_stream.mode != INPUT && asioXRun == true) {
@ -722,17 +721,16 @@ bool airtaudio::api::Asio::callbackEvent(long bufferIndex) {
status |= RTAUDIO_INPUT_OVERFLOW; status |= RTAUDIO_INPUT_OVERFLOW;
asioXRun = false; asioXRun = false;
} }
int32_t cbReturnValue = callback(m_stream.userBuffer[0], int32_t cbReturnValue = info->callback(m_stream.userBuffer[0],
m_stream.userBuffer[1], m_stream.userBuffer[1],
m_stream.bufferSize, m_stream.bufferSize,
streamTime, streamTime,
status, status);
info->userData);
if (cbReturnValue == 2) { if (cbReturnValue == 2) {
m_stream.state = STREAM_STOPPING; m_stream.state = STREAM_STOPPING;
handle->drainCounter = 2; handle->drainCounter = 2;
unsigned threadId; unsigned threadId;
m_stream.callbackInfo.thread = _beginthreadex(NULL, m_stream.callbackInfo.thread = _beginthreadex(nullptr,
0, 0,
&asioStopStream, &asioStopStream,
&m_stream.callbackInfo, &m_stream.callbackInfo,

View File

@ -71,7 +71,7 @@ airtaudio::api::Core::Core() {
// requirement starting with OS-X 10.6. If not called, queries and // requirement starting with OS-X 10.6. If not called, queries and
// updates to various audio device properties are not handled // updates to various audio device properties are not handled
// correctly. // correctly.
CFRunLoopRef theRunLoop = NULL; CFRunLoopRef theRunLoop = nullptr;
AudioObjectPropertyAddress property = { AudioObjectPropertyAddress property = {
kAudioHardwarePropertyRunLoop, kAudioHardwarePropertyRunLoop,
kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyScopeGlobal,
@ -80,7 +80,7 @@ airtaudio::api::Core::Core() {
OSStatus result = AudioObjectSetPropertyData(kAudioObjectSystemObject, OSStatus result = AudioObjectSetPropertyData(kAudioObjectSystemObject,
&property, &property,
0, 0,
NULL, nullptr,
sizeof(CFRunLoopRef), sizeof(CFRunLoopRef),
&theRunLoop); &theRunLoop);
if (result != noErr) { if (result != noErr) {
@ -106,7 +106,7 @@ uint32_t airtaudio::api::Core::getDeviceCount() {
kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyScopeGlobal,
kAudioObjectPropertyElementMaster kAudioObjectPropertyElementMaster
}; };
OSStatus result = AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &propertyAddress, 0, NULL, &dataSize); OSStatus result = AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &propertyAddress, 0, nullptr, &dataSize);
if (result != noErr) { if (result != noErr) {
ATA_ERROR("airtaudio::api::Core::getDeviceCount: OS-X error getting device info!"); ATA_ERROR("airtaudio::api::Core::getDeviceCount: OS-X error getting device info!");
return 0; return 0;
@ -129,7 +129,7 @@ uint32_t airtaudio::api::Core::getDefaultInputDevice() {
OSStatus result = AudioObjectGetPropertyData(kAudioObjectSystemObject, OSStatus result = AudioObjectGetPropertyData(kAudioObjectSystemObject,
&property, &property,
0, 0,
NULL, nullptr,
&dataSize, &dataSize,
&id); &id);
if (result != noErr) { if (result != noErr) {
@ -142,7 +142,7 @@ uint32_t airtaudio::api::Core::getDefaultInputDevice() {
result = AudioObjectGetPropertyData(kAudioObjectSystemObject, result = AudioObjectGetPropertyData(kAudioObjectSystemObject,
&property, &property,
0, 0,
NULL, nullptr,
&dataSize, &dataSize,
(void*)&deviceList); (void*)&deviceList);
if (result != noErr) { if (result != noErr) {
@ -173,7 +173,7 @@ uint32_t airtaudio::api::Core::getDefaultOutputDevice() {
OSStatus result = AudioObjectGetPropertyData(kAudioObjectSystemObject, OSStatus result = AudioObjectGetPropertyData(kAudioObjectSystemObject,
&property, &property,
0, 0,
NULL, nullptr,
&dataSize, &dataSize,
&id); &id);
if (result != noErr) { if (result != noErr) {
@ -186,7 +186,7 @@ uint32_t airtaudio::api::Core::getDefaultOutputDevice() {
result = AudioObjectGetPropertyData(kAudioObjectSystemObject, result = AudioObjectGetPropertyData(kAudioObjectSystemObject,
&property, &property,
0, 0,
NULL, nullptr,
&dataSize, &dataSize,
(void*)&deviceList); (void*)&deviceList);
if (result != noErr) { if (result != noErr) {
@ -225,7 +225,7 @@ airtaudio::DeviceInfo airtaudio::api::Core::getDeviceInfo(uint32_t _device) {
OSStatus result = AudioObjectGetPropertyData(kAudioObjectSystemObject, OSStatus result = AudioObjectGetPropertyData(kAudioObjectSystemObject,
&property, &property,
0, 0,
NULL, nullptr,
&dataSize, &dataSize,
(void*)&deviceList); (void*)&deviceList);
if (result != noErr) { if (result != noErr) {
@ -238,7 +238,7 @@ airtaudio::DeviceInfo airtaudio::api::Core::getDeviceInfo(uint32_t _device) {
CFStringRef cfname; CFStringRef cfname;
dataSize = sizeof(CFStringRef); dataSize = sizeof(CFStringRef);
property.mSelector = kAudioObjectPropertyManufacturer; property.mSelector = kAudioObjectPropertyManufacturer;
result = AudioObjectGetPropertyData(id, &property, 0, NULL, &dataSize, &cfname); result = AudioObjectGetPropertyData(id, &property, 0, nullptr, &dataSize, &cfname);
if (result != noErr) { if (result != noErr) {
ATA_ERROR("airtaudio::api::Core::probeDeviceInfo: system error (" << getErrorCode(result) << ") getting device manufacturer."); ATA_ERROR("airtaudio::api::Core::probeDeviceInfo: system error (" << getErrorCode(result) << ") getting device manufacturer.");
return info; return info;
@ -252,7 +252,7 @@ airtaudio::DeviceInfo airtaudio::api::Core::getDeviceInfo(uint32_t _device) {
CFRelease(cfname); CFRelease(cfname);
free(mname); free(mname);
property.mSelector = kAudioObjectPropertyName; property.mSelector = kAudioObjectPropertyName;
result = AudioObjectGetPropertyData(id, &property, 0, NULL, &dataSize, &cfname); result = AudioObjectGetPropertyData(id, &property, 0, nullptr, &dataSize, &cfname);
if (result != noErr) { if (result != noErr) {
ATA_ERROR("airtaudio::api::Core::probeDeviceInfo: system error (" << getErrorCode(result) << ") getting device name."); ATA_ERROR("airtaudio::api::Core::probeDeviceInfo: system error (" << getErrorCode(result) << ") getting device name.");
return info; return info;
@ -270,18 +270,18 @@ airtaudio::DeviceInfo airtaudio::api::Core::getDeviceInfo(uint32_t _device) {
property.mScope = kAudioDevicePropertyScopeOutput; property.mScope = kAudioDevicePropertyScopeOutput;
// property.mElement = kAudioObjectPropertyElementWildcard; // property.mElement = kAudioObjectPropertyElementWildcard;
dataSize = 0; dataSize = 0;
result = AudioObjectGetPropertyDataSize(id, &property, 0, NULL, &dataSize); result = AudioObjectGetPropertyDataSize(id, &property, 0, nullptr, &dataSize);
if (result != noErr || dataSize == 0) { if (result != noErr || dataSize == 0) {
ATA_ERROR("airtaudio::api::Core::getDeviceInfo: system error (" << getErrorCode(result) << ") getting output stream configuration info for device (" << _device << ")."); ATA_ERROR("airtaudio::api::Core::getDeviceInfo: system error (" << getErrorCode(result) << ") getting output stream configuration info for device (" << _device << ").");
return info; return info;
} }
// Allocate the AudioBufferList. // Allocate the AudioBufferList.
bufferList = (AudioBufferList *) malloc(dataSize); bufferList = (AudioBufferList *) malloc(dataSize);
if (bufferList == NULL) { if (bufferList == nullptr) {
ATA_ERROR("airtaudio::api::Core::getDeviceInfo: memory error allocating output AudioBufferList."); ATA_ERROR("airtaudio::api::Core::getDeviceInfo: memory error allocating output AudioBufferList.");
return info; return info;
} }
result = AudioObjectGetPropertyData(id, &property, 0, NULL, &dataSize, bufferList); result = AudioObjectGetPropertyData(id, &property, 0, nullptr, &dataSize, bufferList);
if ( result != noErr if ( result != noErr
|| dataSize == 0) { || dataSize == 0) {
free(bufferList); free(bufferList);
@ -296,7 +296,7 @@ airtaudio::DeviceInfo airtaudio::api::Core::getDeviceInfo(uint32_t _device) {
free(bufferList); free(bufferList);
// Get the input stream "configuration". // Get the input stream "configuration".
property.mScope = kAudioDevicePropertyScopeInput; property.mScope = kAudioDevicePropertyScopeInput;
result = AudioObjectGetPropertyDataSize(id, &property, 0, NULL, &dataSize); result = AudioObjectGetPropertyDataSize(id, &property, 0, nullptr, &dataSize);
if ( result != noErr if ( result != noErr
|| dataSize == 0) { || dataSize == 0) {
ATA_ERROR("airtaudio::api::Core::getDeviceInfo: system error (" << getErrorCode(result) << ") getting input stream configuration info for device (" << _device << ")."); ATA_ERROR("airtaudio::api::Core::getDeviceInfo: system error (" << getErrorCode(result) << ") getting input stream configuration info for device (" << _device << ").");
@ -304,11 +304,11 @@ airtaudio::DeviceInfo airtaudio::api::Core::getDeviceInfo(uint32_t _device) {
} }
// Allocate the AudioBufferList. // Allocate the AudioBufferList.
bufferList = (AudioBufferList *) malloc(dataSize); bufferList = (AudioBufferList *) malloc(dataSize);
if (bufferList == NULL) { if (bufferList == nullptr) {
ATA_ERROR("airtaudio::api::Core::getDeviceInfo: memory error allocating input AudioBufferList."); ATA_ERROR("airtaudio::api::Core::getDeviceInfo: memory error allocating input AudioBufferList.");
return info; return info;
} }
result = AudioObjectGetPropertyData(id, &property, 0, NULL, &dataSize, bufferList); result = AudioObjectGetPropertyData(id, &property, 0, nullptr, &dataSize, bufferList);
if (result != noErr || dataSize == 0) { if (result != noErr || dataSize == 0) {
free(bufferList); free(bufferList);
ATA_ERROR("airtaudio::api::Core::getDeviceInfo: system error (" << getErrorCode(result) << ") getting input stream configuration for device (" << _device << ")."); ATA_ERROR("airtaudio::api::Core::getDeviceInfo: system error (" << getErrorCode(result) << ") getting input stream configuration for device (" << _device << ").");
@ -333,7 +333,7 @@ airtaudio::DeviceInfo airtaudio::api::Core::getDeviceInfo(uint32_t _device) {
// Determine the supported sample rates. // Determine the supported sample rates.
property.mSelector = kAudioDevicePropertyAvailableNominalSampleRates; property.mSelector = kAudioDevicePropertyAvailableNominalSampleRates;
if (isInput == false) property.mScope = kAudioDevicePropertyScopeOutput; if (isInput == false) property.mScope = kAudioDevicePropertyScopeOutput;
result = AudioObjectGetPropertyDataSize(id, &property, 0, NULL, &dataSize); result = AudioObjectGetPropertyDataSize(id, &property, 0, nullptr, &dataSize);
if ( result != kAudioHardwareNoError if ( result != kAudioHardwareNoError
|| dataSize == 0) { || dataSize == 0) {
ATA_ERROR("airtaudio::api::Core::getDeviceInfo: system error (" << getErrorCode(result) << ") getting sample rate info."); ATA_ERROR("airtaudio::api::Core::getDeviceInfo: system error (" << getErrorCode(result) << ") getting sample rate info.");
@ -341,7 +341,7 @@ airtaudio::DeviceInfo airtaudio::api::Core::getDeviceInfo(uint32_t _device) {
} }
uint32_t nRanges = dataSize / sizeof(AudioValueRange); uint32_t nRanges = dataSize / sizeof(AudioValueRange);
AudioValueRange rangeList[ nRanges ]; AudioValueRange rangeList[ nRanges ];
result = AudioObjectGetPropertyData(id, &property, 0, NULL, &dataSize, &rangeList); result = AudioObjectGetPropertyData(id, &property, 0, nullptr, &dataSize, &rangeList);
if (result != kAudioHardwareNoError) { if (result != kAudioHardwareNoError) {
ATA_ERROR("airtaudio::api::Core::getDeviceInfo: system error (" << getErrorCode(result) << ") getting sample rates."); ATA_ERROR("airtaudio::api::Core::getDeviceInfo: system error (" << getErrorCode(result) << ") getting sample rates.");
return info; return info;
@ -427,7 +427,7 @@ static OSStatus rateListener(AudioObjectID _inDevice,
kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyScopeGlobal,
kAudioObjectPropertyElementMaster kAudioObjectPropertyElementMaster
}; };
AudioObjectGetPropertyData(_inDevice, &property, 0, NULL, &dataSize, rate); AudioObjectGetPropertyData(_inDevice, &property, 0, nullptr, &dataSize, rate);
return kAudioHardwareNoError; return kAudioHardwareNoError;
} }
@ -461,7 +461,7 @@ bool airtaudio::api::Core::probeDeviceOpen(uint32_t _device,
OSStatus result = AudioObjectGetPropertyData(kAudioObjectSystemObject, OSStatus result = AudioObjectGetPropertyData(kAudioObjectSystemObject,
&property, &property,
0, 0,
NULL, nullptr,
&dataSize, &dataSize,
(void *) &deviceList); (void *) &deviceList);
if (result != noErr) { if (result != noErr) {
@ -481,7 +481,7 @@ bool airtaudio::api::Core::probeDeviceOpen(uint32_t _device,
AudioBufferList *bufferList = nil; AudioBufferList *bufferList = nil;
dataSize = 0; dataSize = 0;
property.mSelector = kAudioDevicePropertyStreamConfiguration; property.mSelector = kAudioDevicePropertyStreamConfiguration;
result = AudioObjectGetPropertyDataSize(id, &property, 0, NULL, &dataSize); result = AudioObjectGetPropertyDataSize(id, &property, 0, nullptr, &dataSize);
if ( result != noErr if ( result != noErr
|| dataSize == 0) { || dataSize == 0) {
ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: system error (" << getErrorCode(result) << ") getting stream configuration info for device (" << _device << ")."); ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: system error (" << getErrorCode(result) << ") getting stream configuration info for device (" << _device << ").");
@ -489,11 +489,11 @@ bool airtaudio::api::Core::probeDeviceOpen(uint32_t _device,
} }
// Allocate the AudioBufferList. // Allocate the AudioBufferList.
bufferList = (AudioBufferList *) malloc(dataSize); bufferList = (AudioBufferList *) malloc(dataSize);
if (bufferList == NULL) { if (bufferList == nullptr) {
ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: memory error allocating AudioBufferList."); ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: memory error allocating AudioBufferList.");
return false; return false;
} }
result = AudioObjectGetPropertyData(id, &property, 0, NULL, &dataSize, bufferList); result = AudioObjectGetPropertyData(id, &property, 0, nullptr, &dataSize, bufferList);
if ( result != noErr if ( result != noErr
|| dataSize == 0) { || dataSize == 0) {
ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: system error (" << getErrorCode(result) << ") getting stream configuration for device (" << _device << ")."); ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: system error (" << getErrorCode(result) << ") getting stream configuration for device (" << _device << ").");
@ -569,7 +569,7 @@ bool airtaudio::api::Core::probeDeviceOpen(uint32_t _device,
AudioValueRange bufferRange; AudioValueRange bufferRange;
dataSize = sizeof(AudioValueRange); dataSize = sizeof(AudioValueRange);
property.mSelector = kAudioDevicePropertyBufferFrameSizeRange; property.mSelector = kAudioDevicePropertyBufferFrameSizeRange;
result = AudioObjectGetPropertyData(id, &property, 0, NULL, &dataSize, &bufferRange); result = AudioObjectGetPropertyData(id, &property, 0, nullptr, &dataSize, &bufferRange);
if (result != noErr) { if (result != noErr) {
ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: system error (" << getErrorCode(result) << ") getting buffer size range for device (" << _device << ")."); ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: system error (" << getErrorCode(result) << ") getting buffer size range for device (" << _device << ").");
return false; return false;
@ -579,7 +579,7 @@ bool airtaudio::api::Core::probeDeviceOpen(uint32_t _device,
} else if (bufferRange.mMaximum < *_bufferSize) { } else if (bufferRange.mMaximum < *_bufferSize) {
*_bufferSize = (uint64_t) bufferRange.mMaximum; *_bufferSize = (uint64_t) bufferRange.mMaximum;
} }
if ( _options != NULL if ( _options != nullptr
&& _options->flags & MINIMIZE_LATENCY) { && _options->flags & MINIMIZE_LATENCY) {
*_bufferSize = (uint64_t) bufferRange.mMinimum; *_bufferSize = (uint64_t) bufferRange.mMinimum;
} }
@ -588,7 +588,7 @@ bool airtaudio::api::Core::probeDeviceOpen(uint32_t _device,
uint32_t theSize = (uint32_t) *_bufferSize; uint32_t theSize = (uint32_t) *_bufferSize;
dataSize = sizeof(uint32_t); dataSize = sizeof(uint32_t);
property.mSelector = kAudioDevicePropertyBufferFrameSize; property.mSelector = kAudioDevicePropertyBufferFrameSize;
result = AudioObjectSetPropertyData(id, &property, 0, NULL, dataSize, &theSize); result = AudioObjectSetPropertyData(id, &property, 0, nullptr, dataSize, &theSize);
if (result != noErr) { if (result != noErr) {
ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: system error (" << getErrorCode(result) << ") setting the buffer size for device (" << _device << ")."); ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: system error (" << getErrorCode(result) << ") setting the buffer size for device (" << _device << ").");
return false; return false;
@ -605,19 +605,19 @@ bool airtaudio::api::Core::probeDeviceOpen(uint32_t _device,
m_stream.bufferSize = *_bufferSize; m_stream.bufferSize = *_bufferSize;
m_stream.nBuffers = 1; m_stream.nBuffers = 1;
// Try to set "hog" mode ... it's not clear to me this is working. // Try to set "hog" mode ... it's not clear to me this is working.
if ( _options != NULL if ( _options != nullptr
&& _options->flags & HOG_DEVICE) { && _options->flags & HOG_DEVICE) {
pid_t hog_pid; pid_t hog_pid;
dataSize = sizeof(hog_pid); dataSize = sizeof(hog_pid);
property.mSelector = kAudioDevicePropertyHogMode; property.mSelector = kAudioDevicePropertyHogMode;
result = AudioObjectGetPropertyData(id, &property, 0, NULL, &dataSize, &hog_pid); result = AudioObjectGetPropertyData(id, &property, 0, nullptr, &dataSize, &hog_pid);
if (result != noErr) { if (result != noErr) {
ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: system error (" << getErrorCode(result) << ") getting 'hog' state!"); ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: system error (" << getErrorCode(result) << ") getting 'hog' state!");
return false; return false;
} }
if (hog_pid != getpid()) { if (hog_pid != getpid()) {
hog_pid = getpid(); hog_pid = getpid();
result = AudioObjectSetPropertyData(id, &property, 0, NULL, dataSize, &hog_pid); result = AudioObjectSetPropertyData(id, &property, 0, nullptr, dataSize, &hog_pid);
if (result != noErr) { if (result != noErr) {
ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: system error (" << getErrorCode(result) << ") setting 'hog' state!"); ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: system error (" << getErrorCode(result) << ") setting 'hog' state!");
return false; return false;
@ -628,7 +628,7 @@ bool airtaudio::api::Core::probeDeviceOpen(uint32_t _device,
double nominalRate; double nominalRate;
dataSize = sizeof(double); dataSize = sizeof(double);
property.mSelector = kAudioDevicePropertyNominalSampleRate; property.mSelector = kAudioDevicePropertyNominalSampleRate;
result = AudioObjectGetPropertyData(id, &property, 0, NULL, &dataSize, &nominalRate); result = AudioObjectGetPropertyData(id, &property, 0, nullptr, &dataSize, &nominalRate);
if (result != noErr) { if (result != noErr) {
ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: system error (" << getErrorCode(result) << ") getting current sample rate."); ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: system error (" << getErrorCode(result) << ") getting current sample rate.");
return false; return false;
@ -644,7 +644,7 @@ bool airtaudio::api::Core::probeDeviceOpen(uint32_t _device,
return false; return false;
} }
nominalRate = (double) _sampleRate; nominalRate = (double) _sampleRate;
result = AudioObjectSetPropertyData(id, &property, 0, NULL, dataSize, &nominalRate); result = AudioObjectSetPropertyData(id, &property, 0, nullptr, dataSize, &nominalRate);
if (result != noErr) { if (result != noErr) {
ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: system error (" << getErrorCode(result) << ") setting sample rate for device (" << _device << ")."); ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: system error (" << getErrorCode(result) << ") setting sample rate for device (" << _device << ").");
return false; return false;
@ -670,7 +670,7 @@ bool airtaudio::api::Core::probeDeviceOpen(uint32_t _device,
AudioStreamBasicDescription description; AudioStreamBasicDescription description;
dataSize = sizeof(AudioStreamBasicDescription); dataSize = sizeof(AudioStreamBasicDescription);
property.mSelector = kAudioStreamPropertyVirtualFormat; property.mSelector = kAudioStreamPropertyVirtualFormat;
result = AudioObjectGetPropertyData(id, &property, 0, NULL, &dataSize, &description); result = AudioObjectGetPropertyData(id, &property, 0, nullptr, &dataSize, &description);
if (result != noErr) { if (result != noErr) {
ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: system error (" << getErrorCode(result) << ") getting stream format for device (" << _device << ")."); ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: system error (" << getErrorCode(result) << ") getting stream format for device (" << _device << ").");
return false; return false;
@ -688,7 +688,7 @@ bool airtaudio::api::Core::probeDeviceOpen(uint32_t _device,
updateFormat = true; updateFormat = true;
} }
if (updateFormat) { if (updateFormat) {
result = AudioObjectSetPropertyData(id, &property, 0, NULL, dataSize, &description); result = AudioObjectSetPropertyData(id, &property, 0, nullptr, dataSize, &description);
if (result != noErr) { if (result != noErr) {
ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: system error (" << getErrorCode(result) << ") setting sample rate or data format for device (" << _device << ")."); ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: system error (" << getErrorCode(result) << ") setting sample rate or data format for device (" << _device << ").");
return false; return false;
@ -696,7 +696,7 @@ bool airtaudio::api::Core::probeDeviceOpen(uint32_t _device,
} }
// Now check the physical format. // Now check the physical format.
property.mSelector = kAudioStreamPropertyPhysicalFormat; property.mSelector = kAudioStreamPropertyPhysicalFormat;
result = AudioObjectGetPropertyData(id, &property, 0, NULL, &dataSize, &description); result = AudioObjectGetPropertyData(id, &property, 0, nullptr, &dataSize, &description);
if (result != noErr) { if (result != noErr) {
ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: system error (" << getErrorCode(result) << ") getting stream physical format for device (" << _device << ")."); ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: system error (" << getErrorCode(result) << ") getting stream physical format for device (" << _device << ").");
return false; return false;
@ -738,7 +738,7 @@ bool airtaudio::api::Core::probeDeviceOpen(uint32_t _device,
testDescription.mBytesPerFrame = testDescription.mBitsPerChannel/8 * testDescription.mChannelsPerFrame; testDescription.mBytesPerFrame = testDescription.mBitsPerChannel/8 * testDescription.mChannelsPerFrame;
} }
testDescription.mBytesPerPacket = testDescription.mBytesPerFrame * testDescription.mFramesPerPacket; testDescription.mBytesPerPacket = testDescription.mBytesPerFrame * testDescription.mFramesPerPacket;
result = AudioObjectSetPropertyData(id, &property, 0, NULL, dataSize, &testDescription); result = AudioObjectSetPropertyData(id, &property, 0, nullptr, dataSize, &testDescription);
if (result == noErr) { if (result == noErr) {
setPhysicalFormat = true; setPhysicalFormat = true;
//std::cout << "Updated physical stream format:" << std::endl; //std::cout << "Updated physical stream format:" << std::endl;
@ -759,7 +759,7 @@ bool airtaudio::api::Core::probeDeviceOpen(uint32_t _device,
dataSize = sizeof(uint32_t); dataSize = sizeof(uint32_t);
property.mSelector = kAudioDevicePropertyLatency; property.mSelector = kAudioDevicePropertyLatency;
if (AudioObjectHasProperty(id, &property) == true) { if (AudioObjectHasProperty(id, &property) == true) {
result = AudioObjectGetPropertyData(id, &property, 0, NULL, &dataSize, &latency); result = AudioObjectGetPropertyData(id, &property, 0, nullptr, &dataSize, &latency);
if (result == kAudioHardwareNoError) { if (result == kAudioHardwareNoError) {
m_stream.latency[ _mode ] = latency; m_stream.latency[ _mode ] = latency;
} else { } else {
@ -783,7 +783,7 @@ bool airtaudio::api::Core::probeDeviceOpen(uint32_t _device,
} }
m_stream.nUserChannels[_mode] = _channels; m_stream.nUserChannels[_mode] = _channels;
m_stream.channelOffset[_mode] = channelOffset; // offset within a CoreAudio stream m_stream.channelOffset[_mode] = channelOffset; // offset within a CoreAudio stream
if ( _options != NULL if ( _options != nullptr
&& _options->flags & NONINTERLEAVED) { && _options->flags & NONINTERLEAVED) {
m_stream.userInterleaved = false; m_stream.userInterleaved = false;
} else { } else {
@ -813,7 +813,7 @@ bool airtaudio::api::Core::probeDeviceOpen(uint32_t _device,
CoreHandle *handle = 0; CoreHandle *handle = 0;
if (m_stream.apiHandle == 0) { if (m_stream.apiHandle == 0) {
handle = new CoreHandle; handle = new CoreHandle;
if (handle == NULL) { if (handle == nullptr) {
ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: error allocating CoreHandle memory."); ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: error allocating CoreHandle memory.");
return false; return false;
} }
@ -830,7 +830,7 @@ bool airtaudio::api::Core::probeDeviceOpen(uint32_t _device,
// m_stream.userBuffer[_mode] = (char *) calloc(bufferBytes, 1); // m_stream.userBuffer[_mode] = (char *) calloc(bufferBytes, 1);
m_stream.userBuffer[_mode] = (char *) malloc(bufferBytes * sizeof(char)); m_stream.userBuffer[_mode] = (char *) malloc(bufferBytes * sizeof(char));
memset(m_stream.userBuffer[_mode], 0, bufferBytes * sizeof(char)); memset(m_stream.userBuffer[_mode], 0, bufferBytes * sizeof(char));
if (m_stream.userBuffer[_mode] == NULL) { if (m_stream.userBuffer[_mode] == nullptr) {
ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: error allocating user buffer memory."); ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: error allocating user buffer memory.");
goto error; goto error;
} }
@ -854,10 +854,10 @@ bool airtaudio::api::Core::probeDeviceOpen(uint32_t _device,
bufferBytes *= *_bufferSize; bufferBytes *= *_bufferSize;
if (m_stream.deviceBuffer) { if (m_stream.deviceBuffer) {
free(m_stream.deviceBuffer); free(m_stream.deviceBuffer);
m_stream.deviceBuffer = NULL; m_stream.deviceBuffer = nullptr;
} }
m_stream.deviceBuffer = (char *) calloc(bufferBytes, 1); m_stream.deviceBuffer = (char *) calloc(bufferBytes, 1);
if (m_stream.deviceBuffer == NULL) { if (m_stream.deviceBuffer == nullptr) {
ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: error allocating device buffer memory."); ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: error allocating device buffer memory.");
goto error; goto error;
} }
@ -955,12 +955,12 @@ enum airtaudio::errorType airtaudio::api::Core::closeStream() {
for (int32_t i=0; i<2; i++) { for (int32_t i=0; i<2; i++) {
if (m_stream.userBuffer[i]) { if (m_stream.userBuffer[i]) {
free(m_stream.userBuffer[i]); free(m_stream.userBuffer[i]);
m_stream.userBuffer[i] = NULL; m_stream.userBuffer[i] = nullptr;
} }
} }
if (m_stream.deviceBuffer) { if (m_stream.deviceBuffer) {
free(m_stream.deviceBuffer); free(m_stream.deviceBuffer);
m_stream.deviceBuffer = NULL; m_stream.deviceBuffer = nullptr;
} }
delete handle; delete handle;
m_stream.apiHandle = 0; m_stream.apiHandle = 0;
@ -1099,7 +1099,6 @@ bool airtaudio::api::Core::callbackEvent(AudioDeviceID _deviceId,
// draining stream or duplex mode AND the input/output devices are // draining stream or duplex mode AND the input/output devices are
// different AND this function is called for the input device. // different AND this function is called for the input device.
if (handle->drainCounter == 0 && (m_stream.mode != DUPLEX || _deviceId == outputDevice)) { if (handle->drainCounter == 0 && (m_stream.mode != DUPLEX || _deviceId == outputDevice)) {
airtaudio::AirTAudioCallback callback = (airtaudio::AirTAudioCallback) info->callback;
double streamTime = getStreamTime(); double streamTime = getStreamTime();
airtaudio::streamStatus status = 0; airtaudio::streamStatus status = 0;
if ( m_stream.mode != INPUT if ( m_stream.mode != INPUT
@ -1112,12 +1111,11 @@ bool airtaudio::api::Core::callbackEvent(AudioDeviceID _deviceId,
status |= INPUT_OVERFLOW; status |= INPUT_OVERFLOW;
handle->xrun[1] = false; handle->xrun[1] = false;
} }
int32_t cbReturnValue = callback(m_stream.userBuffer[0], int32_t cbReturnValue = info->callback(m_stream.userBuffer[0],
m_stream.userBuffer[1], m_stream.userBuffer[1],
m_stream.bufferSize, m_stream.bufferSize,
streamTime, streamTime,
status, status);
info->userData);
if (cbReturnValue == 2) { if (cbReturnValue == 2) {
m_stream.state = STREAM_STOPPING; m_stream.state = STREAM_STOPPING;
handle->drainCounter = 2; handle->drainCounter = 2;

View File

@ -67,7 +67,7 @@ airtaudio::api::CoreIos::~CoreIos(void) {
ATA_INFO("Destroy CoreIOs interface"); ATA_INFO("Destroy CoreIOs interface");
AudioUnitUninitialize(m_private->audioUnit); AudioUnitUninitialize(m_private->audioUnit);
delete m_private; delete m_private;
m_private = NULL; m_private = nullptr;
} }
uint32_t airtaudio::api::CoreIos::getDeviceCount(void) { uint32_t airtaudio::api::CoreIos::getDeviceCount(void) {
@ -124,24 +124,21 @@ void airtaudio::api::CoreIos::callBackEvent(void* _data,
return; return;
#endif #endif
int32_t doStopStream = 0; int32_t doStopStream = 0;
airtaudio::AirTAudioCallback callback = (airtaudio::AirTAudioCallback) m_stream.callbackInfo.callback;
double streamTime = getStreamTime(); double streamTime = getStreamTime();
airtaudio::streamStatus status = 0; airtaudio::streamStatus status = 0;
if (m_stream.doConvertBuffer[OUTPUT] == true) { if (m_stream.doConvertBuffer[OUTPUT] == true) {
doStopStream = callback(m_stream.userBuffer[OUTPUT], doStopStream = m_stream.callbackInfo.callback(m_stream.userBuffer[OUTPUT],
NULL, nullptr,
_frameRate, _frameRate,
streamTime, streamTime,
status, status);
m_stream.callbackInfo.userData);
convertBuffer((char*)_data, (char*)m_stream.userBuffer[OUTPUT], m_stream.convertInfo[OUTPUT]); convertBuffer((char*)_data, (char*)m_stream.userBuffer[OUTPUT], m_stream.convertInfo[OUTPUT]);
} else { } else {
doStopStream = callback(_data, doStopStream = m_stream.callbackInfo.callback(_data,
NULL, nullptr,
_frameRate, _frameRate,
streamTime, streamTime,
status, status);
m_stream.callbackInfo.userData);
} }
if (doStopStream == 2) { if (doStopStream == 2) {
abortStream(); abortStream();
@ -156,8 +153,8 @@ static OSStatus playbackCallback(void *_userData,
uint32_t inBusNumber, uint32_t inBusNumber,
uint32_t inNumberFrames, uint32_t inNumberFrames,
AudioBufferList *ioData) { AudioBufferList *ioData) {
if (_userData == NULL) { if (_userData == nullptr) {
ATA_ERROR("callback event ... NULL pointer"); ATA_ERROR("callback event ... nullptr pointer");
return -1; return -1;
} }
airtaudio::api::CoreIos* myClass = static_cast<airtaudio::api::CoreIos*>(_userData); airtaudio::api::CoreIos* myClass = static_cast<airtaudio::api::CoreIos*>(_userData);
@ -214,7 +211,7 @@ bool airtaudio::api::CoreIos::probeDeviceOpen(uint32_t _device,
// Allocate necessary internal buffers. // Allocate necessary internal buffers.
uint64_t bufferBytes = m_stream.nUserChannels[_mode] * m_stream.bufferSize * formatBytes(m_stream.userFormat); uint64_t bufferBytes = m_stream.nUserChannels[_mode] * m_stream.bufferSize * formatBytes(m_stream.userFormat);
m_stream.userBuffer[_mode] = (char *) calloc(bufferBytes, 1); m_stream.userBuffer[_mode] = (char *) calloc(bufferBytes, 1);
if (m_stream.userBuffer[_mode] == NULL) { if (m_stream.userBuffer[_mode] == nullptr) {
ATA_ERROR("airtaudio::api::Android::probeDeviceOpen: error allocating user buffer memory."); ATA_ERROR("airtaudio::api::Android::probeDeviceOpen: error allocating user buffer memory.");
} }
setConvertInfo(_mode, _firstChannel); setConvertInfo(_mode, _firstChannel);
@ -238,7 +235,7 @@ bool airtaudio::api::CoreIos::probeDeviceOpen(uint32_t _device,
desc.componentManufacturer = kAudioUnitManufacturer_Apple; desc.componentManufacturer = kAudioUnitManufacturer_Apple;
// Get component // Get component
AudioComponent inputComponent = AudioComponentFindNext(NULL, &desc); AudioComponent inputComponent = AudioComponentFindNext(nullptr, &desc);
// Get audio units // Get audio units
status = AudioComponentInstanceNew(inputComponent, &m_private->audioUnit); status = AudioComponentInstanceNew(inputComponent, &m_private->audioUnit);

View File

@ -113,7 +113,7 @@ airtaudio::api::Ds::Ds() {
// Dsound will run both-threaded. If CoInitialize fails, then just // Dsound will run both-threaded. If CoInitialize fails, then just
// accept whatever the mainline chose for a threading model. // accept whatever the mainline chose for a threading model.
m_coInitialized = false; m_coInitialized = false;
HRESULT hr = CoInitialize(NULL); HRESULT hr = CoInitialize(nullptr);
if (!FAILED(hr)) { if (!FAILED(hr)) {
m_coInitialized = true; m_coInitialized = true;
} }
@ -196,7 +196,7 @@ rtaudio::DeviceInfo airtaudio::api::Ds::getDeviceInfo(uint32_t _device) {
} }
LPDIRECTSOUND output; LPDIRECTSOUND output;
DSCAPS outCaps; DSCAPS outCaps;
result = DirectSoundCreate(dsDevices[ _device ].id[0], &output, NULL); result = DirectSoundCreate(dsDevices[ _device ].id[0], &output, nullptr);
if (FAILED(result)) { if (FAILED(result)) {
ATA_ERROR("airtaudio::api::Ds::getDeviceInfo: error (" << getErrorString(result) << ") opening output device (" << dsDevices[ _device ].name << ")!"); ATA_ERROR("airtaudio::api::Ds::getDeviceInfo: error (" << getErrorString(result) << ") opening output device (" << dsDevices[ _device ].name << ")!");
goto probeInput; goto probeInput;
@ -236,7 +236,7 @@ rtaudio::DeviceInfo airtaudio::api::Ds::getDeviceInfo(uint32_t _device) {
} }
probeInput: probeInput:
LPDIRECTSOUNDCAPTURE input; LPDIRECTSOUNDCAPTURE input;
result = DirectSoundCaptureCreate(dsDevices[ _device ].id[1], &input, NULL); result = DirectSoundCaptureCreate(dsDevices[ _device ].id[1], &input, nullptr);
if (FAILED(result)) { if (FAILED(result)) {
ATA_ERROR("airtaudio::api::Ds::getDeviceInfo: error (" << getErrorString(result) << ") opening input device (" << dsDevices[ _device ].name << ")!"); ATA_ERROR("airtaudio::api::Ds::getDeviceInfo: error (" << getErrorString(result) << ") opening input device (" << dsDevices[ _device ].name << ")!");
return info; return info;
@ -438,10 +438,10 @@ bool airtaudio::api::Ds::probeDeviceOpen(uint32_t _device,
// two. This is a judgement call and a value of two is probably too // two. This is a judgement call and a value of two is probably too
// low for capture, but it should work for playback. // low for capture, but it should work for playback.
int32_t nBuffers = 0; int32_t nBuffers = 0;
if (_options != NULL) { if (_options != nullptr) {
nBuffers = _options->numberOfBuffers; nBuffers = _options->numberOfBuffers;
} }
if ( _options!= NULL if ( _options!= nullptr
&& _options->flags & RTAUDIO_MINIMIZE_LATENCY) { && _options->flags & RTAUDIO_MINIMIZE_LATENCY) {
nBuffers = 2; nBuffers = 2;
} }
@ -469,7 +469,7 @@ bool airtaudio::api::Ds::probeDeviceOpen(uint32_t _device,
HRESULT result; HRESULT result;
if (_mode == OUTPUT) { if (_mode == OUTPUT) {
LPDIRECTSOUND output; LPDIRECTSOUND output;
result = DirectSoundCreate(dsDevices[ _device ].id[0], &output, NULL); result = DirectSoundCreate(dsDevices[ _device ].id[0], &output, nullptr);
if (FAILED(result)) { if (FAILED(result)) {
ATA_ERROR("airtaudio::api::Ds::probeDeviceOpen: error (" << getErrorString(result) << ") opening output device (" << dsDevices[ _device ].name << ")!"); ATA_ERROR("airtaudio::api::Ds::probeDeviceOpen: error (" << getErrorString(result) << ") opening output device (" << dsDevices[ _device ].name << ")!");
return false; return false;
@ -526,7 +526,7 @@ bool airtaudio::api::Ds::probeDeviceOpen(uint32_t _device,
bufferDescription.dwFlags = DSBCAPS_PRIMARYBUFFER; bufferDescription.dwFlags = DSBCAPS_PRIMARYBUFFER;
// Obtain the primary buffer // Obtain the primary buffer
LPDIRECTSOUNDBUFFER buffer; LPDIRECTSOUNDBUFFER buffer;
result = output->CreateSoundBuffer(&bufferDescription, &buffer, NULL); result = output->CreateSoundBuffer(&bufferDescription, &buffer, nullptr);
if (FAILED(result)) { if (FAILED(result)) {
output->Release(); output->Release();
ATA_ERROR("airtaudio::api::Ds::probeDeviceOpen: error (" << getErrorString(result) << ") accessing primary buffer (" << dsDevices[ _device ].name << ")!"); ATA_ERROR("airtaudio::api::Ds::probeDeviceOpen: error (" << getErrorString(result) << ") accessing primary buffer (" << dsDevices[ _device ].name << ")!");
@ -550,13 +550,13 @@ bool airtaudio::api::Ds::probeDeviceOpen(uint32_t _device,
bufferDescription.lpwfxFormat = &waveFormat; bufferDescription.lpwfxFormat = &waveFormat;
// Try to create the secondary DS buffer. If that doesn't work, // Try to create the secondary DS buffer. If that doesn't work,
// try to use software mixing. Otherwise, there's a problem. // try to use software mixing. Otherwise, there's a problem.
result = output->CreateSoundBuffer(&bufferDescription, &buffer, NULL); result = output->CreateSoundBuffer(&bufferDescription, &buffer, nullptr);
if (FAILED(result)) { if (FAILED(result)) {
bufferDescription.dwFlags = ( DSBCAPS_STICKYFOCUS bufferDescription.dwFlags = ( DSBCAPS_STICKYFOCUS
| DSBCAPS_GLOBALFOCUS | DSBCAPS_GLOBALFOCUS
| DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GETCURRENTPOSITION2
| DSBCAPS_LOCSOFTWARE); // Force software mixing | DSBCAPS_LOCSOFTWARE); // Force software mixing
result = output->CreateSoundBuffer(&bufferDescription, &buffer, NULL); result = output->CreateSoundBuffer(&bufferDescription, &buffer, nullptr);
if (FAILED(result)) { if (FAILED(result)) {
output->Release(); output->Release();
ATA_ERROR("airtaudio::api::Ds::probeDeviceOpen: error (" << getErrorString(result) << ") creating secondary buffer (" << dsDevices[ _device ].name << ")!"); ATA_ERROR("airtaudio::api::Ds::probeDeviceOpen: error (" << getErrorString(result) << ") creating secondary buffer (" << dsDevices[ _device ].name << ")!");
@ -577,7 +577,7 @@ bool airtaudio::api::Ds::probeDeviceOpen(uint32_t _device,
// Lock the DS buffer // Lock the DS buffer
LPVOID audioPtr; LPVOID audioPtr;
DWORD dataLen; DWORD dataLen;
result = buffer->Lock(0, dsBufferSize, &audioPtr, &dataLen, NULL, NULL, 0); result = buffer->Lock(0, dsBufferSize, &audioPtr, &dataLen, nullptr, nullptr, 0);
if (FAILED(result)) { if (FAILED(result)) {
output->Release(); output->Release();
buffer->Release(); buffer->Release();
@ -587,7 +587,7 @@ bool airtaudio::api::Ds::probeDeviceOpen(uint32_t _device,
// Zero the DS buffer // Zero the DS buffer
ZeroMemory(audioPtr, dataLen); ZeroMemory(audioPtr, dataLen);
// Unlock the DS buffer // Unlock the DS buffer
result = buffer->Unlock(audioPtr, dataLen, NULL, 0); result = buffer->Unlock(audioPtr, dataLen, nullptr, 0);
if (FAILED(result)) { if (FAILED(result)) {
output->Release(); output->Release();
buffer->Release(); buffer->Release();
@ -599,7 +599,7 @@ bool airtaudio::api::Ds::probeDeviceOpen(uint32_t _device,
} }
if (_mode == INPUT) { if (_mode == INPUT) {
LPDIRECTSOUNDCAPTURE input; LPDIRECTSOUNDCAPTURE input;
result = DirectSoundCaptureCreate(dsDevices[ _device ].id[1], &input, NULL); result = DirectSoundCaptureCreate(dsDevices[ _device ].id[1], &input, nullptr);
if (FAILED(result)) { if (FAILED(result)) {
ATA_ERROR("airtaudio::api::Ds::probeDeviceOpen: error (" << getErrorString(result) << ") opening input device (" << dsDevices[ _device ].name << ")!"); ATA_ERROR("airtaudio::api::Ds::probeDeviceOpen: error (" << getErrorString(result) << ") opening input device (" << dsDevices[ _device ].name << ")!");
return false; return false;
@ -659,7 +659,7 @@ bool airtaudio::api::Ds::probeDeviceOpen(uint32_t _device,
bufferDescription.lpwfxFormat = &waveFormat; bufferDescription.lpwfxFormat = &waveFormat;
// Create the capture buffer. // Create the capture buffer.
LPDIRECTSOUNDCAPTUREBUFFER buffer; LPDIRECTSOUNDCAPTUREBUFFER buffer;
result = input->CreateCaptureBuffer(&bufferDescription, &buffer, NULL); result = input->CreateCaptureBuffer(&bufferDescription, &buffer, nullptr);
if (FAILED(result)) { if (FAILED(result)) {
input->Release(); input->Release();
ATA_ERROR("airtaudio::api::Ds::probeDeviceOpen: error (" << getErrorString(result) << ") creating input buffer (" << dsDevices[ _device ].name << ")!"); ATA_ERROR("airtaudio::api::Ds::probeDeviceOpen: error (" << getErrorString(result) << ") creating input buffer (" << dsDevices[ _device ].name << ")!");
@ -683,7 +683,7 @@ bool airtaudio::api::Ds::probeDeviceOpen(uint32_t _device,
// Lock the capture buffer // Lock the capture buffer
LPVOID audioPtr; LPVOID audioPtr;
DWORD dataLen; DWORD dataLen;
result = buffer->Lock(0, dsBufferSize, &audioPtr, &dataLen, NULL, NULL, 0); result = buffer->Lock(0, dsBufferSize, &audioPtr, &dataLen, nullptr, nullptr, 0);
if (FAILED(result)) { if (FAILED(result)) {
input->Release(); input->Release();
buffer->Release(); buffer->Release();
@ -693,7 +693,7 @@ bool airtaudio::api::Ds::probeDeviceOpen(uint32_t _device,
// Zero the buffer // Zero the buffer
ZeroMemory(audioPtr, dataLen); ZeroMemory(audioPtr, dataLen);
// Unlock the buffer // Unlock the buffer
result = buffer->Unlock(audioPtr, dataLen, NULL, 0); result = buffer->Unlock(audioPtr, dataLen, nullptr, 0);
if (FAILED(result)) { if (FAILED(result)) {
input->Release(); input->Release();
buffer->Release(); buffer->Release();
@ -710,7 +710,7 @@ bool airtaudio::api::Ds::probeDeviceOpen(uint32_t _device,
m_stream.bufferSize = *_bufferSize; m_stream.bufferSize = *_bufferSize;
m_stream.channelOffset[_mode] = _firstChannel; m_stream.channelOffset[_mode] = _firstChannel;
m_stream.deviceInterleaved[_mode] = true; m_stream.deviceInterleaved[_mode] = true;
if ( _options != NULL if ( _options != nullptr
&& _options->flags & RTAUDIO_NONINTERLEAVED) { && _options->flags & RTAUDIO_NONINTERLEAVED) {
m_stream.userInterleaved = false; m_stream.userInterleaved = false;
} else { } else {
@ -731,7 +731,7 @@ bool airtaudio::api::Ds::probeDeviceOpen(uint32_t _device,
// Allocate necessary internal buffers // Allocate necessary internal buffers
long bufferBytes = m_stream.nUserChannels[_mode] * *_bufferSize * formatBytes(m_stream.userFormat); long bufferBytes = m_stream.nUserChannels[_mode] * *_bufferSize * formatBytes(m_stream.userFormat);
m_stream.userBuffer[_mode] = (char *) calloc(bufferBytes, 1); m_stream.userBuffer[_mode] = (char *) calloc(bufferBytes, 1);
if (m_stream.userBuffer[_mode] == NULL) { if (m_stream.userBuffer[_mode] == nullptr) {
ATA_ERROR("airtaudio::api::Ds::probeDeviceOpen: error allocating user buffer memory."); ATA_ERROR("airtaudio::api::Ds::probeDeviceOpen: error allocating user buffer memory.");
goto error; goto error;
} }
@ -752,7 +752,7 @@ bool airtaudio::api::Ds::probeDeviceOpen(uint32_t _device,
free(m_stream.deviceBuffer); free(m_stream.deviceBuffer);
} }
m_stream.deviceBuffer = (char *) calloc(bufferBytes, 1); m_stream.deviceBuffer = (char *) calloc(bufferBytes, 1);
if (m_stream.deviceBuffer == NULL) { if (m_stream.deviceBuffer == nullptr) {
ATA_ERROR("airtaudio::api::Ds::probeDeviceOpen: error allocating device buffer memory."); ATA_ERROR("airtaudio::api::Ds::probeDeviceOpen: error allocating device buffer memory.");
goto error; goto error;
} }
@ -761,15 +761,15 @@ bool airtaudio::api::Ds::probeDeviceOpen(uint32_t _device,
// Allocate our DsHandle structures for the stream. // Allocate our DsHandle structures for the stream.
if (m_stream.apiHandle == 0) { if (m_stream.apiHandle == 0) {
handle = new DsHandle; handle = new DsHandle;
if (handle == NULL) { if (handle == nullptr) {
ATA_ERROR("airtaudio::api::Ds::probeDeviceOpen: error allocating AsioHandle memory."); ATA_ERROR("airtaudio::api::Ds::probeDeviceOpen: error allocating AsioHandle memory.");
goto error; goto error;
} }
// Create a manual-reset event. // Create a manual-reset event.
handle->condition = CreateEvent(NULL, // no security handle->condition = CreateEvent(nullptr, // no security
TRUE, // manual-reset TRUE, // manual-reset
FALSE, // non-signaled initially FALSE, // non-signaled initially
NULL); // unnamed nullptr); // unnamed
m_stream.apiHandle = (void *) handle; m_stream.apiHandle = (void *) handle;
} else { } else {
handle = (DsHandle *) m_stream.apiHandle; handle = (DsHandle *) m_stream.apiHandle;
@ -798,7 +798,7 @@ bool airtaudio::api::Ds::probeDeviceOpen(uint32_t _device,
unsigned threadId; unsigned threadId;
m_stream.callbackInfo.isRunning = true; m_stream.callbackInfo.isRunning = true;
m_stream.callbackInfo.object = (void *) this; m_stream.callbackInfo.object = (void *) this;
m_stream.callbackInfo.thread = _beginthreadex(NULL, m_stream.callbackInfo.thread = _beginthreadex(nullptr,
0, 0,
&callbackHandler, &callbackHandler,
&m_stream.callbackInfo, &m_stream.callbackInfo,
@ -815,7 +815,7 @@ bool airtaudio::api::Ds::probeDeviceOpen(uint32_t _device,
error: error:
if (handle) { if (handle) {
if (handle->buffer[0]) { if (handle->buffer[0]) {
// the object pointer can be NULL and valid // the object pointer can be nullptr and valid
LPDIRECTSOUND object = (LPDIRECTSOUND) handle->id[0]; LPDIRECTSOUND object = (LPDIRECTSOUND) handle->id[0];
LPDIRECTSOUNDBUFFER buffer = (LPDIRECTSOUNDBUFFER) handle->buffer[0]; LPDIRECTSOUNDBUFFER buffer = (LPDIRECTSOUNDBUFFER) handle->buffer[0];
if (buffer) { if (buffer) {
@ -826,7 +826,7 @@ error:
if (handle->buffer[1]) { if (handle->buffer[1]) {
LPDIRECTSOUNDCAPTURE object = (LPDIRECTSOUNDCAPTURE) handle->id[1]; LPDIRECTSOUNDCAPTURE object = (LPDIRECTSOUNDCAPTURE) handle->id[1];
LPDIRECTSOUNDCAPTUREBUFFER buffer = (LPDIRECTSOUNDCAPTUREBUFFER) handle->buffer[1]; LPDIRECTSOUNDCAPTUREBUFFER buffer = (LPDIRECTSOUNDCAPTUREBUFFER) handle->buffer[1];
if (buffer != NULL) { if (buffer != nullptr) {
buffer->Release(); buffer->Release();
} }
} }
@ -859,7 +859,7 @@ enum airtaudio::errorType airtaudio::api::Ds::closeStream() {
CloseHandle((HANDLE) m_stream.callbackInfo.thread); CloseHandle((HANDLE) m_stream.callbackInfo.thread);
DsHandle *handle = (DsHandle *) m_stream.apiHandle; DsHandle *handle = (DsHandle *) m_stream.apiHandle;
if (handle) { if (handle) {
if (handle->buffer[0]) { // the object pointer can be NULL and valid if (handle->buffer[0]) { // the object pointer can be nullptr and valid
LPDIRECTSOUND object = (LPDIRECTSOUND) handle->id[0]; LPDIRECTSOUND object = (LPDIRECTSOUND) handle->id[0];
LPDIRECTSOUNDBUFFER buffer = (LPDIRECTSOUNDBUFFER) handle->buffer[0]; LPDIRECTSOUNDBUFFER buffer = (LPDIRECTSOUNDBUFFER) handle->buffer[0];
if (buffer) { if (buffer) {
@ -972,7 +972,7 @@ enum airtaudio::errorType airtaudio::api::Ds::stopStream() {
} }
// Lock the buffer and clear it so that if we start to play again, // Lock the buffer and clear it so that if we start to play again,
// we won't have old data playing. // we won't have old data playing.
result = buffer->Lock(0, handle->dsBufferSize[0], &audioPtr, &dataLen, NULL, NULL, 0); result = buffer->Lock(0, handle->dsBufferSize[0], &audioPtr, &dataLen, nullptr, nullptr, 0);
if (FAILED(result)) { if (FAILED(result)) {
ATA_ERROR("airtaudio::api::Ds::stopStream: error (" << getErrorString(result) << ") locking output buffer!"); ATA_ERROR("airtaudio::api::Ds::stopStream: error (" << getErrorString(result) << ") locking output buffer!");
goto unlock; goto unlock;
@ -980,7 +980,7 @@ enum airtaudio::errorType airtaudio::api::Ds::stopStream() {
// Zero the DS buffer // Zero the DS buffer
ZeroMemory(audioPtr, dataLen); ZeroMemory(audioPtr, dataLen);
// Unlock the DS buffer // Unlock the DS buffer
result = buffer->Unlock(audioPtr, dataLen, NULL, 0); result = buffer->Unlock(audioPtr, dataLen, nullptr, 0);
if (FAILED(result)) { if (FAILED(result)) {
ATA_ERROR("airtaudio::api::Ds::stopStream: error (" << getErrorString(result) << ") unlocking output buffer!"); ATA_ERROR("airtaudio::api::Ds::stopStream: error (" << getErrorString(result) << ") unlocking output buffer!");
goto unlock; goto unlock;
@ -991,7 +991,7 @@ enum airtaudio::errorType airtaudio::api::Ds::stopStream() {
if ( m_stream.mode == INPUT if ( m_stream.mode == INPUT
|| m_stream.mode == DUPLEX) { || m_stream.mode == DUPLEX) {
LPDIRECTSOUNDCAPTUREBUFFER buffer = (LPDIRECTSOUNDCAPTUREBUFFER) handle->buffer[1]; LPDIRECTSOUNDCAPTUREBUFFER buffer = (LPDIRECTSOUNDCAPTUREBUFFER) handle->buffer[1];
audioPtr = NULL; audioPtr = nullptr;
dataLen = 0; dataLen = 0;
m_stream.state = STREAM_STOPPED; m_stream.state = STREAM_STOPPED;
result = buffer->Stop(); result = buffer->Stop();
@ -1001,7 +1001,7 @@ enum airtaudio::errorType airtaudio::api::Ds::stopStream() {
} }
// Lock the buffer and clear it so that if we start to play again, // Lock the buffer and clear it so that if we start to play again,
// we won't have old data playing. // we won't have old data playing.
result = buffer->Lock(0, handle->dsBufferSize[1], &audioPtr, &dataLen, NULL, NULL, 0); result = buffer->Lock(0, handle->dsBufferSize[1], &audioPtr, &dataLen, nullptr, nullptr, 0);
if (FAILED(result)) { if (FAILED(result)) {
ATA_ERROR("airtaudio::api::Ds::stopStream: error (" << getErrorString(result) << ") locking input buffer!"); ATA_ERROR("airtaudio::api::Ds::stopStream: error (" << getErrorString(result) << ") locking input buffer!");
goto unlock; goto unlock;
@ -1009,7 +1009,7 @@ enum airtaudio::errorType airtaudio::api::Ds::stopStream() {
// Zero the DS buffer // Zero the DS buffer
ZeroMemory(audioPtr, dataLen); ZeroMemory(audioPtr, dataLen);
// Unlock the DS buffer // Unlock the DS buffer
result = buffer->Unlock(audioPtr, dataLen, NULL, 0); result = buffer->Unlock(audioPtr, dataLen, nullptr, 0);
if (FAILED(result)) { if (FAILED(result)) {
ATA_ERROR("airtaudio::api::Ds::stopStream: error (" << getErrorString(result) << ") unlocking input buffer!"); ATA_ERROR("airtaudio::api::Ds::stopStream: error (" << getErrorString(result) << ") unlocking input buffer!");
goto unlock; goto unlock;
@ -1062,7 +1062,6 @@ void airtaudio::api::Ds::callbackEvent() {
// Invoke user callback to get fresh output data UNLESS we are // Invoke user callback to get fresh output data UNLESS we are
// draining stream. // draining stream.
if (handle->drainCounter == 0) { if (handle->drainCounter == 0) {
airtaudio::AirTAudioCallback callback = (airtaudio::AirTAudioCallback) info->callback;
double streamTime = getStreamTime(); double streamTime = getStreamTime();
rtaudio::streamStatus status = 0; rtaudio::streamStatus status = 0;
if ( m_stream.mode != INPUT if ( m_stream.mode != INPUT
@ -1075,12 +1074,11 @@ void airtaudio::api::Ds::callbackEvent() {
status |= RTAUDIO_INPUT_OVERFLOW; status |= RTAUDIO_INPUT_OVERFLOW;
handle->xrun[1] = false; handle->xrun[1] = false;
} }
int32_t cbReturnValue = callback(m_stream.userBuffer[0], int32_t cbReturnValue = info->callback(m_stream.userBuffer[0],
m_stream.userBuffer[1], m_stream.userBuffer[1],
m_stream.bufferSize, m_stream.bufferSize,
streamTime, streamTime,
status, status);
info->userData);
if (cbReturnValue == 2) { if (cbReturnValue == 2) {
m_stream.state = STREAM_STOPPING; m_stream.state = STREAM_STOPPING;
handle->drainCounter = 2; handle->drainCounter = 2;
@ -1095,8 +1093,8 @@ void airtaudio::api::Ds::callbackEvent() {
DWORD currentWritePointer, safeWritePointer; DWORD currentWritePointer, safeWritePointer;
DWORD currentReadPointer, safeReadPointer; DWORD currentReadPointer, safeReadPointer;
UINT nextWritePointer; UINT nextWritePointer;
LPVOID buffer1 = NULL; LPVOID buffer1 = nullptr;
LPVOID buffer2 = NULL; LPVOID buffer2 = nullptr;
DWORD bufferSize1 = 0; DWORD bufferSize1 = 0;
DWORD bufferSize2 = 0; DWORD bufferSize2 = 0;
char *buffer; char *buffer;
@ -1119,23 +1117,23 @@ void airtaudio::api::Ds::callbackEvent() {
LPDIRECTSOUNDBUFFER dsWriteBuffer = (LPDIRECTSOUNDBUFFER) handle->buffer[0]; LPDIRECTSOUNDBUFFER dsWriteBuffer = (LPDIRECTSOUNDBUFFER) handle->buffer[0];
LPDIRECTSOUNDCAPTUREBUFFER dsCaptureBuffer = (LPDIRECTSOUNDCAPTUREBUFFER) handle->buffer[1]; LPDIRECTSOUNDCAPTUREBUFFER dsCaptureBuffer = (LPDIRECTSOUNDCAPTUREBUFFER) handle->buffer[1];
DWORD startSafeWritePointer, startSafeReadPointer; DWORD startSafeWritePointer, startSafeReadPointer;
result = dsWriteBuffer->GetCurrentPosition(NULL, &startSafeWritePointer); result = dsWriteBuffer->GetCurrentPosition(nullptr, &startSafeWritePointer);
if (FAILED(result)) { if (FAILED(result)) {
ATA_ERROR("airtaudio::api::Ds::callbackEvent: error (" << getErrorString(result) << ") getting current write position!"); ATA_ERROR("airtaudio::api::Ds::callbackEvent: error (" << getErrorString(result) << ") getting current write position!");
return; return;
} }
result = dsCaptureBuffer->GetCurrentPosition(NULL, &startSafeReadPointer); result = dsCaptureBuffer->GetCurrentPosition(nullptr, &startSafeReadPointer);
if (FAILED(result)) { if (FAILED(result)) {
ATA_ERROR("airtaudio::api::Ds::callbackEvent: error (" << getErrorString(result) << ") getting current read position!"); ATA_ERROR("airtaudio::api::Ds::callbackEvent: error (" << getErrorString(result) << ") getting current read position!");
return; return;
} }
while (true) { while (true) {
result = dsWriteBuffer->GetCurrentPosition(NULL, &safeWritePointer); result = dsWriteBuffer->GetCurrentPosition(nullptr, &safeWritePointer);
if (FAILED(result)) { if (FAILED(result)) {
ATA_ERROR("airtaudio::api::Ds::callbackEvent: error (" << getErrorString(result) << ") getting current write position!"); ATA_ERROR("airtaudio::api::Ds::callbackEvent: error (" << getErrorString(result) << ") getting current write position!");
return; return;
} }
result = dsCaptureBuffer->GetCurrentPosition(NULL, &safeReadPointer); result = dsCaptureBuffer->GetCurrentPosition(nullptr, &safeReadPointer);
if (FAILED(result)) { if (FAILED(result)) {
ATA_ERROR("airtaudio::api::Ds::callbackEvent: error (" << getErrorString(result) << ") getting current read position!"); ATA_ERROR("airtaudio::api::Ds::callbackEvent: error (" << getErrorString(result) << ") getting current read position!");
return; return;
@ -1256,7 +1254,7 @@ void airtaudio::api::Ds::callbackEvent() {
} }
// Copy our buffer into the DS buffer // Copy our buffer into the DS buffer
CopyMemory(buffer1, buffer, bufferSize1); CopyMemory(buffer1, buffer, bufferSize1);
if (buffer2 != NULL) { if (buffer2 != nullptr) {
CopyMemory(buffer2, buffer+bufferSize1, bufferSize2); CopyMemory(buffer2, buffer+bufferSize1, bufferSize2);
} }
// Update our buffer offset and unlock sound buffer // Update our buffer offset and unlock sound buffer
@ -1374,12 +1372,12 @@ void airtaudio::api::Ds::callbackEvent() {
if (m_duplexPrerollBytes <= 0) { if (m_duplexPrerollBytes <= 0) {
// Copy our buffer into the DS buffer // Copy our buffer into the DS buffer
CopyMemory(buffer, buffer1, bufferSize1); CopyMemory(buffer, buffer1, bufferSize1);
if (buffer2 != NULL) { if (buffer2 != nullptr) {
CopyMemory(buffer+bufferSize1, buffer2, bufferSize2); CopyMemory(buffer+bufferSize1, buffer2, bufferSize2);
} }
} else { } else {
memset(buffer, 0, bufferSize1); memset(buffer, 0, bufferSize1);
if (buffer2 != NULL) { if (buffer2 != nullptr) {
memset(buffer + bufferSize1, 0, bufferSize2); memset(buffer + bufferSize1, 0, bufferSize2);
} }
m_duplexPrerollBytes -= bufferSize1 + bufferSize2; m_duplexPrerollBytes -= bufferSize1 + bufferSize2;
@ -1424,9 +1422,9 @@ static unsigned __stdcall callbackHandler(void *_ptr) {
#include "tchar.h" #include "tchar.h"
static std::string convertTChar(LPCTSTR _name) { static std::string convertTChar(LPCTSTR _name) {
#if defined(UNICODE) || defined(_UNICODE) #if defined(UNICODE) || defined(_UNICODE)
int32_t length = WideCharToMultiByte(CP_UTF8, 0, _name, -1, NULL, 0, NULL, NULL); int32_t length = WideCharToMultiByte(CP_UTF8, 0, _name, -1, nullptr, 0, nullptr, nullptr);
std::string s(length-1, '\0'); std::string s(length-1, '\0');
WideCharToMultiByte(CP_UTF8, 0, _name, -1, &s[0], length, NULL, NULL); WideCharToMultiByte(CP_UTF8, 0, _name, -1, &s[0], length, nullptr, nullptr);
#else #else
std::string s(_name); std::string s(_name);
#endif #endif
@ -1444,7 +1442,7 @@ static BOOL CALLBACK deviceQueryCallback(LPGUID _lpguid,
if (probeInfo.isInput == true) { if (probeInfo.isInput == true) {
DSCCAPS caps; DSCCAPS caps;
LPDIRECTSOUNDCAPTURE object; LPDIRECTSOUNDCAPTURE object;
hr = DirectSoundCaptureCreate(_lpguid, &object, NULL); hr = DirectSoundCaptureCreate(_lpguid, &object, nullptr);
if (hr != DS_OK) { if (hr != DS_OK) {
return TRUE; return TRUE;
} }
@ -1459,7 +1457,7 @@ static BOOL CALLBACK deviceQueryCallback(LPGUID _lpguid,
} else { } else {
DSCAPS caps; DSCAPS caps;
LPDIRECTSOUND object; LPDIRECTSOUND object;
hr = DirectSoundCreate(_lpguid, &object, NULL); hr = DirectSoundCreate(_lpguid, &object, nullptr);
if (hr != DS_OK) { if (hr != DS_OK) {
return TRUE; return TRUE;
} }
@ -1476,7 +1474,7 @@ static BOOL CALLBACK deviceQueryCallback(LPGUID _lpguid,
// If good device, then save its name and guid. // If good device, then save its name and guid.
std::string name = convertTChar(_description); std::string name = convertTChar(_description);
//if (name == "Primary Sound Driver" || name == "Primary Sound Capture Driver") //if (name == "Primary Sound Driver" || name == "Primary Sound Capture Driver")
if (_lpguid == NULL) { if (_lpguid == nullptr) {
name = "Default Device"; name = "Default Device";
} }
if (validDevice) { if (validDevice) {

View File

@ -88,15 +88,15 @@ airtaudio::api::Jack::~Jack() {
uint32_t airtaudio::api::Jack::getDeviceCount() { uint32_t airtaudio::api::Jack::getDeviceCount() {
// See if we can become a jack client. // See if we can become a jack client.
jack_options_t options = (jack_options_t) (JackNoStartServer); //JackNullOption; jack_options_t options = (jack_options_t) (JackNoStartServer); //JackNullOption;
jack_status_t *status = NULL; jack_status_t *status = nullptr;
jack_client_t *client = jack_client_open("RtApiJackCount", options, status); jack_client_t *client = jack_client_open("RtApiJackCount", options, status);
if (client == NULL) { if (client == nullptr) {
return 0; return 0;
} }
const char **ports; const char **ports;
std::string port, previousPort; std::string port, previousPort;
uint32_t nChannels = 0, nDevices = 0; uint32_t nChannels = 0, nDevices = 0;
ports = jack_get_ports(client, NULL, NULL, 0); ports = jack_get_ports(client, nullptr, nullptr, 0);
if (ports) { if (ports) {
// Parse the port names up to the first colon (:). // Parse the port names up to the first colon (:).
size_t iColon = 0; size_t iColon = 0;
@ -121,9 +121,9 @@ airtaudio::DeviceInfo airtaudio::api::Jack::getDeviceInfo(uint32_t _device) {
airtaudio::DeviceInfo info; airtaudio::DeviceInfo info;
info.probed = false; info.probed = false;
jack_options_t options = (jack_options_t) (JackNoStartServer); //JackNullOption jack_options_t options = (jack_options_t) (JackNoStartServer); //JackNullOption
jack_status_t *status = NULL; jack_status_t *status = nullptr;
jack_client_t *client = jack_client_open("RtApiJackInfo", options, status); jack_client_t *client = jack_client_open("RtApiJackInfo", options, status);
if (client == NULL) { if (client == nullptr) {
ATA_ERROR("airtaudio::api::Jack::getDeviceInfo: Jack server not found or connection error!"); ATA_ERROR("airtaudio::api::Jack::getDeviceInfo: Jack server not found or connection error!");
// TODO : airtaudio::errorWarning; // TODO : airtaudio::errorWarning;
return info; return info;
@ -131,7 +131,7 @@ airtaudio::DeviceInfo airtaudio::api::Jack::getDeviceInfo(uint32_t _device) {
const char **ports; const char **ports;
std::string port, previousPort; std::string port, previousPort;
uint32_t nPorts = 0, nDevices = 0; uint32_t nPorts = 0, nDevices = 0;
ports = jack_get_ports(client, NULL, NULL, 0); ports = jack_get_ports(client, nullptr, nullptr, 0);
if (ports) { if (ports) {
// Parse the port names up to the first colon (:). // Parse the port names up to the first colon (:).
size_t iColon = 0; size_t iColon = 0;
@ -163,7 +163,7 @@ airtaudio::DeviceInfo airtaudio::api::Jack::getDeviceInfo(uint32_t _device) {
// Count the available ports containing the client name as device // Count the available ports containing the client name as device
// channels. Jack "input ports" equal RtAudio output channels. // channels. Jack "input ports" equal RtAudio output channels.
uint32_t nChannels = 0; uint32_t nChannels = 0;
ports = jack_get_ports(client, info.name.c_str(), NULL, JackPortIsInput); ports = jack_get_ports(client, info.name.c_str(), nullptr, JackPortIsInput);
if (ports) { if (ports) {
while (ports[ nChannels ]) { while (ports[ nChannels ]) {
nChannels++; nChannels++;
@ -173,7 +173,7 @@ airtaudio::DeviceInfo airtaudio::api::Jack::getDeviceInfo(uint32_t _device) {
} }
// Jack "output ports" equal RtAudio input channels. // Jack "output ports" equal RtAudio input channels.
nChannels = 0; nChannels = 0;
ports = jack_get_ports(client, info.name.c_str(), NULL, JackPortIsOutput); ports = jack_get_ports(client, info.name.c_str(), nullptr, JackPortIsOutput);
if (ports) { if (ports) {
while (ports[ nChannels ]) { while (ports[ nChannels ]) {
nChannels++; nChannels++;
@ -267,7 +267,7 @@ bool airtaudio::api::Jack::probeDeviceOpen(uint32_t _device,
|| ( _mode == INPUT || ( _mode == INPUT
&& m_stream.mode != OUTPUT)) { && m_stream.mode != OUTPUT)) {
jack_options_t jackoptions = (jack_options_t) (JackNoStartServer); //JackNullOption; jack_options_t jackoptions = (jack_options_t) (JackNoStartServer); //JackNullOption;
jack_status_t *status = NULL; jack_status_t *status = nullptr;
if (_options && !_options->streamName.empty()) { if (_options && !_options->streamName.empty()) {
client = jack_client_open(_options->streamName.c_str(), jackoptions, status); client = jack_client_open(_options->streamName.c_str(), jackoptions, status);
} else { } else {
@ -284,7 +284,7 @@ bool airtaudio::api::Jack::probeDeviceOpen(uint32_t _device,
const char **ports; const char **ports;
std::string port, previousPort, deviceName; std::string port, previousPort, deviceName;
uint32_t nPorts = 0, nDevices = 0; uint32_t nPorts = 0, nDevices = 0;
ports = jack_get_ports(client, NULL, NULL, 0); ports = jack_get_ports(client, nullptr, nullptr, 0);
if (ports) { if (ports) {
// Parse the port names up to the first colon (:). // Parse the port names up to the first colon (:).
size_t iColon = 0; size_t iColon = 0;
@ -313,7 +313,7 @@ bool airtaudio::api::Jack::probeDeviceOpen(uint32_t _device,
uint32_t nChannels = 0; uint32_t nChannels = 0;
uint64_t flag = JackPortIsInput; uint64_t flag = JackPortIsInput;
if (_mode == INPUT) flag = JackPortIsOutput; if (_mode == INPUT) flag = JackPortIsOutput;
ports = jack_get_ports(client, deviceName.c_str(), NULL, flag); ports = jack_get_ports(client, deviceName.c_str(), nullptr, flag);
if (ports) { if (ports) {
while (ports[ nChannels ]) { while (ports[ nChannels ]) {
nChannels++; nChannels++;
@ -334,7 +334,7 @@ bool airtaudio::api::Jack::probeDeviceOpen(uint32_t _device,
} }
m_stream.sampleRate = jackRate; m_stream.sampleRate = jackRate;
// Get the latency of the JACK port. // Get the latency of the JACK port.
ports = jack_get_ports(client, deviceName.c_str(), NULL, flag); ports = jack_get_ports(client, deviceName.c_str(), nullptr, flag);
if (ports[ _firstChannel ]) { if (ports[ _firstChannel ]) {
// Added by Ge Wang // Added by Ge Wang
jack_latency_callback_mode_t cbmode = (_mode == INPUT ? JackCaptureLatency : JackPlaybackLatency); jack_latency_callback_mode_t cbmode = (_mode == INPUT ? JackCaptureLatency : JackPlaybackLatency);
@ -377,7 +377,7 @@ bool airtaudio::api::Jack::probeDeviceOpen(uint32_t _device,
// Allocate our JackHandle structure for the stream. // Allocate our JackHandle structure for the stream.
if (handle == 0) { if (handle == 0) {
handle = new JackHandle; handle = new JackHandle;
if (handle == NULL) { if (handle == nullptr) {
ATA_ERROR("airtaudio::api::Jack::probeDeviceOpen: error allocating JackHandle memory."); ATA_ERROR("airtaudio::api::Jack::probeDeviceOpen: error allocating JackHandle memory.");
goto error; goto error;
} }
@ -389,7 +389,7 @@ bool airtaudio::api::Jack::probeDeviceOpen(uint32_t _device,
uint64_t bufferBytes; uint64_t bufferBytes;
bufferBytes = m_stream.nUserChannels[_mode] * *_bufferSize * formatBytes(m_stream.userFormat); bufferBytes = m_stream.nUserChannels[_mode] * *_bufferSize * formatBytes(m_stream.userFormat);
m_stream.userBuffer[_mode] = (char *) calloc(bufferBytes, 1); m_stream.userBuffer[_mode] = (char *) calloc(bufferBytes, 1);
if (m_stream.userBuffer[_mode] == NULL) { if (m_stream.userBuffer[_mode] == nullptr) {
ATA_ERROR("airtaudio::api::Jack::probeDeviceOpen: error allocating user buffer memory."); ATA_ERROR("airtaudio::api::Jack::probeDeviceOpen: error allocating user buffer memory.");
goto error; goto error;
} }
@ -410,7 +410,7 @@ bool airtaudio::api::Jack::probeDeviceOpen(uint32_t _device,
bufferBytes *= *_bufferSize; bufferBytes *= *_bufferSize;
if (m_stream.deviceBuffer) free(m_stream.deviceBuffer); if (m_stream.deviceBuffer) free(m_stream.deviceBuffer);
m_stream.deviceBuffer = (char *) calloc(bufferBytes, 1); m_stream.deviceBuffer = (char *) calloc(bufferBytes, 1);
if (m_stream.deviceBuffer == NULL) { if (m_stream.deviceBuffer == nullptr) {
ATA_ERROR("airtaudio::api::Jack::probeDeviceOpen: error allocating device buffer memory."); ATA_ERROR("airtaudio::api::Jack::probeDeviceOpen: error allocating device buffer memory.");
goto error; goto error;
} }
@ -418,7 +418,7 @@ bool airtaudio::api::Jack::probeDeviceOpen(uint32_t _device,
} }
// Allocate memory for the Jack ports (channels) identifiers. // Allocate memory for the Jack ports (channels) identifiers.
handle->ports[_mode] = (jack_port_t **) malloc (sizeof (jack_port_t *) * _channels); handle->ports[_mode] = (jack_port_t **) malloc (sizeof (jack_port_t *) * _channels);
if (handle->ports[_mode] == NULL) { if (handle->ports[_mode] == nullptr) {
ATA_ERROR("airtaudio::api::Jack::probeDeviceOpen: error allocating port memory."); ATA_ERROR("airtaudio::api::Jack::probeDeviceOpen: error allocating port memory.");
goto error; goto error;
} }
@ -474,17 +474,17 @@ error:
free(handle->ports[1]); free(handle->ports[1]);
} }
delete handle; delete handle;
m_stream.apiHandle = NULL; m_stream.apiHandle = nullptr;
} }
for (int32_t iii=0; iii<2; ++iii) { for (int32_t iii=0; iii<2; ++iii) {
if (m_stream.userBuffer[iii]) { if (m_stream.userBuffer[iii]) {
free(m_stream.userBuffer[iii]); free(m_stream.userBuffer[iii]);
m_stream.userBuffer[iii] = NULL; m_stream.userBuffer[iii] = nullptr;
} }
} }
if (m_stream.deviceBuffer) { if (m_stream.deviceBuffer) {
free(m_stream.deviceBuffer); free(m_stream.deviceBuffer);
m_stream.deviceBuffer = NULL; m_stream.deviceBuffer = nullptr;
} }
return false; return false;
} }
@ -495,13 +495,13 @@ enum airtaudio::errorType airtaudio::api::Jack::closeStream() {
return airtaudio::errorWarning; return airtaudio::errorWarning;
} }
JackHandle *handle = (JackHandle *) m_stream.apiHandle; JackHandle *handle = (JackHandle *) m_stream.apiHandle;
if (handle != NULL) { if (handle != nullptr) {
if (m_stream.state == STREAM_RUNNING) { if (m_stream.state == STREAM_RUNNING) {
jack_deactivate(handle->client); jack_deactivate(handle->client);
} }
jack_client_close(handle->client); jack_client_close(handle->client);
} }
if (handle != NULL) { if (handle != nullptr) {
if (handle->ports[0]) { if (handle->ports[0]) {
free(handle->ports[0]); free(handle->ports[0]);
} }
@ -509,17 +509,17 @@ enum airtaudio::errorType airtaudio::api::Jack::closeStream() {
free(handle->ports[1]); free(handle->ports[1]);
} }
delete handle; delete handle;
m_stream.apiHandle = NULL; m_stream.apiHandle = nullptr;
} }
for (int32_t i=0; i<2; i++) { for (int32_t i=0; i<2; i++) {
if (m_stream.userBuffer[i]) { if (m_stream.userBuffer[i]) {
free(m_stream.userBuffer[i]); free(m_stream.userBuffer[i]);
m_stream.userBuffer[i] = NULL; m_stream.userBuffer[i] = nullptr;
} }
} }
if (m_stream.deviceBuffer) { if (m_stream.deviceBuffer) {
free(m_stream.deviceBuffer); free(m_stream.deviceBuffer);
m_stream.deviceBuffer = NULL; m_stream.deviceBuffer = nullptr;
} }
m_stream.mode = UNINITIALIZED; m_stream.mode = UNINITIALIZED;
m_stream.state = STREAM_CLOSED; m_stream.state = STREAM_CLOSED;
@ -545,8 +545,8 @@ enum airtaudio::errorType airtaudio::api::Jack::startStream() {
if ( m_stream.mode == OUTPUT if ( m_stream.mode == OUTPUT
|| m_stream.mode == DUPLEX) { || m_stream.mode == DUPLEX) {
result = 1; result = 1;
ports = jack_get_ports(handle->client, handle->deviceName[0].c_str(), NULL, JackPortIsInput); ports = jack_get_ports(handle->client, handle->deviceName[0].c_str(), nullptr, JackPortIsInput);
if (ports == NULL) { if (ports == nullptr) {
ATA_ERROR("airtaudio::api::Jack::startStream(): error determining available JACK input ports!"); ATA_ERROR("airtaudio::api::Jack::startStream(): error determining available JACK input ports!");
goto unlock; goto unlock;
} }
@ -568,8 +568,8 @@ enum airtaudio::errorType airtaudio::api::Jack::startStream() {
if ( m_stream.mode == INPUT if ( m_stream.mode == INPUT
|| m_stream.mode == DUPLEX) { || m_stream.mode == DUPLEX) {
result = 1; result = 1;
ports = jack_get_ports(handle->client, handle->deviceName[1].c_str(), NULL, JackPortIsOutput); ports = jack_get_ports(handle->client, handle->deviceName[1].c_str(), nullptr, JackPortIsOutput);
if (ports == NULL) { if (ports == nullptr) {
ATA_ERROR("airtaudio::api::Jack::startStream(): error determining available JACK output ports!"); ATA_ERROR("airtaudio::api::Jack::startStream(): error determining available JACK output ports!");
goto unlock; goto unlock;
} }
@ -670,7 +670,6 @@ bool airtaudio::api::Jack::callbackEvent(uint64_t _nframes) {
} }
// Invoke user callback first, to get fresh output data. // Invoke user callback first, to get fresh output data.
if (handle->drainCounter == 0) { if (handle->drainCounter == 0) {
airtaudio::AirTAudioCallback callback = (airtaudio::AirTAudioCallback) info->callback;
double streamTime = getStreamTime(); double streamTime = getStreamTime();
airtaudio::streamStatus status = 0; airtaudio::streamStatus status = 0;
if (m_stream.mode != INPUT && handle->xrun[0] == true) { if (m_stream.mode != INPUT && handle->xrun[0] == true) {
@ -681,12 +680,11 @@ bool airtaudio::api::Jack::callbackEvent(uint64_t _nframes) {
status |= INPUT_OVERFLOW; status |= INPUT_OVERFLOW;
handle->xrun[1] = false; handle->xrun[1] = false;
} }
int32_t cbReturnValue = callback(m_stream.userBuffer[0], int32_t cbReturnValue = info->callback(m_stream.userBuffer[0],
m_stream.userBuffer[1], m_stream.userBuffer[1],
m_stream.bufferSize, m_stream.bufferSize,
streamTime, streamTime,
status, status);
info->userData);
if (cbReturnValue == 2) { if (cbReturnValue == 2) {
m_stream.state = STREAM_STOPPING; m_stream.state = STREAM_STOPPING;
handle->drainCounter = 2; handle->drainCounter = 2;

View File

@ -248,7 +248,7 @@ bool airtaudio::api::Oss::probeDeviceOpen(uint32_t _device,
} }
} }
// Set exclusive access if specified. // Set exclusive access if specified.
if ( _options != NULL if ( _options != nullptr
&& _options->flags & RTAUDIO_HOG_DEVICE) { && _options->flags & RTAUDIO_HOG_DEVICE) {
flags |= O_EXCL; flags |= O_EXCL;
} }
@ -266,7 +266,7 @@ bool airtaudio::api::Oss::probeDeviceOpen(uint32_t _device,
// For duplex operation, specifically set this mode (this doesn't seem to work). // For duplex operation, specifically set this mode (this doesn't seem to work).
/* /*
if (flags | O_RDWR) { if (flags | O_RDWR) {
result = ioctl(fd, SNDCTL_DSP_SETDUPLEX, NULL); result = ioctl(fd, SNDCTL_DSP_SETDUPLEX, nullptr);
if (result == -1) { if (result == -1) {
m_errorStream << "airtaudio::api::Oss::probeDeviceOpen: error setting duplex mode for device (" << ainfo.name << ")."; m_errorStream << "airtaudio::api::Oss::probeDeviceOpen: error setting duplex mode for device (" << ainfo.name << ").";
m_errorText = m_errorStream.str(); m_errorText = m_errorStream.str();
@ -391,10 +391,10 @@ bool airtaudio::api::Oss::probeDeviceOpen(uint32_t _device,
ossBufferBytes = 16; ossBufferBytes = 16;
} }
int32_t buffers = 0; int32_t buffers = 0;
if (_options != NULL) { if (_options != nullptr) {
buffers = _options->numberOfBuffers; buffers = _options->numberOfBuffers;
} }
if ( _options != NULL if ( _options != nullptr
&& _options->flags & RTAUDIO_MINIMIZE_LATENCY) { && _options->flags & RTAUDIO_MINIMIZE_LATENCY) {
buffers = 2; buffers = 2;
} }
@ -455,7 +455,7 @@ bool airtaudio::api::Oss::probeDeviceOpen(uint32_t _device,
// Allocate the stream handles if necessary and then save. // Allocate the stream handles if necessary and then save.
if (m_stream.apiHandle == 0) { if (m_stream.apiHandle == 0) {
handle = new OssHandle; handle = new OssHandle;
if handle == NULL) { if handle == nullptr) {
ATA_ERROR("airtaudio::api::Oss::probeDeviceOpen: error allocating OssHandle memory."); ATA_ERROR("airtaudio::api::Oss::probeDeviceOpen: error allocating OssHandle memory.");
goto error; goto error;
} }
@ -468,7 +468,7 @@ bool airtaudio::api::Oss::probeDeviceOpen(uint32_t _device,
uint64_t bufferBytes; uint64_t bufferBytes;
bufferBytes = m_stream.nUserChannels[_mode] * *_bufferSize * formatBytes(m_stream.userFormat); bufferBytes = m_stream.nUserChannels[_mode] * *_bufferSize * formatBytes(m_stream.userFormat);
m_stream.userBuffer[_mode] = (char *) calloc(bufferBytes, 1); m_stream.userBuffer[_mode] = (char *) calloc(bufferBytes, 1);
if (m_stream.userBuffer[_mode] == NULL) { if (m_stream.userBuffer[_mode] == nullptr) {
ATA_ERROR("airtaudio::api::Oss::probeDeviceOpen: error allocating user buffer memory."); ATA_ERROR("airtaudio::api::Oss::probeDeviceOpen: error allocating user buffer memory.");
goto error; goto error;
} }
@ -490,7 +490,7 @@ bool airtaudio::api::Oss::probeDeviceOpen(uint32_t _device,
free(m_stream.deviceBuffer); free(m_stream.deviceBuffer);
} }
m_stream.deviceBuffer = (char *) calloc(bufferBytes, 1); m_stream.deviceBuffer = (char *) calloc(bufferBytes, 1);
if (m_stream.deviceBuffer == NULL) { if (m_stream.deviceBuffer == nullptr) {
ATA_ERROR("airtaudio::api::Oss::probeDeviceOpen: error allocating device buffer memory."); ATA_ERROR("airtaudio::api::Oss::probeDeviceOpen: error allocating device buffer memory.");
goto error; goto error;
} }
@ -515,7 +515,7 @@ bool airtaudio::api::Oss::probeDeviceOpen(uint32_t _device,
m_stream.callbackInfo.object = (void *) this; m_stream.callbackInfo.object = (void *) this;
m_stream.callbackInfo.isRunning = true; m_stream.callbackInfo.isRunning = true;
m_stream.callbackInfo.thread = new std::thread(ossCallbackHandler, &m_stream.callbackInfo); m_stream.callbackInfo.thread = new std::thread(ossCallbackHandler, &m_stream.callbackInfo);
if (m_stream.callbackInfo.thread == NULL) { if (m_stream.callbackInfo.thread == nullptr) {
m_stream.callbackInfo.isRunning = false; m_stream.callbackInfo.isRunning = false;
ATA_ERROR("airtaudio::api::Oss::error creating callback thread!"); ATA_ERROR("airtaudio::api::Oss::error creating callback thread!");
goto error; goto error;
@ -728,7 +728,6 @@ void airtaudio::api::Oss::callbackEvent() {
} }
// Invoke user callback to get fresh output data. // Invoke user callback to get fresh output data.
int32_t doStopStream = 0; int32_t doStopStream = 0;
airtaudio::AirTAudioCallback callback = (airtaudio::AirTAudioCallback) m_stream.callbackInfo.callback;
double streamTime = getStreamTime(); double streamTime = getStreamTime();
rtaudio::streamStatus status = 0; rtaudio::streamStatus status = 0;
if ( m_stream.mode != INPUT if ( m_stream.mode != INPUT
@ -741,12 +740,11 @@ void airtaudio::api::Oss::callbackEvent() {
status |= RTAUDIO_INPUT_OVERFLOW; status |= RTAUDIO_INPUT_OVERFLOW;
handle->xrun[1] = false; handle->xrun[1] = false;
} }
doStopStream = callback(m_stream.userBuffer[0], doStopStream = m_stream.callbackInfo.callback(m_stream.userBuffer[0],
m_stream.userBuffer[1], m_stream.userBuffer[1],
m_stream.bufferSize, m_stream.bufferSize,
streamTime, streamTime,
status, status);
m_stream.callbackInfo.userData);
if (doStopStream == 2) { if (doStopStream == 2) {
this->abortStream(); this->abortStream();
return; return;

View File

@ -108,22 +108,22 @@ enum airtaudio::errorType airtaudio::api::Pulse::closeStream() {
m_stream.mutex.unlock(); m_stream.mutex.unlock();
pah->thread->join(); pah->thread->join();
if (pah->s_play) { if (pah->s_play) {
pa_simple_flush(pah->s_play, NULL); pa_simple_flush(pah->s_play, nullptr);
pa_simple_free(pah->s_play); pa_simple_free(pah->s_play);
} }
if (pah->s_rec) { if (pah->s_rec) {
pa_simple_free(pah->s_rec); pa_simple_free(pah->s_rec);
} }
delete pah; delete pah;
m_stream.apiHandle = NULL; m_stream.apiHandle = nullptr;
} }
if (m_stream.userBuffer[0] != NULL) { if (m_stream.userBuffer[0] != nullptr) {
free(m_stream.userBuffer[0]); free(m_stream.userBuffer[0]);
m_stream.userBuffer[0] = NULL; m_stream.userBuffer[0] = nullptr;
} }
if (m_stream.userBuffer[1] != NULL) { if (m_stream.userBuffer[1] != nullptr) {
free(m_stream.userBuffer[1]); free(m_stream.userBuffer[1]);
m_stream.userBuffer[1] = NULL; m_stream.userBuffer[1] = nullptr;
} }
m_stream.state = STREAM_CLOSED; m_stream.state = STREAM_CLOSED;
m_stream.mode = UNINITIALIZED; m_stream.mode = UNINITIALIZED;
@ -146,15 +146,13 @@ void airtaudio::api::Pulse::callbackEvent() {
ATA_ERROR("airtaudio::api::Pulse::callbackEvent(): the stream is closed ... this shouldn't happen!"); ATA_ERROR("airtaudio::api::Pulse::callbackEvent(): the stream is closed ... this shouldn't happen!");
return; return;
} }
airtaudio::AirTAudioCallback callback = (airtaudio::AirTAudioCallback) m_stream.callbackInfo.callback;
double streamTime = getStreamTime(); double streamTime = getStreamTime();
airtaudio::streamStatus status = 0; airtaudio::streamStatus status = 0;
int32_t doStopStream = callback(m_stream.userBuffer[OUTPUT], int32_t doStopStream = m_stream.callbackInfo.callback(m_stream.userBuffer[OUTPUT],
m_stream.userBuffer[INPUT], m_stream.userBuffer[INPUT],
m_stream.bufferSize, m_stream.bufferSize,
streamTime, streamTime,
status, status);
m_stream.callbackInfo.userData);
if (doStopStream == 2) { if (doStopStream == 2) {
abortStream(); abortStream();
return; return;
@ -346,7 +344,7 @@ bool airtaudio::api::Pulse::probeDeviceOpen(uint32_t _device,
// Allocate necessary internal buffers. // Allocate necessary internal buffers.
bufferBytes = m_stream.nUserChannels[_mode] * *_bufferSize * formatBytes(m_stream.userFormat); bufferBytes = m_stream.nUserChannels[_mode] * *_bufferSize * formatBytes(m_stream.userFormat);
m_stream.userBuffer[_mode] = (char *) calloc(bufferBytes, 1); m_stream.userBuffer[_mode] = (char *) calloc(bufferBytes, 1);
if (m_stream.userBuffer[_mode] == NULL) { if (m_stream.userBuffer[_mode] == nullptr) {
ATA_ERROR("airtaudio::api::Pulse::probeDeviceOpen: error allocating user buffer memory."); ATA_ERROR("airtaudio::api::Pulse::probeDeviceOpen: error allocating user buffer memory.");
goto error; goto error;
} }
@ -364,7 +362,7 @@ bool airtaudio::api::Pulse::probeDeviceOpen(uint32_t _device,
bufferBytes *= *_bufferSize; bufferBytes *= *_bufferSize;
if (m_stream.deviceBuffer) free(m_stream.deviceBuffer); if (m_stream.deviceBuffer) free(m_stream.deviceBuffer);
m_stream.deviceBuffer = (char *) calloc(bufferBytes, 1); m_stream.deviceBuffer = (char *) calloc(bufferBytes, 1);
if (m_stream.deviceBuffer == NULL) { if (m_stream.deviceBuffer == nullptr) {
ATA_ERROR("airtaudio::api::Pulse::probeDeviceOpen: error allocating device buffer memory."); ATA_ERROR("airtaudio::api::Pulse::probeDeviceOpen: error allocating device buffer memory.");
goto error; goto error;
} }
@ -387,14 +385,14 @@ bool airtaudio::api::Pulse::probeDeviceOpen(uint32_t _device,
int32_t error; int32_t error;
switch (_mode) { switch (_mode) {
case INPUT: case INPUT:
pah->s_rec = pa_simple_new(NULL, "RtAudio", PA_STREAM_RECORD, NULL, "Record", &ss, NULL, NULL, &error); pah->s_rec = pa_simple_new(nullptr, "airtAudio", PA_STREAM_RECORD, nullptr, "Record", &ss, nullptr, nullptr, &error);
if (!pah->s_rec) { if (!pah->s_rec) {
ATA_ERROR("airtaudio::api::Pulse::probeDeviceOpen: error connecting input to PulseAudio server."); ATA_ERROR("airtaudio::api::Pulse::probeDeviceOpen: error connecting input to PulseAudio server.");
goto error; goto error;
} }
break; break;
case OUTPUT: case OUTPUT:
pah->s_play = pa_simple_new(NULL, "RtAudio", PA_STREAM_PLAYBACK, NULL, "Playback", &ss, NULL, NULL, &error); pah->s_play = pa_simple_new(nullptr, "airtAudio", PA_STREAM_PLAYBACK, nullptr, "Playback", &ss, nullptr, nullptr, &error);
if (!pah->s_play) { if (!pah->s_play) {
ATA_ERROR("airtaudio::api::Pulse::probeDeviceOpen: error connecting output to PulseAudio server."); ATA_ERROR("airtaudio::api::Pulse::probeDeviceOpen: error connecting output to PulseAudio server.");
goto error; goto error;
@ -414,7 +412,7 @@ bool airtaudio::api::Pulse::probeDeviceOpen(uint32_t _device,
m_stream.callbackInfo.object = this; m_stream.callbackInfo.object = this;
m_stream.callbackInfo.isRunning = true; m_stream.callbackInfo.isRunning = true;
pah->thread = new std::thread(pulseaudio_callback, (void *)&m_stream.callbackInfo); pah->thread = new std::thread(pulseaudio_callback, (void *)&m_stream.callbackInfo);
if (pah->thread == NULL) { if (pah->thread == nullptr) {
ATA_ERROR("airtaudio::api::Pulse::probeDeviceOpen: error creating thread."); ATA_ERROR("airtaudio::api::Pulse::probeDeviceOpen: error creating thread.");
goto error; goto error;
} }

View File

@ -12,6 +12,7 @@
#include <thread> #include <thread>
#include <condition_variable> #include <condition_variable>
#include <mutex> #include <mutex>
#include <functional>
// defien type : uintXX_t and intXX_t // defien type : uintXX_t and intXX_t
#define __STDC_LIMIT_MACROS #define __STDC_LIMIT_MACROS
@ -158,13 +159,13 @@ namespace airtaudio {
* should write \c nFrames of audio sample frames into this * should write \c nFrames of audio sample frames into this
* buffer. This argument should be recast to the datatype * buffer. This argument should be recast to the datatype
* specified when the stream was opened. For input-only * specified when the stream was opened. For input-only
* streams, this argument will be NULL. * streams, this argument will be nullptr.
* *
* @param _inputBuffer For input (or duplex) streams, this buffer will * @param _inputBuffer For input (or duplex) streams, this buffer will
* hold \c nFrames of input audio sample frames. This * hold \c nFrames of input audio sample frames. This
* argument should be recast to the datatype specified when the * argument should be recast to the datatype specified when the
* stream was opened. For output-only streams, this argument * stream was opened. For output-only streams, this argument
* will be NULL. * will be nullptr.
* *
* @param _nFrames The number of sample frames of input or output * @param _nFrames The number of sample frames of input or output
* data in the buffers. The actual buffer size in bytes is * data in the buffers. The actual buffer size in bytes is
@ -178,20 +179,16 @@ namespace airtaudio {
* condition can be determined by comparison with the * condition can be determined by comparison with the
* streamStatus flags. * streamStatus flags.
* *
* @param _userData A pointer to optional data provided by the client
* when opening the stream (default = NULL).
*
* To continue normal stream operation, the RtAudioCallback function * To continue normal stream operation, the RtAudioCallback function
* should return a value of zero. To stop the stream and drain the * should return a value of zero. To stop the stream and drain the
* output buffer, the function should return a value of one. To abort * output buffer, the function should return a value of one. To abort
* the stream immediately, the client should return a value of two. * the stream immediately, the client should return a value of two.
*/ */
typedef int32_t (*AirTAudioCallback)(void *_outputBuffer, typedef std::function<int32_t (void* _outputBuffer,
void *_inputBuffer, const void* const _inputBuffer,
uint32_t _nFrames, uint32_t _nFrames,
double _streamTime, double _streamTime,
airtaudio::streamStatus _status, airtaudio::streamStatus _status)> AirTAudioCallback;
void *_userData);
} }
#include <airtaudio/DeviceInfo.h> #include <airtaudio/DeviceInfo.h>

View File

@ -6,8 +6,8 @@
* @license BSD 3 clauses (see license file) * @license BSD 3 clauses (see license file)
*/ */
#ifndef __EAUDIOFX_DEBUG_H__ #ifndef __AIRTAUDIO_DEBUG_H__
#define __EAUDIOFX_DEBUG_H__ #define __AIRTAUDIO_DEBUG_H__
#include <etk/log.h> #include <etk/log.h>