logo

bytemedia

Home to byte-level sounds, images, videos, … git clone https://hacktivis.me/git/bytemedia.git
commit: b9a421087eedd6541d0fdab179b7e80599f65880
parent ad8f35c554aae372eb50a66b67e0010fb83dae72
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sun, 31 Oct 2021 01:01:11 +0200

C/tap_code: Simplify code structure

Diffstat:

MC/tap_code.c38+++++++++++++++++---------------------
1 file changed, 17 insertions(+), 21 deletions(-)

diff --git a/C/tap_code.c b/C/tap_code.c @@ -56,24 +56,21 @@ static int tap_code[26][2] = { }; void -code_to_tap(int code) +tap(int tone, int dur_multiplier) { - for(int d = 0; d < code; d++) + for(int i = 0; i < dur * dur_multiplier; i++, t++) { - for(int i = 0; i < dur; i++, t++) - { - putchar(t++ * 1 % 30); - } - - for(int i = 0; i < dur * 2; i++, t++) - { - putchar(t++ * 0 % 30); - } + putchar((t++ * tone % 30) * 0.80); } +} - for(int i = 0; i < dur * 4; i++, t++) +void +code_to_tap(int code) +{ + for(int d = 0; d < code; d++) { - putchar(t++ * 0 % 30); + tap(1, 1); + tap(0, 2); } } @@ -107,20 +104,19 @@ main(void) } code_to_tap(tap_code[c][0]); + tap(0, 3); code_to_tap(tap_code[c][1]); } - else + else if(c == ' ') { - for(int i = 0; i < dur; i++, t++) - { - putchar(t++ * 2 % 30); - } + tap(0, 7); } - - for(int i = 0; i < dur * 8; i++, t++) + else { - putchar(t++ * 0 % 30); + tap(2, 1); } + + tap(0, 8); } return 0;