예제 #1
0
void SCProcess::startUp(WorldOptions options, CFStringRef pluginsPath,  CFStringRef synthdefsPath,  int preferredPort) {

    pthread_t scThread;
    char stringBuffer[PATH_MAX] ;
    OSCMessages messages;

    CFStringGetCString(pluginsPath, stringBuffer, sizeof(stringBuffer), kCFStringEncodingUTF8);
    setenv("SC_PLUGIN_PATH", stringBuffer, 1);
    CFStringGetCString(synthdefsPath, stringBuffer, sizeof(stringBuffer), kCFStringEncodingUTF8);
    setenv("SC_SYNTHDEF_PATH", stringBuffer, 1);
    this->portNum = findNextFreeUdpPort(preferredPort);
    world = World_New(&options);
    //world->mDumpOSC=2;
    if (world) {
        if (this->portNum >= 0) World_OpenUDP(world, this->portNum);
        pthread_create (&scThread, NULL, scThreadFunc, (void*)world);
    }
    if (world->mRunning) {
        small_scpacket packet = messages.initTreeMessage();
        World_SendPacket(world, 16, (char*)packet.buf, null_reply_func);
    }
}
extern "C" int scsynth_android_start(JNIEnv* env, jobject obj, 
						jint srate, jint hwBufSize, jint numInChans, jint numOutChans, jint shortsPerSample,
						jstring pluginsPath, jstring synthDefsPath){

	jboolean isCopy;
	bufflen = shortsPerSample*numOutChans*hwBufSize;
	buff = (short*) calloc(bufflen,sizeof(short));
	const char* pluginsPath_c   = env->GetStringUTFChars(pluginsPath,   &isCopy);
	const char* synthDefsPath_c = env->GetStringUTFChars(synthDefsPath, &isCopy);
	__android_log_print(ANDROID_LOG_DEBUG, "libscsynth", "scsynth_android_start(%i, %i, %i, %i, %i, %s, %s)",
		(int)srate, (int)hwBufSize, (int)numInChans, (int)numOutChans, (int)shortsPerSample, pluginsPath_c, synthDefsPath_c);
    setenv("SC_PLUGIN_PATH",   pluginsPath_c,   1);
    setenv("SC_SYNTHDEF_PATH", synthDefsPath_c, 1);
    
    // DEBUG: Check that we can read the path
	DIR *dip;
	struct dirent *dit;
	if ((dip = opendir(pluginsPath_c)) == NULL){
		__android_log_print(ANDROID_LOG_DEBUG, "libscsynth", "Could not opendir(%s)\n", pluginsPath_c);
	}else{
		__android_log_print(ANDROID_LOG_DEBUG, "libscsynth", "OK, listing opendir(%s)\n", pluginsPath_c);
		while ((dit = readdir(dip)) != NULL){
			__android_log_print(ANDROID_LOG_DEBUG, "libscsynth", "Entry: %s\n", dit->d_name);
		}
		if (closedir(dip) == -1)
			__android_log_print(ANDROID_LOG_DEBUG, "libscsynth", "Could not closedir(%s)\n", pluginsPath_c);
	}

	env->ReleaseStringUTFChars(pluginsPath,   pluginsPath_c);
	env->ReleaseStringUTFChars(synthDefsPath, synthDefsPath_c);



	WorldOptions options = kDefaultWorldOptions;
	options.mPreferredSampleRate = srate;
	options.mPreferredHardwareBufferFrameSize = hwBufSize;
	options.mNumInputBusChannels  = numInChans;
	options.mNumOutputBusChannels = numOutChans;
	
	// Reduce things down a bit for lower-spec - these are all open for review
	options.mNumBuffers  = 512;
	options.mMaxGraphDefs = 512;
	options.mMaxWireBufs = 512;
	options.mNumAudioBusChannels = 32;
	options.mRealTimeMemorySize = 512;
	options.mNumRGens = 16;
	options.mLoadGraphDefs = 1;
	options.mVerbosity = 2; // TODO: reduce this back to zero for non-debug builds once dev't is stable
	options.mBufLength = 64; // was hwBufSize / numOutChans;
	
	
	// Similar to SCProcess:startup :
	pthread_t scThread;
	OSCMessages messages;
	
    world = World_New(&options);
    //world->mDumpOSC=2;
    if (world) {
        pthread_create (&scThread, NULL, scThreadFunc, (void*)world);
    }
    if (world->mRunning){
        small_scpacket packet = messages.initTreeMessage();
        World_SendPacket(world, 16, (char*)packet.buf, null_reply_func);
        return 0;
    }else{
    	return 1;
    }
}