From d6428ba117eae3af3a2ec9347ae3f25e61a3cefb Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Sat, 26 Nov 2022 22:05:32 -0500 Subject: [PATCH 01/18] Added Editorconfig --- .editorconfig | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..eefd463 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,11 @@ + +root = true + +[*] +insert_final_newline = true +end_of_line = lf + +[*.{md,c}] +indent_style = space +indent_size = 4 +charset = utf-8 From b71389690e2d1b7c8894021ebcefedb76fb93f65 Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Sat, 26 Nov 2022 22:05:46 -0500 Subject: [PATCH 02/18] Formatted Notes --- ps.c | 1555 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 779 insertions(+), 776 deletions(-) diff --git a/ps.c b/ps.c index b6ef991..7b662d1 100644 --- a/ps.c +++ b/ps.c @@ -49,828 +49,831 @@ int myrand() return seed; } -uint8_t notes[] = -//line0: ch0 note, ch1 note, ch2 note ... -//line1: ... -//... -{ - 100, 0, 130, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - 100, 0, 128, 0, 0, 0, 0, 0, - 10, 0, 130, 0, 0, 0, 0, 0, - 200, 0, 135, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - 20, 0, 0, 0, 0, 0, 0, 0, - 10, 0, 137, 0, 0, 0, 0, 0, - 100, 0, 0, 0, 0, 0, 0, 0, - 200, 0, 130, 0, 0, 0, 0, 0, - 100, 0, 138, 0, 0, 0, 0, 0, - 20, 0, 0, 0, 0, 0, 0, 0, - 200, 0, 142, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - 20, 0, 123, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - 255, 0, 0, 0, 0, 0, 0, 0 + + +/* + * Lines of Notes + * 1 Line = 8 x Notes ( uint8_t ) + */ + +uint8_t notes [] = { + + 100 , 0 , 130 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 128 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 130 , 0 , 0 , 0 , 0 , 0 , + 200 , 0 , 135 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 137 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 0 , 130 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 138 , 0 , 0 , 0 , 0 , 0 , + 20 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 0 , 142 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 0 , 123 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 255 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }; -uint8_t notes2[] = -{ - 100, 0, 130, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - 100, 0, 128, 0, 0, 0, 0, 0, - 10, 0, 130, 0, 0, 0, 0, 0, - 200, 0, 134, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - 20, 0, 0, 0, 0, 0, 0, 0, - 10, 0, 137, 0, 0, 0, 0, 0, - 100, 0, 0, 0, 0, 0, 0, 0, - 200, 0, 130, 0, 0, 0, 0, 0, - 100, 0, 140, 0, 0, 0, 0, 0, - 20, 0, 0, 0, 0, 0, 0, 0, - 200, 0, 142, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - 20, 0, 122, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - 255, 0, 0, 0, 0, 0, 0, 0 +uint8_t notes2 [] = { + + 100 , 0 , 130 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 128 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 130 , 0 , 0 , 0 , 0 , 0 , + 200 , 0 , 134 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 137 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 0 , 130 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 140 , 0 , 0 , 0 , 0 , 0 , + 20 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 0 , 142 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 0 , 122 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 255 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }; -uint8_t notes2_prehat[] = -{ - 100, 0, 130, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - 100, 0, 128, 0, 0, 0, 0, 0, - 10, 0, 130, 0, 0, 0, 0, 0, - 200, 0, 134, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - 20, 0, 0, 0, 0, 0, 0, 0, - 10, 0, 137, 0, 0, 0, 0, 0, - 100, 0, 0, 0, 0, 0, 0, 0, - 200, 100, 130, 0, 0, 0, 0, 0, - 100, 0, 140, 0, 0, 0, 0, 0, - 20, 0, 0, 0, 0, 0, 0, 0, - 200, 100, 142, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - 20, 0, 122, 0, 0, 0, 0, 0, - 10, 100, 0, 0, 0, 0, 0, 0, - 255, 0, 0, 0, 0, 0, 0, 0 +uint8_t notes2_prehat [] = { + + 100 , 0 , 130 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 128 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 130 , 0 , 0 , 0 , 0 , 0 , + 200 , 0 , 134 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 137 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 100 , 130 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 140 , 0 , 0 , 0 , 0 , 0 , + 20 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 100 , 142 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 0 , 122 , 0 , 0 , 0 , 0 , 0 , + 10 , 100 , 0 , 0 , 0 , 0 , 0 , 0 , + 255 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }; -uint8_t notes3[] = -{ - 100, 0, 131, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - 100, 0, 130, 0, 0, 0, 0, 0, - 10, 0, 131, 0, 0, 0, 0, 0, - 200, 0, 135, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - 20, 0, 0, 0, 0, 0, 0, 0, - 10, 0, 137, 0, 0, 0, 0, 0, - 100, 0, 0, 0, 0, 0, 0, 0, - 200, 0, 135, 0, 0, 0, 0, 0, - 100, 0, 140, 0, 0, 0, 0, 0, - 20, 0, 0, 0, 0, 0, 0, 0, - 200, 0, 142, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - 20, 0, 128, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - 255, 0, 0, 0, 0, 0, 0, 0 +uint8_t notes3 [] = { + + 100 , 0 , 131 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 130 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 131 , 0 , 0 , 0 , 0 , 0 , + 200 , 0 , 135 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 137 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 0 , 135 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 140 , 0 , 0 , 0 , 0 , 0 , + 20 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 0 , 142 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 0 , 128 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 255 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }; -uint8_t notes_hat_first[] = -{ - 100, 0, 130, 99, 1, 0, 254, 254, - 10, 1, 0, 99, 0, 0, 0, 0, - 100, 2, 128, 0, 0, 0, 0, 0, - 10, 1, 130, 99, 0, 0, 0, 0, - 200, 100, 135, 99, 0, 0, 0, 0, - 10, 4, 0, 0, 0, 0, 0, 0, - 20, 2, 0, 0, 0, 138, 0, 0, - 10, 4, 137, 0, 0, 0, 0, 0, - 100, 0, 0, 0, 0, 0, 0, 0, - 200, 100, 130, 99, 0, 0, 0, 0, - 100, 1, 138, 99, 0, 0, 0, 0, - 20, 3, 0, 0, 0, 0, 0, 0, - 200, 100, 142, 99, 0, 0, 0, 0, - 10, 1, 0, 0, 0, 0, 0, 0, - 20, 2, 123, 99, 0, 0, 0, 0, - 10, 60, 0, 0, 0, 0, 0, 0, - 255, 1, 0, 0, 0, 0, 0, 0 +uint8_t notes_hat_first [] = { + + 100 , 0 , 130 , 99 , 1 , 0 , 254 , 254 , + 10 , 1 , 0 , 99 , 0 , 0 , 0 , 0 , + 100 , 2 , 128 , 0 , 0 , 0 , 0 , 0 , + 10 , 1 , 130 , 99 , 0 , 0 , 0 , 0 , + 200 , 100 , 135 , 99 , 0 , 0 , 0 , 0 , + 10 , 4 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 2 , 0 , 0 , 0 , 138 , 0 , 0 , + 10 , 4 , 137 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 100 , 130 , 99 , 0 , 0 , 0 , 0 , + 100 , 1 , 138 , 99 , 0 , 0 , 0 , 0 , + 20 , 3 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 100 , 142 , 99 , 0 , 0 , 0 , 0 , + 10 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 2 , 123 , 99 , 0 , 0 , 0 , 0 , + 10 , 60 , 0 , 0 , 0 , 0 , 0 , 0 , + 255 , 1 , 0 , 0 , 0 , 0 , 0 , 0 }; -uint8_t notes_hat_first2[] = -{ - 100, 0, 130, 99, 0, 140, 0, 0, - 10, 1, 0, 99, 0, 0, 0, 0, - 100, 2, 128, 0, 0, 0, 0, 0, - 10, 1, 130, 99, 0, 0, 0, 0, - 200, 100, 135, 99, 0, 0, 0, 0, - 10, 4, 0, 0, 0, 0, 0, 0, - 20, 2, 0, 0, 0, 0, 0, 0, - 10, 4, 137, 0, 2, 0, 0, 0, - 100, 0, 0, 0, 0, 0, 0, 0, - 200, 100, 130, 99, 0, 0, 0, 0, - 100, 1, 138, 99, 0, 0, 0, 0, - 20, 3, 0, 0, 0, 0, 0, 0, - 200, 100, 142, 99, 0, 0, 0, 0, - 10, 1, 0, 0, 0, 0, 0, 0, - 20, 2, 123, 99, 0, 0, 0, 0, - 10, 60, 0, 0, 0, 0, 0, 0, - 255, 1, 0, 0, 0, 0, 0, 0 +uint8_t notes_hat_first2 [] = { + + 100 , 0 , 130 , 99 , 0 , 140 , 0 , 0 , + 10 , 1 , 0 , 99 , 0 , 0 , 0 , 0 , + 100 , 2 , 128 , 0 , 0 , 0 , 0 , 0 , + 10 , 1 , 130 , 99 , 0 , 0 , 0 , 0 , + 200 , 100 , 135 , 99 , 0 , 0 , 0 , 0 , + 10 , 4 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 2 , 0 , 0 , 0 , 0 , 0 , 0 , + 10 , 4 , 137 , 0 , 2 , 0 , 0 , 0 , + 100 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 100 , 130 , 99 , 0 , 0 , 0 , 0 , + 100 , 1 , 138 , 99 , 0 , 0 , 0 , 0 , + 20 , 3 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 100 , 142 , 99 , 0 , 0 , 0 , 0 , + 10 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 2 , 123 , 99 , 0 , 0 , 0 , 0 , + 10 , 60 , 0 , 0 , 0 , 0 , 0 , 0 , + 255 , 1 , 0 , 0 , 0 , 0 , 0 , 0 }; -uint8_t notes_hat_first3[] = -{ - 100, 0, 130, 99, 0, 0, 0, 0, - 10, 1, 0, 99, 0, 0, 0, 0, - 100, 2, 128, 0, 0, 0, 0, 0, - 10, 1, 130, 99, 0, 0, 0, 0, - 200, 100, 135, 99, 0, 0, 0, 0, - 10, 4, 0, 0, 0, 0, 0, 0, - 20, 2, 0, 0, 0, 142, 0, 0, - 10, 4, 137, 0, 0, 0, 0, 0, - 100, 0, 0, 0, 0, 0, 0, 0, - 200, 100, 130, 99, 0, 0, 0, 0, - 100, 1, 138, 99, 0, 0, 0, 0, - 20, 3, 0, 0, 0, 0, 0, 0, - 200, 100, 142, 99, 0, 0, 0, 0, - 10, 1, 0, 0, 0, 0, 0, 0, - 20, 2, 123, 99, 0, 0, 0, 0, - 10, 60, 0, 0, 0, 0, 0, 0, - 255, 1, 0, 0, 0, 0, 0, 0 +uint8_t notes_hat_first3 [] = { + + 100 , 0 , 130 , 99 , 0 , 0 , 0 , 0 , + 10 , 1 , 0 , 99 , 0 , 0 , 0 , 0 , + 100 , 2 , 128 , 0 , 0 , 0 , 0 , 0 , + 10 , 1 , 130 , 99 , 0 , 0 , 0 , 0 , + 200 , 100 , 135 , 99 , 0 , 0 , 0 , 0 , + 10 , 4 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 2 , 0 , 0 , 0 , 142 , 0 , 0 , + 10 , 4 , 137 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 100 , 130 , 99 , 0 , 0 , 0 , 0 , + 100 , 1 , 138 , 99 , 0 , 0 , 0 , 0 , + 20 , 3 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 100 , 142 , 99 , 0 , 0 , 0 , 0 , + 10 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 2 , 123 , 99 , 0 , 0 , 0 , 0 , + 10 , 60 , 0 , 0 , 0 , 0 , 0 , 0 , + 255 , 1 , 0 , 0 , 0 , 0 , 0 , 0 }; -uint8_t notes_hat[] = -{ - 100, 0, 130, 99, 0, 0, 0, 0, - 10, 1, 0, 99, 0, 0, 0, 0, - 100, 2, 128, 0, 0, 0, 0, 0, - 10, 1, 130, 99, 0, 0, 0, 0, - 200, 100, 135, 99, 0, 0, 0, 0, - 10, 4, 0, 0, 0, 0, 0, 0, - 20, 2, 0, 0, 0, 0, 0, 0, - 10, 4, 137, 0, 0, 0, 0, 0, - 100, 0, 0, 0, 0, 0, 0, 0, - 200, 100, 130, 99, 0, 0, 0, 0, - 100, 1, 138, 99, 0, 0, 0, 0, - 20, 3, 0, 0, 0, 0, 0, 0, - 200, 100, 142, 99, 0, 0, 0, 0, - 10, 1, 0, 0, 0, 0, 0, 0, - 20, 2, 123, 99, 0, 0, 0, 0, - 10, 60, 0, 0, 0, 0, 0, 0, - 255, 1, 0, 0, 0, 0, 0, 0 +uint8_t notes_hat [] = { + + 100 , 0 , 130 , 99 , 0 , 0 , 0 , 0 , + 10 , 1 , 0 , 99 , 0 , 0 , 0 , 0 , + 100 , 2 , 128 , 0 , 0 , 0 , 0 , 0 , + 10 , 1 , 130 , 99 , 0 , 0 , 0 , 0 , + 200 , 100 , 135 , 99 , 0 , 0 , 0 , 0 , + 10 , 4 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 2 , 0 , 0 , 0 , 0 , 0 , 0 , + 10 , 4 , 137 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 100 , 130 , 99 , 0 , 0 , 0 , 0 , + 100 , 1 , 138 , 99 , 0 , 0 , 0 , 0 , + 20 , 3 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 100 , 142 , 99 , 0 , 0 , 0 , 0 , + 10 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 2 , 123 , 99 , 0 , 0 , 0 , 0 , + 10 , 60 , 0 , 0 , 0 , 0 , 0 , 0 , + 255 , 1 , 0 , 0 , 0 , 0 , 0 , 0 }; -uint8_t notes2_hat[] = -{ - 100, 0, 130, 94, 0, 142, 0, 0, - 10, 1, 0, 94, 0, 0, 0, 0, - 100, 2, 128, 0, 0, 0, 0, 0, - 10, 1, 130, 94, 0, 0, 0, 0, - 200, 100, 134, 94, 0, 0, 0, 0, - 10, 4, 0, 0, 0, 0, 0, 0, - 20, 2, 0, 0, 2, 0, 0, 0, - 10, 4, 137, 0, 0, 0, 0, 0, - 100, 0, 0, 0, 0, 0, 0, 0, - 200, 100, 130, 94, 0, 0, 0, 0, - 100, 1, 140, 94, 0, 0, 0, 0, - 20, 3, 0, 0, 0, 0, 0, 0, - 200, 100, 142, 94, 0, 0, 0, 0, - 10, 1, 0, 0, 0, 0, 0, 0, - 20, 2, 122, 94, 0, 0, 0, 0, - 10, 60, 0, 0, 0, 0, 0, 0, - 255, 1, 0, 0, 0, 0, 0, 0 +uint8_t notes2_hat [] = { + + 100 , 0 , 130 , 94 , 0 , 142 , 0 , 0 , + 10 , 1 , 0 , 94 , 0 , 0 , 0 , 0 , + 100 , 2 , 128 , 0 , 0 , 0 , 0 , 0 , + 10 , 1 , 130 , 94 , 0 , 0 , 0 , 0 , + 200 , 100 , 134 , 94 , 0 , 0 , 0 , 0 , + 10 , 4 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 2 , 0 , 0 , 2 , 0 , 0 , 0 , + 10 , 4 , 137 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 100 , 130 , 94 , 0 , 0 , 0 , 0 , + 100 , 1 , 140 , 94 , 0 , 0 , 0 , 0 , + 20 , 3 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 100 , 142 , 94 , 0 , 0 , 0 , 0 , + 10 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 2 , 122 , 94 , 0 , 0 , 0 , 0 , + 10 , 60 , 0 , 0 , 0 , 0 , 0 , 0 , + 255 , 1 , 0 , 0 , 0 , 0 , 0 , 0 }; -uint8_t notes3_hat[] = -{ - 100, 0, 131, 92, 0, 145, 0, 0, - 10, 1, 0, 92, 0, 0, 0, 0, - 100, 2, 130, 128, 0, 0, 0, 0, - 10, 1, 131, 92, 0, 0, 0, 0, - 200, 100, 135, 92, 0, 0, 0, 0, - 10, 4, 0, 128, 0, 0, 0, 0, - 20, 2, 0, 0, 1, 116, 0, 0, - 10, 4, 137, 0, 0, 0, 0, 0, - 100, 0, 0, 0, 0, 0, 0, 0, - 200, 100, 135, 92, 0, 0, 0, 0, - 100, 1, 140, 92, 0, 0, 0, 0, - 20, 3, 0, 0, 0, 0, 0, 0, - 200, 100, 142, 92, 0, 0, 0, 0, - 10, 1, 0, 0, 0, 0, 0, 0, - 20, 2, 128, 92, 0, 0, 0, 0, - 10, 60, 0, 0, 0, 0, 0, 0, - 255, 1, 0, 0, 0, 0, 0, 0 +uint8_t notes3_hat [] = { + + 100 , 0 , 131 , 92 , 0 , 145 , 0 , 0 , + 10 , 1 , 0 , 92 , 0 , 0 , 0 , 0 , + 100 , 2 , 130 , 128 , 0 , 0 , 0 , 0 , + 10 , 1 , 131 , 92 , 0 , 0 , 0 , 0 , + 200 , 100 , 135 , 92 , 0 , 0 , 0 , 0 , + 10 , 4 , 0 , 128 , 0 , 0 , 0 , 0 , + 20 , 2 , 0 , 0 , 1 , 116 , 0 , 0 , + 10 , 4 , 137 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 100 , 135 , 92 , 0 , 0 , 0 , 0 , + 100 , 1 , 140 , 92 , 0 , 0 , 0 , 0 , + 20 , 3 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 100 , 142 , 92 , 0 , 0 , 0 , 0 , + 10 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 2 , 128 , 92 , 0 , 0 , 0 , 0 , + 10 , 60 , 0 , 0 , 0 , 0 , 0 , 0 , + 255 , 1 , 0 , 0 , 0 , 0 , 0 , 0 }; -uint8_t notes3_hat2[] = -{ - 100, 0, 131, 92, 0, 0, 0, 0, - 10, 1, 0, 92, 0, 0, 0, 0, - 100, 2, 130, 128, 0, 0, 0, 0, - 10, 1, 131, 92, 0, 0, 0, 0, - 200, 100, 135, 92, 0, 0, 0, 0, - 10, 4, 0, 128, 0, 0, 0, 0, - 20, 2, 0, 0, 0, 0, 0, 0, - 10, 4, 137, 0, 0, 0, 0, 0, - 100, 0, 0, 0, 0, 0, 0, 0, - 200, 100, 135, 92, 0, 0, 0, 0, - 100, 1, 140, 92, 0, 0, 0, 0, - 20, 3, 0, 0, 0, 0, 0, 0, - 200, 100, 142, 92, 0, 0, 0, 0, - 10, 1, 0, 0, 0, 0, 0, 0, - 20, 2, 128, 92, 0, 0, 0, 0, - 10, 60, 0, 0, 0, 0, 0, 0, - 255, 1, 0, 0, 0, 0, 0, 0 +uint8_t notes3_hat2 [] = { + + 100 , 0 , 131 , 92 , 0 , 0 , 0 , 0 , + 10 , 1 , 0 , 92 , 0 , 0 , 0 , 0 , + 100 , 2 , 130 , 128 , 0 , 0 , 0 , 0 , + 10 , 1 , 131 , 92 , 0 , 0 , 0 , 0 , + 200 , 100 , 135 , 92 , 0 , 0 , 0 , 0 , + 10 , 4 , 0 , 128 , 0 , 0 , 0 , 0 , + 20 , 2 , 0 , 0 , 0 , 0 , 0 , 0 , + 10 , 4 , 137 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 100 , 135 , 92 , 0 , 0 , 0 , 0 , + 100 , 1 , 140 , 92 , 0 , 0 , 0 , 0 , + 20 , 3 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 100 , 142 , 92 , 0 , 0 , 0 , 0 , + 10 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 2 , 128 , 92 , 0 , 0 , 0 , 0 , + 10 , 60 , 0 , 0 , 0 , 0 , 0 , 0 , + 255 , 1 , 0 , 0 , 0 , 0 , 0 , 0 }; -uint8_t notes3_hat3[] = -{ - 100, 0, 131, 92, 0, 143, 0, 0, - 10, 1, 0, 92, 0, 0, 0, 0, - 100, 2, 130, 128, 0, 0, 0, 0, - 10, 1, 131, 92, 0, 0, 0, 0, - 200, 100, 135, 92, 0, 0, 0, 0, - 10, 4, 0, 128, 0, 0, 0, 0, - 20, 2, 0, 0, 0, 0, 0, 0, - 10, 4, 137, 0, 0, 0, 0, 0, - 100, 0, 0, 0, 0, 0, 0, 0, - 200, 100, 135, 92, 0, 0, 0, 0, - 100, 1, 140, 92, 0, 0, 0, 0, - 20, 3, 0, 0, 0, 0, 0, 0, - 200, 100, 142, 92, 0, 0, 0, 0, - 10, 1, 0, 0, 0, 0, 0, 0, - 20, 2, 128, 92, 0, 0, 0, 0, - 10, 60, 0, 0, 0, 0, 0, 0, - 255, 1, 0, 0, 0, 0, 0, 0 +uint8_t notes3_hat3 [] = { + + 100 , 0 , 131 , 92 , 0 , 143 , 0 , 0 , + 10 , 1 , 0 , 92 , 0 , 0 , 0 , 0 , + 100 , 2 , 130 , 128 , 0 , 0 , 0 , 0 , + 10 , 1 , 131 , 92 , 0 , 0 , 0 , 0 , + 200 , 100 , 135 , 92 , 0 , 0 , 0 , 0 , + 10 , 4 , 0 , 128 , 0 , 0 , 0 , 0 , + 20 , 2 , 0 , 0 , 0 , 0 , 0 , 0 , + 10 , 4 , 137 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 100 , 135 , 92 , 0 , 0 , 0 , 0 , + 100 , 1 , 140 , 92 , 0 , 0 , 0 , 0 , + 20 , 3 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 100 , 142 , 92 , 0 , 0 , 0 , 0 , + 10 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 2 , 128 , 92 , 0 , 0 , 0 , 0 , + 10 , 60 , 0 , 0 , 0 , 0 , 0 , 0 , + 255 , 1 , 0 , 0 , 0 , 0 , 0 , 0 }; -uint8_t notes3_hat4[] = -{ - 100, 0, 131, 92, 0, 142, 0, 0, - 10, 1, 0, 92, 0, 0, 0, 0, - 100, 2, 130, 128, 0, 0, 0, 0, - 10, 1, 131, 92, 0, 0, 0, 0, - 200, 100, 135, 92, 0, 0, 0, 0, - 10, 4, 0, 128, 0, 0, 0, 0, - 20, 2, 0, 0, 0, 0, 0, 0, - 10, 4, 137, 0, 0, 0, 0, 0, - 100, 0, 0, 0, 0, 0, 0, 0, - 200, 100, 135, 92, 0, 0, 0, 0, - 100, 1, 140, 92, 0, 0, 0, 0, - 20, 3, 0, 0, 0, 0, 0, 0, - 200, 100, 142, 92, 0, 0, 0, 0, - 10, 1, 0, 0, 0, 0, 0, 0, - 20, 2, 128, 92, 0, 0, 0, 0, - 10, 60, 0, 0, 0, 0, 0, 0, - 255, 1, 0, 0, 0, 0, 0, 0 +uint8_t notes3_hat4 [] = { + + 100 , 0 , 131 , 92 , 0 , 142 , 0 , 0 , + 10 , 1 , 0 , 92 , 0 , 0 , 0 , 0 , + 100 , 2 , 130 , 128 , 0 , 0 , 0 , 0 , + 10 , 1 , 131 , 92 , 0 , 0 , 0 , 0 , + 200 , 100 , 135 , 92 , 0 , 0 , 0 , 0 , + 10 , 4 , 0 , 128 , 0 , 0 , 0 , 0 , + 20 , 2 , 0 , 0 , 0 , 0 , 0 , 0 , + 10 , 4 , 137 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 100 , 135 , 92 , 0 , 0 , 0 , 0 , + 100 , 1 , 140 , 92 , 0 , 0 , 0 , 0 , + 20 , 3 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 100 , 142 , 92 , 0 , 0 , 0 , 0 , + 10 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 2 , 128 , 92 , 0 , 0 , 0 , 0 , + 10 , 60 , 0 , 0 , 0 , 0 , 0 , 0 , + 255 , 1 , 0 , 0 , 0 , 0 , 0 , 0 }; -uint8_t notes_hat_first_dual[] = -{ - 100, 0, 131, 95, 0, 0, 135, 0, - 10, 1, 0, 95, 0, 0, 0, 0, - 100, 2, 130, 0, 0, 0, 0, 0, - 10, 1, 131, 95, 0, 0, 0, 0, - 200, 100, 135, 95, 0, 135, 0, 0, - 10, 4, 0, 0, 0, 0, 0, 0, - 20, 2, 0, 0, 0, 0, 0, 0, - 10, 4, 137, 0, 0, 0, 0, 0, - 100, 0, 0, 0, 0, 0, 0, 0, - 200, 100, 135, 95, 0, 0, 0, 0, - 100, 1, 140, 95, 0, 0, 0, 0, - 20, 3, 0, 0, 0, 0, 0, 0, - 200, 100, 142, 95, 0, 0, 0, 0, - 10, 1, 0, 0, 0, 0, 0, 0, - 20, 2, 128, 95, 0, 0, 0, 0, - 10, 60, 0, 0, 0, 0, 0, 0, - - 100, 0, 131, 95, 0, 0, 135, 137, - 10, 1, 0, 95, 0, 0, 0, 0, - 100, 2, 130, 0, 0, 0, 0, 0, - 10, 1, 131, 95, 0, 0, 0, 0, - 200, 100, 135, 95, 0, 0, 0, 0, - 10, 4, 0, 0, 0, 0, 0, 0, - 20, 2, 0, 0, 0, 0, 0, 0, - 10, 4, 137, 0, 0, 0, 0, 0, - 100, 0, 0, 0, 0, 0, 0, 0, - 200, 100, 135, 95, 0, 0, 0, 0, - 100, 1, 140, 95, 0, 0, 0, 0, - 20, 3, 0, 0, 0, 0, 0, 0, - 200, 100, 142, 95, 0, 0, 0, 0, - 10, 1, 0, 0, 0, 0, 0, 0, - 20, 2, 128, 95, 0, 0, 0, 0, - 10, 60, 0, 0, 0, 0, 0, 0, - - 100, 0, 131, 95, 0, 0, 135, 140, - 10, 1, 0, 95, 0, 0, 0, 0, - 100, 2, 130, 0, 0, 0, 0, 0, - 10, 1, 131, 95, 0, 0, 0, 0, - 200, 100, 135, 95, 0, 0, 0, 0, - 10, 4, 0, 0, 0, 0, 0, 0, - 20, 2, 0, 0, 0, 0, 0, 0, - 10, 4, 137, 0, 0, 0, 0, 0, - 100, 0, 0, 0, 0, 0, 0, 0, - 200, 100, 135, 95, 0, 0, 0, 0, - 100, 1, 140, 95, 0, 0, 0, 0, - 20, 3, 0, 0, 0, 0, 0, 0, - 200, 100, 142, 95, 0, 0, 0, 0, - 10, 1, 0, 0, 0, 0, 0, 0, - 20, 2, 128, 95, 0, 0, 0, 0, - 10, 60, 0, 0, 0, 0, 0, 0, - - 100, 0, 131, 95, 2, 159, 135, 142, - 10, 1, 0, 95, 0, 0, 0, 0, - 100, 2, 130, 0, 0, 0, 0, 0, - 10, 1, 131, 95, 0, 0, 0, 0, - 200, 100, 135, 95, 0, 0, 0, 0, - 10, 4, 0, 0, 0, 0, 0, 0, - 20, 2, 0, 0, 0, 0, 0, 0, - 10, 4, 137, 0, 0, 0, 0, 0, - 100, 0, 0, 0, 0, 0, 0, 0, - 200, 100, 135, 95, 0, 0, 0, 0, - 100, 1, 140, 95, 0, 0, 0, 0, - 20, 3, 0, 0, 0, 0, 0, 0, - 200, 100, 142, 95, 0, 0, 0, 0, - 10, 1, 0, 0, 0, 0, 0, 0, - 20, 2, 128, 95, 0, 0, 0, 0, - 10, 60, 0, 0, 0, 0, 0, 0, - - 255, 1, 0, 0, 0, 0, 0, 0 +uint8_t notes_hat_first_dual [] = { + + 100 , 0 , 131 , 95 , 0 , 0 , 135 , 0 , + 10 , 1 , 0 , 95 , 0 , 0 , 0 , 0 , + 100 , 2 , 130 , 0 , 0 , 0 , 0 , 0 , + 10 , 1 , 131 , 95 , 0 , 0 , 0 , 0 , + 200 , 100 , 135 , 95 , 0 , 135 , 0 , 0 , + 10 , 4 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 2 , 0 , 0 , 0 , 0 , 0 , 0 , + 10 , 4 , 137 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 100 , 135 , 95 , 0 , 0 , 0 , 0 , + 100 , 1 , 140 , 95 , 0 , 0 , 0 , 0 , + 20 , 3 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 100 , 142 , 95 , 0 , 0 , 0 , 0 , + 10 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 2 , 128 , 95 , 0 , 0 , 0 , 0 , + 10 , 60 , 0 , 0 , 0 , 0 , 0 , 0 , + + 100 , 0 , 131 , 95 , 0 , 0 , 135 , 137 , + 10 , 1 , 0 , 95 , 0 , 0 , 0 , 0 , + 100 , 2 , 130 , 0 , 0 , 0 , 0 , 0 , + 10 , 1 , 131 , 95 , 0 , 0 , 0 , 0 , + 200 , 100 , 135 , 95 , 0 , 0 , 0 , 0 , + 10 , 4 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 2 , 0 , 0 , 0 , 0 , 0 , 0 , + 10 , 4 , 137 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 100 , 135 , 95 , 0 , 0 , 0 , 0 , + 100 , 1 , 140 , 95 , 0 , 0 , 0 , 0 , + 20 , 3 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 100 , 142 , 95 , 0 , 0 , 0 , 0 , + 10 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 2 , 128 , 95 , 0 , 0 , 0 , 0 , + 10 , 60 , 0 , 0 , 0 , 0 , 0 , 0 , + + 100 , 0 , 131 , 95 , 0 , 0 , 135 , 140 , + 10 , 1 , 0 , 95 , 0 , 0 , 0 , 0 , + 100 , 2 , 130 , 0 , 0 , 0 , 0 , 0 , + 10 , 1 , 131 , 95 , 0 , 0 , 0 , 0 , + 200 , 100 , 135 , 95 , 0 , 0 , 0 , 0 , + 10 , 4 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 2 , 0 , 0 , 0 , 0 , 0 , 0 , + 10 , 4 , 137 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 100 , 135 , 95 , 0 , 0 , 0 , 0 , + 100 , 1 , 140 , 95 , 0 , 0 , 0 , 0 , + 20 , 3 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 100 , 142 , 95 , 0 , 0 , 0 , 0 , + 10 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 2 , 128 , 95 , 0 , 0 , 0 , 0 , + 10 , 60 , 0 , 0 , 0 , 0 , 0 , 0 , + + 100 , 0 , 131 , 95 , 2 , 159 , 135 , 142 , + 10 , 1 , 0 , 95 , 0 , 0 , 0 , 0 , + 100 , 2 , 130 , 0 , 0 , 0 , 0 , 0 , + 10 , 1 , 131 , 95 , 0 , 0 , 0 , 0 , + 200 , 100 , 135 , 95 , 0 , 0 , 0 , 0 , + 10 , 4 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 2 , 0 , 0 , 0 , 0 , 0 , 0 , + 10 , 4 , 137 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 100 , 135 , 95 , 0 , 0 , 0 , 0 , + 100 , 1 , 140 , 95 , 0 , 0 , 0 , 0 , + 20 , 3 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 100 , 142 , 95 , 0 , 0 , 0 , 0 , + 10 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 2 , 128 , 95 , 0 , 0 , 0 , 0 , + 10 , 60 , 0 , 0 , 0 , 0 , 0 , 0 , + + 255 , 1 , 0 , 0 , 0 , 0 , 0 , 0 }; -uint8_t notes_hat_first2_dual[] = -{ - 100, 0, 130, 99, 0, 140, 135, 142, - 10, 1, 0, 99, 0, 0, 0, 0, - 100, 2, 128, 0, 0, 0, 0, 0, - 10, 1, 130, 99, 0, 0, 0, 0, - 200, 100, 135, 99, 0, 0, 0, 0, - 10, 4, 0, 0, 0, 0, 0, 0, - 20, 2, 0, 0, 0, 0, 0, 0, - 10, 4, 137, 0, 2, 0, 0, 0, - 100, 0, 0, 0, 0, 0, 0, 0, - 200, 100, 130, 99, 0, 0, 0, 0, - 100, 1, 138, 99, 0, 0, 0, 0, - 20, 3, 0, 0, 0, 0, 0, 0, - 200, 100, 142, 99, 0, 0, 0, 0, - 10, 1, 0, 0, 0, 0, 0, 0, - 20, 2, 123, 99, 0, 0, 0, 0, - 10, 60, 0, 0, 0, 0, 0, 0, - 255, 1, 0, 0, 0, 0, 0, 0 +uint8_t notes_hat_first2_dual [] = { + + 100 , 0 , 130 , 99 , 0 , 140 , 135 , 142 , + 10 , 1 , 0 , 99 , 0 , 0 , 0 , 0 , + 100 , 2 , 128 , 0 , 0 , 0 , 0 , 0 , + 10 , 1 , 130 , 99 , 0 , 0 , 0 , 0 , + 200 , 100 , 135 , 99 , 0 , 0 , 0 , 0 , + 10 , 4 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 2 , 0 , 0 , 0 , 0 , 0 , 0 , + 10 , 4 , 137 , 0 , 2 , 0 , 0 , 0 , + 100 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 100 , 130 , 99 , 0 , 0 , 0 , 0 , + 100 , 1 , 138 , 99 , 0 , 0 , 0 , 0 , + 20 , 3 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 100 , 142 , 99 , 0 , 0 , 0 , 0 , + 10 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 2 , 123 , 99 , 0 , 0 , 0 , 0 , + 10 , 60 , 0 , 0 , 0 , 0 , 0 , 0 , + 255 , 1 , 0 , 0 , 0 , 0 , 0 , 0 }; -uint8_t notes_hat_first3_dual[] = -{ - 100, 0, 130, 99, 0, 0, 0, 0, - 10, 1, 0, 99, 0, 0, 0, 0, - 100, 2, 128, 0, 0, 0, 0, 0, - 10, 1, 130, 99, 0, 0, 0, 0, - 200, 100, 135, 99, 0, 0, 0, 0, - 10, 4, 0, 0, 0, 0, 0, 0, - 20, 2, 0, 0, 0, 142, 0, 0, - 10, 4, 137, 0, 0, 0, 0, 0, - 100, 0, 0, 0, 0, 0, 0, 0, - 200, 100, 130, 99, 0, 0, 0, 0, - 100, 1, 138, 99, 0, 0, 0, 0, - 20, 3, 0, 0, 0, 0, 0, 0, - 200, 100, 142, 99, 0, 0, 0, 0, - 10, 1, 0, 0, 0, 0, 0, 0, - 20, 2, 123, 99, 0, 0, 0, 0, - 10, 60, 0, 0, 0, 0, 0, 0, - 255, 1, 0, 0, 0, 0, 0, 0 +uint8_t notes_hat_first3_dual [] = { + + 100 , 0 , 130 , 99 , 0 , 0 , 0 , 0 , + 10 , 1 , 0 , 99 , 0 , 0 , 0 , 0 , + 100 , 2 , 128 , 0 , 0 , 0 , 0 , 0 , + 10 , 1 , 130 , 99 , 0 , 0 , 0 , 0 , + 200 , 100 , 135 , 99 , 0 , 0 , 0 , 0 , + 10 , 4 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 2 , 0 , 0 , 0 , 142 , 0 , 0 , + 10 , 4 , 137 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 100 , 130 , 99 , 0 , 0 , 0 , 0 , + 100 , 1 , 138 , 99 , 0 , 0 , 0 , 0 , + 20 , 3 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 100 , 142 , 99 , 0 , 0 , 0 , 0 , + 10 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 2 , 123 , 99 , 0 , 0 , 0 , 0 , + 10 , 60 , 0 , 0 , 0 , 0 , 0 , 0 , + 255 , 1 , 0 , 0 , 0 , 0 , 0 , 0 }; -uint8_t notes_hat_first_dual2[] = -{ - 100, 0, 130, 95, 0, 0, 131, 138, - 10, 1, 0, 95, 0, 0, 0, 0, - 100, 2, 128, 119, 0, 0, 0, 0, - 10, 1, 130, 95, 0, 0, 0, 0, - 200, 100, 135, 95, 0, 0, 0, 0, - 10, 4, 0, 0, 0, 0, 0, 0, - 20, 2, 0, 131, 0, 138, 0, 0, - 10, 4, 137, 119, 0, 0, 0, 0, - 100, 0, 0, 0, 0, 0, 0, 0, - 200, 100, 130, 95, 0, 0, 0, 0, - 100, 1, 138, 95, 0, 0, 0, 0, - 20, 3, 0, 0, 0, 0, 0, 0, - 200, 100, 142, 95, 0, 0, 0, 0, - 10, 1, 0, 119, 0, 0, 0, 0, - 20, 2, 123, 95, 0, 0, 0, 0, - 10, 60, 0, 0, 0, 0, 0, 0, - 255, 1, 0, 0, 0, 0, 0, 0 +uint8_t notes_hat_first_dual2 [] = { + + 100 , 0 , 130 , 95 , 0 , 0 , 131 , 138 , + 10 , 1 , 0 , 95 , 0 , 0 , 0 , 0 , + 100 , 2 , 128 , 119 , 0 , 0 , 0 , 0 , + 10 , 1 , 130 , 95 , 0 , 0 , 0 , 0 , + 200 , 100 , 135 , 95 , 0 , 0 , 0 , 0 , + 10 , 4 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 2 , 0 , 131 , 0 , 138 , 0 , 0 , + 10 , 4 , 137 , 119 , 0 , 0 , 0 , 0 , + 100 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 100 , 130 , 95 , 0 , 0 , 0 , 0 , + 100 , 1 , 138 , 95 , 0 , 0 , 0 , 0 , + 20 , 3 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 100 , 142 , 95 , 0 , 0 , 0 , 0 , + 10 , 1 , 0 , 119 , 0 , 0 , 0 , 0 , + 20 , 2 , 123 , 95 , 0 , 0 , 0 , 0 , + 10 , 60 , 0 , 0 , 0 , 0 , 0 , 0 , + 255 , 1 , 0 , 0 , 0 , 0 , 0 , 0 }; -uint8_t notes_end[] = -{ - 100, 0, 130, 0, 0, 0, 130, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - 100, 0, 128, 0, 0, 0, 0, 0, - 10, 0, 130, 0, 0, 0, 0, 0, - 200, 0, 135, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - 20, 0, 0, 0, 0, 0, 0, 0, - 10, 0, 137, 0, 0, 0, 0, 0, - 100, 0, 0, 0, 0, 0, 0, 0, - 200, 0, 130, 0, 0, 0, 0, 0, - 100, 0, 138, 0, 0, 0, 0, 0, - 20, 0, 0, 0, 0, 0, 0, 0, - 200, 0, 142, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - 20, 0, 123, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - - 100, 0, 130, 0, 0, 0, 0, 128, - 10, 0, 0, 0, 0, 0, 0, 0, - 100, 0, 128, 0, 0, 0, 0, 0, - 10, 0, 130, 0, 0, 0, 0, 0, - 200, 0, 135, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - 20, 0, 0, 0, 0, 0, 0, 0, - 10, 0, 137, 0, 0, 0, 0, 0, - 100, 0, 0, 0, 0, 0, 0, 0, - 200, 0, 130, 0, 0, 0, 0, 0, - 100, 0, 138, 0, 0, 0, 0, 0, - 20, 0, 0, 0, 0, 0, 0, 0, - 200, 0, 142, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - 20, 0, 123, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - - 100, 0, 130, 0, 0, 125, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - 100, 0, 128, 0, 0, 0, 0, 0, - 10, 0, 130, 0, 0, 0, 0, 0, - 200, 0, 135, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - 20, 0, 0, 0, 0, 0, 0, 0, - 10, 0, 137, 0, 0, 0, 0, 0, - 100, 0, 0, 0, 0, 0, 0, 0, - 200, 0, 130, 0, 0, 0, 0, 0, - 100, 0, 138, 0, 0, 0, 0, 0, - 20, 0, 0, 0, 0, 0, 0, 0, - 200, 0, 142, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - 20, 0, 123, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - - 100, 0, 130, 0, 0, 118, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - 100, 0, 128, 0, 0, 0, 0, 0, - 10, 0, 130, 0, 0, 0, 0, 0, - 200, 0, 135, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - 20, 0, 0, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - 5, 0, 0, 0, 0, 0, 0, 0, - 1, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 1, 0, 0, 0, 0, 0, 0, 0, - 2, 0, 0, 0, 0, 0, 0, 0, - 4, 0, 0, 0, 0, 0, 0, 0, - - 255, 0, 0, 0, 0, 0, 0, 0 +uint8_t notes_end [] = { + + 100 , 0 , 130 , 0 , 0 , 0 , 130 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 128 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 130 , 0 , 0 , 0 , 0 , 0 , + 200 , 0 , 135 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 137 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 0 , 130 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 138 , 0 , 0 , 0 , 0 , 0 , + 20 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 0 , 142 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 0 , 123 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + + 100 , 0 , 130 , 0 , 0 , 0 , 0 , 128 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 128 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 130 , 0 , 0 , 0 , 0 , 0 , + 200 , 0 , 135 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 137 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 0 , 130 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 138 , 0 , 0 , 0 , 0 , 0 , + 20 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 0 , 142 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 0 , 123 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + + 100 , 0 , 130 , 0 , 0 , 125 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 128 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 130 , 0 , 0 , 0 , 0 , 0 , + 200 , 0 , 135 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 137 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 0 , 130 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 138 , 0 , 0 , 0 , 0 , 0 , + 20 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 0 , 142 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 0 , 123 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + + 100 , 0 , 130 , 0 , 0 , 118 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 128 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 130 , 0 , 0 , 0 , 0 , 0 , + 200 , 0 , 135 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 5 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 2 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 4 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + + 255 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }; -uint8_t notes_preend[] = -{ - 100, 0, 130, 0, 0, 0, 130, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - 100, 0, 128, 0, 0, 0, 0, 0, - 10, 0, 130, 0, 0, 0, 0, 0, - 200, 0, 135, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - 20, 0, 0, 0, 0, 0, 0, 0, - 10, 0, 137, 0, 0, 0, 0, 0, - 100, 0, 0, 0, 0, 0, 0, 0, - 200, 0, 130, 0, 0, 0, 0, 0, - 100, 0, 138, 0, 0, 0, 0, 0, - 20, 0, 0, 0, 0, 0, 0, 0, - 200, 0, 142, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - 20, 0, 123, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - - 100, 0, 130, 0, 0, 0, 0, 128, - 10, 0, 0, 0, 0, 0, 0, 0, - 100, 0, 128, 0, 0, 0, 0, 0, - 10, 0, 130, 0, 0, 0, 0, 0, - 200, 0, 135, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - 20, 0, 0, 0, 0, 0, 0, 0, - 10, 0, 137, 0, 0, 0, 0, 0, - 100, 0, 0, 0, 0, 0, 0, 0, - 200, 0, 130, 0, 0, 0, 0, 0, - 100, 0, 138, 0, 0, 0, 0, 0, - 20, 0, 0, 0, 0, 0, 0, 0, - 200, 0, 142, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - 20, 0, 123, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - - 100, 0, 130, 0, 0, 125, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - 100, 0, 128, 0, 0, 0, 0, 0, - 10, 0, 130, 0, 0, 0, 0, 0, - 200, 0, 135, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - 20, 0, 0, 0, 0, 0, 0, 0, - 10, 0, 137, 0, 0, 0, 0, 0, - 100, 0, 0, 0, 0, 0, 0, 0, - 200, 0, 130, 0, 0, 0, 0, 0, - 100, 0, 138, 0, 0, 0, 0, 0, - 20, 0, 0, 0, 0, 0, 0, 0, - 200, 0, 142, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - 20, 0, 123, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - - 100, 0, 130, 0, 0, 118, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - 100, 0, 128, 0, 0, 0, 0, 0, - 10, 0, 130, 0, 0, 0, 0, 0, - 200, 0, 135, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - 20, 0, 0, 0, 0, 0, 0, 0, - 10, 0, 137, 0, 0, 0, 0, 0, - 100, 0, 0, 0, 0, 0, 0, 0, - 200, 0, 130, 0, 0, 0, 0, 0, - 100, 0, 138, 0, 0, 0, 0, 0, - 20, 0, 0, 0, 0, 0, 0, 0, - 200, 0, 142, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - 20, 0, 123, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, - - 255, 0, 0, 0, 0, 0, 0, 0 +uint8_t notes_preend [] = { + + 100 , 0 , 130 , 0 , 0 , 0 , 130 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 128 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 130 , 0 , 0 , 0 , 0 , 0 , + 200 , 0 , 135 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 137 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 0 , 130 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 138 , 0 , 0 , 0 , 0 , 0 , + 20 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 0 , 142 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 0 , 123 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + + 100 , 0 , 130 , 0 , 0 , 0 , 0 , 128 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 128 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 130 , 0 , 0 , 0 , 0 , 0 , + 200 , 0 , 135 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 137 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 0 , 130 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 138 , 0 , 0 , 0 , 0 , 0 , + 20 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 0 , 142 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 0 , 123 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + + 100 , 0 , 130 , 0 , 0 , 125 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 128 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 130 , 0 , 0 , 0 , 0 , 0 , + 200 , 0 , 135 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 137 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 0 , 130 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 138 , 0 , 0 , 0 , 0 , 0 , + 20 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 0 , 142 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 0 , 123 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + + 100 , 0 , 130 , 0 , 0 , 118 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 128 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 130 , 0 , 0 , 0 , 0 , 0 , + 200 , 0 , 135 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 137 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 0 , 130 , 0 , 0 , 0 , 0 , 0 , + 100 , 0 , 138 , 0 , 0 , 0 , 0 , 0 , + 20 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 200 , 0 , 142 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + 20 , 0 , 123 , 0 , 0 , 0 , 0 , 0 , + 10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , + + 255 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }; //=-=-=-= -uint8_t part2[] = -{ - 100, 253, 0, 97, 4, 0, 135, 253, -// 100, 253, 0, 97, 4, 0, 0, 0, - 10, 1, 0, 99, 0, 0, 0, 0, - 100, 2, 0, 99, 0, 0, 0, 0, - 10, 1, 0, 97, 0, 0, 0, 0, - 200, 100, 0, 99, 0, 0, 0, 0, - 10, 4, 0, 99, 0, 0, 0, 0, - 20, 2, 0, 97, 0, 0, 0, 0, - 10, 4, 0, 99, 0, 0, 0, 0, - 100, 0, 0, 99, 0, 0, 0, 0, - 200, 100, 0, 97, 0, 0, 0, 0, - 100, 1, 0, 99, 0, 0, 0, 0, - 20, 3, 0, 97, 0, 0, 0, 0, - 200, 100, 0, 99, 0, 0, 0, 0, - 10, 1, 0, 99, 0, 0, 0, 0, - 20, 2, 0, 99, 0, 0, 0, 0, - 10, 60, 0, 99, 0, 0, 0, 0, - - 100, 0, 000, 97, 1, 0, 135, 0, -// 100, 0, 000, 97, 1, 0, 0, 0, - 10, 1, 000, 99, 0, 0, 0, 0, - 100, 2, 00, 99, 0, 0, 0, 0, - 10, 1, 000, 97, 0, 0, 0, 0, - 200, 100, 135, 99, 0, 0, 0, 0, - 10, 4, 0, 99, 0, 0, 0, 0, - 20, 2, 00, 97, 0, 0, 0, 0, - 10, 4, 00, 99, 0, 0, 0, 0, - 100, 0, 0, 99, 0, 0, 0, 0, - 200, 100, 000, 97, 0, 140, 0, 0, - 100, 1, 000, 99, 0, 0, 0, 0, - 20, 3, 00, 97, 0, 0, 0, 0, - 200, 100, 000, 99, 0, 0, 0, 0, - 10, 1, 0, 99, 0, 0, 0, 0, - 20, 2, 000, 99, 0, 0, 0, 0, - 10, 60, 000, 99, 0, 0, 0, 0, - - 100, 0, 0, 93, 0, 138, 135, 142, - 10, 1, 0, 95, 0, 0, 0, 0, - 100, 2, 0, 95, 0, 0, 0, 0, - 10, 1, 0, 93, 0, 0, 0, 0, - 200, 100, 0, 95, 0, 0, 0, 0, - 10, 4, 0, 95, 0, 0, 0, 0, - 20, 2, 0, 93, 0, 0, 0, 0, - 10, 4, 0, 95, 0, 0, 0, 0, - 100, 0, 0, 95, 0, 0, 0, 0, - 200, 100, 0, 95, 0, 0, 0, 0, - 100, 1, 0, 95, 0, 0, 0, 0, - 20, 3, 0, 95, 0, 0, 0, 0, - 200, 100, 0, 93, 0, 0, 0, 0, - 10, 1, 0, 95, 0, 0, 0, 0, - 20, 2, 0, 93, 0, 0, 0, 0, - 10, 60, 0, 95, 0, 0, 0, 0, - - 100, 0, 0, 93, 0, 0, 135, 140, - 10, 1, 0, 95, 0, 0, 0, 0, - 100, 2, 0, 0, 0, 0, 0, 0, - 10, 1, 00, 95, 0, 0, 0, 0, - 200, 100, 0, 93, 0, 0, 0, 0, - 10, 4, 0, 95, 0, 0, 0, 0, - 20, 2, 0, 95, 0, 0, 0, 0, - 10, 4, 0, 93, 2, 0, 0, 0, - 100, 0, 0, 95, 0, 0, 0, 0, - 200, 100, 0, 93, 0, 0, 0, 0, - 100, 1, 0, 95, 0, 0, 0, 0, - 20, 3, 0, 95, 0, 0, 0, 0, - 200, 100, 0, 93, 0, 0, 0, 0, - 10, 1, 0, 95, 0, 0, 0, 0, - 20, 2, 0, 93, 0, 0, 0, 0, - 10, 60, 0, 95, 0, 0, 0, 0, - - 255, 1, 99, 0, 0, 0, 0, 0 +uint8_t part2 [] = { + + 100 , 253 , 0 , 97 , 4 , 0 , 135 , 253 , + 10 , 1 , 0 , 99 , 0 , 0 , 0 , 0 , + 100 , 2 , 0 , 99 , 0 , 0 , 0 , 0 , + 10 , 1 , 0 , 97 , 0 , 0 , 0 , 0 , + 200 , 100 , 0 , 99 , 0 , 0 , 0 , 0 , + 10 , 4 , 0 , 99 , 0 , 0 , 0 , 0 , + 20 , 2 , 0 , 97 , 0 , 0 , 0 , 0 , + 10 , 4 , 0 , 99 , 0 , 0 , 0 , 0 , + 100 , 0 , 0 , 99 , 0 , 0 , 0 , 0 , + 200 , 100 , 0 , 97 , 0 , 0 , 0 , 0 , + 100 , 1 , 0 , 99 , 0 , 0 , 0 , 0 , + 20 , 3 , 0 , 97 , 0 , 0 , 0 , 0 , + 200 , 100 , 0 , 99 , 0 , 0 , 0 , 0 , + 10 , 1 , 0 , 99 , 0 , 0 , 0 , 0 , + 20 , 2 , 0 , 99 , 0 , 0 , 0 , 0 , + 10 , 60 , 0 , 99 , 0 , 0 , 0 , 0 , + + 100 , 0 , 000 , 97 , 1 , 0 , 135 , 0 , + 10 , 1 , 000 , 99 , 0 , 0 , 0 , 0 , + 100 , 2 , 00 , 99 , 0 , 0 , 0 , 0 , + 10 , 1 , 000 , 97 , 0 , 0 , 0 , 0 , + 200 , 100 , 135 , 99 , 0 , 0 , 0 , 0 , + 10 , 4 , 0 , 99 , 0 , 0 , 0 , 0 , + 20 , 2 , 00 , 97 , 0 , 0 , 0 , 0 , + 10 , 4 , 00 , 99 , 0 , 0 , 0 , 0 , + 100 , 0 , 0 , 99 , 0 , 0 , 0 , 0 , + 200 , 100 , 000 , 97 , 0 , 140 , 0 , 0 , + 100 , 1 , 000 , 99 , 0 , 0 , 0 , 0 , + 20 , 3 , 00 , 97 , 0 , 0 , 0 , 0 , + 200 , 100 , 000 , 99 , 0 , 0 , 0 , 0 , + 10 , 1 , 0 , 99 , 0 , 0 , 0 , 0 , + 20 , 2 , 000 , 99 , 0 , 0 , 0 , 0 , + 10 , 60 , 000 , 99 , 0 , 0 , 0 , 0 , + + 100 , 0 , 0 , 93 , 0 , 138 , 135 , 142 , + 10 , 1 , 0 , 95 , 0 , 0 , 0 , 0 , + 100 , 2 , 0 , 95 , 0 , 0 , 0 , 0 , + 10 , 1 , 0 , 93 , 0 , 0 , 0 , 0 , + 200 , 100 , 0 , 95 , 0 , 0 , 0 , 0 , + 10 , 4 , 0 , 95 , 0 , 0 , 0 , 0 , + 20 , 2 , 0 , 93 , 0 , 0 , 0 , 0 , + 10 , 4 , 0 , 95 , 0 , 0 , 0 , 0 , + 100 , 0 , 0 , 95 , 0 , 0 , 0 , 0 , + 200 , 100 , 0 , 95 , 0 , 0 , 0 , 0 , + 100 , 1 , 0 , 95 , 0 , 0 , 0 , 0 , + 20 , 3 , 0 , 95 , 0 , 0 , 0 , 0 , + 200 , 100 , 0 , 93 , 0 , 0 , 0 , 0 , + 10 , 1 , 0 , 95 , 0 , 0 , 0 , 0 , + 20 , 2 , 0 , 93 , 0 , 0 , 0 , 0 , + 10 , 60 , 0 , 95 , 0 , 0 , 0 , 0 , + + 100 , 0 , 0 , 93 , 0 , 0 , 135 , 140 , + 10 , 1 , 0 , 95 , 0 , 0 , 0 , 0 , + 100 , 2 , 0 , 0 , 0 , 0 , 0 , 0 , + 10 , 1 , 00 , 95 , 0 , 0 , 0 , 0 , + 200 , 100 , 0 , 93 , 0 , 0 , 0 , 0 , + 10 , 4 , 0 , 95 , 0 , 0 , 0 , 0 , + 20 , 2 , 0 , 95 , 0 , 0 , 0 , 0 , + 10 , 4 , 0 , 93 , 2 , 0 , 0 , 0 , + 100 , 0 , 0 , 95 , 0 , 0 , 0 , 0 , + 200 , 100 , 0 , 93 , 0 , 0 , 0 , 0 , + 100 , 1 , 0 , 95 , 0 , 0 , 0 , 0 , + 20 , 3 , 0 , 95 , 0 , 0 , 0 , 0 , + 200 , 100 , 0 , 93 , 0 , 0 , 0 , 0 , + 10 , 1 , 0 , 95 , 0 , 0 , 0 , 0 , + 20 , 2 , 0 , 93 , 0 , 0 , 0 , 0 , + 10 , 60 , 0 , 95 , 0 , 0 , 0 , 0 , + + 255 , 1 , 99 , 0 , 0 , 0 , 0 , 0 }; -uint8_t part3[] = -{ - 100, 0, 0, 97, 3, 0, 135, 139, - 10, 1, 0, 99, 0, 0, 0, 0, - 100, 2, 0, 99, 0, 0, 0, 0, - 10, 1, 0, 97, 0, 0, 0, 0, - 200, 100, 0, 99, 0, 0, 0, 0, - 10, 4, 0, 99, 0, 0, 0, 0, - 20, 2, 0, 97, 0, 139, 0, 0, - 10, 4, 0, 99, 0, 0, 0, 0, - 100, 0, 0, 99, 0, 0, 0, 0, - 200, 100, 0, 97, 0, 0, 0, 0, - 100, 1, 0, 99, 0, 0, 0, 0, - 20, 3, 0, 97, 0, 0, 0, 0, - 200, 100, 0, 99, 0, 0, 0, 0, - 10, 1, 0, 99, 0, 0, 0, 0, - 20, 2, 0, 99, 0, 0, 0, 0, - 10, 60, 0, 99, 0, 0, 0, 0, - - 100, 0, 000, 97, 1, 0, 135, 0, - 10, 1, 000, 99, 0, 0, 0, 0, - 100, 2, 00, 99, 0, 0, 0, 0, - 10, 1, 000, 97, 0, 0, 0, 0, - 200, 100, 0, 99, 0, 0, 0, 0, - 10, 4, 0, 99, 0, 0, 0, 0, - 20, 2, 00, 97, 0, 0, 0, 0, - 10, 4, 00, 99, 0, 0, 0, 0, - 100, 0, 0, 99, 0, 0, 0, 0, - 200, 100, 000, 97, 0, 140, 0, 0, - 100, 1, 000, 99, 0, 0, 0, 0, - 20, 3, 00, 97, 0, 0, 0, 0, - 200, 100, 000, 99, 0, 0, 0, 0, - 10, 1, 0, 99, 0, 0, 0, 0, - 20, 2, 000, 99, 0, 0, 0, 0, - 10, 60, 000, 99, 0, 0, 0, 0, - - 100, 0, 0, 93, 0, 138, 135, 142, - 10, 1, 0, 95, 0, 0, 0, 0, - 100, 2, 0, 95, 0, 0, 0, 0, - 10, 1, 0, 93, 0, 0, 0, 0, - 200, 100, 0, 95, 0, 0, 0, 0, - 10, 4, 0, 95, 0, 0, 0, 0, - 20, 2, 0, 93, 0, 0, 0, 0, - 10, 4, 0, 95, 0, 0, 0, 0, - 100, 0, 0, 95, 0, 0, 0, 0, - 200, 100, 0, 95, 0, 0, 0, 0, - 100, 1, 0, 95, 0, 0, 0, 0, - 20, 3, 0, 95, 0, 0, 0, 0, - 200, 100, 0, 93, 0, 0, 0, 0, - 10, 1, 0, 95, 0, 0, 0, 0, - 20, 2, 0, 93, 0, 0, 0, 0, - 10, 60, 0, 95, 0, 0, 0, 0, - - 100, 0, 0, 93, 0, 0, 135, 140, - 10, 1, 0, 95, 0, 0, 0, 0, - 100, 2, 0, 0, 0, 0, 0, 0, - 10, 1, 00, 95, 0, 0, 0, 0, - 200, 100, 0, 93, 0, 0, 0, 0, - 10, 4, 0, 95, 0, 0, 0, 0, - 20, 2, 0, 95, 0, 0, 0, 0, - 10, 4, 0, 93, 2, 0, 0, 0, - 100, 0, 0, 95, 0, 0, 0, 0, - 200, 100, 0, 93, 0, 0, 0, 0, - 100, 1, 0, 95, 0, 0, 0, 0, - 20, 3, 0, 95, 0, 0, 0, 0, - 200, 100, 0, 93, 0, 0, 0, 0, - 10, 1, 0, 95, 0, 0, 0, 0, - 20, 2, 0, 93, 0, 0, 0, 0, - 10, 60, 0, 95, 0, 0, 0, 0, - - 255, 1, 99, 0, 0, 0, 0, 0 +uint8_t part3 [] = { + + 100 , 0 , 0 , 97 , 3 , 0 , 135 , 139 , + 10 , 1 , 0 , 99 , 0 , 0 , 0 , 0 , + 100 , 2 , 0 , 99 , 0 , 0 , 0 , 0 , + 10 , 1 , 0 , 97 , 0 , 0 , 0 , 0 , + 200 , 100 , 0 , 99 , 0 , 0 , 0 , 0 , + 10 , 4 , 0 , 99 , 0 , 0 , 0 , 0 , + 20 , 2 , 0 , 97 , 0 , 139 , 0 , 0 , + 10 , 4 , 0 , 99 , 0 , 0 , 0 , 0 , + 100 , 0 , 0 , 99 , 0 , 0 , 0 , 0 , + 200 , 100 , 0 , 97 , 0 , 0 , 0 , 0 , + 100 , 1 , 0 , 99 , 0 , 0 , 0 , 0 , + 20 , 3 , 0 , 97 , 0 , 0 , 0 , 0 , + 200 , 100 , 0 , 99 , 0 , 0 , 0 , 0 , + 10 , 1 , 0 , 99 , 0 , 0 , 0 , 0 , + 20 , 2 , 0 , 99 , 0 , 0 , 0 , 0 , + 10 , 60 , 0 , 99 , 0 , 0 , 0 , 0 , + + 100 , 0 , 000 , 97 , 1 , 0 , 135 , 0 , + 10 , 1 , 000 , 99 , 0 , 0 , 0 , 0 , + 100 , 2 , 00 , 99 , 0 , 0 , 0 , 0 , + 10 , 1 , 000 , 97 , 0 , 0 , 0 , 0 , + 200 , 100 , 0 , 99 , 0 , 0 , 0 , 0 , + 10 , 4 , 0 , 99 , 0 , 0 , 0 , 0 , + 20 , 2 , 00 , 97 , 0 , 0 , 0 , 0 , + 10 , 4 , 00 , 99 , 0 , 0 , 0 , 0 , + 100 , 0 , 0 , 99 , 0 , 0 , 0 , 0 , + 200 , 100 , 000 , 97 , 0 , 140 , 0 , 0 , + 100 , 1 , 000 , 99 , 0 , 0 , 0 , 0 , + 20 , 3 , 00 , 97 , 0 , 0 , 0 , 0 , + 200 , 100 , 000 , 99 , 0 , 0 , 0 , 0 , + 10 , 1 , 0 , 99 , 0 , 0 , 0 , 0 , + 20 , 2 , 000 , 99 , 0 , 0 , 0 , 0 , + 10 , 60 , 000 , 99 , 0 , 0 , 0 , 0 , + + 100 , 0 , 0 , 93 , 0 , 138 , 135 , 142 , + 10 , 1 , 0 , 95 , 0 , 0 , 0 , 0 , + 100 , 2 , 0 , 95 , 0 , 0 , 0 , 0 , + 10 , 1 , 0 , 93 , 0 , 0 , 0 , 0 , + 200 , 100 , 0 , 95 , 0 , 0 , 0 , 0 , + 10 , 4 , 0 , 95 , 0 , 0 , 0 , 0 , + 20 , 2 , 0 , 93 , 0 , 0 , 0 , 0 , + 10 , 4 , 0 , 95 , 0 , 0 , 0 , 0 , + 100 , 0 , 0 , 95 , 0 , 0 , 0 , 0 , + 200 , 100 , 0 , 95 , 0 , 0 , 0 , 0 , + 100 , 1 , 0 , 95 , 0 , 0 , 0 , 0 , + 20 , 3 , 0 , 95 , 0 , 0 , 0 , 0 , + 200 , 100 , 0 , 93 , 0 , 0 , 0 , 0 , + 10 , 1 , 0 , 95 , 0 , 0 , 0 , 0 , + 20 , 2 , 0 , 93 , 0 , 0 , 0 , 0 , + 10 , 60 , 0 , 95 , 0 , 0 , 0 , 0 , + + 100 , 0 , 0 , 93 , 0 , 0 , 135 , 140 , + 10 , 1 , 0 , 95 , 0 , 0 , 0 , 0 , + 100 , 2 , 0 , 0 , 0 , 0 , 0 , 0 , + 10 , 1 , 00 , 95 , 0 , 0 , 0 , 0 , + 200 , 100 , 0 , 93 , 0 , 0 , 0 , 0 , + 10 , 4 , 0 , 95 , 0 , 0 , 0 , 0 , + 20 , 2 , 0 , 95 , 0 , 0 , 0 , 0 , + 10 , 4 , 0 , 93 , 2 , 0 , 0 , 0 , + 100 , 0 , 0 , 95 , 0 , 0 , 0 , 0 , + 200 , 100 , 0 , 93 , 0 , 0 , 0 , 0 , + 100 , 1 , 0 , 95 , 0 , 0 , 0 , 0 , + 20 , 3 , 0 , 95 , 0 , 0 , 0 , 0 , + 200 , 100 , 0 , 93 , 0 , 0 , 0 , 0 , + 10 , 1 , 0 , 95 , 0 , 0 , 0 , 0 , + 20 , 2 , 0 , 93 , 0 , 0 , 0 , 0 , + 10 , 60 , 0 , 95 , 0 , 0 , 0 , 0 , + + 255 , 1 , 99 , 0 , 0 , 0 , 0 , 0 }; -uint8_t part4[] = -{ - 100, 254, 0, 97, 3, 0, 135, 139, - 10, 1, 0, 99, 0, 0, 0, 0, - 100, 2, 0, 99, 0, 0, 0, 0, - 10, 1, 0, 97, 0, 0, 0, 0, - 200, 100, 0, 99, 0, 0, 0, 0, - 10, 4, 0, 99, 0, 0, 0, 0, - 20, 2, 0, 97, 0, 139, 0, 0, - 10, 4, 0, 99, 0, 0, 0, 0, - 100, 0, 0, 99, 0, 0, 0, 0, - 200, 100, 0, 97, 0, 0, 0, 0, - 100, 1, 0, 99, 0, 0, 0, 0, - 20, 3, 0, 97, 0, 0, 0, 0, - 200, 100, 0, 99, 0, 0, 0, 0, - 10, 1, 0, 99, 0, 0, 0, 0, - 20, 2, 0, 99, 0, 0, 0, 0, - 10, 60, 0, 99, 0, 0, 0, 0, - - 100, 0, 000, 97, 1, 0, 135, 0, - 10, 1, 000, 99, 0, 0, 0, 0, - 100, 2, 00, 99, 0, 0, 0, 0, - 10, 1, 000, 97, 0, 0, 0, 0, - 200, 100, 0, 99, 0, 0, 0, 0, - 10, 4, 0, 99, 0, 0, 0, 0, - 20, 2, 00, 97, 0, 0, 0, 0, - 10, 4, 00, 99, 0, 0, 0, 0, - 100, 0, 0, 99, 0, 0, 0, 0, - 200, 100, 000, 97, 0, 140, 0, 0, - 100, 1, 000, 99, 0, 0, 0, 0, - 20, 3, 00, 97, 0, 0, 0, 0, - 200, 100, 000, 99, 0, 0, 0, 0, - 10, 1, 0, 99, 0, 0, 0, 0, - 20, 2, 000, 99, 0, 0, 0, 0, - 10, 60, 000, 99, 0, 0, 0, 0, - - 100, 0, 0, 93, 0, 138, 135, 142, - 10, 1, 0, 95, 0, 0, 0, 0, - 100, 2, 0, 95, 0, 0, 0, 0, - 10, 1, 0, 93, 0, 0, 0, 0, - 200, 100, 0, 95, 0, 0, 0, 0, - 10, 4, 0, 95, 0, 0, 0, 0, - 20, 2, 0, 93, 0, 0, 0, 0, - 10, 4, 0, 95, 0, 0, 0, 0, - 100, 0, 0, 95, 0, 0, 0, 0, - 200, 100, 0, 95, 0, 0, 0, 0, - 100, 1, 0, 95, 0, 0, 0, 0, - 20, 3, 0, 95, 0, 0, 0, 0, - 200, 100, 0, 93, 0, 0, 0, 0, - 10, 1, 0, 95, 0, 0, 0, 0, - 20, 2, 0, 93, 0, 0, 0, 0, - 10, 60, 0, 95, 0, 0, 0, 0, - - 100, 0, 0, 93, 0, 0, 135, 140, - 10, 1, 0, 95, 0, 0, 0, 0, - 100, 2, 0, 0, 0, 0, 0, 0, - 10, 1, 00, 95, 0, 0, 0, 0, - 200, 100, 0, 93, 0, 0, 0, 0, - 10, 4, 0, 95, 0, 0, 0, 0, - 20, 2, 0, 95, 0, 0, 0, 0, - 10, 4, 0, 93, 2, 0, 0, 0, - 100, 0, 0, 95, 0, 0, 0, 0, - 200, 100, 0, 93, 0, 0, 0, 0, - 100, 1, 0, 95, 0, 0, 0, 0, - 20, 3, 0, 95, 0, 0, 0, 0, - 200, 100, 0, 93, 0, 0, 0, 0, - 10, 1, 0, 95, 0, 0, 0, 0, - 20, 2, 0, 93, 0, 0, 0, 0, - 10, 60, 0, 95, 0, 0, 0, 0, - - 255, 1, 99, 0, 0, 0, 0, 0 +uint8_t part4 [] = { + + 100 , 254 , 0 , 97 , 3 , 0 , 135 , 139 , + 10 , 1 , 0 , 99 , 0 , 0 , 0 , 0 , + 100 , 2 , 0 , 99 , 0 , 0 , 0 , 0 , + 10 , 1 , 0 , 97 , 0 , 0 , 0 , 0 , + 200 , 100 , 0 , 99 , 0 , 0 , 0 , 0 , + 10 , 4 , 0 , 99 , 0 , 0 , 0 , 0 , + 20 , 2 , 0 , 97 , 0 , 139 , 0 , 0 , + 10 , 4 , 0 , 99 , 0 , 0 , 0 , 0 , + 100 , 0 , 0 , 99 , 0 , 0 , 0 , 0 , + 200 , 100 , 0 , 97 , 0 , 0 , 0 , 0 , + 100 , 1 , 0 , 99 , 0 , 0 , 0 , 0 , + 20 , 3 , 0 , 97 , 0 , 0 , 0 , 0 , + 200 , 100 , 0 , 99 , 0 , 0 , 0 , 0 , + 10 , 1 , 0 , 99 , 0 , 0 , 0 , 0 , + 20 , 2 , 0 , 99 , 0 , 0 , 0 , 0 , + 10 , 60 , 0 , 99 , 0 , 0 , 0 , 0 , + + 100 , 0 , 000 , 97 , 1 , 0 , 135 , 0 , + 10 , 1 , 000 , 99 , 0 , 0 , 0 , 0 , + 100 , 2 , 00 , 99 , 0 , 0 , 0 , 0 , + 10 , 1 , 000 , 97 , 0 , 0 , 0 , 0 , + 200 , 100 , 0 , 99 , 0 , 0 , 0 , 0 , + 10 , 4 , 0 , 99 , 0 , 0 , 0 , 0 , + 20 , 2 , 00 , 97 , 0 , 0 , 0 , 0 , + 10 , 4 , 00 , 99 , 0 , 0 , 0 , 0 , + 100 , 0 , 0 , 99 , 0 , 0 , 0 , 0 , + 200 , 100 , 000 , 97 , 0 , 140 , 0 , 0 , + 100 , 1 , 000 , 99 , 0 , 0 , 0 , 0 , + 20 , 3 , 00 , 97 , 0 , 0 , 0 , 0 , + 200 , 100 , 000 , 99 , 0 , 0 , 0 , 0 , + 10 , 1 , 0 , 99 , 0 , 0 , 0 , 0 , + 20 , 2 , 000 , 99 , 0 , 0 , 0 , 0 , + 10 , 60 , 000 , 99 , 0 , 0 , 0 , 0 , + + 100 , 0 , 0 , 93 , 0 , 138 , 135 , 142 , + 10 , 1 , 0 , 95 , 0 , 0 , 0 , 0 , + 100 , 2 , 0 , 95 , 0 , 0 , 0 , 0 , + 10 , 1 , 0 , 93 , 0 , 0 , 0 , 0 , + 200 , 100 , 0 , 95 , 0 , 0 , 0 , 0 , + 10 , 4 , 0 , 95 , 0 , 0 , 0 , 0 , + 20 , 2 , 0 , 93 , 0 , 0 , 0 , 0 , + 10 , 4 , 0 , 95 , 0 , 0 , 0 , 0 , + 100 , 0 , 0 , 95 , 0 , 0 , 0 , 0 , + 200 , 100 , 0 , 95 , 0 , 0 , 0 , 0 , + 100 , 1 , 0 , 95 , 0 , 0 , 0 , 0 , + 20 , 3 , 0 , 95 , 0 , 0 , 0 , 0 , + 200 , 100 , 0 , 93 , 0 , 0 , 0 , 0 , + 10 , 1 , 0 , 95 , 0 , 0 , 0 , 0 , + 20 , 2 , 0 , 93 , 0 , 0 , 0 , 0 , + 10 , 60 , 0 , 95 , 0 , 0 , 0 , 0 , + + 100 , 0 , 0 , 93 , 0 , 0 , 135 , 140 , + 10 , 1 , 0 , 95 , 0 , 0 , 0 , 0 , + 100 , 2 , 0 , 0 , 0 , 0 , 0 , 0 , + 10 , 1 , 00 , 95 , 0 , 0 , 0 , 0 , + 200 , 100 , 0 , 93 , 0 , 0 , 0 , 0 , + 10 , 4 , 0 , 95 , 0 , 0 , 0 , 0 , + 20 , 2 , 0 , 95 , 0 , 0 , 0 , 0 , + 10 , 4 , 0 , 93 , 2 , 0 , 0 , 0 , + 100 , 0 , 0 , 95 , 0 , 0 , 0 , 0 , + 200 , 100 , 0 , 93 , 0 , 0 , 0 , 0 , + 100 , 1 , 0 , 95 , 0 , 0 , 0 , 0 , + 20 , 3 , 0 , 95 , 0 , 0 , 0 , 0 , + 200 , 100 , 0 , 93 , 0 , 0 , 0 , 0 , + 10 , 1 , 0 , 95 , 0 , 0 , 0 , 0 , + 20 , 2 , 0 , 93 , 0 , 0 , 0 , 0 , + 10 , 60 , 0 , 95 , 0 , 0 , 0 , 0 , + + 255 , 1 , 99 , 0 , 0 , 0 , 0 , 0 }; -uint8_t part5[] = -{ - 0, 0, 0, 0, 5, 0, 254, 254, - 0, 0, 0, 0, 0, 0, 253, 253, - 0, 0, 0, 0, 0, 0, 253, 253, - 0, 0, 0, 0, 0, 0, 253, 253, - 0, 0, 0, 0, 0, 0, 253, 253, - 0, 0, 0, 0, 0, 0, 253, 253, - 0, 0, 0, 0, 0, 0, 253, 253, - 0, 0, 0, 0, 0, 0, 253, 253, - 0, 0, 0, 0, 0, 0, 253, 253, - 0, 0, 0, 0, 0, 0, 253, 253, - 0, 0, 0, 0, 0, 0, 253, 253, - 0, 0, 0, 0, 0, 0, 253, 253, - 0, 0, 0, 0, 0, 0, 253, 253, - 0, 0, 0, 0, 0, 0, 253, 253, - 0, 0, 0, 0, 0, 0, 253, 253, - - 0, 0, 0, 0, 0, 0, 253, 253, - 0, 0, 0, 0, 0, 0, 253, 253, - 0, 0, 0, 0, 0, 0, 253, 253, - 0, 0, 0, 0, 0, 0, 253, 253, - 0, 0, 0, 0, 0, 0, 253, 253, - 0, 0, 0, 0, 0, 0, 253, 253, - 0, 0, 0, 0, 0, 0, 253, 253, - 0, 0, 0, 0, 0, 0, 253, 253, - 0, 0, 0, 0, 0, 0, 253, 253, - 0, 0, 0, 0, 0, 0, 253, 253, - 0, 0, 0, 0, 0, 0, 253, 253, - 0, 0, 0, 0, 0, 0, 253, 253, - 0, 0, 0, 0, 0, 0, 253, 253, - 0, 0, 0, 0, 0, 0, 253, 253, - 0, 0, 0, 0, 0, 0, 253, 253, - - 255, 1, 99, 0, 0, 0, 0, 0 +uint8_t part5 [] = { + + 0 , 0 , 0 , 0 , 5 , 0 , 254 , 254 , + 0 , 0 , 0 , 0 , 0 , 0 , 253 , 253 , + 0 , 0 , 0 , 0 , 0 , 0 , 253 , 253 , + 0 , 0 , 0 , 0 , 0 , 0 , 253 , 253 , + 0 , 0 , 0 , 0 , 0 , 0 , 253 , 253 , + 0 , 0 , 0 , 0 , 0 , 0 , 253 , 253 , + 0 , 0 , 0 , 0 , 0 , 0 , 253 , 253 , + 0 , 0 , 0 , 0 , 0 , 0 , 253 , 253 , + 0 , 0 , 0 , 0 , 0 , 0 , 253 , 253 , + 0 , 0 , 0 , 0 , 0 , 0 , 253 , 253 , + 0 , 0 , 0 , 0 , 0 , 0 , 253 , 253 , + 0 , 0 , 0 , 0 , 0 , 0 , 253 , 253 , + 0 , 0 , 0 , 0 , 0 , 0 , 253 , 253 , + 0 , 0 , 0 , 0 , 0 , 0 , 253 , 253 , + 0 , 0 , 0 , 0 , 0 , 0 , 253 , 253 , + + 0 , 0 , 0 , 0 , 0 , 0 , 253 , 253 , + 0 , 0 , 0 , 0 , 0 , 0 , 253 , 253 , + 0 , 0 , 0 , 0 , 0 , 0 , 253 , 253 , + 0 , 0 , 0 , 0 , 0 , 0 , 253 , 253 , + 0 , 0 , 0 , 0 , 0 , 0 , 253 , 253 , + 0 , 0 , 0 , 0 , 0 , 0 , 253 , 253 , + 0 , 0 , 0 , 0 , 0 , 0 , 253 , 253 , + 0 , 0 , 0 , 0 , 0 , 0 , 253 , 253 , + 0 , 0 , 0 , 0 , 0 , 0 , 253 , 253 , + 0 , 0 , 0 , 0 , 0 , 0 , 253 , 253 , + 0 , 0 , 0 , 0 , 0 , 0 , 253 , 253 , + 0 , 0 , 0 , 0 , 0 , 0 , 253 , 253 , + 0 , 0 , 0 , 0 , 0 , 0 , 253 , 253 , + 0 , 0 , 0 , 0 , 0 , 0 , 253 , 253 , + 0 , 0 , 0 , 0 , 0 , 0 , 253 , 253 , + + 255 , 1 , 99 , 0 , 0 , 0 , 0 , 0 + }; -uint8_t* patterns[] = -{ + +uint8_t * patterns [] = { notes, notes, notes, notes, notes2, notes2, notes2, notes2, notes3, notes3, notes3, notes3, @@ -1311,8 +1314,8 @@ void main_callback( float* buf, int len ) if( cur_line[ s ] == 252 ) break; hat_timer[ s ] -= 0.0004; if( hat_timer[ s ] < 0 ) { hat_timer[ s ] = 0; break; } - res1 = ( ( (float)(myrand()&0x7FFF) / 32000.0F ) - 0.5 ) * ( (float)cur_line[ s ] / 10.0F ); - res2 = ( ( (float)(myrand()&0x7FFF) / 32000.0F ) - 0.5 ) * ( (float)cur_line[ s ] / 10.0F ); + res1 = ( ( (float)(randomize()&0x7FFF) / 32000.0F ) - 0.5 ) * ( (float)cur_line[ s ] / 10.0F ); + res2 = ( ( (float)(randomize()&0x7FFF) / 32000.0F ) - 0.5 ) * ( (float)cur_line[ s ] / 10.0F ); if( res1 > hat_old1[ s ] ) hat_old1[ s ] += 0.03; if( res1 < hat_old1[ s ] ) hat_old1[ s ] -= 0.03; if( res2 > hat_old2[ s ] ) hat_old2[ s ] += 0.03; @@ -1384,8 +1387,8 @@ void main_callback( float* buf, int len ) { rec1[ rec_ptr ] = buf[ ( a << 1 ) ]; rec2[ rec_ptr ] = buf[ ( a << 1 ) + 1 ]; - //if( myrand() & 15 ) rec1[ rec_ptr ] += 0.2 * ( (float)( myrand() & 255 ) / 255 ); - //if( myrand() & 15 ) rec2[ rec_ptr ] += 0.2 * ( (float)( myrand() & 255 ) / 255 ); + //if( randomize() & 15 ) rec1[ rec_ptr ] += 0.2 * ( (float)( randomize() & 255 ) / 255 ); + //if( randomize() & 15 ) rec2[ rec_ptr ] += 0.2 * ( (float)( randomize() & 255 ) / 255 ); rec_ptr++; if( rec_ptr >= rec_size ) { From 0039f2af31d6ab2854e12070ebc28d175cae4043 Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Sat, 26 Nov 2022 22:06:29 -0500 Subject: [PATCH 03/18] Added GitIgnore --- .gitignore | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6a5120c --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ + +# Don't include generated files + +/ps +*.o From 2b0f2da2873d7aeef99e9ff27d686376650934b5 Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Sun, 27 Nov 2022 00:26:10 -0500 Subject: [PATCH 04/18] Refactored Predefined Variables --- ps.c | 160 +++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 95 insertions(+), 65 deletions(-) diff --git a/ps.c b/ps.c index 7b662d1..3c2f9e1 100644 --- a/ps.c +++ b/ps.c @@ -39,8 +39,9 @@ float max_vol = 1; int out_mode = 0; //0 - SDL; 1 - WAV EXPORT; const char* export_file_name = NULL; -int myrand() -{ + +int randomize (){ + static int seed = 0; seed *= 13; @@ -614,7 +615,7 @@ uint8_t notes_preend [] = { //=-=-=-= uint8_t part2 [] = { - + 100 , 253 , 0 , 97 , 4 , 0 , 135 , 253 , 10 , 1 , 0 , 99 , 0 , 0 , 0 , 0 , 100 , 2 , 0 , 99 , 0 , 0 , 0 , 0 , @@ -915,50 +916,79 @@ enum { SYNTH_PAD }; -float drum_timer[ chan_num ]; -float drum_timer2[ chan_num ]; -float drum_timer3[ chan_num ]; +float + drum_timer1[ chan_num ] , + drum_timer2[ chan_num ] , + drum_timer3[ chan_num ] ; -float hat_timer[ chan_num ]; -float hat_old1[ chan_num ]; -float hat_old2[ chan_num ]; +float + hat_timer[ chan_num ] , + hat_old1[ chan_num ] , + hat_old2[ chan_num ] ; -float bass_freq[ chan_num ]; -float bass_tdelta[ chan_num ]; -float bass_delta[ chan_num ]; -float bass_timer[ chan_num ]; +float + bass_tdelta[ chan_num ] , + bass_delta[ chan_num ] , + bass_timer[ chan_num ] , + bass_freq[ chan_num ] ; + +float + effect_timer1[ chan_num ] , + effect_timer2[ chan_num ] ; -float effect_timer[ chan_num ]; -float effect_timer2[ chan_num ]; int effect_lowfilter[ chan_num ]; -int syn[ chan_num ] = { SYNTH_DRUM, SYNTH_HAT, SYNTH_BASS, SYNTH_BASS_TINY, SYNTH_EFFECT, SYNTH_POLY, SYNTH_PAD, SYNTH_PAD }; +int syn [ chan_num ] = { + SYNTH_DRUM , + SYNTH_HAT , + SYNTH_BASS , + SYNTH_BASS_TINY , + SYNTH_EFFECT , + SYNTH_POLY , + SYNTH_PAD , + SYNTH_PAD +}; + #define echo_size ( one_tick_size * 3 ) -float echo_buf1[ echo_size * 2 ]; -float echo_buf2[ echo_size * 2 ]; + +float + echo_buf1[ echo_size * 2 ] , + echo_buf2[ echo_size * 2 ] ; + int echo_ptr = 0; + #define reverb 16 + int slow_reverb[ reverb ]; #define max_flanger_size 100 -float flanger_buf1[ max_flanger_size * 3 * 6 ]; -float flanger_buf2[ max_flanger_size * 3 * 6 ]; -float flanger_ptr = 0; -float flanger_size = 0; -float flanger_timer = 0; + +float + flanger_buf1[ max_flanger_size * 3 * 6 ] , + flanger_buf2[ max_flanger_size * 3 * 6 ] ; + +float + flanger_timer = 0 , + flanger_size = 0 , + flanger_ptr = 0 ; int time_effect = 1; int start_recorder = 0; -int rec_ptr = 0; -int rec_play = 0; + +int + rec_play = 0 , + rec_ptr = 0 ; + #define rec_size ( one_tick_size * 16 ) -float rec1[ rec_size ]; -float rec2[ rec_size ]; -static inline void flanger_put( float v1, float v2 ) -{ +float + rec1[ rec_size ] , + rec2[ rec_size ] ; + + +static inline void flanger_put ( float v1, float v2 ){ float ptr2 = flanger_ptr - flanger_size; if( ptr2 < 0 ) ptr2 += ( flanger_size * 2 ); flanger_buf1[ (int)ptr2 ] += v1 / 2; @@ -1088,25 +1118,25 @@ void main_callback( float* buf, int len ) { if( cur_line[ s ] ) { - effect_timer[ s ] = 1; + effect_timer1[ s ] = 1; bass_freq[ s ] = pow( 2, (float)( cur_line[ s ] + offset ) / 12.0F ); bass_tdelta[ s ] = bass_freq[ s ] / srate; bass_timer[ s ] = 0; } if( cur_line[ s ] == 254 ) - effect_timer[ s ] = 0; + effect_timer1[ s ] = 0; if( cur_line[ s ] == 253 ) { - effect_timer[ s ] = 0; + effect_timer1[ s ] = 0; bound = 0.1; } } - if( effect_timer[ s ] ) + if( effect_timer1[ s ] ) { - effect_timer[ s ] *= 0.99998; + effect_timer1[ s ] *= 0.99998; bass_delta[ s ] += ( bass_tdelta[ s ] - bass_delta[ s ] ) / 2000; bass_timer[ s ] += bass_delta[ s ]; - res1 = sin( bass_timer[ s ] ) * sin( bass_timer[ s ] * (sin( effect_timer[ s ] ) * 0.02) ) + cos( bass_timer[ s ] * 0.99 ); + res1 = sin( bass_timer[ s ] ) * sin( bass_timer[ s ] * (sin( effect_timer1[ s ] ) * 0.02) ) + cos( bass_timer[ s ] * 0.99 ); res2 = cos( bass_timer[ s ] * 1.01 ) + cos( bass_timer[ s ] * 0.99 ); if( res1 > 1 ) res1 = 1; if( res1 < -1 ) res1 = -1; @@ -1128,19 +1158,19 @@ void main_callback( float* buf, int len ) { if( cur_line[ s ] ) { - effect_timer[ s ] = 1; + effect_timer1[ s ] = 1; bass_freq[ s ] = pow( 2, (float)( cur_line[ s ] + offset ) / 12.0F ); bass_tdelta[ s ] = bass_freq[ s ] / srate; bass_timer[ s ] = 0; } } - if( effect_timer[ s ] ) + if( effect_timer1[ s ] ) { - effect_timer[ s ] *= 0.99998; + effect_timer1[ s ] *= 0.99998; bass_delta[ s ] += ( bass_tdelta[ s ] - bass_delta[ s ] ) / 1800; bass_timer[ s ] += bass_delta[ s ]; - res1 = sin( bass_timer[ s ] ) * effect_timer[ s ]; - res2 = sin( bass_timer[ s ] * 1.01 ) * effect_timer[ s ]; + res1 = sin( bass_timer[ s ] ) * effect_timer1[ s ]; + res2 = sin( bass_timer[ s ] * 1.01 ) * effect_timer1[ s ]; } else { @@ -1159,7 +1189,7 @@ void main_callback( float* buf, int len ) { if( cur_line[ s ] ) { - effect_timer[ s ] = 1; + effect_timer1[ s ] = 1; effect_timer2[ s ] = 0; } if( cur_line[ s ] == 5 ) { effect_lowfilter[ s ] = 4; rec_play = 1; } @@ -1168,13 +1198,13 @@ void main_callback( float* buf, int len ) if( cur_line[ s ] == 2 ) effect_lowfilter[ s ] = 1; if( cur_line[ s ] == 1 ) effect_lowfilter[ s ] = 0; } - if( effect_timer[ s ] ) + if( effect_timer1[ s ] ) { - effect_timer[ s ] *= 0.99996; + effect_timer1[ s ] *= 0.99996; effect_timer2[ s ] += 0.2; if( effect_lowfilter[ s ] == 4 ) { - effect_timer[ s ] = 1; + effect_timer1[ s ] = 1; /*res1 = rec1[ rec_ptr ] * 1.8; res2 = rec2[ rec_ptr ] * 1.8; rec_ptr--; @@ -1183,23 +1213,23 @@ void main_callback( float* buf, int len ) else if( effect_lowfilter[ s ] == 3 ) { - res2 = sin( ( effect_timer2[ s ] * 1 ) * effect_timer[ s ] ) * effect_timer[ s ]; - res1 = sin( ( effect_timer2[ s ] * 1.5 ) / effect_timer[ s ] ) * effect_timer[ s ]; + res2 = sin( ( effect_timer2[ s ] * 1 ) * effect_timer1[ s ] ) * effect_timer1[ s ]; + res1 = sin( ( effect_timer2[ s ] * 1.5 ) / effect_timer1[ s ] ) * effect_timer1[ s ]; } else if( effect_lowfilter[ s ] == 2 ) { - res2 = sin( ( effect_timer2[ s ] / 4 ) / effect_timer[ s ] ) * effect_timer[ s ]; - res1 = sin( ( effect_timer2[ s ] / 3.5 ) / effect_timer[ s ] ) * effect_timer[ s ]; + res2 = sin( ( effect_timer2[ s ] / 4 ) / effect_timer1[ s ] ) * effect_timer1[ s ]; + res1 = sin( ( effect_timer2[ s ] / 3.5 ) / effect_timer1[ s ] ) * effect_timer1[ s ]; } else if( effect_lowfilter[ s ] == 1 ) { - res2 = sin( ( effect_timer2[ s ] / 2 ) / effect_timer[ s ] ) * effect_timer[ s ]; - res1 = sin( ( effect_timer2[ s ] / 2.5 ) / effect_timer[ s ] ) * effect_timer[ s ]; + res2 = sin( ( effect_timer2[ s ] / 2 ) / effect_timer1[ s ] ) * effect_timer1[ s ]; + res1 = sin( ( effect_timer2[ s ] / 2.5 ) / effect_timer1[ s ] ) * effect_timer1[ s ]; } else - res2 = res1 = sin( effect_timer2[ s ] / effect_timer[ s ] ) * effect_timer[ s ]; + res2 = res1 = sin( effect_timer2[ s ] / effect_timer1[ s ] ) * effect_timer1[ s ]; } else { @@ -1220,13 +1250,13 @@ void main_callback( float* buf, int len ) bass_freq[ s ] = pow( 2, (float)( cur_line[ s ] + offset ) / 12.0F ); bass_tdelta[ s ] = bass_freq[ s ] / srate; bass_timer[ s ] = 0; - effect_timer[ s ] = 1; + effect_timer1[ s ] = 1; effect_timer2[ s ] = 0; } bass_delta[ s ] += ( bass_tdelta[ s ] - bass_delta[ s ] ) / 300; bass_timer[ s ] += bass_delta[ s ]; effect_timer2[ s ] += 0.02 * (32 - (float)tick); - effect_timer[ s ] *= 0.9997; + effect_timer1[ s ] *= 0.9997; if( cur_line[ s ] ) { res2 = res1 = sin( bass_timer[ s ] ) + ( sin( bass_timer[ s ] * 4.01 ) * 0.9 ); @@ -1236,8 +1266,8 @@ void main_callback( float* buf, int len ) if( res2 < -0.2 ) res2 = -0.1; //res1 += ( sin( bass_timer[ s ] ) * cos( effect_timer2[ s ] * effect_timer[ s ] ) * 0.07 ); //res2 += ( sin( bass_timer[ s ] ) * cos( effect_timer2[ s ] * effect_timer[ s ] ) * 0.07 ); - res1 *= effect_timer[ s ]; - res2 *= effect_timer[ s ]; + res1 *= effect_timer1[ s ]; + res2 *= effect_timer1[ s ]; } else { res1 = 0; res2 = 0; } echo_put( res1, res2 ); @@ -1252,11 +1282,11 @@ void main_callback( float* buf, int len ) bass_freq[ s ] = pow( 2, (float)( cur_line[ s ] + offset ) / 12.0F ); bass_tdelta[ s ] = bass_freq[ s ] / srate; bass_timer[ s ] = 0; - effect_timer[ s ] = 1; + effect_timer1[ s ] = 1; } bass_delta[ s ] += ( bass_tdelta[ s ] - bass_delta[ s ] ) / 300; bass_timer[ s ] += bass_delta[ s ]; - effect_timer[ s ] *= 0.9999; + effect_timer1[ s ] *= 0.9999; if( cur_line[ s ] ) { res1 = sin( bass_timer[ s ] ) + sin( bass_timer[ s ] * 2.01 ); @@ -1271,7 +1301,7 @@ void main_callback( float* buf, int len ) res1 = 0; res2 = 0; } - if( bound > 0.1 ) { res1 *= effect_timer[ s ]; res2 *= effect_timer[ s ]; } + if( bound > 0.1 ) { res1 *= effect_timer1[ s ]; res2 *= effect_timer1[ s ]; } if( syn[ s ] == SYNTH_BASS_TINY ) { res1 *= 0.9; res2 *= 0.9; @@ -1336,25 +1366,25 @@ void main_callback( float* buf, int len ) { if( cur_line[ s ] ) { - drum_timer[ s ] = 1; + drum_timer1[ s ] = 1; drum_timer2[ s ] = 0; drum_timer3[ s ] = 1; } } - drum_timer[ s ] -= 0.001; + drum_timer1[ s ] -= 0.001; drum_timer2[ s ] += 0.03; drum_timer3[ s ] += 0.003; - if( drum_timer[ s ] < 0 ) { drum_timer[ s ] = 0; break; } + if( drum_timer1[ s ] < 0 ) { drum_timer1[ s ] = 0; break; } if( 0 ) { - res1 = drum_timer[ s ] * ( (float)cur_line[ s ] / 12.0F ) * sinf( ((float)cur_line[ s ] / 70) * drum_timer2[ s ] / drum_timer3[ s ] ); - res2 = drum_timer[ s ] * ( (float)cur_line[ s ] / 12.0F ) * sinf( drum_timer2[ s ] / drum_timer3[ s ] + 2 ); + res1 = drum_timer1[ s ] * ( (float)cur_line[ s ] / 12.0F ) * sinf( ((float)cur_line[ s ] / 70) * drum_timer2[ s ] / drum_timer3[ s ] ); + res2 = drum_timer1[ s ] * ( (float)cur_line[ s ] / 12.0F ) * sinf( drum_timer2[ s ] / drum_timer3[ s ] + 2 ); } else { - res1 = drum_timer[ s ] * ( (float)cur_line[ s ] / 20.0F ) * sinf( ((float)cur_line[ s ] / 70) * drum_timer2[ s ] / drum_timer3[ s ] ); + res1 = drum_timer1[ s ] * ( (float)cur_line[ s ] / 20.0F ) * sinf( ((float)cur_line[ s ] / 70) * drum_timer2[ s ] / drum_timer3[ s ] ); res2 = res1; - float d2 = drum_timer[ s ] * ( (float)cur_line[ s ] / 120.0F ) * sinf( drum_timer2[ s ] / drum_timer3[ s ] + 2 ); + float d2 = drum_timer1[ s ] * ( (float)cur_line[ s ] / 120.0F ) * sinf( drum_timer2[ s ] / drum_timer3[ s ] + 2 ); if( tick & 1 ) { res1 *= 0.3f; From 3b762521d34f2e46ec2e608f23cf5bd650f46041 Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Sun, 27 Nov 2022 00:42:56 -0500 Subject: [PATCH 05/18] General Refactoring --- ps.c | 419 ++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 253 insertions(+), 166 deletions(-) diff --git a/ps.c b/ps.c index 3c2f9e1..00460a9 100644 --- a/ps.c +++ b/ps.c @@ -988,100 +988,131 @@ float rec2[ rec_size ] ; -static inline void flanger_put ( float v1, float v2 ){ +static inline void flanger_put ( float v1 , float v2 ){ + float ptr2 = flanger_ptr - flanger_size; - if( ptr2 < 0 ) ptr2 += ( flanger_size * 2 ); - flanger_buf1[ (int)ptr2 ] += v1 / 2; - flanger_buf2[ (int)ptr2 ] += v2 / 2; + + if(ptr2 < 0) + ptr2 += ( flanger_size * 2 ); + + flanger_buf1[ (int) ptr2 ] += v1 / 2; + flanger_buf2[ (int) ptr2 ] += v2 / 2; } -static inline void flanger_get( float* v1, float* v2 ) -{ - int ptr2; - flanger_buf1[ (int)flanger_ptr ] /= 1.1; - flanger_buf2[ (int)flanger_ptr ] /= 1.1; - *v1 += flanger_buf1[ (int)flanger_ptr ] / 1.5; - *v2 += flanger_buf2[ (int)flanger_ptr ] / 1.5; + +static inline void flanger_get ( float * v1 , float * v2 ){ + + int index = (int) flanger_ptr; + + flanger_buf1[index] /= 1.1; + flanger_buf2[index] /= 1.1; + + * v1 += flanger_buf1[index] / 1.5; + * v2 += flanger_buf2[index] / 1.5; + flanger_ptr++; - if( flanger_ptr >= flanger_size * 2 ) - { - flanger_ptr -= flanger_size * 2; - } + + if( flanger_ptr >= flanger_size * 2 ) + flanger_ptr -= flanger_size * 2; + flanger_timer += 0.0001; - if( rec_play ) - flanger_size = 580; - else - flanger_size = ( ( sin( flanger_timer / 10 ) + 1 ) / 2 ) * ( max_flanger_size - 30 ) + 30; + + flanger_size = (rec_play) + ? 580 + : ( ( sin( flanger_timer / 10 ) + 1 ) / 2 ) * ( max_flanger_size - 30 ) + 30; } -static inline void echo_put( float v1, float v2 ) -{ + +static inline void echo_put ( float v1 , float v2 ){ + int ptr2 = echo_ptr - echo_size; - if( ptr2 < 0 ) ptr2 += ( echo_size * 2 ); + + if( ptr2 < 0 ) + ptr2 += ( echo_size * 2 ); + if( ptr2 < echo_size ) - echo_buf1[ ptr2 ] += v1 / 2; + echo_buf1[ ptr2 ] += v1 / 2; else - echo_buf2[ ptr2 ] += v2 / 2; - //Slow reverb: - int a; - for( a = 0; a < reverb; a ++ ) - { - ptr2 = echo_ptr + slow_reverb[ a ]; - if( ptr2 < 0 ) ptr2 += ( echo_size * 2 ) * ( 1 - ( ptr2 / (echo_size*2) ) ); - if( ptr2 >= ( echo_size * 2 ) ) ptr2 -= ( echo_size * 2 ) * ( ptr2 / (echo_size*2) ); - if( a & 1 ) - echo_buf1[ ptr2 ] += v1 / 6; - else - echo_buf2[ ptr2 ] += v2 / 6; + echo_buf2[ ptr2 ] += v2 / 2; + + // Slow Reverb + + for ( int a = 0 ; a < reverb ; a++ ){ + + ptr2 = echo_ptr + slow_reverb[ a ]; + + if( ptr2 < 0 ) + ptr2 += ( echo_size * 2 ) * ( 1 - ( ptr2 / ( echo_size * 2 ) ) ); + + if( ptr2 >= ( echo_size * 2 ) ) + ptr2 -= ( echo_size * 2 ) * ( ptr2 / ( echo_size * 2 ) ); + + if( a & 1 ) + echo_buf1[ ptr2 ] += v1 / 6; + else + echo_buf2[ ptr2 ] += v2 / 6; } } -static inline void reverb_put( float v1, float v2 ) -{ + +static inline void reverb_put ( float v1 , float v2 ){ + int ptr2; - //Slow reverb: - int a; - for( a = 0; a < reverb; a ++ ) - { - ptr2 = echo_ptr + slow_reverb[ a ]; - if( ptr2 < 0 ) ptr2 += ( echo_size * 2 ) * ( 1 - ( ptr2 / (echo_size*2) ) ); - if( ptr2 >= ( echo_size * 2 ) ) ptr2 -= ( echo_size * 2 ) * ( ptr2 / (echo_size*2) ); - if( a & 1 ) - echo_buf1[ ptr2 ] += v1 / 6; - else - echo_buf2[ ptr2 ] += v2 / 6; + + // Slow Reverb + + for( int a = 0 ; a < reverb ; a++ ){ + + ptr2 = echo_ptr + slow_reverb[ a ]; + + if( ptr2 < 0 ) + ptr2 += ( echo_size * 2 ) * ( 1 - ( ptr2 / (echo_size * 2) ) ); + + if( ptr2 >= ( echo_size * 2 ) ) + ptr2 -= ( echo_size * 2 ) * ( ptr2 / (echo_size * 2) ); + + if( a & 1 ) + echo_buf1[ ptr2 ] += v1 / 6; + else + echo_buf2[ ptr2 ] += v2 / 6; } } -static inline void echo_get( float* v1, float* v2 ) -{ - int ptr2; - //echo_buf1[ echo_ptr ] /= 2; - //echo_buf2[ echo_ptr ] /= 2; - *v1 += echo_buf1[ echo_ptr ]; - *v2 += echo_buf2[ echo_ptr ]; + +static inline void echo_get ( float * v1 , float * v2 ){ + + * v1 += echo_buf1[ echo_ptr ]; + * v2 += echo_buf2[ echo_ptr ]; + echo_ptr++; - if( echo_ptr >= echo_size * 2 ) - { - echo_ptr = 0; - int a; - int r = ( ( rand() & 255 ) * (echo_size/2) ) >> 8; - r += echo_size; - for( a = 0; a < ( echo_size * 2 ); a++ ) - { - ptr2 = a - r; - if( ptr2 < 0 ) ptr2 += ( echo_size * 2 ); - echo_buf1[ a ] = ( echo_buf1[ a ] + echo_buf1[ ptr2 ] ) / 2; - echo_buf2[ a ] = ( echo_buf2[ a ] + echo_buf2[ ptr2 ] ) / 2; - } + + if( echo_ptr < echo_size * 2 ) + return; + + echo_ptr = 0; + + int r = ( ( rand() & 255 ) * (echo_size/2) ) >> 8; + + r += echo_size; + + for ( int a = 0 ; a < ( echo_size * 2 ) ; a++ ){ + + int ptr2 = a - r; + + if( ptr2 < 0 ) + ptr2 += ( echo_size * 2 ); + + echo_buf1[ a ] = ( echo_buf1[ a ] + echo_buf1[ ptr2 ] ) / 2; + echo_buf2[ a ] = ( echo_buf2[ a ] + echo_buf2[ ptr2 ] ) / 2; } } -int offset = 0; + float bound = 0.05; +int offset = 0; -void main_callback( float* buf, int len ) -{ + +void main_callback ( float * buf , int len ){ int a; int s; int c; @@ -1321,137 +1352,193 @@ void main_callback( float* buf, int len ) break; case SYNTH_HAT: - if( tick_changed ) - { - if( cur_line[ s ] ) - hat_timer[ s ] = 2; - if( cur_line[ s ] == 254 ) - { - offset ++; - fadeout = 1; - break; - } - if( cur_line[ s ] == 253 ) - { - syn[ 3 ] = SYNTH_ACID_BASS; - start_recorder = 1; - } - if( cur_line[ s ] == 252 ) - offset --; + + if( tick_changed ){ + + if( cur_line[ s ] ) + hat_timer[ s ] = 2; + + if( cur_line[ s ] == 254 ){ + offset++; + fadeout = 1; + break; + } + + if( cur_line[ s ] == 253 ){ + syn[ 3 ] = SYNTH_ACID_BASS; + start_recorder = 1; + } + + if( cur_line[ s ] == 252 ) + offset --; } - if( cur_line[ s ] == 254 ) break; - if( cur_line[ s ] == 253 ) break; - if( cur_line[ s ] == 252 ) break; - hat_timer[ s ] -= 0.0004; - if( hat_timer[ s ] < 0 ) { hat_timer[ s ] = 0; break; } - res1 = ( ( (float)(randomize()&0x7FFF) / 32000.0F ) - 0.5 ) * ( (float)cur_line[ s ] / 10.0F ); + + if( cur_line[ s ] == 254 ) + break; + + if( cur_line[ s ] == 253 ) + break; + + if( cur_line[ s ] == 252 ) + break; + + hat_timer[ s ] -= 0.0004; + + if( hat_timer[ s ] < 0 ){ + hat_timer[ s ] = 0; + break; + } + + res1 = ( ( (float)(randomize()&0x7FFF) / 32000.0F ) - 0.5 ) * ( (float)cur_line[ s ] / 10.0F ); res2 = ( ( (float)(randomize()&0x7FFF) / 32000.0F ) - 0.5 ) * ( (float)cur_line[ s ] / 10.0F ); - if( res1 > hat_old1[ s ] ) hat_old1[ s ] += 0.03; - if( res1 < hat_old1[ s ] ) hat_old1[ s ] -= 0.03; - if( res2 > hat_old2[ s ] ) hat_old2[ s ] += 0.03; - if( res2 < hat_old2[ s ] ) hat_old2[ s ] -= 0.03; + + if( res1 > hat_old1[ s ] ) + hat_old1[ s ] += 0.03; + + if( res1 < hat_old1[ s ] ) + hat_old1[ s ] -= 0.03; + + if( res2 > hat_old2[ s ] ) + hat_old2[ s ] += 0.03; + + if( res2 < hat_old2[ s ] ) + hat_old2[ s ] -= 0.03; + res1 = hat_old1[ s ]; res2 = hat_old2[ s ]; + hat_old1[ s ] = res1; hat_old2[ s ] = res2; + res1 *= hat_timer[ s ] * ( (float)cur_line[ s ] / 100.0F ); res2 *= hat_timer[ s ] * ( (float)cur_line[ s ] / 100.0F ); - //reverb_put( res1 / 5, res2 / 5 ); + buf[ ( a << 1 ) ] += res1 / 1.8; buf[ ( a << 1 ) + 1 ] += res2 / 1.8; - break; - case SYNTH_DRUM: - if( tick_changed ) - { - if( cur_line[ s ] ) - { - drum_timer1[ s ] = 1; - drum_timer2[ s ] = 0; - drum_timer3[ s ] = 1; - } + break; + case SYNTH_DRUM : + + if( tick_changed ){ + if( cur_line[ s ] ){ + drum_timer1[ s ] = 1; + drum_timer2[ s ] = 0; + drum_timer3[ s ] = 1; + } } + drum_timer1[ s ] -= 0.001; drum_timer2[ s ] += 0.03; drum_timer3[ s ] += 0.003; - if( drum_timer1[ s ] < 0 ) { drum_timer1[ s ] = 0; break; } - if( 0 ) - { - res1 = drum_timer1[ s ] * ( (float)cur_line[ s ] / 12.0F ) * sinf( ((float)cur_line[ s ] / 70) * drum_timer2[ s ] / drum_timer3[ s ] ); - res2 = drum_timer1[ s ] * ( (float)cur_line[ s ] / 12.0F ) * sinf( drum_timer2[ s ] / drum_timer3[ s ] + 2 ); - } - else - { - res1 = drum_timer1[ s ] * ( (float)cur_line[ s ] / 20.0F ) * sinf( ((float)cur_line[ s ] / 70) * drum_timer2[ s ] / drum_timer3[ s ] ); - res2 = res1; - float d2 = drum_timer1[ s ] * ( (float)cur_line[ s ] / 120.0F ) * sinf( drum_timer2[ s ] / drum_timer3[ s ] + 2 ); - if( tick & 1 ) - { - res1 *= 0.3f; - res1 += d2; - } - else - { - res2 *= 0.3f; - res2 += d2; - } + + if( drum_timer1[ s ] < 0 ){ + drum_timer1[ s ] = 0; + break; + } + + if( 0 ){ + res1 = drum_timer1[ s ] * ( (float)cur_line[ s ] / 12.0F ) * sinf( ((float)cur_line[ s ] / 70) * drum_timer2[ s ] / drum_timer3[ s ] ); + res2 = drum_timer1[ s ] * ( (float)cur_line[ s ] / 12.0F ) * sinf( drum_timer2[ s ] / drum_timer3[ s ] + 2 ); + } else { + + res1 = drum_timer1[ s ] * ( (float)cur_line[ s ] / 20.0F ) * sinf( ((float)cur_line[ s ] / 70) * drum_timer2[ s ] / drum_timer3[ s ] ); + res2 = res1; + + float d2 = drum_timer1[ s ] * ( (float)cur_line[ s ] / 120.0F ) * sinf( drum_timer2[ s ] / drum_timer3[ s ] + 2 ); + + if( tick & 1 ){ + res1 *= 0.3f; + res1 += d2; + } else { + res2 *= 0.3f; + res2 += d2; + } } + float clip = 0.3; - if( res1 > clip ) res1 = clip; - if( res1 < -clip ) res1 = -clip; - if( res2 > clip ) res2 = clip; - if( res2 < -clip ) res2 = -clip; - buf[ ( a << 1 ) ] += res1; + + if( res1 > clip ) + res1 = clip; + + if( res1 < -clip ) + res1 = -clip; + + if( res2 > clip ) + res2 = clip; + + if( res2 < -clip ) + res2 = -clip; + + buf[ ( a << 1 ) ] += res1; buf[ ( a << 1 ) + 1 ] += res2; - res1 = 0; + + res1 = 0; res2 = 0; - break; + + break; } } - //buf[ ( a << 1 ) ] = 0; - //buf[ ( a << 1 ) + 1 ] = 0; - echo_get( &res1, &res2 ); + + echo_get( & res1 , & res2 ); + buf[ ( a << 1 ) ] += res1; buf[ ( a << 1 ) + 1 ] += res2; - if( start_recorder ) - { - rec1[ rec_ptr ] = buf[ ( a << 1 ) ]; + + if( start_recorder ){ + + rec1[ rec_ptr ] = buf[ ( a << 1 ) ]; rec2[ rec_ptr ] = buf[ ( a << 1 ) + 1 ]; - //if( randomize() & 15 ) rec1[ rec_ptr ] += 0.2 * ( (float)( randomize() & 255 ) / 255 ); - //if( randomize() & 15 ) rec2[ rec_ptr ] += 0.2 * ( (float)( randomize() & 255 ) / 255 ); + rec_ptr++; - if( rec_ptr >= rec_size ) - { - start_recorder = 0; - rec_ptr --; + + if( rec_ptr >= rec_size ){ + start_recorder = 0; + rec_ptr --; } } - if( rec_play ) - { - flanger_put( rec1[ rec_ptr ] / 2, rec2[ rec_ptr ] / 2 ); - res1 = 0; res2 = 0; - flanger_get( &res1, &res2 ); - buf[ ( a << 1 ) ] += res1; - buf[ ( a << 1 ) + 1 ] += res2; - rec_ptr--; - if( rec_ptr < 0 ) rec_ptr = rec_size - 1; + + if( rec_play ){ + + flanger_put( + rec1[ rec_ptr ] / 2 , + rec2[ rec_ptr ] / 2 + ); + + res1 = 0; res2 = 0; + + flanger_get( & res1 , & res2 ); + + buf[ ( a << 1 ) ] += res1; + buf[ ( a << 1 ) + 1 ] += res2; + + rec_ptr--; + + if( rec_ptr < 0 ) + rec_ptr = rec_size - 1; } + timer++; - if( fadeout ) - { + + if( fadeout ){ + fadeout_vol -= 0.000001; - if( fadeout_vol <= 0 ) { fadeout_vol = 0; exit_request = 1; } - buf[ ( a << 1 ) ] *= fadeout_vol; + + if( fadeout_vol <= 0 ){ + exit_request = 1; + fadeout_vol = 0; + } + + buf[ ( a << 1 ) ] *= fadeout_vol; buf[ ( a << 1 ) + 1 ] *= fadeout_vol; } } } -//Utrom ekzamen... Ja ne gotov :) ... na na na -//11 june 2005 -void render_buf( float* buf, int len ) //buf: LRLRLR..; len - number of frames (one frame = LR (Left+Right channel)); -{ +//buf: LRLRLR..; len - number of frames (one frame = LR (Left+Right channel)); + +void render_buf( float* buf, int len ){ + main_callback( buf, len ); //Simple DC blocker: if( volume != 1 ) for( int a = 0; a < len * 2; a++ ) buf[ a ] *= volume; From 0a253cdf3438c7024d21705705ba73dd6e0d24bd Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Sun, 27 Nov 2022 00:58:20 -0500 Subject: [PATCH 06/18] General Refactoring --- ps.c | 276 +++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 183 insertions(+), 93 deletions(-) diff --git a/ps.c b/ps.c index 00460a9..15339ed 100644 --- a/ps.c +++ b/ps.c @@ -1537,140 +1537,230 @@ void main_callback ( float * buf , int len ){ //buf: LRLRLR..; len - number of frames (one frame = LR (Left+Right channel)); -void render_buf( float* buf, int len ){ - +void render_buf( float * buf , int len ){ + main_callback( buf, len ); - //Simple DC blocker: - if( volume != 1 ) for( int a = 0; a < len * 2; a++ ) buf[ a ] *= volume; - for( int a = 0; a < len; a++ ) - { + + // Simple DC Blocker + + if( volume != 1 ) + for ( int a = 0 ; a < len * 2 ; a++ ) + buf[ a ] *= volume; + + for ( int a = 0 ; a < len ; a++ ){ dc_sl += buf[ a * 2 ]; dc_sl /= 2; dc_sr += buf[ a * 2 + 1 ]; dc_sr /= 2; } - for( int a = 0; a < len; a++ ) - { - //Simple DC blocker: + + for( int a = 0 ; a < len ; a++ ){ + + // Simple DC Bocker + float a2 = (float)(len-a) / len; float a3 = (float)a / len; + buf[ a * 2 ] -= ( dc_psl * a2 ) + ( dc_sl * a3 ); buf[ a * 2 + 1 ] -= ( dc_psr * a2 ) + ( dc_sr * a3 ); - //Simple volume compression: + + // Simple Volume Compression + buf[ a * 2 ] /= max_vol; buf[ a * 2 + 1 ] /= max_vol; + max_vol -= 0.0005; - if( max_vol < 1 ) max_vol = 1; - float t1 = buf[ a * 2 ]; if( t1 < 0 ) t1 = -t1; - float t2 = buf[ a * 2 + 1 ]; if( t2 < 0 ) t2 = -t2; - if( t1 > max_vol ) max_vol = t1; - if( t2 > max_vol ) max_vol = t2; + + if( max_vol < 1 ) + max_vol = 1; + + float t1 = buf[ a * 2 ]; + + if( t1 < 0 ) + t1 = -t1; + + float t2 = buf[ a * 2 + 1 ]; + + if( t2 < 0 ) + t2 = -t2; + + if( t1 > max_vol ) + max_vol = t1; + + if( t2 > max_vol ) + max_vol = t2; } - dc_psl = dc_sl; dc_psr = dc_sr; + + dc_psl = dc_sl; + dc_psr = dc_sr; } -void sdl_audio_callback( void* udata, Uint8* stream, int len ) -{ - render_buf( (float*)stream, len / 8 ); + +void sdl_audio_callback ( void * udata , Uint8 * stream , int len ){ + render_buf( (float *) stream , len / 8 ); } -int sound_init() -{ - for( int a = 0; a < reverb; a++ ) slow_reverb[ a ] = ( ( rand() & 2047 ) - 1024 ) << 6; - if( out_mode == 0 ) - { - SDL_Init( 0 ); - SDL_AudioSpec a; - a.freq = srate; - a.format = AUDIO_F32; - a.channels = 2; - a.samples = bufsize; - a.callback = sdl_audio_callback; - a.userdata = NULL; - if( SDL_OpenAudio( &a, NULL ) < 0 ) - { - printf( "Couldn't open audio: %s\n", SDL_GetError() ); - return -1; - } - SDL_PauseAudio( 0 ); - return 0; + +int sound_init (){ + + for ( int a = 0 ; a < reverb ; a++ ) + slow_reverb[ a ] = ( ( rand() & 2047 ) - 1024 ) << 6; + + if( out_mode == 0 ){ + + SDL_Init( 0 ); + + SDL_AudioSpec a; + a.freq = srate; + a.format = AUDIO_F32; + a.channels = 2; + a.samples = bufsize; + a.callback = sdl_audio_callback; + a.userdata = NULL; + + if( SDL_OpenAudio( &a, NULL ) < 0 ){ + printf( "Couldn't open audio: %s\n", SDL_GetError() ); + return -1; + } + + SDL_PauseAudio( 0 ); + + return 0; } - if( out_mode == 1 ) - { - FILE* f = fopen( export_file_name, "wb" ); - if( f ) - { + + if( out_mode == 1 ){ + + FILE * f = fopen( export_file_name , "wb" ); + + if( f ){ + printf( "Exporting to WAV...\n" ); - int fixup1 = 0, fixup2 = 0; - int out_bytes = 0; - int val; - //WAV header: - fwrite( (void*)"RIFF", 1, 4, f ); + + int out_bytes = 0 , + fixup1 = 0 , + fixup2 = 0 ; + + int val; + + // WAV Header + + fwrite( (void *) "RIFF" , 1 , 4 , f ); + val = 4 + 24 + 8 + out_bytes; fixup1 = ftell( f ); - fwrite( &val, 4, 1, f ); - fwrite( (void*)"WAVE", 1, 4, f ); - //WAV FORMAT: - fwrite( (void*)"fmt ", 1, 4, f ); - val = 16; fwrite( &val, 4, 1, f ); - val = 3; fwrite( &val, 2, 1, f ); //format - val = 2; fwrite( &val, 2, 1, f ); //channels - val = srate; fwrite( &val, 4, 1, f ); //frames per second - val = srate * 2 * 4; fwrite( &val, 4, 1, f ); //bytes per second - val = 2 * 4; fwrite( &val, 2, 1, f ); //block align - val = 4 * 8; fwrite( &val, 2, 1, f ); //bits per sample - //WAV DATA: - fwrite( (void*)"data", 1, 4, f ); + + fwrite( & val, 4, 1, f ); + fwrite( (void *) "WAVE" , 1 , 4 , f ); + + // WAV Format + + fwrite( (void *) "fmt " , 1 , 4 , f ); + + val = 16; + fwrite( & val , 4 , 1 , f ); + + // Format + + val = 3; + fwrite( & val , 2 , 1 , f ); + + // Channels + + val = 2; + fwrite( & val , 2 , 1 , f ); + + // Frames Per second + + val = srate; + fwrite( & val , 4 , 1 , f ); + + //bytes per second + + val = srate * 2 * 4; + fwrite( & val , 4 , 1 , f ); + + // Block Alignment + + val = 2 * 4; + fwrite( & val , 2 , 1 , f ); + + + // Bits Per Sample + + val = 4 * 8; + fwrite( & val , 2 , 1 , f ); + + // WAV Data + + fwrite( (void *) "data" , 1 , 4 , f ); + fixup2 = ftell( f ); - fwrite( &out_bytes, 4, 1, f ); - while( !exit_request ) - { - float buf[ bufsize * 2 ]; - render_buf( buf, bufsize ); - out_bytes += fwrite( buf, 1, bufsize * 2 * 4, f ); + + fwrite( & out_bytes , 4 , 1 , f ); + + while( !exit_request ){ + + float buf[ bufsize * 2 ]; + render_buf( buf, bufsize ); + + out_bytes += fwrite( buf, 1, bufsize * 2 * 4, f ); } - fseek( f, fixup1, SEEK_SET ); val = 4 + 24 + 8 + out_bytes; fwrite( &val, 4, 1, f ); - fseek( f, fixup2, SEEK_SET ); val = out_bytes; fwrite( &val, 4, 1, f ); + + fseek( f, fixup1, SEEK_SET ); + val = 4 + 24 + 8 + out_bytes; + fwrite( &val, 4, 1, f ); + + fseek( f, fixup2, SEEK_SET ); + val = out_bytes; + fwrite( &val, 4, 1, f ); + int frames = out_bytes / ( 4 * 2 ); + printf( "%d bytes; %d frames; %d seconds\n", out_bytes, frames, frames / srate ); fclose( f ); } - return 0; + + return 0; } + return -1; } -void sound_close() -{ - if( out_mode == 0 ) - { + +void sound_close (){ + + if( out_mode != 0 ) + return; + SDL_CloseAudio(); SDL_Quit(); - } } -void int_handler( int param ) -{ + +void int_handler ( int param ){ exit_request = 1; } -int main( int argc, char* argv[] ) -{ - signal( SIGINT, int_handler ); + +int main( int argc , char * argv [] ){ + + signal( SIGINT , int_handler ); + if( argc == 3 ) - { - if( strcmp( argv[ 1 ], "-o" ) == 0 ) - { - export_file_name = argv[ 2 ]; - out_mode = 1; - } - } + if( strcmp( argv[ 1 ] , "-o" ) == 0 ){ + export_file_name = argv[ 2 ]; + out_mode = 1; + } + printf( "\nNightRadio - P.S.\nnightradio@gmail.com\nWarmPlace.ru\n\n" ); printf( "Usage:\n just play: ./ps\n export to WAV: ./ps -o filename.wav\n" ); printf( "Press CTRL+C to exit\n\n" ); - if( sound_init() ) return 1; - while( !exit_request ) - { - sleep( 1 ); - } + + if(sound_init()) + return 1; + + while(!exit_request) + sleep( 1 ); + sound_close(); + return 0; } From 063306d6d9c3b2392eb0fc46803c08389b2d7c28 Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Sun, 27 Nov 2022 00:58:29 -0500 Subject: [PATCH 07/18] Ignore Generated WAV Files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 6a5120c..84de4f0 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /ps *.o +*.wav From 113b82c7dccfb6c96bf8fc14ade50f4127c3010e Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Sun, 27 Nov 2022 01:29:09 -0500 Subject: [PATCH 08/18] Formatted Instructions --- ps.c | 49 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/ps.c b/ps.c index 15339ed..6906a09 100644 --- a/ps.c +++ b/ps.c @@ -1740,19 +1740,54 @@ void int_handler ( int param ){ } -int main( int argc , char * argv [] ){ +void newline (){ + printf("\n"); +} + +void printed ( char * string ){ + printf( " %s\n" , string ); +} + +void printInstructions (){ + + newline(); + + printed("NighRadio - P.S."); + printed("================"); + + newline(); + + printed("Website : https://WarmPlace.ru"); + printed("GitHub : https://github.com/pixicoder/PS"); + printed("Email : nightradio@gmail.com"); + + newline(); + newline(); + + printed("Usage"); + printed("====="); + + newline(); + + printed("Export : Pass the filename with '-o \"Music.wav\"'"); + printed("Play : Don't pass any arguments."); + printed("Quit : Press Ctrl+C"); + + newline(); +} + + +int main( int argumentCount , char * arguments [] ){ signal( SIGINT , int_handler ); - if( argc == 3 ) - if( strcmp( argv[ 1 ] , "-o" ) == 0 ){ - export_file_name = argv[ 2 ]; + if( argumentCount == 3 ) + if( strcmp( arguments[ 1 ] , "-o" ) == 0 ){ + export_file_name = arguments[ 2 ]; out_mode = 1; } - printf( "\nNightRadio - P.S.\nnightradio@gmail.com\nWarmPlace.ru\n\n" ); - printf( "Usage:\n just play: ./ps\n export to WAV: ./ps -o filename.wav\n" ); - printf( "Press CTRL+C to exit\n\n" ); + printInstructions(); if(sound_init()) return 1; From bc4575affd5623ee6d2916e8421bebb2465d2276 Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Sun, 27 Nov 2022 02:31:18 -0500 Subject: [PATCH 09/18] Refactored WAV Exporting --- ps.c | 252 +++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 149 insertions(+), 103 deletions(-) diff --git a/ps.c b/ps.c index 6906a09..491d3dc 100644 --- a/ps.c +++ b/ps.c @@ -1599,6 +1599,153 @@ void sdl_audio_callback ( void * udata , Uint8 * stream , int len ){ } + +void newline (){ + printf("\n"); +} + +void printed ( char * string ){ + printf( " %s\n" , string ); +} + + +typedef FILE * File; + +#define section( name ) \ + fwrite( (void *)(name) , 1 , 4 , file ) + +#define bytes( literal , size ){ \ + int value = (literal); \ + fwrite( & value , (size) , 1 , file ); \ + } + +#define quad( value ) \ + bytes(value,4) + +#define word( value ) \ + bytes(value,2) + + +/** + * @brief Writes the generated bytes to the output file. + * + * @details Check https://docs.fileformat.com/audio/wav/ + * for information on the WAV file format. + */ + +int exportWAV (){ + + File file = fopen( export_file_name , "wb" ); + + if( file == NULL ){ + printf("Couldn't create export file to write to."); + return -1; + } + + + printed(">> Exporting to WAV .."); + + + // Header + + section("RIFF"); + + // File Size + + int index_fileSize = ftell( file ); + + quad(0); + + + section("WAVE"); + + + // Format + + section("fmt "); + + // Header Size + quad(16); + + // Format + word(3); + + // Channel Count + word(2); + + // Frames Per Second + quad(srate); + + // Bytes Per Second + quad(srate * 2 * 4) + + // Block Alignment + word(2 * 4); + + // Bits Per Sample + word(4 * 8); + + + // Data + + section("data"); + + + // Data Size + int index_dataSize = ftell( file ); + quad(0); + + + int dataSize = 0; + + while( ! exit_request ){ + + float buffer [ bufsize * 2 ]; + + render_buf( buffer , bufsize ); + + dataSize += fwrite( buffer , 1 , bufsize * 2 * 4 , file ); + } + + + // Insert FileSize + + fseek( file , index_fileSize , SEEK_SET ); + quad(4 + 24 + 8 + dataSize); + + // Insert DataSize + + fseek( file , index_dataSize , SEEK_SET ); + quad(dataSize); + + + int frames = dataSize / ( 4 * 2 ) , + seconds = frames / srate ; + + + newline(); + printed("Data Written"); + printed("============"); + + newline(); + + printf(" Seconds: %d\n",seconds); + printf(" Frames: %d\n",frames); + printf(" Bytes: %d\n",dataSize); + + newline(); + + fclose( file ); + + return 0; +} + +#undef section +#undef bytes +#undef quad +#undef word + + int sound_init (){ for ( int a = 0 ; a < reverb ; a++ ) @@ -1626,100 +1773,8 @@ int sound_init (){ return 0; } - if( out_mode == 1 ){ - - FILE * f = fopen( export_file_name , "wb" ); - - if( f ){ - - printf( "Exporting to WAV...\n" ); - - int out_bytes = 0 , - fixup1 = 0 , - fixup2 = 0 ; - - int val; - - // WAV Header - - fwrite( (void *) "RIFF" , 1 , 4 , f ); - - val = 4 + 24 + 8 + out_bytes; - fixup1 = ftell( f ); - - fwrite( & val, 4, 1, f ); - fwrite( (void *) "WAVE" , 1 , 4 , f ); - - // WAV Format - - fwrite( (void *) "fmt " , 1 , 4 , f ); - - val = 16; - fwrite( & val , 4 , 1 , f ); - - // Format - - val = 3; - fwrite( & val , 2 , 1 , f ); - - // Channels - - val = 2; - fwrite( & val , 2 , 1 , f ); - - // Frames Per second - - val = srate; - fwrite( & val , 4 , 1 , f ); - - //bytes per second - - val = srate * 2 * 4; - fwrite( & val , 4 , 1 , f ); - - // Block Alignment - - val = 2 * 4; - fwrite( & val , 2 , 1 , f ); - - - // Bits Per Sample - - val = 4 * 8; - fwrite( & val , 2 , 1 , f ); - - // WAV Data - - fwrite( (void *) "data" , 1 , 4 , f ); - - fixup2 = ftell( f ); - - fwrite( & out_bytes , 4 , 1 , f ); - - while( !exit_request ){ - - float buf[ bufsize * 2 ]; - render_buf( buf, bufsize ); - - out_bytes += fwrite( buf, 1, bufsize * 2 * 4, f ); - } - - fseek( f, fixup1, SEEK_SET ); - val = 4 + 24 + 8 + out_bytes; - fwrite( &val, 4, 1, f ); - - fseek( f, fixup2, SEEK_SET ); - val = out_bytes; - fwrite( &val, 4, 1, f ); - - int frames = out_bytes / ( 4 * 2 ); - - printf( "%d bytes; %d frames; %d seconds\n", out_bytes, frames, frames / srate ); - fclose( f ); - } - - return 0; - } + if( out_mode == 1 ) + return exportWAV(); return -1; } @@ -1739,15 +1794,6 @@ void int_handler ( int param ){ exit_request = 1; } - -void newline (){ - printf("\n"); -} - -void printed ( char * string ){ - printf( " %s\n" , string ); -} - void printInstructions (){ newline(); From 41b2bbd073fb35ec9e293d699cceb194fc870cbf Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Sun, 27 Nov 2022 03:10:41 -0500 Subject: [PATCH 10/18] General Refactoring --- ps.c | 572 +++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 324 insertions(+), 248 deletions(-) diff --git a/ps.c b/ps.c index 491d3dc..d6b152e 100644 --- a/ps.c +++ b/ps.c @@ -8,10 +8,10 @@ #include #include #include +#include #include #include #include -#include #include "SDL2/SDL.h" #if defined(_WIN32) || defined(_WIN64) @@ -28,16 +28,26 @@ int srate = 44100; int bufsize = 1024; int exit_request = 0; int fadeout = 0; + float fadeout_vol = 1; float volume = 1.2; + int timer = 0; //0...one_tick_size int tick = 0; //0...pattern size (number of lines) int cur_pattern = 0; //0...number of patterns -float dc_sl = 0, dc_sr = 0; -float dc_psl = 0, dc_psr = 0; -float max_vol = 1; + +float + dc_sl = 0 , + dc_sr = 0 ; + +float + dc_psl = 0 , + dc_psr = 0 ; + +float loudest = 1; + int out_mode = 0; //0 - SDL; 1 - WAV EXPORT; -const char* export_file_name = NULL; + int randomize (){ @@ -1113,245 +1123,307 @@ int offset = 0; void main_callback ( float * buf , int len ){ - int a; - int s; - int c; - uint8_t* cur_line; + + uint8_t * cur_line; + float res1, res2; float freq; - for( a = 0; a < len; a++ ) { buf[ a << 1 ] = 0; buf[ ( a << 1 ) + 1 ] = 0; } //Clear buffer - //Render: + + + // Clear Buffer + + for ( int a = 0 ; a < len ; a++ ){ + buf[ ( a << 1 ) + 1 ] = 0; + buf[ ( a << 1 ) + 0 ] = 0; + } + + + // Render + int tick_changed = 0; - for( a = 0; a < len; a++ ) - { + + for ( int a = 0 ; a < len ; a++ ){ + tick_changed = 0; - if( timer >= one_tick_size ) - { //Increment tick number: - timer = 0; tick++; + + // Increment Tick Number + + if( timer >= one_tick_size ){ + timer = 0; + tick++; } - if( timer == 0 ) tick_changed = 1; - //Synths (channels): - for( s = 0; s < chan_num; s++ ) - { + + if( timer == 0 ) + tick_changed = 1; + + // Synths Channels + + for ( int s = 0 ; s < chan_num ; s++ ){ + cur_line = patterns[ cur_pattern ] + ( tick * chan_num ); - if( cur_line[ s ] == 255 ) - { //End of pattern: - tick = 0; - cur_pattern++; - if( patterns[ cur_pattern ] == 0 ) { exit_request = 1; return; } - cur_line = patterns[ cur_pattern ] + ( tick * chan_num ); + + // End of Pattern + + if( cur_line[ s ] == 255 ){ + + cur_pattern++; + tick = 0; + + if( patterns[ cur_pattern ] == 0 ){ + exit_request = 1; + return; + } + + cur_line = patterns[ cur_pattern ] + ( tick * chan_num ); } - if( syn[ s ] == 0 ) continue; - switch( syn[ s ] ) - { - case SYNTH_PAD: - if( tick_changed ) - { - if( cur_line[ s ] ) - { - effect_timer1[ s ] = 1; - bass_freq[ s ] = pow( 2, (float)( cur_line[ s ] + offset ) / 12.0F ); - bass_tdelta[ s ] = bass_freq[ s ] / srate; - bass_timer[ s ] = 0; - } - if( cur_line[ s ] == 254 ) - effect_timer1[ s ] = 0; - if( cur_line[ s ] == 253 ) - { - effect_timer1[ s ] = 0; - bound = 0.1; - } - } - if( effect_timer1[ s ] ) - { - effect_timer1[ s ] *= 0.99998; - bass_delta[ s ] += ( bass_tdelta[ s ] - bass_delta[ s ] ) / 2000; - bass_timer[ s ] += bass_delta[ s ]; - res1 = sin( bass_timer[ s ] ) * sin( bass_timer[ s ] * (sin( effect_timer1[ s ] ) * 0.02) ) + cos( bass_timer[ s ] * 0.99 ); - res2 = cos( bass_timer[ s ] * 1.01 ) + cos( bass_timer[ s ] * 0.99 ); - if( res1 > 1 ) res1 = 1; - if( res1 < -1 ) res1 = -1; - if( res2 > 1 ) res2 = 1; - if( res2 < -1 ) res2 = -1; + + if( syn[ s ] == 0 ) + continue; + + switch( syn[ s ] ){ + case SYNTH_PAD : + + if( tick_changed ){ + + if( cur_line[ s ] ){ + effect_timer1[ s ] = 1; + bass_freq[ s ] = pow( 2, (float)( cur_line[ s ] + offset ) / 12.0F ); + bass_tdelta[ s ] = bass_freq[ s ] / srate; + bass_timer[ s ] = 0; + } + + if( cur_line[ s ] == 254 ) + effect_timer1[ s ] = 0; + + if( cur_line[ s ] == 253 ){ + effect_timer1[ s ] = 0; + bound = 0.1; + } } - else - { - res1 = 0; - res2 = 0; + + if( effect_timer1[ s ] ){ + + effect_timer1[ s ] *= 0.99998; + + bass_delta[ s ] += ( bass_tdelta[ s ] - bass_delta[ s ] ) / 2000; + bass_timer[ s ] += bass_delta[ s ]; + + res1 = sin( bass_timer[ s ] ) * sin( bass_timer[ s ] * (sin( effect_timer1[ s ] ) * 0.02) ) + cos( bass_timer[ s ] * 0.99 ); + res2 = cos( bass_timer[ s ] * 1.01 ) + cos( bass_timer[ s ] * 0.99 ); + + if( res1 > 1 ) res1 = 1; + if( res1 < -1 ) res1 = -1; + if( res2 > 1 ) res2 = 1; + if( res2 < -1 ) res2 = -1; + } else { + res1 = 0; + res2 = 0; } + echo_put( res1 / 8, res2 / 8 ); - res1 = 0; + + res1 = 0; res2 = 0; - break; + + break; + case SYNTH_POLY : - case SYNTH_POLY: if( tick_changed ) - { - if( cur_line[ s ] ) - { - effect_timer1[ s ] = 1; - bass_freq[ s ] = pow( 2, (float)( cur_line[ s ] + offset ) / 12.0F ); - bass_tdelta[ s ] = bass_freq[ s ] / srate; - bass_timer[ s ] = 0; - } - } - if( effect_timer1[ s ] ) - { - effect_timer1[ s ] *= 0.99998; - bass_delta[ s ] += ( bass_tdelta[ s ] - bass_delta[ s ] ) / 1800; - bass_timer[ s ] += bass_delta[ s ]; - res1 = sin( bass_timer[ s ] ) * effect_timer1[ s ]; - res2 = sin( bass_timer[ s ] * 1.01 ) * effect_timer1[ s ]; - } - else - { - res1 = 0; - res2 = 0; + if( cur_line[ s ] ){ + effect_timer1[ s ] = 1; + bass_freq[ s ] = pow( 2, (float)( cur_line[ s ] + offset ) / 12.0F ); + bass_tdelta[ s ] = bass_freq[ s ] / srate; + bass_timer[ s ] = 0; + } + + if( effect_timer1[ s ] ){ + effect_timer1[ s ] *= 0.99998; + bass_delta[ s ] += ( bass_tdelta[ s ] - bass_delta[ s ] ) / 1800; + bass_timer[ s ] += bass_delta[ s ]; + res1 = sin( bass_timer[ s ] ) * effect_timer1[ s ]; + res2 = sin( bass_timer[ s ] * 1.01 ) * effect_timer1[ s ]; + } else { + res1 = 0; + res2 = 0; } - buf[ ( a << 1 ) ] += res1 / 8; + buf[ ( a << 1 ) + 1 ] += res2 / 8; + buf[ ( a << 1 ) ] += res1 / 8; + echo_put( res1 / 4, res2 / 4 ); + res1 = 0; res2 = 0; + break; + case SYNTH_EFFECT : - case SYNTH_EFFECT: - if( tick_changed ) - { - if( cur_line[ s ] ) - { - effect_timer1[ s ] = 1; - effect_timer2[ s ] = 0; - } - if( cur_line[ s ] == 5 ) { effect_lowfilter[ s ] = 4; rec_play = 1; } - if( cur_line[ s ] == 4 ) effect_lowfilter[ s ] = 3; - if( cur_line[ s ] == 3 ) effect_lowfilter[ s ] = 2; - if( cur_line[ s ] == 2 ) effect_lowfilter[ s ] = 1; - if( cur_line[ s ] == 1 ) effect_lowfilter[ s ] = 0; - } - if( effect_timer1[ s ] ) - { - effect_timer1[ s ] *= 0.99996; - effect_timer2[ s ] += 0.2; - if( effect_lowfilter[ s ] == 4 ) - { - effect_timer1[ s ] = 1; - /*res1 = rec1[ rec_ptr ] * 1.8; - res2 = rec2[ rec_ptr ] * 1.8; - rec_ptr--; - if( rec_ptr < 0 ) rec_ptr = rec_size - 1;*/ - } - else - if( effect_lowfilter[ s ] == 3 ) - { - res2 = sin( ( effect_timer2[ s ] * 1 ) * effect_timer1[ s ] ) * effect_timer1[ s ]; - res1 = sin( ( effect_timer2[ s ] * 1.5 ) / effect_timer1[ s ] ) * effect_timer1[ s ]; - } - else - if( effect_lowfilter[ s ] == 2 ) - { - res2 = sin( ( effect_timer2[ s ] / 4 ) / effect_timer1[ s ] ) * effect_timer1[ s ]; - res1 = sin( ( effect_timer2[ s ] / 3.5 ) / effect_timer1[ s ] ) * effect_timer1[ s ]; - } - else - if( effect_lowfilter[ s ] == 1 ) - { - res2 = sin( ( effect_timer2[ s ] / 2 ) / effect_timer1[ s ] ) * effect_timer1[ s ]; - res1 = sin( ( effect_timer2[ s ] / 2.5 ) / effect_timer1[ s ] ) * effect_timer1[ s ]; - } - else - res2 = res1 = sin( effect_timer2[ s ] / effect_timer1[ s ] ) * effect_timer1[ s ]; + if( tick_changed ){ + + if( cur_line[ s ] ){ + effect_timer1[ s ] = 1; + effect_timer2[ s ] = 0; + } + + if( cur_line[ s ] == 5 ){ + effect_lowfilter[ s ] = 4; + rec_play = 1; + } + + if( cur_line[ s ] == 4 ) + effect_lowfilter[ s ] = 3; + + if( cur_line[ s ] == 3 ) + effect_lowfilter[ s ] = 2; + + if( cur_line[ s ] == 2 ) + effect_lowfilter[ s ] = 1; + + if( cur_line[ s ] == 1 ) + effect_lowfilter[ s ] = 0; } - else - { - res1 = 0; - res2 = 0; + + if( effect_timer1[ s ] ){ + + effect_timer1[ s ] *= 0.99996; + effect_timer2[ s ] += 0.2; + + if( effect_lowfilter[ s ] == 4 ){ + effect_timer1[ s ] = 1; + } else + if( effect_lowfilter[ s ] == 3 ){ + res2 = sin( ( effect_timer2[ s ] * 1 ) * effect_timer1[ s ] ) * effect_timer1[ s ]; + res1 = sin( ( effect_timer2[ s ] * 1.5 ) / effect_timer1[ s ] ) * effect_timer1[ s ]; + } else + if( effect_lowfilter[ s ] == 2 ){ + res2 = sin( ( effect_timer2[ s ] / 4 ) / effect_timer1[ s ] ) * effect_timer1[ s ]; + res1 = sin( ( effect_timer2[ s ] / 3.5 ) / effect_timer1[ s ] ) * effect_timer1[ s ]; + } else + if( effect_lowfilter[ s ] == 1 ){ + res2 = sin( ( effect_timer2[ s ] / 2 ) / effect_timer1[ s ] ) * effect_timer1[ s ]; + res1 = sin( ( effect_timer2[ s ] / 2.5 ) / effect_timer1[ s ] ) * effect_timer1[ s ]; + } else { + res2 = res1 = sin( effect_timer2[ s ] / effect_timer1[ s ] ) * effect_timer1[ s ]; + } + } else { + res1 = 0; + res2 = 0; } - buf[ ( a << 1 ) ] += ( res1 / 9.0F ); + buf[ ( a << 1 ) + 1 ] += ( res2 / 9.0F ); + buf[ ( a << 1 ) ] += ( res1 / 9.0F ); + if( effect_lowfilter[ s ] != 4 ) - echo_put( res1 / 5, res2 / 5 ); - res1 = 0; + echo_put( res1 / 5, res2 / 5 ); + + res1 = 0; res2 = 0; - break; + + break; + case SYNTH_ACID_BASS: - case SYNTH_ACID_BASS: - if( tick_changed ) - { - bass_freq[ s ] = pow( 2, (float)( cur_line[ s ] + offset ) / 12.0F ); - bass_tdelta[ s ] = bass_freq[ s ] / srate; - bass_timer[ s ] = 0; - effect_timer1[ s ] = 1; - effect_timer2[ s ] = 0; + if( tick_changed ){ + + bass_freq[ s ] = pow( 2, (float)( cur_line[ s ] + offset ) / 12.0F ); + bass_tdelta[ s ] = bass_freq[ s ] / srate; + bass_timer[ s ] = 0; + + effect_timer1[ s ] = 1; + effect_timer2[ s ] = 0; } + bass_delta[ s ] += ( bass_tdelta[ s ] - bass_delta[ s ] ) / 300; bass_timer[ s ] += bass_delta[ s ]; - effect_timer2[ s ] += 0.02 * (32 - (float)tick); + + effect_timer2[ s ] += 0.02 * (32 - (float)tick); effect_timer1[ s ] *= 0.9997; - if( cur_line[ s ] ) - { - res2 = res1 = sin( bass_timer[ s ] ) + ( sin( bass_timer[ s ] * 4.01 ) * 0.9 ); - if( res1 > 0.2 ) res1 = 0.1; - if( res1 < -0.2 ) res1 = -0.1; - if( res2 > 0.2 ) res2 = 0.1; - if( res2 < -0.2 ) res2 = -0.1; - //res1 += ( sin( bass_timer[ s ] ) * cos( effect_timer2[ s ] * effect_timer[ s ] ) * 0.07 ); - //res2 += ( sin( bass_timer[ s ] ) * cos( effect_timer2[ s ] * effect_timer[ s ] ) * 0.07 ); - res1 *= effect_timer1[ s ]; - res2 *= effect_timer1[ s ]; - } - else { res1 = 0; res2 = 0; } + + if( cur_line[ s ] ){ + + res2 = res1 = sin( bass_timer[ s ] ) + ( sin( bass_timer[ s ] * 4.01 ) * 0.9 ); + + if( res1 > 0.2 ) + res1 = 0.1; + + if( res1 < -0.2 ) + res1 = -0.1; + + if( res2 > 0.2 ) + res2 = 0.1; + + if( res2 < -0.2 ) + res2 = -0.1; + + res1 *= effect_timer1[ s ]; + res2 *= effect_timer1[ s ]; + } else { + res1 = 0; + res2 = 0; + } + echo_put( res1, res2 ); - buf[ ( a << 1 ) ] += res1; + buf[ ( a << 1 ) + 1 ] += res2; - break; + buf[ ( a << 1 ) ] += res1; + + break; + case SYNTH_BASS_TINY : + case SYNTH_BASS : - case SYNTH_BASS: - case SYNTH_BASS_TINY: - if( tick_changed ) - { - bass_freq[ s ] = pow( 2, (float)( cur_line[ s ] + offset ) / 12.0F ); - bass_tdelta[ s ] = bass_freq[ s ] / srate; - bass_timer[ s ] = 0; - effect_timer1[ s ] = 1; + if( tick_changed ){ + bass_freq[ s ] = pow( 2, (float)( cur_line[ s ] + offset ) / 12.0F ); + bass_tdelta[ s ] = bass_freq[ s ] / srate; + bass_timer[ s ] = 0; + effect_timer1[ s ] = 1; } + bass_delta[ s ] += ( bass_tdelta[ s ] - bass_delta[ s ] ) / 300; bass_timer[ s ] += bass_delta[ s ]; effect_timer1[ s ] *= 0.9999; - if( cur_line[ s ] ) - { - res1 = sin( bass_timer[ s ] ) + sin( bass_timer[ s ] * 2.01 ); - res2 = cos( bass_timer[ s ] ) + cos( bass_timer[ s ] * 2.006 ); - if( res1 > bound ) res1 = 0.05; - if( res1 < -bound ) res1 = -0.05; - if( res2 > bound ) res2 = 0.05; - if( res2 < -bound ) res2 = -0.05; - } - else - { - res1 = 0; - res2 = 0; - } - if( bound > 0.1 ) { res1 *= effect_timer1[ s ]; res2 *= effect_timer1[ s ]; } - if( syn[ s ] == SYNTH_BASS_TINY ) - { - res1 *= 0.9; res2 *= 0.9; + + if( cur_line[ s ] ){ + + res1 = sin( bass_timer[ s ] ) + sin( bass_timer[ s ] * 2.01 ); + res2 = cos( bass_timer[ s ] ) + cos( bass_timer[ s ] * 2.006 ); + + if( res1 > bound ) + res1 = 0.05; + + if( res1 < -bound ) + res1 = -0.05; + + if( res2 > bound ) + res2 = 0.05; + + if( res2 < -bound ) + res2 = -0.05; + } else { + res1 = 0; + res2 = 0; } - else - { - if( !rec_play ) - { - flanger_put( res1, res2 ); - res1 /= 1.5; res2 /= 1.5; - flanger_get( &res1, &res2 ); - } + + if( bound > 0.1 ){ + res1 *= effect_timer1[ s ]; + res2 *= effect_timer1[ s ]; + } + + if( syn[ s ] == SYNTH_BASS_TINY ){ + res1 *= 0.9; res2 *= 0.9; + } else { + if( !rec_play ){ + flanger_put( res1, res2 ); + res1 /= 1.5; res2 /= 1.5; + flanger_get( &res1, &res2 ); + } } + echo_put( res1, res2 ); - buf[ ( a << 1 ) ] += res1; + buf[ ( a << 1 ) + 1 ] += res2; - break; - - case SYNTH_HAT: + buf[ ( a << 1 ) ] += res1; + + break; + case SYNTH_HAT : if( tick_changed ){ @@ -1528,65 +1600,67 @@ void main_callback ( float * buf , int len ){ fadeout_vol = 0; } - buf[ ( a << 1 ) ] *= fadeout_vol; buf[ ( a << 1 ) + 1 ] *= fadeout_vol; + buf[ ( a << 1 ) ] *= fadeout_vol; } } } -//buf: LRLRLR..; len - number of frames (one frame = LR (Left+Right channel)); +/** + * @brief + * + * @param buffer Buffer with frames, each + * consisting of a left and right channel. + * + * @param length Number of frames + */ -void render_buf( float * buf , int len ){ +void renderBuffer( float * buffer , int length ){ - main_callback( buf, len ); + main_callback( buffer , length ); // Simple DC Blocker if( volume != 1 ) - for ( int a = 0 ; a < len * 2 ; a++ ) - buf[ a ] *= volume; + for ( int a = 0 ; a < length * 2 ; a++ ) + buffer[ a ] *= volume; - for ( int a = 0 ; a < len ; a++ ){ - dc_sl += buf[ a * 2 ]; dc_sl /= 2; - dc_sr += buf[ a * 2 + 1 ]; dc_sr /= 2; + for ( int a = 0 ; a < length ; a++ ){ + dc_sl += buffer[ a * 2 ]; + dc_sl /= 2; + dc_sr += buffer[ a * 2 + 1 ]; + dc_sr /= 2; } - for( int a = 0 ; a < len ; a++ ){ + for( int a = 0 ; a < length ; a++ ){ // Simple DC Bocker - float a2 = (float)(len-a) / len; - float a3 = (float)a / len; + float + a2 = (float)(length - a) / length , + a3 = (float) a / length ; - buf[ a * 2 ] -= ( dc_psl * a2 ) + ( dc_sl * a3 ); - buf[ a * 2 + 1 ] -= ( dc_psr * a2 ) + ( dc_sr * a3 ); + buffer[ a * 2 ] -= ( dc_psl * a2 ) + ( dc_sl * a3 ); + buffer[ a * 2 + 1 ] -= ( dc_psr * a2 ) + ( dc_sr * a3 ); // Simple Volume Compression - buf[ a * 2 ] /= max_vol; - buf[ a * 2 + 1 ] /= max_vol; + buffer[ a * 2 ] /= loudest; + buffer[ a * 2 + 1 ] /= loudest; - max_vol -= 0.0005; - - if( max_vol < 1 ) - max_vol = 1; - - float t1 = buf[ a * 2 ]; - - if( t1 < 0 ) - t1 = -t1; - - float t2 = buf[ a * 2 + 1 ]; - - if( t2 < 0 ) - t2 = -t2; + loudest -= 0.0005; + loudest = fmax(loudest,1); + + float t1 = buffer[ a * 2 ]; - if( t1 > max_vol ) - max_vol = t1; + t1 = abs(t1); - if( t2 > max_vol ) - max_vol = t2; + float t2 = buffer[ a * 2 + 1 ]; + + t2 = abs(t2); + + loudest = fmax(loudest,fmax(t1,t2)); } dc_psl = dc_sl; @@ -1595,7 +1669,7 @@ void render_buf( float * buf , int len ){ void sdl_audio_callback ( void * udata , Uint8 * stream , int len ){ - render_buf( (float *) stream , len / 8 ); + renderBuffer( (float *) stream , len / 8 ); } @@ -1614,9 +1688,9 @@ typedef FILE * File; #define section( name ) \ fwrite( (void *)(name) , 1 , 4 , file ) -#define bytes( literal , size ){ \ - int value = (literal); \ - fwrite( & value , (size) , 1 , file ); \ +#define bytes( literal , size ){ \ + int value = (literal); \ + fwrite( & value , (size) , 1 , file ); \ } #define quad( value ) \ @@ -1633,9 +1707,9 @@ typedef FILE * File; * for information on the WAV file format. */ -int exportWAV (){ +int exportWAV ( const char * path ){ - File file = fopen( export_file_name , "wb" ); + File file = fopen( path , "wb" ); if( file == NULL ){ printf("Couldn't create export file to write to."); @@ -1702,7 +1776,7 @@ int exportWAV (){ float buffer [ bufsize * 2 ]; - render_buf( buffer , bufsize ); + renderBuffer( buffer , bufsize ); dataSize += fwrite( buffer , 1 , bufsize * 2 * 4 , file ); } @@ -1746,7 +1820,7 @@ int exportWAV (){ #undef word -int sound_init (){ +int sound_init ( const char * path ){ for ( int a = 0 ; a < reverb ; a++ ) slow_reverb[ a ] = ( ( rand() & 2047 ) - 1024 ) << 6; @@ -1774,7 +1848,7 @@ int sound_init (){ } if( out_mode == 1 ) - return exportWAV(); + return exportWAV(path); return -1; } @@ -1827,15 +1901,17 @@ int main( int argumentCount , char * arguments [] ){ signal( SIGINT , int_handler ); + const char * export_path = NULL; + if( argumentCount == 3 ) if( strcmp( arguments[ 1 ] , "-o" ) == 0 ){ - export_file_name = arguments[ 2 ]; + export_path = arguments[ 2 ]; out_mode = 1; } printInstructions(); - if(sound_init()) + if(sound_init(export_path)) return 1; while(!exit_request) From 81e93d5974c0a23dd7e7a8a0196cd0c3691ecc02 Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Sun, 27 Nov 2022 04:52:02 -0500 Subject: [PATCH 11/18] General Refactoring --- ps.c | 948 +++++++++++++++++++++++++++++++---------------------------- 1 file changed, 503 insertions(+), 445 deletions(-) diff --git a/ps.c b/ps.c index d6b152e..e863eb6 100644 --- a/ps.c +++ b/ps.c @@ -7,13 +7,15 @@ #include #include -#include -#include #include #include #include +#include +#include + #include "SDL2/SDL.h" + #if defined(_WIN32) || defined(_WIN64) #include #define sleep(sec) Sleep(1000*(sec)) @@ -21,20 +23,33 @@ #include //sleep() #endif -#define one_tick_size (int)6000 -#define chan_num (int)8 //Number of channels (synth tracks) -int srate = 44100; +// Number of Synth Channels + +#define Channel_Count 8 + +#define Tick_Size 6000 + +#define Echo_Size ( Tick_Size * 3 ) + +#define Reverb 16 + +#define Flanger_Max_Size 100 + + + + int bufsize = 1024; -int exit_request = 0; -int fadeout = 0; +int srate = 44100; float fadeout_vol = 1; +int fadeout = 0; + float volume = 1.2; -int timer = 0; //0...one_tick_size +int timer = 0; //0...Tick_Size int tick = 0; //0...pattern size (number of lines) -int cur_pattern = 0; //0...number of patterns +int pattern = 0; //0...number of patterns float dc_sl = 0 , @@ -46,6 +61,7 @@ float float loudest = 1; +int exit_request = 0; int out_mode = 0; //0 - SDL; 1 - WAV EXPORT; @@ -61,6 +77,12 @@ int randomize (){ } +#define limit( value , min , max ) \ + fmax(fmin((value),(max)),(min)) + +#define ranged( value , range ) \ + limit((value),-(range),(range)) + /* * Lines of Notes @@ -927,28 +949,28 @@ enum { }; float - drum_timer1[ chan_num ] , - drum_timer2[ chan_num ] , - drum_timer3[ chan_num ] ; + drum_timer1[ Channel_Count ] , + drum_timer2[ Channel_Count ] , + drum_timer3[ Channel_Count ] ; float - hat_timer[ chan_num ] , - hat_old1[ chan_num ] , - hat_old2[ chan_num ] ; + hat_timer[ Channel_Count ] , + hat_old1[ Channel_Count ] , + hat_old2[ Channel_Count ] ; float - bass_tdelta[ chan_num ] , - bass_delta[ chan_num ] , - bass_timer[ chan_num ] , - bass_freq[ chan_num ] ; + bass_tdelta[ Channel_Count ] , + bass_delta[ Channel_Count ] , + bass_timer[ Channel_Count ] , + bass_freq[ Channel_Count ] ; float - effect_timer1[ chan_num ] , - effect_timer2[ chan_num ] ; + effect_timer1[ Channel_Count ] , + effect_timer2[ Channel_Count ] ; -int effect_lowfilter[ chan_num ]; +int effect_lowfilter[ Channel_Count ]; -int syn [ chan_num ] = { +int syn [ Channel_Count ] = { SYNTH_DRUM , SYNTH_HAT , SYNTH_BASS , @@ -960,23 +982,20 @@ int syn [ chan_num ] = { }; -#define echo_size ( one_tick_size * 3 ) float - echo_buf1[ echo_size * 2 ] , - echo_buf2[ echo_size * 2 ] ; + echo_buf1[ Echo_Size * 2 ] , + echo_buf2[ Echo_Size * 2 ] ; int echo_ptr = 0; -#define reverb 16 -int slow_reverb[ reverb ]; +int slow_reverb[ Reverb ]; -#define max_flanger_size 100 float - flanger_buf1[ max_flanger_size * 3 * 6 ] , - flanger_buf2[ max_flanger_size * 3 * 6 ] ; + flanger_buf1[ Flanger_Max_Size * 3 * 6 ] , + flanger_buf2[ Flanger_Max_Size * 3 * 6 ] ; float flanger_timer = 0 , @@ -991,14 +1010,14 @@ int rec_play = 0 , rec_ptr = 0 ; -#define rec_size ( one_tick_size * 16 ) +#define rec_size ( Tick_Size * 16 ) float rec1[ rec_size ] , rec2[ rec_size ] ; -static inline void flanger_put ( float v1 , float v2 ){ +static inline void putFlanger ( float v1 , float v2 ){ float ptr2 = flanger_ptr - flanger_size; @@ -1010,7 +1029,7 @@ static inline void flanger_put ( float v1 , float v2 ){ } -static inline void flanger_get ( float * v1 , float * v2 ){ +static inline void getFlanger ( float * v1 , float * v2 ){ int index = (int) flanger_ptr; @@ -1029,33 +1048,34 @@ static inline void flanger_get ( float * v1 , float * v2 ){ flanger_size = (rec_play) ? 580 - : ( ( sin( flanger_timer / 10 ) + 1 ) / 2 ) * ( max_flanger_size - 30 ) + 30; + : ( ( sin( flanger_timer / 10 ) + 1 ) / 2 ) * ( Flanger_Max_Size - 30 ) + 30; } -static inline void echo_put ( float v1 , float v2 ){ +static inline void putEcho ( float v1 , float v2 ){ - int ptr2 = echo_ptr - echo_size; + int ptr2 = echo_ptr - Echo_Size; if( ptr2 < 0 ) - ptr2 += ( echo_size * 2 ); + ptr2 += ( Echo_Size * 2 ); - if( ptr2 < echo_size ) + if( ptr2 < Echo_Size ) echo_buf1[ ptr2 ] += v1 / 2; else echo_buf2[ ptr2 ] += v2 / 2; + // Slow Reverb - for ( int a = 0 ; a < reverb ; a++ ){ + for ( int a = 0 ; a < Reverb ; a++ ){ ptr2 = echo_ptr + slow_reverb[ a ]; if( ptr2 < 0 ) - ptr2 += ( echo_size * 2 ) * ( 1 - ( ptr2 / ( echo_size * 2 ) ) ); + ptr2 += ( Echo_Size * 2 ) * ( 1 - ( ptr2 / ( Echo_Size * 2 ) ) ); - if( ptr2 >= ( echo_size * 2 ) ) - ptr2 -= ( echo_size * 2 ) * ( ptr2 / ( echo_size * 2 ) ); + if( ptr2 >= ( Echo_Size * 2 ) ) + ptr2 -= ( Echo_Size * 2 ) * ( ptr2 / ( Echo_Size * 2 ) ); if( a & 1 ) echo_buf1[ ptr2 ] += v1 / 6; @@ -1065,21 +1085,19 @@ static inline void echo_put ( float v1 , float v2 ){ } -static inline void reverb_put ( float v1 , float v2 ){ - - int ptr2; - - // Slow Reverb +// Slow Reverb - for( int a = 0 ; a < reverb ; a++ ){ +static inline void putReverb ( float v1 , float v2 ){ + + for( int a = 0 ; a < Reverb ; a++ ){ - ptr2 = echo_ptr + slow_reverb[ a ]; + int ptr2 = echo_ptr + slow_reverb[ a ]; if( ptr2 < 0 ) - ptr2 += ( echo_size * 2 ) * ( 1 - ( ptr2 / (echo_size * 2) ) ); + ptr2 += ( Echo_Size * 2 ) * ( 1 - ( ptr2 / (Echo_Size * 2) ) ); - if( ptr2 >= ( echo_size * 2 ) ) - ptr2 -= ( echo_size * 2 ) * ( ptr2 / (echo_size * 2) ); + if( ptr2 >= ( Echo_Size * 2 ) ) + ptr2 -= ( Echo_Size * 2 ) * ( ptr2 / (Echo_Size * 2) ); if( a & 1 ) echo_buf1[ ptr2 ] += v1 / 6; @@ -1089,28 +1107,28 @@ static inline void reverb_put ( float v1 , float v2 ){ } -static inline void echo_get ( float * v1 , float * v2 ){ +static inline void getEcho ( float * v1 , float * v2 ){ * v1 += echo_buf1[ echo_ptr ]; * v2 += echo_buf2[ echo_ptr ]; echo_ptr++; - if( echo_ptr < echo_size * 2 ) + if( echo_ptr < Echo_Size * 2 ) return; echo_ptr = 0; - int r = ( ( rand() & 255 ) * (echo_size/2) ) >> 8; + int r = ( ( rand() & 255 ) * (Echo_Size/2) ) >> 8; - r += echo_size; + r += Echo_Size; - for ( int a = 0 ; a < ( echo_size * 2 ) ; a++ ){ + for ( int a = 0 ; a < ( Echo_Size * 2 ) ; a++ ){ int ptr2 = a - r; if( ptr2 < 0 ) - ptr2 += ( echo_size * 2 ); + ptr2 += ( Echo_Size * 2 ); echo_buf1[ a ] = ( echo_buf1[ a ] + echo_buf1[ ptr2 ] ) / 2; echo_buf2[ a ] = ( echo_buf2[ a ] + echo_buf2[ ptr2 ] ) / 2; @@ -1118,25 +1136,29 @@ static inline void echo_get ( float * v1 , float * v2 ){ } + +void clearBuffer ( float * buffer , int frames ){ + + int length = frames * 2; + + for ( int offset = 0 ; offset < length ; offset++ ) + buffer [ offset ] = 0; +} + + + float bound = 0.05; int offset = 0; -void main_callback ( float * buf , int len ){ +void play ( float * buffer , int len ){ - uint8_t * cur_line; - float res1, res2; float freq; - // Clear Buffer + clearBuffer(buffer,len); - for ( int a = 0 ; a < len ; a++ ){ - buf[ ( a << 1 ) + 1 ] = 0; - buf[ ( a << 1 ) + 0 ] = 0; - } - // Render @@ -1144,379 +1166,423 @@ void main_callback ( float * buf , int len ){ for ( int a = 0 ; a < len ; a++ ){ - tick_changed = 0; + tick_changed = 0; - // Increment Tick Number + // Increment Tick Number - if( timer >= one_tick_size ){ - timer = 0; - tick++; - } + if( timer >= Tick_Size ){ + timer = 0; + tick++; + } - if( timer == 0 ) - tick_changed = 1; - - // Synths Channels - - for ( int s = 0 ; s < chan_num ; s++ ){ + if( timer == 0 ) + tick_changed = 1; + + // Synths Channels + + for ( int s = 0 ; s < Channel_Count ; s++ ){ - cur_line = patterns[ cur_pattern ] + ( tick * chan_num ); - - // End of Pattern + uint8_t * line = + patterns[ pattern ] + + ( tick * Channel_Count ); + + // End of Pattern - if( cur_line[ s ] == 255 ){ + if( line[ s ] == 255 ){ - cur_pattern++; - tick = 0; - - if( patterns[ cur_pattern ] == 0 ){ - exit_request = 1; - return; + pattern++; + tick = 0; + + if( patterns[ pattern ] == 0 ){ + exit_request = 1; + return; + } + + line = + patterns[ pattern ] + + ( tick * Channel_Count ); } - cur_line = patterns[ cur_pattern ] + ( tick * chan_num ); - } + if( syn[ s ] == 0 ) + continue; + + switch( syn[ s ] ){ + case SYNTH_PAD : - if( syn[ s ] == 0 ) - continue; - - switch( syn[ s ] ){ - case SYNTH_PAD : + if( tick_changed ){ - if( tick_changed ){ + if( line[ s ] ){ + effect_timer1[ s ] = 1; + bass_freq[ s ] = pow( 2, (float)( line[ s ] + offset ) / 12.0F ); + bass_tdelta[ s ] = bass_freq[ s ] / srate; + bass_timer[ s ] = 0; + } - if( cur_line[ s ] ){ - effect_timer1[ s ] = 1; - bass_freq[ s ] = pow( 2, (float)( cur_line[ s ] + offset ) / 12.0F ); - bass_tdelta[ s ] = bass_freq[ s ] / srate; - bass_timer[ s ] = 0; + if( line[ s ] == 254 ) + effect_timer1[ s ] = 0; + + if( line[ s ] == 253 ){ + effect_timer1[ s ] = 0; + bound = 0.1; + } } - if( cur_line[ s ] == 254 ) - effect_timer1[ s ] = 0; + if( effect_timer1[ s ] ){ - if( cur_line[ s ] == 253 ){ - effect_timer1[ s ] = 0; - bound = 0.1; - } - } + effect_timer1[ s ] *= 0.99998; + + bass_delta[ s ] += ( bass_tdelta[ s ] - bass_delta[ s ] ) / 2000; + bass_timer[ s ] += bass_delta[ s ]; + + float bass = bass_timer[s]; - if( effect_timer1[ s ] ){ + res2 = res1 = cos( bass * 0.99 ); - effect_timer1[ s ] *= 0.99998; - - bass_delta[ s ] += ( bass_tdelta[ s ] - bass_delta[ s ] ) / 2000; - bass_timer[ s ] += bass_delta[ s ]; - - res1 = sin( bass_timer[ s ] ) * sin( bass_timer[ s ] * (sin( effect_timer1[ s ] ) * 0.02) ) + cos( bass_timer[ s ] * 0.99 ); - res2 = cos( bass_timer[ s ] * 1.01 ) + cos( bass_timer[ s ] * 0.99 ); + res1 += + sin( bass * (sin( effect_timer1[ s ] ) * 0.02) ) * + sin( bass ); + + res2 += cos( bass * 1.01 ); + + res1 = limit(res1,-1,1); + res2 = limit(res2,-1,1); + + } else { + res1 = 0; + res2 = 0; + } + + putEcho( + res1 / 8 , + res2 / 8 + ); - if( res1 > 1 ) res1 = 1; - if( res1 < -1 ) res1 = -1; - if( res2 > 1 ) res2 = 1; - if( res2 < -1 ) res2 = -1; - } else { res1 = 0; res2 = 0; - } + + break; + case SYNTH_POLY : + + if( tick_changed ) + if( line[ s ] ){ + effect_timer1[ s ] = 1; + bass_freq[ s ] = pow( 2, (float)( line[ s ] + offset ) / 12.0F ); + bass_tdelta[ s ] = bass_freq[ s ] / srate; + bass_timer[ s ] = 0; + } + + if( effect_timer1[ s ] ){ + + effect_timer1[ s ] *= 0.99998; + + bass_delta[ s ] += ( bass_tdelta[ s ] - bass_delta[ s ] ) / 1800; + bass_timer[ s ] += bass_delta[ s ]; + + res2 = res1 = effect_timer1[ s ]; + + res1 *= sin( bass_timer[ s ] ); + res2 *= sin( bass_timer[ s ] * 1.01 ); + + } else { + res1 = 0; + res2 = 0; + } - echo_put( res1 / 8, res2 / 8 ); - - res1 = 0; - res2 = 0; - - break; - case SYNTH_POLY : + buffer[ ( a << 1 ) + 1 ] += res2 / 8; + buffer[ ( a << 1 ) + 0 ] += res1 / 8; - if( tick_changed ) - if( cur_line[ s ] ){ - effect_timer1[ s ] = 1; - bass_freq[ s ] = pow( 2, (float)( cur_line[ s ] + offset ) / 12.0F ); - bass_tdelta[ s ] = bass_freq[ s ] / srate; - bass_timer[ s ] = 0; - } + putEcho( + res1 / 4 , + res2 / 4 + ); - if( effect_timer1[ s ] ){ - effect_timer1[ s ] *= 0.99998; - bass_delta[ s ] += ( bass_tdelta[ s ] - bass_delta[ s ] ) / 1800; - bass_timer[ s ] += bass_delta[ s ]; - res1 = sin( bass_timer[ s ] ) * effect_timer1[ s ]; - res2 = sin( bass_timer[ s ] * 1.01 ) * effect_timer1[ s ]; - } else { res1 = 0; res2 = 0; - } - - buf[ ( a << 1 ) + 1 ] += res2 / 8; - buf[ ( a << 1 ) ] += res1 / 8; - echo_put( res1 / 4, res2 / 4 ); + break; + case SYNTH_EFFECT : + + if( tick_changed ){ + + if( line[ s ] ){ + effect_timer1[ s ] = 1; + effect_timer2[ s ] = 0; + } + + if( line[ s ] == 5 ){ + effect_lowfilter[ s ] = 4; + rec_play = 1; + } + + if( line[ s ] == 4 ) + effect_lowfilter[ s ] = 3; + + if( line[ s ] == 3 ) + effect_lowfilter[ s ] = 2; + + if( line[ s ] == 2 ) + effect_lowfilter[ s ] = 1; + + if( line[ s ] == 1 ) + effect_lowfilter[ s ] = 0; + } - res1 = 0; - res2 = 0; + if( effect_timer1[ s ] ){ + + effect_timer1[ s ] *= 0.99996; + effect_timer2[ s ] += 0.2; + + if( effect_lowfilter[ s ] == 4 ){ + effect_timer1[ s ] = 1; + } else + if( effect_lowfilter[ s ] == 3 ){ + res2 = sin( ( effect_timer2[ s ] * 1 ) * effect_timer1[ s ] ) * effect_timer1[ s ]; + res1 = sin( ( effect_timer2[ s ] * 1.5 ) / effect_timer1[ s ] ) * effect_timer1[ s ]; + } else + if( effect_lowfilter[ s ] == 2 ){ + res2 = sin( ( effect_timer2[ s ] / 4 ) / effect_timer1[ s ] ) * effect_timer1[ s ]; + res1 = sin( ( effect_timer2[ s ] / 3.5 ) / effect_timer1[ s ] ) * effect_timer1[ s ]; + } else + if( effect_lowfilter[ s ] == 1 ){ + res2 = sin( ( effect_timer2[ s ] / 2 ) / effect_timer1[ s ] ) * effect_timer1[ s ]; + res1 = sin( ( effect_timer2[ s ] / 2.5 ) / effect_timer1[ s ] ) * effect_timer1[ s ]; + } else { + res2 = res1 = sin( effect_timer2[ s ] / effect_timer1[ s ] ) * effect_timer1[ s ]; + } + } else { + res1 = 0; + res2 = 0; + } - break; - case SYNTH_EFFECT : + buffer[ ( a << 1 ) + 1 ] += ( res2 / 9.0F ); + buffer[ ( a << 1 ) + 0 ] += ( res1 / 9.0F ); - if( tick_changed ){ + if( effect_lowfilter[ s ] != 4 ) + putEcho( res1 / 5, res2 / 5 ); + + res1 = 0; + res2 = 0; + + break; + case SYNTH_ACID_BASS: - if( cur_line[ s ] ){ + if( tick_changed ){ + + bass_freq[ s ] = pow( 2, (float)( line[ s ] + offset ) / 12.0F ); + bass_tdelta[ s ] = bass_freq[ s ] / srate; + bass_timer[ s ] = 0; + effect_timer1[ s ] = 1; effect_timer2[ s ] = 0; } - if( cur_line[ s ] == 5 ){ - effect_lowfilter[ s ] = 4; - rec_play = 1; - } - - if( cur_line[ s ] == 4 ) - effect_lowfilter[ s ] = 3; - - if( cur_line[ s ] == 3 ) - effect_lowfilter[ s ] = 2; + bass_delta[ s ] += ( bass_tdelta[ s ] - bass_delta[ s ] ) / 300; + bass_timer[ s ] += bass_delta[ s ]; - if( cur_line[ s ] == 2 ) - effect_lowfilter[ s ] = 1; + effect_timer2[ s ] += 0.02 * (32 - (float)tick); + effect_timer1[ s ] *= 0.9997; - if( cur_line[ s ] == 1 ) - effect_lowfilter[ s ] = 0; - } + if( line[ s ] ){ + + res2 = res1 = + sin( bass_timer[ s ] ) + + sin( bass_timer[ s ] * 4.01 ) * 0.9; + + if( res1 > 0.2 ) + res1 = 0.1; + + if( res1 < -0.2 ) + res1 = -0.1; + + if( res2 > 0.2 ) + res2 = 0.1; + + if( res2 < -0.2 ) + res2 = -0.1; + + res1 *= effect_timer1[ s ]; + res2 *= effect_timer1[ s ]; - if( effect_timer1[ s ] ){ + } else { + res1 = 0; + res2 = 0; + } - effect_timer1[ s ] *= 0.99996; - effect_timer2[ s ] += 0.2; + putEcho( res1, res2 ); + + buffer[ ( a << 1 ) + 1 ] += res2; + buffer[ ( a << 1 ) + 0 ] += res1; + + break; + case SYNTH_BASS_TINY : + case SYNTH_BASS : - if( effect_lowfilter[ s ] == 4 ){ + if( tick_changed ){ + bass_freq[ s ] = pow( 2, (float)( line[ s ] + offset ) / 12.0F ); + bass_tdelta[ s ] = bass_freq[ s ] / srate; + bass_timer[ s ] = 0; effect_timer1[ s ] = 1; - } else - if( effect_lowfilter[ s ] == 3 ){ - res2 = sin( ( effect_timer2[ s ] * 1 ) * effect_timer1[ s ] ) * effect_timer1[ s ]; - res1 = sin( ( effect_timer2[ s ] * 1.5 ) / effect_timer1[ s ] ) * effect_timer1[ s ]; - } else - if( effect_lowfilter[ s ] == 2 ){ - res2 = sin( ( effect_timer2[ s ] / 4 ) / effect_timer1[ s ] ) * effect_timer1[ s ]; - res1 = sin( ( effect_timer2[ s ] / 3.5 ) / effect_timer1[ s ] ) * effect_timer1[ s ]; - } else - if( effect_lowfilter[ s ] == 1 ){ - res2 = sin( ( effect_timer2[ s ] / 2 ) / effect_timer1[ s ] ) * effect_timer1[ s ]; - res1 = sin( ( effect_timer2[ s ] / 2.5 ) / effect_timer1[ s ] ) * effect_timer1[ s ]; - } else { - res2 = res1 = sin( effect_timer2[ s ] / effect_timer1[ s ] ) * effect_timer1[ s ]; } - } else { - res1 = 0; - res2 = 0; - } - buf[ ( a << 1 ) + 1 ] += ( res2 / 9.0F ); - buf[ ( a << 1 ) ] += ( res1 / 9.0F ); + bass_delta[ s ] += ( bass_tdelta[ s ] - bass_delta[ s ] ) / 300; + bass_timer[ s ] += bass_delta[ s ]; + + effect_timer1[ s ] *= 0.9999; + + if( line[ s ] ){ + + res1 = + sin( bass_timer[ s ] ) + + sin( bass_timer[ s ] * 2.01 ); + + res2 = + cos( bass_timer[ s ] ) + + cos( bass_timer[ s ] * 2.006 ); + + if( res1 > bound ) + res1 = 0.05; + + if( res1 < -bound ) + res1 = -0.05; + + if( res2 > bound ) + res2 = 0.05; + + if( res2 < -bound ) + res2 = -0.05; - if( effect_lowfilter[ s ] != 4 ) - echo_put( res1 / 5, res2 / 5 ); - - res1 = 0; - res2 = 0; - - break; - case SYNTH_ACID_BASS: + } else { + res1 = 0; + res2 = 0; + } - if( tick_changed ){ + if( bound > 0.1 ){ + res1 *= effect_timer1[ s ]; + res2 *= effect_timer1[ s ]; + } - bass_freq[ s ] = pow( 2, (float)( cur_line[ s ] + offset ) / 12.0F ); - bass_tdelta[ s ] = bass_freq[ s ] / srate; - bass_timer[ s ] = 0; + if( syn[ s ] == SYNTH_BASS_TINY ){ + res1 *= 0.9; + res2 *= 0.9; + } else + if( !rec_play ){ + + putFlanger( res1, res2 ); + + res1 /= 1.5; + res2 /= 1.5; + + getFlanger( &res1, &res2 ); + } + + putEcho( res1, res2 ); - effect_timer1[ s ] = 1; - effect_timer2[ s ] = 0; - } - - bass_delta[ s ] += ( bass_tdelta[ s ] - bass_delta[ s ] ) / 300; - bass_timer[ s ] += bass_delta[ s ]; - - effect_timer2[ s ] += 0.02 * (32 - (float)tick); - effect_timer1[ s ] *= 0.9997; - - if( cur_line[ s ] ){ + buffer[ ( a << 1 ) + 1 ] += res2; + buffer[ ( a << 1 ) + 0 ] += res1; - res2 = res1 = sin( bass_timer[ s ] ) + ( sin( bass_timer[ s ] * 4.01 ) * 0.9 ); + break; + case SYNTH_HAT : + + if( tick_changed ){ + + if( line[ s ] ) + hat_timer[ s ] = 2; + + if( line[ s ] == 254 ){ + fadeout = 1; + offset++; + break; + } + + if( line[ s ] == 253 ){ + syn[ 3 ] = SYNTH_ACID_BASS; + start_recorder = 1; + } + + if( line[ s ] == 252 ) + offset --; + } + + if( line[ s ] == 254 ) + break; - if( res1 > 0.2 ) - res1 = 0.1; + if( line[ s ] == 253 ) + break; - if( res1 < -0.2 ) - res1 = -0.1; + if( line[ s ] == 252 ) + break; - if( res2 > 0.2 ) - res2 = 0.1; + hat_timer[ s ] -= 0.0004; - if( res2 < -0.2 ) - res2 = -0.1; + if( hat_timer[ s ] < 0 ){ + hat_timer[ s ] = 0; + break; + } - res1 *= effect_timer1[ s ]; - res2 *= effect_timer1[ s ]; - } else { - res1 = 0; - res2 = 0; - } + res2 = res1 = ( (float) line[ s ] / 10.0F ); - echo_put( res1, res2 ); - - buf[ ( a << 1 ) + 1 ] += res2; - buf[ ( a << 1 ) ] += res1; - - break; - case SYNTH_BASS_TINY : - case SYNTH_BASS : - - if( tick_changed ){ - bass_freq[ s ] = pow( 2, (float)( cur_line[ s ] + offset ) / 12.0F ); - bass_tdelta[ s ] = bass_freq[ s ] / srate; - bass_timer[ s ] = 0; - effect_timer1[ s ] = 1; - } - - bass_delta[ s ] += ( bass_tdelta[ s ] - bass_delta[ s ] ) / 300; - bass_timer[ s ] += bass_delta[ s ]; - effect_timer1[ s ] *= 0.9999; - - if( cur_line[ s ] ){ - - res1 = sin( bass_timer[ s ] ) + sin( bass_timer[ s ] * 2.01 ); - res2 = cos( bass_timer[ s ] ) + cos( bass_timer[ s ] * 2.006 ); + res1 *= (((float)( randomize() & 0x7FFF ) / 32000.0F ) - 0.5 ); + res2 *= (((float)( randomize() & 0x7FFF ) / 32000.0F ) - 0.5 ); - if( res1 > bound ) - res1 = 0.05; + if( res1 > hat_old1[ s ] ) + hat_old1[ s ] += 0.03; - if( res1 < -bound ) - res1 = -0.05; + if( res1 < hat_old1[ s ] ) + hat_old1[ s ] -= 0.03; - if( res2 > bound ) - res2 = 0.05; + if( res2 > hat_old2[ s ] ) + hat_old2[ s ] += 0.03; - if( res2 < -bound ) - res2 = -0.05; - } else { - res1 = 0; - res2 = 0; - } + if( res2 < hat_old2[ s ] ) + hat_old2[ s ] -= 0.03; - if( bound > 0.1 ){ - res1 *= effect_timer1[ s ]; - res2 *= effect_timer1[ s ]; - } - - if( syn[ s ] == SYNTH_BASS_TINY ){ - res1 *= 0.9; res2 *= 0.9; - } else { - if( !rec_play ){ - flanger_put( res1, res2 ); - res1 /= 1.5; res2 /= 1.5; - flanger_get( &res1, &res2 ); - } - } + res1 = hat_old1[ s ]; + res2 = hat_old2[ s ]; - echo_put( res1, res2 ); - - buf[ ( a << 1 ) + 1 ] += res2; - buf[ ( a << 1 ) ] += res1; - - break; - case SYNTH_HAT : + hat_old1[ s ] = res1; + hat_old2[ s ] = res2; - if( tick_changed ){ + float hat_factor = hat_timer[ s ] * ( (float) line[ s ] / 100.0F ); - if( cur_line[ s ] ) - hat_timer[ s ] = 2; + res1 *= hat_factor; + res2 *= hat_factor; + + buffer[ ( a << 1 ) + 0 ] += res1 / 1.8; + buffer[ ( a << 1 ) + 1 ] += res2 / 1.8; + + break; + case SYNTH_DRUM : + + if( tick_changed ) + if( line[ s ] ){ + drum_timer1[ s ] = 1; + drum_timer2[ s ] = 0; + drum_timer3[ s ] = 1; + } + + drum_timer1[ s ] -= 0.001; + drum_timer2[ s ] += 0.03; + drum_timer3[ s ] += 0.003; - if( cur_line[ s ] == 254 ){ - offset++; - fadeout = 1; + if( drum_timer1[ s ] < 0 ){ + drum_timer1[ s ] = 0; break; } + - if( cur_line[ s ] == 253 ){ - syn[ 3 ] = SYNTH_ACID_BASS; - start_recorder = 1; - } - - if( cur_line[ s ] == 252 ) - offset --; - } + float drum_ratio = drum_timer2[ s ] / drum_timer3[ s ]; - if( cur_line[ s ] == 254 ) - break; - - if( cur_line[ s ] == 253 ) - break; - - if( cur_line[ s ] == 252 ) - break; - - hat_timer[ s ] -= 0.0004; - - if( hat_timer[ s ] < 0 ){ - hat_timer[ s ] = 0; - break; - } - - res1 = ( ( (float)(randomize()&0x7FFF) / 32000.0F ) - 0.5 ) * ( (float)cur_line[ s ] / 10.0F ); - res2 = ( ( (float)(randomize()&0x7FFF) / 32000.0F ) - 0.5 ) * ( (float)cur_line[ s ] / 10.0F ); - - if( res1 > hat_old1[ s ] ) - hat_old1[ s ] += 0.03; - - if( res1 < hat_old1[ s ] ) - hat_old1[ s ] -= 0.03; - - if( res2 > hat_old2[ s ] ) - hat_old2[ s ] += 0.03; - - if( res2 < hat_old2[ s ] ) - hat_old2[ s ] -= 0.03; - - res1 = hat_old1[ s ]; - res2 = hat_old2[ s ]; - - hat_old1[ s ] = res1; - hat_old2[ s ] = res2; - - res1 *= hat_timer[ s ] * ( (float)cur_line[ s ] / 100.0F ); - res2 *= hat_timer[ s ] * ( (float)cur_line[ s ] / 100.0F ); - - buf[ ( a << 1 ) ] += res1 / 1.8; - buf[ ( a << 1 ) + 1 ] += res2 / 1.8; - - break; - case SYNTH_DRUM : - - if( tick_changed ){ - if( cur_line[ s ] ){ - drum_timer1[ s ] = 1; - drum_timer2[ s ] = 0; - drum_timer3[ s ] = 1; - } - } - - drum_timer1[ s ] -= 0.001; - drum_timer2[ s ] += 0.03; - drum_timer3[ s ] += 0.003; - - if( drum_timer1[ s ] < 0 ){ - drum_timer1[ s ] = 0; - break; - } - - if( 0 ){ - res1 = drum_timer1[ s ] * ( (float)cur_line[ s ] / 12.0F ) * sinf( ((float)cur_line[ s ] / 70) * drum_timer2[ s ] / drum_timer3[ s ] ); - res2 = drum_timer1[ s ] * ( (float)cur_line[ s ] / 12.0F ) * sinf( drum_timer2[ s ] / drum_timer3[ s ] + 2 ); - } else { + float l = line[s]; - res1 = drum_timer1[ s ] * ( (float)cur_line[ s ] / 20.0F ) * sinf( ((float)cur_line[ s ] / 70) * drum_timer2[ s ] / drum_timer3[ s ] ); - res2 = res1; - - float d2 = drum_timer1[ s ] * ( (float)cur_line[ s ] / 120.0F ) * sinf( drum_timer2[ s ] / drum_timer3[ s ] + 2 ); + res2 = res1 = + sinf( ( l / 70) * drum_ratio ) * + drum_timer1[ s ] * + ( l / 20.0F ) ; + + float d2 = + sinf( drum_ratio + 2 ) * + drum_timer1[ s ] * + ( l / 120.0F ) ; if( tick & 1 ){ res1 *= 0.3f; @@ -1525,84 +1591,76 @@ void main_callback ( float * buf , int len ){ res2 *= 0.3f; res2 += d2; } - } - - float clip = 0.3; - - if( res1 > clip ) - res1 = clip; - - if( res1 < -clip ) - res1 = -clip; - - if( res2 > clip ) - res2 = clip; - - if( res2 < -clip ) - res2 = -clip; - - buf[ ( a << 1 ) ] += res1; - buf[ ( a << 1 ) + 1 ] += res2; - - res1 = 0; - res2 = 0; - - break; - } - } - echo_get( & res1 , & res2 ); - buf[ ( a << 1 ) ] += res1; - buf[ ( a << 1 ) + 1 ] += res2; + float clip = 0.3; - if( start_recorder ){ - - rec1[ rec_ptr ] = buf[ ( a << 1 ) ]; - rec2[ rec_ptr ] = buf[ ( a << 1 ) + 1 ]; + res1 = ranged(res1,clip); + res2 = ranged(res2,clip); + + buffer[ ( a << 1 ) + 1 ] += res2; + buffer[ ( a << 1 ) + 0 ] += res1; + + res1 = 0; + res2 = 0; + + break; + } + } - rec_ptr++; + getEcho( & res1 , & res2 ); - if( rec_ptr >= rec_size ){ - start_recorder = 0; - rec_ptr --; - } - } + buffer[ ( a << 1 ) + 1 ] += res2; + buffer[ ( a << 1 ) ] += res1; - if( rec_play ){ + if( start_recorder ){ + + rec1[ rec_ptr ] = buffer[ ( a << 1 ) + 0 ]; + rec2[ rec_ptr ] = buffer[ ( a << 1 ) + 1 ]; - flanger_put( - rec1[ rec_ptr ] / 2 , - rec2[ rec_ptr ] / 2 - ); - - res1 = 0; res2 = 0; - - flanger_get( & res1 , & res2 ); - - buf[ ( a << 1 ) ] += res1; - buf[ ( a << 1 ) + 1 ] += res2; - - rec_ptr--; - - if( rec_ptr < 0 ) - rec_ptr = rec_size - 1; - } + rec_ptr++; - timer++; - - if( fadeout ){ + if( rec_ptr >= rec_size ){ + start_recorder = 0; + rec_ptr --; + } + } - fadeout_vol -= 0.000001; - - if( fadeout_vol <= 0 ){ - exit_request = 1; - fadeout_vol = 0; + if( rec_play ){ + + putFlanger( + rec1[ rec_ptr ] / 2 , + rec2[ rec_ptr ] / 2 + ); + + res1 = 0; + res2 = 0; + + getFlanger( & res1 , & res2 ); + + buffer[ ( a << 1 ) + 1 ] += res2; + buffer[ ( a << 1 ) + 0 ] += res1; + + rec_ptr--; + + if( rec_ptr < 0 ) + rec_ptr = rec_size - 1; + } + + timer++; + + if( fadeout ){ + + fadeout_vol -= 0.000001; + + if( fadeout_vol <= 0 ){ + exit_request = 1; + fadeout_vol = 0; + } + + buffer[ ( a << 1 ) + 0 ] *= fadeout_vol; + buffer[ ( a << 1 ) + 1 ] *= fadeout_vol; } - - buf[ ( a << 1 ) + 1 ] *= fadeout_vol; - buf[ ( a << 1 ) ] *= fadeout_vol; - } } } @@ -1618,7 +1676,7 @@ void main_callback ( float * buf , int len ){ void renderBuffer( float * buffer , int length ){ - main_callback( buffer , length ); + play( buffer , length ); // Simple DC Blocker @@ -1822,7 +1880,7 @@ int exportWAV ( const char * path ){ int sound_init ( const char * path ){ - for ( int a = 0 ; a < reverb ; a++ ) + for ( int a = 0 ; a < Reverb ; a++ ) slow_reverb[ a ] = ( ( rand() & 2047 ) - 1024 ) << 6; if( out_mode == 0 ){ From aa43a62f70ab0d08ac061dcc19b918c31b92a9a1 Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Sun, 27 Nov 2022 06:02:36 -0500 Subject: [PATCH 12/18] General Refactoring --- ps.c | 438 ++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 235 insertions(+), 203 deletions(-) diff --git a/ps.c b/ps.c index e863eb6..a817f47 100644 --- a/ps.c +++ b/ps.c @@ -52,16 +52,16 @@ int tick = 0; //0...pattern size (number of lines) int pattern = 0; //0...number of patterns float - dc_sl = 0 , - dc_sr = 0 ; + dc_s_left = 0 , + dc_s_right = 0 ; float - dc_psl = 0 , - dc_psr = 0 ; + dc_ps_left = 0 , + dc_ps_right = 0 ; float loudest = 1; -int exit_request = 0; +int stop_execution = 0; int out_mode = 0; //0 - SDL; 1 - WAV EXPORT; @@ -85,8 +85,10 @@ int randomize (){ /* - * Lines of Notes - * 1 Line = 8 x Notes ( uint8_t ) + * Note Patterns + * ============= + * - One line consists of 8 channels + * - A value of 255 marks the end of the pattern */ uint8_t notes [] = { @@ -951,20 +953,17 @@ enum { float drum_timer1[ Channel_Count ] , drum_timer2[ Channel_Count ] , - drum_timer3[ Channel_Count ] ; + drum_timer3[ Channel_Count ] , -float hat_timer[ Channel_Count ] , hat_old1[ Channel_Count ] , - hat_old2[ Channel_Count ] ; + hat_old2[ Channel_Count ] , -float bass_tdelta[ Channel_Count ] , bass_delta[ Channel_Count ] , bass_timer[ Channel_Count ] , - bass_freq[ Channel_Count ] ; + bass_freq[ Channel_Count ] , -float effect_timer1[ Channel_Count ] , effect_timer2[ Channel_Count ] ; @@ -1119,7 +1118,7 @@ static inline void getEcho ( float * v1 , float * v2 ){ echo_ptr = 0; - int r = ( ( rand() & 255 ) * (Echo_Size/2) ) >> 8; + int r = ( ( rand() & 255 ) * ( Echo_Size / 2 ) ) >> 8; r += Echo_Size; @@ -1146,25 +1145,34 @@ void clearBuffer ( float * buffer , int frames ){ } +/** + * @details End of pattern list is marked with a `0` + */ + +bool finishedPlaying (){ + return patterns[ pattern ] == 0; +} + + float bound = 0.05; int offset = 0; -void play ( float * buffer , int len ){ +void play ( float * buffer , int length ){ float res1, res2; float freq; - clearBuffer(buffer,len); + clearBuffer(buffer,length); // Render int tick_changed = 0; - for ( int a = 0 ; a < len ; a++ ){ + for ( int a = 0 ; a < length ; a++ ){ tick_changed = 0; @@ -1180,66 +1188,67 @@ void play ( float * buffer , int len ){ // Synths Channels - for ( int s = 0 ; s < Channel_Count ; s++ ){ + for ( int channel = 0 ; channel < Channel_Count ; channel++ ){ + + uint8_t * row = patterns[ pattern ]; - uint8_t * line = - patterns[ pattern ] + - ( tick * Channel_Count ); + row += tick * Channel_Count; - // End of Pattern - if( line[ s ] == 255 ){ + // Has reached the end of the current pattern + + if( row[ channel ] == 255 ){ pattern++; tick = 0; - if( patterns[ pattern ] == 0 ){ - exit_request = 1; + if(finishedPlaying()){ + stop_execution = true; return; } - line = - patterns[ pattern ] + - ( tick * Channel_Count ); + row = patterns[ pattern ]; } - if( syn[ s ] == 0 ) + + if( syn[ channel ] == 0 ) continue; - switch( syn[ s ] ){ + + switch( syn[ channel ] ){ case SYNTH_PAD : if( tick_changed ){ - if( line[ s ] ){ - effect_timer1[ s ] = 1; - bass_freq[ s ] = pow( 2, (float)( line[ s ] + offset ) / 12.0F ); - bass_tdelta[ s ] = bass_freq[ s ] / srate; - bass_timer[ s ] = 0; + if( row[ channel ] ){ + effect_timer1[ channel ] = 1; + bass_freq[ channel ] = pow( 2, (float)( row[ channel ] + offset ) / 12.0F ); + bass_tdelta[ channel ] = bass_freq[ channel ] / srate; + bass_timer[ channel ] = 0; } - if( line[ s ] == 254 ) - effect_timer1[ s ] = 0; + if( row[ channel ] == 254 ) + effect_timer1[ channel ] = 0; - if( line[ s ] == 253 ){ - effect_timer1[ s ] = 0; + if( row[ channel ] == 253 ){ + effect_timer1[ channel ] = 0; bound = 0.1; } } - if( effect_timer1[ s ] ){ + if( effect_timer1[ channel ] ){ - effect_timer1[ s ] *= 0.99998; + effect_timer1[ channel ] *= 0.99998; - bass_delta[ s ] += ( bass_tdelta[ s ] - bass_delta[ s ] ) / 2000; - bass_timer[ s ] += bass_delta[ s ]; + bass_delta[ channel ] += ( bass_tdelta[ channel ] - bass_delta[ channel ] ) / 2000; + bass_timer[ channel ] += bass_delta[ channel ]; - float bass = bass_timer[s]; + float bass = bass_timer[channel]; res2 = res1 = cos( bass * 0.99 ); res1 += - sin( bass * (sin( effect_timer1[ s ] ) * 0.02) ) * + sin( bass * (sin( effect_timer1[ channel ] ) * 0.02) ) * sin( bass ); res2 += cos( bass * 1.01 ); @@ -1264,24 +1273,24 @@ void play ( float * buffer , int len ){ case SYNTH_POLY : if( tick_changed ) - if( line[ s ] ){ - effect_timer1[ s ] = 1; - bass_freq[ s ] = pow( 2, (float)( line[ s ] + offset ) / 12.0F ); - bass_tdelta[ s ] = bass_freq[ s ] / srate; - bass_timer[ s ] = 0; + if( row[ channel ] ){ + effect_timer1[ channel ] = 1; + bass_freq[ channel ] = pow( 2, (float)( row[ channel ] + offset ) / 12.0F ); + bass_tdelta[ channel ] = bass_freq[ channel ] / srate; + bass_timer[ channel ] = 0; } - if( effect_timer1[ s ] ){ + if( effect_timer1[ channel ] ){ - effect_timer1[ s ] *= 0.99998; + effect_timer1[ channel ] *= 0.99998; - bass_delta[ s ] += ( bass_tdelta[ s ] - bass_delta[ s ] ) / 1800; - bass_timer[ s ] += bass_delta[ s ]; + bass_delta[ channel ] += ( bass_tdelta[ channel ] - bass_delta[ channel ] ) / 1800; + bass_timer[ channel ] += bass_delta[ channel ]; - res2 = res1 = effect_timer1[ s ]; + res2 = res1 = effect_timer1[ channel ]; - res1 *= sin( bass_timer[ s ] ); - res2 *= sin( bass_timer[ s ] * 1.01 ); + res1 *= sin( bass_timer[ channel ] ); + res2 *= sin( bass_timer[ channel ] * 1.01 ); } else { res1 = 0; @@ -1304,51 +1313,62 @@ void play ( float * buffer , int len ){ if( tick_changed ){ - if( line[ s ] ){ - effect_timer1[ s ] = 1; - effect_timer2[ s ] = 0; + uint8_t l = row[channel]; + + if( l ){ + effect_timer1[ channel ] = 1; + effect_timer2[ channel ] = 0; } - if( line[ s ] == 5 ){ - effect_lowfilter[ s ] = 4; + if( l == 5 ) rec_play = 1; - } - if( line[ s ] == 4 ) - effect_lowfilter[ s ] = 3; - if( line[ s ] == 3 ) - effect_lowfilter[ s ] = 2; - - if( line[ s ] == 2 ) - effect_lowfilter[ s ] = 1; - - if( line[ s ] == 1 ) - effect_lowfilter[ s ] = 0; + effect_lowfilter[ channel ] = l - 1; } - if( effect_timer1[ s ] ){ - - effect_timer1[ s ] *= 0.99996; - effect_timer2[ s ] += 0.2; - - if( effect_lowfilter[ s ] == 4 ){ - effect_timer1[ s ] = 1; - } else - if( effect_lowfilter[ s ] == 3 ){ - res2 = sin( ( effect_timer2[ s ] * 1 ) * effect_timer1[ s ] ) * effect_timer1[ s ]; - res1 = sin( ( effect_timer2[ s ] * 1.5 ) / effect_timer1[ s ] ) * effect_timer1[ s ]; - } else - if( effect_lowfilter[ s ] == 2 ){ - res2 = sin( ( effect_timer2[ s ] / 4 ) / effect_timer1[ s ] ) * effect_timer1[ s ]; - res1 = sin( ( effect_timer2[ s ] / 3.5 ) / effect_timer1[ s ] ) * effect_timer1[ s ]; - } else - if( effect_lowfilter[ s ] == 1 ){ - res2 = sin( ( effect_timer2[ s ] / 2 ) / effect_timer1[ s ] ) * effect_timer1[ s ]; - res1 = sin( ( effect_timer2[ s ] / 2.5 ) / effect_timer1[ s ] ) * effect_timer1[ s ]; + if( effect_timer1[ channel ] ){ + + effect_timer1[ channel ] *= 0.99996; + effect_timer2[ channel ] += 0.2; + + int filter = effect_lowfilter[channel]; + + float + effect1 = effect_timer1[channel] , + effect2 = effect_timer2[channel] ; + + + if( filter == 4 ){ + effect_timer1[ channel ] = 1; } else { - res2 = res1 = sin( effect_timer2[ s ] / effect_timer1[ s ] ) * effect_timer1[ s ]; + + switch ( filter ){ + case 3 : + res1 = effect2 * 1.5; + res2 = effect2 * 1.0; + break; + case 2 : + res1 = effect2 / 4.0; + res2 = effect2 / 3.5; + break; + case 1 : + res1 = effect2 / 2.0; + res2 = effect2 / 2.5; + break; + default: + res2 = res1 = effect2; + } + + res2 /= effect1; + res2 = sin(res2); + res2 *= effect1; + + res1 /= effect1; + res1 = sin(res2); + res1 *= effect1; } + } else { res1 = 0; res2 = 0; @@ -1357,8 +1377,11 @@ void play ( float * buffer , int len ){ buffer[ ( a << 1 ) + 1 ] += ( res2 / 9.0F ); buffer[ ( a << 1 ) + 0 ] += ( res1 / 9.0F ); - if( effect_lowfilter[ s ] != 4 ) - putEcho( res1 / 5, res2 / 5 ); + if( effect_lowfilter[ channel ] != 4 ) + putEcho( + res1 / 5 , + res2 / 5 + ); res1 = 0; res2 = 0; @@ -1368,25 +1391,27 @@ void play ( float * buffer , int len ){ if( tick_changed ){ - bass_freq[ s ] = pow( 2, (float)( line[ s ] + offset ) / 12.0F ); - bass_tdelta[ s ] = bass_freq[ s ] / srate; - bass_timer[ s ] = 0; + bass_freq[ channel ] = pow( 2, (float)( row[ channel ] + offset ) / 12.0F ); + bass_tdelta[ channel ] = bass_freq[ channel ] / srate; + bass_timer[ channel ] = 0; - effect_timer1[ s ] = 1; - effect_timer2[ s ] = 0; + effect_timer1[ channel ] = 1; + effect_timer2[ channel ] = 0; } - bass_delta[ s ] += ( bass_tdelta[ s ] - bass_delta[ s ] ) / 300; - bass_timer[ s ] += bass_delta[ s ]; + bass_delta[ channel ] += ( bass_tdelta[ channel ] - bass_delta[ channel ] ) / 300; + bass_timer[ channel ] += bass_delta[ channel ]; - effect_timer2[ s ] += 0.02 * (32 - (float)tick); - effect_timer1[ s ] *= 0.9997; + effect_timer2[ channel ] += 0.02 * (32 - (float)tick); + effect_timer1[ channel ] *= 0.9997; - if( line[ s ] ){ + if( row[ channel ] ){ + + float bass = bass_timer[channel]; res2 = res1 = - sin( bass_timer[ s ] ) + - sin( bass_timer[ s ] * 4.01 ) * 0.9; + sin( bass * 4.01 ) * 0.9 + + sin( bass ) ; if( res1 > 0.2 ) res1 = 0.1; @@ -1400,15 +1425,15 @@ void play ( float * buffer , int len ){ if( res2 < -0.2 ) res2 = -0.1; - res1 *= effect_timer1[ s ]; - res2 *= effect_timer1[ s ]; + res1 *= effect_timer1[ channel ]; + res2 *= effect_timer1[ channel ]; } else { res1 = 0; res2 = 0; } - putEcho( res1, res2 ); + putEcho( res1 , res2 ); buffer[ ( a << 1 ) + 1 ] += res2; buffer[ ( a << 1 ) + 0 ] += res1; @@ -1418,38 +1443,40 @@ void play ( float * buffer , int len ){ case SYNTH_BASS : if( tick_changed ){ - bass_freq[ s ] = pow( 2, (float)( line[ s ] + offset ) / 12.0F ); - bass_tdelta[ s ] = bass_freq[ s ] / srate; - bass_timer[ s ] = 0; - effect_timer1[ s ] = 1; + bass_freq[ channel ] = pow( 2, (float)( row[ channel ] + offset ) / 12.0F ); + bass_tdelta[ channel ] = bass_freq[ channel ] / srate; + bass_timer[ channel ] = 0; + effect_timer1[ channel ] = 1; } - bass_delta[ s ] += ( bass_tdelta[ s ] - bass_delta[ s ] ) / 300; - bass_timer[ s ] += bass_delta[ s ]; + bass_delta[ channel ] += ( bass_tdelta[ channel ] - bass_delta[ channel ] ) / 300; + bass_timer[ channel ] += bass_delta[ channel ]; - effect_timer1[ s ] *= 0.9999; + effect_timer1[ channel ] *= 0.9999; + + if( row[ channel ] ){ - if( line[ s ] ){ + float bass = bass_timer[channel]; res1 = - sin( bass_timer[ s ] ) + - sin( bass_timer[ s ] * 2.01 ); + sin( bass ) + + sin( bass * 2.01 ); res2 = - cos( bass_timer[ s ] ) + - cos( bass_timer[ s ] * 2.006 ); + cos( bass ) + + cos( bass * 2.006 ); - if( res1 > bound ) - res1 = 0.05; + if( res1 > + bound ) + res1 = + 0.05; - if( res1 < -bound ) - res1 = -0.05; + if( res1 < - bound ) + res1 = - 0.05; - if( res2 > bound ) - res2 = 0.05; + if( res2 > + bound ) + res2 = + 0.05; - if( res2 < -bound ) - res2 = -0.05; + if( res2 < - bound ) + res2 = - 0.05; } else { res1 = 0; @@ -1457,25 +1484,25 @@ void play ( float * buffer , int len ){ } if( bound > 0.1 ){ - res1 *= effect_timer1[ s ]; - res2 *= effect_timer1[ s ]; + res1 *= effect_timer1[ channel ]; + res2 *= effect_timer1[ channel ]; } - if( syn[ s ] == SYNTH_BASS_TINY ){ + if( syn[ channel ] == SYNTH_BASS_TINY ){ res1 *= 0.9; res2 *= 0.9; } else if( !rec_play ){ - putFlanger( res1, res2 ); + putFlanger( res1 , res2 ); res1 /= 1.5; res2 /= 1.5; - getFlanger( &res1, &res2 ); + getFlanger( & res1 , & res2 ); } - putEcho( res1, res2 ); + putEcho( res1 , res2 ); buffer[ ( a << 1 ) + 1 ] += res2; buffer[ ( a << 1 ) + 0 ] += res1; @@ -1485,64 +1512,66 @@ void play ( float * buffer , int len ){ if( tick_changed ){ - if( line[ s ] ) - hat_timer[ s ] = 2; + if( row[ channel ] ) + hat_timer[ channel ] = 2; - if( line[ s ] == 254 ){ + if( row[ channel ] == 254 ){ fadeout = 1; offset++; break; } - if( line[ s ] == 253 ){ + if( row[ channel ] == 253 ){ syn[ 3 ] = SYNTH_ACID_BASS; start_recorder = 1; } - if( line[ s ] == 252 ) + if( row[ channel ] == 252 ) offset --; } - if( line[ s ] == 254 ) + if( row[ channel ] == 254 ) break; - if( line[ s ] == 253 ) + if( row[ channel ] == 253 ) break; - if( line[ s ] == 252 ) + if( row[ channel ] == 252 ) break; - hat_timer[ s ] -= 0.0004; + hat_timer[ channel ] -= 0.0004; - if( hat_timer[ s ] < 0 ){ - hat_timer[ s ] = 0; + if( hat_timer[ channel ] < 0 ){ + hat_timer[ channel ] = 0; break; } - res2 = res1 = ( (float) line[ s ] / 10.0F ); + res2 = res1 = ( (float) row[ channel ] / 10.0F ); res1 *= (((float)( randomize() & 0x7FFF ) / 32000.0F ) - 0.5 ); res2 *= (((float)( randomize() & 0x7FFF ) / 32000.0F ) - 0.5 ); - if( res1 > hat_old1[ s ] ) - hat_old1[ s ] += 0.03; + if( res1 > hat_old1[ channel ] ) + hat_old1[ channel ] += 0.03; - if( res1 < hat_old1[ s ] ) - hat_old1[ s ] -= 0.03; + if( res1 < hat_old1[ channel ] ) + hat_old1[ channel ] -= 0.03; - if( res2 > hat_old2[ s ] ) - hat_old2[ s ] += 0.03; + if( res2 > hat_old2[ channel ] ) + hat_old2[ channel ] += 0.03; - if( res2 < hat_old2[ s ] ) - hat_old2[ s ] -= 0.03; + if( res2 < hat_old2[ channel ] ) + hat_old2[ channel ] -= 0.03; - res1 = hat_old1[ s ]; - res2 = hat_old2[ s ]; + res1 = hat_old1[ channel ]; + res2 = hat_old2[ channel ]; - hat_old1[ s ] = res1; - hat_old2[ s ] = res2; + hat_old1[ channel ] = res1; + hat_old2[ channel ] = res2; - float hat_factor = hat_timer[ s ] * ( (float) line[ s ] / 100.0F ); + float hat_factor = + hat_timer[ channel ] * + ( (float) row[ channel ] / 100.0F ); res1 *= hat_factor; res2 *= hat_factor; @@ -1554,34 +1583,34 @@ void play ( float * buffer , int len ){ case SYNTH_DRUM : if( tick_changed ) - if( line[ s ] ){ - drum_timer1[ s ] = 1; - drum_timer2[ s ] = 0; - drum_timer3[ s ] = 1; + if( row[ channel ] ){ + drum_timer1[ channel ] = 1; + drum_timer2[ channel ] = 0; + drum_timer3[ channel ] = 1; } - drum_timer1[ s ] -= 0.001; - drum_timer2[ s ] += 0.03; - drum_timer3[ s ] += 0.003; + drum_timer1[ channel ] -= 0.001; + drum_timer2[ channel ] += 0.03; + drum_timer3[ channel ] += 0.003; - if( drum_timer1[ s ] < 0 ){ - drum_timer1[ s ] = 0; + if( drum_timer1[ channel ] < 0 ){ + drum_timer1[ channel ] = 0; break; } - float drum_ratio = drum_timer2[ s ] / drum_timer3[ s ]; + float drum_ratio = drum_timer2[ channel ] / drum_timer3[ channel ]; - float l = line[s]; + float l = row[channel]; res2 = res1 = sinf( ( l / 70) * drum_ratio ) * - drum_timer1[ s ] * + drum_timer1[ channel ] * ( l / 20.0F ) ; float d2 = sinf( drum_ratio + 2 ) * - drum_timer1[ s ] * + drum_timer1[ channel ] * ( l / 120.0F ) ; if( tick & 1 ){ @@ -1611,7 +1640,7 @@ void play ( float * buffer , int len ){ getEcho( & res1 , & res2 ); buffer[ ( a << 1 ) + 1 ] += res2; - buffer[ ( a << 1 ) ] += res1; + buffer[ ( a << 1 ) + 0 ] += res1; if( start_recorder ){ @@ -1654,7 +1683,7 @@ void play ( float * buffer , int len ){ fadeout_vol -= 0.000001; if( fadeout_vol <= 0 ){ - exit_request = 1; + stop_execution = 1; fadeout_vol = 0; } @@ -1685,10 +1714,12 @@ void renderBuffer( float * buffer , int length ){ buffer[ a ] *= volume; for ( int a = 0 ; a < length ; a++ ){ - dc_sl += buffer[ a * 2 ]; - dc_sl /= 2; - dc_sr += buffer[ a * 2 + 1 ]; - dc_sr /= 2; + + dc_s_left += buffer[ a * 2 + 0 ]; + dc_s_right += buffer[ a * 2 + 1 ]; + + dc_s_left /= 2; + dc_s_right /= 2; } for( int a = 0 ; a < length ; a++ ){ @@ -1696,33 +1727,34 @@ void renderBuffer( float * buffer , int length ){ // Simple DC Bocker float - a2 = (float)(length - a) / length , - a3 = (float) a / length ; + ratio_right = (float)( a ) / length , + ratio_left = (float)( length - a ) / length ; + + buffer[ a * 2 + 0 ] -= + dc_ps_left * ratio_left + + dc_s_left * ratio_right ; - buffer[ a * 2 ] -= ( dc_psl * a2 ) + ( dc_sl * a3 ); - buffer[ a * 2 + 1 ] -= ( dc_psr * a2 ) + ( dc_sr * a3 ); + buffer[ a * 2 + 1 ] -= + dc_ps_right * ratio_left + + dc_s_right * ratio_right ; // Simple Volume Compression - buffer[ a * 2 ] /= loudest; + buffer[ a * 2 + 0 ] /= loudest; buffer[ a * 2 + 1 ] /= loudest; loudest -= 0.0005; loudest = fmax(loudest,1); - float t1 = buffer[ a * 2 ]; - - t1 = abs(t1); - - float t2 = buffer[ a * 2 + 1 ]; - - t2 = abs(t2); + float + t1 = abs( buffer[ a * 2 + 0 ] ) , + t2 = abs( buffer[ a * 2 + 1 ] ) ; loudest = fmax(loudest,fmax(t1,t2)); } - dc_psl = dc_sl; - dc_psr = dc_sr; + dc_ps_left = dc_s_left; + dc_ps_right = dc_s_right; } @@ -1830,7 +1862,7 @@ int exportWAV ( const char * path ){ int dataSize = 0; - while( ! exit_request ){ + while( ! stop_execution ){ float buffer [ bufsize * 2 ]; @@ -1888,15 +1920,15 @@ int sound_init ( const char * path ){ SDL_Init( 0 ); SDL_AudioSpec a; - a.freq = srate; - a.format = AUDIO_F32; - a.channels = 2; - a.samples = bufsize; a.callback = sdl_audio_callback; a.userdata = NULL; + a.channels = 2; + a.samples = bufsize; + a.format = AUDIO_F32; + a.freq = srate; - if( SDL_OpenAudio( &a, NULL ) < 0 ){ - printf( "Couldn't open audio: %s\n", SDL_GetError() ); + if( SDL_OpenAudio( & a , NULL ) < 0 ){ + printf( "Couldn't open audio: %s\n" , SDL_GetError() ); return -1; } @@ -1923,7 +1955,7 @@ void sound_close (){ void int_handler ( int param ){ - exit_request = 1; + stop_execution = 1; } void printInstructions (){ @@ -1972,7 +2004,7 @@ int main( int argumentCount , char * arguments [] ){ if(sound_init(export_path)) return 1; - while(!exit_request) + while(!stop_execution) sleep( 1 ); sound_close(); From aab9ae573a2c8088f087e88f1e2063deb2820859 Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Sun, 27 Nov 2022 07:56:21 -0500 Subject: [PATCH 13/18] Split Up Instrument Switch Statement --- ps.c | 900 ++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 518 insertions(+), 382 deletions(-) diff --git a/ps.c b/ps.c index a817f47..c5199f5 100644 --- a/ps.c +++ b/ps.c @@ -1154,11 +1154,467 @@ bool finishedPlaying (){ } - float bound = 0.05; int offset = 0; +void playPad ( float * buffer , uint8_t note , int channel , int frame , bool tick_changed , float * left , float * right ){ + + float res1 , res2; + + if( tick_changed ){ + + if( note ){ + effect_timer1[ channel ] = 1; + bass_freq[ channel ] = pow( 2, (float)( note + offset ) / 12.0F ); + bass_tdelta[ channel ] = bass_freq[ channel ] / srate; + bass_timer[ channel ] = 0; + } + + if( note == 254 ) + effect_timer1[ channel ] = 0; + + if( note == 253 ){ + effect_timer1[ channel ] = 0; + bound = 0.1; + } + } + + if( effect_timer1[ channel ] ){ + + effect_timer1[ channel ] *= 0.99998; + + bass_delta[ channel ] += ( bass_tdelta[ channel ] - bass_delta[ channel ] ) / 2000; + bass_timer[ channel ] += bass_delta[ channel ]; + + float bass = bass_timer[channel]; + + res2 = res1 = cos( bass * 0.99 ); + + res1 += + sin( bass * (sin( effect_timer1[ channel ] ) * 0.02) ) * + sin( bass ); + + res2 += cos( bass * 1.01 ); + + res1 = limit(res1,-1,1); + res2 = limit(res2,-1,1); + + } else { + res1 = 0; + res2 = 0; + } + + putEcho( + res1 / 8 , + res2 / 8 + ); + + res1 = 0; + res2 = 0; + + * left = res1; + * right = res2; +} + + +void playPoly ( float * buffer , uint8_t note , int channel , int frame , bool tick_changed , float * left , float * right ){ + + float res1 , res2; + + if( tick_changed ) + if( note ){ + effect_timer1[ channel ] = 1; + bass_freq[ channel ] = pow( 2, (float)( note + offset ) / 12.0F ); + bass_tdelta[ channel ] = bass_freq[ channel ] / srate; + bass_timer[ channel ] = 0; + } + + if( effect_timer1[ channel ] ){ + + effect_timer1[ channel ] *= 0.99998; + + bass_delta[ channel ] += ( bass_tdelta[ channel ] - bass_delta[ channel ] ) / 1800; + bass_timer[ channel ] += bass_delta[ channel ]; + + res2 = res1 = effect_timer1[ channel ]; + + res1 *= sin( bass_timer[ channel ] ); + res2 *= sin( bass_timer[ channel ] * 1.01 ); + + } else { + res1 = 0; + res2 = 0; + } + + buffer[ ( frame << 1 ) + 1 ] += res2 / 8; + buffer[ ( frame << 1 ) + 0 ] += res1 / 8; + + putEcho( + res1 / 4 , + res2 / 4 + ); + + res1 = 0; + res2 = 0; + + * left = res1; + * right = res2; +} + +void playEffect ( float * buffer , uint8_t note , int channel , int frame , bool tick_changed , float * left , float * right ){ + + float res1 , res2; + + if( tick_changed ){ + + uint8_t l = note; + + if( l ){ + effect_timer1[ channel ] = 1; + effect_timer2[ channel ] = 0; + } + + if( l == 5 ) + rec_play = 1; + + + effect_lowfilter[ channel ] = l - 1; + } + + if( effect_timer1[ channel ] ){ + + effect_timer1[ channel ] *= 0.99996; + effect_timer2[ channel ] += 0.2; + + int filter = effect_lowfilter[channel]; + + float + effect1 = effect_timer1[channel] , + effect2 = effect_timer2[channel] ; + + + if( filter == 4 ){ + effect_timer1[ channel ] = 1; + } else { + + switch ( filter ){ + case 3 : + res1 = effect2 * 1.5; + res2 = effect2 * 1.0; + break; + case 2 : + res1 = effect2 / 4.0; + res2 = effect2 / 3.5; + break; + case 1 : + res1 = effect2 / 2.0; + res2 = effect2 / 2.5; + break; + default: + res2 = res1 = effect2; + } + + res2 /= effect1; + res2 = sin(res2); + res2 *= effect1; + + res1 /= effect1; + res1 = sin(res2); + res1 *= effect1; + } + + } else { + res1 = 0; + res2 = 0; + } + + buffer[ ( frame << 1 ) + 1 ] += ( res2 / 9.0F ); + buffer[ ( frame << 1 ) + 0 ] += ( res1 / 9.0F ); + + if( effect_lowfilter[ channel ] != 4 ) + putEcho( + res1 / 5 , + res2 / 5 + ); + + res1 = 0; + res2 = 0; + + * left = res1; + * right = res2; +} + +void playAcidBass ( float * buffer , uint8_t note , int channel , int frame , bool tick_changed , float * left , float * right ){ + + float res1 , res2; + + if( tick_changed ){ + + bass_freq[ channel ] = pow( 2, (float)( note + offset ) / 12.0F ); + bass_tdelta[ channel ] = bass_freq[ channel ] / srate; + bass_timer[ channel ] = 0; + + effect_timer1[ channel ] = 1; + effect_timer2[ channel ] = 0; + } + + bass_delta[ channel ] += ( bass_tdelta[ channel ] - bass_delta[ channel ] ) / 300; + bass_timer[ channel ] += bass_delta[ channel ]; + + effect_timer2[ channel ] += 0.02 * (32 - (float)tick); + effect_timer1[ channel ] *= 0.9997; + + if( note ){ + + float bass = bass_timer[channel]; + + res2 = res1 = + sin( bass * 4.01 ) * 0.9 + + sin( bass ) ; + + if( res1 > 0.2 ) + res1 = 0.1; + + if( res1 < -0.2 ) + res1 = -0.1; + + if( res2 > 0.2 ) + res2 = 0.1; + + if( res2 < -0.2 ) + res2 = -0.1; + + res1 *= effect_timer1[ channel ]; + res2 *= effect_timer1[ channel ]; + + } else { + res1 = 0; + res2 = 0; + } + + putEcho( res1 , res2 ); + + buffer[ ( frame << 1 ) + 1 ] += res2; + buffer[ ( frame << 1 ) + 0 ] += res1; + + * left = res1; + * right = res2; +} + + +void playBass ( float * buffer , uint8_t note , int channel , int frame , bool tick_changed , float * left , float * right ){ + + float res1 , res2; + + if( tick_changed ){ + bass_freq[ channel ] = pow( 2, (float)( note + offset ) / 12.0F ); + bass_tdelta[ channel ] = bass_freq[ channel ] / srate; + bass_timer[ channel ] = 0; + effect_timer1[ channel ] = 1; + } + + bass_delta[ channel ] += ( bass_tdelta[ channel ] - bass_delta[ channel ] ) / 300; + bass_timer[ channel ] += bass_delta[ channel ]; + + effect_timer1[ channel ] *= 0.9999; + + if( note ){ + + float bass = bass_timer[channel]; + + res1 = + sin( bass ) + + sin( bass * 2.01 ); + + res2 = + cos( bass ) + + cos( bass * 2.006 ); + + if( res1 > + bound ) + res1 = + 0.05; + + if( res1 < - bound ) + res1 = - 0.05; + + if( res2 > + bound ) + res2 = + 0.05; + + if( res2 < - bound ) + res2 = - 0.05; + + } else { + res1 = 0; + res2 = 0; + } + + if( bound > 0.1 ){ + res1 *= effect_timer1[ channel ]; + res2 *= effect_timer1[ channel ]; + } + + if( syn[ channel ] == SYNTH_BASS_TINY ){ + res1 *= 0.9; + res2 *= 0.9; + } else + if( !rec_play ){ + + putFlanger( res1 , res2 ); + + res1 /= 1.5; + res2 /= 1.5; + + getFlanger( & res1 , & res2 ); + } + + putEcho( res1 , res2 ); + + buffer[ ( frame << 1 ) + 1 ] += res2; + buffer[ ( frame << 1 ) + 0 ] += res1; + + * left = res1; + * right = res2; +} + + +void playHat ( float * buffer , uint8_t note , int channel , int frame , bool tick_changed , float * left , float * right ){ + + float res1 , res2; + + if( tick_changed ){ + + if( note ) + hat_timer[ channel ] = 2; + + if( note == 254 ){ + fadeout = 1; + offset++; + return; + } + + if( note == 253 ){ + syn[ 3 ] = SYNTH_ACID_BASS; + start_recorder = 1; + } + + if( note == 252 ) + offset --; + } + + if( note == 254 ) + return; + + if( note == 253 ) + return; + + if( note == 252 ) + return; + + hat_timer[ channel ] -= 0.0004; + + if( hat_timer[ channel ] < 0 ){ + hat_timer[ channel ] = 0; + return; + } + + res2 = res1 = ( (float) note / 10.0F ); + + res1 *= (((float)( randomize() & 0x7FFF ) / 32000.0F ) - 0.5 ); + res2 *= (((float)( randomize() & 0x7FFF ) / 32000.0F ) - 0.5 ); + + if( res1 > hat_old1[ channel ] ) + hat_old1[ channel ] += 0.03; + + if( res1 < hat_old1[ channel ] ) + hat_old1[ channel ] -= 0.03; + + if( res2 > hat_old2[ channel ] ) + hat_old2[ channel ] += 0.03; + + if( res2 < hat_old2[ channel ] ) + hat_old2[ channel ] -= 0.03; + + res1 = hat_old1[ channel ]; + res2 = hat_old2[ channel ]; + + hat_old1[ channel ] = res1; + hat_old2[ channel ] = res2; + + float hat_factor = + hat_timer[ channel ] * + ( (float) note / 100.0F ); + + res1 *= hat_factor; + res2 *= hat_factor; + + buffer[ ( frame << 1 ) + 0 ] += res1 / 1.8; + buffer[ ( frame << 1 ) + 1 ] += res2 / 1.8; + + * left = res1; + * right = res2; +} + + +void playDrum ( float * buffer , uint8_t note , int channel , int frame , bool tick_changed , float * left , float * right ){ + + float res1 , res2; + + if( tick_changed ) + if( note ){ + drum_timer1[ channel ] = 1; + drum_timer2[ channel ] = 0; + drum_timer3[ channel ] = 1; + } + + drum_timer1[ channel ] -= 0.001; + drum_timer2[ channel ] += 0.030; + drum_timer3[ channel ] += 0.003; + + if( drum_timer1[ channel ] < 0 ){ + drum_timer1[ channel ] = 0; + return; + } + + + float drum_ratio = drum_timer2[ channel ] / drum_timer3[ channel ]; + + float l = note; + + res2 = res1 = + sinf( ( l / 70) * drum_ratio ) * + drum_timer1[ channel ] * + ( l / 20.0F ) ; + + float d2 = + sinf( drum_ratio + 2 ) * + drum_timer1[ channel ] * + ( l / 120.0F ) ; + + if( tick & 1 ){ + res1 *= 0.3f; + res1 += d2; + } else { + res2 *= 0.3f; + res2 += d2; + } + + + float clip = 0.3; + + res1 = ranged(res1,clip); + res2 = ranged(res2,clip); + + buffer[ ( frame << 1 ) + 1 ] += res2; + buffer[ ( frame << 1 ) + 0 ] += res1; + + res1 = 0; + res2 = 0; + + * left = res1; + * right = res2; +} + + void play ( float * buffer , int length ){ float res1, res2; @@ -1218,420 +1674,100 @@ void play ( float * buffer , int length ){ switch( syn[ channel ] ){ case SYNTH_PAD : - if( tick_changed ){ - - if( row[ channel ] ){ - effect_timer1[ channel ] = 1; - bass_freq[ channel ] = pow( 2, (float)( row[ channel ] + offset ) / 12.0F ); - bass_tdelta[ channel ] = bass_freq[ channel ] / srate; - bass_timer[ channel ] = 0; - } - - if( row[ channel ] == 254 ) - effect_timer1[ channel ] = 0; - - if( row[ channel ] == 253 ){ - effect_timer1[ channel ] = 0; - bound = 0.1; - } - } - - if( effect_timer1[ channel ] ){ - - effect_timer1[ channel ] *= 0.99998; - - bass_delta[ channel ] += ( bass_tdelta[ channel ] - bass_delta[ channel ] ) / 2000; - bass_timer[ channel ] += bass_delta[ channel ]; - - float bass = bass_timer[channel]; - - res2 = res1 = cos( bass * 0.99 ); - - res1 += - sin( bass * (sin( effect_timer1[ channel ] ) * 0.02) ) * - sin( bass ); - - res2 += cos( bass * 1.01 ); - - res1 = limit(res1,-1,1); - res2 = limit(res2,-1,1); - - } else { - res1 = 0; - res2 = 0; - } - - putEcho( - res1 / 8 , - res2 / 8 + playPad( + buffer , + row[ channel ] , + channel , + a , + tick_changed , + & res1 , + & res2 ); - res1 = 0; - res2 = 0; - break; case SYNTH_POLY : - if( tick_changed ) - if( row[ channel ] ){ - effect_timer1[ channel ] = 1; - bass_freq[ channel ] = pow( 2, (float)( row[ channel ] + offset ) / 12.0F ); - bass_tdelta[ channel ] = bass_freq[ channel ] / srate; - bass_timer[ channel ] = 0; - } - - if( effect_timer1[ channel ] ){ - - effect_timer1[ channel ] *= 0.99998; - - bass_delta[ channel ] += ( bass_tdelta[ channel ] - bass_delta[ channel ] ) / 1800; - bass_timer[ channel ] += bass_delta[ channel ]; - - res2 = res1 = effect_timer1[ channel ]; - - res1 *= sin( bass_timer[ channel ] ); - res2 *= sin( bass_timer[ channel ] * 1.01 ); - - } else { - res1 = 0; - res2 = 0; - } - - buffer[ ( a << 1 ) + 1 ] += res2 / 8; - buffer[ ( a << 1 ) + 0 ] += res1 / 8; - - putEcho( - res1 / 4 , - res2 / 4 + playPoly( + buffer , + row[ channel ] , + channel , + a , + tick_changed , + & res1 , + & res2 ); - res1 = 0; - res2 = 0; - break; case SYNTH_EFFECT : - if( tick_changed ){ - - uint8_t l = row[channel]; - - if( l ){ - effect_timer1[ channel ] = 1; - effect_timer2[ channel ] = 0; - } - - if( l == 5 ) - rec_play = 1; - - - effect_lowfilter[ channel ] = l - 1; - } - - if( effect_timer1[ channel ] ){ - - effect_timer1[ channel ] *= 0.99996; - effect_timer2[ channel ] += 0.2; - - int filter = effect_lowfilter[channel]; - - float - effect1 = effect_timer1[channel] , - effect2 = effect_timer2[channel] ; - - - if( filter == 4 ){ - effect_timer1[ channel ] = 1; - } else { - - switch ( filter ){ - case 3 : - res1 = effect2 * 1.5; - res2 = effect2 * 1.0; - break; - case 2 : - res1 = effect2 / 4.0; - res2 = effect2 / 3.5; - break; - case 1 : - res1 = effect2 / 2.0; - res2 = effect2 / 2.5; - break; - default: - res2 = res1 = effect2; - } - - res2 /= effect1; - res2 = sin(res2); - res2 *= effect1; - - res1 /= effect1; - res1 = sin(res2); - res1 *= effect1; - } - - } else { - res1 = 0; - res2 = 0; - } - - buffer[ ( a << 1 ) + 1 ] += ( res2 / 9.0F ); - buffer[ ( a << 1 ) + 0 ] += ( res1 / 9.0F ); - - if( effect_lowfilter[ channel ] != 4 ) - putEcho( - res1 / 5 , - res2 / 5 - ); - - res1 = 0; - res2 = 0; + playEffect( + buffer , + row[ channel ] , + channel , + a , + tick_changed , + & res1 , + & res2 + ); break; case SYNTH_ACID_BASS: - if( tick_changed ){ - - bass_freq[ channel ] = pow( 2, (float)( row[ channel ] + offset ) / 12.0F ); - bass_tdelta[ channel ] = bass_freq[ channel ] / srate; - bass_timer[ channel ] = 0; - - effect_timer1[ channel ] = 1; - effect_timer2[ channel ] = 0; - } - - bass_delta[ channel ] += ( bass_tdelta[ channel ] - bass_delta[ channel ] ) / 300; - bass_timer[ channel ] += bass_delta[ channel ]; - - effect_timer2[ channel ] += 0.02 * (32 - (float)tick); - effect_timer1[ channel ] *= 0.9997; - - if( row[ channel ] ){ - - float bass = bass_timer[channel]; - - res2 = res1 = - sin( bass * 4.01 ) * 0.9 + - sin( bass ) ; - - if( res1 > 0.2 ) - res1 = 0.1; - - if( res1 < -0.2 ) - res1 = -0.1; - - if( res2 > 0.2 ) - res2 = 0.1; - - if( res2 < -0.2 ) - res2 = -0.1; - - res1 *= effect_timer1[ channel ]; - res2 *= effect_timer1[ channel ]; - - } else { - res1 = 0; - res2 = 0; - } - - putEcho( res1 , res2 ); - - buffer[ ( a << 1 ) + 1 ] += res2; - buffer[ ( a << 1 ) + 0 ] += res1; + playAcidBass( + buffer , + row[ channel ] , + channel , + a , + tick_changed , + & res1 , + & res2 + ); break; case SYNTH_BASS_TINY : case SYNTH_BASS : - if( tick_changed ){ - bass_freq[ channel ] = pow( 2, (float)( row[ channel ] + offset ) / 12.0F ); - bass_tdelta[ channel ] = bass_freq[ channel ] / srate; - bass_timer[ channel ] = 0; - effect_timer1[ channel ] = 1; - } - - bass_delta[ channel ] += ( bass_tdelta[ channel ] - bass_delta[ channel ] ) / 300; - bass_timer[ channel ] += bass_delta[ channel ]; - - effect_timer1[ channel ] *= 0.9999; - - if( row[ channel ] ){ - - float bass = bass_timer[channel]; - - res1 = - sin( bass ) + - sin( bass * 2.01 ); - - res2 = - cos( bass ) + - cos( bass * 2.006 ); - - if( res1 > + bound ) - res1 = + 0.05; - - if( res1 < - bound ) - res1 = - 0.05; - - if( res2 > + bound ) - res2 = + 0.05; - - if( res2 < - bound ) - res2 = - 0.05; - - } else { - res1 = 0; - res2 = 0; - } - - if( bound > 0.1 ){ - res1 *= effect_timer1[ channel ]; - res2 *= effect_timer1[ channel ]; - } - - if( syn[ channel ] == SYNTH_BASS_TINY ){ - res1 *= 0.9; - res2 *= 0.9; - } else - if( !rec_play ){ - - putFlanger( res1 , res2 ); - - res1 /= 1.5; - res2 /= 1.5; - - getFlanger( & res1 , & res2 ); - } + playBass( + buffer , + row[ channel ] , + channel , + a , + tick_changed , + & res1 , + & res2 + ); - putEcho( res1 , res2 ); - buffer[ ( a << 1 ) + 1 ] += res2; - buffer[ ( a << 1 ) + 0 ] += res1; break; case SYNTH_HAT : - if( tick_changed ){ - - if( row[ channel ] ) - hat_timer[ channel ] = 2; - - if( row[ channel ] == 254 ){ - fadeout = 1; - offset++; - break; - } - - if( row[ channel ] == 253 ){ - syn[ 3 ] = SYNTH_ACID_BASS; - start_recorder = 1; - } - - if( row[ channel ] == 252 ) - offset --; - } - - if( row[ channel ] == 254 ) - break; - - if( row[ channel ] == 253 ) - break; - - if( row[ channel ] == 252 ) - break; - - hat_timer[ channel ] -= 0.0004; - - if( hat_timer[ channel ] < 0 ){ - hat_timer[ channel ] = 0; - break; - } - - res2 = res1 = ( (float) row[ channel ] / 10.0F ); + playHat( + buffer , + row[ channel ] , + channel , + a , + tick_changed , + & res1 , + & res2 + ); - res1 *= (((float)( randomize() & 0x7FFF ) / 32000.0F ) - 0.5 ); - res2 *= (((float)( randomize() & 0x7FFF ) / 32000.0F ) - 0.5 ); - - if( res1 > hat_old1[ channel ] ) - hat_old1[ channel ] += 0.03; - - if( res1 < hat_old1[ channel ] ) - hat_old1[ channel ] -= 0.03; - if( res2 > hat_old2[ channel ] ) - hat_old2[ channel ] += 0.03; - - if( res2 < hat_old2[ channel ] ) - hat_old2[ channel ] -= 0.03; - - res1 = hat_old1[ channel ]; - res2 = hat_old2[ channel ]; - - hat_old1[ channel ] = res1; - hat_old2[ channel ] = res2; - - float hat_factor = - hat_timer[ channel ] * - ( (float) row[ channel ] / 100.0F ); - - res1 *= hat_factor; - res2 *= hat_factor; - - buffer[ ( a << 1 ) + 0 ] += res1 / 1.8; - buffer[ ( a << 1 ) + 1 ] += res2 / 1.8; break; case SYNTH_DRUM : - if( tick_changed ) - if( row[ channel ] ){ - drum_timer1[ channel ] = 1; - drum_timer2[ channel ] = 0; - drum_timer3[ channel ] = 1; - } - - drum_timer1[ channel ] -= 0.001; - drum_timer2[ channel ] += 0.03; - drum_timer3[ channel ] += 0.003; - - if( drum_timer1[ channel ] < 0 ){ - drum_timer1[ channel ] = 0; - break; - } - - - float drum_ratio = drum_timer2[ channel ] / drum_timer3[ channel ]; - - float l = row[channel]; - - res2 = res1 = - sinf( ( l / 70) * drum_ratio ) * - drum_timer1[ channel ] * - ( l / 20.0F ) ; - - float d2 = - sinf( drum_ratio + 2 ) * - drum_timer1[ channel ] * - ( l / 120.0F ) ; - - if( tick & 1 ){ - res1 *= 0.3f; - res1 += d2; - } else { - res2 *= 0.3f; - res2 += d2; - } - - - float clip = 0.3; + playDrum( + buffer , + row[ channel ] , + channel , + a , + tick_changed , + & res1 , + & res2 + ); - res1 = ranged(res1,clip); - res2 = ranged(res2,clip); - - buffer[ ( a << 1 ) + 1 ] += res2; - buffer[ ( a << 1 ) + 0 ] += res1; - res1 = 0; - res2 = 0; break; } From 9736a14c09084a82e9a547adb281b17df81d6922 Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Sun, 27 Nov 2022 08:50:57 -0500 Subject: [PATCH 14/18] Replaced Switch With Function Pointers --- ps.c | 234 ++++++++++++++++++++++++++--------------------------------- 1 file changed, 101 insertions(+), 133 deletions(-) diff --git a/ps.c b/ps.c index c5199f5..e97526e 100644 --- a/ps.c +++ b/ps.c @@ -1158,11 +1158,29 @@ float bound = 0.05; int offset = 0; -void playPad ( float * buffer , uint8_t note , int channel , int frame , bool tick_changed , float * left , float * right ){ +struct PlayState { + + bool tick_changed; + + uint8_t note; + + int channel; + int frame; + + float * buffer; + float * right; + float * left; +}; + + +void playPad ( struct PlayState * state ){ + + int channel = state -> channel; + uint8_t note = state -> note; float res1 , res2; - if( tick_changed ){ + if( state -> tick_changed ){ if( note ){ effect_timer1[ channel ] = 1; @@ -1213,16 +1231,21 @@ void playPad ( float * buffer , uint8_t note , int channel , int frame , bool ti res1 = 0; res2 = 0; - * left = res1; - * right = res2; + * (state -> left) = res1; + * (state -> right) = res2; } -void playPoly ( float * buffer , uint8_t note , int channel , int frame , bool tick_changed , float * left , float * right ){ +void playPoly ( struct PlayState * state ){ + + uint8_t note = state -> note; + int channel = state -> channel; + int frame = state -> frame; + float * buffer = state -> buffer; float res1 , res2; - if( tick_changed ) + if( state -> tick_changed ) if( note ){ effect_timer1[ channel ] = 1; bass_freq[ channel ] = pow( 2, (float)( note + offset ) / 12.0F ); @@ -1258,15 +1281,20 @@ void playPoly ( float * buffer , uint8_t note , int channel , int frame , bool t res1 = 0; res2 = 0; - * left = res1; - * right = res2; + * (state -> left) = res1; + * (state -> right) = res2; } -void playEffect ( float * buffer , uint8_t note , int channel , int frame , bool tick_changed , float * left , float * right ){ +void playEffect ( struct PlayState * state ){ + + uint8_t note = state -> note; + int channel = state -> channel; + int frame = state -> frame; + float * buffer = state -> buffer; float res1 , res2; - if( tick_changed ){ + if( state -> tick_changed ){ uint8_t l = note; @@ -1341,15 +1369,20 @@ void playEffect ( float * buffer , uint8_t note , int channel , int frame , bool res1 = 0; res2 = 0; - * left = res1; - * right = res2; + * (state -> left) = res1; + * (state -> right) = res2; } -void playAcidBass ( float * buffer , uint8_t note , int channel , int frame , bool tick_changed , float * left , float * right ){ +void playAcidBass ( struct PlayState * state ){ + + uint8_t note = state -> note; + int channel = state -> channel; + int frame = state -> frame; + float * buffer = state -> buffer; float res1 , res2; - if( tick_changed ){ + if( state -> tick_changed ){ bass_freq[ channel ] = pow( 2, (float)( note + offset ) / 12.0F ); bass_tdelta[ channel ] = bass_freq[ channel ] / srate; @@ -1398,16 +1431,21 @@ void playAcidBass ( float * buffer , uint8_t note , int channel , int frame , bo buffer[ ( frame << 1 ) + 1 ] += res2; buffer[ ( frame << 1 ) + 0 ] += res1; - * left = res1; - * right = res2; + * (state -> left) = res1; + * (state -> right) = res2; } -void playBass ( float * buffer , uint8_t note , int channel , int frame , bool tick_changed , float * left , float * right ){ +void playBass ( struct PlayState * state ){ + + uint8_t note = state -> note; + int channel = state -> channel; + int frame = state -> frame; + float * buffer = state -> buffer; float res1 , res2; - if( tick_changed ){ + if( state -> tick_changed ){ bass_freq[ channel ] = pow( 2, (float)( note + offset ) / 12.0F ); bass_tdelta[ channel ] = bass_freq[ channel ] / srate; bass_timer[ channel ] = 0; @@ -1472,16 +1510,21 @@ void playBass ( float * buffer , uint8_t note , int channel , int frame , bool t buffer[ ( frame << 1 ) + 1 ] += res2; buffer[ ( frame << 1 ) + 0 ] += res1; - * left = res1; - * right = res2; + * (state -> left) = res1; + * (state -> right) = res2; } -void playHat ( float * buffer , uint8_t note , int channel , int frame , bool tick_changed , float * left , float * right ){ +void playHat ( struct PlayState * state ){ + + uint8_t note = state -> note; + int channel = state -> channel; + int frame = state -> frame; + float * buffer = state -> buffer; float res1 , res2; - if( tick_changed ){ + if( state -> tick_changed ){ if( note ) hat_timer[ channel ] = 2; @@ -1498,7 +1541,7 @@ void playHat ( float * buffer , uint8_t note , int channel , int frame , bool ti } if( note == 252 ) - offset --; + offset--; } if( note == 254 ) @@ -1550,16 +1593,21 @@ void playHat ( float * buffer , uint8_t note , int channel , int frame , bool ti buffer[ ( frame << 1 ) + 0 ] += res1 / 1.8; buffer[ ( frame << 1 ) + 1 ] += res2 / 1.8; - * left = res1; - * right = res2; + * (state -> left) = res1; + * (state -> right) = res2; } -void playDrum ( float * buffer , uint8_t note , int channel , int frame , bool tick_changed , float * left , float * right ){ +void playDrum ( struct PlayState * state ){ + + uint8_t note = state -> note; + int channel = state -> channel; + int frame = state -> frame; + float * buffer = state -> buffer; float res1 , res2; - if( tick_changed ) + if( state -> tick_changed ) if( note ){ drum_timer1[ channel ] = 1; drum_timer2[ channel ] = 0; @@ -1578,17 +1626,15 @@ void playDrum ( float * buffer , uint8_t note , int channel , int frame , bool t float drum_ratio = drum_timer2[ channel ] / drum_timer3[ channel ]; - float l = note; - res2 = res1 = - sinf( ( l / 70) * drum_ratio ) * + sinf( ( note / 70) * drum_ratio ) * drum_timer1[ channel ] * - ( l / 20.0F ) ; + ( note / 20.0F ) ; float d2 = sinf( drum_ratio + 2 ) * drum_timer1[ channel ] * - ( l / 120.0F ) ; + ( note / 120.0F ) ; if( tick & 1 ){ res1 *= 0.3f; @@ -1610,11 +1656,23 @@ void playDrum ( float * buffer , uint8_t note , int channel , int frame , bool t res1 = 0; res2 = 0; - * left = res1; - * right = res2; + * (state -> left) = res1; + * (state -> right) = res2; } +void ( * Instruments [] )( struct PlayState * ) = { + playDrum , + playHat , + playBass , + playBass , + playAcidBass , + playEffect , + playPoly , + playPad +}; + + void play ( float * buffer , int length ){ float res1, res2; @@ -1669,108 +1727,18 @@ void play ( float * buffer , int length ){ if( syn[ channel ] == 0 ) continue; - - switch( syn[ channel ] ){ - case SYNTH_PAD : - - playPad( - buffer , - row[ channel ] , - channel , - a , - tick_changed , - & res1 , - & res2 - ); - - break; - case SYNTH_POLY : - - playPoly( - buffer , - row[ channel ] , - channel , - a , - tick_changed , - & res1 , - & res2 - ); - break; - case SYNTH_EFFECT : - - playEffect( - buffer , - row[ channel ] , - channel , - a , - tick_changed , - & res1 , - & res2 - ); - - break; - case SYNTH_ACID_BASS: - - playAcidBass( - buffer , - row[ channel ] , - channel , - a , - tick_changed , - & res1 , - & res2 - ); - - break; - case SYNTH_BASS_TINY : - case SYNTH_BASS : - - playBass( - buffer , - row[ channel ] , - channel , - a , - tick_changed , - & res1 , - & res2 - ); + struct PlayState state; + state.tick_changed = tick_changed; + state.channel = channel; + state.buffer = buffer; + state.frame = a; + state.right = & res2; + state.left = & res1; + state.note = row[ channel ]; - - - break; - case SYNTH_HAT : - - playHat( - buffer , - row[ channel ] , - channel , - a , - tick_changed , - & res1 , - & res2 - ); - - - - break; - case SYNTH_DRUM : - - playDrum( - buffer , - row[ channel ] , - channel , - a , - tick_changed , - & res1 , - & res2 - ); - - - - break; - } + ( * Instruments[channel] )( & state ); } getEcho( & res1 , & res2 ); From be42ddeeb85978ec31e3b527a37f75a45eb4ea79 Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Sun, 27 Nov 2022 09:55:18 -0500 Subject: [PATCH 15/18] General Refactoring --- ps.c | 360 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 179 insertions(+), 181 deletions(-) diff --git a/ps.c b/ps.c index e97526e..69838e9 100644 --- a/ps.c +++ b/ps.c @@ -83,6 +83,18 @@ int randomize (){ #define ranged( value , range ) \ limit((value),-(range),(range)) +#define square( value ) \ + pow(2,(value)) + +#define constrict( value , threshold , limit ){ \ + \ + if((value) > + (threshold)) \ + (value) = + (limit); \ + \ + if((value) < - (threshold)) \ + (value) = - (limit); \ +} + /* * Note Patterns @@ -1173,18 +1185,38 @@ struct PlayState { }; +#define setFrame( Left , Right ){ \ + \ + * (state -> right) = (Right); \ + * (state -> left) = (Left); \ +} + +#define addChannel( offset , value ){ \ + \ + int index = ( (state -> frame) << 1 ) + (offset); \ + \ + (state -> buffer)[ index ] += (value); \ +} + +#define addBuffer( left , right ){ \ + \ + addChannel(0,left); \ + addChannel(1,right); \ +} + + void playPad ( struct PlayState * state ){ int channel = state -> channel; uint8_t note = state -> note; - float res1 , res2; + float left , right; if( state -> tick_changed ){ if( note ){ effect_timer1[ channel ] = 1; - bass_freq[ channel ] = pow( 2, (float)( note + offset ) / 12.0F ); + bass_freq[ channel ] = square( (float)( note + offset ) / 12.0F ); bass_tdelta[ channel ] = bass_freq[ channel ] / srate; bass_timer[ channel ] = 0; } @@ -1207,32 +1239,28 @@ void playPad ( struct PlayState * state ){ float bass = bass_timer[channel]; - res2 = res1 = cos( bass * 0.99 ); + right = left = cos( bass * 0.99 ); - res1 += - sin( bass * (sin( effect_timer1[ channel ] ) * 0.02) ) * + left += + sin( bass * 0.02 * sin( effect_timer1[ channel ] ) ) * sin( bass ); - res2 += cos( bass * 1.01 ); + right += cos( bass * 1.01 ); - res1 = limit(res1,-1,1); - res2 = limit(res2,-1,1); + right = limit(right,-1,1); + left = limit(left,-1,1); } else { - res1 = 0; - res2 = 0; + left = 0; + right = 0; } putEcho( - res1 / 8 , - res2 / 8 + left / 8 , + right / 8 ); - - res1 = 0; - res2 = 0; - * (state -> left) = res1; - * (state -> right) = res2; + setFrame(0,0) } @@ -1240,15 +1268,13 @@ void playPoly ( struct PlayState * state ){ uint8_t note = state -> note; int channel = state -> channel; - int frame = state -> frame; - float * buffer = state -> buffer; - float res1 , res2; + float left , right; if( state -> tick_changed ) if( note ){ effect_timer1[ channel ] = 1; - bass_freq[ channel ] = pow( 2, (float)( note + offset ) / 12.0F ); + bass_freq[ channel ] = square( (float)( note + offset ) / 12.0F ); bass_tdelta[ channel ] = bass_freq[ channel ] / srate; bass_timer[ channel ] = 0; } @@ -1260,39 +1286,35 @@ void playPoly ( struct PlayState * state ){ bass_delta[ channel ] += ( bass_tdelta[ channel ] - bass_delta[ channel ] ) / 1800; bass_timer[ channel ] += bass_delta[ channel ]; - res2 = res1 = effect_timer1[ channel ]; + right = left = effect_timer1[ channel ]; - res1 *= sin( bass_timer[ channel ] ); - res2 *= sin( bass_timer[ channel ] * 1.01 ); + left *= sin( bass_timer[ channel ] ); + right *= sin( bass_timer[ channel ] * 1.01 ); } else { - res1 = 0; - res2 = 0; + left = 0; + right = 0; } - buffer[ ( frame << 1 ) + 1 ] += res2 / 8; - buffer[ ( frame << 1 ) + 0 ] += res1 / 8; + addBuffer( + left / 8 , + right / 8 + ); putEcho( - res1 / 4 , - res2 / 4 + left / 4 , + right / 4 ); - res1 = 0; - res2 = 0; - - * (state -> left) = res1; - * (state -> right) = res2; + setFrame(0,0) } void playEffect ( struct PlayState * state ){ uint8_t note = state -> note; int channel = state -> channel; - int frame = state -> frame; - float * buffer = state -> buffer; - float res1 , res2; + float left , right; if( state -> tick_changed ){ @@ -1328,63 +1350,59 @@ void playEffect ( struct PlayState * state ){ switch ( filter ){ case 3 : - res1 = effect2 * 1.5; - res2 = effect2 * 1.0; + left = effect2 * 1.5; + right = effect2 * 1.0; break; case 2 : - res1 = effect2 / 4.0; - res2 = effect2 / 3.5; + left = effect2 / 4.0; + right = effect2 / 3.5; break; case 1 : - res1 = effect2 / 2.0; - res2 = effect2 / 2.5; + left = effect2 / 2.0; + right = effect2 / 2.5; break; default: - res2 = res1 = effect2; + right = left = effect2; } - res2 /= effect1; - res2 = sin(res2); - res2 *= effect1; + right /= effect1; + right = sin(right); + right *= effect1; - res1 /= effect1; - res1 = sin(res2); - res1 *= effect1; + left /= effect1; + left = sin(right); + left *= effect1; } } else { - res1 = 0; - res2 = 0; + left = 0; + right = 0; } - buffer[ ( frame << 1 ) + 1 ] += ( res2 / 9.0F ); - buffer[ ( frame << 1 ) + 0 ] += ( res1 / 9.0F ); + addBuffer( + left / 9.0F , + right / 9.0F + ); if( effect_lowfilter[ channel ] != 4 ) putEcho( - res1 / 5 , - res2 / 5 + left / 5 , + right / 5 ); - res1 = 0; - res2 = 0; - - * (state -> left) = res1; - * (state -> right) = res2; + setFrame(0,0) } void playAcidBass ( struct PlayState * state ){ uint8_t note = state -> note; int channel = state -> channel; - int frame = state -> frame; - float * buffer = state -> buffer; - float res1 , res2; + float left , right; if( state -> tick_changed ){ - bass_freq[ channel ] = pow( 2, (float)( note + offset ) / 12.0F ); + bass_freq[ channel ] = square( (float)( note + offset ) / 12.0F ); bass_tdelta[ channel ] = bass_freq[ channel ] / srate; bass_timer[ channel ] = 0; @@ -1402,37 +1420,34 @@ void playAcidBass ( struct PlayState * state ){ float bass = bass_timer[channel]; - res2 = res1 = + right = left = sin( bass * 4.01 ) * 0.9 + sin( bass ) ; - if( res1 > 0.2 ) - res1 = 0.1; + if( left > 0.2 ) + left = 0.1; - if( res1 < -0.2 ) - res1 = -0.1; + if( left < -0.2 ) + left = -0.1; - if( res2 > 0.2 ) - res2 = 0.1; + if( right > 0.2 ) + right = 0.1; - if( res2 < -0.2 ) - res2 = -0.1; + if( right < -0.2 ) + right = -0.1; - res1 *= effect_timer1[ channel ]; - res2 *= effect_timer1[ channel ]; + left *= effect_timer1[ channel ]; + right *= effect_timer1[ channel ]; } else { - res1 = 0; - res2 = 0; + left = 0; + right = 0; } - putEcho( res1 , res2 ); - - buffer[ ( frame << 1 ) + 1 ] += res2; - buffer[ ( frame << 1 ) + 0 ] += res1; + putEcho( left , right ); + addBuffer( left , right ); - * (state -> left) = res1; - * (state -> right) = res2; + setFrame(left,right) } @@ -1440,13 +1455,11 @@ void playBass ( struct PlayState * state ){ uint8_t note = state -> note; int channel = state -> channel; - int frame = state -> frame; - float * buffer = state -> buffer; - float res1 , res2; + float left , right; if( state -> tick_changed ){ - bass_freq[ channel ] = pow( 2, (float)( note + offset ) / 12.0F ); + bass_freq[ channel ] = square( (float)( note + offset ) / 12.0F ); bass_tdelta[ channel ] = bass_freq[ channel ] / srate; bass_timer[ channel ] = 0; effect_timer1[ channel ] = 1; @@ -1461,57 +1474,45 @@ void playBass ( struct PlayState * state ){ float bass = bass_timer[channel]; - res1 = + left = sin( bass ) + sin( bass * 2.01 ); - res2 = + right = cos( bass ) + cos( bass * 2.006 ); - if( res1 > + bound ) - res1 = + 0.05; - - if( res1 < - bound ) - res1 = - 0.05; - - if( res2 > + bound ) - res2 = + 0.05; - - if( res2 < - bound ) - res2 = - 0.05; + constrict(left,bound,0.05) + constrict(right,bound,0.05) } else { - res1 = 0; - res2 = 0; + left = 0; + right = 0; } if( bound > 0.1 ){ - res1 *= effect_timer1[ channel ]; - res2 *= effect_timer1[ channel ]; + left *= effect_timer1[ channel ]; + right *= effect_timer1[ channel ]; } if( syn[ channel ] == SYNTH_BASS_TINY ){ - res1 *= 0.9; - res2 *= 0.9; + left *= 0.9; + right *= 0.9; } else if( !rec_play ){ - putFlanger( res1 , res2 ); + putFlanger( left , right ); - res1 /= 1.5; - res2 /= 1.5; + left /= 1.5; + right /= 1.5; - getFlanger( & res1 , & res2 ); + getFlanger( & left , & right ); } - putEcho( res1 , res2 ); - - buffer[ ( frame << 1 ) + 1 ] += res2; - buffer[ ( frame << 1 ) + 0 ] += res1; + putEcho( left , right ); + addBuffer( left , right ); - * (state -> left) = res1; - * (state -> right) = res2; + setFrame(left,right) } @@ -1519,10 +1520,8 @@ void playHat ( struct PlayState * state ){ uint8_t note = state -> note; int channel = state -> channel; - int frame = state -> frame; - float * buffer = state -> buffer; - float res1 , res2; + float left , right; if( state -> tick_changed ){ @@ -1560,41 +1559,42 @@ void playHat ( struct PlayState * state ){ return; } - res2 = res1 = ( (float) note / 10.0F ); + right = left = ( (float) note / 10.0F ); - res1 *= (((float)( randomize() & 0x7FFF ) / 32000.0F ) - 0.5 ); - res2 *= (((float)( randomize() & 0x7FFF ) / 32000.0F ) - 0.5 ); + left *= (((float)( randomize() & 0x7FFF ) / 32000.0F ) - 0.5 ); + right *= (((float)( randomize() & 0x7FFF ) / 32000.0F ) - 0.5 ); - if( res1 > hat_old1[ channel ] ) + if( left > hat_old1[ channel ] ) hat_old1[ channel ] += 0.03; - if( res1 < hat_old1[ channel ] ) + if( left < hat_old1[ channel ] ) hat_old1[ channel ] -= 0.03; - if( res2 > hat_old2[ channel ] ) + if( right > hat_old2[ channel ] ) hat_old2[ channel ] += 0.03; - if( res2 < hat_old2[ channel ] ) + if( right < hat_old2[ channel ] ) hat_old2[ channel ] -= 0.03; - res1 = hat_old1[ channel ]; - res2 = hat_old2[ channel ]; + left = hat_old1[ channel ]; + right = hat_old2[ channel ]; - hat_old1[ channel ] = res1; - hat_old2[ channel ] = res2; + hat_old1[ channel ] = left; + hat_old2[ channel ] = right; float hat_factor = hat_timer[ channel ] * ( (float) note / 100.0F ); - res1 *= hat_factor; - res2 *= hat_factor; + left *= hat_factor; + right *= hat_factor; - buffer[ ( frame << 1 ) + 0 ] += res1 / 1.8; - buffer[ ( frame << 1 ) + 1 ] += res2 / 1.8; + addBuffer( + left / 1.8 , + right / 1.8 + ); - * (state -> left) = res1; - * (state -> right) = res2; + setFrame(left,right) } @@ -1602,10 +1602,8 @@ void playDrum ( struct PlayState * state ){ uint8_t note = state -> note; int channel = state -> channel; - int frame = state -> frame; - float * buffer = state -> buffer; - float res1 , res2; + float left , right; if( state -> tick_changed ) if( note ){ @@ -1626,7 +1624,7 @@ void playDrum ( struct PlayState * state ){ float drum_ratio = drum_timer2[ channel ] / drum_timer3[ channel ]; - res2 = res1 = + right = left = sinf( ( note / 70) * drum_ratio ) * drum_timer1[ channel ] * ( note / 20.0F ) ; @@ -1637,29 +1635,28 @@ void playDrum ( struct PlayState * state ){ ( note / 120.0F ) ; if( tick & 1 ){ - res1 *= 0.3f; - res1 += d2; + left *= 0.3f; + left += d2; } else { - res2 *= 0.3f; - res2 += d2; + right *= 0.3f; + right += d2; } float clip = 0.3; - res1 = ranged(res1,clip); - res2 = ranged(res2,clip); - - buffer[ ( frame << 1 ) + 1 ] += res2; - buffer[ ( frame << 1 ) + 0 ] += res1; + left = ranged(left,clip); + right = ranged(right,clip); - res1 = 0; - res2 = 0; + addBuffer(left,right); - * (state -> left) = res1; - * (state -> right) = res2; + setFrame(0,0) } +#undef addChannel +#undef addBuffer +#undef setFrame + void ( * Instruments [] )( struct PlayState * ) = { playDrum , @@ -1675,8 +1672,7 @@ void ( * Instruments [] )( struct PlayState * ) = { void play ( float * buffer , int length ){ - float res1, res2; - float freq; + float left , right; clearBuffer(buffer,length); @@ -1686,7 +1682,7 @@ void play ( float * buffer , int length ){ int tick_changed = 0; - for ( int a = 0 ; a < length ; a++ ){ + for ( int frame = 0 ; frame < length ; frame++ ){ tick_changed = 0; @@ -1733,23 +1729,23 @@ void play ( float * buffer , int length ){ state.tick_changed = tick_changed; state.channel = channel; state.buffer = buffer; - state.frame = a; - state.right = & res2; - state.left = & res1; + state.frame = frame; + state.right = & right; state.note = row[ channel ]; + state.left = & left; ( * Instruments[channel] )( & state ); } - getEcho( & res1 , & res2 ); + getEcho( & left , & right ); - buffer[ ( a << 1 ) + 1 ] += res2; - buffer[ ( a << 1 ) + 0 ] += res1; + buffer[ ( frame << 1 ) + 1 ] += right; + buffer[ ( frame << 1 ) + 0 ] += left; if( start_recorder ){ - rec1[ rec_ptr ] = buffer[ ( a << 1 ) + 0 ]; - rec2[ rec_ptr ] = buffer[ ( a << 1 ) + 1 ]; + rec1[ rec_ptr ] = buffer[ ( frame << 1 ) + 0 ]; + rec2[ rec_ptr ] = buffer[ ( frame << 1 ) + 1 ]; rec_ptr++; @@ -1766,13 +1762,13 @@ void play ( float * buffer , int length ){ rec2[ rec_ptr ] / 2 ); - res1 = 0; - res2 = 0; + left = 0; + right = 0; - getFlanger( & res1 , & res2 ); + getFlanger( & left , & right ); - buffer[ ( a << 1 ) + 1 ] += res2; - buffer[ ( a << 1 ) + 0 ] += res1; + buffer[ ( frame << 1 ) + 1 ] += right; + buffer[ ( frame << 1 ) + 0 ] += left; rec_ptr--; @@ -1791,8 +1787,8 @@ void play ( float * buffer , int length ){ fadeout_vol = 0; } - buffer[ ( a << 1 ) + 0 ] *= fadeout_vol; - buffer[ ( a << 1 ) + 1 ] *= fadeout_vol; + buffer[ ( frame << 1 ) + 0 ] *= fadeout_vol; + buffer[ ( frame << 1 ) + 1 ] *= fadeout_vol; } } } @@ -1868,11 +1864,11 @@ void sdl_audio_callback ( void * udata , Uint8 * stream , int len ){ -void newline (){ +inline void newline (){ printf("\n"); } -void printed ( char * string ){ +inline void printed ( char * string ){ printf( " %s\n" , string ); } @@ -1882,10 +1878,12 @@ typedef FILE * File; #define section( name ) \ fwrite( (void *)(name) , 1 , 4 , file ) -#define bytes( literal , size ){ \ - int value = (literal); \ - fwrite( & value , (size) , 1 , file ); \ - } +#define bytes( literal , size ){ \ + \ + int value = (literal); \ + \ + fwrite( & value , (size) , 1 , file ); \ +} #define quad( value ) \ bytes(value,4) @@ -2066,8 +2064,8 @@ void printInstructions (){ newline(); - printed("NighRadio - P.S."); - printed("================"); + printed("NightRadio - P.S."); + printed("================="); newline(); From eab5e3af30a99e0f80bdf4b7c8adc6a776b98c9e Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Sun, 27 Nov 2022 10:13:58 -0500 Subject: [PATCH 16/18] General Refactoring --- ps.c | 171 ++++++++++++++++++++++++++--------------------------------- 1 file changed, 75 insertions(+), 96 deletions(-) diff --git a/ps.c b/ps.c index 69838e9..2654086 100644 --- a/ps.c +++ b/ps.c @@ -1177,7 +1177,7 @@ struct PlayState { uint8_t note; int channel; - int frame; + int offset; float * buffer; float * right; @@ -1191,9 +1191,9 @@ struct PlayState { * (state -> left) = (Left); \ } -#define addChannel( offset , value ){ \ +#define addChannel( Offset , value ){ \ \ - int index = ( (state -> frame) << 1 ) + (offset); \ + int index = state -> offset + (Offset); \ \ (state -> buffer)[ index ] += (value); \ } @@ -1205,7 +1205,7 @@ struct PlayState { } -void playPad ( struct PlayState * state ){ +void Pad ( struct PlayState * state ){ int channel = state -> channel; uint8_t note = state -> note; @@ -1264,7 +1264,7 @@ void playPad ( struct PlayState * state ){ } -void playPoly ( struct PlayState * state ){ +void Poly ( struct PlayState * state ){ uint8_t note = state -> note; int channel = state -> channel; @@ -1296,40 +1296,33 @@ void playPoly ( struct PlayState * state ){ right = 0; } - addBuffer( - left / 8 , - right / 8 - ); - - putEcho( - left / 4 , - right / 4 - ); + addBuffer( left / 8 , right / 8 ); + putEcho( left / 4 , right / 4 ); setFrame(0,0) } -void playEffect ( struct PlayState * state ){ +void Effect ( struct PlayState * state ){ uint8_t note = state -> note; int channel = state -> channel; - float left , right; + float + right = 0 , + left = 0 ; if( state -> tick_changed ){ - uint8_t l = note; - - if( l ){ + if( note ){ effect_timer1[ channel ] = 1; effect_timer2[ channel ] = 0; } - if( l == 5 ) + if( note == 5 ) rec_play = 1; - effect_lowfilter[ channel ] = l - 1; + effect_lowfilter[ channel ] = note - 1; } if( effect_timer1[ channel ] ){ @@ -1374,31 +1367,24 @@ void playEffect ( struct PlayState * state ){ left *= effect1; } - } else { - left = 0; - right = 0; } - addBuffer( - left / 9.0F , - right / 9.0F - ); + addBuffer( left / 9.0F , right / 9.0F ); if( effect_lowfilter[ channel ] != 4 ) - putEcho( - left / 5 , - right / 5 - ); + putEcho( left / 5 , right / 5 ); setFrame(0,0) } -void playAcidBass ( struct PlayState * state ){ +void AcidBass ( struct PlayState * state ){ uint8_t note = state -> note; int channel = state -> channel; - float left , right; + float + right = 0 , + left = 0 ; if( state -> tick_changed ){ @@ -1439,9 +1425,6 @@ void playAcidBass ( struct PlayState * state ){ left *= effect_timer1[ channel ]; right *= effect_timer1[ channel ]; - } else { - left = 0; - right = 0; } putEcho( left , right ); @@ -1451,12 +1434,14 @@ void playAcidBass ( struct PlayState * state ){ } -void playBass ( struct PlayState * state ){ +void Bass ( struct PlayState * state ){ uint8_t note = state -> note; int channel = state -> channel; - float left , right; + float + right = 0 , + left = 0 ; if( state -> tick_changed ){ bass_freq[ channel ] = square( (float)( note + offset ) / 12.0F ); @@ -1485,26 +1470,23 @@ void playBass ( struct PlayState * state ){ constrict(left,bound,0.05) constrict(right,bound,0.05) - } else { - left = 0; - right = 0; } if( bound > 0.1 ){ - left *= effect_timer1[ channel ]; right *= effect_timer1[ channel ]; + left *= effect_timer1[ channel ]; } if( syn[ channel ] == SYNTH_BASS_TINY ){ - left *= 0.9; right *= 0.9; + left *= 0.9; } else if( !rec_play ){ putFlanger( left , right ); - left /= 1.5; right /= 1.5; + left /= 1.5; getFlanger( & left , & right ); } @@ -1516,7 +1498,7 @@ void playBass ( struct PlayState * state ){ } -void playHat ( struct PlayState * state ){ +void Hat ( struct PlayState * state ){ uint8_t note = state -> note; int channel = state -> channel; @@ -1598,7 +1580,7 @@ void playHat ( struct PlayState * state ){ } -void playDrum ( struct PlayState * state ){ +void Drum ( struct PlayState * state ){ uint8_t note = state -> note; int channel = state -> channel; @@ -1645,8 +1627,8 @@ void playDrum ( struct PlayState * state ){ float clip = 0.3; - left = ranged(left,clip); right = ranged(right,clip); + left = ranged(left,clip); addBuffer(left,right); @@ -1658,16 +1640,8 @@ void playDrum ( struct PlayState * state ){ #undef setFrame -void ( * Instruments [] )( struct PlayState * ) = { - playDrum , - playHat , - playBass , - playBass , - playAcidBass , - playEffect , - playPoly , - playPad -}; +void ( * Instruments [] )( struct PlayState * ) = + { Drum , Hat , Bass , Bass , AcidBass , Effect , Poly , Pad }; void play ( float * buffer , int length ){ @@ -1680,11 +1654,12 @@ void play ( float * buffer , int length ){ // Render - int tick_changed = 0; - for ( int frame = 0 ; frame < length ; frame++ ){ - tick_changed = 0; + int offset = ( frame << 1 ); + + bool tick_changed = false; + // Increment Tick Number @@ -1694,8 +1669,9 @@ void play ( float * buffer , int length ){ } if( timer == 0 ) - tick_changed = 1; + tick_changed = true; + // Synths Channels for ( int channel = 0 ; channel < Channel_Count ; channel++ ){ @@ -1729,7 +1705,7 @@ void play ( float * buffer , int length ){ state.tick_changed = tick_changed; state.channel = channel; state.buffer = buffer; - state.frame = frame; + state.offset = offset; state.right = & right; state.note = row[ channel ]; state.left = & left; @@ -1739,13 +1715,13 @@ void play ( float * buffer , int length ){ getEcho( & left , & right ); - buffer[ ( frame << 1 ) + 1 ] += right; - buffer[ ( frame << 1 ) + 0 ] += left; + buffer[ offset + 1 ] += right; + buffer[ offset + 0 ] += left; if( start_recorder ){ - rec1[ rec_ptr ] = buffer[ ( frame << 1 ) + 0 ]; - rec2[ rec_ptr ] = buffer[ ( frame << 1 ) + 1 ]; + rec1[ rec_ptr ] = buffer[ offset + 0 ]; + rec2[ rec_ptr ] = buffer[ offset + 1 ]; rec_ptr++; @@ -1767,8 +1743,8 @@ void play ( float * buffer , int length ){ getFlanger( & left , & right ); - buffer[ ( frame << 1 ) + 1 ] += right; - buffer[ ( frame << 1 ) + 0 ] += left; + buffer[ offset + 1 ] += right; + buffer[ offset + 0 ] += left; rec_ptr--; @@ -1787,8 +1763,8 @@ void play ( float * buffer , int length ){ fadeout_vol = 0; } - buffer[ ( frame << 1 ) + 0 ] *= fadeout_vol; - buffer[ ( frame << 1 ) + 1 ] *= fadeout_vol; + buffer[ offset + 0 ] *= fadeout_vol; + buffer[ offset + 1 ] *= fadeout_vol; } } } @@ -2012,36 +1988,39 @@ int exportWAV ( const char * path ){ #undef word +int playAudio (){ + + SDL_Init( 0 ); + + SDL_AudioSpec a; + a.callback = sdl_audio_callback; + a.userdata = NULL; + a.channels = 2; + a.samples = bufsize; + a.format = AUDIO_F32; + a.freq = srate; + + if( SDL_OpenAudio( & a , NULL ) < 0 ){ + printf( "Couldn't open audio: %s\n" , SDL_GetError() ); + return -1; + } + + SDL_PauseAudio( 0 ); + + return 0; +} + + int sound_init ( const char * path ){ for ( int a = 0 ; a < Reverb ; a++ ) slow_reverb[ a ] = ( ( rand() & 2047 ) - 1024 ) << 6; - if( out_mode == 0 ){ - - SDL_Init( 0 ); - - SDL_AudioSpec a; - a.callback = sdl_audio_callback; - a.userdata = NULL; - a.channels = 2; - a.samples = bufsize; - a.format = AUDIO_F32; - a.freq = srate; - - if( SDL_OpenAudio( & a , NULL ) < 0 ){ - printf( "Couldn't open audio: %s\n" , SDL_GetError() ); - return -1; - } - - SDL_PauseAudio( 0 ); - - return 0; + switch ( out_mode ){ + case 0 : return playAudio(); + case 1 : return exportWAV( path ); } - if( out_mode == 1 ) - return exportWAV(path); - return -1; } @@ -2056,7 +2035,7 @@ void sound_close (){ } -void int_handler ( int param ){ +void onInterrupt (){ stop_execution = 1; } @@ -2091,7 +2070,7 @@ void printInstructions (){ int main( int argumentCount , char * arguments [] ){ - signal( SIGINT , int_handler ); + signal( SIGINT , onInterrupt ); const char * export_path = NULL; From b4c4bdffa51e6644a23e5000d2f5911ed50736cc Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Sun, 27 Nov 2022 20:29:16 -0500 Subject: [PATCH 17/18] General Refactoring --- ps.c | 92 +++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 51 insertions(+), 41 deletions(-) diff --git a/ps.c b/ps.c index 2654086..3cba257 100644 --- a/ps.c +++ b/ps.c @@ -40,7 +40,7 @@ int bufsize = 1024; -int srate = 44100; +int fps = 44100; float fadeout_vol = 1; int fadeout = 0; @@ -1019,13 +1019,11 @@ int start_recorder = 0; int rec_play = 0 , - rec_ptr = 0 ; + recoder_frame = 0 ; #define rec_size ( Tick_Size * 16 ) -float - rec1[ rec_size ] , - rec2[ rec_size ] ; + static inline void putFlanger ( float v1 , float v2 ){ @@ -1057,9 +1055,15 @@ static inline void getFlanger ( float * v1 , float * v2 ){ flanger_timer += 0.0001; - flanger_size = (rec_play) - ? 580 - : ( ( sin( flanger_timer / 10 ) + 1 ) / 2 ) * ( Flanger_Max_Size - 30 ) + 30; + if(rec_play){ + flanger_size = 580; + return; + } + + flanger_size = sin( flanger_timer / 10 ) + 1; + flanger_size /= 2; + flanger_size *= ( Flanger_Max_Size - 30 ); + flanger_size += 30; } @@ -1210,14 +1214,16 @@ void Pad ( struct PlayState * state ){ int channel = state -> channel; uint8_t note = state -> note; - float left , right; + float + right = 0 , + left = 0 ; if( state -> tick_changed ){ if( note ){ effect_timer1[ channel ] = 1; bass_freq[ channel ] = square( (float)( note + offset ) / 12.0F ); - bass_tdelta[ channel ] = bass_freq[ channel ] / srate; + bass_tdelta[ channel ] = bass_freq[ channel ] / fps; bass_timer[ channel ] = 0; } @@ -1250,15 +1256,9 @@ void Pad ( struct PlayState * state ){ right = limit(right,-1,1); left = limit(left,-1,1); - } else { - left = 0; - right = 0; } - putEcho( - left / 8 , - right / 8 - ); + putEcho( left / 8 , right / 8 ); setFrame(0,0) } @@ -1269,31 +1269,36 @@ void Poly ( struct PlayState * state ){ uint8_t note = state -> note; int channel = state -> channel; - float left , right; if( state -> tick_changed ) if( note ){ effect_timer1[ channel ] = 1; bass_freq[ channel ] = square( (float)( note + offset ) / 12.0F ); - bass_tdelta[ channel ] = bass_freq[ channel ] / srate; + bass_tdelta[ channel ] = bass_freq[ channel ] / fps; bass_timer[ channel ] = 0; } + + float + right = 0 , + left = 0 ; + + if( effect_timer1[ channel ] ){ effect_timer1[ channel ] *= 0.99998; bass_delta[ channel ] += ( bass_tdelta[ channel ] - bass_delta[ channel ] ) / 1800; bass_timer[ channel ] += bass_delta[ channel ]; - + + right = left = effect_timer1[ channel ]; - left *= sin( bass_timer[ channel ] ); - right *= sin( bass_timer[ channel ] * 1.01 ); + float bass = bass_timer[ channel ]; + + right *= sin( bass * 1.01 ); + left *= sin( bass ); - } else { - left = 0; - right = 0; } addBuffer( left / 8 , right / 8 ); @@ -1302,6 +1307,7 @@ void Poly ( struct PlayState * state ){ setFrame(0,0) } + void Effect ( struct PlayState * state ){ uint8_t note = state -> note; @@ -1389,7 +1395,7 @@ void AcidBass ( struct PlayState * state ){ if( state -> tick_changed ){ bass_freq[ channel ] = square( (float)( note + offset ) / 12.0F ); - bass_tdelta[ channel ] = bass_freq[ channel ] / srate; + bass_tdelta[ channel ] = bass_freq[ channel ] / fps; bass_timer[ channel ] = 0; effect_timer1[ channel ] = 1; @@ -1445,7 +1451,7 @@ void Bass ( struct PlayState * state ){ if( state -> tick_changed ){ bass_freq[ channel ] = square( (float)( note + offset ) / 12.0F ); - bass_tdelta[ channel ] = bass_freq[ channel ] / srate; + bass_tdelta[ channel ] = bass_freq[ channel ] / fps; bass_timer[ channel ] = 0; effect_timer1[ channel ] = 1; } @@ -1646,6 +1652,10 @@ void ( * Instruments [] )( struct PlayState * ) = void play ( float * buffer , int length ){ + static float + recoder_left[ rec_size ] , + recoder_right[ rec_size ] ; + float left , right; @@ -1720,22 +1730,22 @@ void play ( float * buffer , int length ){ if( start_recorder ){ - rec1[ rec_ptr ] = buffer[ offset + 0 ]; - rec2[ rec_ptr ] = buffer[ offset + 1 ]; + recoder_left[ recoder_frame ] = buffer[ offset + 0 ]; + recoder_right[ recoder_frame ] = buffer[ offset + 1 ]; - rec_ptr++; + recoder_frame++; - if( rec_ptr >= rec_size ){ + if( recoder_frame >= rec_size ){ start_recorder = 0; - rec_ptr --; + recoder_frame --; } } if( rec_play ){ putFlanger( - rec1[ rec_ptr ] / 2 , - rec2[ rec_ptr ] / 2 + recoder_left[ recoder_frame ] / 2 , + recoder_right[ recoder_frame ] / 2 ); left = 0; @@ -1746,10 +1756,10 @@ void play ( float * buffer , int length ){ buffer[ offset + 1 ] += right; buffer[ offset + 0 ] += left; - rec_ptr--; + recoder_frame--; - if( rec_ptr < 0 ) - rec_ptr = rec_size - 1; + if( recoder_frame < 0 ) + recoder_frame = rec_size - 1; } timer++; @@ -1916,10 +1926,10 @@ int exportWAV ( const char * path ){ word(2); // Frames Per Second - quad(srate); + quad(fps); // Bytes Per Second - quad(srate * 2 * 4) + quad(fps * 2 * 4) // Block Alignment word(2 * 4); @@ -1962,7 +1972,7 @@ int exportWAV ( const char * path ){ int frames = dataSize / ( 4 * 2 ) , - seconds = frames / srate ; + seconds = frames / fps ; newline(); @@ -1998,7 +2008,7 @@ int playAudio (){ a.channels = 2; a.samples = bufsize; a.format = AUDIO_F32; - a.freq = srate; + a.freq = fps; if( SDL_OpenAudio( & a , NULL ) < 0 ){ printf( "Couldn't open audio: %s\n" , SDL_GetError() ); From e25f4db32e3112dcbc35f7ec72809452846aabb9 Mon Sep 17 00:00:00 2001 From: ElectronicsArchiver <85485984+ElectronicsArchiver@users.noreply.github.com> Date: Sun, 27 Nov 2022 21:56:19 -0500 Subject: [PATCH 18/18] General Refactoring --- .gitignore | 4 ++++ ps.c | 38 ++++++++++++++++++++++++++++---------- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 84de4f0..34290f1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,8 @@ +# VSCode configuration + +.vscode/ + # Don't include generated files /ps diff --git a/ps.c b/ps.c index 3cba257..b8af65e 100644 --- a/ps.c +++ b/ps.c @@ -24,8 +24,10 @@ #endif -// Number of Synth Channels +#define Flanger_Max_Size 100 + +// Number of Synth Channels #define Channel_Count 8 #define Tick_Size 6000 @@ -34,8 +36,6 @@ #define Reverb 16 -#define Flanger_Max_Size 100 - @@ -47,9 +47,14 @@ int fadeout = 0; float volume = 1.2; -int timer = 0; //0...Tick_Size -int tick = 0; //0...pattern size (number of lines) -int pattern = 0; //0...number of patterns +// 0 .. Tick_Size +int timer = 0; + +// 0 .. Pattern Size (number of lines) +int tick = 0; + +// 0 .. Number of Patterns +int pattern = 0; float dc_s_left = 0 , @@ -62,7 +67,14 @@ float float loudest = 1; int stop_execution = 0; -int out_mode = 0; //0 - SDL; 1 - WAV EXPORT; + + +/* + * 0 : SDL + * 1 : WAV Export + */ + +int out_mode = 0; @@ -1824,6 +1836,7 @@ void renderBuffer( float * buffer , int length ){ dc_ps_right * ratio_left + dc_s_right * ratio_right ; + // Simple Volume Compression buffer[ a * 2 + 0 ] /= loudest; @@ -1844,8 +1857,13 @@ void renderBuffer( float * buffer , int length ){ } -void sdl_audio_callback ( void * udata , Uint8 * stream , int len ){ - renderBuffer( (float *) stream , len / 8 ); +void onRequestAudio ( void * userData , Uint8 * stream , int length ){ + + // 4 x Bytes Per Float * 2 x LR Channels + + int frames = length / ( 4 * 2 ); + + renderBuffer( (float *) stream , frames ); } @@ -2003,7 +2021,7 @@ int playAudio (){ SDL_Init( 0 ); SDL_AudioSpec a; - a.callback = sdl_audio_callback; + a.callback = onRequestAudio; a.userdata = NULL; a.channels = 2; a.samples = bufsize;