void CARingBuffer::Allocate(int nChannels, UInt32 bytesPerFrame, UInt32 capacityFrames) { Deallocate(); //capacityFrames = NextPowerOfTwo(capacityFrames); mNumberChannels = nChannels; mBytesPerFrame = bytesPerFrame; mCapacityFrames = capacityFrames; //mCapacityFramesMask = capacityFrames - 1; mCapacityBytes = bytesPerFrame * capacityFrames; // put everything in one memory allocation, first the pointers, then the deinterleaved channels UInt32 allocSize = (mCapacityBytes + sizeof(Byte *)) * nChannels; Byte *p = (Byte *)CA_malloc(allocSize); memset(p, 0, allocSize); mBuffers = (Byte **)p; p += nChannels * sizeof(Byte *); for (int i = 0; i < nChannels; ++i) { mBuffers[i] = p; p += mCapacityBytes; } for (UInt32 i = 0; i<kGeneralRingTimeBoundsQueueSize; ++i) { mTimeBoundsQueue[i].mStartTime = 0; mTimeBoundsQueue[i].mEndTime = 0; mTimeBoundsQueue[i].mUpdateCounter = 0; } mTimeBoundsQueuePtr = 0; }
static void _ShowCF (FILE* file, CFStringRef str) { if (CFGetTypeID(str) != CFStringGetTypeID()) { CFShow(str); return; } UInt32 len = CFStringGetLength(str); char* chars = (char*)CA_malloc (len * 2); // give us plenty of room for unichar chars if (CFStringGetCString (str, chars, len * 2, kCFStringEncodingUTF8)) fprintf (file, "%s", chars); else CFShow (str); free (chars); }
//_____________________________________________________________________________ // bool AUScope::RestoreElementNames (CFDictionaryRef& inNameDict) { static char string[32]; //first we have to see if we have enough elements and if not create them bool didAddElements = false; unsigned int maxElNum = 0; int dictSize = CFDictionaryGetCount(inNameDict); CFStringRef * keys = (CFStringRef*)CA_malloc (dictSize * sizeof (CFStringRef)); CFDictionaryGetKeysAndValues (inNameDict, reinterpret_cast<const void**>(keys), NULL); for (int i = 0; i < dictSize; i++) { unsigned int intKey; CFStringGetCString (keys[i], string, 32, kCFStringEncodingASCII); sscanf (string, "%u", &intKey); if (UInt32(intKey) > maxElNum) maxElNum = intKey; } if (maxElNum >= GetNumberOfElements()) { SetNumberOfElements (maxElNum+1); didAddElements = true; } // OK, now we have the number of elements that we need - lets restate their names for (int i = 0; i < dictSize; i++) { CFStringRef elName = reinterpret_cast<CFStringRef>(CFDictionaryGetValue (inNameDict, keys[i])); int intKey; CFStringGetCString (keys[i], string, 32, kCFStringEncodingASCII); sscanf (string, "%d", &intKey); GetElement (intKey)->SetName (elName); } free (keys); return didAddElements; }