Beispiel #1
0
CLWProgram::CLWProgram(cl_program program)
: ReferenceCounter<cl_program, clRetainProgram, clReleaseProgram>(program)
{
    cl_int status = CL_SUCCESS;
    cl_uint numKernels;
    status = clCreateKernelsInProgram(*this, 0, nullptr, &numKernels);
    ThrowIf(numKernels == 0, CL_BUILD_ERROR, "clCreateKernelsInProgram return 0 kernels");

    ThrowIf(status != CL_SUCCESS, status, "clCreateKernelsInProgram failed");
    
    std::vector<cl_kernel> kernels(numKernels);
    status = clCreateKernelsInProgram(*this, numKernels, &kernels[0], nullptr);
    
    ThrowIf(status != CL_SUCCESS, status, "clCreateKernelsInProgram failed");
    
    std::for_each(kernels.begin(), kernels.end(), [this](cl_kernel k)
                  {
                      size_t size = 0;
                      cl_int res;
                      
                      res = clGetKernelInfo(k, CL_KERNEL_FUNCTION_NAME, 0, nullptr, &size);
                      ThrowIf(res != CL_SUCCESS, res, "clGetKernelInfo failed");
                      
                      std::vector<char> temp(size);
                      res = clGetKernelInfo(k, CL_KERNEL_FUNCTION_NAME, size, &temp[0], nullptr);
                      ThrowIf(res != CL_SUCCESS, res, "clGetKernelInfo failed");
                      
                      std::string funcName(temp.begin(), temp.end()-1);
                      kernels_[funcName] = CLWKernel::Create(k);
                  });
}
Beispiel #2
0
void	HLAudioFile::Open(bool inForReading, bool inForWriting)
{
	if(mOpenCount == 0)
	{
		//	only actully open the file the first time
		
		//	save off the permissions
		mOpenForReading = inForReading;
		mOpenForWriting = inForWriting;
		
		//	open the file
		SInt8 thePermissions = 0;
		if(mOpenForReading)
		{
			thePermissions += fsRdPerm;
		}
		if(mOpenForWriting)
		{
			thePermissions += fsWrPerm;
		}
		OSStatus theError = AudioFileOpen(&mFSRef, thePermissions, 0, &mAudioFileID);
		ThrowIfError(theError, CAException(theError), "HLAudioFile::Open: couldn't open the file");
	}
	else
	{
		//	file is already open, so it's an error if someone tries to add permissions
		ThrowIf((mOpenForReading && !mOpenForWriting) && inForWriting, CAException(fBsyErr), "HLAudioFile::Open: can't add write permissions");
		ThrowIf((!mOpenForReading && mOpenForWriting) && inForReading, CAException(fBsyErr), "HLAudioFile::Open: can't add read permissions");
	}

	//	increment the open count
	++mOpenCount;
}
Beispiel #3
0
void	HP_Object::SetPropertyData(const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, const void* inData, const AudioTimeStamp* inWhen)
{
	ThrowIf(!IsPropertySettable(inAddress), CAException(kAudioHardwareIllegalOperationError), "HP_Object::SetPropertyData: address isn't settable");
	switch(inAddress.mSelector)
	{
		case kAudioObjectPropertyListenerAdded:
			ThrowIf(inDataSize != sizeof(AudioObjectPropertyAddress), CAException(kAudioHardwareBadPropertySizeError), "IOA_Device::SetPropertyData: wrong data size for kAudioObjectPropertyListenerAdded");
			PropertyListenerAdded(*(static_cast<const AudioObjectPropertyAddress*>(inData)));
			break;
		
		case kAudioObjectPropertyListenerRemoved:
			ThrowIf(inDataSize != sizeof(AudioObjectPropertyAddress), CAException(kAudioHardwareBadPropertySizeError), "IOA_Device::SetPropertyData: wrong data size for kAudioObjectPropertyListenerRemoved");
			PropertyListenerRemoved(*(static_cast<const AudioObjectPropertyAddress*>(inData)));
			break;
			
		default:
		{
			HP_Property* theProperty = FindActivePropertyByAddress(inAddress);
			if(theProperty != NULL)
			{
				theProperty->SetPropertyData(inAddress, inQualifierDataSize, inQualifierData, inDataSize, inData, inWhen);
			}
			else
			{
				DebugMessage("HP_Object::SetPropertyData: unknown property");
				Throw(CAException(kAudioHardwareUnknownPropertyError));
			}
		}
		break;
	};
}
	void SelectorControl::GetPropertyData(const CMIOObjectPropertyAddress& address, UInt32 qualifierDataSize, const void* qualifierData, UInt32 dataSize, UInt32& dataUsed, void* data) const
	{
		switch (address.mSelector)
		{
			case kCMIOSelectorControlPropertyCurrentItem:
				ThrowIf(dataSize != GetPropertyDataSize(address, qualifierDataSize, qualifierData), CAException(kCMIOHardwareBadPropertySizeError), "CMIO::DP::SelectorControl::GetPropertyData: wrong data size for kCMIOSelectorControlPropertyCurrentItem");
				*static_cast<UInt32*>(data) = GetCurrentItemID();
				dataUsed = sizeof(UInt32);
				break;
			
			case kCMIOSelectorControlPropertyAvailableItems:
				{
					UInt32 numberItemsToGet = std::min((UInt32)(dataSize / sizeof(UInt32)), GetNumberItems());
					UInt32* itemIDs = static_cast<UInt32*>(data);
					for(UInt32 index = 0; index < numberItemsToGet; ++index)
					{
						itemIDs[index] = GetItemIDForIndex(index);
					}
					dataUsed = numberItemsToGet * sizeof(UInt32);
				}
				break;
			
			case kCMIOSelectorControlPropertyItemName:
				ThrowIf(dataSize != GetPropertyDataSize(address, qualifierDataSize, qualifierData), CAException(kCMIOHardwareBadPropertySizeError), "CMIO::DP::SelectorControl::GetPropertyData: wrong data size for kCMIOSelectorControlPropertyItemName");
				ThrowIf(qualifierDataSize != sizeof(UInt32), CAException(kCMIOHardwareBadPropertySizeError), "CMIO::DP::SelectorControl::GetPropertyData: wrong qualifier size for kCMIOSelectorControlPropertyItemName");
				*static_cast<CFStringRef*>(data) = CopyItemNameByID(*static_cast<const UInt32*>(qualifierData));
				dataUsed = sizeof(CFStringRef);
				break;
			
			default:
				Control::GetPropertyData(address, qualifierDataSize, qualifierData, dataSize, dataUsed, data);
				break;
		};
	}
