From 29f69b5b7831c846cea1f61a7de4920fafa97ede Mon Sep 17 00:00:00 2001 From: sowgro Date: Wed, 10 Dec 2025 17:49:22 -0500 Subject: push for laptop --- project/.settings/language.settings.xml | 4 ++-- project/Core/Inc/Activities/activity4.h | 2 ++ project/Core/Inc/Project/song_info.h | 2 +- project/Core/Src/Activties/activity4.c | 18 +++++++++++------- project/Core/Src/Project/player.c | 23 +++++++++++++++++++---- project/Core/Src/Project/song_info.c | 23 +++++++++++------------ 6 files changed, 46 insertions(+), 26 deletions(-) diff --git a/project/.settings/language.settings.xml b/project/.settings/language.settings.xml index ae082b2..ec1bb84 100644 --- a/project/.settings/language.settings.xml +++ b/project/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + @@ -16,7 +16,7 @@ - + diff --git a/project/Core/Inc/Activities/activity4.h b/project/Core/Inc/Activities/activity4.h index e3b677a..fb9d5ce 100644 --- a/project/Core/Inc/Activities/activity4.h +++ b/project/Core/Inc/Activities/activity4.h @@ -18,4 +18,6 @@ typedef struct { void activity4_run(); +header_t *get_header(uint8_t *p_song); + #endif /* INC_ACTIVITIES_ACTIVITY4_H_ */ diff --git a/project/Core/Inc/Project/song_info.h b/project/Core/Inc/Project/song_info.h index fbc5bc2..c951fca 100644 --- a/project/Core/Inc/Project/song_info.h +++ b/project/Core/Inc/Project/song_info.h @@ -14,6 +14,6 @@ typedef struct { int tempo; } song_info_t; -song_info_t get_song_info(unsigned char *p_song); +song_info_t get_song_info(uint8_t *p_song, song_info_t *ret); #endif /* INC_PROJECT_SONG_INFO_H_ */ diff --git a/project/Core/Src/Activties/activity4.c b/project/Core/Src/Activties/activity4.c index f3bd673..898cd2d 100644 --- a/project/Core/Src/Activties/activity4.c +++ b/project/Core/Src/Activties/activity4.c @@ -12,19 +12,23 @@ #include "activity4.h" void activity4_run() { - header_t* p_header; + header_t* p_header = get_header(get_song(0).p_song); - p_header = (header_t *) (get_song(0).p_song); + printf ("Header: \r\n"); + printf ("\tLength: %lu\r\n", p_header->length); + printf ("\tFormat: %u\r\n", p_header->format); + printf ("\tNum Tracks: %u\r\n", p_header->ntrcks); + printf ("\tDivision: %u\r\n", p_header->division); +} + +header_t get_header(uint8_t *p_song) { + header_t* p_header = (header_t *) (p_song); p_header->length = convert_to_uint32((uint8_t*) &p_header->length); p_header->format = convert_to_uint16((uint8_t*) &p_header->format); p_header->ntrcks = convert_to_uint16((uint8_t*) &p_header->ntrcks); p_header->division = convert_to_uint16((uint8_t*) &p_header->division); - printf ("Header: \r\n"); - printf ("\tLength: %lu\r\n", p_header->length); - printf ("\tFormat: %u\r\n", p_header->format); - printf ("\tNum Tracks: %u\r\n", p_header->ntrcks); - printf ("\tDivision: %u\r\n", p_header->division); + return *p_header; } diff --git a/project/Core/Src/Project/player.c b/project/Core/Src/Project/player.c index 71531a8..0925483 100644 --- a/project/Core/Src/Project/player.c +++ b/project/Core/Src/Project/player.c @@ -9,6 +9,8 @@ #include #include "endian_converters.h" #include "hw8.h" +#include "activity4.h" +#include "song_info.h" #define NOTE_OFF_EVENT (0) #define NOTE_ON_EVENT (1) @@ -22,11 +24,24 @@ typedef struct { } note_event_t; void parse_song(uint8_t *p_song) { + header_t header; + header = get_header(p_song); + p_song += sizeof(header_t) - 2; // move pointer past header + + song_info_t song_info; + p_song = get_song_info(p_song, &song_info); + + note_event_t trackEvents[header.ntrcks][1024]; + for(int i = 0; i < header.ntrcks; i++){ + p_song = parse_track(p_song, trackEvents[i]); + } +} + +uint8_t parse_track(uint8_t *p_song, note_event_t *events) { p_song += 4; // skip MTrk uint32_t MTrk_len = convert_to_uint32(p_song); p_song += 4; - note_event_t events[1/*track*/][1024/*event*/]; int curEvent = 0; uint32_t prev_abs_time = 0; @@ -59,9 +74,9 @@ void parse_song(uint8_t *p_song) { note.value = *p_song; p_song++; - events[0][curEvent++] = note; + events[curEvent++] = note; } - events[0][curEvent] = 0; + events[curEvent] = 0; // null terminate array - printf("done %p", events); + return p_song; } diff --git a/project/Core/Src/Project/song_info.c b/project/Core/Src/Project/song_info.c index 4a94954..2990da0 100644 --- a/project/Core/Src/Project/song_info.c +++ b/project/Core/Src/Project/song_info.c @@ -11,10 +11,11 @@ #include "song_info.h" #include "endian_converters.h" -song_info_t get_song_info(uint8_t *p_song) { - song_info_t ret = {0, 0, 0}; -// header_t *header = (header_t *) p_song; - p_song += sizeof(header_t) - 2; // move pointer past header +uint8_t get_song_info(uint8_t *p_song, song_info_t *ret) { + ret->copyright = 0; + ret->tempo = 0; + ret->title = 0; + p_song += 4; // move past MTrk label uint32_t MTrk_len = convert_to_uint32(p_song); // read in size of MTrk @@ -26,8 +27,8 @@ song_info_t get_song_info(uint8_t *p_song) { p_song += sizeof(uint16_t); uint8_t ev_len = *(uint8_t *) p_song; p_song += sizeof(ev_len); - ret.copyright = (char *) p_song; - ret.copyright[ev_len] = 0; + ret->copyright = (char *) p_song; + ret->copyright[ev_len] = 0; } // FF 03 - title @@ -35,19 +36,17 @@ song_info_t get_song_info(uint8_t *p_song) { p_song += sizeof(uint16_t); uint8_t ev_len = *(uint8_t *) p_song; p_song += sizeof(ev_len); - ret.title = (char *) p_song; - ret.title[ev_len] = 0; + ret->title = (char *) p_song; + ret->title[ev_len] = 0; } // FF 51 - tempo if (convert_to_uint16(p_song) == 0xFF51) { p_song += sizeof(uint16_t); p_song += sizeof(uint8_t); // skip length, always 03 - ret.tempo = convert_to_uint24(p_song); + ret->tempo = convert_to_uint24(p_song); } } - - - return ret; + return p_song; } -- cgit v1.2.3