pa_asio.cpp File Reference

#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <windows.h>
#include <mmsystem.h>
#include "portaudio.h"
#include "pa_asio.h"
#include "pa_util.h"
#include "pa_allocation.h"
#include "pa_hostapi.h"
#include "pa_stream.h"
#include "pa_cpuload.h"
#include "pa_process.h"
#include "pa_debugprint.h"
#include "asiosys.h"
#include "asio.h"
#include "asiodrivers.h"
#include "iasiothiscallresolver.h"

Data Structures

struct  PaAsioDriverInfo
struct  PaAsioHostApiRepresentation
struct  PaAsioDeviceInfo
struct  PaAsioStream

Defines

#define CARBON_COMPATIBLE   (0)
#define PA_ASIO_SET_LAST_HOST_ERROR(errorCode, errorText)   PaUtil_SetLastHostErrorInfo( paASIO, errorCode, errorText )
#define PA_ASIO_SET_LAST_SYSTEM_ERROR(errorCode)   PaAsio_SetLastSystemError( errorCode )
#define PA_ASIO_SET_LAST_ASIO_ERROR(asioError)   PaUtil_SetLastHostErrorInfo( paASIO, asioError, PaAsio_GetAsioErrorText( asioError ) )
#define PA_SWAP32_(x)   ((x>>24) | ((x>>8)&0xFF00) | ((x<<8)&0xFF0000) | (x<<24));
#define PA_SWAP_(x, y)   temp=x; x = y; y = temp;
#define PA_DEFAULTSAMPLERATESEARCHORDER_COUNT_   13
#define ASIO64toDouble(a)   ((a).lo + (a).hi * twoRaisedTo32)

Typedefs

typedef void PaAsioBufferConverter (void *, long, long)
typedef BOOL(WINAPI * IsDebuggerPresentPtr )(VOID)

Functions

bool loadAsioDriver (char *name)
PaError PaAsio_Initialize (PaUtilHostApiRepresentation **hostApi, PaHostApiIndex hostApiIndex)
void AsioSampleTypeLOG (ASIOSampleType type)
PaError PaAsio_GetAvailableLatencyValues (PaDeviceIndex device, long *minLatency, long *maxLatency, long *preferredLatency, long *granularity)
PaError PaAsio_ShowControlPanel (PaDeviceIndex device, void *systemSpecific)
PaError PaAsio_GetInputChannelName (PaDeviceIndex device, int channelIndex, const char **channelName)
PaError PaAsio_GetOutputChannelName (PaDeviceIndex device, int channelIndex, const char **channelName)

Variables

AsioDrivers * asioDrivers
IsDebuggerPresentPtr IsDebuggerPresent_ = 0
const double twoRaisedTo32 = 4294967296.

Detailed Description

Note that specific support for paInputUnderflow, paOutputOverflow and paNeverDropInput is not necessary or possible with this driver due to the synchronous full duplex double-buffered architecture of ASIO.

Todo:
check that CoInitialize()/CoUninitialize() are always correctly paired, even in error cases.
Todo:
implement host api specific extension to set i/o buffer sizes in frames
Todo:
implement ReadStream, WriteStream, GetStreamReadAvailable, GetStreamWriteAvailable
Todo:
implement IsFormatSupported
Todo:
work out how to implement stream stoppage from callback and implement IsStreamActive properly. Stream stoppage could be implemented using a high-priority thread blocked on an Event which is signalled by the callback. Or, we could just call ASIO stop from the callback and see what happens.
Todo:
rigorously check asio return codes and convert to pa error codes
Todo:
Different channels of a multichannel stream can have different sample formats, but we assume that all are the same as the first channel for now. Fixing this will require the block processor to maintain per-channel conversion functions - could get nasty.
Todo:
investigate whether the asio processNow flag needs to be honoured
Todo:
handle asioMessages() callbacks in a useful way, or at least document what cases we don't handle.
Todo:
miscellaneous other FIXMEs
Todo:
provide an asio-specific method for setting the systems specific value (aka main window handle) - check that this matches the value passed to PaAsio_ShowControlPanel, or remove it entirely from PaAsio_ShowControlPanel. - this would allow PaAsio_ShowControlPanel to be called for the currently open stream (at present all streams must be closed).

