comparison examples/05-Communication/basic-network/main.cpp @ 464:8fcfbfb32aa0 prerelease

Examples reorder with subdirectories. Added header to each project. Moved Doxygen to bottom of render.cpp.
author Robert Jack <robert.h.jack@gmail.com>
date Mon, 20 Jun 2016 16:20:38 +0100
parents
children
comparison
equal deleted inserted replaced
463:c47709e8b5c9 464:8fcfbfb32aa0
1 /*
2 ____ _____ _ _
3 | __ )| ____| | / \
4 | _ \| _| | | / _ \
5 | |_) | |___| |___ / ___ \
6 |____/|_____|_____/_/ \_\
7
8 The platform for ultra-low latency audio and sensor processing
9
10 http://bela.io
11
12 A project of the Augmented Instruments Laboratory within the
13 Centre for Digital Music at Queen Mary University of London.
14 http://www.eecs.qmul.ac.uk/~andrewm
15
16 (c) 2016 Augmented Instruments Laboratory: Andrew McPherson,
17 Astrid Bin, Liam Donovan, Christian Heinrichs, Robert Jack,
18 Giulio Moro, Laurel Pardue, Victor Zappi. All rights reserved.
19
20 The Bela software is distributed under the GNU Lesser General Public License
21 (LGPL 3.0), available here: https://www.gnu.org/licenses/lgpl-3.0.txt
22 */
23
24 #include <iostream>
25 #include <cstdlib>
26 #include <libgen.h>
27 #include <signal.h>
28 #include <getopt.h>
29 #include <unistd.h>
30 #include <Bela.h>
31
32 using namespace std;
33
34 // Handle Ctrl-C by requesting that the audio rendering stop
35 void interrupt_handler(int var)
36 {
37 gShouldStop = true;
38 }
39
40 // Print usage information
41 void usage(const char * processName)
42 {
43 cerr << "Usage: " << processName << " [options]" << endl;
44
45 Bela_usage();
46
47 cerr << " --frequency [-f] frequency: Set the frequency of the oscillator\n";
48 cerr << " --help [-h]: Print this menu\n";
49 }
50
51 int main(int argc, char *argv[])
52 {
53 BelaInitSettings settings; // Standard audio settings
54 float frequency = 440.0; // Frequency of oscillator
55
56 struct option customOptions[] =
57 {
58 {"help", 0, NULL, 'h'},
59 {"frequency", 1, NULL, 'f'},
60 {NULL, 0, NULL, 0}
61 };
62
63 // Set default settings
64 Bela_defaultSettings(&settings);
65
66 // Parse command-line arguments
67 while (1) {
68 int c;
69 if ((c = Bela_getopt_long(argc, argv, "hf:", customOptions, &settings)) < 0)
70 break;
71 switch (c) {
72 case 'h':
73 usage(basename(argv[0]));
74 exit(0);
75 case 'f':
76 frequency = atof(optarg);
77 break;
78 case '?':
79 default:
80 usage(basename(argv[0]));
81 exit(1);
82 }
83 }
84
85 // Initialise the PRU audio device
86 if(Bela_initAudio(&settings, &frequency) != 0) {
87 cout << "Error: unable to initialise audio" << endl;
88 return -1;
89 }
90
91 // Start the audio device running
92 if(Bela_startAudio()) {
93 cout << "Error: unable to start real-time audio" << endl;
94 return -1;
95 }
96
97 // Set up interrupt handler to catch Control-C and SIGTERM
98 signal(SIGINT, interrupt_handler);
99 signal(SIGTERM, interrupt_handler);
100
101 // Run until told to stop
102 while(!gShouldStop) {
103 usleep(100000);
104 }
105
106 // Stop the audio device
107 Bela_stopAudio();
108
109 // Clean up any resources allocated for audio
110 Bela_cleanupAudio();
111
112 // All done!
113 return 0;
114 }