Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: 25LCxxx_SPI CommonTypes Gameduino mbed
SoundManager.h
00001 /* 00002 * SOURCE FILE : SoundManager.h 00003 * 00004 * Responsible for playing simple sounds. 00005 * 00006 */ 00007 00008 #ifndef SoundManagerIncluded 00009 00010 #define SoundManagerIncluded 00011 00012 #include <stdio.h> // for NULL 00013 #include "Types.h" // various types 00014 #include "Gameduino.h" // Gameduino stuff 00015 00016 class SoundManager { 00017 00018 public : 00019 00020 // An instance of this class. 00021 static SoundManager Instance; 00022 00023 /***************/ 00024 /* CONSTRUCTOR */ 00025 /***************/ 00026 SoundManager(); 00027 00028 /*******************************************/ 00029 /* SET GAMEDUINO THAT WILL PLAY THE SOUNDS */ 00030 /*******************************************/ 00031 // Pass pointer to a Gameduino which will play the sounds. 00032 // You must call this before using other routines. 00033 void SetGameduino( Gameduino *gameduino ) { 00034 gd = gameduino; 00035 } 00036 00037 /************************/ 00038 /* TRY AND PLAY A SOUND */ 00039 /************************/ 00040 // Pass address of tune in program memory in tuneAddress. 00041 // Pass bias to apply to left speaker amplitude in leftAmpBias. 00042 // Pass bias to apply to right speaker amplitude in leftAmpBias. 00043 // Returns true if sound was started, false if no sound slots free. 00044 bool PlaySound( const UInt8 *tuneAddress, UInt8 leftAmpBias, UInt8 rightAmpBias ); 00045 00046 /****************************/ 00047 /* UPDATE PLAYING OF SOUNDS */ 00048 /****************************/ 00049 // Should be called at regular intervals. 00050 void Update( void ); 00051 00052 /**********************************/ 00053 /* COUNT NUMBER OF SOUNDS PLAYING */ 00054 /**********************************/ 00055 // Returns number of sounds playing. 00056 UInt8 CountSoundsPlaying( void ); 00057 00058 /******************************/ 00059 /* SILENCE ALL SOUNDS PLAYING */ 00060 /******************************/ 00061 void SilenceAll( void ); 00062 00063 private : 00064 00065 enum { 00066 FirstVoice = 0, // First Gameduino voice channel used 00067 VoiceCount = 8, // Number of voice channels used 00068 }; 00069 00070 // Record for tune associated with each voice used. 00071 class TuneRecord { 00072 public : 00073 00074 TuneRecord() : 00075 TuneAddress( (UInt8*)NULL ) 00076 { 00077 } 00078 00079 Gameduino::WaveForm TuneWaveform; 00080 UInt8 LeftAmpBias, RightAmpBias; 00081 const UInt8 *TuneAddress; 00082 UInt8 Countdown; 00083 00084 }; 00085 00086 // Records used to step through each tune. 00087 // A value of zero in TuneAddress field indicates an unused slot. 00088 TuneRecord tuneRecords[ VoiceCount ]; 00089 00090 // Gameduino that plays the sounds. 00091 Gameduino *gd; 00092 00093 /*****************************/ 00094 /* UPDATE A SINGLE TUNE SLOT */ 00095 /*****************************/ 00096 // Do NOT call with a record containing zero in TuneAddress (a free slot). 00097 void UpdateTuneSection( UInt8 voiceNum, TuneRecord *rec ); 00098 00099 }; 00100 00101 #endif 00102 00103 /* END of SoundManager.h */ 00104
Generated on Tue Jul 12 2022 21:10:36 by
1.7.2