]> git.donarmstrong.com Git - qmk_firmware.git/blob - quantum/audio.h
getting ready for getters and setters
[qmk_firmware.git] / quantum / audio.h
1 #include <stdint.h>
2 #include <stdbool.h>
3 #include <avr/io.h>
4 #include <util/delay.h>
5 #include "musical_notes.h"
6 #include "song_list.h"
7
8 #ifndef AUDIO_H
9 #define AUDIO_H
10
11 typedef union {
12     uint8_t raw;
13     struct {
14         bool    enable :1;
15         uint8_t level  :7;
16     };
17 } audio_config_t;
18
19 void audio_toggle(void);
20 void audio_on(void);
21 void audio_off(void);
22
23 void play_sample(uint8_t * s, uint16_t l, bool r);
24 void play_note(double freq, int vol);
25 void stop_note(double freq);
26 void stop_all_notes(void);
27 void init_notes(void);
28 void play_notes(float (*np)[][2], uint8_t n_count, bool n_repeat, float n_rest);
29
30 void set_timbre(float timbre);
31 void set_tempo(float tempo);
32 void increase_tempo(uint8_t tempo_change);
33 void decrease_tempo(uint8_t tempo_change);
34
35 #define SCALE (int []){ 0 + (12*0), 2 + (12*0), 4 + (12*0), 5 + (12*0), 7 + (12*0), 9 + (12*0), 11 + (12*0), \
36                                                 0 + (12*1), 2 + (12*1), 4 + (12*1), 5 + (12*1), 7 + (12*1), 9 + (12*1), 11 + (12*1), \
37                                                 0 + (12*2), 2 + (12*2), 4 + (12*2), 5 + (12*2), 7 + (12*2), 9 + (12*2), 11 + (12*2), \
38                                                 0 + (12*3), 2 + (12*3), 4 + (12*3), 5 + (12*3), 7 + (12*3), 9 + (12*3), 11 + (12*3), \
39                                                 0 + (12*4), 2 + (12*4), 4 + (12*4), 5 + (12*4), 7 + (12*4), 9 + (12*4), 11 + (12*4), }
40
41 // These macros are used to allow play_notes to play an array of indeterminate
42 // length. This works around the limitation of C's sizeof operation on pointers.
43 // The global float array for the song must be used here.
44 #define NOTE_ARRAY_SIZE(x) ((int)(sizeof(x) / (sizeof(x[0]))))
45 #define PLAY_NOTE_ARRAY(note_array, note_repeat, note_rest_style) play_notes(&note_array, NOTE_ARRAY_SIZE((note_array)), (note_repeat), (note_rest_style));
46
47 void play_goodbye_tone(void);
48 void play_startup_tone(void);
49
50 #define VIBRATO_LUT (float []) { \
51 1.00090714186239, \
52 1.00181152169061, \
53 1.00270955652027, \
54 1.00359767896099, \
55 1.00447235162891, \
56 1.00533008160601, \
57 1.00616743486158, \
58 1.00698105056935, \
59 1.00776765525194, \
60 1.00852407668313, \
61 1.0092472574777, \
62 1.00993426829815, \
63 1.01058232060837, \
64 1.01118877890462, \
65 1.01175117235612, \
66 1.01226720578933, \
67 1.01273476995269, \
68 1.01315195100182, \
69 1.0135170391489, \
70 1.01382853642434, \
71 1.01408516350345, \
72 1.01428586555648, \
73 1.0144298170856, \
74 1.0145164257189, \
75 1.01454533493752, \
76 1.0145164257189, \
77 1.0144298170856, \
78 1.01428586555648, \
79 1.01408516350345, \
80 1.01382853642434, \
81 1.0135170391489, \
82 1.01315195100182, \
83 1.01273476995269, \
84 1.01226720578933, \
85 1.01175117235612, \
86 1.01118877890462, \
87 1.01058232060837, \
88 1.00993426829815, \
89 1.0092472574777, \
90 1.00852407668313, \
91 1.00776765525194, \
92 1.00698105056935, \
93 1.00616743486158, \
94 1.00533008160601, \
95 1.00447235162891, \
96 1.00359767896099, \
97 1.00270955652027, \
98 1.00181152169061, \
99 1.00090714186239, \
100 1, \
101 0.999093680298157, \
102 0.998191753986265, \
103 0.997297765337276, \
104 0.996415217934032, \
105 0.995547561242821, \
106 0.99469817754036, \
107 0.993870369236874, \
108 0.993067346634376, \
109 0.992292216155724, \
110 0.991547969076588, \
111 0.990837470789065, \
112 0.990163450622494, \
113 0.989528492243954, \
114 0.988935024658062, \
115 0.988385313823004, \
116 0.98788145489731, \
117 0.987425365129624, \
118 0.987018777401739, \
119 0.986663234433381, \
120 0.986360083655655, \
121 0.986110472758728, \
122 0.985915345918143, \
123 0.985775440703176, \
124 0.985691285669809, \
125 0.985663198640188, \
126 0.985691285669809, \
127 0.985775440703176, \
128 0.985915345918143, \
129 0.986110472758728, \
130 0.986360083655655, \
131 0.986663234433381, \
132 0.987018777401739, \
133 0.987425365129624, \
134 0.98788145489731, \
135 0.988385313823004, \
136 0.988935024658062, \
137 0.989528492243954, \
138 0.990163450622494, \
139 0.990837470789065, \
140 0.991547969076588, \
141 0.992292216155724, \
142 0.993067346634376, \
143 0.993870369236874, \
144 0.99469817754036, \
145 0.99554756124282, \
146 0.996415217934032, \
147 0.997297765337276, \
148 0.998191753986265, \
149 0.999093680298157, \
150 1, \
151 }
152 #define VIBRATO_LUT_LENGTH NOTE_ARRAY_SIZE(VIBRATO_LUT)
153
154 #endif