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