Contains the source code from the course work throughout my undergraduate Computer Engineering degree at Brigham Young University. There is a mixture of Go, Python, C, C++, Java, VHDL, Verilog, Matlab, Bash, Assembly, etc..
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sounds.c 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. * sounds.c
  3. *
  4. * Created on: Oct 26, 2013
  5. * Author: superman
  6. */
  7. #include "sounds.h"
  8. extern int shoot_numberOfSamples;
  9. extern int tankDeath_numberOfSamples;
  10. extern int spaceShipSound_numberOfSamples;
  11. extern int spaceShipDeathSound_numberOfSamples;
  12. extern int alienDeathSound_numberOfSamples;
  13. extern int alienMovement1Sound_numberOfSamples;
  14. extern int alienMovement2Sound_numberOfSamples;
  15. extern int alienMovement3Sound_numberOfSamples;
  16. extern int alienMovement4Sound_numberOfSamples;
  17. extern int shoot_soundData[];
  18. extern int tankDeath_soundData[];
  19. extern int spaceShipSound_soundData[];
  20. extern int spaceShipDeathSound_soundData[];
  21. extern int alienDeathSound_soundData[];
  22. extern int alienMovement1Sound_soundData[];
  23. extern int alienMovement2Sound_soundData[];
  24. extern int alienMovement3Sound_soundData[];
  25. extern int alienMovement4Sound_soundData[];
  26. extern int alienSilenceSound_soundData[];
  27. int haveTankBulletSound = 0;
  28. int haveTankDeathSound = 0;
  29. int haveSpaceShipSound = 0;
  30. int haveSpaceShipDeathSound = 0;
  31. int haveAlienDeathSound = 0;
  32. int haveAlienMoveSound =1;
  33. int bulletSoundIndex = 0;
  34. int tankDeathIndex = 0;
  35. int spaceShipIndex = 0;
  36. int spaceShipDeathIndex = 0;
  37. int alienDeathIndex = 0;
  38. int alienCadenceIndex = 1;
  39. int alien1Index=0;
  40. int alien2Index=0;
  41. int alien3Index=0;
  42. int alien4Index=0;
  43. int isHaveTankBulletSound() {
  44. return haveTankBulletSound;
  45. }
  46. void setHaveTankBulletSound(int x) {
  47. haveTankBulletSound = x;
  48. }
  49. int isHaveTankDeathSound() {
  50. return haveTankDeathSound;
  51. }
  52. void setHaveTankDeathSound(int x) {
  53. haveTankDeathSound = x;
  54. }
  55. int isHaveSpaceShipSound() {
  56. return haveSpaceShipSound;
  57. }
  58. void setHaveSpaceShipSound(int x) {
  59. haveSpaceShipSound = x;
  60. }
  61. int isHaveSpaceShipDeathSound() {
  62. return haveSpaceShipDeathSound;
  63. }
  64. void setHaveSpaceShipDeathSound(int x) {
  65. haveSpaceShipDeathSound = x;
  66. }
  67. int isHaveAlienDeathSound() {
  68. return haveAlienDeathSound;
  69. }
  70. void setHaveAlienDeathSound(int x) {
  71. haveAlienDeathSound = x;
  72. }
  73. int isAlienSoundCadence(){
  74. return alienCadenceIndex;
  75. }
  76. void setAlienSoundCadence(int x){
  77. alienCadenceIndex = x;
  78. }
  79. //Responsible for rotating the different alien sounds called in the timer
  80. void incrementAlienSoundCadence(){
  81. if(isAlienSoundCadence() == 8)
  82. setAlienSoundCadence(1);
  83. else
  84. setAlienSoundCadence(isAlienSoundCadence() + 1);
  85. }
  86. void fillSound(){
  87. int i;
  88. for(i=0;i<256;i++){
  89. Xuint32 sample = getNextSample();
  90. XAC97_mSetInFifoData(XPAR_AXI_AC97_0_BASEADDR,sample);
  91. }
  92. }
  93. Xuint32 getNextSample(){
  94. Xuint32 sample = 0x00000000; //Play no sound
  95. if (haveTankBulletSound != 0) {
  96. sample = (shoot_soundData[bulletSoundIndex] | (shoot_soundData[bulletSoundIndex])<<16);
  97. if(bulletSoundIndex < (shoot_numberOfSamples - 1)){
  98. bulletSoundIndex++;
  99. } else {
  100. bulletSoundIndex = 0;
  101. haveTankBulletSound = 0;
  102. }
  103. } else if (haveTankDeathSound != 0) {
  104. sample = (tankDeath_soundData[tankDeathIndex] | (tankDeath_soundData[tankDeathIndex])<<16);
  105. if (tankDeathIndex < (tankDeath_numberOfSamples - 1)) {
  106. tankDeathIndex++;
  107. } else {
  108. tankDeathIndex = 0;
  109. haveTankDeathSound = 0;
  110. }
  111. } else if (haveSpaceShipSound != 0 ) { //set in setHaveSpaceShip global
  112. sample = (spaceShipSound_soundData[spaceShipIndex] | (spaceShipSound_soundData[spaceShipIndex])<<16);
  113. if (spaceShipIndex < (spaceShipSound_numberOfSamples -1)) {
  114. spaceShipIndex++;
  115. } else {
  116. spaceShipIndex = 0;
  117. //Set no sound when it goes off the page - Done by setHaveSpaceShip global
  118. }
  119. } else if (haveSpaceShipDeathSound != 0) {
  120. sample = (spaceShipDeathSound_soundData[spaceShipDeathIndex] | (spaceShipDeathSound_soundData[spaceShipDeathIndex])<<16);
  121. if (spaceShipDeathIndex < (spaceShipDeathSound_numberOfSamples - 1)) {
  122. spaceShipDeathIndex++;
  123. } else {
  124. spaceShipDeathIndex = 0;
  125. haveSpaceShipDeathSound = 0;
  126. }
  127. }
  128. else if (haveAlienDeathSound != 0) {
  129. sample = (alienDeathSound_soundData[alienDeathIndex] | (alienDeathSound_soundData[alienDeathIndex])<<16);
  130. if (alienDeathIndex < (alienDeathSound_numberOfSamples - 1)) {
  131. alienDeathIndex++;
  132. } else {
  133. alienDeathIndex = 0;
  134. haveAlienDeathSound = 0;
  135. }
  136. }
  137. //Set to always on since aliens are always in the game
  138. else if (haveAlienMoveSound != 0){
  139. //Performs the change in the four different sounds which are incremented by the alienCounter which is in timer_interrupt_handler()
  140. switch (isAlienSoundCadence()){
  141. case 1:
  142. sample = (alienMovement1Sound_soundData[alien1Index] | (alienMovement1Sound_soundData[alien1Index]) <<16);
  143. if(alien1Index < (alienMovement1Sound_numberOfSamples -1)){
  144. alien1Index++;
  145. }
  146. else{
  147. alien1Index = 0;
  148. }
  149. break;
  150. case 3:
  151. sample = (alienMovement2Sound_soundData[alien2Index] | (alienMovement2Sound_soundData[alienCadenceIndex]) <<16);
  152. if(alien2Index < (alienMovement2Sound_numberOfSamples -1)){
  153. alien2Index++;
  154. }
  155. else{
  156. alien2Index = 0;
  157. }
  158. break;
  159. case 5:
  160. sample = (alienMovement3Sound_soundData[alien3Index] | (alienMovement3Sound_soundData[alienCadenceIndex]) <<16);
  161. if(alien3Index < (alienMovement3Sound_numberOfSamples -1)){
  162. alien3Index++;
  163. }
  164. else{
  165. alien3Index = 0;
  166. }
  167. break;
  168. case 7:
  169. sample = (alienMovement4Sound_soundData[alien4Index] | (alienMovement4Sound_soundData[alienCadenceIndex]) <<16);
  170. if(alien4Index < (alienMovement4Sound_numberOfSamples -1)){
  171. alien4Index++;
  172. }
  173. else{
  174. alien4Index = 0;
  175. }
  176. break;
  177. default:
  178. sample = 0x00000080;
  179. break;
  180. }
  181. }
  182. return sample;
  183. }