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.

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