![]() |
Zap'Em Blast'Em Robots
robots that play laser tag!
|
Sound Task state machine for playing audio files corresponding to game mechanics. More...
#include "laser_buf.h"
#include "game_over_buf.h"
#include "start_buf.h"
#include "hit_buf.h"
#include "sound_task.h"
#include <stdio.h>
Functions | |
void | sound_task_run (SoundTask *sound_task) |
Runs the current state of the SoundTask. | |
void | sound_task_state_0_init (SoundTask *sound_task) |
Initializes the sound task (state 0). | |
void | sound_task_state_1_wait (SoundTask *sound_task) |
Waits for sound flags (state 1). | |
void | sound_task_state_2_laser (SoundTask *sound_task) |
Starts the interrupts and sets the array pointer for the laser sound(state 2). | |
void | sound_task_state_3_hit (SoundTask *sound_task) |
Starts the interrupts and sets the array pointer for the hit sound(state 3). | |
void | sound_task_state_4_win (SoundTask *sound_task) |
Starts the interrupts and sets the array pointer for the win sound(state 4). | |
void | sound_task_state_5_start (SoundTask *sound_task) |
Starts the interrupts and sets the array pointer for the start sound(state 5). | |
void | sound_task_state_6_stop (SoundTask *sound_task) |
Stops the interrupts and PWM for speaker after sound played (state 6) |
Variables | |
volatile uint32_t | sample_index = 0 |
volatile uint8_t | pwm_div_count = 0 |
volatile uint32_t | audio_buf_len |
volatile uint32_t | playing = 0 |
const int16_t * | audio_buf_ptr |
Sound Task state machine for playing audio files corresponding to game mechanics.
Created on: May 22, 2025
void sound_task_run | ( | SoundTask * | sound_task | ) |
void sound_task_state_0_init | ( | SoundTask * | sound_task | ) |
Initializes the sound task (state 0).
Goes to state 1, waiting for sound flags.
sound_task | Pointer to the SoundTask instance. |
void sound_task_state_1_wait | ( | SoundTask * | sound_task | ) |
Waits for sound flags (state 1).
Waits for flags to go high and then sends the state machine into the corresponding state.
sound_task | Pointer to the SoundTask instance. |
void sound_task_state_2_laser | ( | SoundTask * | sound_task | ) |
Starts the interrupts and sets the array pointer for the laser sound(state 2).
Assigns the corresponding audio buffer and length to the extern variables. Then, restarts interrupts and PWM for the speaker.
sound_task | Pointer to the SoundTask instance. |
void sound_task_state_3_hit | ( | SoundTask * | sound_task | ) |
Starts the interrupts and sets the array pointer for the hit sound(state 3).
Assigns the corresponding audio buffer and length to the extern variables. Then, restarts interrupts and PWM for the speaker.
sound_task | Pointer to the SoundTask instance. |
void sound_task_state_4_win | ( | SoundTask * | sound_task | ) |
Starts the interrupts and sets the array pointer for the win sound(state 4).
Assigns the corresponding audio buffer and length to the extern variables. Then, restarts interrupts and PWM for the speaker.
sound_task | Pointer to the SoundTask instance. |
void sound_task_state_5_start | ( | SoundTask * | sound_task | ) |
Starts the interrupts and sets the array pointer for the start sound(state 5).
Assigns the corresponding audio buffer and length to the extern variables. Then, restarts interrupts and PWM for the speaker.
sound_task | Pointer to the SoundTask instance. |
void sound_task_state_6_stop | ( | SoundTask * | sound_task | ) |
Stops the interrupts and PWM for speaker after sound played (state 6)
Stops interrupts and PWM for speaker then goes back to the waiting state.
sound_task | Pointer to the SoundTask instance. |
volatile uint32_t audio_buf_len |
Length current sound buffer
const int16_t* audio_buf_ptr |
Pointer to current sound buffer
volatile uint32_t playing = 0 |
Flag for when a sound is playing
volatile uint8_t pwm_div_count = 0 |
counter for stepping through audio buf
volatile uint32_t sample_index = 0 |
Index of step in sound buffer