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