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

View File

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

View File

@ -10,6 +10,8 @@
#define __AIRTAUDIO_CALLBACK_INFO_H__
#include <thread>
#include <functional>
#include <airtaudio/base.h>
namespace airtaudio {
// This global structure type is used to pass callback information
@ -19,8 +21,7 @@ namespace airtaudio {
public:
void* object; // Used as a "this" pointer.
std::thread* thread;
void* callback;
void* userData;
airtaudio::AirTAudioCallback callback;
void* apiInfo; // void pointer for API specific callback information
bool isRunning;
bool doRealtime;
@ -28,10 +29,9 @@ namespace airtaudio {
// Default constructor.
CallbackInfo() :
object(0),
callback(0),
userData(0),
apiInfo(0),
object(nullptr),
callback(nullptr),
apiInfo(nullptr),
isRunning(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) {
delete m_rtapi;
m_rtapi = nullptr;
for (auto &it :m_apiAvaillable) {
@ -146,7 +145,6 @@ enum airtaudio::errorType airtaudio::Interface::openStream(
uint32_t _sampleRate,
uint32_t* _bufferFrames,
airtaudio::AirTAudioCallback _callback,
void* _userData,
airtaudio::StreamOptions* _options) {
if (m_rtapi == nullptr) {
return airtaudio::errorInputNull;
@ -157,7 +155,6 @@ enum airtaudio::errorType airtaudio::Interface::openStream(
_sampleRate,
_bufferFrames,
_callback,
_userData,
_options);
}

View File

@ -173,8 +173,6 @@ namespace airtaudio {
* allowable value is determined.
* @param _callback A client-defined function that will be invoked
* 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
* global stream options, including a list of OR'ed airtaudio::streamFlags
* and a suggested number of stream buffers that can be used to
@ -193,7 +191,6 @@ namespace airtaudio {
uint32_t _sampleRate,
uint32_t *_bufferFrames,
airtaudio::AirTAudioCallback _callback,
void *_userData = nullptr,
airtaudio::StreamOptions *_options = nullptr);
/**

View File

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

View File

@ -120,24 +120,21 @@ enum airtaudio::errorType airtaudio::api::Android::abortStream() {
void airtaudio::api::Android::callBackEvent(void* _data,
int32_t _frameRate) {
int32_t doStopStream = 0;
airtaudio::AirTAudioCallback callback = (airtaudio::AirTAudioCallback) m_stream.callbackInfo.callback;
double streamTime = getStreamTime();
airtaudio::streamStatus status = 0;
if (m_stream.doConvertBuffer[OUTPUT] == true) {
doStopStream = callback(m_stream.userBuffer[OUTPUT],
NULL,
_frameRate,
streamTime,
status,
m_stream.callbackInfo.userData);
doStopStream = m_stream.callbackInfo.callback(m_stream.userBuffer[OUTPUT],
nullptr,
_frameRate,
streamTime,
status);
convertBuffer((char*)_data, (char*)m_stream.userBuffer[OUTPUT], m_stream.convertInfo[OUTPUT]);
} else {
doStopStream = callback(_data,
NULL,
_frameRate,
streamTime,
status,
m_stream.callbackInfo.userData);
doStopStream = m_stream.callbackInfo.callback(_data,
nullptr,
_frameRate,
streamTime,
status);
}
if (doStopStream == 2) {
abortStream();
@ -149,8 +146,8 @@ void airtaudio::api::Android::callBackEvent(void* _data,
void airtaudio::api::Android::androidCallBackEvent(void* _data,
int32_t _frameRate,
void* _userData) {
if (_userData == NULL) {
ATA_INFO("callback event ... NULL pointer");
if (_userData == nullptr) {
ATA_INFO("callback event ... nullptr pointer");
return;
}
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.
uint64_t bufferBytes = m_stream.nUserChannels[_mode] * m_stream.bufferSize * formatBytes(m_stream.userFormat);
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.");
}
setConvertInfo(_mode, _firstChannel);

View File

@ -68,7 +68,7 @@ airtaudio::api::Asio::Asio() {
// CoInitialize beforehand, but it must be for appartment threading
// (in which case, CoInitilialize will return S_FALSE here).
m_coInitialized = false;
HRESULT hr = CoInitialize(NULL);
HRESULT hr = CoInitialize(nullptr);
if (FAILED(hr)) {
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.nBuffers = 2;
if ( _options != NULL
if ( _options != nullptr
&& _options->flags & RTAUDIO_NONINTERLEAVED) {
m_stream.userInterleaved = false;
} else {
@ -409,19 +409,19 @@ bool airtaudio::api::Asio::probeDeviceOpen(uint32_t _device,
m_stream.deviceInterleaved[_mode] = false;
// Allocate, if necessary, our AsioHandle structure for the stream.
AsioHandle *handle = (AsioHandle *) m_stream.apiHandle;
if (handle == NULL) {
if (handle == nullptr) {
handle = new AsioHandle;
if (handle == NULL) {
if (handle == nullptr) {
drivers.removeCurrentDriver();
ATA_ERROR("airtaudio::api::Asio::probeDeviceOpen: error allocating AsioHandle memory.");
return false;
}
handle->bufferInfos = 0;
// Create a manual-reset event.
handle->condition = CreateEvent(NULL, // no security
handle->condition = CreateEvent(nullptr, // no security
TRUE, // manual-reset
FALSE, // non-signaled initially
NULL); // unnamed
nullptr); // unnamed
m_stream.apiHandle = (void *) handle;
}
// 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
&& m_stream.mode == OUTPUT) {
ASIODisposeBuffers();
if (handle->bufferInfos == NULL) {
if (handle->bufferInfos == nullptr) {
free(handle->bufferInfos);
handle->bufferInfos = NULL;
handle->bufferInfos = nullptr;
}
}
// Allocate, initialize, and save the bufferInfos in our stream callbackInfo structure.
bool buffersAllocated = false;
uint32_t i, nChannels = m_stream.nDeviceChannels[0] + m_stream.nDeviceChannels[1];
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 << ").");
goto error;
}
@ -460,7 +460,7 @@ bool airtaudio::api::Asio::probeDeviceOpen(uint32_t _device,
asioCallbacks.bufferSwitch = &bufferSwitch;
asioCallbacks.sampleRateDidChange = &sampleRateChanged;
asioCallbacks.asioMessage = &asioMessages;
asioCallbacks.bufferSwitchTimeInfo = NULL;
asioCallbacks.bufferSwitchTimeInfo = nullptr;
result = ASIOCreateBuffers(handle->bufferInfos, nChannels, m_stream.bufferSize, &asioCallbacks);
if (result != ASE_OK) {
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;
bufferBytes = m_stream.nUserChannels[_mode] * *_bufferSize * formatBytes(m_stream.userFormat);
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.");
goto error;
}
@ -499,10 +499,10 @@ bool airtaudio::api::Asio::probeDeviceOpen(uint32_t _device,
bufferBytes *= *_bufferSize;
if (m_stream.deviceBuffer) {
free(m_stream.deviceBuffer);
m_stream.deviceBuffer = NULL;
m_stream.deviceBuffer = nullptr;
}
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.");
goto error;
}
@ -544,10 +544,10 @@ error:
CloseHandle(handle->condition);
if (handle->bufferInfos) {
free(handle->bufferInfos);
handle->bufferInfos = NULL;
handle->bufferInfos = nullptr;
}
delete handle;
handle = NULL;
handle = nullptr;
m_stream.apiHandle = 0;
}
for (int32_t i=0; i<2; i++) {
@ -703,15 +703,14 @@ bool airtaudio::api::Asio::callbackEvent(long bufferIndex) {
SetEvent(handle->condition);
} else { // spawn a thread to stop the stream
unsigned threadId;
m_stream.callbackInfo.thread = _beginthreadex(NULL, 0, &asioStopStream,
&m_stream.callbackInfo, 0, &threadId);
m_stream.callbackInfo.thread = _beginthreadex(nullptr, 0, &asioStopStream,
&m_stream.callbackInfo, 0, &threadId);
}
return true;
}
// Invoke user callback to get fresh output data UNLESS we are
// draining stream.
if (handle->drainCounter == 0) {
airtaudio::AirTAudioCallback callback = (airtaudio::AirTAudioCallback) info->callback;
double streamTime = getStreamTime();
rtaudio::streamStatus status = 0;
if (m_stream.mode != INPUT && asioXRun == true) {
@ -722,17 +721,16 @@ bool airtaudio::api::Asio::callbackEvent(long bufferIndex) {
status |= RTAUDIO_INPUT_OVERFLOW;
asioXRun = false;
}
int32_t cbReturnValue = callback(m_stream.userBuffer[0],
m_stream.userBuffer[1],
m_stream.bufferSize,
streamTime,
status,
info->userData);
int32_t cbReturnValue = info->callback(m_stream.userBuffer[0],
m_stream.userBuffer[1],
m_stream.bufferSize,
streamTime,
status);
if (cbReturnValue == 2) {
m_stream.state = STREAM_STOPPING;
handle->drainCounter = 2;
unsigned threadId;
m_stream.callbackInfo.thread = _beginthreadex(NULL,
m_stream.callbackInfo.thread = _beginthreadex(nullptr,
0,
&asioStopStream,
&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
// updates to various audio device properties are not handled
// correctly.
CFRunLoopRef theRunLoop = NULL;
CFRunLoopRef theRunLoop = nullptr;
AudioObjectPropertyAddress property = {
kAudioHardwarePropertyRunLoop,
kAudioObjectPropertyScopeGlobal,
@ -80,7 +80,7 @@ airtaudio::api::Core::Core() {
OSStatus result = AudioObjectSetPropertyData(kAudioObjectSystemObject,
&property,
0,
NULL,
nullptr,
sizeof(CFRunLoopRef),
&theRunLoop);
if (result != noErr) {
@ -106,7 +106,7 @@ uint32_t airtaudio::api::Core::getDeviceCount() {
kAudioObjectPropertyScopeGlobal,
kAudioObjectPropertyElementMaster
};
OSStatus result = AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &propertyAddress, 0, NULL, &dataSize);
OSStatus result = AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &propertyAddress, 0, nullptr, &dataSize);
if (result != noErr) {
ATA_ERROR("airtaudio::api::Core::getDeviceCount: OS-X error getting device info!");
return 0;
@ -129,7 +129,7 @@ uint32_t airtaudio::api::Core::getDefaultInputDevice() {
OSStatus result = AudioObjectGetPropertyData(kAudioObjectSystemObject,
&property,
0,
NULL,
nullptr,
&dataSize,
&id);
if (result != noErr) {
@ -142,7 +142,7 @@ uint32_t airtaudio::api::Core::getDefaultInputDevice() {
result = AudioObjectGetPropertyData(kAudioObjectSystemObject,
&property,
0,
NULL,
nullptr,
&dataSize,
(void*)&deviceList);
if (result != noErr) {
@ -173,7 +173,7 @@ uint32_t airtaudio::api::Core::getDefaultOutputDevice() {
OSStatus result = AudioObjectGetPropertyData(kAudioObjectSystemObject,
&property,
0,
NULL,
nullptr,
&dataSize,
&id);
if (result != noErr) {
@ -186,7 +186,7 @@ uint32_t airtaudio::api::Core::getDefaultOutputDevice() {
result = AudioObjectGetPropertyData(kAudioObjectSystemObject,
&property,
0,
NULL,
nullptr,
&dataSize,
(void*)&deviceList);
if (result != noErr) {
@ -225,7 +225,7 @@ airtaudio::DeviceInfo airtaudio::api::Core::getDeviceInfo(uint32_t _device) {
OSStatus result = AudioObjectGetPropertyData(kAudioObjectSystemObject,
&property,
0,
NULL,
nullptr,
&dataSize,
(void*)&deviceList);
if (result != noErr) {
@ -238,7 +238,7 @@ airtaudio::DeviceInfo airtaudio::api::Core::getDeviceInfo(uint32_t _device) {
CFStringRef cfname;
dataSize = sizeof(CFStringRef);
property.mSelector = kAudioObjectPropertyManufacturer;
result = AudioObjectGetPropertyData(id, &property, 0, NULL, &dataSize, &cfname);
result = AudioObjectGetPropertyData(id, &property, 0, nullptr, &dataSize, &cfname);
if (result != noErr) {
ATA_ERROR("airtaudio::api::Core::probeDeviceInfo: system error (" << getErrorCode(result) << ") getting device manufacturer.");
return info;
@ -252,7 +252,7 @@ airtaudio::DeviceInfo airtaudio::api::Core::getDeviceInfo(uint32_t _device) {
CFRelease(cfname);
free(mname);
property.mSelector = kAudioObjectPropertyName;
result = AudioObjectGetPropertyData(id, &property, 0, NULL, &dataSize, &cfname);
result = AudioObjectGetPropertyData(id, &property, 0, nullptr, &dataSize, &cfname);
if (result != noErr) {
ATA_ERROR("airtaudio::api::Core::probeDeviceInfo: system error (" << getErrorCode(result) << ") getting device name.");
return info;
@ -270,18 +270,18 @@ airtaudio::DeviceInfo airtaudio::api::Core::getDeviceInfo(uint32_t _device) {
property.mScope = kAudioDevicePropertyScopeOutput;
// property.mElement = kAudioObjectPropertyElementWildcard;
dataSize = 0;
result = AudioObjectGetPropertyDataSize(id, &property, 0, NULL, &dataSize);
result = AudioObjectGetPropertyDataSize(id, &property, 0, nullptr, &dataSize);
if (result != noErr || dataSize == 0) {
ATA_ERROR("airtaudio::api::Core::getDeviceInfo: system error (" << getErrorCode(result) << ") getting output stream configuration info for device (" << _device << ").");
return info;
}
// Allocate the AudioBufferList.
bufferList = (AudioBufferList *) malloc(dataSize);
if (bufferList == NULL) {
if (bufferList == nullptr) {
ATA_ERROR("airtaudio::api::Core::getDeviceInfo: memory error allocating output AudioBufferList.");
return info;
}
result = AudioObjectGetPropertyData(id, &property, 0, NULL, &dataSize, bufferList);
result = AudioObjectGetPropertyData(id, &property, 0, nullptr, &dataSize, bufferList);
if ( result != noErr
|| dataSize == 0) {
free(bufferList);
@ -296,7 +296,7 @@ airtaudio::DeviceInfo airtaudio::api::Core::getDeviceInfo(uint32_t _device) {
free(bufferList);
// Get the input stream "configuration".
property.mScope = kAudioDevicePropertyScopeInput;
result = AudioObjectGetPropertyDataSize(id, &property, 0, NULL, &dataSize);
result = AudioObjectGetPropertyDataSize(id, &property, 0, nullptr, &dataSize);
if ( result != noErr
|| dataSize == 0) {
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.
bufferList = (AudioBufferList *) malloc(dataSize);
if (bufferList == NULL) {
if (bufferList == nullptr) {
ATA_ERROR("airtaudio::api::Core::getDeviceInfo: memory error allocating input AudioBufferList.");
return info;
}
result = AudioObjectGetPropertyData(id, &property, 0, NULL, &dataSize, bufferList);
result = AudioObjectGetPropertyData(id, &property, 0, nullptr, &dataSize, bufferList);
if (result != noErr || dataSize == 0) {
free(bufferList);
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.
property.mSelector = kAudioDevicePropertyAvailableNominalSampleRates;
if (isInput == false) property.mScope = kAudioDevicePropertyScopeOutput;
result = AudioObjectGetPropertyDataSize(id, &property, 0, NULL, &dataSize);
result = AudioObjectGetPropertyDataSize(id, &property, 0, nullptr, &dataSize);
if ( result != kAudioHardwareNoError
|| dataSize == 0) {
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);
AudioValueRange rangeList[ nRanges ];
result = AudioObjectGetPropertyData(id, &property, 0, NULL, &dataSize, &rangeList);
result = AudioObjectGetPropertyData(id, &property, 0, nullptr, &dataSize, &rangeList);
if (result != kAudioHardwareNoError) {
ATA_ERROR("airtaudio::api::Core::getDeviceInfo: system error (" << getErrorCode(result) << ") getting sample rates.");
return info;
@ -427,7 +427,7 @@ static OSStatus rateListener(AudioObjectID _inDevice,
kAudioObjectPropertyScopeGlobal,
kAudioObjectPropertyElementMaster
};
AudioObjectGetPropertyData(_inDevice, &property, 0, NULL, &dataSize, rate);
AudioObjectGetPropertyData(_inDevice, &property, 0, nullptr, &dataSize, rate);
return kAudioHardwareNoError;
}
@ -461,7 +461,7 @@ bool airtaudio::api::Core::probeDeviceOpen(uint32_t _device,
OSStatus result = AudioObjectGetPropertyData(kAudioObjectSystemObject,
&property,
0,
NULL,
nullptr,
&dataSize,
(void *) &deviceList);
if (result != noErr) {
@ -481,7 +481,7 @@ bool airtaudio::api::Core::probeDeviceOpen(uint32_t _device,
AudioBufferList *bufferList = nil;
dataSize = 0;
property.mSelector = kAudioDevicePropertyStreamConfiguration;
result = AudioObjectGetPropertyDataSize(id, &property, 0, NULL, &dataSize);
result = AudioObjectGetPropertyDataSize(id, &property, 0, nullptr, &dataSize);
if ( result != noErr
|| dataSize == 0) {
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.
bufferList = (AudioBufferList *) malloc(dataSize);
if (bufferList == NULL) {
if (bufferList == nullptr) {
ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: memory error allocating AudioBufferList.");
return false;
}
result = AudioObjectGetPropertyData(id, &property, 0, NULL, &dataSize, bufferList);
result = AudioObjectGetPropertyData(id, &property, 0, nullptr, &dataSize, bufferList);
if ( result != noErr
|| dataSize == 0) {
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;
dataSize = sizeof(AudioValueRange);
property.mSelector = kAudioDevicePropertyBufferFrameSizeRange;
result = AudioObjectGetPropertyData(id, &property, 0, NULL, &dataSize, &bufferRange);
result = AudioObjectGetPropertyData(id, &property, 0, nullptr, &dataSize, &bufferRange);
if (result != noErr) {
ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: system error (" << getErrorCode(result) << ") getting buffer size range for device (" << _device << ").");
return false;
@ -579,7 +579,7 @@ bool airtaudio::api::Core::probeDeviceOpen(uint32_t _device,
} else if (bufferRange.mMaximum < *_bufferSize) {
*_bufferSize = (uint64_t) bufferRange.mMaximum;
}
if ( _options != NULL
if ( _options != nullptr
&& _options->flags & MINIMIZE_LATENCY) {
*_bufferSize = (uint64_t) bufferRange.mMinimum;
}
@ -588,7 +588,7 @@ bool airtaudio::api::Core::probeDeviceOpen(uint32_t _device,
uint32_t theSize = (uint32_t) *_bufferSize;
dataSize = sizeof(uint32_t);
property.mSelector = kAudioDevicePropertyBufferFrameSize;
result = AudioObjectSetPropertyData(id, &property, 0, NULL, dataSize, &theSize);
result = AudioObjectSetPropertyData(id, &property, 0, nullptr, dataSize, &theSize);
if (result != noErr) {
ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: system error (" << getErrorCode(result) << ") setting the buffer size for device (" << _device << ").");
return false;
@ -605,19 +605,19 @@ bool airtaudio::api::Core::probeDeviceOpen(uint32_t _device,
m_stream.bufferSize = *_bufferSize;
m_stream.nBuffers = 1;
// Try to set "hog" mode ... it's not clear to me this is working.
if ( _options != NULL
if ( _options != nullptr
&& _options->flags & HOG_DEVICE) {
pid_t hog_pid;
dataSize = sizeof(hog_pid);
property.mSelector = kAudioDevicePropertyHogMode;
result = AudioObjectGetPropertyData(id, &property, 0, NULL, &dataSize, &hog_pid);
result = AudioObjectGetPropertyData(id, &property, 0, nullptr, &dataSize, &hog_pid);
if (result != noErr) {
ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: system error (" << getErrorCode(result) << ") getting 'hog' state!");
return false;
}
if (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) {
ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: system error (" << getErrorCode(result) << ") setting 'hog' state!");
return false;
@ -628,7 +628,7 @@ bool airtaudio::api::Core::probeDeviceOpen(uint32_t _device,
double nominalRate;
dataSize = sizeof(double);
property.mSelector = kAudioDevicePropertyNominalSampleRate;
result = AudioObjectGetPropertyData(id, &property, 0, NULL, &dataSize, &nominalRate);
result = AudioObjectGetPropertyData(id, &property, 0, nullptr, &dataSize, &nominalRate);
if (result != noErr) {
ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: system error (" << getErrorCode(result) << ") getting current sample rate.");
return false;
@ -644,7 +644,7 @@ bool airtaudio::api::Core::probeDeviceOpen(uint32_t _device,
return false;
}
nominalRate = (double) _sampleRate;
result = AudioObjectSetPropertyData(id, &property, 0, NULL, dataSize, &nominalRate);
result = AudioObjectSetPropertyData(id, &property, 0, nullptr, dataSize, &nominalRate);
if (result != noErr) {
ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: system error (" << getErrorCode(result) << ") setting sample rate for device (" << _device << ").");
return false;
@ -670,7 +670,7 @@ bool airtaudio::api::Core::probeDeviceOpen(uint32_t _device,
AudioStreamBasicDescription description;
dataSize = sizeof(AudioStreamBasicDescription);
property.mSelector = kAudioStreamPropertyVirtualFormat;
result = AudioObjectGetPropertyData(id, &property, 0, NULL, &dataSize, &description);
result = AudioObjectGetPropertyData(id, &property, 0, nullptr, &dataSize, &description);
if (result != noErr) {
ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: system error (" << getErrorCode(result) << ") getting stream format for device (" << _device << ").");
return false;
@ -688,7 +688,7 @@ bool airtaudio::api::Core::probeDeviceOpen(uint32_t _device,
updateFormat = true;
}
if (updateFormat) {
result = AudioObjectSetPropertyData(id, &property, 0, NULL, dataSize, &description);
result = AudioObjectSetPropertyData(id, &property, 0, nullptr, dataSize, &description);
if (result != noErr) {
ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: system error (" << getErrorCode(result) << ") setting sample rate or data format for device (" << _device << ").");
return false;
@ -696,7 +696,7 @@ bool airtaudio::api::Core::probeDeviceOpen(uint32_t _device,
}
// Now check the physical format.
property.mSelector = kAudioStreamPropertyPhysicalFormat;
result = AudioObjectGetPropertyData(id, &property, 0, NULL, &dataSize, &description);
result = AudioObjectGetPropertyData(id, &property, 0, nullptr, &dataSize, &description);
if (result != noErr) {
ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: system error (" << getErrorCode(result) << ") getting stream physical format for device (" << _device << ").");
return false;
@ -738,7 +738,7 @@ bool airtaudio::api::Core::probeDeviceOpen(uint32_t _device,
testDescription.mBytesPerFrame = testDescription.mBitsPerChannel/8 * testDescription.mChannelsPerFrame;
}
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) {
setPhysicalFormat = true;
//std::cout << "Updated physical stream format:" << std::endl;
@ -759,7 +759,7 @@ bool airtaudio::api::Core::probeDeviceOpen(uint32_t _device,
dataSize = sizeof(uint32_t);
property.mSelector = kAudioDevicePropertyLatency;
if (AudioObjectHasProperty(id, &property) == true) {
result = AudioObjectGetPropertyData(id, &property, 0, NULL, &dataSize, &latency);
result = AudioObjectGetPropertyData(id, &property, 0, nullptr, &dataSize, &latency);
if (result == kAudioHardwareNoError) {
m_stream.latency[ _mode ] = latency;
} else {
@ -783,7 +783,7 @@ bool airtaudio::api::Core::probeDeviceOpen(uint32_t _device,
}
m_stream.nUserChannels[_mode] = _channels;
m_stream.channelOffset[_mode] = channelOffset; // offset within a CoreAudio stream
if ( _options != NULL
if ( _options != nullptr
&& _options->flags & NONINTERLEAVED) {
m_stream.userInterleaved = false;
} else {
@ -813,7 +813,7 @@ bool airtaudio::api::Core::probeDeviceOpen(uint32_t _device,
CoreHandle *handle = 0;
if (m_stream.apiHandle == 0) {
handle = new CoreHandle;
if (handle == NULL) {
if (handle == nullptr) {
ATA_ERROR("airtaudio::api::Core::probeDeviceOpen: error allocating CoreHandle memory.");
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 *) malloc(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.");
goto error;
}
@ -854,10 +854,10 @@ bool airtaudio::api::Core::probeDeviceOpen(uint32_t _device,
bufferBytes *= *_bufferSize;
if (m_stream.deviceBuffer) {
free(m_stream.deviceBuffer);
m_stream.deviceBuffer = NULL;
m_stream.deviceBuffer = nullptr;
}
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.");
goto error;
}
@ -955,12 +955,12 @@ enum airtaudio::errorType airtaudio::api::Core::closeStream() {
for (int32_t i=0; i<2; i++) {
if (m_stream.userBuffer[i]) {
free(m_stream.userBuffer[i]);
m_stream.userBuffer[i] = NULL;
m_stream.userBuffer[i] = nullptr;
}
}
if (m_stream.deviceBuffer) {
free(m_stream.deviceBuffer);
m_stream.deviceBuffer = NULL;
m_stream.deviceBuffer = nullptr;
}
delete handle;
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
// different AND this function is called for the input device.
if (handle->drainCounter == 0 && (m_stream.mode != DUPLEX || _deviceId == outputDevice)) {
airtaudio::AirTAudioCallback callback = (airtaudio::AirTAudioCallback) info->callback;
double streamTime = getStreamTime();
airtaudio::streamStatus status = 0;
if ( m_stream.mode != INPUT
@ -1112,12 +1111,11 @@ bool airtaudio::api::Core::callbackEvent(AudioDeviceID _deviceId,
status |= INPUT_OVERFLOW;
handle->xrun[1] = false;
}
int32_t cbReturnValue = callback(m_stream.userBuffer[0],
m_stream.userBuffer[1],
m_stream.bufferSize,
streamTime,
status,
info->userData);
int32_t cbReturnValue = info->callback(m_stream.userBuffer[0],
m_stream.userBuffer[1],
m_stream.bufferSize,
streamTime,
status);
if (cbReturnValue == 2) {
m_stream.state = STREAM_STOPPING;
handle->drainCounter = 2;

View File

@ -67,7 +67,7 @@ airtaudio::api::CoreIos::~CoreIos(void) {
ATA_INFO("Destroy CoreIOs interface");
AudioUnitUninitialize(m_private->audioUnit);
delete m_private;
m_private = NULL;
m_private = nullptr;
}
uint32_t airtaudio::api::CoreIos::getDeviceCount(void) {
@ -124,24 +124,21 @@ void airtaudio::api::CoreIos::callBackEvent(void* _data,
return;
#endif
int32_t doStopStream = 0;
airtaudio::AirTAudioCallback callback = (airtaudio::AirTAudioCallback) m_stream.callbackInfo.callback;
double streamTime = getStreamTime();
airtaudio::streamStatus status = 0;
if (m_stream.doConvertBuffer[OUTPUT] == true) {
doStopStream = callback(m_stream.userBuffer[OUTPUT],
NULL,
_frameRate,
streamTime,
status,
m_stream.callbackInfo.userData);
doStopStream = m_stream.callbackInfo.callback(m_stream.userBuffer[OUTPUT],
nullptr,
_frameRate,
streamTime,
status);
convertBuffer((char*)_data, (char*)m_stream.userBuffer[OUTPUT], m_stream.convertInfo[OUTPUT]);
} else {
doStopStream = callback(_data,
NULL,
_frameRate,
streamTime,
status,
m_stream.callbackInfo.userData);
doStopStream = m_stream.callbackInfo.callback(_data,
nullptr,
_frameRate,
streamTime,
status);
}
if (doStopStream == 2) {
abortStream();
@ -156,8 +153,8 @@ static OSStatus playbackCallback(void *_userData,
uint32_t inBusNumber,
uint32_t inNumberFrames,
AudioBufferList *ioData) {
if (_userData == NULL) {
ATA_ERROR("callback event ... NULL pointer");
if (_userData == nullptr) {
ATA_ERROR("callback event ... nullptr pointer");
return -1;
}
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.
uint64_t bufferBytes = m_stream.nUserChannels[_mode] * m_stream.bufferSize * formatBytes(m_stream.userFormat);
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.");
}
setConvertInfo(_mode, _firstChannel);
@ -238,7 +235,7 @@ bool airtaudio::api::CoreIos::probeDeviceOpen(uint32_t _device,
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
// Get component
AudioComponent inputComponent = AudioComponentFindNext(NULL, &desc);
AudioComponent inputComponent = AudioComponentFindNext(nullptr, &desc);
// Get audio units
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
// accept whatever the mainline chose for a threading model.
m_coInitialized = false;
HRESULT hr = CoInitialize(NULL);
HRESULT hr = CoInitialize(nullptr);
if (!FAILED(hr)) {
m_coInitialized = true;
}
@ -196,7 +196,7 @@ rtaudio::DeviceInfo airtaudio::api::Ds::getDeviceInfo(uint32_t _device) {
}
LPDIRECTSOUND output;
DSCAPS outCaps;
result = DirectSoundCreate(dsDevices[ _device ].id[0], &output, NULL);
result = DirectSoundCreate(dsDevices[ _device ].id[0], &output, nullptr);
if (FAILED(result)) {
ATA_ERROR("airtaudio::api::Ds::getDeviceInfo: error (" << getErrorString(result) << ") opening output device (" << dsDevices[ _device ].name << ")!");
goto probeInput;
@ -236,7 +236,7 @@ rtaudio::DeviceInfo airtaudio::api::Ds::getDeviceInfo(uint32_t _device) {
}
probeInput:
LPDIRECTSOUNDCAPTURE input;
result = DirectSoundCaptureCreate(dsDevices[ _device ].id[1], &input, NULL);
result = DirectSoundCaptureCreate(dsDevices[ _device ].id[1], &input, nullptr);
if (FAILED(result)) {
ATA_ERROR("airtaudio::api::Ds::getDeviceInfo: error (" << getErrorString(result) << ") opening input device (" << dsDevices[ _device ].name << ")!");
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
// low for capture, but it should work for playback.
int32_t nBuffers = 0;
if (_options != NULL) {
if (_options != nullptr) {
nBuffers = _options->numberOfBuffers;
}
if ( _options!= NULL
if ( _options!= nullptr
&& _options->flags & RTAUDIO_MINIMIZE_LATENCY) {
nBuffers = 2;
}
@ -469,7 +469,7 @@ bool airtaudio::api::Ds::probeDeviceOpen(uint32_t _device,
HRESULT result;
if (_mode == OUTPUT) {
LPDIRECTSOUND output;
result = DirectSoundCreate(dsDevices[ _device ].id[0], &output, NULL);
result = DirectSoundCreate(dsDevices[ _device ].id[0], &output, nullptr);
if (FAILED(result)) {
ATA_ERROR("airtaudio::api::Ds::probeDeviceOpen: error (" << getErrorString(result) << ") opening output device (" << dsDevices[ _device ].name << ")!");
return false;
@ -526,7 +526,7 @@ bool airtaudio::api::Ds::probeDeviceOpen(uint32_t _device,
bufferDescription.dwFlags = DSBCAPS_PRIMARYBUFFER;
// Obtain the primary buffer
LPDIRECTSOUNDBUFFER buffer;
result = output->CreateSoundBuffer(&bufferDescription, &buffer, NULL);
result = output->CreateSoundBuffer(&bufferDescription, &buffer, nullptr);
if (FAILED(result)) {
output->Release();
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;
// Try to create the secondary DS buffer. If that doesn't work,
// 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)) {
bufferDescription.dwFlags = ( DSBCAPS_STICKYFOCUS
| DSBCAPS_GLOBALFOCUS
| DSBCAPS_GETCURRENTPOSITION2
| DSBCAPS_LOCSOFTWARE); // Force software mixing
result = output->CreateSoundBuffer(&bufferDescription, &buffer, NULL);
result = output->CreateSoundBuffer(&bufferDescription, &buffer, nullptr);
if (FAILED(result)) {
output->Release();
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
LPVOID audioPtr;
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)) {
output->Release();
buffer->Release();
@ -587,7 +587,7 @@ bool airtaudio::api::Ds::probeDeviceOpen(uint32_t _device,
// Zero the DS buffer
ZeroMemory(audioPtr, dataLen);
// Unlock the DS buffer
result = buffer->Unlock(audioPtr, dataLen, NULL, 0);
result = buffer->Unlock(audioPtr, dataLen, nullptr, 0);
if (FAILED(result)) {
output->Release();
buffer->Release();
@ -599,7 +599,7 @@ bool airtaudio::api::Ds::probeDeviceOpen(uint32_t _device,
}
if (_mode == INPUT) {
LPDIRECTSOUNDCAPTURE input;
result = DirectSoundCaptureCreate(dsDevices[ _device ].id[1], &input, NULL);
result = DirectSoundCaptureCreate(dsDevices[ _device ].id[1], &input, nullptr);
if (FAILED(result)) {
ATA_ERROR("airtaudio::api::Ds::probeDeviceOpen: error (" << getErrorString(result) << ") opening input device (" << dsDevices[ _device ].name << ")!");
return false;
@ -659,7 +659,7 @@ bool airtaudio::api::Ds::probeDeviceOpen(uint32_t _device,
bufferDescription.lpwfxFormat = &waveFormat;
// Create the capture buffer.
LPDIRECTSOUNDCAPTUREBUFFER buffer;
result = input->CreateCaptureBuffer(&bufferDescription, &buffer, NULL);
result = input->CreateCaptureBuffer(&bufferDescription, &buffer, nullptr);
if (FAILED(result)) {
input->Release();
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
LPVOID audioPtr;
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)) {
input->Release();
buffer->Release();
@ -693,7 +693,7 @@ bool airtaudio::api::Ds::probeDeviceOpen(uint32_t _device,
// Zero the buffer
ZeroMemory(audioPtr, dataLen);
// Unlock the buffer
result = buffer->Unlock(audioPtr, dataLen, NULL, 0);
result = buffer->Unlock(audioPtr, dataLen, nullptr, 0);
if (FAILED(result)) {
input->Release();
buffer->Release();
@ -710,7 +710,7 @@ bool airtaudio::api::Ds::probeDeviceOpen(uint32_t _device,
m_stream.bufferSize = *_bufferSize;
m_stream.channelOffset[_mode] = _firstChannel;
m_stream.deviceInterleaved[_mode] = true;
if ( _options != NULL
if ( _options != nullptr
&& _options->flags & RTAUDIO_NONINTERLEAVED) {
m_stream.userInterleaved = false;
} else {
@ -731,7 +731,7 @@ bool airtaudio::api::Ds::probeDeviceOpen(uint32_t _device,
// Allocate necessary internal buffers
long bufferBytes = m_stream.nUserChannels[_mode] * *_bufferSize * formatBytes(m_stream.userFormat);
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.");
goto error;
}
@ -752,7 +752,7 @@ bool airtaudio::api::Ds::probeDeviceOpen(uint32_t _device,
free(m_stream.deviceBuffer);
}
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.");
goto error;
}
@ -761,15 +761,15 @@ bool airtaudio::api::Ds::probeDeviceOpen(uint32_t _device,
// Allocate our DsHandle structures for the stream.
if (m_stream.apiHandle == 0) {
handle = new DsHandle;
if (handle == NULL) {
if (handle == nullptr) {
ATA_ERROR("airtaudio::api::Ds::probeDeviceOpen: error allocating AsioHandle memory.");
goto error;
}
// Create a manual-reset event.
handle->condition = CreateEvent(NULL, // no security
handle->condition = CreateEvent(nullptr, // no security
TRUE, // manual-reset
FALSE, // non-signaled initially
NULL); // unnamed
nullptr); // unnamed
m_stream.apiHandle = (void *) handle;
} else {
handle = (DsHandle *) m_stream.apiHandle;
@ -798,7 +798,7 @@ bool airtaudio::api::Ds::probeDeviceOpen(uint32_t _device,
unsigned threadId;
m_stream.callbackInfo.isRunning = true;
m_stream.callbackInfo.object = (void *) this;
m_stream.callbackInfo.thread = _beginthreadex(NULL,
m_stream.callbackInfo.thread = _beginthreadex(nullptr,
0,
&callbackHandler,
&m_stream.callbackInfo,
@ -815,7 +815,7 @@ bool airtaudio::api::Ds::probeDeviceOpen(uint32_t _device,
error:
if (handle) {
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];
LPDIRECTSOUNDBUFFER buffer = (LPDIRECTSOUNDBUFFER) handle->buffer[0];
if (buffer) {
@ -826,7 +826,7 @@ error:
if (handle->buffer[1]) {
LPDIRECTSOUNDCAPTURE object = (LPDIRECTSOUNDCAPTURE) handle->id[1];
LPDIRECTSOUNDCAPTUREBUFFER buffer = (LPDIRECTSOUNDCAPTUREBUFFER) handle->buffer[1];
if (buffer != NULL) {
if (buffer != nullptr) {
buffer->Release();
}
}
@ -859,7 +859,7 @@ enum airtaudio::errorType airtaudio::api::Ds::closeStream() {
CloseHandle((HANDLE) m_stream.callbackInfo.thread);
DsHandle *handle = (DsHandle *) m_stream.apiHandle;
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];
LPDIRECTSOUNDBUFFER buffer = (LPDIRECTSOUNDBUFFER) handle->buffer[0];
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,
// 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)) {
ATA_ERROR("airtaudio::api::Ds::stopStream: error (" << getErrorString(result) << ") locking output buffer!");
goto unlock;
@ -980,7 +980,7 @@ enum airtaudio::errorType airtaudio::api::Ds::stopStream() {
// Zero the DS buffer
ZeroMemory(audioPtr, dataLen);
// Unlock the DS buffer
result = buffer->Unlock(audioPtr, dataLen, NULL, 0);
result = buffer->Unlock(audioPtr, dataLen, nullptr, 0);
if (FAILED(result)) {
ATA_ERROR("airtaudio::api::Ds::stopStream: error (" << getErrorString(result) << ") unlocking output buffer!");
goto unlock;
@ -991,7 +991,7 @@ enum airtaudio::errorType airtaudio::api::Ds::stopStream() {
if ( m_stream.mode == INPUT
|| m_stream.mode == DUPLEX) {
LPDIRECTSOUNDCAPTUREBUFFER buffer = (LPDIRECTSOUNDCAPTUREBUFFER) handle->buffer[1];
audioPtr = NULL;
audioPtr = nullptr;
dataLen = 0;
m_stream.state = STREAM_STOPPED;
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,
// 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)) {
ATA_ERROR("airtaudio::api::Ds::stopStream: error (" << getErrorString(result) << ") locking input buffer!");
goto unlock;
@ -1009,7 +1009,7 @@ enum airtaudio::errorType airtaudio::api::Ds::stopStream() {
// Zero the DS buffer
ZeroMemory(audioPtr, dataLen);
// Unlock the DS buffer
result = buffer->Unlock(audioPtr, dataLen, NULL, 0);
result = buffer->Unlock(audioPtr, dataLen, nullptr, 0);
if (FAILED(result)) {
ATA_ERROR("airtaudio::api::Ds::stopStream: error (" << getErrorString(result) << ") unlocking input buffer!");
goto unlock;
@ -1062,7 +1062,6 @@ void airtaudio::api::Ds::callbackEvent() {
// Invoke user callback to get fresh output data UNLESS we are
// draining stream.
if (handle->drainCounter == 0) {
airtaudio::AirTAudioCallback callback = (airtaudio::AirTAudioCallback) info->callback;
double streamTime = getStreamTime();
rtaudio::streamStatus status = 0;
if ( m_stream.mode != INPUT
@ -1075,12 +1074,11 @@ void airtaudio::api::Ds::callbackEvent() {
status |= RTAUDIO_INPUT_OVERFLOW;
handle->xrun[1] = false;
}
int32_t cbReturnValue = callback(m_stream.userBuffer[0],
m_stream.userBuffer[1],
m_stream.bufferSize,
streamTime,
status,
info->userData);
int32_t cbReturnValue = info->callback(m_stream.userBuffer[0],
m_stream.userBuffer[1],
m_stream.bufferSize,
streamTime,
status);
if (cbReturnValue == 2) {
m_stream.state = STREAM_STOPPING;
handle->drainCounter = 2;
@ -1095,8 +1093,8 @@ void airtaudio::api::Ds::callbackEvent() {
DWORD currentWritePointer, safeWritePointer;
DWORD currentReadPointer, safeReadPointer;
UINT nextWritePointer;
LPVOID buffer1 = NULL;
LPVOID buffer2 = NULL;
LPVOID buffer1 = nullptr;
LPVOID buffer2 = nullptr;
DWORD bufferSize1 = 0;
DWORD bufferSize2 = 0;
char *buffer;
@ -1119,23 +1117,23 @@ void airtaudio::api::Ds::callbackEvent() {
LPDIRECTSOUNDBUFFER dsWriteBuffer = (LPDIRECTSOUNDBUFFER) handle->buffer[0];
LPDIRECTSOUNDCAPTUREBUFFER dsCaptureBuffer = (LPDIRECTSOUNDCAPTUREBUFFER) handle->buffer[1];
DWORD startSafeWritePointer, startSafeReadPointer;
result = dsWriteBuffer->GetCurrentPosition(NULL, &startSafeWritePointer);
result = dsWriteBuffer->GetCurrentPosition(nullptr, &startSafeWritePointer);
if (FAILED(result)) {
ATA_ERROR("airtaudio::api::Ds::callbackEvent: error (" << getErrorString(result) << ") getting current write position!");
return;
}
result = dsCaptureBuffer->GetCurrentPosition(NULL, &startSafeReadPointer);
result = dsCaptureBuffer->GetCurrentPosition(nullptr, &startSafeReadPointer);
if (FAILED(result)) {
ATA_ERROR("airtaudio::api::Ds::callbackEvent: error (" << getErrorString(result) << ") getting current read position!");
return;
}
while (true) {
result = dsWriteBuffer->GetCurrentPosition(NULL, &safeWritePointer);
result = dsWriteBuffer->GetCurrentPosition(nullptr, &safeWritePointer);
if (FAILED(result)) {
ATA_ERROR("airtaudio::api::Ds::callbackEvent: error (" << getErrorString(result) << ") getting current write position!");
return;
}
result = dsCaptureBuffer->GetCurrentPosition(NULL, &safeReadPointer);
result = dsCaptureBuffer->GetCurrentPosition(nullptr, &safeReadPointer);
if (FAILED(result)) {
ATA_ERROR("airtaudio::api::Ds::callbackEvent: error (" << getErrorString(result) << ") getting current read position!");
return;
@ -1256,7 +1254,7 @@ void airtaudio::api::Ds::callbackEvent() {
}
// Copy our buffer into the DS buffer
CopyMemory(buffer1, buffer, bufferSize1);
if (buffer2 != NULL) {
if (buffer2 != nullptr) {
CopyMemory(buffer2, buffer+bufferSize1, bufferSize2);
}
// Update our buffer offset and unlock sound buffer
@ -1374,12 +1372,12 @@ void airtaudio::api::Ds::callbackEvent() {
if (m_duplexPrerollBytes <= 0) {
// Copy our buffer into the DS buffer
CopyMemory(buffer, buffer1, bufferSize1);
if (buffer2 != NULL) {
if (buffer2 != nullptr) {
CopyMemory(buffer+bufferSize1, buffer2, bufferSize2);
}
} else {
memset(buffer, 0, bufferSize1);
if (buffer2 != NULL) {
if (buffer2 != nullptr) {
memset(buffer + bufferSize1, 0, bufferSize2);
}
m_duplexPrerollBytes -= bufferSize1 + bufferSize2;
@ -1424,9 +1422,9 @@ static unsigned __stdcall callbackHandler(void *_ptr) {
#include "tchar.h"
static std::string convertTChar(LPCTSTR _name) {
#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');
WideCharToMultiByte(CP_UTF8, 0, _name, -1, &s[0], length, NULL, NULL);
WideCharToMultiByte(CP_UTF8, 0, _name, -1, &s[0], length, nullptr, nullptr);
#else
std::string s(_name);
#endif
@ -1444,7 +1442,7 @@ static BOOL CALLBACK deviceQueryCallback(LPGUID _lpguid,
if (probeInfo.isInput == true) {
DSCCAPS caps;
LPDIRECTSOUNDCAPTURE object;
hr = DirectSoundCaptureCreate(_lpguid, &object, NULL);
hr = DirectSoundCaptureCreate(_lpguid, &object, nullptr);
if (hr != DS_OK) {
return TRUE;
}
@ -1459,7 +1457,7 @@ static BOOL CALLBACK deviceQueryCallback(LPGUID _lpguid,
} else {
DSCAPS caps;
LPDIRECTSOUND object;
hr = DirectSoundCreate(_lpguid, &object, NULL);
hr = DirectSoundCreate(_lpguid, &object, nullptr);
if (hr != DS_OK) {
return TRUE;
}
@ -1476,7 +1474,7 @@ static BOOL CALLBACK deviceQueryCallback(LPGUID _lpguid,
// If good device, then save its name and guid.
std::string name = convertTChar(_description);
//if (name == "Primary Sound Driver" || name == "Primary Sound Capture Driver")
if (_lpguid == NULL) {
if (_lpguid == nullptr) {
name = "Default Device";
}
if (validDevice) {

View File

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

View File

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

View File

@ -108,22 +108,22 @@ enum airtaudio::errorType airtaudio::api::Pulse::closeStream() {
m_stream.mutex.unlock();
pah->thread->join();
if (pah->s_play) {
pa_simple_flush(pah->s_play, NULL);
pa_simple_flush(pah->s_play, nullptr);
pa_simple_free(pah->s_play);
}
if (pah->s_rec) {
pa_simple_free(pah->s_rec);
}
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]);
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]);
m_stream.userBuffer[1] = NULL;
m_stream.userBuffer[1] = nullptr;
}
m_stream.state = STREAM_CLOSED;
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!");
return;
}
airtaudio::AirTAudioCallback callback = (airtaudio::AirTAudioCallback) m_stream.callbackInfo.callback;
double streamTime = getStreamTime();
airtaudio::streamStatus status = 0;
int32_t doStopStream = callback(m_stream.userBuffer[OUTPUT],
m_stream.userBuffer[INPUT],
m_stream.bufferSize,
streamTime,
status,
m_stream.callbackInfo.userData);
int32_t doStopStream = m_stream.callbackInfo.callback(m_stream.userBuffer[OUTPUT],
m_stream.userBuffer[INPUT],
m_stream.bufferSize,
streamTime,
status);
if (doStopStream == 2) {
abortStream();
return;
@ -346,7 +344,7 @@ bool airtaudio::api::Pulse::probeDeviceOpen(uint32_t _device,
// Allocate necessary internal buffers.
bufferBytes = m_stream.nUserChannels[_mode] * *_bufferSize * formatBytes(m_stream.userFormat);
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.");
goto error;
}
@ -364,7 +362,7 @@ bool airtaudio::api::Pulse::probeDeviceOpen(uint32_t _device,
bufferBytes *= *_bufferSize;
if (m_stream.deviceBuffer) free(m_stream.deviceBuffer);
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.");
goto error;
}
@ -387,14 +385,14 @@ bool airtaudio::api::Pulse::probeDeviceOpen(uint32_t _device,
int32_t error;
switch (_mode) {
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) {
ATA_ERROR("airtaudio::api::Pulse::probeDeviceOpen: error connecting input to PulseAudio server.");
goto error;
}
break;
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) {
ATA_ERROR("airtaudio::api::Pulse::probeDeviceOpen: error connecting output to PulseAudio server.");
goto error;
@ -414,7 +412,7 @@ bool airtaudio::api::Pulse::probeDeviceOpen(uint32_t _device,
m_stream.callbackInfo.object = this;
m_stream.callbackInfo.isRunning = true;
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.");
goto error;
}

View File

@ -12,6 +12,7 @@
#include <thread>
#include <condition_variable>
#include <mutex>
#include <functional>
// defien type : uintXX_t and intXX_t
#define __STDC_LIMIT_MACROS
@ -158,13 +159,13 @@ namespace airtaudio {
* should write \c nFrames of audio sample frames into this
* buffer. This argument should be recast to the datatype
* 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
* hold \c nFrames of input audio sample frames. This
* argument should be recast to the datatype specified when the
* 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
* 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
* 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
* 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
* the stream immediately, the client should return a value of two.
*/
typedef int32_t (*AirTAudioCallback)(void *_outputBuffer,
void *_inputBuffer,
uint32_t _nFrames,
double _streamTime,
airtaudio::streamStatus _status,
void *_userData);
typedef std::function<int32_t (void* _outputBuffer,
const void* const _inputBuffer,
uint32_t _nFrames,
double _streamTime,
airtaudio::streamStatus _status)> AirTAudioCallback;
}
#include <airtaudio/DeviceInfo.h>

View File

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