song.c

Go to the documentation of this file.
00001 
00130 #include <includes.h>
00131 
00132 SONG_STATE song_state = SONG_STOP; 
00134 unsigned int song_index; 
00135 unsigned int song_wait; 
00136 SONG_NOTE* song_notes; 
00137 SONG_NOTE song_current_note; 
00138 unsigned int song_length; 
00145 void song_set(SONG_NOTE* song, unsigned int length){
00146   song_notes = song;
00147   song_length = length;
00148   song_wait = 0;
00149   song_index = 0;
00150   song_current_note = song_notes[song_index];
00151 }
00152 
00156 void song_update(void){
00157   switch (song_state){
00158     case SONG_FAST_FORWARD: song_wait++;
00159     case SONG_PLAY:
00160       song_wait++;
00161       if (song_wait >= song_current_note.length){
00162         song_current_note = song_notes[song_index];
00163         song_index++;
00164         if (song_index >= song_length){song_index = 0;}
00165         song_wait = 0;
00166       }
00167       if (song_wait >= song_current_note.duration - 50){
00168         buzzer_off();
00169       } else{ 
00170         buzzer_set_frequency(song_current_note.frequency);
00171         buzzer_on();
00172       }
00173       break;
00174     case SONG_STOP: buzzer_off(); break;
00175     case SONG_PAUSE: buzzer_off(); break;
00176   }
00177 } 
00178 
00182 void song_stop(void){
00183   song_wait = 0;
00184   song_index = 0;
00185   song_current_note = song_notes[song_index];
00186   song_state = SONG_STOP;
00187 }
00188 
00192 void song_play(void){
00193   song_state = SONG_PLAY;
00194 }
00195 
00199 void song_pause(void){
00200   song_state = SONG_PAUSE;
00201 }
00202 
00206 void song_fast_forward(void){
00207   song_state = SONG_FAST_FORWARD;
00208 }
00209 
Generated on Tue Jun 29 16:36:14 2010 by  doxygen 1.6.3