void	HP_PreferredChannels::GetPropertyData(const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32& ioDataSize, void* outData) const
{
	bool isInput = inAddress.mScope == kAudioDevicePropertyScopeInput;
	switch(inAddress.mSelector)
	{
		case kAudioDevicePropertyPreferredChannelsForStereo:
			{
				ThrowIf(ioDataSize != GetPropertyDataSize(inAddress, inQualifierDataSize, inQualifierData), CAException(kAudioHardwareBadPropertySizeError), "HP_PreferredChannels::GetPropertyData: wrong data size for kAudioDevicePropertyPreferredChannelsForStereo");
				UInt32* theStereoChannels = static_cast<UInt32*>(outData);
				
				//	initialize the output
				theStereoChannels[0] = 1;
				theStereoChannels[1] = 2;
				
				//	get the preference
				CACFArray thePrefStereoChannels(isInput ? mPreferredInputStereoChannels : mPreferredOutputStereoChannels, false);
				if(thePrefStereoChannels.IsValid())
				{
					//	get the values from the array
					thePrefStereoChannels.GetUInt32(0, theStereoChannels[0]);
					thePrefStereoChannels.GetUInt32(1, theStereoChannels[1]);
				}
				
				if (!isInput) 
				{
					// update the cached value if necessary
					memcpy(const_cast<HP_PreferredChannels*>(this)->mOutputStereoPair, theStereoChannels, sizeof(UInt32)*2);
				}
			}
			break;
			
		case kAudioDevicePropertyPreferredChannelLayout:
			{
				ThrowIf(ioDataSize != GetPropertyDataSize(inAddress, inQualifierDataSize, inQualifierData), CAException(kAudioHardwareBadPropertySizeError), "HP_PreferredChannels::GetPropertyData: wrong data size for kAudioDevicePropertyPreferredChannelLayout");
				AudioChannelLayout* theChannelLayout = static_cast<AudioChannelLayout*>(outData);
				
				//	fetch the default layout from the device
				mDevice->GetDefaultChannelLayout(isInput, *theChannelLayout);
				
				//	get the pref
				CACFDictionary thePrefChannelLayout(isInput ? mPreferredInputChannelLayout : mPreferredOutputChannelLayout, false);
				if(thePrefChannelLayout.IsValid())
				{
					HP_PreferredChannels_ConstructLayoutFromDictionary(thePrefChannelLayout, *theChannelLayout);
				}
			}
			break;
			
		case 'srdd':
			{
				ThrowIf(ioDataSize != GetPropertyDataSize(inAddress, inQualifierDataSize, inQualifierData), CAException(kAudioHardwareBadPropertySizeError), "HP_PreferredChannels::GetPropertyData: wrong data size for 'srdd'");
				AudioChannelLayout* theChannelLayout = static_cast<AudioChannelLayout*>(outData);
				
				//	fetch the default layout from the device
				mDevice->GetDefaultChannelLayout(isInput, *theChannelLayout);
			}
			break;
	};
}
ComponentInstance	SMACIMAsdec::InitializeIMAAudioDecoder(Component inDecoderComponent, const AudioStreamBasicDescription& inFormat)
{
	UInt32 theSize;
	ComponentInstance theDecoder = OpenComponent(inDecoderComponent);
	ThrowIf(theDecoder == NULL, badComponentInstance, "SMACIMAsdec::InitializeIMAAudioDecoder: couldn't open the component");
	
	//	first, give the decoder the info we have
	theSize = sizeof(AudioStreamBasicDescription);
	ComponentResult theError = AudioCodecSetProperty(theDecoder, kAudioCodecPropertyCurrentInputFormat, theSize, &inFormat);
	ThrowIfError(theError, (CAException)theError, "SMACIMAsdec::InitializeIMAAudioDecoder: got an error setting the input format");
		
	//	now find out what it can output
	theError = AudioCodecGetPropertyInfo(theDecoder, kAudioCodecPropertySupportedOutputFormats, &theSize, NULL);
	ThrowIfError(theError, (CAException)theError, "SMACIMAsdec::InitializeIMAAudioDecoder: got an error getting the available output format list size");
	
	UInt32 theNumberAvailableOutputFormats = theSize / sizeof(AudioStreamBasicDescription);
	AudioStreamBasicDescription* theAvailableOutputFormats = new AudioStreamBasicDescription[theNumberAvailableOutputFormats];
	
	try
	{
		theSize = theNumberAvailableOutputFormats * sizeof(AudioStreamBasicDescription);
		theError = AudioCodecGetProperty(theDecoder, kAudioCodecPropertySupportedOutputFormats, &theSize, theAvailableOutputFormats);
		ThrowIfError(theError, (CAException)theError, "SMACIMAsdec::InitializeIMAAudioDecoder: got an error getting the available output formats");
	
		//	find an acceptable output format
		AudioStreamBasicDescription* theOutputFormat = FindNEFloatFormat(theAvailableOutputFormats, theNumberAvailableOutputFormats);
		ThrowIf(theOutputFormat == NULL, badFormat, "SMACIMAsdec::InitializeIMAAudioDecoder: couldn't find an acceptable output format");
		
		// finish filling out the output format
		theOutputFormat->mSampleRate = inFormat.mSampleRate;
		theOutputFormat->mChannelsPerFrame = inFormat.mChannelsPerFrame;
		theOutputFormat->mBytesPerFrame = 4 * inFormat.mChannelsPerFrame;
		theOutputFormat->mFormatID = kAudioFormatLinearPCM;
		theOutputFormat->mFormatFlags = kAudioFormatFlagsNativeFloatPacked;
		theOutputFormat->mBytesPerPacket = 4 * inFormat.mChannelsPerFrame;
		theOutputFormat->mFramesPerPacket = 1;
		theOutputFormat->mBitsPerChannel = 32;

		//	tell the decoder about it
		theSize = sizeof(AudioStreamBasicDescription);
		theError = AudioCodecSetProperty(theDecoder, kAudioCodecPropertyCurrentOutputFormat, theSize, theOutputFormat);
		ThrowIfError(theError, (CAException)theError, "SMACIMAsdec::InitializeIMAAudioDecoder: got an error setting the output format");
		
		delete[] theAvailableOutputFormats;
		theAvailableOutputFormats = NULL;
	}
	catch(...)
	{
		delete[] theAvailableOutputFormats;
		throw;
	}
	
	//	finally initialize the decoder
	theError = AudioCodecInitialize(theDecoder, NULL, NULL, NULL, 0);
	ThrowIfError(theError, (CAException)theError, "SMACIMAsdec::InitializeIMAAudioDecoder: got an error initializing the decoder");
	
	return theDecoder;
}
Beispiel #7
0
void	BGM_PlugIn::GetPropertyData(AudioObjectID inObjectID, pid_t inClientPID, const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, UInt32& outDataSize, void* outData) const
{
	switch(inAddress.mSelector)
	{
		case kAudioObjectPropertyManufacturer:
			//	This is the human readable name of the maker of the plug-in.
			ThrowIf(inDataSize < sizeof(CFStringRef), CAException(kAudioHardwareBadPropertySizeError), "BGM_PlugIn::GetPropertyData: not enough space for the return value of kAudioObjectPropertyManufacturer");
			*reinterpret_cast<CFStringRef*>(outData) = CFSTR("Background Music contributors");
			outDataSize = sizeof(CFStringRef);
			break;
			
		case kAudioObjectPropertyOwnedObjects:
		case kAudioPlugInPropertyDeviceList:
            {
    			//	This plug-in object only owns the device
    			AudioObjectID* theReturnedDeviceList = reinterpret_cast<AudioObjectID*>(outData);
                if(inDataSize >= sizeof(AudioObjectID))
                {
                    theReturnedDeviceList[0] = kObjectID_Device;
                    
    				//	say how much we returned
    				outDataSize = sizeof(AudioObjectID);
                }
                else
                {
                    outDataSize = 0;
                }
            }
			break;
			
		case kAudioPlugInPropertyTranslateUIDToDevice:
            {
                //	This property translates the UID passed in the qualifier as a CFString into the
                //	AudioObjectID for the device the UID refers to or kAudioObjectUnknown if no device
                //	has the UID.
                ThrowIf(inQualifierDataSize < sizeof(CFStringRef), CAException(kAudioHardwareBadPropertySizeError), "BGM_PlugIn::GetPropertyData: the qualifier size is too small for kAudioPlugInPropertyTranslateUIDToDevice");
                ThrowIf(inDataSize < sizeof(AudioObjectID), CAException(kAudioHardwareBadPropertySizeError), "BGM_PlugIn::GetPropertyData: not enough space for the return value of kAudioPlugInPropertyTranslateUIDToDevice");
                CFStringRef theUID = *reinterpret_cast<const CFStringRef*>(inQualifierData);
                *reinterpret_cast<AudioObjectID*>(outData) =
                    CFEqual(theUID, BGM_Device::GetInstance().CopyDeviceUID()) ? kObjectID_Device : kAudioObjectUnknown;
                outDataSize = sizeof(AudioObjectID);
            }
			break;
			
		case kAudioPlugInPropertyResourceBundle:
			//	The resource bundle is a path relative to the path of the plug-in's bundle.
			//	To specify that the plug-in bundle itself should be used, we just return the
			//	empty string.
			ThrowIf(inDataSize < sizeof(AudioObjectID), CAException(kAudioHardwareBadPropertySizeError), "BGM_GetPlugInPropertyData: not enough space for the return value of kAudioPlugInPropertyResourceBundle");
			*reinterpret_cast<CFStringRef*>(outData) = CFSTR("");
			outDataSize = sizeof(CFStringRef);
			break;
		
		default:
			BGM_Object::GetPropertyData(inObjectID, inClientPID, inAddress, inQualifierDataSize, inQualifierData, inDataSize, outDataSize, outData);
			break;
	};
}
Beispiel #8
0
void	SMACscom::SetInfo(SoundSource inSourceID, OSType inSelector, void* inData)
{
    switch(inSelector)
    {
        case siCompressionParams:
            {
                //	process the the new params and produce an initialized
                //	AudioCodec instance
                ComponentInstance theEncoder = SetCompressionParams(inData);
                ThrowIf(theEncoder == NULL, badFormat, "SMACscom::SetInfo: siCompressionParams didn't generate an encoder");

                //	get rid of the input data
                mSourceData = NULL;
                mOutputData.desc.sampleCount = 0;
                mOutputData.bufferSize = 0;
                mOutputData.frameCount = 0;
                mOutputData.commonFrameSize = 0;

                //	close the old encoder if necessary
                if((mEncoder != NULL) && (theEncoder != mEncoder))
                {
                    CloseComponent(mEncoder);
                }
                
                //	use the new one
                mEncoder = theEncoder;
                
                //	get the number of frames in 1 packet of data
                UInt32 theSize = sizeof(UInt32);
                ComponentResult theError = AudioCodecGetProperty(mEncoder, kAudioCodecPropertyPacketFrameSize, &theSize, &mPacketFrameSize);
                ThrowIfError(theError, (CAException)theError, "SMACscom::SetInfo: siCompressionParams got an error from AudioCodecGetProperty while getting the packet frame size");
                
                //	get the maximum number of bytes in 1 packet of data
                theSize = sizeof(UInt32);
                theError = AudioCodecGetProperty(mEncoder, kAudioCodecPropertyMaximumPacketByteSize, &theSize, &mMaxPacketByteSize);
                ThrowIfError(theError, (CAException)theError, "SMACscom::SetInfo: siCompressionParams got an error from AudioCodecGetProperty while getting the maximum packet byte size");
                
                //	toss the old output buffer
                delete[] mOutputBuffer;
                
                //	allocate enough space for 1 packet of data, since that's
                //	that's all this component will produce per call to GetSourceData
                mOutputBuffer = new Byte[mMaxPacketByteSize];
            }
            break;
        
        case siSourceIsExhausted:
			// in this case it seems to be passed by value -- ugh!
            mSourceIsExhausted = (Boolean)((UInt32)inData);
            // Now pass this on, so no break!
        default:
            ThrowIf(mSourceComponent == NULL, siUnknownInfoType, "SMACscom::SetInfo: no source to pass request to")
            ComponentResult theError = SoundComponentSetInfo(mSourceComponent, inSourceID, inSelector, inData);
            ThrowIfError(theError, (CAException)theError, "SMACscom::SetInfo: got an error from SoundComponentSetInfo");
            break;
    };
}
	void* AppleCMIODPSampleNewPlugIn(CFAllocatorRef allocator, CFUUIDRef requestedTypeUUID) 
	{
		if (not CFEqual(requestedTypeUUID, kCMIOHardwarePlugInTypeID))
			return 0;
		
		try
		{
			// Before going any further, make sure the SampleAssistant process is registerred with Mach's bootstrap service.  Normally, this would be done by having an appropriately
			// configured plist in /Library/LaunchDaemons, but if that is done then the process will be owned by root, thus complicating the debugging process.  Therefore, in the event that the
			// plist is missing (as would be the case for most debugging efforts) attempt to register the SampleAssistant now.  It will fail gracefully if allready registered.
			mach_port_t assistantServicePort;		
			name_t assistantServiceName = "com.apple.cmio.DPA.Sample";
			kern_return_t err = bootstrap_look_up(bootstrap_port, assistantServiceName, &assistantServicePort);
			if (BOOTSTRAP_SUCCESS != err)
			{
				// Create an URL to SampleAssistant that resides at "/Library/CoreMediaIO/Plug-Ins/DAL/Sample.plugin/Contents/Resources/SampleAssistant" 
				CACFURL assistantURL(CFURLCreateWithFileSystemPath(NULL, CFSTR("/Library/CoreMediaIO/Plug-Ins/DAL/Sample.plugin/Contents/Resources/SampleAssistant"), kCFURLPOSIXPathStyle, false));
				ThrowIf(not assistantURL.IsValid(), CAException(-1), "AppleCMIODPSampleNewPlugIn: unable to create URL for the SampleAssistant");

				// Get the maximum size of the of the file system representation of the SampleAssistant's absolute path
				CFIndex length = CFStringGetMaximumSizeOfFileSystemRepresentation(CACFString(CFURLCopyFileSystemPath(CACFURL(CFURLCopyAbsoluteURL(assistantURL.GetCFObject())).GetCFObject(), kCFURLPOSIXPathStyle)).GetCFString());

				// Get the file system representation
				CAAutoFree<char> path(length);
				(void) CFURLGetFileSystemRepresentation(assistantURL.GetCFObject(), true, reinterpret_cast<UInt8*>(path.get()), length);

				mach_port_t assistantServerPort;
				err = bootstrap_create_server(bootstrap_port, path, getuid(), true, &assistantServerPort);
				ThrowIf(BOOTSTRAP_SUCCESS != err, CAException(err), "AppleCMIODPSampleNewPlugIn: couldn't create server");
				
				err = bootstrap_check_in(assistantServerPort, assistantServiceName, &assistantServicePort);

				// The server port is no longer needed so get rid of it
				(void) mach_port_deallocate(mach_task_self(), assistantServerPort);

				// Make sure the call to bootstrap_create_service() succeeded
				ThrowIf(BOOTSTRAP_SUCCESS != err, CAException(err), "AppleCMIODPSampleNewPlugIn: couldn't create SampleAssistant service port");
			}

			// The service port is not longer needed so get rid of it
			(void) mach_port_deallocate(mach_task_self(), assistantServicePort);


			CMIO::DP::Sample::PlugIn* plugIn = new CMIO::DP::Sample::PlugIn(requestedTypeUUID);
			plugIn->Retain();
			return plugIn->GetInterface();
		}
		catch (...)
		{
			return NULL;
		}
	}
Beispiel #10
0
void	HP_Stream::GetPropertyData(const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32& ioDataSize, void* outData) const
{
	//	take and hold the state mutex
	CAMutex::Locker theStateMutex(const_cast<HP_Device*>(mOwningDevice)->GetStateMutex());
	
	switch(inAddress.mSelector)
	{
		case kAudioObjectPropertyName:
			ThrowIf(ioDataSize != GetPropertyDataSize(inAddress, inQualifierDataSize, inQualifierData), CAException(kAudioHardwareBadPropertySizeError), "HP_Stream::GetPropertyData: wrong data size for kAudioObjectPropertyName");
			*static_cast<CFStringRef*>(outData) = CopyStreamName();
			break;
			
		case kAudioObjectPropertyManufacturer:
			ThrowIf(ioDataSize != GetPropertyDataSize(inAddress, inQualifierDataSize, inQualifierData), CAException(kAudioHardwareBadPropertySizeError), "HP_Stream::GetPropertyData: wrong data size for kAudioObjectPropertyName");
			*static_cast<CFStringRef*>(outData) = CopyStreamManufacturerName();
			break;
			
		case kAudioObjectPropertyElementName:
			ThrowIf(ioDataSize != GetPropertyDataSize(inAddress, inQualifierDataSize, inQualifierData), CAException(kAudioHardwareBadPropertySizeError), "HP_Stream::GetPropertyData: wrong data size for kAudioObjectPropertyElementName");
			*static_cast<CFStringRef*>(outData) = CopyElementFullName(inAddress);
			break;
			
		case kAudioObjectPropertyElementCategoryName:
			ThrowIf(ioDataSize != GetPropertyDataSize(inAddress, inQualifierDataSize, inQualifierData), CAException(kAudioHardwareBadPropertySizeError), "HP_Stream::GetPropertyData: wrong data size for kAudioObjectPropertyElementCategoryName");
			*static_cast<CFStringRef*>(outData) = CopyElementCategoryName(inAddress);
			break;
			
		case kAudioObjectPropertyElementNumberName:
			ThrowIf(ioDataSize != GetPropertyDataSize(inAddress, inQualifierDataSize, inQualifierData), CAException(kAudioHardwareBadPropertySizeError), "HP_Stream::GetPropertyData: wrong data size for kAudioObjectPropertyElementNumberName");
			*static_cast<CFStringRef*>(outData) = CopyElementNumberName(inAddress);
			break;
			
		case kAudioStreamPropertyDirection:
			ThrowIf(ioDataSize != GetPropertyDataSize(inAddress, inQualifierDataSize, inQualifierData), CAException(kAudioHardwareBadPropertySizeError), "HP_Stream::GetPropertyData: wrong data size for kAudioStreamPropertyDirection");
			*static_cast<UInt32*>(outData) = IsInput() ? 1 : 0;
			break;
			
		case kAudioStreamPropertyTerminalType:
			ThrowIf(ioDataSize != GetPropertyDataSize(inAddress, inQualifierDataSize, inQualifierData), CAException(kAudioHardwareBadPropertySizeError), "HP_Stream::GetPropertyData: wrong data size for kAudioStreamPropertyTerminalType");
			*static_cast<UInt32*>(outData) = GetTerminalType();
			break;
			
		case kAudioStreamPropertyStartingChannel:
			ThrowIf(ioDataSize != GetPropertyDataSize(inAddress, inQualifierDataSize, inQualifierData), CAException(kAudioHardwareBadPropertySizeError), "HP_Stream::GetPropertyData: wrong data size for kAudioStreamPropertyStartingChannel");
			*static_cast<UInt32*>(outData) = GetStartingDeviceChannelNumber();
			break;
			
		case kAudioStreamPropertyLatency:
			ThrowIf(ioDataSize != GetPropertyDataSize(inAddress, inQualifierDataSize, inQualifierData), CAException(kAudioHardwareBadPropertySizeError), "HP_Stream::GetPropertyData: wrong data size for kAudioStreamPropertyLatency");
			*static_cast<UInt32*>(outData) = GetLatency();
			break;
			
		default:
			HP_Object::GetPropertyData(inAddress, inQualifierDataSize, inQualifierData, ioDataSize, outData);
			break;
	};
}
// Normally, QuickTime will call this directly. In IMA it doesn't.
// The compression params are or contain the "MagicCookie" used by the codec
// When this is called we can initialize the codec as we will have all the necessary information
// to do so. 
ComponentInstance	SMACIMAsdec::SetDecompressionParams(const void* inData)
{
	AudioStreamBasicDescription theInputFormat = {mSampleRate, kIMAAudioGeneralFormatID, 0, kIMA4BlockBytes, kIMA4BlockSamples, 0, mNumChannels, 0, 0 };

	//	use the format to locate a suitable decoder
	Component theDecoderComponent = FindIMAAudioDecoderComponent(theInputFormat);
	ThrowIf(theDecoderComponent == NULL, badFormat, "SMACIMAsdec::SetDecompressionParams: couldn't find a decoder");

	ComponentInstance theDecoder = InitializeIMAAudioDecoder(theDecoderComponent, theInputFormat);
	ThrowIf(theDecoder == NULL, badFormat, "SMACIMAsdec::SetDecompressionParams: couldn't initialize the decoder");
	
	return theDecoder;
}
Beispiel #12
0
 JackPosixMutex::JackPosixMutex(const char* name)
 {
     // Use recursive mutex
     pthread_mutexattr_t mutex_attr;
     int res;
     res = pthread_mutexattr_init(&mutex_attr);
     ThrowIf(res != 0, JackException("JackBasePosixMutex: could not init the mutex attribute"));
     res = pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE);
     ThrowIf(res != 0, JackException("JackBasePosixMutex: could not settype the mutex"));
     res = pthread_mutex_init(&fMutex, &mutex_attr);
     ThrowIf(res != 0, JackException("JackBasePosixMutex: could not init the mutex"));
     pthread_mutexattr_destroy(&mutex_attr);
 }
float CLWEvent::GetDuration() const
{
    cl_ulong commandStart, commandEnd;
    cl_int status = CL_SUCCESS;

    status = clGetEventProfilingInfo(*this, CL_PROFILING_COMMAND_START, sizeof(cl_ulong), &commandStart, nullptr);

    ThrowIf(status != CL_SUCCESS, status, "clGetEventProfilingInfo failed");

    status = clGetEventProfilingInfo(*this, CL_PROFILING_COMMAND_END, sizeof(cl_ulong), &commandEnd, nullptr);

    ThrowIf(status != CL_SUCCESS, status, "clGetEventProfilingInfo failed");

    return (float)(commandEnd - commandStart) / 1000000.f;
}
static OSStatus	HP_HardwarePlugIn_DeviceCreateIOProcIDWithBlock(AudioHardwarePlugInRef inSelf, AudioDeviceIOProcID* outIOProcID, AudioDeviceID inDeviceID, dispatch_queue_t inDispatchQueue, AudioDeviceIOBlock inBlock)
{
	OSStatus theError = kAudioHardwareNoError;
	
	try
	{
		//  check the function arguments
		ThrowIfNULL(inSelf, CAException(kAudioHardwareIllegalOperationError), "HP_HardwarePlugIn_DeviceCreateIOProcIDWithBlock: no plug-in");
		ThrowIf(inBlock == 0, CAException(kAudioHardwareIllegalOperationError), "HP_HardwarePlugIn_DeviceCreateIOProcIDWithBlock: no IOBlock to add");
		ThrowIfNULL(outIOProcID, CAException(kAudioHardwareIllegalOperationError), "HP_HardwarePlugIn_DeviceCreateIOProcIDWithBlock: nowhere to put the return value");
		
		//  find the device for the given ID
		HP_Device* theDevice = HP_Object::GetDeviceByID(inDeviceID);
		ThrowIfNULL(theDevice, CAException(kAudioHardwareBadDeviceError), "HP_HardwarePlugIn_DeviceCreateIOProcIDWithBlock: no device with given ID");
		
		//	do the work
		*outIOProcID = theDevice->Do_CreateIOProcIDWithBlock(inDispatchQueue, inBlock);
	}
	catch(const CAException& inException)
	{
		theError = inException.GetError();
	}
	catch(...)
	{
		theError = kAudioHardwareUnspecifiedError;
	}
	
	return theError;
}
Beispiel #15
0
UInt32	ZKMORHP_SelectorControl::GetItemKindByID(UInt32 inItemID) const
{
	SelectorMap::const_iterator theIterator = mSelectorMap.find(inItemID);
	ThrowIf(theIterator == mSelectorMap.end(), CAException(kAudioHardwareIllegalOperationError), "ZKMORHP_SelectorControl::GetItemKindByID: ID not in selector map");
	
	return theIterator->second.mItemKind;
}
void    BGMDeviceControlSync::Activate()
{
    ThrowIf((mBGMDevice.GetObjectID() == kAudioDeviceUnknown || mOutputDevice.GetObjectID() == kAudioDeviceUnknown),
            BGM_DeviceNotSetException(),
            "BGMDeviceControlSync::Activate: Both the output device and BGMDevice must be set to start synchronizing their controls");
    
    // Init BGMDevice controls to match output device
    CopyVolume(mOutputDevice, mBGMDevice, kAudioObjectPropertyScopeOutput);
    CopyMute(mOutputDevice, mBGMDevice, kAudioObjectPropertyScopeOutput);
    
    if(!mActive)
    {
        // Register listeners for volume and mute values
        mBGMDevice.AddPropertyListener(kVolumePropertyAddress, &BGMDeviceControlSync::BGMDeviceListenerProc, this);
        
        try
        {
            mBGMDevice.AddPropertyListener(kMutePropertyAddress, &BGMDeviceControlSync::BGMDeviceListenerProc, this);
        }
        catch(CAException)
        {
            mBGMDevice.RemovePropertyListener(kVolumePropertyAddress, &BGMDeviceControlSync::BGMDeviceListenerProc, this);
            throw;
        }
        
        mActive = true;
    }
}
Beispiel #17
0
void	HP_Object::GetPropertyData(const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32& ioDataSize, void* outData) const
{
	switch(inAddress.mSelector)
	{
		case kAudioObjectPropertyListenerAdded:
		case kAudioObjectPropertyListenerRemoved:
			ThrowIf(ioDataSize != sizeof(AudioObjectPropertyAddress), CAException(kAudioHardwareBadPropertySizeError), "IOA_Device::GetPropertyData: wrong data size for kAudioObjectPropertyListenerAdded/kAudioObjectPropertyListenerRemoved");
			memset(outData, 0, ioDataSize);
			break;
			
		default:
		{
			HP_Property* theProperty = FindActivePropertyByAddress(inAddress);
			if(theProperty != NULL)
			{
				theProperty->GetPropertyData(inAddress, inQualifierDataSize, inQualifierData, ioDataSize, outData);
			}
			else
			{
				DebugMessage("HP_Object::GetPropertyData: unknown property");
				Throw(CAException(kAudioHardwareUnknownPropertyError));
			}
		}
		break;
	};
}
Beispiel #18
0
void	HLAudioFile::WriteAudioBytes(SInt64 inOffset, UInt32& ioNumberBytes, void* inData, bool inCache)
{
	ThrowIf(mAudioFileID == 0, CAException(fnOpnErr), "HLAudioFile::WriteAudioBytes: file isn't prepared");
	
	OSStatus theError = AudioFileWriteBytes(mAudioFileID, inCache, inOffset, &ioNumberBytes, inData);
	ThrowIfError(theError, CAException(theError), "HLAudioFile::WriteAudioBytes: couldn't write the data");
}
Beispiel #19
0
CFStringRef	ZKMORHP_SelectorControl::CopyItemNameByID(UInt32 inItemID) const
{
	SelectorMap::const_iterator theIterator = mSelectorMap.find(inItemID);
	ThrowIf(theIterator == mSelectorMap.end(), CAException(kAudioHardwareIllegalOperationError), "ZKMORHP_SelectorControl::CopyItemNameByID: ID not in selector map");
	
	return (CFStringRef)CFRetain(theIterator->second.mItemName);
}
Beispiel #20
0
HLFileSystemObject*	HLAudioFileFactory::Create(const FSRef& inParentFSRef, CFStringRef inName, const void* inData, UInt32 inDataSize)
{
	HLFile* theFile = NULL;
	
	//	the data for an HLAudioFile is a stream descption
	ThrowIf(inDataSize != sizeof(AudioStreamBasicDescription), CAException(paramErr), "HLAudioFileFactory::Create: the data is supposed to be an AudioStreamBasicDescription");

	const AudioStreamBasicDescription* theFormat = reinterpret_cast<const AudioStreamBasicDescription*>(inData);

	//	create the file on disk
	FSRef theFSRef;
	AudioFileID theAudioFileID = 0;
	OSStatus theError = AudioFileCreate(&inParentFSRef, inName, mObjectType, theFormat, 0, &theFSRef, &theAudioFileID);
	if(theError == 0)
	{
		AudioFileClose(theAudioFileID);
		
		//	make the object
		theFile = CreateObject(theFSRef);
		theFile->Prepare();
	}
	else
	{
		ThrowIfError(theError, CAException(theError), "HLAudioFileFactory::Create: AudioFileCreate failed");
	}
	
	return theFile;
}
void    BGMPlayThrough::Init(BGMAudioDevice inInputDevice, BGMAudioDevice inOutputDevice)
{
    BGMAssert(mInputDeviceIOProcState.is_lock_free(),
              "BGMPlayThrough::BGMPlayThrough: !mInputDeviceIOProcState.is_lock_free()");
    BGMAssert(mOutputDeviceIOProcState.is_lock_free(),
              "BGMPlayThrough::BGMPlayThrough: !mOutputDeviceIOProcState.is_lock_free()");
    BGMAssert(!mActive, "BGMPlayThrough::BGMPlayThrough: Can't init while active.");
    
    mInputDevice = inInputDevice;
    mOutputDevice = inOutputDevice;
    
    AllocateBuffer();
    
    try
    {
        // Init the semaphore for the output IOProc.
        if(mOutputDeviceIOProcSemaphore == SEMAPHORE_NULL)
        {
            kern_return_t theError = semaphore_create(mach_task_self(), &mOutputDeviceIOProcSemaphore, SYNC_POLICY_FIFO, 0);
            BGM_Utils::ThrowIfMachError("BGMPlayThrough::BGMPlayThrough", "semaphore_create", theError);
            
            ThrowIf(mOutputDeviceIOProcSemaphore == SEMAPHORE_NULL,
                    CAException(kAudioHardwareUnspecifiedError),
                    "BGMPlayThrough::BGMPlayThrough: Could not create semaphore");
        }
    }
    catch (...)
    {
        // Clean up.
        mBuffer.Deallocate();
        throw;
    }
}
Beispiel #22
0
UInt32	ZKMORHP_SelectorControl::GetItemIDForIndex(UInt32 inItemIndex) const
{
	ThrowIf(inItemIndex >= mSelectorMap.size(), CAException(kAudioHardwareIllegalOperationError), "ZKMORHP_SelectorControl::GetItemIDForIndex: index out of range");
	SelectorMap::const_iterator theIterator = mSelectorMap.begin();
	std::advance(theIterator, inItemIndex);
	return theIterator->first;
}
Beispiel #23
0
HLFileSystemObject*	HLDirectoryFactory::Allocate(const char* inPath)
{
	FSRef theFSRef;
	bool theFileExists = HLFileSystem::MakeFSRefFromPath(inPath, theFSRef);
	ThrowIf(!theFileExists, CAException(fnfErr), "HLDirectoryFactory::Allocate: the object doesn't exist");
	return Allocate(theFSRef);
}
Beispiel #24
0
HLFileSystemObject*	HLDirectoryFactory::Create(const char* inPath, bool inCreateParentDirectories, const void* inData, UInt32 inDataSize)
{
	//	can't make the directory if it already exists
	ThrowIf(HLFileSystem::ObjectExists(inPath), CAException(dupFNErr), "HLDirectoryFactory::Create: the directory already exists");
	
	//	normalize the path
	char theNormalizedPath[PATH_MAX];
	HLFileSystem::NormalizePath(inPath, theNormalizedPath, PATH_MAX);
	
	//	extract the directory name
	CACFString theDirectoryName(HLFileSystem::CopyNameFromPath(theNormalizedPath));
	
	//	extract the parent path
	char theParentPath[PATH_MAX];
	HLFileSystem::CopyParentPathFromPath(theNormalizedPath, theParentPath, PATH_MAX);
	
	//	make an FSRef for the parent path
	FSRef theParentFSRef;
	bool theParentExists = HLFileSystem::MakeFSRefFromPath(theParentPath, theParentFSRef);
	if(!theParentExists && inCreateParentDirectories)
	{
		//	the parent directory doesn't exist, but we're allowed to create it
		CAAutoDelete<HLFileSystemObject> theObject(Create(theParentPath, inCreateParentDirectories, NULL, 0));
		theObject->GetFSRef(theParentFSRef);
	}
	else if(!theParentExists)
	{
		//	don't have an FSRef for the parent, so we have to bail
		DebugMessage("HLFileSystemObject::CreateDirectory: couldn't make an FSRef for the parent");
		throw CAException(fnfErr);
	}
	
	//	we have the parent FSRef and the CFString name, so create the directory
	return Create(theParentFSRef, theDirectoryName.GetCFString(), inData, inDataSize);
}
Beispiel #25
0
bool	HLDirectoryFactory::ObjectIsA(const char* inPath) const
{
	FSRef theFSRef;
	bool theFileExists = HLFileSystem::MakeFSRefFromPath(inPath, theFSRef);
	ThrowIf(!theFileExists, CAException(fnfErr), "HLDirectoryFactory::ObjectIsA: the object doesn't exist");
	return ObjectIsA(theFSRef);
}
static OSStatus	HP_HardwarePlugIn_DeviceGetPropertyInfo(AudioHardwarePlugInRef inSelf, AudioDeviceID inDeviceID, UInt32 inChannel, Boolean isInput, AudioDevicePropertyID inPropertyID, UInt32* outSize, Boolean* outWritable)
{
	OSStatus	theError = kAudioHardwareNoError;
	CAMutex*	theObjectStateMutex = NULL;
	bool		theObjectStateMutexNeedsUnlocking = false;
	
	try
	{
		//  check the function arguments
		ThrowIfNULL(inSelf, CAException(kAudioHardwareIllegalOperationError), "HP_HardwarePlugIn_DeviceGetPropertyInfo: no plug-in");
		
		//  find the device for the given ID
		HP_Device* theDevice = HP_Object::GetDeviceByID(inDeviceID);
		ThrowIfNULL(theDevice, CAException(kAudioHardwareBadDeviceError), "HP_HardwarePlugIn_DeviceGetPropertyInfo: no device with given ID");
		
		//	get the object state mutex
		theObjectStateMutex = HP_Object::GetObjectStateMutexByID(inDeviceID);
		
		//	lock the mutex
		if(theObjectStateMutex != NULL)
		{
			theObjectStateMutexNeedsUnlocking = theObjectStateMutex->Lock();
			
			// re-find the object for the given ID since it may have changed while we blocked waiting for the lock
			theDevice = HP_Object::GetDeviceByID(inDeviceID);
			ThrowIfNULL(theDevice, CAException(kAudioHardwareBadObjectError), "HP_HardwarePlugIn_DeviceGetPropertyInfo: no device with given ID after locking");
		}
		
		//  construct a property address
		CAPropertyAddress theAddress(inPropertyID, isInput == 0 ? kAudioDevicePropertyScopeOutput : kAudioDevicePropertyScopeInput, inChannel);
		
		//	do the work
		ThrowIf(!theDevice->HasProperty(theAddress), CAException(kAudioHardwareUnknownPropertyError), "HP_HardwarePlugIn_DeviceGetPropertyInfo: no such property");
		if(outSize != NULL)
		{
			*outSize = theDevice->GetPropertyDataSize(theAddress, 0, NULL);
		}
		if(outWritable != NULL)
		{
			*outWritable = theDevice->IsPropertySettable(theAddress) ? 1 : 0;
		}
	}
	catch(const CAException& inException)
	{
		theError = inException.GetError();
	}
	catch(...)
	{
		theError = kAudioHardwareUnspecifiedError;
	}
	
	//	unlock the object state mutex if we need to
	if((theObjectStateMutex != NULL) && theObjectStateMutexNeedsUnlocking)
	{
		theObjectStateMutex->Unlock();
	}
	
	return theError;
}
void	CAAudioHardwareStream::GetAvailablePhysicalFormatByIndex(UInt32 inIndex, AudioStreamBasicDescription& outFormat) const
{
	UInt32 theNumberFormats = GetNumberAvailablePhysicalFormats();
	ThrowIf(inIndex >= theNumberFormats, CAException(kAudioHardwareIllegalOperationError), "CAAudioHardwareStream::GetAvailablePhysicalFormatByIndex: index out of range");
	CAAutoArrayDelete<AudioStreamBasicDescription> theFormats(theNumberFormats);
	GetAvailablePhysicalFormats(theNumberFormats, theFormats);
	outFormat = theFormats[inIndex];
}
Beispiel #28
0
void	HLAudioFile::WriteAudioFrames(SInt64 inOffset, UInt32& ioNumberFrames, void* inData, bool inCache)
{
	ThrowIf(mAudioFileID == 0, CAException(fnOpnErr), "HLAudioFile::WriteAudioFrames: file isn't prepared");
	
	UInt32 theNumberBytesToWrite = ioNumberFrames * mFormat.mBytesPerFrame;
	OSStatus theError = AudioFileWritePackets(mAudioFileID, inCache, theNumberBytesToWrite, NULL, inOffset, &ioNumberFrames, inData);
	ThrowIfError(theError, CAException(theError), "HLAudioFile::WriteAudioFrames: couldn't write the data");
}
Beispiel #29
0
CLWKernel CLWProgram::GetKernel(std::string const& funcName) const
{
    auto iter = kernels_.find(funcName);
    
    ThrowIf(iter == kernels_.end(), CL_INVALID_KERNEL_NAME, "No such kernel in program");
    
    return iter->second;
}
	//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
	// GetPossibleFrameRateByIndex()
	//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
	Float64 Stream::GetPossibleFrameRateByIndex(UInt32 index) const
	{
		UInt32 numberRates = GetNumberAllPossibleFrameRates();
		ThrowIf(index >= numberRates, CAException(kCMIOHardwareIllegalOperationError), "CMIO::DALA::Stream::GetFrameRateByIndex: index out of range");
		CAAutoArrayDelete<Float64> rates(numberRates);
		GetAllPossibleFrameRates(numberRates, rates);
		return rates[index];
	}