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@64
|
35 BeagleRTInitSettings settings; // Standard audio settings
|
giuliomoro@64
|
36
|
giuliomoro@64
|
37 struct option customOptions[] =
|
giuliomoro@64
|
38 {
|
giuliomoro@64
|
39 {"help", 0, NULL, 'h'},
|
giuliomoro@64
|
40 {NULL, 0, NULL, 0}
|
giuliomoro@64
|
41 };
|
giuliomoro@64
|
42
|
giuliomoro@64
|
43 // Set default settings
|
giuliomoro@64
|
44 BeagleRT_defaultSettings(&settings);
|
giuliomoro@64
|
45
|
giuliomoro@64
|
46 // Parse command-line arguments
|
giuliomoro@64
|
47 while (1) {
|
giuliomoro@64
|
48 int c;
|
giuliomoro@64
|
49 if ((c = BeagleRT_getopt_long(argc, argv, "h", customOptions, &settings)) < 0)
|
giuliomoro@64
|
50 break;
|
giuliomoro@64
|
51 switch (c) {
|
giuliomoro@64
|
52 case 'h':
|
giuliomoro@64
|
53 usage(basename(argv[0]));
|
giuliomoro@64
|
54 exit(0);
|
giuliomoro@64
|
55 case '?':
|
giuliomoro@64
|
56 default:
|
giuliomoro@64
|
57 usage(basename(argv[0]));
|
giuliomoro@64
|
58 exit(1);
|
giuliomoro@64
|
59 }
|
giuliomoro@64
|
60 }
|
giuliomoro@64
|
61
|
giuliomoro@64
|
62 // Initialise the PRU audio device
|
giuliomoro@64
|
63 if(BeagleRT_initAudio(&settings, 0) != 0) {
|
giuliomoro@64
|
64 cout << "Error: unable to initialise audio" << endl;
|
giuliomoro@64
|
65 return -1;
|
giuliomoro@64
|
66 }
|
giuliomoro@64
|
67
|
giuliomoro@64
|
68 // Start the audio device running
|
giuliomoro@64
|
69 if(BeagleRT_startAudio()) {
|
giuliomoro@64
|
70 cout << "Error: unable to start real-time audio" << endl;
|
giuliomoro@64
|
71 return -1;
|
giuliomoro@64
|
72 }
|
giuliomoro@64
|
73
|
giuliomoro@64
|
74 // Set up interrupt handler to catch Control-C and SIGTERM
|
giuliomoro@64
|
75 signal(SIGINT, interrupt_handler);
|
giuliomoro@64
|
76 signal(SIGTERM, interrupt_handler);
|
giuliomoro@64
|
77
|
giuliomoro@64
|
78 // Run until told to stop
|
giuliomoro@64
|
79 while(!gShouldStop) {
|
giuliomoro@64
|
80 usleep(100000);
|
giuliomoro@64
|
81 }
|
giuliomoro@64
|
82
|
giuliomoro@64
|
83 // Stop the audio device
|
giuliomoro@64
|
84 BeagleRT_stopAudio();
|
giuliomoro@64
|
85
|
giuliomoro@64
|
86 // Clean up any resources allocated for audio
|
giuliomoro@64
|
87 BeagleRT_cleanupAudio();
|
giuliomoro@64
|
88
|
giuliomoro@64
|
89 // All done!
|
giuliomoro@64
|
90 return 0;
|
giuliomoro@64
|
91 }
|