You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

295 lines
9.4 KiB

  1. # Audio
  2. Your keyboard can make sounds! If you've got a Planck, Preonic, or basically any AVR keyboard that allows access to certain PWM-capable pins, you can hook up a simple speaker and make it beep. You can use those beeps to indicate layer transitions, modifiers, special keys, or just to play some funky 8bit tunes.
  3. Up to two simultaneous audio voices are supported, one driven by timer 1 and another driven by timer 3. The following pins can be defined as audio outputs in config.h:
  4. Timer 1:
  5. `#define B5_AUDIO`
  6. `#define B6_AUDIO`
  7. `#define B7_AUDIO`
  8. Timer 3:
  9. `#define C4_AUDIO`
  10. `#define C5_AUDIO`
  11. `#define C6_AUDIO`
  12. If you add `AUDIO_ENABLE = yes` to your `rules.mk`, there's a couple different sounds that will automatically be enabled without any other configuration:
  13. ```
  14. STARTUP_SONG // plays when the keyboard starts up (audio.c)
  15. GOODBYE_SONG // plays when you press the RESET key (quantum.c)
  16. AG_NORM_SONG // plays when you press AG_NORM (quantum.c)
  17. AG_SWAP_SONG // plays when you press AG_SWAP (quantum.c)
  18. MUSIC_ON_SONG // plays when music mode is activated (process_music.c)
  19. MUSIC_OFF_SONG // plays when music mode is deactivated (process_music.c)
  20. CHROMATIC_SONG // plays when the chromatic music mode is selected (process_music.c)
  21. GUITAR_SONG // plays when the guitar music mode is selected (process_music.c)
  22. VIOLIN_SONG // plays when the violin music mode is selected (process_music.c)
  23. MAJOR_SONG // plays when the major music mode is selected (process_music.c)
  24. ```
  25. You can override the default songs by doing something like this in your `config.h`:
  26. ```c
  27. #ifdef AUDIO_ENABLE
  28. #define STARTUP_SONG SONG(STARTUP_SOUND)
  29. #endif
  30. ```
  31. A full list of sounds can be found in [quantum/audio/song_list.h](https://github.com/qmk/qmk_firmware/blob/master/quantum/audio/song_list.h) - feel free to add your own to this list! All available notes can be seen in [quantum/audio/musical_notes.h](https://github.com/qmk/qmk_firmware/blob/master/quantum/audio/musical_notes.h).
  32. To play a custom sound at a particular time, you can define a song like this (near the top of the file):
  33. ```c
  34. float my_song[][2] = SONG(QWERTY_SOUND);
  35. ```
  36. And then play your song like this:
  37. ```c
  38. PLAY_SONG(my_song);
  39. ```
  40. Alternatively, you can play it in a loop like this:
  41. ```c
  42. PLAY_LOOP(my_song);
  43. ```
  44. It's advised that you wrap all audio features in `#ifdef AUDIO_ENABLE` / `#endif` to avoid causing problems when audio isn't built into the keyboard.
  45. The available keycodes for audio are:
  46. * `AU_ON` - Turn audio mode on
  47. * `AU_OFF` - Turn audio mode off
  48. * `AU_TOG` - Toggle audio mode
  49. ## ARM Audio Volume
  50. For ARM devices, you can adjust the DAC sample values. If your board is too loud for you or your coworkers, you can set the max using `DAC_SAMPLE_MAX` in your `config.h`:
  51. ```c
  52. #define DAC_SAMPLE_MAX 65535U
  53. ```
  54. ## Music Mode
  55. The music mode maps your columns to a chromatic scale, and your rows to octaves. This works best with ortholinear keyboards, but can be made to work with others. All keycodes less than `0xFF` get blocked, so you won't type while playing notes - if you have special keys/mods, those will still work. A work-around for this is to jump to a different layer with KC_NOs before (or after) enabling music mode.
  56. Recording is experimental due to some memory issues - if you experience some weird behavior, unplugging/replugging your keyboard will fix things.
  57. Keycodes available:
  58. * `MU_ON` - Turn music mode on
  59. * `MU_OFF` - Turn music mode off
  60. * `MU_TOG` - Toggle music mode
  61. * `MU_MOD` - Cycle through the music modes:
  62. * `CHROMATIC_MODE` - Chromatic scale, row changes the octave
  63. * `GUITAR_MODE` - Chromatic scale, but the row changes the string (+5 st)
  64. * `VIOLIN_MODE` - Chromatic scale, but the row changes the string (+7 st)
  65. * `MAJOR_MODE` - Major scale
  66. In music mode, the following keycodes work differently, and don't pass through:
  67. * `LCTL` - start a recording
  68. * `LALT` - stop recording/stop playing
  69. * `LGUI` - play recording
  70. * `KC_UP` - speed-up playback
  71. * `KC_DOWN` - slow-down playback
  72. By default, `MUSIC_MASK` is set to `keycode < 0xFF` which means keycodes less than `0xFF` are turned into notes, and don't output anything. You can change this by defining this in your `config.h` like this:
  73. #define MUSIC_MASK keycode != KC_NO
  74. Which will capture all keycodes - be careful, this will get you stuck in music mode until you restart your keyboard!
  75. For a more advanced way to control which keycodes should still be processed, you can use `music_mask_kb(keycode)` in `<keyboard>.c` and `music_mask_user(keycode)` in your `keymap.c`:
  76. bool music_mask_user(uint16_t keycode) {
  77. switch (keycode) {
  78. case RAISE:
  79. case LOWER:
  80. return false;
  81. default:
  82. return true;
  83. }
  84. }
  85. Things that return false are not part of the mask, and are always processed.
  86. The pitch standard (`PITCH_STANDARD_A`) is 440.0f by default - to change this, add something like this to your `config.h`:
  87. #define PITCH_STANDARD_A 432.0f
  88. You can completely disable Music Mode as well. This is useful, if you're pressed for space on your controller. To disable it, add this to your `config.h`:
  89. #define NO_MUSIC_MODE
  90. ## Audio Click
  91. This adds a click sound each time you hit a button, to simulate click sounds from the keyboard. And the sounds are slightly different for each keypress, so it doesn't sound like a single long note, if you type rapidly.
  92. * `CK_TOGG` - Toggles the status (will play sound if enabled)
  93. * `CK_ON` - Turns on Audio Click (plays sound)
  94. * `CK_OFF` - Turns off Audio Click (doesn't play sound)
  95. * `CK_RST` - Resets the frequency to the default state (plays sound at default frequency)
  96. * `CK_UP` - Increases the frequency of the clicks (plays sound at new frequency)
  97. * `CK_DOWN` - Decreases the frequency of the clicks (plays sound at new frequency)
  98. The feature is disabled by default, to save space. To enable it, add this to your `config.h`:
  99. #define AUDIO_CLICKY
  100. You can configure the default, min and max frequencies, the stepping and built in randomness by defining these values:
  101. | Option | Default Value | Description |
  102. |--------|---------------|-------------|
  103. | `AUDIO_CLICKY_FREQ_DEFAULT` | 440.0f | Sets the default/starting audio frequency for the clicky sounds. |
  104. | `AUDIO_CLICKY_FREQ_MIN` | 65.0f | Sets the lowest frequency (under 60f are a bit buggy). |
  105. | `AUDIO_CLICKY_FREQ_MAX` | 1500.0f | Sets the the highest frequency. Too high may result in coworkers attacking you. |
  106. | `AUDIO_CLICKY_FREQ_FACTOR` | 1.18921f| Sets the stepping of UP/DOWN key codes. |
  107. | `AUDIO_CLICKY_FREQ_RANDOMNESS` | 0.05f | Sets a factor of randomness for the clicks, Setting this to `0f` will make each click identical, and `1.0f` will make this sound much like the 90's computer screen scrolling/typing effect. |
  108. ## MIDI Functionality
  109. This is still a WIP, but check out `quantum/keymap_midi.c` to see what's happening. Enable from the Makefile.
  110. ## Audio Keycodes
  111. |Key |Aliases |Description |
  112. |----------------|---------|----------------------------------|
  113. |`AU_ON` | |Audio mode on |
  114. |`AU_OFF` | |Audio mode off |
  115. |`AU_TOG` | |Toggles Audio mode |
  116. |`CLICKY_TOGGLE` |`CK_TOGG`|Toggles Audio clicky mode |
  117. |`CLICKY_UP` |`CK_UP` |Increases frequency of the clicks |
  118. |`CLICKY_DOWN` |`CK_DOWN`|Decreases frequency of the clicks |
  119. |`CLICKY_RESET` |`CK_RST` |Resets frequency to default |
  120. |`MU_ON` | |Turns on Music Mode |
  121. |`MU_OFF` | |Turns off Music Mode |
  122. |`MU_TOG` | |Toggles Music Mode |
  123. |`MU_MOD` | |Cycles through the music modes |
  124. <!-- FIXME: this formatting needs work
  125. ## Audio
  126. ```c
  127. #ifdef AUDIO_ENABLE
  128. AU_ON,
  129. AU_OFF,
  130. AU_TOG,
  131. #ifdef FAUXCLICKY_ENABLE
  132. FC_ON,
  133. FC_OFF,
  134. FC_TOG,
  135. #endif
  136. // Music mode on/off/toggle
  137. MU_ON,
  138. MU_OFF,
  139. MU_TOG,
  140. // Music voice iterate
  141. MUV_IN,
  142. MUV_DE,
  143. #endif
  144. ```
  145. ### Midi
  146. #if !MIDI_ENABLE_STRICT || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
  147. MI_ON, // send midi notes when music mode is enabled
  148. MI_OFF, // don't send midi notes when music mode is enabled
  149. #endif
  150. MIDI_TONE_MIN,
  151. MIDI_TONE_MAX
  152. MI_C = MIDI_TONE_MIN,
  153. MI_Cs,
  154. MI_Db = MI_Cs,
  155. MI_D,
  156. MI_Ds,
  157. MI_Eb = MI_Ds,
  158. MI_E,
  159. MI_F,
  160. MI_Fs,
  161. MI_Gb = MI_Fs,
  162. MI_G,
  163. MI_Gs,
  164. MI_Ab = MI_Gs,
  165. MI_A,
  166. MI_As,
  167. MI_Bb = MI_As,
  168. MI_B,
  169. MIDI_TONE_KEYCODE_OCTAVES > 1
  170. where x = 1-5:
  171. MI_C_x,
  172. MI_Cs_x,
  173. MI_Db_x = MI_Cs_x,
  174. MI_D_x,
  175. MI_Ds_x,
  176. MI_Eb_x = MI_Ds_x,
  177. MI_E_x,
  178. MI_F_x,
  179. MI_Fs_x,
  180. MI_Gb_x = MI_Fs_x,
  181. MI_G_x,
  182. MI_Gs_x,
  183. MI_Ab_x = MI_Gs_x,
  184. MI_A_x,
  185. MI_As_x,
  186. MI_Bb_x = MI_As_x,
  187. MI_B_x,
  188. MI_OCT_Nx 1-2
  189. MI_OCT_x 0-7
  190. MIDI_OCTAVE_MIN = MI_OCT_N2,
  191. MIDI_OCTAVE_MAX = MI_OCT_7,
  192. MI_OCTD, // octave down
  193. MI_OCTU, // octave up
  194. MI_TRNS_Nx 1-6
  195. MI_TRNS_x 0-6
  196. MIDI_TRANSPOSE_MIN = MI_TRNS_N6,
  197. MIDI_TRANSPOSE_MAX = MI_TRNS_6,
  198. MI_TRNSD, // transpose down
  199. MI_TRNSU, // transpose up
  200. MI_VEL_x 1-10
  201. MIDI_VELOCITY_MIN = MI_VEL_1,
  202. MIDI_VELOCITY_MAX = MI_VEL_9,
  203. MI_VELD, // velocity down
  204. MI_VELU, // velocity up
  205. MI_CHx 1-16
  206. MIDI_CHANNEL_MIN = MI_CH1
  207. MIDI_CHANNEL_MAX = MI_CH16,
  208. MI_CHD, // previous channel
  209. MI_CHU, // next channel
  210. MI_ALLOFF, // all notes off
  211. MI_SUS, // sustain
  212. MI_PORT, // portamento
  213. MI_SOST, // sostenuto
  214. MI_SOFT, // soft pedal
  215. MI_LEG, // legato
  216. MI_MOD, // modulation
  217. MI_MODSD, // decrease modulation speed
  218. MI_MODSU, // increase modulation speed
  219. #endif // MIDI_ADVANCED
  220. -->