giuliomoro@64
|
1 /*
|
giuliomoro@64
|
2 * default_main.cpp
|
giuliomoro@64
|
3 *
|
giuliomoro@64
|
4 * Created on: Oct 24, 2014
|
giuliomoro@64
|
5 * Author: parallels
|
giuliomoro@64
|
6 */
|
giuliomoro@64
|
7 #include <unistd.h>
|
giuliomoro@64
|
8 #include <iostream>
|
giuliomoro@64
|
9 #include <cstdlib>
|
giuliomoro@64
|
10 #include <libgen.h>
|
giuliomoro@64
|
11 #include <signal.h>
|
giuliomoro@64
|
12 #include <getopt.h>
|
giuliomoro@64
|
13 #include "../include/BeagleRT.h"
|
giuliomoro@64
|
14
|
giuliomoro@64
|
15 using namespace std;
|
giuliomoro@64
|
16
|
giuliomoro@64
|
17 // Handle Ctrl-C by requesting that the audio rendering stop
|
giuliomoro@64
|
18 void interrupt_handler(int var)
|
giuliomoro@64
|
19 {
|
giuliomoro@64
|
20 gShouldStop = true;
|
giuliomoro@64
|
21 }
|
giuliomoro@64
|
22
|
giuliomoro@64
|
23 // Print usage information
|
giuliomoro@64
|
24 void usage(const char * processName)
|
giuliomoro@64
|
25 {
|
giuliomoro@64
|
26 cerr << "Usage: " << processName << " [options]" << endl;
|
giuliomoro@64
|
27
|
giuliomoro@64
|
28 BeagleRT_usage();
|
giuliomoro@64
|
29
|
giuliomoro@64
|
30 cerr << " --help [-h]: Print this menu\n";
|
giuliomoro@64
|
31 }
|
giuliomoro@64
|
32
|
giuliomoro@64
|
33 int main(int argc, char *argv[])
|
giuliomoro@64
|
34 {
|
giuliomoro@175
|
35 printf("in main\n");
|
giuliomoro@175
|
36 dumpAuxTasks();
|
giuliomoro@64
|
37 BeagleRTInitSettings settings; // Standard audio settings
|
giuliomoro@64
|
38
|
giuliomoro@64
|
39 struct option customOptions[] =
|
giuliomoro@64
|
40 {
|
giuliomoro@64
|
41 {"help", 0, NULL, 'h'},
|
giuliomoro@64
|
42 {NULL, 0, NULL, 0}
|
giuliomoro@64
|
43 };
|
giuliomoro@64
|
44
|
giuliomoro@64
|
45 // Set default settings
|
giuliomoro@64
|
46 BeagleRT_defaultSettings(&settings);
|
giuliomoro@64
|
47
|
giuliomoro@64
|
48 // Parse command-line arguments
|
giuliomoro@64
|
49 while (1) {
|
giuliomoro@64
|
50 int c;
|
giuliomoro@64
|
51 if ((c = BeagleRT_getopt_long(argc, argv, "h", customOptions, &settings)) < 0)
|
giuliomoro@64
|
52 break;
|
giuliomoro@64
|
53 switch (c) {
|
giuliomoro@64
|
54 case 'h':
|
giuliomoro@64
|
55 usage(basename(argv[0]));
|
giuliomoro@64
|
56 exit(0);
|
giuliomoro@64
|
57 case '?':
|
giuliomoro@64
|
58 default:
|
giuliomoro@64
|
59 usage(basename(argv[0]));
|
giuliomoro@64
|
60 exit(1);
|
giuliomoro@64
|
61 }
|
giuliomoro@64
|
62 }
|
giuliomoro@64
|
63
|
giuliomoro@64
|
64 // Initialise the PRU audio device
|
giuliomoro@64
|
65 if(BeagleRT_initAudio(&settings, 0) != 0) {
|
giuliomoro@64
|
66 cout << "Error: unable to initialise audio" << endl;
|
giuliomoro@64
|
67 return -1;
|
giuliomoro@64
|
68 }
|
giuliomoro@64
|
69
|
giuliomoro@64
|
70 // Start the audio device running
|
giuliomoro@64
|
71 if(BeagleRT_startAudio()) {
|
giuliomoro@64
|
72 cout << "Error: unable to start real-time audio" << endl;
|
giuliomoro@64
|
73 return -1;
|
giuliomoro@64
|
74 }
|
giuliomoro@64
|
75
|
giuliomoro@64
|
76 // Set up interrupt handler to catch Control-C and SIGTERM
|
giuliomoro@64
|
77 signal(SIGINT, interrupt_handler);
|
giuliomoro@64
|
78 signal(SIGTERM, interrupt_handler);
|
giuliomoro@64
|
79
|
giuliomoro@64
|
80 // Run until told to stop
|
giuliomoro@64
|
81 while(!gShouldStop) {
|
giuliomoro@64
|
82 usleep(100000);
|
giuliomoro@64
|
83 }
|
giuliomoro@64
|
84
|
giuliomoro@64
|
85 // Stop the audio device
|
giuliomoro@64
|
86 BeagleRT_stopAudio();
|
giuliomoro@64
|
87
|
giuliomoro@64
|
88 // Clean up any resources allocated for audio
|
giuliomoro@64
|
89 BeagleRT_cleanupAudio();
|
giuliomoro@64
|
90
|
giuliomoro@64
|
91 // All done!
|
giuliomoro@64
|
92 return 0;
|
giuliomoro@64
|
93 }
|