Mercurial > hg > beaglert
comparison examples/analogDigitalDemo/main.cpp @ 300:dbeed520b014 prerelease
Renamed projects to examples
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Fri, 27 May 2016 13:58:20 +0100 |
parents | projects/analogDigitalDemo/main.cpp@3c3a1357657d |
children | e4392164b458 |
comparison
equal
deleted
inserted
replaced
297:a3d83ebdf49b | 300:dbeed520b014 |
---|---|
1 /* | |
2 * assignment1_crossover | |
3 * RTDSP 2015 | |
4 * | |
5 * First assignment for ECS732 RTDSP, to implement a 2-way audio crossover | |
6 * using the BeagleBone Black. | |
7 * | |
8 * Andrew McPherson and Victor Zappi | |
9 * Queen Mary, University of London | |
10 */ | |
11 | |
12 #include <iostream> | |
13 #include <cstdlib> | |
14 #include <libgen.h> | |
15 #include <signal.h> | |
16 #include <getopt.h> | |
17 #include <unistd.h> | |
18 #include <stdlib.h> | |
19 #include <fcntl.h> | |
20 | |
21 #include <BeagleRT.h> | |
22 | |
23 using namespace std; | |
24 | |
25 // Handle Ctrl-C by requesting that the audio rendering stop | |
26 void interrupt_handler(int var) | |
27 { | |
28 gShouldStop = true; | |
29 } | |
30 | |
31 // Print usage information | |
32 void usage(const char * processName) | |
33 { | |
34 cerr << "Usage: " << processName << " [options]" << endl; | |
35 | |
36 BeagleRT_usage(); | |
37 | |
38 cerr << " --help [-h]: Print this menu\n"; | |
39 } | |
40 | |
41 int main(int argc, char *argv[]) | |
42 { | |
43 BeagleRTInitSettings settings; // Standard audio settings | |
44 float frequency = 1000.0; // Frequency of crossover | |
45 | |
46 struct option customOptions[] = | |
47 { | |
48 {"help", 0, NULL, 'h'}, | |
49 {"frequency", 1, NULL, 'f'}, | |
50 {NULL, 0, NULL, 0} | |
51 }; | |
52 | |
53 // Set default settings | |
54 BeagleRT_defaultSettings(&settings); | |
55 | |
56 // Parse command-line arguments | |
57 while (1) { | |
58 int c; | |
59 if ((c = BeagleRT_getopt_long(argc, argv, "hf:", customOptions, &settings)) < 0) | |
60 break; | |
61 switch (c) { | |
62 case 'h': | |
63 usage(basename(argv[0])); | |
64 exit(0); | |
65 case 'f': | |
66 frequency = atof(optarg); | |
67 if(frequency < 20.0) | |
68 frequency = 20.0; | |
69 if(frequency > 5000.0) | |
70 frequency = 5000.0; | |
71 break; | |
72 case '?': | |
73 default: | |
74 usage(basename(argv[0])); | |
75 exit(1); | |
76 } | |
77 } | |
78 | |
79 // Initialise the PRU audio device | |
80 if(BeagleRT_initAudio(&settings, &frequency) != 0) { | |
81 cout << "Error: unable to initialise audio" << endl; | |
82 return -1; | |
83 } | |
84 | |
85 // Start the audio device running | |
86 if(BeagleRT_startAudio()) { | |
87 cout << "Error: unable to start real-time audio" << endl; | |
88 return -1; | |
89 } | |
90 | |
91 // Set up interrupt handler to catch Control-C | |
92 signal(SIGINT, interrupt_handler); | |
93 signal(SIGTERM, interrupt_handler); | |
94 | |
95 // Run until told to stop | |
96 while(!gShouldStop) { | |
97 usleep(100000); | |
98 } | |
99 | |
100 // Stop the audio device | |
101 BeagleRT_stopAudio(); | |
102 | |
103 // Clean up any resources allocated for audio | |
104 BeagleRT_cleanupAudio(); | |
105 | |
106 // All done! | |
107 return 0; | |
108 } |