void play_note_delay(note_t *note) { timer_load(TIMER_2, (1193181/note->freq)); speaker_on(); delay(note->dur); speaker_off(); }
void music_state_machine() { static int noteTime = 0; switch (state) { case OFF: break; case INIT: if (noteIndex >= song->lenght) { state = OFF; break; } Note *note = &song->notes[noteIndex++]; noteTime = note->dur; timer_load(TIMER_2, TIMER_CLK / notes_frequency[note->freq]); speaker_on(); state = PLAYING; break; case PLAYING: noteTime--; if (noteTime <= 0) { speaker_off(); state = PAUSING; noteTime = song->pause; } break; case PAUSING: noteTime--; if (noteTime <= 0) { state = INIT; } } }
void play_note(Note *note) { timer_init(2,LCOM_MODE); timer_load(2,musicDiv(note->freq)); speaker_on(); mili_sleep(note->dur); speaker_off(); }
/* Briefly beep the PC speaker. */ void speaker_beep (void) { /* Only attempt to beep the speaker if interrupts are enabled, because we don't want to freeze the machine during the beep. We could add a hook to the timer interrupt to avoid that problem, but then we'd risk failing to ever stop the beep if Pintos crashes for some unrelated reason. There's nothing more annoying than a machine whose beeping you can't stop without a power cycle. We can't just enable interrupts while we sleep. For one thing, we get called (indirectly) from printf, which should always work, even during boot before we're ready to enable interrupts. */ if (intr_get_level () == INTR_ON) { speaker_on (440); timer_msleep (250); speaker_off (); } }