Define Documentation

#define ASIO64toDouble (  )     ((a).lo + (a).hi * twoRaisedTo32)
#define CARBON_COMPATIBLE   (0)
#define PA_ASIO_SET_LAST_ASIO_ERROR ( asioError   )     PaUtil_SetLastHostErrorInfo( paASIO, asioError, PaAsio_GetAsioErrorText( asioError ) )
#define PA_ASIO_SET_LAST_HOST_ERROR ( errorCode,
errorText   )     PaUtil_SetLastHostErrorInfo( paASIO, errorCode, errorText )
#define PA_ASIO_SET_LAST_SYSTEM_ERROR ( errorCode   )     PaAsio_SetLastSystemError( errorCode )
#define PA_DEFAULTSAMPLERATESEARCHORDER_COUNT_   13

Referenced by PaAsio_Initialize().

#define PA_SWAP32_ (  )     ((x>>24) | ((x>>8)&0xFF00) | ((x<<8)&0xFF0000) | (x<<24));
#define PA_SWAP_ ( x,
 )     temp=x; x = y; y = temp;

Typedef Documentation

typedef BOOL(WINAPI * IsDebuggerPresentPtr)(VOID)
typedef void PaAsioBufferConverter(void *, long, long)

Function Documentation

void AsioSampleTypeLOG ( ASIOSampleType  type  ) 

References PA_DEBUG.

bool loadAsioDriver ( char *  name  ) 
PaError PaAsio_GetAvailableLatencyValues ( PaDeviceIndex  device,
long *  minLatency,
long *  maxLatency,
long *  preferredLatency,
long *  granularity 
)

Retrieve legal latency settings for the specificed device, in samples.

Parameters:
device The global index of the device about which the query is being made.
minLatency A pointer to the location which will recieve the minimum latency value.
maxLatency A pointer to the location which will recieve the maximum latency value.
preferredLatency A pointer to the location which will recieve the preferred latency value.
granularity A pointer to the location which will recieve the granularity. This value determines which values between minLatency and maxLatency are available. ie the step size, if granularity is -1 then available latency settings are powers of two.
See also:
ASIOGetBufferSize in the ASIO SDK.
Todo:
This function should have a better name, any suggestions?

References PaAsioDeviceInfo::bufferGranularity, PaUtilHostApiRepresentation::deviceInfos, PaAsioDeviceInfo::maxBufferSize, PaAsioDeviceInfo::minBufferSize, paASIO, paNoError, PaUtil_DeviceIndexToHostApiDeviceIndex(), PaUtil_GetHostApiRepresentation(), and PaAsioDeviceInfo::preferredBufferSize.

Referenced by main().

PaError PaAsio_GetInputChannelName ( PaDeviceIndex  device,
int  channelIndex,
const char **  channelName 
)

Retrieve a pointer to a string containing the name of the specified input channel. The string is valid until Pa_Terminate is called.

The string will be no longer than 32 characters including the null terminator.

References PaAsioDeviceInfo::asioChannelInfos, PaAsioDeviceInfo::commonDeviceInfo, PaUtilHostApiRepresentation::deviceInfos, PaDeviceInfo::maxInputChannels, paASIO, paInvalidChannelCount, paNoError, PaUtil_DeviceIndexToHostApiDeviceIndex(), and PaUtil_GetHostApiRepresentation().

PaError PaAsio_GetOutputChannelName ( PaDeviceIndex  device,
int  channelIndex,
const char **  channelName 
)

Retrieve a pointer to a string containing the name of the specified input channel. The string is valid until Pa_Terminate is called.

The string will be no longer than 32 characters including the null terminator.

