comparison projects/tank_wars/main.cpp @ 268:8d80eda512cd prerelease

Added new overlay for using PRU0 or PRU1, a script to halt board on button press, and several example projects
author andrewm
date Tue, 17 May 2016 14:46:26 +0100
parents 3c3a1357657d
children
comparison
equal deleted inserted replaced
267:247a182adb6d 268:8d80eda512cd
17 17
18 float *gMusicBuffer = 0; 18 float *gMusicBuffer = 0;
19 int gMusicBufferLength = 0; 19 int gMusicBufferLength = 0;
20 float *gSoundBoomBuffer = 0; 20 float *gSoundBoomBuffer = 0;
21 int gSoundBoomBufferLength = 0; 21 int gSoundBoomBufferLength = 0;
22 float *gSoundHitBuffer = 0;
23 int gSoundHitBufferLength = 0;
24
22 25
23 using namespace std; 26 using namespace std;
24 27
25 // Load a sound sample from file 28 // Load a sound sample from file
26 int loadSoundFile(const string& path, float **buffer, int *bufferLength) 29 int loadSoundFile(const string& path, float **buffer, int *bufferLength)
78 int main(int argc, char *argv[]) 81 int main(int argc, char *argv[])
79 { 82 {
80 BeagleRTInitSettings settings; // Standard audio settings 83 BeagleRTInitSettings settings; // Standard audio settings
81 string musicFileName = "music.wav"; 84 string musicFileName = "music.wav";
82 string soundBoomFileName = "boom.wav"; 85 string soundBoomFileName = "boom.wav";
83 86 string soundHitFileName = "hit.wav";
87
84 struct option customOptions[] = 88 struct option customOptions[] =
85 { 89 {
86 {"help", 0, NULL, 'h'}, 90 {"help", 0, NULL, 'h'},
87 {"fps", 1, NULL, 'f'}, 91 {"fps", 1, NULL, 'f'},
88 {NULL, 0, NULL, 0} 92 {NULL, 0, NULL, 0}
119 cout << "Warning: unable to load sound file " << musicFileName << endl; 123 cout << "Warning: unable to load sound file " << musicFileName << endl;
120 } 124 }
121 if(loadSoundFile(soundBoomFileName, &gSoundBoomBuffer, &gSoundBoomBufferLength) != 0) { 125 if(loadSoundFile(soundBoomFileName, &gSoundBoomBuffer, &gSoundBoomBufferLength) != 0) {
122 cout << "Warning: unable to load sound file " << soundBoomFileName << endl; 126 cout << "Warning: unable to load sound file " << soundBoomFileName << endl;
123 } 127 }
124 128 if(loadSoundFile(soundHitFileName, &gSoundHitBuffer, &gSoundHitBufferLength) != 0) {
129 cout << "Warning: unable to load sound file " << soundHitFileName << endl;
130 }
131
125 // Initialise the PRU audio device 132 // Initialise the PRU audio device
126 if(BeagleRT_initAudio(&settings, 0) != 0) { 133 if(BeagleRT_initAudio(&settings, 0) != 0) {
127 cout << "Error: unable to initialise audio" << endl; 134 cout << "Error: unable to initialise audio" << endl;
128 return -1; 135 return -1;
129 } 136 }
152 // Release sound files 159 // Release sound files
153 if(gMusicBuffer != 0) 160 if(gMusicBuffer != 0)
154 free(gMusicBuffer); 161 free(gMusicBuffer);
155 if(gSoundBoomBuffer != 0) 162 if(gSoundBoomBuffer != 0)
156 free(gSoundBoomBuffer); 163 free(gSoundBoomBuffer);
157 164 if(gSoundHitBuffer != 0)
165 free(gSoundHitBuffer);
166
158 // All done! 167 // All done!
159 return 0; 168 return 0;
160 } 169 }