comparison examples/07-DataLogging/write-file/main.cpp @ 501:6962184f8567 prerelease

Additional name changes to doxygen example title.
author Robert Jack <robert.h.jack@gmail.com>
date Wed, 22 Jun 2016 00:34:07 +0100
parents
children
comparison
equal deleted inserted replaced
500:b935f890e512 501:6962184f8567
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
25 #include <unistd.h>
26 #include <iostream>
27 #include <cstdlib>
28 #include <libgen.h>
29 #include <signal.h>
30 #include <getopt.h>
31 #include <Bela.h>
32
33 using namespace std;
34
35 // Handle Ctrl-C by requesting that the audio rendering stop
36 void interrupt_handler(int var)
37 {
38 gShouldStop = true;
39 }
40
41 // Print usage information
42 void usage(const char * processName)
43 {
44 cerr << "Usage: " << processName << " [options]" << endl;
45
46 Bela_usage();
47
48 cerr << " --frequency [-f] frequency: Set the frequency of the oscillator\n";
49 cerr << " --help [-h]: Print this menu\n";
50 }
51
52 int main(int argc, char *argv[])
53 {
54 BelaInitSettings settings; // Standard audio settings
55 float frequency = 440.0; // Frequency of oscillator
56
57 struct option customOptions[] =
58 {
59 {"help", 0, NULL, 'h'},
60 {"frequency", 1, NULL, 'f'},
61 {NULL, 0, NULL, 0}
62 };
63
64 // Set default settings
65 Bela_defaultSettings(&settings);
66
67 // Parse command-line arguments
68 while (1) {
69 int c;
70 if ((c = Bela_getopt_long(argc, argv, "hf:", customOptions, &settings)) < 0)
71 break;
72 switch (c) {
73 case 'h':
74 usage(basename(argv[0]));
75 exit(0);
76 case 'f':
77 frequency = atof(optarg);
78 break;
79 case '?':
80 default:
81 usage(basename(argv[0]));
82 exit(1);
83 }
84 }
85
86 // Initialise the PRU audio device
87 if(Bela_initAudio(&settings, &frequency) != 0) {
88 cout << "Error: unable to initialise audio" << endl;
89 return -1;
90 }
91
92 // Start the audio device running
93 if(Bela_startAudio()) {
94 cout << "Error: unable to start real-time audio" << endl;
95 return -1;
96 }
97
98 // Set up interrupt handler to catch Control-C and SIGTERM
99 signal(SIGINT, interrupt_handler);
100 signal(SIGTERM, interrupt_handler);
101
102 // Run until told to stop
103 while(!gShouldStop) {
104 usleep(100000);
105 }
106
107 // Stop the audio device
108 Bela_stopAudio();
109
110 // Clean up any resources allocated for audio
111 Bela_cleanupAudio();
112
113 // All done!
114 return 0;
115 }