diff options
| author | sowgro <tpoke.ferrari@gmail.com> | 2025-12-14 01:10:28 -0500 |
|---|---|---|
| committer | sowgro <tpoke.ferrari@gmail.com> | 2025-12-14 01:10:28 -0500 |
| commit | 0616056e336da34b0a84e98e6e0ee286d4b69b8b (patch) | |
| tree | be1c9de52e1a52dedbeed3cb13235eef54226a11 /project/Core/Src | |
| parent | e68a05b29de507a56b8747557707e8d6cdd68542 (diff) | |
| download | 340-repo-Sowgro-0616056e336da34b0a84e98e6e0ee286d4b69b8b.tar.gz 340-repo-Sowgro-0616056e336da34b0a84e98e6e0ee286d4b69b8b.tar.bz2 340-repo-Sowgro-0616056e336da34b0a84e98e6e0ee286d4b69b8b.zip | |
add comments
Diffstat (limited to 'project/Core/Src')
| -rw-r--r-- | project/Core/Src/Project/parser.c | 44 | ||||
| -rw-r--r-- | project/Core/Src/Project/player.c | 8 | ||||
| -rw-r--r-- | project/Core/Src/Project/project.c | 2 | ||||
| -rw-r--r-- | project/Core/Src/main.c | 18 |
4 files changed, 45 insertions, 27 deletions
diff --git a/project/Core/Src/Project/parser.c b/project/Core/Src/Project/parser.c index c34b3ba..397dd7b 100644 --- a/project/Core/Src/Project/parser.c +++ b/project/Core/Src/Project/parser.c @@ -1,5 +1,6 @@ /* - * player.c + * parser.c + * Handles parsing of songs and playing of the parsed notes * * Created on: Nov 25, 2025 * Author: sowgro @@ -19,9 +20,21 @@ static int nTracks; static int startTime; static song_info_t song_info; -void parser_play_notes() { - int count = systick_get_count(); - int curAbsTime = count - startTime; +/** + * Prepare the parser to play the notes + * Expected that parse_song() was called first + */ +void parser_play_init() { + startTime = systick_get_count(); +} + +/** + * Play any notes that are ready to be played + * Should be called continuously in the play state + * Expected that parse_song() was called first + */ +void parser_play_loop() { + int curAbsTime = systick_get_count() - startTime; for (int i = 0; i < nTracks; i++) { note_event_t curEvent = tracks[i].events[tracks[i].curEventIndex]; if (curEvent.abs_time >= curAbsTime) { @@ -31,12 +44,16 @@ void parser_play_notes() { case NOTE_ON_EVENT: add_tone(curEvent.key_number, curEvent.value); break; } + tracks[i].curEventIndex++; } - tracks[i].curEventIndex++; } play_tones(); } +/** + * Parse a song and populate the static fields with its information + * @param p_song a pointer to the current position in the song + */ void parse_song(uint8_t *p_song) { header_t header; header = get_header(p_song); @@ -50,8 +67,13 @@ void parse_song(uint8_t *p_song) { } } +/** + * Parse the track and populate the track parameter with its information + * @param p_song a pointer to the current position in the song + * @param track a pointer to a track to output to + * @returns a pointer to the song after the track + */ uint8_t *parse_track(uint8_t *p_song, track_t *track) { - printf("Parsing track \r\n"); p_song += 4; // skip MTrk uint32_t MTrk_len = convert_to_uint32(p_song); p_song += 4; @@ -93,10 +115,15 @@ uint8_t *parse_track(uint8_t *p_song, track_t *track) { track->nEvents = curEvent; track->curEventIndex = 0; - printf("parsing track done\r\n"); return p_song; } +/** + * Parses the track information + * @param p_song a pointer to the current position in the song + * @param ret the output parameter + * @returns a pointer to the song after the track info + */ uint8_t *parse_song_info(uint8_t *p_song, song_info_t *ret) { ret->copyright = 0; ret->tempo = 0; @@ -136,6 +163,9 @@ uint8_t *parse_song_info(uint8_t *p_song, song_info_t *ret) { return p_song; } +/** + * An accessor for other files to get the song information + */ song_info_t parser_get_song_info() { return song_info; } diff --git a/project/Core/Src/Project/player.c b/project/Core/Src/Project/player.c index 42b652d..0c41e6d 100644 --- a/project/Core/Src/Project/player.c +++ b/project/Core/Src/Project/player.c @@ -69,6 +69,7 @@ void player_next() { */ void player_play() { state = PLAYING_STATE; + parser_play_init(); LED_On(); } @@ -90,14 +91,13 @@ void player_stop() { /** * Toggles the LED every second if in pause mode */ -void player_tick() { - int count = systick_get_count(); +void player_loop() { switch (state) { case PAUSED_STATE: - if(!(count & 1023)) { + if(!(systick_get_count() & 1023)) { LED_Toggle(); }; break; case PLAYING_STATE: - parser_play_notes(count); break; + parser_play_loop(); break; } } diff --git a/project/Core/Src/Project/project.c b/project/Core/Src/Project/project.c index 5ee41a8..77e1e1c 100644 --- a/project/Core/Src/Project/project.c +++ b/project/Core/Src/Project/project.c @@ -45,7 +45,7 @@ void project_run() { case LOCAL_MODE: local_control_loop(); break; } - player_tick(); + player_loop(); } } diff --git a/project/Core/Src/main.c b/project/Core/Src/main.c index 0a36667..8eca7db 100644 --- a/project/Core/Src/main.c +++ b/project/Core/Src/main.c @@ -3,20 +3,15 @@ // include project specific header files +#include <stdio.h> #include "error_handler.h" #include "SysClock.h" #include "LED.h" #include "UART.h" #include "demo.h" -#include "activity10.h" -#include <stdio.h> -#include "hw4.h" #include "project.h" -#include "hw8.h" -#include "activity12.h" -#include "song.h" -int main(void){ +int main() { // initialization code System_Clock_Init(); // set System Clock = 80 MHz @@ -25,14 +20,7 @@ int main(void){ // application run function printf("\n\n\n\n\n\n\n\n\r"); -// run_demo(); -// activity4_run(); + project_run(); -// activity10_run(); -// hw6_run(); -// activity12_run(); -// activity13_run(); -// hw8_run(); -// parse_song(get_song(0).p_song + 109); } |
