[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Sc-devel] scsynth -L option



Hello,

as mentioned in my previous mail, the latency for port audio streams should be setable at startup. I propose a -L switch for this, the patch below implements this in scsynth_main, World etc..

Let me know what you think. It should not effect other platforms (the #ifdefs are for PORTAUDIO rather than SC_WIN32). Should this go into PsyCollider 3.2 final?

Chris

Index: build/SCClassLibrary/Common/Control/Server.sc
===================================================================
--- build/SCClassLibrary/Common/Control/Server.sc	(revision 7351)
+++ build/SCClassLibrary/Common/Control/Server.sc	(working copy)
@@ -26,6 +26,7 @@
 	var <>outputStreamsEnabled;
 
 	var <>device = nil;
+	var <>latency = nil;
 	
 	var <>blockAllocClass;
 	
@@ -109,6 +110,10 @@
 		if (outputStreamsEnabled.notNil, {
 			o = o ++ " -O " ++ outputStreamsEnabled ;
 		});
+		// exclusive to Port Audio builds
+		if (latency.notNil, {
+			o = o ++ " -L \"" ++ latency ++ "\"" ;
+		});
 		if (device.notNil, {
 			o = o ++ " -H \"" ++ device ++ "\"" ;
 		});
Index: Headers/plugin_interface/SC_WorldOptions.h
===================================================================
--- Headers/plugin_interface/SC_WorldOptions.h	(revision 7351)
+++ Headers/plugin_interface/SC_WorldOptions.h	(working copy)
@@ -70,6 +70,10 @@
     CFStringRef mServerPortName;
     CFStringRef mReplyPortName;
 #endif
+#if SC_AUDIO_API == SC_AUDIO_API_PORTAUDIO
+	float mLatency;
+#endif
+
 	const char *mDeviceName;
 	
 	int mVerbosity;
Index: Headers/server/SC_HiddenWorld.h
===================================================================
--- Headers/server/SC_HiddenWorld.h	(revision 7351)
+++ Headers/server/SC_HiddenWorld.h	(working copy)
@@ -102,6 +102,9 @@
 	const char* mInputStreamsEnabled;
 	const char* mOutputStreamsEnabled;
 #endif
+#if SC_AUDIO_API == SC_AUDIO_API_PORTAUDIO
+	float mLatency;
+#endif
 	const char *mDeviceName;
 };
 
Index: Source/server/SC_CoreAudio.cpp
===================================================================
--- Source/server/SC_CoreAudio.cpp	(revision 7353)
+++ Source/server/SC_CoreAudio.cpp	(working copy)
@@ -1755,16 +1755,24 @@
 		inStreamParams.device = mDeviceInOut[0];
 		inStreamParams.channelCount = mInputChannelCount;
 		inStreamParams.sampleFormat = fmt;
-		inStreamParams.suggestedLatency = Pa_GetDeviceInfo( mDeviceInOut[0] )->defaultLowInputLatency; //$$$todo : allow user to choose latency instead of this
-		scprintf("suggestedLatency used: %.3f\n", Pa_GetDeviceInfo( mDeviceInOut[0] )->defaultLowInputLatency);
+		if (mWorld->hw->mLatency) 
+			inStreamParams.suggestedLatency = mWorld->hw->mLatency;
+		else
+			inStreamParams.suggestedLatency = Pa_GetDeviceInfo( mDeviceInOut[0] )->defaultLowInputLatency;
 		inStreamParams.hostApiSpecificStreamInfo = NULL;
 
 		PaStreamParameters outStreamParams;
 		outStreamParams.device = mDeviceInOut[1];
 		outStreamParams.channelCount = mOutputChannelCount;
 		outStreamParams.sampleFormat = fmt;
-		outStreamParams.suggestedLatency = Pa_GetDeviceInfo( mDeviceInOut[1] )->defaultLowOutputLatency; //$$$todo : allow user to choose latency instead of this
+		if (mWorld->hw->mLatency)
+			outStreamParams.suggestedLatency = mWorld->hw->mLatency;
+		else
+			outStreamParams.suggestedLatency = Pa_GetDeviceInfo( mDeviceInOut[1] )->defaultLowOutputLatency;
 		outStreamParams.hostApiSpecificStreamInfo = NULL;
+		scprintf("PortAudio OutStream latency used: %.3f\n", outStreamParams.suggestedLatency);
 
 		paerror = Pa_OpenStream(&mStream, &inStreamParams, &outStreamParams, *outSampleRate, *outNumSamples, paNoFlag, SC_PortAudioStreamCallback, this );
 		if( paerror != paNoError )
Index: Source/server/SC_World.cpp
===================================================================
--- Source/server/SC_World.cpp	(revision 7351)
+++ Source/server/SC_World.cpp	(working copy)
@@ -364,6 +364,9 @@
 		world->hw->mInputStreamsEnabled = inOptions->mInputStreamsEnabled;
 		world->hw->mOutputStreamsEnabled = inOptions->mOutputStreamsEnabled;
 #endif 
+#if SC_AUDIO_API == SC_AUDIO_API_PORTAUDIO
+		world->hw->mLatency = inOptions->mLatency;
+#endif
 		world->hw->mDeviceName = inOptions->mDeviceName;
 		hw->mMaxWireBufs = inOptions->mMaxWireBufs;
 		hw->mWireBufSpace = 0;
Index: Source/server/scsynth_main.cpp
===================================================================
--- Source/server/scsynth_main.cpp	(revision 7351)
+++ Source/server/scsynth_main.cpp	(working copy)
@@ -82,6 +82,10 @@
 		"   -O <output-streams-enabled>\n"
         "   -M <server-mach-port-name> <reply-mach-port-name>\n"
 #endif 
+#if SC_AUDIO_API == SC_AUDIO_API_PORTAUDIO
+		"	-L <input/output port audio stream latency>\n"
+		"			if omitted the suggested latency of the device is used\n"
+#endif
         "   -H <hardware-device-name>\n"
         "   -v <verbosity>\n"
         "          0 is normal behaviour\n"
@@ -142,7 +146,7 @@
 	WorldOptions options = kDefaultWorldOptions;
 	
 	for (int i=1; i<argc;) {
-		if (argv[i][0] != '-' || argv[i][1] == 0 || strchr("utaioczblndpmwZrNSDIOMHvR", argv[i][1]) == 0) {
+		if (argv[i][0] != '-' || argv[i][1] == 0 || strchr("utaioczblndpmwZrNSDIOMHvRL", argv[i][1]) == 0) {
 			scprintf("ERROR: Invalid option %s\n", argv[i]);
 			Usage();
 		}
@@ -247,6 +251,11 @@
                 options.mReplyPortName = CFStringCreateWithCStringNoCopy(NULL, argv[j + 2], kCFStringEncodingUTF8, kCFAllocatorNull);
                 break;
 #endif 
+#if SC_AUDIO_API == SC_AUDIO_API_PORTAUDIO
+			case 'L' :
+				checkNumArgs(2);
+				options.mLatency = atof(argv[j+1]);
+#endif
 			case 'H' :
 				checkNumArgs(2);
 				options.mDeviceName = argv[j+1];