Commit e4b2d61a authored by sletz's avatar sletz
Browse files

Cleanup

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@2102 0c269be4-1314-0410-8aa9-9f06e86f4224
parent d822ee05
......@@ -29,23 +29,17 @@ namespace Jack
// Used for external C API (JackAPI.cpp)
JackGraphManager* GetGraphManager()
{
if (JackLibGlobals::fGlobals)
return JackLibGlobals::fGlobals->fGraphManager;
else
return NULL;
return (JackLibGlobals::fGlobals) ? JackLibGlobals::fGlobals->fGraphManager : NULL;
}
JackEngineControl* GetEngineControl()
{
if (JackLibGlobals::fGlobals)
return JackLibGlobals::fGlobals->fEngineControl;
else
return NULL;
return (JackLibGlobals::fGlobals) ? JackLibGlobals::fGlobals->fEngineControl : NULL;
}
JackSynchro** GetSynchroTable()
{
return (JackLibGlobals::fGlobals ? JackLibGlobals::fGlobals->fSynchroTable : 0);
return (JackLibGlobals::fGlobals) ? JackLibGlobals::fGlobals->fSynchroTable : NULL;
}
//-------------------
......@@ -114,12 +108,12 @@ int JackLibClient::Open(const char* server_name, const char* name, jack_options_
#endif
*/
// Connect shared synchro : the synchro must be usable in I/O mode when several clients live in the same process
if (!fSynchroTable[fClientControl->fRefNum]->Connect(name_res, fServerName)) {
if (!fSynchroTable[GetClientControl()->fRefNum]->Connect(name_res, fServerName)) {
jack_error("Cannot ConnectSemaphore %s client", name_res);
goto error;
}
jack_log("JackLibClient::Open name = %s refnum = %ld", name_res, fClientControl->fRefNum);
jack_log("JackLibClient::Open name = %s refnum = %ld", name_res, GetClientControl()->fRefNum);
return 0;
error:
......
......@@ -228,11 +228,9 @@ typedef struct _jack_driver
JackDriverBufSizeFunction bufsize;
JACK_DRIVER_DECL /* expand the macro */
}
jack_driver_t;
typedef jack_driver_desc_t * (*JackDriverDescFunction) ();
void jack_driver_init (jack_driver_t *);
......@@ -241,7 +239,6 @@ void jack_driver_release (jack_driver_t *);
jack_driver_t *jack_driver_load (int argc, char **argv);
void jack_driver_unload (jack_driver_t *);
/****************************
*** Non-Threaded Drivers ***
****************************/
......@@ -265,8 +262,6 @@ void jack_driver_unload (jack_driver_t *);
Note that stop/start may be called multiple times in the event of an
error return from the `wait' function.
*/
struct _jack_driver_nt;
......@@ -281,7 +276,6 @@ typedef int (*JackDriverNTRunCycleFunction)(struct _jack_driver_nt *);
typedef struct _jack_driver_nt
{
#define JACK_DRIVER_NT_DECL \
JACK_DRIVER_DECL \
struct _jack_engine * engine; \
......@@ -299,13 +293,10 @@ typedef struct _jack_driver_nt
#define nt_null_cycle null_cycle
JACK_DRIVER_NT_DECL
}
jack_driver_nt_t;
void jack_driver_nt_init (jack_driver_nt_t * driver);
void jack_driver_nt_finish (jack_driver_nt_t * driver);
#endif /* __jack_driver_h__ */
......@@ -191,7 +191,7 @@ int Jack_XRun_Callback(void *arg)
{
xrun++;
have_xrun = 1;
printf("Xrun has been detected ! (msg from callback)\n");
Log("Xrun has been detected ! (msg from callback)\n");
return 0;
}
......@@ -276,7 +276,7 @@ int Jack_Sync_Callback(jack_transport_state_t state, jack_position_t *pos, void
*
* -1 : idle mode
* 0 : write zeros to output 1
* 1 : write continuously signal1 (sinusodal test signal) to output1
* 1 : write continuously signal1 (sinusoidal test signal) to output1
* 3 : mode for summation test. While record (done by process2) is not running, write signal1 to both out1 & out1b.
* when record begin (index2 > 0), write signal1 in phase opposition to out1 & out2
* 5 : Frames Time checking mode : write the array containing the three values of frame_time, frames cycles start and
......
......@@ -34,7 +34,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "JackGlobals.h"
#include <iostream>
#include <windows.h>
#include <mmsystem.h>
......@@ -43,7 +42,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "asiodrivers.h"
#include "iasiothiscallresolver.h"
/* external references */
extern AsioDrivers* asioDrivers ;
bool loadAsioDriver(char *name);
......@@ -59,46 +57,45 @@ namespace Jack
and must be closed by the called by calling ASIOExit() - if an error
is returned the driver will already be closed.
*/
static PaError LoadAsioDriver( const char *driverName,
PaAsioDriverInfo *driverInfo, void *systemSpecific )
static PaError LoadAsioDriver(const char *driverName, PaAsioDriverInfo *driverInfo, void *systemSpecific)
{
PaError result = paNoError;
ASIOError asioError;
int asioIsInitialized = 0;
if ( !loadAsioDriver(const_cast<char*>(driverName))) {
if (!loadAsioDriver(const_cast<char*>(driverName))) {
result = paUnanticipatedHostError;
PA_ASIO_SET_LAST_HOST_ERROR( 0, "Failed to load ASIO driver" );
PA_ASIO_SET_LAST_HOST_ERROR(0, "Failed to load ASIO driver");
goto error;
}
memset( &driverInfo->asioDriverInfo, 0, sizeof(ASIODriverInfo) );
memset(&driverInfo->asioDriverInfo, 0, sizeof(ASIODriverInfo));
driverInfo->asioDriverInfo.asioVersion = 2;
driverInfo->asioDriverInfo.sysRef = systemSpecific;
if ( (asioError = ASIOInit( &driverInfo->asioDriverInfo )) != ASE_OK ) {
if ((asioError = ASIOInit(&driverInfo->asioDriverInfo)) != ASE_OK) {
result = paUnanticipatedHostError;
PA_ASIO_SET_LAST_ASIO_ERROR( asioError );
PA_ASIO_SET_LAST_ASIO_ERROR(asioError);
goto error;
} else {
asioIsInitialized = 1;
}
if ( (asioError = ASIOGetChannels(&driverInfo->inputChannelCount,
&driverInfo->outputChannelCount)) != ASE_OK ) {
if ((asioError = ASIOGetChannels(&driverInfo->inputChannelCount,
&driverInfo->outputChannelCount)) != ASE_OK) {
result = paUnanticipatedHostError;
PA_ASIO_SET_LAST_ASIO_ERROR( asioError );
PA_ASIO_SET_LAST_ASIO_ERROR(asioError);
goto error;
}
if ( (asioError = ASIOGetBufferSize(&driverInfo->bufferMinSize,
if ((asioError = ASIOGetBufferSize(&driverInfo->bufferMinSize,
&driverInfo->bufferMaxSize, &driverInfo->bufferPreferredSize,
&driverInfo->bufferGranularity)) != ASE_OK ) {
&driverInfo->bufferGranularity)) != ASE_OK) {
result = paUnanticipatedHostError;
PA_ASIO_SET_LAST_ASIO_ERROR( asioError );
PA_ASIO_SET_LAST_ASIO_ERROR(asioError);
goto error;
}
if ( ASIOOutputReady() == ASE_OK )
if (ASIOOutputReady() == ASE_OK)
driverInfo->postOutput = true;
else
driverInfo->postOutput = false;
......@@ -106,13 +103,12 @@ static PaError LoadAsioDriver( const char *driverName,
return result;
error:
if ( asioIsInitialized )
if (asioIsInitialized)
ASIOExit();
return result;
}
int JackASIODriver::bufferSwitch(long index, ASIOBool directProcess)
{
JackASIODriver* driver = (JackASIODriver*)userData;
......@@ -131,7 +127,7 @@ int JackASIODriver::bufferSwitch(long index, ASIOBool directProcess)
// get the time stamp of the buffer, not necessary if no
// synchronization to other media is required
if ( ASIOGetSamplePosition(&timeInfo.timeInfo.samplePosition, &timeInfo.timeInfo.systemTime) == ASE_OK)
if (ASIOGetSamplePosition(&timeInfo.timeInfo.samplePosition, &timeInfo.timeInfo.systemTime) == ASE_OK)
timeInfo.timeInfo.flags = kSystemTimeValid | kSamplePositionValid;
......@@ -140,7 +136,7 @@ int JackASIODriver::bufferSwitch(long index, ASIOBool directProcess)
driver->fOutputBuffer = (float**)outputBuffer;
// Call the real callback
bufferSwitchTimeInfo( &timeInfo, index, directProcess );
bufferSwitchTimeInfo(&timeInfo, index, directProcess);
return driver->Process();
}
......@@ -155,8 +151,7 @@ int JackASIODriver::Write()
return 0;
}
int JackASIODriver::Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiIndex hostApiIndex )
int JackASIODriver::Initialize(PaUtilHostApiRepresentation **hostApi, PaHostApiIndex hostApiIndex)
{
PaError result = paNoError;
int i, driverCount;
......@@ -165,14 +160,14 @@ int JackASIODriver::Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApi
char **names;
PaAsioDriverInfo paAsioDriverInfo;
asioHostApi = (PaAsioHostApiRepresentation*)PaUtil_AllocateMemory( sizeof(PaAsioHostApiRepresentation) );
if ( !asioHostApi ) {
asioHostApi = (PaAsioHostApiRepresentation*)PaUtil_AllocateMemory(sizeof(PaAsioHostApiRepresentation));
if (!asioHostApi) {
result = paInsufficientMemory;
goto error;
}
asioHostApi->allocations = PaUtil_CreateAllocationGroup();
if ( !asioHostApi->allocations ) {
if (!asioHostApi->allocations) {
result = paInsufficientMemory;
goto error;
}
......@@ -194,7 +189,7 @@ int JackASIODriver::Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApi
#endif
/* MUST BE CHECKED : to force fragments loading on Mac */
loadAsioDriver( "dummy" );
loadAsioDriver("dummy");
/* driverCount is the number of installed drivers - not necessarily
the number of installed physical devices. */
......@@ -204,32 +199,31 @@ int JackASIODriver::Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApi
driverCount = asioDrivers->asioGetNumDev();
#endif
if ( driverCount > 0 ) {
names = GetAsioDriverNames( asioHostApi->allocations, driverCount );
if ( !names ) {
if (driverCount > 0) {
names = GetAsioDriverNames(asioHostApi->allocations, driverCount);
if (!names) {
result = paInsufficientMemory;
goto error;
}
/* allocate enough space for all drivers, even if some aren't installed */
(*hostApi)->deviceInfos = (PaDeviceInfo**)PaUtil_GroupAllocateMemory(
asioHostApi->allocations, sizeof(PaDeviceInfo*) * driverCount );
if ( !(*hostApi)->deviceInfos ) {
asioHostApi->allocations, sizeof(PaDeviceInfo*) * driverCount);
if (!(*hostApi)->deviceInfos) {
result = paInsufficientMemory;
goto error;
}
/* allocate all device info structs in a contiguous block */
deviceInfoArray = (PaAsioDeviceInfo*)PaUtil_GroupAllocateMemory(
asioHostApi->allocations, sizeof(PaAsioDeviceInfo) * driverCount );
if ( !deviceInfoArray ) {
asioHostApi->allocations, sizeof(PaAsioDeviceInfo) * driverCount);
if (!deviceInfoArray) {
result = paInsufficientMemory;
goto error;
}
for ( i = 0; i < driverCount; ++i ) {
for (i = 0; i < driverCount; ++i) {
PA_DEBUG(("ASIO names[%d]:%s\n", i, names[i]));
......@@ -240,18 +234,17 @@ int JackASIODriver::Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApi
// so lets NOT try to load any such wrappers.
// The ones i [davidv] know of so far are:
if ( strcmp (names[i], "ASIO DirectX Full Duplex Driver") == 0
|| strcmp (names[i], "ASIO Multimedia Driver") == 0
|| strncmp(names[i], "Premiere", 8) == 0 //"Premiere Elements Windows Sound 1.0"
|| strncmp(names[i], "Adobe", 5) == 0 ) //"Adobe Default Windows Sound 1.5"
if (strcmp (names[i], "ASIO DirectX Full Duplex Driver") == 0
|| strcmp (names[i], "ASIO Multimedia Driver") == 0
|| strncmp(names[i], "Premiere", 8) == 0 //"Premiere Elements Windows Sound 1.0"
|| strncmp(names[i], "Adobe", 5) == 0) //"Adobe Default Windows Sound 1.5"
{
PA_DEBUG(("BLACKLISTED!!!\n"));
continue;
}
/* Attempt to load the asio driver... */
if ( LoadAsioDriver( names[i], &paAsioDriverInfo, asioHostApi->systemSpecific ) == paNoError ) {
if (LoadAsioDriver(names[i], &paAsioDriverInfo, asioHostApi->systemSpecific) == paNoError) {
PaAsioDeviceInfo *asioDeviceInfo = &deviceInfoArray[ (*hostApi)->info.deviceCount ];
PaDeviceInfo *deviceInfo = &asioDeviceInfo->commonDeviceInfo;
......@@ -272,9 +265,9 @@ int JackASIODriver::Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApi
deviceInfo->defaultSampleRate = 0.;
bool foundDefaultSampleRate = false;
for ( int j = 0; j < PA_DEFAULTSAMPLERATESEARCHORDER_COUNT_; ++j ) {
ASIOError asioError = ASIOCanSampleRate( defaultSampleRateSearchOrder_[j] );
if ( asioError != ASE_NoClock && asioError != ASE_NotPresent ) {
for (int j = 0; j < PA_DEFAULTSAMPLERATESEARCHORDER_COUNT_; ++j) {
ASIOError asioError = ASIOCanSampleRate(defaultSampleRateSearchOrder_[j]);
if (asioError != ASE_NoClock && asioError != ASE_NotPresent) {
deviceInfo->defaultSampleRate = defaultSampleRateSearchOrder_[j];
foundDefaultSampleRate = true;
break;
......@@ -283,7 +276,7 @@ int JackASIODriver::Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApi
PA_DEBUG(("PaAsio_Initialize: drv:%d defaultSampleRate = %f\n", i, deviceInfo->defaultSampleRate));
if ( foundDefaultSampleRate ) {
if (foundDefaultSampleRate) {
/* calculate default latency values from bufferPreferredSize
for default low latency, and bufferPreferredSize * 3
......@@ -302,20 +295,19 @@ int JackASIODriver::Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApi
long defaultHighLatencyBufferSize =
paAsioDriverInfo.bufferPreferredSize * 3;
if ( defaultHighLatencyBufferSize > paAsioDriverInfo.bufferMaxSize )
if (defaultHighLatencyBufferSize > paAsioDriverInfo.bufferMaxSize)
defaultHighLatencyBufferSize = paAsioDriverInfo.bufferMaxSize;
double defaultHighLatency =
defaultHighLatencyBufferSize / deviceInfo->defaultSampleRate;
if ( defaultHighLatency < defaultLowLatency )
if (defaultHighLatency < defaultLowLatency)
defaultHighLatency = defaultLowLatency; /* just incase the driver returns something strange */
deviceInfo->defaultHighInputLatency = defaultHighLatency;
deviceInfo->defaultHighOutputLatency = defaultHighLatency;
} else {
deviceInfo->defaultLowInputLatency = 0.;
deviceInfo->defaultLowOutputLatency = 0.;
deviceInfo->defaultHighInputLatency = 0.;
......@@ -336,33 +328,33 @@ int JackASIODriver::Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApi
asioDeviceInfo->asioChannelInfos = (ASIOChannelInfo*)PaUtil_GroupAllocateMemory(
asioHostApi->allocations,
sizeof(ASIOChannelInfo) * (deviceInfo->maxInputChannels
+ deviceInfo->maxOutputChannels) );
if ( !asioDeviceInfo->asioChannelInfos ) {
+ deviceInfo->maxOutputChannels));
if (!asioDeviceInfo->asioChannelInfos) {
result = paInsufficientMemory;
goto error;
}
int a;
for ( a = 0; a < deviceInfo->maxInputChannels; ++a ) {
for (a = 0; a < deviceInfo->maxInputChannels; ++a) {
asioDeviceInfo->asioChannelInfos[a].channel = a;
asioDeviceInfo->asioChannelInfos[a].isInput = ASIOTrue;
ASIOError asioError = ASIOGetChannelInfo( &asioDeviceInfo->asioChannelInfos[a] );
if ( asioError != ASE_OK ) {
ASIOError asioError = ASIOGetChannelInfo(&asioDeviceInfo->asioChannelInfos[a]);
if (asioError != ASE_OK) {
result = paUnanticipatedHostError;
PA_ASIO_SET_LAST_ASIO_ERROR( asioError );
PA_ASIO_SET_LAST_ASIO_ERROR(asioError);
goto error;
}
}
for ( a = 0; a < deviceInfo->maxOutputChannels; ++a ) {
for (a = 0; a < deviceInfo->maxOutputChannels; ++a) {
int b = deviceInfo->maxInputChannels + a;
asioDeviceInfo->asioChannelInfos[b].channel = a;
asioDeviceInfo->asioChannelInfos[b].isInput = ASIOFalse;
ASIOError asioError = ASIOGetChannelInfo( &asioDeviceInfo->asioChannelInfos[b] );
if ( asioError != ASE_OK ) {
ASIOError asioError = ASIOGetChannelInfo(&asioDeviceInfo->asioChannelInfos[b]);
if (asioError != ASE_OK) {
result = paUnanticipatedHostError;
PA_ASIO_SET_LAST_ASIO_ERROR( asioError );
PA_ASIO_SET_LAST_ASIO_ERROR(asioError);
goto error;
}
}
......@@ -377,7 +369,7 @@ int JackASIODriver::Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApi
}
}
if ( (*hostApi)->info.deviceCount > 0 ) {
if ((*hostApi)->info.deviceCount > 0) {
(*hostApi)->info.defaultInputDevice = 0;
(*hostApi)->info.defaultOutputDevice = 0;
} else {
......@@ -390,34 +382,32 @@ int JackASIODriver::Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApi
(*hostApi)->OpenStream = OpenStream;
(*hostApi)->IsFormatSupported = IsFormatSupported;
PaUtil_InitializeStreamInterface( &asioHostApi->callbackStreamInterface, CloseStream, StartStream,
PaUtil_InitializeStreamInterface(&asioHostApi->callbackStreamInterface, CloseStream, StartStream,
StopStream, AbortStream, IsStreamStopped, IsStreamActive,
GetStreamTime, GetStreamCpuLoad,
PaUtil_DummyRead, PaUtil_DummyWrite,
PaUtil_DummyGetReadAvailable, PaUtil_DummyGetWriteAvailable );
PaUtil_DummyGetReadAvailable, PaUtil_DummyGetWriteAvailable);
PaUtil_InitializeStreamInterface( &asioHostApi->blockingStreamInterface, CloseStream, StartStream,
PaUtil_InitializeStreamInterface(&asioHostApi->blockingStreamInterface, CloseStream, StartStream,
StopStream, AbortStream, IsStreamStopped, IsStreamActive,
GetStreamTime, PaUtil_DummyGetCpuLoad,
ReadStream, WriteStream, GetStreamReadAvailable, GetStreamWriteAvailable );
ReadStream, WriteStream, GetStreamReadAvailable, GetStreamWriteAvailable);
return result;
error:
if ( asioHostApi ) {
if ( asioHostApi->allocations ) {
PaUtil_FreeAllAllocations( asioHostApi->allocations );
PaUtil_DestroyAllocationGroup( asioHostApi->allocations );
if (asioHostApi) {
if (asioHostApi->allocations) {
PaUtil_FreeAllAllocations(asioHostApi->allocations);
PaUtil_DestroyAllocationGroup(asioHostApi->allocations);
}
PaUtil_FreeMemory( asioHostApi );
PaUtil_FreeMemory(asioHostApi);
}
return result;
}
void JackASIODriverTerminate( struct PaUtilHostApiRepresentation *hostApi )
void JackASIODriverTerminate(struct PaUtilHostApiRepresentation *hostApi)
{
PaAsioHostApiRepresentation *asioHostApi = (PaAsioHostApiRepresentation*)hostApi;
......@@ -426,16 +416,15 @@ void JackASIODriverTerminate( struct PaUtilHostApiRepresentation *hostApi )
- clean up any resources not handled by the allocation group
*/
if ( asioHostApi->allocations )
if (asioHostApi->allocations)
{
PaUtil_FreeAllAllocations( asioHostApi->allocations );
PaUtil_DestroyAllocationGroup( asioHostApi->allocations );
PaUtil_FreeAllAllocations(asioHostApi->allocations);
PaUtil_DestroyAllocationGroup(asioHostApi->allocations);
}
PaUtil_FreeMemory( asioHostApi );
PaUtil_FreeMemory(asioHostApi);
}
int JackASIODriver::Open(jack_nframes_t nframes,
jack_nframes_t samplerate,
int capturing,
......@@ -480,9 +469,7 @@ void JackASIODriver::PrintState()
{
int i;
std::cout << "JackASIODriver state" << std::endl;
jack_port_id_t port_index;
std::cout << "Input ports" << std::endl;
/*
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment