void CAHALAudioDevice::GetStreams(bool inIsInput, UInt32& ioNumberStreams, AudioObjectID* outStreamList) const { CAPropertyAddress theAddress(kAudioDevicePropertyStreams, inIsInput ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput); UInt32 theSize = ioNumberStreams * SizeOf32(AudioObjectID); GetPropertyData(theAddress, 0, NULL, theSize, outStreamList); ioNumberStreams = theSize / SizeOf32(AudioObjectID); }
void CAHALAudioStream::GetAvailablePhysicalFormats(UInt32& ioNumberFormats, AudioStreamRangedDescription* outFormats) const { CAPropertyAddress theAddress(kAudioStreamPropertyAvailablePhysicalFormats); UInt32 theSize = ioNumberFormats * SizeOf32(AudioStreamRangedDescription); GetPropertyData(theAddress, 0, NULL, theSize, outFormats); ioNumberFormats = theSize / SizeOf32(AudioStreamRangedDescription); }
void ACAppleIMA4Encoder::GetPropertyInfo(AudioCodecPropertyID inPropertyID, UInt32& outPropertyDataSize, Boolean& outWritable) { switch(inPropertyID) { case kAudioCodecPropertyAvailableNumberChannels: outPropertyDataSize = SizeOf32(UInt32) * kMaxIMA4Channels; outWritable = false; break; case kAudioCodecPropertyAvailableInputSampleRates: outPropertyDataSize = SizeOf32(AudioValueRange); outWritable = false; break; case kAudioCodecPropertyAvailableOutputSampleRates: outPropertyDataSize = SizeOf32(AudioValueRange); outWritable = false; break; case kAudioCodecPropertyZeroFramesPadded: outPropertyDataSize = SizeOf32(UInt32); outWritable = false; break; case kAudioCodecPropertyPrimeInfo: outPropertyDataSize = SizeOf32(AudioCodecPrimeInfo); outWritable = false; break; default: ACAppleIMA4Codec::GetPropertyInfo(inPropertyID, outPropertyDataSize, outWritable); break; }; }
void CAHALAudioSystemObject::GetAudioDevices(UInt32& ioNumberAudioDevices, AudioObjectID* outAudioDevices) const { CAPropertyAddress theAddress(kAudioHardwarePropertyDevices); UInt32 theSize = ioNumberAudioDevices * SizeOf32(AudioObjectID); GetPropertyData(theAddress, 0, NULL, theSize, outAudioDevices); ioNumberAudioDevices = theSize / SizeOf32(AudioObjectID); }
void CAHALAudioDevice::GetAvailableDataSources(AudioObjectPropertyScope inScope, UInt32 inChannel, UInt32& ioNumberSources, UInt32* outSources) const { CAPropertyAddress theAddress(kAudioDevicePropertyDataSources, inScope, inChannel); UInt32 theNumberSources = std::min(GetNumberAvailableDataSources(inScope, inChannel), ioNumberSources); UInt32 theSize = theNumberSources * SizeOf32(UInt32); GetPropertyData(theAddress, 0, NULL, theSize, outSources); ioNumberSources = theSize / SizeOf32(UInt32); }
void CAHALAudioDevice::GetAvailableClockSources(UInt32& ioNumberSources, UInt32* outSources) const { CAPropertyAddress theAddress(kAudioDevicePropertyClockSources); UInt32 theNumberSources = std::min(GetNumberAvailableClockSources(), ioNumberSources); UInt32 theSize = theNumberSources * SizeOf32(UInt32); GetPropertyData(theAddress, 0, NULL, theSize, outSources); ioNumberSources = theSize / SizeOf32(UInt32); }
void CAHALAudioDevice::GetAvailableNominalSampleRateRanges(UInt32& ioNumberRanges, AudioValueRange* outRanges) const { CAPropertyAddress theAddress(kAudioDevicePropertyAvailableNominalSampleRates); if(HasProperty(theAddress)) { UInt32 theSize = ioNumberRanges * SizeOf32(AudioValueRange); GetPropertyData(theAddress, 0, NULL, theSize, outRanges); ioNumberRanges = theSize / SizeOf32(AudioValueRange); } else { ioNumberRanges = 0; } }
UInt32 CAHALAudioStream::GetNumberAvailablePhysicalFormats() const { CAPropertyAddress theAddress(kAudioStreamPropertyAvailablePhysicalFormats); UInt32 theAnswer = GetPropertyDataSize(theAddress, 0, NULL); theAnswer /= SizeOf32(AudioStreamRangedDescription); return theAnswer; }
UInt32 CAHALAudioSystemObject::GetNumberAudioDevices() const { CAPropertyAddress theAddress(kAudioHardwarePropertyDevices); UInt32 theAnswer = GetPropertyDataSize(theAddress, 0, NULL); theAnswer /= SizeOf32(AudioObjectID); return theAnswer; }
UInt32 CAHALAudioDevice::GetNumberStreams(bool inIsInput) const { CAPropertyAddress theAddress(kAudioDevicePropertyStreams, inIsInput ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput); UInt32 theAnswer = GetPropertyDataSize(theAddress, 0, NULL); theAnswer /= SizeOf32(AudioObjectID); return theAnswer; }
void CAHALAudioDevice::GetRelatedAudioDevices(UInt32& ioNumberRelatedDevices, AudioObjectID* outRelatedDevices) const { CAPropertyAddress theAddress(kAudioDevicePropertyRelatedDevices); if(HasProperty(theAddress)) { UInt32 theSize = ioNumberRelatedDevices * SizeOf32(AudioObjectID); GetPropertyData(theAddress, 0, NULL, theSize, outRelatedDevices); ioNumberRelatedDevices = theSize / SizeOf32(AudioObjectID); } else { UInt32 theSize = ioNumberRelatedDevices * SizeOf32(AudioObjectID); memset(outRelatedDevices, 0, theSize); ioNumberRelatedDevices = 0; } }
UInt32 CAHALAudioObject::GetNumberOwnedObjects(AudioClassID inClass) const { // set up the return value UInt32 theAnswer = 0; // set up the property address CAPropertyAddress theAddress(kAudioObjectPropertyOwnedObjects); // figure out the qualifier UInt32 theQualifierSize = 0; void* theQualifierData = NULL; if(inClass != 0) { theQualifierSize = sizeof(AudioObjectID); theQualifierData = &inClass; } // get the property data size theAnswer = GetPropertyDataSize(theAddress, theQualifierSize, theQualifierData); // calculate the number of object IDs theAnswer /= SizeOf32(AudioObjectID); return theAnswer; }
bool HP_SystemInfo::IsCurrentProcessInitingOrExiting() { UInt32 isInitingOrExiting = 0; UInt32 theSize = SizeOf32(UInt32); AudioObjectPropertyAddress theAddress = { kAudioHardwarePropertyIsInitingOrExiting, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster }; AudioObjectGetPropertyData(kAudioObjectSystemObject, &theAddress, 0, NULL, &theSize, &isInitingOrExiting); return isInitingOrExiting != 0; }
OSStatus HP_SystemInfo::SystemListener(AudioObjectID inObjectID, UInt32 inNumberAddresses, const AudioObjectPropertyAddress inAddresses[], void* /*inClientData*/) { if(inObjectID == kAudioObjectSystemObject) { for(UInt32 theAddressIndex = 0; theAddressIndex < inNumberAddresses; ++theAddressIndex) { switch(inAddresses[theAddressIndex].mSelector) { case 'user': // kAudioHardwarePropertyUserSessionIsActiveOrHeadless { CAPropertyAddress theAddress('user'); // kAudioHardwarePropertyUserSessionIsActiveOrHeadless UInt32 theUserSessionIsActiveOrHeadless = 1; UInt32 theSize = SizeOf32(UInt32); AudioObjectGetPropertyData(kAudioObjectSystemObject, &theAddress, 0, NULL, &theSize, &theUserSessionIsActiveOrHeadless); sCurrentUserSessionIsActiveOrHeadless = theUserSessionIsActiveOrHeadless != 0; } break; case 'pmut': // kAudioHardwarePropertyProcessIsAudible { CAPropertyAddress theAddress('pmut'); // kAudioHardwarePropertyProcessIsAudible UInt32 theProcessIsAudible = 1; UInt32 theSize = SizeOf32(UInt32); AudioObjectGetPropertyData(kAudioObjectSystemObject, &theAddress, 0, NULL, &theSize, &theProcessIsAudible); sCurrentProcessIsAudible = theProcessIsAudible != 0; } break; case 'stmo': // kAudioHardwarePropertyMixStereoToMono { CAPropertyAddress theAddress('stmo'); // kAudioHardwarePropertyMixStereoToMono UInt32 theIsMixingStereoToMono = 1; UInt32 theSize = SizeOf32(UInt32); OSStatus theError = AudioObjectGetPropertyData(kAudioObjectSystemObject, &theAddress, 0, NULL, &theSize, &theIsMixingStereoToMono); if(theError == 0) { sIsMixingStereoToMono = theIsMixingStereoToMono != 0; } } break; }; } } return 0; }
bool HP_SystemInfo::IsCurrentProcessTheMaster() { UInt32 isMaster = 0; UInt32 theSize = SizeOf32(UInt32); AudioObjectPropertyAddress theAddress = { kAudioHardwarePropertyProcessIsMaster, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster }; AudioObjectGetPropertyData(kAudioObjectSystemObject, &theAddress, 0, NULL, &theSize, &isMaster); return isMaster != 0; }
void CAHALAudioDevice::SetIOProcStreamUsage(AudioDeviceIOProcID inIOProcID, bool inIsInput, const bool* inStreamUsage) { // make an AudioHardwareIOProcStreamUsage the right size UInt32 theNumberStreams = GetNumberStreams(inIsInput); UInt32 theSize = SizeOf32(void*) + SizeOf32(UInt32) + (theNumberStreams * SizeOf32(UInt32)); CAAutoFree<AudioHardwareIOProcStreamUsage> theStreamUsage(theSize); // set it up theStreamUsage->mIOProc = reinterpret_cast<void*>(inIOProcID); theStreamUsage->mNumberStreams = theNumberStreams; for(UInt32 theIndex = 0; theIndex < theNumberStreams; ++theIndex) { theStreamUsage->mStreamIsOn[theIndex] = (inStreamUsage[theIndex] ? 1 : 0); } // set the property CAPropertyAddress theAddress(kAudioDevicePropertyIOProcStreamUsage, inIsInput ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput); SetPropertyData(theAddress, 0, NULL, theSize, theStreamUsage); }
UInt32 CAHALAudioDevice::GetNumberAvailableDataSources(AudioObjectPropertyScope inScope, UInt32 inChannel) const { CAPropertyAddress theAddress(kAudioDevicePropertyDataSources, inScope, inChannel); UInt32 theAnswer = 0; if(HasProperty(theAddress)) { UInt32 theSize = GetPropertyDataSize(theAddress, 0, NULL); theAnswer = theSize / SizeOf32(UInt32); } return theAnswer; }
UInt32 CAHALAudioDevice::GetNumberRelatedAudioDevices() const { CAPropertyAddress theAddress(kAudioDevicePropertyRelatedDevices); UInt32 theAnswer = 0; if(HasProperty(theAddress)) { theAnswer = GetPropertyDataSize(theAddress, 0, NULL); theAnswer /= SizeOf32(AudioObjectID); } return theAnswer; }
UInt32 CAHALAudioDevice::GetNumberAvailableNominalSampleRateRanges() const { UInt32 theAnswer = 0; CAPropertyAddress theAddress(kAudioDevicePropertyAvailableNominalSampleRates); if(HasProperty(theAddress)) { UInt32 theSize = GetPropertyDataSize(theAddress, 0, NULL); theAnswer = theSize / SizeOf32(AudioValueRange); } return theAnswer; }
UInt32 CAHALAudioDevice::GetNumberAvailableClockSources() const { CAPropertyAddress theAddress(kAudioDevicePropertyClockSources); UInt32 theAnswer = 0; if(HasProperty(theAddress)) { UInt32 theSize = GetPropertyDataSize(theAddress, 0, NULL); theAnswer = theSize / SizeOf32(UInt32); } return theAnswer; }
void CAHALAudioObject::GetAllOwnedObjects(AudioClassID inClass, UInt32& ioNumberObjects, AudioObjectID* ioObjectIDs) const { // set up the property address CAPropertyAddress theAddress(kAudioObjectPropertyOwnedObjects); // figure out the qualifier UInt32 theQualifierSize = 0; void* theQualifierData = NULL; if(inClass != 0) { theQualifierSize = sizeof(AudioObjectID); theQualifierData = &inClass; } // get the property data UInt32 theDataSize = ioNumberObjects * SizeOf32(AudioClassID); GetPropertyData(theAddress, theQualifierSize, theQualifierData, theDataSize, ioObjectIDs); // set the number of object IDs being returned ioNumberObjects = theDataSize / SizeOf32(AudioObjectID); }
void ACSimpleCodec::GetPropertyInfo(AudioCodecPropertyID inPropertyID, UInt32& outPropertyDataSize, Boolean& outWritable) { switch(inPropertyID) { case kAudioCodecPropertyInputBufferSize: outPropertyDataSize = SizeOf32(UInt32); outWritable = true; break; default: ACBaseCodec::GetPropertyInfo(inPropertyID, outPropertyDataSize, outWritable); break; } }
bool CAAudioBufferList::HasData(AudioBufferList& inBufferList) { bool hasData = false; for(UInt32 theBufferIndex = 0; !hasData && (theBufferIndex < inBufferList.mNumberBuffers); ++theBufferIndex) { if(inBufferList.mBuffers[theBufferIndex].mData != NULL) { UInt32* theBuffer = (UInt32*)inBufferList.mBuffers[theBufferIndex].mData; UInt32 theNumberSamples = inBufferList.mBuffers[theBufferIndex].mDataByteSize / SizeOf32(UInt32); for(UInt32 theSampleIndex = 0; !hasData && (theSampleIndex < theNumberSamples); ++theSampleIndex) { hasData = theBuffer[theSampleIndex] != 0; } } } return hasData; }
UInt32 HP_PreferredChannels::GetPropertyDataSize(const AudioObjectPropertyAddress& inAddress, UInt32 /*inQualifierDataSize*/, const void* /*inQualifierData*/) const { UInt32 theAnswer = 0; switch(inAddress.mSelector) { case kAudioDevicePropertyPreferredChannelsForStereo: theAnswer = 2 * SizeOf32(UInt32); break; case kAudioDevicePropertyPreferredChannelLayout: theAnswer = CAAudioChannelLayout::CalculateByteSize(mDevice->GetTotalNumberChannels(inAddress.mScope == kAudioDevicePropertyScopeInput)); break; case 'srdd': theAnswer = CAAudioChannelLayout::CalculateByteSize(mDevice->GetTotalNumberChannels(inAddress.mScope == kAudioDevicePropertyScopeInput)); break; }; return theAnswer; }
ACAppleIMA4Encoder::ACAppleIMA4Encoder(AudioComponentInstance inInstance) : ACAppleIMA4Codec(kInputBufferPackets * kIMAFramesPerPacket * SizeOf32(SInt16), inInstance), mEndOfInput(false), mZeroPaddedOnce(false), mZeroesPadded(0) { // This encoder only accepts 16 bit native endian signed integer as it's input, // but can handle any sample rate and any number of channels CAStreamBasicDescription theInputFormat(kAudioStreamAnyRate, kAudioFormatLinearPCM, 0, 1, 0, 0, 16, kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked); AddInputFormat(theInputFormat); // set our intial input format to mono 16 bit native endian signed integer at a 44100 sample rate mInputFormat.mSampleRate = 44100; mInputFormat.mFormatID = kAudioFormatLinearPCM; mInputFormat.mFormatFlags = kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked; mInputFormat.mBytesPerPacket = 2; mInputFormat.mFramesPerPacket = 1; mInputFormat.mBytesPerFrame = 2; mInputFormat.mChannelsPerFrame = 1; mInputFormat.mBitsPerChannel = 16; // This encoder only puts out an Acme IMA4 stream CAStreamBasicDescription theOutputFormat(kAudioStreamAnyRate, 'DEMO', 0, kIMAFramesPerPacket, 0, 0, 0, 0); AddOutputFormat(theOutputFormat); // set our intial output format to mono Apple IMA4 at a 44100 sample rate mOutputFormat.mSampleRate = 44100; mOutputFormat.mFormatID = 'DEMO'; mOutputFormat.mFormatFlags = 0; mOutputFormat.mBytesPerPacket = kIMA4PacketBytes; mOutputFormat.mFramesPerPacket = kIMAFramesPerPacket; mOutputFormat.mBytesPerFrame = 0; mOutputFormat.mChannelsPerFrame = 1; mOutputFormat.mBitsPerChannel = 0; mSupportedChannelTotals[0] = 1; mSupportedChannelTotals[1] = 2; // initialize our channel state InitializeChannelStateList(); }
AudioObjectID CAHALAudioObject::GetOwnedObjectByIndex(AudioClassID inClass, UInt32 inIndex) { // set up the property address CAPropertyAddress theAddress(kAudioObjectPropertyOwnedObjects); // figure out the qualifier UInt32 theQualifierSize = 0; void* theQualifierData = NULL; if(inClass != 0) { theQualifierSize = sizeof(AudioObjectID); theQualifierData = &inClass; } // figure out how much space to allocate UInt32 theDataSize = GetPropertyDataSize(theAddress, theQualifierSize, theQualifierData); UInt32 theNumberObjectIDs = theDataSize / SizeOf32(AudioObjectID); // set up the return value AudioObjectID theAnswer = 0; // maker sure the index is in range if(inIndex < theNumberObjectIDs) { // allocate it CAAutoArrayDelete<AudioObjectID> theObjectList(theDataSize / sizeof(AudioObjectID)); // get the property data GetPropertyData(theAddress, theQualifierSize, theQualifierData, theDataSize, theObjectList); // get the return value theAnswer = theObjectList[inIndex]; } return theAnswer; }
void ACBaseCodec::GetPropertyInfo(AudioCodecPropertyID inPropertyID, UInt32& outPropertyDataSize, Boolean& outWritable) { switch(inPropertyID) { case kAudioCodecPropertyNameCFString: outPropertyDataSize = SizeOf32(CFStringRef); outWritable = false; break; case kAudioCodecPropertyManufacturerCFString: outPropertyDataSize = SizeOf32(CFStringRef); outWritable = false; break; case kAudioCodecPropertyFormatCFString: outPropertyDataSize = SizeOf32(CFStringRef); outWritable = false; break; case kAudioCodecPropertyRequiresPacketDescription: outPropertyDataSize = SizeOf32(UInt32); outWritable = false; break; case kAudioCodecPropertyMinimumNumberInputPackets : outPropertyDataSize = SizeOf32(UInt32); outWritable = false; break; case kAudioCodecPropertyMinimumNumberOutputPackets : outPropertyDataSize = SizeOf32(UInt32); outWritable = false; break; case kAudioCodecPropertyCurrentInputFormat: outPropertyDataSize = SizeOf32(AudioStreamBasicDescription); outWritable = true; break; case kAudioCodecPropertySupportedInputFormats: case kAudioCodecPropertyInputFormatsForOutputFormat: outPropertyDataSize = GetNumberSupportedInputFormats() * SizeOf32(AudioStreamBasicDescription); outWritable = false; break; case kAudioCodecPropertyCurrentOutputFormat: outPropertyDataSize = SizeOf32(AudioStreamBasicDescription); outWritable = true; break; case kAudioCodecPropertySupportedOutputFormats: case kAudioCodecPropertyOutputFormatsForInputFormat: outPropertyDataSize = GetNumberSupportedOutputFormats() * SizeOf32(AudioStreamBasicDescription); outWritable = false; break; case kAudioCodecPropertyMagicCookie: outPropertyDataSize = GetMagicCookieByteSize(); outWritable = true; break; case kAudioCodecPropertyInputBufferSize: outPropertyDataSize = SizeOf32(UInt32); outWritable = false; break; case kAudioCodecPropertyUsedInputBufferSize: outPropertyDataSize = SizeOf32(UInt32); outWritable = false; break; case kAudioCodecPropertyIsInitialized: outPropertyDataSize = SizeOf32(UInt32); outWritable = false; break; case kAudioCodecPropertyAvailableNumberChannels: outPropertyDataSize = SizeOf32(UInt32) * 2; // Mono, stereo outWritable = false; break; case kAudioCodecPropertyPrimeMethod: outPropertyDataSize = SizeOf32(UInt32); outWritable = false; break; case kAudioCodecPropertyPrimeInfo: outPropertyDataSize = SizeOf32(AudioCodecPrimeInfo); outWritable = false; break; case kAudioCodecPropertyDoesSampleRateConversion: outPropertyDataSize = SizeOf32(UInt32); outWritable = false; break; default: CODEC_THROW(kAudioCodecUnknownPropertyError); break; }; }
UInt32 CAAudioBufferList::CalculateByteSize(UInt32 inNumberBuffers) { UInt32 theSize = SizeOf32(AudioBufferList) - SizeOf32(AudioBuffer); theSize += inNumberBuffers * SizeOf32(AudioBuffer); return theSize; }
void CAAudioBufferList::Sum(const AudioBufferList& inSourceBufferList, AudioBufferList& ioSummedBufferList) { // assumes that the buffers are Float32 samples and the listst have the same layout // this is a lame algorithm, by the way. it could at least be unrolled a couple of times for(UInt32 theBufferIndex = 0; theBufferIndex < ioSummedBufferList.mNumberBuffers; ++theBufferIndex) { Float32* theSourceBuffer = static_cast<Float32*>(inSourceBufferList.mBuffers[theBufferIndex].mData); Float32* theSummedBuffer = static_cast<Float32*>(ioSummedBufferList.mBuffers[theBufferIndex].mData); UInt32 theNumberSamplesToMix = ioSummedBufferList.mBuffers[theBufferIndex].mDataByteSize / SizeOf32(Float32); if((theSourceBuffer != NULL) && (theSummedBuffer != NULL) && (theNumberSamplesToMix > 0)) { while(theNumberSamplesToMix > 0) { *theSummedBuffer += *theSourceBuffer; ++theSummedBuffer; ++theSourceBuffer; --theNumberSamplesToMix; } } } }
void CAAudioBufferList::CopyChannel(const AudioBuffer& inSource, UInt32 inSourceChannel, AudioBuffer& outDestination, UInt32 inDestinationChannel) { // set up the stuff for the loop UInt32 theNumberFramesToCopy = outDestination.mDataByteSize / (outDestination.mNumberChannels * SizeOf32(Float32)); const Float32* theSource = static_cast<const Float32*>(inSource.mData); Float32* theDestination = static_cast<Float32*>(outDestination.mData); // loop through the data and copy the samples while(theNumberFramesToCopy > 0) { // copy the data theDestination[inDestinationChannel] = theSource[inSourceChannel]; // adjust the pointers --theNumberFramesToCopy; theSource += inSource.mNumberChannels; theDestination += outDestination.mNumberChannels; } }