void init_delay(Delay *c, int di) { // turn size into a mask for quick modding //c->size = 2*di; /* int p = 0; while(c->size) { c->size /= 2; p++; } c->size = 1; while(p) { c->size *= 2; p--; } c->mask = c->size - 1; */ c->size = NEXTPOWEROFTWO(2*di); c->mask = c->size - 1; c->x = (float *)RTAlloc(gWorld,sizeof(float) * c->size);//new float[c->size]; //c->y = new float[c->size]; memset(c->x,0,c->size*sizeof(float)); // memset(c->y,0,c->size*sizeof(float)); c->cursor = 0; c->di = di; c->d1 = (c->size-di)%c->size; }
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; } }
int main(int argc, char* argv[]) { setlinebuf(stdout); #ifdef _WIN32 #ifdef SC_WIN32_STATIC_PTHREADS // initialize statically linked pthreads library pthread_win32_process_attach_np(); #endif // initialize winsock WSAData wsaData; int nCode; if ((nCode = WSAStartup(MAKEWORD(1, 1), &wsaData)) != 0) { scprintf( "WSAStartup() failed with error code %d.\n", nCode ); return 1; } #endif int udpPortNum = -1; int tcpPortNum = -1; WorldOptions options = kDefaultWorldOptions; for (int i=1; i<argc;) { if (argv[i][0] != '-' || argv[i][1] == 0 || strchr("utaioczblndpmwZrNSDIOMHvRUhPL", argv[i][1]) == 0) { scprintf("ERROR: Invalid option %s\n", argv[i]); Usage(); } int j = i; switch (argv[j][1]) { case 'u' : checkNumArgs(2); udpPortNum = atoi(argv[j+1]); break; case 't' : checkNumArgs(2); tcpPortNum = atoi(argv[j+1]); break; case 'a' : checkNumArgs(2); options.mNumAudioBusChannels = atoi(argv[j+1]); break; case 'i' : checkNumArgs(2); options.mNumInputBusChannels = atoi(argv[j+1]); break; case 'o' : checkNumArgs(2); options.mNumOutputBusChannels = atoi(argv[j+1]); break; case 'c' : checkNumArgs(2); options.mNumControlBusChannels = atoi(argv[j+1]); break; case 'z' : checkNumArgs(2); options.mBufLength = NEXTPOWEROFTWO(atoi(argv[j+1])); break; case 'Z' : checkNumArgs(2); options.mPreferredHardwareBufferFrameSize = NEXTPOWEROFTWO(atoi(argv[j+1])); break; case 'b' : checkNumArgs(2); options.mNumBuffers = NEXTPOWEROFTWO(atoi(argv[j+1])); break; case 'l' : checkNumArgs(2); options.mMaxLogins = NEXTPOWEROFTWO(atoi(argv[j+1])); break; case 'n' : checkNumArgs(2); options.mMaxNodes = NEXTPOWEROFTWO(atoi(argv[j+1])); break; case 'd' : checkNumArgs(2); options.mMaxGraphDefs = NEXTPOWEROFTWO(atoi(argv[j+1])); break; case 'p' : checkNumArgs(2); options.mPassword = argv[j+1]; break; case 'm' : checkNumArgs(2); options.mRealTimeMemorySize = atoi(argv[j+1]); break; case 'w' : checkNumArgs(2); options.mMaxWireBufs = atoi(argv[j+1]); break; case 'r' : checkNumArgs(2); options.mNumRGens = atoi(argv[j+1]); break; case 'S' : checkNumArgs(2); options.mPreferredSampleRate = (uint32)atof(argv[j+1]); break; case 'D' : checkNumArgs(2); options.mLoadGraphDefs = atoi(argv[j+1]); break; case 'N' : #ifdef NO_LIBSNDFILE scprintf("NRT mode not supported: scsynth compiled without libsndfile\n"); exit(0); #endif // -N cmd-filename input-filename output-filename sample-rate header-format sample-format checkNumArgs(7); options.mRealTime = false; options.mNonRealTimeCmdFilename = strcmp(argv[j+1], "_") ? argv[j+1] : 0; options.mNonRealTimeInputFilename = strcmp(argv[j+2], "_") ? argv[j+2] : 0; options.mNonRealTimeOutputFilename = argv[j+3]; options.mPreferredSampleRate = (uint32)atof(argv[j+4]); options.mNonRealTimeOutputHeaderFormat = argv[j+5]; options.mNonRealTimeOutputSampleFormat = argv[j+6]; break; #ifdef __APPLE__ case 'I' : checkNumArgs(2); options.mInputStreamsEnabled = argv[j+1]; break; case 'O' : checkNumArgs(2); options.mOutputStreamsEnabled = argv[j+1]; break; case 'M': #endif case 'H' : checkNumArgs(2); options.mInDeviceName = argv[j+1]; #ifdef __APPLE__ if (i+1>argc || argv[j+2][0]=='-') { options.mOutDeviceName = options.mInDeviceName; } else { // If there's a second argument then the user wants separate I/O devices options.mOutDeviceName = argv[j+2]; ++i; } #else options.mOutDeviceName = options.mInDeviceName; // Non-Mac platforms always use same device #endif break; case 'L' : checkNumArgs(1); #if (_POSIX_MEMLOCK - 0) >= 200112L options.mMemoryLocking = true; #else options.mMemoryLocking = false; #endif break; case 'v' : checkNumArgs(2); options.mVerbosity = atoi(argv[j+1]); break; case 'R' : checkNumArgs(2); options.mRendezvous = atoi(argv[j+1]) > 0; break; case 'U' : checkNumArgs(2); options.mUGensPluginPath = argv[j+1]; break; case 'P' : checkNumArgs(2); options.mRestrictedPath = argv[j+1]; break; case 'h': default: Usage(); } } if (udpPortNum == -1 && tcpPortNum == -1 && options.mRealTime) { scprintf("ERROR: There must be a -u and/or a -t options, or -N for nonrealtime.\n"); Usage(); } if (options.mNumInputBusChannels + options.mNumOutputBusChannels > options.mNumAudioBusChannels) { scprintf("ERROR: number of audio bus channels < inputs + outputs.\n"); Usage(); } struct World *world = World_New(&options); if (!world) return 1; if (!options.mRealTime) { #ifdef NO_LIBSNDFILE return 1; #else int exitCode = 0; try { World_NonRealTimeSynthesis(world, &options); } catch (std::exception& exc) { scprintf("%s\n", exc.what()); exitCode = 1; } return exitCode; #endif } if (udpPortNum >= 0) { if (!World_OpenUDP(world, udpPortNum)) { World_Cleanup(world); return 1; } } if (tcpPortNum >= 0) { if (!World_OpenTCP(world, tcpPortNum, options.mMaxLogins, 8)) { World_Cleanup(world); return 1; } } if(options.mVerbosity >=0){ #ifdef NDEBUG scprintf("SuperCollider 3 server ready.\n"); #else scprintf("SuperCollider 3 server ready (debug build).\n"); #endif } fflush(stdout); World_WaitForQuit(world); #ifdef _WIN32 // clean up winsock WSACleanup(); #ifdef SC_WIN32_STATIC_PTHREADS // clean up statically linked pthreads pthread_win32_process_detach_np(); #endif // SC_WIN32_STATIC_PTHREADS #endif // _WIN32 return 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; }