diff options
Diffstat (limited to 'quantum/audio/muse.c')
| -rw-r--r-- | quantum/audio/muse.c | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/quantum/audio/muse.c b/quantum/audio/muse.c new file mode 100644 index 000000000..f3cb592d8 --- /dev/null +++ b/quantum/audio/muse.c | |||
| @@ -0,0 +1,111 @@ | |||
| 1 | #include "muse.h" | ||
| 2 | |||
| 3 | enum { | ||
| 4 | MUSE_OFF, | ||
| 5 | MUSE_ON, | ||
| 6 | MUSE_C_1_2, | ||
| 7 | MUSE_C1, | ||
| 8 | MUSE_C2, | ||
| 9 | MUSE_C4, | ||
| 10 | MUSE_C8, | ||
| 11 | MUSE_C3, | ||
| 12 | MUSE_C6, | ||
| 13 | MUSE_B1, | ||
| 14 | MUSE_B2, | ||
| 15 | MUSE_B3, | ||
| 16 | MUSE_B4, | ||
| 17 | MUSE_B5, | ||
| 18 | MUSE_B6, | ||
| 19 | MUSE_B7, | ||
| 20 | MUSE_B8, | ||
| 21 | MUSE_B9, | ||
| 22 | MUSE_B10, | ||
| 23 | MUSE_B11, | ||
| 24 | MUSE_B12, | ||
| 25 | MUSE_B13, | ||
| 26 | MUSE_B14, | ||
| 27 | MUSE_B15, | ||
| 28 | MUSE_B16, | ||
| 29 | MUSE_B17, | ||
| 30 | MUSE_B18, | ||
| 31 | MUSE_B19, | ||
| 32 | MUSE_B20, | ||
| 33 | MUSE_B21, | ||
| 34 | MUSE_B22, | ||
| 35 | MUSE_B23, | ||
| 36 | MUSE_B24, | ||
| 37 | MUSE_B25, | ||
| 38 | MUSE_B26, | ||
| 39 | MUSE_B27, | ||
| 40 | MUSE_B28, | ||
| 41 | MUSE_B29, | ||
| 42 | MUSE_B30, | ||
| 43 | MUSE_B31 | ||
| 44 | }; | ||
| 45 | |||
| 46 | bool number_of_ones_to_bool[16] = { | ||
| 47 | 1, 0, 0, 1, 0, 1, 1, 0, | ||
| 48 | 0, 1, 1, 0, 1, 0, 0, 1 | ||
| 49 | }; | ||
| 50 | |||
| 51 | uint8_t muse_interval[4] = {MUSE_B7, MUSE_B19, MUSE_B3, MUSE_B28}; | ||
| 52 | uint8_t muse_theme[4] = {MUSE_B8, MUSE_B23, MUSE_B18, MUSE_B17}; | ||
| 53 | |||
| 54 | bool muse_timer_1bit = 0; | ||
| 55 | uint8_t muse_timer_2bit = 0; | ||
| 56 | uint8_t muse_timer_2bit_counter = 0; | ||
| 57 | uint8_t muse_timer_4bit = 0; | ||
| 58 | uint32_t muse_timer_31bit = 0; | ||
| 59 | |||
| 60 | bool bit_for_value(uint8_t value) { | ||
| 61 | switch (value) { | ||
| 62 | case MUSE_OFF: | ||
| 63 | return 0; | ||
| 64 | case MUSE_ON: | ||
| 65 | return 1; | ||
| 66 | case MUSE_C_1_2: | ||
| 67 | return muse_timer_1bit; | ||
| 68 | case MUSE_C1: | ||
| 69 | return (muse_timer_4bit & 1); | ||
| 70 | case MUSE_C2: | ||
| 71 | return (muse_timer_4bit & 2); | ||
| 72 | case MUSE_C4: | ||
| 73 | return (muse_timer_4bit & 4); | ||
| 74 | case MUSE_C8: | ||
| 75 | return (muse_timer_4bit & 8); | ||
| 76 | case MUSE_C3: | ||
| 77 | return (muse_timer_2bit & 1); | ||
| 78 | case MUSE_C6: | ||
| 79 | return (muse_timer_2bit & 2); | ||
| 80 | default: | ||
| 81 | return muse_timer_31bit & (1UL << (value - MUSE_B1)); | ||
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | uint8_t muse_clock_pulse(void) { | ||
| 86 | |||
| 87 | bool top = number_of_ones_to_bool[ | ||
| 88 | bit_for_value(muse_theme[0]) + | ||
| 89 | (bit_for_value(muse_theme[1]) << 1) + | ||
| 90 | (bit_for_value(muse_theme[2]) << 2) + | ||
| 91 | (bit_for_value(muse_theme[3]) << 3) | ||
| 92 | ]; | ||
| 93 | |||
| 94 | if (muse_timer_1bit == 0) { | ||
| 95 | if (muse_timer_2bit_counter == 0) { | ||
| 96 | muse_timer_2bit = (muse_timer_2bit + 1) % 4; | ||
| 97 | } | ||
| 98 | muse_timer_2bit_counter = (muse_timer_2bit_counter + 1) % 3; | ||
| 99 | muse_timer_4bit = (muse_timer_4bit + 1) % 16; | ||
| 100 | muse_timer_31bit = (muse_timer_31bit << 1) + top; | ||
| 101 | } | ||
| 102 | |||
| 103 | muse_timer_1bit = (muse_timer_1bit + 1) % 2; | ||
| 104 | |||
| 105 | return | ||
| 106 | bit_for_value(muse_interval[0]) + | ||
| 107 | (bit_for_value(muse_interval[1]) << 1) + | ||
| 108 | (bit_for_value(muse_interval[2]) << 2) + | ||
| 109 | (bit_for_value(muse_interval[3]) << 3); | ||
| 110 | |||
| 111 | } | ||
