Simple starter skeleton for asteroids video game.

Dependencies:   PinDetect

Revision:
1:a6872783beca
Parent:
0:0c450cb95a1e
Child:
2:30020ddfccf6
diff -r 0c450cb95a1e -r a6872783beca Sounds/Speaker.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Sounds/Speaker.h	Sat Feb 23 21:38:45 2019 +0000
@@ -0,0 +1,91 @@
+#include "mbed.h"
+#include "buzzy_siren.h"
+#include "buzzy_begin.h"
+#include "buzzy_chomp.h"
+#include "buzzy_eatghost.h"
+#include "buzzy_death.h"
+#include "buzzy_eatfruit.h"
+
+
+class Speaker : public PwmOut
+{
+public:
+    enum BUZZY_Sounds {BEGIN, SIREN, CHOMP, EAT_GHOST, DEATH, EAT_FRUIT};
+    
+    Speaker(PinName nPin):PwmOut(nPin)
+    {
+       m_ulAudioArrayIndex = 0;
+       m_enActiveAudioArray = BEGIN;    
+       pAudioArray = NULL;
+    }
+    
+    void PlayNextValue()
+    {
+        if (pAudioArray != NULL)
+        {
+            write(pAudioArray[ GetNextValue() ]);
+        }       
+    }
+    
+    void SwitchAudioFile ( const BUZZY_Sounds &newSound)
+    {
+        switch (newSound)
+        {           
+            case BEGIN:
+                pAudioArray = &data_BEGIN[0];
+                break;   
+            case CHOMP:
+                 pAudioArray = &data_CHOMP[0];
+                break;
+            case EAT_GHOST:
+                pAudioArray = &data_GHOST[0];
+                break;
+            case DEATH:
+                pAudioArray = &data_DEATH[0];
+                break;
+            case EAT_FRUIT:
+                pAudioArray = &data_EAT_FRUIT[0];
+                break;              
+            case SIREN:
+            default:
+                pAudioArray = &data_SIREN[0];
+                break; 
+        }
+                             
+    }
+    
+    unsigned int GetNextValue()
+    {
+        m_ulAudioArrayIndex++;
+        switch (m_enActiveAudioArray)
+        {           
+            case BEGIN:
+                m_ulAudioArrayIndex %= NUM_BEGIN_ELEMENTS;
+                break;   
+            case CHOMP:
+                 m_ulAudioArrayIndex %= NUM_CHOMP_ELEMENTS;
+                break;
+            case EAT_GHOST:
+                 m_ulAudioArrayIndex %= NUM_GHOST_ELEMENTS;
+                break;
+            case DEATH:
+                 m_ulAudioArrayIndex %= NUM_DEATH_ELEMENTS;
+                break;
+            case EAT_FRUIT:
+                 m_ulAudioArrayIndex %= NUM_EAT_FRUIT_ELEMENTS;
+                break;              
+            case SIREN:
+            default:
+                 m_ulAudioArrayIndex %= NUM_SIREN_ELEMENTS;
+                break;          
+        }
+        return m_ulAudioArrayIndex;
+    }
+private:
+    unsigned long m_ulAudioArrayIndex;
+    BUZZY_Sounds m_enActiveAudioArray;
+    float *pAudioArray;
+    
+};
+
+            
\ No newline at end of file