Header file for the sound task system.
More...
#include <stdint.h>
#include "stm32f4xx_hal.h"
Go to the source code of this file.
|
struct | SoundTask |
| Structure that represents the sound task state and configuration. More...
|
|
typedef void(* | sound_fcn_t) (SoundTask *sound_task) |
| Function pointer type for sound state functions.
|
Header file for the sound task system.
- Author
- Andrew Carr
Created on: May 22, 2025
◆ PWM_FREQ
Output Timer PWM frequency
◆ SAMPLE_RATE
#define SAMPLE_RATE 44100U |
◆ STEP_RATIO
◆ sound_fcn_t
typedef void(* sound_fcn_t) (SoundTask *sound_task) |
Function pointer type for sound state functions.
Each state function must take a pointer to SoundTask as its argument.
◆ sound_task_run()
void sound_task_run |
( |
SoundTask * | sound_task | ) |
|
Executes the current sound task state.
- Parameters
-
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_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_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_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_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_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_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_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
-
◆ audio_buf_len
volatile uint32_t audio_buf_len |
|
extern |
Length current sound buffer
◆ audio_buf_ptr
const int16_t* audio_buf_ptr |
|
extern |
Pointer to current sound buffer
◆ playing
volatile uint32_t playing |
|
extern |
Flag for when a sound is playing
◆ pwm_div_count
volatile uint8_t pwm_div_count |
|
extern |
counter for stepping through audio buf
◆ sample_index
volatile uint32_t sample_index |
|
extern |
Index of step in sound buffer