comparison examples/basic_analog_input/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 int gSensorInputFrequency = 0; 17 int gSensorInputFrequency = 0;
18 int gSensorInputAmplitude = 1; 18 int gSensorInputAmplitude = 1;
26 // Print usage information 26 // Print usage information
27 void usage(const char * processName) 27 void usage(const char * processName)
28 { 28 {
29 cerr << "Usage: " << processName << " [options]" << endl; 29 cerr << "Usage: " << processName << " [options]" << endl;
30 30
31 BeagleRT_usage(); 31 Bela_usage();
32 32
33 cerr << " --frequency [-f] input: Choose the analog input controlling frequency (0-7; default 0)\n"; 33 cerr << " --frequency [-f] input: Choose the analog input controlling frequency (0-7; default 0)\n";
34 cerr << " --amplitude [-a] input: Choose the analog input controlling amplitude (0-7; default 1)\n"; 34 cerr << " --amplitude [-a] input: Choose the analog input controlling amplitude (0-7; default 1)\n";
35 cerr << " --help [-h]: Print this menu\n"; 35 cerr << " --help [-h]: Print this menu\n";
36 } 36 }
37 37
38 int main(int argc, char *argv[]) 38 int main(int argc, char *argv[])
39 { 39 {
40 BeagleRTInitSettings settings; // Standard audio settings 40 BelaInitSettings settings; // Standard audio settings
41 41
42 struct option customOptions[] = 42 struct option customOptions[] =
43 { 43 {
44 {"help", 0, NULL, 'h'}, 44 {"help", 0, NULL, 'h'},
45 {"frequency", 1, NULL, 'f'}, 45 {"frequency", 1, NULL, 'f'},
46 {"amplitude", 1, NULL, 'a'}, 46 {"amplitude", 1, NULL, 'a'},
47 {NULL, 0, NULL, 0} 47 {NULL, 0, NULL, 0}
48 }; 48 };
49 49
50 // Set default settings 50 // Set default settings
51 BeagleRT_defaultSettings(&settings); 51 Bela_defaultSettings(&settings);
52 52
53 // Parse command-line arguments 53 // Parse command-line arguments
54 while (1) { 54 while (1) {
55 int c; 55 int c;
56 if ((c = BeagleRT_getopt_long(argc, argv, "hf:a:", customOptions, &settings)) < 0) 56 if ((c = Bela_getopt_long(argc, argv, "hf:a:", customOptions, &settings)) < 0)
57 break; 57 break;
58 switch (c) { 58 switch (c) {
59 case 'h': 59 case 'h':
60 usage(basename(argv[0])); 60 usage(basename(argv[0]));
61 exit(0); 61 exit(0);
79 exit(1); 79 exit(1);
80 } 80 }
81 } 81 }
82 82
83 // Initialise the PRU audio device 83 // Initialise the PRU audio device
84 if(BeagleRT_initAudio(&settings, 0) != 0) { 84 if(Bela_initAudio(&settings, 0) != 0) {
85 cout << "Error: unable to initialise audio" << endl; 85 cout << "Error: unable to initialise audio" << endl;
86 return -1; 86 return -1;
87 } 87 }
88 88
89 if(settings.verbose) { 89 if(settings.verbose) {
90 cout << "--> Frequency on input " << gSensorInputFrequency << endl; 90 cout << "--> Frequency on input " << gSensorInputFrequency << endl;
91 cout << "--> Amplitude on input " << gSensorInputAmplitude << endl; 91 cout << "--> Amplitude on input " << gSensorInputAmplitude << endl;
92 } 92 }
93 93
94 // Start the audio device running 94 // Start the audio device running
95 if(BeagleRT_startAudio()) { 95 if(Bela_startAudio()) {
96 cout << "Error: unable to start real-time audio" << endl; 96 cout << "Error: unable to start real-time audio" << endl;
97 return -1; 97 return -1;
98 } 98 }
99 99
100 // Set up interrupt handler to catch Control-C and SIGTERM 100 // Set up interrupt handler to catch Control-C and SIGTERM
105 while(!gShouldStop) { 105 while(!gShouldStop) {
106 usleep(100000); 106 usleep(100000);
107 } 107 }
108 108
109 // Stop the audio device 109 // Stop the audio device
110 BeagleRT_stopAudio(); 110 Bela_stopAudio();
111 111
112 // Clean up any resources allocated for audio 112 // Clean up any resources allocated for audio
113 BeagleRT_cleanupAudio(); 113 Bela_cleanupAudio();
114 114
115 // All done! 115 // All done!
116 return 0; 116 return 0;
117 } 117 }