Browse Source

Version 3.0.3

tags/3.0.3
Gary Scavone Stephen Sinclair 11 years ago
parent
commit
0fbcd74a04
25 changed files with 1310 additions and 1445 deletions
  1. +262
    -177
      RtAudio.cpp
  2. +2
    -1
      RtAudio.h
  3. +0
    -0
      asio/asio.cpp
  4. +107
    -8
      asio/asio.h
  5. +0
    -0
      asio/asiodrivers.cpp
  6. +0
    -0
      asio/asiodrvr.h
  7. +0
    -0
      asio/asiolist.cpp
  8. +0
    -0
      asio/iasiodrv.h
  9. +563
    -0
      asio/iasiothiscallresolver.cpp
  10. +201
    -0
      asio/iasiothiscallresolver.h
  11. +25
    -17
      doc/doxygen/tutorial.txt
  12. +6
    -0
      doc/release.txt
  13. +0
    -955
      tests/Windows/asio.h
  14. +0
    -41
      tests/Windows/asiodrivers.h
  15. +0
    -46
      tests/Windows/asiolist.h
  16. +0
    -82
      tests/Windows/asiosys.h
  17. +18
    -10
      tests/Windows/call_inout.dsp
  18. +18
    -10
      tests/Windows/call_saw.dsp
  19. +0
    -38
      tests/Windows/ginclude.h
  20. +18
    -10
      tests/Windows/in_out.dsp
  21. +18
    -10
      tests/Windows/info.dsp
  22. +18
    -10
      tests/Windows/play_raw.dsp
  23. +18
    -10
      tests/Windows/play_saw.dsp
  24. +18
    -10
      tests/Windows/record_raw.dsp
  25. +18
    -10
      tests/Windows/twostreams.dsp

+ 262
- 177
RtAudio.cpp View File

@@ -37,13 +37,7 @@
*/
/************************************************************************/

// RtAudio: Version 3.0.2 (14 October 2005)

// Modified by Robin Davies, 1 October 2005
// - Improvements to DirectX pointer chasing.
// - Backdoor RtDsStatistics hook provides DirectX performance information.
// - Bug fix for non-power-of-two Asio granularity used by Edirol PCR-A30.
// - Auto-call CoInitialize for DSOUND and ASIO platforms.
// RtAudio: Version 3.0.3 (18 November 2005)

#include "RtAudio.h"
#include <iostream>
@@ -2742,11 +2736,35 @@ void RtApiJack :: initialize(void)
if ( (client = jack_client_new( "RtApiJack" )) == 0)
return;

RtApiDevice device;
// Determine the name of the device.
device.name = "Jack Server";
devices_.push_back(device);
nDevices_++;
/*
RtApiDevice device;
// Determine the name of the device.
device.name = "Jack Server";
devices_.push_back(device);
nDevices_++;
*/
const char **ports;
std::string port, prevPort;
unsigned int nChannels = 0;
ports = jack_get_ports( client, NULL, NULL, 0 );
if ( ports ) {
port = (char *) ports[ nChannels ];
unsigned int colonPos = 0;
do {
port = (char *) ports[ nChannels ];
if ( (colonPos = port.find(":")) != std::string::npos ) {
port = port.substr( 0, colonPos+1 );
if ( port != prevPort ) {
RtApiDevice device;
device.name = port;
devices_.push_back( device );
nDevices_++;
prevPort = port;
}
}
} while ( ports[++nChannels] );
free( ports );
}