References PaAsioDeviceInfo::asioChannelInfos, PaAsioDeviceInfo::commonDeviceInfo, PaUtilHostApiRepresentation::deviceInfos, PaDeviceInfo::maxInputChannels, PaDeviceInfo::maxOutputChannels, paASIO, paInvalidChannelCount, paNoError, PaUtil_DeviceIndexToHostApiDeviceIndex(), and PaUtil_GetHostApiRepresentation().

PaError PaAsio_Initialize ( PaUtilHostApiRepresentation **  hostApi,
PaHostApiIndex  hostApiIndex 
)

References PaAsioHostApiRepresentation::allocations, PaAsioDeviceInfo::asioChannelInfos, asioDrivers, PaAsioHostApiRepresentation::blockingStreamInterface, PaAsioDeviceInfo::bufferGranularity, PaAsioDriverInfo::bufferGranularity, PaAsioDriverInfo::bufferMaxSize, PaAsioDriverInfo::bufferMinSize, PaAsioDriverInfo::bufferPreferredSize, PaAsioHostApiRepresentation::callbackStreamInterface, PaAsioDeviceInfo::commonDeviceInfo, PaDeviceInfo::defaultHighInputLatency, PaDeviceInfo::defaultHighOutputLatency, PaDeviceInfo::defaultLowInputLatency, PaDeviceInfo::defaultLowOutputLatency, PaDeviceInfo::defaultSampleRate, PaDeviceInfo::hostApi, PaUtilHostApiRepresentation::info, PaAsioHostApiRepresentation::inheritedHostApiRep, PaAsioDriverInfo::inputChannelCount, IsDebuggerPresent_, loadAsioDriver(), PaAsioDeviceInfo::maxBufferSize, PaDeviceInfo::maxInputChannels, PaDeviceInfo::maxOutputChannels, PaAsioDeviceInfo::minBufferSize, PaDeviceInfo::name, PaAsioHostApiRepresentation::openAsioDeviceIndex, PaAsioDriverInfo::outputChannelCount, PA_ASIO_SET_LAST_ASIO_ERROR, PA_DEBUG, PA_DEFAULTSAMPLERATESEARCHORDER_COUNT_, paASIO, paInsufficientMemory, paNoDevice, paNoError, paUnanticipatedHostError, PaUtil_AllocateMemory(), PaUtil_CreateAllocationGroup(), PaUtil_DestroyAllocationGroup(), PaUtil_DummyGetCpuLoad(), PaUtil_DummyGetReadAvailable(), PaUtil_DummyGetWriteAvailable(), PaUtil_DummyRead(), PaUtil_DummyWrite(), PaUtil_FreeAllAllocations(), PaUtil_FreeMemory(), PaUtil_GroupAllocateMemory(), PaUtil_InitializeStreamInterface(), PaAsioDeviceInfo::preferredBufferSize, PaDeviceInfo::structVersion, PaHostApiInfo::structVersion, and PaAsioHostApiRepresentation::systemSpecific.

PaError PaAsio_ShowControlPanel ( PaDeviceIndex  device,
void *  systemSpecific 
)

Display the ASIO control panel for the specified device.

Parameters:
device The global index of the device whose control panel is to be displayed.
systemSpecific On Windows, the calling application's main window handle, on Macintosh this value should be zero.

References PaAsioDeviceInfo::commonDeviceInfo, PaUtilHostApiRepresentation::deviceInfos, loadAsioDriver(), PaDeviceInfo::name, PaAsioHostApiRepresentation::openAsioDeviceIndex, PA_ASIO_SET_LAST_ASIO_ERROR, PA_DEBUG, paASIO, paDeviceUnavailable, paNoDevice, paNoError, paUnanticipatedHostError, PaUtil_DeviceIndexToHostApiDeviceIndex(), and PaUtil_GetHostApiRepresentation().


Variable Documentation

AsioDrivers* asioDrivers

Referenced by PaAsio_Initialize().

Referenced by PaAsio_Initialize().

const double twoRaisedTo32 = 4294967296.

Generated for PortAudio by  doxygen1.6.1