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