diff projects/d-box/main.cpp @ 5:09f03ac40fcc

API improvements and cleanups. Now all common audio command-line options can be parsed automatically.
author andrewm
date Sat, 08 Nov 2014 16:16:55 +0100
parents 8a575ba3ab52
children 901d205d1a3c
line wrap: on
line diff
--- a/projects/d-box/main.cpp	Thu Nov 06 19:02:48 2014 +0000
+++ b/projects/d-box/main.cpp	Sat Nov 08 16:16:55 2014 +0100
@@ -262,7 +262,7 @@
 }
 
 
-void parseArguments(arg_data args)
+void parseArguments(arg_data args, RTAudioSettings *settings)
 {
 	// Default filename;
 	gPartialFilename = strdup("D-Box_sound_250_60_40_h88_2.txt");
@@ -271,12 +271,10 @@
 	struct option long_option[] =
 	{
 		{"help", 0, NULL, 'h'},
-		{"period", 1, NULL, 'p'},
-		{"verbose", 1, NULL, 'v'},
 		{"audioin", 1, NULL, 'i'},
 		{"file", 1, NULL, 'f'},
 		{"keyboard", 1, NULL, 'k'},
-		{"audio-test", 0, NULL, 'A'},
+		{"audio-test", 0, NULL, 'T'},
 		{"new-sensors", 0, NULL, 'S'},
 		{"sensor0", 1, NULL, 'Q'},
 		{"sensor1", 1, NULL, 'R'},
@@ -290,22 +288,18 @@
 	int morehelp = 0;
 	int tmp = -1;
 
+	BeagleRT_defaultSettings(settings);
+
 	while (1)
 	{
 		int c;
-		if ((c = getopt_long(args.argc, args.argv, "hp:vf:ki:sAQ:R:Sl:u:o:n:g:", long_option, NULL)) < 0)
+		if ((c = BeagleRT_getopt_long(args.argc, args.argv, "hf:ki:sTQ:R:Sl:u:o:n:g:", long_option, settings)) < 0)
 				break;
 		switch (c)
 		{
 		case 'h':
 				morehelp++;
 				break;
-		case 'p':
-				gPeriodSize = atoi(optarg);
-				break;
-		case 'v':
-				gVerbose = 1;
-				break;
 		case 'f':
 				free(gPartialFilename);
 				gPartialFilename = strdup(optarg);
@@ -319,7 +313,7 @@
 		case 's':
 				forceSensors = true;
 				break;
-		case 'A':
+		case 'T':
 				useAudioTest = true;
 				break;
 		case 'S':
@@ -360,10 +354,14 @@
 				break;
 		}
 	}
+
+	gPeriodSize = settings->periodSize;
+	gVerbose = settings->verbose;
 }
 
 int main(int argc, char *argv[])
 {
+	RTAudioSettings settings;	// Standard audio settings
 	RT_TASK rtSensorThread;
 	const char rtSensorThreadName[] = "dbox-sensor";
 	int oscBankHopSize;
@@ -371,7 +369,7 @@
 	// Parse command-line arguments
 	args.argc = argc;
 	args.argv = argv;
-	parseArguments(args);
+	parseArguments(args, &settings);
 
 	setVerboseLevel(gVerbose);
 	if(gVerbose == 1 && useAudioTest)
@@ -384,7 +382,7 @@
 	oscBankHopSize = gOscBanks[gCurrentOscBank]->getHopSize()/gOscBanks[gCurrentOscBank]->getMinSpeed();
 
 	// Initialise the audio device
-	if(initAudio(gPeriodSize, 1, &oscBankHopSize) != 0)
+	if(BeagleRT_initAudio(&settings, &oscBankHopSize) != 0)
 		return -1;
 
 	// Initialise the status LED
@@ -405,7 +403,7 @@
 	if(gVerbose == 1)
 		cout << "main() : creating audio thread" << endl;
 
-	if(startAudio()) {
+	if(BeagleRT_startAudio()) {
 		cout << "Error: unable to start real-time audio" << endl;
 		return -1;
 	}
@@ -465,12 +463,12 @@
 		usleep(100000);
 	}
 
-	stopAudio();
+	BeagleRT_stopAudio();
 
 	if(!useAudioTest)
 		rt_task_join(&rtSensorThread);
 
-	cleanupAudio();
+	BeagleRT_cleanupAudio();
 
 	pthread_join( keyboardThread, NULL);
 	pthread_join( logThread, NULL);