comparison examples/basic_network/main.cpp @ 301:e4392164b458 prerelease

RENAMED BeagleRT to Bela AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA, scripts probably not working
author Giulio Moro <giuliomoro@yahoo.it>
date Fri, 27 May 2016 14:34:41 +0100
parents dbeed520b014
children
comparison
equal deleted inserted replaced
300:dbeed520b014 301:e4392164b458
9 #include <cstdlib> 9 #include <cstdlib>
10 #include <libgen.h> 10 #include <libgen.h>
11 #include <signal.h> 11 #include <signal.h>
12 #include <getopt.h> 12 #include <getopt.h>
13 #include <unistd.h> 13 #include <unistd.h>
14 #include <BeagleRT.h> 14 #include <Bela.h>
15 15
16 using namespace std; 16 using namespace std;
17 17
18 // Handle Ctrl-C by requesting that the audio rendering stop 18 // Handle Ctrl-C by requesting that the audio rendering stop
19 void interrupt_handler(int var) 19 void interrupt_handler(int var)
24 // Print usage information 24 // Print usage information
25 void usage(const char * processName) 25 void usage(const char * processName)
26 { 26 {
27 cerr << "Usage: " << processName << " [options]" << endl; 27 cerr << "Usage: " << processName << " [options]" << endl;
28 28
29 BeagleRT_usage(); 29 Bela_usage();
30 30
31 cerr << " --frequency [-f] frequency: Set the frequency of the oscillator\n"; 31 cerr << " --frequency [-f] frequency: Set the frequency of the oscillator\n";
32 cerr << " --help [-h]: Print this menu\n"; 32 cerr << " --help [-h]: Print this menu\n";
33 } 33 }
34 34
35 int main(int argc, char *argv[]) 35 int main(int argc, char *argv[])
36 { 36 {
37 BeagleRTInitSettings settings; // Standard audio settings 37 BelaInitSettings settings; // Standard audio settings
38 float frequency = 440.0; // Frequency of oscillator 38 float frequency = 440.0; // Frequency of oscillator
39 39
40 struct option customOptions[] = 40 struct option customOptions[] =
41 { 41 {
42 {"help", 0, NULL, 'h'}, 42 {"help", 0, NULL, 'h'},
43 {"frequency", 1, NULL, 'f'}, 43 {"frequency", 1, NULL, 'f'},
44 {NULL, 0, NULL, 0} 44 {NULL, 0, NULL, 0}
45 }; 45 };
46 46
47 // Set default settings 47 // Set default settings
48 BeagleRT_defaultSettings(&settings); 48 Bela_defaultSettings(&settings);
49 49
50 // Parse command-line arguments 50 // Parse command-line arguments
51 while (1) { 51 while (1) {
52 int c; 52 int c;
53 if ((c = BeagleRT_getopt_long(argc, argv, "hf:", customOptions, &settings)) < 0) 53 if ((c = Bela_getopt_long(argc, argv, "hf:", customOptions, &settings)) < 0)
54 break; 54 break;
55 switch (c) { 55 switch (c) {
56 case 'h': 56 case 'h':
57 usage(basename(argv[0])); 57 usage(basename(argv[0]));
58 exit(0); 58 exit(0);
65 exit(1); 65 exit(1);
66 } 66 }
67 } 67 }
68 68
69 // Initialise the PRU audio device 69 // Initialise the PRU audio device
70 if(BeagleRT_initAudio(&settings, &frequency) != 0) { 70 if(Bela_initAudio(&settings, &frequency) != 0) {
71 cout << "Error: unable to initialise audio" << endl; 71 cout << "Error: unable to initialise audio" << endl;
72 return -1; 72 return -1;
73 } 73 }
74 74
75 // Start the audio device running 75 // Start the audio device running
76 if(BeagleRT_startAudio()) { 76 if(Bela_startAudio()) {
77 cout << "Error: unable to start real-time audio" << endl; 77 cout << "Error: unable to start real-time audio" << endl;
78 return -1; 78 return -1;
79 } 79 }
80 80
81 // Set up interrupt handler to catch Control-C and SIGTERM 81 // Set up interrupt handler to catch Control-C and SIGTERM
86 while(!gShouldStop) { 86 while(!gShouldStop) {
87 usleep(100000); 87 usleep(100000);
88 } 88 }
89 89
90 // Stop the audio device 90 // Stop the audio device
91 BeagleRT_stopAudio(); 91 Bela_stopAudio();
92 92
93 // Clean up any resources allocated for audio 93 // Clean up any resources allocated for audio
94 BeagleRT_cleanupAudio(); 94 Bela_cleanupAudio();
95 95
96 // All done! 96 // All done!
97 return 0; 97 return 0;
98 } 98 }