Zap'Em Blast'Em Robots
robots that play laser tag!
Loading...
Searching...
No Matches
sound_task.c File Reference

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

Detailed Description

Sound Task state machine for playing audio files corresponding to game mechanics.

Author
Andrew Carr

Created on: May 22, 2025

Function Documentation

◆ sound_task_run()

void sound_task_run ( SoundTask * sound_task)

Runs the current state of the SoundTask.

Executes the current sound task state.

Checks whether the current state index is valid. If so, it calls the corresponding state function from the task's function pointer array.

Parameters
sound_taskPointer to the SoundTask instance.

◆ sound_task_state_0_init()

void sound_task_state_0_init ( SoundTask * sound_task)

Initializes the sound task (state 0).

Goes to state 1, waiting for sound flags.

Parameters
sound_taskPointer to the SoundTask instance.

◆ sound_task_state_1_wait()

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.

Parameters
sound_taskPointer to the SoundTask instance.

◆ sound_task_state_2_laser()

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.

Parameters
sound_taskPointer to the SoundTask instance.

◆ sound_task_state_3_hit()

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.

Parameters
sound_taskPointer to the SoundTask instance.

◆ sound_task_state_4_win()

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.

Parameters
sound_taskPointer to the SoundTask instance.

◆ sound_task_state_5_start()

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.

Parameters
sound_taskPointer to the SoundTask instance.

◆ sound_task_state_6_stop()

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.

Parameters
sound_taskPointer to the SoundTask instance.

Variable Documentation

◆ audio_buf_len

volatile uint32_t audio_buf_len

Length current sound buffer

◆ audio_buf_ptr

const int16_t* audio_buf_ptr

Pointer to current sound buffer

◆ playing

volatile uint32_t playing = 0

Flag for when a sound is playing

◆ pwm_div_count

volatile uint8_t pwm_div_count = 0

counter for stepping through audio buf

◆ sample_index

volatile uint32_t sample_index = 0

Index of step in sound buffer