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.

297 lines
9.5 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 Feature on
  47. * `AU_OFF` - Turn Audio Feature off
  48. * `AU_TOG` - Toggle Audio Feature state
  49. !> These keycodes turn all of the audio functionality on and off. Turning it off means that audio feedback, audio clicky, music mode, etc. are disabled, completely.
  50. ## ARM Audio Volume
  51. 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`:
  52. ```c
  53. #define DAC_SAMPLE_MAX 65535U
  54. ```
  55. ## Music Mode
  56. 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.
  57. Recording is experimental due to some memory issues - if you experience some weird behavior, unplugging/replugging your keyboard will fix things.
  58. Keycodes available:
  59. * `MU_ON` - Turn music mode on
  60. * `MU_OFF` - Turn music mode off
  61. * `MU_TOG` - Toggle music mode
  62. * `MU_MOD` - Cycle through the music modes:
  63. * `CHROMATIC_MODE` - Chromatic scale, row changes the octave
  64. * `GUITAR_MODE` - Chromatic scale, but the row changes the string (+5 st)
  65. * `VIOLIN_MODE` - Chromatic scale, but the row changes the string (+7 st)
  66. * `MAJOR_MODE` - Major scale
  67. In music mode, the following keycodes work differently, and don't pass through:
  68. * `LCTL` - start a recording
  69. * `LALT` - stop recording/stop playing
  70. * `LGUI` - play recording
  71. * `KC_UP` - speed-up playback
  72. * `KC_DOWN` - slow-down playback
  73. 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:
  74. #define MUSIC_MASK keycode != KC_NO
  75. Which will capture all keycodes - be careful, this will get you stuck in music mode until you restart your keyboard!
  76. 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`:
  77. bool music_mask_user(uint16_t keycode) {
  78. switch (keycode) {
  79. case RAISE:
  80. case LOWER:
  81. return false;
  82. default:
  83. return true;
  84. }
  85. }
  86. Things that return false are not part of the mask, and are always processed.
  87. The pitch standard (`PITCH_STANDARD_A`) is 440.0f by default - to change this, add something like this to your `config.h`:
  88. #define PITCH_STANDARD_A 432.0f
  89. 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`:
  90. #define NO_MUSIC_MODE
  91. ## Audio Click
  92. 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.
  93. * `CK_TOGG` - Toggles the status (will play sound if enabled)
  94. * `CK_ON` - Turns on Audio Click (plays sound)
  95. * `CK_OFF` - Turns off Audio Click (doesn't play sound)
  96. * `CK_RST` - Resets the frequency to the default state (plays sound at default frequency)
  97. * `CK_UP` - Increases the frequency of the clicks (plays sound at new frequency)
  98. * `CK_DOWN` - Decreases the frequency of the clicks (plays sound at new frequency)
  99. The feature is disabled by default, to save space. To enable it, add this to your `config.h`:
  100. #define AUDIO_CLICKY
  101. You can configure the default, min and max frequencies, the stepping and built in randomness by defining these values:
  102. | Option | Default Value | Description |
  103. |--------|---------------|-------------|
  104. | `AUDIO_CLICKY_FREQ_DEFAULT` | 440.0f | Sets the default/starting audio frequency for the clicky sounds. |
  105. | `AUDIO_CLICKY_FREQ_MIN` | 65.0f | Sets the lowest frequency (under 60f are a bit buggy). |
  106. | `AUDIO_CLICKY_FREQ_MAX` | 1500.0f | Sets the the highest frequency. Too high may result in coworkers attacking you. |
  107. | `AUDIO_CLICKY_FREQ_FACTOR` | 1.18921f| Sets the stepping of UP/DOWN key codes. |
  108. | `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. |
  109. ## MIDI Functionality
  110. This is still a WIP, but check out `quantum/process_keycode/process_midi.c` to see what's happening. Enable from the Makefile.
  111. ## Audio Keycodes
  112. |Key |Aliases |Description |
  113. |----------------|---------|----------------------------------|
  114. |`AU_ON` | |Audio mode on |
  115. |`AU_OFF` | |Audio mode off |
  116. |`AU_TOG` | |Toggles Audio mode |
  117. |`CLICKY_TOGGLE` |`CK_TOGG`|Toggles Audio clicky mode |
  118. |`CLICKY_UP` |`CK_UP` |Increases frequency of the clicks |
  119. |`CLICKY_DOWN` |`CK_DOWN`|Decreases frequency of the clicks |
  120. |`CLICKY_RESET` |`CK_RST` |Resets frequency to default |
  121. |`MU_ON` | |Turns on Music Mode |
  122. |`MU_OFF` | |Turns off Music Mode |
  123. |`MU_TOG` | |Toggles Music Mode |
  124. |`MU_MOD` | |Cycles through the music modes |
  125. <!-- FIXME: this formatting needs work
  126. ## Audio
  127. ```c
  128. #ifdef AUDIO_ENABLE
  129. AU_ON,
  130. AU_OFF,
  131. AU_TOG,
  132. #ifdef FAUXCLICKY_ENABLE
  133. FC_ON,
  134. FC_OFF,
  135. FC_TOG,
  136. #endif
  137. // Music mode on/off/toggle
  138. MU_ON,
  139. MU_OFF,
  140. MU_TOG,
  141. // Music voice iterate
  142. MUV_IN,
  143. MUV_DE,
  144. #endif
  145. ```
  146. ### Midi
  147. #if !MIDI_ENABLE_STRICT || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
  148. MI_ON, // send midi notes when music mode is enabled
  149. MI_OFF, // don't send midi notes when music mode is enabled
  150. #endif
  151. MIDI_TONE_MIN,
  152. MIDI_TONE_MAX
  153. MI_C = MIDI_TONE_MIN,
  154. MI_Cs,
  155. MI_Db = MI_Cs,
  156. MI_D,
  157. MI_Ds,
  158. MI_Eb = MI_Ds,
  159. MI_E,
  160. MI_F,
  161. MI_Fs,
  162. MI_Gb = MI_Fs,
  163. MI_G,
  164. MI_Gs,
  165. MI_Ab = MI_Gs,
  166. MI_A,
  167. MI_As,
  168. MI_Bb = MI_As,
  169. MI_B,
  170. MIDI_TONE_KEYCODE_OCTAVES > 1
  171. where x = 1-5:
  172. MI_C_x,
  173. MI_Cs_x,
  174. MI_Db_x = MI_Cs_x,
  175. MI_D_x,
  176. MI_Ds_x,
  177. MI_Eb_x = MI_Ds_x,
  178. MI_E_x,
  179. MI_F_x,
  180. MI_Fs_x,
  181. MI_Gb_x = MI_Fs_x,
  182. MI_G_x,
  183. MI_Gs_x,
  184. MI_Ab_x = MI_Gs_x,
  185. MI_A_x,
  186. MI_As_x,
  187. MI_Bb_x = MI_As_x,
  188. MI_B_x,
  189. MI_OCT_Nx 1-2
  190. MI_OCT_x 0-7
  191. MIDI_OCTAVE_MIN = MI_OCT_N2,
  192. MIDI_OCTAVE_MAX = MI_OCT_7,
  193. MI_OCTD, // octave down
  194. MI_OCTU, // octave up
  195. MI_TRNS_Nx 1-6
  196. MI_TRNS_x 0-6
  197. MIDI_TRANSPOSE_MIN = MI_TRNS_N6,
  198. MIDI_TRANSPOSE_MAX = MI_TRNS_6,
  199. MI_TRNSD, // transpose down
  200. MI_TRNSU, // transpose up
  201. MI_VEL_x 1-10
  202. MIDI_VELOCITY_MIN = MI_VEL_1,
  203. MIDI_VELOCITY_MAX = MI_VEL_9,
  204. MI_VELD, // velocity down
  205. MI_VELU, // velocity up
  206. MI_CHx 1-16
  207. MIDI_CHANNEL_MIN = MI_CH1
  208. MIDI_CHANNEL_MAX = MI_CH16,
  209. MI_CHD, // previous channel
  210. MI_CHU, // next channel
  211. MI_ALLOFF, // all notes off
  212. MI_SUS, // sustain
  213. MI_PORT, // portamento
  214. MI_SOST, // sostenuto
  215. MI_SOFT, // soft pedal
  216. MI_LEG, // legato
  217. MI_MOD, // modulation
  218. MI_MODSD, // decrease modulation speed
  219. MI_MODSU, // increase modulation speed
  220. #endif // MIDI_ADVANCED
  221. -->