Ejemplo n.º 1
0
void PlayLoop (MusicPlayer &player, AUGraph &graph, MusicTimeStamp sequenceLength, bool shouldPrint, bool waitAtEnd)
{
	OSStatus result;
	int waitCounter = 0;
	while (1) {
		usleep (2 * 1000 * 1000);
		
		if (didOverload) {
			printf ("* * * * * %lu Overloads detected on device playing audio\n", (unsigned long)didOverload);
			overloadTime = CAHostTimeBase::ConvertToNanos (overloadTime - startRunningTime);
			printf ("\tSeconds after start = %lf\n", double(overloadTime / 1000000000.));
			didOverload = 0;
		}

		if (waitAtEnd && ++waitCounter > 10) break;
		
		MusicTimeStamp time;
		FailIf ((result = MusicPlayerGetTime (player, &time)), fail, "MusicPlayerGetTime");
					
		if (shouldPrint) {
			printf ("current time: %6.2f beats", time);
			if (graph) {
				Float32 load;
				FailIf ((result = AUGraphGetCPULoad(graph, &load)), fail, "AUGraphGetCPULoad");
				printf (", CPU load = %.2f%%\n", (load * 100.));
			} else
				printf ("\n"); //no cpu load on AUGraph - its not running - if just playing out to MIDI
		}
		
		if (time >= sequenceLength)
			break;
	}
	
	return;
fail:
	if (shouldPrint) printf ("Error = %ld\n", (long)result);
	exit(1);
}
JNIEXPORT jint JNICALL Java_com_apple_audio_toolbox_AUGraph_AUGraphGetCPULoad
  (JNIEnv *, jclass, jint inGraph, jint outCPULoad)
{
	return (jint)AUGraphGetCPULoad((AUGraph)inGraph, (Float32 *)outCPULoad);
}