jack_client_close(client);
}
@@ -2755,7 +2773,7 @@ void RtApiJack :: probeDeviceInfo(RtApiDevice *info)
{
// Look for jack server and try to become a client.
jack_client_t *client;
if ( (client = jack_client_new( "RtApiJack" )) == 0) {
if ( (client = jack_client_new( "RtApiJack_Probe" )) == 0) {
sprintf(message_, "RtApiJack: error connecting to Linux Jack server in probeDeviceInfo() (jack: %s)!",
jackmsg.c_str());
error(RtError::WARNING);
@@ -2771,7 +2789,7 @@ void RtApiJack :: probeDeviceInfo(RtApiDevice *info)
const char **ports;
char *port;
unsigned int nChannels = 0;
ports = jack_get_ports( client, NULL, NULL, JackPortIsInput );
ports = jack_get_ports( client, info->name.c_str(), NULL, JackPortIsInput );
if ( ports ) {
port = (char *) ports[nChannels];
while ( port )
@@ -2783,7 +2801,7 @@ void RtApiJack :: probeDeviceInfo(RtApiDevice *info)

// Jack "output ports" equal RtAudio input channels.
nChannels = 0;
ports = jack_get_ports( client, NULL, NULL, JackPortIsOutput );
ports = jack_get_ports( client, info->name.c_str(), NULL, JackPortIsOutput );
if ( ports ) {
port = (char *) ports[nChannels];
while ( port )
@@ -3178,7 +3196,7 @@ void RtApiJack :: startStream()
int result;
// Get the list of available ports.
if ( stream_.mode == OUTPUT || stream_.mode == DUPLEX ) {
ports = jack_get_ports(handle->client, NULL, NULL, JackPortIsPhysical|JackPortIsInput);
ports = jack_get_ports(handle->client, devices_[stream_.device[0]].name.c_str(), NULL, JackPortIsInput);
if ( ports == NULL) {
sprintf(message_, "RtApiJack: error determining available jack input ports!");
error(RtError::SYSTEM_ERROR);
@@ -3201,7 +3219,7 @@ void RtApiJack :: startStream()
}

if ( stream_.mode == INPUT || stream_.mode == DUPLEX ) {
ports = jack_get_ports( handle->client, NULL, NULL, JackPortIsPhysical|JackPortIsOutput );
ports = jack_get_ports( handle->client, devices_[stream_.device[1]].name.c_str(), NULL, JackPortIsOutput );
if ( ports == NULL) {
sprintf(message_, "RtApiJack: error determining available jack output ports!");
error(RtError::SYSTEM_ERROR);
@@ -4209,6 +4227,72 @@ void RtApiAlsa :: closeStream()
stream_.mode = UNINITIALIZED;
}

// Pump a bunch of zeros into the output buffer. This is needed only when we
// are doing duplex operations.
bool RtApiAlsa :: primeOutputBuffer()
{
int err;
char *buffer;
int channels;
snd_pcm_t **handle;
RtAudioFormat format;
AlsaHandle *apiInfo = (AlsaHandle *) stream_.apiHandle;
handle = (snd_pcm_t **) apiInfo->handles;
if (stream_.mode == DUPLEX) {

// Setup parameters and do buffer conversion if necessary.
if ( stream_.doConvertBuffer[0] ) {
convertBuffer( stream_.deviceBuffer, apiInfo->tempBuffer, stream_.convertInfo[0] );
channels = stream_.nDeviceChannels[0];
format = stream_.deviceFormat[0];
}
else {
channels = stream_.nUserChannels[0];
format = stream_.userFormat;
}

buffer = new char[stream_.bufferSize * formatBytes(format) * channels];
bzero(buffer, stream_.bufferSize * formatBytes(format) * channels);
for (int i=0; i<stream_.nBuffers; i++) {
// Write samples to device in interleaved/non-interleaved format.
if (stream_.deInterleave[0]) {
void *bufs[channels];
size_t offset = stream_.bufferSize * formatBytes(format);
for (int i=0; i<channels; i++)
bufs[i] = (void *) (buffer + (i * offset));
err = snd_pcm_writen(handle[0], bufs, stream_.bufferSize);
}
else
err = snd_pcm_writei(handle[0], buffer, stream_.bufferSize);
if (err < stream_.bufferSize) {
// Either an error or underrun occured.
if (err == -EPIPE) {
snd_pcm_state_t state = snd_pcm_state(handle[0]);
if (state == SND_PCM_STATE_XRUN) {
sprintf(message_, "RtApiAlsa: underrun detected while priming output buffer.");
return false;
}
else {
sprintf(message_, "RtApiAlsa: primeOutputBuffer() error, current state is %s.",
snd_pcm_state_name(state));
return false;
}
}
else {
sprintf(message_, "RtApiAlsa: audio write error for device (%s): %s.",
devices_[stream_.device[0]].name.c_str(), snd_strerror(err));
return false;
}
}
}
}

return true;
}

void RtApiAlsa :: startStream()
{
// This method calls snd_pcm_prepare if the device isn't already in that state.
@@ -4232,6 +4316,11 @@ void RtApiAlsa :: startStream()
MUTEX_UNLOCK(&stream_.mutex);
error(RtError::DRIVER_ERROR);
}
// Reprime output buffer if needed
if ( (stream_.mode == DUPLEX) && ( !primeOutputBuffer() ) ) {
MUTEX_UNLOCK(&stream_.mutex);
error(RtError::DRIVER_ERROR);
}
}
}

@@ -4247,6 +4336,11 @@ void RtApiAlsa :: startStream()
}
}
}

if ( (stream_.mode == DUPLEX) && ( !primeOutputBuffer() ) ) {
MUTEX_UNLOCK(&stream_.mutex);
error(RtError::DRIVER_ERROR);
}
stream_.state = STREAM_RUNNING;

MUTEX_UNLOCK(&stream_.mutex);
@@ -4441,6 +4535,11 @@ void RtApiAlsa :: tickStream()
MUTEX_UNLOCK(&stream_.mutex);
error(RtError::DRIVER_ERROR);
}
// Reprime output buffer if needed.
if ( (stream_.mode == DUPLEX) && ( !primeOutputBuffer() ) ) {
MUTEX_UNLOCK(&stream_.mutex);
error(RtError::DRIVER_ERROR);
}
}
else {
sprintf(message_, "RtApiAlsa: tickStream() error, current state is %s.",
@@ -4639,6 +4738,7 @@ extern "C" void *alsaCallbackHandler(void *ptr)

#include "asio/asiosys.h"
#include "asio/asio.h"
#include "asio/iasiothiscallresolver.h"
#include "asio/asiodrivers.h"
#include <math.h>

@@ -4656,7 +4756,7 @@ struct AsioHandle {
:stopStream(false), bufferInfos(0) {}
};

static const char*GetAsioErrorString(ASIOError result)
static const char* GetAsioErrorString( ASIOError result )
{
struct Messages
{
@@ -4674,10 +4774,9 @@ static const char*GetAsioErrorString(ASIOError result)
{ ASE_NoMemory, "Not enough memory to complete the request." }
};

for (int i = 0; i < sizeof(m)/sizeof(m[0]); ++i)
{
for (unsigned int i = 0; i < sizeof(m)/sizeof(m[0]); ++i)
if (m[i].value == result) return m[i].message;
}
return "Unknown error.";
}

@@ -4695,11 +4794,9 @@ RtApiAsio :: RtApiAsio()
RtApiAsio :: ~RtApiAsio()
{
if ( stream_.mode != UNINITIALIZED ) closeStream();

if ( coInitialized )
{
CoUninitialize();
}

}

void RtApiAsio :: initialize(void)
@@ -4709,8 +4806,7 @@ void RtApiAsio :: initialize(void)
// for appartment threading (in which case, CoInitilialize will return S_FALSE here).
coInitialized = false;
HRESULT hr = CoInitialize(NULL);
if (FAILED(hr))
{
if ( FAILED(hr) ) {
sprintf(message_,"RtApiAsio: ASIO requires a single-threaded appartment. Call CoInitializeEx(0,COINIT_APARTMENTTHREADED)");
}
coInitialized = true;
@@ -5573,29 +5669,24 @@ void RtApiAsio :: callbackEvent(long bufferIndex)
static inline DWORD dsPointerDifference(DWORD laterPointer,DWORD earlierPointer,DWORD bufferSize)
{
if (laterPointer > earlierPointer)
{
return laterPointer-earlierPointer;
} else
{
else
return laterPointer-earlierPointer+bufferSize;
}
}

static inline DWORD dsPointerBetween(DWORD pointer, DWORD laterPointer,DWORD earlierPointer, DWORD bufferSize)
{
if (pointer > bufferSize) pointer -= bufferSize;

if (laterPointer < earlierPointer)
{
laterPointer += bufferSize;
}
if (pointer < earlierPointer)
{
pointer += bufferSize;
}
return pointer >= earlierPointer && pointer < laterPointer;
}


#undef GENERATE_DEBUG_LOG // Define this to generate a debug timing log file in c:/rtaudiolog.txt"
#ifdef GENERATE_DEBUG_LOG

@@ -5637,38 +5728,34 @@ RtApiDs::RtDsStatistics RtApiDs::getDsStatistics()

if (s.inputFrameSize != 0)
{
s.latency += s.readDeviceSafeLeadBytes*1.0/s.inputFrameSize / s.sampleRate;
}
if (s.outputFrameSize != 0)
{
s.latency +=
(s.writeDeviceSafeLeadBytes+ s.writeDeviceBufferLeadBytes)*1.0/s.outputFrameSize / s.sampleRate;
}
s.latency += (s.writeDeviceSafeLeadBytes+ s.writeDeviceBufferLeadBytes)*1.0/s.outputFrameSize / s.sampleRate;

return s;
}


// Declarations for utility functions, callbacks, and structures
// specific to the DirectSound implementation.
static bool CALLBACK deviceCountCallback(LPGUID lpguid,
LPCSTR lpcstrDescription,
LPCSTR lpcstrModule,
LPCTSTR description,
LPCTSTR module,
LPVOID lpContext);

static bool CALLBACK deviceInfoCallback(LPGUID lpguid,
LPCSTR lpcstrDescription,
LPCSTR lpcstrModule,
LPCTSTR description,
LPCTSTR module,
LPVOID lpContext);

static bool CALLBACK defaultDeviceCallback(LPGUID lpguid,
LPCSTR lpcstrDescription,
LPCSTR lpcstrModule,
LPCTSTR description,
LPCTSTR module,
LPVOID lpContext);

static bool CALLBACK deviceIdCallback(LPGUID lpguid,
LPCSTR lpcstrDescription,
LPCSTR lpcstrModule,
LPCTSTR description,
LPCTSTR module,
LPVOID lpContext);

static char* getErrorString(int code);
@@ -5676,7 +5763,7 @@ static char* getErrorString(int code);
extern "C" unsigned __stdcall callbackHandler(void *ptr);

struct enum_info {
char name[64];
std::string name;
LPGUID id;
bool isInput;
bool isValid;
@@ -5684,13 +5771,12 @@ struct enum_info {

RtApiDs :: RtApiDs()
{
// Dsound will run both-threaded. If CoInitialize fails, then just accept whatever the mainline
// chose for a threading model.
// Dsound will run both-threaded. If CoInitialize fails, then just
// accept whatever the mainline chose for a threading model.
coInitialized = false;
HRESULT hr = CoInitialize(NULL);
if (!FAILED(hr)) {
if ( !FAILED(hr) )
coInitialized = true;
}

this->initialize();

@@ -5703,16 +5789,14 @@ RtApiDs :: RtApiDs()
RtApiDs :: ~RtApiDs()
{
if (coInitialized)
{
CoUninitialize(); // balanced call.
}
if ( stream_.mode != UNINITIALIZED ) closeStream();
}

int RtApiDs :: getDefaultInputDevice(void)
{
enum_info info;
info.name[0] = '\0';

// Enumerate through devices to find the default output.
HRESULT result = DirectSoundCaptureEnumerate((LPDSENUMCALLBACK)defaultDeviceCallback, &info);
@@ -5724,10 +5808,9 @@ int RtApiDs :: getDefaultInputDevice(void)
}

for ( int i=0; i<nDevices_; i++ ) {
if ( strncmp( info.name, devices_[i].name.c_str(), 64 ) == 0 ) return i;
if ( info.name == devices_[i].name ) return i;
}


return 0;
}

@@ -5746,7 +5829,7 @@ int RtApiDs :: getDefaultOutputDevice(void)
}

for ( int i=0; i<nDevices_; i++ )
if ( strncmp( info.name, devices_[i].name.c_str(), 64 ) == 0 ) return i;
if ( info.name == devices_[i].name ) return i;

return 0;
}
@@ -5778,7 +5861,6 @@ void RtApiDs :: initialize(void)

std::vector<enum_info> info(count);
for (i=0; i<count; i++) {
info[i].name[0] = '\0';
if (i < outs) info[i].isInput = false;
else info[i].isInput = true;
}
@@ -5804,11 +5886,10 @@ void RtApiDs :: initialize(void)
// opened, they report < 1 supported channels, or they report no
// supported data (capture only).
RtApiDevice device;
int index = 0;
for (i=0; i<count; i++) {
if ( info[i].isValid ) {
device.name.erase();
device.name.append( (const char *)info[i].name, strlen(info[i].name)+1);
device.name = info[i].name;
devices_.push_back(device);
}
}
@@ -5820,7 +5901,7 @@ void RtApiDs :: initialize(void)
void RtApiDs :: probeDeviceInfo(RtApiDevice *info)
{
enum_info dsinfo;
strncpy( dsinfo.name, info->name.c_str(), 64 );
dsinfo.name = info->name;
dsinfo.isValid = false;

// Enumerate through input devices to find the id (if it exists).
@@ -6073,32 +6154,25 @@ bool RtApiDs :: probeDeviceOpen( int device, StreamMode mode, int channels,
waveFormat.nBlockAlign = waveFormat.nChannels * waveFormat.wBitsPerSample / 8;
waveFormat.nAvgBytesPerSec = waveFormat.nSamplesPerSec * waveFormat.nBlockAlign;

// Determine the device buffer size. By default, 32k,
// but we will grow it to make allowances for very large softare buffer sizes.
// Determine the device buffer size. By default, 32k, but we will
// grow it to make allowances for very large software buffer sizes.
DWORD dsBufferSize = 0;
DWORD dsPointerLeadTime = 0;

buffer_size = MINIMUM_DEVICE_BUFFER_SIZE; // sound cards will always *knock wood* support this


// poisonously large buffer lead time? Then increase the device buffer size accordingly.
while (dsPointerLeadTime *2U > (DWORD)buffer_size)
{
buffer_size *= 2;
}



enum_info dsinfo;
void *ohandle = 0, *bhandle = 0;
strncpy( dsinfo.name, devices_[device].name.c_str(), 64 );
// strncpy( dsinfo.name, devices_[device].name.c_str(), 64 );
dsinfo.name = devices_[device].name;
dsinfo.isValid = false;
if ( mode == OUTPUT ) {
dsPointerLeadTime = (numberOfBuffers) *
(*bufferSize) *
(waveFormat.wBitsPerSample / 8)
*channels;

dsPointerLeadTime = numberOfBuffers * (*bufferSize) * (waveFormat.wBitsPerSample / 8) * channels;

// If the user wants an even bigger buffer, increase the device buffer size accordingly.
while ( dsPointerLeadTime * 2U > (DWORD)buffer_size )
buffer_size *= 2;

if ( devices_[device].maxOutputChannels < channels ) {
sprintf(message_, "RtApiDs: requested channels (%d) > than supported (%d) by device (%s).",
@@ -6595,18 +6669,16 @@ void RtApiDs :: startStream()
verifyStream();
if (stream_.state == STREAM_RUNNING) return;

// increase scheduler frequency on lesser windows (a side-effect of increasing timer accuracy.
// on greater windows (Win2K or later), this is already in effect.
// Increase scheduler frequency on lesser windows (a side-effect of
// increasing timer accuracy). On greater windows (Win2K or later),
// this is already in effect.

MUTEX_LOCK(&stream_.mutex);

DsHandle *handles = (DsHandle *) stream_.apiHandle;

timeBeginPeriod(1);


memset(&statistics,0,sizeof(statistics));
statistics.sampleRate = stream_.sampleRate;
statistics.writeDeviceBufferLeadBytes = handles[0].dsPointerLeadTime ;
@@ -6614,8 +6686,7 @@ void RtApiDs :: startStream()
buffersRolling = false;
duplexPrerollBytes = 0;

if (stream_.mode == DUPLEX)
{
if (stream_.mode == DUPLEX) {
// 0.5 seconds of silence in DUPLEX mode while the devices spin up and synchronize.
duplexPrerollBytes = (int)(0.5*stream_.sampleRate*formatBytes( stream_.deviceFormat[1])*stream_.nDeviceChannels[1]);
}
@@ -6629,9 +6700,8 @@ void RtApiDs :: startStream()
statistics.outputFrameSize = formatBytes( stream_.deviceFormat[0])
*stream_.nDeviceChannels[0];


LPDIRECTSOUNDBUFFER buffer = (LPDIRECTSOUNDBUFFER) handles[0].buffer;
result = buffer->Play(0, 0, DSBPLAY_LOOPING );
result = buffer->Play( 0, 0, DSBPLAY_LOOPING );
if ( FAILED(result) ) {
sprintf(message_, "RtApiDs: Unable to start buffer (%s): %s.",
devices_[stream_.device[0]].name.c_str(), getErrorString(result));
@@ -6661,34 +6731,30 @@ void RtApiDs :: stopStream()
verifyStream();
if (stream_.state == STREAM_STOPPED) return;


// Change the state before the lock to improve shutdown response
// when using a callback.
stream_.state = STREAM_STOPPED;
MUTEX_LOCK(&stream_.mutex);


timeEndPeriod(1); // revert to normal scheduler frequency on lesser windows.

#ifdef GENERATE_DEBUG_LOG
// write the timing log to a .TSV file for analysis in Excel.
// Write the timing log to a .TSV file for analysis in Excel.
unlink("c:/rtaudiolog.txt");
std::ofstream os("c:/rtaudiolog.txt");
os << "writeTime\treadDelay\tnextWritePointer\tnextReadPointer\tcurrentWritePointer\tsafeWritePointer\tcurrentReadPointer\tsafeReadPointer" << std::endl;
for (int i = 0; i < currentDebugLogEntry ; ++i)
{
for (int i = 0; i < currentDebugLogEntry ; ++i) {
TTickRecord &r = debugLog[i];
os
<< r.writeTime-debugLog[0].writeTime << "\t" << (r.readTime-r.writeTime) << "\t"
<< r.nextWritePointer % BUFFER_SIZE << "\t" << r.nextReadPointer % BUFFER_SIZE
<< "\t" << r.currentWritePointer % BUFFER_SIZE << "\t" << r.safeWritePointer % BUFFER_SIZE
<< "\t" << r.currentReadPointer % BUFFER_SIZE << "\t" << r.safeReadPointer % BUFFER_SIZE << std::endl;
os << r.writeTime-debugLog[0].writeTime << "\t" << (r.readTime-r.writeTime) << "\t"
<< r.nextWritePointer % BUFFER_SIZE << "\t" << r.nextReadPointer % BUFFER_SIZE
<< "\t" << r.currentWritePointer % BUFFER_SIZE << "\t" << r.safeWritePointer % BUFFER_SIZE
<< "\t" << r.currentReadPointer % BUFFER_SIZE << "\t" << r.safeReadPointer % BUFFER_SIZE << std::endl;
}
#endif

// There is no specific DirectSound API call to "drain" a buffer
// before stopping. We can hack this for playback by writing zeroes
// for another bufferSize * nBuffers frames. For capture, the
// before stopping. We can hack this for playback by writing
// buffers of zeroes over the entire buffer. For capture, the
// concept is less clear so we'll repeat what we do in the
// abortStream() case.
HRESULT result;
@@ -6701,27 +6767,26 @@ void RtApiDs :: stopStream()
if (stream_.mode == OUTPUT || stream_.mode == DUPLEX) {

DWORD currentPos, safePos;
long buffer_bytes = stream_.bufferSize * stream_.nDeviceChannels[0]
* formatBytes(stream_.deviceFormat[0]);

long buffer_bytes = stream_.bufferSize * stream_.nDeviceChannels[0] * formatBytes(stream_.deviceFormat[0]);

LPDIRECTSOUNDBUFFER dsBuffer = (LPDIRECTSOUNDBUFFER) handles[0].buffer;
long nextWritePos = handles[0].bufferPointer;
DWORD nextWritePos = handles[0].bufferPointer;
dsBufferSize = handles[0].dsBufferSize;
DWORD dsBytesWritten = 0;

// Write zeroes for nBuffer counts.
for (int i=0; i<stream_.nBuffers; i++) {
// Write zeroes for at least dsBufferSize bytes.
while ( dsBytesWritten < dsBufferSize ) {

// Find out where the read and "safe write" pointers are.
result = dsBuffer->GetCurrentPosition(&currentPos, &safePos);
result = dsBuffer->GetCurrentPosition( &currentPos, &safePos );
if ( FAILED(result) ) {
sprintf(message_, "RtApiDs: Unable to get current position (%s): %s.",
devices_[stream_.device[0]].name.c_str(), getErrorString(result));
error(RtError::DRIVER_ERROR);
}
// Chase nextWritePos.

if ( currentPos < (DWORD)nextWritePos ) currentPos += dsBufferSize; // unwrap offset
// Chase nextWritePosition.
if ( currentPos < nextWritePos ) currentPos += dsBufferSize; // unwrap offset
DWORD endWrite = nextWritePos + buffer_bytes;

// Check whether the entire write region is behind the play pointer.
@@ -6738,11 +6803,12 @@ void RtApiDs :: stopStream()
devices_[stream_.device[0]].name.c_str(), getErrorString(result));
error(RtError::DRIVER_ERROR);
}

if ( currentPos < (DWORD)nextWritePos ) currentPos += dsBufferSize; // unwrap offset
}

// Lock free space in the buffer
result = dsBuffer->Lock (nextWritePos, buffer_bytes, &buffer1,
result = dsBuffer->Lock( nextWritePos, buffer_bytes, &buffer1,
&bufferSize1, &buffer2, &bufferSize2, 0);
if ( FAILED(result) ) {
sprintf(message_, "RtApiDs: Unable to lock buffer during playback (%s): %s.",
@@ -6751,11 +6817,11 @@ void RtApiDs :: stopStream()
}

// Zero the free space
ZeroMemory(buffer1, bufferSize1);
if (buffer2 != NULL) ZeroMemory(buffer2, bufferSize2);
ZeroMemory( buffer1, bufferSize1 );
if (buffer2 != NULL) ZeroMemory( buffer2, bufferSize2 );

// Update our buffer offset and unlock sound buffer
dsBuffer->Unlock (buffer1, bufferSize1, buffer2, bufferSize2);
dsBuffer->Unlock( buffer1, bufferSize1, buffer2, bufferSize2 );
if ( FAILED(result) ) {
sprintf(message_, "RtApiDs: Unable to unlock buffer during playback (%s): %s.",
devices_[stream_.device[0]].name.c_str(), getErrorString(result));
@@ -6763,6 +6829,15 @@ void RtApiDs :: stopStream()
}
nextWritePos = (nextWritePos + bufferSize1 + bufferSize2) % dsBufferSize;
handles[0].bufferPointer = nextWritePos;
dsBytesWritten += buffer_bytes;
}

// OK, now stop the buffer.
result = dsBuffer->Stop();
if ( FAILED(result) ) {
sprintf(message_, "RtApiDs: Unable to stop buffer (%s): %s",
devices_[stream_.device[0]].name.c_str(), getErrorString(result));
error(RtError::DRIVER_ERROR);
}

// If we play again, start at the beginning of the buffer.
@@ -6821,6 +6896,8 @@ void RtApiDs :: abortStream()
stream_.state = STREAM_STOPPED;
MUTEX_LOCK(&stream_.mutex);

timeEndPeriod(1); // revert to normal scheduler frequency on lesser windows.

HRESULT result;
long dsBufferSize;
LPVOID audioPtr;
@@ -7001,6 +7078,7 @@ void RtApiDs :: tickStream()
#ifdef GENERATE_DEBUG_LOG
DWORD writeTime, readTime;
#endif

LPVOID buffer1 = NULL;
LPVOID buffer2 = NULL;
DWORD bufferSize1 = 0;
@@ -7010,29 +7088,29 @@ void RtApiDs :: tickStream()
long buffer_bytes;
DsHandle *handles = (DsHandle *) stream_.apiHandle;

if (stream_.mode == DUPLEX && !buffersRolling)
{
if (stream_.mode == DUPLEX && !buffersRolling) {
assert(handles[0].dsBufferSize == handles[1].dsBufferSize);

// it takes a while for the devices to get rolling. As a result, there's
// no guarantee that the capture and write device pointers will move in lockstep.
// Wait here for both devices to start rolling, and then set our buffer pointers accordingly.
// e.g. Crystal Drivers: the capture buffer starts up 5700 to 9600 bytes later than the write
// buffer.
// It takes a while for the devices to get rolling. As a result,
// there's no guarantee that the capture and write device pointers
// will move in lockstep. Wait here for both devices to start
// rolling, and then set our buffer pointers accordingly.
// e.g. Crystal Drivers: the capture buffer starts up 5700 to 9600
// bytes later than the write buffer.

// Stub: a serious risk of having a pre-emptive scheduling round take place between
// the two GetCurrentPosition calls... but I'm really not sure how to solve the problem.
// Temporarily boost to Realtime priority, maybe; but I'm not sure what priority the
// directsound service threads run at. We *should* be roughly within a ms or so of correct.
// Stub: a serious risk of having a pre-emptive scheduling round
// take place between the two GetCurrentPosition calls... but I'm
// really not sure how to solve the problem. Temporarily boost to
// Realtime priority, maybe; but I'm not sure what priority the
// directsound service threads run at. We *should* be roughly
// within a ms or so of correct.

LPDIRECTSOUNDBUFFER dsWriteBuffer = (LPDIRECTSOUNDBUFFER) handles[0].buffer;
LPDIRECTSOUNDCAPTUREBUFFER dsCaptureBuffer = (LPDIRECTSOUNDCAPTUREBUFFER) handles[1].buffer;


DWORD initialWritePos, initialSafeWritePos;
DWORD initialReadPos, initialSafeReadPos;;


result = dsWriteBuffer->GetCurrentPosition(&initialWritePos, &initialSafeWritePos);
if ( FAILED(result) ) {
sprintf(message_, "RtApiDs: Unable to get current position (%s): %s.",
@@ -7045,8 +7123,7 @@ void RtApiDs :: tickStream()
devices_[stream_.device[1]].name.c_str(), getErrorString(result));
error(RtError::DRIVER_ERROR);
}
while (true)
{
while (true) {
result = dsWriteBuffer->GetCurrentPosition(&currentWritePos, &safeWritePos);
if ( FAILED(result) ) {
sprintf(message_, "RtApiDs: Unable to get current position (%s): %s.",
@@ -7059,16 +7136,14 @@ void RtApiDs :: tickStream()
devices_[stream_.device[1]].name.c_str(), getErrorString(result));
error(RtError::DRIVER_ERROR);
}
if (safeWritePos != initialSafeWritePos && safeReadPos != initialSafeReadPos)
{
if (safeWritePos != initialSafeWritePos && safeReadPos != initialSafeReadPos) {
break;
}
Sleep(1);
}

assert(handles[0].dsBufferSize == handles[1].dsBufferSize);
assert( handles[0].dsBufferSize == handles[1].dsBufferSize );

UINT writeBufferLead = (safeWritePos-safeReadPos + handles[0].dsBufferSize) % handles[0].dsBufferSize;
buffersRolling = true;
handles[0].bufferPointer = (safeWritePos + handles[0].dsPointerLeadTime);
handles[1].bufferPointer = safeReadPos;
@@ -7104,8 +7179,7 @@ void RtApiDs :: tickStream()
nextWritePos = handles[0].bufferPointer;

DWORD endWrite;
while (true)
{
while ( true ) {
// Find out where the read and "safe write" pointers are.
result = dsBuffer->GetCurrentPosition(&currentWritePos, &safeWritePos);
if ( FAILED(result) ) {
@@ -7115,16 +7189,11 @@ void RtApiDs :: tickStream()
}

leadPos = safeWritePos + handles[0].dsPointerLeadTime;
if (leadPos > dsBufferSize) {
leadPos -= dsBufferSize;
}
if ( leadPos > dsBufferSize ) leadPos -= dsBufferSize;
if ( leadPos < nextWritePos ) leadPos += dsBufferSize; // unwrap offset


endWrite = nextWritePos + buffer_bytes;

// Check whether the entire write region is behind the play pointer.

// Check whether the entire write region is behind the play pointer.
if ( leadPos >= endWrite ) break;

// If we are here, then we must wait until the play pointer gets
@@ -7139,28 +7208,24 @@ void RtApiDs :: tickStream()
double millis = (endWrite - leadPos) * 900.0;
millis /= ( formatBytes(stream_.deviceFormat[0]) *stream_.nDeviceChannels[0]* stream_.sampleRate);
if ( millis < 1.0 ) millis = 1.0;
if (millis > 50.0) {
if ( millis > 50.0 ) {
static int nOverruns = 0;
++nOverruns;
}
Sleep( (DWORD) millis );
// Sleep( (DWORD) 2);
}

#ifdef GENERATE_DEBUG_LOG
writeTime = timeGetTime();
#endif
if (statistics.writeDeviceSafeLeadBytes < dsPointerDifference(safeWritePos,currentWritePos,handles[0].dsBufferSize))
{
if (statistics.writeDeviceSafeLeadBytes < dsPointerDifference(safeWritePos,currentWritePos,handles[0].dsBufferSize)) {
statistics.writeDeviceSafeLeadBytes = dsPointerDifference(safeWritePos,currentWritePos,handles[0].dsBufferSize);
}

if (
dsPointerBetween(nextWritePos,safeWritePos,currentWritePos,dsBufferSize)
|| dsPointerBetween(endWrite,safeWritePos,currentWritePos,dsBufferSize)
)
{
// we've strayed into the forbidden zone.
// resync the read pointer.
if ( dsPointerBetween( nextWritePos, safeWritePos, currentWritePos, dsBufferSize )
|| dsPointerBetween( endWrite, safeWritePos, currentWritePos, dsBufferSize ) ) {
// We've strayed into the forbidden zone ... resync the read pointer.
++statistics.numberOfWriteUnderruns;
nextWritePos = safeWritePos + handles[0].dsPointerLeadTime-buffer_bytes+dsBufferSize;
while (nextWritePos >= dsBufferSize) nextWritePos-= dsBufferSize;
@@ -7169,8 +7234,8 @@ void RtApiDs :: tickStream()
}
// Lock free space in the buffer
result = dsBuffer->Lock (nextWritePos, buffer_bytes, &buffer1,
&bufferSize1, &buffer2, &bufferSize2, 0);
result = dsBuffer->Lock( nextWritePos, buffer_bytes, &buffer1,
&bufferSize1, &buffer2, &bufferSize2, 0 );
if ( FAILED(result) ) {
sprintf(message_, "RtApiDs: Unable to lock buffer during playback (%s): %s.",
devices_[stream_.device[0]].name.c_str(), getErrorString(result));
@@ -7182,7 +7247,7 @@ void RtApiDs :: tickStream()
if (buffer2 != NULL) CopyMemory(buffer2, buffer+bufferSize1, bufferSize2);

// Update our buffer offset and unlock sound buffer
dsBuffer->Unlock (buffer1, bufferSize1, buffer2, bufferSize2);
dsBuffer->Unlock( buffer1, bufferSize1, buffer2, bufferSize2 );
if ( FAILED(result) ) {
sprintf(message_, "RtApiDs: Unable to unlock buffer during playback (%s): %s.",
devices_[stream_.device[0]].name.c_str(), getErrorString(result));
@@ -7230,9 +7295,9 @@ void RtApiDs :: tickStream()
// 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 provide a pre-roll
// period of 0.5 seconds
// in which we return zeros from the read buffer while the pointers sync up.
// In order to minimize audible dropouts in DUPLEX mode, we will
// provide a pre-roll period of 0.5 seconds in which we return
// zeros from the read buffer while the pointers sync up.

if (stream_.mode == DUPLEX)
{
@@ -7381,8 +7446,8 @@ extern "C" unsigned __stdcall callbackHandler(void *ptr)
}

static bool CALLBACK deviceCountCallback(LPGUID lpguid,
LPCSTR lpcstrDescription,
LPCSTR lpcstrModule,
LPCTSTR description,
LPCTSTR module,
LPVOID lpContext)
{
int *pointer = ((int *) lpContext);
@@ -7391,22 +7456,41 @@ static bool CALLBACK deviceCountCallback(LPGUID lpguid,
return true;
}

#include "tchar.h"

std::string convertTChar( LPCTSTR name )
{
std::string s;

#if defined( UNICODE ) || defined( _UNICODE )
// Yes, this conversion doesn't make sense for two-byte characters
// but RtAudio is currently written to return an std::string of
// one-byte chars for the device name.
for ( unsigned int i=0; i<wcslen( name ); i++ )
s.push_back( name[i] );
#else
s.append( std::string( name ) );
#endif

return s;
}

static bool CALLBACK deviceInfoCallback(LPGUID lpguid,
LPCSTR lpcstrDescription,
LPCSTR lpcstrModule,
LPCTSTR description,
LPCTSTR module,
LPVOID lpContext)
{
enum_info *info = ((enum_info *) lpContext);
while (strlen(info->name) > 0) info++;
while ( !info->name.empty() ) info++;

strncpy(info->name, lpcstrDescription, 64);
info->name = convertTChar( description );
info->id = lpguid;

HRESULT hr;
HRESULT hr;
info->isValid = false;
if (info->isInput == true) {
DSCCAPS caps;
LPDIRECTSOUNDCAPTURE object;
DSCCAPS caps;
LPDIRECTSOUNDCAPTURE object;

hr = DirectSoundCaptureCreate( lpguid, &object, NULL );
if( hr != DS_OK ) return true;
@@ -7420,8 +7504,8 @@ static bool CALLBACK deviceInfoCallback(LPGUID lpguid,
object->Release();
}
else {
DSCAPS caps;
LPDIRECTSOUND object;
DSCAPS caps;
LPDIRECTSOUND object;
hr = DirectSoundCreate( lpguid, &object, NULL );
if( hr != DS_OK ) return true;

@@ -7438,14 +7522,14 @@ static bool CALLBACK deviceInfoCallback(LPGUID lpguid,
}

static bool CALLBACK defaultDeviceCallback(LPGUID lpguid,
LPCSTR lpcstrDescription,
LPCSTR lpcstrModule,
LPCTSTR description,
LPCTSTR module,
LPVOID lpContext)
{
enum_info *info = ((enum_info *) lpContext);

if ( lpguid == NULL ) {
strncpy(info->name, lpcstrDescription, 64);
info->name = convertTChar( description );
return false;
}

@@ -7453,13 +7537,14 @@ static bool CALLBACK defaultDeviceCallback(LPGUID lpguid,
}

static bool CALLBACK deviceIdCallback(LPGUID lpguid,
LPCSTR lpcstrDescription,
LPCSTR lpcstrModule,
LPCTSTR description,
LPCTSTR module,
LPVOID lpContext)
{
enum_info *info = ((enum_info *) lpContext);

if ( strncmp( info->name, lpcstrDescription, 64 ) == 0 ) {
std::string s = convertTChar( description );
if ( info->name == s ) {
info->id = lpguid;
info->isValid = true;
return false;


+ 2
- 1
RtAudio.h View File

@@ -37,7 +37,7 @@
*/
/************************************************************************/

// RtAudio: Version 3.0.2 (14 October 2005)
// RtAudio: Version 3.0.3 (18 November 2005)

#ifndef __RTAUDIO_H
#define __RTAUDIO_H
@@ -552,6 +552,7 @@ public:
private:

void initialize(void);
bool primeOutputBuffer();
void probeDeviceInfo( RtApiDevice *info );
bool probeDeviceOpen( int device, StreamMode mode, int channels,
int sampleRate, RtAudioFormat format,


tests/Windows/asio.cpp → asio/asio.cpp View File


+ 107
- 8
asio/asio.h View File

@@ -3,9 +3,12 @@
/*
Steinberg Audio Stream I/O API
(c) 1997 - 1999, Steinberg Soft- und Hardware GmbH
(c) 1997 - 2005, Steinberg Media Technologies GmbH
ASIO Interface Specification v 2.1
2005 - Added support for DSD sample data (in cooperation with Sony)
ASIO Interface Specification v 2.0
basic concept is an i/o synchronous double-buffer scheme:
@@ -131,7 +134,7 @@ enum {
// these are used for 32 bit data buffer, with different alignment of the data inside
// 32 bit PCI bus systems can be more easily used with these
ASIOSTInt32MSB16 = 8, // 32 bit data with 18 bit alignment
ASIOSTInt32MSB16 = 8, // 32 bit data with 16 bit alignment
ASIOSTInt32MSB18 = 9, // 32 bit data with 18 bit alignment
ASIOSTInt32MSB20 = 10, // 32 bit data with 20 bit alignment
ASIOSTInt32MSB24 = 11, // 32 bit data with 24 bit alignment
@@ -147,9 +150,56 @@ enum {
ASIOSTInt32LSB16 = 24, // 32 bit data with 18 bit alignment
ASIOSTInt32LSB18 = 25, // 32 bit data with 18 bit alignment
ASIOSTInt32LSB20 = 26, // 32 bit data with 20 bit alignment
ASIOSTInt32LSB24 = 27 // 32 bit data with 24 bit alignment
ASIOSTInt32LSB24 = 27, // 32 bit data with 24 bit alignment
// ASIO DSD format.
ASIOSTDSDInt8LSB1 = 32, // DSD 1 bit data, 8 samples per byte. First sample in Least significant bit.
ASIOSTDSDInt8MSB1 = 33, // DSD 1 bit data, 8 samples per byte. First sample in Most significant bit.
ASIOSTDSDInt8NER8 = 40, // DSD 8 bit data, 1 sample per byte. No Endianness required.
ASIOSTLastEntry
};
/*-----------------------------------------------------------------------------
// DSD operation and buffer layout
// Definition by Steinberg/Sony Oxford.
//
// We have tried to treat DSD as PCM and so keep a consistant structure across
// the ASIO interface.
//
// DSD's sample rate is normally referenced as a multiple of 44.1Khz, so
// the standard sample rate is refered to as 64Fs (or 2.8224Mhz). We looked
// at making a special case for DSD and adding a field to the ASIOFuture that
// would allow the user to select the Over Sampleing Rate (OSR) as a seperate
// entity but decided in the end just to treat it as a simple value of
// 2.8224Mhz and use the standard interface to set it.
//
// The second problem was the "word" size, in PCM the word size is always a
// greater than or equal to 8 bits (a byte). This makes life easy as we can
// then pack the samples into the "natural" size for the machine.
// In DSD the "word" size is 1 bit. This is not a major problem and can easily
// be dealt with if we ensure that we always deal with a multiple of 8 samples.
//
// DSD brings with it another twist to the Endianness religion. How are the
// samples packed into the byte. It would be nice to just say the most significant
// bit is always the first sample, however there would then be a performance hit
// on little endian machines. Looking at how some of the processing goes...
// Little endian machines like the first sample to be in the Least Significant Bit,
// this is because when you write it to memory the data is in the correct format
// to be shifted in and out of the words.
// Big endian machine prefer the first sample to be in the Most Significant Bit,
// again for the same reasion.
//
// And just when things were looking really muddy there is a proposed extension to
// DSD that uses 8 bit word sizes. It does not care what endianness you use.
//
// Switching the driver between DSD and PCM mode
// ASIOFuture allows for extending the ASIO API quite transparently.
// See kAsioSetIoFormat, kAsioGetIoFormat, kAsioCanDoIoFormat
//
//-----------------------------------------------------------------------------*/
//- - - - - - - - - - - - - - - - - - - - - - - - -
// Error codes
//- - - - - - - - - - - - - - - - - - - - - - - - -
@@ -403,9 +453,14 @@ enum
kAsioSupportsTimeInfo, // if host returns true here, it will expect the
// callback bufferSwitchTimeInfo to be called instead
// of bufferSwitch
kAsioSupportsTimeCode, // supports time code reading/writing
kAsioSupportsInputMonitor, // supports input monitoring
kAsioSupportsTimeCode, //
kAsioMMCCommand, // unused - value: number of commands, message points to mmc commands
kAsioSupportsInputMonitor, // kAsioSupportsXXX return 1 if host supports this
kAsioSupportsInputGain, // unused and undefined
kAsioSupportsInputMeter, // unused and undefined
kAsioSupportsOutputGain, // unused and undefined
kAsioSupportsOutputMeter, // unused and undefined
kAsioOverload, // driver detected an overload
kAsioNumMessageSelectors
};
@@ -860,7 +915,14 @@ enum
kAsioCanInputGain,
kAsioCanInputMeter,
kAsioCanOutputGain,
kAsioCanOutputMeter
kAsioCanOutputMeter,
// DSD support
// The following extensions are required to allow switching
// and control of the DSD subsystem.
kAsioSetIoFormat = 0x23111961, /* ASIOIoFormat * in params. */
kAsioGetIoFormat = 0x23111983, /* ASIOIoFormat * in params. */
kAsioCanDoIoFormat = 0x23112004, /* ASIOIoFormat * in params. */
};
typedef struct ASIOInputMonitor
@@ -905,6 +967,43 @@ enum
kTransMonitor // trackSwitches
};
/*
// DSD support
// Some notes on how to use ASIOIoFormatType.
//
// The caller will fill the format with the request types.
// If the board can do the request then it will leave the
// values unchanged. If the board does not support the
// request then it will change that entry to Invalid (-1)
//
// So to request DSD then
//
// ASIOIoFormat NeedThis={kASIODSDFormat};
//
// if(ASE_SUCCESS != ASIOFuture(kAsioSetIoFormat,&NeedThis) ){
// // If the board did not accept one of the parameters then the
// // whole call will fail and the failing parameter will
// // have had its value changes to -1.
// }
//
// Note: Switching between the formats need to be done before the "prepared"
// state (see ASIO 2 documentation) is entered.
*/
typedef long int ASIOIoFormatType;
enum ASIOIoFormatType_e
{
kASIOFormatInvalid = -1,
kASIOPCMFormat = 0,
kASIODSDFormat = 1,
};
typedef struct ASIOIoFormat_s
{
ASIOIoFormatType FormatType;
char future[512-sizeof(ASIOIoFormatType)];
} ASIOIoFormat;
ASIOError ASIOOutputReady(void);
/* Purpose:
this tells the driver that the host has completed processing


tests/Windows/asiodrivers.cpp → asio/asiodrivers.cpp View File


tests/Windows/asiodrvr.h → asio/asiodrvr.h View File


tests/Windows/asiolist.cpp → asio/asiolist.cpp View File


tests/Windows/iasiodrv.h → asio/iasiodrv.h View File


+ 563
- 0
asio/iasiothiscallresolver.cpp View File

@@ -0,0 +1,563 @@
/*
IASIOThiscallResolver.cpp see the comments in iasiothiscallresolver.h for
the top level description - this comment describes the technical details of
the implementation.
The latest version of this file is available from:
http://www.audiomulch.com/~rossb/code/calliasio
please email comments to Ross Bencina <rossb@audiomulch.com>
BACKGROUND
The IASIO interface declared in the Steinberg ASIO 2 SDK declares
functions with no explicit calling convention. This causes MSVC++ to default
to using the thiscall convention, which is a proprietary convention not
implemented by some non-microsoft compilers - notably borland BCC,
C++Builder, and gcc. MSVC++ is the defacto standard compiler used by
Steinberg. As a result of this situation, the ASIO sdk will compile with
any compiler, however attempting to execute the compiled code will cause a
crash due to different default calling conventions on non-Microsoft
compilers.
IASIOThiscallResolver solves the problem by providing an adapter class that
delegates to the IASIO interface using the correct calling convention
(thiscall). Due to the lack of support for thiscall in the Borland and GCC
compilers, the calls have been implemented in assembly language.
A number of macros are defined for thiscall function calls with different
numbers of parameters, with and without return values - it may be possible
to modify the format of these macros to make them work with other inline
assemblers.
THISCALL DEFINITION
A number of definitions of the thiscall calling convention are floating
around the internet. The following definition has been validated against
output from the MSVC++ compiler:
For non-vararg functions, thiscall works as follows: the object (this)
pointer is passed in ECX. All arguments are passed on the stack in
right to left order. The return value is placed in EAX. The callee
clears the passed arguments from the stack.
FINDING FUNCTION POINTERS FROM AN IASIO POINTER
The first field of a COM object is a pointer to its vtble. Thus a pointer
to an object implementing the IASIO interface also points to a pointer to
that object's vtbl. The vtble is a table of function pointers for all of
the virtual functions exposed by the implemented interfaces.
If we consider a variable declared as a pointer to IASO:
IASIO *theAsioDriver
theAsioDriver points to:
object implementing IASIO
{
IASIOvtbl *vtbl
other data
}
in other words, theAsioDriver points to a pointer to an IASIOvtbl
vtbl points to a table of function pointers:
IASIOvtbl ( interface IASIO : public IUnknown )
{
(IUnknown functions)
0 virtual HRESULT STDMETHODCALLTYPE (*QueryInterface)(REFIID riid, void **ppv) = 0;
4 virtual ULONG STDMETHODCALLTYPE (*AddRef)() = 0;
8 virtual ULONG STDMETHODCALLTYPE (*Release)() = 0;
(IASIO functions)
12 virtual ASIOBool (*init)(void *sysHandle) = 0;
16 virtual void (*getDriverName)(char *name) = 0;
20 virtual long (*getDriverVersion)() = 0;
24 virtual void (*getErrorMessage)(char *string) = 0;
28 virtual ASIOError (*start)() = 0;
32 virtual ASIOError (*stop)() = 0;
36 virtual ASIOError (*getChannels)(long *numInputChannels, long *numOutputChannels) = 0;
40 virtual ASIOError (*getLatencies)(long *inputLatency, long *outputLatency) = 0;
44 virtual ASIOError (*getBufferSize)(long *minSize, long *maxSize,
long *preferredSize, long *granularity) = 0;
48 virtual ASIOError (*canSampleRate)(ASIOSampleRate sampleRate) = 0;
52 virtual ASIOError (*getSampleRate)(ASIOSampleRate *sampleRate) = 0;
56 virtual ASIOError (*setSampleRate)(ASIOSampleRate sampleRate) = 0;
60 virtual ASIOError (*getClockSources)(ASIOClockSource *clocks, long *numSources) = 0;
64 virtual ASIOError (*setClockSource)(long reference) = 0;
68 virtual ASIOError (*getSamplePosition)(ASIOSamples *sPos, ASIOTimeStamp *tStamp) = 0;
72 virtual ASIOError (*getChannelInfo)(ASIOChannelInfo *info) = 0;
76 virtual ASIOError (*createBuffers)(ASIOBufferInfo *bufferInfos, long numChannels,
long bufferSize, ASIOCallbacks *callbacks) = 0;
80 virtual ASIOError (*disposeBuffers)() = 0;
84 virtual ASIOError (*controlPanel)() = 0;
88 virtual ASIOError (*future)(long selector,void *opt) = 0;
92 virtual ASIOError (*outputReady)() = 0;
};
The numbers in the left column show the byte offset of each function ptr
from the beginning of the vtbl. These numbers are used in the code below
to select different functions.
In order to find the address of a particular function, theAsioDriver
must first be dereferenced to find the value of the vtbl pointer:
mov eax, theAsioDriver
mov edx, [theAsioDriver] // edx now points to vtbl[0]
Then an offset must be added to the vtbl pointer to select a
particular function, for example vtbl+44 points to the slot containing
a pointer to the getBufferSize function.
Finally vtbl+x must be dereferenced to obtain the value of the function
pointer stored in that address:
call [edx+44] // call the function pointed to by
// the value in the getBufferSize field of the vtbl
SEE ALSO
Martin Fay's OpenASIO DLL at http://www.martinfay.com solves the same
problem by providing a new COM interface which wraps IASIO with an
interface that uses portable calling conventions. OpenASIO must be compiled
with MSVC, and requires that you ship the OpenASIO DLL with your
application.
ACKNOWLEDGEMENTS
Ross Bencina: worked out the thiscall details above, wrote the original
Borland asm macros, and a patch for asio.cpp (which is no longer needed).
Thanks to Martin Fay for introducing me to the issues discussed here,
and to Rene G. Ceballos for assisting with asm dumps from MSVC++.
Antti Silvast: converted the original calliasio to work with gcc and NASM
by implementing the asm code in a separate file.
Fraser Adams: modified the original calliasio containing the Borland inline
asm to add inline asm for gcc i.e. Intel syntax for Borland and AT&T syntax
for gcc. This seems a neater approach for gcc than to have a separate .asm
file and it means that we only need one version of the thiscall patch.
Fraser Adams: rewrote the original calliasio patch in the form of the
IASIOThiscallResolver class in order to avoid modifications to files from
the Steinberg SDK, which may have had potential licence issues.
Andrew Baldwin: contributed fixes for compatibility problems with more
recent versions of the gcc assembler.
*/
// We only need IASIOThiscallResolver at all if we are on Win32. For other
// platforms we simply bypass the IASIOThiscallResolver definition to allow us
// to be safely #include'd whatever the platform to keep client code portable
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
// If microsoft compiler we can call IASIO directly so IASIOThiscallResolver
// is not used.
#if !defined(_MSC_VER)
#include <new>
#include <assert.h>
// We have a mechanism in iasiothiscallresolver.h to ensure that asio.h is
// #include'd before it in client code, we do NOT want to do this test here.
#define iasiothiscallresolver_sourcefile 1
#include "iasiothiscallresolver.h"
#undef iasiothiscallresolver_sourcefile
// iasiothiscallresolver.h redefines ASIOInit for clients, but we don't want
// this macro defined in this translation unit.
#undef ASIOInit
// theAsioDriver is a global pointer to the current IASIO instance which the
// ASIO SDK uses to perform all actions on the IASIO interface. We substitute
// our own forwarding interface into this pointer.
extern IASIO* theAsioDriver;
// The following macros define the inline assembler for BORLAND first then gcc
#if defined(__BCPLUSPLUS__) || defined(__BORLANDC__)
#define CALL_THISCALL_0( resultName, thisPtr, funcOffset )\
void *this_ = (thisPtr); \
__asm { \
mov ecx, this_ ; \
mov eax, [ecx] ; \
call [eax+funcOffset] ; \
mov resultName, eax ; \
}
#define CALL_VOID_THISCALL_1( thisPtr, funcOffset, param1 )\
void *this_ = (thisPtr); \
__asm { \
mov eax, param1 ; \
push eax ; \
mov ecx, this_ ; \
mov eax, [ecx] ; \
call [eax+funcOffset] ; \
}
#define CALL_THISCALL_1( resultName, thisPtr, funcOffset, param1 )\
void *this_ = (thisPtr); \
__asm { \
mov eax, param1 ; \
push eax ; \
mov ecx, this_ ; \
mov eax, [ecx] ; \
call [eax+funcOffset] ; \
mov resultName, eax ; \
}
#define CALL_THISCALL_1_DOUBLE( resultName, thisPtr, funcOffset, param1 )\
void *this_ = (thisPtr); \
void *doubleParamPtr_ (&param1); \
__asm { \
mov eax, doubleParamPtr_ ; \
push [eax+4] ; \
push [eax] ; \
mov ecx, this_ ; \
mov eax, [ecx] ; \
call [eax+funcOffset] ; \
mov resultName, eax ; \
}
#define CALL_THISCALL_2( resultName, thisPtr, funcOffset, param1, param2 )\
void *this_ = (thisPtr); \
__asm { \
mov eax, param2 ; \
push eax ; \
mov eax, param1 ; \
push eax ; \
mov ecx, this_ ; \
mov eax, [ecx] ; \
call [eax+funcOffset] ; \
mov resultName, eax ; \
}
#define CALL_THISCALL_4( resultName, thisPtr, funcOffset, param1, param2, param3, param4 )\
void *this_ = (thisPtr); \
__asm { \
mov eax, param4 ; \
push eax ; \
mov eax, param3 ; \
push eax ; \
mov eax, param2 ; \
push eax ; \
mov eax, param1 ; \
push eax ; \
mov ecx, this_ ; \
mov eax, [ecx] ; \
call [eax+funcOffset] ; \
mov resultName, eax ; \
}
#elif defined(__GNUC__)
#define CALL_THISCALL_0( resultName, thisPtr, funcOffset ) \
__asm__ __volatile__ ("movl (%1), %%edx\n\t" \
"call *"#funcOffset"(%%edx)\n\t" \
:"=a"(resultName) /* Output Operands */ \
:"c"(thisPtr) /* Input Operands */ \
); \
#define CALL_VOID_THISCALL_1( thisPtr, funcOffset, param1 ) \
__asm__ __volatile__ ("pushl %0\n\t" \
"movl (%1), %%edx\n\t" \
"call *"#funcOffset"(%%edx)\n\t" \
: /* Output Operands */ \
:"r"(param1), /* Input Operands */ \
"c"(thisPtr) \
); \
#define CALL_THISCALL_1( resultName, thisPtr, funcOffset, param1 ) \
__asm__ __volatile__ ("pushl %1\n\t" \
"movl (%2), %%edx\n\t" \
"call *"#funcOffset"(%%edx)\n\t" \
:"=a"(resultName) /* Output Operands */ \
:"r"(param1), /* Input Operands */ \
"c"(thisPtr) \
); \
#define CALL_THISCALL_1_DOUBLE( resultName, thisPtr, funcOffset, param1 ) \
__asm__ __volatile__ ("pushl 4(%1)\n\t" \
"pushl (%1)\n\t" \
"movl (%2), %%edx\n\t" \
"call *"#funcOffset"(%%edx);\n\t" \
:"=a"(resultName) /* Output Operands */ \
:"a"(&param1), /* Input Operands */ \
/* Note: Using "r" above instead of "a" fails */ \
/* when using GCC 3.3.3, and maybe later versions*/\
"c"(thisPtr) \
); \
#define CALL_THISCALL_2( resultName, thisPtr, funcOffset, param1, param2 ) \
__asm__ __volatile__ ("pushl %1\n\t" \
"pushl %2\n\t" \
"movl (%3), %%edx\n\t" \
"call *"#funcOffset"(%%edx)\n\t" \
:"=a"(resultName) /* Output Operands */ \
:"r"(param2), /* Input Operands */ \
"r"(param1), \
"c"(thisPtr) \
); \
#define CALL_THISCALL_4( resultName, thisPtr, funcOffset, param1, param2, param3, param4 )\
__asm__ __volatile__ ("pushl %1\n\t" \
"pushl %2\n\t" \
"pushl %3\n\t" \
"pushl %4\n\t" \
"movl (%5), %%edx\n\t" \
"call *"#funcOffset"(%%edx)\n\t" \
:"=a"(resultName) /* Output Operands */ \
:"r"(param4), /* Input Operands */ \
"r"(param3), \
"r"(param2), \
"r"(param1), \
"c"(thisPtr) \
); \
#endif
// Our static singleton instance.
IASIOThiscallResolver IASIOThiscallResolver::instance;
// Constructor called to initialize static Singleton instance above. Note that
// it is important not to clear that_ incase it has already been set by the call
// to placement new in ASIOInit().
IASIOThiscallResolver::IASIOThiscallResolver()
{
}
// Constructor called from ASIOInit() below
IASIOThiscallResolver::IASIOThiscallResolver(IASIO* that)
: that_( that )
{
}
// Implement IUnknown methods as assert(false). IASIOThiscallResolver is not
// really a COM object, just a wrapper which will work with the ASIO SDK.
// If you wanted to use ASIO without the SDK you might want to implement COM
// aggregation in these methods.
HRESULT STDMETHODCALLTYPE IASIOThiscallResolver::QueryInterface(REFIID riid, void **ppv)
{
(void)riid; // suppress unused variable warning
assert( false ); // this function should never be called by the ASIO SDK.
*ppv = NULL;
return E_NOINTERFACE;
}
ULONG STDMETHODCALLTYPE IASIOThiscallResolver::AddRef()
{
assert( false ); // this function should never be called by the ASIO SDK.
return 1;
}
ULONG STDMETHODCALLTYPE IASIOThiscallResolver::Release()
{
assert( false ); // this function should never be called by the ASIO SDK.
return 1;
}
// Implement the IASIO interface methods by performing the vptr manipulation
// described above then delegating to the real implementation.
ASIOBool IASIOThiscallResolver::init(void *sysHandle)
{
ASIOBool result;
CALL_THISCALL_1( result, that_, 12, sysHandle );
return result;
}
void IASIOThiscallResolver::getDriverName(char *name)
{
CALL_VOID_THISCALL_1( that_, 16, name );
}
long IASIOThiscallResolver::getDriverVersion()
{
ASIOBool result;
CALL_THISCALL_0( result, that_, 20 );
return result;
}
void IASIOThiscallResolver::getErrorMessage(char *string)
{
CALL_VOID_THISCALL_1( that_, 24, string );
}
ASIOError IASIOThiscallResolver::start()
{
ASIOBool result;
CALL_THISCALL_0( result, that_, 28 );
return result;
}
ASIOError IASIOThiscallResolver::stop()
{
ASIOBool result;
CALL_THISCALL_0( result, that_, 32 );
return result;
}
ASIOError IASIOThiscallResolver::getChannels(long *numInputChannels, long *numOutputChannels)
{
ASIOBool result;
CALL_THISCALL_2( result, that_, 36, numInputChannels, numOutputChannels );
return result;
}
ASIOError IASIOThiscallResolver::getLatencies(long *inputLatency, long *outputLatency)
{
ASIOBool result;
CALL_THISCALL_2( result, that_, 40, inputLatency, outputLatency );
return result;
}
ASIOError IASIOThiscallResolver::getBufferSize(long *minSize, long *maxSize,
long *preferredSize, long *granularity)
{
ASIOBool result;
CALL_THISCALL_4( result, that_, 44, minSize, maxSize, preferredSize, granularity );
return result;
}
ASIOError IASIOThiscallResolver::canSampleRate(ASIOSampleRate sampleRate)
{
ASIOBool result;
CALL_THISCALL_1_DOUBLE( result, that_, 48, sampleRate );
return result;
}
ASIOError IASIOThiscallResolver::getSampleRate(ASIOSampleRate *sampleRate)
{
ASIOBool result;
CALL_THISCALL_1( result, that_, 52, sampleRate );
return result;
}
ASIOError IASIOThiscallResolver::setSampleRate(ASIOSampleRate sampleRate)
{
ASIOBool result;
CALL_THISCALL_1_DOUBLE( result, that_, 56, sampleRate );
return result;
}
ASIOError IASIOThiscallResolver::getClockSources(ASIOClockSource *clocks, long *numSources)
{
ASIOBool result;
CALL_THISCALL_2( result, that_, 60, clocks, numSources );
return result;
}
ASIOError IASIOThiscallResolver::setClockSource(long reference)
{
ASIOBool result;
CALL_THISCALL_1( result, that_, 64, reference );
return result;
}
ASIOError IASIOThiscallResolver::getSamplePosition(ASIOSamples *sPos, ASIOTimeStamp *tStamp)
{
ASIOBool result;
CALL_THISCALL_2( result, that_, 68, sPos, tStamp );
return result;
}
ASIOError IASIOThiscallResolver::getChannelInfo(ASIOChannelInfo *info)
{
ASIOBool result;
CALL_THISCALL_1( result, that_, 72, info );
return result;
}
ASIOError IASIOThiscallResolver::createBuffers(ASIOBufferInfo *bufferInfos,
long numChannels, long bufferSize, ASIOCallbacks *callbacks)
{
ASIOBool result;
CALL_THISCALL_4( result, that_, 76, bufferInfos, numChannels, bufferSize, callbacks );
return result;
}
ASIOError IASIOThiscallResolver::disposeBuffers()
{
ASIOBool result;
CALL_THISCALL_0( result, that_, 80 );
return result;
}
ASIOError IASIOThiscallResolver::controlPanel()
{
ASIOBool result;
CALL_THISCALL_0( result, that_, 84 );
return result;
}
ASIOError IASIOThiscallResolver::future(long selector,void *opt)
{
ASIOBool result;
CALL_THISCALL_2( result, that_, 88, selector, opt );
return result;
}
ASIOError IASIOThiscallResolver::outputReady()
{
ASIOBool result;
CALL_THISCALL_0( result, that_, 92 );
return result;
}
// Implement our substitute ASIOInit() method
ASIOError IASIOThiscallResolver::ASIOInit(ASIODriverInfo *info)
{
// To ensure that our instance's vptr is correctly constructed, even if
// ASIOInit is called prior to main(), we explicitly call its constructor
// (potentially over the top of an existing instance). Note that this is
// pretty ugly, and is only safe because IASIOThiscallResolver has no
// destructor and contains no objects with destructors.
new((void*)&instance) IASIOThiscallResolver( theAsioDriver );
// Interpose between ASIO client code and the real driver.
theAsioDriver = &instance;
// Note that we never need to switch theAsioDriver back to point to the
// real driver because theAsioDriver is reset to zero in ASIOExit().
// Delegate to the real ASIOInit
return ::ASIOInit(info);
}
#endif /* !defined(_MSC_VER) */
#endif /* Win32 */

+ 201
- 0
asio/iasiothiscallresolver.h View File

@@ -0,0 +1,201 @@
// ****************************************************************************
//
// Changed: I have modified this file slightly (includes) to work with
// RtAudio. RtAudio.cpp must include this file after asio.h.
//
// File: IASIOThiscallResolver.h
// Description: The IASIOThiscallResolver class implements the IASIO
// interface and acts as a proxy to the real IASIO interface by
// calling through its vptr table using the thiscall calling
// convention. To put it another way, we interpose
// IASIOThiscallResolver between ASIO SDK code and the driver.
// This is necessary because most non-Microsoft compilers don't
// implement the thiscall calling convention used by IASIO.
//
// iasiothiscallresolver.cpp contains the background of this
// problem plus a technical description of the vptr
// manipulations.
//
// In order to use this mechanism one simply has to add
// iasiothiscallresolver.cpp to the list of files to compile
// and #include <iasiothiscallresolver.h>
//
// Note that this #include must come after the other ASIO SDK
// #includes, for example:
//
// #include <windows.h>
// #include <asiosys.h>
// #include <asio.h>
// #include <asiodrivers.h>
// #include <iasiothiscallresolver.h>
//
// Actually the important thing is to #include
// <iasiothiscallresolver.h> after <asio.h>. We have
// incorporated a test to enforce this ordering.
//
// The code transparently takes care of the interposition by
// using macro substitution to intercept calls to ASIOInit()
// and ASIOExit(). We save the original ASIO global
// "theAsioDriver" in our "that" variable, and then set
// "theAsioDriver" to equal our IASIOThiscallResolver instance.
//
// Whilst this method of resolving the thiscall problem requires
// the addition of #include <iasiothiscallresolver.h> to client
// code it has the advantage that it does not break the terms
// of the ASIO licence by publishing it. We are NOT modifying
// any Steinberg code here, we are merely implementing the IASIO
// interface in the same way that we would need to do if we
// wished to provide an open source ASIO driver.
//
// For compilation with MinGW -lole32 needs to be added to the
// linker options. For BORLAND, linking with Import32.lib is
// sufficient.
//
// The dependencies are with: CoInitialize, CoUninitialize,
// CoCreateInstance, CLSIDFromString - used by asiolist.cpp
// and are required on Windows whether ThiscallResolver is used
// or not.
//
// Searching for the above strings in the root library path
// of your compiler should enable the correct libraries to be
// identified if they aren't immediately obvious.
//
// Note that the current implementation of IASIOThiscallResolver
// is not COM compliant - it does not correctly implement the
// IUnknown interface. Implementing it is not necessary because
// it is not called by parts of the ASIO SDK which call through
// theAsioDriver ptr. The IUnknown methods are implemented as
// assert(false) to ensure that the code fails if they are
// ever called.
// Restrictions: None. Public Domain & Open Source distribute freely
// You may use IASIOThiscallResolver commercially as well as
// privately.
// You the user assume the responsibility for the use of the
// files, binary or text, and there is no guarantee or warranty,
// expressed or implied, including but not limited to the
// implied warranties of merchantability and fitness for a
// particular purpose. You assume all responsibility and agree
// to hold no entity, copyright holder or distributors liable
// for any loss of data or inaccurate representations of data
// as a result of using IASIOThiscallResolver.
// Version: 1.4 Added separate macro CALL_THISCALL_1_DOUBLE from
// Andrew Baldwin, and volatile for whole gcc asm blocks,
// both for compatibility with newer gcc versions. Cleaned up
// Borland asm to use one less register.
// 1.3 Switched to including assert.h for better compatibility.
// Wrapped entire .h and .cpp contents with a check for
// _MSC_VER to provide better compatibility with MS compilers.
// Changed Singleton implementation to use static instance
// instead of freestore allocated instance. Removed ASIOExit
// macro as it is no longer needed.
// 1.2 Removed semicolons from ASIOInit and ASIOExit macros to
// allow them to be embedded in expressions (if statements).
// Cleaned up some comments. Removed combase.c dependency (it
// doesn't compile with BCB anyway) by stubbing IUnknown.
// 1.1 Incorporated comments from Ross Bencina including things
// such as changing name from ThiscallResolver to
// IASIOThiscallResolver, tidying up the constructor, fixing
// a bug in IASIOThiscallResolver::ASIOExit() and improving
// portability through the use of conditional compilation
// 1.0 Initial working version.
// Created: 6/09/2003
// Authors: Fraser Adams
// Ross Bencina
// Rene G. Ceballos
// Martin Fay
// Antti Silvast
// Andrew Baldwin
//
// ****************************************************************************
#ifndef included_iasiothiscallresolver_h
#define included_iasiothiscallresolver_h
// We only need IASIOThiscallResolver at all if we are on Win32. For other
// platforms we simply bypass the IASIOThiscallResolver definition to allow us
// to be safely #include'd whatever the platform to keep client code portable
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
// If microsoft compiler we can call IASIO directly so IASIOThiscallResolver
// is not used.
#if !defined(_MSC_VER)
// The following is in order to ensure that this header is only included after
// the other ASIO headers (except for the case of iasiothiscallresolver.cpp).
// We need to do this because IASIOThiscallResolver works by eclipsing the
// original definition of ASIOInit() with a macro (see below).
#if !defined(iasiothiscallresolver_sourcefile)
#if !defined(__ASIO_H)
#error iasiothiscallresolver.h must be included AFTER asio.h
#endif
#endif
#include <windows.h>
#include "iasiodrv.h" /* From ASIO SDK */
class IASIOThiscallResolver : public IASIO {
private:
IASIO* that_; // Points to the real IASIO
static IASIOThiscallResolver instance; // Singleton instance
// Constructors - declared private so construction is limited to
// our Singleton instance
IASIOThiscallResolver();
IASIOThiscallResolver(IASIO* that);
public:
// Methods from the IUnknown interface. We don't fully implement IUnknown
// because the ASIO SDK never calls these methods through theAsioDriver ptr.
// These methods are implemented as assert(false).
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppv);
virtual ULONG STDMETHODCALLTYPE AddRef();
virtual ULONG STDMETHODCALLTYPE Release();
// Methods from the IASIO interface, implemented as forwarning calls to that.
virtual ASIOBool init(void *sysHandle);
virtual void getDriverName(char *name);
virtual long getDriverVersion();
virtual void getErrorMessage(char *string);
virtual ASIOError start();
virtual ASIOError stop();
virtual ASIOError getChannels(long *numInputChannels, long *numOutputChannels);
virtual ASIOError getLatencies(long *inputLatency, long *outputLatency);
virtual ASIOError getBufferSize(long *minSize, long *maxSize, long *preferredSize, long *granularity);
virtual ASIOError canSampleRate(ASIOSampleRate sampleRate);
virtual ASIOError getSampleRate(ASIOSampleRate *sampleRate);
virtual ASIOError setSampleRate(ASIOSampleRate sampleRate);
virtual ASIOError getClockSources(ASIOClockSource *clocks, long *numSources);
virtual ASIOError setClockSource(long reference);
virtual ASIOError getSamplePosition(ASIOSamples *sPos, ASIOTimeStamp *tStamp);
virtual ASIOError getChannelInfo(ASIOChannelInfo *info);
virtual ASIOError createBuffers(ASIOBufferInfo *bufferInfos, long numChannels, long bufferSize, ASIOCallbacks *callbacks);
virtual ASIOError disposeBuffers();
virtual ASIOError controlPanel();
virtual ASIOError future(long selector,void *opt);
virtual ASIOError outputReady();
// Class method, see ASIOInit() macro below.
static ASIOError ASIOInit(ASIODriverInfo *info); // Delegates to ::ASIOInit
};
// Replace calls to ASIOInit with our interposing version.
// This macro enables us to perform thiscall resolution simply by #including
// <iasiothiscallresolver.h> after the asio #includes (this file _must_ be
// included _after_ the asio #includes)
#define ASIOInit(name) IASIOThiscallResolver::ASIOInit((name))
#endif /* !defined(_MSC_VER) */
#endif /* Win32 */
#endif /* included_iasiothiscallresolver_h */

+ 25
- 17
doc/doxygen/tutorial.txt View File

@@ -36,7 +36,7 @@ The RtError class declaration and definition have been extracted to a separate f

\section download Download

Latest Release (14 October 2005): <A href="http://music.mcgill.ca/~gary/rtaudio/release/rtaudio-3.0.2.tar.gz">Version 3.0.2</A>
Latest Release (18 November 2005): <A href="http://music.mcgill.ca/~gary/rtaudio/release/rtaudio-3.0.3.tar.gz">Version 3.0.3</A>

\section start Getting Started

@@ -66,12 +66,12 @@ int main()
}
\endcode

Obviously, this example doesn't demonstrate any of the real functionality of RtAudio. However, all uses of RtAudio must begin with a constructor (either default or overloaded varieties) and must end with class destruction. Further, it is necessary that all class methods which can throw a C++ exception be called within a try/catch block.
Obviously, this example doesn't demonstrate any of the real functionality of RtAudio. However, all uses of RtAudio must begin with a constructor (either default or overloaded varieties) and must end with class destruction. Further, it is necessary that all class methods that can throw a C++ exception be called within a try/catch block.


\section error Error Handling

RtAudio uses a C++ exception handler called RtError, which is declared and defined in RtError.h. The RtError class is quite simple but it does allow errors to be "caught" by RtError::Type. Almost all RtAudio methods can "throw" an RtError, most typically if a driver error occurs or a stream function is called when no stream is open. There are a number of cases within RtAudio where warning messages may be displayed but an exception is not thrown. There is a protected RtAudio method, error(), which can be modified to globally control how these messages are handled and reported. By default, error messages are not automatically displayed in RtAudio unless the preprocessor definition __RTAUDIO_DEBUG__ is defined. Messages associated with caught exceptions can be displayed with, for example, the RtError::printMessage() function.
RtAudio uses a C++ exception handler called RtError, which is declared and defined in RtError.h. The RtError class is quite simple but it does allow errors to be "caught" by RtError::Type. Almost all RtAudio methods can "throw" an RtError, most typically if a driver error occurs or a stream function is called when no stream is open. There are a number of cases within RtAudio where warning messages may be displayed but an exception is not thrown. There is a protected RtAudio method, error(), that can be modified to globally control how these messages are handled and reported. By default, error messages are not automatically displayed in RtAudio unless the preprocessor definition __RTAUDIO_DEBUG__ is defined. Messages associated with caught exceptions can be displayed with, for example, the RtError::printMessage() function.


\section probing Probing Device Capabilities
@@ -152,7 +152,7 @@ The following data formats are defined and fully supported by RtAudio:
static const RtAudioFormat RTAUDIO_FLOAT64; // 64-bit double normalized between +/- 1.0
\endcode

The <I>nativeFormats</I> member of the RtAudioDeviceInfo structure is a bit mask of the above formats which are natively supported by the device. However, RtAudio will automatically provide format conversion if a particular format is not natively supported. When the <I>probed</I> member of the RtAudioDeviceInfo structure is false, the remaining structure members are undefined and the device is probably unuseable.
The <I>nativeFormats</I> member of the RtAudioDeviceInfo structure is a bit mask of the above formats that are natively supported by the device. However, RtAudio will automatically provide format conversion if a particular format is not natively supported. When the <I>probed</I> member of the RtAudioDeviceInfo structure is false, the remaining structure members are undefined and the device is probably unuseable.

While some audio devices may require a minimum channel value greater than one, RtAudio will provide automatic channel number compensation when the number of channels set by the user is less than that required by the device. Channel compensation is <I>NOT</I> possible when the number of channels set by the user is greater than that supported by the device.

@@ -201,11 +201,11 @@ int main()
}
\endcode

The RtAudio::openStream() method attempts to open a stream with a specified set of parameter values. In this case, we attempt to open a two channel playback stream with the default output device, 32-bit floating point data, a sample rate of 44100 Hz, a frame rate of 256 sample frames per read/write, and 4 internal device buffers. When device = 0, RtAudio first attempts to open the default audio device with the given parameters. If that attempt fails, RtAudio searches through the remaining available devices in an effort to find a device which will meet the given parameters. If all attempts are unsuccessful, an RtError is thrown. When a non-zero device value is specified, an attempt is made to open that device \e ONLY (device = 1 specifies the first identified device, as reported by RtAudio::getDeviceInfo()).
The RtAudio::openStream() method attempts to open a stream with a specified set of parameter values. In this case, we attempt to open a two channel playback stream with the default output device, 32-bit floating point data, a sample rate of 44100 Hz, a frame rate of 256 sample frames per read/write, and 4 internal device buffers. When device = 0, RtAudio first attempts to open the default audio device with the given parameters. If that attempt fails, RtAudio searches through the remaining available devices in an effort to find a device that will meet the given parameters. If all attempts are unsuccessful, an RtError is thrown. When a non-zero device value is specified, an attempt is made to open that device \e ONLY (device = 1 specifies the first identified device, as reported by RtAudio::getDeviceInfo()).

RtAudio provides four signed integer and two floating point data formats which can be specified using the RtAudioFormat parameter values mentioned earlier. If the opened device does not natively support the given format, RtAudio will automatically perform the necessary data format conversion.
RtAudio provides four signed integer and two floating point data formats that can be specified using the RtAudioFormat parameter values mentioned earlier. If the opened device does not natively support the given format, RtAudio will automatically perform the necessary data format conversion.

The <I>bufferSize</I> parameter specifies the desired number of sample frames which will be written to and/or read from a device per write/read operation. The <I>nBuffers</I> parameter is used in setting the underlying device buffer parameters. Both the <I>bufferSize</I> and <I>nBuffers</I> parameters can be used to control stream latency though there is no guarantee that the passed values will be those used by a device (the <I>nBuffers</I> parameter is ignored when using the OS X CoreAudio, Linux Jack, and the Windows ASIO APIs). In general, lower values for both parameters will produce less latency but perhaps less robust performance. Both parameters can be specified with values of zero, in which case the smallest allowable values will be used. The <I>bufferSize</I> parameter is passed as a pointer and the actual value used by the stream is set during the device setup procedure. <I>bufferSize</I> values should be a power of two. Optimal and allowable buffer values tend to vary between systems and devices. Check the \ref apinotes section for general guidelines.
The <I>bufferSize</I> parameter specifies the desired number of sample frames that will be written to and/or read from a device per write/read operation. The <I>nBuffers</I> parameter is used in setting the underlying device buffer parameters. Both the <I>bufferSize</I> and <I>nBuffers</I> parameters can be used to control stream latency though there is no guarantee that the passed values will be those used by a device (the <I>nBuffers</I> parameter is ignored when using the OS X CoreAudio, Linux Jack, and the Windows ASIO APIs). In general, lower values for both parameters will produce less latency but perhaps less robust performance. Both parameters can be specified with values of zero, in which case the smallest allowable values will be used. The <I>bufferSize</I> parameter is passed as a pointer and the actual value used by the stream is set during the device setup procedure. <I>bufferSize</I> values should be a power of two. Optimal and allowable buffer values tend to vary between systems and devices. Check the \ref apinotes section for general guidelines.

As noted earlier, the device capabilities reported by a driver or underlying audio API are not always accurate and/or may be dependent on a combination of device settings. Because of this, RtAudio does not attempt to query a device's capabilities or use previously reported values when opening a device. Instead, RtAudio simply attempts to set the given parameters on a specified device and then checks whether the setup is successful or not.

@@ -252,7 +252,7 @@ int main()
goto cleanup;
}

// An example loop which runs for 40000 sample frames
// An example loop that runs for 40000 sample frames
count = 0;
while (count < 40000) {
// Generate your samples and fill the buffer with bufferSize sample frames of data
@@ -295,7 +295,7 @@ In general, one should call the RtAudio::stopStream() and RtAudio::closeStream()

\section playbackc Playback (callback functionality)

The primary difference in using RtAudio with callback functionality involves the creation of a user-defined callback function. Here is an example which produces a sawtooth waveform for playback.
The primary difference in using RtAudio with callback functionality involves the creation of a user-defined callback function. Here is an example that produces a sawtooth waveform for playback.

\code

@@ -374,7 +374,7 @@ int main()
}
\endcode

After opening the device in exactly the same way as the previous example (except with a data format change), we must set our callback function for the stream using RtAudio::setStreamCallback(). When the underlying audio API uses blocking calls (OSS, ALSA, SGI, and Windows DirectSound), this method will spawn a new process (or thread) which automatically calls the callback function when more data is needed. Callback-based audio APIs (OS X CoreAudio Linux Jack, and ASIO) implement their own event notification schemes. Note that the callback function is called only when the stream is "running" (between calls to the RtAudio::startStream() and RtAudio::stopStream() methods). The last argument to RtAudio::setStreamCallback() is a pointer to arbitrary data that you wish to access from within your callback function.
After opening the device in exactly the same way as the previous example (except with a data format change), we must set our callback function for the stream using RtAudio::setStreamCallback(). When the underlying audio API uses blocking calls (OSS, ALSA, SGI, and Windows DirectSound), this method will spawn a new process (or thread) that automatically calls the callback function when more data is needed. Callback-based audio APIs (OS X CoreAudio Linux Jack, and ASIO) implement their own event notification schemes. Note that the callback function is called only when the stream is "running" (between calls to the RtAudio::startStream() and RtAudio::stopStream() methods). The last argument to RtAudio::setStreamCallback() is a pointer to arbitrary data that you wish to access from within your callback function.

In this example, we stop the stream with an explicit call to RtAudio::stopStream(). When using callback functionality, it is also possible to stop a stream by returning a non-zero value from the callback function.

@@ -423,7 +423,7 @@ int main()
goto cleanup;
}

// An example loop which runs for about 40000 sample frames
// An example loop that runs for about 40000 sample frames
count = 0;
while (count < 40000) {

@@ -645,7 +645,7 @@ The example compiler statements above could be used to compile the <TT>probe.cpp

\section debug Debugging

If you are having problems getting RtAudio to run on your system, try passing the preprocessor definition <TT>__RTAUDIO_DEBUG__</TT> to the compiler (or uncomment the definition at the bottom of RtAudio.h). A variety of warning messages will be displayed which may help in determining the problem. Also try using the programs included in the <tt>test</tt> directory. The program <tt>info</tt> displays the queried capabilities of all hardware devices found.
If you are having problems getting RtAudio to run on your system, try passing the preprocessor definition <TT>__RTAUDIO_DEBUG__</TT> to the compiler (or uncomment the definition at the bottom of RtAudio.h). A variety of warning messages will be displayed that may help in determining the problem. Also try using the programs included in the <tt>test</tt> directory. The program <tt>info</tt> displays the queried capabilities of all hardware devices found.

\section apinotes API Notes

@@ -655,7 +655,7 @@ RtAudio is designed to provide a common API across the various supported operati

RtAudio for Linux was developed under Redhat distributions 7.0 - Fedora. Three different audio APIs are supported on Linux platforms: OSS, <A href="http://www.alsa-project.org/">ALSA</A>, and <A href="http://jackit.sourceforge.net/">Jack</A>. The OSS API has existed for at least 6 years and the Linux kernel is distributed with free versions of OSS audio drivers. Therefore, a generic Linux system is most likely to have OSS support (though the availability and quality of OSS drivers for new hardware is decreasing). The ALSA API, although relatively new, is now part of the Linux development kernel and offers significantly better functionality than the OSS API. RtAudio provides support for the 1.0 and higher versions of ALSA. Jack, which is still in development, is a low-latency audio server, written primarily for the GNU/Linux operating system. It can connect a number of different applications to an audio device, as well as allow them to share audio between themselves. Input/output latency on the order of 15 milliseconds can typically be achieved using any of the Linux APIs by fine-tuning the RtAudio buffer parameters (without kernel modifications). Latencies on the order of 5 milliseconds or less can be achieved using a low-latency kernel patch and increasing FIFO scheduling priority. The pthread library, which is used for callback functionality, is a standard component of all Linux distributions.

The ALSA library includes OSS emulation support. That means that you can run programs compiled for the OSS API even when using the ALSA drivers and library. It should be noted however that OSS emulation under ALSA is not perfect. Specifically, channel number queries seem to consistently produce invalid results. While OSS emulation is successful for the majority of RtAudio tests, it is recommended that the native ALSA implementation of RtAudio be used on systems which have ALSA drivers installed.
The ALSA library includes OSS emulation support. That means that you can run programs compiled for the OSS API even when using the ALSA drivers and library. It should be noted however that OSS emulation under ALSA is not perfect. Specifically, channel number queries seem to consistently produce invalid results. While OSS emulation is successful for the majority of RtAudio tests, it is recommended that the native ALSA implementation of RtAudio be used on systems that have ALSA drivers installed.

The ALSA implementation of RtAudio makes no use of the ALSA "plug" interface. All necessary data format conversions, channel compensation, de-interleaving, and byte-swapping is handled by internal RtAudio routines.

@@ -673,13 +673,17 @@ The Irix version of RtAudio was written and tested on an SGI Indy running Irix v

\subsection windowsds Windows (DirectSound):

In order to compile RtAudio under Windows for the DirectSound API, you must have the header and source files for DirectSound version 5.0 or higher. As far as I know, there is no DirectSoundCapture support for Windows NT. Audio output latency with DirectSound can be reasonably good (on the order of 20 milliseconds). On the other hand, input audio latency tends to be terrible (100 milliseconds or more). Further, DirectSound drivers tend to crash easily when experimenting with buffer parameters. On my system, I found it necessary to use values around nBuffers = 8 and bufferSize = 512 to avoid crashes. RtAudio was originally developed with Visual C++ version 6.0.
In order to compile RtAudio under Windows for the DirectSound API, you must have the header and source files for DirectSound version 5.0 or higher. As far as I know, there is no DirectSoundCapture support for Windows NT. Audio output latency with DirectSound can be reasonably good, especially since RtAudio version 3.0.2. Input audio latency still tends to be bad but better since version 3.0.2. RtAudio was originally developed with Visual C++ version 6.0 but has been tested with .NET.

The DirectSound version of RtAudio can be compiled with or without the UNICODE preprocessor definition.

\subsection windowsasio Windows (ASIO):

The Steinberg ASIO audio API is based on a callback scheme. In addition, the API allows only a single device driver to be loaded and accessed at a time. ASIO device drivers must be supplied by audio hardware manufacturers, though ASIO emulation is possible on top of systems with DirectSound drivers. The <I>numberOfBuffers</I> parameter to the RtAudio::openStream() function has no affect in this implementation.

A number of ASIO source and header files are required for use with RtAudio. Specifically, an RtAudio project must include the following files: <TT>asio.h,cpp; asiodrivers.h,cpp; asiolist.h,cpp; asiodrvr.h; asiosys.h; ginclude.h; iasiodrv.h</TT>. The Visual C++ projects found in <TT>/tests/Windows/</TT> compile both ASIO and DirectSound support.
A number of ASIO source and header files are required for use with RtAudio. Specifically, an RtAudio project must include the following files: <TT>asio.h,cpp; asiodrivers.h,cpp; asiolist.h,cpp; asiodrvr.h; asiosys.h; ginclude.h; iasiodrv.h; iasiothiscallresolver.h,cpp</TT>. The Visual C++ projects found in <TT>/tests/Windows/</TT> compile both ASIO and DirectSound support.

The Steinberg provided <TT>asiolist</TT> class does not compile when the preprocessor definition UNICODE is defined. Note that this could be an issue when using RtAudio with Qt, though Qt programs appear to compile without the UNICODE definition (try <tt>DEFINES -= UNICODE</tt> in your .pro file). RtAudio with ASIO support has been tested using the MinGW compiler under Windows XP, as well as in the Visual Studio environment.

\section wishlist Possible Future Changes

@@ -694,8 +698,12 @@ There are a few issues that still need to be addressed in future versions of RtA

\section acknowledge Acknowledgements

Thanks to Robin Davies for a number of bug fixes and improvements to
the DirectSound and ASIO implementations in the 3.0.2 release!
Many thanks to the following people for providing bug fixes and improvements:
<UL>
<LI>Robin Davies (Windows DS and ASIO)</LI>
<LI>Ryan Williams (Windows non-MS compiler ASIO support)</LI>
<LI>Ed Wildgoose (Linux ALSA and Jack)</LI>
</UL>

The RtAudio API incorporates many of the concepts developed in the <A
href="http://www.portaudio.com/">PortAudio</A> project by Phil Burk


+ 6
- 0
doc/release.txt View File

@@ -2,6 +2,12 @@ RtAudio - a set of C++ classes which provide a common API for realtime audio inp

By Gary P. Scavone, 2001-2005.

v3.0.3: ( November 2005)
- UNICODE fix for Windows DirectSound API
- MinGW compiler fix for ASIO API
- jack support to create virtual devices for each jack plugin
- support to prefill output buffer with zeroes in duplex mode

v3.0.2: (14 October 2005)
- modification of ALSA read/write order to fix duplex under/overruns
- added synchronization of input/output devices for ALSA duplex operation


+ 0
- 955
tests/Windows/asio.h View File

@@ -1,955 +0,0 @@
//---------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------
/*
Steinberg Audio Stream I/O API
(c) 1997 - 1999, Steinberg Soft- und Hardware GmbH
ASIO Interface Specification v 2.0
basic concept is an i/o synchronous double-buffer scheme:
on bufferSwitch(index == 0), host will read/write:
after ASIOStart(), the
read first input buffer A (index 0)
| will be invalid (empty)
* ------------------------
|------------------------|-----------------------|
| | |
| Input Buffer A (0) | Input Buffer B (1) |
| | |
|------------------------|-----------------------|
| | |
| Output Buffer A (0) | Output Buffer B (1) |
| | |
|------------------------|-----------------------|
* -------------------------
| before calling ASIOStart(),
write host will have filled output
buffer B (index 1) already
*please* take special care of proper statement of input
and output latencies (see ASIOGetLatencies()), these
control sequencer sync accuracy
*/
//---------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------
/*
prototypes summary:
ASIOError ASIOInit(ASIODriverInfo *info);
ASIOError ASIOExit(void);
ASIOError ASIOStart(void);
ASIOError ASIOStop(void);
ASIOError ASIOGetChannels(long *numInputChannels, long *numOutputChannels);
ASIOError ASIOGetLatencies(long *inputLatency, long *outputLatency);
ASIOError ASIOGetBufferSize(long *minSize, long *maxSize, long *preferredSize, long *granularity);
ASIOError ASIOCanSampleRate(ASIOSampleRate sampleRate);
ASIOError ASIOGetSampleRate(ASIOSampleRate *currentRate);
ASIOError ASIOSetSampleRate(ASIOSampleRate sampleRate);
ASIOError ASIOGetClockSources(ASIOClockSource *clocks, long *numSources);
ASIOError ASIOSetClockSource(long reference);
ASIOError ASIOGetSamplePosition (ASIOSamples *sPos, ASIOTimeStamp *tStamp);
ASIOError ASIOGetChannelInfo(ASIOChannelInfo *info);
ASIOError ASIOCreateBuffers(ASIOBufferInfo *bufferInfos, long numChannels,
long bufferSize, ASIOCallbacks *callbacks);
ASIOError ASIODisposeBuffers(void);
ASIOError ASIOControlPanel(void);
void *ASIOFuture(long selector, void *params);
ASIOError ASIOOutputReady(void);
*/
//---------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------
#ifndef __ASIO_H
#define __ASIO_H
// force 4 byte alignment
#if defined(_MSC_VER) && !defined(__MWERKS__)
#pragma pack(push,4)
#elif PRAGMA_ALIGN_SUPPORTED
#pragma options align = native
#endif
//- - - - - - - - - - - - - - - - - - - - - - - - -
// Type definitions
//- - - - - - - - - - - - - - - - - - - - - - - - -
// number of samples data type is 64 bit integer
#if NATIVE_INT64
typedef long long int ASIOSamples;
#else
typedef struct ASIOSamples {
unsigned long hi;
unsigned long lo;
} ASIOSamples;
#endif
// Timestamp data type is 64 bit integer,
// Time format is Nanoseconds.
#if NATIVE_INT64
typedef long long int ASIOTimeStamp ;
#else
typedef struct ASIOTimeStamp {
unsigned long hi;
unsigned long lo;
} ASIOTimeStamp;
#endif
// Samplerates are expressed in IEEE 754 64 bit double float,
// native format as host computer
#if IEEE754_64FLOAT
typedef double ASIOSampleRate;
#else
typedef struct ASIOSampleRate {
char ieee[8];
} ASIOSampleRate;
#endif
// Boolean values are expressed as long
typedef long ASIOBool;
enum {
ASIOFalse = 0,
ASIOTrue = 1
};
// Sample Types are expressed as long
typedef long ASIOSampleType;
enum {
ASIOSTInt16MSB = 0,
ASIOSTInt24MSB = 1, // used for 20 bits as well
ASIOSTInt32MSB = 2,
ASIOSTFloat32MSB = 3, // IEEE 754 32 bit float
ASIOSTFloat64MSB = 4, // IEEE 754 64 bit double float
// these are used for 32 bit data buffer, with different alignment of the data inside
// 32 bit PCI bus systems can be more easily used with these
ASIOSTInt32MSB16 = 8, // 32 bit data with 18 bit alignment
ASIOSTInt32MSB18 = 9, // 32 bit data with 18 bit alignment
ASIOSTInt32MSB20 = 10, // 32 bit data with 20 bit alignment
ASIOSTInt32MSB24 = 11, // 32 bit data with 24 bit alignment
ASIOSTInt16LSB = 16,
ASIOSTInt24LSB = 17, // used for 20 bits as well
ASIOSTInt32LSB = 18,
ASIOSTFloat32LSB = 19, // IEEE 754 32 bit float, as found on Intel x86 architecture
ASIOSTFloat64LSB = 20, // IEEE 754 64 bit double float, as found on Intel x86 architecture
// these are used for 32 bit data buffer, with different alignment of the data inside
// 32 bit PCI bus systems can more easily used with these
ASIOSTInt32LSB16 = 24, // 32 bit data with 18 bit alignment
ASIOSTInt32LSB18 = 25, // 32 bit data with 18 bit alignment
ASIOSTInt32LSB20 = 26, // 32 bit data with 20 bit alignment
ASIOSTInt32LSB24 = 27 // 32 bit data with 24 bit alignment
};
//- - - - - - - - - - - - - - - - - - - - - - - - -
// Error codes
//- - - - - - - - - - - - - - - - - - - - - - - - -
typedef long ASIOError;
enum {
ASE_OK = 0, // This value will be returned whenever the call succeeded
ASE_SUCCESS = 0x3f4847a0, // unique success return value for ASIOFuture calls
ASE_NotPresent = -1000, // hardware input or output is not present or available
ASE_HWMalfunction, // hardware is malfunctioning (can be returned by any ASIO function)
ASE_InvalidParameter, // input parameter invalid
ASE_InvalidMode, // hardware is in a bad mode or used in a bad mode
ASE_SPNotAdvancing, // hardware is not running when sample position is inquired
ASE_NoClock, // sample clock or rate cannot be determined or is not present
ASE_NoMemory // not enough memory for completing the request
};
//---------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------
//- - - - - - - - - - - - - - - - - - - - - - - - -
// Time Info support
//- - - - - - - - - - - - - - - - - - - - - - - - -
typedef struct ASIOTimeCode
{
double speed; // speed relation (fraction of nominal speed)
// optional; set to 0. or 1. if not supported
ASIOSamples timeCodeSamples; // time in samples
unsigned long flags; // some information flags (see below)
char future[64];
} ASIOTimeCode;
typedef enum ASIOTimeCodeFlags
{
kTcValid = 1,
kTcRunning = 1 << 1,
kTcReverse = 1 << 2,
kTcOnspeed = 1 << 3,
kTcStill = 1 << 4,
kTcSpeedValid = 1 << 8
} ASIOTimeCodeFlags;
typedef struct AsioTimeInfo
{
double speed; // absolute speed (1. = nominal)
ASIOTimeStamp systemTime; // system time related to samplePosition, in nanoseconds
// on mac, must be derived from Microseconds() (not UpTime()!)
// on windows, must be derived from timeGetTime()
ASIOSamples samplePosition;
ASIOSampleRate sampleRate; // current rate
unsigned long flags; // (see below)
char reserved[12];
} AsioTimeInfo;
typedef enum AsioTimeInfoFlags
{
kSystemTimeValid = 1, // must always be valid
kSamplePositionValid = 1 << 1, // must always be valid
kSampleRateValid = 1 << 2,
kSpeedValid = 1 << 3,
kSampleRateChanged = 1 << 4,
kClockSourceChanged = 1 << 5
} AsioTimeInfoFlags;
typedef struct ASIOTime // both input/output
{
long reserved[4]; // must be 0
struct AsioTimeInfo timeInfo; // required
struct ASIOTimeCode timeCode; // optional, evaluated if (timeCode.flags & kTcValid)
} ASIOTime;
/*
using time info:
it is recommended to use the new method with time info even if the asio
device does not support timecode; continuous calls to ASIOGetSamplePosition
and ASIOGetSampleRate are avoided, and there is a more defined relationship
between callback time and the time info.
see the example below.
to initiate time info mode, after you have received the callbacks pointer in
ASIOCreateBuffers, you will call the asioMessage callback with kAsioSupportsTimeInfo
as the argument. if this returns 1, host has accepted time info mode.
now host expects the new callback bufferSwitchTimeInfo to be used instead
of the old bufferSwitch method. the ASIOTime structure is assumed to be valid
and accessible until the callback returns.
using time code:
if the device supports reading time code, it will call host's asioMessage callback
with kAsioSupportsTimeCode as the selector. it may then fill the according
fields and set the kTcValid flag.
host will call the future method with the kAsioEnableTimeCodeRead selector when
it wants to enable or disable tc reading by the device. you should also support
the kAsioCanTimeInfo and kAsioCanTimeCode selectors in ASIOFuture (see example).
note:
the AsioTimeInfo/ASIOTimeCode pair is supposed to work in both directions.
as a matter of convention, the relationship between the sample
position counter and the time code at buffer switch time is
(ignoring offset between tc and sample pos when tc is running):
on input: sample 0 -> input buffer sample 0 -> time code 0
on output: sample 0 -> output buffer sample 0 -> time code 0
this means that for 'real' calculations, one has to take into account
the according latencies.
example:
ASIOTime asioTime;
in createBuffers()
{
memset(&asioTime, 0, sizeof(ASIOTime));
AsioTimeInfo* ti = &asioTime.timeInfo;
ti->sampleRate = theSampleRate;
ASIOTimeCode* tc = &asioTime.timeCode;
tc->speed = 1.;
timeInfoMode = false;
canTimeCode = false;
if(callbacks->asioMessage(kAsioSupportsTimeInfo, 0, 0, 0) == 1)
{
timeInfoMode = true;
#if kCanTimeCode
if(callbacks->asioMessage(kAsioSupportsTimeCode, 0, 0, 0) == 1)
canTimeCode = true;
#endif
}
}
void switchBuffers(long doubleBufferIndex, bool processNow)
{
if(timeInfoMode)
{
AsioTimeInfo* ti = &asioTime.timeInfo;
ti->flags = kSystemTimeValid | kSamplePositionValid | kSampleRateValid;
ti->systemTime = theNanoSeconds;
ti->samplePosition = theSamplePosition;
if(ti->sampleRate != theSampleRate)
ti->flags |= kSampleRateChanged;
ti->sampleRate = theSampleRate;
#if kCanTimeCode
if(canTimeCode && timeCodeEnabled)
{
ASIOTimeCode* tc = &asioTime.timeCode;
tc->timeCodeSamples = tcSamples; // tc in samples
tc->flags = kTcValid | kTcRunning | kTcOnspeed; // if so...
}
ASIOTime* bb = callbacks->bufferSwitchTimeInfo(&asioTime, doubleBufferIndex, processNow ? ASIOTrue : ASIOFalse);
#else
callbacks->bufferSwitchTimeInfo(&asioTime, doubleBufferIndex, processNow ? ASIOTrue : ASIOFalse);
#endif
}
else
callbacks->bufferSwitch(doubleBufferIndex, ASIOFalse);
}
ASIOError ASIOFuture(long selector, void *params)
{
switch(selector)
{
case kAsioEnableTimeCodeRead:
timeCodeEnabled = true;
return ASE_SUCCESS;
case kAsioDisableTimeCodeRead:
timeCodeEnabled = false;
return ASE_SUCCESS;
case kAsioCanTimeInfo:
return ASE_SUCCESS;
#if kCanTimeCode
case kAsioCanTimeCode:
return ASE_SUCCESS;
#endif
}
return ASE_NotPresent;
};
*/
//- - - - - - - - - - - - - - - - - - - - - - - - -
// application's audio stream handler callbacks
//- - - - - - - - - - - - - - - - - - - - - - - - -
typedef struct ASIOCallbacks
{
void (*bufferSwitch) (long doubleBufferIndex, ASIOBool directProcess);
// bufferSwitch indicates that both input and output are to be processed.
// the current buffer half index (0 for A, 1 for B) determines
// - the output buffer that the host should start to fill. the other buffer
// will be passed to output hardware regardless of whether it got filled
// in time or not.
// - the input buffer that is now filled with incoming data. Note that
// because of the synchronicity of i/o, the input always has at
// least one buffer latency in relation to the output.
// directProcess suggests to the host whether it should immedeately
// start processing (directProcess == ASIOTrue), or whether its process
// should be deferred because the call comes from a very low level
// (for instance, a high level priority interrupt), and direct processing
// would cause timing instabilities for the rest of the system. If in doubt,
// directProcess should be set to ASIOFalse.
// Note: bufferSwitch may be called at interrupt time for highest efficiency.
void (*sampleRateDidChange) (ASIOSampleRate sRate);
// gets called when the AudioStreamIO detects a sample rate change
// If sample rate is unknown, 0 is passed (for instance, clock loss
// when externally synchronized).
long (*asioMessage) (long selector, long value, void* message, double* opt);
// generic callback for various purposes, see selectors below.
// note this is only present if the asio version is 2 or higher
ASIOTime* (*bufferSwitchTimeInfo) (ASIOTime* params, long doubleBufferIndex, ASIOBool directProcess);
// new callback with time info. makes ASIOGetSamplePosition() and various
// calls to ASIOGetSampleRate obsolete,
// and allows for timecode sync etc. to be preferred; will be used if
// the driver calls asioMessage with selector kAsioSupportsTimeInfo.
} ASIOCallbacks;
// asioMessage selectors
enum
{
kAsioSelectorSupported = 1, // selector in <value>, returns 1L if supported,
// 0 otherwise
kAsioEngineVersion, // returns engine (host) asio implementation version,
// 2 or higher
kAsioResetRequest, // request driver reset. if accepted, this
// will close the driver (ASIO_Exit() ) and
// re-open it again (ASIO_Init() etc). some
// drivers need to reconfigure for instance
// when the sample rate changes, or some basic
// changes have been made in ASIO_ControlPanel().
// returns 1L; note the request is merely passed
// to the application, there is no way to determine
// if it gets accepted at this time (but it usually
// will be).
kAsioBufferSizeChange, // not yet supported, will currently always return 0L.
// for now, use kAsioResetRequest instead.
// once implemented, the new buffer size is expected
// in <value>, and on success returns 1L
kAsioResyncRequest, // the driver went out of sync, such that
// the timestamp is no longer valid. this
// is a request to re-start the engine and
// slave devices (sequencer). returns 1 for ok,
// 0 if not supported.
kAsioLatenciesChanged, // the drivers latencies have changed. The engine
// will refetch the latencies.
kAsioSupportsTimeInfo, // if host returns true here, it will expect the
// callback bufferSwitchTimeInfo to be called instead
// of bufferSwitch
kAsioSupportsTimeCode, // supports time code reading/writing
kAsioSupportsInputMonitor, // supports input monitoring
kAsioNumMessageSelectors
};
//---------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------
//- - - - - - - - - - - - - - - - - - - - - - - - -
// (De-)Construction
//- - - - - - - - - - - - - - - - - - - - - - - - -
typedef struct ASIODriverInfo
{
long asioVersion; // currently, 2
long driverVersion; // driver specific
char name[32];
char errorMessage[124];
void *sysRef; // on input: system reference
// (Windows: application main window handle, Mac & SGI: 0)
} ASIODriverInfo;
ASIOError ASIOInit(ASIODriverInfo *info);
/* Purpose:
Initialize the AudioStreamIO.
Parameter:
info: pointer to an ASIODriver structure:
- asioVersion:
- on input, the host version. *** Note *** this is 0 for earlier asio
implementations, and the asioMessage callback is implemeted
only if asioVersion is 2 or greater. sorry but due to a design fault
the driver doesn't have access to the host version in ASIOInit :-(
added selector for host (engine) version in the asioMessage callback
so we're ok from now on.
- on return, asio implementation version.
older versions are 1
if you support this version (namely, ASIO_outputReady() )
this should be 2 or higher. also see the note in
ASIO_getTimeStamp() !
- version: on return, the driver version (format is driver specific)
- name: on return, a null-terminated string containing the driver's name
- error message: on return, should contain a user message describing
the type of error that occured during ASIOInit(), if any.
- sysRef: platform specific
Returns:
If neither input nor output is present ASE_NotPresent
will be returned.
ASE_NoMemory, ASE_HWMalfunction are other possible error conditions
*/
ASIOError ASIOExit(void);
/* Purpose:
Terminates the AudioStreamIO.
Parameter:
None.
Returns:
If neither input nor output is present ASE_NotPresent
will be returned.
Notes: this implies ASIOStop() and ASIODisposeBuffers(),
meaning that no host callbacks must be accessed after ASIOExit().
*/
//- - - - - - - - - - - - - - - - - - - - - - - - -
// Start/Stop
//- - - - - - - - - - - - - - - - - - - - - - - - -
ASIOError ASIOStart(void);
/* Purpose:
Start input and output processing synchronously.
This will
- reset the sample counter to zero
- start the hardware (both input and output)
The first call to the hosts' bufferSwitch(index == 0) then tells
the host to read from input buffer A (index 0), and start
processing to output buffer A while output buffer B (which
has been filled by the host prior to calling ASIOStart())
is possibly sounding (see also ASIOGetLatencies())
Parameter:
None.
Returns:
If neither input nor output is present, ASE_NotPresent
will be returned.
If the hardware fails to start, ASE_HWMalfunction will be returned.
Notes:
There is no restriction on the time that ASIOStart() takes
to perform (that is, it is not considered a realtime trigger).
*/
ASIOError ASIOStop(void);
/* Purpose:
Stops input and output processing altogether.
Parameter:
None.
Returns:
If neither input nor output is present ASE_NotPresent
will be returned.
Notes:
On return from ASIOStop(), the driver must in no
case call the hosts' bufferSwitch() routine.
*/
//- - - - - - - - - - - - - - - - - - - - - - - - -
// Inquiry methods and sample rate
//- - - - - - - - - - - - - - - - - - - - - - - - -
ASIOError ASIOGetChannels(long *numInputChannels, long *numOutputChannels);
/* Purpose:
Returns number of individual input/output channels.
Parameter:
numInputChannels will hold the number of available input channels
numOutputChannels will hold the number of available output channels
Returns:
If no input/output is present ASE_NotPresent will be returned.
If only inputs, or only outputs are available, the according
other parameter will be zero, and ASE_OK is returned.
*/
ASIOError ASIOGetLatencies(long *inputLatency, long *outputLatency);
/* Purpose:
Returns the input and output latencies. This includes
device specific delays, like FIFOs etc.
Parameter:
inputLatency will hold the 'age' of the first sample frame
in the input buffer when the hosts reads it in bufferSwitch()
(this is theoretical, meaning it does not include the overhead
and delay between the actual physical switch, and the time
when bufferSitch() enters).
This will usually be the size of one block in sample frames, plus
device specific latencies.
outputLatency will specify the time between the buffer switch,
and the time when the next play buffer will start to sound.
The next play buffer is defined as the one the host starts
processing after (or at) bufferSwitch(), indicated by the
index parameter (0 for buffer A, 1 for buffer B).
It will usually be either one block, if the host writes directly
to a dma buffer, or two or more blocks if the buffer is 'latched' by
the driver. As an example, on ASIOStart(), the host will have filled
the play buffer at index 1 already; when it gets the callback (with
the parameter index == 0), this tells it to read from the input
buffer 0, and start to fill the play buffer 0 (assuming that now
play buffer 1 is already sounding). In this case, the output
latency is one block. If the driver decides to copy buffer 1
at that time, and pass it to the hardware at the next slot (which
is most commonly done, but should be avoided), the output latency
becomes two blocks instead, resulting in a total i/o latency of at least
3 blocks. As memory access is the main bottleneck in native dsp processing,
and to acheive less latency, it is highly recommended to try to avoid
copying (this is also why the driver is the owner of the buffers). To
summarize, the minimum i/o latency can be acheived if the input buffer
is processed by the host into the output buffer which will physically
start to sound on the next time slice. Also note that the host expects
the bufferSwitch() callback to be accessed for each time slice in order
to retain sync, possibly recursively; if it fails to process a block in
time, it will suspend its operation for some time in order to recover.
Returns:
If no input/output is present ASE_NotPresent will be returned.
*/
ASIOError ASIOGetBufferSize(long *minSize, long *maxSize, long *preferredSize, long *granularity);
/* Purpose:
Returns min, max, and preferred buffer sizes for input/output
Parameter:
minSize will hold the minimum buffer size
maxSize will hold the maxium possible buffer size
preferredSize will hold the preferred buffer size (a size which
best fits performance and hardware requirements)
granularity will hold the granularity at which buffer sizes
may differ. Usually, the buffer size will be a power of 2;
in this case, granularity will hold -1 on return, signalling
possible buffer sizes starting from minSize, increased in
powers of 2 up to maxSize.
Returns:
If no input/output is present ASE_NotPresent will be returned.
Notes:
When minimum and maximum buffer size are equal,
the preferred buffer size has to be the same value as well; granularity
should be 0 in this case.
*/
ASIOError ASIOCanSampleRate(ASIOSampleRate sampleRate);
/* Purpose:
Inquires the hardware for the available sample rates.
Parameter:
sampleRate is the rate in question.
Returns:
If the inquired sample rate is not supported, ASE_NoClock will be returned.
If no input/output is present ASE_NotPresent will be returned.
*/
ASIOError ASIOGetSampleRate(ASIOSampleRate *currentRate);
/* Purpose:
Get the current sample Rate.
Parameter:
currentRate will hold the current sample rate on return.
Returns:
If sample rate is unknown, sampleRate will be 0 and ASE_NoClock will be returned.
If no input/output is present ASE_NotPresent will be returned.
Notes:
*/
ASIOError ASIOSetSampleRate(ASIOSampleRate sampleRate);
/* Purpose:
Set the hardware to the requested sample Rate. If sampleRate == 0,
enable external sync.
Parameter:
sampleRate: on input, the requested rate
Returns:
If sampleRate is unknown ASE_NoClock will be returned.
If the current clock is external, and sampleRate is != 0,
ASE_InvalidMode will be returned
If no input/output is present ASE_NotPresent will be returned.
Notes:
*/
typedef struct ASIOClockSource
{
long index; // as used for ASIOSetClockSource()
long associatedChannel; // for instance, S/PDIF or AES/EBU
long associatedGroup; // see channel groups (ASIOGetChannelInfo())
ASIOBool isCurrentSource; // ASIOTrue if this is the current clock source
char name[32]; // for user selection
} ASIOClockSource;
ASIOError ASIOGetClockSources(ASIOClockSource *clocks, long *numSources);
/* Purpose:
Get the available external audio clock sources
Parameter:
clocks points to an array of ASIOClockSource structures:
- index: this is used to identify the clock source
when ASIOSetClockSource() is accessed, should be
an index counting from zero
- associatedInputChannel: the first channel of an associated
input group, if any.
- associatedGroup: the group index of that channel.
groups of channels are defined to seperate for
instance analog, S/PDIF, AES/EBU, ADAT connectors etc,
when present simultaniously. Note that associated channel
is enumerated according to numInputs/numOutputs, means it
is independant from a group (see also ASIOGetChannelInfo())
inputs are associated to a clock if the physical connection
transfers both data and clock (like S/PDIF, AES/EBU, or
ADAT inputs). if there is no input channel associated with
the clock source (like Word Clock, or internal oscillator), both
associatedChannel and associatedGroup should be set to -1.
- isCurrentSource: on exit, ASIOTrue if this is the current clock
source, ASIOFalse else
- name: a null-terminated string for user selection of the available sources.
numSources:
on input: the number of allocated array members
on output: the number of available clock sources, at least
1 (internal clock generator).
Returns:
If no input/output is present ASE_NotPresent will be returned.
Notes:
*/
ASIOError ASIOSetClockSource(long index);
/* Purpose:
Set the audio clock source
Parameter:
index as obtained from an inquiry to ASIOGetClockSources()
Returns:
If no input/output is present ASE_NotPresent will be returned.
If the clock can not be selected because an input channel which
carries the current clock source is active, ASE_InvalidMode
*may* be returned (this depends on the properties of the driver
and/or hardware).
Notes:
Should *not* return ASE_NoClock if there is no clock signal present
at the selected source; this will be inquired via ASIOGetSampleRate().
It should call the host callback procedure sampleRateHasChanged(),
if the switch causes a sample rate change, or if no external clock
is present at the selected source.
*/
ASIOError ASIOGetSamplePosition (ASIOSamples *sPos, ASIOTimeStamp *tStamp);
/* Purpose:
Inquires the sample position/time stamp pair.
Parameter:
sPos will hold the sample position on return. The sample
position is reset to zero when ASIOStart() gets called.
tStamp will hold the system time when the sample position
was latched.
Returns:
If no input/output is present, ASE_NotPresent will be returned.
If there is no clock, ASE_SPNotAdvancing will be returned.
Notes:
in order to be able to synchronise properly,
the sample position / time stamp pair must refer to the current block,
that is, the engine will call ASIOGetSamplePosition() in its bufferSwitch()
callback and expect the time for the current block. thus, when requested
in the very first bufferSwitch after ASIO_Start(), the sample position
should be zero, and the time stamp should refer to the very time where
the stream was started. it also means that the sample position must be
block aligned. the driver must ensure proper interpolation if the system
time can not be determined for the block position. the driver is responsible
for precise time stamps as it usually has most direct access to lower
level resources. proper behaviour of ASIO_GetSamplePosition() and ASIO_GetLatencies()
are essential for precise media synchronization!
*/
typedef struct ASIOChannelInfo
{
long channel; // on input, channel index
ASIOBool isInput; // on input
ASIOBool isActive; // on exit
long channelGroup; // dto
ASIOSampleType type; // dto
char name[32]; // dto
} ASIOChannelInfo;
ASIOError ASIOGetChannelInfo(ASIOChannelInfo *info);
/* Purpose:
retreive information about the nature of a channel
Parameter:
info: pointer to a ASIOChannelInfo structure with
- channel: on input, the channel index of the channel in question.
- isInput: on input, ASIOTrue if info for an input channel is
requested, else output
- channelGroup: on return, the channel group that the channel
belongs to. For drivers which support different types of
channels, like analog, S/PDIF, AES/EBU, ADAT etc interfaces,
there should be a reasonable grouping of these types. Groups
are always independant form a channel index, that is, a channel
index always counts from 0 to numInputs/numOutputs regardless
of the group it may belong to.
There will always be at least one group (group 0). Please
also note that by default, the host may decide to activate
channels 0 and 1; thus, these should belong to the most
useful type (analog i/o, if present).
- type: on return, contains the sample type of the channel
- isActive: on return, ASIOTrue if channel is active as it was
installed by ASIOCreateBuffers(), ASIOFalse else
- name: describing the type of channel in question. Used to allow
for user selection, and enabling of specific channels. examples:
"Analog In", "SPDIF Out" etc
Returns:
If no input/output is present ASE_NotPresent will be returned.
Notes:
If possible, the string should be organised such that the first
characters are most significantly describing the nature of the
port, to allow for identification even if the view showing the
port name is too small to display more than 8 characters, for
instance.
*/
//- - - - - - - - - - - - - - - - - - - - - - - - -
// Buffer preparation
//- - - - - - - - - - - - - - - - - - - - - - - - -
typedef struct ASIOBufferInfo
{
ASIOBool isInput; // on input: ASIOTrue: input, else output
long channelNum; // on input: channel index
void *buffers[2]; // on output: double buffer addresses
} ASIOBufferInfo;
ASIOError ASIOCreateBuffers(ASIOBufferInfo *bufferInfos, long numChannels,
long bufferSize, ASIOCallbacks *callbacks);
/* Purpose:
Allocates input/output buffers for all input and output channels to be activated.
Parameter:
bufferInfos is a pointer to an array of ASIOBufferInfo structures:
- isInput: on input, ASIOTrue if the buffer is to be allocated
for an input, output buffer else
- channelNum: on input, the index of the channel in question
(counting from 0)
- buffers: on exit, 2 pointers to the halves of the channels' double-buffer.
the size of the buffer(s) of course depend on both the ASIOSampleType
as obtained from ASIOGetChannelInfo(), and bufferSize
numChannels is the sum of all input and output channels to be created;
thus bufferInfos is a pointer to an array of numChannels ASIOBufferInfo
structures.
bufferSize selects one of the possible buffer sizes as obtained from
ASIOGetBufferSizes().
callbacks is a pointer to an ASIOCallbacks structure.
Returns:
If not enough memory is available ASE_NoMemory will be returned.
If no input/output is present ASE_NotPresent will be returned.
If bufferSize is not supported, or one or more of the bufferInfos elements
contain invalid settings, ASE_InvalidMode will be returned.
Notes:
If individual channel selection is not possible but requested,
the driver has to handle this. namely, bufferSwitch() will only
have filled buffers of enabled outputs. If possible, processing
and buss activities overhead should be avoided for channels which
were not enabled here.
*/
ASIOError ASIODisposeBuffers(void);
/* Purpose:
Releases all buffers for the device.
Parameter:
None.
Returns:
If no buffer were ever prepared, ASE_InvalidMode will be returned.
If no input/output is present ASE_NotPresent will be returned.
Notes:
This implies ASIOStop().
*/
ASIOError ASIOControlPanel(void);
/* Purpose:
request the driver to start a control panel component
for device specific user settings. This will not be
accessed on some platforms (where the component is accessed
instead).
Parameter:
None.
Returns:
If no panel is available ASE_NotPresent will be returned.
Actually, the return code is ignored.
Notes:
if the user applied settings which require a re-configuration
of parts or all of the enigine and/or driver (such as a change of
the block size), the asioMessage callback can be used (see
ASIO_Callbacks).
*/
ASIOError ASIOFuture(long selector, void *params);
/* Purpose:
various
Parameter:
selector: operation Code as to be defined. zero is reserved for
testing purposes.
params: depends on the selector; usually pointer to a structure
for passing and retreiving any type and amount of parameters.
Returns:
the return value is also selector dependant. if the selector
is unknown, ASE_InvalidParameter should be returned to prevent
further calls with this selector. on success, ASE_SUCCESS
must be returned (note: ASE_OK is *not* sufficient!)
Notes:
see selectors defined below.
*/
enum
{
kAsioEnableTimeCodeRead = 1, // no arguments
kAsioDisableTimeCodeRead, // no arguments
kAsioSetInputMonitor, // ASIOInputMonitor* in params
kAsioTransport, // ASIOTransportParameters* in params
kAsioSetInputGain, // ASIOChannelControls* in params, apply gain
kAsioGetInputMeter, // ASIOChannelControls* in params, fill meter
kAsioSetOutputGain, // ASIOChannelControls* in params, apply gain
kAsioGetOutputMeter, // ASIOChannelControls* in params, fill meter
kAsioCanInputMonitor, // no arguments for kAsioCanXXX selectors
kAsioCanTimeInfo,
kAsioCanTimeCode,
kAsioCanTransport,
kAsioCanInputGain,
kAsioCanInputMeter,
kAsioCanOutputGain,
kAsioCanOutputMeter
};
typedef struct ASIOInputMonitor
{
long input; // this input was set to monitor (or off), -1: all
long output; // suggested output for monitoring the input (if so)
long gain; // suggested gain, ranging 0 - 0x7fffffffL (-inf to +12 dB)
ASIOBool state; // ASIOTrue => on, ASIOFalse => off
long pan; // suggested pan, 0 => all left, 0x7fffffff => right
} ASIOInputMonitor;
typedef struct ASIOChannelControls
{
long channel; // on input, channel index
ASIOBool isInput; // on input
long gain; // on input, ranges 0 thru 0x7fffffff
long meter; // on return, ranges 0 thru 0x7fffffff
char future[32];
} ASIOChannelControls;
typedef struct ASIOTransportParameters
{
long command; // see enum below
ASIOSamples samplePosition;
long track;
long trackSwitches[16]; // 512 tracks on/off
char future[64];
} ASIOTransportParameters;
enum
{
kTransStart = 1,
kTransStop,
kTransLocate, // to samplePosition
kTransPunchIn,
kTransPunchOut,
kTransArmOn, // track
kTransArmOff, // track
kTransMonitorOn, // track
kTransMonitorOff, // track
kTransArm, // trackSwitches
kTransMonitor // trackSwitches
};
ASIOError ASIOOutputReady(void);
/* Purpose:
this tells the driver that the host has completed processing
the output buffers. if the data format required by the hardware
differs from the supported asio formats, but the hardware
buffers are DMA buffers, the driver will have to convert
the audio stream data; as the bufferSwitch callback is
usually issued at dma block switch time, the driver will
have to convert the *previous* host buffer, which increases
the output latency by one block.
when the host finds out that ASIOOutputReady() returns
true, it will issue this call whenever it completed
output processing. then the driver can convert the
host data directly to the dma buffer to be played next,
reducing output latency by one block.
another way to look at it is, that the buffer switch is called
in order to pass the *input* stream to the host, so that it can
process the input into the output, and the output stream is passed
to the driver when the host has completed its process.
Parameter:
None
Returns:
only if the above mentioned scenario is given, and a reduction
of output latency can be acheived by this mechanism, should
ASE_OK be returned. otherwise (and usually), ASE_NotPresent
should be returned in order to prevent further calls to this
function. note that the host may want to determine if it is
to use this when the system is not yet fully initialized, so
ASE_OK should always be returned if the mechanism makes sense.
Notes:
please remeber to adjust ASIOGetLatencies() according to
whether ASIOOutputReady() was ever called or not, if your
driver supports this scenario.
also note that the engine may fail to call ASIO_OutputReady()
in time in overload cases. as already mentioned, bufferSwitch
should be called for every block regardless of whether a block
could be processed in time.
*/
// restore old alignment
#if defined(_MSC_VER) && !defined(__MWERKS__)
#pragma pack(pop)
#elif PRAGMA_ALIGN_SUPPORTED
#pragma options align = reset
#endif
#endif

+ 0
- 41
tests/Windows/asiodrivers.h View File

@@ -1,41 +0,0 @@
#ifndef __AsioDrivers__
#define __AsioDrivers__
#include "ginclude.h"
#if MAC
#include "CodeFragments.hpp"
class AsioDrivers : public CodeFragments
#elif WINDOWS
#include <windows.h>
#include "asiolist.h"
class AsioDrivers : public AsioDriverList
#elif SGI || BEOS
#include "asiolist.h"
class AsioDrivers : public AsioDriverList
#else
#error implement me
#endif
{
public:
AsioDrivers();
~AsioDrivers();
bool getCurrentDriverName(char *name);
long getDriverNames(char **names, long maxDrivers);
bool loadDriver(char *name);
void removeCurrentDriver();
long getCurrentDriverIndex() {return curIndex;}
protected:
unsigned long connID;
long curIndex;
};
#endif

+ 0
- 46
tests/Windows/asiolist.h View File

@@ -1,46 +0,0 @@
#ifndef __asiolist__
#define __asiolist__
#define DRVERR -5000
#define DRVERR_INVALID_PARAM DRVERR-1
#define DRVERR_DEVICE_ALREADY_OPEN DRVERR-2
#define DRVERR_DEVICE_NOT_FOUND DRVERR-3
#define MAXPATHLEN 512
#define MAXDRVNAMELEN 128
struct asiodrvstruct
{
int drvID;
CLSID clsid;
char dllpath[MAXPATHLEN];
char drvname[MAXDRVNAMELEN];
LPVOID asiodrv;
struct asiodrvstruct *next;
};
typedef struct asiodrvstruct ASIODRVSTRUCT;
typedef ASIODRVSTRUCT *LPASIODRVSTRUCT;
class AsioDriverList {
public:
AsioDriverList();
~AsioDriverList();
LONG asioOpenDriver (int,VOID **);
LONG asioCloseDriver (int);
// nice to have
LONG asioGetNumDev (VOID);
LONG asioGetDriverName (int,char *,int);
LONG asioGetDriverPath (int,char *,int);
LONG asioGetDriverCLSID (int,CLSID *);
// or use directly access
LPASIODRVSTRUCT lpdrvlist;
int numdrv;
};
typedef class AsioDriverList *LPASIODRIVERLIST;
#endif

+ 0
- 82
tests/Windows/asiosys.h View File

@@ -1,82 +0,0 @@
#ifndef __asiosys__
#define __asiosys__
#ifdef WIN32
#undef MAC
#define PPC 0
#define WINDOWS 1
#define SGI 0
#define SUN 0
#define LINUX 0
#define BEOS 0
#define NATIVE_INT64 0
#define IEEE754_64FLOAT 1
#elif BEOS
#define MAC 0
#define PPC 0
#define WINDOWS 0
#define PC 0
#define SGI 0
#define SUN 0
#define LINUX 0
#define NATIVE_INT64 0
#define IEEE754_64FLOAT 1
#ifndef DEBUG
#define DEBUG 0
#if DEBUG
void DEBUGGERMESSAGE(char *string);
#else
#define DEBUGGERMESSAGE(a)
#endif
#endif
#elif SGI
#define MAC 0
#define PPC 0
#define WINDOWS 0
#define PC 0
#define SUN 0
#define LINUX 0
#define BEOS 0
#define NATIVE_INT64 0
#define IEEE754_64FLOAT 1
#ifndef DEBUG
#define DEBUG 0
#if DEBUG
void DEBUGGERMESSAGE(char *string);
#else
#define DEBUGGERMESSAGE(a)
#endif
#endif
#else // MAC
#define MAC 1
#define PPC 1
#define WINDOWS 0
#define PC 0
#define SGI 0
#define SUN 0
#define LINUX 0
#define BEOS 0
#define NATIVE_INT64 0
#define IEEE754_64FLOAT 1
#ifndef DEBUG
#define DEBUG 0
#if DEBUG
void DEBUGGERMESSAGE(char *string);
#else
#define DEBUGGERMESSAGE(a)
#endif
#endif
#endif
#endif

+ 18
- 10
tests/Windows/call_inout.dsp View File

@@ -87,15 +87,15 @@ LINK32=link.exe
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\asio.cpp
SOURCE=..\..\asio\asio.cpp
# End Source File
# Begin Source File
SOURCE=.\asiodrivers.cpp
SOURCE=..\..\asio\asiodrivers.cpp
# End Source File
# Begin Source File
SOURCE=.\asiolist.cpp
SOURCE=..\..\asio\asiolist.cpp
# End Source File
# Begin Source File
@@ -103,6 +103,10 @@ SOURCE=..\call_inout.cpp
# End Source File
# Begin Source File
SOURCE=..\..\asio\iasiothiscallresolver.cpp
# End Source File
# Begin Source File
SOURCE=..\..\RtAudio.cpp
# End Source File
# End Group
@@ -111,31 +115,35 @@ SOURCE=..\..\RtAudio.cpp
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\asio.h
SOURCE=..\..\asio\asio.h
# End Source File
# Begin Source File
SOURCE=..\..\asio\asiodrivers.h
# End Source File
# Begin Source File
SOURCE=.\asiodrivers.h
SOURCE=..\..\asio\asiodrvr.h
# End Source File
# Begin Source File
SOURCE=.\asiodrvr.h
SOURCE=..\..\asio\asiolist.h
# End Source File
# Begin Source File
SOURCE=.\asiolist.h
SOURCE=..\..\asio\asiosys.h
# End Source File
# Begin Source File
SOURCE=.\asiosys.h
SOURCE=..\..\asio\ginclude.h
# End Source File
# Begin Source File
SOURCE=.\ginclude.h
SOURCE=..\..\asio\iasiodrv.h
# End Source File
# Begin Source File
SOURCE=.\iasiodrv.h
SOURCE=..\..\asio\iasiothiscallresolver.h
# End Source File
# Begin Source File


+ 18
- 10
tests/Windows/call_saw.dsp View File

@@ -87,15 +87,15 @@ LINK32=link.exe
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\asio.cpp
SOURCE=..\..\asio\asio.cpp
# End Source File
# Begin Source File
SOURCE=.\asiodrivers.cpp
SOURCE=..\..\asio\asiodrivers.cpp
# End Source File
# Begin Source File
SOURCE=.\asiolist.cpp
SOURCE=..\..\asio\asiolist.cpp
# End Source File
# Begin Source File
@@ -103,6 +103,10 @@ SOURCE=..\call_saw.cpp
# End Source File
# Begin Source File
SOURCE=..\..\asio\iasiothiscallresolver.cpp
# End Source File
# Begin Source File
SOURCE=..\..\RtAudio.cpp
# End Source File
# End Group
@@ -111,31 +115,35 @@ SOURCE=..\..\RtAudio.cpp
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\asio.h
SOURCE=..\..\asio\asio.h
# End Source File
# Begin Source File
SOURCE=..\..\asio\asiodrivers.h
# End Source File
# Begin Source File
SOURCE=.\asiodrivers.h
SOURCE=..\..\asio\asiodrvr.h
# End Source File
# Begin Source File
SOURCE=.\asiodrvr.h
SOURCE=..\..\asio\asiolist.h
# End Source File
# Begin Source File
SOURCE=.\asiolist.h
SOURCE=..\..\asio\asiosys.h
# End Source File
# Begin Source File
SOURCE=.\asiosys.h
SOURCE=..\..\asio\ginclude.h
# End Source File
# Begin Source File
SOURCE=.\ginclude.h
SOURCE=..\..\asio\iasiodrv.h
# End Source File
# Begin Source File
SOURCE=.\iasiodrv.h
SOURCE=..\..\asio\iasiothiscallresolver.h
# End Source File
# Begin Source File


+ 0
- 38
tests/Windows/ginclude.h View File

@@ -1,38 +0,0 @@
#ifndef __gInclude__
#define __gInclude__
#if SGI
#undef BEOS
#undef MAC
#undef WINDOWS
//
#define ASIO_BIG_ENDIAN 1
#define ASIO_CPU_MIPS 1
#elif defined WIN32
#undef BEOS
#undef MAC
#undef SGI
#define WINDOWS 1
#define ASIO_LITTLE_ENDIAN 1
#define ASIO_CPU_X86 1
#elif BEOS
#undef MAC
#undef SGI
#undef WINDOWS
#define ASIO_LITTLE_ENDIAN 1
#define ASIO_CPU_X86 1
//
#else
#define MAC 1
#undef BEOS
#undef WINDOWS
#undef SGI
#define ASIO_BIG_ENDIAN 1
#define ASIO_CPU_PPC 1
#endif
// always
#define NATIVE_INT64 0
#define IEEE754_64FLOAT 1
#endif // __gInclude__

+ 18
- 10
tests/Windows/in_out.dsp View File

@@ -87,15 +87,19 @@ LINK32=link.exe
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\asio.cpp
SOURCE=..\..\asio\asio.cpp
# End Source File
# Begin Source File
SOURCE=.\asiodrivers.cpp
SOURCE=..\..\asio\asiodrivers.cpp
# End Source File
# Begin Source File
SOURCE=.\asiolist.cpp
SOURCE=..\..\asio\asiolist.cpp
# End Source File
# Begin Source File
SOURCE=..\..\asio\iasiothiscallresolver.cpp
# End Source File
# Begin Source File
@@ -111,31 +115,35 @@ SOURCE=..\..\RtAudio.cpp
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\asio.h
SOURCE=..\..\asio\asio.h
# End Source File
# Begin Source File
SOURCE=..\..\asio\asiodrivers.h
# End Source File
# Begin Source File
SOURCE=.\asiodrivers.h
SOURCE=..\..\asio\asiodrvr.h
# End Source File
# Begin Source File
SOURCE=.\asiodrvr.h
SOURCE=..\..\asio\asiolist.h
# End Source File
# Begin Source File
SOURCE=.\asiolist.h
SOURCE=..\..\asio\asiosys.h
# End Source File
# Begin Source File
SOURCE=.\asiosys.h
SOURCE=..\..\asio\ginclude.h
# End Source File
# Begin Source File
SOURCE=.\ginclude.h
SOURCE=..\..\asio\iasiodrv.h
# End Source File
# Begin Source File
SOURCE=.\iasiodrv.h
SOURCE=..\..\asio\iasiothiscallresolver.h
# End Source File
# Begin Source File


+ 18
- 10
tests/Windows/info.dsp View File

@@ -87,15 +87,19 @@ LINK32=link.exe
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\asio.cpp
SOURCE=..\..\asio\asio.cpp
# End Source File
# Begin Source File
SOURCE=.\asiodrivers.cpp
SOURCE=..\..\asio\asiodrivers.cpp
# End Source File
# Begin Source File
SOURCE=.\asiolist.cpp
SOURCE=..\..\asio\asiolist.cpp
# End Source File
# Begin Source File
SOURCE=..\..\asio\iasiothiscallresolver.cpp
# End Source File
# Begin Source File
@@ -111,31 +115,35 @@ SOURCE=..\..\RtAudio.cpp
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\asio.h
SOURCE=..\..\asio\asio.h
# End Source File
# Begin Source File
SOURCE=..\..\asio\asiodrivers.h
# End Source File
# Begin Source File
SOURCE=.\asiodrivers.h
SOURCE=..\..\asio\asiodrvr.h
# End Source File
# Begin Source File
SOURCE=.\asiodrvr.h
SOURCE=..\..\asio\asiolist.h
# End Source File
# Begin Source File
SOURCE=.\asiolist.h
SOURCE=..\..\asio\asiosys.h
# End Source File
# Begin Source File
SOURCE=.\asiosys.h
SOURCE=..\..\asio\ginclude.h
# End Source File
# Begin Source File
SOURCE=.\ginclude.h
SOURCE=..\..\asio\iasiodrv.h
# End Source File
# Begin Source File
SOURCE=.\iasiodrv.h
SOURCE=..\..\asio\iasiothiscallresolver.h
# End Source File
# Begin Source File


+ 18
- 10
tests/Windows/play_raw.dsp View File

@@ -87,15 +87,19 @@ LINK32=link.exe
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\asio.cpp
SOURCE=..\..\asio\asio.cpp
# End Source File
# Begin Source File
SOURCE=.\asiodrivers.cpp
SOURCE=..\..\asio\asiodrivers.cpp
# End Source File
# Begin Source File
SOURCE=.\asiolist.cpp
SOURCE=..\..\asio\asiolist.cpp
# End Source File
# Begin Source File
SOURCE=..\..\asio\iasiothiscallresolver.cpp
# End Source File
# Begin Source File
@@ -111,31 +115,35 @@ SOURCE=..\..\RtAudio.cpp
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\asio.h
SOURCE=..\..\asio\asio.h
# End Source File
# Begin Source File
SOURCE=..\..\asio\asiodrivers.h
# End Source File
# Begin Source File
SOURCE=.\asiodrivers.h
SOURCE=..\..\asio\asiodrvr.h
# End Source File
# Begin Source File
SOURCE=.\asiodrvr.h
SOURCE=..\..\asio\asiolist.h
# End Source File
# Begin Source File
SOURCE=.\asiolist.h
SOURCE=..\..\asio\asiosys.h
# End Source File
# Begin Source File
SOURCE=.\asiosys.h
SOURCE=..\..\asio\ginclude.h
# End Source File
# Begin Source File
SOURCE=.\ginclude.h
SOURCE=..\..\asio\iasiodrv.h
# End Source File
# Begin Source File
SOURCE=.\iasiodrv.h
SOURCE=..\..\asio\iasiothiscallresolver.h
# End Source File
# Begin Source File


+ 18
- 10
tests/Windows/play_saw.dsp View File

@@ -87,15 +87,19 @@ LINK32=link.exe
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\asio.cpp
SOURCE=..\..\asio\asio.cpp
# End Source File
# Begin Source File
SOURCE=.\asiodrivers.cpp
SOURCE=..\..\asio\asiodrivers.cpp
# End Source File
# Begin Source File
SOURCE=.\asiolist.cpp
SOURCE=..\..\asio\asiolist.cpp
# End Source File
# Begin Source File
SOURCE=..\..\asio\iasiothiscallresolver.cpp
# End Source File
# Begin Source File
@@ -111,31 +115,35 @@ SOURCE=..\..\RtAudio.cpp
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\asio.h
SOURCE=..\..\asio\asio.h
# End Source File
# Begin Source File
SOURCE=..\..\asio\asiodrivers.h
# End Source File
# Begin Source File
SOURCE=.\asiodrivers.h
SOURCE=..\..\asio\asiodrvr.h
# End Source File
# Begin Source File
SOURCE=.\asiodrvr.h
SOURCE=..\..\asio\asiolist.h
# End Source File
# Begin Source File
SOURCE=.\asiolist.h
SOURCE=..\..\asio\asiosys.h
# End Source File
# Begin Source File
SOURCE=.\asiosys.h
SOURCE=..\..\asio\ginclude.h
# End Source File
# Begin Source File
SOURCE=.\ginclude.h
SOURCE=..\..\asio\iasiodrv.h
# End Source File
# Begin Source File
SOURCE=.\iasiodrv.h
SOURCE=..\..\asio\iasiothiscallresolver.h
# End Source File
# Begin Source File


+ 18
- 10
tests/Windows/record_raw.dsp View File

@@ -87,15 +87,19 @@ LINK32=link.exe
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\asio.cpp
SOURCE=..\..\asio\asio.cpp
# End Source File
# Begin Source File
SOURCE=.\asiodrivers.cpp
SOURCE=..\..\asio\asiodrivers.cpp
# End Source File
# Begin Source File
SOURCE=.\asiolist.cpp
SOURCE=..\..\asio\asiolist.cpp
# End Source File
# Begin Source File
SOURCE=..\..\asio\iasiothiscallresolver.cpp
# End Source File
# Begin Source File
@@ -111,31 +115,35 @@ SOURCE=..\..\RtAudio.cpp
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\asio.h
SOURCE=..\..\asio\asio.h
# End Source File
# Begin Source File
SOURCE=..\..\asio\asiodrivers.h
# End Source File
# Begin Source File
SOURCE=.\asiodrivers.h
SOURCE=..\..\asio\asiodrvr.h
# End Source File
# Begin Source File
SOURCE=.\asiodrvr.h
SOURCE=..\..\asio\asiolist.h
# End Source File
# Begin Source File
SOURCE=.\asiolist.h
SOURCE=..\..\asio\asiosys.h
# End Source File
# Begin Source File
SOURCE=.\asiosys.h
SOURCE=..\..\asio\ginclude.h
# End Source File
# Begin Source File
SOURCE=.\ginclude.h
SOURCE=..\..\asio\iasiodrv.h
# End Source File
# Begin Source File
SOURCE=.\iasiodrv.h
SOURCE=..\..\asio\iasiothiscallresolver.h
# End Source File
# Begin Source File


+ 18
- 10
tests/Windows/twostreams.dsp View File

@@ -87,15 +87,19 @@ LINK32=link.exe
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\asio.cpp
SOURCE=..\..\asio\asio.cpp
# End Source File
# Begin Source File
SOURCE=.\asiodrivers.cpp
SOURCE=..\..\asio\asiodrivers.cpp
# End Source File
# Begin Source File
SOURCE=.\asiolist.cpp
SOURCE=..\..\asio\asiolist.cpp
# End Source File
# Begin Source File
SOURCE=..\..\asio\iasiothiscallresolver.cpp
# End Source File
# Begin Source File
@@ -111,31 +115,35 @@ SOURCE=..\twostreams.cpp
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\asio.h
SOURCE=..\..\asio\asio.h
# End Source File
# Begin Source File
SOURCE=..\..\asio\asiodrivers.h
# End Source File
# Begin Source File
SOURCE=.\asiodrivers.h
SOURCE=..\..\asio\asiodrvr.h
# End Source File
# Begin Source File
SOURCE=.\asiodrvr.h
SOURCE=..\..\asio\asiolist.h
# End Source File
# Begin Source File
SOURCE=.\asiolist.h
SOURCE=..\..\asio\asiosys.h
# End Source File
# Begin Source File
SOURCE=.\asiosys.h
SOURCE=..\..\asio\ginclude.h
# End Source File
# Begin Source File
SOURCE=.\ginclude.h
SOURCE=..\..\asio\iasiodrv.h
# End Source File
# Begin Source File
SOURCE=.\iasiodrv.h
SOURCE=..\..\asio\iasiothiscallresolver.h
# End Source File
# Begin Source File


Loading…
Cancel
Save