// HostAPI-specific initialization function PaError PaMacCore_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiIndex hostApiIndex ) { PaError result = paNoError; PaMacCoreHostApiRepresentation *macCoreHostApi = (PaMacCoreHostApiRepresentation *)PaUtil_AllocateMemory( sizeof(PaMacCoreHostApiRepresentation) ); if( !macCoreHostApi ) { result = paInsufficientMemory; goto error; } macCoreHostApi->allocations = PaUtil_CreateAllocationGroup(); if( !macCoreHostApi->allocations ) { result = paInsufficientMemory; goto error; } *hostApi = &macCoreHostApi->inheritedHostApiRep; (*hostApi)->info.structVersion = 1; (*hostApi)->info.type = paCoreAudio; (*hostApi)->info.name = "CoreAudio"; result = InitializeDeviceInfos(macCoreHostApi, hostApiIndex); if (result != paNoError) { goto error; } // Set up the proper callbacks to this HostApi's functions (*hostApi)->Terminate = Terminate; (*hostApi)->OpenStream = OpenStream; (*hostApi)->IsFormatSupported = IsFormatSupported; PaUtil_InitializeStreamInterface( &macCoreHostApi->callbackStreamInterface, CloseStream, StartStream, StopStream, AbortStream, IsStreamStopped, IsStreamActive, GetStreamTime, GetStreamCpuLoad, PaUtil_DummyRead, PaUtil_DummyWrite, PaUtil_DummyGetReadAvailable, PaUtil_DummyGetWriteAvailable ); PaUtil_InitializeStreamInterface( &macCoreHostApi->blockingStreamInterface, CloseStream, StartStream, StopStream, AbortStream, IsStreamStopped, IsStreamActive, GetStreamTime, PaUtil_DummyGetCpuLoad, ReadStream, WriteStream, GetStreamReadAvailable, GetStreamWriteAvailable ); return result; error: if( macCoreHostApi ) { CleanUp(macCoreHostApi); } return result; }
PaError PaSkeleton_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiIndex hostApiIndex ) { PaError result = paNoError; int i, deviceCount; PaSkeletonHostApiRepresentation *skeletonHostApi; PaDeviceInfo *deviceInfoArray; skeletonHostApi = (PaSkeletonHostApiRepresentation*)PaUtil_AllocateMemory( sizeof(PaSkeletonHostApiRepresentation) ); if( !skeletonHostApi ) { result = paInsufficientMemory; goto error; } skeletonHostApi->allocations = PaUtil_CreateAllocationGroup(); if( !skeletonHostApi->allocations ) { result = paInsufficientMemory; goto error; } *hostApi = &skeletonHostApi->commonHostApiRep; (*hostApi)->info.structVersion = 1; (*hostApi)->info.type = paInDevelopment; /* IMPLEMENT ME: change to correct type id */ (*hostApi)->info.name = "skeleton implementation"; /* IMPLEMENT ME: change to correct name */ (*hostApi)->deviceCount = 0; (*hostApi)->defaultInputDeviceIndex = paNoDevice; /* IMPLEMENT ME */ (*hostApi)->defaultOutputDeviceIndex = paNoDevice; /* IMPLEMENT ME */ deviceCount = 0; /* IMPLEMENT ME */ if( deviceCount > 0 ) { (*hostApi)->deviceInfos = (PaDeviceInfo**)PaUtil_GroupAllocateMemory( skeletonHostApi->allocations, sizeof(PaDeviceInfo*) * deviceCount ); if( !(*hostApi)->deviceInfos ) { result = paInsufficientMemory; goto error; } /* allocate all device info structs in a contiguous block */ deviceInfoArray = (PaDeviceInfo*)PaUtil_GroupAllocateMemory( skeletonHostApi->allocations, sizeof(PaDeviceInfo) * deviceCount ); if( !deviceInfoArray ) { result = paInsufficientMemory; goto error; } for( i=0; i < deviceCount; ++i ) { PaDeviceInfo *deviceInfo = &deviceInfoArray[i]; deviceInfo->structVersion = 2; deviceInfo->hostApi = hostApiIndex; deviceInfo->name = 0; /* IMPLEMENT ME: allocate block and copy name eg: deviceName = (char*)PaUtil_GroupAllocateMemory( skeletonHostApi->allocations, strlen(srcName) + 1 ); if( !deviceName ) { result = paInsufficientMemory; goto error; } strcpy( deviceName, srcName ); deviceInfo->name = deviceName; */ /* IMPLEMENT ME: - populate other device info fields */ (*hostApi)->deviceInfos[i] = deviceInfo; ++(*hostApi)->deviceCount; } } (*hostApi)->Terminate = Terminate; (*hostApi)->OpenStream = OpenStream; PaUtil_InitializeStreamInterface( &skeletonHostApi->callbackStreamInterface, CloseStream, StartStream, StopStream, AbortStream, IsStreamStopped, IsStreamActive, GetStreamTime, GetStreamCpuLoad, PaUtil_DummyReadWrite, PaUtil_DummyReadWrite, PaUtil_DummyGetAvailable, PaUtil_DummyGetAvailable ); PaUtil_InitializeStreamInterface( &skeletonHostApi->blockingStreamInterface, CloseStream, StartStream, StopStream, AbortStream, IsStreamStopped, IsStreamActive, GetStreamTime, PaUtil_DummyGetCpuLoad, ReadStream, WriteStream, GetStreamReadAvailable, GetStreamWriteAvailable ); return result; error: if( skeletonHostApi ) { if( skeletonHostApi->allocations ) { PaUtil_FreeAllAllocations( skeletonHostApi->allocations ); PaUtil_DestroyAllocationGroup( skeletonHostApi->allocations ); } PaUtil_FreeMemory( skeletonHostApi ); } return result; }
PaError PaSndio_Initialize(PaUtilHostApiRepresentation **hostApi, PaHostApiIndex hostApiIndex) { PaSndioHostApiRepresentation *sndioHostApi; PaDeviceInfo *info; struct sio_hdl *hdl; DPR("PaSndio_Initialize: initializing...\n"); /* unusable APIs should return paNoError and a NULL hostApi */ *hostApi = NULL; sndioHostApi = PaUtil_AllocateMemory(sizeof(PaSndioHostApiRepresentation)); if (sndioHostApi == NULL) return paNoError; info = &sndioHostApi->default_info; info->structVersion = 2; info->name = "default"; info->hostApi = hostApiIndex; info->maxInputChannels = 128; info->maxOutputChannels = 128; info->defaultLowInputLatency = 0.01; info->defaultLowOutputLatency = 0.01; info->defaultHighInputLatency = 0.5; info->defaultHighOutputLatency = 0.5; info->defaultSampleRate = 48000; sndioHostApi->infos[0] = info; *hostApi = &sndioHostApi->base; (*hostApi)->info.structVersion = 1; (*hostApi)->info.type = paSndio; (*hostApi)->info.name = "sndio"; (*hostApi)->info.deviceCount = 1; (*hostApi)->info.defaultInputDevice = 0; (*hostApi)->info.defaultOutputDevice = 0; (*hostApi)->deviceInfos = sndioHostApi->infos; (*hostApi)->Terminate = Terminate; (*hostApi)->OpenStream = OpenStream; (*hostApi)->IsFormatSupported = IsFormatSupported; PaUtil_InitializeStreamInterface(&sndioHostApi->blocking, CloseStream, StartStream, StopStream, AbortStream, IsStreamStopped, IsStreamActive, GetStreamTime, PaUtil_DummyGetCpuLoad, BlockingReadStream, BlockingWriteStream, BlockingGetStreamReadAvailable, BlockingGetStreamWriteAvailable); PaUtil_InitializeStreamInterface(&sndioHostApi->callback, CloseStream, StartStream, StopStream, AbortStream, IsStreamStopped, IsStreamActive, GetStreamTime, PaUtil_DummyGetCpuLoad, PaUtil_DummyRead, PaUtil_DummyWrite, PaUtil_DummyGetReadAvailable, PaUtil_DummyGetWriteAvailable); DPR("PaSndio_Initialize: done\n"); return paNoError; }
PaError PaSndio_Initialize(PaUtilHostApiRepresentation **hostApi, PaHostApiIndex hostApiIndex) { PaSndioHostApiRepresentation *sndioHostApi; PaDeviceInfo *info; struct sio_hdl *hdl; char *audiodevices; char *device; size_t deviceCount; DPR("PaSndio_Initialize: initializing...\n"); /* unusable APIs should return paNoError and a NULL hostApi */ *hostApi = NULL; sndioHostApi = PaUtil_AllocateMemory(sizeof(PaSndioHostApiRepresentation)); if (sndioHostApi == NULL) return paNoError; // Add default device info = &sndioHostApi->device_info[0]; InitDeviceInfo(info, hostApiIndex, SIO_DEVANY); sndioHostApi->infos[0] = info; deviceCount = 1; // Add additional devices as specified in the PA_SNDIO_AUDIODEVICES // environment variable as a colon separated list sndioHostApi->audiodevices = NULL; audiodevices = getenv("PA_SNDIO_AUDIODEVICES"); if (audiodevices != NULL) { sndioHostApi->audiodevices = strdup(audiodevices); if (sndioHostApi->audiodevices == NULL) return paNoError; audiodevices = sndioHostApi->audiodevices; while ((device = strsep(&audiodevices, ":")) != NULL && deviceCount < PA_SNDIO_AUDIODEVICES_MAX) { if (*device == '\0') continue; info = &sndioHostApi->device_info[deviceCount]; InitDeviceInfo(info, hostApiIndex, device); sndioHostApi->infos[deviceCount] = info; deviceCount++; } } *hostApi = &sndioHostApi->base; (*hostApi)->info.structVersion = 1; (*hostApi)->info.type = paSndio; (*hostApi)->info.name = "sndio"; (*hostApi)->info.deviceCount = deviceCount; (*hostApi)->info.defaultInputDevice = 0; (*hostApi)->info.defaultOutputDevice = 0; (*hostApi)->deviceInfos = sndioHostApi->infos; (*hostApi)->Terminate = Terminate; (*hostApi)->OpenStream = OpenStream; (*hostApi)->IsFormatSupported = IsFormatSupported; PaUtil_InitializeStreamInterface(&sndioHostApi->blocking, CloseStream, StartStream, StopStream, AbortStream, IsStreamStopped, IsStreamActive, GetStreamTime, PaUtil_DummyGetCpuLoad, BlockingReadStream, BlockingWriteStream, BlockingGetStreamReadAvailable, BlockingGetStreamWriteAvailable); PaUtil_InitializeStreamInterface(&sndioHostApi->callback, CloseStream, StartStream, StopStream, AbortStream, IsStreamStopped, IsStreamActive, GetStreamTime, PaUtil_DummyGetCpuLoad, PaUtil_DummyRead, PaUtil_DummyWrite, PaUtil_DummyGetReadAvailable, PaUtil_DummyGetWriteAvailable); DPR("PaSndio_Initialize: done\n"); return paNoError; }
PaError PaJack_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiIndex hostApiIndex ) { PaError result = paNoError; PaJackHostApiRepresentation *jackHostApi; jackHostApi = (PaJackHostApiRepresentation*) PaUtil_AllocateMemory( sizeof(PaJackHostApiRepresentation) ); if( !jackHostApi ) { result = paInsufficientMemory; goto error; } jackHostApi->deviceInfoMemory = NULL; /* Try to become a client of the JACK server. If we cannot do * this, than this API cannot be used. */ jackHostApi->jack_client = jack_client_new( "PortAudio client" ); if( jackHostApi->jack_client == 0 ) { /* the V19 development docs say that if an implementation * detects that it cannot be used, it should return a NULL * interface and paNoError */ result = paNoError; *hostApi = NULL; goto error; } jackHostApi->deviceInfoMemory = PaUtil_CreateAllocationGroup(); if( !jackHostApi->deviceInfoMemory ) { result = paInsufficientMemory; goto error; } jackHostApi->hostApiIndex = hostApiIndex; *hostApi = &jackHostApi->commonHostApiRep; (*hostApi)->info.structVersion = 1; (*hostApi)->info.type = paInDevelopment; (*hostApi)->info.name = "JACK Audio Connection Kit"; (*hostApi)->info.defaultInputDevice = paNoDevice; /* set in BuildDeviceList() */ (*hostApi)->info.defaultOutputDevice = paNoDevice; /* set in BuildDeviceList() */ (*hostApi)->info.deviceCount = 0; /* set in BuildDeviceList() */ /* Build a device list by querying the JACK server */ result = BuildDeviceList( jackHostApi ); if( result != paNoError ) goto error; /* Register functions */ (*hostApi)->Terminate = Terminate; (*hostApi)->OpenStream = OpenStream; (*hostApi)->IsFormatSupported = IsFormatSupported; PaUtil_InitializeStreamInterface( &jackHostApi->callbackStreamInterface, CloseStream, StartStream, StopStream, AbortStream, IsStreamStopped, IsStreamActive, GetStreamTime, GetStreamCpuLoad, PaUtil_DummyRead, PaUtil_DummyWrite, PaUtil_DummyGetReadAvailable, PaUtil_DummyGetWriteAvailable ); return result; error: if( jackHostApi ) { if( jackHostApi->deviceInfoMemory ) { PaUtil_FreeAllAllocations( jackHostApi->deviceInfoMemory ); PaUtil_DestroyAllocationGroup( jackHostApi->deviceInfoMemory ); } PaUtil_FreeMemory( jackHostApi ); } return result; }