diff options
Diffstat (limited to 'project/Core/Src')
| -rw-r--r-- | project/Core/Src/Project/player.c | 67 | ||||
| -rw-r--r-- | project/Core/Src/Project/song_info.c | 2 | ||||
| -rw-r--r-- | project/Core/Src/main.c | 4 |
3 files changed, 72 insertions, 1 deletions
diff --git a/project/Core/Src/Project/player.c b/project/Core/Src/Project/player.c new file mode 100644 index 0000000..71531a8 --- /dev/null +++ b/project/Core/Src/Project/player.c @@ -0,0 +1,67 @@ +/* + * player.c + * + * Created on: Nov 25, 2025 + * Author: sowgro + */ + +#include "endian_converters.h" +#include <stdint.h> +#include "endian_converters.h" +#include "hw8.h" + +#define NOTE_OFF_EVENT (0) +#define NOTE_ON_EVENT (1) +#define KEY_PRESSURE (2) + +typedef struct { + uint8_t ev_type; + uint32_t abs_time; + uint8_t key_number; + uint8_t value; +} note_event_t; + +void parse_song(uint8_t *p_song) { + 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; + + for (uint8_t *p_end = p_song + MTrk_len; p_song != p_end; p_song++) { + note_event_t note; + + parseDelay_result_t delay_result = parseDelay(p_song); + uint32_t abs_time = prev_abs_time + delay_result.value; + note.abs_time = abs_time; + prev_abs_time = abs_time; + p_song += delay_result.bytes_used; + + + if (*p_song >> 4 == 0b1000) { + note.ev_type = NOTE_OFF_EVENT; + } else if (*p_song >> 4 == 0b1001) { + note.ev_type = NOTE_ON_EVENT; + } else if (*p_song >> 4 == 0b1010) { + note.ev_type = KEY_PRESSURE; + } else { + continue; + } + +// size_t channelNumber = *p_song && 0b00001111; + p_song++; + + note.key_number = *p_song; + p_song++; + + note.value = *p_song; + p_song++; + + events[0][curEvent++] = note; + } + events[0][curEvent] = 0; + + printf("done %p", events); +} diff --git a/project/Core/Src/Project/song_info.c b/project/Core/Src/Project/song_info.c index 75f6dd9..4a94954 100644 --- a/project/Core/Src/Project/song_info.c +++ b/project/Core/Src/Project/song_info.c @@ -47,5 +47,7 @@ song_info_t get_song_info(uint8_t *p_song) { } } + + return ret; } diff --git a/project/Core/Src/main.c b/project/Core/Src/main.c index b78da42..29c8f5e 100644 --- a/project/Core/Src/main.c +++ b/project/Core/Src/main.c @@ -14,6 +14,7 @@ #include "project.h" #include "hw8.h" #include "activity12.h" +#include "song.h" int main(void){ @@ -31,6 +32,7 @@ int main(void){ // hw6_run(); // activity12_run(); // activity13_run(); - hw8_run(); +// hw8_run(); + parse_song(get_song(0).p_song + 109); } |
