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

[sc-dev] SF.net SVN: supercollider: [7358] trunk/Source/server/SC_CoreAudio.cpp



Revision: 7358
          http://svn.sourceforge.net/supercollider/?rev=7358&view=rev
Author:   joshpar
Date:     2008-02-19 14:47:22 -0800 (Tue, 19 Feb 2008)

Log Message:
-----------
revert to old SC_CoreAudio for 3.2 packaging

Modified Paths:
--------------
    trunk/Source/server/SC_CoreAudio.cpp

Modified: trunk/Source/server/SC_CoreAudio.cpp
===================================================================
--- trunk/Source/server/SC_CoreAudio.cpp	2008-02-19 22:18:07 UTC (rev 7357)
+++ trunk/Source/server/SC_CoreAudio.cpp	2008-02-19 22:47:22 UTC (rev 7358)
@@ -155,14 +155,6 @@
 	return GetCurrentOSCTime();
 }
 
-int64 PaStreamTimeToOSC(PaTime pa_time) {
-	uint64 s, f;
-	s = (uint64)pa_time;
-	f = (uint64)((pa_time - s) * 1000000 * kMicrosToOSCunits);
-
-	return (s << 32) + f;
-}
-
 void initializeScheduler()
 {
 	gOSCoffset = GetCurrentOSCTime(); 
@@ -206,7 +198,7 @@
 
 int PerformOSCMessage(World *inWorld, int inSize, char *inData, ReplyAddress *inReply)
 {
-	// scprintf("->PerformOSCMessage %d\n", inData[0]);
+	//scprintf("->PerformOSCMessage %d\n", inData[0]);
 	SC_LibCmd *cmdObj;
 	int cmdNameLen;
 	if (inData[0] == 0) {
@@ -274,6 +266,7 @@
 	
 		// in real time engine, schedule the packet
 		int64 time = OSCtime(packet->mData + 8);
+
 		if (time == 0 || time == 1) {
 			PerformOSCBundle(world, packet);
 		} else {
@@ -284,11 +277,6 @@
 				
 				//ReportLateness(packet->mReply, seconds)
 			}
-			// DEBUG
-			// else	
-				//scprintf("scheduled in %.6f at time %.6f\n", 
-				//	(time-driver->mOSCbuftime)*kOSCtoSecs, 
-				//	(time-gStartupOSCTime)*kOSCtoSecs);
 			
 			SC_ScheduledEvent event(world, time, packet);
 			driver->AddEvent(event);
@@ -1573,16 +1561,15 @@
             PaStreamCallbackFlags statusFlags )
 {
     World *world = mWorld;
-    (void) frameCount, timeInfo, statusFlags; // suppress unused parameter warnings
 
+    (void) frameCount, timeInfo, statusFlags; // suppress unused parameter warnings
+    
 	try {
-		// synchronise against the output buffer - timeInfo->currentTime is 0.0 bug in PA?
-		if (mPaStreamStartupTime==0 && mPaStreamStartupTimeOSC==0) {
-			mPaStreamStartupTimeOSC = GetCurrentOSCTime();
-			mPaStreamStartupTime = timeInfo->outputBufferDacTime;
-		}
-		mOSCbuftime = PaStreamTimeToOSC(timeInfo->outputBufferDacTime - mPaStreamStartupTime) + mPaStreamStartupTimeOSC;
+		int64 oscTime = GetCurrentOSCTime();
+		int64 temptime = oscTime;
 		
+		mOSCbuftime = oscTime;
+		
 		mFromEngine.Free();
 		mToEngine.Perform();
 		mOscPacketsToEngine.Perform();
@@ -1591,7 +1578,7 @@
 		int numOutputs = mOutputChannelCount;
 		const float **inBuffers = (const float**)input;
 		float **outBuffers = (float**)output;
-		
+
 		int numSamples = NumSamplesPerCallback();
 		int bufFrames = mWorld->mBufLength;
 		int numBufs = numSamples / bufFrames;
@@ -1606,7 +1593,6 @@
 
 		int bufFramePos = 0;
 
-		int64 oscTime = mOSCbuftime;
 		int64 oscInc = mOSCincrement;
 		double oscToSamples = mOSCtoSamples;
 	
@@ -1626,30 +1612,17 @@
 				*tch++ = bufCounter;
 			}
 
+
 			// run engine
+
 			int64 schedTime;
 			int64 nextTime = oscTime + oscInc;
-			// DEBUG
-			/*
-			if (mScheduler.Ready(nextTime)) {
-				double diff = (mScheduler.NextTime() - mOSCbuftime)*kOSCtoSecs; 
-				scprintf("rdy %.6f %.6f %.6f %.6f \n", (mScheduler.NextTime()-gStartupOSCTime) * kOSCtoSecs, (mOSCbuftime-gStartupOSCTime)*kOSCtoSecs, diff, (nextTime-gStartupOSCTime)*kOSCtoSecs);
-			}
-			*/
 			while ((schedTime = mScheduler.NextTime()) <= nextTime) {
-				float diffTime = (float)(schedTime - oscTime) * oscToSamples + 0.5;
-				float diffTimeFloor = floor(diffTime);
-				world->mSampleOffset = (int)diffTimeFloor;
-				world->mSubsampleOffset = diffTime - diffTimeFloor;
-				
-				if (world->mSampleOffset < 0) world->mSampleOffset = 0;
-				else if (world->mSampleOffset >= world->mBufLength) world->mSampleOffset = world->mBufLength-1;
-				
+				world->mSampleOffset = (int)((double)(schedTime - oscTime) * oscToSamples);
 				SC_ScheduledEvent event = mScheduler.Remove();
 				event.Perform();
+				world->mSampleOffset = 0;
 			}
-			world->mSampleOffset = 0;
-			world->mSubsampleOffset = 0.f;
 
 			World_Run(world);
 
@@ -1666,7 +1639,7 @@
 			}
 
 			// update buffer time
-			oscTime = mOSCbuftime = nextTime;
+			mOSCbuftime = nextTime;
 		}
 	} catch (std::exception& exc) {
 		scprintf("SC_PortAudioDriver: exception in real time: %s\n", exc.what());
@@ -1756,7 +1729,6 @@
 		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);
 		inStreamParams.hostApiSpecificStreamInfo = NULL;
 
 		PaStreamParameters outStreamParams;
@@ -1789,13 +1761,6 @@
     if( paerror != paNoError )
         PRINT_PORTAUDIO_ERROR( Pa_StartStream, paerror );
 
-	// sync times
-	mPaStreamStartupTimeOSC = 0;
-	mPaStreamStartupTime = 0;
-	// it would be better to do the sync here, but the timeInfo in the callback is incomplete
-	//mPaStreamStartupTimeOSC = GetCurrentOSCTime();
-	//mPaStreamStartupTime = Pa_GetStreamTime(mStream);
-
 	return paerror == paNoError;
 }
 
@@ -1990,4 +1955,4 @@
 {
 }
 
-#endif // SC_AUDIO_API_INNERSC_VST
+#endif // SC_AUDIO_API_INNERSC_VST
\ No newline at end of file


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.