Mercurial > hg > beaglert
comparison examples/tank_wars/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 <sndfile.h> | 13 #include <sndfile.h> |
14 #include <BeagleRT.h> | 14 #include <Bela.h> |
15 | 15 |
16 extern int gScreenFramesPerSecond; | 16 extern int gScreenFramesPerSecond; |
17 | 17 |
18 float *gMusicBuffer = 0; | 18 float *gMusicBuffer = 0; |
19 int gMusicBufferLength = 0; | 19 int gMusicBufferLength = 0; |
70 // Print usage information | 70 // Print usage information |
71 void usage(const char * processName) | 71 void usage(const char * processName) |
72 { | 72 { |
73 cerr << "Usage: " << processName << " [options]" << endl; | 73 cerr << "Usage: " << processName << " [options]" << endl; |
74 | 74 |
75 BeagleRT_usage(); | 75 Bela_usage(); |
76 | 76 |
77 cerr << " --fps [-f] value: Set target frames per second\n"; | 77 cerr << " --fps [-f] value: Set target frames per second\n"; |
78 cerr << " --help [-h]: Print this menu\n"; | 78 cerr << " --help [-h]: Print this menu\n"; |
79 } | 79 } |
80 | 80 |
81 int main(int argc, char *argv[]) | 81 int main(int argc, char *argv[]) |
82 { | 82 { |
83 BeagleRTInitSettings settings; // Standard audio settings | 83 BelaInitSettings settings; // Standard audio settings |
84 string musicFileName = "music.wav"; | 84 string musicFileName = "music.wav"; |
85 string soundBoomFileName = "boom.wav"; | 85 string soundBoomFileName = "boom.wav"; |
86 string soundHitFileName = "hit.wav"; | 86 string soundHitFileName = "hit.wav"; |
87 | 87 |
88 struct option customOptions[] = | 88 struct option customOptions[] = |
91 {"fps", 1, NULL, 'f'}, | 91 {"fps", 1, NULL, 'f'}, |
92 {NULL, 0, NULL, 0} | 92 {NULL, 0, NULL, 0} |
93 }; | 93 }; |
94 | 94 |
95 // Set default settings | 95 // Set default settings |
96 BeagleRT_defaultSettings(&settings); | 96 Bela_defaultSettings(&settings); |
97 | 97 |
98 // Parse command-line arguments | 98 // Parse command-line arguments |
99 while (1) { | 99 while (1) { |
100 int c; | 100 int c; |
101 if ((c = BeagleRT_getopt_long(argc, argv, "hf:", customOptions, &settings)) < 0) | 101 if ((c = Bela_getopt_long(argc, argv, "hf:", customOptions, &settings)) < 0) |
102 break; | 102 break; |
103 switch (c) { | 103 switch (c) { |
104 case 'f': | 104 case 'f': |
105 gScreenFramesPerSecond = atoi(optarg); | 105 gScreenFramesPerSecond = atoi(optarg); |
106 if(gScreenFramesPerSecond < 1) | 106 if(gScreenFramesPerSecond < 1) |
128 if(loadSoundFile(soundHitFileName, &gSoundHitBuffer, &gSoundHitBufferLength) != 0) { | 128 if(loadSoundFile(soundHitFileName, &gSoundHitBuffer, &gSoundHitBufferLength) != 0) { |
129 cout << "Warning: unable to load sound file " << soundHitFileName << endl; | 129 cout << "Warning: unable to load sound file " << soundHitFileName << endl; |
130 } | 130 } |
131 | 131 |
132 // Initialise the PRU audio device | 132 // Initialise the PRU audio device |
133 if(BeagleRT_initAudio(&settings, 0) != 0) { | 133 if(Bela_initAudio(&settings, 0) != 0) { |
134 cout << "Error: unable to initialise audio" << endl; | 134 cout << "Error: unable to initialise audio" << endl; |
135 return -1; | 135 return -1; |
136 } | 136 } |
137 | 137 |
138 // Start the audio device running | 138 // Start the audio device running |
139 if(BeagleRT_startAudio()) { | 139 if(Bela_startAudio()) { |
140 cout << "Error: unable to start real-time audio" << endl; | 140 cout << "Error: unable to start real-time audio" << endl; |
141 return -1; | 141 return -1; |
142 } | 142 } |
143 | 143 |
144 // Set up interrupt handler to catch Control-C and SIGTERM | 144 // Set up interrupt handler to catch Control-C and SIGTERM |
149 while(!gShouldStop) { | 149 while(!gShouldStop) { |
150 usleep(100000); | 150 usleep(100000); |
151 } | 151 } |
152 | 152 |
153 // Stop the audio device | 153 // Stop the audio device |
154 BeagleRT_stopAudio(); | 154 Bela_stopAudio(); |
155 | 155 |
156 // Clean up any resources allocated for audio | 156 // Clean up any resources allocated for audio |
157 BeagleRT_cleanupAudio(); | 157 Bela_cleanupAudio(); |
158 | 158 |
159 // Release sound files | 159 // Release sound files |
160 if(gMusicBuffer != 0) | 160 if(gMusicBuffer != 0) |
161 free(gMusicBuffer); | 161 free(gMusicBuffer); |
162 if(gSoundBoomBuffer != 0) | 162 if(gSoundBoomBuffer != 0) |