Mercurial > hg > beaglert
comparison examples/basic_analog_output/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 |
---|---|
8 #include <iostream> | 8 #include <iostream> |
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 <BeagleRT.h> | 13 #include <Bela.h> |
14 | 14 |
15 using namespace std; | 15 using namespace std; |
16 | 16 |
17 // Handle Ctrl-C by requesting that the audio rendering stop | 17 // Handle Ctrl-C by requesting that the audio rendering stop |
18 void interrupt_handler(int var) | 18 void interrupt_handler(int var) |
23 // Print usage information | 23 // Print usage information |
24 void usage(const char * processName) | 24 void usage(const char * processName) |
25 { | 25 { |
26 cerr << "Usage: " << processName << " [options]" << endl; | 26 cerr << "Usage: " << processName << " [options]" << endl; |
27 | 27 |
28 BeagleRT_usage(); | 28 Bela_usage(); |
29 | 29 |
30 cerr << " --frequency [-f] frequency: Set the frequency of the LED fade (default: 1.0)\n"; | 30 cerr << " --frequency [-f] frequency: Set the frequency of the LED fade (default: 1.0)\n"; |
31 cerr << " --help [-h]: Print this menu\n"; | 31 cerr << " --help [-h]: Print this menu\n"; |
32 } | 32 } |
33 | 33 |
34 int main(int argc, char *argv[]) | 34 int main(int argc, char *argv[]) |
35 { | 35 { |
36 BeagleRTInitSettings settings; // Standard audio settings | 36 BelaInitSettings settings; // Standard audio settings |
37 float frequency = 1.0; // Frequency of LED fades | 37 float frequency = 1.0; // Frequency of LED fades |
38 | 38 |
39 struct option customOptions[] = | 39 struct option customOptions[] = |
40 { | 40 { |
41 {"help", 0, NULL, 'h'}, | 41 {"help", 0, NULL, 'h'}, |
42 {"frequency", 1, NULL, 'f'}, | 42 {"frequency", 1, NULL, 'f'}, |
43 {NULL, 0, NULL, 0} | 43 {NULL, 0, NULL, 0} |
44 }; | 44 }; |
45 | 45 |
46 // Set default settings | 46 // Set default settings |
47 BeagleRT_defaultSettings(&settings); | 47 Bela_defaultSettings(&settings); |
48 | 48 |
49 // In this example, audio isn't used so might as well leave speaker muted | 49 // In this example, audio isn't used so might as well leave speaker muted |
50 settings.beginMuted = 1; | 50 settings.beginMuted = 1; |
51 | 51 |
52 // Parse command-line arguments | 52 // Parse command-line arguments |
53 while (1) { | 53 while (1) { |
54 int c; | 54 int c; |
55 if ((c = BeagleRT_getopt_long(argc, argv, "hf:", customOptions, &settings)) < 0) | 55 if ((c = Bela_getopt_long(argc, argv, "hf:", customOptions, &settings)) < 0) |
56 break; | 56 break; |
57 switch (c) { | 57 switch (c) { |
58 case 'h': | 58 case 'h': |
59 usage(basename(argv[0])); | 59 usage(basename(argv[0])); |
60 exit(0); | 60 exit(0); |
71 exit(1); | 71 exit(1); |
72 } | 72 } |
73 } | 73 } |
74 | 74 |
75 // Initialise the PRU audio device | 75 // Initialise the PRU audio device |
76 if(BeagleRT_initAudio(&settings, &frequency) != 0) { | 76 if(Bela_initAudio(&settings, &frequency) != 0) { |
77 cout << "Error: unable to initialise audio" << endl; | 77 cout << "Error: unable to initialise audio" << endl; |
78 return -1; | 78 return -1; |
79 } | 79 } |
80 | 80 |
81 // Start the audio device running | 81 // Start the audio device running |
82 if(BeagleRT_startAudio()) { | 82 if(Bela_startAudio()) { |
83 cout << "Error: unable to start real-time audio" << endl; | 83 cout << "Error: unable to start real-time audio" << endl; |
84 return -1; | 84 return -1; |
85 } | 85 } |
86 | 86 |
87 // Set up interrupt handler to catch Control-C and SIGTERM | 87 // Set up interrupt handler to catch Control-C and SIGTERM |
92 while(!gShouldStop) { | 92 while(!gShouldStop) { |
93 usleep(100000); | 93 usleep(100000); |
94 } | 94 } |
95 | 95 |
96 // Stop the audio device | 96 // Stop the audio device |
97 BeagleRT_stopAudio(); | 97 Bela_stopAudio(); |
98 | 98 |
99 // Clean up any resources allocated for audio | 99 // Clean up any resources allocated for audio |
100 BeagleRT_cleanupAudio(); | 100 Bela_cleanupAudio(); |
101 | 101 |
102 // All done! | 102 // All done! |
103 return 0; | 103 return 0; |
104 } | 104 } |