Пример #1
0
inline static void calcParamSpecs1(GraphDef* graphDef, char*& buffer)
{
	if (graphDef->mNumParamSpecs) {
		int hashTableSize = NEXTPOWEROFTWO(graphDef->mNumParamSpecs);
		graphDef->mParamSpecTable = new ParamSpecTable(&gMalloc, hashTableSize, false);
		uint32 nSpecs = graphDef->mNumParamSpecs;
		graphDef->mParamSpecs = (ParamSpec*)malloc(nSpecs * sizeof(ParamSpec));
		IndexMap *tempMaps = (IndexMap*)malloc(nSpecs * sizeof(IndexMap));
		
		for (uint32 i=0; i<nSpecs; ++i) {
			ParamSpec *paramSpec = graphDef->mParamSpecs + i;
			ParamSpec_ReadVer1(paramSpec, buffer); // read version 1 (the only difference to ver 2).
			graphDef->mParamSpecTable->Add(paramSpec);
			IndexMap *tempMap = tempMaps + i;
			tempMap->index = i;
			tempMap->paramSpecIndex = paramSpec->mIndex;
		}
		// calculate numChannels for each spec
		// printf("\n\n**************\n");
		std::sort(tempMaps, tempMaps + nSpecs, sortIndexMaps);
		for (uint32 i=0; i<(nSpecs - 1); ++i) {
			IndexMap *tempMap = tempMaps + i;
			IndexMap *nextTempMap = tempMap + 1;
			ParamSpec *paramSpec = graphDef->mParamSpecs + tempMap->index;
			paramSpec->mNumChannels = nextTempMap->paramSpecIndex - tempMap->paramSpecIndex;
			// printf("%s: numChannels = %i\n", paramSpec->mName, paramSpec->mNumChannels);
		}
		
		IndexMap *tempMap = tempMaps + nSpecs - 1;
		ParamSpec *paramSpec = graphDef->mParamSpecs + tempMap->index;
		paramSpec->mNumChannels = graphDef->mNumControls - tempMap->paramSpecIndex;
		
		// printf("%s: numChannels = %i\n", paramSpec->mName, paramSpec->mNumChannels, paramSpec->mIndex);
		
		free(tempMaps);
	} else {
		// empty table to eliminate test in Graph_SetControl
		graphDef->mParamSpecTable = new ParamSpecTable(&gMalloc, 4, false);
		graphDef->mParamSpecs = 0;
	}
	
}
Пример #2
0
// ver 0 or 1
GraphDef* GraphDef_ReadVer1(World *inWorld, char*& buffer, GraphDef* inList, int32 inVersion)
{
	int32 name[kSCNodeDefNameLen];
	ReadNodeDefName(buffer, name);

	GraphDef* graphDef = (GraphDef*)calloc(1, sizeof(GraphDef));

	graphDef->mOriginal = graphDef;

	graphDef->mNodeDef.mAllocSize = sizeof(Graph);

	memcpy((char*)graphDef->mNodeDef.mName, (char*)name, kSCNodeDefNameByteLen);

	graphDef->mNodeDef.mHash = Hash(graphDef->mNodeDef.mName);

	graphDef->mNumConstants = readInt16_be(buffer);
	graphDef->mConstants = (float*)malloc(graphDef->mNumConstants * sizeof(float));
	for (uint32 i=0; i<graphDef->mNumConstants; ++i) {
		graphDef->mConstants[i] = readFloat_be(buffer);
	}

	graphDef->mNumControls = readInt16_be(buffer);
	graphDef->mInitialControlValues = (float32*)malloc(sizeof(float32) * graphDef->mNumControls);
	for (uint32 i=0; i<graphDef->mNumControls; ++i) {
		graphDef->mInitialControlValues[i] = readFloat_be(buffer);
	}

	graphDef->mNumParamSpecs = readInt16_be(buffer);
	if (graphDef->mNumParamSpecs) {
		int hashTableSize = NEXTPOWEROFTWO(graphDef->mNumParamSpecs);
		graphDef->mParamSpecTable = new ParamSpecTable(&gMalloc, hashTableSize, false);
		graphDef->mParamSpecs = (ParamSpec*)malloc(graphDef->mNumParamSpecs * sizeof(ParamSpec));
		for (uint32 i=0; i<graphDef->mNumParamSpecs; ++i) {
			ParamSpec *paramSpec = graphDef->mParamSpecs + i;
			ParamSpec_ReadVer1(paramSpec, buffer);
			graphDef->mParamSpecTable->Add(paramSpec);
		}
	} else {
		// empty table to eliminate test in Graph_SetControl
		graphDef->mParamSpecTable = new ParamSpecTable(&gMalloc, 4, false);
		graphDef->mParamSpecs = 0;
	}

	graphDef->mNumWires = graphDef->mNumConstants;
	graphDef->mNumUnitSpecs = readInt16_be(buffer);
	graphDef->mUnitSpecs = (UnitSpec*)malloc(sizeof(UnitSpec) * graphDef->mNumUnitSpecs);
	graphDef->mNumCalcUnits = 0;
	for (uint32 i=0; i<graphDef->mNumUnitSpecs; ++i) {
		UnitSpec *unitSpec = graphDef->mUnitSpecs + i;
		UnitSpec_ReadVer1(unitSpec, buffer);

		switch (unitSpec->mCalcRate)
		{
			case calc_ScalarRate :
				unitSpec->mRateInfo = &inWorld->mBufRate;
				break;
			case calc_BufRate :
				graphDef->mNumCalcUnits++;
				unitSpec->mRateInfo = &inWorld->mBufRate;
				break;
			case calc_FullRate :
				graphDef->mNumCalcUnits++;
				unitSpec->mRateInfo = &inWorld->mFullRate;
				break;
			case calc_DemandRate :
				unitSpec->mRateInfo = &inWorld->mBufRate;
				break;
		}

		graphDef->mNodeDef.mAllocSize += unitSpec->mAllocSize;
		graphDef->mNumWires += unitSpec->mNumOutputs;
	}

	DoBufferColoring(inWorld, graphDef);

	graphDef->mWiresAllocSize = graphDef->mNumWires * sizeof(Wire);
	graphDef->mUnitsAllocSize = graphDef->mNumUnitSpecs * sizeof(Unit*);
	graphDef->mCalcUnitsAllocSize = graphDef->mNumCalcUnits * sizeof(Unit*);

	graphDef->mNodeDef.mAllocSize += graphDef->mWiresAllocSize;
	graphDef->mNodeDef.mAllocSize += graphDef->mUnitsAllocSize;
	graphDef->mNodeDef.mAllocSize += graphDef->mCalcUnitsAllocSize;

	graphDef->mControlAllocSize = graphDef->mNumControls * sizeof(float);
	graphDef->mNodeDef.mAllocSize += graphDef->mControlAllocSize;

	graphDef->mMapControlsAllocSize = graphDef->mNumControls * sizeof(float*);
	graphDef->mNodeDef.mAllocSize += graphDef->mMapControlsAllocSize;

	graphDef->mMapControlRatesAllocSize = graphDef->mNumControls * sizeof(int*);
	graphDef->mNodeDef.mAllocSize += graphDef->mMapControlRatesAllocSize;


	graphDef->mNext = inList;
	graphDef->mRefCount = 1;

	if (inVersion >= 1) {
		graphDef->mNumVariants = readInt16_be(buffer);
		if (graphDef->mNumVariants) {
			graphDef->mVariants = (GraphDef*)calloc(graphDef->mNumVariants, sizeof(GraphDef));
			for (uint32 i=0; i<graphDef->mNumVariants; ++i) {
				GraphDef_ReadVariant(inWorld, buffer, graphDef, graphDef->mVariants + i);
			}
		}
	}

	return graphDef;
}