|
|
@@ -367,7 +367,7 @@ double RtApi :: getStreamTime( void ) |
|
|
|
then = stream_.lastTickTimestamp;
|
|
|
|
return stream_.streamTime +
|
|
|
|
((now.tv_sec + 0.000001 * now.tv_usec) -
|
|
|
|
(then.tv_sec + 0.000001 * then.tv_usec));
|
|
|
|
(then.tv_sec + 0.000001 * then.tv_usec));
|
|
|
|
#else
|
|
|
|
return stream_.streamTime;
|
|
|
|
#endif
|
|
|
@@ -741,7 +741,7 @@ OSStatus callbackHandler( AudioDeviceID inDevice, |
|
|
|
const AudioBufferList* inInputData,
|
|
|
|
const AudioTimeStamp* inInputTime,
|
|
|
|
AudioBufferList* outOutputData,
|
|
|
|
const AudioTimeStamp* inOutputTime,
|
|
|
|
const AudioTimeStamp* inOutputTime,
|
|
|
|
void* infoPointer )
|
|
|
|
{
|
|
|
|
CallbackInfo *info = (CallbackInfo *) infoPointer;
|
|
|
@@ -1710,7 +1710,7 @@ bool RtApiCore :: callbackEvent( AudioDeviceID deviceId, |
|
|
|
channelsLeft -= streamChannels;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ( stream_.doConvertBuffer[1] ) { // convert from our internal "device" buffer
|
|
|
|
convertBuffer( stream_.userBuffer[1],
|
|
|
|
stream_.deviceBuffer,
|
|
|
@@ -2583,7 +2583,7 @@ RtApiAsio :: RtApiAsio() |
|
|
|
// CoInitialize beforehand, but it must be for appartment threading
|
|
|
|
// (in which case, CoInitilialize will return S_FALSE here).
|
|
|
|
coInitialized_ = false;
|
|
|
|
HRESULT hr = CoInitialize( NULL );
|
|
|
|
HRESULT hr = CoInitialize( NULL );
|
|
|
|
if ( FAILED(hr) ) {
|
|
|
|
errorText_ = "RtApiAsio::ASIO requires a single-threaded appartment. Call CoInitializeEx(0,COINIT_APARTMENTTHREADED)";
|
|
|
|
error( RtError::WARNING );
|
|
|
@@ -2934,7 +2934,7 @@ bool RtApiAsio :: probeDeviceOpen( unsigned int device, StreamMode mode, unsigne |
|
|
|
handle = new AsioHandle;
|
|
|
|
}
|
|
|
|
catch ( std::bad_alloc& ) {
|
|
|
|
//if ( handle == NULL ) {
|
|
|
|
//if ( handle == NULL ) {
|
|
|
|
drivers.removeCurrentDriver();
|
|
|
|
errorText_ = "RtApiAsio::probeDeviceOpen: error allocating AsioHandle memory.";
|
|
|
|
return FAILURE;
|
|
|
@@ -3470,13 +3470,13 @@ long asioMessages( long selector, long value, void* message, double* opt ) |
|
|
|
|
|
|
|
static const char* getAsioErrorString( ASIOError result )
|
|
|
|
{
|
|
|
|
struct Messages
|
|
|
|
struct Messages
|
|
|
|
{
|
|
|
|
ASIOError value;
|
|
|
|
const char*message;
|
|
|
|
};
|
|
|
|
|
|
|
|
static Messages m[] =
|
|
|
|
static Messages m[] =
|
|
|
|
{
|
|
|
|
{ ASE_NotPresent, "Hardware input or output is not present or available." },
|
|
|
|
{ ASE_HWMalfunction, "Hardware is malfunctioning." },
|
|
|
@@ -3499,7 +3499,7 @@ static const char* getAsioErrorString( ASIOError result ) |
|
|
|
#if defined(__WINDOWS_DS__) // Windows DirectSound API
|
|
|
|
|
|
|
|
// Modified by Robin Davies, October 2005
|
|
|
|
// - Improvements to DirectX pointer chasing.
|
|
|
|
// - Improvements to DirectX pointer chasing.
|
|
|
|
// - Bug fix for non-power-of-two Asio granularity used by Edirol PCR-A30.
|
|
|
|
// - Auto-call CoInitialize for DSOUND and ASIO platforms.
|
|
|
|
// Various revisions for RtAudio 4.0 by Gary Scavone, April 2007
|
|
|
@@ -3539,7 +3539,7 @@ struct DsHandle { |
|
|
|
void *id[2];
|
|
|
|
void *buffer[2];
|
|
|
|
bool xrun[2];
|
|
|
|
UINT bufferPointer[2];
|
|
|
|
UINT bufferPointer[2];
|
|
|
|
DWORD dsBufferSize[2];
|
|
|
|
DWORD dsPointerLeadTime[2]; // the number of bytes ahead of the safe pointer to lead by.
|
|
|
|
HANDLE condition;
|
|
|
@@ -4377,7 +4377,7 @@ void RtApiDs :: startStream() |
|
|
|
// Increase scheduler frequency on lesser windows (a side-effect of
|
|
|
|
// increasing timer accuracy). On greater windows (Win2K or later),
|
|
|
|
// this is already in effect.
|
|
|
|
timeBeginPeriod( 1 );
|
|
|
|
timeBeginPeriod( 1 );
|
|
|
|
|
|
|
|
buffersRolling = false;
|
|
|
|
duplexPrerollBytes = 0;
|
|
|
@@ -4675,7 +4675,7 @@ void RtApiDs :: callbackEvent() |
|
|
|
}
|
|
|
|
|
|
|
|
if ( stream_.mode == OUTPUT || stream_.mode == DUPLEX ) {
|
|
|
|
|
|
|
|
|
|
|
|
LPDIRECTSOUNDBUFFER dsBuffer = (LPDIRECTSOUNDBUFFER) handle->buffer[0];
|
|
|
|
|
|
|
|
if ( handle->drainCounter > 1 ) { // write zeros to the output stream
|
|
|
@@ -4740,7 +4740,7 @@ void RtApiDs :: callbackEvent() |
|
|
|
}
|
|
|
|
|
|
|
|
if ( dsPointerBetween( nextWritePointer, safeWritePointer, currentWritePointer, dsBufferSize )
|
|
|
|
|| dsPointerBetween( endWrite, safeWritePointer, currentWritePointer, dsBufferSize ) ) {
|
|
|
|
|| dsPointerBetween( endWrite, safeWritePointer, currentWritePointer, dsBufferSize ) ) {
|
|
|
|
// We've strayed into the forbidden zone ... resync the read pointer.
|
|
|
|
handle->xrun[0] = true;
|
|
|
|
nextWritePointer = safeWritePointer + handle->dsPointerLeadTime[0] - bufferBytes;
|
|
|
@@ -4807,14 +4807,14 @@ void RtApiDs :: callbackEvent() |
|
|
|
if ( safeReadPointer < (DWORD)nextReadPointer ) safeReadPointer += dsBufferSize; // unwrap offset
|
|
|
|
DWORD endRead = nextReadPointer + bufferBytes;
|
|
|
|
|
|
|
|
// Handling depends on whether we are INPUT or DUPLEX.
|
|
|
|
// Handling depends on whether we are INPUT or DUPLEX.
|
|
|
|
// If we're in INPUT mode then waiting is a good thing. If we're in DUPLEX mode,
|
|
|
|
// then a wait here will drag the write pointers into the forbidden zone.
|
|
|
|
//
|
|
|
|
// In DUPLEX mode, rather than wait, we will back off the read pointer until
|
|
|
|
// it's in a safe position. This causes dropouts, but it seems to be the only
|
|
|
|
// practical way to sync up the read and write pointers reliably, given the
|
|
|
|
// the very complex relationship between phase and increment of the read and write
|
|
|
|
//
|
|
|
|
// In DUPLEX mode, rather than wait, we will back off the read pointer until
|
|
|
|
// it's in a safe position. This causes dropouts, but it seems to be the only
|
|
|
|
// practical way to sync up the read and write pointers reliably, given the
|
|
|
|
// the very complex relationship between phase and increment of the read and write
|
|
|
|
// pointers.
|
|
|
|
//
|
|
|
|
// In order to minimize audible dropouts in DUPLEX mode, we will
|
|
|
@@ -4863,7 +4863,7 @@ void RtApiDs :: callbackEvent() |
|
|
|
errorText_ = errorStream_.str();
|
|
|
|
error( RtError::SYSTEM_ERROR );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ( safeReadPointer < (DWORD)nextReadPointer ) safeReadPointer += dsBufferSize; // unwrap offset
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -6040,7 +6040,7 @@ void RtApiAlsa :: stopStream() |
|
|
|
AlsaHandle *apiInfo = (AlsaHandle *) stream_.apiHandle;
|
|
|
|
snd_pcm_t **handle = (snd_pcm_t **) apiInfo->handles;
|
|
|
|
if ( stream_.mode == OUTPUT || stream_.mode == DUPLEX ) {
|
|
|
|
if ( apiInfo->synchronized )
|
|
|
|
if ( apiInfo->synchronized )
|
|
|
|
result = snd_pcm_drop( handle[0] );
|
|
|
|
else
|
|
|
|
result = snd_pcm_drain( handle[0] );
|
|
|
@@ -6697,14 +6697,14 @@ bool RtApiPulse::probeDeviceOpen( unsigned int device, StreamMode mode, |
|
|
|
int 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( NULL, options->streamName.c_str(), PA_STREAM_RECORD, NULL, "Record", &ss, NULL, NULL, &error );
|
|
|
|
if ( !pah->s_rec ) {
|
|
|
|
errorText_ = "RtApiPulse::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( NULL, options->streamName.c_str(), PA_STREAM_PLAYBACK, NULL, "Playback", &ss, NULL, NULL, &error );
|
|
|
|
if ( !pah->s_play ) {
|
|
|
|
errorText_ = "RtApiPulse::probeDeviceOpen: error connecting output to PulseAudio server.";
|
|
|
|
goto error;
|
|
|
@@ -6732,7 +6732,7 @@ bool RtApiPulse::probeDeviceOpen( unsigned int device, StreamMode mode, |
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
closeStream();
|
|
|
|
return false;
|
|
|
|